14 #include "canvas/Persistency/Common/FindManyP.h" 48 fQMax = pset.
get<
float>(
"MaxCharge",1000);
49 fQJump = pset.
get<
float>(
"MaxChargeJump",500);
60 std::vector< std::vector< std::vector<float> > > finalInputs;
65 finalInputs.push_back(twoVecs);
70 std::unique_ptr<tf::CTPGraph> convNet =
tf::CTPGraph::create(fullPath.c_str(),std::vector<std::string>(),2,1);
72 std::vector< std::vector< std::vector<float> > > convNetOutput = convNet->
run(finalInputs);
83 std::vector<std::vector<float>> netInputs;
87 return std::vector<std::vector<float>>();
96 return std::vector<std::vector<float>>();
99 std::vector<float> dedxVector = thisCalo->
dEdx();
102 float dedxSigma = 0.;
105 std::vector<float> dedxTrunc;
107 unsigned int avStart = dedxVector.size() - 1 - pointsForAverage;
108 unsigned int avEnd = dedxVector.size() - 1 - (2*pointsForAverage);
109 for(
unsigned int e = avStart;
e > avEnd; --
e) dedxTrunc.push_back(dedxVector.at(
e));
117 std::vector<float> finalInputDedx;
118 finalInputDedx.insert(finalInputDedx.begin(),dedxVector.end() -
fDedxLength,dedxVector.end());
120 std::vector<float> finalInputVariables;
122 float nTrack, nShower, nGrand;
124 finalInputVariables.push_back(nTrack);
125 finalInputVariables.push_back(nShower);
126 finalInputVariables.push_back(nGrand);
128 finalInputVariables.push_back(dedxMean);
129 finalInputVariables.push_back(dedxSigma);
131 float deflectionMean, deflectionSigma;
133 finalInputVariables.push_back(deflectionMean);
134 finalInputVariables.push_back(deflectionSigma);
136 netInputs.push_back(finalInputDedx);
137 netInputs.push_back(finalInputVariables);
158 using weightedMCPair = std::pair<const simb::MCParticle*, float>;
159 std::vector<weightedMCPair> outVecHits;
164 std::unordered_map<const simb::MCParticle*, float> mcHitMap;
169 mcHitMap[curr_part] += 1.;
174 for (weightedMCPair
const &
p : mcHitMap) outVecHits.push_back(
p);
176 if(outVecHits.size() == 0) assert(0);
178 std::sort(outVecHits.begin(),outVecHits.end(),[](weightedMCPair
a, weightedMCPair
b){
return a.second >
b.second;});
179 for(weightedMCPair &
p : outVecHits)
p.second /= hitTotal;
182 return outVecHits.at(0);
192 for(
float &
val : dedx){
199 std::cout <<
"CTPHelper: small value " <<
val <<
" set to 1.0e-3 " <<
std::endl;
206 unsigned int nQ = dedx.size();
208 for(
unsigned int q = 1; q < nQ - 1; ++q){
209 if((dedx[q] - dedx[q-1]) >
fQJump)
212 dedx[q] = 0.5 * (dedx[q-1]+dedx[q+1]);
227 std::normal_distribution<float> gaussDist(mean,sigma);
229 unsigned int originalSize = dedx.size();
237 randVal = gaussDist(generator);
241 dedx.insert(dedx.begin(),randVal);
248 float averageDedx = 0;
250 for(
const float &q : dedx) averageDedx += q;
251 mean = averageDedx /
static_cast<float>(dedx.size());
252 for(
const float &q : dedx) sigmaDedx += (mean -q)*(mean-q);
253 sigma = std::sqrt(sigmaDedx / static_cast<float>(dedx.size()));
258 std::vector<float> trajAngle;
262 trajAngle.push_back(thisDir.Angle(prevDir));
268 float averageAngle = 0;
269 float standardDevAngle = 0;
270 for(
const float &
a : trajAngle) averageAngle +=
a;
271 mean = averageAngle /
static_cast<float>(trajAngle.size());
272 for(
const float &
a : trajAngle) standardDevAngle += (
a -
mean)*(
a - mean);
273 sigma = sqrt(standardDevAngle / static_cast<float>(trajAngle.size()));
287 nGrand += child->NumDaughters();
295 for(
float &dedx :
inputs.at(0)){
301 float newVal = std::log(2*dedx) + 1;
302 if(newVal > 5.) newVal = 5.;
303 dedx = (newVal / 2.5) - 1;
307 for(
unsigned int v = 0; v < 3; ++v){
310 inputs.at(1).at(v) = (val / 2.5) - 1.0;
315 val = std::log(2*val) + 1;
316 if(val > 5.) val = 5.;
317 inputs.at(1).at(3) = (val / 2.5) - 1;
321 if(val > 3) val = 3.;
322 inputs.at(1).at(4) = (val/1.5) - 1;
326 if(val > 0.05) val = 0.05;
327 inputs.at(1).at(5) = (val / 0.025) - 1.0;
331 if(val > 0.3) val = 0.3;
332 inputs.at(1).at(6) = (val / 0.15) - 1.0;
static art::Ptr< recob::Track > GetTrack(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &trackLabel)
Get the track associated to this particle. Should only be called if IsTrack method succeeds...
Class storing the result from the convolutional track PID.
const std::vector< float > GetDeDxVector(const art::Ptr< recob::PFParticle >, const art::Event &evt) const
void NormaliseInputs(std::vector< std::vector< float >> &netInputs) const
Class containing some utility functions for all things CVN.
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
T DirectionAtPoint(unsigned int p) const
Direction at point p. Use e.g. as:
Utility containing helpful functions for end users to access information about Tracks.
static std::unique_ptr< CTPGraph > create(const char *graph_file_name, const std::vector< std::string > &outputs={}, int ninputs=1, int noutputs=1)
const int GetTruePDGCode(const art::Ptr< recob::PFParticle >, const art::Event &evt) const
const simb::MCParticle * TrackIdToParticle_P(int id) const
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
const std::vector< std::vector< float > > GetNetworkInputs(const art::Ptr< recob::PFParticle >, const art::Event &evt) const
static bool IsShower(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &showerLabel)
Check if this particle has an associated shower.
std::vector< float > run(const std::vector< std::vector< float > > &x)
Functions to help use the convolutional track PID.
static std::vector< art::Ptr< recob::PFParticle > > GetChildParticles(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the child particles (one step down in the hierarchy) of this particle.
void SmoothDedxVector(std::vector< float > &dedx) const
size_t NPoints() const
Returns the number of stored trajectory points.
std::string getenv(std::string const &name)
T get(std::string const &key) const
void GetDeflectionMeanAndSigma(const art::Ptr< recob::Track > track, float &mean, float &sigma) const
Utility containing helpful functions for end users to access information about PFParticles.
void GetDedxMeanAndSigma(const std::vector< float > &dedx, float &mean, float &sigma) const
const std::pair< const simb::MCParticle *, float > GetTrueParticle(const art::Ptr< recob::PFParticle >, const art::Event &evt) const
Detector simulation of raw signals on wires.
const std::vector< float > & dEdx() const
unsigned int fMinTrackPoints
Declaration of signal hit object.
std::string fParticleLabel
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the hits associated to this particle.
Provides recob::Track data product.
static art::Ptr< anab::Calorimetry > GetCalorimetry(const art::Ptr< recob::Track > &pTrack, const art::Event &evt, const std::string &trackLabel, const std::string &caloLabel)
Get the particle associated with the track.
static bool IsTrack(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &trackLabel)
Check if this particle has an associated track.
std::string fCalorimetryLabel
Ionization energy from a Geant4 track.
void GetChildParticles(const art::Ptr< recob::PFParticle > part, const art::Event &evt, float &nTrack, float &nShower, float &nGrand) const
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
const std::vector< float > GetVariableVector(const art::Ptr< recob::PFParticle >, const art::Event &evt) const
void PadDedxVector(std::vector< float > &dedx, const float mean, const float sigma) const
QTextStream & endl(QTextStream &s)
CTPHelper(const fhicl::ParameterSet &pset)
const ctp::CTPResult RunConvolutionalTrackPID(const art::Ptr< recob::PFParticle > particle, const art::Event &evt) const