36 std::vector<double>&
values,
59 std::vector<double>& dEdxVec);
61 std::vector<double>
MakeSeed(std::vector<double>& dEdxVec);
69 std::vector<double>& dEdxVec,
73 double& old_posteior);
110 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could not find the prior file";
115 TFile fin(fname.c_str(),
"READ");
117 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could read the prior file. Stopping";
123 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could not read the electron hist";
125 photonpriorHist =
dynamic_cast<TH1F*
>(fin.Get(photon_histoname.c_str()));
127 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could not read the photon hist ";
131 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Histrogram bins do not match";
156 <<
"Start position not set, returning " <<
std::endl;
160 std::map<int, std::vector<double>> dEdx_plane_final;
161 std::map<int, std::vector<double>> dEdx_vec_planes;
165 for (
auto const& dEdx_vec_plane : dEdx_vec_planes) {
168 if (dEdx_vec_plane.second.size() < 1) {
169 dEdx_plane_final[dEdx_vec_plane.first] = {};
173 std::vector<double> dEdx_vec = dEdx_vec_plane.second;
175 double electronprob_eprior = 0;
176 double photonprob_eprior = 0;
178 double electronprob_pprior = 0;
179 double photonprob_pprior = 0;
181 std::vector<double> dEdx_electronprior =
183 std::vector<double> dEdx_photonprior =
187 if (electronprob_eprior < photonprob_pprior) {
188 dEdx_plane_final[dEdx_vec_plane.first] = dEdx_photonprior;
191 dEdx_plane_final[dEdx_vec_plane.first] = dEdx_electronprior;
197 std::vector<double> dEdx_final;
198 std::vector<double> dEdx_finalErr;
201 int best_plane = -999;
204 for (
auto const& dEdx_plane : dEdx_plane_final) {
207 if ((
int)(dEdx_plane.second).size() > max_hits) {
208 best_plane = dEdx_plane.first;
209 max_hits = (dEdx_plane.second).
size();
212 if ((dEdx_plane.second).empty()) {
213 dEdx_final.push_back(-999);
214 dEdx_finalErr.push_back(-999);
218 dEdx_final.push_back(TMath::Median((dEdx_plane.second).size(), &(dEdx_plane.second)[0]));
219 dEdx_finalErr.push_back(-999);
224 if (!check)
return 1;
235 std::vector<double>&
values)
237 int minprob_iter = -999;
239 float likelihood = -999;
245 std::vector<double>&
values,
254 float likelihood_other = 1;
258 float minprob_temp = 9999;
261 TH1F* prior_hist =
nullptr;
262 TH1F* other_hist =
nullptr;
264 if (priorname ==
"electron") {
268 if (priorname ==
"photon") {
273 TAxis* xaxis = prior_hist->GetXaxis();
276 for (
int i = 0; i < (
int)values.size(); ++i) {
278 float value = values[i];
280 Int_t
bin = xaxis->FindBin(value);
283 float other_prob = -9999;
285 if (bin != xaxis->GetNbins() || bin == 0) {
287 prob = prior_hist->GetBinContent(bin);
288 other_prob = other_hist->GetBinContent(bin);
295 if (prob < minprob_temp) {
300 if (prob == 0 && other_prob == 0) {
continue; }
303 meanprob += prior_hist->GetBinContent(bin);
305 likelihood_other *= other_prob;
308 posterior = likelihood / (likelihood + likelihood_other);
310 meanprob /= values.size();
319 TH1F* prior_hist =
nullptr;
324 TAxis* xaxis = prior_hist->GetXaxis();
326 Int_t
bin = xaxis->FindBin(value);
330 if (bin != xaxis->GetNbins() + 1 || bin == 0) {
332 prob = prior_hist->GetBinContent(bin);
346 std::vector<double>& dEdxVec)
350 std::vector<double> dEdxVec_temp = dEdxVec;
353 std::vector<double> SeedTrack =
MakeSeed(dEdxVec_temp);
360 double posterior = 999;
364 int SkippedHitsNum = 0;
365 RecurivelyAddHit(SeedTrack, dEdxVec_temp, prior, SkippedHitsNum, mean, posterior);
378 std::vector<double> seed_vector;
382 if (
fNumSeedHits > (
int)dEdxVec.size()) { MaxHit = (
int)dEdxVec.size(); }
388 for (
int hit_iter = 0; hit_iter < MaxHit; ++hit_iter) {
389 seed_vector.push_back(dEdxVec[0]);
390 dEdxVec.erase(dEdxVec.begin());
403 int minprob_iter = 999;
404 float likelihood = -999;
406 while ((mean <
fProbSeedCut || prob <= 0) && SeedTrack.size() > 1) {
410 SeedTrack.erase(SeedTrack.begin() + minprob_iter);
423 std::vector<double>& dEdxVec,
427 double& old_posteior)
431 if (dEdxVec.size() < 1) {
return; }
459 SeedTrack.push_back(dEdxVec[0]);
463 dEdxVec.erase(dEdxVec.begin());
465 RecurivelyAddHit(SeedTrack, dEdxVec, prior, SkippedHitsNum, old_mean, old_posteior);
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool check(const std::vector< std::vector< float > > &outputs)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
T get(std::string const &key) const
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
QTextStream & bin(QTextStream &s)
std::string find_file(std::string const &filename) const
auto const & get(AssnsNode< L, R, D > const &r)
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)