PFParticleVarExtractor.cxx
Go to the documentation of this file.
2 
8 
9 #include "utils.h"
10 
11 namespace VLN {
12 
13 static const std::vector<std::string> SCALAR_VARS({ });
14 static const std::vector<std::string> VECTOR_VARS({
15  "length",
16  "is_shower",
17  "start.x",
18  "start.y",
19  "start.z",
20  "dir.x",
21  "dir.y",
22  "dir.z",
23  "energy",
24  "nHit",
25  "charge",
26  "calE",
27 });
28 
30  const std::string &prefix,
31  calo::CalorimetryAlg &algCalorimetry,
32  const std::string &labelPFPModule,
33  const std::string &labelPFPTrack,
34  const std::string &labelPFPShower,
35  unsigned int plane
37  algCalorimetry(algCalorimetry),
38  labelPFPModule(labelPFPModule),
39  labelPFPTrack(labelPFPTrack),
40  labelPFPShower(labelPFPShower),
41  plane(plane)
42 { }
43 
45  const art::Event &evt,
46  const art::Ptr<recob::PFParticle> &particle,
47  VarDict &vars
48 )
49 {
51  particle, evt, labelPFPModule, labelPFPTrack
52  );
53  auto start = track->Start();
54  auto dir = track->StartDirection();
55 
56  appendToVectorVar(vars, "is_shower", 0);
57  appendToVectorVar(vars, "length", track->Length());
58  appendToVectorVar(vars, "start.x", start.x());
59  appendToVectorVar(vars, "start.y", start.y());
60  appendToVectorVar(vars, "start.z", start.z());
61  appendToVectorVar(vars, "dir.x", dir.x());
62  appendToVectorVar(vars, "dir.y", dir.y());
63  appendToVectorVar(vars, "dir.z", dir.z());
64  appendToVectorVar(vars, "energy", track->StartMomentum());
65 
66  const auto hits = dune_ana::DUNEAnaTrackUtils::GetHits(
67  track, evt, labelPFPTrack
68  );
69 
70  extractBasicVars(evt, hits, vars);
71 }
72 
74  const art::Event &evt,
75  const art::Ptr<recob::PFParticle> &particle,
76  VarDict &vars
77 )
78 {
80  particle, evt, labelPFPModule, labelPFPShower
81  );
82  auto start = shower->ShowerStart();
83  auto dir = shower->Direction();
84  auto energy = shower->Energy();
85 
86  appendToVectorVar(vars, "is_shower", 1);
87  appendToVectorVar(vars, "length", shower->Length());
88  appendToVectorVar(vars, "start.x", start.x());
89  appendToVectorVar(vars, "start.y", start.y());
90  appendToVectorVar(vars, "start.z", start.z());
91  appendToVectorVar(vars, "dir.x", dir.x());
92  appendToVectorVar(vars, "dir.y", dir.y());
93  appendToVectorVar(vars, "dir.z", dir.z());
95  vars, "energy", (energy.size() < plane + 1) ? 0 : energy[plane]
96  );
97 
98  const auto hits = dune_ana::DUNEAnaShowerUtils::GetHits(
100  );
101 
102  extractBasicVars(evt, hits, vars);
103 }
104 
106  const art::Event &evt,
107  const std::vector<art::Ptr<recob::Hit>> &hits,
108  VarDict &vars
109 )
110 {
111  const auto chargeCalE = calcHitsChargeCalE(
112  hits, evt, algCalorimetry, plane
113  );
114 
115  appendToVectorVar(vars, "nHit", hits.size());
116  appendToVectorVar(vars, "charge", chargeCalE.first);
117  appendToVectorVar(vars, "calE", chargeCalE.second);
118 }
119 
121 {
122  const std::vector<art::Ptr<recob::PFParticle>> particles
124 
125  for (const auto &particle : particles)
126  {
127  const bool isTrack = dune_ana::DUNEAnaPFParticleUtils::IsTrack(
128  particle, evt, labelPFPModule, labelPFPTrack
129  );
130 
131  const bool isShower = dune_ana::DUNEAnaPFParticleUtils::IsShower(
132  particle, evt, labelPFPModule, labelPFPShower
133  );
134 
135  if (isTrack == isShower) {
136  /* TODO: Maybe handle this condition somehow? */
137  continue;
138  }
139 
140  if (isShower) {
141  extractShowerVars(evt, particle, vars);
142  }
143  else if (isTrack) {
144  extractTrackVars(evt, particle, vars);
145  }
146  }
147 }
148 
149 }
150 
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...
calo::CalorimetryAlg & algCalorimetry
static const std::vector< std::string > VECTOR_VARS({})
void extractVars(const art::Event &evt, VarDict &vars) override
Utility containing helpful functions for end users to access information about Tracks.
std::pair< double, double > calcHitsChargeCalE(const std::vector< art::Ptr< recob::Hit >> &hits, const art::Event &evt, calo::CalorimetryAlg &algCalorimetry, unsigned int plane)
Definition: utils.cxx:10
std::string string
Definition: nybbler.cc:12
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.
struct vector vector
void extractShowerVars(const art::Event &evt, const art::Ptr< recob::PFParticle > &particle, VarDict &vars)
string dir
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Ptr< recob::Track > &pTrack, const art::Event &evt, const std::string &label)
Get the hits associated with the track.
static art::Ptr< recob::Shower > GetShower(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &showerLabel)
Get the shower associated to this particle. Should only be called if IsShower method succeeds...
Definition: VarDict.h:8
static const std::vector< std::string > SCALAR_VARS({"run","subRun","event"})
Utility containing helpful functions for end users to access information about Showers.
void appendToVectorVar(VarDict &vars, const std::string &name, double value) const
Definition: utils.cxx:6
Utility containing helpful functions for end users to access information about PFParticles.
Utility containing helpful functions for end users to access products from events.
void extractTrackVars(const art::Event &evt, const art::Ptr< recob::PFParticle > &particle, VarDict &vars)
void extractBasicVars(const art::Event &evt, const std::vector< art::Ptr< recob::Hit >> &hits, VarDict &vars)
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Ptr< recob::Shower > &pShower, const art::Event &evt, const std::string &label)
Get the hits associated with the shower.
PFParticleVarExtractor(const std::string &prefix, calo::CalorimetryAlg &algCalorimetry, const std::string &labelPFPModule, const std::string &labelPFPTrack, const std::string &labelPFPShower, unsigned int plane=2)
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.
TCEvent evt
Definition: DataStructs.cxx:7
static std::vector< art::Ptr< recob::PFParticle > > GetPFParticles(const art::Event &evt, const std::string &label)
Get the particles from the event.