LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArVoxelID.cxx
Go to the documentation of this file.
1 
11 
15 
19 #include <TLorentzVector.h>
20 
21 #include <ostream>
22 
23 namespace sim {
24 
25  //----------------------------------------------------------------------------
27  LArVoxelID::LArVoxelID(const int x, const int y, const int z, const int t)
28  {
29  fbins = std::vector<int>(4);
30  fbins[0] = x;
31  fbins[1] = y;
32  fbins[2] = z;
33  fbins[3] = t;
34  }
35 
36  //----------------------------------------------------------------------------
38  LArVoxelID::LArVoxelID(const TLorentzVector& coord)
39  {
40  // Copy each axis from the vector and convert it to a bin.
41  fbins = std::vector<int>(4);
43  for (Ssiz_t a = 0; a != 4; ++a) {
44  fbins[a] = voxelCalc->AxisToBin(a, coord[a]);
45  }
46  }
47 
48  //----------------------------------------------------------------------------
49  LArVoxelID::LArVoxelID(const double x, const double y, const double z, const double t)
50  {
52 
53  // Convert each axis into its corresponding bin.
54  fbins = std::vector<int>(4);
55  fbins[0] = voxelCalc->XAxisToBin(x);
56  fbins[1] = voxelCalc->YAxisToBin(y);
57  fbins[2] = voxelCalc->ZAxisToBin(z);
58  fbins[3] = voxelCalc->TAxisToBin(t);
59  }
60 
61  //----------------------------------------------------------------------------
64 
65  //----------------------------------------------------------------------------
68  double LArVoxelID::X() const
69  {
71  return voxelCalc->XBinToAxis(fbins[0]);
72  }
73 
74  //----------------------------------------------------------------------------
75  double LArVoxelID::Y() const
76  {
78  return voxelCalc->YBinToAxis(fbins[1]);
79  }
80 
81  //----------------------------------------------------------------------------
82  double LArVoxelID::Z() const
83  {
85  return voxelCalc->ZBinToAxis(fbins[2]);
86  }
87 
88  //----------------------------------------------------------------------------
89  double LArVoxelID::T() const
90  {
92  return voxelCalc->TBinToAxis(fbins[3]);
93  }
94 
95  //----------------------------------------------------------------------------
96  double LArVoxelID::operator[](const int i) const
97  {
98  switch (i) {
99  case 0: return X(); break;
100  case 1: return Y(); break;
101  case 2: return Z(); break;
102  case 3: return T(); break;
103  }
104  // I suppose I should put some error processing here; for now
105  // I'll just return zero.
106  return 0;
107  }
108 
109  //----------------------------------------------------------------------------
113  std::ostream& operator<<(std::ostream& output, const LArVoxelID& id)
114  {
115  output << "(" << id.X() << "," << id.Y() << "," << id.Z() << "," << id.T() << ")";
116 
117  return output;
118  }
119 
120  //----------------------------------------------------------------------------
124  {
125  // What is a good sort order for voxels in the list? I'm not sure.
126  // For now, pick an ordering but be prepared to change it: sort by
127  // T, Z, X, then Y.
128 
129  if (fbins[3] < other.fbins[3]) return true;
130 
131  if (fbins[3] == other.fbins[3]) {
132  if (fbins[2] < other.fbins[2]) return true;
133 
134  if (fbins[2] == other.fbins[2]) {
135  if (fbins[0] < other.fbins[0]) return true;
136 
137  if (fbins[0] == other.fbins[0]) {
138  if (fbins[1] < other.fbins[1]) return true;
139  }
140  }
141  }
142 
143  return false;
144  }
145 
146  //----------------------------------------------------------------------------
149  {
150  if (fbins[0] == other.fbins[0] && fbins[1] == other.fbins[1] && fbins[2] == other.fbins[2] &&
151  fbins[3] == other.fbins[3])
152  return true;
153 
154  return false;
155  }
156 
157  //----------------------------------------------------------------------------
158  LArVoxelID::operator TLorentzVector() const
159  {
160  return TLorentzVector(X(), Y(), Z(), T());
161  }
162 
163  //----------------------------------------------------------------------------
164  LArVoxelID::operator TVector3() const
165  {
166  return TVector3(X(), Y(), Z());
167  }
168 
169 } // namespace sim
Float_t x
Definition: compare.C:6
std::vector< int > fbins
Definition: LArVoxelID.h:84
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.
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
bool operator<(const LArVoxelID &) const
Definition: LArVoxelID.cxx:123
int ZAxisToBin(const double value) const
double operator[](const int) const
Definition: LArVoxelID.cxx:96
virtual ~LArVoxelID()
Destructor.
Definition: LArVoxelID.cxx:63
double TBinToAxis(const int value) const
int XAxisToBin(const double value) const
double Y() const
Definition: LArVoxelID.cxx:75
int TAxisToBin(const double value) const
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
double X() const
Definition: LArVoxelID.cxx:68
double XBinToAxis(const int value) const
double T() const
Definition: LArVoxelID.cxx:89
double ZBinToAxis(const int value) const
Unique identifier for a given LAr voxel.
int YAxisToBin(const double value) const