hitrmsfinding_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////
2 // Class: hitrmsfinding ///
3 // File: hitrmsfinding_module.cc ///
4 //Description: ///
5 //drift hitrmsfinding calculation module ///
6 //dumps all the infomrmation in TTrees which needs to analysed ///
7 //contact person:apaudel@phys.ksu.edu ///
8 //////////////////////////////////////////////////////////////////////////////
13 #include "art_root_io/TFileService.h"
14 #include "art_root_io/TFileDirectory.h"
16 #include "canvas/Persistency/Common/FindManyP.h"
19 #include "fhiclcpp/ParameterSet.h"
21 #include "dune/Protodune/singlephase/DataUtils/ProtoDUNEDataUtils.h"
23 
33 #include "lardataobj/RawData/raw.h"
57 
58 #include "TFile.h"
59 #include "TTree.h"
60 #include "TDirectory.h"
61 #include "TH1.h"
62 #include "TH2.h"
63 #include "TF1.h"
64 #include "TProfile.h"
65 #include "TROOT.h"
66 #include "TStyle.h"
67 #include "TMath.h"
68 #include "TGraphErrors.h"
69 #include "TMinuit.h"
70 #include "TString.h"
71 #include "TTimeStamp.h"
72 #include "TVectorD.h"
73 #include "TCanvas.h"
74 #include "TFrame.h"
75 #include "TLine.h"
76 #include "TAxis.h"
77 #include "TTimeStamp.h"
78 
79 //Root and C++ include
80 #include "TVector3.h"
81 #include "TLorentzVector.h"
82 #include <vector>
83 #include <fstream>
84 #include "TPaveStats.h"
85 #include <iostream>
86 #include <string>
87 #include "math.h"
88 #include "stdio.h"
89 #include <iterator>
90 
91 //using namespace std;
92 
93 
94 namespace protoana{
95  class hitrmsfinding : public art::EDAnalyzer {
96  public:
97  explicit hitrmsfinding(fhicl::ParameterSet const& pset);
98  virtual ~hitrmsfinding();
99 
100  void beginJob();
101  void endJob();
102  void beginRun(const art::Run& run);
103  void analyze(const art::Event& evt);
104  void reset();
105 
106  private:
108  TTree* fEventTree;
110 
111  //These are the tree variables I will be using
112  Int_t run;
113  Int_t subrun;
114  Int_t event;
115  Double_t evttime;
117  std::vector<float> trackthetaxz;
118  std::vector<float> trackthetayz;
119  std::vector<float> trkstartx;
120  std::vector<float> trkstarty;
121  std::vector<float> trkstartz;
122  std::vector< std::vector<float> > trkstartcosxyz;
123  std::vector< std::vector<float> > trkendcosxyz;
124  std::vector<float> trkendx;
125  std::vector<float> trkendy;
126  std::vector<float> trkendz;
127 
128  std::vector<float> trkstartx_crt2;
129  std::vector<float> trkendx_crt2;
130  std::vector<float> crtreco_x0;
131  std::vector<float> crtreco_x1;
132  std::vector<float> crtreco_y0;
133  std::vector<float> crtreco_y1;
134  std::vector<float> crtreco_z0;
135  std::vector<float> crtreco_z1;
136 
137 
138 
139  std::vector<float> trklen;
140  std::vector<int> TrkID;
141  std::vector<float> xprojectedlen;
142  std::vector<double> T0_values;
143  // std::vector<double> t0crt1;
144  std::vector<double> t0crt2;
145  std::vector<double> crt2tickoffset;
146  std::vector<int> tot_trks;
147  std::vector< std::vector<float> > hit_peakT0;
148  std::vector< std::vector<int> > hit_tpc0;
149  std::vector< std::vector<int> > hit_wire0;
150  std::vector< std::vector<float> > hit_rms0;
151  std::vector< std::vector<float> > hit_deltaT;
152  std::vector< std::vector<float> > trkhitx0;
153  std::vector< std::vector<float> > trkhity0;
154  std::vector< std::vector<float> > trkhitz0;
155  std::vector< std::vector<float> > trkdq_amp0;
156  std::vector< std::vector<float> >trkdq_int0;
157  std::vector< std::vector<float> > hit_peakT1;
158  std::vector< std::vector<int> > hit_tpc1;
159  std::vector< std::vector<int> > hit_wire1;
160  std::vector< std::vector<float> > hit_rms1;
161  std::vector< std::vector<float> > trkhitx1;
162  std::vector< std::vector<float> > trkhity1;
163  std::vector< std::vector<float> > trkhitz1;
164  std::vector< std::vector<float> > trkdq_amp1;
165  std::vector< std::vector<float> > trkdq_int1;
166  std::vector< std::vector<float> > hit_peakT2;
167  std::vector< std::vector<int> > hit_tpc2;
168  std::vector< std::vector<int> > hit_wire2;
169  std::vector< std::vector<float> > hit_rms2;
170  std::vector< std::vector<float> > hit_rms_true;
171  std::vector< std::vector<float> > trkhitx2;
172  std::vector< std::vector<float> > trkhity2;
173  std::vector< std::vector<float> > trkhitz2;
174  std::vector< std::vector<float> > trkhitz_wire2;
175  std::vector< std::vector<float> > trkdq_amp2;
176  std::vector< std::vector<float> > trkdq_int2;
177  std::vector< std::vector<float> > multiplicity2;
178  std::vector< std::vector<float> > goodnessoffit2;
184  };
185 
186  //========================================================================
188  EDAnalyzer(pset),
189  fDataUtils (pset.get<fhicl::ParameterSet>("DataUtils")),
190  fHitsModuleLabel (pset.get< std::string >("HitsModuleLabel","") ),
191  fTrackModuleLabel (pset.get< std::string >("TrackModuleLabel","") ),
192  fCalorimetryModuleLabel (pset.get< std::string >("CalorimetryModuleLabel","") ),
193  fSaveTrackInfo (pset.get< bool>("SaveTrackInfo",false)),
194  fSaveCaloInfo (pset.get< bool>("SaveCaloInfo",false))
195 
196  {
197  if (fSaveTrackInfo == false) fSaveCaloInfo = false;
198  }
199 
200  //========================================================================
202  }
203  //========================================================================
204 
205  //========================================================================
207  std::cout<<"job begin..."<<std::endl;
209  fEventTree = tfs->make<TTree>("Event", "Event Tree from Reco");
210  fEventTree->Branch("event", &event,"event/I");
211  fEventTree->Branch("evttime",&evttime,"evttime/D");
212  fEventTree->Branch("run", &run,"run/I");
213  fEventTree->Branch("Nactivefembs",&fNactivefembs,"Nactivefembs[6]/I");
214  fEventTree->Branch("subrun", &subrun,"surbrun/I");
215  fEventTree->Branch("T0_values",&T0_values);
216  fEventTree->Branch("xprojectedlen",&xprojectedlen);
217  fEventTree->Branch("trackthetaxz",&trackthetaxz);
218  fEventTree->Branch("trackthetayz",&trackthetayz);
219  fEventTree->Branch("trkstartx",&trkstartx);
220  fEventTree->Branch("trkstarty",&trkstarty);
221  fEventTree->Branch("trkstartz",&trkstartz);
222  fEventTree->Branch("trkendx",&trkendx);
223  fEventTree->Branch("trkendy",&trkendy);
224  fEventTree->Branch("trkendz",&trkendz);
225  fEventTree->Branch("trkendx_crt2",&trkendx_crt2);
226  fEventTree->Branch("trkstartx_crt2",&trkstartx_crt2);
227  fEventTree->Branch("crtreco_x0",&crtreco_x0);
228  fEventTree->Branch("crtreco_x1",&crtreco_x1);
229  fEventTree->Branch("crtreco_y0",&crtreco_y0);
230  fEventTree->Branch("crtreco_y1",&crtreco_y1);
231  fEventTree->Branch("crtreco_z0",&crtreco_z0);
232  fEventTree->Branch("crtreco_z1",&crtreco_z1);
233  fEventTree->Branch("crt2tickoffset",&crt2tickoffset);
234  fEventTree->Branch("trklen",&trklen);
235  fEventTree->Branch("TrkID",&TrkID);
236  fEventTree->Branch("tot_trks",&tot_trks);
237  fEventTree->Branch("hit_peakT0",&hit_peakT0);
238  fEventTree->Branch("hit_tpc0",&hit_tpc0);
239  fEventTree->Branch("hit_wire0",&hit_wire0);
240  fEventTree->Branch("hit_rms0",&hit_rms0);
241  fEventTree->Branch("hit_deltaT",&hit_deltaT);
242  fEventTree->Branch("trkhitx0",&trkhitx0);
243  fEventTree->Branch("trkhity0",&trkhity0);
244  fEventTree->Branch("trkhitz0",&trkhitz0);
245  fEventTree->Branch("trkdq_int0",&trkdq_int0);
246  fEventTree->Branch("trkdq_amp0",&trkdq_amp0);
247  fEventTree->Branch("hit_peakT1",&hit_peakT1);
248  fEventTree->Branch("hit_tpc1",&hit_tpc1);
249  fEventTree->Branch("hit_wire1",&hit_wire1);
250  fEventTree->Branch("hit_rms1",&hit_rms1);
251  fEventTree->Branch("trkhitx1",&trkhitx1);
252  fEventTree->Branch("trkhity1",&trkhity1);
253  fEventTree->Branch("trkhitz1",&trkhitz1);
254  fEventTree->Branch("trkdq_int1",&trkdq_int1);
255  fEventTree->Branch("trkdq_amp1",&trkdq_amp1);
256  fEventTree->Branch("hit_peakT2",&hit_peakT2);
257  fEventTree->Branch("hit_tpc2",&hit_tpc2);
258  fEventTree->Branch("hit_wire2",&hit_wire2);
259  fEventTree->Branch("hit_rms2",&hit_rms2);
260  fEventTree->Branch("hit_rms_true",&hit_rms_true);
261  fEventTree->Branch("trkhitx2",&trkhitx2);
262  fEventTree->Branch("trkhity2",&trkhity2);
263  fEventTree->Branch("trkhitz2",&trkhitz2);
264  fEventTree->Branch("trkhitz_wire2",&trkhitz_wire2);
265  fEventTree->Branch("trkdq_int2",&trkdq_int2);
266  fEventTree->Branch("trkdq_amp2",&trkdq_amp2);
267  fEventTree->Branch("trkstartcosxyz",&trkstartcosxyz);
268  fEventTree->Branch("trkendcosxyz",&trkendcosxyz);
269  fEventTree->Branch("multiplicity2",&multiplicity2);
270  fEventTree->Branch("goodnessoffit2",&goodnessoffit2);
271  // fEventTree->Branch("t0crt1",&t0crt1);
272  fEventTree->Branch("t0crt2",&t0crt2);
273  }
274 
275  //========================================================================
277 
278  }
279 
280  //========================================================================
282  mf::LogInfo("hitrmsfinding")<<"begin run..."<<std::endl;
283  }
284  //========================================================================
285 
286  //========================================================================
287 
288  //========================================================================
289 
290  void hitrmsfinding::analyze( const art::Event& evt){//analyze
291  reset();
292 
293  // art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
295  //Detector properties service
296  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataFor(evt);
297 
298  std::vector<art::Ptr<recob::Track> > tracklist;
299  auto trackListHandle = evt.getHandle< std::vector<recob::Track> >("pandoraTrack");
300  if(trackListHandle) {
301  art::fill_ptr_vector(tracklist, trackListHandle);
302  }
303  else return;
304 
305  std::vector<art::Ptr<recob::PFParticle> > pfplist;
306  auto PFPListHandle = evt.getHandle< std::vector<recob::PFParticle> >("pandora");
307  if(PFPListHandle) art::fill_ptr_vector(pfplist, PFPListHandle);
308 
309  std::vector<art::Ptr<recob::Hit>> hitlist;
310  auto hitListHandle = evt.getHandle< std::vector<recob::Hit> >(fHitsModuleLabel);
311  if (hitListHandle) art::fill_ptr_vector(hitlist, hitListHandle);
312  art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trackListHandle, evt, fTrackModuleLabel); // to associate tracks and hits
313  art::FindManyP<anab::T0> trk_t0_assn_v(PFPListHandle, evt ,"pandora");
314  art::FindManyP<recob::PFParticle> pfp_trk_assn(trackListHandle,evt,"pandoraTrack");
315  art::FindManyP<anab::T0> fmT0(trackListHandle, evt ,"pmtrack");
316  std::vector<const sim::SimChannel*> fSimChannels;
317  try{
318  evt.getView("largeant", fSimChannels);
319  }catch (art::Exception const&e){
320  }
321 
322  //Get 2-CRT T0
323  art::FindManyP<anab::T0> fmt0crt2(trackListHandle, evt, "crtreco");
324  art::FindManyP<anab::CosmicTag> fmctcrt2(trackListHandle, evt, "crtreco");
325 
326  //Get 1-CRT T0
327  // art::FindManyP<anab::T0> fmt0crt1(trackListHandle, evt, "crttag");
328  // art::FindManyP<anab::CosmicTag> fmctcrt1(trackListHandle, evt, "crttag");
329 
330  run = evt.run();
331  subrun = evt.subRun();
332  event = evt.id().event();
333  art::Timestamp ts = evt.time();
334  TTimeStamp tts(ts.timeHigh(), ts.timeLow());
335  evttime=tts.AsDouble();
336 
337 
338 
339  // Get number of active fembs
340  if(!evt.isRealData()){
341  for(int k=0; k < 6; k++)
342  fNactivefembs[k] = 20;
343  }
344  else{
345  for(int k=0; k < 6; k++)
347  }
348 
349 
350  //defining the 1D temporary storage vectors
351  std::vector< float> peakT_0; std::vector< float> peakT_1; std::vector< float> peakT_2;
352  std::vector< int > tpc_0; std::vector< int > tpc_1; std::vector<int> tpc_2;
353  std::vector< int > wire_0; std::vector< int > wire_1; std::vector<int> wire_2;
354  std::vector< float > int_0; std::vector< float > int_1; std::vector<float> int_2;
355  std::vector< float > amp_0; std::vector< float > amp_1; std::vector<float> amp_2;
356  std::vector<float> rms_0; std::vector<float> rms_1; std::vector<float> rms_2;
357  std::vector<float> hitx_0; std::vector<float> hitx_1; std::vector<float> hitx_2;
358  std::vector<float> hity_0; std::vector<float> hity_1; std::vector<float> hity_2;
359  std::vector<float> hitz_0; std::vector<float> hitz_1; std::vector<float> hitz_2;
360  std::vector<float> hitz_wire2; std::vector<float> startcosxyz; std::vector<float> endcosxyz;
361  std::vector<float> dT_buffer; std::vector<float> gof, multi,truerms;
362 
363  float max_value;
364  float min_value;
365  int trks=0;
366  size_t NTracks = tracklist.size();
367  for(size_t i=0; i<NTracks;++i){
368  double xoffset=0.0;
369  //clearing the 1D temporary storage vectors
370  peakT_0.clear(); peakT_1.clear(); peakT_2.clear();
371  tpc_0.clear(); tpc_1.clear(); tpc_2.clear();
372  wire_0.clear(); wire_1.clear(); wire_2.clear();
373  int_0.clear(); int_1.clear() ; int_2.clear();
374  amp_0.clear(); amp_1.clear() ; amp_2.clear();
375  rms_0.clear(); rms_1.clear(); rms_2.clear();
376  hitx_0.clear(); hitx_1.clear(); hitx_2.clear();
377  hity_0.clear(); hity_1.clear(); hity_2.clear();
378  hitz_0.clear(); hitz_1.clear(); hitz_2.clear();
379  hitz_wire2.clear(); startcosxyz.clear();endcosxyz.clear();
380  dT_buffer.clear(); gof.clear(); multi.clear();
381  truerms.clear();
382 
383 
384  art::Ptr<recob::Track> ptrack(trackListHandle, i);
385 
386  ///this block just saves the t0 values while I include entries with no T0s as well also this saves T0 coming from pandroaTrack alg only
387  double t_zero=-999999;
388  max_value=0.0;
389  min_value=0.0;
390  /* if(fTrackModuleLabel=="pandoraTrack"){
391  std::vector<art::Ptr<recob::PFParticle>> pfps=pfp_trk_assn.at(i);
392  if(!pfps.size()) continue;
393  std::vector<art::Ptr<anab::T0>> t0s=trk_t0_assn_v.at(pfps[0].key());
394  // if(!t0s.size()) continue;
395  //auto t0 = t0s.at(0);
396  // double t_zero=t0->Time();
397  if(t0s.size()==0) continue;
398  if(t0s.size()){
399  auto t0=t0s.at(0);
400  t_zero=t0->Time();
401  }
402  }
403 
404  if(fTrackModuleLabel=="pmtrack"){
405  std::vector<art::Ptr<anab::T0>> T0s=fmT0.at(i);
406  if(T0s.size()==0)
407  continue;
408  }
409  */
410  // all_trks++;
411  const recob::Track& track = *ptrack;
412 
413 
414  double this_t0crt2=-DBL_MAX;
415  //double this_t0crt1=-DBL_MAX;
416  double this_crt2x0 = -DBL_MAX;
417  double this_crt2x1 = -DBL_MAX;
418  double this_crt2y0 = -DBL_MAX;
419  double this_crt2y1 = -DBL_MAX;
420  double this_crt2z0 = -DBL_MAX;
421  double this_crt2z1 = -DBL_MAX;
422 
423  bool test1=true;
424  // bool test2=true;
425  if(fmt0crt2.isValid()){
426  auto const& vt0crt2 = fmt0crt2.at(i);
427  if (!vt0crt2.empty()){
428  this_t0crt2 = vt0crt2[0]->Time();
429  test1=false;
430  }
431 
432  }
433  if(test1) continue;
434  if (fmctcrt2.isValid()){
435  auto const& vctcrt2 = fmctcrt2.at(i);
436  if (!vctcrt2.empty()){
437  this_crt2x0 = vctcrt2[0]->EndPoint1()[0];
438  this_crt2x1 = vctcrt2[0]->EndPoint2()[0];
439  this_crt2y0 = vctcrt2[0]->EndPoint1()[1];
440  this_crt2y1 = vctcrt2[0]->EndPoint2()[1];
441  this_crt2z0 = vctcrt2[0]->EndPoint1()[2];
442  this_crt2z1 = vctcrt2[0]->EndPoint2()[2];
443 
444  }
445  }
446 
447 
448 
449 
450  /* if (fmt0crt1.isValid()){
451  auto const& vt0crt1 = fmt0crt1.at(i);
452  if (!vt0crt1.empty()){
453  this_t0crt1 = vt0crt1[0]->Time();
454  test2=false;
455  }
456  }*/
457  // if(test1 && test2) continue;
458 
459 
460 
461 
462  auto pos = track.Vertex();
463  auto dir_start = track.VertexDirection();
464  auto dir_end = track.EndDirection();
465  auto end = track.End();
466  double theta_xz = std::atan2(dir_start.X(), dir_start.Z());
467  double theta_yz = std::atan2(dir_start.Y(), dir_start.Z());
468 
469  int planenum=999;
470  float xpos=-9999;
471  float ypos=-9999;
472  float zpos=-9999;
473  auto allHits=fmthm.at(i);
474  double ticksoffset=0;
475 
476  // if (this_t0crt2 > -DBL_MAX) ticksoffset = this_t0crt2/500.+detProp.GetXTicksOffset(allHits[0]->WireID());
477  if (this_t0crt2 > -DBL_MAX) ticksoffset = this_t0crt2/500.+detProp.GetXTicksOffset (allHits[0]->WireID().Plane, allHits[0]->WireID().TPC, allHits[0]->WireID().Cryostat);
478  // else if (this_t0crt1 > -DBL_MAX) ticksoffset = this_t0crt1/500.+detProp.GetXTicksOffset(allHits[0]->WireID());
479  xoffset = detProp.ConvertTicksToX(ticksoffset,allHits[0]->WireID());
480  std::cout<<"tickoffset , x offset "<<ticksoffset<<" "<<xoffset<<" default term "<<detProp.GetXTicksOffset (allHits[10]->WireID().Plane, allHits[10]->WireID().TPC, allHits[10]->WireID().Cryostat)<<std::endl;
481 
482 
483 
484  //hits and calorimetry loop
485  if(fmthm.isValid()){
486  auto vhit=fmthm.at(i);
487  auto vmeta=fmthm.data(i);
488  for (size_t ii = 0; ii<vhit.size(); ++ii){ //loop over all meta data hit
489  bool fBadhit = false;
490  if (vmeta[ii]->Index() == static_cast<unsigned int>(std::numeric_limits<int>::max())){
491  fBadhit = true;
492  //cout<<"fBadHit"<<fBadhit<<endl;
493  continue;
494  }
495  if (vmeta[ii]->Index()>=tracklist[i]->NumberTrajectoryPoints()){
496  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!!";
497  }
498  if (!tracklist[i]->HasValidPoint(vmeta[ii]->Index())){
499  fBadhit = true;
500  // cout<<"had valid point "<<fBadhit<<endl;
501  continue;
502  }
503 
504  auto loc = tracklist[i]->LocationAtPoint(vmeta[ii]->Index());
505  xpos=loc.X();
506  ypos=loc.Y();
507  zpos=loc.Z();
508  // cout<<"x, y, z "<<xpos<<" "<<ypos<<" "<<zpos<<endl;
509  // cout<<"BadHit"<<fBadhit<<endl;
510  if (fBadhit) continue; //HY::If BAD hit, skip this hit and go next
511  if (zpos<-100) continue; //hit not on track
512  planenum=vhit[ii]->WireID().Plane;
513  if(planenum==0){
514  peakT_0.push_back(vhit[ii]->PeakTime());
515  tpc_0.push_back(vhit[ii]->WireID().TPC);
516  wire_0.push_back(vhit[ii]->WireID().Wire);
517  int_0.push_back(vhit[ii]->Integral());
518  amp_0.push_back(vhit[ii]->PeakAmplitude());
519  rms_0.push_back(vhit[ii]->RMS());
520  hitx_0.push_back(xpos);
521  hity_0.push_back(ypos);
522  hitz_0.push_back(zpos);
523  }//planenum 0
524  if(planenum==1){
525  peakT_1.push_back(vhit[ii]->PeakTime());
526  tpc_1.push_back(vhit[ii]->WireID().TPC);
527  wire_1.push_back(vhit[ii]->WireID().Wire);
528  int_1.push_back(vhit[ii]->Integral());
529  amp_1.push_back(vhit[ii]->PeakAmplitude());
530  rms_1.push_back(vhit[ii]->RMS());
531  hitx_1.push_back(xpos);
532  hity_1.push_back(ypos);
533  hitz_1.push_back(zpos);
534  }//planenum 1
535  if(planenum==2){
536  peakT_2.push_back(vhit[ii]->PeakTime()-this_t0crt2/500.0);
537  tpc_2.push_back(vhit[ii]->WireID().TPC);
538  wire_2.push_back(vhit[ii]->WireID().Wire);
539  int_2.push_back(vhit[ii]->Integral());
540  amp_2.push_back(vhit[ii]->PeakAmplitude());
541  rms_2.push_back(vhit[ii]->RMS());
542  dT_buffer.push_back(vhit[ii]->EndTick()-vhit[ii]->StartTick());
543  hitx_2.push_back(xpos);
544  hity_2.push_back(ypos);
545  hitz_2.push_back(zpos);
546  gof.push_back(vhit[ii]->GoodnessOfFit());
547  multi.push_back(vhit[ii]->Multiplicity());
548  double xyzStart[3];
549  double xyzEnd[3];
550  unsigned int wireno=vhit[ii]->WireID().Wire;
551  fGeometry->WireEndPoints(0,vhit[ii]->WireID().TPC,2,wireno, xyzStart, xyzEnd);
552  hitz_wire2.push_back(xyzStart[2]);
553  double truermsb=-1;
554 
555  //section for using tuth information
556  unsigned int t0=vhit[ii]->PeakTime()-3*(vhit[ii]->RMS());
557  if(t0<0) t0=0;
558  unsigned int t1=vhit[ii]->PeakTime()+3*(vhit[ii]->RMS());
559  if(t1>6000) t1=6000-1;
560 
561  if(!evt.isRealData()){
562  const sim::SimChannel* chan=0;
563  for(size_t sc=0;sc<fSimChannels.size();++sc){
564  if(fSimChannels[sc]->Channel()==vhit[ii]->Channel()) chan=fSimChannels[sc];
565  }
566  if(chan){
567  const auto &tdcidemap = chan->TDCIDEMap();
568  double hit_ch=0;
569  double mean_t=0;
570  double mean_t2=0;
571  double hit_rmsvalue=0;
572  for(auto mapitr = tdcidemap.begin(); mapitr != tdcidemap.end(); mapitr++){
573  if(!((*mapitr).first>t0 && (*mapitr).first<=t1)) continue;
574  // loop over the vector of IDE objects.
575  int hit_nelec=0;
576  const std::vector<sim::IDE> idevec = (*mapitr).second;
577  for(size_t iv = 0; iv < idevec.size(); ++iv){
578  hit_nelec+=idevec[iv].numElectrons;
579  }//iv loop
580  hit_ch+=hit_nelec;
581  // std::cout<<"hit_ch "<<hit_ch<<std::endl;
582  int j=(*mapitr).first;
583  mean_t+=double(j)*double(hit_nelec);
584  double jterm=double(j)*double(j)*double(hit_nelec);
585  mean_t2=mean_t2+jterm;
586  }//mapitr loop
587  mean_t/=hit_ch;
588  mean_t2/=hit_ch;
589  hit_rmsvalue=sqrt(mean_t2-mean_t*mean_t);
590  // std::cout<<"hit rms "<<hit_rmsvalue<<" reco rms "<<vhit[ii]->RMS()<<std::endl;
591  truermsb=hit_rmsvalue;
592  }//if(chan)
593  }//!evt.IsRealData
594  truerms.push_back(truermsb);
595 
596 
597  }//planenum 2
598  }//loop over vhit
599  }//fmthm valid
600  //hits and calorimetry loop
601  if(peakT_2.size()<10) continue;
602  max_value=*std::max_element(peakT_2.begin(),peakT_2.end());
603  min_value=*std::min_element(peakT_2.begin(),peakT_2.end());
604  // if(max_value-min_value<4300) continue;
605  std::cout<<max_value<<" "<<min_value<<std::endl;
606  trks++;
607  hit_peakT0.push_back(peakT_0);
608  hit_tpc0.push_back(tpc_0);
609  hit_wire0.push_back(wire_0);
610  hit_rms0.push_back(rms_0);
611  trkhitx0.push_back(hitx_0);
612  trkhity0.push_back(hity_0);
613  trkhitz0.push_back(hitz_0);
614  trkdq_amp0.push_back(amp_0);
615  trkdq_int0.push_back(int_0);
616 
617  hit_peakT1.push_back(peakT_1);
618  hit_tpc1.push_back(tpc_1);
619  hit_wire1.push_back(wire_1);
620  hit_rms1.push_back(rms_1);
621  trkhitx1.push_back(hitx_1);
622  trkhity1.push_back(hity_1);
623  trkhitz1.push_back(hitz_1);
624  trkdq_amp1.push_back(amp_1);
625  trkdq_int1.push_back(int_1);
626 
627  hit_peakT2.push_back(peakT_2);
628  hit_tpc2.push_back(tpc_2);
629  hit_wire2.push_back(wire_2);
630  hit_rms2.push_back(rms_2);
631  hit_rms_true.push_back(truerms);
632  trkhitx2.push_back(hitx_2);
633  trkhity2.push_back(hity_2);
634  trkhitz2.push_back(hitz_2);
635  trkhitz_wire2.push_back(hitz_wire2);
636  trkdq_amp2.push_back(amp_2);
637  trkdq_int2.push_back(int_2);
638  hit_deltaT.push_back(dT_buffer);
639  multiplicity2.push_back(multi);
640  goodnessoffit2.push_back(gof);
641 
642 
643 
644  xprojectedlen.push_back(TMath::Abs(end.X()-pos.X()));
645  trackthetaxz.push_back(theta_xz);
646  trackthetayz.push_back(theta_yz);
647  trkstartx.push_back(pos.X());
648  trkstartx_crt2.push_back(pos.X()-xoffset);
649  trkstarty.push_back(pos.Y());
650  trkstartz.push_back(pos.Z());
651  startcosxyz.push_back(dir_start.X());
652  startcosxyz.push_back(dir_start.Y());
653  startcosxyz.push_back(dir_start.Z());
654  endcosxyz.push_back(dir_end.X());
655  endcosxyz.push_back(dir_end.Y());
656  endcosxyz.push_back(dir_end.Z());
657 
658  trkstartcosxyz.push_back(startcosxyz);
659  trkendcosxyz.push_back(endcosxyz);
660  trkendx.push_back(end.X());
661  trkendx_crt2.push_back(end.X()-xoffset);
662  crtreco_x0.push_back(this_crt2x0);
663  crtreco_x1.push_back(this_crt2x1);
664  crtreco_y0.push_back(this_crt2y0);
665  crtreco_y1.push_back(this_crt2y1);
666  crtreco_z0.push_back(this_crt2z0);
667  crtreco_z1.push_back(this_crt2z1);
668 
669  trkendy.push_back(end.Y());
670  trkendz.push_back(end.Z());
671  trklen.push_back(track.Length());
672  TrkID.push_back(track.ID());
673  T0_values.push_back(t_zero);
674  crt2tickoffset.push_back(ticksoffset);
675  t0crt2.push_back(this_t0crt2/500.0);
676  } // loop over trks...
677  tot_trks.push_back(trks);
678  fEventTree->Fill();
679  } // end of analyze function
680 
681  /////////////////// Defintion of reset function ///////////
683  run = -9999;
684  subrun = -9999;
685  event = -9999;
686  evttime = -9999;
687  //all_trks = -9999;
688  for(int k=0; k < 6; k++)
689  fNactivefembs[k] = -9999;
690  trackthetaxz.clear();
691  trackthetayz.clear();
692  trkstartx.clear();
693  trkstartx_crt2.clear();
694  trkendx_crt2.clear();
695  trkstarty.clear();
696  trkstartz.clear();
697  trkstartcosxyz.clear();
698  trkendcosxyz.clear();
699  trkendx.clear();
700  trkendy.clear();
701  trkendz.clear();
702  trklen.clear();
703  TrkID.clear();
704  tot_trks.clear();
705  T0_values.clear();
706  xprojectedlen.clear();
707  hit_peakT0.clear();
708  hit_tpc0.clear();
709  hit_wire0.clear();
710  trkhitx0.clear();
711  trkhity0.clear();
712  trkhitz0.clear();
713  trkdq_int0.clear();
714  trkdq_amp0.clear();
715  hit_rms0.clear();
716  hit_peakT1.clear();
717  hit_tpc1.clear();
718  hit_wire1.clear();
719  trkhitx1.clear();
720  trkhity1.clear();
721  trkhitz1.clear();
722  trkdq_int1.clear();
723  trkdq_amp1.clear();
724  hit_rms1.clear();
725  hit_peakT2.clear();
726  hit_tpc2.clear();
727  hit_wire2.clear();
728  trkhitx2.clear();
729  trkhity2.clear();
730  trkhitz2.clear();
731  trkhitz_wire2.clear();
732  trkdq_int2.clear();
733  trkdq_amp2.clear();
734  hit_rms2.clear();
735  hit_deltaT.clear();
736  multiplicity2.clear();
737  goodnessoffit2.clear();
738  hit_rms_true.clear();
739  crtreco_x0.clear();
740  crtreco_x1.clear();
741  crtreco_y0.clear();
742  crtreco_y1.clear();
743  crtreco_z0.clear();
744  crtreco_z1.clear();
745  crt2tickoffset.clear();
746 
747  // t0crt1.clear();
748  t0crt2.clear();
749 
750  }
751  //////////////////////// End of definition ///////////////
752 
754 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< float > trkendz
code to link reconstructed objects back to the MC truth information
std::vector< float > trkstartx
std::vector< float > trkendx
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
std::vector< double > crt2tickoffset
std::vector< std::vector< float > > trkdq_amp0
std::vector< std::vector< float > > trkdq_int0
Energy deposited on a readout channel by simulated tracks.
Definition: SimChannel.h:140
std::vector< std::vector< int > > hit_wire1
TH3F * xpos
Definition: doAna.cpp:29
std::vector< std::vector< float > > trkhity2
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< std::vector< int > > hit_tpc0
std::vector< std::vector< float > > trkhitx1
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
std::vector< std::vector< float > > hit_rms_true
std::vector< std::vector< float > > trkhity1
std::vector< float > trkstarty
std::vector< std::vector< float > > trkhity0
Class to keep data related to recob::Hit associated with recob::Track.
Vector_t VertexDirection() const
Definition: Track.h:132
STL namespace.
std::vector< std::vector< float > > trkstartcosxyz
unsigned int Index
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Particle class.
object containing MC flux information
std::vector< std::vector< float > > trkhitz2
art framework interface to geometry description
Definition: Run.h:17
TH3F * ypos
Definition: doAna.cpp:30
std::vector< std::vector< float > > trkhitx0
std::vector< std::vector< float > > hit_peakT2
std::vector< float > trkstartx_crt2
std::vector< std::vector< float > > hit_rms1
bool isRealData() const
std::vector< std::vector< float > > goodnessoffit2
std::vector< std::vector< float > > hit_rms0
std::vector< float > crtreco_x1
TH3F * zpos
Definition: doAna.cpp:31
const double e
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
Timestamp time() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
Point_t const & Vertex() const
Definition: Track.h:124
std::vector< std::vector< float > > trkdq_int1
std::vector< std::vector< float > > trkdq_int2
std::vector< std::vector< float > > hit_deltaT
std::vector< std::vector< float > > hit_peakT1
std::vector< std::vector< float > > trkhitx2
std::vector< float > trackthetayz
void analyze(const art::Event &evt)
std::vector< std::vector< int > > hit_tpc1
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
hitrmsfinding(fhicl::ParameterSet const &pset)
std::vector< float > crtreco_z0
RunNumber_t run() const
Definition: DataViewImpl.cc:71
static int max(int a, int b)
Description of geometry of one entire detector.
Definition of data types for geometry description.
std::vector< std::vector< float > > trkdq_amp1
std::vector< std::vector< float > > trkhitz_wire2
geo::GeometryCore const * fGeometry
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< double > T0_values
int ID() const
Definition: Track.h:198
std::vector< std::vector< float > > hit_peakT0
Declaration of signal hit object.
std::vector< double > t0crt2
std::vector< float > xprojectedlen
std::vector< std::vector< float > > trkendcosxyz
std::vector< float > crtreco_y1
int GetNActiveFembsForAPA(art::Event const &evt, int apa) const
Get number of active fembs in an APA.
Vector_t EndDirection() const
Definition: Track.h:133
std::vector< float > trkendy
std::vector< std::vector< float > > trkhitz1
std::vector< float > trackthetaxz
std::vector< float > crtreco_y0
Provides recob::Track data product.
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
std::vector< std::vector< int > > hit_wire2
EventNumber_t event() const
Definition: EventID.h:116
Point_t const & End() const
Definition: Track.h:125
Declaration of basic channel signal object.
TDCIDEs_t const & TDCIDEMap() const
Returns all the deposited energy information as stored.
Definition: SimChannel.h:328
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:500
std::vector< float > crtreco_x0
std::vector< std::vector< float > > trkhitz0
TCEvent evt
Definition: DataStructs.cxx:7
std::vector< std::vector< int > > hit_wire0
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
recob::tracking::Plane Plane
Definition: TrackState.h:17
std::vector< std::vector< int > > hit_tpc2
std::vector< float > trklen
int bool
Definition: qglobal.h:345
std::vector< float > trkendx_crt2
std::vector< float > trkstartz
EventID id() const
Definition: Event.cc:34
std::vector< std::vector< float > > multiplicity2
std::vector< std::vector< float > > hit_rms2
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
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void beginRun(const art::Run &run)
QTextStream & endl(QTextStream &s)
Event finding and building.
std::vector< float > crtreco_z1
std::vector< std::vector< float > > trkdq_amp2