XYZcalibration_module.cc
Go to the documentation of this file.
5 #include "art_root_io/TFileService.h"
6 #include "art_root_io/TFileDirectory.h"
8 #include "canvas/Persistency/Common/FindManyP.h"
11 #include "fhiclcpp/ParameterSet.h"
14 
23 #include "lardataobj/RawData/raw.h"
40 
41 #include "TFile.h"
42 #include "TTree.h"
43 #include "TDirectory.h"
44 #include "TH1.h"
45 #include "TH2.h"
46 #include "TF1.h"
47 #include "TProfile.h"
48 #include "TROOT.h"
49 #include "TStyle.h"
50 #include "TMath.h"
51 #include "TGraphErrors.h"
52 #include "TMinuit.h"
53 #include "TString.h"
54 #include "TTimeStamp.h"
55 #include "TVectorD.h"
56 #include "TCanvas.h"
57 #include "TFrame.h"
58 #include "TLine.h"
59 #include "TAxis.h"
60 #include "TTimeStamp.h"
61 
62 #include <vector>
63 #include <fstream>
64 #include "TPaveStats.h"
65 #include <iostream>
66 #include <string>
67 #include "math.h"
68 #include "stdio.h"
69 #include <iterator>
70 
71 const int kMaxTracks = 200;
72 
73 using namespace std;
74 
75 namespace dune{
76 
78  public:
79 
80  explicit XYZcalibration(fhicl::ParameterSet const& pset);
81  virtual ~XYZcalibration();
82 
83  void beginJob();
84  void endJob();
85  void beginRun(const art::Run& run);
86  void analyze(const art::Event& evt);
87  void reset();
88 
89  private:
90  TTree* fEventTree;
91  Int_t run;
92  Int_t subrun;
93  Int_t event;
94  Double_t evttime;
96  Int_t hour_min_sec;
97  Int_t cross_trks;
99  Int_t all_trks;
100  Float_t xprojectedlen[kMaxTracks];
101  Float_t trackthetaxz[kMaxTracks];
102  Float_t trackthetayz[kMaxTracks];
103  Float_t trkstartx[kMaxTracks];
104  Float_t trkstarty[kMaxTracks];
105  Float_t trkstartz[kMaxTracks];
106  Float_t trkendx[kMaxTracks];
107  Float_t trkendy[kMaxTracks];
108  Float_t trkendz[kMaxTracks];
109  Float_t trklen[kMaxTracks];
110  Int_t TrkID[kMaxTracks];
111  Float_t trkstartcosxyz[kMaxTracks][3];
112  Float_t trkendcosxyz[kMaxTracks][3];
113  Int_t ntrkhits[kMaxTracks][3];
114  Float_t trkdqdx[kMaxTracks][3][3000];
115  Float_t trkdedx[kMaxTracks][3][3000];
116  Float_t trkresrange[kMaxTracks][3][3000];
117  Float_t trkhitx[kMaxTracks][3][3000];
118  Float_t trkhity[kMaxTracks][3][3000];
119  Float_t trkhitz[kMaxTracks][3][3000];
125  };
126 
127  //========================================================================
128  XYZcalibration::XYZcalibration(fhicl::ParameterSet const& pset) :
129  EDAnalyzer(pset),
130  fHitsModuleLabel (pset.get< std::string >("HitsModuleLabel","") ),
131  fTrackModuleLabel (pset.get< std::string >("TrackModuleLabel","") ),
132  fCalorimetryModuleLabel (pset.get< std::string >("CalorimetryModuleLabel","") ),
133  fSaveCaloInfo (pset.get< bool>("SaveCaloInfo",false)),
134  fSaveTrackInfo (pset.get< bool>("SaveTrackInfo",false))
135  {
136  if (fSaveTrackInfo == false) fSaveCaloInfo = false;
137  }
138 
139  //========================================================================
141  }
142  //========================================================================
143 
144  //========================================================================
146  std::cout<<"job begin..."<<std::endl;
148  // deltaX = tfs->make<TH1D>("deltaX","Plot of deltaX",400,0,400);
149  // deltaX->Sumw2();
150  fEventTree = tfs->make<TTree>("Event", "Event Tree from Reco");
151  fEventTree->Branch("event", &event,"event/I");
152  fEventTree->Branch("evttime",&evttime,"evttime/D");
153  fEventTree->Branch("run", &run,"run/I");
154  fEventTree->Branch("subrun", &subrun,"surbrun/I");
155  fEventTree->Branch("year_month_date", &year_month_date,"year_month_date/I");
156  fEventTree->Branch("hour_min_sec", &hour_min_sec,"hour_min_sec/I");
157  fEventTree->Branch("cross_trks",&cross_trks,"cross_trks/I");
158  fEventTree->Branch("stopping_trks",&stopping_trks,"stopping_trks/I");
159  fEventTree->Branch("all_trks",&all_trks,"all_trks/I");
160  fEventTree->Branch("xprojectedlen",xprojectedlen,"xprojectedlen[all_trks]/F");
161  fEventTree->Branch("trackthetaxz",trackthetaxz,"trackthetaxz[cross_trks]/F");
162  fEventTree->Branch("trackthetayz",trackthetayz,"trackthetayz[cross_trks]/F");
163  fEventTree->Branch("trkstartx",trkstartx,"trkstartx[cross_trks]/F");
164  fEventTree->Branch("trkstarty",trkstarty,"trkstarty[cross_trks]/F");
165  fEventTree->Branch("trkstartz",trkstartz,"trkstartz[cross_trks]/F");
166  fEventTree->Branch("trkendx",trkendx,"trkendx[cross_trks]/F");
167  fEventTree->Branch("trkendy",trkendy,"trkendy[cross_trks]/F");
168  fEventTree->Branch("trkendz",trkendz,"trkendz[cross_trks]/F");
169  fEventTree->Branch("trklen",trklen,"trklen[cross_trks]/F");
170  fEventTree->Branch("TrkID",TrkID,"TrkID[cross_trks]/I");
171  fEventTree->Branch("trkstartcosxyz",trkstartcosxyz,"trkstartcosxyz[cross_trks][3]/F");
172  fEventTree->Branch("trkendcosxyz",trkendcosxyz,"trkendcosxyz[cross_trks][3]/F");
173  fEventTree->Branch("ntrkhits",ntrkhits,"ntrkhits[cross_trks][3]/I");
174  fEventTree->Branch("trkdqdx",trkdqdx,"trkdqdx[cross_trks][3][3000]/F");
175  fEventTree->Branch("trkdedx",trkdedx,"trkdedx[cross_trks][3][3000]/F");
176  fEventTree->Branch("trkresrange",trkresrange,"trkresrange[cross_trks][3][3000]/F");
177  fEventTree->Branch("trkhitx",trkhitx,"trkhitx[cross_trks][3][3000]/F");
178  fEventTree->Branch("trkhity",trkhity,"trkhity[cross_trks][3][3000]/F");
179  fEventTree->Branch("trkhitz",trkhitz,"trkhitz[cross_trks][3][3000]/F");
180  }
181 
182  //========================================================================
184 
185  }
186 
187  //========================================================================
189  mf::LogInfo("XYZcalibration")<<"begin run..."<<std::endl;
190  }
191  //========================================================================
192 
193  //========================================================================
194 
195  //========================================================================
196 
198  reset();
199 
200 
201  std::vector<art::Ptr<recob::Track> > tracklist;
202  std::vector<art::Ptr<recob::PFParticle> > pfplist;
203 
204  auto trackListHandle = evt.getHandle< std::vector<recob::Track> >(fTrackModuleLabel);
205  if (trackListHandle) art::fill_ptr_vector(tracklist, trackListHandle);
206 
207  auto PFPListHandle = evt.getHandle< std::vector<recob::PFParticle> >("pandora");
208  if (PFPListHandle) art::fill_ptr_vector(pfplist, PFPListHandle);
209 
210  art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryModuleLabel);
211  art::FindManyP<anab::T0> trk_t0_assn_v(PFPListHandle, evt ,"pandora");
212  art::FindManyP<recob::PFParticle> pfp_trk_assn(trackListHandle,evt,"pandoraTrack");
213  art::FindManyP<anab::T0> fmT0(trackListHandle, evt ,"pmtrack");
214 
215  run = evt.run();
216  subrun = evt.subRun();
217  event = evt.id().event();
218  art::Timestamp ts = evt.time();
219  TTimeStamp tts(ts.timeHigh(), ts.timeLow());
220  evttime=tts.AsDouble();
221 
222  UInt_t year=0;
223  UInt_t month=0;
224  UInt_t day=0;
225 
226  year_month_date=tts.GetDate(kTRUE,0,&year,&month,&day);
227 
228  UInt_t hour=0;
229  UInt_t min=0;
230  UInt_t sec=0;
231 
232  hour_min_sec=tts.GetTime(kTRUE,0,&hour,&min,&sec);
233 
234  cross_trks=0;
235  stopping_trks=0;
236  all_trks=0;
237 
238  size_t NTracks = tracklist.size();
239  for(size_t i=0; i<NTracks;++i){
240  art::Ptr<recob::Track> ptrack(trackListHandle, i);
241  if(fTrackModuleLabel=="pandoraTrack"){
242  std::vector<art::Ptr<recob::PFParticle>> pfps=pfp_trk_assn.at(i);
243  if(!pfps.size()) continue;
244  std::vector<art::Ptr<anab::T0>> t0s=trk_t0_assn_v.at(pfps[0].key());
245  if(!t0s.size()) continue;
246  //auto t0 = t0s.at(0);
247  // double t_zero=t0->Time();
248  }
249  if(fTrackModuleLabel=="pmtrack"){
250  std::vector<art::Ptr<anab::T0>> T0s=fmT0.at(i);
251  if(T0s.size()==0)
252  continue;
253  }
254  all_trks++;
255  std::vector<art::Ptr<anab::Calorimetry>> calos=fmcal.at(i);
256 
257  const recob::Track& track = *ptrack;
258  auto pos = track.Vertex();
259  auto dir_start = track.VertexDirection();
260  auto dir_end = track.EndDirection();
261  auto end = track.End();
262  double theta_xz = std::atan2(dir_start.X(), dir_start.Z());
263  double theta_yz = std::atan2(dir_start.Y(), dir_start.Z());
264  //deltaX->Fill(X);
265  cross_trks++;
266  if(std::abs(pos.X())<340 && std::abs(end.X())<340 && pos.Y()>20 && pos.Y()<580 && end.Y()>20 && end.Y()<580 && pos.Z()>20 && pos.Z()<675 && end.Z()>20 && end.Z()<675) stopping_trks++;//this infact gives both ends confined, we have not counted the stopping muon tracks in this module
267  trackthetaxz[cross_trks-1]=theta_xz;
268  trackthetayz[cross_trks-1]=theta_yz;
269  trkstartx[cross_trks-1]=pos.X();
270  trkstarty[cross_trks-1]=pos.Y();
271  trkstartz[cross_trks-1]=pos.Z();
272  trkendx[cross_trks-1]=end.X();
273  trkendy[cross_trks-1]=end.Y();
274  trkendz[cross_trks-1]=end.Z();
275  trklen[cross_trks-1]=track.Length();
276  TrkID[cross_trks-1]=track.ID();
277  trkstartcosxyz[cross_trks-1][0]=dir_start.X();
278  trkstartcosxyz[cross_trks-1][1]=dir_start.Y();
279  trkstartcosxyz[cross_trks-1][2]=dir_start.Z();
280  trkendcosxyz[cross_trks-1][0]=dir_end.X();
281  trkendcosxyz[cross_trks-1][1]=dir_end.Y();
282  trkendcosxyz[cross_trks-1][2]=dir_end.Z();
283 
284  for(size_t ical = 0; ical<calos.size(); ++ical){
285  if(!calos[ical]) continue;
286  if(!calos[ical]->PlaneID().isValid) continue;
287  int planenum = calos[ical]->PlaneID().Plane;
288  if(planenum<0||planenum>2) continue;
289  const size_t NHits = calos[ical] -> dEdx().size();
290  ntrkhits[cross_trks-1][planenum]=int(NHits);
291  for(size_t iHit = 0; iHit < NHits; ++iHit){
292  const auto& TrkPos = (calos[ical] -> XYZ())[iHit];
293  trkdqdx[cross_trks-1][planenum][iHit]=(calos[ical] -> dQdx())[iHit];
294  trkdedx[cross_trks-1][planenum][iHit]=(calos[ical] -> dEdx())[iHit];
295  trkresrange[cross_trks-1][planenum][iHit]=(calos[ical]->ResidualRange())[iHit];
296  trkhitx[cross_trks-1][planenum][iHit]=TrkPos.X();
297  trkhity[cross_trks-1][planenum][iHit]=TrkPos.Y();
298  trkhitz[cross_trks-1][planenum][iHit]=TrkPos.Z();
299  } // loop over iHit..
300  } // loop over ical 2 nd time...
301  } // loop over trks...
302  fEventTree->Fill();
303  } // end of analyze function
304 
305  /////////////////// Defintion of reset function ///////////
307  run = -9999;
308  subrun = -9999;
309  event = -9999;
310  evttime = -9999;
311  cross_trks = -9999;
312  all_trks = -9999;
313  year_month_date=-9999;
314  hour_min_sec=-9999;
315  for(int i=0; i<kMaxTracks; i++){
316  trackthetaxz[i]=-9999;
317  trackthetayz[i]=-9999;
318  trkstartx[i]=-9999;
319  trkstarty[i]=-9999;
320  trkstartz[i]=-9999;
321  trkendx[i]=-9999;
322  trkendy[i]=-9999;
323  trkendz[i]=-9999;
324  trklen[i]=-9999;
325  TrkID[i]=-9999;
326  xprojectedlen[i]=-9999;
327  trkstartcosxyz[i][0]=-9999;
328  trkstartcosxyz[i][1]=-9999;
329  trkstartcosxyz[i][2]=-9999;
330  trkendcosxyz[i][0]=-9999;
331  trkendcosxyz[i][1]=-9999;
332  trkendcosxyz[i][2]=-9999;
333  ntrkhits[i][0] = -9999;
334  ntrkhits[i][1] = -9999;
335  ntrkhits[i][2] = -9999;
336  for(int j=0; j<3; j++){
337  for(int k=0; k<3000; k++){
338  trkdqdx[i][j][k]=-9999;
339  trkdedx[i][j][k]=-9999;
340  trkresrange[i][j][k]=-9999;
341  trkhitx[i][j][k]=-9999;
342  trkhity[i][j][k]=-9999;
343  trkhitz[i][j][k]=-9999;
344  }
345  }
346  }
347  }
348  //////////////////////// End of definition ///////////////
349 
351 }
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...
Float_t trkendy[kMaxTracks]
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
Int_t ntrkhits[kMaxTracks][3]
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Float_t trackthetayz[kMaxTracks]
Float_t trkhitz[kMaxTracks][3][3000]
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
Float_t trkendx[kMaxTracks]
Vector_t VertexDirection() const
Definition: Track.h:132
STL namespace.
Float_t trkdqdx[kMaxTracks][3][3000]
Float_t trkendcosxyz[kMaxTracks][3]
Float_t trkstartx[kMaxTracks]
Float_t trkdedx[kMaxTracks][3][3000]
object containing MC flux information
Float_t trkstartcosxyz[kMaxTracks][3]
art framework interface to geometry description
Definition: Run.h:17
Float_t trkstartz[kMaxTracks]
void analyze(const art::Event &evt)
T abs(T value)
QTextStream & reset(QTextStream &s)
double dEdx(float dqdx, float Efield)
Definition: doAna.cpp:21
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
void beginJob()
Definition: Breakpoints.cc:14
const int kMaxTracks
def key(type, name=None)
Definition: graph.py:13
Float_t trkstarty[kMaxTracks]
Point_t const & Vertex() const
Definition: Track.h:124
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
Float_t trkhitx[kMaxTracks][3][3000]
RunNumber_t run() const
Definition: DataViewImpl.cc:71
Definition of data types for geometry description.
Float_t trklen[kMaxTracks]
Float_t trkhity[kMaxTracks][3][3000]
int ID() const
Definition: Track.h:198
Declaration of signal hit object.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
Vector_t EndDirection() const
Definition: Track.h:133
Float_t xprojectedlen[kMaxTracks]
Provides recob::Track data product.
Float_t trkendz[kMaxTracks]
EventNumber_t event() const
Definition: EventID.h:116
Point_t const & End() const
Definition: Track.h:125
Declaration of basic channel signal object.
detail::Node< FrameID, bool > PlaneID
Definition: CRTID.h:125
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
void beginRun(const art::Run &run)
Float_t trkresrange[kMaxTracks][3][3000]
int bool
Definition: qglobal.h:345
EventID id() const
Definition: Event.cc:34
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
QTextStream & endl(QTextStream &s)
Event finding and building.
Float_t trackthetaxz[kMaxTracks]