pionanalysis_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: pionanalysis
3 // Plugin Type: analyzer (art v2_11_02)
4 // File: pionanalysis_module.cc
5 // Pionanalysis module: Ajib Paudel
6 // from cetlib version v3_03_01.
7 ////////////////////////////////////////////////////////////////////////
8 
9 // Framework includes
14 #include "art_root_io/TFileService.h"
15 #include "art_root_io/TFileDirectory.h"
18 #include "fhiclcpp/ParameterSet.h"
19 
22 
24 #include "canvas/Persistency/Common/FindManyP.h"
25 
28 
36 
44 
46 #include "dune/DuneObj/ProtoDUNEBeamEvent.h"
51 #include "dune/Protodune/singlephase/DataUtils/ProtoDUNEDataUtils.h"
54 
56 
57 // ROOT includes
58 #include "TTree.h"
59 #include "TTimeStamp.h"
60 #include "TVector3.h"
61 #include "TFile.h"
62 #include "TString.h"
63 #include "TH1.h"
64 #include "TLorentzVector.h"
65 #include "TProfile.h"
66 #include <map>
67 #include <tuple>
68 
69 //const int kMaxTracks = 1000;
70 //const int kMaxHits = 10000;
71 double theta12(double x1, double x2, double y1, double y2, double z1, double z2,double x1p, double x2p, double y1p, double y2p, double z1p, double z2p){
72  double numer=(x2-x1)*(x2p-x1p)+(y2-y1)*(y2p-y1p)+(z2-z1)*(z2p-z1p);
73  double den1=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1);
74  double den2=(x2p-x1p)*(x2p-x1p)+(y2p-y1p)*(y2p-y1p)+(z2p-z1p)*(z2p-z1p);
75  return 180/3.14*acos(numer/sqrt(den1*den2));
76 }
77 
78 using namespace std;
79 
80 namespace protoana {
81  class pionanalysis;
82 }
83 
84 
85 
86 
88 public:
89  explicit pionanalysis(fhicl::ParameterSet const & p);
90  // The compiler-generated destructor is fine for non-base
91  // classes without bare pointers or other resource use.
92 
93  // Plugins should not be copied or assigned.
94  pionanalysis(pionanalysis const &) = delete;
95  pionanalysis(pionanalysis &&) = delete;
96  pionanalysis & operator = (pionanalysis const &) = delete;
97  pionanalysis & operator = (pionanalysis &&) = delete;
98 
99  // Required functions.
100  void analyze(art::Event const & e) override;
101 
102  // Selected optional functions.
103  void beginJob() override;
104  void endJob() override;
105 
106  void reset();
107 
108 private:
109 
110  //const art::InputTag fSpacePointModuleLabel;
112  //const art::InputTag fTimeDecoderModuleLabel;
113 
115  //std::string fBeamModuleLabel;
116 
117 
118  TTree *fTree;
119  // Run information
120  int run;
121  int subrun;
122  int event;
123  //int trigger;
124  double evttime;
125  int fNactivefembs[6];
126 
127  // beam information
128  std::vector<double> beamPosx;
129  std::vector<double> beamPosy;
130  std::vector<double> beamPosz;
131 
132  std::vector<double> beamDirx;
133  std::vector<double> beamDiry;
134  std::vector<double> beamDirz;
135 
136  std::vector<double> beamMomentum;
137 
138  double tof;
139  std::vector<double> tofs;
140  std::vector<int> ch_tofs;
143  double low_pressure;
145 
146  //Beamline utils
150 
151  // fcl parameters for PFP particles
157  //std::string fGeneratorTag;
158 
159  //Beam Momentum
161  //bool fUseCERNCalibSelection;
162  bool fVerbose;
163 
164 
165  // define parameters for primary tracks
166  std::vector<double> primtrk_startx;
167  std::vector<double> primtrk_starty;
168  std::vector<double> primtrk_startz;
169 
170  std::vector<double> primtrk_endx;
171  std::vector<double> primtrk_endy;
172  std::vector<double> primtrk_endz;
173 
174  std::vector<double> primtrk_Dirx;
175  std::vector<double> primtrk_Diry;
176  std::vector<double> primtrk_Dirz;
177  std::vector<double> primtrklen;
178  std::vector<double> primtrkID;
179  std::vector<int> primtrk_trktag;
180  //hit wire and charge info
181  std::vector<std::vector<int> > wireno_2;
182  std::vector<std::vector<float> > peakTime_2;
183  std::vector<std::vector<float> > dq_2;
184  std::vector<std::vector<float> > trkhitx2;
185  std::vector<std::vector<float> > trkhity2;
186  std::vector<std::vector<float> > trkhitz2;
187 
188 
189  //calo info
190  std::vector< std::vector<double> > primtrk_dqdx;
191  std::vector< std::vector<double> > primtrk_resrange;
192  std::vector< std::vector<double> > primtrk_dedx;
193  std::vector<double> primtrk_range;
194  std::vector< std::vector<double> > primtrk_hitx;
195  std::vector< std::vector<double> > primtrk_hity;
196  std::vector< std::vector<double> > primtrk_hitz;
197  std::vector< std::vector<double> > primtrk_pitch;
198 
200 
201  std::vector<int> pdg_code;
202  std::vector<int> n_daughter;
203  std::vector<int> n_beamparticle;
204  std::vector<int> isPrimary;
205  std::vector<int> pfp_self;
206  //std::vector<int> pfp_parent;
207  std::vector<int> pfp_daughter;
208 
209 
210  ////Michel tagging
211  std::vector< std::vector<int> > Mendhitssecondary;
212  std::vector< std::vector<double> > Msecondarystartx;
213  std::vector< std::vector<double> > Msecondaryendx;
214  std::vector< std::vector<double> > Msecondarystarty;
215  std::vector< std::vector<double> > Msecondaryendy;
216  std::vector< std::vector<double> > Msecondarystartz;
217  std::vector< std::vector<double> > Msecondaryendz;
218  std::vector< std::vector<double> > MdQmichel;
219  std::vector< std::vector<double> > MdQtrackend;
220  std::vector< std::vector<double> > MdQtrackbegin;
221  std::vector< std::vector<double> > Mprimsectheta;
222  std::vector< std::vector<double> > Mtracklengthsecondary;
223  std::vector< std::vector<int> > MtrackID;
224  ////CNN for michel tagging
225  std::vector< std::vector<double> > trackscore;
226  std::vector< std::vector<double> > emscore;
227  std::vector< std::vector<double> > michelscore;
228  std::vector< std::vector<double> > nonescore;
229 
230 
231 
232 
233 };
234 
235 
237  :
238  EDAnalyzer(p),
239  //fSpacePointModuleLabel(p.get< art::InputTag >("SpacePointModuleLabel")),
240  fTrackModuleLabel(p.get< art::InputTag >("TrackModuleLabel")),
241  fBeamModuleLabel(p.get< art::InputTag >("BeamModuleLabel")),
242  beam_cuts(p.get<fhicl::ParameterSet>("BeamCuts")),
243  fBeamlineUtils(p.get<fhicl::ParameterSet>("BeamlineUtils")),
244  //fBeamModuleLabel(p.get<std::string>("BeamModuleLabel")),
245 
246  //fTimeDecoderModuleLabel(p.get< art::InputTag >("TimeDecoderModuleLabel")),
247 
248  dataUtil(p.get<fhicl::ParameterSet>("DataUtils")),
249  fCalorimetryTag(p.get<std::string>("CalorimetryTag")),
250  fTrackerTag(p.get<std::string>("TrackerTag")),
251  fShowerTag(p.get<std::string>("ShowerTag")),
252  fPFParticleTag(p.get<std::string>("PFParticleTag")),
253  fHitsModuleLabel(p.get<std::string>("HitsModuleLabel")),
254  //fGeneratorTag(p.get<std::string>("GeneratorTag")),
255  fBeamPars(p.get<fhicl::ParameterSet>("BeamPars")),
256 //fUseCERNCalibSelection(p.get<bool>("UseCERNCalibSelection")),
257  fVerbose(p.get<bool>("Verbose"))
258 {
259  //if (fSaveTrackInfo == false) fSaveCaloInfo = false;
260 
261 }
262 
264 {
265  //reset containers
267 
268 
269  //Access the Beam Event ======================================================================//
270  auto beamHandle = evt.getValidHandle<std::vector<beam::ProtoDUNEBeamEvent>>("beamevent");
271  std::vector<art::Ptr<beam::ProtoDUNEBeamEvent>> beamVec;
272  if( beamHandle.isValid()){
273  art::fill_ptr_vector(beamVec, beamHandle);
274  }
275  const beam::ProtoDUNEBeamEvent & beamEvent = *(beamVec.at(0)); //Should just have one
276  /////////////////////////////////////////////////////////////
277 
278  //Check the quality of the event
279  std::cout << "Timing Trigger: " << beamEvent.GetTimingTrigger() << std::endl;
280  std::cout << "Is Matched: " << beamEvent.CheckIsMatched() << std::endl;
281 
283  std::cout << "Failed quality check!\n" << std::endl;
284  return; //returns, does nothing when !=IsGoodBeamlineTrigger
285  }
286 
287  std::cout << "Passed quality check!" << std::endl << std::endl;
288  /////////////////////////////////////////////////////////////
289 
290  //Access momentum
291  const std::vector< double > & momenta = beamEvent.GetRecoBeamMomenta();
292  std::cout << "Number of reconstructed momenta: " << momenta.size() << std::endl;
293 
294  if( momenta.size() > 0 )
295  std::cout << "Measured Momentum: " << momenta.at(0) << std::endl;
296  /////////////////////////////////////////////////////////////
297 
298  //Access time of flight
299  const std::vector< double > & the_tofs = beamEvent.GetTOFs();
300  const std::vector< int > & the_chans = beamEvent.GetTOFChans();
301 
302  std::cout<<"run/subrun/event:"<<evt.run()<<"/"<<evt.subRun()<<"/"<<evt.id().event()<<std::endl;
303  std::cout << "Number of measured TOF: " << the_tofs.size() << std::endl;
304  std::cout << "First TOF: " << beamEvent.GetTOF() << std::endl;
305  std::cout << "First TOF Channel: " << beamEvent.GetTOFChan() << std::endl << std::endl;
306 
307  std::cout << "All (TOF, Channels): " << std::endl;
308  for( size_t i = 0; i < the_tofs.size(); ++i ){
309  std::cout << "\t(" << the_tofs[i] << ", " << the_chans[i] << ")" << std::endl;
310  }
311  std::cout << std::endl;
312  /////////////////////////////////////////////////////////////
313 
314  //Access Cerenkov info
315  std::cout << "Cerenkov status, pressure:" << std::endl;
316  std::cout << "C0: " << beamEvent.GetCKov0Status() << ", " << beamEvent.GetCKov0Pressure() << std::endl;
317  std::cout << "C1: " << beamEvent.GetCKov1Status() << ", " << beamEvent.GetCKov1Pressure() << std::endl << std::endl;
318 
319  //if (beamEvent.GetBITrigger() == 1) {
320  //ckov0status = beamEvent.GetCKov0Status(); //low_pressure_status
321  //ckov1status = beamEvent.GetCKov1Status(); //high_pressure_status
322 
323  //ckov0pressure=beamEvent.GetCKov0Pressure();
324  //ckov1pressure=beamEvent.GetCKov1Pressure();
325  //}
326 
327  if(beamEvent.GetCKov0Pressure() < beamEvent.GetCKov1Pressure() ){
328  high_pressure_status = beamEvent.GetCKov1Status();
329  low_pressure_status = beamEvent.GetCKov0Status();
330 
331  high_pressure=beamEvent.GetCKov1Pressure();
332  low_pressure=beamEvent.GetCKov0Pressure();
333  }
334  else{
335  high_pressure_status = beamEvent.GetCKov0Status();
336  low_pressure_status = beamEvent.GetCKov1Status();
337 
338  high_pressure=beamEvent.GetCKov0Pressure();
339  low_pressure=beamEvent.GetCKov1Pressure();
340  }
341 
342  /////////////////////////////////////////////////////////////
343 
344  double nom_beam_mon=fBeamPars.get<double>("Momentum");
345  std::cout<<"Selected nominal beam momentum is: "<<nom_beam_mon<<" GeV/c"<<std::endl;
346 
347  //Access PID
348  //std::vector< int > pids = fBeamlineUtils.GetPID( beamEvent, nom_beam_mon);
349  //for( size_t i = 0; i < pids.size(); ++i ){
350  //std::cout << "pid["<<i<<"]: "<< pids[i] << std::endl;
351  //}
352 
353  PossibleParticleCands candidates = fBeamlineUtils.GetPIDCandidates( beamEvent, nom_beam_mon);
354  std::cout << "electron " << candidates.electron << std::endl;
355  std::cout << "muon " << candidates.muon << std::endl;
356  std::cout << "pion " << candidates.pion << std::endl;
357  std::cout << "kaon " << candidates.kaon << std::endl;
358  std::cout << "proton " << candidates.proton << std::endl;
359 
360  std::cout << std::endl;
361  //if (candidates.proton==0) {
362  //std::cout<<"no proton!!!!!!"<<std::endl;
363  //}
364  /////////////////////////////////////////////////////////////
365 
366  //Manual Event Selection -----------------------------------------------------------------------------------------------------------------------------------------------//
367  /*bool IsProton=false;
368  //old Tof: (!fUseCERNCalibSelection&&tof>170.)
369  if (nom_beam_mon==1.) {
370  if ((beamEvent.GetTOF()>110.&&beamEvent.GetTOF()<160.)&&low_pressure_status==0) {
371  IsProton=true;
372  std::cout<<"-->> This is a proton candidate..."<<std::endl;
373  }
374  }
375  */
376 
377  //HY::For Calo info
378  std::vector<art::Ptr<recob::Track> > tracklist;
379  auto trackListHandle = evt.getHandle< std::vector<recob::Track> >(fTrackModuleLabel);
380  if (trackListHandle) art::fill_ptr_vector(tracklist, trackListHandle);
381  else return;
382  art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryTag);
383  art::FindManyP<recob::PFParticle> pfp_trk_assn(trackListHandle, evt, "pandoraTrack");
384  // std::vector<art::Ptr<recob::Hit>> pfpHits;//pfpHits definition
385  std::vector<art::Ptr<recob::Hit>> hitlist;
386  auto hitListHandle = evt.getHandle< std::vector<recob::Hit> >(fHitsModuleLabel); // to get information about the hits
387  if (hitListHandle) art::fill_ptr_vector(hitlist, hitListHandle);
388  art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trackListHandle, evt, fTrackModuleLabel); // to associate tracks and hits
389  // Implementation of required member function here.
390  art::FindManyP<recob::Track> thass(hitListHandle, evt, fTrackModuleLabel); //to associate hit just trying
391  run = evt.run();
392  subrun = evt.subRun();
393  event = evt.id().event();
394  art::Timestamp ts = evt.time();
395  //std::cout<<ts.timeHigh()<<" "<<ts.timeLow()<<std::endl;
396  if (ts.timeHigh() == 0){
397  //TTimeStamp tts(ts.timeLow());
398  //evttime = tts.AsDouble();
399  TTimeStamp ts2(ts.timeLow());
400  evttime = ts2.AsDouble();
401  }
402  else{
403  //TTimeStamp tts(ts.timeHigh(), ts.timeLow());
404  //evttime = tts.AsDouble();
405  TTimeStamp ts2(ts.timeHigh(), ts.timeLow());
406  evttime = ts2.AsDouble();
407  }
408 
409  // Get number of active fembs
410  if(!evt.isRealData()){
411  for(int ik=0; ik<6; ik++)
412  fNactivefembs[ik]=20;
413  }
414  else{
415  for(int ik=0; ik<6; ik++)
417  }
418  //CNN
419  anab::MVAReader<recob::Hit,4> hitResults(evt, "emtrkmichelid:emtrkmichel" );
420 
421 
422 
423  if (beamVec.size()&&candidates.pion==1) { //if beam pion
424  if (beamEvent.GetTimingTrigger()==12) { //get beam timing trigger
425  if (beamEvent.CheckIsMatched()){ //if CheckIsMatched
426  //Get TOF info
427  if (beamEvent.GetTOFChan() != -1) {//if TOFChan == -1, then there was not a successful match, if it's 0, 1, 2, or 3, then there was a good match corresponding to the different pair-wise combinations of the upstream and downstream channels
428  tof = beamEvent.GetTOF();
429  for( size_t ii = 0; ii < the_tofs.size(); ++ii ){
430  tofs.push_back(the_tofs[ii]);
431  ch_tofs.push_back(the_chans[ii]);
432  }
433  }
434  //Get beam particle trajectory info
435  //auto & tracks = beaminfo[0]->GetBeamTracks();
436  auto & tracks = beamEvent.GetBeamTracks();
437  std::cout<<"ToF:"<<tof<<" [ns]"<<std::endl;
438  std::cout<<"beam trk size:"<<tracks.size()<<std::endl;
439  for (size_t i = 0; i<tracks.size(); ++i){
440  beamPosx.push_back(tracks[i].End().X());
441  beamPosy.push_back(tracks[i].End().Y());
442  beamPosz.push_back(tracks[i].End().Z());
443  beamDirx.push_back(tracks[i].StartDirection().X());
444  beamDiry.push_back(tracks[i].StartDirection().Y());
445  beamDirz.push_back(tracks[i].StartDirection().Z());
446 
447  std::cout<<"run/subrun/evt:"<<run<<"/"<<subrun<<"/"<<event<<std::endl;
448  std::cout<<"beamPosx/beamPosy/beamPosz:"<<tracks[i].End().X()<<"/"<<tracks[i].End().Y()<<"/"<<tracks[i].End().Z()<<std::endl;
449  std::cout<<"beamDirx/beamDiry/beamDirz:"<<tracks[i].StartDirection().X()<<"/"<<tracks[i].StartDirection().Y()<<"/"<<tracks[i].StartDirection().Z()<<std::endl;
450  //std::cout<<"beamDirx^2+beamDiry^2+beamDirz^2:"<<tracks[i].StartDirection().X()*tracks[i].StartDirection().X()+tracks[i].StartDirection().Y()*tracks[i].StartDirection().Y()+tracks[i].StartDirection().Z()*tracks[i].StartDirection().Z()<<std::endl;
451  }
452  //Get reconstructed beam momentum info
453  //auto & beammom = beaminfo[0]->GetRecoBeamMomenta();
454  //auto & beammom = beamEvent.GetRecoBeamMomenta();
455  //auto & beammom = beamEvent.GetRecoBeamMomenta();
456  //std::cout<<"==============================================================="<<std::endl;
457  std::cout<<"beam mom size:"<<momenta.size()<<std::endl;
458  for (size_t i = 0; i<momenta.size(); ++i){
459  beamMomentum.push_back(momenta[i]);
460  std::cout<<"beam mom["<<i<<"]:"<<momenta[i]<<" [GeV]"<<std::endl;
461  }
462  //std::cout<<"==============================================================="<<std::endl;
463 
464  //put the track parameters in the cryo here ----------------------------------------------------------------------------//
465  /*
466  // Now we want to access the output from Pandora. This comes in the form of particle flow objects (recob::PFParticle).
467  // The primary PFParticles are those we want to consider and these PFParticles then have a hierarchy of daughters that
468  // describe the whole interaction of a given primary particle
469  //
470  // / daughter track
471  // /
472  // primary track /
473  // ---------------- ---- daughter track
474  // \
475  // /\-
476  // /\\-- daughter shower
477  //
478  // The above primary PFParticle will have links to three daughter particles, two track-like and one shower-like
479  */
480 
481  std::cout<<"\n*******************************************************"<<std::endl;
482  std::cout<<"Moving on to the PFParticle section..."<<std::endl;
483 
484  // Get the PFParticle utility
486 
487  // Get the track utility
489 
490  // Get all of the PFParticles, by default from the "pandora" product
491  auto recoParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleTag);
492 
493  // We'd like to find the beam particle. Pandora tries to do this for us, so let's use the PFParticle utility
494  // to look for it. Pandora reconstructs slices containing one (or sometimes more) primary PFParticles. These
495  // are tagged as either beam or cosmic for ProtoDUNE. This function automatically considers only those
496  // PFParticles considered as primary
497 
498  /// Use the pandora metadata to tell us if this is a beam particle or not
499  //bool isBeamParticle=dataUtil.IsBeamParticle(fPFParticleTag, evt, );
500  //bool IsBeamParticle(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const;
501 
502 
503  //std::vector<const recob::PFParticle*> beamParticles = pfpUtil.GetPFParticlesFromBeamSlice(evt,fPFParticleTag);
504  auto beamParticles = pfpUtil.GetPFParticlesFromBeamSlice(evt,fPFParticleTag);
505  //HY:: From the new version, prepend recob::PFParticle* with "const"
506  if(beamParticles.size() == 0){
507  std::cerr << "We found no beam particles for this event... moving on" << std::endl;
508  return;
509  }
510 
511  //unsigned int nPrimPFPartices=pfpUtil.GetNumberPrimaryPFParticle(evt,fPFParticleTag); //count all the particles
512  //std::cout<<"--> Number of all prim. PFPartices:"<<nPrimPFPartices<<std::endl;
513 
514  //int tmp_counter=0;
515  n_beamparticle.push_back(beamParticles.size());
516  std::cout<<"we have "<<beamParticles.size()<<" beam particle(s)"<<std::endl;
517  for(const recob::PFParticle* particle : beamParticles){
518  int nTrack=0;
519  int nShower=0;
520 
521  // "particle" is the pointer to our beam particle. The recob::Track or recob::Shower object
522  // of this particle might be more helpful. These return null pointers if not track-like / shower-like
523  const recob::Track* thisTrack = pfpUtil.GetPFParticleTrack(*particle,evt,fPFParticleTag,fTrackerTag);
524  // art::Ptr<recob::Track> *track = thisTrack;
525  // art::Ptr<recob::Track> thisTrack = pfpUtil.GetPFParticleTrack(*particle,evt,fPFParticleTag,fTrackerTag);
526  const recob::Shower* thisShower = pfpUtil.GetPFParticleShower(*particle,evt,fPFParticleTag,fShowerTag);
527  auto recoTracks = evt.getValidHandle<std::vector<recob::Track>>(fTrackerTag);
528  art::FindManyP<recob::Hit> findHitsFromTracks(recoTracks,evt,fTrackerTag);
529  /////end of Michel hits loop
530  double beamstx=-30;
531  double beamendx=-30;
532  double beamsty=420;
533  double beamendy=420;
534  double beamstz=30;
535  double beamendz=100;
536 
537  if(thisTrack != 0x0){
538  if(!beam_cuts.IsBeamlike(*thisTrack, evt, "1")) return;
539  beamstx=thisTrack->Start().X();
540  beamsty=thisTrack->Start().Y();
541  beamstz=thisTrack->Start().Z();
542  beamendx=thisTrack->End().X();
543  beamendy=thisTrack->End().Y();
544  beamendz=thisTrack->End().Z();
545  std::cout<<"beamstx "<<beamstx<<std::endl;
546  //////Michel tagging here
547  std::vector<double> secondarystartx1;
548  std::vector<double> secondarystarty1;
549  std::vector<double> secondarystartz1;
550  std::vector<double> secondaryendx1;
551  std::vector<double> secondaryendy1;
552  std::vector<double> secondaryendz1;
553  std::vector<double> dQmichel1;
554  std::vector<double> dQtrackbegin1;
555  std::vector<double> dQtrackend1;
556  std::vector<double> tracklengthsecondary1;
557  std::vector<double> primsectheta1;
558  std::vector<int> endhitssecondary1,trackID1;
559  std::vector<double> trks1;
560  std::vector<double> ems1;
561  std::vector<double> michels1;
562  std::vector<double> nones1;
563  size_t NTracks = tracklist.size();
564  for(size_t i=0;i<NTracks;i++){
565  art::Ptr<recob::Track> ptrack(trackListHandle, i);
566  const recob::Track& track = *ptrack;
567  auto pos = track.Vertex();
568  auto end = track.End();
569  int counter1=0;
570  double startx=pos.X();
571  double starty=pos.Y();
572  double startz=pos.Z();
573  double endx=end.X();
574  double endy=end.Y();
575  double endz=end.Z();
576  if(track.Length()<5) continue;
577  // if(TMath::Max(endy,starty)>520 || TMath::Min(endy, starty)<150 || TMath::Max(startx, endx)>20||TMath::Min(startx,endx)<-300||TMath::Max(startz,endz)<230) continue;
578  if(TMath::Max(endy,starty)>500 || TMath::Min(endy, starty)<200 || TMath::Max(startx, endx)>0||TMath::Min(startx,endx)<-200||TMath::Max(startz,endz)<30) continue;
579  //std::cout<<"event trackid "<<event<<" "<<track.ID()<<std::endl;
580  std::vector<int> wirenos;
581  std::vector<float> peakts,dqbuff1;
582  std::vector<float> dQstart,dQend;
583  std::vector<double> micheldq;
584  wirenos.clear();peakts.clear();dqbuff1.clear();
585  float peaktime=-1;
586  int wireno=-99999;
587  int tpcno=-1;
588  float zlast0=-99999;
589  float zlast=-99999;
590  std::vector<std::tuple<double,double,double,double,int,double>> buff_ZYXTWQ;
591  buff_ZYXTWQ.clear();
592  double thetavalue=theta12(beamstx,beamendx,beamsty,beamendy,beamstz,beamendz,startx,endx,starty,endy,startz,endz);
593  if(fmthm.isValid()){
594  auto vhit=fmthm.at(i);
595  auto vmeta=fmthm.data(i);
596  for (size_t ii = 0; ii<vhit.size(); ++ii){ //loop over all meta data hit
597  bool fBadhit = false;
598  if (vmeta[ii]->Index() == static_cast<unsigned int>(std::numeric_limits<int>::max())){
599  fBadhit = true;
600  //cout<<"fBadHit"<<fBadhit<<endl;
601  continue;
602  }
603  if (vmeta[ii]->Index()>=tracklist[i]->NumberTrajectoryPoints()){
604  throw cet::exception("Calorimetry_module.cc") << "Requested track trajectory index "<<vmeta[ii]->Index()<<" exceeds the total number of trajectory points "<<tracklist[i]->NumberTrajectoryPoints()<<" for track index "<<i<<". Something is wrong with the track reconstruction. Please contact tjyang@fnal.gov!!";
605  }
606  if (!tracklist[i]->HasValidPoint(vmeta[ii]->Index())){
607  fBadhit = true;
608  // cout<<"had valid point "<<fBadhit<<endl;
609  continue;
610  }
611 
612  auto loc = tracklist[i]->LocationAtPoint(vmeta[ii]->Index());
613  if (fBadhit) continue; //HY::If BAD hit, skip this hit and go next
614  if (loc.Z()<-100) continue; //hit not on track
615  if(vhit[ii]->WireID().Plane==2){
616  buff_ZYXTWQ.push_back(std::make_tuple(loc.Z(),loc.Y(),loc.X(),vhit[ii]->PeakTime(),vhit[ii]->WireID().Wire,vhit[ii]->Integral()));
617  wirenos.push_back(vhit[ii]->WireID().Wire);
618  peakts.push_back(vhit[ii]->PeakTime());
619  zlast=loc.Z();
620  if(zlast>zlast0){
621  zlast0=zlast;
622  wireno=vhit[ii]->WireID().Wire;
623  peaktime=vhit[ii]->PeakTime();
624  tpcno=vhit[ii]->WireID().TPC;
625  }
626  }//planenum 2
627  }//loop over vhit
628  }//fmthm valid
629  //save start and end point of each track
630  //taking care of flipped start and end point
631  if(endz<startz){
632  startx=end.X();
633  starty=end.Y();
634  startz=end.Z();
635  endx=pos.X();
636  endy=pos.Y();
637  endz=pos.Z();
638  }
639  double trk_score=0.0;
640  double em_score=0;
641  double michel_score=0;
642  double none_score=0;
643  for(size_t hitl=0;hitl<hitlist.size();hitl++){
644  std::array<float,4> cnn_out=hitResults.getOutput(hitlist[hitl]);
645  auto & tracks = thass.at(hitlist[hitl].key());
646  // if (!tracks.empty() && tracks[0].key()!=ptrack.key() && tracklist[tracks[0].key()]->Length()>25) continue;
647  if (!tracks.empty() && tracks[0].key()!=ptrack.key() && tracklist[tracks[0].key()]->Length()>25) continue;
648  bool test=true;
649  float peakth1=hitlist[hitl]->PeakTime();
650  int wireh1=hitlist[hitl]->WireID().Wire;
651  for(size_t m=0;m<wirenos.size();m++){
652  if(wireh1==wirenos[m] && peakth1==peakts[m]){
653  test=false;
654  break;
655  }
656  }
657  if(!test) continue;
658  int planeid=hitlist[hitl]->WireID().Plane;
659  int tpcid=hitlist[hitl]->WireID().TPC;
660  if(abs(wireh1-wireno)<20 && abs(peakth1-peaktime)<150 && planeid==2 && tpcid==tpcno){
661  counter1++;
662  micheldq.push_back(hitlist[hitl]->Integral());
663  micheldq.push_back(hitlist[hitl]->Integral());
664  trk_score+=cnn_out[hitResults.getIndex("track")];
665  em_score+=cnn_out[hitResults.getIndex("em")];
666  michel_score+=cnn_out[hitResults.getIndex("michel")];
667  none_score+=cnn_out[hitResults.getIndex("none")];
668  }
669  }//hitlist loop
670  if(buff_ZYXTWQ.size()<10) continue;
671  sort(buff_ZYXTWQ.begin(),buff_ZYXTWQ.end());
672  dQstart.clear(); dQend.clear();
673  int qi11=buff_ZYXTWQ.size();
674  for(int qi=5;qi<TMath::Min(15,qi11);qi++){
675  dQstart.push_back(std::get<5>(buff_ZYXTWQ[qi]));
676  }
677 
678  for(int qi=qi11-5;qi<qi11;qi++){
679  dQend.push_back(std::get<5>(buff_ZYXTWQ[qi]));
680  }
681  secondarystartx1.push_back(startx);
682  secondarystarty1.push_back(starty);
683  secondarystartz1.push_back(startz);
684  secondaryendx1.push_back(endx);
685  secondaryendy1.push_back(endy);
686  secondaryendz1.push_back(endz);
687  endhitssecondary1.push_back(counter1);
688  tracklengthsecondary1.push_back(track.Length());
689  trackID1.push_back(track.ID());
690  dQmichel1.push_back(TMath::Median(micheldq.size(),&micheldq[0]));
691  dQtrackbegin1.push_back(TMath::Median(dQstart.size(),&dQstart[0]));
692  dQtrackend1.push_back(TMath::Median(dQend.size(),&dQend[0]));
693  primsectheta1.push_back(thetavalue);
694  trks1.push_back(trk_score);
695  ems1.push_back(em_score);
696  michels1.push_back(michel_score);
697  nones1.push_back(none_score);
698  }//Ntracks
699  Msecondarystartx.push_back(secondarystartx1);
700  Msecondarystarty.push_back(secondarystarty1);
701  Msecondarystartz.push_back(secondarystartz1);
702  Msecondaryendx.push_back(secondaryendx1);
703  Msecondaryendy.push_back(secondaryendy1);
704  Msecondaryendz.push_back(secondaryendz1);
705  Mendhitssecondary.push_back(endhitssecondary1);
706  Mtracklengthsecondary.push_back(tracklengthsecondary1);
707  MtrackID.push_back(trackID1);
708  MdQmichel.push_back(dQmichel1);
709  MdQtrackbegin.push_back(dQtrackbegin1);
710  MdQtrackend.push_back(dQtrackend1);
711  Mprimsectheta.push_back(primsectheta1);
712  trackscore.push_back(trks1);
713  emscore.push_back(ems1);
714  michelscore.push_back(michels1);
715  nonescore.push_back(nones1);
716  //std::cout<<"clearing trees now "<<std::endl;
717  endhitssecondary1.clear();
718  secondarystartx1.clear();
719  secondaryendx1.clear();
720  secondarystarty1.clear();
721  secondaryendy1.clear();
722  secondarystartz1.clear();
723  secondaryendz1.clear();
724  dQmichel1.clear();
725  primsectheta1.clear();
726  dQtrackbegin1.clear();
727  dQtrackend1.clear();
728  tracklengthsecondary1.clear();
729  trks1.clear();
730  ems1.clear();
731  michels1.clear();
732  nones1.clear();
733  }
734  ///////////////End of Michel checking
735  /////defining secondary hits parameters
736 
737  if(thisTrack != 0x0) {
738  if(!beam_cuts.IsBeamlike(*thisTrack, evt, "1")) return;
739  std::cout << "Beam particle is track-like" << std::endl;
740  nTrack++;
741  primtrk_trktag.push_back(1);
742 
743  //Adding hit coordinates info using space points
744  // pfpHits = findHitsFromTracks.at(thisTrack->ID());
745  // art::FindManyP<recob::SpacePoint> spFromHits(pfpHits, evt, fHitsModuleLabel);
746  //hits and calorimetry loop
747  ////End of Hit Meta
748  //HY::Get the Calorimetry(s) from track
749  std::vector<anab::Calorimetry> calovector = trackUtil.GetRecoTrackCalorimetry(*thisTrack, evt, fTrackerTag, fCalorimetryTag);
750  std::vector<double> tmp_primtrk_dqdx;
751  std::vector<double> tmp_primtrk_resrange;
752  std::vector<double> tmp_primtrk_dedx;
753  std::vector<double> tmp_primtrk_hitx;
754  std::vector<double> tmp_primtrk_hity;
755  std::vector<double> tmp_primtrk_hitz;
756  std::vector<double> tmp_primtrk_pitch;
757  for (auto & calo : calovector){
758  if (calo.PlaneID().Plane == 2){ //only collection plane
759  primtrk_range.push_back(calo.Range());
760  for (size_t ihit = 0; ihit < calo.dQdx().size(); ++ihit){ //loop over hits
761  tmp_primtrk_dqdx.push_back(calo.dQdx()[ihit]);
762  tmp_primtrk_resrange.push_back(calo.ResidualRange()[ihit]);
763  tmp_primtrk_dedx.push_back(calo.dEdx()[ihit]);
764  tmp_primtrk_pitch.push_back(calo.TrkPitchVec()[ihit]);
765 
766  const auto &primtrk_pos=(calo.XYZ())[ihit];
767  tmp_primtrk_hitx.push_back(primtrk_pos.X());
768  tmp_primtrk_hity.push_back(primtrk_pos.Y());
769  tmp_primtrk_hitz.push_back(primtrk_pos.Z());
770  //std::cout<<"dqdx="<<calo.dQdx()[ihit]<<"; resrange="<<calo.ResidualRange()[ihit]<<std::endl;
771  //std::cout<<"(X,Y,Z)="<<"("<<calo.XYZ()[ihit].X()<<","<<calo.XYZ()[ihit].Y()<<","<<calo.XYZ()[ihit].Z()<<")"<<std::endl;
772  //std::cout<<"(X,Y,Z)="<<"("<<primtrk_pos.X()<<","<<primtrk_pos.Y()<<","<<primtrk_pos.Z()<<")"<<std::endl;
773  //std::cout<<"(X,Y,Z)="<<"("<<tmp_primtrk_hitx[ihit]<<","<<tmp_primtrk_hity[ihit]<<","<<tmp_primtrk_hitz[ihit]<<")"<<std::endl;
774  } //loop over hits
775  } //only collection plane
776  }
777  //primtrk_dqdx->push_back(tmp_primtrk_dqdx);
778  //primtrk_resrange->push_back(tmp_primtrk_resrange);
779  //primtrk_dedx->push_back(tmp_primtrk_dedx);
780  if (tmp_primtrk_hitz.size()!=0) { //prevent the zero vectors being push_back
781  primtrk_dqdx.push_back(tmp_primtrk_dqdx);
782  primtrk_resrange.push_back(tmp_primtrk_resrange);
783  primtrk_dedx.push_back(tmp_primtrk_dedx);
784  primtrk_hitx.push_back(tmp_primtrk_hitx);
785  primtrk_hity.push_back(tmp_primtrk_hity);
786  primtrk_hitz.push_back(tmp_primtrk_hitz);
787  primtrk_pitch.push_back(tmp_primtrk_pitch);
788  } //prevent the zero vectors being push_back
789 
790  tmp_primtrk_dqdx.clear();
791  tmp_primtrk_resrange.clear();
792  tmp_primtrk_dedx.clear();
793  tmp_primtrk_hitx.clear();
794  tmp_primtrk_hity.clear();
795  tmp_primtrk_hitz.clear();
796  tmp_primtrk_pitch.clear();
797 
798 
799  //HY::Here comes the start/end position of primary track
800  // Find the particle vertex. We need the tracker tag here because we need to do a bit of
801  // additional work if the PFParticle is track-like to find the vertex.
802  const TVector3 vtx = pfpUtil.GetPFParticleVertex(*particle,evt,fPFParticleTag,fTrackerTag);
803  const TVector3 vtx_end(thisTrack->Trajectory().End().X(), thisTrack->Trajectory().End().Y(), thisTrack->Trajectory().End().Z());
804  primtrk_startx.push_back(vtx.X());
805  primtrk_starty.push_back(vtx.Y());
806  primtrk_startz.push_back(vtx.Z());
807  std::cout<<"vtx_X:"<<vtx.X()<<" ; vtx_Y:"<<vtx.Y()<<" ; vtx_Z:"<<vtx.Z()<<std::endl;
808 
809  primtrk_endx.push_back(vtx_end.X());
810  primtrk_endy.push_back(vtx_end.Y());
811  primtrk_endz.push_back(vtx_end.Z());
812  std::cout<<"vtx_end_X:"<<vtx_end.X()<<" ; vtx_end_Y:"<<vtx_end.Y()<<" ; vtx_end_Z:"<<vtx_end.Z()<<std::endl;
813 
814  if (vtx.Z()==vtx_end.Z()) { //warning message if Z_start=Z_end
815  std::cout<<"WARNING!! StartZ and EndZ are the same!!"<<std::endl;
816  }
817 
818 
819 
820  }
821  if(thisShower != 0x0) {
822  std::cout << "Beam particle is shower-like" << std::endl;
823  nShower++;
824  primtrk_trktag.push_back(-1);
825  }
826 
827 
828 
829  //HY Add
830  pdg_code.push_back(particle->PdgCode());
831  n_daughter.push_back(particle->NumDaughters());
832  isPrimary.push_back(particle->IsPrimary());
833  pfp_self.push_back(particle->Self());
834  //pfp_parent.push_back(particle->Parent());
835 
836  std::cout<<"pdg code:"<<particle->PdgCode()<<std::endl;
837  std::cout<<"IsPrimary:"<<particle->IsPrimary()<<std::endl;
838  std::cout<<"NumDaughters:"<<particle->NumDaughters()<<std::endl;
839  std::cout<<"Self:"<<particle->Self()<<std::endl;
840  std::cout<<"Parent:"<<particle->Parent()<<std::endl;
841 
842  if ((particle->NumDaughters())>0) {
843  for (int ii=0; ii<(particle->NumDaughters());++ii) {
844  std::cout<<"Daughter["<<ii<<"]:"<<particle->Daughter(ii)<<std::endl;
845  pfp_daughter.push_back(particle->Daughter(ii));
846  }
847  }
848  else {
849  pfp_daughter.push_back(-99);
850  }
851 
852 
853  //int pdg_code=pfpUtil.PdgCode(*particle,evt,fPFParticleTag,fShowerTag);
854  //std::cout<<"IsDaughters:"<<particle->Daughters()<<std::endl;
855  //HY::Add parameters for the primary tracks here ---------------//
856 
857  // Get track direction
858  if (thisTrack) {
859  //pdg_code=thisTrack->PdgCode();
860  //std::cout<<"pdg code:"<<pdg_code<<std::endl;
861 
862  auto trackdir = thisTrack->StartDirection();
863  std::cout<<"run/subrun/event:"<<run<<"/"<<subrun<<"/"<<event<<std::endl;
864  std::cout<<"trkDirx/trkDiry/trkDirz:"<<trackdir.X()<<"/"<<trackdir.Y()<<"/"<<trackdir.Z()<<std::endl;
865  primtrk_Dirx.push_back(trackdir.X());
866  primtrk_Diry.push_back(trackdir.Y());
867  primtrk_Dirz.push_back(trackdir.Z());
868 
869  primtrklen.push_back(thisTrack->Length()); //track length
870  std::cout<<"trk length: "<<thisTrack->Length()<<" [cm]"<<std::endl;
871  primtrkID.push_back(thisTrack->ID());
872  std::cout<<"trk ID: "<<thisTrack->ID()<<""<<std::endl; //HY::Fix me::trk ID seems wrong
873  //std::cout<<"trk ID: "<<thisTrack->TrackId()<<std::endl;
874 
875  //std::cout<<"trkDirx^2+trkDiry^2+trkDirz^2:"<<trackdir.X()*trackdir.X()+trackdir.Y()*trackdir.Y()+trackdir.Z()*trackdir.Z()<<std::endl;
876  //int nn=tracks.size()-1;
877  //cosine_beam_primtrk=tracks[nn].StartDirection().X()*trackdir.X()+tracks[nn].StartDirection().Y()*trackdir.Y()+tracks[nn].StartDirection().Z()*trackdir.Z();
878  if (tracks.size()){
879  cosine_beam_primtrk=tracks[0].StartDirection().X()*trackdir.X()+tracks[0].StartDirection().Y()*trackdir.Y()+tracks[0].StartDirection().Z()*trackdir.Z();
880  }
881  // fill a histogram of trackdir.X()*beamdir.X() + .....
882  // try to get calorimetry info of this track
883 
884  }
885  // Now we can look for the interaction point of the particle if one exists, i.e where the particle
886  // scatters off an argon nucleus. Shower-like objects won't have an interaction point, so we can
887  // check this by making sure we get a sensible position
888  const TVector3 interactionVtx = pfpUtil.GetPFParticleSecondaryVertex(*particle,evt,fPFParticleTag,fTrackerTag);
889 
890 
891  // Let's get the daughter PFParticles... we can do this simply without the utility
892  for(const int daughterID : particle->Daughters()){
893  // Daughter ID is the element of the original recoParticle vector
894  const recob::PFParticle *daughterParticle = &(recoParticles->at(daughterID));
895  std::cout << "Daughter " << daughterID << " has " << daughterParticle->NumDaughters() << " daughters" << std::endl;
896  }
897 
898  // For actually studying the objects, it is easier to have the daughters in their track and shower forms.
899  // We can use the utility to get a vector of track-like and a vector of shower-like daughters
900  const std::vector<const recob::Track*> trackDaughters = pfpUtil.GetPFParticleDaughterTracks(*particle,evt,fPFParticleTag,fTrackerTag);
901  const std::vector<const recob::Shower*> showerDaughters = pfpUtil.GetPFParticleDaughterShowers(*particle,evt,fPFParticleTag,fShowerTag);
902  std::cout << "Beam particle has " << trackDaughters.size() << " track-like daughters and " << showerDaughters.size() << " shower-like daughters." << std::endl;
903 
904  std::cout<<"# total Tracks:"<<nTrack<<std::endl;
905  std::cout<<"# total Showers:"<<nShower<<std::endl;
906  //tmp_counter++;
907  }
908  //std::cout<<"tmp_counter:"<<tmp_counter<<"\n\n\n"<<std::endl;
909  //'tmp_counter' should be the same as 'nBeamP'
910  std::cout<<"*******************************************************"<<std::endl;
911 
912  //put the track parameters in the cryo here ----------------------------------------------------------------------------//
913 
914 
915  } //if CheckIsMatched
916  } //get beam timing trigger
917 
918  } //if beam pion
919 
920  fTree->Fill();
921 }
922 
924 {
926  fTree = tfs->make<TTree>("beamana","beam analysis tree");
927  fTree->Branch("run",&run,"run/I");
928  fTree->Branch("subrun",&subrun,"subrun/I");
929  fTree->Branch("event",&event,"event/I");
930  //fTree->Branch("trigger",&trigger,"trigger/I");
931  fTree->Branch("evttime",&evttime,"evttime/D");
932  fTree->Branch("Nactivefembs",&fNactivefembs,"Nactivefembs[5]/I");
933 
934  fTree->Branch("beamPosx",&beamPosx);
935  fTree->Branch("beamPosy",&beamPosy);
936  fTree->Branch("beamPosz",&beamPosz);
937  fTree->Branch("beamDirx",&beamDirx);
938  fTree->Branch("beamDiry",&beamDiry);
939  fTree->Branch("beamDirz",&beamDirz);
940  fTree->Branch("beamMomentum",&beamMomentum);
941  fTree->Branch("tof", &tof, "tof/D");
942  fTree->Branch("tofs",&tofs);
943  fTree->Branch("ch_tofs",&ch_tofs);
944  fTree->Branch("low_pressure_status", &low_pressure_status, "low_pressure_status/S");
945  fTree->Branch("high_pressure_status", &high_pressure_status, "high_pressure_status/S");
946  fTree->Branch("low_pressure", &low_pressure, "low_pressure/D");
947  fTree->Branch("high_pressure", &high_pressure, "high_pressure/D");
948 
949  fTree->Branch("cosine_beam_primtrk", &cosine_beam_primtrk, "cosine_beam_primtrk/D");
950  fTree->Branch("primtrk_startx",&primtrk_startx);
951  fTree->Branch("primtrk_starty",&primtrk_starty);
952  fTree->Branch("primtrk_startz",&primtrk_startz);
953  //hit wire info
954  fTree->Branch("wireno_2",&wireno_2);
955  fTree->Branch("peakTime_2",&peakTime_2);
956  fTree->Branch("dq_2",&dq_2);
957  fTree->Branch("trkhitx2",&trkhitx2);
958  fTree->Branch("trkhity2",&trkhity2);
959  fTree->Branch("trkhitz2",&trkhitz2);
960  //hit wire info ends
961 
962 
963 
964  fTree->Branch("primtrk_endx",&primtrk_endx);
965  fTree->Branch("primtrk_endy",&primtrk_endy);
966  fTree->Branch("primtrk_endz",&primtrk_endz);
967 
968  fTree->Branch("primtrk_Dirx",&primtrk_Dirx);
969  fTree->Branch("primtrk_Diry",&primtrk_Diry);
970  fTree->Branch("primtrk_Dirz",&primtrk_Dirz);
971  fTree->Branch("primtrklen",&primtrklen);
972  fTree->Branch("primtrkID",&primtrkID);
973 
974  fTree->Branch("primtrk_dqdx",&primtrk_dqdx);
975  fTree->Branch("primtrk_dedx",&primtrk_dedx);
976  fTree->Branch("primtrk_resrange",&primtrk_resrange);
977  fTree->Branch("primtrk_range",&primtrk_range);
978  fTree->Branch("primtrk_hitx",&primtrk_hitx);
979  fTree->Branch("primtrk_hity",&primtrk_hity);
980  fTree->Branch("primtrk_hitz",&primtrk_hitz);
981  fTree->Branch("primtrk_pitch",&primtrk_pitch);
982  //stitched tracks info ends here
983  fTree->Branch("pdg_code", &pdg_code);
984  fTree->Branch("n_beamparticle", &n_beamparticle);
985  fTree->Branch("n_daughter", &n_daughter);
986  fTree->Branch("isPrimary", &isPrimary);
987  fTree->Branch("pfp_self", &pfp_self);
988  //fTree->Branch("pfp_parent", &pfp_parent);
989  fTree->Branch("pfp_daughter", &pfp_daughter);
990  fTree->Branch("primtrk_trktag", &primtrk_trktag);
991  //Michel tagging
992  fTree->Branch("Mendhitssecondary",&Mendhitssecondary);
993  fTree->Branch("Msecondarystartx",&Msecondarystartx);
994  fTree->Branch("Msecondarystarty",&Msecondarystarty);
995  fTree->Branch("Msecondarystartz",&Msecondarystartz);
996  fTree->Branch("Msecondaryendx",&Msecondaryendx);
997  fTree->Branch("Msecondaryendy",&Msecondaryendy);
998  fTree->Branch("Msecondaryendz",&Msecondaryendz);
999  fTree->Branch("MdQmichel",&MdQmichel);
1000  fTree->Branch("Mprimsectheta",&Mprimsectheta);
1001  fTree->Branch("MdQtrackbegin",&MdQtrackbegin);
1002  fTree->Branch("MdQtrackend",&MdQtrackend);
1003  fTree->Branch("Mtracklengthsecondary",&Mtracklengthsecondary);
1004  fTree->Branch("MtrackID",&MtrackID);
1005  fTree->Branch("trackscore",&trackscore);
1006  fTree->Branch("emscore",&emscore);
1007  fTree->Branch("michelscore",&michelscore);
1008  fTree->Branch("nonescore",&nonescore);
1009 
1010 
1011 }
1012 
1014 {
1015 
1016 }
1017 
1019 {
1020  for(int k=0; k < 5; k++)
1021  fNactivefembs[k] = -999;
1022 
1023  tof = -1;
1024  tofs.clear();
1025  ch_tofs.clear();
1026 
1027  low_pressure_status = -1;
1028  high_pressure_status = -1;
1029  low_pressure = -99;
1030  high_pressure = -99;
1031 
1032  beamPosx.clear();
1033  beamPosy.clear();
1034  beamPosz.clear();
1035  beamDirx.clear();
1036  beamDiry.clear();
1037  beamDirz.clear();
1038  beamMomentum.clear();
1039 
1040  primtrk_startx.clear();
1041  primtrk_starty.clear();
1042  primtrk_startz.clear();
1043 
1044  primtrk_endx.clear();
1045  primtrk_endy.clear();
1046  primtrk_endz.clear();
1047 
1048  primtrk_Dirx.clear();
1049  primtrk_Diry.clear();
1050  primtrk_Dirz.clear();
1051  primtrklen.clear();
1052  primtrkID.clear();
1053  primtrk_trktag.clear();
1054 
1055  //primtrk_dqdx->clear();
1056  //primtrk_resrange->clear();
1057  //primtrk_dedx->clear();
1058  primtrk_dqdx.clear();
1059  primtrk_resrange.clear();
1060  primtrk_dedx.clear();
1061  primtrk_range.clear();
1062  primtrk_hitx.clear();
1063  primtrk_hity.clear();
1064  primtrk_hitz.clear();
1065  primtrk_pitch.clear();
1066  //wire info
1067  wireno_2.clear();
1068  peakTime_2.clear();
1069  dq_2.clear();
1070  trkhitx2.clear();
1071  trkhity2.clear();
1072  trkhitz2.clear();
1073  //****************
1074 
1075  pdg_code.clear();
1076  n_beamparticle.clear();
1077  n_daughter.clear();
1078 
1079  isPrimary.clear();
1080  pfp_self.clear();
1081  //pfp_parent.clear();
1082  pfp_daughter.clear();
1083 
1084  cosine_beam_primtrk=-99;
1085  ////stitched track
1086  //New variables Michel
1087  Mendhitssecondary.clear();
1088  Msecondarystartx.clear();
1089  Msecondaryendx.clear();
1090  Msecondarystarty.clear();
1091  Msecondaryendy.clear();
1092  Msecondarystartz.clear();
1093  Msecondaryendz.clear();
1094  MdQmichel.clear();
1095  Mprimsectheta.clear();
1096  MdQtrackbegin.clear();
1097  MdQtrackend.clear();
1098  Mtracklengthsecondary.clear();
1099  MtrackID.clear();
1100  trackscore.clear();
1101  emscore.clear();
1102  michelscore.clear();
1103  nonescore.clear();
1104 }
1105 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:69
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< std::vector< double > > Msecondaryendz
std::vector< int > ch_tofs
PossibleParticleCands GetPIDCandidates(beam::ProtoDUNEBeamEvent const &beamevt, double nominal_momentum)
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
const int & GetTimingTrigger() const
std::vector< double > primtrk_starty
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
Definition: PFParticle.h:89
pionanalysis(fhicl::ParameterSet const &p)
const std::vector< double > & GetTOFs() const
std::vector< std::vector< double > > MdQtrackbegin
std::vector< std::vector< double > > Msecondarystarty
std::vector< std::vector< double > > Mprimsectheta
std::vector< double > beamDirz
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.
std::vector< double > primtrk_endx
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
void analyze(art::Event const &e) override
std::vector< double > primtrk_endy
const double & GetCKov0Pressure() const
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
std::vector< std::vector< double > > Msecondarystartz
std::vector< int > n_beamparticle
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.
std::vector< double > primtrk_Diry
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
const short & GetCKov1Status() const
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.
std::vector< double > primtrk_startz
Class to keep data related to recob::Hit associated with recob::Track.
const art::InputTag fTrackModuleLabel
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
Definition: MVAReader.h:82
STL namespace.
Information about charge reconstructed in the active volume.
std::vector< double > beamPosy
unsigned int Index
std::vector< double > beamDiry
Particle class.
double theta12(double x1, double x2, double y1, double y2, double z1, double z2, double x1p, double x2p, double y1p, double y2p, double z1p, double z2p)
std::vector< double > primtrk_Dirz
std::vector< std::vector< double > > Mtracklengthsecondary
std::vector< double > primtrkID
std::vector< std::vector< double > > Msecondaryendx
bool IsBeamlike(const recob::Track &, const art::Event &, std::string)
protoana::ProtoDUNEBeamlineUtils fBeamlineUtils
bool isRealData() const
T abs(T value)
std::vector< double > primtrk_endz
std::vector< std::vector< double > > MdQtrackend
QTextStream & reset(QTextStream &s)
std::vector< std::vector< double > > emscore
std::vector< std::vector< double > > primtrk_resrange
Vector_t StartDirection() const
Access to track direction at different points.
Definition: Track.h:131
std::vector< std::vector< double > > primtrk_dedx
const double e
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
std::vector< std::vector< int > > MtrackID
std::vector< double > primtrk_startx
Timestamp time() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void beginJob()
Definition: Breakpoints.cc:14
Point_t const & Start() const
Access to track position at different points.
Definition: Track.h:123
def key(type, name=None)
Definition: graph.py:13
std::vector< std::vector< double > > primtrk_dqdx
std::vector< std::vector< double > > primtrk_hitz
const std::vector< double > & GetRecoBeamMomenta() const
const double & GetTOF() const
std::vector< std::vector< double > > Msecondarystartx
std::vector< std::vector< double > > trackscore
key_type key() const noexcept
Definition: Ptr.h:216
T get(std::string const &key) const
Definition: ParameterSet.h:271
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.
Point_t const & Vertex() const
Definition: Track.h:124
fhicl::ParameterSet fBeamPars
std::vector< double > primtrklen
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
std::vector< double > primtrk_Dirx
p
Definition: test.py:223
std::vector< std::vector< float > > trkhity2
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
std::vector< int > pdg_code
std::vector< std::vector< double > > primtrk_hitx
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...
std::vector< std::vector< float > > peakTime_2
bool IsGoodBeamlineTrigger(art::Event const &evt) const
RunNumber_t run() const
Definition: DataViewImpl.cc:71
static int max(int a, int b)
const art::InputTag fBeamModuleLabel
std::vector< std::vector< float > > trkhitz2
Definition: tracks.py:1
std::vector< double > primtrk_range
int ID() const
Definition: Track.h:198
std::vector< std::vector< float > > dq_2
Declaration of signal hit object.
std::vector< double > beamDirx
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
const std::vector< int > & GetTOFChans() const
void End(void)
Definition: gXSecComp.cxx:210
int GetNActiveFembsForAPA(art::Event const &evt, int apa) const
Get number of active fembs in an APA.
const std::vector< const recob::Shower * > GetPFParticleDaughterShowers(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Get the daughter showers from the PFParticle.
std::vector< std::vector< double > > primtrk_pitch
std::vector< std::vector< double > > Msecondaryendy
std::vector< std::vector< double > > nonescore
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
Provides recob::Track data product.
protoana::ProtoDUNEBeamCuts beam_cuts
std::vector< int > n_daughter
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
const std::vector< recob::Track > & GetBeamTracks() const
const short & GetCKov0Status() const
std::vector< int > pfp_self
std::vector< double > tofs
std::vector< double > beamMomentum
std::vector< double > beamPosz
std::vector< std::vector< float > > trkhitx2
std::vector< std::vector< int > > wireno_2
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
std::vector< double > beamPosx
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
const bool & CheckIsMatched() const
std::vector< std::vector< int > > Mendhitssecondary
int bool
Definition: qglobal.h:345
protoana::ProtoDUNEDataUtils dataUtil
std::array< float, N > getOutput(size_t key) const
Get copy of the MVA output vector at index "key".
Definition: MVAReader.h:129
std::vector< int > isPrimary
const int & GetTOFChan() const
const std::vector< const recob::Track * > GetPFParticleDaughterTracks(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the daughter tracks from the PFParticle.
EventID id() const
Definition: Event.cc:34
std::vector< std::vector< double > > primtrk_hity
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
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
Event finding and building.
std::vector< std::vector< double > > michelscore
std::vector< std::vector< double > > MdQmichel
std::vector< int > primtrk_trktag
std::vector< int > pfp_daughter
const double & GetCKov1Pressure() const