20 #include "canvas/Persistency/Common/Ptr.h"
21 #include "cetlib/search_path.h"
22 #include "fhiclcpp/ParameterSet.h"
32 cet::search_path sp(
"FW_SEARCH_PATH");
35 throw cet::exception(
"Chi2ParticleID") <<
"cannot find the root template file: \n"
37 <<
"\n bail ungracefully.\n";
52 std::bitset<8> thisBitset;
54 thisBitset.set(planeID.
Plane);
63 std::vector<anab::sParticleIDAlgScores> AlgScoresVec;
66 for (
size_t i_calo = 0; i_calo < calos.size(); i_calo++){
68 art::Ptr<anab::Calorimetry>
calo = calos.at(i_calo);
71 else if(plid != calo->
PlaneID())
72 throw cet::exception(
"Chi2PIDAlg") <<
"PlaneID mismatch: " << plid <<
", " << calo->
PlaneID();
80 std::vector<double> vpida;
81 std::vector<float> trkdedx = calo->dEdx();
82 std::vector<float> trkres = calo->ResidualRange();
83 std::vector<float> deadwireresrc = calo->DeadWireResRC();
86 for (
unsigned i = 0; i<trkdedx.size(); ++i){
88 if (i==0 || i==trkdedx.size()-1)
continue;
89 avgdedx += trkdedx[i];
91 PIDA += trkdedx[i]*pow(trkres[i],0.42);
92 vpida.push_back(trkdedx[i]*pow(trkres[i],0.42));
95 if (trkdedx[i]>1000)
continue;
96 int bin = dedx_range_pro->FindBin(trkres[i]);
97 if (bin>=1&&bin<=dedx_range_pro->GetNbinsX()){
98 double bincpro = dedx_range_pro->GetBinContent(bin);
100 bincpro = (dedx_range_pro->GetBinContent(bin-1)+dedx_range_pro->GetBinContent(bin+1))/2;
102 double bincka = dedx_range_ka->GetBinContent(bin);
104 bincka = (dedx_range_ka->GetBinContent(bin-1)+dedx_range_ka->GetBinContent(bin+1))/2;
106 double bincpi = dedx_range_pi->GetBinContent(bin);
108 bincpi = (dedx_range_pi->GetBinContent(bin-1)+dedx_range_pi->GetBinContent(bin+1))/2;
110 double bincmu = dedx_range_mu->GetBinContent(bin);
112 bincmu = (dedx_range_mu->GetBinContent(bin-1)+dedx_range_mu->GetBinContent(bin+1))/2;
114 double binepro = dedx_range_pro->GetBinError(bin);
116 binepro = (dedx_range_pro->GetBinError(bin-1)+dedx_range_pro->GetBinError(bin+1))/2;
118 double bineka = dedx_range_ka->GetBinError(bin);
120 bineka = (dedx_range_ka->GetBinError(bin-1)+dedx_range_ka->GetBinError(bin+1))/2;
122 double binepi = dedx_range_pi->GetBinError(bin);
124 binepi = (dedx_range_pi->GetBinError(bin-1)+dedx_range_pi->GetBinError(bin+1))/2;
126 double binemu = dedx_range_mu->GetBinError(bin);
128 binemu = (dedx_range_mu->GetBinError(bin-1)+dedx_range_mu->GetBinError(bin+1))/2;
131 double errdedx = 0.04231+0.0001783*trkdedx[i]*trkdedx[i];
132 errdedx *= trkdedx[i];
133 chi2pro += pow((trkdedx[i]-bincpro)/std::sqrt(pow(binepro,2)+pow(errdedx,2)),2);
134 chi2ka += pow((trkdedx[i]-bincka)/std::sqrt(pow(bineka,2)+pow(errdedx,2)),2);
135 chi2pi += pow((trkdedx[i]-bincpi)/std::sqrt(pow(binepi,2)+pow(errdedx,2)),2);
136 chi2mu += pow((trkdedx[i]-bincmu)/std::sqrt(pow(binemu,2)+pow(errdedx,2)),2);
156 chi2proton.
fPlaneMask = GetBitset(calo->PlaneID());
157 chi2proton.
fNdf = npt;
158 chi2proton.
fValue = chi2pro/npt;
164 chi2muon.
fPlaneMask = GetBitset(calo->PlaneID());
166 chi2muon.
fValue = chi2mu/npt;
172 chi2kaon.
fPlaneMask = GetBitset(calo->PlaneID());
174 chi2kaon.
fValue = chi2ka/npt;
180 chi2pion.
fPlaneMask = GetBitset(calo->PlaneID());
182 chi2pion.
fValue = chi2pi/npt;
184 AlgScoresVec.push_back(chi2proton);
185 AlgScoresVec.push_back(chi2muon);
186 AlgScoresVec.push_back(chi2kaon);
187 AlgScoresVec.push_back(chi2pion);
193 pida_median.
fAlgName =
"PIDA_median";
196 pida_median.
fValue = TMath::Median(vpida.size(), &vpida[0]);
197 pida_median.
fPlaneMask = GetBitset(calo->PlaneID());
198 AlgScoresVec.push_back(pida_median);
204 pida_mean.
fValue = PIDA/used_trkres;
205 pida_mean.
fPlaneMask = GetBitset(calo->PlaneID());
206 AlgScoresVec.push_back(pida_mean);
Chi2PIDAlg(fhicl::ParameterSet const &pset)
TProfile * dedx_range_mu
muon template
The data type to uniquely identify a Plane.
TProfile * dedx_range_pro
proton template
TProfile * dedx_range_pi
pion template
float fValue
Result of Particle ID algorithm/test.
std::bitset< 8 > fPlaneMask
Bitset for PlaneID used by algorithm, allowing for multiple planes and up to 8 total planes...
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::string fAlgName
< determined particle ID
process_name can override from command line with o or output calo
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
int fNdf
Number of degrees of freedom used by algorithm, if applicable. Set to -9999 by default.
kTrackDir fTrackDir
Track direction enum: defined in ParticleID_VariableTypeEnums.h. Set to kNoDirection by default...
kVariableType fVariableType
Variable type enum: defined in ParticleID_VariableTypeEnums.h. Set to kNotSet by default.
constexpr PlaneID()=default
Default constructor: an invalid plane ID.
std::bitset< 8 > GetBitset(geo::PlaneID planeID)
std::string fTemplateFile
PlaneID_t Plane
Index of the plane within its TPC.
anab::ParticleID DoParticleID(const std::vector< art::Ptr< anab::Calorimetry >> &calo)
TProfile * dedx_range_ka
kaon template
int fAssumedPdg
PDG of particle hypothesis assumed by algorithm, if applicable. Set to 0 by default.