27 #include "FairRootManager.h"
28 #include "FairRunAna.h"
29 #include "FairRuntimeDb.h"
31 #include "TClonesArray.h"
45 using std::setprecision;
51 : FairTask(
"GEMFindClusters", 1) {
66 : FairTask(
"GEMFindClusters", iVerbose) {
81 : FairTask(name, iVerbose) {
107 if (
fVerbose > 0 ) cout <<
"-I- PndGemFindClusters::Exec()"<<endl;
132 cout <<
">>>> created " <<
fDigiClusters.size() <<
" clusters, " << nofC2W <<
" to write" << endl;
178 FairRunAna*
run = FairRunAna::Instance();
179 if ( ! run ) Fatal(
"SetParContainers",
"No analysis run");
181 FairRuntimeDb* db = run->GetRuntimeDb();
182 if ( ! db ) Fatal(
"SetParContainers",
"No runtime database");
196 FairRootManager* ioman = FairRootManager::Instance();
197 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
198 fDigis = (TClonesArray*) ioman->GetObject(
"GEMDigi");
202 fClusters =
new TClonesArray(
"PndGemCluster", 1000);
203 ioman->Register(
"GEMCluster",
"Cluster in GEM",
fClusters, kTRUE);
205 cout <<
"-I- " << fName.Data() <<
"::Init(). There are " <<
fDigiPar->
GetNStations() <<
" GEM stations." << endl;
206 cout <<
"-I- " << fName.Data() <<
"::Init(). Initialization succesfull." << endl;
232 if (
fVerbose ) cout <<
"-I- PndGemFindClusters::SortDigis()" <<endl;
236 cout <<
"-E- " << fName <<
"::SortDigis: No input array!" << endl;
239 TRandom2* randNumber =
new TRandom2();
242 Int_t nDigis =
fDigis->GetEntriesFast();
248 for (Int_t iDigi=0; iDigi<nDigis; iDigi++) {
251 Double_t time = randNumber->Gaus(0.,5.);
258 map<Double_t, Int_t>::iterator mapIt;
324 cout <<
"-I- PndGemFindClusters::CreateClusters()" <<endl;
330 for ( Int_t idigi = 0 ; idigi <
fDigis->GetEntries() ; idigi++ ) {
341 tempDC.
digiNr.push_back(idigi);
344 tempDC.
cluTDC = digi->GetTimeStamp();
791 if (
fVerbose > 0 ) cout <<
"-I- PndGemFindClusters::WriteClusters()" <<endl;
796 for (
size_t idc = 0 ; idc <
fDigiClusters.size() ; idc++ ) {
804 for (
size_t idigi = 0 ; idigi <
fDigiClusters[idc].digiNr.size() ; idigi++ ) {
878 if (
fVerbose > 0 ) cout <<
"PndGemFindClusters::CompareDigiToClustersDigis" << endl;
884 Int_t iDigiUsed = -1;
885 for (
size_t idc = 0 ; idc <
fDigiClusters.size() ; idc++ ) {
895 Double_t digiDigiDist=999999999, testDist;
896 for (
size_t id = 0 ;
id <
fDigiClusters[idc].digiNr.size() ;
id++ ) {
898 if ( testDist < digiDigiDist ) digiDigiDist=testDist;
901 if ( digiDigiDist < 0. )
continue;
902 if ( digiDigiDist > 1 )
continue;
905 cout <<
"digi " << digiNumber <<
" ( " << digi->
GetDetectorId() <<
" / " << digi->
GetChannelNr() <<
" ) could attach to cluster "
906 << idc <<
" ( " <<
fDigiClusters[idc].cluPos <<
" ) with distance " << digiDigiDist <<
" . " <<
fDigiClusters[idc].digiNr.size() <<
" digis in cluster" << flush;
911 cout <<
" >>> mean channel = " <<
fDigiClusters[idc].cluPos << endl;
913 if ( iDigiUsed >= 0 ) {
920 return (iDigiUsed==-1?kFALSE:kTRUE);
927 if (
fVerbose > 0 ) cout <<
"PndGemFindClusters::JointTwoClusters()" << endl;
931 for (
size_t id2 = 0 ; id2 <
fDigiClusters[clus2].digiNr.size() ; id2++ ) {
935 Int_t addDigi = kTRUE;
936 for (
size_t id1 = 0 ; id1 <
fDigiClusters[clus1].digiNr.size() ; id1++ ) {
937 if ( chan2 ==
fDigiClusters[clus1].chanNr[id1] ) addDigi = kFALSE;
949 if (
fVerbose > 0 ) cout <<
"PndGemFindClusters::AddDigiToCluster()" << endl;
989 if (
fVerbose > 0 ) cout <<
"PndGemFindClusters::SortClusters()" << endl;
990 for (
size_t idc = 0 ; idc <
fDigiClusters.size() ; idc++ ) {
998 if (
fVerbose > 0 ) cout <<
"PndGemFindClusters::SortCluster()" << endl;
999 Int_t channelPosition = 0;
1002 for (
size_t idigi = channelPosition ; idigi <
fDigiClusters[clus].digiNr.size() ; idigi++ ) {
1022 if (
fVerbose > 0 ) cout <<
"PndGemFindClusters::PrintClusters()" << endl;
1024 for (
size_t idc = 0 ; idc <
fDigiClusters.size() ; idc++ ) {
1034 if (
fVerbose > 0 ) cout <<
"PndGemFindClusters::PrintCluster()" << endl;
1037 <<
" CREATED FROM " <<
fDigiClusters[clus].digiNr.size() <<
" DIGIS, FROM "
1041 for ( Int_t icol = 0 ; icol <
fDigiClusters[clus].cluPMx-
fDigiClusters[clus].cluPMn+3 ; icol++ ) cout <<
"-" << flush; cout<<endl;
1042 for (
Double_t fh = 0.99 ; fh >= 0. ; fh-=0.247475 ) {
1043 cout <<
"|" << flush;
1052 if ( thisADC > fh*
fDigiClusters[clus].cluMVl ) cout <<
"*" << flush;
1053 else cout <<
" " << flush;
1055 cout <<
"|" << endl;
1057 for ( Int_t icol = 0 ; icol <
fDigiClusters[clus].cluPMx-
fDigiClusters[clus].cluPMn+3 ; icol++ ) cout <<
"-" << flush; cout<<endl;
1066 cout <<
"-------------------- " << fName.Data() <<
" : Summary -----------------------" << endl;
1067 cout <<
" Events: " << setw(10) <<
fTNofEvents << endl;
1071 cout <<
"---------------------------------------------------------------------" << endl;
std::vector< Int_t > digiNr
Bool_t CompareDigiToClustersDigis(Int_t digiNumber)
std::map< Double_t, Int_t > fTimeOrderedDigis
virtual ~PndGemFindClusters()
Int_t GetStationNr() const
void PrintCluster(Int_t clus)
std::vector< Int_t > chanNr
virtual InitStatus Init()
Digitization Parameter Class for GEM part.
virtual InitStatus ReInit()
Int_t GetDetectorId() const
PndGemSensor * GetSensor(Int_t iSensor)
void SortCluster(Int_t clus)
Int_t GetSensorNr() const
PndGemSensor * GetSensor(Int_t stationNr, Int_t sensorNr)
std::vector< DigiCluster > fDigiClusters
void AddDigiToCluster(Int_t digiNr, Int_t clusNr)
Double_t GetChannelNr() const
std::vector< Double_t > sigADC
virtual void SetParContainers()
void JoinTwoClusters(Int_t clus1, Int_t clus2)
Double_t GetDistance2(Int_t iSide, Double_t chan1, Double_t chan2)
Double_t GetCharge() const
Double_t GetOuterRadius() const
Double_t GetMeanChannel(Int_t iSide, Double_t chan1, Double_t weight1, Double_t chan2, Double_t weight2)
virtual void Exec(Option_t *opt)
PndGemStation * GetStation(Int_t iStation)