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