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