-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCScraper_module.cc
More file actions
378 lines (295 loc) · 11.7 KB
/
Copy pathMCScraper_module.cc
File metadata and controls
378 lines (295 loc) · 11.7 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
////////////////////////////////////////////////////////////////////////
// Class: MCScraper
// Plugin Type: analyzer (Unknown Unknown)
// File: MCScraper_module.cc
//
// Generated at Tue Jan 23 01:17:55 2024 by Alexander Antonakis using cetskelgen
// from version .
////////////////////////////////////////////////////////////////////////
#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 "canvas/Persistency/Common/Ptr.h"
#include "art/Framework/Principal/Run.h"
#include "art/Framework/Principal/SubRun.h"
#include "canvas/Utilities/InputTag.h"
#include "fhiclcpp/ParameterSet.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "canvas/Persistency/Common/FindManyP.h"
// Additional LArSoft Includes
#include "lardataobj/RecoBase/PFParticle.h"
#include "lardataobj/RecoBase/Track.h"
#include "lardataobj/AnalysisBase/Calorimetry.h"
#include "larcoreobj/SummaryData/POTSummary.h"
#include "larsim/MCCheater/BackTrackerService.h"
#include "larsim/MCCheater/ParticleInventoryService.h"
#include "larsim/Utils/TruthMatchUtils.h"
#include "lardata/DetectorInfoServices/DetectorClocksService.h"
#include "lardataobj/RecoBase/Track.h"
#include "lardataobj/RecoBase/Shower.h"
#include "lardataobj/RecoBase/PFParticle.h"
#include "lardataobj/RecoBase/Cluster.h"
#include "lardataobj/RecoBase/Hit.h"
#include "lardataobj/RecoBase/EndPoint2D.h"
#include "lardataobj/RecoBase/Vertex.h"
#include "lardataobj/RecoBase/Slice.h"
#include "lardataobj/RecoBase/PFParticleMetadata.h"
#include "larcoreobj/SimpleTypesAndConstants/geo_types.h"
#include "lardataobj/AnalysisBase/CosmicTag.h"
#include "lardataobj/AnalysisBase/FlashMatch.h"
#include "lardataobj/RecoBase/MCSFitResult.h"
#include "lardata/DetectorInfoServices/DetectorClocksService.h"
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
#include "larreco/RecoAlg/TrackMomentumCalculator.h"
#include "larreco/RecoAlg/TrajectoryMCSFitter.h"
#include "larreco/Calorimetry/CalorimetryAlg.h"
#include "lardataobj/RecoBase/MCSFitResult.h"
#include "larreco/RecoAlg/PMAlg/PmaTrack3D.h"
#include "larpandora/LArPandoraInterface/LArPandoraHelper.h"
#include "lardataobj/RecoBase/PFParticleMetadata.h"
#include "sbndcode/RecoUtils/RecoUtils.h"
#include "nusimdata/SimulationBase/GTruth.h"
#include "sbnobj/Common/Reco/OpT0FinderResult.h"
#include "sbnobj/Common/Reco/CRUMBSResult.h"
//#include "sbnobj/Common/Reco/CNNScore.h"
#include "sbnobj/Common/Reco/MVAPID.h"
#include "lardataobj/AnalysisBase/T0.h"
#include <cstring> // std::memcpy()
#include <vector>
#include <map>
#include <utility>
#include <iterator> // std::begin(), std::end()
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <functional> // std::mem_fn()
#include <typeinfo>
#include <cmath>
#include "TTimeStamp.h"
#include "art_root_io/TFileService.h"
#include "TH1F.h"
#include "TNtuple.h"
#include "TTree.h"
#include <algorithm>
#include <cassert>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <bitset>
#include "lardataobj/AnalysisBase/T0.h"
#include "larcoreobj/SummaryData/POTSummary.h"
// includes inspired from uboone code
#include "TDatabasePDG.h"
#include "TParticlePDG.h"
// Custom Classes
#include "MCUtils/TruthMatcher.h"
#include "MCUtils/GeoHelper.h"
#include "MCUtils/MCNeutrinoInfo.h"
#include "MCUtils/MCParticleInfo.h"
#include "MCUtils/RecoShowerInfo.h"
#include "MCUtils/RecoTrackInfo.h"
#include "MCUtils/PFParticleInfo.h"
#include "MCUtils/SliceInfo.h"
#include "MCUtils/CrumbsInfo.h"
namespace analysis {
class MCScraper;
/// information from the subrun
struct SubRunData_t {
SubRunData_t() { Clear(); }
void Clear() { pot = -99999.; }
Double_t pot; //protons on target
Double_t goodpot; // good pots
}; // struct SubRunData_t
}
class analysis::MCScraper : public art::EDAnalyzer {
public:
explicit MCScraper(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.
MCScraper(MCScraper const&) = delete;
MCScraper(MCScraper&&) = delete;
MCScraper& operator=(MCScraper const&) = delete;
MCScraper& operator=(MCScraper&&) = delete;
// Required functions.
void analyze(art::Event const& e) override;
void beginSubRun(const art::SubRun& sr);
// Selected optional functions.
void beginJob() override;
void endJob() override;
private:
//art::InputTag potSummaryTag_;
// Declare member data here.
// Create a SubRun TTree
TTree *fSubRunTree;
// Create an output TTree
TTree *fTree;
SubRunData_t SubRunData;
Double_t totPOT = 0.;
Double_t totGoodPOT = 0.;
TTree *fpfpTree;
TTree *fSliceTree;
TTree *fShwTree;
TTree *fTrkTree;
TTree *fnuTree;
TTree *fnuPartTree;
TTree *fCrumbsTree;
PFParticleInfo pfpInfo;
SliceInfo sliceInfo;
RecoShowerInfo recoShwInfo; // custom object to handle reco showers
RecoTrackInfo recoTrkInfo;
MCNeutrinoInfo mcNuInfo; // custom object to handle our favorite particle -> nu
MCParticleInfo mcNuPartInfo;
CrumbsInfo crumbsInfo;
// Tree variables
unsigned int fEventID;
unsigned int fRun;
unsigned int fSubRun;
double fEventTime;
// Define input labels --> producers
const std::string fPFParticleLabel; // Pandora for instance
const std::string fTrackLabel;
const std::string fShowerLabel;
const std::string fCalorimetryLabel;
const std::string fPOTModuleLabel;
const std::string fVertexModuleLabel;
const std::string fGenieGenLabel;
const std::string fHitModuleLabel;
const std::string fCosmicTaggerLabel;
const std::string fOpT0FinderLabel;
const std::string fCrumbsResultLabel;
};
analysis::MCScraper::MCScraper(fhicl::ParameterSet const& p)
: EDAnalyzer{p},
fPFParticleLabel(p.get<std::string>("PFParticleLabel")), // Put all of the producer labels for DataProducts here
fTrackLabel(p.get<std::string>("TrackLabel")),
fShowerLabel(p.get<std::string>("ShowerLabel")),
fCalorimetryLabel(p.get<std::string>("CalorimetryLabel")),
fPOTModuleLabel(p.get<std::string>("POTModuleLabel")),
fVertexModuleLabel(p.get<std::string>("VertexModuleLabel")),
fGenieGenLabel(p.get<std::string>("GenieGenLabel")),
fHitModuleLabel(p.get<std::string>("HitModuleLabel")),
fCosmicTaggerLabel(p.get<std::string>("CosmicTaggerLabel")),
fOpT0FinderLabel(p.get<std::string>("OpT0FinderLabel")),
fCrumbsResultLabel(p.get<std::string>("CrumbsResultLabel"))
// More initializers here.
{
// Call appropriate consumes<>() for any products to be retrieved by this module.
}
void analysis::MCScraper::beginSubRun(const art::SubRun& sr)
{
std::cout << "In the beginSubRun Function" << std::endl;
art::Handle< sumdata::POTSummary > potListHandle;
//sr.getByLabel(fPOTModuleLabel,potListHandle);
if(sr.getByLabel(fPOTModuleLabel,potListHandle)) {
SubRunData.pot=potListHandle->totpot;
SubRunData.goodpot=potListHandle->totgoodpot;
totPOT += potListHandle->totpot;
totGoodPOT += potListHandle->totgoodpot;
std::cout << "POT in SubRun " << potListHandle->totpot << std::endl;
std::cout << "Good POT in SubRun " << potListHandle->totgoodpot << std::endl;
}
else {
SubRunData.pot=0.;
}
} // End of beginSubRun function
void analysis::MCScraper::analyze(art::Event const& e)
{
// Grab the LArSoft Event ID for the current event
fEventID = e.id().event();
std::cout << "Processing Event: " << fEventID << std::endl;
fRun = e.run();
fSubRun = e.subRun();
std::cout << "Processing SubRun " << fSubRun << std::endl;
art::Timestamp ts = e.time();
TTimeStamp tts(ts.timeHigh(), ts.timeLow());
fEventTime = tts.AsDouble();
//copied from MergeDataPaddles.cxx
// art::Handle< raw::BeamInfo > beam;
// if (evt.getByLabel("beam",beam)){
// fData->beamtime = (double)beam->get_t_ms();
// fData->beamtime/=1000.; //in second
// }
//
art::ServiceHandle<cheat::ParticleInventoryService> particleInventoryService;
auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
art::Handle<std::vector<anab::T0>> T0Handle;
std::vector<art::Ptr<anab::T0>> T0Vec;
if (e.getByLabel(fPFParticleLabel, T0Handle))
art::fill_ptr_vector(T0Vec, T0Handle);
// Load the PFParticles from Pandora
art::Handle<std::vector<recob::PFParticle>> pfpHandle;
std::vector<art::Ptr<recob::PFParticle>> pfpVec;
if (e.getByLabel(fPFParticleLabel, pfpHandle))
art::fill_ptr_vector(pfpVec, pfpHandle);
// Check if there are any reconstructed particles in this event
if (pfpVec.empty())
return;
// Custom class functions
pfpInfo.clearPFParticleData();
pfpInfo.fillPFParticleTree(fpfpTree, e, fPFParticleLabel, pfpHandle, fVertexModuleLabel, fOpT0FinderLabel);
// Not Efficient, but convenient
sliceInfo.clearSliceData();
sliceInfo.fillSliceTree(fSliceTree, e, fPFParticleLabel, pfpHandle, fVertexModuleLabel, fOpT0FinderLabel);
// custom class function
recoShwInfo.clearRecoShowerData();
// Make a map between showers and PFPs
recoShwInfo.makeShwPFPMap(e, fShowerLabel, pfpHandle);
// Fill the reco shower tree
recoShwInfo.fillRecoShowerTree(fShwTree, e, fShowerLabel, fPFParticleLabel);
recoTrkInfo.clearRecoTrackData();
recoTrkInfo.makeTrkPFPMap(e, fTrackLabel, pfpHandle);
recoTrkInfo.fillRecoTrackTree(fTrkTree, e, fTrackLabel, fPFParticleLabel, fCalorimetryLabel, fCosmicTaggerLabel);
mcNuInfo.clearMCNeutrinoData();
mcNuInfo.fillMCNeutrinoTree(fnuTree, e, fGenieGenLabel, fHitModuleLabel, fPFParticleLabel, clockData);
mcNuPartInfo.clearMCParticleData();
mcNuPartInfo.fillMCParticleTree(fnuPartTree, e, fGenieGenLabel);
crumbsInfo.clearCrumbsData();
crumbsInfo.fillCrumbsTree(fCrumbsTree, e, fPFParticleLabel, fCrumbsResultLabel);
fTree->Fill();
} // end of analyze event
void analysis::MCScraper::beginJob()
{
// Implementation of optional member function here.
std::cout << "/-------- Begin Job Step -------- /" << std::endl;
std::cout << std::endl;
std::cout << "Clearing the SubRun Info at the Begin Job Step ???" << std::endl;
SubRunData.Clear();
art::ServiceHandle<art::TFileService> tfs;
fSubRunTree = tfs->make<TTree>("subrun_ttree", "subrun_ttree");
fSubRunTree->Branch("totPOT", &totPOT);
fSubRunTree->Branch("totGoodPOT", &totGoodPOT);
fpfpTree = tfs->make<TTree>("pfp_ttree", "pfp_ttree");
pfpInfo.setPFParticleAddresses(fpfpTree, fPFParticleLabel);
fSliceTree = tfs->make<TTree>("slice_ttree", "slice_ttree");
sliceInfo.setSliceAddresses(fSliceTree, fPFParticleLabel);
fShwTree = tfs->make<TTree>("reco_shower_ttree", "reco_shower_ttree");
recoShwInfo.setRecoShowerAddresses(fShwTree, fShowerLabel);
fTrkTree = tfs->make<TTree>("reco_track_ttree", "reco_track_ttree");
recoTrkInfo.setRecoTrackAddresses(fTrkTree, fTrackLabel);
fnuTree = tfs->make<TTree>("mc_nu_ttree", "mc_nu_ttree");
mcNuInfo.setMCNeutrinoAddresses(fnuTree);
fnuPartTree = tfs->make<TTree>("mc_nu_particle_ttree", "mc_nu_particle_ttree");
mcNuPartInfo.setMCParticleAddresses(fnuPartTree);
fCrumbsTree = tfs->make<TTree>("crumbs_ttree", "crumbs_ttree");
crumbsInfo.setCrumbsAddresses(fCrumbsTree);
fTree = tfs->make<TTree>("tree", "output ttree");
fTree->Branch("eventID", &fEventID);
fTree->Branch("Run", &fRun);
fTree->Branch("SubRun", &fSubRun);
fTree->Branch("EventTime", &fEventTime);
}
void analysis::MCScraper::endJob()
{
// Implementation of optional member function here.
// Fill the total POT Info at the end
fSubRunTree->Fill();
}
DEFINE_ART_MODULE(analysis::MCScraper)