18#include "FairRootManager.h"
19#include "FairRunAna.h"
20#include "FairRuntimeDb.h"
22#include "TClonesArray.h"
35using std::setprecision;
54 : FairTask(
"STSRealFindHits", iVerbose) {
68 : FairTask(name, iVerbose) {
98 if ( ! fDigiScheme ) {
99 cerr <<
"-E- " << fName <<
"::Exec: No digi scheme!" << endl;
111 Int_t nClustersF = 0;
112 Int_t nClustersB = 0;
116 for (Int_t iStation=0; iStation<nStations; iStation++) {
119 Int_t nClustersFInStation = 0;
120 Int_t nClustersBInStation = 0;
121 Int_t nHitsInStation = 0;
123 for (Int_t iSector=0; iSector<nSectors; iSector++) {
125 set <Int_t> fSet, bSet;
126 if ( fClusterMapF.find(sector) == fClusterMapF.end() ) {
127 cout <<
"-E- " << fName <<
"::Exec: sector "
134 fSet = fClusterMapF[sector];
136 if ( fClusterMapB.find(sector) == fClusterMapB.end() ) {
137 cout <<
"-E- " << fName <<
"::Exec: sector "
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);
151 <<
", Clusters front " << nClustersFInSector
152 <<
", Clusters Back " << nClustersBInSector
153 <<
", Hits " << nHitsInSector << endl;
154 nHitsInStation += nHitsInSector;
155 nClustersFInStation += nClustersFInSector;
156 nClustersBInStation += nClustersBInSector;
159 if ( fVerbose > 1 ) cout <<
"Total for station "
161 << nClustersFInStation <<
", clusters back "
162 << nClustersBInStation <<
", hits "
163 << nHitsInStation << endl;
164 nClustersB += nClustersBInStation;
165 nClustersF += nClustersFInStation;
166 nHits += nHitsInStation;
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()
181 if ( warn ) cout <<
"- ";
183 cout << setw(15) << left << fName <<
": " << setprecision(4) << setw(8)
184 << fixed << right << fTimer.RealTime()
185 <<
" s, clusters " << nClustersF <<
" / " << nClustersB <<
", hits: "
197void CbmStsRealFindHits::SetParContainers() {
200 FairRunAna*
run = FairRunAna::Instance();
201 if ( !
run ) Fatal(
"SetParContainers",
"No analysis run");
203 FairRuntimeDb* db =
run->GetRuntimeDb();
204 if ( ! db ) Fatal(
"SetParContainers",
"No runtime database");
207 fGeoPar = (
CbmGeoStsPar*) db->getContainer(
"CbmGeoStsPar");
210 fDigiPar = (
CbmStsDigiPar*) db->getContainer(
"CbmStsDigiPar");
219InitStatus CbmStsRealFindHits::Init() {
222 FairRootManager* ioman = FairRootManager::Instance();
223 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
224 fClusters = (TClonesArray*) ioman->GetObject(
"StsCluster");
227 fHits =
new TClonesArray(
"CbmStsHit", 1000);
228 ioman->Register(
"StsHit",
"Hit in STS", fHits, kTRUE);
231 Bool_t success = fDigiScheme->
Init(fGeoPar, fDigiPar);
232 if ( ! success )
return kERROR;
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;
243 <<
", Sectors: " << fDigiScheme->
GetNSectors() <<
", Channels: "
254InitStatus CbmStsRealFindHits::ReInit() {
257 fDigiScheme->
Clear();
260 Bool_t success = fDigiScheme->
Init(fGeoPar, fDigiPar);
261 if ( ! success )
return kERROR;
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;
272 <<
", Sectors: " << fDigiScheme->
GetNSectors() <<
", Channels: "
283void CbmStsRealFindHits::MakeSets() {
285 fClusterMapF.clear();
286 fClusterMapB.clear();
288 for (Int_t iStation=0; iStation<nStations; iStation++) {
291 for (Int_t iSector=0; iSector<nSectors; iSector++) {
294 fClusterMapF[sector] = a;
297 fClusterMapB[sector] = b;
309void CbmStsRealFindHits::SortClusters() {
313 cout <<
"-E- " << fName <<
"::SortClusters: No input array!" << endl;
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();
327 Int_t stationNr = -1;
330 Int_t nClusters = fClusters->GetEntriesFast();
331 for (Int_t iClus=0; iClus<nClusters ; iClus++) {
336 sector = fDigiScheme->
GetSector(stationNr, sectorNr);
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;
344 fClusterMapF[sector].insert(iClus);
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;
353 fClusterMapB[sector].insert(iClus);
366 set<Int_t>& fSet, set<Int_t>& bSet) {
373 Int_t iType = sector->
GetType();
376 Double_t dx = sector->
GetDx();
377 Double_t dy = sector->
GetDy();
385 Double_t sinrot = TMath::Sin(rot);
386 Double_t cosrot = TMath::Cos(rot);
387 Double_t tanstr = TMath::Tan(stereoB);
390 Double_t vX, vY, vXY;
392 vX = dx / TMath::Sqrt(12.);
393 vY = dy / TMath::Sqrt(12.);
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;
402 cerr <<
"-E- " << fName <<
"::FindHits: Illegal sector type "
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);
420 set<Int_t>::iterator it1;
421 set<Int_t>::iterator it2;
425 Fatal(
"FindHits",
"Sorry, not implemented yet");
430 else if ( iType == 2 ) {
431 Fatal(
"FindHits",
"Sorry, not implemented yet");
436 else if (iType == 3 ) {
441 Int_t nHits = fHits->GetEntriesFast();
448 for (it1=fSet.begin(); it1!=fSet.end(); it1++) {
452 cout <<
"-W- " << GetName() <<
"::FindHits: Invalid cluster index "
453 << iClusF <<
" in front set of sector "
459 for (it2=bSet.begin(); it2!=bSet.end(); it2++ ) {
463 cout <<
"-W- " << GetName() <<
"::FindHits: Invalid cluster index "
464 << iClusB <<
" in back set of sector "
473 if ( sensorDetId == -1 )
continue;
475 pos.SetXYZ(xHit, yHit, zHit);
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;
485 if ( statLayer == -1 )
486 cout <<
"unknown layer for hit at z = " << zHit << endl;
488 new ((*fHits)[nHits++])
CbmStsHit(sensorDetId, pos, dpos, wXY,
489 iClusF, iClusB, (Int_t)chanF, (Int_t)chanB, statLayer);
492 if ( fVerbose > 3 ) cout <<
"New StsHit at (" << xHit <<
", " << yHit
493 <<
", " << zHit <<
"), station "
494 << stationNr <<
", sector " << sectorNr
495 <<
", channel " << chanF <<
" / "
513 cout <<
"============================================================"
515 cout <<
"===== " << fName <<
": Run summary " << endl;
516 cout <<
"===== " << endl;
517 cout <<
"===== Number of hits : "
518 << setw(8) << setprecision(2)
520 cout <<
"============================================================"
Int_t GetStationNr() const
Int_t GetSectorNr() const
Double_t GetMeanError() const
void Print(Bool_t kLong=kFALSE)
CbmStsSector * GetSector(Int_t stationNr, Int_t sectorNr)
CbmStsStation * GetStation(Int_t iStation)
virtual ~CbmStsRealFindHits()
virtual void Exec(Option_t *opt)
Int_t GetSectorNr() 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)