LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
sim::MCRecoPart Class Reference

#include "MCRecoPart.h"

Inheritance diagram for sim::MCRecoPart:

Public Member Functions

 MCRecoPart (fhicl::ParameterSet const &pset)
 Default constructor with fhicl parameters. More...
 
virtual ~MCRecoPart ()
 Default destructor. More...
 
void AddParticles (const std::vector< simb::MCParticle > &mcp_v, const std::vector< simb::Origin_t > &orig_v, const std::vector< simb::MCParticle > &mcmp_v={})
 
unsigned int AncestorTrackID (const unsigned int part_index)
 
unsigned int MotherTrackID (const unsigned int part_index) const
 
unsigned int TrackToParticleIndex (const unsigned int track_id) const
 
bool InDetector (const double &x, const double &y, const double &z) const
 

Public Attributes

std::map< unsigned int, unsigned int > _track_index
 Track ID => Index Map. More...
 
std::set< int > _pdg_list
 PDG code list for which particle's trajectory within the detector is saved. More...
 
elements
 STL member. More...
 

Protected Attributes

double _x_max
 x-max of volume box used to determine whether to save track information More...
 
double _x_min
 x-min of volume box used to determine whether to save track information More...
 
double _y_max
 y-max of volume box used to determine whether to save track information More...
 
double _y_min
 y-min of volume box used to determine whether to save track information More...
 
double _z_max
 z-max of volume box used to determine whether to save track information More...
 
double _z_min
 z-min of volume box used to determine whether to save track information More...
 
std::vector< unsigned int > _trackIDOffsets
 Track ID offsets for different MCTruths. More...
 

Detailed Description

Definition at line 91 of file MCRecoPart.h.

Constructor & Destructor Documentation

sim::MCRecoPart::MCRecoPart ( fhicl::ParameterSet const &  pset)

Default constructor with fhicl parameters.

Definition at line 19 of file MCRecoPart.cxx.

References _pdg_list, _track_index, _trackIDOffsets, _x_max, _x_min, _y_max, _y_min, _z_max, _z_min, clear(), and geo::GeometryCore::Iterate().

20  : _x_max{std::numeric_limits<double>::min()}
21  , _x_min{std::numeric_limits<double>::max()}
22  , _y_max{std::numeric_limits<double>::min()}
23  , _y_min{std::numeric_limits<double>::max()}
24  , _z_max{std::numeric_limits<double>::min()}
25  , _z_min{std::numeric_limits<double>::max()}
26  , _trackIDOffsets{pset.get<std::vector<unsigned int>>("TrackIDOffsets", {0})}
27  {
28  this->clear();
29  _track_index.clear();
30  _pdg_list.clear();
31  for (auto const& id : pset.get<std::vector<int>>("SavePathPDGList"))
32 
33  _pdg_list.insert(id);
34 
36  // Build "Fiducial" Volume Definition:
37  //
38  // Iterate over all TPC's to get bounding box that covers volumes of each individual TPC in the detector
39  for (auto const& tpc : geo->Iterate<geo::TPCGeo>()) {
40  _x_max = std::max(_x_max, tpc.BoundingBox().MaxX());
41  _x_min = std::min(_x_min, tpc.BoundingBox().MinX());
42  _y_max = std::max(_y_max, tpc.BoundingBox().MaxY());
43  _y_min = std::min(_y_min, tpc.BoundingBox().MinY());
44  _z_max = std::max(_z_max, tpc.BoundingBox().MaxZ());
45  _z_min = std::min(_z_min, tpc.BoundingBox().MinZ());
46  }
47  }
details::range_type< T > Iterate() const
Initializes the specified ID with the ID of the first cryostat.
Definition: GeometryCore.h:541
double _z_max
z-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:134
Geometry information for a single TPC.
Definition: TPCGeo.h:36
double _y_max
y-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:132
double _y_min
y-min of volume box used to determine whether to save track information
Definition: MCRecoPart.h:133
std::map< unsigned int, unsigned int > _track_index
Track ID => Index Map.
Definition: MCRecoPart.h:123
double _z_min
z-min of volume box used to determine whether to save track information
Definition: MCRecoPart.h:135
std::vector< unsigned int > _trackIDOffsets
Track ID offsets for different MCTruths.
Definition: MCRecoPart.h:136
double _x_max
x-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:130
double _x_min
x-min of volume box used to determine whether to save track information
Definition: MCRecoPart.h:131
std::set< int > _pdg_list
PDG code list for which particle&#39;s trajectory within the detector is saved.
Definition: MCRecoPart.h:127
Namespace collecting geometry-related classes utilities.
vec_iX clear()
virtual sim::MCRecoPart::~MCRecoPart ( )
inlinevirtual

Default destructor.

Definition at line 98 of file MCRecoPart.h.

98 {};

Member Function Documentation

void sim::MCRecoPart::AddParticles ( const std::vector< simb::MCParticle > &  mcp_v,
const std::vector< simb::Origin_t > &  orig_v,
const std::vector< simb::MCParticle > &  mcmp_v = {} 
)

Definition at line 133 of file MCRecoPart.cxx.

References _pdg_list, _track_index, clear(), InDetector(), and util::size().

Referenced by MCReco::produce().

137  {
138  if (orig_v.size() != mcp_v.size())
139  throw cet::exception(__FUNCTION__) << "MCParticle and Origin_t vector size not same!";
140 
141  this->clear();
142  _track_index.clear();
143 
144  for (size_t i = 0; i < mcp_v.size(); ++i) {
145 
146  auto const& mcp = mcp_v[i];
147 
148  //std::cout<<" Track ID : "<<mcp.TrackId()<<" ... Index : " <<this->size()<<std::endl;
149 
150  _track_index.insert(std::make_pair((size_t)(mcp.TrackId()), (size_t)(this->size())));
151 
152  // Change units to LArSoft (MeV, cm, us)
153  // (done inside constructor of MCMiniPart)
154  this->push_back(MCMiniPart(mcp));
155 
156  auto& mini_mcp = (*this->rbegin());
157 
158  for (size_t i = 0; i < (size_t)(mcp.NumberDaughters()); ++i) {
159  mini_mcp.AddDaughter(mcp.Daughter(i));
160  }
161  mini_mcp._origin = orig_v[i];
162 
163  if (_pdg_list.find(mcp.PdgCode()) != _pdg_list.end()) {
164 
165  std::set<size_t> det_path_index;
166 
167  for (size_t i = 0; i < mcp.NumberTrajectoryPoints(); ++i) {
168 
169  if (InDetector(mcp.Vx(i), mcp.Vy(i), mcp.Vz(i))) det_path_index.insert(i);
170  }
171 
172  if (det_path_index.size()) {
173  if ((*det_path_index.begin())) det_path_index.insert((*det_path_index.begin()) - 1);
174  if (det_path_index.size() > 1) {
175  if (((*det_path_index.rbegin()) + 1) < mcp.NumberTrajectoryPoints())
176  det_path_index.insert((*det_path_index.rbegin()) + 1);
177  }
178  std::vector<std::pair<TLorentzVector, TLorentzVector>> det_path;
179  det_path.reserve(det_path_index.size());
180  for (auto const& index : det_path_index) {
181 
182  TLorentzVector vec(mcp.Momentum(index));
183  for (size_t i = 0; i < 4; ++i)
184  vec[i] *= 1.e3;
185 
186  det_path.emplace_back(mcp.Position(index), vec);
187  }
188  mini_mcp._det_path = std::move(det_path);
189  }
190  } // end if in _pdg_list
191  } // end for loop over mcp_v
192 
193  // Now loop over dropped particles
194  for (auto const& mcmp : mcmp_v) {
195 
196  _track_index.try_emplace(mcmp.TrackId(), this->size());
197 
198  this->push_back(sim::MCMiniPart(mcmp));
199 
200  } // end for loop over mcmp_v
201  } // end AddParticles
std::map< unsigned int, unsigned int > _track_index
Track ID => Index Map.
Definition: MCRecoPart.h:123
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::set< int > _pdg_list
PDG code list for which particle&#39;s trajectory within the detector is saved.
Definition: MCRecoPart.h:127
bool InDetector(const double &x, const double &y, const double &z) const
Definition: MCRecoPart.cxx:126
vec_iX clear()
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
unsigned int sim::MCRecoPart::AncestorTrackID ( const unsigned int  part_index)

Definition at line 76 of file MCRecoPart.cxx.

References _trackIDOffsets, sim::kINVALID_UINT, MotherTrackID(), util::size(), and TrackToParticleIndex().

Referenced by sim::MCTrackRecoAlg::Reconstruct(), and sim::MCShowerRecoAlg::Reconstruct().

78  {
79  if (part_index >= this->size()) return kINVALID_UINT;
80 
81  if ((*this)[part_index]._ancestor != kINVALID_UINT) return (*this)[part_index]._ancestor;
82 
83  auto result = MotherTrackID(part_index);
84 
85  if (result == this->at(part_index)._track_id) return result;
86 
87  //Is a primary particle. Account for possible track ID offsets
88  for (auto const& offset : _trackIDOffsets) {
89  if (result == offset) return this->at(part_index)._track_id;
90  }
91 
92  auto mother_index = TrackToParticleIndex(result);
93 
94  while (1) {
95 
96  if (mother_index != kINVALID_UINT) {
97 
98  auto const new_result = MotherTrackID(mother_index);
99 
100  if (new_result == this->at(mother_index)._track_id) break;
101 
102  result = new_result;
103  }
104  else {
105 
106  // Look for a particle that has a daughter = this mother
107  auto const old_result = result;
108  for (auto const& p : *this) {
109 
110  if (p.HasDaughter(result)) {
111  result = p._track_id;
112  break;
113  }
114  }
115  if (result == old_result) break;
116  }
117 
118  mother_index = TrackToParticleIndex(result);
119  }
120 
121  (*this)[part_index]._ancestor = result;
122  return result;
123  }
unsigned int MotherTrackID(const unsigned int part_index) const
Definition: MCRecoPart.cxx:50
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::vector< unsigned int > _trackIDOffsets
Track ID offsets for different MCTruths.
Definition: MCRecoPart.h:136
const unsigned int kINVALID_UINT
Definition: MCLimits.h:14
unsigned int TrackToParticleIndex(const unsigned int track_id) const
Definition: MCRecoPart.h:112
bool sim::MCRecoPart::InDetector ( const double &  x,
const double &  y,
const double &  z 
) const

Definition at line 126 of file MCRecoPart.cxx.

References _x_max, _y_max, _y_min, _z_max, x, and y.

Referenced by AddParticles().

128  {
129  return !(x > _x_max || x < _x_min || z > _z_max || z < _z_min || y > _y_max || y < _y_min);
130  }
Float_t x
Definition: compare.C:6
double _z_max
z-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:134
Float_t y
Definition: compare.C:6
double _y_max
y-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:132
double _y_min
y-min of volume box used to determine whether to save track information
Definition: MCRecoPart.h:133
double _x_max
x-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:130
unsigned int sim::MCRecoPart::MotherTrackID ( const unsigned int  part_index) const

Definition at line 50 of file MCRecoPart.cxx.

References _trackIDOffsets, sim::kINVALID_UINT, part, util::size(), and TrackToParticleIndex().

Referenced by AncestorTrackID(), sim::MCTrackRecoAlg::Reconstruct(), and sim::MCShowerRecoAlg::Reconstruct().

52  {
53  if (this->size() <= part_index) return ::sim::kINVALID_UINT;
54 
55  unsigned int result = this->at(part_index)._mother;
56 
57  //Is a primary particle. Account for possible track ID offsets
58  for (auto const& offset : _trackIDOffsets) {
59  if (result == offset) return this->at(part_index)._track_id;
60  }
61 
62  if (TrackToParticleIndex(result) != ::sim::kINVALID_UINT) return result;
63 
64  //std::cout<< "\033[95mWarning:\033[00m Mother particle not in the particle list!"<<std::endl;
65  // Do brute search
66  unsigned int daughter_id = this->at(part_index)._track_id;
67 
68  for (auto const& part : *this) {
69 
70  if (part.HasDaughter(daughter_id)) return part._track_id;
71  }
72  return result;
73  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
TString part[npart]
Definition: Style.C:32
std::vector< unsigned int > _trackIDOffsets
Track ID offsets for different MCTruths.
Definition: MCRecoPart.h:136
const unsigned int kINVALID_UINT
Definition: MCLimits.h:14
unsigned int TrackToParticleIndex(const unsigned int track_id) const
Definition: MCRecoPart.h:112
unsigned int sim::MCRecoPart::TrackToParticleIndex ( const unsigned int  track_id) const
inline

Definition at line 112 of file MCRecoPart.h.

References sim::kINVALID_UINT.

Referenced by AncestorTrackID(), MotherTrackID(), sim::MCTrackRecoAlg::Reconstruct(), and sim::MCShowerRecoAlg::Reconstruct().

113  {
114  auto const iter(_track_index.find(track_id));
115  if (iter == _track_index.end()) return kINVALID_UINT;
116  return (*iter).second;
117  }
std::map< unsigned int, unsigned int > _track_index
Track ID => Index Map.
Definition: MCRecoPart.h:123
const unsigned int kINVALID_UINT
Definition: MCLimits.h:14

Member Data Documentation

std::set<int> sim::MCRecoPart::_pdg_list

PDG code list for which particle's trajectory within the detector is saved.

Definition at line 127 of file MCRecoPart.h.

Referenced by AddParticles(), MCRecoPart(), and sim::MCTrackRecoAlg::Reconstruct().

std::map<unsigned int, unsigned int> sim::MCRecoPart::_track_index

Track ID => Index Map.

Definition at line 123 of file MCRecoPart.h.

Referenced by AddParticles(), sim::MCShowerRecoPart::ConstructShower(), and MCRecoPart().

std::vector<unsigned int> sim::MCRecoPart::_trackIDOffsets
protected

Track ID offsets for different MCTruths.

Definition at line 136 of file MCRecoPart.h.

Referenced by AncestorTrackID(), MCRecoPart(), and MotherTrackID().

double sim::MCRecoPart::_x_max
protected

x-max of volume box used to determine whether to save track information

Definition at line 130 of file MCRecoPart.h.

Referenced by InDetector(), and MCRecoPart().

double sim::MCRecoPart::_x_min
protected

x-min of volume box used to determine whether to save track information

Definition at line 131 of file MCRecoPart.h.

Referenced by MCRecoPart().

double sim::MCRecoPart::_y_max
protected

y-max of volume box used to determine whether to save track information

Definition at line 132 of file MCRecoPart.h.

Referenced by InDetector(), and MCRecoPart().

double sim::MCRecoPart::_y_min
protected

y-min of volume box used to determine whether to save track information

Definition at line 133 of file MCRecoPart.h.

Referenced by InDetector(), and MCRecoPart().

double sim::MCRecoPart::_z_max
protected

z-max of volume box used to determine whether to save track information

Definition at line 134 of file MCRecoPart.h.

Referenced by InDetector(), and MCRecoPart().

double sim::MCRecoPart::_z_min
protected

z-min of volume box used to determine whether to save track information

Definition at line 135 of file MCRecoPart.h.

Referenced by MCRecoPart().

T std::vector< T >::elements
inherited

STL member.


The documentation for this class was generated from the following files: