-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdEdx_module.cc
309 lines (255 loc) · 9.08 KB
/
dEdx_module.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#ifndef dEdx_Module
#define dEdx_Module
// LArSoft includes
#include "lardataobj/Simulation/SimChannel.h"
#include "larsim/Simulation/LArG4Parameters.h"
#include "larcore/Geometry/Geometry.h"
#include "nusimdata/SimulationBase/MCParticle.h"
#include "nusimdata/SimulationBase/MCTruth.h"
#include "larcoreobj/SimpleTypesAndConstants/geo_types.h"
// Framework includes
#include "art/Framework/Core/EDAnalyzer.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "art_root_io/TFileService.h"
#include "art/Framework/Core/ModuleMacros.h"
#include "canvas/Persistency/Common/FindManyP.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "fhiclcpp/ParameterSet.h"
// ROOT includes.
#include "TF1.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TTree.h"
#include "TLorentzVector.h"
#include "TVector3.h"
#include "THStack.h"
// C++ Includes
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
///////////////////////////////////////////////////////////////////////
// This module is used to calculate dE/dx from simulated (cheated) //
// information. It was intended for a e/gamma separation study, //
// but can be adapted for similar purposes if desired. //
// //
// Kevin R. Wood -- [email protected] (07/23/2014) //
///////////////////////////////////////////////////////////////////////
namespace AnalysisExample
{
class dEdx : public art::EDAnalyzer
{
public:
explicit dEdx(fhicl::ParameterSet const& pset);
virtual ~dEdx();
void beginJob();
void beginRun(const art::Run& run);
void reconfigure(fhicl::ParameterSet const& pset);
void analyze(const art::Event& evt);
void endJob();
void findDepositionVertex(std::vector<sim::SimChannel> SCHandle);
void checkDepositionVertex(std::vector<sim::SimChannel> SCHandle, double x, double y, double z);
private:
art::ServiceHandle<art::TFileService> tfs;
art::ServiceHandle<geo::Geometry> fGeom;
std::string fSimulationProducerLabel;
// dE/dx "cheated" information
TH1D* fMCdEdxHist;
std::vector<double> fMCdEdxVec;
double fMaxMCdEdx = 0.;
double dE;
// distance of energy deposition from conversion point
double trackLength;
// energy deposition 3d positions for conversion points, ~2.5cm of "track"
// upstream of conversion point (for dE/dx), and shower respectively
TH3D* fStartEdepHist;
TH3D* fTrackEdepHist;
TH3D* fShowerEdepHist;
// list of event numbers corresponding to unusually low dEdx measurement
std::vector<unsigned int> fNullList;
// position of conversion point
double xi = 0.;
double yi = 0.;
double zi = 1000.;
// for finding conversion point
double ziFalse = -500.;
unsigned int nearDeps = 0;
bool goodDepVertex = false;
// for conversion distance
double fConvDist;
TH1D* fConvDistHist;
double Vxi; //
double Vyi; // primary vertex coordinates
double Vzi; //
};
//-----------------------------------------------------------------------
dEdx::dEdx(fhicl::ParameterSet const& parameterSet)
: EDAnalyzer(parameterSet)
{
this->reconfigure(parameterSet);
}
//-----------------------------------------------------------------------
dEdx::~dEdx()
{
}
//-----------------------------------------------------------------------
void dEdx::beginJob()
{
// hard-coded fd4apa cryostat dimensions
fStartEdepHist = tfs->make<TH3D>("fStartEdepHist","fStartEdepHist",50,-240.,240.,50,-750.,800.,50,-50.,560.);
fTrackEdepHist = tfs->make<TH3D>("fTrackEdepHist","fTrackEdepHist",50,-240.,240.,50,-750.,800.,50,-50.,560.);
fShowerEdepHist = tfs->make<TH3D>("fShowerEdepHist","fShowerEdepHist",50,-240.,240.,50,-750.,800.,50,-50.,560.);
fStartEdepHist->GetXaxis()->SetTitle("x");
fStartEdepHist->GetYaxis()->SetTitle("y");
fStartEdepHist->GetZaxis()->SetTitle("z");
fShowerEdepHist->GetXaxis()->SetTitle("x");
fShowerEdepHist->GetYaxis()->SetTitle("y");
fShowerEdepHist->GetZaxis()->SetTitle("z");
fTrackEdepHist->GetXaxis()->SetTitle("x");
fTrackEdepHist->GetYaxis()->SetTitle("y");
fTrackEdepHist->GetZaxis()->SetTitle("z");
fConvDistHist = tfs->make<TH1D>("fConvDistHist","fConvDistHist",100,0.,50.);
}
//-----------------------------------------------------------------------
void dEdx::beginRun(const art::Run& run)
{
}
//-----------------------------------------------------------------------
void dEdx::reconfigure(fhicl::ParameterSet const& p)
{
fSimulationProducerLabel = p.get<std::string>("SimulationLabel");
}
//-----------------------------------------------------------------------
void dEdx::analyze( const art::Event& event )
{
art::Handle<std::vector<sim::SimChannel>> simChanHandle;
event.getByLabel(fSimulationProducerLabel, simChanHandle);
// initialize at the start of every event
dE = 0.;
trackLength = 0.;
goodDepVertex = false;
unsigned int nTries = 0;
ziFalse = -500.;
// find conversion point
while(!goodDepVertex && nTries < 300)
{
this->findDepositionVertex( (*simChanHandle) );
this->checkDepositionVertex( (*simChanHandle), xi, yi, zi );
nTries++;
}
std::cout << "Number of attemps at finding deposition vertex = " << nTries << "." << std::endl;
// find energy deposited into first 2.5 cm of "track"
if(nTries < 300 && goodDepVertex)
{
fStartEdepHist->Fill(xi,yi,zi);
for(auto const& channel : (*simChanHandle))
{
if(fGeom->SignalType(channel.Channel()) == geo::kCollection)
{
auto const& timeSlices = channel.TDCIDEMap();
for(auto const& t : timeSlices)
{
auto const& eDeps = t.second;
for(auto const& eDep : eDeps)
{
fShowerEdepHist->Fill(eDep.x,eDep.y,eDep.z);
trackLength = std::sqrt( (eDep.x-xi)*(eDep.x-xi) + (eDep.y-yi)*(eDep.y-yi) + (eDep.z-zi)*(eDep.z-zi) );
if(trackLength < 2.5 /* && eDep.z >= zi*/)
{
dE += eDep.energy;
fTrackEdepHist->Fill(eDep.x,eDep.y,eDep.z);
}
} // every energy deposition
} // in every time slice
} // for the collection plane
} // and for every wire
dE /= 2.5;
fMCdEdxVec.push_back(dE);
if(dE > fMaxMCdEdx) fMaxMCdEdx = dE;
if(dE < 0.5) fNullList.push_back(event.id().event());
}
art::Handle< std::vector<simb::MCParticle> > particleHandle;
event.getByLabel(fSimulationProducerLabel, particleHandle);
for(auto const& particle : (*particleHandle))
{
if(particle.Process() == "primary")
{
Vxi = particle.Vx();
Vyi = particle.Vy();
Vzi = particle.Vz();
}
}
fConvDist = std::sqrt( (Vxi-xi)*(Vxi-xi) + (Vyi-yi)*(Vyi-yi) + (Vzi-zi)*(Vzi-zi) );
fConvDistHist->Fill(fConvDist);
}
//-----------------------------------------------------------------------
void dEdx::endJob()
{
fMCdEdxHist = tfs->make<TH1D>("fMCdEdxHist",";dE/dx (MeV/cm)",200,0.0,10.);
for(unsigned int e = 0; e < fMCdEdxVec.size(); e++)
{
fMCdEdxHist->Fill(fMCdEdxVec[e]);
}
std::cout << "Events with < 0.5 dE/dx entry: ";
for(unsigned int a = 0; a < fNullList.size(); a++) std::cout << fNullList[a] << ", ";
}
void dEdx::findDepositionVertex(std::vector<sim::SimChannel> SCHandle)
{
zi = 1000.;
std::cout << "Finding Deposition Vertex... " << std::endl;
for(auto const& channel : SCHandle)
{
if(fGeom->SignalType(channel.Channel()) == geo::kCollection)
{
auto const& timeSlices = channel.TDCIDEMap();
for(auto const& t : timeSlices)
{
auto const& eDeps = t.second;
for(auto const& eDep : eDeps)
{
if( (eDep.z < zi) && (eDep.energy > 0.) && (eDep.z > ziFalse) )
{
xi = eDep.x;
yi = eDep.y;
zi = eDep.z;
} // if z position is a "valid" minimum
} // energy deposition loop
} // time slice loop
} // if collection wire
} // sim channel loop
} // findDepositionVertex
void dEdx::checkDepositionVertex(std::vector<sim::SimChannel> SCHandle, double x,double y, double z)
{
std::cout << "Checking for Deposition Vertex" << std::endl;
nearDeps = 0;
double track = 0;
for(auto const& channel : SCHandle)
{
if(fGeom->SignalType(channel.Channel()) == geo::kCollection)
{
auto const& timeSlices = channel.TDCIDEMap();
for(auto const& t : timeSlices)
{
auto const& eDeps = t.second;
for(auto const& eDep : eDeps)
{
track = std::sqrt( (eDep.x-x)*(eDep.x-x) + (eDep.y-y)*(eDep.y-y) + (eDep.z-z)*(eDep.z-z) );
if(track < 2.5 && eDep.energy > 0.)
{
nearDeps++;
} // if z position is minimum
} // energy deposition loop
} // time slice loop
} // if collection wire
} // sim channel loop
if( nearDeps > 30) goodDepVertex = true;
else ziFalse = z + 0.05;
} // checkDepositionVertex
DEFINE_ART_MODULE(dEdx)
} // namespace AnalysisExample
#endif // dEdx_Module