116 static std::vector<double> mult_v;
117 static std::vector<std::vector<double> > pespec_v;
118 static std::vector<std::vector<unsigned int> > hitidx_v;
119 double min_time=1.1e20;
120 double max_time=1.1e20;
121 for(
auto const& oph : ophits) {
122 if(max_time > 1.e20 || oph.peak_time > max_time) max_time = oph.peak_time;
123 if(min_time > 1.e20 || oph.peak_time < min_time) min_time = oph.peak_time;
128 std::cout <<
"T span: " << min_time <<
" => " << max_time <<
" ... " << (size_t)((max_time - min_time) /
_time_res) << std::endl;
130 size_t nbins_pesum_v = (size_t)((max_time - min_time) /
_time_res) + 1;
132 if(mult_v.size() < nbins_pesum_v) mult_v.resize(nbins_pesum_v,0);
133 if(pespec_v.size() < nbins_pesum_v) pespec_v.resize(nbins_pesum_v,std::vector<double>(NOpDet));
134 if(hitidx_v.size() < nbins_pesum_v) hitidx_v.resize(nbins_pesum_v,std::vector<unsigned int>());
135 for(
size_t i=0; i<
_pesum_v.size(); ++i) {
139 for(
auto& v : pespec_v[i]) v=0;
143 for(
size_t hitidx = 0; hitidx < ophits.size(); ++hitidx) {
144 auto const& oph = ophits[hitidx];
146 if(
_debug)
std::cout <<
"Ignoring OpChannel " << oph.channel << std::endl;
149 if(
Veto(oph.peak_time)) {
150 if(
_debug)
std::cout <<
"Ignoring hit @ time " << oph.peak_time << std::endl;
153 if(oph.pe <= 0.)
continue;
155 size_t index = (size_t)((oph.peak_time - min_time) /
_time_res);
159 hitidx_v[index].push_back(hitidx);
163 std::map<double,size_t> pesum_idx_map;
164 for(
size_t idx=0; idx<nbins_pesum_v; ++idx) {
167 pesum_idx_map[1./(
_pesum_v[idx])] = idx;
171 std::vector<std::pair<size_t,size_t> > flash_period_v;
172 std::vector<size_t> flash_time_v;
176 flash_period_v.reserve(pesum_idx_map.size());
177 flash_time_v.reserve(pesum_idx_map.size());
179 double sum_baseline = 0;
182 for(
auto const& pe_idx : pesum_idx_map) {
185 auto const& idx = pe_idx.second;
188 if(start_time < precount) start_time = 0;
189 else start_time = idx - precount;
193 size_t integral_ctr = default_integral_ctr;
194 for(
auto const& used_period : flash_period_v) {
195 if( start_time <= used_period.first && (start_time + veto_ctr) > used_period.first ) {
199 if( used_period.first <= start_time && start_time < (used_period.first + veto_ctr) ) {
203 if( used_period.first >= start_time && used_period.first < (start_time + integral_ctr) ) {
205 <<
" (previous flash @ " << used_period.first
206 <<
") ... integral ctr change: " << integral_ctr
207 <<
" => " << used_period.first - start_time << std::endl;
209 integral_ctr = used_period.first -
start_time;
213 <<
" => " << min_time + (used_period.first + used_period.second) *
_time_res
214 <<
" does not interfare with THIS flash @ " << min_time + start_time *
_time_res
215 <<
" => " << min_time + (start_time + integral_ctr) *
_time_res << std::endl;
219 if(
_debug)
std::cout <<
"Skipping a candidate @ " << min_time + start_time *
_time_res <<
" as it is in a veto window!" <<std::endl;
225 for(
size_t i=start_time; i<std::min(nbins_pesum_v,(start_time+integral_ctr)); ++i)
230 if(
_debug)
std::cout <<
"Skipping a candidate @ " << start_time <<
" => " << start_time + integral_ctr
231 <<
" as it got " << pesum
232 <<
" PE which is lower than threshold " << (
_min_pe_flash + sum_baseline) << std::endl;
236 flash_period_v.push_back(std::pair<size_t,size_t>(start_time,integral_ctr));
237 flash_time_v.push_back(idx);
242 for(
size_t flash_idx=0; flash_idx<flash_period_v.size(); ++flash_idx) {
244 auto const& start = flash_period_v[flash_idx].first;
245 auto const& period = flash_period_v[flash_idx].second;
246 auto const& time = flash_time_v[flash_idx];
248 std::vector<double> pe_v(max_ch+1,0);
249 for(
size_t index=start; index<(start+period) && index<pespec_v.size(); ++index) {
251 for(
size_t pmt_index=0; pmt_index<NOpDet; ++pmt_index)
257 for(
size_t opch=0; opch<max_ch; ++opch) {
259 if(_opch_to_index_v[opch]<0)
continue;
263 if(pe_v[opch]<0) pe_v[opch]=0;
267 std::vector<unsigned int> asshit_v;
268 for(
size_t index=start; index<(start+period) && index<pespec_v.size(); ++index) {
269 for(
auto const& idx : hitidx_v[index])
270 asshit_v.push_back(idx);
275 <<
" : " << std::flush;
277 for(
auto const& v : pe_v) {
std::cout << v <<
" "; tmpsum +=v; }
278 std::cout <<
" ... sum = " << tmpsum << std::endl;
281 LiteOpFlash_t flash( min_time + time *
_time_res,
282 period * _time_res / 2.,
284 std::move(asshit_v));
285 res.emplace_back( std::move(flash) );
bool Veto(double t) const
std::vector< pmtana::LiteOpFlash_t > LiteOpFlashArray_t
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production start_time
std::vector< double > _pesum_v
std::vector< int > _index_to_opch_v
std::vector< int > _opch_to_index_v
BEGIN_PROLOG could also be cout