All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCRecoPart.h
Go to the documentation of this file.
1 #ifndef MCRECOPART_H
2 #define MCRECOPART_H
3 
4 // ART includes
5 namespace fhicl { class ParameterSet; }
6 
7 // LArSoft
8 #include "lardataobj/MCBase/MCLimits.h" // kINVALID_X
9 #include "lardataobj/MCBase/MCParticleLite.h" // sim::MCParticleLite
10 #include "nusimdata/SimulationBase/MCParticle.h"
11 #include "nusimdata/SimulationBase/MCTruth.h" // simb::Origin_t
12 
13 // STL
14 #include <set>
15 #include <utility> // std::pair<>
16 #include <vector>
17 
18 #include "TLorentzVector.h"
19 
20 namespace sim
21 {
22 
23  class MCMiniPart {
24 
25  public:
26 
28 
29  virtual ~MCMiniPart(){}
30 
31  unsigned int _track_id;
32  std::string _process;
33  unsigned int _mother;
34  unsigned int _ancestor;
35  int _pdgcode;
36  TLorentzVector _start_vtx;
37  TLorentzVector _start_mom;
38  TLorentzVector _end_vtx;
39  TLorentzVector _end_mom;
40  std::vector<std::pair<TLorentzVector,TLorentzVector> > _det_path;
41  std::set<unsigned int> _daughters;
42  ::simb::Origin_t _origin;
43 
44  void Reset(){
47  _process = "";
48  _origin = ::simb::kUnknown;
49 
50  TLorentzVector invalid(kINVALID_DOUBLE,
54  _start_vtx = invalid;
55  _start_mom = invalid;
56  _end_vtx = invalid;
57  _end_mom = invalid;
58  _daughters.clear();
59  _det_path.clear();
60  }
61 
62  bool HasDaughter(unsigned int d) const {
63  return std::find(_daughters.begin(), _daughters.end(), d) != _daughters.end();
64  }
65 
66  void AddDaughter(unsigned int d) {
67  _daughters.insert(d);
68  }
69 
70  operator simb::MCParticle() const {
71  simb::MCParticle mcpart(_track_id,
72  _pdgcode,
73  _process,
74  _mother);
75  // Also converting back from LArSoft units
76  mcpart.AddTrajectoryPoint(_start_vtx, 1.e-3 * _start_mom);
77  mcpart.AddTrajectoryPoint(_end_vtx, 1.e-3 * _end_mom);
78  for (auto const & d : _daughters) mcpart.AddDaughter(d);
79  return mcpart;
80  }
81 
82  MCMiniPart(const simb::MCParticle& p) {
83  Reset();
84  _track_id = p.TrackId();
85  _pdgcode = p.PdgCode();
86  _mother = p.Mother();
87  _process = p.Process();
88  _start_vtx = p.Position();
89  _start_mom = 1.e3 * p.Momentum(); // Change units to (MeV, cm, us)
90  _end_vtx = p.EndPosition();
91  _end_mom = 1.e3 * p.EndMomentum(); // idem as above
92  }
93 
95  Reset();
96  _track_id = p.TrackID();
97  _pdgcode = p.PdgCode();
98  _mother = p.Mother();
99  _process = p.Process();
100  _start_vtx = p.StartVtx();
101  _start_mom = 1.e3 * p.StartMom(); // Change units to (MeV, cm, us)
102  _end_vtx = p.EndVtx();
103  _end_mom = 1.e3 * p.EndMom(); // idem as above
104  }
105 
106  };
107 
108  class MCRecoPart : public std::vector<sim::MCMiniPart> {
109 
110  public:
111 
112  /// Default constructor with fhicl parameters
113  MCRecoPart(fhicl::ParameterSet const& pset);
114 
115  /// Default destructor
116  virtual ~MCRecoPart(){};
117 
118  void AddParticles(const std::vector<simb::MCParticle>& mcp_v,
119  const std::vector<simb::Origin_t>& orig_v,
120  const std::vector<sim::MCParticleLite>& mcmp_v = {});
121 
122  unsigned int AncestorTrackID(const unsigned int part_index);
123 
124  unsigned int MotherTrackID(const unsigned int part_index) const;
125 
126  /*
127  Take TrackID and returns the corresponding particle unique index number (MCParticle array index)
128  Returns kINVALID_UINT if nothing found.
129  */
130  unsigned int TrackToParticleIndex(const unsigned int track_id) const
131  {
132  auto const iter (_track_index.find(track_id));
133  if(iter==_track_index.end()) return kINVALID_UINT;
134  return (*iter).second;
135  }
136 
137  bool InDetector(const double& x,
138  const double& y,
139  const double& z) const;
140 
141  public:
142 
143  /// Track ID => Index Map
144  std::map<unsigned int, unsigned int> _track_index;
145  //std::map<size_t,size_t> _track_index;
146 
147  /// PDG code list for which particle's trajectory within the detector is saved
148  std::set<int> _pdg_list;
149 
150  protected:
151 
152  double _x_max; //!< x-max of volume box used to determine whether to save track information
153  double _x_min; //!< x-min of volume box used to determine whether to save track information
154  double _y_max; //!< y-max of volume box used to determine whether to save track information
155  double _y_min; //!< y-min of volume box used to determine whether to save track information
156  double _z_max; //!< z-max of volume box used to determine whether to save track information
157  double _z_min; //!< z-min of volume box used to determine whether to save track information
158 
159  }; // class MCRecoPart
160 
161 } //namespace cluster
162 #endif
std::string _process
Definition: MCRecoPart.h:32
const double kINVALID_DOUBLE
Definition: MCLimits.h:10
process_name opflash particleana ie ie ie z
const TLorentzVector & EndVtx() const
const int kINVALID_INT
Definition: MCLimits.h:16
const TLorentzVector & EndMom() const
const TLorentzVector & StartVtx() const
double _z_max
z-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:156
process_name opflash particleana ie x
void AddParticles(const std::vector< simb::MCParticle > &mcp_v, const std::vector< simb::Origin_t > &orig_v, const std::vector< sim::MCParticleLite > &mcmp_v={})
Definition: MCRecoPart.cxx:128
pdgs p
Definition: selectors.fcl:22
virtual ~MCRecoPart()
Default destructor.
Definition: MCRecoPart.h:116
MCMiniPart(const simb::MCParticle &p)
Definition: MCRecoPart.h:82
unsigned int MotherTrackID(const unsigned int part_index) const
Definition: MCRecoPart.cxx:42
double _y_max
y-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:154
double _y_min
y-min of volume box used to determine whether to save track information
Definition: MCRecoPart.h:155
Class def header for MCParticleLite data container.
std::map< unsigned int, unsigned int > _track_index
Track ID =&gt; Index Map.
Definition: MCRecoPart.h:144
TLorentzVector _start_vtx
Definition: MCRecoPart.h:36
std::vector< std::pair< TLorentzVector, TLorentzVector > > _det_path
Definition: MCRecoPart.h:40
TLorentzVector _start_mom
Definition: MCRecoPart.h:37
const std::string & Process() const
unsigned int Mother() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
double _z_min
z-min of volume box used to determine whether to save track information
Definition: MCRecoPart.h:157
unsigned int AncestorTrackID(const unsigned int part_index)
Definition: MCRecoPart.cxx:68
process_name opflash particleana ie ie y
bool HasDaughter(unsigned int d) const
Definition: MCRecoPart.h:62
MCMiniPart(const sim::MCParticleLite &p)
Definition: MCRecoPart.h:94
MCRecoPart(fhicl::ParameterSet const &pset)
Default constructor with fhicl parameters.
Definition: MCRecoPart.cxx:19
int PdgCode() const
TLorentzVector _end_mom
Definition: MCRecoPart.h:39
virtual ~MCMiniPart()
Definition: MCRecoPart.h:29
TLorentzVector _end_vtx
Definition: MCRecoPart.h:38
::simb::Origin_t _origin
Definition: MCRecoPart.h:42
unsigned int _mother
Definition: MCRecoPart.h:33
double _x_max
x-max of volume box used to determine whether to save track information
Definition: MCRecoPart.h:152
double _x_min
x-min of volume box used to determine whether to save track information
Definition: MCRecoPart.h:153
unsigned int TrackID() const
std::set< int > _pdg_list
PDG code list for which particle&#39;s trajectory within the detector is saved.
Definition: MCRecoPart.h:148
do i e
const unsigned int kINVALID_UINT
Definition: MCLimits.h:14
unsigned int _track_id
Definition: MCRecoPart.h:31
bool InDetector(const double &x, const double &y, const double &z) const
Definition: MCRecoPart.cxx:117
unsigned int TrackToParticleIndex(const unsigned int track_id) const
Definition: MCRecoPart.h:130
std::set< unsigned int > _daughters
Definition: MCRecoPart.h:41
void AddDaughter(unsigned int d)
Definition: MCRecoPart.h:66
const TLorentzVector & StartMom() const
unsigned int _ancestor
Definition: MCRecoPart.h:34