BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
CbmStsIdealDigitize.cxx
Go to the documentation of this file.
1//* $Id: */
2
3// -------------------------------------------------------------------------
4// ----- CbmStsDigitize source file -----
5// ----- Created 30/08/06 by V. Friese -----
6// -------------------------------------------------------------------------
7
8// Includes from STS
10
11#include "CbmGeoStsPar.h"
12#include "CbmStsDigi.h"
13#include "CbmStsDigiMatch.h"
14#include "CbmStsDigiPar.h"
15#include "CbmStsDigiScheme.h"
16#include "CbmStsPoint.h"
17#include "CbmStsSector.h"
18#include "CbmStsSensor.h"
19#include "CbmStsStation.h"
20
21// Includes from base
22#include "FairRootManager.h"
23#include "FairRunAna.h"
24#include "FairRuntimeDb.h"
25
26// Includes from ROOT
27#include "TClonesArray.h"
28#include "TGeoManager.h"
29#include "TGeoNode.h"
30#include "TMath.h"
31#include "TObjArray.h"
32
33#include <iomanip>
34#include <iostream>
35#include <map>
36
37using std::cerr;
38using std::cout;
39using std::endl;
40using std::fixed;
41using std::left;
42using std::map;
43using std::pair;
44using std::right;
45using std::setprecision;
46using std::setw;
47
48// ----- Default constructor ------------------------------------------
50 : FairTask("STS Digitizer", 1)
51 , fGeoPar(NULL)
52 , fDigiPar(NULL)
53 , fDigiScheme(NULL)
54 , fPoints(NULL)
55 , fDigis(NULL)
56 , fDigiMatches(NULL)
57 , fNPoints(0)
58 , fNFailed(0)
59 , fNOutside(0)
60 , fNMulti(0)
61 , fNDigis(0)
62 , fTimer()
63 , fChannelMap()
64{
65 Reset();
66}
67// -------------------------------------------------------------------------
68
69// ----- Standard constructor ------------------------------------------
71 : FairTask("STSDigitize", iVerbose)
72 , fGeoPar(NULL)
73 , fDigiPar(NULL)
74 , fDigiScheme(NULL)
75 , fPoints(NULL)
76 , fDigis(NULL)
77 , fDigiMatches(NULL)
78 , fNPoints(0)
79 , fNFailed(0)
80 , fNOutside(0)
81 , fNMulti(0)
82 , fNDigis(0)
83 , fTimer()
84 , fChannelMap()
85{
86 Reset();
87}
88// -------------------------------------------------------------------------
89
90// ----- Constructor with name -----------------------------------------
92 : FairTask(name, iVerbose)
93 , fGeoPar(NULL)
94 , fDigiPar(NULL)
95 , fDigiScheme(NULL)
96 , fPoints(NULL)
97 , fDigis(NULL)
98 , fDigiMatches(NULL)
99 , fNPoints(0)
100 , fNFailed(0)
101 , fNOutside(0)
102 , fNMulti(0)
103 , fNDigis(0)
104 , fTimer()
105 , fChannelMap()
106{
108 Reset();
109}
110// -------------------------------------------------------------------------
111
112// ----- Destructor ----------------------------------------------------
114{
115 if (fGeoPar)
116 delete fGeoPar;
117 if (fDigiPar)
118 delete fDigiPar;
119 if (fDigis) {
120 fDigis->Delete();
121 delete fDigis;
122 }
123 if (fDigiMatches) {
124 fDigiMatches->Delete();
125 delete fDigiMatches;
126 }
127 if (fDigiScheme)
128 delete fDigiScheme;
129 Reset();
130}
131// -------------------------------------------------------------------------
132
133// ----- Public method Exec --------------------------------------------
135{
136
137 // Reset all eventwise counters
138 fTimer.Start();
139 Reset();
140
141 // Verbose screen output
142 if (fVerbose > 2) {
143 cout << endl << "-I- " << fName << ": executing event" << endl;
144 cout << "----------------------------------------------" << endl;
145 }
146
147 // Loop over all StsPoints
148 if (!fPoints) {
149 cerr << "-W- " << fName << "::Exec: No input array (STSPoint) " << endl;
150 cout << "- " << fName << endl;
151 return;
152 }
153
154 for (Int_t iPoint = 0; iPoint < fPoints->GetEntriesFast(); iPoint++) {
155 CbmStsPoint* point = (CbmStsPoint*)fPoints->At(iPoint);
156 fNPoints++;
157
158 Double_t xIn = point->GetXIn();
159 Double_t yIn = point->GetYIn();
160 Double_t zIn = point->GetZIn();
161
162 gGeoManager->FindNode(xIn, yIn, zIn);
163 TGeoNode* curNode = gGeoManager->GetCurrentNode();
164
165 // AZ CbmStsSensor* sensor = fDigiScheme->GetSensorByName(curNode->GetName());
166 // AZ
167 CbmStsSensor* sensor = NULL;
168 if (fDigiScheme->IsNewGeometry()) {
169 TString curPath = fDigiScheme->GetCurrentPath();
170 sensor = fDigiScheme->GetSensorByName(curPath);
171 } else
172 sensor = fDigiScheme->GetSensorByName(curNode->GetName());
173 // AZ
174
175 if (!sensor)
176 LOG(fatal) << "No sensor in DigiScheme with name: " << curNode->GetName();
177
178 Int_t stationNr = sensor->GetStationNr();
179 Int_t sectorNr = sensor->GetSectorNr();
180
181 // Take point coordinates in the midplane of the sensor
182 if (!point->IsUsable())
183 continue;
184 Double_t xpt = point->GetX(sensor->GetZ0());
185 Double_t ypt = point->GetY(sensor->GetZ0());
186
187 Int_t iChan = -1;
188 Int_t channelF = -1;
189 Int_t channelB = -1;
190
191 iChan = sensor->GetChannel(xpt, ypt, 0);
192
193 // point outside active sensor area
194 if (iChan < 0) {
195 if (fVerbose) {
196 Float_t tempX = sensor->GetX0();
197 Float_t tempY = sensor->GetY0();
198 Float_t rot = sensor->GetRotation();
199 Float_t tempLX = sensor->GetLx() / 2. * TMath::Cos(rot) + sensor->GetLy() / 2. * TMath::Sin(rot);
200 Float_t tempLY = sensor->GetLy() / 2. * TMath::Cos(rot) + sensor->GetLx() / 2. * TMath::Sin(rot);
201
202 cout.precision(8);
203 cout << fName << ". Warning: Point " << xpt << ", " << ypt << ", " << sensor->GetZ0()
204 << " not inside sector." << endl;
205 }
206 continue;
207 }
208
209 channelF = iChan;
210
211 Int_t sectorDetId = 2 << 24 | stationNr << 16 | sectorNr << 4;
212
213 // Treat front side
214 pair<Int_t, Int_t> a(sectorDetId, channelF);
215 if (fChannelMap.find(a) == fChannelMap.end()) {
216 // Channel not yet active. Create new Digi and Match.
217 new ((*fDigis)[fNDigis]) CbmStsDigi(stationNr, sectorNr, 0, channelF, 0, 0);
218 new ((*fDigiMatches)[fNDigis]) CbmStsDigiMatch(iPoint);
219 fChannelMap[a] = fNDigis;
220 fNDigis++;
221 } else {
222 // Channel already active. Update DigiMatch.
223 Int_t iDigi = fChannelMap[a];
224 CbmStsDigiMatch* match = dynamic_cast<CbmStsDigiMatch*>(fDigiMatches->At(iDigi));
225 if (match) {
226 match->AddPoint(iPoint);
227 fNMulti++;
228 }
229 }
230
231 // Treat back side (strip sensors only)
232 if (sensor->GetType() < 2 || sensor->GetType() > 3)
233 continue;
234
235 iChan = sensor->GetChannel(xpt, ypt, 1);
236 if (iChan < 0) {
237 cerr << "-W- " << fName << "::Exec: No back side channel "
238 << " for StsPoint " << iPoint << ", station " << stationNr << ", sector " << sectorNr
239 << ", front side channel " << channelF << endl;
240 continue;
241 }
242 sectorDetId = sectorDetId | (1 << 0); // for back side channel
243 channelB = iChan;
244 pair<Int_t, Int_t> b(sectorDetId, channelB);
245 if (fChannelMap.find(b) == fChannelMap.end()) {
246 // Channel not yet active. Create new Digi and Match.
247 new ((*fDigis)[fNDigis]) CbmStsDigi(stationNr, sectorNr, 1, channelB, 0, 0);
248 new ((*fDigiMatches)[fNDigis]) CbmStsDigiMatch(iPoint);
249 fChannelMap[b] = fNDigis;
250 fNDigis++;
251 } else {
252 // Channel already active. Update DigiMatch.
253 Int_t iDigi = fChannelMap[b];
254 CbmStsDigiMatch* match = dynamic_cast<CbmStsDigiMatch*>(fDigiMatches->At(iDigi));
255 if (match) {
256 match->AddPoint(iPoint);
257 fNMulti++;
258 }
259 }
260
261 // Verbose screen output
262 if (fVerbose > 2) {
263 cout.precision(6);
264 cout << "StsPoint " << iPoint << ", station " << stationNr << ", (" << xpt << ", " << ypt << ") cm, sector "
265 << sectorNr << ", front " << channelF << ", back " << channelB << endl;
266 }
267
268 // Not found in any sector?
269 if (sectorNr == -1)
270 fNOutside++;
271
272 } // StsPoint loop
273
274 // Screen output
275 fTimer.Stop();
276 if (fVerbose) {
277 cout << "+ ";
278 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8) << fixed << right << fTimer.RealTime()
279 << " s, points " << fNPoints << ", failed " << fNFailed << ", outside " << fNOutside << ", multihits "
280 << fNMulti << ", digis " << fNDigis << endl;
281 }
282}
283// -------------------------------------------------------------------------
284
285// ----- Private method SetParContainers -------------------------------
287{
288
289 // Get run and runtime database
290 FairRunAna* run = FairRunAna::Instance();
291 if (!run)
292 Fatal("SetParContainers", "No analysis run");
293
294 FairRuntimeDb* db = run->GetRuntimeDb();
295 if (!db)
296 Fatal("SetParContainers", "No runtime database");
297
298 // Get STS geometry parameter container
299 fGeoPar = (CbmGeoStsPar*)db->getContainer("CbmGeoStsPar");
300
301 // Get STS digitisation parameter container
302 fDigiPar = (CbmStsDigiPar*)db->getContainer("CbmStsDigiPar");
303}
304// -------------------------------------------------------------------------
305
306// ----- Private method Init -------------------------------------------
308{
309
310 // Get input array
311 FairRootManager* ioman = FairRootManager::Instance();
312 if (!ioman)
313 Fatal("Init", "No FairRootManager");
314 fPoints = (TClonesArray*)ioman->GetObject("StsPoint");
315
316 // Register output array StsDigi
317 fDigis = new TClonesArray("CbmStsDigi", 1000);
318 ioman->Register("StsDigi", "Digital response in STS", fDigis, kTRUE);
319
320 // Register output array StsDigiMatches
321 fDigiMatches = new TClonesArray("CbmStsDigiMatch", 1000);
322 ioman->Register("StsDigiMatch", "Digi Match in STS", fDigiMatches, kTRUE);
323
324 // Build digitisation scheme
325 if (fDigiScheme->Init(fGeoPar, fDigiPar)) {
326 if (fVerbose == 1 || fVerbose == 2)
327 fDigiScheme->Print(kFALSE);
328 else if (fVerbose > 2)
329 fDigiScheme->Print(kTRUE);
330 cout << "-I- " << fName << "::Init: "
331 << "STS digitisation scheme succesfully initialised" << endl;
332 cout << " Stations: " << fDigiScheme->GetNStations() << ", Sectors: " << fDigiScheme->GetNSectors()
333 << ", Channels: " << fDigiScheme->GetNChannels() << endl;
334 return kSUCCESS;
335 }
336
337 return kERROR;
338}
339// -------------------------------------------------------------------------
340
341// ----- Private method ReInit -----------------------------------------
343{
344
345 // Clear digitisation scheme
346 fDigiScheme->Clear();
347
348 // Build new digitisation scheme
349 if (fDigiScheme->Init(fGeoPar, fDigiPar))
350 return kSUCCESS;
351
352 return kERROR;
353}
354// -------------------------------------------------------------------------
355
356// ----- Private method Reset ------------------------------------------
358{
360 fChannelMap.clear();
361 // if ( fDigis ) fDigis->Clear();
362 // if ( fDigiMatches ) fDigiMatches->Clear();
363 if (fDigis)
364 fDigis->Delete();
365 if (fDigiMatches)
366 fDigiMatches->Delete();
367}
368// -------------------------------------------------------------------------
int Int_t
float Float_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TGeoManager * gGeoManager
CbmStsDigiMatch.h.
CbmStsDigi.h.
Definition CbmStsDigi.h:32
virtual ~CbmStsIdealDigitize()
Destructor.
TClonesArray * fPoints
Digitisation scheme.
Int_t fNPoints
Output array of CbmStsDigiMatches.
CbmStsDigiPar * fDigiPar
Geometry parameter container.
CbmStsDigiScheme * fDigiScheme
Digitisation parameter container.
virtual void Exec(Option_t *opt)
Execution.
TClonesArray * fDigis
Input array of CbmStsPoint.
virtual void SetParContainers()
Get parameter containers.
void Reset()
Reset eventwise counters.
std::map< std::pair< Int_t, Int_t >, Int_t > fChannelMap
Map of active channels (pair detectorId, channel number) to index of StsDigi.
TClonesArray * fDigiMatches
Output array of CbmStsDigi.
CbmStsIdealDigitize()
Default constructor.
virtual InitStatus Init()
Intialisation.
virtual InitStatus ReInit()
Reinitialisation.
Bool_t IsUsable() const
Check for distance between in and out.
Double_t GetY(Double_t z) const
Double_t GetX(Double_t z) const
Point coordinates at given z from linear extrapolation.
Double_t GetXIn() const
Accessors.
Definition CbmStsPoint.h:64
Double_t GetZIn() const
Definition CbmStsPoint.h:66
Double_t GetYIn() const
Definition CbmStsPoint.h:65
Double_t GetZ0() const
Double_t GetRotation() const
Int_t GetType() const
Double_t GetX0() const
Double_t GetLy() const
Int_t GetSectorNr() const
Int_t GetStationNr() const
Int_t GetChannel(Double_t x, Double_t y, Int_t iSide)
Calculate channel number for a coordinate pair.
Double_t GetY0() const
Double_t GetLx() const
const char * GetName() const override
Double_t Cos(Double_t)
Double_t Sin(Double_t)