14 #include "art/Utilities/ToolMacros.h"
24 namespace ShowerRecoTools {
38 std::vector<double>&
values,
61 std::vector<double>& dEdxVec);
63 std::vector<double>
MakeSeed(std::vector<double>& dEdxVec);
71 std::vector<double>& dEdxVec,
75 double& old_posteior);
95 , fVerbose(pset.
get<int>(
"Verbose"))
96 , fdEdxInputLabel(pset.
get<
std::string>(
"dEdxInputLabel"))
97 , fNumSeedHits(pset.
get<int>(
"NumSeedHits"))
98 , fProbSeedCut(pset.
get<float>(
"ProbSeedCut"))
99 , fProbPointCut(pset.
get<float>(
"ProbPointCut"))
100 , fPostiorCut(pset.
get<float>(
"PostiorCut"))
101 , fnSkipHits(pset.
get<int>(
"nSkipHits"))
102 , fShowerdEdxOutputLabel(pset.
get<
std::string>(
"ShowerdEdxOutputLabel"))
103 , fDefineBestPlane(pset.
get<
bool>(
"DefineBestPlane"))
104 , fShowerBestPlaneOutputLabel(pset.
get<
std::string>(
"ShowerBestPlaneOutputLabel"))
109 cet::search_path sp(
"FW_SEARCH_PATH");
110 auto PriorPath = pset.get<std::string>(
"PriorFname");
111 if (!sp.find_file(PriorPath, fname)) {
112 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could not find the prior file";
114 std::string electron_histoname = pset.get<std::string>(
"PriorElectronHistoName");
115 std::string photon_histoname = pset.get<std::string>(
"PriorPhotonHistoName");
117 TFile fin(fname.c_str(),
"READ");
119 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could read the prior file. Stopping";
125 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could not read the electron hist";
127 photonpriorHist =
dynamic_cast<TH1F*
>(fin.Get(photon_histoname.c_str()));
129 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Could not read the photon hist ";
133 throw cet::exception(
"ShowerBayesianTrucatingdEdx") <<
"Histrogram bins do not match";
157 mf::LogError(
"ShowerBayesianTrucatingdEdx")
158 <<
"Start position not set, returning " << std::endl;
162 std::map<int, std::vector<double>> dEdx_plane_final;
163 std::map<int, std::vector<double>> dEdx_vec_planes;
167 for (
auto const& dEdx_vec_plane : dEdx_vec_planes) {
170 if (dEdx_vec_plane.second.size() < 1) {
171 dEdx_plane_final[dEdx_vec_plane.first] = {};
175 std::vector<double> dEdx_vec = dEdx_vec_plane.second;
177 double electronprob_eprior = 0;
178 double photonprob_eprior = 0;
180 double electronprob_pprior = 0;
181 double photonprob_pprior = 0;
183 std::vector<double> dEdx_electronprior =
185 std::vector<double> dEdx_photonprior =
189 if (electronprob_eprior < photonprob_pprior) {
190 dEdx_plane_final[dEdx_vec_plane.first] = dEdx_photonprior;
193 dEdx_plane_final[dEdx_vec_plane.first] = dEdx_electronprior;
199 std::vector<double> dEdx_final;
200 std::vector<double> dEdx_finalErr;
203 int best_plane = -999;
206 for (
auto const& dEdx_plane : dEdx_plane_final) {
209 if ((
int)(dEdx_plane.second).size() > max_hits) {
210 best_plane = dEdx_plane.first;
211 max_hits = (dEdx_plane.second).
size();
214 if ((dEdx_plane.second).empty()) {
215 dEdx_final.push_back(-999);
216 dEdx_finalErr.push_back(-999);
220 dEdx_final.push_back(TMath::Median((dEdx_plane.second).size(), &(dEdx_plane.second)[0]));
221 dEdx_finalErr.push_back(-999);
226 if (!check)
return 1;
237 std::vector<double>&
values)
239 int minprob_iter = -999;
241 float likelihood = -999;
247 std::vector<double>&
values,
256 float likelihood_other = 1;
260 float minprob_temp = 9999;
263 TH1F* prior_hist =
nullptr;
264 TH1F* other_hist =
nullptr;
266 if (priorname ==
"electron") {
270 if (priorname ==
"photon") {
275 TAxis* xaxis = prior_hist->GetXaxis();
278 for (
int i = 0; i < (int)values.size(); ++i) {
280 float value = values[i];
282 Int_t
bin = xaxis->FindBin(value);
285 float other_prob = -9999;
287 if (bin != xaxis->GetNbins() || bin == 0) {
289 prob = prior_hist->GetBinContent(bin);
290 other_prob = other_hist->GetBinContent(bin);
297 if (prob < minprob_temp) {
302 if (prob == 0 && other_prob == 0) {
continue; }
305 meanprob += prior_hist->GetBinContent(bin);
307 likelihood_other *= other_prob;
310 posterior = likelihood / (likelihood + likelihood_other);
312 meanprob /= values.size();
321 TH1F* prior_hist =
nullptr;
326 TAxis* xaxis = prior_hist->GetXaxis();
328 Int_t
bin = xaxis->FindBin(value);
332 if (bin != xaxis->GetNbins() + 1 || bin == 0) {
334 prob = prior_hist->GetBinContent(bin);
348 std::vector<double>& dEdxVec)
352 std::vector<double> dEdxVec_temp = dEdxVec;
355 std::vector<double> SeedTrack =
MakeSeed(dEdxVec_temp);
362 double posterior = 999;
366 int SkippedHitsNum = 0;
367 RecurivelyAddHit(SeedTrack, dEdxVec_temp, prior, SkippedHitsNum, mean, posterior);
380 std::vector<double> seed_vector;
384 if (
fNumSeedHits > (
int)dEdxVec.size()) { MaxHit = (int)dEdxVec.size(); }
390 for (
int hit_iter = 0; hit_iter < MaxHit; ++hit_iter) {
391 seed_vector.push_back(dEdxVec[0]);
392 dEdxVec.erase(dEdxVec.begin());
405 int minprob_iter = 999;
406 float likelihood = -999;
408 while ((mean <
fProbSeedCut || prob <= 0) && SeedTrack.size() > 1) {
412 SeedTrack.erase(SeedTrack.begin() + minprob_iter);
425 std::vector<double>& dEdxVec,
429 double& old_posteior)
433 if (dEdxVec.size() < 1) {
return; }
461 SeedTrack.push_back(dEdxVec[0]);
465 dEdxVec.erase(dEdxVec.begin());
467 RecurivelyAddHit(SeedTrack, dEdxVec, prior, SkippedHitsNum, old_mean, old_posteior);
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
std::size_t size(FixedBins< T, C > const &) noexcept
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
bool CheckElement(const std::string &Name) const
process_name tightIsolTest check
int GetElement(const std::string &Name, T &Element) const
double mean(const std::vector< short > &wf, size_t start, size_t nsample)