LArVoxelID.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file LArVoxelID.h
3 /// \brief Unique identifier for a given LAr voxel.
4 ///
5 /// \author seligman@nevis.columbia.edu
6 ////////////////////////////////////////////////////////////////////////
7 
8 /// This class defines a unique identifier for a given volume element
9 /// ("voxel") in the LAr volume. It is sortable, can be tested for
10 /// equality, and is persistent under ROOT I/O.
11 
12 /// (Actually, the term "voxel" is a mis-nomer, since we're also
13 /// keeping track of the time slice. What's a four-dimensional volume
14 /// element? A "tesseract element or "tessel"?)
15 
19 #include <TLorentzVector.h>
20 
21 #include <ostream>
22 
23 namespace sim {
24 
25  //----------------------------------------------------------------------------
26  /// Expert constructor based on actual bins.
28  const int y,
29  const int z,
30  const int t )
31  {
32  fbins = std::vector<int>(4);
33  fbins[0] = x;
34  fbins[1] = y;
35  fbins[2] = z;
36  fbins[3] = t;
37 
38  }
39 
40  //----------------------------------------------------------------------------
41  /// Standard constructors.
42  LArVoxelID::LArVoxelID( const TLorentzVector& coord )
43  {
44  // Copy each axis from the vector and convert it to a bin.
45  fbins = std::vector<int>(4);
47  for ( Ssiz_t a = 0; a != 4; ++a ){
48  fbins[a] = voxelCalc->AxisToBin( a, coord[a] );
49  }
50  }
51 
52  //----------------------------------------------------------------------------
53  LArVoxelID::LArVoxelID( const double x, const double y, const double z, const double t )
54  {
56 
57  // Convert each axis into its corresponding bin.
58  fbins = std::vector<int>(4);
59  fbins[0] = voxelCalc->XAxisToBin( x );
60  fbins[1] = voxelCalc->YAxisToBin( y );
61  fbins[2] = voxelCalc->ZAxisToBin( z );
62  fbins[3] = voxelCalc->TAxisToBin( t );
63  }
64 
65  //----------------------------------------------------------------------------
66  /// Destructor.
68 
69  //----------------------------------------------------------------------------
70  /// The accessors I expect to be used: The values of the
71  /// co-ordinates at the bin centers.
72  double LArVoxelID::X() const
73  {
75  return voxelCalc->XBinToAxis(fbins[0]);
76  }
77 
78  //----------------------------------------------------------------------------
79  double LArVoxelID::Y() const
80  {
82  return voxelCalc->YBinToAxis(fbins[1]);
83  }
84 
85  //----------------------------------------------------------------------------
86  double LArVoxelID::Z() const
87  {
89  return voxelCalc->ZBinToAxis(fbins[2]);
90  }
91 
92  //----------------------------------------------------------------------------
93  double LArVoxelID::T() const
94  {
96  return voxelCalc->TBinToAxis(fbins[3]);
97  }
98 
99  //----------------------------------------------------------------------------
100  double LArVoxelID::operator[]( const int i ) const
101  {
102  switch (i){
103  case 0:
104  return X(); break;
105  case 1:
106  return Y(); break;
107  case 2:
108  return Z(); break;
109  case 3:
110  return T(); break;
111  }
112  // I suppose I should put some error processing here; for now
113  // I'll just return zero.
114  return 0;
115  }
116 
117  //----------------------------------------------------------------------------
118  /// Put the contents on the output stream. We have a choice: write
119  /// the bin number, or write the position represented by the bins.
120  /// For now, let's pick writing the positions.
121  std::ostream& operator<< ( std::ostream& output, const LArVoxelID& id )
122  {
123  output << "(" << id.X()
124  << "," << id.Y()
125  << "," << id.Z()
126  << "," << id.T()
127  << ")";
128 
129  return output;
130  }
131 
132  //----------------------------------------------------------------------------
133  /// The comparison operator. This a key function, since it
134  /// establishes the sort order of the voxels in a list.
136  {
137  // What is a good sort order for voxels in the list? I'm not sure.
138  // For now, pick an ordering but be prepared to change it: sort by
139  // T, Z, X, then Y.
140 
141  if ( fbins[3] < other.fbins[3] ) return true;
142 
143  if ( fbins[3] == other.fbins[3] ){
144  if ( fbins[2] < other.fbins[2] ) return true;
145 
146  if ( fbins[2] == other. fbins[2] ){
147  if ( fbins[0] < other.fbins[0] ) return true;
148 
149  if ( fbins[0] == other.fbins[0] ){
150  if ( fbins[1] < other.fbins[1] ) return true;
151  }
152  }
153  }
154 
155  return false;
156  }
157 
158  //----------------------------------------------------------------------------
159  /// Test for equality. Handy, but not usually necessary.
161  {
162  if ( fbins[0] == other.fbins[0] &&
163  fbins[1] == other.fbins[1] &&
164  fbins[2] == other.fbins[2] &&
165  fbins[3] == other.fbins[3] )
166  return true;
167 
168  return false;
169  }
170 
171  //----------------------------------------------------------------------------
172  LArVoxelID::operator TLorentzVector() const
173  {
174  return TLorentzVector( X(), Y(), Z(), T() );
175  }
176 
177  //----------------------------------------------------------------------------
178  LArVoxelID::operator TVector3() const
179  {
180  return TVector3( X(), Y(), Z() );
181  }
182 
183 
184 } // namespace sim
std::vector< int > fbins
Definition: LArVoxelID.h:91
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
double YBinToAxis(const int value) const
Encapsulates calculation of LArVoxelID and LArVoxel parameters.
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
bool operator<(const LArVoxelID &) const
Definition: LArVoxelID.cxx:135
int ZAxisToBin(const double value) const
double operator[](const int) const
Definition: LArVoxelID.cxx:100
virtual ~LArVoxelID()
Destructor.
Definition: LArVoxelID.cxx:67
double TBinToAxis(const int value) const
int XAxisToBin(const double value) const
double Y() const
Definition: LArVoxelID.cxx:79
const double a
int TAxisToBin(const double value) const
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
Code to link reconstructed objects back to the MC truth information.
double Z() const
Definition: LArVoxelID.cxx:86
double X() const
Definition: LArVoxelID.cxx:72
double XBinToAxis(const int value) const
double T() const
Definition: LArVoxelID.cxx:93
list x
Definition: train.py:276
double ZBinToAxis(const int value) const
Unique identifier for a given LAr voxel.
int YAxisToBin(const double value) const