LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TotallyCheatTracker_module.cc
Go to the documentation of this file.
1 
14 // LArSoft libraries
19 
20 // framework libraries
24 #include "art/Framework/Principal/Handle.h" // art::ValidHandle<>
30 #include "fhiclcpp/types/Atom.h"
31 #include "fhiclcpp/types/Table.h"
32 
33 // C/C++ standard libraries
34 #include <vector>
35 #include <memory> // std::make_unique()
36 
37 
38 namespace lar {
39  namespace example {
40 
76 
77  public:
78 
80  struct Config {
81 
82  using Name = fhicl::Name;
84 
86  Name("particles"),
87  Comment("the data product of simulated particles to be processed"),
88  "largeant" // default
89  };
90 
92  Name("minLength"),
93  Comment("minimum length of particle trajectory [cm]"),
94  1.0 // default
95  };
96 
98  Name("minEnergy"),
99  Comment("minimum energy of particle [GeV]"),
100  1.0 // default
101  };
102 
104  Name("algoConfig"),
105  Comment("configuration of TotallyCheatTrackingAlg algorithm"),
107  };
108 
109  }; // Config
110 
113 
115  explicit TotallyCheatTracker(Parameters const& config);
116 
117 
118  virtual void produce(art::Event& event) override;
119 
120 
122  bool acceptParticle(simb::MCParticle const& particle) const;
123 
124 
125  private:
127 
128  double minLength;
129  double minEnergy;
130 
133 
134 
135  }; // class TotallyCheatTracker
136 
137  } // namespace example
138 } // namespace lar
139 
140 
141 
142 //------------------------------------------------------------------------------
143 //--- TotallyCheatTracker
144 //---
146  (Parameters const& config)
147  : particleTag(config().particles())
148  , minLength(config().minLength())
149  , minEnergy(config().minEnergy())
150  , trackMaker(config().algoConfig())
151 {
152 
153  consumes<std::vector<simb::MCParticle>>(particleTag);
154 
155  produces<std::vector<lar::example::CheatTrack>>();
156  produces<art::Assns<lar::example::CheatTrack, simb::MCParticle>>();
157 
158 } // lar::example::TotallyCheatTracker::TotallyCheatTracker()
159 
160 
161 //------------------------------------------------------------------------------
163 
164  //
165  // read the input
166  //
167  auto particleHandle
168  = event.getValidHandle<std::vector<simb::MCParticle>>(particleTag);
169  auto const& particles = *particleHandle;
170 
171  //
172  // prepare the output structures
173  //
174  auto tracks = std::make_unique<std::vector<lar::example::CheatTrack>>();
175  auto trackToPart =
176  std::make_unique<art::Assns<lar::example::CheatTrack, simb::MCParticle>>();
177 
178  art::PtrMaker<simb::MCParticle> makePartPtr(event, particleHandle.id());
179  art::PtrMaker<lar::example::CheatTrack> makeTrackPtr(event, *this);
180 
181 
182  //
183  // set up the algorithm
184  //
185  trackMaker.setup();
186 
187  //
188  // run the algorithm
189  //
190  for (std::size_t iParticle = 0U; iParticle < particles.size(); ++iParticle) {
191  simb::MCParticle const& particle = particles[iParticle];
192 
193  //
194  // apply filters
195  //
196  if (!acceptParticle(particle)) continue;
197 
198  //
199  // run the algorithm
200  //
201  tracks->push_back(trackMaker.makeTrack(particle));
202 
203  //
204  // create the association
205  //
206  auto const iTrack = tracks->size() - 1;
207  art::Ptr<lar::example::CheatTrack> const trackPtr = makeTrackPtr(iTrack);
208  art::Ptr<simb::MCParticle> const partPtr = makePartPtr(iParticle);
209  trackToPart->addSingle(trackPtr, partPtr);
210 
211  } // for
212 
213  //
214  // store the data products into the event (and print a short summary)
215  //
216  mf::LogInfo("TotallyCheatTracker")
217  << "Reconstructed " << tracks->size() << " tracks out of "
218  << particleHandle->size() << " particles from '"
219  << particleTag.encode() << "'";
220 
221  event.put(std::move(tracks));
222  event.put(std::move(trackToPart));
223 
224 } // lar::example::TotallyCheatTracker::produce()
225 
226 
227 //------------------------------------------------------------------------------
229  (simb::MCParticle const& particle) const
230 {
231  // skip empty particle
232  if (particle.NumberTrajectoryPoints() == 0) return false;
233 
234  // energy at the first point
235  if (particle.E() < minEnergy) return false;
236 
237  // path length
238  if (particle.Trajectory().TotalLength() < minLength) return false;
239 
240  // good enough!
241  return true;
242 
243 } // lar::example::TotallyCheatTracker::acceptParticle()
244 
245 //------------------------------------------------------------------------------
247 
248 
249 //------------------------------------------------------------------------------
double E(const int i=0) const
Definition: MCParticle.h:237
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:222
Data product for reconstructed trajectory in space.
Reconstructs tracks from simulated particles.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const simb::MCTrajectory & Trajectory() const
Definition: MCParticle.h:257
virtual void produce(art::Event &event) override
double minLength
Minimum particle length [cm].
Algorithm to "reconstruct" trajectories from simulated particles.
fhicl::Table< lar::example::TotallyCheatTrackingAlg::Config > algoConfig
Particle class.
Pseudo-track data product for TotallyCheatTracks example.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
std::string encode() const
Definition: InputTag.cc:36
bool acceptParticle(simb::MCParticle const &particle) const
Returns whether the particle satisfies the selection criteria.
lar::example::CheatTrack makeTrack(simb::MCParticle const &mcParticle) const
Returns a reconstructed track from the specified particle.
void setup()
Set up the algorithm (currently no operation).
lar::example::TotallyCheatTrackingAlg trackMaker
Reconstruction algorithm.
Module: creates tracks from simulated particles.
LArSoft-specific namespace.
double TotalLength() const
TotallyCheatTracker(Parameters const &config)
Constructor; see the class documentation for the configuration.
art::InputTag particleTag
Label of the input data product.
Definition: fwd.h:25
EventID id() const
Definition: Event.h:56
Event finding and building.