All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TCShowerTemplateMaker_module.cc
Go to the documentation of this file.
1 // -------------------------------------------------
2 // makes shower profile templates
3 //
4 // Author: Rory Fitzpatrick (roryfitz@umich.edu)
5 // Created: 7/16/18
6 // -------------------------------------------------
7 
8 // Framework includes
9 #include "art/Framework/Core/EDAnalyzer.h"
10 #include "art/Framework/Core/ModuleMacros.h"
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Principal/Handle.h"
13 #include "art/Framework/Services/Registry/ServiceHandle.h"
14 #include "art_root_io/TFileService.h"
15 #include "canvas/Persistency/Common/FindManyP.h"
16 #include "fhiclcpp/ParameterSet.h"
17 
28 #include "nusimdata/SimulationBase/MCTruth.h"
29 
30 #include "TH1.h"
31 #include "TH3.h"
32 #include "TProfile.h"
33 #include "TProfile2D.h"
34 
35 namespace shower {
36 
37  class TCShowerTemplateMaker : public art::EDAnalyzer {
38  public:
39  explicit TCShowerTemplateMaker(fhicl::ParameterSet const& pset);
40 
41  private:
42  void beginJob() override;
43  void analyze(const art::Event& evt) override;
44 
45  void showerProfile(detinfo::DetectorClocksData const& clockData,
47  std::vector<art::Ptr<recob::Hit>> showerhits,
48  TVector3 shwvtx,
49  TVector3 shwdir,
50  double elep);
51  void showerProfileTrue(detinfo::DetectorClocksData const& clockData,
52  detinfo::DetectorPropertiesData const& detProp,
53  std::vector<art::Ptr<recob::Hit>> allhits,
54  double elep);
55  void showerProfileTrue(std::vector<art::Ptr<sim::SimChannel>> allchan,
56  simb::MCParticle electron);
57 
61 
65 
69 
73 
77 
81 
85 
89 
93 
95  TH3F* fTransverse;
101 
102  // electrons
109  // photons
116  // other
123 
124  const int LBINS = 20;
125  const int LMIN = 0;
126  const int LMAX = 5;
127 
128  const int TBINS = 20;
129  const int TMIN = -5;
130  const int TMAX = 5;
131 
132  const int EBINS = 20;
133  const double EMIN = 0.5;
134  const double EMAX = 20.5;
135 
136  const double X0 = 14;
137 
138  std::string fHitModuleLabel;
139  std::string fShowerModuleLabel;
140  std::string fGenieGenModuleLabel;
141  std::string fDigitModuleLabel;
142 
144 
145  }; // class TCShowerAnalysis
146 
147 } // shower
148 
149 // -------------------------------------------------
150 
152  : EDAnalyzer(pset)
153  , fHitModuleLabel(pset.get<std::string>("HitModuleLabel", "trajcluster"))
154  , fShowerModuleLabel(pset.get<std::string>("ShowerModuleLabel", "tcshower"))
155  , fGenieGenModuleLabel(pset.get<std::string>("GenieGenModuleLabel", "generator"))
156  , fDigitModuleLabel(pset.get<std::string>("DigitModuleLabel", "largeant"))
157  , fCalorimetryAlg(pset.get<fhicl::ParameterSet>("CalorimetryAlg"))
158 {} // TCShowerTemplateMaker
159 
160 // -------------------------------------------------
161 
162 void
164 {
165 
166  art::ServiceHandle<art::TFileService const> tfs;
167  fShowerProfileSimLong =
168  tfs->make<TProfile>("fShowerProfileSimLong",
169  "longitudinal e- profile (true, simchannel);t;E (MeV)",
170  LBINS,
171  LMIN,
172  LMAX);
173  fShowerProfileHitLong = tfs->make<TProfile>(
174  "fShowerProfileHitLong", "longitudinal e- profile (true, hit);t;E (MeV)", LBINS, LMIN, LMAX);
175  fShowerProfileRecoLong = tfs->make<TProfile>(
176  "fShowerProfileRecoLong", "longitudinal e- profile (reco);t;Q", LBINS, LMIN, LMAX);
177 
178  fShowerProfileSimLong2D = tfs->make<TProfile2D>(
179  "fShowerProfileSimLong2D",
180  "longitudinal e- profile (true, simchannel);t;electron energy (MeV);E (MeV)",
181  LBINS,
182  LMIN,
183  LMAX,
184  EBINS,
185  EMIN,
186  EMAX);
187  fShowerProfileHitLong2D =
188  tfs->make<TProfile2D>("fShowerProfileHitLong2D",
189  "longitudinal e- profile (true, hit);t;electron energy (MeV);E (MeV)",
190  LBINS,
191  LMIN,
192  LMAX,
193  EBINS,
194  EMIN,
195  EMAX);
196  fShowerProfileRecoLong2D =
197  tfs->make<TProfile2D>("fShowerProfileRecoLong2D",
198  "longitudinal e- profile (reco);t;electron energy (MeV);Q",
199  LBINS,
200  LMIN,
201  LMAX,
202  EBINS,
203  EMIN,
204  EMAX);
205 
206  fShowerProfileSimTrans =
207  tfs->make<TProfile>("fShowerProfileSimTrans",
208  "transverse e- profile (true, simchannel);dist (cm);E (MeV)",
209  TBINS,
210  TMIN,
211  TMAX);
212  fShowerProfileHitTrans =
213  tfs->make<TProfile>("fShowerProfileHitTrans",
214  "transverse e- profile (true, hit);dist (cm);E (MeV)",
215  TBINS,
216  TMIN,
217  TMAX);
218  fShowerProfileRecoTrans = tfs->make<TProfile>(
219  "fShowerProfileRecoTrans", "transverse e- profile (reco);dist (cm);Q", TBINS, TMIN, TMAX);
220 
221  fShowerProfileSimTrans2D = tfs->make<TProfile2D>(
222  "fShowerProfileSimTrans2D",
223  "transverse e- profile (true, simchannel);t;electron energy (MeV);E (MeV)",
224  TBINS,
225  TMIN,
226  TMAX,
227  EBINS,
228  EMIN,
229  EMAX);
230  fShowerProfileHitTrans2D =
231  tfs->make<TProfile2D>("fShowerProfileHitTrans2D",
232  "transverse e- profile (true, hit);t;electron energy (MeV);E (MeV)",
233  TBINS,
234  TMIN,
235  TMAX,
236  EBINS,
237  EMIN,
238  EMAX);
239  fShowerProfileRecoTrans2D =
240  tfs->make<TProfile2D>("fShowerProfileRecoTrans2D",
241  "transverse e- profile (reco);t;electron energy (MeV);Q",
242  TBINS,
243  TMIN,
244  TMAX,
245  EBINS,
246  EMIN,
247  EMAX);
248 
249  fShowerProfileSimTrans2D_1 = tfs->make<TProfile2D>(
250  "fShowerProfileSimTrans2D_1",
251  "transverse e- profile [0 <= t < 1] (true, simchannel);t;electron energy (MeV);E (MeV)",
252  TBINS,
253  TMIN,
254  TMAX,
255  EBINS,
256  EMIN,
257  EMAX);
258  fShowerProfileHitTrans2D_1 = tfs->make<TProfile2D>(
259  "fShowerProfileHitTrans2D_1",
260  "transverse e- profile [0 <= t < 1] (true, hit);t;electron energy (MeV);E (MeV)",
261  TBINS,
262  TMIN,
263  TMAX,
264  EBINS,
265  EMIN,
266  EMAX);
267  fShowerProfileRecoTrans2D_1 =
268  tfs->make<TProfile2D>("fShowerProfileRecoTrans2D_1",
269  "transverse e- profile [0 <= t < 1] (reco);t;electron energy (MeV);Q",
270  TBINS,
271  TMIN,
272  TMAX,
273  EBINS,
274  EMIN,
275  EMAX);
276 
277  fShowerProfileSimTrans2D_2 = tfs->make<TProfile2D>(
278  "fShowerProfileSimTrans2D_2",
279  "transverse e- profile [1 <= t < 2] (true, simchannel);t;electron energy (MeV);E (MeV)",
280  TBINS,
281  TMIN,
282  TMAX,
283  EBINS,
284  EMIN,
285  EMAX);
286  fShowerProfileHitTrans2D_2 = tfs->make<TProfile2D>(
287  "fShowerProfileHitTrans2D_2",
288  "transverse e- profile [1 <= t < 2] (true, hit);t;electron energy (MeV);E (MeV)",
289  TBINS,
290  TMIN,
291  TMAX,
292  EBINS,
293  EMIN,
294  EMAX);
295  fShowerProfileRecoTrans2D_2 =
296  tfs->make<TProfile2D>("fShowerProfileRecoTrans2D_2",
297  "transverse e- profile [1 <= t < 2] (reco);t;electron energy (MeV);Q",
298  TBINS,
299  TMIN,
300  TMAX,
301  EBINS,
302  EMIN,
303  EMAX);
304 
305  fShowerProfileSimTrans2D_3 = tfs->make<TProfile2D>(
306  "fShowerProfileSimTrans2D_3",
307  "transverse e- profile [2 <= t < 3] (true, simchannel);t;electron energy (MeV);E (MeV)",
308  TBINS,
309  TMIN,
310  TMAX,
311  EBINS,
312  EMIN,
313  EMAX);
314  fShowerProfileHitTrans2D_3 = tfs->make<TProfile2D>(
315  "fShowerProfileHitTrans2D_3",
316  "transverse e- profile [2 <= t < 3] (true, hit);t;electron energy (MeV);E (MeV)",
317  TBINS,
318  TMIN,
319  TMAX,
320  EBINS,
321  EMIN,
322  EMAX);
323  fShowerProfileRecoTrans2D_3 =
324  tfs->make<TProfile2D>("fShowerProfileRecoTrans2D_3",
325  "transverse e- profile [2 <= t < 3] (reco);t;electron energy (MeV);Q",
326  TBINS,
327  TMIN,
328  TMAX,
329  EBINS,
330  EMIN,
331  EMAX);
332 
333  fShowerProfileSimTrans2D_4 = tfs->make<TProfile2D>(
334  "fShowerProfileSimTrans2D_4",
335  "transverse e- profile [3 <= t < 4] (true, simchannel);t;electron energy (MeV);E (MeV)",
336  TBINS,
337  TMIN,
338  TMAX,
339  EBINS,
340  EMIN,
341  EMAX);
342  fShowerProfileHitTrans2D_4 = tfs->make<TProfile2D>(
343  "fShowerProfileHitTrans2D_4",
344  "transverse e- profile [3 <= t < 4] (true, hit);t;electron energy (MeV);E (MeV)",
345  TBINS,
346  TMIN,
347  TMAX,
348  EBINS,
349  EMIN,
350  EMAX);
351  fShowerProfileRecoTrans2D_4 =
352  tfs->make<TProfile2D>("fShowerProfileRecoTrans2D_4",
353  "transverse e- profile [3 <= t < 4] (reco);t;electron energy (MeV);Q",
354  TBINS,
355  TMIN,
356  TMAX,
357  EBINS,
358  EMIN,
359  EMAX);
360 
361  fShowerProfileSimTrans2D_5 = tfs->make<TProfile2D>(
362  "fShowerProfileSimTrans2D_5",
363  "transverse e- profile [4 <= t < 5] (true, simchannel);t;electron energy (MeV);E (MeV)",
364  TBINS,
365  TMIN,
366  TMAX,
367  EBINS,
368  EMIN,
369  EMAX);
370  fShowerProfileHitTrans2D_5 = tfs->make<TProfile2D>(
371  "fShowerProfileHitTrans2D_5",
372  "transverse e- profile [4 <= t < 5] (true, hit);t;electron energy (MeV);E (MeV)",
373  TBINS,
374  TMIN,
375  TMAX,
376  EBINS,
377  EMIN,
378  EMAX);
379  fShowerProfileRecoTrans2D_5 =
380  tfs->make<TProfile2D>("fShowerProfileRecoTrans2D_5",
381  "transverse e- profile [4 <= t < 5] (reco);t;electron energy (MeV);Q",
382  TBINS,
383  TMIN,
384  TMAX,
385  EBINS,
386  EMIN,
387  EMAX);
388 
389  fLongitudinal = tfs->make<TH3F>("fLongitudinal",
390  "longitudinal e- profile;t;electron energy (MeV);Q",
391  LBINS,
392  LMIN,
393  LMAX,
394  EBINS,
395  EMIN,
396  EMAX,
397  100,
398  0,
399  150000);
400  fTransverse = tfs->make<TH3F>("fTransverse",
401  "transverse e- profile;dist (cm);electron energy (MeV);Q",
402  TBINS,
403  TMIN,
404  TMAX,
405  EBINS,
406  EMIN,
407  EMAX,
408  100,
409  0,
410  150000);
411  fTransverse_1 =
412  tfs->make<TH3F>("fTransverse_1",
413  "transverse e- profile [0 <= t < 1];dist (cm);electron energy (MeV);Q",
414  TBINS,
415  TMIN,
416  TMAX,
417  EBINS,
418  EMIN,
419  EMAX,
420  100,
421  0,
422  100000);
423  fTransverse_2 =
424  tfs->make<TH3F>("fTransverse_2",
425  "transverse e- profile [1 <= t < 2];dist (cm);electron energy (MeV);Q",
426  TBINS,
427  TMIN,
428  TMAX,
429  EBINS,
430  EMIN,
431  EMAX,
432  100,
433  0,
434  100000);
435  fTransverse_3 =
436  tfs->make<TH3F>("fTransverse_3",
437  "transverse e- profile [2 <= t < 3];dist (cm);electron energy (MeV);Q",
438  TBINS,
439  TMIN,
440  TMAX,
441  EBINS,
442  EMIN,
443  EMAX,
444  100,
445  0,
446  100000);
447  fTransverse_4 =
448  tfs->make<TH3F>("fTransverse_4",
449  "transverse e- profile [3 <= t < 4];dist (cm);electron energy (MeV);Q",
450  TBINS,
451  TMIN,
452  TMAX,
453  EBINS,
454  EMIN,
455  EMAX,
456  100,
457  0,
458  100000);
459  fTransverse_5 =
460  tfs->make<TH3F>("fTransverse_5",
461  "transverse e- profile [4 <= t < 5];dist (cm);electron energy (MeV);Q",
462  TBINS,
463  TMIN,
464  TMAX,
465  EBINS,
466  EMIN,
467  EMAX,
468  100,
469  0,
470  100000);
471 
472  // electrons
473  fLongitudinal_electron = tfs->make<TProfile>(
474  "fLongitudinal_electron", "longitudinal e- profile (reco);t;Q", LBINS, LMIN, LMAX);
475  fTransverse1_electron =
476  tfs->make<TProfile>("fTransverse1_electron",
477  "transverse e- profile [0 <= t < 1] (reco);dist (cm);Q",
478  TBINS,
479  TMIN,
480  TMAX);
481  fTransverse2_electron =
482  tfs->make<TProfile>("fTransverse2_electron",
483  "transverse e- profile [1 <= t < 2] (reco);dist (cm);Q",
484  TBINS,
485  TMIN,
486  TMAX);
487  fTransverse3_electron =
488  tfs->make<TProfile>("fTransverse3_electron",
489  "transverse e- profile [2 <= t < 3] (reco);dist (cm);Q",
490  TBINS,
491  TMIN,
492  TMAX);
493  fTransverse4_electron =
494  tfs->make<TProfile>("fTransverse4_electron",
495  "transverse e- profile [3 <= t < 4] (reco);dist (cm);Q",
496  TBINS,
497  TMIN,
498  TMAX);
499  fTransverse5_electron =
500  tfs->make<TProfile>("fTransverse5_electron",
501  "transverse e- profile [4 <= t < 5] (reco);dist (cm);Q",
502  TBINS,
503  TMIN,
504  TMAX);
505 
506  // photons
507  fLongitudinal_photon = tfs->make<TProfile>(
508  "fLongitudinal_photon", "longitudinal photon profile (reco);t;Q", LBINS, LMIN, LMAX);
509  fTransverse1_photon =
510  tfs->make<TProfile>("fTransverse1_photon",
511  "transverse photon profile [0 <= t < 1] (reco);dist (cm);Q",
512  TBINS,
513  TMIN,
514  TMAX);
515  fTransverse2_photon =
516  tfs->make<TProfile>("fTransverse2_photon",
517  "transverse photon profile [1 <= t < 2] (reco);dist (cm);Q",
518  TBINS,
519  TMIN,
520  TMAX);
521  fTransverse3_photon =
522  tfs->make<TProfile>("fTransverse3_photon",
523  "transverse photon profile [2 <= t < 3] (reco);dist (cm);Q",
524  TBINS,
525  TMIN,
526  TMAX);
527  fTransverse4_photon =
528  tfs->make<TProfile>("fTransverse4_photon",
529  "transverse photon profile [3 <= t < 4] (reco);dist (cm);Q",
530  TBINS,
531  TMIN,
532  TMAX);
533  fTransverse5_photon =
534  tfs->make<TProfile>("fTransverse5_photon",
535  "transverse photon profile [4 <= t < 5] (reco);dist (cm);Q",
536  TBINS,
537  TMIN,
538  TMAX);
539 
540  // other
541  fLongitudinal_other = tfs->make<TProfile>(
542  "fLongitudinal_other", "longitudinal other profile (reco);t;Q", LBINS, LMIN, LMAX);
543  fTransverse1_other =
544  tfs->make<TProfile>("fTransverse1_other",
545  "transverse other profile [0 <= t < 1] (reco);dist (cm);Q",
546  TBINS,
547  TMIN,
548  TMAX);
549  fTransverse2_other =
550  tfs->make<TProfile>("fTransverse2_other",
551  "transverse other profile [1 <= t < 2] (reco);dist (cm);Q",
552  TBINS,
553  TMIN,
554  TMAX);
555  fTransverse3_other =
556  tfs->make<TProfile>("fTransverse3_other",
557  "transverse other profile [2 <= t < 3] (reco);dist (cm);Q",
558  TBINS,
559  TMIN,
560  TMAX);
561  fTransverse4_other =
562  tfs->make<TProfile>("fTransverse4_other",
563  "transverse other profile [3 <= t < 4] (reco);dist (cm);Q",
564  TBINS,
565  TMIN,
566  TMAX);
567  fTransverse5_other =
568  tfs->make<TProfile>("fTransverse5_other",
569  "transverse other profile [4 <= t < 5] (reco);dist (cm);Q",
570  TBINS,
571  TMIN,
572  TMAX);
573 
574 } // beginJob
575 
576 // -------------------------------------------------
577 
578 void
580 {
581 
582  art::Handle<std::vector<recob::Hit>> hitListHandle;
583  std::vector<art::Ptr<recob::Hit>> hitlist;
584  if (evt.getByLabel(fHitModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
585 
586  art::Handle<std::vector<sim::SimChannel>> scListHandle;
587  std::vector<art::Ptr<sim::SimChannel>> simchanlist;
588  if (evt.getByLabel(fDigitModuleLabel, scListHandle))
589  art::fill_ptr_vector(simchanlist, scListHandle);
590 
591  art::Handle<std::vector<recob::Shower>> showerListHandle;
592  std::vector<art::Ptr<recob::Shower>> showerlist;
593  if (evt.getByLabel(fShowerModuleLabel, showerListHandle))
594  art::fill_ptr_vector(showerlist, showerListHandle);
595 
596  art::Handle<std::vector<simb::MCTruth>> mctruthListHandle;
597  std::vector<art::Ptr<simb::MCTruth>> mclist;
598  if (evt.getByLabel(fGenieGenModuleLabel, mctruthListHandle))
599  art::fill_ptr_vector(mclist, mctruthListHandle);
600 
601  art::FindManyP<recob::Hit> shwfm(showerListHandle, evt, fShowerModuleLabel);
602 
603  if (empty(mclist)) return;
604 
605  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
606  auto const det_prop =
607  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clock_data);
608 
609  art::Ptr<simb::MCTruth> mctruth = mclist[0];
610  if (mctruth->NeutrinoSet()) {
611  if (std::abs(mctruth->GetNeutrino().Nu().PdgCode()) == 12 &&
612  mctruth->GetNeutrino().CCNC() == 0) {
613  double elep = mctruth->GetNeutrino().Lepton().E();
614  if (showerlist.size()) {
615  std::vector<art::Ptr<recob::Hit>> showerhits = shwfm.at(0);
616  showerProfile(clock_data,
617  det_prop,
618  showerhits,
619  showerlist[0]->ShowerStart(),
620  showerlist[0]->Direction(),
621  elep);
622  }
623  showerProfileTrue(clock_data, det_prop, hitlist, elep);
624  showerProfileTrue(simchanlist, mctruth->GetNeutrino().Lepton());
625  }
626  }
627 } // analyze
628 
629 // -------------------------------------------------
630 
631 void
634  std::vector<art::Ptr<recob::Hit>> showerhits,
635  TVector3 shwvtx,
636  TVector3 shwdir,
637  double elep)
638 {
639  art::ServiceHandle<geo::Geometry const> geom;
640 
641  auto collectionPlane = geo::PlaneID(0, 0, 1);
642 
643  double shwVtxTime = detProp.ConvertXToTicks(shwvtx[0], collectionPlane);
644  double shwVtxWire = geom->WireCoordinate(shwvtx[1], shwvtx[2], collectionPlane);
645 
646  double shwTwoTime = detProp.ConvertXToTicks(shwvtx[0] + shwdir[0], collectionPlane);
647  double shwTwoWire =
648  geom->WireCoordinate(shwvtx[1] + shwdir[1], shwvtx[2] + shwdir[2], collectionPlane);
649 
650  TH1F* ltemp = new TH1F("ltemp", "ltemp", LBINS, LMIN, LMAX);
651  TH1F* ttemp = new TH1F("ttemp", "ttemp", TBINS, TMIN, TMAX);
652 
653  TH1F* ttemp_1 = new TH1F("ttemp_1", "ttemp_1", TBINS, TMIN, TMAX);
654  TH1F* ttemp_2 = new TH1F("ttemp_2", "ttemp_2", TBINS, TMIN, TMAX);
655  TH1F* ttemp_3 = new TH1F("ttemp_3", "ttemp_3", TBINS, TMIN, TMAX);
656  TH1F* ttemp_4 = new TH1F("ttemp_4", "ttemp_4", TBINS, TMIN, TMAX);
657  TH1F* ttemp_5 = new TH1F("ttemp_5", "ttemp_5", TBINS, TMIN, TMAX);
658 
659  for (size_t i = 0; i < showerhits.size(); ++i) {
660  if (showerhits[i]->WireID().Plane != collectionPlane.Plane) continue;
661 
662  double wirePitch = geom->WirePitch(showerhits[i]->WireID());
663  double tickToDist = detProp.DriftVelocity(detProp.Efield(), detProp.Temperature());
664  tickToDist *= 1.e-3 * sampling_rate(clockData); // 1e-3 is conversion of 1/us to 1/ns
665 
666  double xvtx = shwVtxTime * tickToDist;
667  double yvtx = shwVtxWire * wirePitch;
668 
669  double xtwo = shwTwoTime * tickToDist;
670  double ytwo = shwTwoWire * wirePitch;
671 
672  double xtwoorth = (ytwo - yvtx) + xvtx;
673  double ytwoorth = -(xtwo - xvtx) + yvtx;
674 
675  double xhit = showerhits[i]->PeakTime() * tickToDist;
676  double yhit = showerhits[i]->WireID().Wire * wirePitch;
677 
678  double ldist = std::abs((ytwoorth - yvtx) * xhit - (xtwoorth - xvtx) * yhit + xtwoorth * yvtx -
679  ytwoorth * xvtx) /
680  std::hypot(ytwoorth - yvtx, xtwoorth - xvtx);
681  double tdist = ((ytwo - yvtx) * xhit - (xtwo - xvtx) * yhit + xtwo * yvtx - ytwo * xvtx) /
682  std::hypot(ytwo - yvtx, xtwo - xvtx);
683 
684  double to3D = 1. / std::hypot(xvtx - xtwo,
685  yvtx - ytwo); // distance between two points in 3D space is one
686  ldist *= to3D;
687  tdist *= to3D;
688  double t = ldist / X0;
689 
690  double Q = showerhits[i]->Integral() *
691  fCalorimetryAlg.LifetimeCorrection(clockData, detProp, showerhits[i]->PeakTime());
692 
693  ltemp->Fill(t, Q);
694  ttemp->Fill(tdist, Q);
695 
696  if (t < 1)
697  ttemp_1->Fill(tdist, Q);
698  else if (t < 2)
699  ttemp_2->Fill(tdist, Q);
700  else if (t < 3)
701  ttemp_3->Fill(tdist, Q);
702  else if (t < 4)
703  ttemp_4->Fill(tdist, Q);
704  else if (t < 5)
705  ttemp_5->Fill(tdist, Q);
706 
707  } // loop through showerhits
708 
709  for (int i = 0; i < LBINS; ++i) {
710  if (ltemp->GetBinContent(i + 1) == 0) continue;
711  fShowerProfileRecoLong->Fill(ltemp->GetBinCenter(i + 1), ltemp->GetBinContent(i + 1));
712  fShowerProfileRecoLong2D->Fill(ltemp->GetBinCenter(i + 1), elep, ltemp->GetBinContent(i + 1));
713  fLongitudinal->Fill(ltemp->GetBinCenter(i + 1), elep, ltemp->GetBinContent(i + 1));
714  }
715 
716  for (int i = 0; i < TBINS; ++i) {
717  if (ttemp->GetBinContent(i + 1) == 0) continue;
718  fShowerProfileRecoTrans->Fill(ttemp->GetBinCenter(i + 1), ttemp->GetBinContent(i + 1));
719  fShowerProfileRecoTrans2D->Fill(ttemp->GetBinCenter(i + 1), elep, ttemp->GetBinContent(i + 1));
720  fTransverse->Fill(ttemp->GetBinCenter(i + 1), elep, ttemp->GetBinContent(i + 1));
721 
722  fShowerProfileRecoTrans2D_1->Fill(
723  ttemp_1->GetBinCenter(i + 1), elep, ttemp_1->GetBinContent(i + 1));
724  fShowerProfileRecoTrans2D_2->Fill(
725  ttemp_2->GetBinCenter(i + 1), elep, ttemp_2->GetBinContent(i + 1));
726  fShowerProfileRecoTrans2D_3->Fill(
727  ttemp_3->GetBinCenter(i + 1), elep, ttemp_3->GetBinContent(i + 1));
728  fShowerProfileRecoTrans2D_4->Fill(
729  ttemp_4->GetBinCenter(i + 1), elep, ttemp_4->GetBinContent(i + 1));
730  fShowerProfileRecoTrans2D_5->Fill(
731  ttemp_5->GetBinCenter(i + 1), elep, ttemp_5->GetBinContent(i + 1));
732 
733  fTransverse_1->Fill(ttemp_1->GetBinCenter(i + 1), elep, ttemp_1->GetBinContent(i + 1));
734  fTransverse_2->Fill(ttemp_2->GetBinCenter(i + 1), elep, ttemp_2->GetBinContent(i + 1));
735  fTransverse_3->Fill(ttemp_3->GetBinCenter(i + 1), elep, ttemp_3->GetBinContent(i + 1));
736  fTransverse_4->Fill(ttemp_4->GetBinCenter(i + 1), elep, ttemp_4->GetBinContent(i + 1));
737  fTransverse_5->Fill(ttemp_5->GetBinCenter(i + 1), elep, ttemp_5->GetBinContent(i + 1));
738  }
739 } // showerProfile
740 
741 // -------------------------------------------------
742 
743 void
746  std::vector<art::Ptr<recob::Hit>> allhits,
747  double elep)
748 {
749  art::ServiceHandle<geo::Geometry const> geom;
750  auto collectionPlane = geo::PlaneID(0, 0, 1);
751  art::ServiceHandle<cheat::BackTrackerService const> btserv;
752  art::ServiceHandle<cheat::ParticleInventoryService const> piserv;
753  std::map<int, double> trkID_E;
754 
755  TH1F* ltemp = new TH1F("ltemp", "ltemp", LBINS, LMIN, LMAX);
756  TH1F* ttemp = new TH1F("ttemp", "ttemp", TBINS, TMIN, TMAX);
757 
758  TH1F* ttemp_1 = new TH1F("ttemp_1", "ttemp_1", TBINS, TMIN, TMAX);
759  TH1F* ttemp_2 = new TH1F("ttemp_2", "ttemp_2", TBINS, TMIN, TMAX);
760  TH1F* ttemp_3 = new TH1F("ttemp_3", "ttemp_3", TBINS, TMIN, TMAX);
761  TH1F* ttemp_4 = new TH1F("ttemp_4", "ttemp_4", TBINS, TMIN, TMAX);
762  TH1F* ttemp_5 = new TH1F("ttemp_5", "ttemp_5", TBINS, TMIN, TMAX);
763 
764  double xvtx = -999;
765  double yvtx = -999;
766  double zvtx = -999;
767  double xtwo = -999;
768  double ytwo = -999;
769  double ztwo = -999;
770  double shwvtxT = -999;
771  double shwvtxW = -999;
772  double shwtwoT = -999;
773  double shwtwoW = -999;
774 
775  double shwvtxx = -999;
776  double shwvtxy = -999;
777  double shwtwox = -999;
778  double shwtwoy = -999;
779  double xtwoorth = -999;
780  double ytwoorth = -999;
781 
782  double wirePitch = -999;
783  double tickToDist = -999;
784 
785  bool foundParent = false;
786 
787  for (auto const& hit : allhits) {
788  if (hit->WireID().Plane != collectionPlane.Plane) continue;
789 
790  // art::Ptr<recob::Hit> hit = allhits[i];
791  std::vector<sim::TrackIDE> trackIDs = btserv->HitToEveTrackIDEs(clockData, hit);
792 
793  for (size_t j = 0; j < trackIDs.size(); ++j) {
794  // only want energy associated with the electron and electron must have neutrino mother
795  if (std::abs((piserv->TrackIdToParticle_P(trackIDs[j].trackID))->PdgCode()) != 11) continue;
796  if (std::abs((piserv->TrackIdToParticle_P(trackIDs[j].trackID))->Mother()) != 0) continue;
797 
798  if (!foundParent) {
799  xvtx = (piserv->TrackIdToParticle_P(trackIDs[j].trackID))->Vx();
800  yvtx = (piserv->TrackIdToParticle_P(trackIDs[j].trackID))->Vy();
801  zvtx = (piserv->TrackIdToParticle_P(trackIDs[j].trackID))->Vz();
802 
803  xtwo = xvtx + (piserv->TrackIdToParticle_P(trackIDs[j].trackID))->Px();
804  ytwo = yvtx + (piserv->TrackIdToParticle_P(trackIDs[j].trackID))->Py();
805  ztwo = zvtx + (piserv->TrackIdToParticle_P(trackIDs[j].trackID))->Pz();
806 
807  shwvtxT = detProp.ConvertXToTicks(xvtx, collectionPlane);
808  shwvtxW = geom->WireCoordinate(yvtx, zvtx, collectionPlane);
809 
810  shwtwoT = detProp.ConvertXToTicks(xtwo, collectionPlane);
811  shwtwoW = geom->WireCoordinate(ytwo, ztwo, collectionPlane);
812 
813  wirePitch = geom->WirePitch(hit->WireID());
814  tickToDist = detProp.DriftVelocity(detProp.Efield(), detProp.Temperature());
815  tickToDist *= 1.e-3 * sampling_rate(clockData); // 1e-3 is conversion of 1/us to 1/ns
816 
817  shwvtxx = shwvtxT * tickToDist;
818  shwvtxy = shwvtxW * wirePitch;
819 
820  shwtwox = shwtwoT * tickToDist;
821  shwtwoy = shwtwoW * wirePitch;
822 
823  xtwoorth = (shwtwoy - shwvtxy) + shwvtxx;
824  ytwoorth = -(shwtwox - shwvtxx) + shwvtxy;
825 
826  foundParent = true;
827  }
828  double xhit = hit->PeakTime() * tickToDist;
829  double yhit = hit->WireID().Wire * wirePitch;
830 
831  double ldist = abs((ytwoorth - shwvtxy) * xhit - (xtwoorth - shwvtxx) * yhit +
832  xtwoorth * shwvtxy - ytwoorth * shwvtxx) /
833  std::hypot(ytwoorth - shwvtxy, xtwoorth - shwvtxx);
834  double tdist = ((shwtwoy - shwvtxy) * xhit - (shwtwox - shwvtxx) * yhit + shwtwox * shwvtxy -
835  shwtwoy * shwvtxx) /
836  std::hypot(shwtwoy - shwvtxy, shwtwox - shwvtxx);
837 
838  double to3D = std::hypot(xvtx - xtwo, yvtx - ytwo, zvtx - ztwo) /
839  std::hypot(shwvtxx - shwtwox,
840  shwvtxy - shwtwoy); // distance between two points in 3D space is one
841  ldist *= to3D;
842  tdist *= to3D;
843  double t = ldist / X0;
844 
845  double energy = trackIDs[j].energy;
846 
847  ltemp->Fill(t, energy);
848  ttemp->Fill(tdist, energy);
849 
850  if (t < 1)
851  ttemp_1->Fill(tdist, energy);
852  else if (t < 2)
853  ttemp_2->Fill(tdist, energy);
854  else if (t < 3)
855  ttemp_3->Fill(tdist, energy);
856  else if (t < 4)
857  ttemp_4->Fill(tdist, energy);
858  else if (t < 5)
859  ttemp_5->Fill(tdist, energy);
860 
861  } // loop through track IDE
862 
863  } // loop through all hits
864 
865  for (int i = 0; i < LBINS; ++i) {
866  if (ltemp->GetBinContent(i + 1) == 0) continue;
867  fShowerProfileHitLong->Fill(ltemp->GetBinCenter(i + 1), ltemp->GetBinContent(i + 1));
868  fShowerProfileHitLong2D->Fill(ltemp->GetBinCenter(i + 1), elep, ltemp->GetBinContent(i + 1));
869  }
870 
871  for (int i = 0; i < TBINS; ++i) {
872  if (ttemp->GetBinContent(i + 1) == 0) continue;
873  fShowerProfileHitTrans->Fill(ttemp->GetBinCenter(i + 1), ttemp->GetBinContent(i + 1));
874  fShowerProfileHitTrans2D->Fill(ttemp->GetBinCenter(i + 1), elep, ttemp->GetBinContent(i + 1));
875 
876  fShowerProfileHitTrans2D_1->Fill(
877  ttemp_1->GetBinCenter(i + 1), elep, ttemp_1->GetBinContent(i + 1));
878  fShowerProfileHitTrans2D_2->Fill(
879  ttemp_2->GetBinCenter(i + 1), elep, ttemp_2->GetBinContent(i + 1));
880  fShowerProfileHitTrans2D_3->Fill(
881  ttemp_3->GetBinCenter(i + 1), elep, ttemp_3->GetBinContent(i + 1));
882  fShowerProfileHitTrans2D_4->Fill(
883  ttemp_4->GetBinCenter(i + 1), elep, ttemp_4->GetBinContent(i + 1));
884  fShowerProfileHitTrans2D_5->Fill(
885  ttemp_5->GetBinCenter(i + 1), elep, ttemp_5->GetBinContent(i + 1));
886  }
887 } // showerProfileTrue
888 
889 // -------------------------------------------------
890 
891 void
893  simb::MCParticle electron)
894 {
895  art::ServiceHandle<cheat::ParticleInventoryService const> piserv;
896  art::ServiceHandle<geo::Geometry const> geom;
897 
898  std::vector<sim::MCEnDep> alledep;
899 
900  TH1F* ltemp = new TH1F("ltemp", "ltemp", LBINS, LMIN, LMAX);
901  TH1F* ttemp = new TH1F("ttemp", "ttemp", TBINS, TMIN, TMAX);
902 
903  TH1F* ttemp_1 = new TH1F("ttemp_1", "ttemp_1", TBINS, TMIN, TMAX);
904  TH1F* ttemp_2 = new TH1F("ttemp_2", "ttemp_2", TBINS, TMIN, TMAX);
905  TH1F* ttemp_3 = new TH1F("ttemp_3", "ttemp_3", TBINS, TMIN, TMAX);
906  TH1F* ttemp_4 = new TH1F("ttemp_4", "ttemp_4", TBINS, TMIN, TMAX);
907  TH1F* ttemp_5 = new TH1F("ttemp_5", "ttemp_5", TBINS, TMIN, TMAX);
908 
909  // get electron energy depositions
910  for (size_t i = 0; i < allchan.size(); ++i) {
911  art::Ptr<sim::SimChannel> simchan = allchan[i];
912  if (geom->View(simchan->Channel()) != geo::kV) continue;
913  auto tdc_ide_map = simchan->TDCIDEMap();
914 
915  for (auto const& tdc_ide_pair : tdc_ide_map) {
916  for (auto const& ide : tdc_ide_pair.second) {
917  if (piserv->TrackIdToMotherParticle_P(ide.trackID) == NULL) continue;
918  if (std::abs(piserv->TrackIdToMotherParticle_P(ide.trackID)->PdgCode()) != 11) continue;
919 
920  sim::MCEnDep edep;
921  edep.SetVertex(ide.x, ide.y, ide.z);
922  edep.SetEnergy(ide.energy);
923  edep.SetTrackId(ide.trackID);
924 
925  alledep.push_back(edep);
926 
927  } // loop through ide
928  } // loop through tdc_ide
929 
930  } // loop through channels
931 
932  double x0 = electron.Vx();
933  double y0 = electron.Vy();
934  double z0 = electron.Vz();
935 
936  double x2 = electron.Px();
937  double y2 = electron.Py();
938  double z2 = electron.Pz();
939 
940  TVector3 v0(x2, y2, z2);
941  v0 = v0.Unit();
942 
943  for (size_t i = 0; i < alledep.size(); ++i) {
944  double x = (double)alledep[i].Vertex()[0];
945  double y = (double)alledep[i].Vertex()[1];
946  double z = (double)alledep[i].Vertex()[2];
947 
948  TVector3 v1(x - x0, y - y0, z - z0);
949 
950  double ldist = v0.Dot(v1);
951  double t = ldist / X0;
952  double tdist = (v0.Orthogonal()).Dot(v1);
953 
954  double energy = alledep[i].Energy();
955 
956  ltemp->Fill(t, energy);
957  ttemp->Fill(tdist, energy);
958 
959  if (t < 1)
960  ttemp_1->Fill(tdist, energy);
961  else if (t < 2)
962  ttemp_2->Fill(tdist, energy);
963  else if (t < 3)
964  ttemp_3->Fill(tdist, energy);
965  else if (t < 4)
966  ttemp_4->Fill(tdist, energy);
967  else if (t < 5)
968  ttemp_5->Fill(tdist, energy);
969  }
970 
971  for (int i = 0; i < LBINS; ++i) {
972  if (ltemp->GetBinContent(i + 1) == 0) continue;
973  fShowerProfileSimLong->Fill(ltemp->GetBinCenter(i + 1), ltemp->GetBinContent(i + 1));
974  fShowerProfileSimLong2D->Fill(
975  ltemp->GetBinCenter(i + 1), electron.E(), ltemp->GetBinContent(i + 1));
976  }
977 
978  for (int i = 0; i < TBINS; ++i) {
979  if (ttemp->GetBinContent(i + 1) == 0) continue;
980  fShowerProfileSimTrans->Fill(ttemp->GetBinCenter(i + 1), ttemp->GetBinContent(i + 1));
981  fShowerProfileSimTrans2D->Fill(
982  ttemp->GetBinCenter(i + 1), electron.E(), ttemp->GetBinContent(i + 1));
983 
984  fShowerProfileSimTrans2D_1->Fill(
985  ttemp_1->GetBinCenter(i + 1), electron.E(), ttemp_1->GetBinContent(i + 1));
986  fShowerProfileSimTrans2D_2->Fill(
987  ttemp_2->GetBinCenter(i + 1), electron.E(), ttemp_2->GetBinContent(i + 1));
988  fShowerProfileSimTrans2D_3->Fill(
989  ttemp_3->GetBinCenter(i + 1), electron.E(), ttemp_3->GetBinContent(i + 1));
990  fShowerProfileSimTrans2D_4->Fill(
991  ttemp_4->GetBinCenter(i + 1), electron.E(), ttemp_4->GetBinContent(i + 1));
992  fShowerProfileSimTrans2D_5->Fill(
993  ttemp_5->GetBinCenter(i + 1), electron.E(), ttemp_5->GetBinContent(i + 1));
994  }
995 } // showerProfileTrue
996 
997 // -------------------------------------------------
998 
999 DEFINE_ART_MODULE(shower::TCShowerTemplateMaker)
process_name opflash particleana ie ie ie z
TCShowerTemplateMaker(fhicl::ParameterSet const &pset)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
void SetEnergy(float e)
Definition: MCDataHolder.h:39
void analyze(const art::Event &evt) override
process_name opflash particleana ie x
Planes which measure V.
Definition: geo_types.h:130
Declaration of signal hit object.
double Temperature() const
In kelvin.
void SetTrackId(unsigned int id)
Definition: MCDataHolder.h:41
process_name hit
Definition: cheaterreco.fcl:51
void showerProfile(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> showerhits, TVector3 shwvtx, TVector3 shwdir, double elep)
process_name shower
Definition: cheaterreco.fcl:51
double Efield(unsigned int planegap=0) const
kV/cm
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
T abs(T value)
void showerProfileTrue(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> allhits, double elep)
standard_singlep gaussian distribution X0
Definition: multigen.fcl:8
process_name opflash particleana ie ie y
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void SetVertex(float x, float y, float z)
Definition: MCDataHolder.h:32
double ConvertXToTicks(double X, int p, int t, int c) const
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
Contains all timing reference information for the detector.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
art framework interface to geometry description
auto const detProp