QwAnalysis
QwDetectorInfo.cc
Go to the documentation of this file.
1 //
2 // C++ Implementation: QwDetectorInfo
3 //
4 // Description:
5 //
6 //
7 // Author: Wouter Deconinck <wdconinc@mit.edu>, (C) 2009
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 
13 #include "QwDetectorInfo.h"
15 
16 // System headers
17 #include <cstdlib>
18 
19 // Qweak headers
20 #include "QwParameterFile.h"
21 
22 QwDetectorInfo::QwDetectorInfo(const std::string& name)
23 : fType(kTypeNull),fPackage(kPackageNull),fRegion(kRegionIDNull),
24  fDirection(kDirectionNull),
25  fPlane(0),fOctant(0),
26  fCrate(0),fModule(0),fChannel(0),
27  fDetectorOriginX(0),fDetectorOriginY(0),fDetectorOriginZ(0),
28  fDetectorPitch(0),fDetectorPitchCos(1),fDetectorPitchSin(0),
29  fDetectorYaw(0),fDetectorYawCos(1),fDetectorYawSin(0),
30  fDetectorRoll(0),fDetectorRollCos(1),fDetectorRollSin(0),
31  fRotatorPitch(0),fRotatorPitchCos(1),fRotatorPitchSin(0),
32  fRotatorYaw(0),fRotatorYawCos(1),fRotatorYawSin(0),
33  fRotatorRoll(0),fRotatorRollCos(1),fRotatorRollSin(0),
34  fIsActive(true),fSpatialResolution(0),fTrackResolution(0),fSlopeMatching(0),
35  fActiveWidthX(0),fActiveWidthY(0),fActiveWidthZ(0),
36  fElementSpacing(0),fElementAngle(0),fElementAngleCos(0),fElementAngleSin(0),
37  fElementOffset(0),fPlaneOffset(0),fNumberOfElements(0),fTree(0),
38  fDetectorName(name),fReferenceChannelIndex(0)
39 {
40 
41 }
42 
43 /** Parse the geometry definition for this detector
44  * @param map Relevant fraction of the parameter file
45  */
47 {
48  std::string varvalue;
49 
50  map->TrimWhitespace();
51 
52  if (map->FileHasVariablePair("=","active_width_x",varvalue))
53  fActiveWidthX = map->ConvertValue<double>(varvalue) * Qw::cm;
54  if (map->FileHasVariablePair("=","active_width_y",varvalue))
55  fActiveWidthY = map->ConvertValue<double>(varvalue) * Qw::cm;
56  if (map->FileHasVariablePair("=","active_width_z",varvalue))
57  fActiveWidthZ = map->ConvertValue<double>(varvalue) * Qw::cm;
58 
59  if (map->FileHasVariablePair("=","detector_origin_x",varvalue))
60  fDetectorOriginX = map->ConvertValue<double>(varvalue) * Qw::cm;
61  if (map->FileHasVariablePair("=","detector_origin_y",varvalue))
62  fDetectorOriginY = map->ConvertValue<double>(varvalue) * Qw::cm;
63  if (map->FileHasVariablePair("=","detector_origin_z",varvalue))
64  fDetectorOriginZ = map->ConvertValue<double>(varvalue) * Qw::cm;
65  if (map->FileHasVariablePair("=","detector_pitch",varvalue)) {
66  fDetectorPitch = map->ConvertValue<double>(varvalue) * Qw::deg;
69  }
70  if (map->FileHasVariablePair("=","detector_yaw",varvalue)) {
71  fDetectorYaw = map->ConvertValue<double>(varvalue) * Qw::deg;
74  }
75  if (map->FileHasVariablePair("=","detector_roll",varvalue)) {
76  fDetectorRoll = map->ConvertValue<double>(varvalue) * Qw::deg;
79  }
80  if(map->FileHasVariablePair("=","rotator_pitch",varvalue)) {
81  fRotatorPitch = map->ConvertValue<double>(varvalue) * Qw::deg;
84  }
85  if(map->FileHasVariablePair("=","rotator_yaw",varvalue)) {
86  fRotatorYaw = map->ConvertValue<double>(varvalue) * Qw::deg;
89  }
90  if(map->FileHasVariablePair("=","rotator_roll",varvalue)) {
91  fRotatorRoll = map->ConvertValue<double>(varvalue) * Qw::deg;
94  }
95 
96  if (map->FileHasVariablePair("=","number_of_elements",varvalue))
97  SetNumberOfElements(map->ConvertValue<int>(varvalue));
98  if (map->FileHasVariablePair("=","element_spacing",varvalue))
99  SetElementSpacing(map->ConvertValue<double>(varvalue) * Qw::cm);
100  if (map->FileHasVariablePair("=","element_offset",varvalue))
101  SetElementOffset(map->ConvertValue<double>(varvalue) * Qw::cm);
102 
103  if (map->FileHasVariablePair("=","element_angle_cos",varvalue))
104  fElementAngleCos = map->ConvertValue<double>(varvalue);
105  if (map->FileHasVariablePair("=","element_angle_sin",varvalue))
106  fElementAngleSin = map->ConvertValue<double>(varvalue);
108 
109  if (map->FileHasVariablePair("=","spatial_resolution",varvalue))
110  fSpatialResolution = map->ConvertValue<double>(varvalue) * Qw::cm;
111  if (map->FileHasVariablePair("=","track_resolution",varvalue))
112  fTrackResolution = map->ConvertValue<double>(varvalue) * Qw::cm;
113  if (map->FileHasVariablePair("=","slope_matching",varvalue))
114  fSlopeMatching = map->ConvertValue<double>(varvalue) * Qw::cm;
115 
116  if (map->FileHasVariablePair("=","type",varvalue))
117  fType = kQwTypeMap.find(map->ConvertValue<char>(varvalue))->second;
118  if (map->FileHasVariablePair("=","package",varvalue))
119  fPackage = kQwPackageMap.find(map->ConvertValue<char>(varvalue))->second;
120  if (map->FileHasVariablePair("=","region",varvalue))
121  fRegion = kQwRegionMap.find(map->ConvertValue<char>(varvalue))->second;
122  if (map->FileHasVariablePair("=","direction",varvalue))
123  fDirection = kQwDirectionMap.find(map->ConvertValue<char>(varvalue))->second;
124 
125  if (map->FileHasVariablePair("=","octant",varvalue))
126  fOctant = map->ConvertValue<int>(varvalue);
127  if (map->FileHasVariablePair("=","plane",varvalue))
128  fPlane = map->ConvertValue<int>(varvalue);
129 
130  if (map->FileHasVariablePair("=","active",varvalue))
131  fIsActive = map->ConvertValue<bool>(varvalue);
132 
133  if (map->FileHasVariablePair("=","efficiency",varvalue)) {
134  SetElementEfficiency(map->ConvertValue<double>(varvalue));
135  }
136  if (map->FileHasVariablePair("=","efficiency_list",varvalue)) {
137  std::string list = map->ConvertValue<string>(varvalue);
138  size_t begin = 0; // start of a 'element:efficiency' pair
139  while (begin < list.size()) {
140  // find next space
141  size_t end = list.find(' ',begin);
142  // if no space, point to end of the line
143  if (end == std::string::npos) end = list.size();
144  // get the 'element:efficiency' pair
145  std::string word = list.substr(begin,end-begin);
146  // find next colon
147  size_t colon = word.find(':');
148  // if no colon, stop
149  if (colon == std::string::npos) continue;
150 #if defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L
151  // get element and efficiency
152  int element = std::stoi(word.substr(0,colon));
153  double efficiency = std::stod(word.substr(colon+1,word.size()-colon-1));
154  SetElementEfficiency(element,efficiency);
155 #else
156  // get element and efficiency
157  string str1 = word.substr(0,colon);
158  string str2 = word.substr(colon+1,word.size()-colon-1);
159  int element = std::atoi(str1.c_str());
160  double efficiency = std::atof(str2.c_str());
161  SetElementEfficiency(element,efficiency);
162 #endif
163  // continue
164  begin = end+1;
165  }
166  }
167 
168  // A value of importance for region 2 only
170 }
171 
172 
173 
174 /** Parse the crosstalk definition for this detector
175  * @param map Relevant fraction of the parameter file
176  */
178 {
179  map->TrimWhitespace();
180  map->RewindToFileStart();
181  while (map->ReadNextLine()) {
182  std::string varname,varvalue;
183  if (! map->HasVariablePair("=",varname,varvalue)) continue;
184 
185  if (varname == "crosstalk") {
186  std::string list = map->ConvertValue<string>(varvalue);
187  size_t begin = 0; // start of a 'element1,element2' pair
188  while (begin < list.size()) {
189  // find next space
190  size_t end = list.find(' ',begin);
191  // if no space, point to end of the line
192  if (end == std::string::npos) end = list.size();
193  // get the 'element1,element2' pair
194  std::string word = list.substr(begin,end-begin);
195  // find next comma
196  size_t comma = word.find(',');
197  // if no comma, stop
198  if (comma == std::string::npos) continue;
199 #if defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L
200  // get element1 and element2
201  int element1 = std::stoi(word.substr(0,comma));
202  int element2 = std::stoi(word.substr(comma+1,word.size()-comma-1));
203  fCrosstalk[element1] = element2;
204  fCrosstalk[element2] = element1;
205  QwOut << "crosstalk in " << GetDetectorName() << ": " << element1 << "," << element2 << QwLog::endl;
206 #else
207  // get element1 and element2
208  string str1 = word.substr(0,comma);
209  string str2 = word.substr(comma+1,word.size()-comma-1);
210  int element1 = std::atoi(str1.c_str());
211  int element2 = std::atoi(str2.c_str());
212  fCrosstalk[element1] = element2;
213  fCrosstalk[element2] = element1;
214  QwOut << "crosstalk in " << GetDetectorName() << ": " << element1 << "," << element2 << QwLog::endl;
215 #endif
216  // continue
217  begin = end+1;
218  }
219  }
220  }
221 }
222 
223 /** Get position of the detector
224  * @return TVector3
225  */
226 const TVector3 QwDetectorInfo::GetPosition() const
227 {
229 }
230 
231 /** Set position of the detector
232  * @param position TVector3
233  */
234 void QwDetectorInfo::SetPosition(const TVector3& position)
235 {
236  fDetectorOriginX = position.X();
237  fDetectorOriginY = position.Y();
238  fDetectorOriginZ = position.Z();
239 }
240 
241 /**
242  * Get the coordinate of the specified element. E.g. this returns the x/u/v
243  * position of the specified wire, taking into account the offset of wire 1.
244  * @param element Element number
245  * @return Coordinate of the element
246  */
247 double QwDetectorInfo::GetElementCoordinate(const int element) const
248 {
249  return GetElementOffset() + (element - 1) * GetElementSpacing();
250 }
251 
252 /**
253  * Print all variables in this
254  */
255 void QwDetectorInfo::Print(Option_t *option) const
256 {
257  QwOut << "type = " << fType << QwLog::endl;
258  QwOut << "region = " << fRegion << QwLog::endl;
259  QwOut << "package = " << fPackage << QwLog::endl;
260  QwOut << "direction = " << fDirection << QwLog::endl;
261  QwOut << "octant = " << fOctant << QwLog::endl;
262  QwOut << "plane = " << fPlane << QwLog::endl;
263  QwOut << "active_width_x = " << fActiveWidthX/Qw::cm << QwLog::endl;
264  QwOut << "active_width_y = " << fActiveWidthY/Qw::cm << QwLog::endl;
265  QwOut << "active_width_z = " << fActiveWidthZ/Qw::cm << QwLog::endl;
266  QwOut << "detector_origin_x = " << fDetectorOriginX/Qw::cm << QwLog::endl;
267  QwOut << "detector_origin_y = " << fDetectorOriginY/Qw::cm << QwLog::endl;
268  QwOut << "detector_origin_z = " << fDetectorOriginZ/Qw::cm << QwLog::endl;
269  QwOut << "detector_pitch = " << fDetectorPitch/Qw::deg << QwLog::endl;
270  QwOut << "detector_roll = " << fDetectorRoll/Qw::deg << QwLog::endl;
271  QwOut << "detector_yaw = " << fDetectorYaw/Qw::deg << QwLog::endl;
272  QwOut << "rotator_pitch = " << fRotatorPitch/Qw::deg << QwLog::endl;
273  QwOut << "rotator_roll = " << fRotatorRoll/Qw::deg << QwLog::endl;
274  QwOut << "rotator_yaw = " << fRotatorYaw/Qw::deg << QwLog::endl;
275  QwOut << "spatial_resolution = " << fSpatialResolution << QwLog::endl;
276  QwOut << "track_resolution = " << fTrackResolution << QwLog::endl;
277  QwOut << "slope_matching = " << fSlopeMatching << QwLog::endl;
278  QwOut << "element_angle = " << fElementAngle/Qw::deg << QwLog::endl;
279  QwOut << "element_spacing = " << fElementSpacing/Qw::cm << QwLog::endl;
280  QwOut << "element_offset = " << fElementOffset/Qw::cm << QwLog::endl;
281  QwOut << "number_of_elements = " << fNumberOfElements << QwLog::endl;
282  QwOut << "plane_offset = " << fPlaneOffset/Qw::cm << QwLog::endl;
283 }
284 
285 /**
286  * Output stream operator
287  * @param stream Output stream
288  * @param det Detector info object
289  * @return Output stream
290  */
291 std::ostream& operator<< (std::ostream& stream, const QwDetectorInfo& det)
292 {
293  stream << det.fDetectorName << ": ";
294  stream << "type " << det.fType << ", ";
295  stream << "package " << det.fPackage << ", ";
296  stream << "region " << det.fRegion << ", ";
297  stream << "plane " << det.fPlane << ", ";
298  stream << "octant " << det.fOctant << ", ";
299  stream << "dir " << det.GetElementDirection() << " ";
300  stream << "(y = " << det.GetXPosition() / Qw::cm << " cm)";
301  stream << "(z = " << det.GetZPosition() / Qw::cm << " cm)";
302  return stream;
303 }
double GetElementCoordinate(const int element) const
double fRotatorPitch
Pitch of rotator (rotation of rotator about global x-axis)
EQwRegionID fRegion
#define QwOut
Predefined log drain for explicit output.
Definition: QwLog.h:35
double fDetectorPitchSin
Sin of detector pitch.
std::ostream & operator<<(std::ostream &out, const QwColor &color)
Output stream operator which uses the enum-to-escape-code mapping.
Definition: QwColor.h:153
double fDetectorOriginZ
Detector position in z.
EQwDetectorPackage fPackage
bool fIsActive
Is this detector activated in tracking.
double fElementAngleCos
Cos of the element orientation.
std::string GetDetectorName() const
double fSlopeMatching
Slope matching resolution (how accurate do the tracks line up)
double fRotatorRoll
Roll of rotator (rotation of rotator about global z-axis)
static const QwDirectionMap kQwDirectionMap
Definition: QwTypes.h:67
static const double deg
Definition: QwUnits.h:106
double fActiveWidthZ
Active volume in z.
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
double fDetectorRollSin
Sin of detector roll.
double fDetectorPitchCos
Cos of detector pitch.
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
std::string fDetectorName
void SetNumberOfElements(const int nelements)
double fDetectorPitch
Pitch of detector.
void SetElementOffset(const double offset)
double GetElementOffset() const
double fRotatorPitchCos
Cos of rotator pitch.
void SetPosition(const TVector3 &position)
static const QwPackageMap kQwPackageMap
Definition: QwTypes.h:92
const TVector3 GetPosition() const
double fActiveWidthX
Active volume in x.
Bool_t ReadNextLine()
void SetElementEfficiency(int element, double efficiency)
double fRotatorRollCos
Cos of rotator roll.
double fTrackResolution
Track resolution (how accurate are the tracks through the hits)
double fDetectorYaw
Yaw of detector.
EQwDirectionID fDirection
double fRotatorRollSin
Sin of rotator roll.
double fRotatorYawSin
Sin of rotator yaw.
Bool_t FileHasVariablePair(const std::string &separatorchars, const std::string &varname, std::string &varvalue)
int fNumberOfElements
Total number of elements in this detector.
EQwDirectionID GetElementDirection() const
double fDetectorOriginX
Detector position in x.
void LoadGeometryDefinition(QwParameterFile *map)
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
double GetElementSpacing() const
double fDetectorOriginY
Detector position in y.
double fDetectorYawCos
Cos of detector yaw.
ClassImp(QwF1TDC)
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.
static const QwRegionMap kQwRegionMap
Definition: QwTypes.h:38
double fDetectorYawSin
Sin of detector yaw.
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
double fRotatorPitchSin
Sin of rotator pitch.
double GetZPosition() const
double GetXPosition() const
double fDetectorRoll
Roll of detector.
QwDetectorInfo(const std::string &name="")
Constructor with optional name.
void SetElementSpacing(const double spacing)
std::map< int, int > fCrosstalk
double fElementAngleSin
Sin of the element orientation.
double fRotatorYaw
Yaw of rotator (rotation of rotator about global y-axis)
T ConvertValue(const std::string &value)
Convert string value into specific type.
static const QwTypeMap kQwTypeMap
Definition: QwTypes.h:120
double fElementSpacing
Perpendicular distance between the elements.
static const double cm
Length units: base unit is mm.
Definition: QwUnits.h:61
void LoadCrosstalkDefinition(QwParameterFile *map)