38 std::vector<double>& values,
54 bool CheckPoint(std::string priorname,
double& value);
59 std::vector<double>& dEdxVec);
61 std::vector<double>
MakeSeed(std::vector<double>& dEdxVec);
69 std::vector<double>& dEdxVec,
73 double& old_posteior);
92 :
IShowerTool(pset.get<fhicl::ParameterSet>(
"BaseTools"))
93 , fVerbose(pset.get<int>(
"Verbose"))
94 , fdEdxInputLabel(pset.get<std::string>(
"dEdxInputLabel"))
95 , fNumSeedHits(pset.get<int>(
"NumSeedHits"))
96 , fProbSeedCut(pset.get<float>(
"ProbSeedCut"))
97 , fProbPointCut(pset.get<float>(
"ProbPointCut"))
98 , fPostiorCut(pset.get<float>(
"PostiorCut"))
99 , fnSkipHits(pset.get<int>(
"nSkipHits"))
100 , fShowerdEdxOutputLabel(pset.get<std::string>(
"ShowerdEdxOutputLabel"))
101 , fDefineBestPlane(pset.get<bool>(
"DefineBestPlane"))
102 , fShowerBestPlaneOutputLabel(pset.get<std::string>(
"ShowerBestPlaneOutputLabel"))
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";
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";
140 const art::Ptr<recob::PFParticle>& pfparticle,
155 mf::LogError(
"ShowerBayesianTrucatingdEdx")
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;
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();
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);