CbmRoot
CbmStsSimSensor.cxx
Go to the documentation of this file.
1 
7 #include "CbmStsSimSensor.h"
8 
9 #include <FairField.h>
10 #include <FairRun.h>
11 #include <TGeoBBox.h>
12 
13 #include "CbmStsAddress.h"
14 #include "CbmStsElement.cxx"
15 #include "CbmStsPoint.h"
16 #include "CbmStsSensorPoint.h"
17 
18 using std::vector;
19 
21 
22 
23  // ----- Constructor ---------------------------------------------------
25  : fElement(element) {}
26 // -------------------------------------------------------------------------
27 
28 
29 // ----- Get the unique address from the sensor name (static) ----------
31 
32  Int_t unit = 10 * (name[5] - '0') + name[6] - '0' - 1;
33  Int_t ladder = 10 * (name[9] - '0') + name[10] - '0' - 1;
34  Int_t hLadder = (name[11] == 'U' ? 0 : 1);
35  Int_t module = 10 * (name[14] - '0') + name[15] - '0' - 1;
36  Int_t sensor = 10 * (name[18] - '0') + name[19] - '0' - 1;
37 
38  return CbmStsAddress::GetAddress(unit, ladder, hLadder, module, sensor);
39 }
40 // -------------------------------------------------------------------------
41 
42 
43 // ----- Get the sensor Id within the module ---------------------------
45  assert(fElement);
47 }
48 // -------------------------------------------------------------------------
49 
50 
51 // ----- Process a CbmStsPoint ------------------------------------------
53  Double_t eventTime,
54  CbmLink* link) {
55 
56  // --- Physical node
57  assert(fElement);
58  TGeoPhysicalNode* node = fElement->GetPnode();
59 
60  // --- Set current link
61  fCurrentLink = link;
62 
63  // --- Transform start coordinates into local C.S.
64  Double_t global[3];
65  Double_t local[3];
66  global[0] = point->GetXIn();
67  global[1] = point->GetYIn();
68  global[2] = point->GetZIn();
69  node->GetMatrix()->MasterToLocal(global, local);
70  Double_t x1 = local[0];
71  Double_t y1 = local[1];
72  Double_t z1 = local[2];
73 
74  // --- Transform stop coordinates into local C.S.
75  global[0] = point->GetXOut();
76  global[1] = point->GetYOut();
77  global[2] = point->GetZOut();
78  node->GetMatrix()->MasterToLocal(global, local);
79  Double_t x2 = local[0];
80  Double_t y2 = local[1];
81  Double_t z2 = local[2];
82 
83  // --- Average track direction in local c.s.
84  Double_t tXav = 0.;
85  Double_t tYav = 0.;
86  // Int_t tZav = 0;
87  if (z2 - z1 != 0.) {
88  tXav = (x2 - x1) / (z2 - z1);
89  tYav = (y2 - y1) / (z2 - z1);
90  // tZav = 1;
91  }
92 
93  // --- Normally, the entry and exit coordinates are slightly outside of
94  // --- the active node, which is a feature of the transport engine.
95  // --- We correct here for this, in case a track was entering or
96  // --- exiting the sensor (not for tracks newly created or stopped
97  // --- in the sensor volume).
98  // --- We here consider only the case of tracks leaving through the front
99  // --- or back plane. The rare case of tracks leaving through the sensor
100  // --- sides is caught by the digitisation procedure.
101  Double_t dZ = dynamic_cast<TGeoBBox*>(node->GetShape())->GetDZ();
102 
103  // --- Correct start coordinates in case of entry step
104  if (point->IsEntry()) {
105 
106  // Get track direction in local c.s.
107  global[0] = point->GetPx();
108  global[1] = point->GetPy();
109  global[2] = point->GetPz();
110  Double_t* rot;
111  rot = node->GetMatrix()->GetRotationMatrix();
112  TGeoHMatrix rotMat;
113  rotMat.SetRotation(rot);
114  rotMat.MasterToLocal(global, local);
115  if (local[2] != 0.) {
116  ; // should always be; else no correction
117  Double_t tX = local[0] / local[2]; // px/pz
118  Double_t tY = local[1] / local[2]; // py/pz
119 
120  // New start coordinates
121  Double_t xNew = 0.;
122  Double_t yNew = 0.;
123  Double_t zNew = 0.;
124  if (z1 > 0.)
125  zNew = dZ - 1.e-4; // front plane, safety margin 1 mum
126  else
127  zNew = 1.e-4 - dZ; // back plane, safety margin 1 mum
128  xNew = x1 + tX * (zNew - z1);
129  yNew = y1 + tY * (zNew - z1);
130 
131  x1 = xNew;
132  y1 = yNew;
133  z1 = zNew;
134  } //? pz != 0.
135 
136  } //? track has entered
137 
138  // --- Correct stop coordinates in case of being outside the sensor
139  if (TMath::Abs(z2) > dZ) {
140 
141  // Get track direction in local c.s.
142  global[0] = point->GetPxOut();
143  global[1] = point->GetPyOut();
144  global[2] = point->GetPzOut();
145  Double_t* rot;
146  rot = node->GetMatrix()->GetRotationMatrix();
147  TGeoHMatrix rotMat;
148  rotMat.SetRotation(rot);
149  rotMat.MasterToLocal(global, local);
150  Double_t tX = 0.;
151  Double_t tY = 0.;
152  // Use momentum components for track direction, if available
153  if (local[2] != 0.) {
154  tX = local[0] / local[2]; // px/pz
155  tY = local[1] / local[2]; // py/pz
156  }
157  // Sometimes, a track is stopped outside the sensor volume.
158  // Then we take the average track direction as best approximation.
159  // Note that there may be cases where entry and exit coordinates are
160  // the same. In this case, tXav = tYav = 0; there will be no correction
161  // of the coordinates.
162  else {
163  tX = tXav; // (x2-x1)/(z2-z1) or 0 if z2 = z1
164  tY = tYav; // (y2-y1)/(z2-z1) or 0 if z2 = z1
165  }
166 
167  // New coordinates
168  Double_t xNew = 0.;
169  Double_t yNew = 0.;
170  Double_t zNew = 0.;
171  if (z2 > 0.)
172  zNew = dZ - 1.e-4; // front plane, safety margin 1 mum
173  else
174  zNew = 1.e-4 - dZ; // back plane, safety margin 1 mum
175  xNew = x2 + tX * (zNew - z2);
176  yNew = y2 + tY * (zNew - z2);
177 
178  x2 = xNew;
179  y2 = yNew;
180  z2 = zNew;
181 
182  } //? track step outside sensor
183 
184 
185  // --- Momentum magnitude
186  Double_t px = 0.5 * (point->GetPx() + point->GetPxOut());
187  Double_t py = 0.5 * (point->GetPy() + point->GetPyOut());
188  Double_t pz = 0.5 * (point->GetPz() + point->GetPzOut());
189  Double_t p = TMath::Sqrt(px * px + py * py + pz * pz);
190 
191  // --- Get magnetic field
192  global[0] = 0.5 * (point->GetXIn() + point->GetXOut());
193  global[1] = 0.5 * (point->GetYIn() + point->GetYOut());
194  global[2] = 0.5 * (point->GetZIn() + point->GetZOut());
195  Double_t bField[3] = {0., 0., 0.};
196  if (FairRun::Instance()->GetField())
197  FairRun::Instance()->GetField()->Field(global, bField);
198 
199  // --- Absolute time of StsPoint
200  Double_t pTime = eventTime + point->GetTime();
201 
202  // --- Create SensorPoint
203  // Note: there is a conversion from kG to T in the field values.
204  CbmStsSensorPoint* sPoint = new CbmStsSensorPoint(x1,
205  y1,
206  z1,
207  x2,
208  y2,
209  z2,
210  p,
211  point->GetEnergyLoss(),
212  pTime,
213  bField[0] / 10.,
214  bField[1] / 10.,
215  bField[2] / 10.,
216  point->GetPid());
217 
218  // --- Calculate the detector response
219  Int_t result = CalculateResponse(sPoint);
220  delete sPoint;
221 
222  return result;
223 }
224 // -------------------------------------------------------------------------
CbmStsPoint::GetPid
Int_t GetPid() const
Definition: CbmStsPoint.h:90
CbmStsSimSensor::fCurrentLink
CbmLink * fCurrentLink
Definition: CbmStsSimSensor.h:174
CbmStsElement::GetAddress
Int_t GetAddress() const
Definition: CbmStsElement.h:65
CbmStsPoint::GetXOut
Double_t GetXOut() const
Definition: CbmStsPoint.h:84
CbmStsAddress::GetAddress
Int_t GetAddress(UInt_t unit=0, UInt_t ladder=0, UInt_t halfladder=0, UInt_t module=0, UInt_t sensor=0, UInt_t side=0, UInt_t version=kCurrentVersion)
Construct address.
Definition: CbmStsAddress.cxx:90
CbmStsSimSensor::ProcessPoint
Int_t ProcessPoint(const CbmStsPoint *point, Double_t eventTime=0., CbmLink *link=NULL)
Process one MC Point.
Definition: CbmStsSimSensor.cxx:52
CbmStsPoint::GetPxOut
Double_t GetPxOut() const
Definition: CbmStsPoint.h:87
CbmStsSensorPoint
Container class for a local point in a STS sensor.
Definition: CbmStsSensorPoint.h:19
CbmStsSimSensor
Class for the simulation of a sensor in the CBM-STS.
Definition: CbmStsSimSensor.h:32
CbmStsPoint::GetZOut
Double_t GetZOut() const
Definition: CbmStsPoint.h:86
CbmStsSimSensor::GetAddressFromName
static UInt_t GetAddressFromName(TString name)
Get the address from the sensor name (static)
Definition: CbmStsSimSensor.cxx:30
CbmStsPoint
Definition: CbmStsPoint.h:27
CbmStsSimSensor::CbmStsSimSensor
CbmStsSimSensor(CbmStsElement *element=nullptr)
Standard constructor.
CbmStsPoint::IsEntry
Bool_t IsEntry() const
Definition: CbmStsPoint.h:92
CbmStsElement::GetPnode
TGeoPhysicalNode * GetPnode() const
Definition: CbmStsElement.h:106
CbmStsSimSensor::CalculateResponse
virtual Int_t CalculateResponse(CbmStsSensorPoint *point)=0
Link to currently processed MCPoint.
z2
Double_t z2[nSects2]
Definition: pipe_v16a_mvdsts100.h:11
CbmStsPoint::GetPyOut
Double_t GetPyOut() const
Definition: CbmStsPoint.h:88
CbmStsPoint::GetYOut
Double_t GetYOut() const
Definition: CbmStsPoint.h:85
CbmStsAddress::GetElementId
UInt_t GetElementId(Int_t address, Int_t level)
Get the index of an element.
Definition: CbmStsAddress.cxx:180
CbmStsElement.cxx
CbmStsPoint::GetXIn
Double_t GetXIn() const
Definition: CbmStsPoint.h:81
CbmStsPoint::GetYIn
Double_t GetYIn() const
Definition: CbmStsPoint.h:82
CbmStsSimSensor.h
CbmStsPoint::GetPzOut
Double_t GetPzOut() const
Definition: CbmStsPoint.h:89
CbmStsPoint.h
ClassImp
ClassImp(CbmStsSimSensor) CbmStsSimSensor
Definition: CbmStsSimSensor.cxx:20
CbmStsPoint::GetZIn
Double_t GetZIn() const
Definition: CbmStsPoint.h:83
kStsSensor
@ kStsSensor
Definition: CbmStsAddress.h:22
CbmStsAddress.h
CbmStsSimSensor::GetSensorId
Int_t GetSensorId() const
Sensor ID.
Definition: CbmStsSimSensor.cxx:44
z1
Double_t z1[nSects1]
Definition: pipe_v16a_mvdsts100.h:6
CbmStsSimSensor::fElement
CbmStsElement * fElement
Definition: CbmStsSimSensor.h:166
CbmStsSensorPoint.h
CbmStsElement
Class representing an element of the STS setup.
Definition: CbmStsElement.h:32