forked from kvtsang/Supera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLArSoftSuperaDriver_module.cc
284 lines (247 loc) · 9.83 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
////////////////////////////////////////////////////////////////////////
// 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 "lardataobj/RecoBase/Hit.h"
#include "lardataobj/RecoBase/Wire.h"
#include "lardataobj/RawData/OpDetWaveform.h"
#include "lardataobj/MCBase/MCShower.h"
#include "lardataobj/MCBase/MCTrack.h"
#include "lardataobj/Simulation/SimChannel.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 "larcv/core/Base/PSet.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;
};
LArSoftSuperaDriver::LArSoftSuperaDriver(fhicl::ParameterSet const & p)
:
EDAnalyzer(p) // ,
// More initializers here.
{
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);
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)
{
//
// 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;
throw ::larcv::larbys("Could not locate data!");
}
_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
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;
throw ::larcv::larbys("Could not locate data!");
}
_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;
throw ::larcv::larbys("Could not locate data!");
}
_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;
throw ::larcv::larbys("Could not locate data!");
}
_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;
throw ::larcv::larbys("Could not locate data!");
}
_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)));
}
/*
std::vector<bool> filled_ch( ::larcv::supera::Nchannels(), false );
// If specified check RawDigit pedestal value: if negative this channel is not used by wire (set status=>-2)
if(!_core.producer_digit().empty()) {
art::Handle<std::vector<raw::RawDigit> > digit_h;
e.getByLabel(_core.producer_digit(),digit_h);
for(auto const& digit : *digit_h) {
auto const ch = digit.Channel();
if(ch >= filled_ch.size()) throw ::larcv::larbys("Found RawDigit > possible channel number!");
if(digit.GetPedestal()<0.) {
_core.set_chstatus(ch,::larcv::chstatus::kNEGATIVEPEDESTAL);
filled_ch[ch] = true;
}
}
}
// Set database status
const lariov::ChannelStatusProvider& chanFilt = art::ServiceHandle<lariov::ChannelStatusService>()->GetProvider();
for(size_t i=0; i < ::larcv::supera::Nchannels(); ++i) {
if ( filled_ch[i] ) continue;
if (!chanFilt.IsPresent(i)) _core.set_chstatus(i,::larcv::chstatus::kNOTPRESENT);
else _core.set_chstatus(i,(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)