6 #include <unordered_map> 29 , m_fluctuate(fluctuate)
30 , m_calcstrat(calcstrat)
40 const double center_time = depo->time();
48 double eff_nsigma = sigma_time>0?
m_nsigma:0;
49 if (nmin_sigma > eff_nsigma || nmax_sigma < -eff_nsigma) {
64 double nmin_sigma = pitch_desc.
distance(ibins.min());
65 double nmax_sigma = pitch_desc.
distance(ibins.max());
67 double eff_nsigma = sigma_pitch>0?
m_nsigma:0;
68 if (nmin_sigma > eff_nsigma || nmax_sigma < -eff_nsigma) {
87 auto gd = std::make_shared<GaussianDiffusion>(depo, time_desc, pitch_desc);
132 std::map<int,int> map_redimp_vec;
133 for (
size_t i =0; i!= vec_impact.size(); i++){
134 map_redimp_vec[vec_impact[i]] =
int(i);
139 std::map<int, int> map_imp_ch;
141 std::map<int, int> map_imp_redimp;
144 for (
int wireind=0;wireind!=rb.nbins();wireind++){
147 for (
int imp_no = imps_range.first; imp_no != imps_range.second; imp_no ++){
148 map_imp_ch[imp_no] = wireind;
149 map_imp_redimp[imp_no] = imp_no - wire_imp_no;
157 int max_imp = ib.nbins();
166 const auto patch = diff->patch();
167 const auto qweight = diff->weights();
169 const int poffset_bin = diff->poffset_bin();
170 const int toffset_bin = diff->toffset_bin();
172 const int np =
patch.rows();
173 const int nt =
patch.cols();
175 for (
int pbin = 0; pbin != np; pbin++){
176 int abs_pbin = pbin + poffset_bin;
177 if (abs_pbin < min_imp || abs_pbin >= max_imp)
continue;
178 double weight = qweight[pbin];
180 for (
int tbin = 0; tbin!= nt; tbin++){
181 int abs_tbin = tbin + toffset_bin;
182 double charge =
patch(pbin, tbin);
186 vec_spmatrix.at(map_redimp_vec[map_imp_redimp[abs_pbin] ])->coeffRef(abs_tbin,map_imp_ch[abs_pbin]) += charge *
weight;
187 vec_spmatrix.at(map_redimp_vec[map_imp_redimp[abs_pbin]+1])->coeffRef(abs_tbin,map_imp_ch[abs_pbin]) += charge*(1-
weight);
210 diff->clear_sampling();
214 for (
auto it = vec_spmatrix.begin(); it!=vec_spmatrix.end(); it++){
215 (*it)->makeCompressed();
228 std::map<int,int> map_redimp_vec;
229 std::vector<std::unordered_map<long int, int> > vec_map_pair_pos;
230 for (
size_t i =0; i!= vec_impact.size(); i++){
231 map_redimp_vec[vec_impact[i]] =
int(i);
232 std::unordered_map<long int, int> map_pair_pos;
233 vec_map_pair_pos.push_back(map_pair_pos);
238 std::map<int, int> map_imp_ch;
240 std::map<int, int> map_imp_redimp;
244 for (
int wireind=0;wireind!=rb.nbins();wireind++){
247 for (
int imp_no = imps_range.first; imp_no != imps_range.second; imp_no ++){
248 map_imp_ch[imp_no] = wireind;
249 map_imp_redimp[imp_no] = imp_no - wire_imp_no;
263 int max_imp = ib.nbins();
282 const auto patch = diff->patch();
283 const auto qweight = diff->weights();
285 const int poffset_bin = diff->poffset_bin();
286 const int toffset_bin = diff->toffset_bin();
288 const int np =
patch.rows();
289 const int nt =
patch.cols();
293 for (
int pbin = 0; pbin != np; pbin++){
294 int abs_pbin = pbin + poffset_bin;
295 if (abs_pbin < min_imp || abs_pbin >= max_imp)
continue;
296 double weight = qweight[pbin];
297 auto const channel = map_imp_ch[abs_pbin];
298 auto const redimp = map_imp_redimp[abs_pbin];
299 auto const array_num_redimp = map_redimp_vec[redimp];
300 auto const next_array_num_redimp = map_redimp_vec[redimp+1];
302 auto& map_pair_pos = vec_map_pair_pos.at(array_num_redimp);
303 auto& next_map_pair_pos = vec_map_pair_pos.at(next_array_num_redimp);
305 auto& vec_charge = vec_vec_charge.at(array_num_redimp);
306 auto& next_vec_charge = vec_vec_charge.at(next_array_num_redimp);
308 for (
int tbin = 0; tbin!= nt; tbin++){
309 int abs_tbin = tbin + toffset_bin;
310 double charge =
patch(pbin, tbin);
324 long int index1 =
channel*100000 + abs_tbin;
325 auto it = map_pair_pos.find(index1);
326 if (it == map_pair_pos.end()){
327 map_pair_pos[index1] = vec_charge.size();
328 vec_charge.emplace_back(
channel, abs_tbin, charge*weight);
330 std::get<2>(vec_charge.at(it->second)) += charge * weight;
333 auto it1 = next_map_pair_pos.find(index1);
334 if (it1 == next_map_pair_pos.end()){
335 next_map_pair_pos[index1] = next_vec_charge.size();
336 next_vec_charge.emplace_back(
channel, abs_tbin, charge*(1-weight));
338 std::get<2>(next_vec_charge.at(it1->second)) += charge*(1-weight);
359 if (counter % 5000==0){
370 for (
auto it = vec_map_pair_pos.begin(); it != vec_map_pair_pos.end(); it++){
376 diff->clear_sampling();
410 std::pair<double,double>
gausdesc_range(
const std::vector<Gen::GausDesc> gds,
double nsigma)
413 double vmin=0, vmax=0;
414 for (
auto gd : gds) {
417 const double lvmin = gd.center - gd.sigma*nsigma;
418 const double lvmax = gd.center + gd.sigma*nsigma;
427 return std::make_pair(vmin,vmax);
432 std::vector<Gen::GausDesc> gds;
434 gds.push_back(diff->pitch_desc());
443 return std::make_pair(
std::max(ibins.bin(
mm.first), 0),
444 std::min(ibins.bin(
mm.second)+1, ibins.nbins()));
449 std::vector<Gen::GausDesc> gds;
451 gds.push_back(diff->time_desc());
std::shared_ptr< const IDepo > pointer
double distance(double x)
Return the distance in number of sigma that x is from the center.
const Binning & region_binning() const
double distance(const Point &pt, int axis=2) const
Binning tbins(nticks, t0, t0+readout_time)
const Binning & impact_binning() const
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
int bin(double val) const
std::shared_ptr< Interface > pointer
static int max(int a, int b)
int wire_impact(int wireind) const
Return the impact position index coincident with the wire index.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Pimpos pimpos(nwires, min_wire_pitch, max_wire_pitch)
std::pair< int, int > wire_impacts(int wireind) const