All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ToFAnalyzer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ToFAnalyzer
3 // Plugin Type: analyzer (art v3_05_01)
4 // File: ToFAnalyzer_module.cc
5 //
6 // Generated at Tue Feb 1 09:34:47 2022 by Varuna Crishan Meddage using cetskelgen
7 // from cetlib version v3_10_00.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/SubRun.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "art/Framework/Principal/View.h"
16 #include "canvas/Persistency/Common/Ptr.h"
17 #include "canvas/Persistency/Common/PtrVector.h"
18 #include "art/Framework/Services/Registry/ServiceHandle.h"
19 #include "art_root_io/TFileService.h"
20 #include "art_root_io/TFileDirectory.h"
21 #include "canvas/Persistency/Common/FindMany.h"
22 #include "canvas/Persistency/Common/FindManyP.h"
23 #include "canvas/Persistency/Common/FindOneP.h"
24 #include "fhiclcpp/ParameterSet.h"
25 #include "messagefacility/MessageLogger/MessageLogger.h"
29 
31 #include "nusimdata/SimulationBase/GTruth.h"
32 #include "nusimdata/SimulationBase/MCTruth.h"
33 #include "nusimdata/SimulationBase/MCFlux.h"
63 
66 
67 // sbndcode includes
74 
76 
77 #include "TFile.h"
78 #include "TTree.h"
79 #include "TDirectory.h"
80 #include "TH1.h"
81 #include "TH2.h"
82 #include "TF1.h"
83 #include "TProfile.h"
84 #include "TROOT.h"
85 #include "TStyle.h"
86 #include "TMath.h"
87 #include "TGraphErrors.h"
88 #include "TMinuit.h"
89 #include "TString.h"
90 #include "TTimeStamp.h"
91 #include "TVectorD.h"
92 #include "TCanvas.h"
93 #include "TFrame.h"
94 #include "TLine.h"
95 #include "TAxis.h"
96 #include "TTimeStamp.h"
97 
98 #include <vector>
99 #include <fstream>
100 #include "TPaveStats.h"
101 #include <iostream>
102 #include <string>
103 #include "math.h"
104 #include "stdio.h"
105 #include <iterator>
106 #include <map>
107 
108 
109 using namespace std;
110 
111 namespace sbnd{
112 
113 class ToFAnalyzer : public art::EDAnalyzer {
114 public:
116  explicit ToFAnalyzer(fhicl::ParameterSet const& p);
117  ToFAnalyzer(ToFAnalyzer const&) = delete;
118  ToFAnalyzer(ToFAnalyzer&&) = delete;
119  ToFAnalyzer& operator=(ToFAnalyzer const&) = delete;
120  ToFAnalyzer& operator=(ToFAnalyzer&&) = delete;
121 
122  void beginJob() override;
123  void analyze(art::Event const& evt) override;
124  bool HitCompare(const art::Ptr<CRTHit>& h1, const art::Ptr<CRTHit>& h2);
125  void ClearVecs();
126  double length(const simb::MCParticle& part, TVector3& start, TVector3& end);
127 
128 private:
129  const double LAR_PROP_DELAY = 1.0/1.35e1; //[ns/cm] - from fcl dump on G4 fcl file (vuv_vgroup_mean: 1.35e1)
130 
131  art::InputTag fGenLabel;
132  art::InputTag fSimLabel;
133  art::InputTag fOpHitModuleLabel;
134  art::InputTag fOpFlashModuleLabel0;
135  art::InputTag fOpFlashModuleLabel1;
136  art::InputTag fCrtHitModuleLabel;
137  art::InputTag fCrtTrackModuleLabel;
138 
139  double fCoinWindow;
140  double fOpDelay;
143  double fHitPeThresh;
144  double fBeamLow;
145  double fBeamUp;
146  bool fLFlash;
148  bool fCFlash;
150  bool fLhit;
151  bool fChit;
154  double fG4timeUp;
155  double fG4timeLow;
158 
160  map<int,art::InputTag> fFlashLabels;
162 
163  TTree* fMatchTree;
164 
165  int frun;
166  int fsubrun;
167  int fevent;
168 
169  vector<int> fnu_pdg;
170  vector<double> fnu_E;
171  vector<int> fnu_mode; //0=QE/El, 1=RES, 2=DIS, 3=Coherent production
172  vector<int> fnu_CCNC; //0=CC 1=NC
173  vector<double> fnu_posX;
174  vector<double> fnu_posY;
175  vector<double> fnu_posZ;
176  vector<double> fnu_T;
177  vector<bool> fnu_CRYO;
178  vector<bool> fnu_TPC;
179 
180  vector<int> fg4_pdg;
181  vector<int> fg4_trkid;
182  vector<bool> fg4st_TPC;
183  vector<bool> fg4en_TPC;
184  vector<bool> fg4st_CRYO;
185  vector<bool> fg4en_CRYO;
186  vector<bool> fg4is_prim;
187  vector<double> fg4_T0;
188  vector<double> fg4_T0_CRYO;
189  vector<double> fg4_T0_TPC;
190  vector<int> fg4_org;
191  vector<double> fg4_stX;
192  vector<double> fg4_stY;
193  vector<double> fg4_stZ;
194  vector<double> fg4_enX;
195  vector<double> fg4_enY;
196  vector<double> fg4_enZ;
197  vector<double> fg4_tlen;
198  vector<double> fg4_E;
199  vector<bool> fg4_is_in_TPC;
200  vector<bool> fg4_is_in_CRYO;
201 
202  vector<double> fLhit_tof_vec;
203  vector<bool> fLhit_frmtrk_vec;
204  vector<bool> fLhit_frmhit_vec;
205  vector<int> fLhit_crthitkey_vec;
206  vector<int> fLhit_crttrkkey_vec;
207  vector<double> fLhit_crttime_t1_vec;
208  vector<double> fLhit_crttime_t0_vec;
209  vector<double> fLhit_crtpos_X_vec;
210  vector<double> fLhit_crtpos_Y_vec;
211  vector<double> fLhit_crtpos_Z_vec;
212  vector<double> fLhit_crtpe_vec;
213  vector<std::string> fLhit_crttgr_vec;
214  vector<int> fLhit_pmthitkey_vec;
215  vector<double> fLhit_pmthitT_vec;
216  vector<double> fLhit_pmthitX_vec;
217  vector<double> fLhit_pmthitY_vec;
218  vector<double> fLhit_pmthitZ_vec;
219  vector<double> fLhit_pmthitpe_vec;
220 
221  vector<double> fChit_tof_vec;
222  vector<bool> fChit_frmtrk_vec;
223  vector<bool> fChit_frmhit_vec;
224  vector<int> fChit_crthitkey_vec;
225  vector<int> fChit_crttrkkey_vec;
226  vector<double> fChit_crttime_t1_vec;
227  vector<double> fChit_crttime_t0_vec;
228  vector<double> fChit_crtpos_X_vec;
229  vector<double> fChit_crtpos_Y_vec;
230  vector<double> fChit_crtpos_Z_vec;
231  vector<double> fChit_crtpe_vec;
232  vector<std::string> fChit_crttgr_vec;
233  vector<int> fChit_pmthitkey_vec;
234  vector<double> fChit_pmthitT_vec;
235  vector<double> fChit_pmthitX_vec;
236  vector<double> fChit_pmthitY_vec;
237  vector<double> fChit_pmthitZ_vec;
238  vector<double> fChit_pmthitpe_vec;
239 
240  vector<double> fLflsh_tof_vec;
241  vector<bool> fLflsh_frmtrk_vec;
242  vector<bool> fLflsh_frmhit_vec;
243  vector<int> fLflsh_crthitkey_vec;
244  vector<int> fLflsh_crttrkkey_vec;
245  vector<double> fLflsh_crttime_t1_vec;
246  vector<double> fLflsh_crttime_t0_vec;
247  vector<double> fLflsh_crtpos_X_vec;
248  vector<double> fLflsh_crtpos_Y_vec;
249  vector<double> fLflsh_crtpos_Z_vec;
250  vector<double> fLflsh_crtpe_vec;
251  vector<std::string> fLflsh_crttgr_vec;
254  vector<double> fLflsh_pmtflshT_vec;
255  vector<double> fLflsh_pmtflshY_vec;
256  vector<double> fLflsh_pmtflshZ_vec;
257  vector<double> fLflsh_pmtflshpe_vec;
258 
259  vector<double> fCflsh_tof_vec;
260  vector<bool> fCflsh_frmtrk_vec;
261  vector<bool> fCflsh_frmhit_vec;
262  vector<int> fCflsh_crthitkey_vec;
263  vector<int> fCflsh_crttrkkey_vec;
264  vector<double> fCflsh_crttime_t1_vec;
265  vector<double> fCflsh_crttime_t0_vec;
266  vector<double> fCflsh_crtpos_X_vec;
267  vector<double> fCflsh_crtpos_Y_vec;
268  vector<double> fCflsh_crtpos_Z_vec;
269  vector<double> fCflsh_crtpe_vec;
270  vector<std::string> fCflsh_crttgr_vec;
273  vector<double> fCflsh_pmtflshT_vec;
274  vector<double> fCflsh_pmtflshY_vec;
275  vector<double> fCflsh_pmtflshZ_vec;
276  vector<double> fCflsh_pmtflshpe_vec;
277 
278  vector<double> fLflshhit_tof_vec;
279  vector<bool> fLflshhit_frmtrk_vec;
280  vector<bool> fLflshhit_frmhit_vec;
283  vector<double> fLflshhit_crttime_t1_vec;
284  vector<double> fLflshhit_crttime_t0_vec;
285  vector<double> fLflshhit_crtpos_X_vec;
286  vector<double> fLflshhit_crtpos_Y_vec;
287  vector<double> fLflshhit_crtpos_Z_vec;
288  vector<double> fLflshhit_crtpe_vec;
289  vector<std::string> fLflshhit_crttgr_vec;
292  vector<int> fLflshhit_pmtkey_vec;
293  vector<double> fLflshhit_pmtflshT_vec;
294  vector<double> fLflshhit_pmtflshX_vec;
295  vector<double> fLflshhit_pmtflshY_vec;
296  vector<double> fLflshhit_pmtflshZ_vec;
297  vector<double> fLflshhit_pmtflshpe_vec;
298 
299  vector<double> fCflshhit_tof_vec;
300  vector<bool> fCflshhit_frmtrk_vec;
301  vector<bool> fCflshhit_frmhit_vec;
304  vector<double> fCflshhit_crttime_t1_vec;
305  vector<double> fCflshhit_crttime_t0_vec;
306  vector<double> fCflshhit_crtpos_X_vec;
307  vector<double> fCflshhit_crtpos_Y_vec;
308  vector<double> fCflshhit_crtpos_Z_vec;
309  vector<double> fCflshhit_crtpe_vec;
310  vector<std::string> fCflshhit_crttgr_vec;
313  vector<int> fCflshhit_pmtkey_vec;
314  vector<double> fCflshhit_pmtflshT_vec;
315  vector<double> fCflshhit_pmtflshX_vec;
316  vector<double> fCflshhit_pmtflshY_vec;
317  vector<double> fCflshhit_pmtflshZ_vec;
318  vector<double> fCflshhit_pmtflshpe_vec;
319 
320  vector<double> fTrue_TOF;
321  vector<bool> fTrue_TOF_hit; // from hit == true, from track == alse
322  vector<int> fTrue_TOF_pdg;
323  vector<int> fTrue_TOF_part_ID;
324  vector<bool> fTrue_TOF_part_prim;
325  vector<bool> fTrue_TOF_part_org;
326  vector<double> fTrue_TOF_traj_T;
327  vector<double> fTrue_TOF_traj_X;
328  vector<double> fTrue_TOF_traj_Y;
329  vector<double> fTrue_TOF_traj_Z;
330  vector<bool> fTrue_TOF_traj_in_TPC; // if trajectory point is in TPC = true, else false
331 };
332 
333 ToFAnalyzer::ToFAnalyzer(fhicl::ParameterSet const& pset):
334 EDAnalyzer{pset},
335 fGenLabel(pset.get<art::InputTag>("GenLabel")),
336 fSimLabel(pset.get<art::InputTag>("SimLabel")),
337 fOpHitModuleLabel(pset.get<art::InputTag>("OpHitModuleLabel")),
338 fOpFlashModuleLabel0(pset.get<art::InputTag>("OpFlashModuleLabel0")),
339 fOpFlashModuleLabel1(pset.get<art::InputTag>("OpFlashModuleLabel1")),
340 fCrtHitModuleLabel(pset.get<art::InputTag>("CrtHitModuleLabel")),
341 fCrtTrackModuleLabel(pset.get<art::InputTag>("CrtTrackModuleLabel")),
342 fCoinWindow(pset.get<double>("CoincidenceWindow")),
343 fOpDelay(pset.get<double>("OpDelay")), // the cable time delay (135 ns) + PMTTransit Time delay (55 ns) + average TPB emission time delay (~4.5 ns)
344 fCRThitThresh(pset.get<double>("CRThitThresh")),
345 fFlashPeThresh(pset.get<int>("FlashPeThresh")),
346 fHitPeThresh(pset.get<int>("HitPeThresh")),
347 fBeamLow(pset.get<double>("BeamLow")),
348 fBeamUp(pset.get<double>("BeamUp")),
349 fLFlash(pset.get<bool>("LFlash")),
350 fLFlash_hit(pset.get<bool>("LFlash_hit")),
351 fCFlash(pset.get<bool>("CFlash")),
352 fCFlash_hit(pset.get<bool>("CFlash_hit")),
353 fLhit(pset.get<bool>("Lhit")),
354 fChit(pset.get<bool>("Chit")),
355 fSaveNuInfo(pset.get<bool>("SaveNuInfo")),
356 fSaveG4Info(pset.get<bool>("SaveG4Info")),
357 fG4timeUp(pset.get<double>("G4timeUp")),
358 fG4timeLow(pset.get<double>("G4timeLow")),
359 fkeeponlytracks(pset.get<bool>("keeponlytracks")),
360 fSaveTrueToFInfo(pset.get<bool>("SaveTrueToFInfo")),
361 bt(new CRTBackTracker(pset.get<fhicl::ParameterSet>("CRTBackTrack")))
362 {
363 fFlashLabels[0] = fOpFlashModuleLabel0;
364 fFlashLabels[1] = fOpFlashModuleLabel1;
365 }
366 
367 //========================================================================
369  std::cout<<"job begin..."<<std::endl;
370 
371  fGeometryService = lar::providerFrom<geo::Geometry>();
372 
373  art::ServiceHandle<art::TFileService> tfs;
374  fMatchTree = tfs->make<TTree>("matchTree","CRTHit - OpHit/Flash matching analysis");
375 
376  fMatchTree->Branch("run", &frun, "run/I");
377  fMatchTree->Branch("subrun", &fsubrun, "subrun/I");
378  fMatchTree->Branch("event", &fevent, "event/I");
379 
380  fMatchTree->Branch("nu_pdg", &fnu_pdg);
381  fMatchTree->Branch("nu_E", &fnu_E);
382  fMatchTree->Branch("nu_mode", &fnu_mode);
383  fMatchTree->Branch("nu_CCNC", &fnu_CCNC);
384  fMatchTree->Branch("nu_posX", &fnu_posX);
385  fMatchTree->Branch("nu_posY", &fnu_posY);
386  fMatchTree->Branch("nu_posZ", &fnu_posZ);
387  fMatchTree->Branch("nu_T", &fnu_T);
388  fMatchTree->Branch("nu_CRYO", &fnu_CRYO);
389  fMatchTree->Branch("nu_TPC", &fnu_TPC);
390 
391  fMatchTree->Branch("g4_pdg", &fg4_pdg);
392  fMatchTree->Branch("g4_trkid", &fg4_trkid);
393  fMatchTree->Branch("g4st_TPC", &fg4st_TPC);
394  fMatchTree->Branch("g4en_TPC", &fg4en_TPC);
395  fMatchTree->Branch("g4st_CRYO", &fg4st_CRYO);
396  fMatchTree->Branch("g4en_CRYO", &fg4en_CRYO);
397  fMatchTree->Branch("g4is_prim", &fg4is_prim);
398  fMatchTree->Branch("g4_T0", &fg4_T0);
399  fMatchTree->Branch("g4_T0_CRYO", &fg4_T0_CRYO);
400  fMatchTree->Branch("g4_T0_TPC", &fg4_T0_TPC);
401  fMatchTree->Branch("g4_org", &fg4_org);
402  fMatchTree->Branch("g4_stX", &fg4_stX);
403  fMatchTree->Branch("g4_stY", &fg4_stY);
404  fMatchTree->Branch("g4_stZ", &fg4_stZ);
405  fMatchTree->Branch("g4_enX", &fg4_enX);
406  fMatchTree->Branch("g4_enY", &fg4_enY);
407  fMatchTree->Branch("g4_enZ", &fg4_enZ);
408  fMatchTree->Branch("g4_tlen", &fg4_tlen);
409  fMatchTree->Branch("g4_E", &fg4_E);
410  fMatchTree->Branch("g4_is_in_TPC", &fg4_is_in_TPC);
411  fMatchTree->Branch("g4_is_in_CRYO", &fg4_is_in_CRYO);
412 
413  fMatchTree->Branch("Lhit_tof_vec", &fLhit_tof_vec);
414  fMatchTree->Branch("Lhit_frmtrk_vec", &fLhit_frmtrk_vec);
415  fMatchTree->Branch("Lhit_frmhit_vec", &fLhit_frmhit_vec);
416  fMatchTree->Branch("Lhit_crthitkey_vec", &fLhit_crthitkey_vec);
417  fMatchTree->Branch("Lhit_crttrkkey_vec", &fLhit_crttrkkey_vec);
418  fMatchTree->Branch("Lhit_crttime_t1_vec", &fLhit_crttime_t1_vec);
419  fMatchTree->Branch("Lhit_crttime_t0_vec", &fLhit_crttime_t0_vec);
420  fMatchTree->Branch("Lhit_crtpos_X_vec", &fLhit_crtpos_X_vec);
421  fMatchTree->Branch("Lhit_crtpos_Y_vec", &fLhit_crtpos_Y_vec);
422  fMatchTree->Branch("Lhit_crtpos_Z_vec", &fLhit_crtpos_Z_vec);
423  fMatchTree->Branch("Lhit_crtpe_vec", &fLhit_crtpe_vec);
424  fMatchTree->Branch("Lhit_crttgr_vec", &fLhit_crttgr_vec);
425  fMatchTree->Branch("Lhit_pmthitkey_vec", &fLhit_pmthitkey_vec);
426  fMatchTree->Branch("Lhit_pmthitT_vec", &fLhit_pmthitT_vec);
427  fMatchTree->Branch("Lhit_pmthitX_vec", &fLhit_pmthitX_vec);
428  fMatchTree->Branch("Lhit_pmthitY_vec", &fLhit_pmthitY_vec);
429  fMatchTree->Branch("Lhit_pmthitZ_vec", &fLhit_pmthitZ_vec);
430  fMatchTree->Branch("Lhit_pmthitpe_vec", &fLhit_pmthitpe_vec);
431 
432  fMatchTree->Branch("Chit_tof_vec", &fChit_tof_vec);
433  fMatchTree->Branch("Chit_frmtrk_vec", &fChit_frmtrk_vec);
434  fMatchTree->Branch("Chit_frmhit_vec", &fChit_frmhit_vec);
435  fMatchTree->Branch("Chit_crthitkey_vec", &fChit_crthitkey_vec);
436  fMatchTree->Branch("Chit_crttrkkey_vec", &fChit_crttrkkey_vec);
437  fMatchTree->Branch("Chit_crttime_t1_vec", &fChit_crttime_t1_vec);
438  fMatchTree->Branch("Chit_crttime_t0_vec", &fChit_crttime_t0_vec);
439  fMatchTree->Branch("Chit_crtpos_X_vec", &fChit_crtpos_X_vec);
440  fMatchTree->Branch("Chit_crtpos_Y_vec", &fChit_crtpos_Y_vec);
441  fMatchTree->Branch("Chit_crtpos_Z_vec", &fChit_crtpos_Z_vec);
442  fMatchTree->Branch("Chit_crtpe_vec", &fChit_crtpe_vec);
443  fMatchTree->Branch("Chit_crttgr_vec", &fChit_crttgr_vec);
444  fMatchTree->Branch("Chit_pmthitkey_vec", &fChit_pmthitkey_vec);
445  fMatchTree->Branch("Chit_pmthitT_vec", &fChit_pmthitT_vec);
446  fMatchTree->Branch("Chit_pmthitX_vec", &fChit_pmthitX_vec);
447  fMatchTree->Branch("Chit_pmthitY_vec", &fChit_pmthitY_vec);
448  fMatchTree->Branch("Chit_pmthitZ_vec", &fChit_pmthitZ_vec);
449  fMatchTree->Branch("Chit_pmthitpe_vec", &fChit_pmthitpe_vec);
450 
451  fMatchTree->Branch("Lflsh_tof_vec", &fLflsh_tof_vec);
452  fMatchTree->Branch("Lflsh_frmtrk_vec", &fLflsh_frmtrk_vec);
453  fMatchTree->Branch("Lflsh_frmhit_vec", &fLflsh_frmhit_vec);
454  fMatchTree->Branch("Lflsh_crthitkey_vec", &fLflsh_crthitkey_vec);
455  fMatchTree->Branch("Lflsh_crttrkkey_vec", &fLflsh_crttrkkey_vec);
456  fMatchTree->Branch("Lflsh_crttime_t1_vec", &fLflsh_crttime_t1_vec);
457  fMatchTree->Branch("Lflsh_crttime_t0_vec", &fLflsh_crttime_t0_vec);
458  fMatchTree->Branch("Lflsh_crtpos_X_vec", &fLflsh_crtpos_X_vec);
459  fMatchTree->Branch("Lflsh_crtpos_Y_vec", &fLflsh_crtpos_Y_vec);
460  fMatchTree->Branch("Lflsh_crtpos_Z_vec", &fLflsh_crtpos_Z_vec);
461  fMatchTree->Branch("Lflsh_crtpe_vec", &fLflsh_crtpe_vec);
462  fMatchTree->Branch("Lflsh_crttgr_vec", &fLflsh_crttgr_vec);
463  fMatchTree->Branch("Lflsh_pmtflshtpcID_vec", &fLflsh_pmtflshtpcID_vec);
464  fMatchTree->Branch("Lflsh_pmtflshkey_vec", &fLflsh_pmtflshkey_vec);
465  fMatchTree->Branch("Lflsh_pmtflshT_vec", &fLflsh_pmtflshT_vec);
466  fMatchTree->Branch("Lflsh_pmtflshY_vec", &fLflsh_pmtflshY_vec);
467  fMatchTree->Branch("Lflsh_pmtflshZ_vec", &fLflsh_pmtflshZ_vec);
468  fMatchTree->Branch("Lflsh_pmtflshpe_vec", &fLflsh_pmtflshpe_vec);
469 
470  fMatchTree->Branch("Cflsh_tof_vec", &fCflsh_tof_vec);
471  fMatchTree->Branch("Cflsh_frmtrk_vec", &fCflsh_frmtrk_vec);
472  fMatchTree->Branch("Cflsh_frmhit_vec", &fCflsh_frmhit_vec);
473  fMatchTree->Branch("Cflsh_crthitkey_vec", &fCflsh_crthitkey_vec);
474  fMatchTree->Branch("Cflsh_crttrkkey_vec", &fCflsh_crttrkkey_vec);
475  fMatchTree->Branch("Cflsh_crttime_t1_vec", &fCflsh_crttime_t1_vec);
476  fMatchTree->Branch("Cflsh_crttime_t0_vec", &fCflsh_crttime_t0_vec);
477  fMatchTree->Branch("Cflsh_crtpos_X_vec", &fCflsh_crtpos_X_vec);
478  fMatchTree->Branch("Cflsh_crtpos_Y_vec", &fCflsh_crtpos_Y_vec);
479  fMatchTree->Branch("Cflsh_crtpos_Z_vec", &fCflsh_crtpos_Z_vec);
480  fMatchTree->Branch("Cflsh_crtpe_vec", &fCflsh_crtpe_vec);
481  fMatchTree->Branch("Cflsh_crttgr_vec", &fCflsh_crttgr_vec);
482  fMatchTree->Branch("Cflsh_pmtflshtpcID_vec", &fCflsh_pmtflshtpcID_vec);
483  fMatchTree->Branch("Cflsh_pmtflshkey_vec", &fCflsh_pmtflshkey_vec);
484  fMatchTree->Branch("Cflsh_pmtflshT_vec", &fCflsh_pmtflshT_vec);
485  fMatchTree->Branch("Cflsh_pmtflshY_vec", &fCflsh_pmtflshY_vec);
486  fMatchTree->Branch("Cflsh_pmtflshZ_vec", &fCflsh_pmtflshZ_vec);
487  fMatchTree->Branch("Cflsh_pmtflshpe_vec", &fCflsh_pmtflshpe_vec);
488 
489  fMatchTree->Branch("Lflshhit_tof_vec", &fLflshhit_tof_vec);
490  fMatchTree->Branch("Lflshhit_frmtrk_vec", &fLflshhit_frmtrk_vec);
491  fMatchTree->Branch("Lflshhit_frmhit_vec", &fLflshhit_frmhit_vec);
492  fMatchTree->Branch("Lflshhit_crthitkey_vec", &fLflshhit_crthitkey_vec);
493  fMatchTree->Branch("Lflshhit_crttrkkey_vec", &fLflshhit_crttrkkey_vec);
494  fMatchTree->Branch("Lflshhit_crttime_t1_vec", &fLflshhit_crttime_t1_vec);
495  fMatchTree->Branch("Lflshhit_crttime_t0_vec", &fLflshhit_crttime_t0_vec);
496  fMatchTree->Branch("Lflshhit_crtpos_X_vec", &fLflshhit_crtpos_X_vec);
497  fMatchTree->Branch("Lflshhit_crtpos_Y_vec", &fLflshhit_crtpos_Y_vec);
498  fMatchTree->Branch("Lflshhit_crtpos_Z_vec", &fLflshhit_crtpos_Z_vec);
499  fMatchTree->Branch("Lflshhit_crtpe_vec", &fLflshhit_crtpe_vec);
500  fMatchTree->Branch("Lflshhit_crttgr_vec", &fLflshhit_crttgr_vec);
501  fMatchTree->Branch("Lflshhit_pmtflshtpcID_vec", &fLflshhit_pmtflshtpcID_vec);
502  fMatchTree->Branch("Lflshhit_pmtflshkey_vec", &fLflshhit_pmtflshkey_vec);
503  fMatchTree->Branch("Lflshhit_pmtkey_vec", &fLflshhit_pmtkey_vec);
504  fMatchTree->Branch("Lflshhit_pmtflshT_vec", &fLflshhit_pmtflshT_vec);
505  fMatchTree->Branch("Lflshhit_pmtflshX_vec", &fLflshhit_pmtflshX_vec);
506  fMatchTree->Branch("Lflshhit_pmtflshY_vec", &fLflshhit_pmtflshY_vec);
507  fMatchTree->Branch("Lflshhit_pmtflshZ_vec", &fLflshhit_pmtflshZ_vec);
508  fMatchTree->Branch("Lflshhit_pmtflshpe_vec", &fLflshhit_pmtflshpe_vec);
509 
510  fMatchTree->Branch("Cflshhit_tof_vec", &fCflshhit_tof_vec);
511  fMatchTree->Branch("Cflshhit_frmtrk_vec", &fCflshhit_frmtrk_vec);
512  fMatchTree->Branch("Cflshhit_frmhit_vec", &fCflshhit_frmhit_vec);
513  fMatchTree->Branch("Cflshhit_crthitkey_vec", &fCflshhit_crthitkey_vec);
514  fMatchTree->Branch("Cflshhit_crttrkkey_vec", &fCflshhit_crttrkkey_vec);
515  fMatchTree->Branch("Cflshhit_crttime_t1_vec", &fCflshhit_crttime_t1_vec);
516  fMatchTree->Branch("Cflshhit_crttime_t0_vec", &fCflshhit_crttime_t0_vec);
517  fMatchTree->Branch("Cflshhit_crtpos_X_vec", &fCflshhit_crtpos_X_vec);
518  fMatchTree->Branch("Cflshhit_crtpos_Y_vec", &fCflshhit_crtpos_Y_vec);
519  fMatchTree->Branch("Cflshhit_crtpos_Z_vec", &fCflshhit_crtpos_Z_vec);
520  fMatchTree->Branch("Cflshhit_crtpe_vec", &fCflshhit_crtpe_vec);
521  fMatchTree->Branch("Cflshhit_crttgr_vec", &fCflshhit_crttgr_vec);
522  fMatchTree->Branch("Cflshhit_pmtflshtpcID_vec", &fCflshhit_pmtflshtpcID_vec);
523  fMatchTree->Branch("Cflshhit_pmtflshkey_vec", &fCflshhit_pmtflshkey_vec);
524  fMatchTree->Branch("Cflshhit_pmtkey_vec", &fCflshhit_pmtkey_vec);
525  fMatchTree->Branch("Cflshhit_pmtflshT_vec", &fCflshhit_pmtflshT_vec);
526  fMatchTree->Branch("Cflshhit_pmtflshX_vec", &fCflshhit_pmtflshX_vec);
527  fMatchTree->Branch("Cflshhit_pmtflshY_vec", &fCflshhit_pmtflshY_vec);
528  fMatchTree->Branch("Cflshhit_pmtflshZ_vec", &fCflshhit_pmtflshZ_vec);
529  fMatchTree->Branch("Cflshhit_pmtflshpe_vec", &fCflshhit_pmtflshpe_vec);
530 
531  fMatchTree->Branch("True_TOF", &fTrue_TOF);
532  fMatchTree->Branch("True_TOF_hit", &fTrue_TOF_hit);
533  fMatchTree->Branch("True_TOF_pdg", &fTrue_TOF_pdg);
534  fMatchTree->Branch("True_TOF_part_ID", &fTrue_TOF_part_ID);
535  fMatchTree->Branch("True_TOF_part_prim", &fTrue_TOF_part_prim);
536  fMatchTree->Branch("True_TOF_part_org", &fTrue_TOF_part_org);
537  fMatchTree->Branch("True_TOF_traj_T", &fTrue_TOF_traj_T);
538  fMatchTree->Branch("True_TOF_traj_X", &fTrue_TOF_traj_X);
539  fMatchTree->Branch("True_TOF_traj_Y", &fTrue_TOF_traj_Y);
540  fMatchTree->Branch("True_TOF_traj_Z", &fTrue_TOF_traj_Z);
541  fMatchTree->Branch("True_TOF_traj_in_TPC", &fTrue_TOF_traj_in_TPC);
542 }
543 
544 
545 
546 void ToFAnalyzer::analyze(art::Event const& evt)
547 {
548  ClearVecs();
549 
550  geo::CryostatGeo const& cryo0 = fGeometryService->Cryostat(0);
551  geo::TPCGeo const& tpc00 = cryo0.TPC(0);
552  geo::TPCGeo const& tpc01 = cryo0.TPC(1);
553 
554  frun=evt.run();
555  fsubrun=evt.subRun();
556  fevent=evt.id().event();
557 
558  //std::cout << "****************** " << frun << " " << fsubrun << " " << fevent << " *****************\n";
559 
560  //===================Neutrino information =========================
561 
562  if(fSaveNuInfo){
563  art::Handle< std::vector<simb::MCTruth> > MCTruthListHandle;
564  std::vector< art::Ptr<simb::MCTruth> > MCTruthkList;
565  if( evt.getByLabel(fGenLabel,MCTruthListHandle))
566  art::fill_ptr_vector(MCTruthkList, MCTruthListHandle);
567 
568  for(auto const& mctruth : MCTruthkList){
569  if (!mctruth->NeutrinoSet()) continue;
570  auto const& nu = mctruth->GetNeutrino();
571  const TLorentzVector xyzt = nu.Nu().Position(0);
572  fnu_pdg.push_back(nu.Nu().PdgCode());
573  fnu_E.push_back(nu.Nu().E());
574  fnu_mode.push_back(nu.Mode());
575  fnu_CCNC.push_back(nu.CCNC());
576  fnu_posX.push_back(xyzt.X());
577  fnu_posY.push_back(xyzt.Y());
578  fnu_posZ.push_back(xyzt.Z());
579  fnu_T.push_back(xyzt.T());
580  double point[3] = {fnu_posX.back(), fnu_posY.back(), fnu_posZ.back()};
581  if(cryo0.ContainsPosition(point)) fnu_CRYO.push_back(true);
582  else fnu_CRYO.push_back(false);
583  if(tpc00.ContainsPosition(point) || tpc01.ContainsPosition(point)) fnu_TPC.push_back(true);
584  else fnu_TPC.push_back(false);
585  }
586  }
587 
588 //===================================================================
589 
590 //=============G4 level particle information ========================
591 
592  if(fSaveG4Info){
593  art::Handle< std::vector<simb::MCParticle> > SimPartListHandle;
594  std::vector< art::Ptr<simb::MCParticle> > SimPartList;
595  if( evt.getByLabel(fSimLabel,SimPartListHandle))
596  art::fill_ptr_vector(SimPartList, SimPartListHandle);
597 
598  for(auto const& part : SimPartList){
599  const cheat::ParticleInventory *inventory_service=lar::providerFrom<cheat::ParticleInventoryService>();
600  if(!(part->T()<=fG4timeUp && part->T()>=fG4timeLow)) continue;
601  if(fkeeponlytracks){
602  if(!(TMath::Abs(part->PdgCode())==13 || TMath::Abs(part->PdgCode())==211 || TMath::Abs(part->PdgCode())==2212 || TMath::Abs(part->PdgCode())==321)) continue;
603  }
604 
605  fg4_pdg.push_back(part->PdgCode());
606  fg4_trkid.push_back(part->TrackId());
607  if(part->Process()=="primary") fg4is_prim.push_back(true);
608  else fg4is_prim.push_back(false);
609  fg4_T0.push_back(part->T());
610  art::Ptr<simb::MCTruth> truth=inventory_service->TrackIdToMCTruth_P(part->TrackId());
611  fg4_org.push_back(truth->NeutrinoSet());
612  //std::cout << "******* Total number of trajectory points : " << part->NumberTrajectoryPoints() <<"\n";
613  const TLorentzVector st_xyzt = part->Position(0);
614  double st_point[3] = {st_xyzt.X(), st_xyzt.Y(), st_xyzt.Z()};
615  fg4_stX.push_back(st_point[0]);
616  fg4_stY.push_back(st_point[1]);
617  fg4_stZ.push_back(st_point[2]);
618  if(cryo0.ContainsPosition(st_point)) fg4st_CRYO.push_back(true);
619  else fg4st_CRYO.push_back(false);
620  if(tpc00.ContainsPosition(st_point) || tpc01.ContainsPosition(st_point)) fg4st_TPC.push_back(true);
621  else fg4st_TPC.push_back(false);
622  const TLorentzVector en_xyzt = part->EndPosition();
623  double en_point[3] = {en_xyzt.X(), en_xyzt.Y(), en_xyzt.Z()};
624  fg4_enX.push_back(en_point[0]);
625  fg4_enY.push_back(en_point[1]);
626  fg4_enZ.push_back(en_point[2]);
627  if(cryo0.ContainsPosition(en_point)) fg4en_CRYO.push_back(true);
628  else fg4en_CRYO.push_back(false);
629  if(tpc00.ContainsPosition(en_point) || tpc01.ContainsPosition(en_point)) fg4en_TPC.push_back(true);
630  else fg4en_TPC.push_back(false);
631  fg4_E.push_back(part->E());
632  TVector3 mcstart, mcend;
633  fg4_tlen.push_back(length(*part, mcstart, mcend));
634  bool is_in_TPC=false;
635  bool is_in_CRYO=false;
636  bool is_filled=false;
637  fg4_T0_CRYO.push_back(-9999);
638  fg4_T0_TPC.push_back(-9999);
639  for(size_t i=0; i<part->NumberTrajectoryPoints(); i++){
640  const TLorentzVector& pos = part->Position(i);
641  double point[3] = {pos.X(),pos.Y(),pos.Z()};
642  //std::cout << "Trjectory point : " << i << " " << pos.X() << " " << pos.Y() << " " << pos.Z() << "\n";
643  if(cryo0.ContainsPosition(point) && !is_filled){
644  is_filled=true;
645  is_in_CRYO=true;
646  fg4_T0_CRYO.back()=pos.T();
647  }
648 
649  if(tpc00.ContainsPosition(point) || tpc01.ContainsPosition(point)){
650  is_in_TPC=true;
651  fg4_T0_TPC.back()=pos.T();
652  break;
653  }
654  }
655  fg4_is_in_TPC.push_back(is_in_TPC);
656  fg4_is_in_CRYO.push_back(is_in_CRYO);
657  }
658  }
659 
660  //==================================================================
661 
662  art::Handle< std::vector<sbn::crt::CRTTrack> > crtTrackListHandle;
663  std::vector< art::Ptr<sbn::crt::CRTTrack> > crtTrackList;
664  if( evt.getByLabel(fCrtTrackModuleLabel,crtTrackListHandle))
665  art::fill_ptr_vector(crtTrackList, crtTrackListHandle);
666 
667  art::FindManyP<sbn::crt::CRTHit> findManyHits(crtTrackListHandle, evt, fCrtTrackModuleLabel);
668  std::vector<std::vector<art::Ptr<CRTHit>>> trackhits;
669 
670  //================================================================
671 
672  for(size_t itrk=0; itrk<crtTrackList.size(); itrk++){
673  std::vector<art::Ptr<CRTHit>> trkhits = findManyHits.at(itrk);
674  std::sort(trkhits.begin(),trkhits.end(),
675  [](const art::Ptr<CRTHit>& a, const art::Ptr<CRTHit>& b)->bool
676  {
677  return a->ts1_ns < b->ts1_ns;
678  });
679  trackhits.push_back(trkhits);
680  } // Crt hits coming from are ordered on ascending order by looking into ts1_ns variable
681 
682  //==================================================================
683 
684  art::Handle< std::vector<sbn::crt::CRTHit> > crtHitListHandle;
685  std::vector< art::Ptr<sbn::crt::CRTHit> > crtHitList;
686  if( evt.getByLabel(fCrtHitModuleLabel,crtHitListHandle))
687  art::fill_ptr_vector(crtHitList, crtHitListHandle);
688 
689  map<int, std::vector<art::Ptr<CRTHit>> > Lhit_tof_crt_hits;
690  map<int, std::vector<art::Ptr<recob::OpHit>> > Lhit_tof_op_hits;
691 
692  map<int, std::vector<art::Ptr<CRTHit>> > Chit_tof_crt_hits;
693  map<int, std::vector<art::Ptr<recob::OpHit>> > Chit_tof_op_hits;
694 
695  map<int, std::vector<art::Ptr<CRTHit>> > Lflsh_tof_crt_hits;
696  map<int, std::vector<art::Ptr<recob::OpFlash>> > Lflsh_tof_op_flashes;
697  map<int, std::vector<int>> Lflsh_tof_op_tpc;
698 
699  map<int, std::vector<art::Ptr<CRTHit>> > Cflsh_tof_crt_hits;
700  map<int, std::vector<art::Ptr<recob::OpFlash>> > Cflsh_tof_op_flashes;
701  map<int, std::vector<int>> Cflsh_tof_op_tpc;
702 
703  map<int, std::vector<art::Ptr<CRTHit>> > Lflshhit_tof_crt_hits;
704  map<int, std::vector<art::Ptr<recob::OpHit>> > Lflshhit_tof_op_hits;
705  map<int, std::vector<art::Ptr<recob::OpFlash>> > Lflshhit_tof_op_flashes;
706  map<int, std::vector<int>> Lflshhit_tof_op_tpc;
707 
708  map<int, std::vector<art::Ptr<CRTHit>> > Cflshhit_tof_crt_hits;
709  map<int, std::vector<art::Ptr<recob::OpHit>> > Cflshhit_tof_op_hits;
710  map<int, std::vector<art::Ptr<recob::OpFlash>> > Cflshhit_tof_op_flashes;
711  map<int, std::vector<int>> Cflshhit_tof_op_tpc;
712 
713  map<int, std::vector<art::Ptr<CRTHit>> > True_tof_crt_hits;
714  map<int,std::vector<const simb::MCParticle*>> True_tof_sim_particles;
715 
716  for(auto const& crt : crtHitList){
717  if(!(crt->ts1_ns >= fBeamLow && crt->ts1_ns<= fBeamUp)) continue;
718  if(crt->peshit < fCRThitThresh) continue;
719 
720  bool frm_trk=false;
721  int index=0;
722 
723  for(auto const& trkhits: trackhits){
724  for(size_t ihit=0; ihit<trkhits.size(); ihit++){
725  if(HitCompare(trkhits[ihit],crt)){
726  frm_trk=true;
727  break;
728  }
729  }
730  if(frm_trk) break;
731  index++;
732  }
733 
734  //======================== Doing a truth level study of ToF======================================
735 
736  if(fSaveTrueToFInfo){
737  const cheat::ParticleInventory *inventory_service=lar::providerFrom<cheat::ParticleInventoryService>();
738  int trackID=bt->TrueIdFromTotalEnergy(evt,*crt);
739  auto const& simparticles = *evt.getValidHandle<vector<simb::MCParticle>>(fSimLabel);
740  map<int,const simb::MCParticle*> particleMap;
741  for(auto const& particle : simparticles) particleMap[particle.TrackId()] = &particle;
742 
743  if(particleMap.find(abs(trackID))!=particleMap.end()){
744  if(frm_trk){
745  True_tof_crt_hits[index].push_back(crt);
746  True_tof_sim_particles[index].push_back(particleMap[abs(trackID)]);
747  }
748  else{
749  auto const& particle=particleMap[abs(trackID)];
750  bool found_tpc_traj_point=false;
751  for(size_t i=0; i<particle->NumberTrajectoryPoints(); i++){
752  const TLorentzVector& pos = particle->Position(i);
753  double point[3] = {pos.X(),pos.Y(),pos.Z()};
754  if(tpc00.ContainsPosition(point) || tpc01.ContainsPosition(point)){
755  double opDetPos[3];
756  (cryo0.OpDet(cryo0.GetClosestOpDet(point))).GetCenter(opDetPos);
757  double dprop=sqrt(pow(opDetPos[0]-pos[0],2) + pow(opDetPos[1]-pos[1],2) + pow(opDetPos[2]-pos[2],2));
758  double tprop=pos.T() + dprop*LAR_PROP_DELAY;
759  fTrue_TOF.push_back(crt->ts1_ns-tprop);
760  fTrue_TOF_hit.push_back(true);
761  fTrue_TOF_pdg.push_back(particle->PdgCode());
762  fTrue_TOF_part_ID.push_back(particle->TrackId());
763  if(particle->Process()=="primary") fTrue_TOF_part_prim.push_back(true);
764  else fTrue_TOF_part_prim.push_back(false);
765  art::Ptr<simb::MCTruth> truth=inventory_service->TrackIdToMCTruth_P(particle->TrackId());
766  fTrue_TOF_part_org.push_back(truth->NeutrinoSet());
767  fTrue_TOF_traj_T.push_back(pos.T());
768  fTrue_TOF_traj_X.push_back(point[0]);
769  fTrue_TOF_traj_Y.push_back(point[1]);
770  fTrue_TOF_traj_Z.push_back(point[2]);
771  fTrue_TOF_traj_in_TPC.push_back(true);
772  found_tpc_traj_point=true;
773  break;
774  } // trajectory point is in TPC
775  } // loop over trajectory points
776 
777  if(!found_tpc_traj_point){
778  for(size_t i=0; i<particle->NumberTrajectoryPoints(); i++){
779  const TLorentzVector& pos = particle->Position(i);
780  double point[3] = {pos.X(),pos.Y(),pos.Z()};
781  if(cryo0.ContainsPosition(point)){
782  double opDetPos[3];
783  (cryo0.OpDet(cryo0.GetClosestOpDet(point))).GetCenter(opDetPos);
784  double dprop=sqrt(pow(opDetPos[0]-pos[0],2) + pow(opDetPos[1]-pos[1],2) + pow(opDetPos[2]-pos[2],2));
785  double tprop=pos.T() + dprop*LAR_PROP_DELAY;
786  fTrue_TOF.push_back(crt->ts1_ns-tprop);
787  fTrue_TOF_hit.push_back(true);
788  fTrue_TOF_pdg.push_back(particle->PdgCode());
789  fTrue_TOF_part_ID.push_back(particle->TrackId());
790  if(particle->Process()=="primary") fTrue_TOF_part_prim.push_back(true);
791  else fTrue_TOF_part_prim.push_back(false);
792  art::Ptr<simb::MCTruth> truth=inventory_service->TrackIdToMCTruth_P(particle->TrackId());
793  fTrue_TOF_part_org.push_back(truth->NeutrinoSet());
794  fTrue_TOF_traj_T.push_back(pos.T());
795  fTrue_TOF_traj_X.push_back(point[0]);
796  fTrue_TOF_traj_Y.push_back(point[1]);
797  fTrue_TOF_traj_Z.push_back(point[2]);
798  fTrue_TOF_traj_in_TPC.push_back(false);
799  break;
800  } // found a trajectory point inside CRYO
801  } // loop over trajectory points
802  } // did not find a trajectory point inside TPC
803 
804  } // lonely CRT hit
805 
806  } // CRT hit is truth matched
807  } // Save true ToF information
808 
809  //===============================================================================================
810 
811  //============================== Calculating ToF using largest optical hit ======================
812 
813  if(fLhit){
814  double pehit_max=0;
815  bool found_tof = false;
816  int ophit_index = -1;
817 
818  art::Handle< std::vector<recob::OpHit> > opHitListHandle;
819  std::vector< art::Ptr<recob::OpHit> > opHitList;
820  if( evt.getByLabel(fOpHitModuleLabel,opHitListHandle) )
821  art::fill_ptr_vector(opHitList, opHitListHandle);
822 
823  for(auto const& hit : opHitList){
824  if(hit->PE()<fHitPeThresh) continue;
825  double thit = hit->PeakTime()*1e3-fOpDelay;
826 
827  if(abs(crt->ts1_ns-thit)<fCoinWindow && hit->PE()>pehit_max){
828  pehit_max = hit->PE();
829  ophit_index = hit.key();
830  found_tof = true;
831  }
832  } // loop over optical hit list
833 
834  if(found_tof){
835  if(frm_trk){
836  Lhit_tof_crt_hits[index].push_back(crt);
837  Lhit_tof_op_hits[index].push_back(opHitList[ophit_index]);
838  }
839 
840  else{
841  fLhit_tof_vec.push_back(crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-fOpDelay));
842  fLhit_frmtrk_vec.push_back(false);
843  fLhit_frmhit_vec.push_back(true);
844  fLhit_crthitkey_vec.push_back(crt.key());
845  fLhit_crttrkkey_vec.push_back(-9999);
846  fLhit_crttime_t1_vec.push_back(crt->ts1_ns);
847  fLhit_crttime_t0_vec.push_back(crt->ts0_ns);
848  fLhit_crtpos_X_vec.push_back(crt->x_pos);
849  fLhit_crtpos_Y_vec.push_back(crt->y_pos);
850  fLhit_crtpos_Z_vec.push_back(crt->z_pos);
851  fLhit_crtpe_vec.push_back(crt->peshit);
852  fLhit_crttgr_vec.push_back(crt->tagger);
853  fLhit_pmthitkey_vec.push_back(ophit_index);
854  fLhit_pmthitT_vec.push_back(opHitList[ophit_index]->PeakTime()*1e3-fOpDelay);
855  double pos[3];
856  fGeometryService->OpDetGeoFromOpChannel(opHitList[ophit_index]->OpChannel()).GetCenter(pos);
857  fLhit_pmthitX_vec.push_back(pos[0]);
858  fLhit_pmthitY_vec.push_back(pos[1]);
859  fLhit_pmthitZ_vec.push_back(pos[2]);
860  fLhit_pmthitpe_vec.push_back(opHitList[ophit_index]->PE());
861  //std::cout << "CRT time : " << crt->ts1_ns << " CRT PE : " << crt->peshit << " CRT Tagger : " << crt->tagger << "\n";
862  }
863  }
864  }
865 
866  //===============================================================================================
867 
868  //============================== Calculating ToF using closest optical hit ======================
869 
870  if(fChit){
871  double ophit_minTOF = DBL_MAX;
872  bool found_tof = false;
873  int ophit_index = -1;
874 
875  art::Handle< std::vector<recob::OpHit> > opHitListHandle;
876  std::vector< art::Ptr<recob::OpHit> > opHitList;
877  if( evt.getByLabel(fOpHitModuleLabel,opHitListHandle) )
878  art::fill_ptr_vector(opHitList, opHitListHandle);
879 
880  for(auto const& hit : opHitList){
881  if(hit->PE()<fHitPeThresh) continue;
882  double thit = hit->PeakTime()*1e3-fOpDelay;
883 
884  if(abs(crt->ts1_ns-thit)<fCoinWindow && abs(crt->ts1_ns-thit)<ophit_minTOF){
885  ophit_minTOF = abs(crt->ts1_ns-thit);
886  ophit_index = hit.key();
887  found_tof = true;
888  }
889  } // loop over optical hit list
890 
891  if(found_tof){
892  if(frm_trk){
893  Chit_tof_crt_hits[index].push_back(crt);
894  Chit_tof_op_hits[index].push_back(opHitList[ophit_index]);
895  }
896 
897  else{
898  fChit_tof_vec.push_back(crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-fOpDelay));
899  fChit_frmtrk_vec.push_back(false);
900  fChit_frmhit_vec.push_back(true);
901  fChit_crthitkey_vec.push_back(crt.key());
902  fChit_crttrkkey_vec.push_back(-9999);
903  fChit_crttime_t1_vec.push_back(crt->ts1_ns);
904  fChit_crttime_t0_vec.push_back(crt->ts0_ns);
905  fChit_crtpos_X_vec.push_back(crt->x_pos);
906  fChit_crtpos_Y_vec.push_back(crt->y_pos);
907  fChit_crtpos_Z_vec.push_back(crt->z_pos);
908  fChit_crtpe_vec.push_back(crt->peshit);
909  fChit_crttgr_vec.push_back(crt->tagger);
910  fChit_pmthitkey_vec.push_back(ophit_index);
911  fChit_pmthitT_vec.push_back(opHitList[ophit_index]->PeakTime()*1e3-fOpDelay);
912  double pos[3];
913  fGeometryService->OpDetGeoFromOpChannel(opHitList[ophit_index]->OpChannel()).GetCenter(pos);
914  fChit_pmthitX_vec.push_back(pos[0]);
915  fChit_pmthitY_vec.push_back(pos[1]);
916  fChit_pmthitZ_vec.push_back(pos[2]);
917  fChit_pmthitpe_vec.push_back(opHitList[ophit_index]->PE());
918  }
919  }
920  }
921 
922  //===============================================================================================
923 
924  //============================== Calculating ToF using largest flash ============================
925 
926  if(fLFlash){
927  double peflash_max=0;
928  bool found_tof = false;
929  int opflash_index = -1;
930  int flash_tpc = -1;
931 
932  std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
933  std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
934 
935  for(int i=0; i<2; i++) {
936  if( evt.getByLabel(fFlashLabels[i],flashHandles[i]) )
937  art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
938  }
939 
940  for(auto const& flashList : opFlashLists){
941  for(size_t iflash=0; iflash<flashList.second.size(); iflash++){
942  auto const& flash = flashList.second[iflash];
943  if(flash->TotalPE()<fFlashPeThresh) continue;
944  double tflash = flash->AbsTime()*1e3-fOpDelay;
945  if(abs(crt->ts1_ns-tflash)<fCoinWindow && flash->TotalPE()>peflash_max){
946  peflash_max=flash->TotalPE();
947  opflash_index = flash.key();
948  found_tof = true;
949  flash_tpc = flashList.first;
950  }
951  }
952  }
953 
954  if(found_tof){
955  if(frm_trk){
956  Lflsh_tof_crt_hits[index].push_back(crt);
957  Lflsh_tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
958  Lflsh_tof_op_tpc[index].push_back(flash_tpc);
959  }
960  else{
961  fLflsh_tof_vec.push_back(crt->ts1_ns - (opFlashLists[flash_tpc][opflash_index]->Time()*1e3-fOpDelay));
962  fLflsh_frmtrk_vec.push_back(false);
963  fLflsh_frmhit_vec.push_back(true);
964  fLflsh_crthitkey_vec.push_back(crt.key());
965  fLflsh_crttrkkey_vec.push_back(-9999);
966  fLflsh_crttime_t1_vec.push_back(crt->ts1_ns);
967  fLflsh_crttime_t0_vec.push_back(crt->ts0_ns);
968  fLflsh_crtpos_X_vec.push_back(crt->x_pos);
969  fLflsh_crtpos_Y_vec.push_back(crt->y_pos);
970  fLflsh_crtpos_Z_vec.push_back(crt->z_pos);
971  fLflsh_crtpe_vec.push_back(crt->peshit);
972  fLflsh_crttgr_vec.push_back(crt->tagger);
973  fLflsh_pmtflshtpcID_vec.push_back(flash_tpc);
974  fLflsh_pmtflshkey_vec.push_back(opflash_index);
975  fLflsh_pmtflshT_vec.push_back(opFlashLists[flash_tpc][opflash_index]->Time()*1e3-fOpDelay);
976  fLflsh_pmtflshY_vec.push_back(opFlashLists[flash_tpc][opflash_index]->YCenter());
977  fLflsh_pmtflshZ_vec.push_back(opFlashLists[flash_tpc][opflash_index]->ZCenter());
978  fLflsh_pmtflshpe_vec.push_back(opFlashLists[flash_tpc][opflash_index]->TotalPE());
979  }
980  }
981  }
982 
983  //===============================================================================================
984 
985  //============================== Calculating ToF using closest flash ============================
986 
987  if(fCFlash){
988  double flash_minTOF = DBL_MAX;
989  bool found_tof = false;
990  int opflash_index = -1;
991  int flash_tpc = -1;
992 
993  std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
994  std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
995 
996  for(int i=0; i<2; i++) {
997  if( evt.getByLabel(fFlashLabels[i],flashHandles[i]) )
998  art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
999  }
1000 
1001  for(auto const& flashList : opFlashLists){
1002  for(size_t iflash=0; iflash<flashList.second.size(); iflash++){
1003  auto const& flash = flashList.second[iflash];
1004  if(flash->TotalPE()<fFlashPeThresh) continue;
1005  double tflash = flash->Time()*1e3-fOpDelay;
1006  if(abs(crt->ts1_ns-tflash)<fCoinWindow && abs(crt->ts1_ns-tflash)<flash_minTOF){
1007  flash_minTOF= abs(crt->ts1_ns-tflash);
1008  opflash_index = flash.key();
1009  found_tof = true;
1010  flash_tpc = flashList.first;
1011  }
1012  }
1013  }
1014 
1015  if(found_tof){
1016  if(frm_trk){
1017  Cflsh_tof_crt_hits[index].push_back(crt);
1018  Cflsh_tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
1019  Cflsh_tof_op_tpc[index].push_back(flash_tpc);
1020  }
1021  else{
1022  fCflsh_tof_vec.push_back(crt->ts1_ns - (opFlashLists[flash_tpc][opflash_index]->Time()*1e3-fOpDelay));
1023  fCflsh_frmtrk_vec.push_back(false);
1024  fCflsh_frmhit_vec.push_back(true);
1025  fCflsh_crthitkey_vec.push_back(crt.key());
1026  fCflsh_crttrkkey_vec.push_back(-9999);
1027  fCflsh_crttime_t1_vec.push_back(crt->ts1_ns);
1028  fCflsh_crttime_t0_vec.push_back(crt->ts0_ns);
1029  fCflsh_crtpos_X_vec.push_back(crt->x_pos);
1030  fCflsh_crtpos_Y_vec.push_back(crt->y_pos);
1031  fCflsh_crtpos_Z_vec.push_back(crt->z_pos);
1032  fCflsh_crtpe_vec.push_back(crt->peshit);
1033  fCflsh_crttgr_vec.push_back(crt->tagger);
1034  fCflsh_pmtflshtpcID_vec.push_back(flash_tpc);
1035  fCflsh_pmtflshkey_vec.push_back(opflash_index);
1036  fCflsh_pmtflshT_vec.push_back(opFlashLists[flash_tpc][opflash_index]->Time()*1e3-fOpDelay);
1037  fCflsh_pmtflshY_vec.push_back(opFlashLists[flash_tpc][opflash_index]->YCenter());
1038  fCflsh_pmtflshZ_vec.push_back(opFlashLists[flash_tpc][opflash_index]->ZCenter());
1039  fCflsh_pmtflshpe_vec.push_back(opFlashLists[flash_tpc][opflash_index]->TotalPE());
1040  }
1041  }
1042  }
1043 
1044  //===============================================================================================
1045 
1046  //================ Calculating ToF using earliest hit of the largest flash ======================
1047 
1048  if(fLFlash_hit){
1049  double peflash_max=0;
1050  bool found_tof = false;
1051  int opflash_index = -1;
1052  int flash_tpc = -1;
1053  int ophit_index = -1;
1054 
1055  std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
1056  std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
1057 
1058  for(int i=0; i<2; i++) {
1059  if( evt.getByLabel(fFlashLabels[i],flashHandles[i]) )
1060  art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
1061  }
1062 
1063  art::Handle< std::vector<recob::OpHit> > opHitListHandle;
1064  std::vector< art::Ptr<recob::OpHit> > opHitList;
1065  if( evt.getByLabel(fOpHitModuleLabel,opHitListHandle) )
1066  art::fill_ptr_vector(opHitList, opHitListHandle);
1067 
1068  for(auto const& flashList : opFlashLists){
1069  art::FindManyP<recob::OpHit> findManyOpHits(flashHandles[flashList.first], evt, fFlashLabels[flashList.first]);
1070  for(size_t iflash=0; iflash<flashList.second.size(); iflash++){
1071  auto const& flash = flashList.second[iflash];
1072  if(flash->TotalPE()<fFlashPeThresh) continue;
1073  double tflash = flash->AbsTime()*1e3-fOpDelay;
1074  if(abs(crt->ts1_ns-tflash)<fCoinWindow && flash->TotalPE()>peflash_max){
1075  peflash_max=flash->TotalPE();
1076  opflash_index = flash.key();
1077  found_tof = true;
1078  flash_tpc = flashList.first;
1079  vector<art::Ptr<recob::OpHit>> hits = findManyOpHits.at(flash.key());
1080  double flashMinHitT = DBL_MAX;
1081  for(auto const& hit : hits){
1082  double tPmt = hit->PeakTime()*1e3-fOpDelay;
1083  if(tPmt < flashMinHitT){
1084  flashMinHitT = tPmt;
1085  ophit_index = hit.key();
1086  } // getting the earliest hit
1087  } // loop over associated ophits of the flash
1088  } // with in conincidence window and getting the largest flash
1089  } // loop over flash list
1090  } // loop over flash list map
1091 
1092  if(found_tof){
1093  if(frm_trk){
1094  Lflshhit_tof_crt_hits[index].push_back(crt);
1095  Lflshhit_tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
1096  Lflshhit_tof_op_tpc[index].push_back(flash_tpc);
1097  Lflshhit_tof_op_hits[index].push_back(opHitList[ophit_index]);
1098  }
1099 
1100  else{
1101  fLflshhit_tof_vec.push_back(crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-fOpDelay));
1102  fLflshhit_frmtrk_vec.push_back(false);
1103  fLflshhit_frmhit_vec.push_back(true);
1104  fLflshhit_crthitkey_vec.push_back(crt.key());
1105  fLflshhit_crttrkkey_vec.push_back(-9999);
1106  fLflshhit_crttime_t1_vec.push_back(crt->ts1_ns);
1107  fLflshhit_crttime_t0_vec.push_back(crt->ts0_ns);
1108  fLflshhit_crtpos_X_vec.push_back(crt->x_pos);
1109  fLflshhit_crtpos_Y_vec.push_back(crt->y_pos);
1110  fLflshhit_crtpos_Z_vec.push_back(crt->z_pos);
1111  fLflshhit_crtpe_vec.push_back(crt->peshit);
1112  fLflshhit_crttgr_vec.push_back(crt->tagger);
1113  fLflshhit_pmtflshtpcID_vec.push_back(flash_tpc);
1114  fLflshhit_pmtflshkey_vec.push_back(opflash_index);
1115  fLflshhit_pmtkey_vec.push_back(ophit_index);
1116  fLflshhit_pmtflshT_vec.push_back(opHitList[ophit_index]->PeakTime()*1e3-fOpDelay);
1117  double pos[3];
1118  fGeometryService->OpDetGeoFromOpChannel(opHitList[ophit_index]->OpChannel()).GetCenter(pos);
1119  fLflshhit_pmtflshX_vec.push_back(pos[0]);
1120  fLflshhit_pmtflshY_vec.push_back(pos[1]);
1121  fLflshhit_pmtflshZ_vec.push_back(pos[2]);
1122  fLflshhit_pmtflshpe_vec.push_back(opHitList[ophit_index]->PE());
1123  }
1124  }
1125  }
1126 
1127  //===============================================================================================
1128 
1129  //================ Calculating ToF using earliest hit of the closest flash ======================
1130 
1131  if(fCFlash_hit){
1132  double flash_minTOF = DBL_MAX;
1133  bool found_tof = false;
1134  int opflash_index = -1;
1135  int flash_tpc = -1;
1136  int ophit_index = -1;
1137 
1138  std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
1139  std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
1140 
1141  for(int i=0; i<2; i++) {
1142  if( evt.getByLabel(fFlashLabels[i],flashHandles[i]) )
1143  art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
1144  }
1145 
1146  art::Handle< std::vector<recob::OpHit> > opHitListHandle;
1147  std::vector< art::Ptr<recob::OpHit> > opHitList;
1148  if( evt.getByLabel(fOpHitModuleLabel,opHitListHandle) )
1149  art::fill_ptr_vector(opHitList, opHitListHandle);
1150 
1151  for(auto const& flashList : opFlashLists){
1152  art::FindManyP<recob::OpHit> findManyOpHits(flashHandles[flashList.first], evt, fFlashLabels[flashList.first]);
1153  for(size_t iflash=0; iflash<flashList.second.size(); iflash++){
1154  auto const& flash = flashList.second[iflash];
1155  if(flash->TotalPE()<fFlashPeThresh) continue;
1156  double tflash = flash->AbsTime()*1e3-fOpDelay;
1157  if(abs(crt->ts1_ns-tflash)<fCoinWindow && abs(crt->ts1_ns-tflash)<flash_minTOF){
1158  flash_minTOF= abs(crt->ts1_ns-tflash);
1159  opflash_index = flash.key();
1160  found_tof = true;
1161  flash_tpc = flashList.first;
1162  vector<art::Ptr<recob::OpHit>> hits = findManyOpHits.at(flash.key());
1163  double flashMinHitT = DBL_MAX;
1164  for(auto const& hit : hits){
1165  double tPmt = hit->PeakTime()*1e3-fOpDelay;
1166  if(tPmt < flashMinHitT){
1167  flashMinHitT = tPmt;
1168  ophit_index = hit.key();
1169  } // getting the earliest hit
1170  } // loop over associated ophits of the flash
1171  } // with in conincidence window and getting the largest flash
1172  } // loop over flash list
1173  } // loop over flash list map
1174 
1175  if(found_tof){
1176  if(frm_trk){
1177  Cflshhit_tof_crt_hits[index].push_back(crt);
1178  Cflshhit_tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
1179  Cflshhit_tof_op_tpc[index].push_back(flash_tpc);
1180  Cflshhit_tof_op_hits[index].push_back(opHitList[ophit_index]);
1181  }
1182 
1183  else{
1184  fCflshhit_tof_vec.push_back(crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-fOpDelay));
1185  fCflshhit_frmtrk_vec.push_back(false);
1186  fCflshhit_frmhit_vec.push_back(true);
1187  fCflshhit_crthitkey_vec.push_back(crt.key());
1188  fCflshhit_crttrkkey_vec.push_back(-9999);
1189  fCflshhit_crttime_t1_vec.push_back(crt->ts1_ns);
1190  fCflshhit_crttime_t0_vec.push_back(crt->ts0_ns);
1191  fCflshhit_crtpos_X_vec.push_back(crt->x_pos);
1192  fCflshhit_crtpos_Y_vec.push_back(crt->y_pos);
1193  fCflshhit_crtpos_Z_vec.push_back(crt->z_pos);
1194  fCflshhit_crtpe_vec.push_back(crt->peshit);
1195  fCflshhit_crttgr_vec.push_back(crt->tagger);
1196  fCflshhit_pmtflshtpcID_vec.push_back(flash_tpc);
1197  fCflshhit_pmtflshkey_vec.push_back(opflash_index);
1198  fCflshhit_pmtkey_vec.push_back(ophit_index);
1199  fCflshhit_pmtflshT_vec.push_back(opHitList[ophit_index]->PeakTime()*1e3-fOpDelay);
1200  double pos[3];
1201  fGeometryService->OpDetGeoFromOpChannel(opHitList[ophit_index]->OpChannel()).GetCenter(pos);
1202  fCflshhit_pmtflshX_vec.push_back(pos[0]);
1203  fCflshhit_pmtflshY_vec.push_back(pos[1]);
1204  fCflshhit_pmtflshZ_vec.push_back(pos[2]);
1205  fCflshhit_pmtflshpe_vec.push_back(opHitList[ophit_index]->PE());
1206  }
1207  }
1208  }
1209 
1210  //===============================================================================================
1211 
1212  } // loop over CRT hits
1213 
1214 
1215  //============================== Calculating ToF using largest optical hit =========================
1216 
1217  if(fLhit){
1218  if(!Lhit_tof_crt_hits.empty()){
1219  for (auto& ele: Lhit_tof_crt_hits){
1220  double min_time = DBL_MAX;
1221  int all_index = 0;
1222  int min_index = 0;
1223  for (auto const& hit: ele.second){
1224  if(hit->ts1_ns < min_time){
1225  min_time = hit->ts1_ns;
1226  min_index = all_index;
1227  }
1228  all_index++;
1229  }
1230 
1231  fLhit_tof_vec.push_back(trackhits[ele.first].front()->ts1_ns - (Lhit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay));
1232  fLhit_frmtrk_vec.push_back(true);
1233  fLhit_frmhit_vec.push_back(false);
1234  fLhit_crthitkey_vec.push_back(trackhits[ele.first].front().key());
1235  fLhit_crttrkkey_vec.push_back(ele.first);
1236  fLhit_crttime_t1_vec.push_back(trackhits[ele.first].front()->ts1_ns);
1237  fLhit_crttime_t0_vec.push_back(trackhits[ele.first].front()->ts0_ns);
1238  fLhit_crtpos_X_vec.push_back(trackhits[ele.first].front()->x_pos);
1239  fLhit_crtpos_Y_vec.push_back(trackhits[ele.first].front()->y_pos);
1240  fLhit_crtpos_Z_vec.push_back(trackhits[ele.first].front()->z_pos);
1241  fLhit_crtpe_vec.push_back(trackhits[ele.first].front()->peshit);
1242  fLhit_crttgr_vec.push_back(trackhits[ele.first].front()->tagger);
1243  fLhit_pmthitkey_vec.push_back(Lhit_tof_op_hits[ele.first][min_index].key());
1244  fLhit_pmthitT_vec.push_back(Lhit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay);
1245  double pos[3];
1246  fGeometryService->OpDetGeoFromOpChannel(Lhit_tof_op_hits[ele.first][min_index]->OpChannel()).GetCenter(pos);
1247  fLhit_pmthitX_vec.push_back(pos[0]);
1248  fLhit_pmthitY_vec.push_back(pos[1]);
1249  fLhit_pmthitZ_vec.push_back(pos[2]);
1250  fLhit_pmthitpe_vec.push_back(Lhit_tof_op_hits[ele.first][min_index]->PE());
1251  }
1252  }
1253  }
1254 
1255  //==================================================================================================
1256 
1257  //============================== Calculating ToF using closest optical hit =========================
1258 
1259  if(fChit){
1260  if(!Chit_tof_crt_hits.empty()){
1261  for (auto& ele: Chit_tof_crt_hits){
1262  double min_time = DBL_MAX;
1263  int all_index = 0;
1264  int min_index = 0;
1265  for (auto const& hit: ele.second){
1266  if(hit->ts1_ns < min_time){
1267  min_time = hit->ts1_ns;
1268  min_index = all_index;
1269  }
1270  all_index++;
1271  }
1272 
1273  fChit_tof_vec.push_back(trackhits[ele.first].front()->ts1_ns - (Chit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay));
1274  fChit_frmtrk_vec.push_back(true);
1275  fChit_frmhit_vec.push_back(false);
1276  fChit_crthitkey_vec.push_back(trackhits[ele.first].front().key());
1277  fChit_crttrkkey_vec.push_back(ele.first);
1278  fChit_crttime_t1_vec.push_back(trackhits[ele.first].front()->ts1_ns);
1279  fChit_crttime_t0_vec.push_back(trackhits[ele.first].front()->ts0_ns);
1280  fChit_crtpos_X_vec.push_back(trackhits[ele.first].front()->x_pos);
1281  fChit_crtpos_Y_vec.push_back(trackhits[ele.first].front()->y_pos);
1282  fChit_crtpos_Z_vec.push_back(trackhits[ele.first].front()->z_pos);
1283  fChit_crtpe_vec.push_back(trackhits[ele.first].front()->peshit);
1284  fChit_crttgr_vec.push_back(trackhits[ele.first].front()->tagger);
1285  fChit_pmthitkey_vec.push_back(Chit_tof_op_hits[ele.first][min_index].key());
1286  fChit_pmthitT_vec.push_back(Chit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay);
1287  double pos[3];
1288  fGeometryService->OpDetGeoFromOpChannel(Chit_tof_op_hits[ele.first][min_index]->OpChannel()).GetCenter(pos);
1289  fChit_pmthitX_vec.push_back(pos[0]);
1290  fChit_pmthitY_vec.push_back(pos[1]);
1291  fChit_pmthitZ_vec.push_back(pos[2]);
1292  fChit_pmthitpe_vec.push_back(Chit_tof_op_hits[ele.first][min_index]->PE());
1293  }
1294  }
1295  }
1296 
1297  //==================================================================================================
1298 
1299  //============================== Calculating ToF using largest optical flash =======================
1300 
1301  if(fLFlash){
1302  if(!Lflsh_tof_crt_hits.empty()){
1303  for (auto& ele: Lflsh_tof_crt_hits){
1304  double min_time = DBL_MAX;
1305  int all_index = 0;
1306  int min_index = 0;
1307  for (auto const& hit: ele.second){
1308  if(hit->ts1_ns < min_time){
1309  min_time = hit->ts1_ns;
1310  min_index = all_index;
1311  }
1312  all_index++;
1313  }
1314 
1315  fLflsh_tof_vec.push_back(trackhits[ele.first].front()->ts1_ns - (Lflsh_tof_op_flashes[ele.first][min_index]->Time()*1e3-fOpDelay));
1316  fLflsh_frmtrk_vec.push_back(true);
1317  fLflsh_frmhit_vec.push_back(false);
1318  fLflsh_crthitkey_vec.push_back(trackhits[ele.first].front().key());
1319  fLflsh_crttrkkey_vec.push_back(ele.first);
1320  fLflsh_crttime_t1_vec.push_back(trackhits[ele.first].front()->ts1_ns);
1321  fLflsh_crttime_t0_vec.push_back(trackhits[ele.first].front()->ts0_ns);
1322  fLflsh_crtpos_X_vec.push_back(trackhits[ele.first].front()->x_pos);
1323  fLflsh_crtpos_Y_vec.push_back(trackhits[ele.first].front()->y_pos);
1324  fLflsh_crtpos_Z_vec.push_back(trackhits[ele.first].front()->z_pos);
1325  fLflsh_crtpe_vec.push_back(trackhits[ele.first].front()->peshit);
1326  fLflsh_crttgr_vec.push_back(trackhits[ele.first].front()->tagger);
1327  fLflsh_pmtflshtpcID_vec.push_back(Lflsh_tof_op_tpc[ele.first][min_index]);
1328  fLflsh_pmtflshkey_vec.push_back(Lflsh_tof_op_flashes[ele.first][min_index].key());
1329  fLflsh_pmtflshT_vec.push_back(Lflsh_tof_op_flashes[ele.first][min_index]->Time()*1e3-fOpDelay);
1330  fLflsh_pmtflshY_vec.push_back(Lflsh_tof_op_flashes[ele.first][min_index]->YCenter());
1331  fLflsh_pmtflshZ_vec.push_back(Lflsh_tof_op_flashes[ele.first][min_index]->ZCenter());
1332  fLflsh_pmtflshpe_vec.push_back(Lflsh_tof_op_flashes[ele.first][min_index]->TotalPE());
1333  }
1334  }
1335  }
1336 
1337  //==================================================================================================
1338 
1339  //============================== Calculating ToF using closest optical flash =======================
1340 
1341  if(fCFlash){
1342  if(!Cflsh_tof_crt_hits.empty()){
1343  for (auto& ele: Cflsh_tof_crt_hits){
1344  double min_time = DBL_MAX;
1345  int all_index = 0;
1346  int min_index = 0;
1347  for (auto const& hit: ele.second){
1348  if(hit->ts1_ns < min_time){
1349  min_time = hit->ts1_ns;
1350  min_index = all_index;
1351  }
1352  all_index++;
1353  }
1354 
1355  fCflsh_tof_vec.push_back(trackhits[ele.first].front()->ts1_ns - (Cflsh_tof_op_flashes[ele.first][min_index]->Time()*1e3-fOpDelay));
1356  fCflsh_frmtrk_vec.push_back(true);
1357  fCflsh_frmhit_vec.push_back(false);
1358  fCflsh_crthitkey_vec.push_back(trackhits[ele.first].front().key());
1359  fCflsh_crttrkkey_vec.push_back(ele.first);
1360  fCflsh_crttime_t1_vec.push_back(trackhits[ele.first].front()->ts1_ns);
1361  fCflsh_crttime_t0_vec.push_back(trackhits[ele.first].front()->ts0_ns);
1362  fCflsh_crtpos_X_vec.push_back(trackhits[ele.first].front()->x_pos);
1363  fCflsh_crtpos_Y_vec.push_back(trackhits[ele.first].front()->y_pos);
1364  fCflsh_crtpos_Z_vec.push_back(trackhits[ele.first].front()->z_pos);
1365  fCflsh_crtpe_vec.push_back(trackhits[ele.first].front()->peshit);
1366  fCflsh_crttgr_vec.push_back(trackhits[ele.first].front()->tagger);
1367  fCflsh_pmtflshtpcID_vec.push_back(Cflsh_tof_op_tpc[ele.first][min_index]);
1368  fCflsh_pmtflshkey_vec.push_back(Cflsh_tof_op_flashes[ele.first][min_index].key());
1369  fCflsh_pmtflshT_vec.push_back(Cflsh_tof_op_flashes[ele.first][min_index]->Time()*1e3-fOpDelay);
1370  fCflsh_pmtflshY_vec.push_back(Cflsh_tof_op_flashes[ele.first][min_index]->YCenter());
1371  fCflsh_pmtflshZ_vec.push_back(Cflsh_tof_op_flashes[ele.first][min_index]->ZCenter());
1372  fCflsh_pmtflshpe_vec.push_back(Cflsh_tof_op_flashes[ele.first][min_index]->TotalPE());
1373  }
1374  }
1375  }
1376 
1377  //==================================================================================================
1378 
1379  //=============Calculation ToF values using Earliest hit of the Largest flash =====================
1380 
1381  if(fLFlash_hit){
1382  if(!Lflshhit_tof_crt_hits.empty()){
1383  for (auto& ele: Lflshhit_tof_crt_hits){
1384  double min_time = DBL_MAX;
1385  int all_index = 0;
1386  int min_index = 0;
1387  for (auto const& hit: ele.second){
1388  if(hit->ts1_ns < min_time){
1389  min_time = hit->ts1_ns;
1390  min_index = all_index;
1391  }
1392  all_index++;
1393  }
1394 
1395  fLflshhit_tof_vec.push_back(trackhits[ele.first].front()->ts1_ns - (Lflshhit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay));
1396  fLflshhit_frmtrk_vec.push_back(true);
1397  fLflshhit_frmhit_vec.push_back(false);
1398  fLflshhit_crthitkey_vec.push_back(trackhits[ele.first].front().key());
1399  fLflshhit_crttrkkey_vec.push_back(ele.first);
1400  fLflshhit_crttime_t1_vec.push_back(trackhits[ele.first].front()->ts1_ns);
1401  fLflshhit_crttime_t0_vec.push_back(trackhits[ele.first].front()->ts0_ns);
1402  fLflshhit_crtpos_X_vec.push_back(trackhits[ele.first].front()->x_pos);
1403  fLflshhit_crtpos_Y_vec.push_back(trackhits[ele.first].front()->y_pos);
1404  fLflshhit_crtpos_Z_vec.push_back(trackhits[ele.first].front()->z_pos);
1405  fLflshhit_crtpe_vec.push_back(trackhits[ele.first].front()->peshit);
1406  fLflshhit_crttgr_vec.push_back(trackhits[ele.first].front()->tagger);
1407  fLflshhit_pmtflshtpcID_vec.push_back(Lflshhit_tof_op_tpc[ele.first][min_index]);
1408  fLflshhit_pmtflshkey_vec.push_back(Lflshhit_tof_op_flashes[ele.first][min_index].key());
1409  fLflshhit_pmtkey_vec.push_back(Lflshhit_tof_op_hits[ele.first][min_index].key());
1410  fLflshhit_pmtflshT_vec.push_back(Lflshhit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay);
1411  double pos[3];
1412  fGeometryService->OpDetGeoFromOpChannel(Lflshhit_tof_op_hits[ele.first][min_index]->OpChannel()).GetCenter(pos);
1413  fLflshhit_pmtflshX_vec.push_back(pos[0]);
1414  fLflshhit_pmtflshY_vec.push_back(pos[1]);
1415  fLflshhit_pmtflshZ_vec.push_back(pos[2]);
1416  fLflshhit_pmtflshpe_vec.push_back(Lflshhit_tof_op_hits[ele.first][min_index]->PE());
1417  }
1418  }
1419  }
1420 
1421  //===================================================================================================
1422 
1423  //=============Calculation ToF values using Earliest hit of the Closest flash =======================
1424 
1425  if(fCFlash_hit){
1426  if(!Cflshhit_tof_crt_hits.empty()){
1427  for (auto& ele: Cflshhit_tof_crt_hits){
1428  double min_time = DBL_MAX;
1429  int all_index = 0;
1430  int min_index = 0;
1431  for (auto const& hit: ele.second){
1432  if(hit->ts1_ns < min_time){
1433  min_time = hit->ts1_ns;
1434  min_index = all_index;
1435  }
1436  all_index++;
1437  }
1438 
1439  fCflshhit_tof_vec.push_back(trackhits[ele.first].front()->ts1_ns - (Cflshhit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay));
1440  fCflshhit_frmtrk_vec.push_back(true);
1441  fCflshhit_frmhit_vec.push_back(false);
1442  fCflshhit_crthitkey_vec.push_back(trackhits[ele.first].front().key());
1443  fCflshhit_crttrkkey_vec.push_back(ele.first);
1444  fCflshhit_crttime_t1_vec.push_back(trackhits[ele.first].front()->ts1_ns);
1445  fCflshhit_crttime_t0_vec.push_back(trackhits[ele.first].front()->ts0_ns);
1446  fCflshhit_crtpos_X_vec.push_back(trackhits[ele.first].front()->x_pos);
1447  fCflshhit_crtpos_Y_vec.push_back(trackhits[ele.first].front()->y_pos);
1448  fCflshhit_crtpos_Z_vec.push_back(trackhits[ele.first].front()->z_pos);
1449  fCflshhit_crtpe_vec.push_back(trackhits[ele.first].front()->peshit);
1450  fCflshhit_crttgr_vec.push_back(trackhits[ele.first].front()->tagger);
1451  fCflshhit_pmtflshtpcID_vec.push_back(Cflshhit_tof_op_tpc[ele.first][min_index]);
1452  fCflshhit_pmtflshkey_vec.push_back(Cflshhit_tof_op_flashes[ele.first][min_index].key());
1453  fCflshhit_pmtkey_vec.push_back(Cflshhit_tof_op_hits[ele.first][min_index].key());
1454  fCflshhit_pmtflshT_vec.push_back(Cflshhit_tof_op_hits[ele.first][min_index]->PeakTime()*1e3-fOpDelay);
1455  double pos[3];
1456  fGeometryService->OpDetGeoFromOpChannel(Cflshhit_tof_op_hits[ele.first][min_index]->OpChannel()).GetCenter(pos);
1457  fCflshhit_pmtflshX_vec.push_back(pos[0]);
1458  fCflshhit_pmtflshY_vec.push_back(pos[1]);
1459  fCflshhit_pmtflshZ_vec.push_back(pos[2]);
1460  fCflshhit_pmtflshpe_vec.push_back(Cflshhit_tof_op_hits[ele.first][min_index]->PE());
1461  }
1462  }
1463  }
1464 
1465  //===================================================================================================
1466 
1467  //=============Calculation ToF values uisng truth level information ================================
1468 
1469  if(fSaveTrueToFInfo){
1470  if(!True_tof_crt_hits.empty()){
1471  const cheat::ParticleInventory *inventory_service=lar::providerFrom<cheat::ParticleInventoryService>();
1472  for (auto& ele: True_tof_crt_hits){
1473  double min_time = DBL_MAX;
1474  int all_index = 0;
1475  int min_index = 0;
1476  for (auto const& hit: ele.second){
1477  if(hit->ts1_ns < min_time){
1478  min_time = hit->ts1_ns;
1479  min_index = all_index;
1480  }
1481  all_index++;
1482  }
1483 
1484  bool found_tpc_traj_point=false;
1485  for(size_t i=0; i<True_tof_sim_particles[ele.first][min_index]->NumberTrajectoryPoints(); i++){
1486  const TLorentzVector& pos = True_tof_sim_particles[ele.first][min_index]->Position(i);
1487  double point[3] = {pos.X(),pos.Y(),pos.Z()};
1488  if(tpc00.ContainsPosition(point) || tpc01.ContainsPosition(point)){
1489  double opDetPos[3];
1490  (cryo0.OpDet(cryo0.GetClosestOpDet(point))).GetCenter(opDetPos);
1491  double dprop=sqrt(pow(opDetPos[0]-pos[0],2) + pow(opDetPos[1]-pos[1],2) + pow(opDetPos[2]-pos[2],2));
1492  double tprop=pos.T() + dprop*LAR_PROP_DELAY;
1493  fTrue_TOF.push_back(trackhits[ele.first].front()->ts1_ns-tprop);
1494  fTrue_TOF_hit.push_back(false);
1495  fTrue_TOF_pdg.push_back(True_tof_sim_particles[ele.first][min_index]->PdgCode());
1496  fTrue_TOF_part_ID.push_back(True_tof_sim_particles[ele.first][min_index]->TrackId());
1497  if(True_tof_sim_particles[ele.first][min_index]->Process()=="primary") fTrue_TOF_part_prim.push_back(true);
1498  else fTrue_TOF_part_prim.push_back(false);
1499  art::Ptr<simb::MCTruth> truth=inventory_service->TrackIdToMCTruth_P(True_tof_sim_particles[ele.first][min_index]->TrackId());
1500  fTrue_TOF_part_org.push_back(truth->NeutrinoSet());
1501  fTrue_TOF_traj_T.push_back(pos.T());
1502  fTrue_TOF_traj_X.push_back(point[0]);
1503  fTrue_TOF_traj_Y.push_back(point[1]);
1504  fTrue_TOF_traj_Z.push_back(point[2]);
1505  fTrue_TOF_traj_in_TPC.push_back(true);
1506  found_tpc_traj_point=true;
1507  break;
1508  } // trajectory point is in TPC
1509  } // loop over trajectory points
1510 
1511  if(!found_tpc_traj_point){
1512  for(size_t i=0; i<True_tof_sim_particles[ele.first][min_index]->NumberTrajectoryPoints(); i++){
1513  const TLorentzVector& pos = True_tof_sim_particles[ele.first][min_index]->Position(i);
1514  double point[3] = {pos.X(),pos.Y(),pos.Z()};
1515  if(cryo0.ContainsPosition(point)){
1516  double opDetPos[3];
1517  (cryo0.OpDet(cryo0.GetClosestOpDet(point))).GetCenter(opDetPos);
1518  double dprop=sqrt(pow(opDetPos[0]-pos[0],2) + pow(opDetPos[1]-pos[1],2) + pow(opDetPos[2]-pos[2],2));
1519  double tprop=pos.T() + dprop*LAR_PROP_DELAY;
1520  fTrue_TOF.push_back(trackhits[ele.first].front()->ts1_ns-tprop);
1521  fTrue_TOF_hit.push_back(false);
1522  fTrue_TOF_pdg.push_back(True_tof_sim_particles[ele.first][min_index]->PdgCode());
1523  fTrue_TOF_part_ID.push_back(True_tof_sim_particles[ele.first][min_index]->TrackId());
1524  if(True_tof_sim_particles[ele.first][min_index]->Process()=="primary") fTrue_TOF_part_prim.push_back(true);
1525  else fTrue_TOF_part_prim.push_back(false);
1526  art::Ptr<simb::MCTruth> truth=inventory_service->TrackIdToMCTruth_P(True_tof_sim_particles[ele.first][min_index]->TrackId());
1527  fTrue_TOF_part_org.push_back(truth->NeutrinoSet());
1528  fTrue_TOF_traj_T.push_back(pos.T());
1529  fTrue_TOF_traj_X.push_back(point[0]);
1530  fTrue_TOF_traj_Y.push_back(point[1]);
1531  fTrue_TOF_traj_Z.push_back(point[2]);
1532  fTrue_TOF_traj_in_TPC.push_back(false);
1533  break;
1534  } // found a trajectory point inside CRYO
1535  } // loop over trajectory points
1536  } // did not find a trajectory point inside TPC
1537  }
1538  }
1539  }
1540 
1541  //==================================================================================================
1542 
1543  fMatchTree->Fill();
1544 } // End of Analyze function
1545 
1546 //==========================================================================================
1547 bool ToFAnalyzer::HitCompare(const art::Ptr<CRTHit>& hit1, const art::Ptr<CRTHit>& hit2) {
1548  if(hit1->ts1_ns != hit2->ts1_ns) return false;
1549  if(hit1->plane != hit2->plane) return false;
1550  if(hit1->x_pos != hit2->x_pos) return false;
1551  if(hit1->y_pos != hit2->y_pos) return false;
1552  if(hit1->z_pos != hit2->z_pos) return false;
1553  if(hit1->x_err != hit2->x_err) return false;
1554  if(hit1->y_err != hit2->y_err) return false;
1555  if(hit1->z_err != hit2->z_err) return false;
1556  if(hit1->tagger != hit2->tagger) return false;
1557  return true;
1558 }
1559 //===========================================================================================
1560 
1561 //===========================================================================================
1562 double ToFAnalyzer::length(const simb::MCParticle& part, TVector3& start, TVector3& end)
1563 {
1564  art::ServiceHandle<geo::Geometry> geom;
1565  double xmin = -2.0 * geom->DetHalfWidth();
1566  double xmax = 2.0 * geom->DetHalfWidth();
1567  double ymin = -geom->DetHalfHeight();
1568  double ymax = geom->DetHalfHeight();
1569  double zmin = 0.;
1570  double zmax = geom->DetLength();
1571 
1572  double result = 0.;
1573  TVector3 disp;
1574  int n = part.NumberTrajectoryPoints();
1575  bool first = true;
1576 
1577  for(int i = 0; i < n; ++i) {
1578  double mypos[3] = {part.Vx(i), part.Vy(i), part.Vz(i)};
1579  if(mypos[0] >= xmin && mypos[0] <= xmax && mypos[1] >= ymin && mypos[1] <= ymax && mypos[2] >= zmin && mypos[2] <= zmax){
1580  double xGen = part.Vx(i);
1581  double newX = xGen;
1582 
1583  TVector3 pos(newX,part.Vy(i),part.Vz(i));
1584  if(first){
1585  start = pos;
1586  }
1587  else {
1588  disp -= pos;
1589  result += disp.Mag();
1590  }
1591  first=false;
1592  disp = pos;
1593  end = pos;
1594  }
1595  }
1596  return result;
1597 }
1598 //================================================================================================
1599 
1600 //================================================================================================
1602 {
1603  frun = -9999;
1604  fsubrun = -9999;
1605  fevent = -9999;
1606 
1607  fnu_pdg.clear();
1608  fnu_E.clear();
1609  fnu_mode.clear();
1610  fnu_CCNC.clear();
1611  fnu_posX.clear();
1612  fnu_posY.clear();
1613  fnu_posZ.clear();
1614  fnu_T.clear();
1615  fnu_CRYO.clear();
1616  fnu_TPC.clear();
1617 
1618  fg4_pdg.clear();
1619  fg4_trkid.clear();
1620  fg4st_TPC.clear();
1621  fg4en_TPC.clear();
1622  fg4st_CRYO.clear();
1623  fg4en_CRYO.clear();
1624  fg4is_prim.clear();
1625  fg4_T0.clear();
1626  fg4_T0_CRYO.clear();
1627  fg4_T0_TPC.clear();
1628  fg4_org.clear();
1629  fg4_stX.clear();
1630  fg4_stY.clear();
1631  fg4_stZ.clear();
1632  fg4_enX.clear();
1633  fg4_enY.clear();
1634  fg4_enZ.clear();
1635  fg4_tlen.clear();
1636  fg4_E.clear();
1637  fg4_is_in_TPC.clear();
1638  fg4_is_in_CRYO.clear();
1639 
1640  fLhit_tof_vec.clear();
1641  fLhit_frmtrk_vec.clear();
1642  fLhit_frmhit_vec.clear();
1643  fLhit_crthitkey_vec.clear();
1644  fLhit_crttrkkey_vec.clear();
1645  fLhit_crttime_t1_vec.clear();
1646  fLhit_crttime_t0_vec.clear();
1647  fLhit_crtpos_X_vec.clear();
1648  fLhit_crtpos_Y_vec.clear();
1649  fLhit_crtpos_Z_vec.clear();
1650  fLhit_crtpe_vec.clear();
1651  fLhit_crttgr_vec.clear();
1652  fLhit_pmthitkey_vec.clear();
1653  fLhit_pmthitT_vec.clear();
1654  fLhit_pmthitX_vec.clear();
1655  fLhit_pmthitY_vec.clear();
1656  fLhit_pmthitZ_vec.clear();
1657  fLhit_pmthitpe_vec.clear();
1658 
1659  fChit_tof_vec.clear();
1660  fChit_frmtrk_vec.clear();
1661  fChit_frmhit_vec.clear();
1662  fChit_crthitkey_vec.clear();
1663  fChit_crttrkkey_vec.clear();
1664  fChit_crttime_t1_vec.clear();
1665  fChit_crttime_t0_vec.clear();
1666  fChit_crtpos_X_vec.clear();
1667  fChit_crtpos_Y_vec.clear();
1668  fChit_crtpos_Z_vec.clear();
1669  fChit_crtpe_vec.clear();
1670  fChit_crttgr_vec.clear();
1671  fChit_pmthitkey_vec.clear();
1672  fChit_pmthitT_vec.clear();
1673  fChit_pmthitX_vec.clear();
1674  fChit_pmthitY_vec.clear();
1675  fChit_pmthitZ_vec.clear();
1676  fChit_pmthitpe_vec.clear();
1677 
1678  fLflsh_tof_vec.clear();
1679  fLflsh_frmtrk_vec.clear();
1680  fLflsh_frmhit_vec.clear();
1681  fLflsh_crthitkey_vec.clear();
1682  fLflsh_crttrkkey_vec.clear();
1683  fLflsh_crttime_t1_vec.clear();
1684  fLflsh_crttime_t0_vec.clear();
1685  fLflsh_crtpos_X_vec.clear();
1686  fLflsh_crtpos_Y_vec.clear();
1687  fLflsh_crtpos_Z_vec.clear();
1688  fLflsh_crtpe_vec.clear();
1689  fLflsh_crttgr_vec.clear();
1690  fLflsh_pmtflshtpcID_vec.clear();
1691  fLflsh_pmtflshkey_vec.clear();
1692  fLflsh_pmtflshT_vec.clear();
1693  fLflsh_pmtflshY_vec.clear();
1694  fLflsh_pmtflshZ_vec.clear();
1695  fLflsh_pmtflshpe_vec.clear();
1696 
1697  fCflsh_tof_vec.clear();
1698  fCflsh_frmtrk_vec.clear();
1699  fCflsh_frmhit_vec.clear();
1700  fCflsh_crthitkey_vec.clear();
1701  fCflsh_crttrkkey_vec.clear();
1702  fCflsh_crttime_t1_vec.clear();
1703  fCflsh_crttime_t0_vec.clear();
1704  fCflsh_crtpos_X_vec.clear();
1705  fCflsh_crtpos_Y_vec.clear();
1706  fCflsh_crtpos_Z_vec.clear();
1707  fCflsh_crtpe_vec.clear();
1708  fCflsh_crttgr_vec.clear();
1709  fCflsh_pmtflshtpcID_vec.clear();
1710  fCflsh_pmtflshkey_vec.clear();
1711  fCflsh_pmtflshT_vec.clear();
1712  fCflsh_pmtflshY_vec.clear();
1713  fCflsh_pmtflshZ_vec.clear();
1714  fCflsh_pmtflshpe_vec.clear();
1715 
1716  fLflshhit_tof_vec.clear();
1717  fLflshhit_frmtrk_vec.clear();
1718  fLflshhit_frmhit_vec.clear();
1719  fLflshhit_crthitkey_vec.clear();
1720  fLflshhit_crttrkkey_vec.clear();
1721  fLflshhit_crttime_t1_vec.clear();
1722  fLflshhit_crttime_t0_vec.clear();
1723  fLflshhit_crtpos_X_vec.clear();
1724  fLflshhit_crtpos_Y_vec.clear();
1725  fLflshhit_crtpos_Z_vec.clear();
1726  fLflshhit_crtpe_vec.clear();
1727  fLflshhit_crttgr_vec.clear();
1729  fLflshhit_pmtflshkey_vec.clear();
1730  fLflshhit_pmtkey_vec.clear();
1731  fLflshhit_pmtflshT_vec.clear();
1732  fLflshhit_pmtflshX_vec.clear();
1733  fLflshhit_pmtflshY_vec.clear();
1734  fLflshhit_pmtflshZ_vec.clear();
1735  fLflshhit_pmtflshpe_vec.clear();
1736 
1737  fCflshhit_tof_vec.clear();
1738  fCflshhit_frmtrk_vec.clear();
1739  fCflshhit_frmhit_vec.clear();
1740  fCflshhit_crthitkey_vec.clear();
1741  fCflshhit_crttrkkey_vec.clear();
1742  fCflshhit_crttime_t1_vec.clear();
1743  fCflshhit_crttime_t0_vec.clear();
1744  fCflshhit_crtpos_X_vec.clear();
1745  fCflshhit_crtpos_Y_vec.clear();
1746  fCflshhit_crtpos_Z_vec.clear();
1747  fCflshhit_crtpe_vec.clear();
1748  fCflshhit_crttgr_vec.clear();
1750  fCflshhit_pmtflshkey_vec.clear();
1751  fCflshhit_pmtkey_vec.clear();
1752  fCflshhit_pmtflshT_vec.clear();
1753  fCflshhit_pmtflshX_vec.clear();
1754  fCflshhit_pmtflshY_vec.clear();
1755  fCflshhit_pmtflshZ_vec.clear();
1756  fCflshhit_pmtflshpe_vec.clear();
1757 
1758  fTrue_TOF.clear();
1759  fTrue_TOF_hit.clear();
1760  fTrue_TOF_pdg.clear();
1761  fTrue_TOF_part_ID.clear();
1762  fTrue_TOF_part_prim.clear();
1763  fTrue_TOF_part_org.clear();
1764  fTrue_TOF_traj_T.clear();
1765  fTrue_TOF_traj_X.clear();
1766  fTrue_TOF_traj_Y.clear();
1767  fTrue_TOF_traj_Z.clear();
1768  fTrue_TOF_traj_in_TPC.clear();
1769 }
1770 //================================================================================================
1771 DEFINE_ART_MODULE(ToFAnalyzer)
1772 }
vector< double > fg4_enY
vector< double > fChit_pmthitZ_vec
vector< int > fTrue_TOF_part_ID
unsigned int GetClosestOpDet(geo::Point_t const &point) const
vector< double > fg4_tlen
process_name opflashCryo1 flashfilter analyze
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
vector< bool > fLhit_frmhit_vec
vector< double > fCflsh_crtpe_vec
vector< double > fg4_T0_CRYO
vector< double > fChit_crtpos_Y_vec
vector< double > fChit_crttime_t1_vec
vector< double > fLflshhit_crttime_t1_vec
vector< int > fCflsh_pmtflshkey_vec
Implementation of the Projection Matching Algorithm.
vector< double > fTrue_TOF_traj_Y
vector< bool > fg4en_CRYO
vector< double > fLhit_pmthitY_vec
vector< bool > fLflsh_frmhit_vec
vector< double > fg4_enZ
vector< double > fLflsh_crtpos_Y_vec
vector< double > fnu_posY
vector< double > fLflsh_crttime_t1_vec
vector< double > fCflsh_crtpos_Z_vec
vector< double > fChit_pmthitX_vec
vector< double > fCflshhit_pmtflshZ_vec
Declaration of signal hit object.
vector< double > fChit_crtpe_vec
vector< double > fCflsh_crttime_t0_vec
pdgs p
Definition: selectors.fcl:22
vector< bool > fTrue_TOF_traj_in_TPC
vector< bool > fCflsh_frmhit_vec
Geometry information for a single TPC.
Definition: TPCGeo.h:38
vector< double > fLflshhit_crtpos_Z_vec
vector< double > fCflsh_tof_vec
vector< double > fLhit_crtpe_vec
vector< int > fLflsh_pmtflshtpcID_vec
vector< int > fChit_pmthitkey_vec
vector< double > fLhit_pmthitpe_vec
Definition of basic raw digits.
vector< double > fLflshhit_pmtflshpe_vec
art::InputTag fOpHitModuleLabel
vector< double > fCflsh_crttime_t1_vec
map< int, art::InputTag > fFlashLabels
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
vector< double > fLhit_tof_vec
vector< double > fLflshhit_crtpos_Y_vec
process_name hit
Definition: cheaterreco.fcl:51
vector< int > fTrue_TOF_pdg
vector< int > fCflshhit_crttrkkey_vec
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
void beginJob() override
vector< double > fChit_tof_vec
vector< double > fLflshhit_pmtflshT_vec
vector< double > fTrue_TOF_traj_X
vector< double > fLflsh_crttime_t0_vec
vector< double > fCflshhit_pmtflshX_vec
vector< double > fLhit_pmthitZ_vec
const double LAR_PROP_DELAY
vector< double > fChit_pmthitT_vec
vector< double > fLflshhit_pmtflshY_vec
int TrueIdFromTotalEnergy(const art::Event &event, const sbnd::crt::CRTData &data)
vector< int > fCflsh_crthitkey_vec
vector< double > fLflshhit_crtpe_vec
art::InputTag fCrtHitModuleLabel
vector< double > fLhit_pmthitT_vec
vector< double > fLflsh_pmtflshT_vec
vector< bool > fTrue_TOF_hit
vector< double > fChit_pmthitY_vec
vector< double > fChit_crttime_t0_vec
process_name gaushit a
vector< int > fChit_crttrkkey_vec
vector< bool > fChit_frmhit_vec
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
vector< int > fLflsh_pmtflshkey_vec
T abs(T value)
vector< bool > fLflshhit_frmhit_vec
vector< bool > fg4en_TPC
vector< double > fLflsh_tof_vec
vector< bool > fLhit_frmtrk_vec
vector< bool > fg4is_prim
object containing MC truth information necessary for making RawDigits and doing back tracking ...
vector< double > fg4_enX
vector< double > fCflsh_crtpos_Y_vec
vector< std::string > fChit_crttgr_vec
vector< double > fCflshhit_crttime_t0_vec
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet&#39;th optical detector in the cryostat.
vector< bool > fLflshhit_frmtrk_vec
bool HitCompare(const art::Ptr< CRTHit > &h1, const art::Ptr< CRTHit > &h2)
vector< double > fLflsh_pmtflshpe_vec
vector< double > fLhit_pmthitX_vec
vector< int > fLhit_pmthitkey_vec
vector< bool > fChit_frmtrk_vec
vector< double > fLflshhit_pmtflshZ_vec
vector< int > fLflsh_crttrkkey_vec
vector< int > fLflshhit_crthitkey_vec
double length(const simb::MCParticle &part, TVector3 &start, TVector3 &end)
vector< double > fg4_T0
vector< double > fLhit_crtpos_Z_vec
vector< double > fChit_crtpos_Z_vec
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
vector< double > fLhit_crttime_t1_vec
vector< double > fCflsh_pmtflshY_vec
vector< int > fCflsh_crttrkkey_vec
vector< double > fLflshhit_tof_vec
vector< double > fLflsh_crtpe_vec
vector< double > fChit_pmthitpe_vec
vector< bool > fg4_is_in_CRYO
vector< double > fLhit_crtpos_Y_vec
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
geo::GeometryCore const * fGeometryService
vector< double > fnu_posX
void analyze(art::Event const &evt) override
vector< std::string > fCflshhit_crttgr_vec
vector< double > fCflsh_pmtflshT_vec
vector< bool > fCflsh_frmtrk_vec
Description of geometry of one entire detector.
Declaration of cluster object.
vector< double > fLflshhit_crttime_t0_vec
vector< bool > fg4st_TPC
vector< double > fg4_stY
Definition of data types for geometry description.
vector< double > fCflsh_crtpos_X_vec
vector< bool > fTrue_TOF_part_prim
vector< double > fCflshhit_crtpos_Z_vec
vector< int > fCflshhit_pmtflshkey_vec
vector< double > fg4_stZ
Provides recob::Track data product.
vector< bool > fnu_TPC
vector< double > fg4_E
vector< double > fTrue_TOF
vector< bool > fg4_is_in_TPC
vector< double > fnu_E
vector< std::string > fLhit_crttgr_vec
vector< int > fCflsh_pmtflshtpcID_vec
vector< double > fCflshhit_crtpos_Y_vec
vector< int > fLhit_crthitkey_vec
vector< double > fCflshhit_crtpos_X_vec
vector< double > fCflshhit_crttime_t1_vec
vector< double > fLflsh_crtpos_Z_vec
art::InputTag fOpFlashModuleLabel0
vector< int > fLflsh_crthitkey_vec
vector< double > fLflsh_crtpos_X_vec
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:93
vector< int > fLflshhit_crttrkkey_vec
vector< double > fLflshhit_pmtflshX_vec
vector< int > fCflshhit_crthitkey_vec
art::InputTag fOpFlashModuleLabel1
vector< double > fCflshhit_pmtflshpe_vec
vector< double > fLhit_crttime_t0_vec
vector< double > fTrue_TOF_traj_T
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Class def header for MCShower data container.
vector< bool > fTrue_TOF_part_org
vector< int > fChit_crthitkey_vec
vector< bool > fLflsh_frmtrk_vec
vector< double > fCflshhit_tof_vec
vector< double > fChit_crtpos_X_vec
stream1 can override from command line with o or output services user sbnd
vector< double > fnu_T
vector< int > fLflshhit_pmtflshtpcID_vec
vector< double > fg4_stX
vector< int > fLflshhit_pmtkey_vec
vector< double > fLhit_crtpos_X_vec
vector< double > fLflsh_pmtflshZ_vec
art::ServiceHandle< art::TFileService > tfs
vector< int > fCflshhit_pmtkey_vec
TCEvent evt
Definition: DataStructs.cxx:8
vector< int > fLhit_crttrkkey_vec
CRTBackTracker * bt
vector< double > fg4_T0_TPC
vector< double > fCflshhit_pmtflshY_vec
vector< double > fnu_posZ
vector< bool > fnu_CRYO
vector< int > fCflshhit_pmtflshtpcID_vec
vector< double > fLflsh_pmtflshY_vec
vector< double > fLflshhit_crtpos_X_vec
process_name crt
vector< bool > fCflshhit_frmhit_vec
helper function for LArPandoraInterface producer module
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
BEGIN_PROLOG SN nu
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
vector< double > fCflsh_pmtflshZ_vec
vector< int > fLflshhit_pmtflshkey_vec
bool ContainsPosition(geo::Point_t const &point, double wiggle=1.0) const
Returns whether this volume contains the specified point.
art framework interface to geometry description
BEGIN_PROLOG could also be cout
vector< double > fCflsh_pmtflshpe_vec
art::InputTag fCrtTrackModuleLabel
vector< double > fCflshhit_crtpe_vec
vector< double > fTrue_TOF_traj_Z
vector< std::string > fCflsh_crttgr_vec
vector< std::string > fLflsh_crttgr_vec
vector< bool > fg4st_CRYO
vector< bool > fCflshhit_frmtrk_vec
vector< std::string > fLflshhit_crttgr_vec
vector< double > fCflshhit_pmtflshT_vec