LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckDRCalorimeterHits_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 // CheckDRCalorimeterHits_module.cc: Analyzer module that demonstrates access to
13 // DRCalorimeter hits and makes some histograms
14 //
15 // Author: Hans Wenzel (Fermilab)
16 //===============================================================================
17 
18 #include "fhiclcpp/ParameterSet.h"
19 
27 #include "art_root_io/TFileService.h"
28 // artg4tk includes:
29 #include "artg4tk/pluginDetectors/gdml/ByParticle.hh"
30 #include "artg4tk/pluginDetectors/gdml/DRCalorimeterHit.hh"
32 
33 // Root includes.
34 #include "TH1F.h"
35 #include "TH2F.h"
36 #include "TNtuple.h"
37 
38 // Other includes.
39 #include "CLHEP/Units/SystemOfUnits.h"
40 using namespace std;
41 namespace artg4tk {
42  class CheckDRCalorimeterHits;
43 }
44 
46 public:
48  void beginJob() override;
49  void analyze(const art::Event& event) override;
50 
51 private:
52  fhicl::ParameterSet pstl; // parameterset from PhysicsListService
53  std::map<std::string, TH1F*> mapofhistos;
54  std::map<std::string, TH1F*> ncmapofhistos;
55  std::vector<TH1F*> vecofhistosthin;
56  std::vector<TH1F*> vecofhistosthick;
57  std::vector<double> edepthin;
58  std::vector<double> edepthick;
59  TH1F* _hnDRHits; // number of DRCaloHits
60  TH1F* _hDREdep; // total energy deposition in DRCaloHits
61  TH1F* _hNCeren; // total number of Cerenkovphotons in DRCaloHits
63  TNtuple* _ntuple;
64  TNtuple* _ntuple2;
65 };
66 
68  : art::EDAnalyzer(p)
69  , pstl(p.get<fhicl::ParameterSet>("pstl"))
70  , _hnDRHits(0)
71  , _hDREdep(0)
72  , _hNCeren(0)
73  , _hEdepvsNCeren(0)
74  , _ntuple(0)
75  , _ntuple2(0)
76 {}
77 
78 void
80 {
82  _hnDRHits = tfs->make<TH1F>("hnDRHits", "Number of DRCaloArtHits", 100, 0., 20000.);
83  _hDREdep = tfs->make<TH1F>("hDREdep", "total Energy deposition in DRCaloArtHits", 100, 0., 11.);
84  _hNCeren = tfs->make<TH1F>(
85  "hNCeren", "total number of Cerenkov Photons in DRCaloArtHits", 100, 0., 10000.);
86  _hEdepvsNCeren = tfs->make<TH2F>("hEdepvsNCeren", "Edep vs. NCeren", 100, 0, 11, 100, 0, 10000.);
87  _ntuple = tfs->make<TNtuple>(
88  "ntuple", "Demo ntuple", "Event:Edep0:Edep1:Edep2:Edep3:Edep4:Edep5:Edep6:Edep7:Edep8:Edep9");
89  _ntuple2 = tfs->make<TNtuple>(
90  "ntuple2",
91  "Demo ntuple",
92  "Event:Nceren0:Nceren1:Nceren2:Nceren3:Nceren4:Nceren5:Nceren6:Nceren7:Nceren8:Nceren9");
93  mapofhistos["Fragment"] = tfs->make<TH1F>("hFragment", "Fragment percentage", 100, 0., 100.);
94  mapofhistos["He3"] = tfs->make<TH1F>("hHe3", "He3 percentage", 100, 0., 100.);
95  mapofhistos["alpha"] = tfs->make<TH1F>("halpha", "alpha percentage", 100, 0., 100.);
96  mapofhistos["deuteron"] = tfs->make<TH1F>("hdeuteron", "deuteron percentage", 100, 0., 100.);
97  mapofhistos["triton"] = tfs->make<TH1F>("htriton", "triton percentage", 100, 0., 100.);
98  mapofhistos["proton"] = tfs->make<TH1F>("hproton", "proton percentage", 100, 0., 100.);
99  mapofhistos["neutron"] = tfs->make<TH1F>("hneutron", "neutron percentage", 100, 0., 100.);
100  mapofhistos["e+"] = tfs->make<TH1F>("he+", "positron percentage", 100, 0., 100.);
101  mapofhistos["e-"] = tfs->make<TH1F>("he-", "electron percentage", 100, 0., 100.);
102  mapofhistos["pi+"] = tfs->make<TH1F>("hpiplus", "piplus percentage", 100, 0., 100.);
103  mapofhistos["pi-"] = tfs->make<TH1F>("hpiminus", "piminus percentage", 100, 0., 100.);
104  mapofhistos["gamma"] = tfs->make<TH1F>("hgamma", "gamma percentage", 100, 0., 100.);
105  mapofhistos["mu+"] = tfs->make<TH1F>("hmu+", "mu+ percentage", 100, 0., 100.);
106  mapofhistos["mu-"] = tfs->make<TH1F>("hmu-", "mu- percentage", 100, 0., 100.);
107  mapofhistos["sigma+"] = tfs->make<TH1F>("hsigma+", "sigma+ percentage", 100, 0., 100.);
108  mapofhistos["sigma-"] = tfs->make<TH1F>("hsigma-", "sigma- percentage", 100, 0., 100.);
109  mapofhistos["kaon+"] = tfs->make<TH1F>("hkaon+", "kaon+ percentage", 100, 0., 100.);
110  mapofhistos["kaon-"] = tfs->make<TH1F>("hkaon-", "kaon- percentage", 100, 0., 100.);
111  mapofhistos["kaon0L"] = tfs->make<TH1F>("hkaon0L", "kaon0 percentage", 100, 0., 100.);
112  mapofhistos["kaon0S"] = tfs->make<TH1F>("hkaon0S", "Kspercentage", 100, 0., 100.);
113  mapofhistos["lambda"] = tfs->make<TH1F>("hlambda", "lambda percentage", 100, 0., 100.);
114  mapofhistos["xi-"] = tfs->make<TH1F>("hximinus", "ximinu percentage", 100, 0., 100.);
115  mapofhistos["anti_neutron"] =
116  tfs->make<TH1F>("hneutronbar", "neutronbar percentage", 100, 0., 100.);
117  mapofhistos["anti_sigma-"] =
118  tfs->make<TH1F>("hsigmaminusbar", "anti_sigma- percentage", 100, 0., 100.);
119  mapofhistos["anti_proton"] = tfs->make<TH1F>("hpar", "pbar percentage", 100, 0., 100.);
120  mapofhistos["anti_xi-"] = tfs->make<TH1F>("hantiximinus", "anti_xi-percentage", 100, 0., 100.);
121  mapofhistos["anti_omega-"] =
122  tfs->make<TH1F>("hantiomegaminus", "anti_omega- percentage", 100, 0., 100.);
123  mapofhistos["anti_sigma+"] =
124  tfs->make<TH1F>("hantisigmaplus", "anti_sigma+percentage", 100, 0., 100.);
125  mapofhistos["anti_lambda"] =
126  tfs->make<TH1F>("hlambdabar", "anti_lambda percentage", 100, 0., 100.);
127  mapofhistos["anti_xi0"] = tfs->make<TH1F>("hxi0bar", "anti_xi0 percentage", 100, 0., 100.);
128  mapofhistos["other"] =
129  tfs->make<TH1F>("hother", "other percentage", 100, 0., 100.); // Just in case
130  //
131  ncmapofhistos["deuteron"] =
132  tfs->make<TH1F>("NCeren_deuteron", "deuteronp ercentage", 100, 0., 100.);
133  ncmapofhistos["triton"] = tfs->make<TH1F>("NCeren_triton", "triton percentage", 100, 0., 100.);
134  ncmapofhistos["He3"] = tfs->make<TH1F>("NCeren_He3", "He3 percentage", 100, 0., 100.);
135  ncmapofhistos["proton"] = tfs->make<TH1F>("NCeren_proton", "proton percentage", 100, 0., 100.);
136  ncmapofhistos["e+"] = tfs->make<TH1F>("NCeren_e+", "e+ percentage", 100, 0., 100.);
137  ncmapofhistos["e-"] = tfs->make<TH1F>("NCeren_e-", "e- percentage", 100, 0., 100.);
138  ncmapofhistos["mu+"] = tfs->make<TH1F>("NCeren_mu+", "mu+ percentage", 100, 0., 100.);
139  ncmapofhistos["mu-"] = tfs->make<TH1F>("NCeren_mu-", "mu- percentage", 100, 0., 100.);
140  ncmapofhistos["pi+"] = tfs->make<TH1F>("NCeren_pi+", "pi+ percentage", 100, 0., 100.);
141  ncmapofhistos["pi-"] = tfs->make<TH1F>("NCeren_pi-", "pi- percentage", 100, 0., 100.);
142  ncmapofhistos["kaon+"] = tfs->make<TH1F>("NCeren_kaon+", "kaon+ percentage", 100, 0., 100.);
143  ncmapofhistos["kaon-"] = tfs->make<TH1F>("NCeren_kaon-", "kaon- percentage", 100, 0., 100.);
144  ncmapofhistos["sigma+"] = tfs->make<TH1F>("NCeren_sigma+", "sigma+ percentage", 100, 0., 100.);
145  ncmapofhistos["sigma-"] = tfs->make<TH1F>("NCeren_sigma-", "sigma- percentage", 100, 0., 100.);
146  ncmapofhistos["xi-"] = tfs->make<TH1F>("NCeren_xi-", "xi- percentage", 100, 0., 100.);
147  ncmapofhistos["anti_sigma+"] =
148  tfs->make<TH1F>("NCeren_anti_sigma+", "anti_sigma+ percentage", 100, 0., 100.);
149  ncmapofhistos["anti_sigma-"] =
150  tfs->make<TH1F>("NCeren_anti_sigma-", "anti_sigma- percentage", 100, 0., 100.);
151  ncmapofhistos["anti_proton"] =
152  tfs->make<TH1F>("NCeren_anti_proton", "anti_proton percentage", 100, 0., 100.);
153  ncmapofhistos["anti_xi-"] =
154  tfs->make<TH1F>("NCeren_anti_xi-", "anti_xi- percentage", 100, 0., 100.);
155  ncmapofhistos["anti_omega-"] =
156  tfs->make<TH1F>("NCeren_anti_omega-", "anti_omega- percentage", 100, 0., 100.);
157  ncmapofhistos["other"] =
158  tfs->make<TH1F>("NCeren_other", "other percentage", 100, 0., 100.); // Just in case
159  const unsigned int numz = 10;
160  for (unsigned int jj = 0; jj < numz; jj++) {
161  std::string histonamethin = "Edep_thin_lay" + std::to_string(jj);
162  std::string histonamethick = "Edep_thick_lay" + std::to_string(jj);
163  cout << histonamethin << endl;
164  cout << histonamethin.c_str() << endl;
165  vecofhistosthin.push_back(
166  tfs->make<TH1F>(histonamethin.c_str(), histonamethin.c_str(), 100, 0., 2.));
167  vecofhistosthick.push_back(
168  tfs->make<TH1F>(histonamethick.c_str(), histonamethick.c_str(), 100, 0., 2.));
169  }
170  std::cout << " artg4tk::CheckDRCalorimeterHits: The name of the used reference physics list is: "
171  << pstl.get<std::string>("PhysicsListName") << std::endl;
172 
173 } // end beginJob
174 
175 void
177 {
178  typedef std::vector<art::Handle<DRCalorimeterHitCollection>> DRHandleVector;
179  // DRHandleVector allDRSims;
180  double sumDRE = 0;
181  double sumNCeren = 0.0;
182  unsigned int numz = 10;
183  std::vector<double> edepthin;
184  std::vector<double> edepthick;
185  std::vector<double> ncerenthin;
186  std::vector<double> ncerenthick;
187  for (unsigned int ijk = 0; ijk < numz; ijk++) {
188  edepthin.push_back(0.0);
189  edepthick.push_back(0.0);
190  ncerenthin.push_back(0.0);
191  ncerenthick.push_back(0.0);
192  }
193  // event.getManyByType(allDRSims);
194  auto allDRSims = event.getMany<DRCalorimeterHitCollection>();
195  for (DRHandleVector::const_iterator i = allDRSims.begin(); i != allDRSims.end(); ++i) {
197  auto const* prov = ih.provenance();
198  string iname = prov->productInstanceName();
199  string pname = prov->processName();
200  std::cout << "iname: " << iname << std::endl;
201  std::cout << "pname: " << pname << std::endl;
202  fhicl::ParameterSet ps = prov->parameterSet();
203  std::vector<std::string> names = ps.get_names();
204 
205  for (vector<string>::iterator t = names.begin(); t != names.end(); ++t) {
206  std::cout << *t << std::endl;
207  }
208  const DRCalorimeterHitCollection& DRsims(**i);
209  _hnDRHits->Fill(DRsims.size());
210  for (DRCalorimeterHitCollection::const_iterator j = DRsims.begin(); j != DRsims.end(); ++j) {
211  const DRCalorimeterHit& hit = *j;
212  unsigned int lay = (int)(hit.GetID() / (numz * numz));
213  // unsigned int jj = (int)(((hit.GetID()-kk*(numz*numz)))/numy);
214  // unsigned int ii = (int)(hit.GetID()-kk*(numz*numz)-jj*numy);
215  // cout << "ID: "<<hit.GetID()<<" Layer: "<< kk<<" Column: " << jj<< " row: "<<
216  // ii<<endl;
217  sumDRE = sumDRE + hit.GetEdep();
218  sumNCeren = sumNCeren + hit.GetNceren();
219  if (iname.find("thin") != std::string::npos) {
220  edepthin[lay] = edepthin[lay] + hit.GetEdep();
221  ncerenthin[lay] = ncerenthin[lay] + hit.GetNceren();
222  } else {
223  edepthick[lay] = edepthick[lay] + hit.GetEdep();
224  ncerenthick[lay] = ncerenthick[lay] + hit.GetNceren();
225  }
226  }
227  }
228  _hDREdep->Fill(sumDRE / CLHEP::GeV);
229  _hNCeren->Fill(sumNCeren);
230  _hEdepvsNCeren->Fill(sumDRE / CLHEP::GeV, sumNCeren);
231  for (unsigned int ijk = 0; ijk < numz; ijk++) {
232  vecofhistosthin[ijk]->Fill(edepthin[ijk] / CLHEP::GeV);
233  vecofhistosthick[ijk]->Fill(edepthick[ijk] / CLHEP::GeV);
234  }
235  _ntuple->Fill(event.event(),
236  edepthin[0],
237  edepthin[1],
238  edepthin[2],
239  edepthin[3],
240  edepthin[4],
241  edepthin[5],
242  edepthin[6],
243  edepthin[7],
244  edepthin[8],
245  edepthin[9]);
246  _ntuple2->Fill(event.event(),
247  ncerenthin.at(0),
248  ncerenthin.at(1),
249  ncerenthin.at(2),
250  ncerenthin.at(3),
251  ncerenthin.at(4),
252  ncerenthin.at(5),
253  ncerenthin.at(6),
254  ncerenthin.at(7),
255  ncerenthin.at(8),
256  ncerenthin.at(9));
257  typedef std::vector<art::Handle<ByParticle>> EdepHandleVector;
258  // EdepHandleVector allEdeps;
259  // event.getManyByType(allEdeps);
260  auto allEdeps = event.getMany<ByParticle>();
261  bool first = true;
262  ByParticle addup;
263  ByParticle addupnc;
264  double junkie = 0.0;
265  for (EdepHandleVector::const_iterator i = allEdeps.begin(); i != allEdeps.end(); ++i) {
266  art::Handle<ByParticle> ih = *i;
267  auto const* prov = ih.provenance();
268  string instancename = prov->productInstanceName();
269 
270  if (instancename.find("NCeren") != std::string::npos) {
271  const ByParticle& Edeps(**i);
272  if (first) {
273  addupnc = Edeps;
274  junkie = Edeps.at("NCerentot");
275  first = false;
276  } else {
277  junkie = junkie + Edeps.at("NCerentot");
278  for (std::map<std::string, double>::const_iterator it = Edeps.begin(); it != Edeps.end();
279  ++it) {
280  addupnc[it->first] = addupnc[it->first] + it->second;
281  }
282  }
283  } else if (instancename.find("Edep") != std::string::npos) {
284  const ByParticle& Edeps(**i);
285  if (first) {
286  addup = Edeps;
287  junkie = Edeps.at("Etot");
288  first = false;
289  } else {
290  junkie = junkie + Edeps.at("Etot");
291  for (std::map<std::string, double>::const_iterator it = Edeps.begin(); it != Edeps.end();
292  ++it) {
293  addup[it->first] = addup[it->first] + it->second;
294  }
295  }
296  /*
297  for (std::map<std::string, double>::const_iterator it = Edeps.begin(); it != Edeps.end();
298  ++it) {
299 
300  if (mapofhistos.find(it->first) != mapofhistos.end())
301  mapofhistos[it->first]->Fill((100.*it->second)/junkie);
302  }
303  */
304  }
305  }
306  for (std::map<std::string, double>::const_iterator it = addup.begin(); it != addup.end(); ++it) {
307  if (mapofhistos.find(it->first) != mapofhistos.end())
308  mapofhistos[it->first]->Fill((100. * it->second) / junkie);
309  }
310  for (std::map<std::string, double>::const_iterator it = addupnc.begin(); it != addupnc.end();
311  ++it) {
312  if (ncmapofhistos.find(it->first) != ncmapofhistos.end())
313  ncmapofhistos[it->first]->Fill((100. * it->second) / junkie);
314  }
315 } // end analyze
316 
intermediate_table::iterator iterator
STL namespace.
intermediate_table::const_iterator const_iterator
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void beginJob()
Definition: Breakpoints.cc:14
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
Provenance const * provenance() const
Definition: Handle.h:217
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:314
EventNumber_t event() const
Definition: Event.cc:41
std::map< std::string, TH1F * > ncmapofhistos
Detector simulation of raw signals on wires.
void analyze(const art::Event &event) override
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
CheckDRCalorimeterHits(fhicl::ParameterSet const &p)
std::vector< std::string > get_names() const
Definition: MVAAlg.h:12
std::map< std::string, TH1F * > mapofhistos
Event finding and building.