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