All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArVoxelID.h
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 ///
16 /// A LArVoxelID is created by supplying the (x,y,z,t) co-ordinates,
17 /// which can be in the form of a TLorentzVector:
18 ///
19 /// sim::LArVoxelID id(1,2,3,4);
20 /// TLorentzVector v(1,2,3,4);
21 /// sim::LArVoxelID otherID(v);
22 ///
23 /// There are several ways to "get" at the contents of a LArVoxelID:
24 ///
25 /// sim::LArVoxelID id;
26 /// double x = id.X(); // axis-by-axis
27 /// int xBinNumber = id.XBin(); // bin number; might be useful for debugging
28 /// TLorentzVector pos(id); // convert to TLorentzVector
29 ///
30 /// Note that the first and third methods above both return the
31 /// bin-center value(s).
32 ///
33 /// If you need to know the sizes of the bins (voxels), see
34 /// LArVoxelCalculator.
35 ///
36 /// Output methods are implemented so this class can be a good
37 /// "citizen":
38 ///
39 /// sim::LArVoxelID voxelID;
40 /// std::cout << voxelID << std::endl; // C++ ostream method
41 
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 <iosfwd>
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  public:
94  // Accessors for the bin values. I don't expect these to be used
95  // often, but include them for completeness.
96  int XBin() const;
97  int YBin() const;
98  int ZBin() const;
99  int TBin() const;
100 
101  // The accessors I expect to be used: The values of the
102  // co-ordinates at the bin centers.
103  double X() const;
104  double Y() const;
105  double Z() const;
106  double T() const;
107 
108  // Alternative accessor: Pretend the LArVoxelID is a vector that
109  // takes subscripts, and returns the bin centers of the axis in
110  // the square brackets (x=0, y=1, z=2, t=3).
111  double operator[]( const int ) const;
112 
113  // Conversion function from LArVoxelID to a TLorentzVector. This
114  // lets you do something like:
115  // sim::LArVoxelID larVoxelID = ... // whatever
116  // TLorentzVector v = TLorentzVector( larVoxelID );
117  operator TLorentzVector() const;
118 
119  // The three-vector version of the above conversion; e.g.:
120  // sim::LArVoxelID larVoxelID = ... // whatever
121  // TLVector3 v = TVector3( larVoxelID );
122  operator TVector3() const;
123 
124  // The comparison operator. This a key function, since it
125  // establishes the sort order of the voxels in a list.
126  bool operator<( const LArVoxelID& ) const;
127 
128  // Test for equality. Handy, but not usually necessary.
129  bool operator==( const LArVoxelID& ) const;
130 
131  friend std::ostream& operator<< ( std::ostream& output, const LArVoxelID& );
132 
133  };
134 
135 } // sim
136 
137 inline int sim::LArVoxelID::XBin() const { return fbins[0]; }
138 inline int sim::LArVoxelID::YBin() const { return fbins[1]; }
139 inline int sim::LArVoxelID::ZBin() const { return fbins[2]; }
140 inline int sim::LArVoxelID::TBin() const { return fbins[3]; }
141 
142 // A potentially handy definition: At this stage, I'm not sure
143 // whether I'm going to be keeping a list based on LArVoxelID or on
144 // LArVoxelID*. We've already defined operator<(LArVoxelID,LArVoxelID),
145 // that is, how to compare two LArVoxelID objects; by default that
146 // also defines std::less<LArVoxelID>, which is what the STL containers
147 // use for comparisons.
148 
149 // The following defines std::less<LArVoxelID*>, that is, how to
150 // compare two LArVoxelID*: by looking at the objects, not at the
151 // pointer addresses. The result is that, e.g., a
152 // map<LArVoxelID*,double> will be sorted in the order I expect.
153 
154 namespace std {
155  template <>
156  class less<sim::LArVoxelID*>
157  {
158  public:
159  bool operator()( const sim::LArVoxelID* lhs, const sim::LArVoxelID* rhs )
160  {
161  return (*lhs) < (*rhs);
162  }
163  };
164 } // std
165 
166 #endif // sim_LArVoxelID_h
std::vector< int > fbins
Definition: LArVoxelID.h:91
process_name opflash particleana ie ie ie z
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
int ZBin() const
Definition: LArVoxelID.h:139
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
process_name opflash particleana ie x
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
int XBin() const
Definition: LArVoxelID.h:137
int TBin() const
Definition: LArVoxelID.h:140
process_name opflash particleana ie ie y
double Y() const
Definition: LArVoxelID.cxx:79
int YBin() const
Definition: LArVoxelID.h:138
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
double Z() const
Definition: LArVoxelID.cxx:86
bool operator()(const sim::LArVoxelID *lhs, const sim::LArVoxelID *rhs)
Definition: LArVoxelID.h:159
double X() const
Definition: LArVoxelID.cxx:72
double T() const
Definition: LArVoxelID.cxx:93
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output