8#include "TClonesArray.h"
11#include "FairRootManager.h"
12#include "FairRunAna.h"
13#include "FairRuntimeDb.h"
36using std::setprecision;
56 : FairTask(
"STSClusterFinder", iVerbose) {
69 : FairTask(name, iVerbose) {
98 cout << endl <<
"-I- " << fName <<
": executing event with " << fDigis->GetEntriesFast() <<
" digis." << endl;
99 cout <<
"----------------------------------------------" << endl;
103 if ( ! fDigiScheme ) {
104 cerr <<
"-E- " << fName <<
"::Exec: No digi scheme!" << endl;
123 for (Int_t iStation=0; iStation<nStations; iStation++) {
125 Int_t nDigisFInStation = 0;
126 Int_t nDigisBInStation = 0;
129 for (Int_t iSector=0; iSector<nSectors; iSector++) {
133 set <Int_t> fSet, bSet;
134 if ( fDigiMapF.find(sector) == fDigiMapF.end() ) {
135 cout <<
"-E- " << fName <<
"::Exec: sector "
142 fSet = fDigiMapF[sector];
143 FindClusters(iStation+1,iSector+1,0, fSet);
145 if ( fDigiMapB.find(sector) == fDigiMapB.end() ) {
146 cout <<
"-E- " << fName <<
"::Exec: sector "
154 bSet = fDigiMapB[sector];
155 FindClusters(iStation+1,iSector+1,1, bSet);
156 Int_t nDigisFInSector = fSet.size();
157 Int_t nDigisBInSector = bSet.size();
158 nDigisFInStation += nDigisFInSector;
159 nDigisBInStation += nDigisBInSector;
162 nDigisF += nDigisFInStation;
163 nDigisB += nDigisBInStation;
173 cout <<
"-I- " << fName <<
":Event summary" << endl;
174 cout <<
" Active channels front side: " << nDigisF << endl;
175 cout <<
" Active channels back side : " << nDigisB << endl;
176 cout <<
" Real time : " << fTimer.RealTime()
180 if ( warn ) cout <<
"- ";
182 cout << setw(15) << left << fName <<
": " << setprecision(4) << setw(8)
183 << fixed << right << fTimer.RealTime()
184 <<
" s, " << fNofClusters
185 <<
"(" << fNofClustersGood
186 <<
"+" << fNofClustersWP
187 <<
") clusters, longest till now " << fLongestCluster << endl;
199void CbmStsRealClusterFinder::SetParContainers() {
202 FairRunAna*
run = FairRunAna::Instance();
203 if ( !
run ) Fatal(
"SetParContainers",
"No analysis run");
205 FairRuntimeDb* db =
run->GetRuntimeDb();
206 if ( ! db ) Fatal(
"SetParContainers",
"No runtime database");
209 fGeoPar = (
CbmGeoStsPar*) db->getContainer(
"CbmGeoStsPar");
212 fDigiPar = (
CbmStsDigiPar*) db->getContainer(
"CbmStsDigiPar");
221InitStatus CbmStsRealClusterFinder::Init() {
224 FairRootManager* ioman = FairRootManager::Instance();
225 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
226 fDigis = (TClonesArray*) ioman->GetObject(
"StsDigi");
228 fClusters =
new TClonesArray(
"CbmStsCluster", 1000);
229 ioman->Register(
"StsCluster",
"Cluster in STS", fClusters, kTRUE);
232 Bool_t success = fDigiScheme->
Init(fGeoPar, fDigiPar);
233 if ( ! success )
return kERROR;
239 if (fVerbose == 1 || fVerbose == 2) fDigiScheme->
Print(kFALSE);
240 else if (fVerbose > 2) fDigiScheme->
Print(kTRUE);
241 cout <<
"-I- " << fName <<
"::Init: "
242 <<
"STS digitisation scheme succesfully initialised" << endl;
244 <<
", Sectors: " << fDigiScheme->
GetNSectors() <<
", Channels: "
248 fNofClustersGood = 0;
253 fLongestGoodCluster = 0;
263InitStatus CbmStsRealClusterFinder::ReInit() {
266 fDigiScheme->
Clear();
269 Bool_t success = fDigiScheme->
Init(fGeoPar, fDigiPar);
270 if ( ! success )
return kERROR;
276 if (fVerbose == 1 || fVerbose == 2) fDigiScheme->
Print(kFALSE);
277 else if (fVerbose > 2) fDigiScheme->
Print(kTRUE);
278 cout <<
"-I- " << fName <<
"::Init: "
279 <<
"STS digitisation scheme succesfully reinitialised" << endl;
281 <<
", Sectors: " << fDigiScheme->
GetNSectors() <<
", Channels: "
285 fNofClustersGood = 0;
290 fLongestGoodCluster = 0;
300void CbmStsRealClusterFinder::MakeSets() {
305 for (Int_t iStation=0; iStation<nStations; iStation++) {
308 for (Int_t iSector=0; iSector<nSectors; iSector++) {
311 fDigiMapF[sector] = a;
314 fDigiMapB[sector] = b;
326void CbmStsRealClusterFinder::SortDigis() {
330 cout <<
"-E- " << fName <<
"::SortDigis: No input array!" << endl;
335 const Int_t nDigis = fDigis->GetEntriesFast();
338 map<CbmStsSector*, set<Int_t> >::iterator mapIt;
339 for (mapIt=fDigiMapF.begin(); mapIt!=fDigiMapF.end(); mapIt++)
340 ((*mapIt).second).clear();
341 for (mapIt=fDigiMapB.begin(); mapIt!=fDigiMapB.end(); mapIt++)
342 ((*mapIt).second).clear();
346 Int_t stationNr = -1;
349 Int_t channelNr = -1;
351 for (Int_t iDigi=0; iDigi<nDigis; iDigi++) {
357 sector = fDigiScheme->
GetSector(stationNr, sectorNr);
359 if ( fDigiMapF.find(sector) == fDigiMapF.end() ) {
360 cerr <<
"-E- " << fName <<
"::SortDigits:: sector " << sectorNr
361 <<
" of station " << stationNr
362 <<
" not found in digi scheme (F)!" << endl;
365 fDigiMapF[sector].insert(iDigi);
367 else if (iSide == 1 ) {
368 if ( fDigiMapB.find(sector) == fDigiMapB.end() ) {
369 cerr <<
"-E- " << fName <<
"::SortDigits:: sector " << sectorNr
370 <<
" of station " << stationNr
371 <<
" not found in digi scheme (B)!" << endl;
374 fDigiMapB[sector].insert(iDigi);
381Int_t CbmStsRealClusterFinder::FindClusters(Int_t stationNr, Int_t sectorNr, Int_t iSide, set<Int_t>& digiSet) {
383 set<Int_t>::iterator it1;
390 Double_t digiSig = -1.;
391 Int_t lastDigiNr = -1;
392 Int_t lastDigiPos = -1;
393 Double_t lastDigiSig = 100000.;
394 Int_t clusterMaxNr = -1;
395 Int_t clusterMaxPos = -1;
396 Double_t clusterMaxSig = -1.;
397 Bool_t clusterHasMinimum = kFALSE;
398 Bool_t clusterHasPlateau = kFALSE;
399 Int_t clusterBeginPos = 0;
400 Int_t clusterWidth = 0;
404 for (it1=digiSet.begin(); it1!=digiSet.end(); it1++) {
409 digiSig = digi->GetADC();
411 if ( lastDigiPos == -1 ) {
412 cluster =
new ((*fClusters)[fNofClusters++])
CbmStsCluster(iDigi,stationNr,sectorNr,iSide);
414 clusterBeginPos = digiPos;
417 if ( digiPos == lastDigiPos+1 ) {
419 if ( digiSig == lastDigiSig ) {
421 clusterHasPlateau = kTRUE;
425 if ( digiSig > lastDigiSig && lastDigiSig < clusterMaxSig ) {
426 cluster->
SetMean(clusterMaxNr);
428 cluster =
new ((*fClusters)[fNofClusters++])
CbmStsCluster(iDigi,stationNr,sectorNr,iSide);
434 clusterWidth = lastDigiPos - clusterBeginPos + 1;
435 if ( clusterWidth > fLongestCluster )
436 fLongestCluster = clusterWidth;
437 if ( clusterHasPlateau ) {
440 if ( !clusterHasMinimum && !clusterHasPlateau ) {
442 if ( clusterWidth > fLongestGoodCluster )
443 fLongestGoodCluster = clusterWidth;
446 clusterHasPlateau = kFALSE;
449 clusterBeginPos = digiPos;
452 else if ( lastDigiPos>=0 ) {
453 cluster->
SetMean(clusterMaxNr);
455 cluster =
new ((*fClusters)[fNofClusters++])
CbmStsCluster(iDigi,stationNr,sectorNr,iSide);
459 clusterWidth = lastDigiPos - clusterBeginPos + 1;
460 if ( clusterWidth > fLongestCluster )
461 fLongestCluster = clusterWidth;
462 if ( clusterHasPlateau ) {
465 if ( !clusterHasMinimum && !clusterHasPlateau ) {
467 if ( clusterWidth > fLongestGoodCluster )
468 fLongestGoodCluster = clusterWidth;
471 clusterHasPlateau = kFALSE;
474 clusterBeginPos = digiPos;
476 if ( digiSig > clusterMaxSig ) {
477 clusterMaxNr = iDigi;
478 clusterMaxPos = digiPos;
479 clusterMaxSig = digiSig;
482 clusterWidth = lastDigiPos - clusterBeginPos + 1;
483 if ( clusterWidth < 90 )
487 cluster->
SetMean(clusterMaxNr);
490 cluster =
new ((*fClusters)[fNofClusters++])
CbmStsCluster(iDigi,stationNr,sectorNr,iSide);
493 clusterWidth = lastDigiPos - clusterBeginPos + 1;
494 if ( clusterWidth > fLongestCluster )
495 fLongestCluster = clusterWidth;
496 if ( clusterHasPlateau ) {
499 if ( !clusterHasMinimum && !clusterHasPlateau ) {
501 if ( clusterWidth > fLongestGoodCluster )
502 fLongestGoodCluster = clusterWidth;
505 clusterHasPlateau = kFALSE;
508 clusterBeginPos = digiPos;
512 lastDigiPos = digiPos;
513 lastDigiSig = digiSig;
515 if ( digiSig > 0. ) {
516 cluster->
SetMean(clusterMaxNr);
519 clusterWidth = lastDigiPos - clusterBeginPos + 1;
520 if ( clusterWidth > fLongestCluster )
521 fLongestCluster = clusterWidth;
522 if ( clusterHasPlateau ) {
525 if ( lastDigiPos && !clusterHasPlateau ) {
527 if ( clusterWidth > fLongestGoodCluster )
528 fLongestGoodCluster = clusterWidth;
534 map<Int_t , Int_t> channelSorted;
535 for (it1=digiSet.begin(); it1!=digiSet.end(); it1++) {
544 for (Int_t iter=0; iter<1100; iter++) {
545 iDigi = channelSorted[iter];
546 if ( iDigi == 0 )
continue;
549 if ( iFS >= channelSorted.size() )
break;
573void CbmStsRealClusterFinder::AnalyzeClusters() {
574 for ( Int_t iclus = 0 ; iclus < fNofClusters ; iclus++ ) {
575 AnalyzeCluster(iclus);
581void CbmStsRealClusterFinder::AnalyzeCluster(Int_t iCluster) {
584 Int_t maxDigiNr = (Int_t)cluster->
GetMean();
586 Double_t maxDigiSig = 0.;
590 maxDigiSig = digi->GetADC() - plateau;
592 if ( TMath::Abs(plateau-maxDigiSig)<0.0001 ) plateau = 0.;
598 Double_t chanADC = 0.;
601 for ( Int_t itemp = 0 ; itemp < cluster->
GetNDigis() ; itemp++ ) {
604 chanADC = digi->GetADC();
605 chanADC = ( chanADC < plateau ? 0 : chanADC-plateau );
607 sumWX += chanNr*chanADC;
614 if ( sumW < maxDigiSig ) {
615 cout <<
" MAX DIGI = " << maxDigiSig <<
", while SUMW = " << sumW << endl;
616 for ( Int_t itemp = 0 ; itemp < cluster->
GetNDigis() ; itemp++ ) {
618 cout <<
"digi ADC = " << digi->GetADC() <<
" at channel# " << digi->
GetChannelNr() << endl;
628 fNofClusters = fNofClustersGood+fNofClustersWP;
630 cout <<
"============================================================"
632 cout <<
"===== " << fName <<
": Run summary " << endl;
633 cout <<
"===== " << endl;
634 cout <<
"===== Number of clusters : "
635 << setw(8) << setprecision(2)
636 << fNofClusters << endl;
637 cout <<
"===== Number of good clusters : "
638 << setw(8) << setprecision(2)
639 << fNofClustersGood <<
" ("
640 << setw(8) << setprecision(2)
641 << 100.*fNofClustersGood/fNofClusters <<
"%)" << endl;
642 cout <<
"===== Number of plateau clusters : "
643 << setw(8) << setprecision(2)
644 << fNofClustersWP <<
" ("
645 << setw(8) << setprecision(2)
646 << 100.*fNofClustersWP/fNofClusters <<
"%)" << endl;
647 cout <<
"===== Number of minimum clusters : "
648 << setw(8) << setprecision(2)
649 << fNofClustersWM <<
" ("
650 << setw(8) << setprecision(2)
651 << 100.*fNofClustersWM/fNofClusters <<
"%)" << endl;
652 cout <<
"===== Longest cluster : "
653 << setw(8) << setprecision(2)
654 << fLongestCluster << endl;
655 cout <<
"===== Longest good cluster : "
656 << setw(8) << setprecision(2)
657 << fLongestGoodCluster << endl;
658 cout <<
"============================================================"
void SetMeanError(Double_t err)
void SetMean(Double_t chan)
Double_t GetMeanError() const
Int_t GetDigi(Int_t inum)
void AddDigi(Int_t idigi)
void Print(Bool_t kLong=kFALSE)
CbmStsSector * GetSector(Int_t stationNr, Int_t sectorNr)
CbmStsStation * GetStation(Int_t iStation)
Int_t GetSectorNr() const
Int_t GetChannelNr() const
Int_t GetStationNr() const
virtual void Exec(Option_t *opt)
virtual ~CbmStsRealClusterFinder()
CbmStsRealClusterFinder()
Int_t GetSectorNr() const
Int_t GetNSectors() const
Int_t GetStationNr() const
CbmStsSector * GetSector(Int_t iSector)