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