hitrms_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////
2 /// Class: hitrms ///
3 /// File: hitrms_module.cc ///
4 /// Description: Module for calculations with hit information saved ///
5 /// following deconvolution. Information is taken from ///
6 /// MC samples or data files and put into TTrees to be ///
7 /// analyzed. ///
8 /// Contact Person: ehinkle@uchicago.edu ///
9 /// Written by: Ajib Paudel ///
10 /// Modified by: Elise Hinkle ///
11 /// Last Date Modified: April 1, 2021 ///
12 //////////////////////////////////////////////////////////////////////////////
13 
18 #include "art_root_io/TFileService.h"
19 #include "art_root_io/TFileDirectory.h"
21 #include "canvas/Persistency/Common/FindManyP.h"
24 #include "fhiclcpp/ParameterSet.h"
26 #include "dune/Protodune/singlephase/DataUtils/ProtoDUNEDataUtils.h"
28 
38 #include "lardataobj/RawData/raw.h"
62 
63 #include "TFile.h"
64 #include "TTree.h"
65 #include "TDirectory.h"
66 #include "TH1.h"
67 #include "TH2.h"
68 #include "TF1.h"
69 #include "TProfile.h"
70 #include "TROOT.h"
71 #include "TStyle.h"
72 #include "TMath.h"
73 #include "TGraphErrors.h"
74 #include "TMinuit.h"
75 #include "TString.h"
76 #include "TTimeStamp.h"
77 #include "TVectorD.h"
78 #include "TCanvas.h"
79 #include "TFrame.h"
80 #include "TLine.h"
81 #include "TAxis.h"
82 #include "TTimeStamp.h"
83 
84 //Root and C++ include
85 #include "TVector3.h"
86 #include "TLorentzVector.h"
87 #include <vector>
88 #include <fstream>
89 #include "TPaveStats.h"
90 #include <iostream>
91 #include <string>
92 #include "math.h"
93 #include "stdio.h"
94 #include <iterator>
95 
96 //using namespace std;
97 
98 
99 namespace protoana{
100  class hitrms : public art::EDAnalyzer {
101  public:
102  explicit hitrms(fhicl::ParameterSet const& pset);
103  virtual ~hitrms();
104 
105  void beginJob();
106  void endJob();
107  void beginRun(const art::Run& run);
108  void analyze(const art::Event& evt);
109  void reset();
110 
111  private:
112  unsigned int fWaveformSize; // Full waveform size
114  TTree* fEventTree;
116 
117  //These are the tree variables I will be using
118  Int_t run;
119  Int_t subrun;
120  Int_t event;
121  Double_t evttime;
123  std::vector<float> trackthetaxz;
124  std::vector<float> trackthetayz;
125  std::vector<float> trkstartx;
126  std::vector<float> trkstarty;
127  std::vector<float> trkstartz;
128  std::vector< std::vector<float> > trkstartcosxyz;
129  std::vector< std::vector<float> > trkendcosxyz;
130  std::vector<float> trkendx;
131  std::vector<float> trkendy;
132  std::vector<float> trkendz;
133 
134  std::vector<float> trkstartx_crt2;
135  std::vector<float> trkendx_crt2;
136  std::vector<float> crtreco_x0;
137  std::vector<float> crtreco_x1;
138  std::vector<float> crtreco_y0;
139  std::vector<float> crtreco_y1;
140  std::vector<float> crtreco_z0;
141  std::vector<float> crtreco_z1;
142 
143 
144 
145  std::vector<float> trklen;
146  std::vector<int> TrkID;
147  std::vector<float> xprojectedlen;
148  std::vector<double> T0_values;
149  // std::vector<double> t0crt1;
150  std::vector<double> t0crt2;
151  std::vector<double> crt2tickoffset;
152  std::vector<int> tot_trks;
153  std::vector< std::vector<float> > hit_peakT0;
154  std::vector< std::vector<int> > hit_tpc0;
155  std::vector< std::vector<int> > hit_wire0;
156  std::vector< std::vector<float> > hit_rms0;
157  std::vector< std::vector<float> > hit_deltaT;
158  std::vector< std::vector<float> > trkhitx0;
159  std::vector< std::vector<float> > trkhity0;
160  std::vector< std::vector<float> > trkhitz0;
161  std::vector< std::vector<float> > trkdq_amp0;
162  std::vector< std::vector<float> >trkdq_int0;
163  std::vector< std::vector<float> > hit_peakT1;
164  std::vector< std::vector<int> > hit_tpc1;
165  std::vector< std::vector<int> > hit_wire1;
166  std::vector< std::vector<float> > hit_rms1;
167  std::vector< std::vector<float> > trkhitx1;
168  std::vector< std::vector<float> > trkhity1;
169  std::vector< std::vector<float> > trkhitz1;
170  std::vector< std::vector<float> > trkdq_amp1;
171  std::vector< std::vector<float> > trkdq_int1;
172  std::vector< std::vector<float> > hit_peakT2;
173  std::vector< std::vector<int> > hit_tpc2;
174  std::vector< std::vector<int> > hit_wire2;
175  std::vector< std::vector<float> > hit_rms2;
176  // std::vector< std::vector<float> > hit_rmsraw2; // RAWDIGITS
177  // std::vector< std::vector<float> > hit_peakTraw2; // RAWDIGITS
178  // float hit_signal[10][5000][60];//[TrackIndex, hitindex,peakTindex]signal for each hit peaktime-30 to peaktime+30 ticks // RAWDIGITS
179  std::vector< std::vector<float> > hit_rms_true;
180  std::vector< std::vector<float> > trkhitx2;
181  std::vector< std::vector<float> > trkhity2;
182  std::vector< std::vector<float> > trkhitz2;
183  std::vector< std::vector<float> > trkhitz_wire2;
184  std::vector< std::vector<float> > trkdq_amp2;
185  std::vector< std::vector<float> > trkdq_int2;
186  std::vector< std::vector<float> > multiplicity2;
187  std::vector< std::vector<float> > goodnessoffit2;
195  };
196 
197  //========================================================================
199  EDAnalyzer(pset),
200  fWaveformSize (pset.get<unsigned int>("WaveformSize", 6000)),
201  fDataUtils (pset.get<fhicl::ParameterSet>("DataUtils")),
202  fHitsModuleLabel (pset.get< std::string >("HitsModuleLabel","") ),
203  fTrackModuleLabel (pset.get< std::string >("TrackModuleLabel","") ),
204  fCalorimetryModuleLabel (pset.get< std::string >("CalorimetryModuleLabel","") ),
205  fSaveTrackInfo (pset.get< bool>("SaveTrackInfo",false)),
206  fSaveCaloInfo (pset.get< bool>("SaveCaloInfo",false)),
207  fRawProducerLabel (pset.get<art::InputTag>("RawProducerLabel","")),
208  fWireProducerLabel (pset.get<art::InputTag>("WireProducerLabel",""))
209 
210  {
211  if (fSaveTrackInfo == false) fSaveCaloInfo = false;
212  }
213 
214  //========================================================================
216  }
217  //========================================================================
218 
219  //========================================================================
221  std::cout<<"job begin..."<<std::endl;
223  fEventTree = tfs->make<TTree>("Event", "Event Tree from Reco");
224  fEventTree->Branch("event", &event,"event/I");
225  fEventTree->Branch("evttime",&evttime,"evttime/D");
226  fEventTree->Branch("run", &run,"run/I");
227  fEventTree->Branch("Nactivefembs",&fNactivefembs,"Nactivefembs[6]/I");
228  fEventTree->Branch("subrun", &subrun,"surbrun/I");
229  fEventTree->Branch("T0_values",&T0_values);
230  fEventTree->Branch("xprojectedlen",&xprojectedlen);
231  fEventTree->Branch("trackthetaxz",&trackthetaxz);
232  fEventTree->Branch("trackthetayz",&trackthetayz);
233  fEventTree->Branch("trkstartx",&trkstartx);
234  fEventTree->Branch("trkstarty",&trkstarty);
235  fEventTree->Branch("trkstartz",&trkstartz);
236  fEventTree->Branch("trkendx",&trkendx);
237  fEventTree->Branch("trkendy",&trkendy);
238  fEventTree->Branch("trkendz",&trkendz);
239  fEventTree->Branch("trkendx_crt2",&trkendx_crt2);
240  fEventTree->Branch("trkstartx_crt2",&trkstartx_crt2);
241  fEventTree->Branch("crtreco_x0",&crtreco_x0);
242  fEventTree->Branch("crtreco_x1",&crtreco_x1);
243  fEventTree->Branch("crtreco_y0",&crtreco_y0);
244  fEventTree->Branch("crtreco_y1",&crtreco_y1);
245  fEventTree->Branch("crtreco_z0",&crtreco_z0);
246  fEventTree->Branch("crtreco_z1",&crtreco_z1);
247  fEventTree->Branch("crt2tickoffset",&crt2tickoffset);
248  fEventTree->Branch("trklen",&trklen);
249  fEventTree->Branch("TrkID",&TrkID);
250  fEventTree->Branch("tot_trks",&tot_trks);
251  fEventTree->Branch("hit_peakT0",&hit_peakT0);
252  fEventTree->Branch("hit_tpc0",&hit_tpc0);
253  fEventTree->Branch("hit_wire0",&hit_wire0);
254  fEventTree->Branch("hit_rms0",&hit_rms0);
255  fEventTree->Branch("hit_deltaT",&hit_deltaT);
256  fEventTree->Branch("trkhitx0",&trkhitx0);
257  fEventTree->Branch("trkhity0",&trkhity0);
258  fEventTree->Branch("trkhitz0",&trkhitz0);
259  fEventTree->Branch("trkdq_int0",&trkdq_int0);
260  fEventTree->Branch("trkdq_amp0",&trkdq_amp0);
261  fEventTree->Branch("hit_peakT1",&hit_peakT1);
262  fEventTree->Branch("hit_tpc1",&hit_tpc1);
263  fEventTree->Branch("hit_wire1",&hit_wire1);
264  fEventTree->Branch("hit_rms1",&hit_rms1);
265  fEventTree->Branch("trkhitx1",&trkhitx1);
266  fEventTree->Branch("trkhity1",&trkhity1);
267  fEventTree->Branch("trkhitz1",&trkhitz1);
268  fEventTree->Branch("trkdq_int1",&trkdq_int1);
269  fEventTree->Branch("trkdq_amp1",&trkdq_amp1);
270  fEventTree->Branch("hit_peakT2",&hit_peakT2);
271  fEventTree->Branch("hit_tpc2",&hit_tpc2);
272  fEventTree->Branch("hit_wire2",&hit_wire2);
273  fEventTree->Branch("hit_rms2",&hit_rms2);
274  // fEventTree->Branch("hit_rmsraw2",&hit_rmsraw2); // RAWDIGITS
275  // fEventTree->Branch("hit_peakTraw2",&hit_peakTraw2); // RAWDIGITS
276  // fEventTree->Branch("hit_signal",hit_signal,"hit_signal[10][5000][60]/F");// RAWDIGITS
277  fEventTree->Branch("hit_rms_true",&hit_rms_true);
278  fEventTree->Branch("trkhitx2",&trkhitx2);
279  fEventTree->Branch("trkhity2",&trkhity2);
280  fEventTree->Branch("trkhitz2",&trkhitz2);
281  fEventTree->Branch("trkhitz_wire2",&trkhitz_wire2);
282  fEventTree->Branch("trkdq_int2",&trkdq_int2);
283  fEventTree->Branch("trkdq_amp2",&trkdq_amp2);
284  fEventTree->Branch("trkstartcosxyz",&trkstartcosxyz);
285  fEventTree->Branch("trkendcosxyz",&trkendcosxyz);
286  fEventTree->Branch("multiplicity2",&multiplicity2);
287  fEventTree->Branch("goodnessoffit2",&goodnessoffit2);
288  // fEventTree->Branch("t0crt1",&t0crt1);
289  fEventTree->Branch("t0crt2",&t0crt2);
290  }
291 
292  //========================================================================
293  void hitrms::endJob(){
294 
295  }
296 
297  //========================================================================
299  mf::LogInfo("hitrms")<<"begin run..."<<std::endl;
300  }
301  //========================================================================
302 
303  //========================================================================
304 
305  //========================================================================
306 
307  void hitrms::analyze( const art::Event& evt){//analyze
308  reset();
309  std::cout<<"raw producer module label "<<fRawProducerLabel<<std::endl;
310  // art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
312  //Detector properties service
313  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataFor(evt);
314 
315  std::vector<art::Ptr<recob::Track> > tracklist;
316  auto trackListHandle = evt.getHandle< std::vector<recob::Track> >("pandoraTrack");
317  if (trackListHandle){
318  art::fill_ptr_vector(tracklist, trackListHandle);
319  }
320  else return;
321 
322  std::vector<art::Ptr<recob::PFParticle> > pfplist;
323 
324  auto PFPListHandle = evt.getHandle< std::vector<recob::PFParticle> >("pandora");
325  if (PFPListHandle) art::fill_ptr_vector(pfplist, PFPListHandle);
326 
327  std::vector<art::Ptr<recob::Hit>> hitlist;
328  auto hitListHandle = evt.getHandle< std::vector<recob::Hit> >(fHitsModuleLabel); // to get information about the hits
329  if (hitListHandle) art::fill_ptr_vector(hitlist, hitListHandle);
330 
331  art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trackListHandle, evt, fTrackModuleLabel); // to associate tracks and hits
332  art::FindManyP<anab::T0> trk_t0_assn_v(PFPListHandle, evt ,"pandora");
333  art::FindManyP<recob::PFParticle> pfp_trk_assn(trackListHandle,evt,"pandoraTrack");
334  art::FindManyP<anab::T0> fmT0(trackListHandle, evt ,"pmtrack");
335  // // RAWDIGITS CODE
336  // std::vector<art::Ptr<raw::RawDigit> > rawlist;
337  // auto rawListHandle = evt.getHandle< std::vector<raw::RawDigit> >(fRawProducerLabel);
338  // if (rawListHandle)
339  // art::fill_ptr_vector(rawlist, rawListHandle);
340 
341 
342  // std::vector<art::Ptr<recob::Wire> > wirelist;
343  // auto wireListHandle = evt.getHandle< std::vector<recob::Wire> > (fWireProducerLabel);
344  // if (wireListHandle)
345  // art::fill_ptr_vector(wirelist, wireListHandle);
346  // std::cout<<"rawlist size, wirelist size"<<rawlist.size()<<" "<<wirelist.size()<<std::endl;
347  // // RAWDIGITS CODE
348  std::vector<const sim::SimChannel*> fSimChannels;
349  try{
350  evt.getView("largeant", fSimChannels);
351  }catch (art::Exception const&e){
352  }
353 
354  //Get 2-CRT T0
355  art::FindManyP<anab::T0> fmt0crt2(trackListHandle, evt, "crtreco");
356  art::FindManyP<anab::CosmicTag> fmctcrt2(trackListHandle, evt, "crtreco");
357 
358  //Get 1-CRT T0
359  // art::FindManyP<anab::T0> fmt0crt1(trackListHandle, evt, "crttag");
360  // art::FindManyP<anab::CosmicTag> fmctcrt1(trackListHandle, evt, "crttag");
361 
362  run = evt.run();
363  subrun = evt.subRun();
364  event = evt.id().event();
365  art::Timestamp ts = evt.time();
366  TTimeStamp tts(ts.timeHigh(), ts.timeLow());
367  evttime=tts.AsDouble();
368 
369 
370 
371  // Get number of active fembs
372  if(!evt.isRealData()){
373  for(int k=0; k < 6; k++)
374  fNactivefembs[k] = 20;
375  }
376  else{
377  for(int k=0; k < 6; k++)
379  }
380 
381 
382  //defining the 1D temporary storage vectors
383  std::vector< float> peakT_0; std::vector< float> peakT_1; std::vector< float> peakT_2; // std::vector<float> hit_peakTrawb; // RAWDIGITS
384  std::vector< int > tpc_0; std::vector< int > tpc_1; std::vector<int> tpc_2;
385  std::vector< int > wire_0; std::vector< int > wire_1; std::vector<int> wire_2;
386  std::vector< float > int_0; std::vector< float > int_1; std::vector<float> int_2;
387  std::vector< float > amp_0; std::vector< float > amp_1; std::vector<float> amp_2;
388  std::vector<float> rms_0; std::vector<float> rms_1; std::vector<float> rms_2; // rms_raw2; // RAWDIGITS
389  std::vector<float> hitx_0; std::vector<float> hitx_1; std::vector<float> hitx_2;
390  std::vector<float> hity_0; std::vector<float> hity_1; std::vector<float> hity_2;
391  std::vector<float> hitz_0; std::vector<float> hitz_1; std::vector<float> hitz_2;
392  std::vector<float> hitz_wire2; std::vector<float> startcosxyz; std::vector<float> endcosxyz;
393  std::vector<float> dT_buffer; std::vector<float> gof, multi,truerms;
394 
395  float max_value;
396  float min_value;
397  int ntrks=0;
398  size_t NTracks = tracklist.size();
399  for(size_t i=0; i<NTracks;++i){
400  double xoffset=0.0;
401  int nhits=0;
402  //clearing the 1D temporary storage vectors
403  peakT_0.clear(); peakT_1.clear(); peakT_2.clear(); // hit_peakTrawb.clear(); // RAWDIGITS
404  tpc_0.clear(); tpc_1.clear(); tpc_2.clear();
405  wire_0.clear(); wire_1.clear(); wire_2.clear();
406  int_0.clear(); int_1.clear() ; int_2.clear();
407  amp_0.clear(); amp_1.clear() ; amp_2.clear();
408  rms_0.clear(); rms_1.clear(); rms_2.clear(); // rms_raw2.clear(); // RAWDIGITS
409  hitx_0.clear(); hitx_1.clear(); hitx_2.clear();
410  hity_0.clear(); hity_1.clear(); hity_2.clear();
411  hitz_0.clear(); hitz_1.clear(); hitz_2.clear();
412  hitz_wire2.clear(); startcosxyz.clear();endcosxyz.clear();
413  dT_buffer.clear(); gof.clear(); multi.clear();
414  truerms.clear();
415 
416 
417  art::Ptr<recob::Track> ptrack(trackListHandle, i);
418 
419  ///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
420  double t_zero=-999999;
421  max_value=0.0;
422  min_value=0.0;
423  /* if(fTrackModuleLabel=="pandoraTrack"){
424  std::vector<art::Ptr<recob::PFParticle>> pfps=pfp_trk_assn.at(i);
425  if(!pfps.size()) continue;
426  std::vector<art::Ptr<anab::T0>> t0s=trk_t0_assn_v.at(pfps[0].key());
427  // if(!t0s.size()) continue;
428  //auto t0 = t0s.at(0);
429  // double t_zero=t0->Time();
430  if(t0s.size()==0) continue;
431  if(t0s.size()){
432  auto t0=t0s.at(0);
433  t_zero=t0->Time();
434  }
435  }
436 
437  if(fTrackModuleLabel=="pmtrack"){
438  std::vector<art::Ptr<anab::T0>> T0s=fmT0.at(i);
439  if(T0s.size()==0)
440  continue;
441  }
442  */
443  // all_trks++;
444  const recob::Track& track = *ptrack;
445 
446 
447  double this_t0crt2=-DBL_MAX;
448  //double this_t0crt1=-DBL_MAX;
449  double this_crt2x0 = -DBL_MAX;
450  double this_crt2x1 = -DBL_MAX;
451  double this_crt2y0 = -DBL_MAX;
452  double this_crt2y1 = -DBL_MAX;
453  double this_crt2z0 = -DBL_MAX;
454  double this_crt2z1 = -DBL_MAX;
455 
456  bool test1=true;
457  // bool test2=true;
458  if(fmt0crt2.isValid()){
459  auto const& vt0crt2 = fmt0crt2.at(i);
460  if (!vt0crt2.empty()){
461  this_t0crt2 = vt0crt2[0]->Time();
462  test1=false;
463  }
464 
465  }
466  if(test1) continue;
467  if (fmctcrt2.isValid()){
468  auto const& vctcrt2 = fmctcrt2.at(i);
469  if (!vctcrt2.empty()){
470  this_crt2x0 = vctcrt2[0]->EndPoint1()[0];
471  this_crt2x1 = vctcrt2[0]->EndPoint2()[0];
472  this_crt2y0 = vctcrt2[0]->EndPoint1()[1];
473  this_crt2y1 = vctcrt2[0]->EndPoint2()[1];
474  this_crt2z0 = vctcrt2[0]->EndPoint1()[2];
475  this_crt2z1 = vctcrt2[0]->EndPoint2()[2];
476 
477  }
478  }
479 
480 
481 
482 
483  /* if (fmt0crt1.isValid()){
484  auto const& vt0crt1 = fmt0crt1.at(i);
485  if (!vt0crt1.empty()){
486  this_t0crt1 = vt0crt1[0]->Time();
487  test2=false;
488  }
489  }*/
490  // if(test1 && test2) continue;
491 
492 
493 
494 
495  auto pos = track.Vertex();
496  auto dir_start = track.VertexDirection();
497  auto dir_end = track.EndDirection();
498  auto end = track.End();
499  double theta_xz = std::atan2(dir_start.X(), dir_start.Z());
500  double theta_yz = std::atan2(dir_start.Y(), dir_start.Z());
501 
502  int planenum=999;
503  float xpos=-9999;
504  float ypos=-9999;
505  float zpos=-9999;
506  auto allHits=fmthm.at(i);
507  double ticksoffset=0;
508 
509  // if (this_t0crt2 > -DBL_MAX) ticksoffset = this_t0crt2/500.+detProp.GetXTicksOffset(allHits[0]->WireID());
510  if (this_t0crt2 > -DBL_MAX) ticksoffset = this_t0crt2/500.+detProp.GetXTicksOffset (allHits[0]->WireID().Plane, allHits[0]->WireID().TPC, allHits[0]->WireID().Cryostat);
511  // else if (this_t0crt1 > -DBL_MAX) ticksoffset = this_t0crt1/500.+detProp.GetXTicksOffset(allHits[0]->WireID());
512  xoffset = detProp.ConvertTicksToX(ticksoffset,allHits[0]->WireID());
513  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;
514 
515 
516 
517  //hits and calorimetry loop
518  if(fmthm.isValid()){
519  auto vhit=fmthm.at(i);
520  auto vmeta=fmthm.data(i);
521  for (size_t ii = 0; ii<vhit.size(); ++ii){ //loop over all meta data hit
522  bool fBadhit = false;
523  if (vmeta[ii]->Index() == static_cast<unsigned int>(std::numeric_limits<int>::max())){
524  fBadhit = true;
525  //cout<<"fBadHit"<<fBadhit<<endl;
526  continue;
527  }
528  if (vmeta[ii]->Index()>=tracklist[i]->NumberTrajectoryPoints()){
529  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!!";
530  }
531  if (!tracklist[i]->HasValidPoint(vmeta[ii]->Index())){
532  fBadhit = true;
533  // cout<<"had valid point "<<fBadhit<<endl;
534  continue;
535  }
536 
537  auto loc = tracklist[i]->LocationAtPoint(vmeta[ii]->Index());
538  xpos=loc.X();
539  ypos=loc.Y();
540  zpos=loc.Z();
541  // cout<<"x, y, z "<<xpos<<" "<<ypos<<" "<<zpos<<endl;
542  // cout<<"BadHit"<<fBadhit<<endl;
543  if (fBadhit) continue; //HY::If BAD hit, skip this hit and go next
544  if (zpos<-100) continue; //hit not on track
545  planenum=vhit[ii]->WireID().Plane;
546  if(planenum==0){
547  peakT_0.push_back(vhit[ii]->PeakTime());
548  tpc_0.push_back(vhit[ii]->WireID().TPC);
549  wire_0.push_back(vhit[ii]->WireID().Wire);
550  int_0.push_back(vhit[ii]->Integral());
551  amp_0.push_back(vhit[ii]->PeakAmplitude());
552  rms_0.push_back(vhit[ii]->RMS());
553  hitx_0.push_back(xpos);
554  hity_0.push_back(ypos);
555  hitz_0.push_back(zpos);
556  }//planenum 0
557  if(planenum==1){
558  peakT_1.push_back(vhit[ii]->PeakTime());
559  tpc_1.push_back(vhit[ii]->WireID().TPC);
560  wire_1.push_back(vhit[ii]->WireID().Wire);
561  int_1.push_back(vhit[ii]->Integral());
562  amp_1.push_back(vhit[ii]->PeakAmplitude());
563  rms_1.push_back(vhit[ii]->RMS());
564  hitx_1.push_back(xpos);
565  hity_1.push_back(ypos);
566  hitz_1.push_back(zpos);
567  }//planenum 1
568  if(planenum==2){
569  // Remove all hits within 30tt of other hits by looping over all other hits:
570  bool removehit=false;
571  for (size_t i2=0; i2<hitlist.size(); ++i2) {
572  if (vhit[ii].key() == hitlist[i2].key()) continue;
573  if (vhit[ii]->Channel()!=hitlist[i2]->Channel()) continue;
574  if ((vhit[ii]->PeakTime()+30<hitlist[i2]->PeakTime()-30) || (vhit[ii]->PeakTime()-30>hitlist[i2]->PeakTime()+30)) continue;
575  removehit=true;
576  break;
577  }
578  if (removehit) continue;
579  // Normal procedure resumes (i.e. keep this if keeping all hits):
580  nhits++;
581  peakT_2.push_back(vhit[ii]->PeakTime()-this_t0crt2/500.0);
582  tpc_2.push_back(vhit[ii]->WireID().TPC);
583  wire_2.push_back(vhit[ii]->WireID().Wire);
584  int_2.push_back(vhit[ii]->Integral());
585  amp_2.push_back(vhit[ii]->PeakAmplitude());
586  rms_2.push_back(vhit[ii]->RMS());
587  dT_buffer.push_back(vhit[ii]->EndTick()-vhit[ii]->StartTick());
588  hitx_2.push_back(xpos);
589  hity_2.push_back(ypos);
590  hitz_2.push_back(zpos);
591  gof.push_back(vhit[ii]->GoodnessOfFit());
592  multi.push_back(vhit[ii]->Multiplicity());
593  double xyzStart[3];
594  double xyzEnd[3];
595  unsigned int wireno=vhit[ii]->WireID().Wire;
596  fGeometry->WireEndPoints(0,vhit[ii]->WireID().TPC,2,wireno, xyzStart, xyzEnd);
597  hitz_wire2.push_back(xyzStart[2]);
598  double truermsb=-1;
599 
600  //section for using tuth information
601  unsigned int t0=vhit[ii]->PeakTime()-3*(vhit[ii]->RMS());
602  if(t0<0) t0=0;
603  unsigned int t1=vhit[ii]->PeakTime()+3*(vhit[ii]->RMS());
604  if(t1>6000) t1=6000-1;
605 
606  // // RAWDIGITS CODE
607  // double hit_rms=-9999;
608  // std::cout<<"wirelist size, rawlist size "<<wirelist.size()<<" "<<rawlist.size()<<std::endl;
609  // double hit_t = -1;
610  // for (unsigned int ich = 0; ich < (rawlist.empty()?wirelist.size():rawlist.size()); ++ich){
611  // std::vector<float> inputsignal(fWaveformSize);
612 
613  // if (!wirelist.empty() && evt.isRealData()){
614  // const auto & wire = wirelist[ich];
615  // if(wirelist[ich]->Channel()!=vhit[ii]->Channel()) continue;
616  // //art::Ptr<recob::Wire> wire(wireHandle, wireIter);
617  // const auto & signal = wire->Signal();
618  // double hit_pk = -1;
619 
620  // for (size_t itck = t0; itck <inputsignal.size(); ++itck){
621  // if(itck>t1) continue;
622  // inputsignal[itck] = signal[itck];
623  // if (inputsignal[itck]>hit_pk){
624  // hit_pk = inputsignal[itck];
625  // hit_t = itck;
626  // }
627  // }//finding peak signal
628  // std::cout<<"hitpeak time, hitraw peak time "<<vhit[ii]->PeakTime()<<" "<<hit_t<<std::endl;
629  // int hitindx=0;
630  // for(size_t it1=hit_t-30;it1<hit_t+30;it1++){
631  // if(it1<1||it1>5999||it1>inputsignal.size()) continue;
632  // hit_signal[ntrks][nhits-1][hitindx]=signal[it1];
633  // hitindx++;
634  // }//storing signal for peakT-30 to peakT+30 ticks
635  // double hit_ch = 0;
636  // double hit_fwhh = 0;
637  // double mean_t = 0;
638  // double mean_t2 = 0;
639  // for (size_t itck = t0; itck < inputsignal.size(); ++itck){
640  // if(itck>t1) continue;
641  // if (inputsignal[itck]>=0.5*hit_pk){
642  // ++hit_fwhh;
643  // }
644  // if (inputsignal[itck]>=0.1*hit_pk){
645  // hit_ch += inputsignal[itck];
646  // mean_t += itck*(inputsignal[itck]);
647  // mean_t2 += itck*itck*(inputsignal[itck]);
648  // }
649  // }//itick loop
650  // mean_t/=hit_ch;
651  // mean_t2/=hit_ch;
652  // hit_rms = sqrt(mean_t2-mean_t*mean_t);
653  // }
654  // else if (!rawlist.empty()){
655  // const auto & digitVec = rawlist[ich];
656  // if(rawlist[ich]->Channel()!=vhit[ii]->Channel()) continue;
657  // std::vector<short> rawadc(fWaveformSize);
658  // raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->GetPedestal(), digitVec->Compression());
659  // double hit_pk = -1;
660  // // double hit_t = -1;
661  // std::vector<double> signalbuffer;
662  // signalbuffer.clear();
663  // //calculating the median of signals
664  // for(size_t it=0;it<rawadc.size();it++){
665  // signalbuffer.push_back(rawadc[it]);
666  // }
667  // double med_signal=TMath::Median(signalbuffer.size(),&signalbuffer[0]);//median signal for a channel
668  // std::cout<<"median , pedestal , rawadc size "<<med_signal<<" "<<digitVec->GetPedestal()<<" "<<rawadc.size()<<std::endl;
669  // ////////////////////////////////
670 
671  // for (size_t itck = t0; itck <rawadc.size(); ++itck){
672  // if(itck>t1) continue;
673  // // inputsignal[itck] = rawadc[itck] - digitVec->GetPedestal();
674  // inputsignal[itck] = rawadc[itck] - med_signal;
675  // if (inputsignal[itck]>hit_pk){
676  // hit_pk = inputsignal[itck];
677  // hit_t = itck;
678  // }
679  // }//itick loop
680  // std::cout<<"hitpeak time, hitraw peak time "<<vhit[ii]->PeakTime()<<" "<<hit_t<<std::endl;
681  // int hitindex=0;
682  // for(size_t it1=hit_t-30;it1<hit_t+30;it1++){
683  // if(it1<1|| it1>5999 || it1>rawadc.size()) continue;
684  // // hit_signal[ntrks][nhits-1][hitindex]=rawadc[it1]-digitVec->GetPedestal();
685  // hit_signal[ntrks][nhits-1][hitindex]=rawadc[it1]-med_signal;
686  // hitindex++;
687  // }
688 
689  // double hit_ch = 0;
690  // double hit_fwhh = 0;
691  // double mean_t = 0;
692  // double mean_t2 = 0;
693  // for (size_t itck = t0; itck < inputsignal.size(); ++itck){
694  // if(itck>t1) continue;
695  // // inputsignal[itck] = rawadc[itck] - digitVec->GetPedestal();
696  // inputsignal[itck] = rawadc[itck] - med_signal;
697  // if (inputsignal[itck]>=0.5*hit_pk){
698  // ++hit_fwhh;
699  // }
700  // if (inputsignal[itck]>=0.1*hit_pk){
701  // hit_ch += inputsignal[itck];
702  // mean_t += itck*(inputsignal[itck]);
703  // mean_t2 += itck*itck*(inputsignal[itck]);
704  // }
705  // }//itick loop
706  // mean_t/=hit_ch;
707  // mean_t2/=hit_ch;
708  // hit_rms = sqrt(mean_t2-mean_t*mean_t);
709  // }
710  // }//rawdigit channel loop
711  // rms_raw2.push_back(hit_rms);
712  // hit_peakTrawb.push_back(hit_t);
713  // // RAWDIGITS CODE
714  if(!evt.isRealData()){
715  const sim::SimChannel* chan=0;
716  for(size_t sc=0;sc<fSimChannels.size();++sc){
717  if(fSimChannels[sc]->Channel()==vhit[ii]->Channel()) chan=fSimChannels[sc];
718  }
719  if(chan){
720  const auto &tdcidemap = chan->TDCIDEMap();
721  double hit_ch=0;
722  double mean_t=0;
723  double mean_t2=0;
724  double hit_rmsvalue=0;
725  for(auto mapitr = tdcidemap.begin(); mapitr != tdcidemap.end(); mapitr++){
726  if(!((*mapitr).first>t0 && (*mapitr).first<=t1)) continue;
727  // loop over the vector of IDE objects.
728  int hit_nelec=0;
729  const std::vector<sim::IDE> idevec = (*mapitr).second;
730  for(size_t iv = 0; iv < idevec.size(); ++iv){
731  hit_nelec+=idevec[iv].numElectrons;
732  }//iv loop
733  hit_ch+=hit_nelec;
734  // std::cout<<"hit_ch "<<hit_ch<<std::endl;
735  int j=(*mapitr).first;
736  mean_t+=double(j)*double(hit_nelec);
737  double jterm=double(j)*double(j)*double(hit_nelec);
738  mean_t2=mean_t2+jterm;
739  }//mapitr loop
740  mean_t/=hit_ch;
741  mean_t2/=hit_ch;
742  hit_rmsvalue=sqrt(mean_t2-mean_t*mean_t);
743  // std::cout<<"hit rms "<<hit_rmsvalue<<" reco rms "<<vhit[ii]->RMS()<<std::endl;
744  truermsb=hit_rmsvalue;
745  }//if(chan)
746  }//!evt.IsRealData
747  truerms.push_back(truermsb);
748 
749 
750  }//planenum 2
751  }//loop over vhit
752  }//fmthm valid
753  //hits and calorimetry loop
754  if(peakT_2.size()<10) continue;
755  max_value=*std::max_element(peakT_2.begin(),peakT_2.end());
756  min_value=*std::min_element(peakT_2.begin(),peakT_2.end());
757  // if(max_value-min_value<4300) continue;
758  std::cout<<max_value<<" "<<min_value<<std::endl;
759  ntrks++;
760  hit_peakT0.push_back(peakT_0);
761  hit_tpc0.push_back(tpc_0);
762  hit_wire0.push_back(wire_0);
763  hit_rms0.push_back(rms_0);
764  trkhitx0.push_back(hitx_0);
765  trkhity0.push_back(hity_0);
766  trkhitz0.push_back(hitz_0);
767  trkdq_amp0.push_back(amp_0);
768  trkdq_int0.push_back(int_0);
769 
770  hit_peakT1.push_back(peakT_1);
771  hit_tpc1.push_back(tpc_1);
772  hit_wire1.push_back(wire_1);
773  hit_rms1.push_back(rms_1);
774  trkhitx1.push_back(hitx_1);
775  trkhity1.push_back(hity_1);
776  trkhitz1.push_back(hitz_1);
777  trkdq_amp1.push_back(amp_1);
778  trkdq_int1.push_back(int_1);
779 
780  hit_peakT2.push_back(peakT_2);
781  // hit_peakTraw2.push_back(hit_peakTrawb); // RAWDIGITS
782  hit_tpc2.push_back(tpc_2);
783  hit_wire2.push_back(wire_2);
784  hit_rms2.push_back(rms_2);
785  // hit_rmsraw2.push_back(rms_raw2); // RAWDIGITS
786  hit_rms_true.push_back(truerms);
787  trkhitx2.push_back(hitx_2);
788  trkhity2.push_back(hity_2);
789  trkhitz2.push_back(hitz_2);
790  trkhitz_wire2.push_back(hitz_wire2);
791  trkdq_amp2.push_back(amp_2);
792  trkdq_int2.push_back(int_2);
793  hit_deltaT.push_back(dT_buffer);
794  multiplicity2.push_back(multi);
795  goodnessoffit2.push_back(gof);
796 
797 
798 
799  xprojectedlen.push_back(TMath::Abs(end.X()-pos.X()));
800  trackthetaxz.push_back(theta_xz);
801  trackthetayz.push_back(theta_yz);
802  trkstartx.push_back(pos.X());
803  trkstartx_crt2.push_back(pos.X()-xoffset);
804  trkstarty.push_back(pos.Y());
805  trkstartz.push_back(pos.Z());
806  startcosxyz.push_back(dir_start.X());
807  startcosxyz.push_back(dir_start.Y());
808  startcosxyz.push_back(dir_start.Z());
809  endcosxyz.push_back(dir_end.X());
810  endcosxyz.push_back(dir_end.Y());
811  endcosxyz.push_back(dir_end.Z());
812 
813  trkstartcosxyz.push_back(startcosxyz);
814  trkendcosxyz.push_back(endcosxyz);
815  trkendx.push_back(end.X());
816  trkendx_crt2.push_back(end.X()-xoffset);
817  crtreco_x0.push_back(this_crt2x0);
818  crtreco_x1.push_back(this_crt2x1);
819  crtreco_y0.push_back(this_crt2y0);
820  crtreco_y1.push_back(this_crt2y1);
821  crtreco_z0.push_back(this_crt2z0);
822  crtreco_z1.push_back(this_crt2z1);
823 
824  trkendy.push_back(end.Y());
825  trkendz.push_back(end.Z());
826  trklen.push_back(track.Length());
827  TrkID.push_back(track.ID());
828  T0_values.push_back(t_zero);
829  crt2tickoffset.push_back(ticksoffset);
830  t0crt2.push_back(this_t0crt2/500.0);
831  } // loop over trks...
832  tot_trks.push_back(ntrks);
833  fEventTree->Fill();
834  } // end of analyze function
835 
836  /////////////////// Defintion of reset function ///////////
838  run = -9999;
839  subrun = -9999;
840  event = -9999;
841  evttime = -9999;
842  //all_trks = -9999;
843  for(int k=0; k < 6; k++)
844  fNactivefembs[k] = -9999;
845  trackthetaxz.clear();
846  trackthetayz.clear();
847  trkstartx.clear();
848  trkstartx_crt2.clear();
849  trkendx_crt2.clear();
850  trkstarty.clear();
851  trkstartz.clear();
852  trkstartcosxyz.clear();
853  trkendcosxyz.clear();
854  trkendx.clear();
855  trkendy.clear();
856  trkendz.clear();
857  trklen.clear();
858  TrkID.clear();
859  tot_trks.clear();
860  T0_values.clear();
861  xprojectedlen.clear();
862  hit_peakT0.clear();
863  hit_tpc0.clear();
864  hit_wire0.clear();
865  trkhitx0.clear();
866  trkhity0.clear();
867  trkhitz0.clear();
868  trkdq_int0.clear();
869  trkdq_amp0.clear();
870  hit_rms0.clear();
871  hit_peakT1.clear();
872  hit_tpc1.clear();
873  hit_wire1.clear();
874  trkhitx1.clear();
875  trkhity1.clear();
876  trkhitz1.clear();
877  trkdq_int1.clear();
878  trkdq_amp1.clear();
879  hit_rms1.clear();
880  hit_peakT2.clear();
881  hit_tpc2.clear();
882  hit_wire2.clear();
883  trkhitx2.clear();
884  trkhity2.clear();
885  trkhitz2.clear();
886  trkhitz_wire2.clear();
887  trkdq_int2.clear();
888  trkdq_amp2.clear();
889  hit_rms2.clear();
890  // hit_peakTraw2.clear(); // RAWDIGITS
891  // hit_rmsraw2.clear(); // RAWDIGITS
892  hit_deltaT.clear();
893  multiplicity2.clear();
894  goodnessoffit2.clear();
895  hit_rms_true.clear();
896  crtreco_x0.clear();
897  crtreco_x1.clear();
898  crtreco_y0.clear();
899  crtreco_y1.clear();
900  crtreco_z0.clear();
901  crtreco_z1.clear();
902  crt2tickoffset.clear();
903 
904  // t0crt1.clear();
905  t0crt2.clear();
906  // RAWDIGITS CODE
907  // for(int i=0; i<10; i++){
908  // for(int j=0; j<5000; j++){
909  // for(int k=0;k<60;k++){
910  // hit_signal[i][j][k]=-99999;;
911  // }
912  // }
913  // }
914  // RAWDIGITS CODE
915  }
916  //////////////////////// End of definition ///////////////
917 
919 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
code to link reconstructed objects back to the MC truth information
void beginRun(const art::Run &run)
std::vector< std::vector< float > > goodnessoffit2
std::vector< std::vector< float > > trkdq_amp0
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
std::vector< float > trackthetayz
std::vector< float > crtreco_y0
std::vector< float > trklen
Energy deposited on a readout channel by simulated tracks.
Definition: SimChannel.h:140
TH3F * xpos
Definition: doAna.cpp:29
std::vector< float > crtreco_z1
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< int > TrkID
std::vector< std::vector< float > > hit_rms2
std::vector< std::vector< float > > trkhitx1
std::vector< std::vector< int > > hit_wire2
std::vector< float > trkendy
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
std::vector< float > trkstartx
std::vector< int > tot_trks
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
std::vector< std::vector< float > > trkdq_amp2
art::InputTag fRawProducerLabel
STL namespace.
std::vector< std::vector< float > > hit_rms0
std::vector< std::vector< int > > hit_tpc1
std::vector< float > trackthetaxz
unsigned int Index
std::vector< std::vector< float > > trkhitz1
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::vector< double > T0_values
Particle class.
std::vector< std::vector< float > > hit_deltaT
geo::GeometryCore const * fGeometry
object containing MC flux information
art framework interface to geometry description
Definition: Run.h:17
TH3F * ypos
Definition: doAna.cpp:30
std::vector< std::vector< float > > trkdq_int2
std::vector< double > crt2tickoffset
bool isRealData() const
std::vector< float > crtreco_z0
std::vector< std::vector< float > > multiplicity2
std::vector< float > trkstarty
TH3F * zpos
Definition: doAna.cpp:31
std::vector< std::vector< int > > hit_tpc0
std::vector< float > trkendx_crt2
const double e
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
std::vector< std::vector< float > > hit_rms1
Timestamp time() const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
def key(type, name=None)
Definition: graph.py:13
Point_t const & Vertex() const
Definition: Track.h:124
std::string fTrackModuleLabel
std::vector< std::vector< float > > hit_peakT0
std::vector< float > trkendx
std::vector< std::vector< int > > hit_tpc2
std::vector< std::vector< float > > trkhitx2
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
std::vector< double > t0crt2
void analyze(const art::Event &evt)
RunNumber_t run() const
Definition: DataViewImpl.cc:71
static int max(int a, int b)
std::vector< std::vector< float > > trkhitx0
Description of geometry of one entire detector.
std::vector< std::vector< int > > hit_wire1
Definition of data types for geometry description.
std::vector< float > xprojectedlen
std::vector< float > trkendz
std::vector< std::vector< float > > trkhitz0
std::vector< std::vector< float > > trkhitz_wire2
std::vector< std::vector< float > > trkhity1
std::vector< std::vector< float > > trkdq_int1
std::vector< std::vector< float > > trkhitz2
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
int ID() const
Definition: Track.h:198
Declaration of signal hit object.
std::vector< std::vector< float > > trkendcosxyz
std::vector< float > trkstartz
int GetNActiveFembsForAPA(art::Event const &evt, int apa) const
Get number of active fembs in an APA.
std::string fHitsModuleLabel
std::vector< float > crtreco_x0
art::InputTag fWireProducerLabel
Vector_t EndDirection() const
Definition: Track.h:133
hitrms(fhicl::ParameterSet const &pset)
Provides recob::Track data product.
std::vector< std::vector< float > > hit_peakT1
std::vector< std::vector< int > > hit_wire0
std::vector< std::vector< float > > trkdq_int0
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
unsigned int fWaveformSize
EventNumber_t event() const
Definition: EventID.h:116
Point_t const & End() const
Definition: Track.h:125
Declaration of basic channel signal object.
std::vector< std::vector< float > > hit_rms_true
std::vector< float > crtreco_x1
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
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
std::vector< std::vector< float > > trkhity2
std::string fCalorimetryModuleLabel
recob::tracking::Plane Plane
Definition: TrackState.h:17
std::vector< float > crtreco_y1
std::vector< std::vector< float > > trkstartcosxyz
ProtoDUNEDataUtils fDataUtils
int bool
Definition: qglobal.h:345
std::vector< float > trkstartx_crt2
EventID id() const
Definition: Event.cc:34
std::vector< std::vector< float > > trkdq_amp1
std::vector< std::vector< float > > hit_peakT2
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
QTextStream & endl(QTextStream &s)
Event finding and building.