26 , fExponentConstant(p.
get<float>(
"ExponentConstant", 0.42))
27 , fMinResRange(p.
get<float>(
"MinResRange", 0))
28 , fMaxResRange(p.
get<float>(
"MaxResRange", 30))
29 , fMaxPIDAValue(p.
get<float>(
"MaxPIDAValue", 50))
30 , fKDEEvalMaxSigma(p.
get<float>(
"KDEEvalMaxSigma", 3))
31 , fKDEEvalStepSize(p.
get<float>(
"KDEEvalStepSize", 0.01))
32 , fKDEBandwidths(p.
get<
std::
vector<float>>(
"KDEBandwidths"))
33 , fnormalDist(
util::NormalDistribution(fKDEEvalMaxSigma, fKDEEvalStepSize))
34 , fPIDAHistNbins(p.
get<unsigned int>(
"PIDAHistNbins", 100))
35 , fPIDAHistMin(p.
get<float>(
"PIDAHistMin", 0.0))
36 , fPIDAHistMax(p.
get<float>(
"PIDAHistMax", 50.0))
62 throw "Error: input histograms larger than max allowed bandwidths.";
64 throw "Error: input histograms do not have same size as bandwidths.";
69 hPIDAvalues->SetNameTitle(
"hPIDAvalues",
"PIDA Distribution");
72 for (
size_t i_hist = 0; i_hist < hist_kde.size(); i_hist++) {
75 std::stringstream hname, htitle;
76 hname <<
"hPIDAKDE_" << i_hist;
77 htitle <<
"PIDA KDE-smoothed Distribution, Bandwidth=" <<
fKDEBandwidths.at(i_hist);
79 hPIDAKDE[i_hist]->SetNameTitle(hname.str().c_str(), htitle.str().c_str());
90 for (
size_t i_hist = 0; i_hist < hist_kde.size(); i_hist++) {
91 std::stringstream bname;
92 bname <<
"hpida_kde_" << i_hist;
138 std::vector<float>
const&
dEdx = calo.
dEdx();
157 std::map<double, double> range_dEdx_map;
159 for (
size_t i_r = 0; i_r < resRange.size(); i_r++) {
162 range_dEdx_map[resRange[i_r]] = dEdx[i_r];
178 unsigned int calo_index,
188 if (
fpida_values.size() == 0)
throw "pid::PIDAAlg --- PIDA Values not filled!";
211 if (range_dEdx_map.size() < 2)
return;
216 map_iter != std::prev(range_dEdx_map.end());
218 double range_width = std::next(map_iter)->first - map_iter->first;
220 0.5 * (map_iter->second - std::next(map_iter)->second));
225 std::pow((std::prev(range_dEdx_map.end())->first - range_dEdx_map.begin()->first),
232 if (
fpida_values.size() == 0)
throw "pid::PIDAAlg --- PIDA Values not filled!";
248 const size_t min_pida_location = std::distance(
fpida_values.begin(), min_pida_iterator);
253 const size_t max_pida_location = std::distance(
fpida_values.begin(), max_pida_iterator);
258 const size_t kde_dist_size =
263 for (
size_t i_step = 0; i_step < kde_dist_size; i_step++) {
267 for (
size_t i_pida = 0; i_pida <
fpida_values.size(); i_pida++)
270 fpida_errors[i_pida];
282 for (
size_t i_step = step_max; i_step > 0; i_step--) {
286 float high_width = 0;
287 for (
size_t i_step = step_max; i_step < kde_dist_size; i_step++) {
302 unsigned int calo_index,
348 for (
size_t i_pida = 0; i_pida <
fpida_values.size(); i_pida++)
349 std::cout <<
"\tPIDA --- " << i_pida <<
"\t" <<
fpida_values[i_pida] << std::endl;
355 if (step_size == 0)
throw "util::NormalDistribution --- Cannot have zero step size!";
357 const size_t vector_size = (size_t)(max_sigma / step_size);
358 fValues.resize(vector_size);
360 const float AMPLITUDE = 1. / std::sqrt(2 * M_PI);
363 for (
size_t i_step = 0; i_step < vector_size; i_step++) {
364 float diff = i_step * step_size;
365 fValues[i_step] = AMPLITUDE * std::exp(-0.5 * diff * diff);
366 integral += fValues[i_step];
369 for (
size_t i_step = 0; i_step < vector_size; i_step++)
370 fValues[i_step] /= (integral * 2);
372 fStepSize = step_size;
373 fMaxSigma = fStepSize * vector_size;
380 if (x > fMaxSigma)
return 0;
382 size_t bin_low = x / fStepSize;
383 float remainder = (x - (bin_low * fStepSize)) / fStepSize;
385 return fValues[bin_low] * (1 - remainder) + remainder * fValues[bin_low + 1];
std::vector< float > fpida_errors
TH1F * hPIDAKDE[MAX_BANDWIDTHS]
void SetPIDATree(TTree *, TH1F *, std::vector< TH1F * >)
Namespace for general, non-LArSoft-specific utilities.
std::string leaf_structure
float kde_bandwidth[MAX_BANDWIDTHS]
float fpida_integral_pida
void FillPIDATree(unsigned int, unsigned int, unsigned int, anab::Calorimetry const &)
util::NormalDistribution fnormalDist
std::vector< float > fkde_dist_min
const geo::PlaneID & PlaneID() const
constexpr auto abs(T v)
Returns the absolute value of the argument.
PIDAAlg(fhicl::ParameterSet const &p)
std::vector< std::vector< float > > fkde_distribution
std::vector< float > fpida_kde_mp
void FillPIDAProperties(unsigned int, unsigned int, unsigned int, anab::Calorimetry const &)
void createKDE(const size_t)
unsigned int n_bandwidths
const std::vector< float > & ResidualRange() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
const std::vector< float > & getPIDAValues()
std::vector< float > fkde_dist_max
std::vector< float > fpida_kde_fwhm
unsigned int fPIDAHistNbins
float kde_fwhm[MAX_BANDWIDTHS]
float getPIDAKDEMostProbable(const size_t)
void RunPIDAAlg(std::vector< float > const &, std::vector< float > const &)
const unsigned int MAX_BANDWIDTHS
std::vector< float > fpida_values
PlaneID_t Plane
Index of the plane within its TPC.
Definition of data types for geometry description.
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
const std::vector< float > & dEdx() const
float getPIDAKDEFullWidthHalfMax(const size_t)
std::vector< float > fpida_kde_b
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
void calculatePIDAIntegral(std::map< double, double > const &)
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
const float & KineticEnergy() const
std::vector< float > fKDEBandwidths
const std::vector< float > & getPIDAErrors()
PIDAProperties_t fPIDAProperties
float fpida_integral_dedx
const float & Range() const
void calculatePIDASigma()
float kde_mp[MAX_BANDWIDTHS]
Event finding and building.