forked from DeepLearnPhysics/Supera
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LArSoftSuperaDriver_module.cc
374 lines (337 loc) · 12.8 KB
/
LArSoftSuperaDriver_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
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
////////////////////////////////////////////////////////////////////////
// Class: LArSoftSuperaDriver
// Module Type: analyzer
// File: LArSoftSuperaDriver_module.cc
//
// Generated at Tue May 2 17:36:15 2017 by Kazuhiro Terao using artmod
// from cetpkgsupport v1_11_00.
////////////////////////////////////////////////////////////////////////
#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 "fhiclcpp/ParameterSet.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "nusimdata/SimulationBase/MCTruth.h"
#include "nusimdata/SimulationBase/MCParticle.h"
#include "lardataobj/RecoBase/Hit.h"
#include "lardataobj/RecoBase/Wire.h"
#include "lardataobj/RecoBase/SpacePoint.h"
#include "lardataobj/RawData/OpDetWaveform.h"
#include "lardataobj/MCBase/MCShower.h"
#include "lardataobj/MCBase/MCTrack.h"
#include "lardataobj/Simulation/SimChannel.h"
#include "lardataobj/Simulation/SimEnergyDeposit.h"
#include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
#include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h"
#include "larcore/Geometry/Geometry.h"
#include <TString.h>
#include <TTimeStamp.h>
//#include "LArCVMetaMaker.h"
#include "LArCVSuperaDriver.h"
#include "GenRandom.h"
#include "larcv/core/Base/PSet.h"
#include "CLHEP/Random/RandFlat.h"
#include "TRandom.h"
#include "nurandom/RandomUtils/NuRandomService.h"
class LArSoftSuperaDriver;
class LArSoftSuperaDriver : public art::EDAnalyzer {
public:
explicit LArSoftSuperaDriver(fhicl::ParameterSet const & p);
// The destructor generated by the compiler is fine for classes
// without bare pointers or other resource use.
// Plugins should not be copied or assigned.
LArSoftSuperaDriver(LArSoftSuperaDriver const &) = delete;
LArSoftSuperaDriver(LArSoftSuperaDriver &&) = delete;
LArSoftSuperaDriver & operator = (LArSoftSuperaDriver const &) = delete;
LArSoftSuperaDriver & operator = (LArSoftSuperaDriver &&) = delete;
// Required functions.
void analyze(art::Event const & e) override;
void beginJob() override;
void endJob() override;
private:
// Declare member data here.
larcv::LArCVSuperaDriver _supera;
unsigned int _verbosity;
CLHEP::HepRandomEngine& fFlatEngine;
bool _strictDataLoading;
};
LArSoftSuperaDriver::LArSoftSuperaDriver(fhicl::ParameterSet const & p)
: EDAnalyzer(p)
, fFlatEngine(art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "HepJamesRandom", "Supera"))
// More initializers here.
{
//fEfficiencyEngine(art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "HepJamesRandom", "Efficiencies"))
_verbosity = p.get<unsigned int>("Verbosity",3);
_strictDataLoading = p.get<bool>("StrictDataLoading", true);
// Setup random number generator
supera::GenRandom::get().SetFlatGen(new CLHEP::RandFlat(fFlatEngine,0,1));
std::string supera_cfg;
cet::search_path finder("FHICL_FILE_PATH");
if( !finder.find_file(p.get<std::string>("supera_params"), supera_cfg) )
throw cet::exception("LArSoftSuperaDriver") << "Unable to find supera cfg in " << finder.to_string() << "\n";
_supera.configure(supera_cfg);
_supera.set_verbosity(::larcv::msg::Level_t(_verbosity));
auto process_names = _supera.ProcessNames();
for(auto const& proc_name : process_names) {
std::string param_name = "CSV" + proc_name;
auto constraint_file = p.get<std::string>(param_name.c_str(),"");
if(constraint_file.empty()) continue;
std::string fullpath;
if( !finder.find_file(constraint_file,fullpath) )
throw cet::exception("LArSoftSuperaDriver") << "Unable to find CSV file " << constraint_file << "\n";
_supera.SetCSV(proc_name,fullpath);
}
// Decide on output filename
auto out_fname = p.get<std::string>("out_filename","");
if(p.get<bool>("unique_filename") || out_fname.empty()) {
TString tmp_fname;
if(out_fname.empty())
tmp_fname = "emptyname_" + p.get<std::string>("stream");
else {
tmp_fname = out_fname;
tmp_fname.ReplaceAll(".root","");
tmp_fname += "_" + p.get<std::string>("stream");
}
TTimeStamp ts;
out_fname = Form("%s_%08d_%06d_%06d.root",tmp_fname.Data(),ts.GetDate(),ts.GetTime(), (int)(ts.GetNanoSec()/1.e3));
}
_supera.override_output_file(out_fname);
//art::ServiceHandle<util::LArCVMetaMaker> metamaker;
//metamaker->addJson(out_fname,p.get<std::string>("stream"));
}
void LArSoftSuperaDriver::beginJob()
{
_supera.initialize();
}
void LArSoftSuperaDriver::analyze(art::Event const & e)
{
// FIXME(kvtsang) Temporary solution to access associations
_supera.SetEvent(&e);
//
// set data pointers
//
/*
// hit
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArHit_t)) {
if(label.empty()) continue;
art::Handle<std::vector<recob::Hit> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
throw ::larcv::larbys("Could not locate data!");
}
_supera.SetDataPointer(*data_h,label);
}
*/
// wire
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArWire_t)) {
if(label.empty()) continue;
art::Handle<std::vector<recob::Wire> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
_supera.SetDataPointer(*data_h,label);
}
// opdigit
/*
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArOpDigit_t)) {
if(label.empty()) continue;
art::Handle<std::vector<raw::OpDetWaveform> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
throw ::larcv::larbys("Could not locate data!");
}
_supera.SetDataPointer(*data_h,label);
}
*/
// mctruth
if(_verbosity==0) std::cout << "Checking MCTruth data request" << std::endl;
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArMCTruth_t)) {
if(label.empty()) continue;
art::Handle<std::vector<simb::MCTruth> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
_supera.SetDataPointer(*data_h,label);
}
// mcparticle
if(_verbosity==0) std::cout << "Checking MCParticle data request" << std::endl;
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArMCParticle_t)) {
if(label.empty()) continue;
art::Handle<std::vector<simb::MCParticle> > data_h;
//art::Assns<simb::MCTruth,simb::MCParticle,sim::GeneratedParticleInfo> ass_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
//e.getByLabel(label.substr(0,label.find(" ")),
// label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
// ass_h);
}else{
e.getByLabel(label, data_h);
//e.getByLabel(label, ass_h);
}
if(!data_h.isValid() || data_h->empty()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
/*
std::vector<art::Handle<std::vector<simb::MCTruth>>> mclists;
e.getManyByType(mclists);
//Find tracks associated with hits
art::FindManyP<simb::MCTruth> ass(data_h,e);
for (size_t i = 0; data_h->size(); ++i) {
auto const mct = ass.at(i);
}
*/
_supera.SetDataPointer(*data_h,label);
}
// SimEnergyDeposit
if(_verbosity==0) std::cout << "Checking SimEnergyDeposit data request" << std::endl;
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArSimEnergyDeposit_t)) {
if(_verbosity==0) std::cout << "Requested: " << label << std::endl;
if(label.empty()) continue;
art::Handle<std::vector<sim::SimEnergyDeposit> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
_supera.SetDataPointer(*data_h,label);
}
// mctrack
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArMCTrack_t)) {
if(label.empty()) continue;
art::Handle<std::vector<sim::MCTrack> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
_supera.SetDataPointer(*data_h,label);
}
// mcshower
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArMCShower_t)) {
if(label.empty()) continue;
art::Handle<std::vector<sim::MCShower> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
_supera.SetDataPointer(*data_h,label);
}
// SpacePoint
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArSpacePoint_t)) {
if(label.empty()) continue;
art::Handle<std::vector<recob::SpacePoint> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
_supera.SetDataPointer(*data_h,label);
}
// simch
for(auto const& label : _supera.DataLabels(::supera::LArDataType_t::kLArSimCh_t)) {
if(label.empty()) continue;
art::Handle<std::vector<sim::SimChannel> > data_h;
if(label.find(" ")<label.size()) {
e.getByLabel(label.substr(0,label.find(" ")),
label.substr(label.find(" ")+1,label.size()-label.find(" ")-1),
data_h);
}else{ e.getByLabel(label, data_h); }
if(!data_h.isValid()) {
std::cerr<< "Attempted to load data: " << label << std::endl;
if(_strictDataLoading)
throw ::larcv::larbys("Could not locate data!");
else
return;
}
_supera.SetDataPointer(*data_h,label);
}
/*
// chstatus
auto supera_chstatus = _supera.SuperaChStatusPointer();
if(supera_chstatus) {
// Set database status
auto const* geom = ::lar::providerFrom<geo::Geometry>();
const lariov::ChannelStatusProvider& chanFilt = art::ServiceHandle<lariov::ChannelStatusService>()->GetProvider();
for(size_t i=0; i < geom->Nchannels(); ++i) {
auto const wid = geom->ChannelToWire(i).front();
if (!chanFilt.IsPresent(i)) supera_chstatus->set_chstatus(wid.Plane, wid.Wire, ::larcv::chstatus::kNOTPRESENT);
else supera_chstatus->set_chstatus(wid.Plane, wid.Wire, (short)(chanFilt.Status(i)));
}
}
*/
//
// execute supera
//
_supera.process(e.id().run(),e.id().subRun(),e.id().event());
}
void LArSoftSuperaDriver::endJob()
{
_supera.finalize();
}
DEFINE_ART_MODULE(LArSoftSuperaDriver)