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