pionanalysismc_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: pionanalysismc
3 // File: pionanalysismc_module.cc
4 //
5 // Extract protoDUNE useful information, do a firs tpre-selection and save output to a flat tree
6 //
7 // Some parts are copied from the beam module example
8 //
9 // Georgios Christodoulou - georgios.christodoulou at cern.ch
10 // Heng-Ye Liao modified for his protonanalysis - liao@phys.ksu.edu
11 //
12 ////////////////////////////////////////////////////////////////////////
13 
20 #include "art_root_io/TFileService.h"
22 #include "canvas/Persistency/Common/FindManyP.h"
23 #include "fhiclcpp/ParameterSet.h"
25 
39 #include "dune/DuneObj/ProtoDUNEBeamEvent.h"
40 //#include "dune/EventGenerator/ProtoDUNEbeamDataProducts/ProtoDUNEbeamsim.h"
41 //#include "dune/EventGenerator/ProtoDUNEbeamDataProducts/ProtoDUNEBeamInstrument.h"
42 
47 #include "dune/Protodune/singlephase/DataUtils/ProtoDUNEDataUtils.h"
48 
50 
51 // ROOT includes
52 #include "TTree.h"
53 #include "TFile.h"
54 #include "TString.h"
55 #include "TTimeStamp.h"
56 
57 // C++ Includes
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <fstream>
61 #include <string>
62 #include <sstream>
63 #include <cmath>
64 #include <algorithm>
65 #include <iostream>
66 #include <vector>
67 
68 // Maximum number of beam particles to save
69 const int NMAXDAUGTHERS = 15;
70 
71 //const int kMaxTracks = 1000;
72 //const int kMaxHits = 10000;
73 
74 namespace protoana {
75  class pionanalysismc;
76 }
77 
78 
80 public:
81 
82  explicit pionanalysismc(fhicl::ParameterSet const & p);
83 
84  pionanalysismc(pionanalysismc const &) = delete;
85  pionanalysismc(pionanalysismc &&) = delete;
86  pionanalysismc & operator = (pionanalysismc const &) = delete;
88 
89  virtual void beginJob() override;
90  virtual void endJob() override;
91 
92  // Required functions.
93  void analyze(art::Event const & evt) override;
94 
95 private:
96 
97  // Helper utility functions
102 
103  // Initialise tree variables
104  void Initialise();
105 
106  // Fill cosmics tree
107  void FillCosmicsTree(art::Event const & evt, std::string pfParticleTag);
108 
109  // fcl parameters
116  bool fVerbose;
117 
118  TTree *fPandoraBeam;
119  //TTree *fPandoraCosmics;
120 
121  // Tree variables
122  int fRun;
123  int fSubRun;
124  int fevent;
125  double fTimeStamp;
126  int fNactivefembs[6];//why is the size=6???????
127 
128  ////// Beam track information
130  double ftof;
134  double fbeamtrackP[3]; //Px/Py/Pz
136  double fbeamtrackPos[3];
137  double fbeamtrackDir[3];
141 
142  // Reconstructed tracks/showers information
143  double fvertex[3];
144  double fsecvertex[3];
145 
151  double fprimaryPhi;
167  double fprimaryRange[3];
169  double fprimaryT0;
170 
171 
172 
173  //*********************truth information*******************************************//
189 
190  //calo info
191  std::vector< std::vector<double> > primtrk_dqdx;
192  std::vector< std::vector<double> > primtrk_resrange;
193  std::vector< std::vector<double> > primtrk_dedx;
194  std::vector<double> primtrk_range;
195  std::vector< std::vector<double> > primtrk_hitx;
196  std::vector< std::vector<double> > primtrk_hity;
197  std::vector< std::vector<double> > primtrk_hitz;
198  std::vector< std::vector<double> > primtrk_pitch;
199  //
200  //MC Truth information
201  /* std::vector<double> truth_startx;
202  std::vector<double> truth_starty;
203  std::vector<double> truth_startz;
204  std::vector<double> truth_endx;
205  std::vector<double> truth_endy;
206  std::vector<double> truth_endz;
207  std::vector<double> truth_Ndaughter;
208  std::vector<double> truth_pdg;
209  std::vector<string> truth_endprocess;
210  std::vector<string> truth_process;*/
211 
212  //////////////////////////////
213 
214 
215 
216  // Daughters from primary
241 
254 
255 };
256 
257 
259  :
260  EDAnalyzer(p),
261  dataUtil(p.get<fhicl::ParameterSet>("DataUtils")),
262  fBeamModuleLabel(p.get< art::InputTag >("BeamModuleLabel")),
263  fCalorimetryTag(p.get<std::string>("CalorimetryTag")),
264  fTrackerTag(p.get<std::string>("TrackerTag")),
265  fShowerTag(p.get<std::string>("ShowerTag")),
266  fPFParticleTag(p.get<std::string>("PFParticleTag")),
267  fGeneratorTag(p.get<std::string>("GeneratorTag")),
268  fVerbose(p.get<bool>("Verbose"))
269 {
270 
271 }
272 
274 
276 
277  fPandoraBeam = tfs->make<TTree>("PandoraBeam", "Beam events reconstructed with Pandora");
278  fPandoraBeam->Branch("run", &fRun, "run/I");
279  fPandoraBeam->Branch("subrun", &fSubRun, "subrun/I");
280  fPandoraBeam->Branch("event", &fevent, "event/I");
281  fPandoraBeam->Branch("timestamp", &fTimeStamp, "timestamp/D");
282  fPandoraBeam->Branch("Nactivefembs", &fNactivefembs, "Nactivefembs[5]/I");
283 
284  fPandoraBeam->Branch("beamtrigger", &fbeamtrigger, "beamtrigger/I");
285  fPandoraBeam->Branch("tof", &ftof, "tof/D");
286  fPandoraBeam->Branch("cerenkov1", &fcerenkov1, "cerenkov1/I");
287  fPandoraBeam->Branch("cerenkov2", &fcerenkov2, "cerenkov2/I");
288  fPandoraBeam->Branch("beamtrackMomentum", &fbeamtrackMomentum, "beamtrackMomentum/D");
289  fPandoraBeam->Branch("beamtrackP", &fbeamtrackP, "beamtrackP[3]/D");
290  fPandoraBeam->Branch("beamtrackEnergy", &fbeamtrackEnergy, "beamtrackEnergy/D");
291  fPandoraBeam->Branch("beamtrackPos", &fbeamtrackPos, "beamtrackPos[3]/D");
292  fPandoraBeam->Branch("beamtrackDir", &fbeamtrackDir, "beamtrackDir[3]/D");
293  fPandoraBeam->Branch("beamtrackTime", &fbeamtrackTime, "beamtrackTime/D");
294  fPandoraBeam->Branch("beamtrackPdg", &fbeamtrackPdg, "beamtrackPdg/I");
295  fPandoraBeam->Branch("beamtrackID", &fbeamtrackID, "beamtrackID/I");
296 
297  fPandoraBeam->Branch("vertex", &fvertex, "vertex[3]/D");
298  fPandoraBeam->Branch("secvertex", &fsecvertex, "secvertex[3]/D");
299  fPandoraBeam->Branch("isprimarytrack", &fisprimarytrack, "isprimarytrack/I");
300  fPandoraBeam->Branch("isprimaryshower", &fisprimaryshower, "isprimaryshower/I");
301  fPandoraBeam->Branch("primaryBDTScore", &fprimaryBDTScore, "primaryBDTScore/D");
302  fPandoraBeam->Branch("primaryNHits", &fprimaryNHits, "fprimaryNHits/I");
303  fPandoraBeam->Branch("primaryTheta", &fprimaryTheta, "primaryTheta/D");
304  fPandoraBeam->Branch("primaryPhi", &fprimaryPhi, "primaryPhi/D");
305  fPandoraBeam->Branch("primaryLength", &fprimaryLength, "primaryLength/D");
306  fPandoraBeam->Branch("primaryMomentum", &fprimaryMomentum, "primaryMomentum/D");
307  fPandoraBeam->Branch("primaryEndMomentum", &fprimaryEndMomentum, "primaryEndMomentum/D");
308  fPandoraBeam->Branch("primaryEndPosition", &fprimaryEndPosition, "primaryEndPosition[3]/D");
309  fPandoraBeam->Branch("primaryStartPosition", &fprimaryStartPosition, "primaryStartPosition[3]/D");
310  fPandoraBeam->Branch("primaryEndDirection", &fprimaryEndDirection, "primaryEndDirection[3]/D");
311  fPandoraBeam->Branch("primaryStartDirection", &fprimaryStartDirection, "primaryStartDirection[3]/D");
312  fPandoraBeam->Branch("primaryOpeningAngle", &fprimaryOpeningAngle, "primaryOpeningAngle/D");
313  fPandoraBeam->Branch("primaryID", &fprimaryID, "primaryID/I");
314  fPandoraBeam->Branch("primaryShowerBestPlane", &fprimaryShowerBestPlane, "primaryShowerBestPlane/I");
315  fPandoraBeam->Branch("primaryShowerEnergy", &fprimaryShowerEnergy, "primaryShowerEnergy/I");
316  fPandoraBeam->Branch("primaryShowerMIPEnergy", &fprimaryShowerMIPEnergy, "primaryShowerMIPEnergy/I");
317  fPandoraBeam->Branch("primaryShowerdEdx", &fprimaryShowerdEdx, "primaryShowerdEdx/I");
318  fPandoraBeam->Branch("primaryMomentumByRangeProton", &fprimaryMomentumByRangeProton, "primaryMomentumByRangeProton/D");
319  fPandoraBeam->Branch("primaryMomentumByRangeMuon", &fprimaryMomentumByRangeMuon, "primaryMomentumByRangeMuon/D");
320  fPandoraBeam->Branch("primaryKineticEnergy", &fprimaryKineticEnergy, "primaryKineticEnergy[3]/D");
321  fPandoraBeam->Branch("primaryRange", &fprimaryRange, "primaryRange[3]/D");
322  fPandoraBeam->Branch("primaryT0", &fprimaryT0, "primaryT0/D");
323 
324  fPandoraBeam->Branch("primary_truth_TrackId", &fprimary_truth_TrackId, "primary_truth_TrackId/I");
325  fPandoraBeam->Branch("primary_truth_Pdg", &fprimary_truth_Pdg, "primary_truth_Pdg/I");
326  fPandoraBeam->Branch("primary_truth_StartPosition", &fprimary_truth_StartPosition, "primary_truth_StartPosition[4]/D");
327  fPandoraBeam->Branch("primary_truth_EndPosition", &fprimary_truth_EndPosition, "primary_truth_EndPosition[4]/D");
328  fPandoraBeam->Branch("primary_truth_Momentum", &fprimary_truth_Momentum, "primary_truth_Momentum[4]/D");
329  fPandoraBeam->Branch("primary_truth_EndMomentum", &fprimary_truth_EndMomentum, "primary_truth_EndMomentum[4]/D");
330  fPandoraBeam->Branch("primary_truth_P", &fprimary_truth_P, "primary_truth_P/D");
331  fPandoraBeam->Branch("primary_truth_Pt", &fprimary_truth_Pt, "primary_truth_Pt/D");
332  fPandoraBeam->Branch("primary_truth_Mass", &fprimary_truth_Mass, "primary_truth_Mass/D");
333  fPandoraBeam->Branch("primary_truth_Theta", &fprimary_truth_Theta, "primary_truth_Theta/D");
334  fPandoraBeam->Branch("primary_truth_Phi", &fprimary_truth_Phi, "primary_truth_Phi/D");
335  fPandoraBeam->Branch("primary_truth_Process", &fprimary_truth_Process, "primary_truth_Process/I");
336  fPandoraBeam->Branch("primary_truth_Isbeammatched", &fprimary_truth_Isbeammatched, "primary_truth_Isbeammatched/I");
337  fPandoraBeam->Branch("primary_truth_NDaughters", &fprimary_truth_NDaughters, "primary_truth_NDaughters/I");
338  fPandoraBeam->Branch("fprimary_truth_EndProcess", &fprimary_truth_EndProcess);
339 
340  fPandoraBeam->Branch("NDAUGHTERS", &fNDAUGHTERS, "NDAUGHTERS/I");
341  fPandoraBeam->Branch("isdaughtertrack", &fisdaughtertrack, "isdaughtertrack[NDAUGHTERS]/I");
342  fPandoraBeam->Branch("isdaughtershower", &fisdaughtershower, "isdaughtershower[NDAUGHTERS]/I");
343  fPandoraBeam->Branch("daughterNHits", &fdaughterNHits, "daughterNHits[NDAUGHTERS]/I");
344  fPandoraBeam->Branch("daughterTheta", &fdaughterTheta, "daughterTheta[NDAUGHTERS]/D");
345  fPandoraBeam->Branch("daughterPhi", &fdaughterPhi, "daughterPhi[NDAUGHTERS]/D");
346  fPandoraBeam->Branch("daughterLength", &fdaughterLength, "daughterLength[NDAUGHTERS]/D");
347  fPandoraBeam->Branch("daughterMomentum", &fdaughterMomentum, "daughterMomentum[NDAUGHTERS]/D");
348  fPandoraBeam->Branch("daughterEndMomentum", &fdaughterEndMomentum, "daughterEndMomentum[NDAUGHTERS]/D");
349  fPandoraBeam->Branch("daughterEndPosition", &fdaughterEndPosition, "daughterEndPosition[NDAUGHTERS][3]/D");
350  fPandoraBeam->Branch("daughterStartPosition", &fdaughterStartPosition, "daughterStartPosition[NDAUGHTERS][3]/D");
351  fPandoraBeam->Branch("daughterStartDirection", &fdaughterStartDirection, "daughterStartDirection[NDAUGHTERS][3]/D");
352  fPandoraBeam->Branch("daughterEndDirection", &fdaughterEndDirection, "daughterEndDirection[NDAUGHTERS][3]/D");
353  fPandoraBeam->Branch("daughterOpeningAngle", &fdaughterOpeningAngle, "daughterOpeningAngle[NDAUGHTERS]/D");
354  fPandoraBeam->Branch("daughterShowerBestPlane", &fdaughterShowerBestPlane, "daughterShowerBestPlane[NDAUGHTERS]/D");
355  fPandoraBeam->Branch("daughterShowerEnergy", &fdaughterShowerEnergy, "daughterShowerEnergy[NDAUGHTERS]/D");
356  fPandoraBeam->Branch("daughterShowerMIPEnergy", &fdaughterShowerMIPEnergy, "daughterShowerMIPEnergy[NDAUGHTERS]/D");
357  fPandoraBeam->Branch("daughterShowerdEdx", &fdaughterShowerdEdx, "daughterShowerdEdx[NDAUGHTERS]/D");
358  fPandoraBeam->Branch("daughterMomentumByRangeProton", &fdaughterMomentumByRangeProton,"daughterMomentumByRangeProton[NDAUGHTERS]/D");
359  fPandoraBeam->Branch("daughterMomentumByRangeMuon", &fdaughterMomentumByRangeMuon, "daughterMomentumByRangeMuon[NDAUGHTERS]/D");
360  fPandoraBeam->Branch("daughterKineticEnergy", &fdaughterKineticEnergy, "daughterKineticEnergy[NDAUGHTERS][3]/D");
361  fPandoraBeam->Branch("daughterRange", &fdaughterRange, "daughterRange[NDAUGHTERS][3]/D");
362  fPandoraBeam->Branch("daughterID", &fdaughterID, "daughterID[NDAUGHTERS]/I");
363  fPandoraBeam->Branch("daughterT0", &fdaughterT0, "daughterT0[NDAUGHTERS]/D");
364 
365  fPandoraBeam->Branch("daughter_truth_TrackId", &fdaughter_truth_TrackId, "daughter_truth_TrackId[NDAUGHTERS]/I");
366  fPandoraBeam->Branch("daughter_truth_Pdg", &fdaughter_truth_Pdg, "daughter_truth_Pdg[NDAUGHTERS]/I");
367  fPandoraBeam->Branch("daughter_truth_StartPosition", &fdaughter_truth_StartPosition, "daughter_truth_StartPosition[NDAUGHTERS][4]/D");
368  fPandoraBeam->Branch("daughter_truth_EndPosition", &fdaughter_truth_EndPosition, "daughter_truth_EndPosition[NDAUGHTERS][4]/D");
369  fPandoraBeam->Branch("daughter_truth_Momentum", &fdaughter_truth_Momentum, "daughter_truth_Momentum[NDAUGHTERS][4]/D");
370  fPandoraBeam->Branch("daughter_truth_EndMomentum", &fdaughter_truth_EndMomentum, "daughter_truth_EndMomentum[NDAUGHTERS][4]/D");
371  fPandoraBeam->Branch("daughter_truth_P", &fdaughter_truth_P, "daughter_truth_P[NDAUGHTERS]/D");
372  fPandoraBeam->Branch("daughter_truth_Pt", &fdaughter_truth_Pt, "daughter_truth_Pt[NDAUGHTERS]/D");
373  fPandoraBeam->Branch("daughter_truth_Mass", &fdaughter_truth_Mass, "daughter_truth_Mass[NDAUGHTERS]/D");
374  fPandoraBeam->Branch("daughter_truth_Theta", &fdaughter_truth_Theta, "daughter_truth_Theta[NDAUGHTERS]/D");
375  fPandoraBeam->Branch("daughter_truth_Phi", &fdaughter_truth_Phi, "daughter_truth_Phi[NDAUGHTERS]/D");
376  fPandoraBeam->Branch("daughter_truth_Process", &fdaughter_truth_Process, "daughter_truth_Process[NDAUGHTERS]/I");
377 
378 
379  fPandoraBeam->Branch("primtrk_dqdx",&primtrk_dqdx);
380  fPandoraBeam->Branch("primtrk_dedx",&primtrk_dedx);
381  fPandoraBeam->Branch("primtrk_resrange",&primtrk_resrange);
382  fPandoraBeam->Branch("primtrk_range",&primtrk_range);
383  fPandoraBeam->Branch("primtrk_hitx",&primtrk_hitx);
384  fPandoraBeam->Branch("primtrk_hity",&primtrk_hity);
385  fPandoraBeam->Branch("primtrk_hitz",&primtrk_hitz);
386  fPandoraBeam->Branch("primtrk_pitch",&primtrk_pitch);
387 
388 
389  ///////////////////////////MC truth from BackTracker///////
390  /* fPandoraBeam->Branch("truth_startx",&truth_startx);
391  fPandoraBeam->Branch("truth_starty",&truth_starty);
392  fPandoraBeam->Branch("truth_startz",&truth_startz);
393  fPandoraBeam->Branch("truth_endx",&truth_endx);
394  fPandoraBeam->Branch("truth_endy",&truth_endy);
395  fPandoraBeam->Branch("truth_endz",&truth_endz);
396  fPandoraBeam->Branch("truth_Ndaughter",&truth_Ndaughter);
397  fPandoraBeam->Branch("truth_pdg",&truth_pdg);
398  fPandoraBeam->Branch("truth_process",&truth_process);*/
399  ////////////////////////////////////////////////////////////
400 
401 }
402 
404 
405  // Initialise tree parameters
406  Initialise();
407 
409 
410 
411 
412  fRun = evt.run();
413  fSubRun = evt.subRun();
414  fevent = evt.id().event();
415  art::Timestamp ts = evt.time();
416  if (ts.timeHigh() == 0){
417  TTimeStamp ts2(ts.timeLow());
418  fTimeStamp = ts2.AsDouble();
419  }
420  else{
421  TTimeStamp ts2(ts.timeHigh(), ts.timeLow());
422  fTimeStamp = ts2.AsDouble();
423  }
424 
425  // Get number of active fembs
426  if(!evt.isRealData()){
427  for(int k=0; k < 6; k++)
428  fNactivefembs[k] = 20;
429  }
430  else{
431  for(int k=0; k < 6; k++)
433  }
434 
435  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(evt);
436 
437  bool beamTriggerEvent = false;
438  // If this event is MC then we can check what the true beam particle is
439  if(!evt.isRealData()){
440  // Firstly we need to get the list of MCTruth objects from the generator. The standard protoDUNE
441  // simulation has fGeneratorTag = "generator"
442  auto mcTruths = evt.getValidHandle<std::vector<simb::MCTruth>>(fGeneratorTag);
443 
444  // Also get the reconstructed beam information in the MC - TO DO
445  //auto beamsim = evt.getValidHandle<std::vector<sim::ProtoDUNEbeamsim> >(fGeneratorTag);
446  //const sim::ProtoDUNEbeamsim beamsimobj = (*beamsim)[0];
447  //std::cout << beamsimobj.NInstruments() << std::endl;
448  //sim::ProtoDUNEBeamInstrument beamsim_tof1 = beamsimobj.GetInstrument("TOF1");
449  //sim::ProtoDUNEBeamInstrument beamsim_trig2 = beamsimobj.GetInstrument("TRIG2");
450  //std::cout << beamsim_trig2.GetT() - beamsim_tof1.GetT() << " , " << beamsim_trig2.GetSmearedVar1() - beamsim_tof1.GetSmearedVar1() << std::endl;
451  //std::cout << beamsimobj.GetInstrument("TRIG2").GetT() - beamsimobj.GetInstrument("TOF1").GetT() << " , " << beamsimobj.GetInstrument("TRIG2").GetSmearedVar1() - beamsimobj.GetInstrument("TOF1").GetSmearedVar1() << std::endl;
452 
453  // mcTruths is basically a pointer to an std::vector of simb::MCTruth objects. There should only be one
454  // of these, so we pass the first element into the function to get the good particle
455  const simb::MCParticle* geantGoodParticle = truthUtil.GetGeantGoodParticle((*mcTruths)[0],evt);
456 
457  if(geantGoodParticle != 0x0){
458  std::cout << "Found GEANT particle corresponding to the good particle with pdg = " << geantGoodParticle->PdgCode()
459  << " , track id = " << geantGoodParticle->TrackId()
460  << " , Vx/Vy/Vz = " << geantGoodParticle->Vx() << "/"<< geantGoodParticle->Vy() << "/" << geantGoodParticle->Vz()
461  << std::endl;
462 
463  beamTriggerEvent = true;
464  fbeamtrigger = 12;
465  fbeamtrackPos[0] = geantGoodParticle->Vx();
466  fbeamtrackPos[1] = geantGoodParticle->Vy();
467  fbeamtrackPos[2] = geantGoodParticle->Vz();
468  fbeamtrackMomentum = geantGoodParticle->P();
469  fbeamtrackP[0] = geantGoodParticle->Px();
470  fbeamtrackP[1] = geantGoodParticle->Py();
471  fbeamtrackP[2] = geantGoodParticle->Pz();
472  fbeamtrackEnergy = geantGoodParticle->E();
473  fbeamtrackPdg = geantGoodParticle->PdgCode();
474  fbeamtrackTime = geantGoodParticle->T();
475  fbeamtrackID = geantGoodParticle->TrackId();
476  }
477  }
478  else{
479  // For data we can see if this event comes from a beam trigger
480  beamTriggerEvent = dataUtil.IsBeamTrigger(evt);
481 
482  std::vector< art::Ptr<beam::ProtoDUNEBeamEvent> > beaminfo;
483  auto pdbeamHandle = evt.getHandle< std::vector<beam::ProtoDUNEBeamEvent> >(fBeamModuleLabel);
484  if (pdbeamHandle) art::fill_ptr_vector(beaminfo, pdbeamHandle);
485 
486  for(unsigned int i = 0; i < beaminfo.size(); ++i){
487  //if(!beaminfo[i]->CheckIsMatched()) continue;
488  fbeamtrigger = beaminfo[i]->GetTimingTrigger();
489  fbeamtrackTime = (double)beaminfo[i]->GetRDTimestamp();
490 
491  // If ToF is 0-3 there was a good match corresponding to the different pair-wise combinations of the upstream and downstream channels
492  if(beaminfo[i]->GetTOFChan() >= 0)
493  ftof = beaminfo[i]->GetTOF();
494 
495  // Get Cerenkov
496  if(beaminfo[i]->GetBITrigger() == 1){
497  fcerenkov1 = beaminfo[i]->GetCKov0Status();
498  fcerenkov2 = beaminfo[i]->GetCKov1Status();
499  }
500 
501  // Beam particle could have more than one tracks - for now take the first one, need to do this properly
502  auto & tracks = beaminfo[i]->GetBeamTracks();
503  if(!tracks.empty()){
504  fbeamtrackPos[0] = tracks[0].End().X();
505  fbeamtrackPos[1] = tracks[0].End().Y();
506  fbeamtrackPos[2] = tracks[0].End().Z();
507  fbeamtrackDir[0] = tracks[0].StartDirection().X();
508  fbeamtrackDir[1] = tracks[0].StartDirection().Y();
509  fbeamtrackDir[2] = tracks[0].StartDirection().Z();
510  }
511 
512  // Beam momentum
513  auto & beammom = beaminfo[i]->GetRecoBeamMomenta();
514  if(!beammom.empty())
515  fbeamtrackMomentum = beammom[0];
516 
517  // For now only take the first beam particle - need to add some criteria if more than one are found
518  break;
519 
520  }
521  }
522 
523  /*
524  // Now we want to access the output from Pandora. This comes in the form of particle flow objects (recob::PFParticle).
525  // The primary PFParticles are those we want to consider and these PFParticles then have a hierarchy of daughters that
526  // describe the whole interaction of a given primary particle
527  //
528  // / daughter track
529  // /
530  // primary track /
531  // ---------------- ---- daughter track
532  // \
533  // /\-
534  // /\\-- daughter shower
535  //
536  // The above primary PFParticle will have links to three daughter particles, two track-like and one shower-like
537  */
538 
539  // Track momentum algorithm calculates momentum based on track range
541  //trmom.SetMinLength(100);
542 
543  // Get all of the PFParticles, by default from the "pandora" product
544  auto recoParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleTag);
545  //std::cout << "All primary pfParticles = " << pfpUtil.GetNumberPrimaryPFParticle(evt,fPFParticleTag) << std::endl;
546 
547  // We'd like to find the beam particle. Pandora tries to do this for us, so let's use the PFParticle utility
548  // to look for it. Pandora reconstructs slices containing one (or sometimes more) primary PFParticles. These
549  // are tagged as either beam or cosmic for ProtoDUNE. This function automatically considers only those
550  // PFParticles considered as primary
551  // std::vector<recob::PFParticle*> pfParticles = pfpUtil.GetPFParticlesFromBeamSlice(evt,fPFParticleTag);
552  auto pfParticles = pfpUtil.GetPFParticlesFromBeamSlice(evt,fPFParticleTag);
553 
554  // We can now look at these particles
555  for(const recob::PFParticle* particle : pfParticles){
556 
557  // Pandora's BDT beam-cosmic score
559 
560  // NHits associated with this pfParticle
562 
563  // Get the T0 for this pfParticle
564  std::vector<anab::T0> pfT0vec = pfpUtil.GetPFParticleT0(*particle,evt,fPFParticleTag);
565  if(!pfT0vec.empty())
566  fprimaryT0 = pfT0vec[0].Time();
567 
568  //std::cout << "Pdg Code = " << particle->PdgCode() << std::endl;
569  // "particle" is the pointer to our beam particle. The recob::Track or recob::Shower object
570  // of this particle might be more helpful. These return null pointers if not track-like / shower-like
571  const recob::Track* thisTrack = pfpUtil.GetPFParticleTrack(*particle,evt,fPFParticleTag,fTrackerTag);
572  const recob::Shower* thisShower = pfpUtil.GetPFParticleShower(*particle,evt,fPFParticleTag,fShowerTag);
573  if(thisTrack != 0x0){
574  fisprimarytrack = 1;
575  fisprimaryshower = 0;
576 
577  fprimaryID = thisTrack->ParticleId();
578  fprimaryTheta = thisTrack->Theta();
579  fprimaryPhi = thisTrack->Phi();
580  fprimaryLength = thisTrack->Length();
581  fprimaryMomentum = thisTrack->StartMomentum();
582  fprimaryEndMomentum = thisTrack->EndMomentum();
583 
584  fprimaryEndPosition[0] = thisTrack->End().X();
585  fprimaryEndPosition[1] = thisTrack->End().Y();
586  fprimaryEndPosition[2] = thisTrack->End().Z();
587  fprimaryStartPosition[0] = thisTrack->Start().X();
588  fprimaryStartPosition[1] = thisTrack->Start().Y();
589  fprimaryStartPosition[2] = thisTrack->Start().Z();
590  fprimaryEndDirection[0] = thisTrack->Trajectory().EndDirection().X();
591  fprimaryEndDirection[1] = thisTrack->Trajectory().EndDirection().Y();
592  fprimaryEndDirection[2] = thisTrack->Trajectory().EndDirection().Z();
593  fprimaryStartDirection[0] = thisTrack->Trajectory().StartDirection().X();
594  fprimaryStartDirection[1] = thisTrack->Trajectory().StartDirection().Y();
595  fprimaryStartDirection[2] = thisTrack->Trajectory().StartDirection().Z();
596 
597  fprimaryMomentumByRangeMuon = trmom.GetTrackMomentum(thisTrack->Length(),13);
598  fprimaryMomentumByRangeProton = trmom.GetTrackMomentum(thisTrack->Length(),2212);
599 
600  std::vector<anab::Calorimetry> calovector = trackUtil.GetRecoTrackCalorimetry(*thisTrack, evt, fTrackerTag, fCalorimetryTag);
601  if(calovector.size() != 3)
602  std::cerr << "WARNING::Calorimetry vector size for primary is = " << calovector.size() << std::endl;
603 
604  //HY::Get the Calorimetry(s) from thisTrack
605  //std::vector<double> tmp_primtrk_dqdx;
606  //std::vector<double> tmp_primtrk_resrange;
607  //std::vector<double> tmp_primtrk_dedx;
608  std::vector<double> tmp_primtrk_dqdx;
609  std::vector<double> tmp_primtrk_resrange;
610  std::vector<double> tmp_primtrk_dedx;
611  std::vector<double> tmp_primtrk_hitx;
612  std::vector<double> tmp_primtrk_hity;
613  std::vector<double> tmp_primtrk_hitz;
614  std::vector<double> tmp_primtrk_pitch;
615  for (auto & calo : calovector) {
616  if (calo.PlaneID().Plane == 2){ //only collection plane
617  primtrk_range.push_back(calo.Range());
618  for (size_t ihit = 0; ihit < calo.dQdx().size(); ++ihit){ //loop over hits
619  tmp_primtrk_dqdx.push_back(calo.dQdx()[ihit]);
620  tmp_primtrk_resrange.push_back(calo.ResidualRange()[ihit]);
621  tmp_primtrk_dedx.push_back(calo.dEdx()[ihit]);
622  tmp_primtrk_pitch.push_back(calo.TrkPitchVec()[ihit]);
623 
624  const auto &primtrk_pos=(calo.XYZ())[ihit];
625  tmp_primtrk_hitx.push_back(primtrk_pos.X());
626  tmp_primtrk_hity.push_back(primtrk_pos.Y());
627  tmp_primtrk_hitz.push_back(primtrk_pos.Z());
628  std::cout<<"dqdx="<<calo.dQdx()[ihit]<<"; resrange="<<calo.ResidualRange()[ihit]<<std::endl;
629  std::cout<<"(X,Y,Z)="<<"("<<calo.XYZ()[ihit].X()<<","<<calo.XYZ()[ihit].Y()<<","<<calo.XYZ()[ihit].Z()<<")"<<std::endl;
630 
631  } //loop over hits
632  } //only collection plane
633  }
634 
635  primtrk_dqdx.push_back(tmp_primtrk_dqdx);
636  primtrk_resrange.push_back(tmp_primtrk_resrange);
637  primtrk_dedx.push_back(tmp_primtrk_dedx);
638  primtrk_hitx.push_back(tmp_primtrk_hitx);
639  primtrk_hity.push_back(tmp_primtrk_hity);
640  primtrk_hitz.push_back(tmp_primtrk_hitz);
641  primtrk_pitch.push_back(tmp_primtrk_pitch);
642 
643  tmp_primtrk_dqdx.clear();
644  tmp_primtrk_resrange.clear();
645  tmp_primtrk_dedx.clear();
646  tmp_primtrk_hitx.clear();
647  tmp_primtrk_hity.clear();
648  tmp_primtrk_hitz.clear();
649  tmp_primtrk_pitch.clear();
650 
651  for(size_t k = 0; k < calovector.size() && k<3; k++){
652  fprimaryKineticEnergy[k] = calovector[k].KineticEnergy();
653  fprimaryRange[k] = calovector[k].Range();
654  //const std::vector< double > & dedxvec = calovector[k].dEdx();
655  }
656 
657  //Get MC truth info using BackTracker
658 
659 
660 
661 
662 
663  // Get the true mc particle
664  const simb::MCParticle* mcparticle1 = truthUtil.GetMCParticleFromRecoTrack(clockData, *thisTrack, evt, fTrackerTag);
665  if(mcparticle1 != 0x0){
666  const simb::MCParticle *mcparticle=pi_serv->TrackIdToMotherParticle_P(mcparticle1->TrackId());
667  if (mcparticle) {
668 
669 
670 
671 
672 
673  fprimary_truth_TrackId = mcparticle->TrackId();
674  fprimary_truth_Pdg = mcparticle->PdgCode();
675  fprimary_truth_StartPosition[0] = mcparticle->Vx();
676  fprimary_truth_StartPosition[1] = mcparticle->Vy();
677  fprimary_truth_StartPosition[2] = mcparticle->Vz();
678  fprimary_truth_StartPosition[3] = mcparticle->T();
679  fprimary_truth_EndPosition[0] = mcparticle->EndX();
680  fprimary_truth_EndPosition[1] = mcparticle->EndY();
681  fprimary_truth_EndPosition[2] = mcparticle->EndZ();
682  fprimary_truth_EndPosition[3] = mcparticle->EndT();
683  fprimary_truth_P = mcparticle->P();
684  fprimary_truth_Momentum[0] = mcparticle->Px();
685  fprimary_truth_Momentum[1] = mcparticle->Py();
686  fprimary_truth_Momentum[2] = mcparticle->Pz();
687  fprimary_truth_Momentum[3] = mcparticle->E();
688  fprimary_truth_Pt = mcparticle->Pt();
689  fprimary_truth_Mass = mcparticle->Mass();
690  fprimary_truth_EndMomentum[0] = mcparticle->EndPx();
691  fprimary_truth_EndMomentum[1] = mcparticle->EndPy();
692  fprimary_truth_EndMomentum[2] = mcparticle->EndPz();
693  fprimary_truth_EndMomentum[3] = mcparticle->EndE();
694  fprimary_truth_Theta = mcparticle->Momentum().Theta();
695  fprimary_truth_Phi = mcparticle->Momentum().Phi();
697  fprimary_truth_EndProcess = mcparticle->EndProcess();
698  fprimary_truth_Process = int(mcparticle->Trajectory().ProcessToKey(mcparticle->Process()));
701  else
703 
704  //std::cout << "Process = " << (mcparticle->Process()).c_str() << " , End process = " << (mcparticle->EndProcess()).c_str()
705  // << " , track ID = " << mcparticle->TrackId()
706  // << std::endl;
707  std::cout<<"End Process name "<<mcparticle->EndProcess()<<std::endl;
708  }
709  }
710  }
711  else if(thisShower != 0x0){
712  fisprimarytrack = 0;
713  fisprimaryshower = 1;
714 
715  fprimaryID = thisShower->ID();
716  fprimaryLength = thisShower->Length();
717  fprimaryShowerBestPlane = thisShower->best_plane();
718  fprimaryOpeningAngle = thisShower->OpenAngle();
719  fprimaryStartPosition[0] = thisShower->ShowerStart().X();
720  fprimaryStartPosition[1] = thisShower->ShowerStart().Y();
721  fprimaryStartPosition[2] = thisShower->ShowerStart().Z();
722  fprimaryStartDirection[0] = thisShower->Direction().X();
723  fprimaryStartDirection[1] = thisShower->Direction().Y();
724  fprimaryStartDirection[2] = thisShower->Direction().Z();
725  if( (thisShower->Energy()).size() > 0 )
726  fprimaryShowerEnergy = thisShower->Energy()[0]; // thisShower->best_plane()
727  if( (thisShower->MIPEnergy()).size() > 0 )
728  fprimaryShowerMIPEnergy = thisShower->MIPEnergy()[0];
729  if( (thisShower->dEdx()).size() > 0 )
730  fprimaryShowerdEdx = thisShower->dEdx()[0];
731  }
732  else{
733  std::cout << "INFO::Primary pfParticle is not track or shower. Skip!" << std::endl;
734  continue;
735  }
736 
737  // Find the particle vertex. We need the tracker tag here because we need to do a bit of
738  // additional work if the PFParticle is track-like to find the vertex.
739  const TVector3 vtx = pfpUtil.GetPFParticleVertex(*particle,evt,fPFParticleTag,fTrackerTag);
740  fvertex[0] = vtx.X(); fvertex[1] = vtx.Y(); fvertex[2] = vtx.Z();
741 
742  // Now we can look for the interaction point of the particle if one exists, i.e where the particle
743  // scatters off an argon nucleus. Shower-like objects won't have an interaction point, so we can
744  // check this by making sure we get a sensible position
745  const TVector3 interactionVtx = pfpUtil.GetPFParticleSecondaryVertex(*particle,evt,fPFParticleTag,fTrackerTag);
746  fsecvertex[0] = interactionVtx.X(); fsecvertex[1] = interactionVtx.Y(); fsecvertex[2] = interactionVtx.Z();
747 
748  // Maximum number of daugthers to be processed
749  if(particle->NumDaughters() > NMAXDAUGTHERS)
750  std::cout << "INFO::Number of daughters is " << particle->NumDaughters() << ". Only the first NMAXDAUGTHERS are processed." << std::endl;
751 
752  // Let's get the daughter PFParticles... we can do this simply without the utility
753  for(const int daughterID : particle->Daughters()){
754  // Daughter ID is the element of the original recoParticle vector
755  const recob::PFParticle *daughterParticle = &(recoParticles->at(daughterID));
756  std::cout << "Daughter " << daughterID << " has " << daughterParticle->NumDaughters() << " daughters" << std::endl;
757 
758  const recob::Track* daughterTrack = pfpUtil.GetPFParticleTrack(*daughterParticle,evt,fPFParticleTag,fTrackerTag);
759  const recob::Shower* daughterShower = pfpUtil.GetPFParticleShower(*daughterParticle,evt,fPFParticleTag,fShowerTag);
760 
761  if(daughterTrack != 0x0){
764  fdaughterTheta[fNDAUGHTERS] = daughterTrack->Theta();
765  fdaughterPhi[fNDAUGHTERS] = daughterTrack->Phi();
766  fdaughterLength[fNDAUGHTERS] = daughterTrack->Length();
767  fdaughterMomentum[fNDAUGHTERS] = daughterTrack->StartMomentum();
768  fdaughterEndMomentum[fNDAUGHTERS] = daughterTrack->EndMomentum();
769  fdaughterStartPosition[fNDAUGHTERS][0] = daughterTrack->Trajectory().Start().X();
770  fdaughterStartPosition[fNDAUGHTERS][1] = daughterTrack->Trajectory().Start().Y();
771  fdaughterStartPosition[fNDAUGHTERS][2] = daughterTrack->Trajectory().Start().Z();
772  fdaughterEndPosition[fNDAUGHTERS][0] = daughterTrack->Trajectory().End().X();
773  fdaughterEndPosition[fNDAUGHTERS][1] = daughterTrack->Trajectory().End().Y();
774  fdaughterEndPosition[fNDAUGHTERS][2] = daughterTrack->Trajectory().End().Z();
775  fdaughterStartDirection[fNDAUGHTERS][0] = daughterTrack->Trajectory().StartDirection().X();
776  fdaughterStartDirection[fNDAUGHTERS][1] = daughterTrack->Trajectory().StartDirection().Y();
777  fdaughterStartDirection[fNDAUGHTERS][2] = daughterTrack->Trajectory().StartDirection().Z();
778  fdaughterEndDirection[fNDAUGHTERS][0] = daughterTrack->Trajectory().EndDirection().X();
779  fdaughterEndDirection[fNDAUGHTERS][1] = daughterTrack->Trajectory().EndDirection().Y();
780  fdaughterEndDirection[fNDAUGHTERS][2] = daughterTrack->Trajectory().EndDirection().Z();
781 
782  fdaughterMomentumByRangeMuon[fNDAUGHTERS] = trmom.GetTrackMomentum(daughterTrack->Length(),13);
783  fdaughterMomentumByRangeProton[fNDAUGHTERS] = trmom.GetTrackMomentum(daughterTrack->Length(),2212);
784 
785  std::vector<anab::Calorimetry> daughtercalovector = trackUtil.GetRecoTrackCalorimetry(*daughterTrack, evt, fTrackerTag, fCalorimetryTag);
786  if(daughtercalovector.size() != 3)
787  std::cerr << "WARNING::Calorimetry vector size for daughter is = " << daughtercalovector.size() << std::endl;
788 
789  for(size_t k = 0; k < daughtercalovector.size() && k<3; k++){
790  fdaughterKineticEnergy[fNDAUGHTERS][k] = daughtercalovector[k].KineticEnergy();
791  fdaughterRange[fNDAUGHTERS][k] = daughtercalovector[k].Range();
792  }
793 
794  // Get the true mc particle
795  const simb::MCParticle* mcdaughterparticle = truthUtil.GetMCParticleFromRecoTrack(clockData, *daughterTrack, evt, fTrackerTag);
796  if(mcdaughterparticle != 0x0){
797  fdaughter_truth_TrackId[fNDAUGHTERS] = mcdaughterparticle->TrackId();
798  fdaughter_truth_Pdg[fNDAUGHTERS] = mcdaughterparticle->PdgCode();
799  fdaughter_truth_StartPosition[fNDAUGHTERS][0] = mcdaughterparticle->Vx();
800  fdaughter_truth_StartPosition[fNDAUGHTERS][1] = mcdaughterparticle->Vy();
801  fdaughter_truth_StartPosition[fNDAUGHTERS][2] = mcdaughterparticle->Vz();
802  fdaughter_truth_StartPosition[fNDAUGHTERS][3] = mcdaughterparticle->T();
803  fdaughter_truth_EndPosition[fNDAUGHTERS][0] = mcdaughterparticle->EndX();
804  fdaughter_truth_EndPosition[fNDAUGHTERS][1] = mcdaughterparticle->EndY();
805  fdaughter_truth_EndPosition[fNDAUGHTERS][2] = mcdaughterparticle->EndZ();
806  fdaughter_truth_EndPosition[fNDAUGHTERS][3] = mcdaughterparticle->EndT();
807  fdaughter_truth_P[fNDAUGHTERS] = mcdaughterparticle->P();
808  fdaughter_truth_Momentum[fNDAUGHTERS][0] = mcdaughterparticle->Px();
809  fdaughter_truth_Momentum[fNDAUGHTERS][1] = mcdaughterparticle->Py();
810  fdaughter_truth_Momentum[fNDAUGHTERS][2] = mcdaughterparticle->Pz();
811  fdaughter_truth_Momentum[fNDAUGHTERS][3] = mcdaughterparticle->E();
812  fdaughter_truth_Pt[fNDAUGHTERS] = mcdaughterparticle->Pt();
813  fdaughter_truth_Mass[fNDAUGHTERS] = mcdaughterparticle->Mass();
814  fdaughter_truth_EndMomentum[fNDAUGHTERS][0] = mcdaughterparticle->EndPx();
815  fdaughter_truth_EndMomentum[fNDAUGHTERS][1] = mcdaughterparticle->EndPy();
816  fdaughter_truth_EndMomentum[fNDAUGHTERS][2] = mcdaughterparticle->EndPz();
817  fdaughter_truth_EndMomentum[fNDAUGHTERS][3] = mcdaughterparticle->EndE();
818  fdaughter_truth_Theta[fNDAUGHTERS] = mcdaughterparticle->Momentum().Theta();
819  fdaughter_truth_Phi[fNDAUGHTERS] = mcdaughterparticle->Momentum().Phi();
820  fdaughter_truth_Process[fNDAUGHTERS] = int(mcdaughterparticle->Trajectory().ProcessToKey(mcdaughterparticle->Process()));
821  std::cout << "Daughter Process = " << (mcdaughterparticle->Process()).c_str()
822  << " , mother = " << mcdaughterparticle->Mother()
823  << std::endl;
824  }
825  }
826  else if(daughterShower != 0x0){
829  fdaughterLength[fNDAUGHTERS] = daughterShower->Length();
830  fdaughterShowerBestPlane[fNDAUGHTERS] = daughterShower->best_plane();
831  fdaughterOpeningAngle[fNDAUGHTERS] = daughterShower->OpenAngle();
832  fdaughterStartPosition[fNDAUGHTERS][0] = daughterShower->ShowerStart().X();
833  fdaughterStartPosition[fNDAUGHTERS][1] = daughterShower->ShowerStart().Y();
834  fdaughterStartPosition[fNDAUGHTERS][2] = daughterShower->ShowerStart().Z();
835  fdaughterStartDirection[fNDAUGHTERS][0] = daughterShower->Direction().X();
836  fdaughterStartDirection[fNDAUGHTERS][1] = daughterShower->Direction().Y();
837  fdaughterStartDirection[fNDAUGHTERS][2] = daughterShower->Direction().Z();
838  if( (daughterShower->Energy()).size() > 0 )
839  fdaughterShowerEnergy[fNDAUGHTERS] = daughterShower->Energy()[0]; // thisShower->best_plane()
840  if( (daughterShower->MIPEnergy()).size() > 0 )
841  fdaughterShowerMIPEnergy[fNDAUGHTERS] = daughterShower->MIPEnergy()[0];
842  if( (daughterShower->dEdx()).size() > 0 )
843  fdaughterShowerdEdx[fNDAUGHTERS] = daughterShower->dEdx()[0];
844  }
845  else{
846  std::cout << "INFO::Daughter pfParticle is not track or shower. Skip!" << std::endl;
847  continue;
848  }
849 
850  fdaughterID[fNDAUGHTERS] = daughterID;
851  // NHits associated with this pfParticle
853  // T0
854  std::vector<anab::T0> pfdaughterT0vec = pfpUtil.GetPFParticleT0(*daughterParticle,evt,fPFParticleTag);
855  if(!pfT0vec.empty())
856  fdaughterT0[fNDAUGHTERS] = pfdaughterT0vec[0].Time();
857 
858  fNDAUGHTERS++;
859 
860  // Only process NMAXDAUGTHERS
861  if(fNDAUGHTERS > NMAXDAUGTHERS) break;
862 
863  }
864 
865  // For actually studying the objects, it is easier to have the daughters in their track and shower forms.
866  // We can use the utility to get a vector of track-like and a vector of shower-like daughters
867  //const std::vector<const recob::Track*> trackDaughters = pfpUtil.GetPFParticleDaughterTracks(*particle,evt,fPFParticleTag,fTrackerTag);
868  //const std::vector<const recob::Shower*> showerDaughters = pfpUtil.GetPFParticleDaughterShowers(*particle,evt,fPFParticleTag,fShowerTag);
869 
870  // For now only consider the first primary track. Need a proper treatment if more than one primary particles are found.
871  break;
872  }
873 
874  // Fill trees
875  if(beamTriggerEvent)
876  fPandoraBeam->Fill();
877 
878  //fPandoraCosmics->Fill();
879 
880 }
881 
883 
884 }
885 
887 
888  // To fill
889 
890 }
891 
893 
894  fRun = -999;
895  fSubRun = -999;
896  fevent = -999;
897  fTimeStamp = -999.0;
898  for(int k=0; k < 5; k++)
899  fNactivefembs[k] = -999;
900 
901  for(int k=0; k < 3; k++){
902  fvertex[k] = -999.0;
903  fsecvertex[k] = -999.0;
904  fprimaryEndPosition[k] = -999.0;
905  fprimaryStartPosition[k] = -999.0;
906  fprimaryEndDirection[k] = -999.0;
907  fprimaryStartDirection[k] = -999.0;
908  fprimaryKineticEnergy[k] = -999.0;
909  fprimaryRange[k] = -999.0;
910  }
911 
912  fbeamtrigger = -999;
913  ftof = -999.0;
914  fcerenkov1 = -999;
915  fcerenkov2 = -999;
916  fbeamtrackMomentum = -999.0;
917  fbeamtrackEnergy = 999.0;
918  fbeamtrackPdg = -999;
919  fbeamtrackTime = -999.0;
920  fbeamtrackID = -999;
921  for(int l=0; l < 3; l++){
922  fbeamtrackP[l] = -999.0;
923  fbeamtrackPos[l] = -999.0;
924  fbeamtrackDir[l] = -999.0;
925  }
926 
927  fisprimarytrack = 0;
928  fisprimaryshower = 0;
929  fNDAUGHTERS = 0;
930 
931  fprimaryBDTScore = -999.0;
932  fprimaryNHits = -999;
933  fprimaryTheta = -999.0;
934  fprimaryPhi = -999.0;
935  fprimaryLength = -999.0;
936  fprimaryMomentum = -999.0;
937  fprimaryEndMomentum = -999.0;
938  fprimaryOpeningAngle = -999.0;
940  fprimaryShowerEnergy = -999;
942  fprimaryShowerdEdx = -999;
943  fprimaryID = -999;
946  fprimaryT0 = -999.0;
947 
948  fprimary_truth_TrackId = -999;
949  fprimary_truth_Pdg = -999;
950  fprimary_truth_P = -999.0;
951  fprimary_truth_Pt = -999.0;
952  fprimary_truth_Mass = -999.0;
953  fprimary_truth_Theta = -999.0;
954  fprimary_truth_Phi = -999.0;
955  fprimary_truth_Process = -999;
958  for(int l=0; l < 4; l++){
960  fprimary_truth_EndPosition[l] = -999.0;
961  fprimary_truth_Momentum[l] = -999.0;
962  fprimary_truth_EndMomentum[l] = -999.0;
963  }
964 
965  for(int k=0; k < NMAXDAUGTHERS; k++){
966  fisdaughtertrack[k] = -999;
967  fisdaughtershower[k] = -999;
968  fdaughterNHits[k] = -999;
969  fdaughterTheta[k] = -999.0;
970  fdaughterPhi[k] = -999.0;
971  fdaughterLength[k] = -999.0;
972  fdaughterMomentum[k] = -999.0;
973  fdaughterEndMomentum[k] = -999.0;
974  for(int l=0; l < 3; l++){
975  fdaughterEndPosition[k][l] = -999.0;
976  fdaughterStartPosition[k][l] = -999.0;
977  fdaughterEndDirection[k][l] = -999.0;
978  fdaughterStartDirection[k][l] = -999.0;
979  fdaughterKineticEnergy[k][l] = -999.0;
980  fdaughterRange[k][l] = -999.0;
981  }
982  fdaughterOpeningAngle[k] = -999.0;
983  fdaughterShowerBestPlane[k] = -999;
984  fdaughterShowerEnergy[k] = -999;
985  fdaughterShowerMIPEnergy[k] = -999;
986  fdaughterShowerdEdx[k] = -999;
989  fdaughterID[k] = -999;
990  fdaughterT0[k] = -999;
991 
992  fdaughter_truth_TrackId[k] = -999;
993  fdaughter_truth_Pdg[k] = -999;
994  fdaughter_truth_P[k] = -999.0;
995  fdaughter_truth_Pt[k] = -999.0;
996  fdaughter_truth_Mass[k] = -999.0;
997  fdaughter_truth_Theta[k] = -999.0;
998  fdaughter_truth_Phi[k] = -999.0;
999  fdaughter_truth_Process[k] = -999;
1000  for(int l=0; l < 4; l++){
1001  fdaughter_truth_StartPosition[k][l] = -999.0;
1002  fdaughter_truth_EndPosition[k][l] = -999.0;
1003  fdaughter_truth_Momentum[k][l] = -999.0;
1004  fdaughter_truth_EndMomentum[k][l] = -999.0;
1005  }
1006  }
1007 
1008  primtrk_dqdx.clear();
1009  primtrk_resrange.clear();
1010  primtrk_dedx.clear();
1011  primtrk_range.clear();
1012  primtrk_hitx.clear();
1013  primtrk_hity.clear();
1014  primtrk_hitz.clear();
1015  primtrk_pitch.clear();
1016 
1017 
1018 }
1019 
double E(const int i=0) const
Definition: MCParticle.h:233
int best_plane() const
Definition: Shower.h:200
double fdaughterLength[NMAXDAUGTHERS]
std::vector< std::vector< double > > primtrk_hitx
protoana::ProtoDUNEDataUtils dataUtil
const TVector3 & ShowerStart() const
Definition: Shower.h:192
double fdaughterShowerEnergy[NMAXDAUGTHERS]
double EndMomentum() const
Definition: Track.h:144
int PdgCode() const
Definition: MCParticle.h:212
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
int fisdaughtershower[NMAXDAUGTHERS]
double Py(const int i=0) const
Definition: MCParticle.h:231
std::vector< std::vector< double > > primtrk_hity
std::vector< anab::T0 > GetPFParticleT0(const recob::PFParticle &particle, art::Event const &evt, std::string particleLabel) const
Get the T0(s) from a given PFParticle.
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
Definition: PFParticle.h:89
const simb::MCParticle * GetGeantGoodParticle(const simb::MCTruth &genTruth, const art::Event &evt) const
double fdaughter_truth_Theta[NMAXDAUGTHERS]
void FillCosmicsTree(art::Event const &evt, std::string pfParticleTag)
double EndE() const
Definition: MCParticle.h:244
double EndZ() const
Definition: MCParticle.h:228
double fdaughterStartDirection[NMAXDAUGTHERS][3]
double Length() const
Definition: Shower.h:201
int ParticleId() const
Definition: Track.h:171
const recob::Shower * GetPFParticleShower(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Get the shower associated to this particle. Returns a null pointer if not found.
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
int fisdaughtertrack[NMAXDAUGTHERS]
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:253
double fdaughterMomentumByRangeProton[NMAXDAUGTHERS]
int fdaughterShowerBestPlane[NMAXDAUGTHERS]
double fdaughterTheta[NMAXDAUGTHERS]
int Mother() const
Definition: MCParticle.h:213
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
std::vector< anab::Calorimetry > GetRecoTrackCalorimetry(const recob::Track &track, art::Event const &evt, const std::string trackModule, const std::string caloModule) const
Get the Calorimetry(s) from a given reco track.
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
double Mass() const
Definition: MCParticle.h:239
std::vector< std::vector< double > > primtrk_dqdx
const std::vector< const recob::Hit * > GetPFParticleHits(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the hits associated to the PFParticle.
const std::vector< double > & Energy() const
Definition: Shower.h:195
double Px(const int i=0) const
Definition: MCParticle.h:230
std::vector< double > primtrk_range
const TVector3 GetPFParticleVertex(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Function to find the interaction vertex of a primary PFParticle.
double fdaughter_truth_EndPosition[NMAXDAUGTHERS][4]
double fdaughterShowerdEdx[NMAXDAUGTHERS]
double fdaughter_truth_StartPosition[NMAXDAUGTHERS][4]
STL namespace.
protoana::ProtoDUNETrackUtils trackUtil
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string Process() const
Definition: MCParticle.h:215
Particle class.
unsigned char ProcessToKey(std::string const &process) const
double EndY() const
Definition: MCParticle.h:227
static QStrList * l
Definition: config.cpp:1044
int NumberDaughters() const
Definition: MCParticle.h:217
double fdaughter_truth_EndMomentum[NMAXDAUGTHERS][4]
int TrackId() const
Definition: MCParticle.h:210
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
double fdaughterT0[NMAXDAUGTHERS]
bool isRealData() const
double fdaughterEndMomentum[NMAXDAUGTHERS]
double Pt(const int i=0) const
Definition: MCParticle.h:236
double fdaughterShowerMIPEnergy[NMAXDAUGTHERS]
double Phi() const
Definition: Track.h:178
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
virtual void endJob() override
Timestamp time() const
const std::vector< double > & dEdx() const
Definition: Shower.h:203
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
const std::vector< double > & MIPEnergy() const
Definition: Shower.h:198
std::string EndProcess() const
Definition: MCParticle.h:216
Point_t const & Start() const
Access to track position at different points.
Definition: Track.h:123
double EndPz() const
Definition: MCParticle.h:243
double fdaughterEndDirection[NMAXDAUGTHERS][3]
double fdaughter_truth_Phi[NMAXDAUGTHERS]
double Theta() const
Access to spherical or geographical angles at vertex or at any point.
Definition: Track.h:176
virtual void beginJob() override
double P(const int i=0) const
Definition: MCParticle.h:234
const recob::Track * GetPFParticleTrack(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the track associated to this particle. Returns a null pointer if not found.
void analyze(art::Event const &evt) override
double OpenAngle() const
Definition: Shower.h:202
protoana::ProtoDUNETruthUtils truthUtil
double T(const int i=0) const
Definition: MCParticle.h:224
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
protoana::ProtoDUNEPFParticleUtils pfpUtil
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
double fdaughterKineticEnergy[NMAXDAUGTHERS][3]
double fdaughter_truth_Mass[NMAXDAUGTHERS]
const simb::MCParticle * GetMCParticleFromRecoTrack(detinfo::DetectorClocksData const &clockData, const recob::Track &track, art::Event const &evt, std::string trackModule) const
const std::vector< const recob::PFParticle * > GetPFParticlesFromBeamSlice(art::Event const &evt, const std::string particleLabel) const
Return the pointers for the PFParticles in the beam slice. Returns an empty vector is no beam slice w...
const TVector3 & Direction() const
Definition: Shower.h:189
RunNumber_t run() const
Definition: DataViewImpl.cc:71
double EndT() const
Definition: MCParticle.h:229
std::vector< std::vector< double > > primtrk_hitz
double fdaughterMomentumByRangeMuon[NMAXDAUGTHERS]
double fdaughterMomentum[NMAXDAUGTHERS]
pionanalysismc(fhicl::ParameterSet const &p)
double fdaughterRange[NMAXDAUGTHERS][3]
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
double fdaughterOpeningAngle[NMAXDAUGTHERS]
Definition: tracks.py:1
double Vx(const int i=0) const
Definition: MCParticle.h:221
Declaration of signal hit object.
double StartMomentum() const
Definition: Track.h:143
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
std::vector< std::vector< double > > primtrk_resrange
std::vector< std::vector< double > > primtrk_pitch
double EndPy() const
Definition: MCParticle.h:242
int GetNActiveFembsForAPA(art::Event const &evt, int apa) const
Get number of active fembs in an APA.
int fdaughter_truth_TrackId[NMAXDAUGTHERS]
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
double Pz(const int i=0) const
Definition: MCParticle.h:232
Provides recob::Track data product.
const art::InputTag fBeamModuleLabel
double Vz(const int i=0) const
Definition: MCParticle.h:223
double fdaughter_truth_Pt[NMAXDAUGTHERS]
const TVector3 GetPFParticleSecondaryVertex(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Function to find the secondary interaction vertex of a primary PFParticle.
EventNumber_t event() const
Definition: EventID.h:116
Point_t const & End() const
Definition: Track.h:125
double fdaughter_truth_Momentum[NMAXDAUGTHERS][4]
double EndPx() const
Definition: MCParticle.h:241
std::vector< std::vector< double > > primtrk_dedx
double fdaughterStartPosition[NMAXDAUGTHERS][3]
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 EndX() const
Definition: MCParticle.h:226
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
int bool
Definition: qglobal.h:345
int ID() const
Definition: Shower.h:187
int fdaughter_truth_Process[NMAXDAUGTHERS]
float GetBeamCosmicScore(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Access the BDT output used to decide if a slice is beam-like or cosmic-like.
int fdaughter_truth_Pdg[NMAXDAUGTHERS]
EventID id() const
Definition: Event.cc:34
double Vy(const int i=0) const
Definition: MCParticle.h:222
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
calorimetry
double GetTrackMomentum(double trkrange, int pdg) const
double fdaughterPhi[NMAXDAUGTHERS]
pionanalysismc & operator=(pionanalysismc const &)=delete
QTextStream & endl(QTextStream &s)
bool IsBeamTrigger(art::Event const &evt) const
double fdaughter_truth_P[NMAXDAUGTHERS]
const int NMAXDAUGTHERS
double fdaughterEndPosition[NMAXDAUGTHERS][3]