BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
CbmStsRealFindHits.cxx
Go to the documentation of this file.
1//* $Id: */
2
3// -------------------------------------------------------------------------
4// ----- CbmStsRealFindHits source file -----
5// ----- Created 26/06/2008 by R. Karabowicz -----
6// -------------------------------------------------------------------------
7
9
10#include "CbmGeoStsPar.h"
11#include "CbmStsCluster.h"
12#include "CbmStsDigiPar.h"
13#include "CbmStsDigiScheme.h"
14#include "CbmStsHit.h"
15#include "CbmStsSector.h"
16#include "CbmStsStation.h"
17#include "FairRootManager.h"
18#include "FairRunAna.h"
19#include "FairRuntimeDb.h"
20#include "TClonesArray.h"
21#include "TMath.h"
22
23#include <iomanip>
24
25using std::cerr;
26using std::cout;
27using std::endl;
28using std::fixed;
29using std::flush;
30using std::left;
31using std::map;
32using std::right;
33using std::set;
34using std::setprecision;
35using std::setw;
36
37// ----- Default constructor ------------------------------------------
39 : FairTask("STS Hit Finder", 1)
40{
41 fGeoPar = NULL;
42 fDigiPar = NULL;
43 fClusters = NULL;
44 fHits = NULL;
45 fNHits = 0;
47}
48// -------------------------------------------------------------------------
49
50// ----- Standard constructor ------------------------------------------
52 : FairTask("STSRealFindHits", iVerbose)
53{
54 fGeoPar = NULL;
55 fDigiPar = NULL;
56 fClusters = NULL;
57 fHits = NULL;
58 fNHits = 0;
60}
61// -------------------------------------------------------------------------
62
63// ----- Constructor with name -----------------------------------------
65 : FairTask(name, iVerbose)
66{
67 fGeoPar = NULL;
68 fDigiPar = NULL;
69 fClusters = NULL;
70 fHits = NULL;
71 fNHits = 0;
73}
74// -------------------------------------------------------------------------
75
76// ----- Destructor ----------------------------------------------------
78{
79 if (fHits) {
80 fHits->Delete();
81 delete fHits;
82 }
83}
84// -------------------------------------------------------------------------
85
86// ----- Public method Exec --------------------------------------------
88{
89
90 fTimer.Start();
91 Bool_t warn = kFALSE;
92
93 // Check for digi scheme
94 if (!fDigiScheme) {
95 cerr << "-E- " << fName << "::Exec: No digi scheme!" << endl;
96 return;
97 }
98
99 // Clear output array
100 // fHits->Clear();
101 fHits->Delete();
102
103 // Sort STS digis with respect to sectors
104 SortClusters();
105
106 // Find hits in sectors
107 Int_t nClustersF = 0;
108 Int_t nClustersB = 0;
109 Int_t nHits = 0;
110 Int_t nStations = fDigiScheme->GetNStations();
111 CbmStsStation* station = NULL;
112 for (Int_t iStation = 0; iStation < nStations; iStation++) {
113 station = fDigiScheme->GetStation(iStation);
114
115 Int_t nClustersFInStation = 0;
116 Int_t nClustersBInStation = 0;
117 Int_t nHitsInStation = 0;
118 Int_t nSectors = station->GetNSectors();
119 for (Int_t iSector = 0; iSector < nSectors; iSector++) {
120 CbmStsSector* sector = station->GetSector(iSector);
121 set<Int_t> fSet, bSet;
122 if (fClusterMapF.find(sector) == fClusterMapF.end()) {
123 cout << "-E- " << fName << "::Exec: sector " << sector->GetSectorNr() << " of station "
124 << station->GetStationNr() << "not found in front map!" << endl;
125 warn = kTRUE;
126 continue;
127 }
128 fSet = fClusterMapF[sector];
129 if (sector->GetType() == 2 || sector->GetType() == 3) {
130 if (fClusterMapB.find(sector) == fClusterMapB.end()) {
131 cout << "-E- " << fName << "::Exec: sector " << sector->GetSectorNr() << " of station "
132 << station->GetStationNr() << "not found in back map!" << endl;
133 warn = kTRUE;
134 continue;
135 }
136 }
137 bSet = fClusterMapB[sector];
138 Int_t nClustersFInSector = fSet.size();
139 Int_t nClustersBInSector = bSet.size();
140 Int_t nHitsInSector = FindHits(station, sector, fSet, bSet);
141 if (fVerbose > 2)
142 cout << "Sector " << sector->GetSectorNr() << ", Clusters front " << nClustersFInSector
143 << ", Clusters Back " << nClustersBInSector << ", Hits " << nHitsInSector << endl;
144 nHitsInStation += nHitsInSector;
145 nClustersFInStation += nClustersFInSector;
146 nClustersBInStation += nClustersBInSector;
147 } // Sector loop
148
149 if (fVerbose > 1)
150 cout << "Total for station " << station->GetStationNr() << ": Clusters front " << nClustersFInStation
151 << ", clusters back " << nClustersBInStation << ", hits " << nHitsInStation << endl;
152 nClustersB += nClustersBInStation;
153 nClustersF += nClustersFInStation;
154 nHits += nHitsInStation;
155
156 } // Station loop
157
158 fTimer.Stop();
159 if (fVerbose) {
160 cout << endl;
161 cout << "-I- " << fName << ":Event summary" << endl;
162 cout << " Clusters front side : " << nClustersF << endl;
163 cout << " Clusters back side : " << nClustersB << endl;
164 cout << " Hits created : " << nHits << endl;
165 cout << " Real time : " << fTimer.RealTime() << endl;
166 } else {
167 if (warn)
168 cout << "- ";
169 else
170 cout << "+ ";
171 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8) << fixed << right << fTimer.RealTime()
172 << " s, clusters " << nClustersF << " / " << nClustersB << ", hits: " << nHits << endl;
173 }
174
175 fNHits += nHits;
176}
177// -------------------------------------------------------------------------
178
179// ----- Private method SetParContainers -------------------------------
181{
182
183 // Get run and runtime database
184 FairRunAna* run = FairRunAna::Instance();
185 if (!run)
186 Fatal("SetParContainers", "No analysis run");
187
188 FairRuntimeDb* db = run->GetRuntimeDb();
189 if (!db)
190 Fatal("SetParContainers", "No runtime database");
191
192 // Get STS geometry parameter container
193 fGeoPar = (CbmGeoStsPar*)db->getContainer("CbmGeoStsPar");
194
195 // Get STS digitisation parameter container
196 fDigiPar = (CbmStsDigiPar*)db->getContainer("CbmStsDigiPar");
197}
198// -------------------------------------------------------------------------
199
200// ----- Private method Init -------------------------------------------
202{
203
204 // Get input array
205 FairRootManager* ioman = FairRootManager::Instance();
206 if (!ioman)
207 Fatal("Init", "No FairRootManager");
208 fClusters = (TClonesArray*)ioman->GetObject("StsCluster");
209
210 // Register output array
211 fHits = new TClonesArray("CbmStsHit", 1000);
212 ioman->Register("StsHit", "Hit in STS", fHits, kTRUE);
213
214 // Build digitisation scheme
215 Bool_t success = fDigiScheme->Init(fGeoPar, fDigiPar);
216 if (!success)
217 return kERROR;
218
219 // Create sectorwise cluster sets
220 MakeSets();
221
222 // Control output
223 if (fVerbose == 1 || fVerbose == 2)
224 fDigiScheme->Print(kFALSE);
225 else if (fVerbose > 2)
226 fDigiScheme->Print(kTRUE);
227 cout << "-I- " << fName << "::Init: "
228 << "STS digitisation scheme succesfully initialised" << endl;
229 cout << " Stations: " << fDigiScheme->GetNStations() << ", Sectors: " << fDigiScheme->GetNSectors()
230 << ", Channels: " << fDigiScheme->GetNChannels() << endl;
231
232 return kSUCCESS;
233}
234// -------------------------------------------------------------------------
235
236// ----- Private method ReInit -----------------------------------------
238{
239
240 // Clear digitisation scheme
241 fDigiScheme->Clear();
242
243 // Build new digitisation scheme
244 Bool_t success = fDigiScheme->Init(fGeoPar, fDigiPar);
245 if (!success)
246 return kERROR;
247
248 // Create sectorwise digi sets
249 MakeSets();
250
251 // Control output
252 if (fVerbose == 1 || fVerbose == 2)
253 fDigiScheme->Print(kFALSE);
254 else if (fVerbose > 2)
255 fDigiScheme->Print(kTRUE);
256 cout << "-I- " << fName << "::Init: "
257 << "STS digitisation scheme succesfully reinitialised" << endl;
258 cout << " Stations: " << fDigiScheme->GetNStations() << ", Sectors: " << fDigiScheme->GetNSectors()
259 << ", Channels: " << fDigiScheme->GetNChannels() << endl;
260
261 return kSUCCESS;
262}
263// -------------------------------------------------------------------------
264
265// ----- Private method MakeSets ---------------------------------------
267{
268
269 fClusterMapF.clear();
270 fClusterMapB.clear();
271 Int_t nStations = fDigiScheme->GetNStations();
272 for (Int_t iStation = 0; iStation < nStations; iStation++) {
273 CbmStsStation* station = fDigiScheme->GetStation(iStation);
274 Int_t nSectors = station->GetNSectors();
275 for (Int_t iSector = 0; iSector < nSectors; iSector++) {
276 CbmStsSector* sector = station->GetSector(iSector);
277 set<Int_t> a;
278 fClusterMapF[sector] = a;
279 if (sector->GetType() == 2 || sector->GetType() == 3) {
280 set<Int_t> b;
281 fClusterMapB[sector] = b;
282 }
283 }
284 }
285}
286// -------------------------------------------------------------------------
287
288// ----- Private method SortClusters --------------------------------------
290{
291
292 // Check input array
293 if (!fClusters) {
294 cout << "-E- " << fName << "::SortClusters: No input array!" << endl;
295 return;
296 }
297
298 // Clear sector cluster sets
299 map<CbmStsSector*, set<Int_t>>::iterator mapIt;
300 for (mapIt = fClusterMapF.begin(); mapIt != fClusterMapF.end(); mapIt++)
301 ((*mapIt).second).clear();
302 for (mapIt = fClusterMapB.begin(); mapIt != fClusterMapB.end(); mapIt++)
303 ((*mapIt).second).clear();
304
305 // Fill clusters into sets
306 CbmStsCluster* cluster = NULL;
307 CbmStsSector* sector = NULL;
308 Int_t stationNr = -1;
309 Int_t sectorNr = -1;
310 Int_t iSide = -1;
311 Int_t nClusters = fClusters->GetEntriesFast();
312 for (Int_t iClus = 0; iClus < nClusters; iClus++) {
313 cluster = (CbmStsCluster*)fClusters->At(iClus);
314 stationNr = cluster->GetStationNr();
315 sectorNr = cluster->GetSectorNr();
316 iSide = cluster->GetSide();
317 sector = fDigiScheme->GetSector(stationNr, sectorNr);
318 if (iSide == 0) {
319 if (fClusterMapF.find(sector) == fClusterMapF.end()) {
320 cerr << "-E- " << fName << "::SortClusters:: sector " << sectorNr << " of station " << stationNr
321 << " not found in digi scheme (F)!" << endl;
322 continue;
323 }
324 fClusterMapF[sector].insert(iClus);
325 } else if (iSide == 1) {
326 if (fClusterMapB.find(sector) == fClusterMapB.end()) {
327 cerr << "-E- " << fName << "::SortClusters:: sector " << sectorNr << " of station " << stationNr
328 << " not found in digi scheme (B)!" << endl;
329 continue;
330 }
331 fClusterMapB[sector].insert(iClus);
332 }
333 }
334}
335// -------------------------------------------------------------------------
336
337// ----- Private method FindHits ---------------------------------------
338Int_t CbmStsRealFindHits::FindHits(CbmStsStation* station, CbmStsSector* sector, set<Int_t>& fSet, set<Int_t>& bSet)
339{
340
341 // Counter
342 Int_t nNew = 0;
343
344 // Get sector parameters
345 Int_t detId = sector->GetDetectorId();
346 Int_t iType = sector->GetType();
347
348 Double_t rot = sector->GetRotation();
349 Double_t dx = sector->GetDx();
350 Double_t dy = sector->GetDy();
351 Double_t stereoB = sector->GetStereoB();
352
353 // Double_t z = station->GetZ();
354 Int_t stationNr = station->GetStationNr();
355 Int_t sectorNr = sector->GetSectorNr();
356
357 // Some auxiliary values
358 Double_t sinrot = TMath::Sin(rot);
359 Double_t cosrot = TMath::Cos(rot);
360 Double_t tanstr = TMath::Tan(stereoB);
361
362 // Calculate error matrix in sector system
363 Double_t vX, vY, vXY;
364 if (iType == 1) {
365 vX = dx / TMath::Sqrt(12.);
366 vY = dy / TMath::Sqrt(12.);
367 vXY = 0.;
368 } else if (iType == 2 || iType == 3) {
369 vX = dx / TMath::Sqrt(12.);
370 vY = dx / TMath::Sqrt(6.) / TMath::Abs(tanstr);
371 vXY = -1. * dx * dx / 12. / tanstr;
372 } else {
373 cerr << "-E- " << fName << "::FindHits: Illegal sector type " << iType << endl;
374 return 0;
375 }
376
377 // Transform variances into global c.s.
378 Double_t wX = vX * vX * cosrot * cosrot - 2. * vXY * cosrot * sinrot + vY * vY * sinrot * sinrot;
379 Double_t wY = vX * vX * sinrot * sinrot + 2. * vXY * cosrot * sinrot + vY * vY * cosrot * cosrot;
380 Double_t wXY = (vX * vX - vY * vY) * cosrot * sinrot + vXY * (cosrot * cosrot - sinrot * sinrot);
381 Double_t sigmaX = TMath::Sqrt(wX);
382 Double_t sigmaY = TMath::Sqrt(wY);
383
384 // Now perform the loop over active channels
385 set<Int_t>::iterator it1;
386 set<Int_t>::iterator it2;
387
388 // ----- Type 1 : Pixel sector ---------------------------------------
389 if (iType == 1) {
390 Fatal("FindHits", "Sorry, not implemented yet");
391 } // Pixel sensor
392 // ---------------------------------------------------------------------
393
394 // ----- Type 2: Strip sector OSU -----------------------------------
395 else if (iType == 2)
396 {
397 Fatal("FindHits", "Sorry, not implemented yet");
398 } // Strip OSU
399 // ---------------------------------------------------------------------
400
401 // ----- Type 3: Strip sector GSI -----------------------------------
402 else if (iType == 3)
403 {
404 Int_t iClusF = -1;
405 Int_t iClusB = -1;
406 Double_t chanF = -1;
407 Double_t chanB = -1;
408 Int_t nHits = fHits->GetEntriesFast();
409 Double_t xHit;
410 Double_t yHit;
411 Double_t zHit;
412 TVector3 pos, dpos;
413 CbmStsCluster* clusterF = NULL;
414 CbmStsCluster* clusterB = NULL;
415 for (it1 = fSet.begin(); it1 != fSet.end(); it1++) {
416 iClusF = (*it1);
417 clusterF = (CbmStsCluster*)fClusters->At(iClusF);
418 if (!clusterF) {
419 cout << "-W- " << GetName() << "::FindHits: Invalid cluster index " << iClusF
420 << " in front set of sector " << sector->GetSectorNr() << ", station " << station->GetStationNr()
421 << endl;
422 continue;
423 }
424 chanF = clusterF->GetMean();
425 for (it2 = bSet.begin(); it2 != bSet.end(); it2++) {
426 iClusB = (*it2);
427 clusterB = (CbmStsCluster*)fClusters->At(iClusB);
428 if (!clusterB) {
429 cout << "-W- " << GetName() << "::FindHits: Invalid cluster index " << iClusB
430 << " in back set of sector " << sector->GetSectorNr() << ", station "
431 << station->GetStationNr() << endl;
432 continue;
433 }
434 chanB = clusterB->GetMean();
435
436 Int_t sensorDetId = sector->IntersectClusters(chanF, chanB, xHit, yHit, zHit);
437
438 if (sensorDetId == -1)
439 continue;
440
441 pos.SetXYZ(xHit, yHit, zHit);
442 dpos.SetXYZ(sigmaX * clusterF->GetMeanError(), sigmaY * clusterB->GetMeanError(), 0.);
443
444 Int_t statLayer = -1;
445 for (Int_t istatL = station->GetNofZ(); istatL > 0; istatL--)
446 if (TMath::Abs(zHit - station->GetZ(istatL - 1)) < 0.00001) {
447 statLayer = istatL - 1;
448 break;
449 }
450
451 if (statLayer == -1)
452 cout << "unknown layer for hit at z = " << zHit << endl;
453
454 new ((*fHits)[nHits++])
455 CbmStsHit(sensorDetId, pos, dpos, wXY, iClusF, iClusB, (Int_t)chanF, (Int_t)chanB, statLayer);
456
457 nNew++;
458 if (fVerbose > 3)
459 cout << "New StsHit at (" << xHit << ", " << yHit << ", " << zHit << "), station " << stationNr
460 << ", sector " << sectorNr << ", channel " << chanF << " / " << chanB << endl;
461
462 } // back side strip loop
463 } // front side strip loop
464
465 } // strip GSI
466 // ---------------------------------------------------------------------
467
468 return nNew;
469}
470// -------------------------------------------------------------------------
471
472// ----- Virtual method Finish -----------------------------------------
474{
475 cout << endl;
476 cout << "============================================================" << endl;
477 cout << "===== " << fName << ": Run summary " << endl;
478 cout << "===== " << endl;
479 cout << "===== Number of hits : " << setw(8) << setprecision(2) << fNHits << endl;
480 cout << "============================================================" << endl;
481}
482// -------------------------------------------------------------------------
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
void Fatal(const char *location, const char *msgfmt,...)
CbmStsCluster.h.
Int_t GetStationNr() const
Int_t GetSectorNr() const
Double_t GetMean() const
Double_t GetMeanError() const
Int_t GetSide() const
virtual ~CbmStsRealFindHits()
Destructor.
virtual void Exec(Option_t *opt)
Execution.
void SortClusters()
Sort digis sectorwise.
virtual InitStatus ReInit()
Reinitialisation.
std::map< CbmStsSector *, std::set< Int_t > > fClusterMapF
Output array of CbmStsHit.
Int_t FindHits(CbmStsStation *station, CbmStsSector *sector, std::set< Int_t > &fSet, std::set< Int_t > &bSet)
Find hits in one sector.
std::map< CbmStsSector *, std::set< Int_t > > fClusterMapB
sector clusters (front)
CbmStsDigiScheme * fDigiScheme
Digitisation parameters.
CbmStsDigiPar * fDigiPar
Geometry parameters.
TClonesArray * fClusters
Digitisation scheme.
TStopwatch fTimer
sector clusters (back)
TClonesArray * fHits
Input array of CbmStsCluster.
virtual void Finish()
Virtual method Finish.
virtual InitStatus Init()
Intialisation.
void MakeSets()
Make sectorwise sets for sigis.
CbmStsRealFindHits()
Default constructor.
virtual void SetParContainers()
Get parameter containers.
Int_t GetType() const
Int_t GetSectorNr() const
Double_t GetDx() const
Double_t GetDy() const
Int_t IntersectClusters(Double_t fChan, Double_t bChan, Double_t &xCross, Double_t &yCross, Double_t &zCross)
Int_t GetDetectorId() const
Double_t GetRotation() const
Double_t GetStereoB() const
Int_t GetNSectors() const
Double_t GetZ(Int_t it=0)
Int_t GetStationNr() const
CbmStsSector * GetSector(Int_t iSector)
void SetXYZ(Double_t x, Double_t y, Double_t z)
Double_t Sqrt(Double_t x)
Double_t Cos(Double_t)
Double_t Abs(Double_t d)
Double_t Sin(Double_t)
Double_t Tan(Double_t)