38 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);
107 cet::search_path sp(
"FW_SEARCH_PATH");
108 auto PriorPath = pset.
get<std::string>(
"PriorFname");
109 if (!sp.find_file(PriorPath, fname)) {
110 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could not find the prior file";
112 std::string electron_histoname = pset.
get<std::string>(
"PriorElectronHistoName");
113 std::string photon_histoname = pset.
get<std::string>(
"PriorPhotonHistoName");
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";
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;
234 std::vector<double>&
values)
236 int minprob_iter = -999;
238 float likelihood = -999;
243 std::vector<double>&
values,
252 float likelihood_other = 1;
256 float minprob_temp = 9999;
259 TH1F* prior_hist =
nullptr;
260 TH1F* other_hist =
nullptr;
262 if (priorname ==
"electron") {
266 if (priorname ==
"photon") {
271 TAxis*
xaxis = prior_hist->GetXaxis();
274 for (
int i = 0; i < (int)values.size(); ++i) {
276 float value = values[i];
278 Int_t
bin = xaxis->FindBin(value);
281 float other_prob = -9999;
283 if (bin != xaxis->GetNbins() || bin == 0) {
285 prob = prior_hist->GetBinContent(bin);
286 other_prob = other_hist->GetBinContent(bin);
293 if (prob < minprob_temp) {
298 if (prob == 0 && other_prob == 0) {
continue; }
301 meanprob += prior_hist->GetBinContent(bin);
303 likelihood_other *= other_prob;
306 posterior = likelihood / (likelihood + likelihood_other);
308 meanprob /= values.size();
316 TH1F* prior_hist =
nullptr;
321 TAxis*
xaxis = prior_hist->GetXaxis();
323 Int_t
bin = xaxis->FindBin(value);
327 if (bin != xaxis->GetNbins() + 1 || bin == 0) {
329 prob = prior_hist->GetBinContent(bin);
340 double& electronprob,
343 std::vector<double>& dEdxVec)
347 std::vector<double> dEdxVec_temp = dEdxVec;
350 std::vector<double> SeedTrack =
MakeSeed(dEdxVec_temp);
357 double posterior = 999;
361 int SkippedHitsNum = 0;
362 RecurivelyAddHit(SeedTrack, dEdxVec_temp, prior, SkippedHitsNum, mean, posterior);
374 std::vector<double> seed_vector;
378 if (
fNumSeedHits > (
int)dEdxVec.size()) { MaxHit = (int)dEdxVec.size(); }
384 for (
int hit_iter = 0; hit_iter < MaxHit; ++hit_iter) {
385 seed_vector.push_back(dEdxVec[0]);
386 dEdxVec.erase(dEdxVec.begin());
398 int minprob_iter = 999;
399 float likelihood = -999;
401 while ((mean <
fProbSeedCut || prob <= 0) && SeedTrack.size() > 1) {
405 SeedTrack.erase(SeedTrack.begin() + minprob_iter);
417 std::vector<double>& dEdxVec,
421 double& old_posteior)
425 if (dEdxVec.size() < 1) {
return; }
453 SeedTrack.push_back(dEdxVec[0]);
457 dEdxVec.erase(dEdxVec.begin());
459 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
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
T get(std::string const &key) const
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
cet::coded_exception< error, detail::translate > exception