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) {
279 if(_opch_to_index_v[opch]<0)
continue;
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;
301 LiteOpFlash_t flash( min_time + time *
_time_res,
302 period * _time_res / 2.,
305 std::move(asshit_v));
306 res.emplace_back( std::move(flash) );
bool Veto(double t) const
std::vector< lightana::LiteOpFlash_t > LiteOpFlashArray_t
std::vector< int > _opch_to_index_v
std::vector< double > _pesum_v
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production start_time
std::vector< int > _index_to_opch_v
BEGIN_PROLOG could also be cout