LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
OpFlashMCTruthAna_module.cc
Go to the documentation of this file.
1 // Christie Chiu and Ben Jones, MIT, 2012
2 //
3 // This is an analyzer module which writes the raw optical
4 // detector pulses for each PMT to an output file
5 //
6 
7 
8 #ifndef OpFlashMCTruthAna_H
9 #define OpFlashMCTruthAna_H 1
10 
11 // LArSoft includes
13 
14 #include "TTree.h"
15 
16 // ART includes.
18 
19 
20 // C++ includes
21 #include <cstring>
22 #include <vector>
23 
26 
27 namespace opdet {
28 
30  public:
31 
32  // Standard constructor and destructor for an ART module.
34  virtual ~OpFlashMCTruthAna();
35 
36  // This method is called once, at the start of the job. In this
37  // example, it will define the histogram we'll write.
38  void beginJob();
39 
40  // The analyzer routine, called once per event.
41  void analyze (const art::Event&);
42 
43  private:
44 
45  // The stuff below is the part you'll most likely have to change to
46  // go from this custom example to your own task.
47 
48  // The parameters we'll read from the .fcl file.
49  std::string fFlashInputModule;
50  std::string fTruthInputModule;
51 
52 
53  TTree * fAnalysisTree;
54  TTree * fPerEventTree;
55 
60  Float_t fVertexX, fVertexY, fVertexZ /* , fVertexU, fVertexV */, fVertexT;
61  Float_t fTrueE;
62  Int_t fTruePDG;
66 
67 
68  };
69 
70 }
71 
72 #endif // OpFlashMCTruthAna_H
73 
74 
75 
76 
77 // OpFlashMCTruthAna_module.cc
78 
79 // This is a short program required by the ART framework. It enables
80 // a program (OpFlashMCTruthAna, in this case) to be called as a module
81 // from a .fcl file. It is unlikely that you'll have to make any
82 // changes to this file.
83 
84 // Framework includes
86 
87 namespace opdet {
89 }
90 
91 
92 // OpFlashMCTruthAna.cxx
93 
94 // LArSoft includes
97 
98 
99 // Framework includes
101 #include "fhiclcpp/ParameterSet.h"
109 
110 // ROOT includes
111 #include "TLorentzVector.h"
112 #include "TVector3.h"
113 
114 // C++ Includes
115 #include <map>
116 #include <vector>
117 #include <iostream>
118 #include <cstring>
119 #include <sstream>
120 #include "math.h"
121 #include <climits>
122 
123 namespace opdet {
124 
125  //-----------------------------------------------------------------------
126  // Constructor
128  : EDAnalyzer(pset)
129  {
130 
131  // Indicate that the Input Module comes from .fcl
132  fFlashInputModule = pset.get<std::string>("FlashInputModule");
133  fTruthInputModule = pset.get<std::string>("TruthInputModule");
134 
135 
136 
138 
139  fPerEventTree = tfs->make<TTree>("PerEventTree", "PerEventTree");
140 
141  fPerEventTree->Branch("EventID", &fEventID, "EventID/I");
142  fPerEventTree->Branch("NFlashes", &fNFlashes, "NFlashes/I");
143 
144  fPerEventTree->Branch("VertexX", &fVertexX, "VertexX/F");
145  fPerEventTree->Branch("VertexY", &fVertexY, "VertexY/F");
146  fPerEventTree->Branch("VertexZ", &fVertexZ, "VertexZ/F");
147 
148  fPerEventTree->Branch("TrueE", &fTrueE, "TrueE/F");
149  fPerEventTree->Branch("TruePDG", &fTruePDG, "TruePDG/I");
150 
151  fPerEventTree->Branch("CenterX", &fCenterX, "CenterX/F");
152  fPerEventTree->Branch("CenterY", &fCenterY, "CenterY/F");
153  fPerEventTree->Branch("CenterZ", &fCenterZ, "CenterZ/F");
154 
155 
156 
157  fAnalysisTree = tfs->make<TTree>("AnalysisTree", "AnalysisTree");
158 
159  fAnalysisTree->Branch("EventID", &fEventID, "EventID/I");
160  fAnalysisTree->Branch("NFlashes", &fNFlashes, "NFlashes/I");
161 
162  fAnalysisTree->Branch("FlashY", &fFlashY, "FlashY/F");
163  fAnalysisTree->Branch("FlashZ", &fFlashZ, "FlashZ/F");
164  fAnalysisTree->Branch("FlashU", &fFlashU, "FlashU/F");
165  fAnalysisTree->Branch("FlashV", &fFlashV, "FlashV/F");
166 
167  fAnalysisTree->Branch("FlashWidthY", &fFlashWidthY, "FlashWidthY/F");
168  fAnalysisTree->Branch("FlashWidthZ", &fFlashWidthZ, "FlashWidthZ/F");
169  fAnalysisTree->Branch("FlashWidthU", &fFlashWidthU, "FlashWidthU/F");
170  fAnalysisTree->Branch("FlashWidthV", &fFlashWidthV, "FlashWidthV/F");
171 
172  fAnalysisTree->Branch("FlashT", &fFlashT, "FlashT/F");
173  fAnalysisTree->Branch("FlashPE", &fFlashPE, "FlashPE/F");
174  fAnalysisTree->Branch("FlashFastToTotal", &fFlashFastToTotal, "FlashFastToTotal/F");
175 
176  fAnalysisTree->Branch("VertexX", &fVertexX, "VertexX/F");
177  fAnalysisTree->Branch("VertexY", &fVertexY, "VertexY/F");
178  fAnalysisTree->Branch("VertexZ", &fVertexZ, "VertexZ/F");
179 
180  fAnalysisTree->Branch("TrueE", &fTrueE, "TrueE/F");
181  fAnalysisTree->Branch("TruePDG", &fTruePDG, "TruePDG/I");
182 
183  fAnalysisTree->Branch("CenterX", &fCenterX, "CenterX/F");
184  fAnalysisTree->Branch("CenterY", &fCenterY, "CenterY/F");
185  fAnalysisTree->Branch("CenterZ", &fCenterZ, "CenterZ/F");
186 
187  fAnalysisTree->Branch("DistFlashCenter", &fDistFlashCenter, "DistFlashCenter/F");
188  fAnalysisTree->Branch("DistFlashVertex", &fDistFlashVertex, "DistFlashVertex/F");
189 
190 
191  }
192 
193  //-----------------------------------------------------------------------
194  // Destructor
196  {}
197 
198  //-----------------------------------------------------------------------
200  {
201  }
202 
203 
204  //-----------------------------------------------------------------------
206  {
207 
208  // Create a handles
211 
212  // Read in data
213  evt.getByLabel(fFlashInputModule, FlashHandle);
214  evt.getByLabel(fTruthInputModule, TruthHandle);
215 
216  fEventID=evt.id().event();
217 
218  fNTruths = TruthHandle->at(0).NParticles();
219  fNFlashes = FlashHandle->size();
220 
221  std::cout<<"Size of truth collection : " << TruthHandle->size()<<std::endl;
222  std::cout<<"We found " << fNTruths<<" truth particles and " << fNFlashes<<" flashes" <<std::endl;
223 
224 
225  for(int iPart=0; iPart!=fNTruths; ++iPart)
226  {
227  const simb::MCParticle ThisPart = TruthHandle->at(0).GetParticle(iPart);
228  fTruePDG = ThisPart.PdgCode();
229  fTrueE = ThisPart.E(0);
230 
231  fVertexX = ThisPart.Vx(0);
232  fVertexY = ThisPart.Vy(0);
233  fVertexZ = ThisPart.Vz(0);
234  fVertexT = ThisPart.T(0);
235 
236  fCenterX = (ThisPart.Vx(0) + ThisPart.EndX())/2.;
237  fCenterY = (ThisPart.Vy(0) + ThisPart.EndY())/2.;
238  fCenterZ = (ThisPart.Vz(0) + ThisPart.EndZ())/2.;
239 
240 
241  for(unsigned int i = 0; i < FlashHandle->size(); ++i)
242  {
243 
244  // Get OpFlash
245  art::Ptr< recob::OpFlash > TheFlashPtr(FlashHandle, i);
246 
247  fFlashT = TheFlashPtr->Time();
248  fFlashPE = TheFlashPtr->TotalPE();
249  fFlashFastToTotal = TheFlashPtr->FastToTotal();
250 
251  fFlashY = TheFlashPtr->YCenter();
252  fFlashZ = TheFlashPtr->ZCenter();
253  fFlashU = TheFlashPtr->WireCenters().at(0);
254  fFlashV = TheFlashPtr->WireCenters().at(1);
255 
256  fFlashWidthY = TheFlashPtr->YWidth();
257  fFlashWidthZ = TheFlashPtr->ZWidth();
258  fFlashWidthU = TheFlashPtr->WireWidths().at(0);
259  fFlashWidthV = TheFlashPtr->WireWidths().at(1);
260 
261 
262 
263 
264 
265  fDistFlashCenter = pow(
266  pow(fCenterY - fFlashY,2) +
267  pow(fCenterZ - fFlashZ,2),
268  0.5);
269 
270  fDistFlashVertex = pow(
271  pow(fVertexY - fFlashY,2) +
272  pow(fVertexZ - fFlashZ,2),
273  0.5);
274 
275  fDistFlashCenterNorm = pow(
276  pow((fCenterY - fFlashY)/fFlashWidthY,2) +
277  pow((fCenterZ - fFlashZ)/fFlashWidthZ,2),
278  0.5);
279 
280  fDistFlashVertexNorm = pow(
281  pow((fVertexY - fFlashY)/fFlashWidthY,2) +
282  pow((fVertexZ - fFlashZ)/fFlashWidthZ,2),
283  0.5);
284 
285  fAnalysisTree->Fill();
286 
287  }
288 
289  }
290 
291  fPerEventTree->Fill();
292  }
293 
294 } // namespace opdet
295 
296 
double E(const int i=0) const
Definition: MCParticle.h:237
int PdgCode() const
Definition: MCParticle.h:216
double EndZ() const
Definition: MCParticle.h:232
double FastToTotal() const
Definition: OpFlash.h:93
void analyze(const art::Event &)
Particle class.
double EndY() const
Definition: MCParticle.h:231
double ZCenter() const
Definition: OpFlash.h:91
double Time() const
Definition: OpFlash.h:83
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< double > WireCenters() const
Definition: OpFlash.h:94
double T(const int i=0) const
Definition: MCParticle.h:228
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
std::vector< double > WireWidths() const
Definition: OpFlash.h:95
double YWidth() const
Definition: OpFlash.h:90
double Vx(const int i=0) const
Definition: MCParticle.h:225
OpFlashMCTruthAna(const fhicl::ParameterSet &)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double Vz(const int i=0) const
Definition: MCParticle.h:227
EventNumber_t event() const
Definition: EventID.h:117
double TotalPE() const
Definition: OpFlash.cxx:56
double EndX() const
Definition: MCParticle.h:230
double YCenter() const
Definition: OpFlash.h:89
EventID id() const
Definition: Event.h:56
double Vy(const int i=0) const
Definition: MCParticle.h:226
art framework interface to geometry description
double ZWidth() const
Definition: OpFlash.h:92