CbmRoot
CbmStsStation.cxx
Go to the documentation of this file.
1 
5 #include "CbmStsStation.h"
6 
7 #include "CbmStsAddress.h" // for kStsLadder
8 #include "CbmStsDefs.h" // for CbmStsSensorClass, CbmStsSensorClass:...
9 #include "CbmStsElement.h" // for CbmStsElement
10 #include "CbmStsParSensor.h" // for CbmStsParSensor
11 #include "CbmStsSensor.h" // for CbmStsSensor
12 
13 #include <FairLogger.h> // for LOG, Logger
14 
15 #include <TGeoBBox.h> // for TGeoBBox
16 #include <TGeoMatrix.h> // for TGeoHMatrix
17 #include <TGeoPhysicalNode.h> // for TGeoPhysicalNode
18 #include <TGeoShape.h> // for TGeoShape
19 #include <TGeoVolume.h> // for TGeoVolumeAssembly
20 #include <TMathBase.h> // for Abs, Max, Min
21 #include <TNamed.h> // for TNamed
22 
23 #include <cassert> // for assert
24 #include <math.h> // for atan2
25 #include <sstream> // for operator<<, basic_ostream, stringstream
26 #include <string> // for char_traits
27 
28 using std::string;
29 using std::stringstream;
30 
31 // ----- Default constructor -------------------------------------------
33  : TNamed()
34  , fZ(0.)
35  , fXmin(0.)
36  , fXmax(0.)
37  , fYmin(0.)
38  , fYmax(0.)
39  , fSensorD(0.)
40  , fSensorRot(0.)
41  , fNofSensors(0)
42  , fDiffSensorD(kFALSE)
43  , fFirstSensor(nullptr)
44  , fNode(nullptr)
45  , fLadders() {}
46 // -------------------------------------------------------------------------
47 
48 
49 // ----- Standard constructor ------------------------------------------
51  const char* title,
52  TGeoPhysicalNode* node)
53  : TNamed(name, title)
54  , fZ(0.)
55  , fXmin(0.)
56  , fXmax(0.)
57  , fYmin(0.)
58  , fYmax(0.)
59  , fSensorD(0.)
60  , fSensorRot(0.)
61  , fNofSensors(0)
62  , fDiffSensorD(kFALSE)
63  , fFirstSensor(nullptr)
64  , fNode(node)
65  , fLadders() {}
66 // -------------------------------------------------------------------------
67 
68 
69 // ----- Destructor ----------------------------------------------------
71 // -------------------------------------------------------------------------
72 
73 
74 // ----- Add a ladder to the station -----------------------------------
76 
77  // Check whether argument really is a ladder
78  assert(ladder);
79  assert(ladder->GetLevel() == kStsLadder);
80 
81  // Add to daughter array
82  fLadders.push_back(ladder);
83 }
84 // -------------------------------------------------------------------------
85 
86 
87 // ----- Initialise the station properties from sensors ----------------
89 
90  Int_t nSensors = 0; // sensor counter
91  Double_t zMin = 999999.; // sensor z minimum
92  Double_t zMax = -999999.; // sensor z maximum
93 
94  // --- Loop over ladders
95  for (UInt_t iLad = 0; iLad < fLadders.size(); iLad++) {
96  CbmStsElement* ladd = fLadders.at(iLad);
97 
98  // --- Loop over half-ladders
99  for (Int_t iHla = 0; iHla < ladd->GetNofDaughters(); iHla++) {
100  CbmStsElement* hlad = ladd->GetDaughter(iHla);
101 
102  // --- Loop over modules
103  for (Int_t iMod = 0; iMod < hlad->GetNofDaughters(); iMod++) {
104  CbmStsElement* modu = hlad->GetDaughter(iMod);
105 
106  // --- Loop over sensors
107  for (Int_t iSen = 0; iSen < modu->GetNofDaughters(); iSen++) {
108  CbmStsSensor* sensor =
109  dynamic_cast<CbmStsSensor*>(modu->GetDaughter(iSen));
110 
111  // Set first sensor
112  if (!nSensors) fFirstSensor = sensor;
113 
114  // Get sensor z position
115  TGeoPhysicalNode* sensorNode = sensor->GetPnode();
116  // --- Transform sensor centre into global C.S.
117  Double_t local[3] = {0., 0., 0.}; // sensor centre, local c.s.
118  Double_t global[3]; // sensor centre, global c.s.
119  sensorNode->GetMatrix()->LocalToMaster(local, global);
120  if (!nSensors) { // first sensor
121  zMin = global[2];
122  zMax = global[2];
123  } else {
124  zMin = TMath::Min(zMin, global[2]);
125  zMax = TMath::Max(zMax, global[2]);
126  }
127 
128  // Get sensor thickness
129  TGeoBBox* sBox = dynamic_cast<TGeoBBox*>(sensorNode->GetShape());
130  if (!sBox) LOG(fatal) << GetName() << ": sensor shape is not a box!";
131  Double_t sD = 2. * sBox->GetDZ();
132  if (!nSensors)
133  fSensorD = sD; // first sensor
134  else {
135  if (TMath::Abs(sD - fSensorD) > 0.0001) fDiffSensorD = kTRUE;
136  }
137 
138  nSensors++;
139  } // # sensors
140  } // # modules
141  } // # half-ladders
142  } // # ladders
143 
144  fZ = 0.5 * (zMin + zMax);
145  fNofSensors = nSensors;
146 }
147 // -------------------------------------------------------------------------
148 
149 
150 // ----- Strip pitch --------------------------------------------------
151 Double_t CbmStsStation::GetSensorPitch(Int_t side) const {
152 
153  assert(side == 0 || side == 1);
154  assert(fFirstSensor);
155  const CbmStsParSensor* parSensor = fFirstSensor->GetParams();
156  assert(parSensor);
157  CbmStsSensorClass sClass = parSensor->GetClass();
158  assert(sClass == CbmStsSensorClass::kDssdStereo
159  || sClass == CbmStsSensorClass::kDssdOrtho);
160  return parSensor->GetPar(side + 6);
161 }
162 // -------------------------------------------------------------------------
163 
164 
165 // ----- Stereo angle -------------------------------------------------
166 Double_t CbmStsStation::GetSensorStereoAngle(Int_t side) const {
167 
168  assert(side == 0 || side == 1);
169  assert(fFirstSensor);
170  const CbmStsParSensor* parSensor = fFirstSensor->GetParams();
171  assert(parSensor);
172  CbmStsSensorClass sClass = parSensor->GetClass();
173  assert(sClass == CbmStsSensorClass::kDssdStereo);
174  return parSensor->GetPar(side + 8);
175 }
176 // -------------------------------------------------------------------------
177 
178 
179 // ----- Initialise station parameters ---------------------------------
181 
182  // Determine x and y extensions of the station, in case it is present
183  // as TGeoNode (for old geometries). This implementation assumes that
184  // the shape of the station volume derives from TGeoBBox and that it is
185  // not rotated in the global c.s.
186  if (fNode) {
187  TGeoBBox* box = dynamic_cast<TGeoBBox*>(fNode->GetShape());
188  if (!box) LOG(fatal) << GetName() << ": shape is not box! ";
189  Double_t local[3] = {0., 0., 0.};
190  Double_t global[3];
191  fNode->GetMatrix()->LocalToMaster(local, global);
192  fXmin = global[0] - box->GetDX();
193  fXmax = global[0] + box->GetDX();
194  fYmin = global[1] - box->GetDY();
195  fYmax = global[1] + box->GetDY();
196  }
197 
198  // For new geometries with units instead of stations, the station element
199  // is not a node in the geometry. To obtain its extensions in x and y,
200  // a station volume is transiently made as TGeoVolumeAssembly, composed
201  // of its ladder daughters.
202  else {
203  TGeoVolumeAssembly* statVol = new TGeoVolumeAssembly("myStation");
204  for (UInt_t iLadder = 0; iLadder < fLadders.size(); iLadder++) {
205  TGeoVolume* ladVol = fLadders.at(iLadder)->GetPnode()->GetVolume();
206  TGeoHMatrix* ladMat = fLadders.at(iLadder)->GetPnode()->GetMatrix();
207  statVol->AddNode(ladVol, iLadder, ladMat);
208  } // # ladders in station
209  statVol->GetShape()->ComputeBBox();
210  TGeoBBox* statShape = dynamic_cast<TGeoBBox*>(statVol->GetShape());
211  const Double_t* origin = statShape->GetOrigin();
212  fXmin = origin[0] - statShape->GetDX();
213  fXmax = origin[0] + statShape->GetDX();
214  fYmin = origin[1] - statShape->GetDY();
215  fYmax = origin[1] + statShape->GetDY();
216  }
217 
218  // The z position of the station is obtained from the sensor positions,
219  // not from the station node. This is more flexible, because it does not
220  // assume the station to be symmetric.
222 
223  // Warning if varying sensor properties are found
224  if (fDiffSensorD)
225  LOG(warn) << GetName() << ": Different values for sensor thickness!";
226 
227  // Determine the rotation (in x-y) of the first sensor
228  assert(fFirstSensor);
229  TGeoPhysicalNode* sensorNode = fFirstSensor->GetNode();
230  assert(sensorNode);
231  // Transform unit vector on local x axis into global c.s.
232  Double_t unitLocal[3] = {1., 0., 0.};
233  Double_t unitGlobal[3];
234  sensorNode->GetMatrix()->LocalToMaster(unitLocal, unitGlobal);
235  // Subtract translation vector of local origin
236  Double_t* translation = sensorNode->GetMatrix()->GetTranslation();
237  unitGlobal[0] -= translation[0];
238  unitGlobal[1] -= translation[1];
239  unitGlobal[2] -= translation[2];
240  // Calculate angle between unit x vector in global and local c.s.
241  fSensorRot = atan2(unitGlobal[1], unitGlobal[0]);
242 }
243 // --------------------------------------------------------------------------
244 
245 
246 // ----- Info -----------------------------------------------------------
247 string CbmStsStation::ToString() const {
248  stringstream ss;
249  ss << GetName() << ": " << fNofSensors << " sensors, z = " << fZ
250  << " cm, x = " << fXmin << " to " << fXmax << " cm, y = " << fYmin
251  << " to " << fYmax << " cm "
252  << "\n\t\t"
253  << " rotation " << fSensorRot * 180. / 3.1415927 << " degrees,"
254  << " sensor thickness " << fSensorD << " cm";
255  if (fFirstSensor && fFirstSensor->GetParams()) {
256  ss << ", pitch " << GetSensorPitch(0) << " cm / " << GetSensorPitch(1)
257  << " cm, stereo angle " << GetSensorStereoAngle(0) << " / "
258  << GetSensorStereoAngle(1);
259  }
260 
261  return ss.str();
262 }
263 // --------------------------------------------------------------------------
264 
CbmStsStation::fXmax
Double_t fXmax
maximal x coordinate [cm]
Definition: CbmStsStation.h:141
CbmStsStation::fYmin
Double_t fYmin
minimal y coordinate [cm]
Definition: CbmStsStation.h:142
CbmStsStation::CbmStsStation
CbmStsStation()
Definition: CbmStsStation.cxx:32
CbmStsStation::fNode
TGeoPhysicalNode * fNode
Pointer to geometry.
Definition: CbmStsStation.h:150
atan2
friend F32vec4 atan2(const F32vec4 &y, const F32vec4 &x)
Definition: L1/vectors/P4_F32vec4.h:142
CbmStsStation::AddLadder
void AddLadder(CbmStsElement *ladder)
Definition: CbmStsStation.cxx:75
CbmStsStation::fFirstSensor
CbmStsSensor * fFirstSensor
Pointer to first sensor.
Definition: CbmStsStation.h:148
CbmStsStation.h
CbmStsStation::fNofSensors
Int_t fNofSensors
Number of sensors in station.
Definition: CbmStsStation.h:146
CbmStsParSensor::GetClass
CbmStsSensorClass GetClass() const
Get the sensor class.
Definition: CbmStsParSensor.h:56
CbmStsStation::fSensorRot
Double_t fSensorRot
Rotation of first sensor in global c.s. [rad].
Definition: CbmStsStation.h:145
CbmStsParSensor.h
CbmStsStation::fZ
Double_t fZ
z position of station [cm]
Definition: CbmStsStation.h:139
CbmStsElement::GetPnode
TGeoPhysicalNode * GetPnode() const
Definition: CbmStsElement.h:106
CbmStsSensorClass::kDssdOrtho
@ kDssdOrtho
CbmStsStation::GetSensorStereoAngle
Double_t GetSensorStereoAngle(Int_t iSide) const
Definition: CbmStsStation.cxx:166
CbmStsSensorClass::kDssdStereo
@ kDssdStereo
CbmStsParSensor
Constructional parameters of a STS sensor.
Definition: CbmStsParSensor.h:38
CbmStsDefs.h
CbmStsStation::fSensorD
Double_t fSensorD
thickness of sensors [cm]
Definition: CbmStsStation.h:144
CbmStsStation::CheckSensorProperties
void CheckSensorProperties()
Check properties of sensors (position, thickness) The z position of the station is determined as the ...
Definition: CbmStsStation.cxx:88
CbmStsElement.h
CbmStsStation::GetSensorPitch
Double_t GetSensorPitch(Int_t iSide) const
Definition: CbmStsStation.cxx:151
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmStsSensor
Class representing an instance of a sensor in the CBM-STS.
Definition: CbmStsSensor.h:38
CbmStsStation::fXmin
Double_t fXmin
minimal x coordinate [cm]
Definition: CbmStsStation.h:140
CbmStsSensorClass
CbmStsSensorClass
Sensor classes.
Definition: CbmStsDefs.h:61
CbmStsStation::fLadders
std::vector< CbmStsElement * > fLadders
Array of ladders.
Definition: CbmStsStation.h:151
CbmStsStation::fYmax
Double_t fYmax
maximal y coordinate [cm]
Definition: CbmStsStation.h:143
CbmStsSensor::GetNode
TGeoPhysicalNode * GetNode() const
Definition: CbmStsSensor.h:77
CbmStsStation::fDiffSensorD
Bool_t fDiffSensorD
Flag for different sensor thicknesses.
Definition: CbmStsStation.h:147
CbmStsElement::GetDaughter
CbmStsElement * GetDaughter(Int_t index) const
Definition: CbmStsElement.cxx:120
CbmStsParSensor::GetPar
Float_t GetPar(UInt_t index) const
Get a parameter.
Definition: CbmStsParSensor.cxx:22
CbmStsElement::GetNofDaughters
Int_t GetNofDaughters() const
Definition: CbmStsElement.h:95
CbmStsElement::GetLevel
EStsElementLevel GetLevel() const
Definition: CbmStsElement.h:85
CbmStsStation::ToString
virtual std::string ToString() const
Definition: CbmStsStation.cxx:247
CbmStsAddress.h
kStsLadder
@ kStsLadder
Definition: CbmStsAddress.h:19
CbmStsSensor::GetParams
const CbmStsParSensor * GetParams() const
Sensor parameters.
Definition: CbmStsSensor.h:83
CbmStsStation::Init
void Init()
Initialise the station parameters.
Definition: CbmStsStation.cxx:180
CbmStsElement
Class representing an element of the STS setup.
Definition: CbmStsElement.h:32
CbmStsStation
Class representing a station of the StsSystem.
Definition: CbmStsStation.h:29
CbmStsStation::~CbmStsStation
virtual ~CbmStsStation()
Definition: CbmStsStation.cxx:70
CbmStsSensor.h