1 #ifndef SIMPLEFLASHALGO_CXX
2 #define SIMPLEFLASHALGO_CXX
19 _debug = p.get<
bool>(
"DebugMode",
false);
26 _time_res = p.get<
double>(
"TimeResolution",0.03);
27 _tpc = p.get<
int>(
"TPC");
32 std::cerr <<
"Integral time cannot exceed veto time!" << std::endl;
33 throw std::exception();
35 auto const range_start_v = p.get<std::vector<double> >(
"HitVetoRangeStart");
36 auto const range_end_v = p.get<std::vector<double> >(
"HitVetoRangeEnd");
37 if(range_start_v.size() != range_end_v.size()) {
38 std::cerr <<
"OpHit veto range start and end config value array have different length!" << std::endl;
39 throw std::exception();
41 for(
size_t i=0; i<range_start_v.size(); ++i) {
42 if(range_start_v[i] >= range_end_v[i]) {
43 std::cerr <<
"OpHit veto range element " << i
44 <<
" have start time @ " << range_start_v[i]
45 <<
" being later than end time @ " << range_end_v[i]
47 throw std::exception();
53 std::vector<std::string> pd_to_use;
54 pd_to_use = p.get<std::vector<std::string>>(
"PD", pd_to_use);
64 for(
auto const& v : opch_v) {
65 auto iter = std::find(opch_to_use.begin(), opch_to_use.end(), v);
66 if (iter != opch_to_use.end()) {
72 auto opch_range = p.get<std::vector<int> >(
"OpChannelRange");
73 if(opch_range.size()!=2) {
74 std::cerr <<
"OpChannelRange must be a vector of length two!" << std::endl;
75 throw std::exception();
76 }
else if(opch_range[0] > opch_range[1]) {
77 std::cerr <<
"OpChannelRange 0th element (" << opch_range[0]
78 <<
") must be larger than the 1st element (" << opch_range[1]
80 throw std::exception();
83 for(
int i=opch_range[0]; i<=opch_range[1]; ++i) {
84 auto iter = std::find(opch_to_use.begin(), opch_to_use.end(), i);
85 if (iter != opch_to_use.end()) {
92 std::set<size_t> duplicate;
95 if(duplicate.find(ch) != duplicate.end()) {
96 std::cerr <<
"Channel number " << ch <<
" is duplicated!" << std::endl;
97 throw std::exception();
101 duplicate.insert(ch);
105 std::cerr <<
"Length of OpChannel array parameter is 0..." << std::endl;
106 throw std::exception();
122 return (t >= (*iter).second);
135 static std::vector<double> mult_v;
136 static std::vector<std::vector<double> > pespec_v;
137 static std::vector<std::vector<unsigned int> > hitidx_v;
138 double min_time=1.1e20;
139 double max_time=1.1e20;
140 for(
auto const& oph : ophits) {
141 if(max_time > 1.e20 || oph.peak_time > max_time) max_time = oph.peak_time;
142 if(min_time > 1.e20 || oph.peak_time < min_time) min_time = oph.peak_time;
147 std::cout <<
"T span: " << min_time <<
" => " << max_time <<
" ... " << (size_t)((max_time - min_time) /
_time_res) << std::endl;
149 size_t nbins_pesum_v = (size_t)((max_time - min_time) /
_time_res) + 1;
151 if(mult_v.size() < nbins_pesum_v) mult_v.resize(nbins_pesum_v,0);
152 if(pespec_v.size() < nbins_pesum_v) pespec_v.resize(nbins_pesum_v,std::vector<double>(NOpDet));
153 if(hitidx_v.size() < nbins_pesum_v) hitidx_v.resize(nbins_pesum_v,std::vector<unsigned int>());
154 for(
size_t i=0; i<
_pesum_v.size(); ++i) {
158 for(
auto& v : pespec_v[i]) v=0;
162 for(
size_t hitidx = 0; hitidx < ophits.size(); ++hitidx) {
163 auto const& oph = ophits[hitidx];
165 if(
_debug)
std::cout <<
"Ignoring OpChannel " << oph.channel << std::endl;
168 if(
Veto(oph.peak_time)) {
169 if(
_debug)
std::cout <<
"Ignoring hit @ time " << oph.peak_time << std::endl;
172 size_t index = (size_t)((oph.peak_time - min_time) /
_time_res);
177 hitidx_v[index].push_back(hitidx);
181 std::map<double,size_t> pesum_idx_map;
182 for(
size_t idx=0; idx<nbins_pesum_v; ++idx) {
187 pesum_idx_map[1./(
_pesum_v[idx])] = idx;
191 std::vector<std::pair<size_t,size_t> > flash_period_v;
192 std::vector<size_t> flash_time_v;
196 flash_period_v.reserve(pesum_idx_map.size());
197 flash_time_v.reserve(pesum_idx_map.size());
199 double sum_baseline = 0;
202 for(
auto const& pe_idx : pesum_idx_map) {
205 auto const& idx = pe_idx.second;
208 if(start_time < precount) start_time = 0;
209 else start_time = idx - precount;
213 size_t integral_ctr = default_integral_ctr;
214 for(
auto const& used_period : flash_period_v) {
215 if( start_time <= used_period.first && (start_time + veto_ctr) > used_period.first ) {
219 if( used_period.first <= start_time && start_time < (used_period.first + veto_ctr) ) {
223 if( used_period.first >= start_time && used_period.first < (start_time + integral_ctr) ) {
225 <<
" (previous flash @ " << used_period.first
226 <<
") ... integral ctr change: " << integral_ctr
227 <<
" => " << used_period.first - start_time << std::endl;
229 integral_ctr = used_period.first -
start_time;
233 <<
" => " << min_time + (used_period.first + used_period.second) *
_time_res
234 <<
" does not interfare with THIS flash @ " << min_time + start_time *
_time_res
235 <<
" => " << min_time + (start_time + integral_ctr) *
_time_res << std::endl;
239 if(
_debug)
std::cout <<
"Skipping a candidate @ " << min_time + start_time *
_time_res <<
" as it is in a veto window!" <<std::endl;
245 for(
size_t i=start_time; i<std::min(nbins_pesum_v,(start_time+integral_ctr)); ++i)
250 if(
_debug)
std::cout <<
"Skipping a candidate @ " << start_time <<
" => " << start_time + integral_ctr
251 <<
" as it got " << pesum
252 <<
" PE which is lower than threshold " << (
_min_pe_flash + sum_baseline) << std::endl;
256 flash_period_v.push_back(std::pair<size_t,size_t>(start_time,integral_ctr));
257 flash_time_v.push_back(idx);
262 for(
size_t flash_idx=0; flash_idx<flash_period_v.size(); ++flash_idx) {
264 auto const& start = flash_period_v[flash_idx].first;
265 auto const& period = flash_period_v[flash_idx].second;
266 auto const& time = flash_time_v[flash_idx];
268 std::vector<double> pe_v(max_ch+1,0);
269 for(
size_t index=start; index<(start+period) && index<pespec_v.size(); ++index) {
271 for(
size_t pmt_index=0; pmt_index<NOpDet; ++pmt_index)
277 for(
size_t opch=0; opch<max_ch; ++opch) {
283 if(pe_v[opch]<0) pe_v[opch]=0;
287 std::vector<unsigned int> asshit_v;
288 for(
size_t index=start; index<(start+period) && index<pespec_v.size(); ++index) {
289 for(
auto const& idx : hitidx_v[index])
290 asshit_v.push_back(idx);
295 <<
" : " << std::flush;
297 for(
auto const& v : pe_v) {
std::cout << v <<
" "; tmpsum +=v; }
298 std::cout <<
" ... sum = " << tmpsum << std::endl;
302 period * _time_res / 2.,
305 std::move(asshit_v));
306 res.emplace_back( std::move(flash) );
bool Veto(double t) const
static SimpleFlashAlgoFactory __SimpleFlashAlgoFactoryStaticObject__
BEGIN_PROLOG could also be cerr
SimpleFlashAlgo(const std::string name)
std::vector< int > PDNamesToList(std::vector< std::string > pd_names)
LiteOpFlashArray_t RecoFlash(const LiteOpHitArray_t ophits)
std::vector< lightana::LiteOpFlash_t > LiteOpFlashArray_t
std::vector< lightana::LiteOpHit_t > LiteOpHitArray_t
A concrete factory class for lightana::SimpleFlashAlgo.
std::vector< int > _opch_to_index_v
std::vector< size_t > ListOpChannelsByTPC(int tpc)
std::vector< double > _pesum_v
virtual ~SimpleFlashAlgo()
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production start_time
std::vector< int > _index_to_opch_v
std::map< double, double > _flash_veto_range_m
BEGIN_PROLOG could also be cout
void Configure(const Config_t &p)
fhicl::ParameterSet Config_t