QwAnalysis
QwDetectorInfo.h
Go to the documentation of this file.
1 #ifndef QWDETECTORINFO_H
2 #define QWDETECTORINFO_H
3 
4 // System headers
5 #include <cmath>
6 #include <vector>
7 #include <string>
8 #include <iostream>
9 #include <algorithm>
10 
11 // ROOT headers
12 #include "TObject.h"
13 #include "TVector3.h"
14 
15 // Qweak headers
16 #include "QwTypes.h"
17 #include "QwLog.h"
18 
19 // Forward declarations
20 class QwParameterFile;
22 
23 ///
24 /// \ingroup QwTracking
25 class QwDetectorInfo: public TObject {
26  ///
27  /// Tracking detector information class. This will be used in an array
28  /// indexed by the package, plane, and wire,
29  ///
30 
31  public:
32 
33  /// Constructor with optional name
34  QwDetectorInfo(const std::string& name = "");
35 
36  // Load geometry information from parameter file
38 
39  // Load crosstalk information from parameter file
41 
42  // Get/set name
43  std::string GetDetectorName() const { return fDetectorName; };
44  void SetDetectorName(const std::string& name) { fDetectorName = name; };
45 
46  // Get/set spatial resolution
47  double GetSpatialResolution() const { return fSpatialResolution; };
48  void SetSpatialResolution(const double res) { fSpatialResolution = res; };
49 
50  // Get/set track resolution
51  double GetTrackResolution() const { return fTrackResolution; };
52  void SetTrackResolution(const double res) { fTrackResolution = res; };
53 
54  // Get/set slope matching
55  double GetSlopeMatching() const { return fSlopeMatching; };
56  void SetSlopeMatching(const double slope) { fSlopeMatching = slope; };
57 
58  // Get/set x and y position
59  const TVector3 GetPosition() const;
60  double GetXPosition() const { return fDetectorOriginX; };
61  double GetYPosition() const { return fDetectorOriginY; };
62  double GetZPosition() const { return fDetectorOriginZ; };
63  void SetPosition(const TVector3& position);
64  void SetZPosition(const double z) { fDetectorOriginZ = z; };
65  void SetXYPosition(const double x, const double y) {
66  fDetectorOriginX = x;
67  fDetectorOriginY = y;
68  };
69  void SetXYZPosition(const double x, const double y, const double z) {
70  SetXYPosition(x,y);
71  SetZPosition(z);
72  };
73 
74  // Get/set the octant
75  void SetOctant(const int octant) { fOctant = octant;};
76  int GetOctant() const {return fOctant; };
77 
78  // Get/set the plane offset
79  void SetPlaneOffset (double offset) { fPlaneOffset = offset; }
80  double GetPlaneOffset() const { return fPlaneOffset; }
81 
82  // Get/set active flag
83  bool IsActive() const { return fIsActive; };
84  bool IsInactive() const { return !IsActive(); };
85  void SetActive(const bool active = true) { fIsActive = active; };
86 
87  // Get/set x and y active width
88  double GetActiveWidthX() const { return fActiveWidthX; };
89  double GetActiveWidthY() const { return fActiveWidthY; };
90  void SetActiveWidthXY(const double x, const double y) {
91  fActiveWidthX = x;
92  fActiveWidthY = y;
93  };
94  // Get/set z active width
95  double GetActiveWidthZ() const { return fActiveWidthZ; };
96  void SetActiveWidthZ(const double z) { fActiveWidthZ = z; };
97  bool InAcceptance(const double x, const double y) const {
98  if (fabs(x - fDetectorOriginX) < fActiveWidthX / 2.0 &&
99  fabs(y - fDetectorOriginY) < fActiveWidthY / 2.0)
100  return true;
101  else return false;
102  };
103 
104  // Get/set element direction
106  void SetElementDirection(const EQwDirectionID dir) { fDirection = dir; };
107 
108  // Get/set element spacing
109  double GetElementSpacing() const { return fElementSpacing; };
110  void SetElementSpacing(const double spacing) { fElementSpacing = spacing; };
111 
112  // Get/set element offset
113  double GetElementOffset() const { return fElementOffset; };
114  void SetElementOffset(const double offset) { fElementOffset = offset; };
115 
116  // Get element coordinate
117  double GetElementCoordinate(const int element) const;
118 
119  // Get/set element orientation
120  double GetElementAngle() const { return fElementAngle; };
121  double GetElementAngleInRad() const { return fElementAngle; };
122  double GetElementAngleInDeg() const { return fElementAngle / Qw::deg; };
123  double GetElementAngleCos() const { return fElementAngleCos; };
124  double GetElementAngleSin() const { return fElementAngleSin; };
125  void SetElementAngle(const double angle) {
126  fElementAngle = angle;
127  fElementAngleCos = std::cos(fElementAngle);
128  fElementAngleSin = std::sin(fElementAngle);
129  };
130  void SetElementAngle(const double cosangle, const double sinangle) {
131  fElementAngleCos = cosangle;
132  fElementAngleSin = sinangle;
133  fElementAngle = std::atan2 (sinangle, cosangle);
134  };
135 
136  // Get/set number of elements
137  int GetNumberOfElements() const { return fNumberOfElements; };
138  void SetNumberOfElements(const int nelements) {
139  fNumberOfElements = nelements;
140  fEfficiency.assign(nelements + 1, 1.0); // wires are counted from 1
141  };
142 
143  // Get/set detector pitch (in degrees)
144  double GetDetectorPitch() const { return fDetectorPitch; };
145  double GetDetectorPitchInRad() const { return fDetectorPitch / Qw::rad; };
146  double GetDetectorPitchInDeg() const { return fDetectorPitch / Qw::deg; };
147  double GetDetectorPitchCos() const { return fDetectorPitchCos; };
148  double GetDetectorPitchSin() const { return fDetectorPitchSin; };
149  void SetDetectorPitch(const double pitch) {
150  fDetectorPitch = pitch; // in radians
151  fDetectorPitchCos = std::cos(fDetectorPitch);
152  fDetectorPitchSin = std::sin(fDetectorPitch);
153  };
154  // Get/set detector yaw (in degrees)
155  double GetDetectorYaw() const { return fDetectorYaw; };
156  double GetDetectorYawInRad() const { return fDetectorYaw / Qw::rad; };
157  double GetDetectorYawInDeg() const { return fDetectorYaw / Qw::deg; };
158  double GetDetectorYawCos() const { return fDetectorYawCos; };
159  double GetDetectorYawSin() const { return fDetectorYawSin; };
160  void SetDetectorYaw(const double yaw) {
161  fDetectorYaw = yaw; // in radians
162  fDetectorYawCos = std::cos(fDetectorYaw);
163  fDetectorYawSin = std::sin(fDetectorYaw);
164  };
165  // Get/set detector roll (in degrees)
166  double GetDetectorRoll() const { return fDetectorRoll; };
167  double GetDetectorRollInRad() const { return fDetectorRoll / Qw::rad; };
168  double GetDetectorRollInDeg() const { return fDetectorRoll / Qw::deg; };
169  double GetDetectorRollCos() const { return fDetectorRollCos; };
170  double GetDetectorRollSin() const { return fDetectorRollSin; };
171  void SetDetectorRoll(const double roll) {
172  fDetectorRoll = roll; // in radians
173  fDetectorRollCos = std::cos(fDetectorRoll);
174  fDetectorRollSin = std::sin(fDetectorRoll);
175  };
176  // Get/set rotator pitch (in degrees)
177  double GetRotatorPitch() const { return fRotatorPitch; };
178  double GetRotatorPitchInRad() const { return fRotatorPitch / Qw::rad; };
179  double GetRotatorPitchInDeg() const { return fRotatorPitch / Qw::deg; };
180  double GetRotatorPitchCos() const { return fRotatorPitchCos; };
181  double GetRotatorPitchSin() const { return fRotatorPitchSin; };
182  void SetRotatorPitch(const double pitch) {
183  fRotatorPitch = pitch; // in radians
184  fRotatorPitchCos = std::cos(fRotatorPitch);
185  fRotatorPitchSin = std::sin(fRotatorPitch);
186  };
187  // Get/set rotator yaw (in degrees)
188  double GetRotatorYaw() const { return fRotatorYaw; };
189  double GetRotatorYawInRad() const { return fRotatorYaw / Qw::rad; };
190  double GetRotatorYawInDeg() const { return fRotatorYaw / Qw::deg; };
191  double GetRotatorYawCos() const { return fRotatorYawCos; };
192  double GetRotatorYawSin() const { return fRotatorYawSin; };
193  void SetRotatorYaw(const double yaw) {
194  fRotatorYaw = yaw; // in radians
195  fRotatorYawCos = std::cos(fRotatorYaw);
196  fRotatorYawSin = std::sin(fRotatorYaw);
197  };
198  // Get/set rotator roll (in degrees)
199  double GetRotatorRoll() const { return fRotatorRoll; };
200  double GetRotatorRollInRad() const { return fRotatorRoll / Qw::rad; };
201  double GetRotatorRollInDeg() const { return fRotatorRoll / Qw::deg; };
202  double GetRotatorRollCos() const { return fRotatorRollCos; };
203  double GetRotatorRollSin() const { return fRotatorRollSin; };
204  void SetRotatorRoll(const double roll) {
205  fRotatorRoll = roll; // in radians
206  fRotatorRollCos = std::cos(fRotatorRoll);
207  fRotatorRollSin = std::sin(fRotatorRoll);
208  };
209 
210  // Get/set tracking search tree
214 
215  // Print function
216  void Print(Option_t *option = "") const;
217 
218  // Output stream operator
219  friend std::ostream& operator<< (std::ostream& stream, const QwDetectorInfo& det);
220 
221  // Get detector information
222  EQwDetectorType GetType() const { return fType; };
224  EQwRegionID GetRegion() const { return fRegion; };
226  int GetPlane() const { return fPlane; };
227 
228  // Get crosstalk element
229  int GetCrosstalkElement(int element) const {
230  if (fCrosstalk.count(element))
231  return fCrosstalk.at(element);
232  else
233  return -1;
234  }
235 
236  // Get element efficiency
237  double GetElementEfficiency(int element) const {
238  try {
239  return fEfficiency.at(element);
240  } catch (std::exception& e) {
241  QwWarning << "Undefined efficiency for element " << element << " in "
242  << *this << QwLog::endl;
243  return 0.0;
244  }
245  }
246  // Set element efficiency
247  void SetElementEfficiency(int element, double efficiency) {
248  try {
249  fEfficiency.at(element) = efficiency;
250  } catch (std::exception& e) {
251  QwWarning << "Undefined element " << element << " in "
252  << *this << QwLog::endl;
253  }
254  }
255  // Set element efficiency for all elements
256  void SetElementEfficiency(double efficiency) {
257  fEfficiency.assign(fEfficiency.size(), efficiency);
258  }
259 
260  private:
261 
262  // Detector information variables
267  int fPlane;
268  int fOctant;
269 
270  // Identification info for readout channels. Filled at load time.
271  int fCrate; //ROC number
272  int fModule; //F1TDC slot number or module index
273  int fChannel; //channel number
274 
275  // Detector position
276  double fDetectorOriginX; ///< Detector position in x
277  double fDetectorOriginY; ///< Detector position in y
278  double fDetectorOriginZ; ///< Detector position in z
279 
280  // Detector orientation
281  double fDetectorPitch; ///< Pitch of detector
282  double fDetectorPitchCos; ///< Cos of detector pitch
283  double fDetectorPitchSin; ///< Sin of detector pitch
284  double fDetectorYaw; ///< Yaw of detector
285  double fDetectorYawCos; ///< Cos of detector yaw
286  double fDetectorYawSin; ///< Sin of detector yaw
287  double fDetectorRoll; ///< Roll of detector
288  double fDetectorRollCos; ///< Cos of detector roll
289  double fDetectorRollSin; ///< Sin of detector roll
290  double fRotatorPitch; ///< Pitch of rotator (rotation of rotator about global x-axis)
291  double fRotatorPitchCos; ///< Cos of rotator pitch
292  double fRotatorPitchSin; ///< Sin of rotator pitch
293  double fRotatorYaw; ///< Yaw of rotator (rotation of rotator about global y-axis)
294  double fRotatorYawCos; ///< Cos of rotator yaw
295  double fRotatorYawSin; ///< Sin of rotator yaw
296  double fRotatorRoll; ///< Roll of rotator (rotation of rotator about global z-axis)
297  double fRotatorRollCos; ///< Cos of rotator roll
298  double fRotatorRollSin; ///< Sin of rotator roll
299 
300 
301  bool fIsActive; ///< Is this detector activated in tracking
302 
303  double fSpatialResolution; ///< Spatial resolution (how accurate is the timing info)
304  double fTrackResolution; ///< Track resolution (how accurate are the tracks through the hits)
305  double fSlopeMatching; ///< Slope matching resolution (how accurate do the tracks line up)
306 
307  double fActiveWidthX; ///< Active volume in x
308  double fActiveWidthY; ///< Active volume in y
309  double fActiveWidthZ; ///< Active volume in z
310 
311  double fElementSpacing; ///< Perpendicular distance between the elements
312  double fElementAngle; ///< Element orientation with respect to the X axis
313  double fElementAngleCos; ///< Cos of the element orientation
314  double fElementAngleSin; ///< Sin of the element orientation
315  double fElementOffset; ///< Position of the first element (it is not
316  /// exactly clear to me what that exactly means)
317  double fPlaneOffset; ///< Perpendicular distance from the first plane in the same direction
318  int fNumberOfElements; ///< Total number of elements in this detector
319 
320  std::map<int,int> fCrosstalk;//! ///< Sets of crosstalking elements, in a map for easy lookup
321 
322  std::vector<double> fEfficiency;//! ///< Efficiency of all elements
323 
324  QwTrackingTreeRegion* fTree; ///< Search tree for this detector
325 
326  public:
327 
328  // Detector name
329  std::string fDetectorName;
330 
331  // Reference channel index in list of reference channels (most prob. filled at load time)
333 
334 
335  // List of active hits by absolute hit number from QwHit array. filled for each event; cleared after each event.
336  std::vector<int> fHitID;
337 
338 
339  void SetElectronics(int crt,int mdl,int chn) {
340  fCrate = crt;
341  fModule = mdl;
342  fChannel = chn;
344  }
345 
346  bool IsHit() { return (!fHitID.empty()); };
347 
348  int GetNumHits() { return fHitID.size(); };
349 
350  void ClearHits() {
351  if (!fHitID.empty())
352  fHitID.clear();
353  }
354 
355  void PushHit(int time) {
356  fHitID.push_back(time);
357  }
358 
360 
361 };
362 
363 // Detectors could be sorted by package, region, z position
364 inline bool operator< (const QwDetectorInfo& lhs, const QwDetectorInfo& rhs) {
365  if (lhs.GetPackage() < rhs.GetPackage()) return true;
366  else if (lhs.GetPackage() == rhs.GetPackage()) {
367  if (lhs.GetRegion() < rhs.GetRegion()) return true;
368  else if (lhs.GetRegion() == rhs.GetRegion()) {
369  if (lhs.GetZPosition() < rhs.GetZPosition()) return true;
370  else if (lhs.GetZPosition() == rhs.GetZPosition()) {
371  return false;
372  } else return false;
373  } else return false;
374  } else return false;
375 }
376 
377 #endif
double GetElementCoordinate(const int element) const
double fRotatorPitch
Pitch of rotator (rotation of rotator about global x-axis)
void SetTrackingSearchTree(QwTrackingTreeRegion *tree)
bool operator<(const QwDetectorInfo &lhs, const QwDetectorInfo &rhs)
double GetDetectorPitchInDeg() const
double GetRotatorYawCos() const
EQwRegionID fRegion
double fDetectorPitchSin
Sin of detector pitch.
void SetElectronics(int crt, int mdl, int chn)
double GetDetectorPitchSin() const
void SetElementDirection(const EQwDirectionID dir)
void SetXYPosition(const double x, const double y)
double GetRotatorYawInRad() const
double fDetectorOriginZ
Detector position in z.
double GetRotatorRollInRad() const
EQwDetectorPackage fPackage
double GetRotatorYawInDeg() const
void PushHit(int time)
bool fIsActive
Is this detector activated in tracking.
double fElementAngleCos
Cos of the element orientation.
double GetSpatialResolution() const
void SetSpatialResolution(const double res)
std::string GetDetectorName() const
EQwDetectorPackage GetPackage() const
double fSlopeMatching
Slope matching resolution (how accurate do the tracks line up)
double GetElementAngleInRad() const
int GetPlane() const
const QwTrackingTreeRegion * GetTrackingSearchTree() const
A container for the pattern databases for each detector region.
double fRotatorRoll
Roll of rotator (rotation of rotator about global z-axis)
std::vector< int > fHitID
static const double deg
Definition: QwUnits.h:106
void SetXYZPosition(const double x, const double y, const double z)
double fActiveWidthZ
Active volume in z.
double GetDetectorYawCos() const
double fDetectorRollSin
Sin of detector roll.
double GetActiveWidthY() const
void SetZPosition(const double z)
double GetDetectorRoll() const
EQwRegionID GetRegion() const
EQwDirectionID GetDirection() const
static const double e
Definition: QwUnits.h:91
double fDetectorPitchCos
Cos of detector pitch.
std::vector< double > fEfficiency
///&lt; Sets of crosstalking elements, in a map for easy lookup
double fRotatorYawCos
Cos of rotator yaw.
double fActiveWidthY
Active volume in y.
double fPlaneOffset
exactly clear to me what that exactly means)
void Print(Option_t *option="") const
EQwDetectorPackage
Definition: QwTypes.h:70
double GetDetectorPitchCos() const
double GetDetectorRollInRad() const
std::string fDetectorName
double GetRotatorYawSin() const
void SetNumberOfElements(const int nelements)
double GetDetectorYawSin() const
QwTrackingTreeRegion * fTree
///&lt; Efficiency of all elements
double GetRotatorYaw() const
double fDetectorPitch
Pitch of detector.
void SetOctant(const int octant)
static const double rad
Definition: QwUnits.h:105
void SetElementOffset(const double offset)
double GetRotatorRollSin() const
QwTrackingTreeRegion * GetTrackingSearchTree()
double GetElementOffset() const
double fRotatorPitchCos
Cos of rotator pitch.
void SetPosition(const TVector3 &position)
double GetDetectorPitch() const
double GetDetectorYaw() const
void SetActiveWidthXY(const double x, const double y)
double GetPlaneOffset() const
EQwDetectorType
Definition: QwTypes.h:94
EQwRegionID
Definition: QwTypes.h:16
double GetSlopeMatching() const
double GetRotatorRollCos() const
void SetElementAngle(const double angle)
A logfile class, based on an identical class in the Hermes analyzer.
const TVector3 GetPosition() const
void SetPlaneOffset(double offset)
double GetRotatorPitchSin() const
double GetDetectorRollInDeg() const
double GetRotatorRollInDeg() const
void SetElementAngle(const double cosangle, const double sinangle)
void SetActive(const bool active=true)
void SetRotatorRoll(const double roll)
double GetElementEfficiency(int element) const
double fActiveWidthX
Active volume in x.
void SetElementEfficiency(int element, double efficiency)
void SetActiveWidthZ(const double z)
double fRotatorRollCos
Cos of rotator roll.
double fTrackResolution
Track resolution (how accurate are the tracks through the hits)
ClassDef(QwDetectorInfo, 0)
bool InAcceptance(const double x, const double y) const
double fDetectorYaw
Yaw of detector.
EQwDirectionID fDirection
void SetRotatorYaw(const double yaw)
void SetElementEfficiency(double efficiency)
double GetRotatorRoll() const
double fRotatorRollSin
Sin of rotator roll.
double GetRotatorPitchInRad() const
double fRotatorYawSin
Sin of rotator yaw.
EQwDetectorType GetType() const
int fNumberOfElements
Total number of elements in this detector.
void SetSlopeMatching(const double slope)
double GetDetectorRollCos() const
double GetYPosition() const
int GetCrosstalkElement(int element) const
double GetElementAngleSin() const
double GetDetectorYawInRad() const
EQwDirectionID GetElementDirection() const
double fDetectorOriginX
Detector position in x.
void LoadGeometryDefinition(QwParameterFile *map)
double GetActiveWidthZ() const
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
double GetElementSpacing() const
double fDetectorOriginY
Detector position in y.
double GetRotatorPitch() const
void SetRotatorPitch(const double pitch)
double fDetectorYawCos
Cos of detector yaw.
EQwDirectionID
Definition: QwTypes.h:41
void SetTrackResolution(const double res)
EQwDetectorType fType
double fSpatialResolution
Spatial resolution (how accurate is the timing info)
double fDetectorRollCos
Cos of detector roll.
double fElementAngle
Element orientation with respect to the X axis.
double GetElementAngleCos() const
double GetDetectorPitchInRad() const
double fDetectorYawSin
Sin of detector yaw.
double GetDetectorRollSin() const
double fRotatorPitchSin
Sin of rotator pitch.
double GetZPosition() const
double GetElementAngle() const
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
void SetDetectorName(const std::string &name)
double GetXPosition() const
friend std::ostream & operator<<(std::ostream &stream, const QwDetectorInfo &det)
double fDetectorRoll
Roll of detector.
double GetElementAngleInDeg() const
QwDetectorInfo(const std::string &name="")
Constructor with optional name.
double GetRotatorPitchInDeg() const
double GetDetectorYawInDeg() const
void SetDetectorPitch(const double pitch)
int GetNumberOfElements() const
void SetElementSpacing(const double spacing)
std::map< int, int > fCrosstalk
void SetDetectorRoll(const double roll)
bool IsActive() const
void SetDetectorYaw(const double yaw)
bool IsInactive() const
double fElementAngleSin
Sin of the element orientation.
double fRotatorYaw
Yaw of rotator (rotation of rotator about global y-axis)
double fElementSpacing
Perpendicular distance between the elements.
double GetTrackResolution() const
double GetRotatorPitchCos() const
int GetOctant() const
double GetActiveWidthX() const
void LoadCrosstalkDefinition(QwParameterFile *map)