All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
8 #include "art/Framework/Core/EDAnalyzer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "art/Framework/Services/Registry/ServiceHandle.h"
13 #include "art_root_io/TFileService.h"
14 #include "canvas/Persistency/Common/Ptr.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
25 #include "nusimdata/SimulationBase/MCTruth.h"
26 #include "nusimdata/SimulationBase/MCParticle.h"
28 
29 namespace opdet {
30 
31  class OpFlashMCTruthAna : public art::EDAnalyzer{
32  public:
33 
34  // Standard constructor and destructor for an ART module.
35  OpFlashMCTruthAna(const fhicl::ParameterSet&);
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.
46  std::string fFlashInputModule;
47  std::string fTruthInputModule;
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 {
78  DEFINE_ART_MODULE(OpFlashMCTruthAna)
79 }
80 
81 
82 // OpFlashMCTruthAna.cxx
83 
84 namespace opdet {
85 
86  //-----------------------------------------------------------------------
87  // Constructor
88  OpFlashMCTruthAna::OpFlashMCTruthAna(fhicl::ParameterSet const& pset)
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 
98  art::ServiceHandle<art::TFileService const> tfs;
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  //-----------------------------------------------------------------------
155  void OpFlashMCTruthAna::analyze(const art::Event& evt)
156  {
157 
158  // Create a handles
159  art::Handle< std::vector< recob::OpFlash > > FlashHandle;
160  art::Handle< std::vector< simb::MCTruth > > TruthHandle;
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 
215  fDistFlashCenter = pow(
216  pow(fCenterY - fFlashY,2) +
217  pow(fCenterZ - fFlashZ,2),
218  0.5);
219 
220  fDistFlashVertex = pow(
221  pow(fVertexY - fFlashY,2) +
222  pow(fVertexZ - fFlashZ,2),
223  0.5);
224 
225  fDistFlashCenterNorm = pow(
226  pow((fCenterY - fFlashY)/fFlashWidthY,2) +
227  pow((fCenterZ - fFlashZ)/fFlashWidthZ,2),
228  0.5);
229 
230  fDistFlashVertexNorm = pow(
231  pow((fVertexY - fFlashY)/fFlashWidthY,2) +
232  pow((fVertexZ - fFlashZ)/fFlashWidthZ,2),
233  0.5);
234 
235  fAnalysisTree->Fill();
236 
237  }
238 
239  }
240 
241  fPerEventTree->Fill();
242  }
243 
244 } // namespace opdet
void analyze(const art::Event &)
OpFlashMCTruthAna(const fhicl::ParameterSet &)
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8
BEGIN_PROLOG could also be cout