1 #ifndef SIMPLEFLASHALGO_CXX
2 #define SIMPLEFLASHALGO_CXX
17 _debug = p.get<
bool>(
"DebugMode",
false);
25 _time_res = p.get<
double>(
"TimeResolution",0.03);
29 std::cerr <<
"Integral time cannot exceed veto time!" << std::endl;
30 throw std::exception();
32 auto const range_start_v = p.get<std::vector<double> >(
"HitVetoRangeStart");
33 auto const range_end_v = p.get<std::vector<double> >(
"HitVetoRangeEnd");
34 if(range_start_v.size() != range_end_v.size()) {
35 std::cerr <<
"OpHit veto range start and end config value array have different length!" << std::endl;
36 throw std::exception();
38 for(
size_t i=0; i<range_start_v.size(); ++i) {
39 if(range_start_v[i] >= range_end_v[i]) {
40 std::cerr <<
"OpHit veto range element " << i
41 <<
" have start time @ " << range_start_v[i]
42 <<
" being later than end time @ " << range_end_v[i]
44 throw std::exception();
52 int cryostat = p.get<
int>(
"Cryostat",-1);
58 auto opch_range = p.get<std::vector<int> >(
"OpChannelRange");
59 if(opch_range.size()!=2) {
60 std::cerr <<
"OpChannelRange must be a vector of length two!" << std::endl;
61 throw std::exception();
62 }
else if(opch_range[0] > opch_range[1]) {
63 std::cerr <<
"OpChannelRange 0th element (" << opch_range[0]
64 <<
") must be larger than the 1st element (" << opch_range[1]
66 throw std::exception();
69 for(
int i=opch_range[0]; i<=opch_range[1]; ++i)
74 std::set<size_t> duplicate;
77 if(duplicate.find(ch) != duplicate.end()) {
78 std::cerr <<
"Channel number " << ch <<
" is duplicated!" << std::endl;
79 throw std::exception();
87 std::cerr <<
"Length of OpChannel array parameter is 0..." << std::endl;
88 throw std::exception();
103 return (t >= (*iter).second);
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) {
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;
282 period * _time_res / 2.,
284 std::move(asshit_v));
285 res.emplace_back( std::move(flash) );
std::vector< pmtana::LiteOpHit_t > LiteOpHitArray_t
A concrete factory class for pmtana::SimpleFlashAlgo.
BEGIN_PROLOG could also be cerr
LiteOpFlashArray_t RecoFlash(const LiteOpHitArray_t ophits)
void Configure(const Config_t &p)
bool Veto(double t) const
std::vector< size_t > ListOpChannels(int cryostat)
fhicl::ParameterSet Config_t
std::map< double, double > _flash_veto_range_m
static SimpleFlashAlgoFactory __SimpleFlashAlgoFactoryStaticObject__
virtual ~SimpleFlashAlgo()
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
SimpleFlashAlgo(const std::string name)
std::vector< int > _index_to_opch_v
std::vector< int > _opch_to_index_v
BEGIN_PROLOG could also be cout