LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TrackTimeAssocAna_module.cc
Go to the documentation of this file.
1 // This analyzer writes out a TTree containing the properties of
2 // each reconstructed flash
3 //
4 #ifndef TrackTimeAssocAna_H
5 #define TrackTimeAssocAna_H 1
6 
7 // ROOT includes
8 #include "TH1.h"
9 #include "TH2.h"
10 #include "TLorentzVector.h"
11 #include "TVector3.h"
12 #include "TTree.h"
13 
14 // C++ includes
15 #include <map>
16 #include <vector>
17 #include <iostream>
18 #include <cstring>
19 #include <sstream>
20 #include "math.h"
21 #include <climits>
22 
23 // LArSoft includes
28 
29 // ART includes.
33 #include "fhiclcpp/ParameterSet.h"
43 
44 
45 namespace opdet {
46 
48  public:
49 
50  // Standard constructor and destructor for an ART module.
52  virtual ~TrackTimeAssocAna();
53 
54  // This method is called once, at the start of the job. In this
55  // example, it will define the histogram we'll write.
56  void beginJob();
57 
58  // The analyzer routine, called once per event.
59  void analyze (const art::Event&);
60 
61  private:
62 
63  // The stuff below is the part you'll most likely have to change to
64  // go from this custom example to your own task.
65 
66  // The parameters we'll read from the .fcl file.
67  std::string fMatchModuleLabel;
68 
69  TTree * fMatchTree;
70 
71  // Match variables
72  Int_t fEventID;
73  Int_t fMatchID;
74  Int_t fFlashID;
75  Int_t fTrackID;
76  Float_t fChi2;
77 
78  // Flash variables
79  Float_t fFFlashTime;
80  Float_t fFAbsTime;
81  Float_t fFTimeWidth;
84  Float_t fFTotalPE;
85  Float_t fFYCenter;
86  Float_t fFYWidth;
87  Float_t fFZCenter;
88  Float_t fFZWidth;
89  Float_t fFUCenter;
90  Float_t fFUWidth;
91  Float_t fFVCenter;
92  Float_t fFVWidth;
93  Float_t fFWCenter;
94  Float_t fFWWidth;
95  Float_t fFFastToTotal;
96 
97  // Track variables
98  Float_t fTEnd1X;
99  Float_t fTEnd2X;
100  Float_t fTEnd1Y;
101  Float_t fTEnd2Y;
102  Float_t fTEnd1Z;
103  Float_t fTEnd2Z;
104  Float_t fTLength;
105 
106 
107  };
108 
109 }
110 
111 #endif // TrackTimeAssocAna_H
112 
113 namespace opdet {
114 
115  //-----------------------------------------------------------------------
116  // Constructor
118  : EDAnalyzer(pset)
119  {
120 
121 
122  // Indicate that the Input Module comes from .fcl
123  fMatchModuleLabel = pset.get<std::string>("MatchModuleLabel");
124 
126 
127  fMatchTree = tfs->make<TTree>("MatchTree","MatchTree");
128 
129  fMatchTree->Branch("EventID", &fEventID, "EventID/I");
130  fMatchTree->Branch("FlashID", &fFlashID, "FlashID/I");
131  fMatchTree->Branch("TrackID", &fTrackID, "TrackID/I");
132  fMatchTree->Branch("Chi2", &fChi2, "Chi2/F");
133 
134 
135  // Flash variables
136  fMatchTree->Branch("FFlashTime", &fFFlashTime, "FFlashTime/F");
137  fMatchTree->Branch("FAbsTime", &fFAbsTime, "FAbsTime/F");
138  fMatchTree->Branch("FTimeWidth", &fFTimeWidth, "FTimeWidth/F");
139  fMatchTree->Branch("FInBeamFrame", &fFInBeamFrame, "FInBeamFrame/B");
140  fMatchTree->Branch("FOnBeamTime", &fFOnBeamTime, "FOnBeamTime/I");
141  fMatchTree->Branch("FTotalPE", &fFTotalPE, "FTotalPE/F");
142  fMatchTree->Branch("FYCenter", &fFYCenter, "FYCenter/F");
143  fMatchTree->Branch("FYWidth", &fFYWidth, "FYWidth/F");
144  fMatchTree->Branch("FZCenter", &fFZCenter, "FZCenter/F");
145  fMatchTree->Branch("FZWidth", &fFZWidth, "FZWidth/F");
146  fMatchTree->Branch("FUCenter", &fFUCenter, "FUCenter/F");
147  fMatchTree->Branch("FUWidth", &fFUWidth, "FUWidth/F");
148  fMatchTree->Branch("FVCenter", &fFVCenter, "FVCenter/F");
149  fMatchTree->Branch("FVWidth", &fFVWidth, "FVWidth/F");
150  fMatchTree->Branch("FWCenter", &fFWCenter, "FWCenter/F");
151  fMatchTree->Branch("FWWidth", &fFWWidth, "FWWidth/F");
152  fMatchTree->Branch("FFastToTotal", &fFFastToTotal, "FFastToTotal/F");
153 
154  fMatchTree->Branch("TEnd1X", &fTEnd1X, "TEnd1X/F");
155  fMatchTree->Branch("TEnd1Y", &fTEnd1Y, "TEnd1Y/F");
156  fMatchTree->Branch("TEnd1Z", &fTEnd1Z, "TEnd1Z/F");
157  fMatchTree->Branch("TEnd2X", &fTEnd2X, "TEnd2X/F");
158  fMatchTree->Branch("TEnd2Y", &fTEnd2Y, "TEnd2Y/F");
159  fMatchTree->Branch("TEnd2Z", &fTEnd2Z, "TEnd2Z/F");
160  fMatchTree->Branch("TLength", &fTLength, "TLength/F");
161 
162  }
163 
164  //-----------------------------------------------------------------------
165  // Destructor
167  {}
168 
169  //-----------------------------------------------------------------------
171  {
172  }
173 
174 
175  //-----------------------------------------------------------------------
177  {
178 
179  // Get flashes from event
181  evt.getByLabel(fMatchModuleLabel, MatchHandle);
182 
184  for(unsigned int i = 0; i < MatchHandle->size(); ++i){
185  art::Ptr<anab::FlashMatch> match(MatchHandle, i);
186  MatchVec.push_back(match);
187  }
188 
189  art::FindManyP<recob::OpFlash> FlashesFMH(MatchHandle, evt, fMatchModuleLabel);
190 
191  art::FindManyP<recob::Track> TracksFMH(MatchHandle, evt, fMatchModuleLabel);
192 
193 
194 
195  for(size_t iMatch = 0; iMatch!=MatchVec.size(); ++iMatch)
196  {
197  fEventID = evt.id().event();
198  fMatchID = iMatch;
199  fTrackID = MatchVec.at(iMatch)->SubjectID();
200  fFlashID = MatchVec.at(iMatch)->FlashID();
201  fChi2 = MatchVec.at(iMatch)->Chi2();
202 
203  std::vector<art::Ptr<recob::Track> > Tracks = TracksFMH.at(iMatch);
204  std::vector<art::Ptr<recob::OpFlash> > Flashes = FlashesFMH.at(iMatch);
205 
206  if(Tracks.size()!=1)
207  {
208  mf::LogError("TrackTimeAssocAna")<<"ERROR! Match to " << Tracks.size()<<" tracks - should be one!";
209  continue;
210  }
211 
212  if(Flashes.size()!=1)
213  {
214  mf::LogError("TrackTimeAssocAna")<<"ERROR! Match to " << Flashes.size()<<" flashes - should be one!";
215  continue;
216  }
217 
218  // Fill flash variables
219  fFFlashTime = Flashes.at(0)->Time();
220  fFAbsTime = Flashes.at(0)->AbsTime();
221  fFTimeWidth = Flashes.at(0)->TimeWidth();
222  fFInBeamFrame = Flashes.at(0)->InBeamFrame();
223  fFOnBeamTime = Flashes.at(0)->OnBeamTime();
224  fFTotalPE = Flashes.at(0)->TotalPE();
225  fFYCenter = Flashes.at(0)->YCenter();
226  fFYWidth = Flashes.at(0)->YWidth();
227  fFZCenter = Flashes.at(0)->ZCenter();
228  fFZWidth = Flashes.at(0)->ZWidth();
229  fFUCenter = Flashes.at(0)->WireCenters()[0];
230  fFUWidth = Flashes.at(0)->WireWidths()[0];
231  fFVCenter = Flashes.at(0)->WireCenters()[1];
232  fFVWidth = Flashes.at(0)->WireWidths()[1];
233  fFWCenter = Flashes.at(0)->WireCenters()[2];
234  fFWWidth = Flashes.at(0)->WireWidths()[2];
235  fFFastToTotal = Flashes.at(0)->FastToTotal();
236 
237 
238  // Fill track variables
239  fTEnd1X = Tracks.at(0)->Vertex().X();
240  fTEnd1Y = Tracks.at(0)->Vertex().Y();
241  fTEnd1Z = Tracks.at(0)->Vertex().Z();
242  fTEnd2X = Tracks.at(0)->End().X();
243  fTEnd2Y = Tracks.at(0)->End().Y();
244  fTEnd2Z = Tracks.at(0)->End().Z();
245 
246  fTLength = Tracks.at(0)->Length();
247 
248  fMatchTree->Fill();
249  }
250 
251 
252  }
253 
254 } // namespace opdet
255 
256 namespace opdet {
258 }
259 
TrackTimeAssocAna(const fhicl::ParameterSet &)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
T get(std::string const &key) const
Definition: ParameterSet.h:231
reference at(size_type n)
Definition: PtrVector.h:365
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
size_type size() const
Definition: PtrVector.h:308
Utility object to perform functions of association.
void analyze(const art::Event &)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
EventNumber_t event() const
Definition: EventID.h:117
TCEvent evt
Definition: DataStructs.cxx:5
Definition: fwd.h:25
EventID id() const
Definition: Event.h:56