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 // Framework includes
13 #include "art_root_io/TFileService.h"
15 #include "fhiclcpp/ParameterSet.h"
16 
17 // ROOT includes
18 #include "TTree.h"
19 
20 // C++ Includes
21 #include <iostream>
22 #include "math.h"
23 
24 // LArSoft includes
28 
29 namespace opdet {
30 
32  public:
33 
34  // Standard constructor and destructor for an ART module.
36 
37  // The analyzer routine, called once per event.
38  void analyze (const art::Event&);
39 
40  private:
41 
42  // The stuff below is the part you'll most likely have to change to
43  // go from this custom example to your own task.
44 
45  // The parameters we'll read from the .fcl file.
48 
49 
50  TTree * fAnalysisTree;
51  TTree * fPerEventTree;
52 
57  Float_t fVertexX, fVertexY, fVertexZ /* , fVertexU, fVertexV */, fVertexT;
58  Float_t fTrueE;
59  Int_t fTruePDG;
63 
64 
65  };
66 
67 }
68 
69 
70 // OpFlashMCTruthAna_module.cc
71 
72 // This is a short program required by the ART framework. It enables
73 // a program (OpFlashMCTruthAna, in this case) to be called as a module
74 // from a .fcl file. It is unlikely that you'll have to make any
75 // changes to this file.
76 
77 namespace opdet {
79 }
80 
81 
82 // OpFlashMCTruthAna.cxx
83 
84 namespace opdet {
85 
86  //-----------------------------------------------------------------------
87  // Constructor
89  : EDAnalyzer(pset)
90  {
91 
92  // Indicate that the Input Module comes from .fcl
93  fFlashInputModule = pset.get<std::string>("FlashInputModule");
94  fTruthInputModule = pset.get<std::string>("TruthInputModule");
95 
96 
97 
99 
100  fPerEventTree = tfs->make<TTree>("PerEventTree", "PerEventTree");
101 
102  fPerEventTree->Branch("EventID", &fEventID, "EventID/I");
103  fPerEventTree->Branch("NFlashes", &fNFlashes, "NFlashes/I");
104 
105  fPerEventTree->Branch("VertexX", &fVertexX, "VertexX/F");
106  fPerEventTree->Branch("VertexY", &fVertexY, "VertexY/F");
107  fPerEventTree->Branch("VertexZ", &fVertexZ, "VertexZ/F");
108 
109  fPerEventTree->Branch("TrueE", &fTrueE, "TrueE/F");
110  fPerEventTree->Branch("TruePDG", &fTruePDG, "TruePDG/I");
111 
112  fPerEventTree->Branch("CenterX", &fCenterX, "CenterX/F");
113  fPerEventTree->Branch("CenterY", &fCenterY, "CenterY/F");
114  fPerEventTree->Branch("CenterZ", &fCenterZ, "CenterZ/F");
115 
116 
117 
118  fAnalysisTree = tfs->make<TTree>("AnalysisTree", "AnalysisTree");
119 
120  fAnalysisTree->Branch("EventID", &fEventID, "EventID/I");
121  fAnalysisTree->Branch("NFlashes", &fNFlashes, "NFlashes/I");
122 
123  fAnalysisTree->Branch("FlashY", &fFlashY, "FlashY/F");
124  fAnalysisTree->Branch("FlashZ", &fFlashZ, "FlashZ/F");
125  fAnalysisTree->Branch("FlashU", &fFlashU, "FlashU/F");
126  fAnalysisTree->Branch("FlashV", &fFlashV, "FlashV/F");
127 
128  fAnalysisTree->Branch("FlashWidthY", &fFlashWidthY, "FlashWidthY/F");
129  fAnalysisTree->Branch("FlashWidthZ", &fFlashWidthZ, "FlashWidthZ/F");
130  fAnalysisTree->Branch("FlashWidthU", &fFlashWidthU, "FlashWidthU/F");
131  fAnalysisTree->Branch("FlashWidthV", &fFlashWidthV, "FlashWidthV/F");
132 
133  fAnalysisTree->Branch("FlashT", &fFlashT, "FlashT/F");
134  fAnalysisTree->Branch("FlashPE", &fFlashPE, "FlashPE/F");
135  fAnalysisTree->Branch("FlashFastToTotal", &fFlashFastToTotal, "FlashFastToTotal/F");
136 
137  fAnalysisTree->Branch("VertexX", &fVertexX, "VertexX/F");
138  fAnalysisTree->Branch("VertexY", &fVertexY, "VertexY/F");
139  fAnalysisTree->Branch("VertexZ", &fVertexZ, "VertexZ/F");
140 
141  fAnalysisTree->Branch("TrueE", &fTrueE, "TrueE/F");
142  fAnalysisTree->Branch("TruePDG", &fTruePDG, "TruePDG/I");
143 
144  fAnalysisTree->Branch("CenterX", &fCenterX, "CenterX/F");
145  fAnalysisTree->Branch("CenterY", &fCenterY, "CenterY/F");
146  fAnalysisTree->Branch("CenterZ", &fCenterZ, "CenterZ/F");
147 
148  fAnalysisTree->Branch("DistFlashCenter", &fDistFlashCenter, "DistFlashCenter/F");
149  fAnalysisTree->Branch("DistFlashVertex", &fDistFlashVertex, "DistFlashVertex/F");
150 
151 
152  }
153 
154  //-----------------------------------------------------------------------
156  {
157 
158  // Create a handles
161 
162  // Read in data
163  evt.getByLabel(fFlashInputModule, FlashHandle);
164  evt.getByLabel(fTruthInputModule, TruthHandle);
165 
166  fEventID=evt.id().event();
167 
168  fNTruths = TruthHandle->at(0).NParticles();
169  fNFlashes = FlashHandle->size();
170 
171  std::cout<<"Size of truth collection : " << TruthHandle->size()<<std::endl;
172  std::cout<<"We found " << fNTruths<<" truth particles and " << fNFlashes<<" flashes" <<std::endl;
173 
174 
175  for(int iPart=0; iPart!=fNTruths; ++iPart)
176  {
177  const simb::MCParticle ThisPart = TruthHandle->at(0).GetParticle(iPart);
178  fTruePDG = ThisPart.PdgCode();
179  fTrueE = ThisPart.E(0);
180 
181  fVertexX = ThisPart.Vx(0);
182  fVertexY = ThisPart.Vy(0);
183  fVertexZ = ThisPart.Vz(0);
184  fVertexT = ThisPart.T(0);
185 
186  fCenterX = (ThisPart.Vx(0) + ThisPart.EndX())/2.;
187  fCenterY = (ThisPart.Vy(0) + ThisPart.EndY())/2.;
188  fCenterZ = (ThisPart.Vz(0) + ThisPart.EndZ())/2.;
189 
190 
191  for(unsigned int i = 0; i < FlashHandle->size(); ++i)
192  {
193 
194  // Get OpFlash
195  art::Ptr< recob::OpFlash > TheFlashPtr(FlashHandle, i);
196 
197  fFlashT = TheFlashPtr->Time();
198  fFlashPE = TheFlashPtr->TotalPE();
199  fFlashFastToTotal = TheFlashPtr->FastToTotal();
200 
201  fFlashY = TheFlashPtr->YCenter();
202  fFlashZ = TheFlashPtr->ZCenter();
203  fFlashU = TheFlashPtr->WireCenters().at(0);
204  fFlashV = TheFlashPtr->WireCenters().at(1);
205 
206  fFlashWidthY = TheFlashPtr->YWidth();
207  fFlashWidthZ = TheFlashPtr->ZWidth();
208  fFlashWidthU = TheFlashPtr->WireWidths().at(0);
209  fFlashWidthV = TheFlashPtr->WireWidths().at(1);
210 
211 
212 
213 
214 
216  pow(fCenterY - fFlashY,2) +
217  pow(fCenterZ - fFlashZ,2),
218  0.5);
219 
221  pow(fVertexY - fFlashY,2) +
222  pow(fVertexZ - fFlashZ,2),
223  0.5);
224 
228  0.5);
229 
233  0.5);
234 
235  fAnalysisTree->Fill();
236 
237  }
238 
239  }
240 
241  fPerEventTree->Fill();
242  }
243 
244 } // namespace opdet
double E(const int i=0) const
Definition: MCParticle.h:233
std::vector< double > const & WireCenters() const
Definition: OpFlash.h:120
int PdgCode() const
Definition: MCParticle.h:212
double EndZ() const
Definition: MCParticle.h:228
double FastToTotal() const
Definition: OpFlash.h:119
std::string string
Definition: nybbler.cc:12
constexpr T pow(T x)
Definition: pow.h:72
void analyze(const art::Event &)
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Particle class.
double EndY() const
Definition: MCParticle.h:227
double ZCenter() const
Definition: OpFlash.h:117
double Time() const
Definition: OpFlash.h:106
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
double T(const int i=0) const
Definition: MCParticle.h:224
std::vector< double > const & WireWidths() const
Definition: OpFlash.h:121
double YWidth() const
Definition: OpFlash.h:116
double Vx(const int i=0) const
Definition: MCParticle.h:221
OpFlashMCTruthAna(const fhicl::ParameterSet &)
double Vz(const int i=0) const
Definition: MCParticle.h:223
EventNumber_t event() const
Definition: EventID.h:116
double TotalPE() const
Definition: OpFlash.cxx:68
TCEvent evt
Definition: DataStructs.cxx:7
double EndX() const
Definition: MCParticle.h:226
double YCenter() const
Definition: OpFlash.h:115
EventID id() const
Definition: Event.cc:34
double Vy(const int i=0) const
Definition: MCParticle.h:222
QTextStream & endl(QTextStream &s)
double ZWidth() const
Definition: OpFlash.h:118