Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
larana
larana
OpticalDetector
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
"
27
#include "
lardataobj/RecoBase/OpFlash.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
53
Int_t
fEventID
,
fNFlashes
,
fNTruths
;
54
Float_t
fFlashY
,
fFlashZ
,
fFlashU
,
fFlashV
,
fFlashT
;
55
Float_t
fFlashPE
,
fFlashFastToTotal
;
56
Float_t
fFlashWidthY
,
fFlashWidthZ
,
fFlashWidthU
,
fFlashWidthV
;
57
Float_t
fVertexX
,
fVertexY
,
fVertexZ
/* , fVertexU, fVertexV */
,
fVertexT
;
58
Float_t
fTrueE
;
59
Int_t
fTruePDG
;
60
Float_t
fCenterX
,
fCenterY
,
fCenterZ
;
61
Float_t
fDistFlashCenter
,
fDistFlashVertex
;
62
Float_t
fDistFlashCenterNorm
,
fDistFlashVertexNorm
;
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
simb::MCParticle::E
double E(const int i=0) const
Definition:
MCParticle.h:233
recob::OpFlash::WireCenters
std::vector< double > const & WireCenters() const
Definition:
OpFlash.h:120
art::ServiceHandle< art::TFileService const >
simb::MCParticle::PdgCode
int PdgCode() const
Definition:
MCParticle.h:212
opdet::OpFlashMCTruthAna::fFlashT
Float_t fFlashT
Definition:
OpFlashMCTruthAna_module.cc:54
opdet::OpFlashMCTruthAna::fCenterX
Float_t fCenterX
Definition:
OpFlashMCTruthAna_module.cc:60
opdet::OpFlashMCTruthAna::fFlashInputModule
std::string fFlashInputModule
Definition:
OpFlashMCTruthAna_module.cc:46
simb::MCParticle::EndZ
double EndZ() const
Definition:
MCParticle.h:228
opdet::OpFlashMCTruthAna::fFlashZ
Float_t fFlashZ
Definition:
OpFlashMCTruthAna_module.cc:54
opdet
Definition:
AverageWaveform_module.cc:41
recob::OpFlash::FastToTotal
double FastToTotal() const
Definition:
OpFlash.h:119
Handle.h
opdet::OpFlashMCTruthAna::fVertexY
Float_t fVertexY
Definition:
OpFlashMCTruthAna_module.cc:57
opdet::OpFlashMCTruthAna::fDistFlashVertexNorm
Float_t fDistFlashVertexNorm
Definition:
OpFlashMCTruthAna_module.cc:62
string
std::string string
Definition:
nybbler.cc:12
opdet::OpFlashMCTruthAna::fTrueE
Float_t fTrueE
Definition:
OpFlashMCTruthAna_module.cc:58
cet::pow
constexpr T pow(T x)
Definition:
pow.h:72
opdet::OpFlashMCTruthAna::fFlashWidthV
Float_t fFlashWidthV
Definition:
OpFlashMCTruthAna_module.cc:56
simb::MCParticle
Definition:
MCParticle.h:24
art::Handle
Definition:
fwd.h:19
opdet::OpFlashMCTruthAna::analyze
void analyze(const art::Event &)
Definition:
OpFlashMCTruthAna_module.cc:155
opdet::OpFlashMCTruthAna::fDistFlashCenter
Float_t fDistFlashCenter
Definition:
OpFlashMCTruthAna_module.cc:61
art::EDAnalyzer::EDAnalyzer
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition:
EDAnalyzer.h:25
MCParticle.h
Particle class.
simb::MCParticle::EndY
double EndY() const
Definition:
MCParticle.h:227
opdet::OpFlashMCTruthAna
Definition:
OpFlashMCTruthAna_module.cc:31
ParameterSet.h
ServiceHandle.h
opdet::OpFlashMCTruthAna::fCenterZ
Float_t fCenterZ
Definition:
OpFlashMCTruthAna_module.cc:60
opdet::OpFlashMCTruthAna::fFlashFastToTotal
Float_t fFlashFastToTotal
Definition:
OpFlashMCTruthAna_module.cc:55
opdet::OpFlashMCTruthAna::fAnalysisTree
TTree * fAnalysisTree
Definition:
OpFlashMCTruthAna_module.cc:50
recob::OpFlash::ZCenter
double ZCenter() const
Definition:
OpFlash.h:117
opdet::OpFlashMCTruthAna::fVertexZ
Float_t fVertexZ
Definition:
OpFlashMCTruthAna_module.cc:57
recob::OpFlash::Time
double Time() const
Definition:
OpFlash.h:106
art::DataViewImpl::getByLabel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition:
DataViewImpl.h:633
DEFINE_ART_MODULE
#define DEFINE_ART_MODULE(klass)
Definition:
ModuleMacros.h:67
opdet::OpFlashMCTruthAna::fFlashWidthZ
Float_t fFlashWidthZ
Definition:
OpFlashMCTruthAna_module.cc:56
fhicl::ParameterSet::get
T get(std::string const &key) const
Definition:
ParameterSet.h:271
opdet::OpFlashMCTruthAna::fVertexT
Float_t fVertexT
Definition:
OpFlashMCTruthAna_module.cc:57
simb::MCParticle::T
double T(const int i=0) const
Definition:
MCParticle.h:224
opdet::OpFlashMCTruthAna::fFlashV
Float_t fFlashV
Definition:
OpFlashMCTruthAna_module.cc:54
opdet::OpFlashMCTruthAna::fFlashWidthY
Float_t fFlashWidthY
Definition:
OpFlashMCTruthAna_module.cc:56
Ptr.h
opdet::OpFlashMCTruthAna::fFlashWidthU
Float_t fFlashWidthU
Definition:
OpFlashMCTruthAna_module.cc:56
EDAnalyzer.h
opdet::OpFlashMCTruthAna::fFlashY
Float_t fFlashY
Definition:
OpFlashMCTruthAna_module.cc:54
ModuleMacros.h
recob::OpFlash::WireWidths
std::vector< double > const & WireWidths() const
Definition:
OpFlash.h:121
opdet::OpFlashMCTruthAna::fVertexX
Float_t fVertexX
Definition:
OpFlashMCTruthAna_module.cc:57
opdet::OpFlashMCTruthAna::fCenterY
Float_t fCenterY
Definition:
OpFlashMCTruthAna_module.cc:60
opdet::OpFlashMCTruthAna::fNTruths
Int_t fNTruths
Definition:
OpFlashMCTruthAna_module.cc:53
recob::OpFlash::YWidth
double YWidth() const
Definition:
OpFlash.h:116
simb::MCParticle::Vx
double Vx(const int i=0) const
Definition:
MCParticle.h:221
opdet::OpFlashMCTruthAna::fDistFlashCenterNorm
Float_t fDistFlashCenterNorm
Definition:
OpFlashMCTruthAna_module.cc:62
art::Event
Definition:
Event.h:22
opdet::OpFlashMCTruthAna::OpFlashMCTruthAna
OpFlashMCTruthAna(const fhicl::ParameterSet &)
Definition:
OpFlashMCTruthAna_module.cc:88
opdet::OpFlashMCTruthAna::fPerEventTree
TTree * fPerEventTree
Definition:
OpFlashMCTruthAna_module.cc:51
opdet::OpFlashMCTruthAna::fNFlashes
Int_t fNFlashes
Definition:
OpFlashMCTruthAna_module.cc:53
OpFlash.h
opdet::OpFlashMCTruthAna::fFlashU
Float_t fFlashU
Definition:
OpFlashMCTruthAna_module.cc:54
opdet::OpFlashMCTruthAna::fDistFlashVertex
Float_t fDistFlashVertex
Definition:
OpFlashMCTruthAna_module.cc:61
art::EDAnalyzer
Definition:
EDAnalyzer.h:20
simb::MCParticle::Vz
double Vz(const int i=0) const
Definition:
MCParticle.h:223
art::EventID::event
EventNumber_t event() const
Definition:
EventID.h:116
MCTruth.h
opdet::OpFlashMCTruthAna::fFlashPE
Float_t fFlashPE
Definition:
OpFlashMCTruthAna_module.cc:55
opdet::OpFlashMCTruthAna::fEventID
Int_t fEventID
Definition:
OpFlashMCTruthAna_module.cc:53
recob::OpFlash::TotalPE
double TotalPE() const
Definition:
OpFlash.cxx:68
tca::evt
TCEvent evt
Definition:
DataStructs.cxx:7
Event.h
opdet::OpFlashMCTruthAna::fTruthInputModule
std::string fTruthInputModule
Definition:
OpFlashMCTruthAna_module.cc:47
opdet::OpFlashMCTruthAna::fTruePDG
Int_t fTruePDG
Definition:
OpFlashMCTruthAna_module.cc:59
simb::MCParticle::EndX
double EndX() const
Definition:
MCParticle.h:226
recob::OpFlash::YCenter
double YCenter() const
Definition:
OpFlash.h:115
art::Ptr< recob::OpFlash >
art::Event::id
EventID id() const
Definition:
Event.cc:34
simb::MCParticle::Vy
double Vy(const int i=0) const
Definition:
MCParticle.h:222
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
recob::OpFlash::ZWidth
double ZWidth() const
Definition:
OpFlash.h:118
fhicl::ParameterSet
Definition:
ParameterSet.h:36
Generated by
1.8.11