-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTPCAnalyzer_module.hh
More file actions
433 lines (372 loc) · 13.4 KB
/
TPCAnalyzer_module.hh
File metadata and controls
433 lines (372 loc) · 13.4 KB
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
////////////////////////////////////////////////////////////////////////
// Class: TPCAnalyzer
// Plugin Type: analyzer (art v3_05_01)
// File: TPCAnalyzer_module.cc
////////////////////////////////////////////////////////////////////////
#include "art/Framework/Core/EDAnalyzer.h"
#include "art/Framework/Core/ModuleMacros.h"
#include "art/Framework/Principal/Event.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Framework/Principal/Run.h"
#include "art/Framework/Principal/SubRun.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "larcore/CoreUtils/ServiceUtil.h"
#include "art_root_io/TFileService.h"
#include "art_root_io/TFileDirectory.h"
#include "canvas/Utilities/InputTag.h"
#include "canvas/Persistency/Common/Ptr.h"
#include "canvas/Persistency/Common/PtrVector.h"
#include "canvas/Persistency/Common/FindMany.h"
#include "canvas/Persistency/Common/FindManyP.h"
#include "canvas/Persistency/Common/FindOneP.h"
#include "canvas/Persistency/Common/Ptr.h"
#include "canvas/Persistency/Common/PtrVector.h"
#include "fhiclcpp/ParameterSet.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "art/Framework/Principal/Handle.h"
#include "art/Framework/Services/Registry/ServiceHandle.h"
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
#include "larsim/MCCheater/ParticleInventoryService.h"
#include "larcore/Geometry/Geometry.h"
#include "larevt/SpaceCharge/SpaceCharge.h"
#include "larevt/SpaceChargeServices/SpaceChargeService.h"
#include "nusimdata/SimulationBase/MCTruth.h"
#include "nusimdata/SimulationBase/MCNeutrino.h"
#include "nusimdata/SimulationBase/MCParticle.h"
#include "lardataobj/Simulation/SimEnergyDeposit.h"
#include "lardataobj/Simulation/SimChannel.h"
#include "lardataobj/RawData/RawDigit.h"
#include "lardataobj/RecoBase/Track.h"
#include "lardataobj/RecoBase/Shower.h"
#include "lardataobj/RecoBase/PFParticle.h"
#include "lardataobj/RecoBase/SpacePoint.h"
#include "lardataobj/RecoBase/Cluster.h"
#include "lardataobj/RecoBase/Hit.h"
#include "lardataobj/RawData/RawDigit.h"
#include "lardataobj/RecoBase/Wire.h"
#include "lardataobj/RecoBase/Vertex.h"
#include "lardataobj/RecoBase/Slice.h"
#include "lardataobj/AnalysisBase/Calorimetry.h"
#include "lardataobj/AnalysisBase/ParticleID.h"
#include "sbndcode/HyperonAnalyzer/LambdaTruthManager/LambdaTruthManager.hh"
#include "TTree.h"
#include "TFile.h"
#include "TInterpreter.h"
#include "TTimeStamp.h"
#include <vector>
#include <limits>
#include <cmath>
#include <map>
#include <sstream>
#include <fstream>
#include <iostream>
#define fXFidCut1 1.5
#define fXFidCut2 190
#define fYFidCut 190
#define fZFidCut1 10
#define fZFidCut2 490
#define fDefaulNeutrinoID 99999
namespace test {
class TPCAnalyzer
;
}
class test::TPCAnalyzer : public art::EDAnalyzer {
public:
explicit TPCAnalyzer
(fhicl::ParameterSet const& p);
// The compiler-generated destructor is fine for non-base
// classes without bare pointers or other resource use.
// Plugins should not be copied or assigned.
TPCAnalyzer(TPCAnalyzer const&) = delete;
TPCAnalyzer(TPCAnalyzer&&) = delete;
TPCAnalyzer & operator=(TPCAnalyzer const&) = delete;
TPCAnalyzer & operator=(TPCAnalyzer &&) = delete;
// Required functions.
void analyze(art::Event const& e) override;
// Selected optional functions.
void beginJob() override;
void endJob() override;
private:
// Declare member data here.
void resetVars();
void resetTrueVars();
void resetSimVars();
void resetWireVars();
void resetRecoVars();
int VertexToDriftTick(double vt, double vx);
bool PointInFV(double x, double y, double z);
void FillReco2(art::Event const& e, std::vector<art::Ptr<recob::PFParticle>> pfpVect, std::map<int, art::Ptr<recob::SpacePoint>> hitToSpacePointMap);
void FillHits(int clusterId, std::vector<art::Ptr<recob::Hit>> hitVect, std::map<int, art::Ptr<recob::SpacePoint>> hitToSpacePointMap);
std::string fMCTruthLabel;
std::string fMCLabel;
std::string fSimEnergyDepositLabel;
std::string fSimEnergyDepositInstanceLabel;
std::string fSimEnergyDepositLabelOut;
std::string fSimEnergyDepositInstanceLabelOut;
std::string fSimChannelLabel;
std::string fRawDigitLabel;
std::string fRecobWireLabel;
std::string fHitLabel;
std::string fReco2Label;
std::string fTrackLabel;
std::string fClusterLabel;
std::string fSpacePointLabel;
std::string fVertexLabel;
std::string fCalorimetryLabel;
std::string fParticleIDLabel;
bool fSaveReco2;
bool fSaveTruth;
bool fSaveSimED;
bool fSaveSimEDOut;
bool fSaveWaveforms;
bool fSaveWires;
bool fSaveHits;
bool fSaveSpacePoints;
bool fSaveVertex;
bool fCreateTPCMap;
bool fApplyFiducialCut;
bool fApplyVertexSCE;
bool fUseSlices;
bool fUseSimChannels;
TTree* fTree;
int fEventID, fRunID, fSubRunID;
//True variables
std::vector<int> fTruePrimariesPDG;
std::vector<double> fTruePrimariesE;
std::vector<std::vector<double>> fTruePrimariesStartP;
double fTrueVx;
double fTrueVy;
double fTrueVz;
double fTrueVt;
int fTrueVU;
int fTrueVV;
int fTrueVC;
int fTrueVTimeTick;
double fTrueVEnergy;
int fIntMode;
int fIntCCNC;
int fIntNProtons;
int fIntNNeutrons;
int fIntNPi0;
int fIntNPip;
int fIntNPim;
int fIntNMuonP;
int fIntNMuonM;
int fIntNElectronP;
int fIntNElectronM;
int fIntNLambda;
bool fIntInFV;
std::vector<double> fLambdaProtonPDir;
std::vector<double> fLambdaPionPDir;
//True SimEnergyDeposits
std::vector<double> fEnDepE;
std::vector<double> fEnDepX;
std::vector<double> fEnDepY;
std::vector<double> fEnDepZ;
std::vector<double> fEnDepU;
std::vector<double> fEnDepV;
std::vector<double> fEnDepC;
std::vector<double> fEnDepT;
std::vector<int> fEnDepPDG;
//True SimEnergyDeposits Out
std::vector<double> fEnDepEOut;
std::vector<double> fEnDepXOut;
std::vector<double> fEnDepYOut;
std::vector<double> fEnDepZOut;
std::vector<double> fEnDepTOut;
//Hit variables
std::vector<int> fHitsView;
std::vector<double> fHitsPeakTime;
std::vector<double> fHitsIntegral;
std::vector<double> fHitsSummedADC;
std::vector<double> fHitsChannel;
std::vector<double> fHitsAmplitude;
std::vector<double> fHitsRMS;
std::vector<double> fHitsStartT;
std::vector<double> fHitsEndT;
std::vector<double> fHitsWidth;
std::vector<double> fHitsChi2;
std::vector<double> fHitsNDF;
std::vector<int> fHitsClusterID;
std::vector<double> fHitsX;
std::vector<double> fHitsY;
std::vector<double> fHitsZ;
// Slice variables
int fNSlices;
//Space Point Variables
std::vector<double> fSpacePointX;
std::vector<double> fSpacePointY;
std::vector<double> fSpacePointZ;
std::vector<double> fSpacePointIntegral;
//Waveforms
std::vector<std::vector<double>> fRawChannelADC;
std::vector<int> fRawChannelID;
std::vector<double> fRawChannelPedestal;
//Recob Wires
unsigned int fNROIs;
std::vector<std::vector<float>> fWireADC;
std::vector<unsigned int> fWireID;
std::vector<int> fWireStampTime;
//Reconstructed vertex
double fRecoVx;
double fRecoVy;
double fRecoVz;
int fRecoVU;
int fRecoVV;
int fRecoVC;
int fRecoVTimeTick;
bool fRecoInFV;
// Reco track start/end points
std::vector<std::vector<double>> fPFTrackStart;
std::vector<std::vector<double>> fPFTrackEnd;
std::vector<double> fPFPDGCode;
int fNAnalyzedEvents;
const geo::GeometryCore* fGeom = art::ServiceHandle<geo::Geometry>()->provider();
unsigned int fNChannels;
unsigned int fReadoutWindow;
double fTriggerOffsetTPC;
double fTickPeriodTPC;
double fDriftVelocity;
double fWirePlanePosition;
// Wire orientation
double fCos60;
double fSin60;
double fWirePitch;
};
void test::TPCAnalyzer::beginJob()
{
// Implementation of optional member function here.
art::ServiceHandle<art::TFileService> tfs;
fTree=tfs->make<TTree>("AnaTPCTree", "Analysis Output Tree");
fTree->Branch("RunID", &fRunID, "RunID/I");
fTree->Branch("SubRunID", &fSubRunID, "SubRunID/I");
fTree->Branch("EventID", &fEventID, "EventID/I");
if(fSaveTruth){
fTree->Branch("TruePrimariesPDG", &fTruePrimariesPDG);
fTree->Branch("TruePrimariesE", &fTruePrimariesE);
fTree->Branch("TruePrimariesStartP", &fTruePrimariesStartP);
fTree->Branch("TrueVx", &fTrueVx, "TrueVx/D");
fTree->Branch("TrueVy", &fTrueVy, "TrueVy/D");
fTree->Branch("TrueVz", &fTrueVz, "TrueVz/D");
fTree->Branch("TrueVt", &fTrueVt, "TrueVt/D");
fTree->Branch("TrueVU", &fTrueVU, "TrueVU/I");
fTree->Branch("TrueVV", &fTrueVV, "TrueVV/I");
fTree->Branch("TrueVC", &fTrueVC, "TrueVC/I");
fTree->Branch("TrueVTimeTick", &fTrueVTimeTick, "TrueVC/I");
fTree->Branch("TrueVEnergy", &fTrueVEnergy, "TrueVEnergy/D");
fTree->Branch("IntMode", &fIntMode, "IntMode/I");
fTree->Branch("IntCCNC", &fIntCCNC, "IntCCMC/I");
fTree->Branch("IntNProtons", &fIntNProtons, "IntNProtons/I");
fTree->Branch("IntNNeutrons", &fIntNNeutrons, "IntNNeutrons/I");
fTree->Branch("IntNPi0", &fIntNPi0, "IntNPi0/I");
fTree->Branch("IntNPip", &fIntNPip, "IntNPip/I");
fTree->Branch("IntNPim", &fIntNPim, "IntNPim/I");
fTree->Branch("IntNMuonP", &fIntNMuonP, "IntNMuonP/I");
fTree->Branch("IntNMuonM", &fIntNMuonM, "IntNMuonM/I");
fTree->Branch("IntNElectronP", &fIntNElectronP, "IntNElectronP/I");
fTree->Branch("IntNElectronM", &fIntNElectronM, "IntNElectronM/I");
fTree->Branch("IntNLambda", &fIntNLambda, "IntNLambda/I");
fTree->Branch("IntInFV", &fIntInFV, "IntInFV/O");
fTree->Branch("LambdaProtonPDir", &fLambdaProtonPDir);
fTree->Branch("LambdaPionPDir", &fLambdaPionPDir);
}
if(fSaveSimED){
fTree->Branch("EnDepE", &fEnDepE);
fTree->Branch("EnDepX", &fEnDepX);
fTree->Branch("EnDepY", &fEnDepY);
fTree->Branch("EnDepZ", &fEnDepZ);
fTree->Branch("EnDepU", &fEnDepU);
fTree->Branch("EnDepV", &fEnDepV);
fTree->Branch("EnDepC", &fEnDepC);
fTree->Branch("EnDepT", &fEnDepT);
fTree->Branch("EnDepPDG", &fEnDepPDG);
}
if(fSaveSimEDOut){
fTree->Branch("EnDepEOut", &fEnDepEOut);
fTree->Branch("EnDepXOut", &fEnDepXOut);
fTree->Branch("EnDepYOut", &fEnDepYOut);
fTree->Branch("EnDepZOut", &fEnDepZOut);
fTree->Branch("EnDepTOut", &fEnDepTOut);
}
if(fSaveWaveforms){
fTree->Branch("RawChannelADC", &fRawChannelADC);
//fTree->Branch("RawChannelID", &fRawChannelID);
//fTree->Branch("RawChannelPedestal", &fRawChannelPedestal);
}
if(fSaveWires){
fTree->Branch("NROIs", &fNROIs);
fTree->Branch("WireID", &fWireID);
fTree->Branch("WireStampTime", &fWireStampTime);
fTree->Branch("WireADC", &fWireADC);
//fTree->Branch("RawChannelID", &fRawChannelID);
//fTree->Branch("RawChannelPedestal", &fRawChannelPedestal);
}
if(fSaveWires){
fTree->Branch("RawChannelADC", &fRawChannelADC);
//fTree->Branch("RawChannelID", &fRawChannelID);
//fTree->Branch("RawChannelPedestal", &fRawChannelPedestal);
}
if(fSaveHits){
fTree->Branch("HitsView", &fHitsView);
fTree->Branch("HitsIntegral", &fHitsIntegral);
fTree->Branch("HitsSummedADC", &fHitsSummedADC);
fTree->Branch("HitsPeakTime", &fHitsPeakTime);
fTree->Branch("HitsChannel", &fHitsChannel);
fTree->Branch("HitsAmplitude", &fHitsAmplitude);
fTree->Branch("HitsRMS", &fHitsRMS);
fTree->Branch("HitsStartT", &fHitsStartT);
fTree->Branch("HitsEndT", &fHitsEndT);
fTree->Branch("HitsWidth", &fHitsWidth);
fTree->Branch("HitsChi2", &fHitsChi2);
fTree->Branch("HitsNDF", &fHitsNDF);
fTree->Branch("HitsClusterID", &fHitsClusterID);
fTree->Branch("HitsX", &fHitsX);
fTree->Branch("HitsY", &fHitsY);
fTree->Branch("HitsZ", &fHitsZ);
}
if(fSaveSpacePoints){
fTree->Branch("SpacePointX", &fSpacePointX);
fTree->Branch("SpacePointY", &fSpacePointY);
fTree->Branch("SpacePointZ", &fSpacePointZ);
fTree->Branch("SpacePointIntegral", &fSpacePointIntegral);
}
if(fSaveVertex){
fTree->Branch("RecoVx", &fRecoVx, "RecoVx/D");
fTree->Branch("RecoVy", &fRecoVy, "RecoVy/D");
fTree->Branch("RecoVz", &fRecoVz, "RecoVz/D");
fTree->Branch("RecoVU", &fRecoVU, "RecoVU/I");
fTree->Branch("RecoVV", &fRecoVV, "RecoVV/I");
fTree->Branch("RecoVC", &fRecoVC, "RecoVC/I");
fTree->Branch("RecoVTimeTick", &fRecoVTimeTick, "RecoVC/I");
fTree->Branch("RecoInFV", &fRecoInFV, "RecoInFV/O");
}
if(fSaveReco2){
fTree->Branch("PFTrackStart", &fPFTrackStart);
fTree->Branch("PFTrackEnd", &fPFTrackEnd);
fTree->Branch("PFPDGCode", &fPFPDGCode);
}
fNAnalyzedEvents=0;
}
void test::TPCAnalyzer::endJob(){
if(fCreateTPCMap){
std::ofstream fileout("TPCMapping.txt");
std::ofstream fileoutXYZ("TPCMappingXYZ.txt");
if(fileout.is_open()){
double xyz_start[3], xyz_end[3];;
for(unsigned int ch=0; ch<fGeom->Nchannels(); ch++){
std::vector<geo::WireID> wireV = fGeom->ChannelToWire(ch);
for(size_t w=0; w<wireV.size(); w++){
fGeom->WireEndPoints(wireV[w], xyz_start, xyz_end);
fileout<<ch<<" "<<wireV[w].Plane<<" "<<wireV[w].TPC<<std::endl;
fileoutXYZ<<ch<<" "<<wireV[w].Plane<<" "<<wireV[w].TPC<<" ";
fileoutXYZ<<xyz_start[0]<<" "<<xyz_start[1]<<" "<<xyz_start[2]<<" ";
fileoutXYZ<<xyz_end[0]<<" "<<xyz_end[1]<<" "<<xyz_end[2]<<std::endl;
std::cout<<ch<<":"<<w<<" ID="<<wireV[w].Wire<<" Plane="<<wireV[w].Plane<<" TPC="<<wireV[w].TPC<<std::endl;
}
}
}
fileout.close();
fileoutXYZ.close();
}
}
DEFINE_ART_MODULE(test::TPCAnalyzer)