LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MCRecoPart.h
Go to the documentation of this file.
1 #ifndef MCRECOPART_H
2 #define MCRECOPART_H
3 
4 // ART includes
5 namespace fhicl {
6  class ParameterSet;
7 }
8 
9 // LArSoft
10 #include "lardataobj/MCBase/MCLimits.h" // kINVALID_X
12 #include "nusimdata/SimulationBase/MCTruth.h" // simb::Origin_t
13 
14 // STL
15 #include <set>
16 #include <utility> // std::pair<>
17 #include <vector>
18 
19 #include "TLorentzVector.h"
20 
21 namespace sim {
22 
23  class MCMiniPart {
24 
25  public:
26  MCMiniPart() { Reset(); }
27 
28  virtual ~MCMiniPart() {}
29 
30  unsigned int _track_id;
31  std::string _process;
32  unsigned int _mother;
33  unsigned int _ancestor;
34  int _pdgcode;
35  TLorentzVector _start_vtx;
36  TLorentzVector _start_mom;
37  TLorentzVector _end_vtx;
38  TLorentzVector _end_mom;
39  std::vector<std::pair<TLorentzVector, TLorentzVector>> _det_path;
40  std::set<unsigned int> _daughters;
42 
43  void Reset()
44  {
45  _track_id = _mother = _ancestor = kINVALID_UINT;
46  _pdgcode = kINVALID_INT;
47  _process = "";
48  _origin = ::simb::kUnknown;
49 
51  _start_vtx = invalid;
52  _start_mom = invalid;
53  _end_vtx = invalid;
54  _end_mom = invalid;
55  _daughters.clear();
56  _det_path.clear();
57  }
58 
59  bool HasDaughter(unsigned int d) const
60  {
61  return std::find(_daughters.begin(), _daughters.end(), d) != _daughters.end();
62  }
63 
64  void AddDaughter(unsigned int d) { _daughters.insert(d); }
65 
66  operator simb::MCParticle() const
67  {
68  simb::MCParticle mcpart(_track_id, _pdgcode, _process, _mother);
69  // Also converting back from LArSoft units
70  mcpart.AddTrajectoryPoint(_start_vtx, 1.e-3 * _start_mom);
71  mcpart.AddTrajectoryPoint(_end_vtx, 1.e-3 * _end_mom);
72  for (auto const& d : _daughters)
73  mcpart.AddDaughter(d);
74  return mcpart;
75  }
76 
78  {
79  Reset();
80  _track_id = p.TrackId();
81  _pdgcode = p.PdgCode();
82  _mother = p.Mother();
83  _process = p.Process();
84  _start_vtx = p.Position();
85  _start_mom = 1.e3 * p.Momentum(); // Change units to (MeV, cm, us)
86  _end_vtx = p.EndPosition();
87  _end_mom = 1.e3 * p.EndMomentum(); // idem as above
88  }
89  };
90 
91  class MCRecoPart : public std::vector<sim::MCMiniPart> {
92 
93  public:
95  MCRecoPart(fhicl::ParameterSet const& pset);
96 
98  virtual ~MCRecoPart(){};
99 
100  void AddParticles(const std::vector<simb::MCParticle>& mcp_v,
101  const std::vector<simb::Origin_t>& orig_v,
102  const std::vector<simb::MCParticle>& mcmp_v = {});
103 
104  unsigned int AncestorTrackID(const unsigned int part_index);
105 
106  unsigned int MotherTrackID(const unsigned int part_index) const;
107 
108  /*
109  Take TrackID and returns the corresponding particle unique index number (MCParticle array index)
110  Returns kINVALID_UINT if nothing found.
111  */
112  unsigned int TrackToParticleIndex(const unsigned int track_id) const
113  {
114  auto const iter(_track_index.find(track_id));
115  if (iter == _track_index.end()) return kINVALID_UINT;
116  return (*iter).second;
117  }
118 
119  bool InDetector(const double& x, const double& y, const double& z) const;
120 
121  public:
123  std::map<unsigned int, unsigned int> _track_index;
124  //std::map<size_t,size_t> _track_index;
125 
127  std::set<int> _pdg_list;
128 
129  protected:
130  double _x_max;
131  double _x_min;
132  double _y_max;
133  double _y_min;
134  double _z_max;
135  double _z_min;
136  std::vector<unsigned int> _trackIDOffsets;
137 
138  }; // class MCRecoPart
139 
140 } //namespace cluster
141 #endif
Float_t x
Definition: compare.C:6
std::string _process
Definition: MCRecoPart.h:31
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:220
void AddDaughter(const int trackID)
Definition: MCParticle.h:269
int PdgCode() const
Definition: MCParticle.h:213
const int kINVALID_INT
Definition: MCLimits.h:16
double _z_max
z-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:134
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
Definition: MCParticle.h:258
const TLorentzVector & EndPosition() const
Definition: MCParticle.h:226
Unknown view.
Definition: geo_types.h:142
int Mother() const
Definition: MCParticle.h:214
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
enum simb::_ev_origin Origin_t
event origin types
virtual ~MCRecoPart()
Default destructor.
Definition: MCRecoPart.h:98
MCMiniPart(const simb::MCParticle &p)
Definition: MCRecoPart.h:77
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
std::string Process() const
Definition: MCParticle.h:216
Particle class.
TLorentzVector _start_vtx
Definition: MCRecoPart.h:35
int TrackId() const
Definition: MCParticle.h:211
TLorentzVector _start_mom
Definition: MCRecoPart.h:36
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
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
bool HasDaughter(unsigned int d) const
Definition: MCRecoPart.h:59
TLorentzVector _end_mom
Definition: MCRecoPart.h:38
ntupleExperimental Reset()
virtual ~MCMiniPart()
Definition: MCRecoPart.h:28
parameter set interface
std::vector< std::pair< TLorentzVector, TLorentzVector > > _det_path
Definition: MCRecoPart.h:39
Float_t d
Definition: plot.C:235
TLorentzVector _end_vtx
Definition: MCRecoPart.h:37
::simb::Origin_t _origin
Definition: MCRecoPart.h:41
Monte Carlo Simulation.
unsigned int _mother
Definition: MCRecoPart.h:32
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
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:221
const unsigned int kINVALID_UINT
Definition: MCLimits.h:14
unsigned int _track_id
Definition: MCRecoPart.h:30
static const double kINVALID_DOUBLE
Float_t e
Definition: plot.C:35
unsigned int TrackToParticleIndex(const unsigned int track_id) const
Definition: MCRecoPart.h:112
const TLorentzVector & EndMomentum() const
Definition: MCParticle.h:241
std::set< unsigned int > _daughters
Definition: MCRecoPart.h:40
void AddDaughter(unsigned int d)
Definition: MCRecoPart.h:64
unsigned int _ancestor
Definition: MCRecoPart.h:33