All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventInfoUtils.cxx
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Algorithms/details/EventInfoUtils.cxx
3  * @brief Class hosting selected information about the event (implementation).
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date May 15, 2020
6  * @see icaruscode/PMT/Trigger/Algorithms/details/EventInfoUtils.h
7  */
8 
9 
10 // library header
12 
13 // LArSoft libraries
14 #include "lardataalg/Utilities/quantities/spacetime.h" // microseconds
17 
18 // C/C++ standard libraries
19 #include <utility> // std::move()
20 #include <cassert>
21 
22 
23 // -----------------------------------------------------------------------------
24 namespace {
25 
26  /// Returns in which active TPC volume `point` falls in (`nullptr` if none).
27  geo::TPCGeo const* pointInActiveTPC
28  (geo::GeometryCore const& geom, geo::Point_t const& point)
29  {
30  geo::TPCGeo const* tpc = geom.PositionToTPCptr(point);
31  return (tpc && tpc->ActiveBoundingBox().ContainsPosition(point))
32  ? tpc: nullptr;
33  } // pointInActiveTPC()
34 
35 
36  /// Helper tracking energy depositions.
37  struct EnergyAccumulator {
38 
41 
42  GeV totalEnergy { 0.0 }, inSpillEnergy { 0.0 }, inPreSpillEnergy { 0.0 };
43  GeV activeEnergy { 0.0 }, inSpillActiveEnergy { 0.0 },
44  inPreSpillActiveEnergy { 0.0 };
45 
46  EnergyAccumulator(
47  TimeSpan_t inSpillTimes,
48  TimeSpan_t inPreSpillTimes,
49  geo::GeometryCore const& geom
50  )
51  : fGeom(geom)
52  , fInSpillTimes(inSpillTimes)
53  , fInPreSpillTimes(inPreSpillTimes)
54  {}
55 
56  void add(
57  GeV energy,
59  geo::Point_t const& location
60  ) {
61 
62  bool const inSpill
63  = (time >= fInSpillTimes.first) && (time <= fInSpillTimes.second);
64  bool const inPreSpill =
65  (time >= fInPreSpillTimes.first) && (time <= fInPreSpillTimes.second);
66 
67  totalEnergy += energy;
68  if (inSpill) inSpillEnergy += energy;
69  if (inPreSpill) inPreSpillEnergy += energy;
70 
71  if (pointInActiveTPC(location)) {
72  activeEnergy += energy;
73  if (inSpill) inSpillActiveEnergy += energy;
74  if (inPreSpill) inPreSpillActiveEnergy += energy;
75  }
76  } // add()
77 
78  private:
79  geo::GeometryCore const& fGeom; ///< Geometry service provider.
80 
81  /// Start and stop time for "in spill" label.
82  TimeSpan_t const fInSpillTimes;
83 
84  /// Start and stop time for "pre-spill" label.
85  TimeSpan_t const fInPreSpillTimes;
86 
87  /// Returns in which active TPC volume `point` falls in (`nullptr` if none).
88  geo::TPCGeo const* pointInActiveTPC(geo::Point_t const& point) const
89  { return ::pointInActiveTPC(fGeom, point); }
90 
91  }; // EnergyAccumulator
92 
93 } // local namespace
94 
95 
96 // -----------------------------------------------------------------------------
98  std::vector<art::InputTag> truthTags,
99  EDepTags_t edepTags,
100  TimeSpan_t inSpillTimes,
101  TimeSpan_t inPreSpillTimes,
102  geo::GeometryCore const& geom,
105  std::string logCategory
106  )
107  : fGeneratorTags(std::move(truthTags))
108  , fEnergyDepositTags(std::move(edepTags))
109  , fLogCategory(std::move(logCategory))
110  , fGeom(geom)
111  , fDetProps(detProps)
112  , fDetTimings(detTimings)
113  , fInSpillTimes(std::move(inSpillTimes))
114  , fInPreSpillTimes(std::move(inPreSpillTimes))
115 {
116 } // icarus::trigger::details::EventInfoExtractor::EventInfoExtractor()
117 
118 
119 // -----------------------------------------------------------------------------
121  (EventInfo_t& info, simb::MCTruth const& truth) const
122 {
123 
124  if (truth.NeutrinoSet()) fillGeneratorNeutrinoInfo(info, truth);
125 
126 } // icarus::trigger::details::EventInfoExtractor::fillGeneratorInfo()
127 
128 
129 // -----------------------------------------------------------------------------
131  (EventInfo_t& info, simb::MCTruth const& truth) const
132 {
133  if (!truth.NeutrinoSet()) return;
134 
135  simulation_time const interactionTime = getInteractionTime(truth);
136 
137  if ((info.nVertices() == 0) || (interactionTime < info.InteractionTime()))
138  setMainGeneratorNeutrinoInfo(info, truth);
139  else
140  addGeneratorNeutrinoInfo(info, truth);
141 
142 } // icarus::trigger::details::EventInfoExtractor::fillGeneratorNeutrinoInfo()
143 
144 
145 // -----------------------------------------------------------------------------
147  (EventInfo_t& info, simb::MCTruth const& truth) const
148 {
149  /*
150  * Sets the full information of the event, overwriting everything.
151  *
152  * Except that the vertex is just inserted into the vertex list, as the
153  * first entry.
154  */
155 
157 
158  //
159  // interaction flavor (nu_mu, nu_e)
160  // interaction type (CC, NC)
161  //
162 
163  simb::MCParticle const& nu = truth.GetNeutrino().Nu();
164  info.SetNeutrinoPDG(nu.PdgCode());
165  info.SetInteractionType(truth.GetNeutrino().InteractionType());
166  info.SetInteractionTime(getInteractionTime(truth));
167 
168  info.SetNeutrinoEnergy(GeV{ nu.E() });
169  info.SetLeptonEnergy(GeV{ truth.GetNeutrino().Lepton().E() });
170  //info.SetNucleonEnergy(truth.GetNeutrino().HitNuc().E());
171 
172  switch (nu.PdgCode()) {
173  case 14:
174  case -14:
175  info.SetNu_mu(true);
176  break;
177  case 12:
178  case -12:
179  info.SetNu_e(true);
180  break;
181  }
182 
183  switch (truth.GetNeutrino().CCNC()) {
184  case simb::kCC: info.AddWeakChargedCurrentInteractions(); break;
185  case simb::kNC: info.AddWeakNeutralCurrentInteractions(); break;
186  default:
187  mf::LogWarning(fLogCategory)
188  << "Unexpected NC/CC flag (" << truth.GetNeutrino().CCNC() << ")";
189  } // switch
190 
191  // we do not trust the vertex (`GvX()`) of the neutrino particle,
192  // since GenieHelper does not translate the vertex
193  // of some of the particles from GENIE to detector frame;
194  // trajectory is always translated:
195  geo::Point_t const vertex { nu.EndX(), nu.EndY(), nu.EndZ() };
196  info.InsertVertex(vertex, 0U);
197 
198  geo::TPCGeo const* tpc = pointInActiveTPC(vertex);
199  if (tpc) info.SetInActiveVolume();
200 
201 } // icarus::trigger::details::EventInfoExtractor::setMainGeneratorNeutrinoInfo()
202 
203 
204 // -----------------------------------------------------------------------------
206  (EventInfo_t& info, simb::MCTruth const& truth) const
207 {
208  /*
209  * The only update to the record so far is the addition of the vertex of the
210  * interaction at the end of the current list.
211  * No information is overwritten.
212  *
213  */
214 
215  simb::MCParticle const& nu = truth.GetNeutrino().Nu();
216 
217  // we do not trust the vertex (`GvX()`) of the neutrino particle,
218  // since GenieHelper does not translate the vertex
219  // of some of the particles from GENIE to detector frame;
220  // trajectory is always translated:
221  geo::Point_t const vertex { nu.EndX(), nu.EndY(), nu.EndZ() };
222  info.AddVertex(vertex);
223 
224 } // icarus::trigger::details::EventInfoExtractor::addGeneratorNeutrinoInfo()
225 
226 
227 // -----------------------------------------------------------------------------
229  (EventInfo_t& info, std::vector<sim::SimEnergyDeposit> const& energyDeposits)
230  const
231 {
233 
234  auto Eacc = EnergyAccumulator(fInSpillTimes, fInPreSpillTimes, fGeom);
235 
236  for (sim::SimEnergyDeposit const& edep: energyDeposits) {
237 
238  Eacc.add(
239  MeV{ edep.Energy() } // assuming it's stored in MeV
240  , detinfo::timescales::simulation_time{ edep.Time() }
241  , edep.MidPoint()
242  );
243 
244  } // for all energy deposits in the data product
245 
246  info.SetDepositedEnergy
247  (info.DepositedEnergy() + Eacc.totalEnergy);
249  (info.DepositedEnergyInSpill() + Eacc.inSpillEnergy);
251  (info.DepositedEnergyInPreSpill() + Eacc.inPreSpillEnergy);
253  (info.DepositedEnergyInActiveVolume() + Eacc.activeEnergy);
255  (info.DepositedEnergyInSpillInActiveVolume() + Eacc.inSpillActiveEnergy);
257  info.DepositedEnergyInPreSpillInActiveVolume() + Eacc.inPreSpillActiveEnergy
258  );
259 
260 } // icarus::trigger::details::EventInfoExtractor::addEnergyDepositionInfo()
261 
262 
263 // -----------------------------------------------------------------------------
265  (EventInfo_t& info, std::vector<sim::SimChannel> const& channels) const
266 {
267  assert(fDetProps);
268  assert(fDetTimings);
269 
271 
272  auto Eacc = EnergyAccumulator(fInSpillTimes, fInPreSpillTimes, fGeom);
273 
274  double const driftVel = fDetProps->DriftVelocity(); // cm/us
275 
276  for (sim::SimChannel const& channel: channels) {
277 
278  // only channels on any of the first induction planes
279  std::vector<geo::WireID> const& wires
280  = fGeom.ChannelToWire(channel.Channel());
281  if (empty(wires)) continue; // ghost channel or something; move on
282  if (wires.front().Plane != 0) continue; // not the first induction plane
283 
284  geo::PlaneGeo const& plane = fGeom.Plane(wires.front());
285 
286  for (auto const& [ tdc, IDEs ]: channel.TDCIDEMap()) {
287 
288  // collection tick: includes also drift time, diffusion and what-not
291  = fDetTimings->toSimulationTime(tick);
292 
293  for (sim::IDE const& IDE: IDEs) {
294  MeV const energy { IDE.energy }; // assuming it's stored in MeV
295  geo::Point_t const location { IDE.x, IDE.y, IDE.z };
296 
297  // tentative estimation of drift length:
298  double const d = plane.DistanceFromPlane(location); // cm
300  { d / driftVel };
301 
302  Eacc.add(energy, time - driftTime, location);
303  } // all deposits at this time tick
304 
305  } // all time ticks in this channel
306 
307  } // for all channels
308 
309  info.SetDepositedEnergy
310  (info.DepositedEnergy() + Eacc.totalEnergy);
312  (info.DepositedEnergyInSpill() + Eacc.inSpillEnergy);
314  (info.DepositedEnergyInPreSpill() + Eacc.inPreSpillEnergy);
316  (info.DepositedEnergyInActiveVolume() + Eacc.activeEnergy);
318  (info.DepositedEnergyInSpillInActiveVolume() + Eacc.inSpillActiveEnergy);
320  info.DepositedEnergyInPreSpillInActiveVolume() + Eacc.inPreSpillActiveEnergy
321  );
322 
323 } // icarus::trigger::details::EventInfoExtractor::addEnergyDepositionInfo()
324 
325 
326 // -----------------------------------------------------------------------------
328  (geo::Point_t const& point) const
329 {
330  return fGeom.PositionToTPCptr(point);
331 } // icarus::trigger::TriggerEfficiencyPlotsBase::pointInTPC()
332 
333 
334 //------------------------------------------------------------------------------
335 geo::TPCGeo const*
337  (geo::Point_t const& point) const
338 {
339  return ::pointInActiveTPC(fGeom, point);
340 } // icarus::trigger::TriggerEfficiencyPlotsBase::pointInActiveTPC()
341 
342 
343 // -----------------------------------------------------------------------------
345  (simb::MCTruth const& truth) const -> simulation_time
346 {
347  assert(truth.NeutrinoSet());
348  simb::MCParticle const& nu = truth.GetNeutrino().Nu();
349  return simulation_time{ nu.EndT() };
350 } // icarus::trigger::details::EventInfoExtractor::getInteractionTime()
351 
352 
353 // -----------------------------------------------------------------------------
354 // --- icarus::trigger::details::EventInfoExtractorMaker
355 // -----------------------------------------------------------------------------
357  std::vector<art::InputTag> truthTags,
358  EDepTags_t edepTags,
359  geo::GeometryCore const& geom,
362  std::string logCategory
363  )
364  : fGeneratorTags(std::move(truthTags))
365  , fEnergyDepositTags(std::move(edepTags))
366  , fLogCategory(std::move(logCategory))
367  , fGeom(geom)
368  , fDetProps(detProps)
369  , fDetTimings(detTimings)
370  {}
371 
372 
373 // -----------------------------------------------------------------------------
376  (TimeSpan_t inSpillTimes, TimeSpan_t inPreSpillTimes) const
377 {
378  return EventInfoExtractor{
379  fGeneratorTags, fEnergyDepositTags,
380  inSpillTimes, inPreSpillTimes,
381  fGeom, fDetProps, fDetTimings, fLogCategory
382  };
383 } // icarus::trigger::details::EventInfoExtractorMaker::make()
384 
385 
386 // -----------------------------------------------------------------------------
process_name vertex
Definition: cheaterreco.fcl:51
fDetProps &fDetProps detProps
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
void SetNu_mu(bool numu)
Marks the flavor of the neutrino in the first interaction.
Definition: EventInfo_t.h:181
timescale_traits< ElectronicsTimeCategory >::tick_t electronics_tick
A point on the electronics time scale expressed in its ticks.
Energy deposited on a readout channel by simulated tracks.
Definition: SimChannel.h:145
geo::TPCGeo const * pointInActiveTPC(geo::Point_t const &point) const
Returns in which active TPC volume point falls in (nullptr if none).
Extracts from event the relevant information on the physics event.
simulation_time getInteractionTime(simb::MCTruth const &truth) const
Geometry information for a single TPC.
Definition: TPCGeo.h:38
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
Definition: TPCGeo.h:320
geo::TPCGeo const * PositionToTPCptr(geo::Point_t const &point) const
Returns the TPC at specified location.
void InsertVertex(geo::Point_t const &vertex, std::size_t beforeIndex)
Definition: EventInfo_t.h:210
void SetDepositedEnergyInSpill(GeV e)
Sets the energy of the event deposited during beam gate [GeV].
Definition: EventInfo_t.h:217
detinfo::timescales::simulation_time simulation_time
std::variant< std::vector< art::InputTag >, SimEnergyDepositSummaryInputTag, SimChannelsInputTag > EDepTags_t
Type to specify the source of energy deposition information, if any.
geo::TPCGeo const * pointInTPC(geo::Point_t const &point) const
Returns in which TPC volume point falls in (nullptr if none).
void fillGeneratorInfo(EventInfo_t &info, simb::MCTruth const &truth) const
Fills info record with generation information from truth.
void SetInteractionTime(simulation_time time)
Sets the time of the first interaction.
Definition: EventInfo_t.h:197
EventInfoExtractorMaker(std::vector< art::InputTag > truthTags, EDepTags_t edepTags, geo::GeometryCore const &geom, detinfo::DetectorPropertiesData const *detProps, detinfo::DetectorTimings const *detTimings, std::string logCategory)
Constructor: stores parameters for construction of EventInfoExtractor.
fDetProps &fDetProps fDetProps &fDetProps fLogCategory
void SetDepositedEnergyInPreSpillInActiveVolume(GeV e)
Definition: EventInfo_t.h:233
void SetDepositedEnergyInPreSpill(GeV e)
Sets the energy of the event deposited during pre-spill window [GeV].
Definition: EventInfo_t.h:220
Access the description of detector geometry.
Charged-current interactions.
Definition: IPrediction.h:38
std::pair< simulation_time, simulation_time > TimeSpan_t
void AddVertex(geo::Point_t const &vertex)
Adds a point to the list of interaction vertices in the event.
Definition: EventInfo_t.h:205
void AddWeakNeutralCurrentInteractions(unsigned int n=1U)
Marks this event as including n more weak neutral current interactions.
Definition: EventInfo_t.h:177
void SetLeptonEnergy(GeV eL)
Sets the lepton energy.
Definition: EventInfo_t.h:191
timescale_traits< SimulationTimeCategory >::time_point_t simulation_time
A point in time on the simulation time scale.
Ionization at a point of the TPC sensitive volume.
Definition: SimChannel.h:86
A value measured in the specified unit.
Definition: quantities.h:566
megaelectronvolt_as<> megaelectronvolt
Type of energy stored in megaelectronvolt, in double precision.
Definition: energy.h:119
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
void SetInActiveVolume(bool active=true)
Set whether the event has relevant activity in the active volume.
Definition: EventInfo_t.h:201
void SetNeutrinoEnergy(GeV eNu)
Sets the neutrino energy.
Definition: EventInfo_t.h:188
Description of geometry of one entire detector.
GeV DepositedEnergyInSpill() const
Returns the total energy deposited in the detector during beam [GeV].
Definition: EventInfo_t.h:146
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
gigaelectronvolt_as<> gigaelectronvolt
Type of energy stored in gigaelectronvolt, in double precision.
Definition: energy.h:129
Functions dealing with icarus::trigger::details::EventInfo_t.
simulation_time InteractionTime() const
Returns the time of the first interaction, in simulation time scale [ns].
Definition: EventInfo_t.h:112
void addEnergyDepositionInfo(EventInfo_t &info, std::vector< sim::SimEnergyDeposit > const &energyDeposits) const
Adds the energy depositions from energyDeposits into info record.
GeV DepositedEnergyInSpillInActiveVolume() const
Returns the energy deposited in the active volume during the beam [GeV].
Definition: EventInfo_t.h:156
GeV DepositedEnergyInPreSpillInActiveVolume() const
Definition: EventInfo_t.h:161
EventInfoExtractor(std::vector< art::InputTag > truthTags, EDepTags_t edepTags, TimeSpan_t inSpillTimes, TimeSpan_t inPreSpillTimes, geo::GeometryCore const &geom, detinfo::DetectorPropertiesData const *detProps, detinfo::DetectorTimings const *detTimings, std::string logCategory="EventInfoExtractor")
Constructor: configures the object.
void SetNeutrinoPDG(int NU)
Marks the neutrino type of the first interaction in the event.
Definition: EventInfo_t.h:185
double DistanceFromPlane(geo::Point_t const &point) const
Returns the distance of the specified point from the wire plane.
Definition: PlaneGeo.h:621
unsigned int nVertices() const
Returns the number of known interaction vertices.
Definition: EventInfo_t.h:118
void setMainGeneratorNeutrinoInfo(EventInfo_t &info, simb::MCTruth const &truth) const
Dimensioned variables representing space or time quantities.
A class exposing an upgraded interface of detinfo::DetectorClocksData.
void SetDepositedEnergy(GeV e)
Sets the total deposited energy of the event [GeV].
Definition: EventInfo_t.h:214
Energy deposition in the active material.
GeV DepositedEnergy() const
Returns the total energy deposited in the detector during the event [GeV].
Definition: EventInfo_t.h:143
Neutral-current interactions.
Definition: IPrediction.h:39
GeV DepositedEnergyInActiveVolume() const
Returns the energy deposited in the active volume during the event [GeV].
Definition: EventInfo_t.h:153
Selected information about the event.
Definition: EventInfo_t.h:45
void fillGeneratorNeutrinoInfo(EventInfo_t &info, simb::MCTruth const &truth) const
Fills info record with generated neutrino information from truth.
fDetProps &fDetProps fDetProps &fDetProps detTimings
void addGeneratorNeutrinoInfo(EventInfo_t &info, simb::MCTruth const &truth) const
EventInfoExtractor make(TimeSpan_t inSpillTimes, TimeSpan_t inPreSpillTimes) const
Creates and returns a new EventInfoExtractor object.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
void SetInteractionType(int type)
Sets the interaction type.
Definition: EventInfo_t.h:194
BEGIN_PROLOG SN nu
void AddWeakChargedCurrentInteractions(unsigned int n=1U)
Marks this event as including n more weak charged current interactions.
Definition: EventInfo_t.h:173
void SetDepositedEnergyInActiveVolume(GeV e)
Sets the total deposited energy of the event in active volume [GeV].
Definition: EventInfo_t.h:223
bool ContainsPosition(geo::Point_t const &point, double wiggle=1.0) const
Returns whether this volume contains the specified point.
Encapsulate the construction of a single detector plane.