LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArVoxelID.h
Go to the documentation of this file.
1 
42 #ifndef sim_LArVoxelID_h
43 #define sim_LArVoxelID_h
44 
45 #include <TLorentzVector.h>
46 #include <TVector3.h>
47 
48 #include <functional> // so we can redefine less<> below
49 #include <iosfwd>
50 #include <vector>
51 
52 namespace sim {
53 
54  class LArVoxelID {
55  public:
56  // What is an appropriate storage class for an element of the bin
57  // ID? Probably a regular integer is the only thing we can use; a
58  // "short int" can only accept values up to +/-32767, and a large
59  // LAr TPC will probably contain more bins on a single axis than
60  // that.
61 
62  // Construct a voxel identifier given the pre-computed bins. This
63  // one is provided for completeness, but it's not the one I
64  // anticipate the clients will use. Note that it's also serves
65  // as the no-argument constructor that ROOT requires for I/O.
66  LArVoxelID(const int x = 0, const int y = 0, const int z = 0, const int t = 0);
67 
68  // The constructors that I expect most clients to use: Given the
69  // (x,y,z,t) in units of (distance,time) of a particle, compute
70  // the voxel identifier. Note that units are ambiguous there; they
71  // have to be consistent between those used by LArVoxelCalculator
72  // and the Monte Carlo, but this class does not enforce that
73  // consistency.
74  explicit LArVoxelID(const TLorentzVector& v);
75  LArVoxelID(const double x, const double y, const double z, const double t);
76 
77  // Destructor.
78  virtual ~LArVoxelID();
79 
80  private:
81  // Implement the bin ID as a "tuple" of four numbers, one bin for
82  // each (x,y,z,t) axis.
83 
84  std::vector<int> fbins; // (x,y,z,t) bins.
85 
86  public:
87  // Accessors for the bin values. I don't expect these to be used
88  // often, but include them for completeness.
89  int XBin() const;
90  int YBin() const;
91  int ZBin() const;
92  int TBin() const;
93 
94  // The accessors I expect to be used: The values of the
95  // co-ordinates at the bin centers.
96  double X() const;
97  double Y() const;
98  double Z() const;
99  double T() const;
100 
101  // Alternative accessor: Pretend the LArVoxelID is a vector that
102  // takes subscripts, and returns the bin centers of the axis in
103  // the square brackets (x=0, y=1, z=2, t=3).
104  double operator[](const int) const;
105 
106  // Conversion function from LArVoxelID to a TLorentzVector. This
107  // lets you do something like:
108  // sim::LArVoxelID larVoxelID = ... // whatever
109  // TLorentzVector v = TLorentzVector( larVoxelID );
110  operator TLorentzVector() const;
111 
112  // The three-vector version of the above conversion; e.g.:
113  // sim::LArVoxelID larVoxelID = ... // whatever
114  // TLVector3 v = TVector3( larVoxelID );
115  operator TVector3() const;
116 
117  // The comparison operator. This a key function, since it
118  // establishes the sort order of the voxels in a list.
119  bool operator<(const LArVoxelID&) const;
120 
121  // Test for equality. Handy, but not usually necessary.
122  bool operator==(const LArVoxelID&) const;
123 
124  friend std::ostream& operator<<(std::ostream& output, const LArVoxelID&);
125  };
126 
127 } // sim
128 
129 inline int sim::LArVoxelID::XBin() const
130 {
131  return fbins[0];
132 }
133 inline int sim::LArVoxelID::YBin() const
134 {
135  return fbins[1];
136 }
137 inline int sim::LArVoxelID::ZBin() const
138 {
139  return fbins[2];
140 }
141 inline int sim::LArVoxelID::TBin() const
142 {
143  return fbins[3];
144 }
145 
146 // A potentially handy definition: At this stage, I'm not sure
147 // whether I'm going to be keeping a list based on LArVoxelID or on
148 // LArVoxelID*. We've already defined operator<(LArVoxelID,LArVoxelID),
149 // that is, how to compare two LArVoxelID objects; by default that
150 // also defines std::less<LArVoxelID>, which is what the STL containers
151 // use for comparisons.
152 
153 // The following defines std::less<LArVoxelID*>, that is, how to
154 // compare two LArVoxelID*: by looking at the objects, not at the
155 // pointer addresses. The result is that, e.g., a
156 // map<LArVoxelID*,double> will be sorted in the order I expect.
157 
158 namespace std {
159  template <>
160  class less<sim::LArVoxelID*> {
161  public:
162  bool operator()(const sim::LArVoxelID* lhs, const sim::LArVoxelID* rhs)
163  {
164  return (*lhs) < (*rhs);
165  }
166  };
167 } // std
168 
169 #endif // sim_LArVoxelID_h
Float_t x
Definition: compare.C:6
std::vector< int > fbins
Definition: LArVoxelID.h:84
int ZBin() const
Definition: LArVoxelID.h:137
LArVoxelID(const int x=0, const int y=0, const int z=0, const int t=0)
Expert constructor based on actual bins.
Definition: LArVoxelID.cxx:27
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
bool operator<(const LArVoxelID &) const
Definition: LArVoxelID.cxx:123
double operator[](const int) const
Definition: LArVoxelID.cxx:96
virtual ~LArVoxelID()
Destructor.
Definition: LArVoxelID.cxx:63
STL namespace.
int XBin() const
Definition: LArVoxelID.h:129
int TBin() const
Definition: LArVoxelID.h:141
double Y() const
Definition: LArVoxelID.cxx:75
int YBin() const
Definition: LArVoxelID.h:133
bool operator==(const LArVoxelID &) const
Test for equality. Handy, but not usually necessary.
Definition: LArVoxelID.cxx:148
friend std::ostream & operator<<(std::ostream &output, const LArVoxelID &)
Definition: LArVoxelID.cxx:113
Monte Carlo Simulation.
double Z() const
Definition: LArVoxelID.cxx:82
bool operator()(const sim::LArVoxelID *lhs, const sim::LArVoxelID *rhs)
Definition: LArVoxelID.h:162
double X() const
Definition: LArVoxelID.cxx:68
double T() const
Definition: LArVoxelID.cxx:89