LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckHits_module.cc
Go to the documentation of this file.
1 //
2 // __ __ __ __ __
3 // ____ ______/ /_____ _/ // / / /_/ /__
4 // / __ `/ ___/ __/ __ `/ // /_/ __/ //_/
5 // / /_/ / / / /_/ /_/ /__ __/ /_/ ,<
6 // \__,_/_/ \__/\__, / /_/ \__/_/|_|
7 // /____/
8 //
9 // artg4tk: art based Geant 4 Toolkit
10 //
11 //=============================================================================
12 // CheckHits_module.cc: Analyzer module that demonstrates access to
13 // Calorimeter hits
14 // and makes some histograms
15 //
16 // Author: Hans Wenzel (Fermilab)
17 //=============================================================================
18 
19 // art Framework includes.
26 #include "art_root_io/TFileService.h"
27 
28 // artg4tk includes:
29 #include "artg4tk/pluginDetectors/gdml/ByParticle.hh"
30 #include "artg4tk/pluginDetectors/gdml/CalorimeterHit.hh"
31 #include "artg4tk/pluginDetectors/gdml/DRCalorimeterHit.hh"
32 
33 // Root includes.
34 #include "TH1F.h"
35 
36 // Other includes.
37 #include "CLHEP/Units/SystemOfUnits.h"
38 
39 namespace artg4tk {
40  class CheckHits;
41 }
42 
44 public:
45  explicit CheckHits(fhicl::ParameterSet const& p);
46  void beginJob() override;
47  void analyze(const art::Event& event) override;
48 
49 private:
50  bool _DumpGDML; // enable/disable dumping of GDML geometry information
51  TH1F* _hnHits; // number of CaloHits
52  TH1F* _hEdep; // total energy deposition in CaloHits
53  TH1F* _hnDRHits; // number of DRCaloHits
54  TH1F* _hDREdep; // total energy deposition in DRCaloHits
55  TH1F* _hNCeren; // total number of Cerenkovphotons in DRCaloHits
56 };
57 
58 using namespace std;
59 
61  : art::EDAnalyzer(p)
62  , _DumpGDML(p.get<bool>("DumpGDML"))
63  , _hnHits(0)
64  , _hEdep(0)
65  , _hnDRHits(0)
66  , _hDREdep(0)
67  , _hNCeren(0)
68 {}
69 
70 void
72 {
74  _hnHits = tfs->make<TH1F>("hnHits", "Number of CaloArtHits", 100, 0., 20000.);
75  _hEdep = tfs->make<TH1F>("hEdep", "total Energy deposition in CaloArtHits", 100, 0., 15.);
76  _hnDRHits = tfs->make<TH1F>("hnDRHits", "Number of DRCaloArtHits", 100, 0., 20000.);
77  _hDREdep = tfs->make<TH1F>("hDREdep", "total Energy deposition in DRCaloArtHits", 100, 0., 11.);
78  _hNCeren = tfs->make<TH1F>(
79  "hNCeren", "total number of Cerenkov Photons in DRCaloArtHits", 100, 0., 1000000.);
80 } // end beginJob
81 
82 void
84 {
85  typedef std::vector<art::Handle<CalorimeterHitCollection>> HandleVector;
86  auto allSims = event.getMany<CalorimeterHitCollection>();
87 
88  cout << "CheckHits Event: " << event.event() << " Nr of CaloHit collections: " << allSims.size()
89  << endl;
90  for (HandleVector::const_iterator i = allSims.begin(); i != allSims.end(); ++i) {
91  const CalorimeterHitCollection& sims(**i);
92  cout << "CaloHit collection size: " << sims.size() << endl;
93  double sumE = 0.0;
94  _hnHits->Fill(sims.size());
95  for (CalorimeterHitCollection::const_iterator j = sims.begin(); j != sims.end(); ++j) {
96  const CalorimeterHit& hit = *j;
97  sumE = sumE + hit.GetEdep();
98  }
99  _hEdep->Fill(sumE / CLHEP::GeV);
100  }
101  typedef std::vector<art::Handle<DRCalorimeterHitCollection>> DRHandleVector;
102  auto allDRSims = event.getMany<DRCalorimeterHitCollection>();
103  cout << "Event: " << event.event() << " Nr of DRCaloHit collections: " << allDRSims.size()
104  << endl;
105  for (DRHandleVector::const_iterator i = allDRSims.begin(); i != allDRSims.end(); ++i) {
106  const DRCalorimeterHitCollection& DRsims(**i);
107  cout << "DRCaloHit collection size: " << DRsims.size() << endl;
108  double sumDRE = 0.0;
109  double sumNCeren = 0.0;
110  _hnDRHits->Fill(DRsims.size());
111  for (DRCalorimeterHitCollection::const_iterator j = DRsims.begin(); j != DRsims.end(); ++j) {
112  const DRCalorimeterHit& hit = *j;
113  sumDRE = sumDRE + hit.GetEdep();
114  sumNCeren = sumNCeren + hit.GetNceren();
115  }
116  _hDREdep->Fill(sumDRE / CLHEP::GeV);
117  _hNCeren->Fill(sumNCeren);
118  }
119  typedef std::vector<art::Handle<ByParticle>> EdepHandleVector;
120  auto allEdeps = event.getMany<ByParticle>();
121 
122  for (EdepHandleVector::const_iterator i = allEdeps.begin(); i != allEdeps.end(); ++i) {
123  const ByParticle& Edeps(**i);
124  cout << "Edep collection size: " << Edeps.size() << endl;
125  for (std::map<std::string, double>::const_iterator it = Edeps.begin(); it != Edeps.end();
126  ++it) {
127  std::cout << "Particle: " << it->first << " " << it->second << " % " << std::endl;
128  }
129  }
130 
131 } // end analyze
132 
CheckHits(fhicl::ParameterSet const &p)
STL namespace.
intermediate_table::const_iterator const_iterator
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
void beginJob() override
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Detector simulation of raw signals on wires.
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
void analyze(const art::Event &event) override
Definition: MVAAlg.h:12
Event finding and building.