29 #include "FairRootManager.h"
30 #include "FairRunAna.h"
31 #include "FairRuntimeDb.h"
33 #include "TClonesArray.h"
48 using std::setprecision;
61 fTimeOrderedDigi(kFALSE),
90 fTimeOrderedDigi(kFALSE),
117 fMCPointBranchId(-1),
118 fUseClusters(kFALSE),
119 fTimeOrderedDigi(kFALSE),
155 if (
fVerbose > 0 ) cout <<
"-I- PndGemFindHits::Exec()" << endl;
186 for (Int_t iStation=0; iStation<nStations; iStation++) {
188 Int_t nDigisFInStation = 0;
189 Int_t nDigisBInStation = 0;
190 Int_t nHitsInStation = 0;
192 for (Int_t iSensor=0; iSensor<nSensors; iSensor++) {
195 set <Int_t> fSet, bSet;
197 cout <<
"-E- " << fName <<
"::Exec: sensor "
206 cout <<
"-E- " << fName <<
"::Exec: sensor "
215 Int_t nDigisFInSensor = fSet.size();
216 Int_t nDigisBInSensor = bSet.size();
224 nHitsInSensor =
FindHits(sensor, fSet, bSet);
227 nHitsInSensor =
FindHits2(sensor, fSet, bSet);
232 <<
", Digis front " << nDigisFInSensor
233 <<
", Digis Back " << nDigisBInSensor
234 <<
", Hit combinations " << nHitsInSensor << endl;
235 nHitsInStation += nHitsInSensor;
236 nDigisFInStation += nDigisFInSensor;
237 nDigisBInStation += nDigisBInSensor;
240 if (
fVerbose > 1 ) cout <<
"Total for station "
242 << nDigisFInStation <<
", digis back "
243 << nDigisBInStation <<
", hit combinations "
244 << nHitsInStation << endl;
245 nDigisB += nDigisBInStation;
246 nDigisF += nDigisFInStation;
247 nHitsTemp += nHitsInStation;
251 if (
fVerbose > 1 ) cout <<
"Total for GEM "
252 <<
": Digis front "<< nDigisF
253 <<
", digis back "<< nDigisB
254 <<
", hit combinations "<< nHitsTemp << endl;
281 cout <<
"-I- " << fName <<
":Event summary" << endl;
282 cout <<
" Active channels front side: " << nDigisF << endl;
283 cout <<
" Active channels back side : " << nDigisB << endl;
284 cout <<
" Hits created : " <<
fHits->GetEntriesFast() << endl;
285 cout <<
" Real time : " <<
fTimer.RealTime()
289 if ( warn ) cout <<
"- ";
291 cout << setw(15) << left << fName <<
": " << setprecision(4) << setw(8)
292 << fixed << right <<
fTimer.RealTime()
293 <<
" s, digis " << nDigisF <<
" / " << nDigisB <<
", hits: "
312 FairRun*
run = FairRun::Instance();
313 if ( ! run ) Fatal(
"SetParContainers",
"No analysis run");
315 FairRuntimeDb* db = run->GetRuntimeDb();
316 if ( ! db ) Fatal(
"SetParContainers",
"No runtime database");
329 FairRootManager* ioman = FairRootManager::Instance();
330 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
333 fDigis = (TClonesArray*) ioman->GetObject(
"GEMCluster");
335 fDigis = (TClonesArray*) ioman->GetObject(
"GEMDigi");
340 fHits =
new TClonesArray(
"PndGemHit", 1000);
344 fHitsTemp =
new TClonesArray(
"PndGemHit", 1000);
345 ioman->Register(
"GEMHitTemp",
"temp Hit in GEM",
fHitsTemp, kFALSE);
350 cout <<
"-I- " << fName.Data() <<
"::Init(). There are " <<
fDigiPar->
GetNStations() <<
" GEM stations." << endl;
351 cout <<
"-I- " << fName.Data() <<
"::Init(). Initialization succesfull." << endl;
365 for ( Int_t isens = 0 ; isens < station->
GetNSensors() ; isens++ ) {
397 for (Int_t iStation=0; iStation<nStations; iStation++) {
400 for (Int_t iSensor=0; iSensor<nSensors; iSensor++) {
414 for ( Int_t iclus = 0 ; iclus <
fDigis->GetEntries() ; iclus++ ) {
424 if (
fVerbose > 0 ) cout <<
"-I- PndGemFindHits::ConfirmHits()" << endl;
425 Bool_t printInfo = kFALSE;
426 if(
fVerbose > 1 ) printInfo = kTRUE;
432 for ( Int_t ihit = 0 ; ihit <
fHits->GetEntriesFast() ; ihit++ ) {
437 Double_t hitProjX = hit->GetX()*(sensor->
GetZ0()/hit->GetZ());
438 Double_t hitProjY = hit->GetY()*(sensor->
GetZ0()/hit->GetZ());
447 cout <<
"COMPARING HIT " << ihit <<
" at "
448 << hit->GetX() <<
","
449 << hit->GetY() <<
","
450 << hit->GetZ() <<
" @ "
451 << hit->GetTimeStamp() << endl;
454 Bool_t hitConfirmed[2] = {kFALSE,kFALSE};
455 Int_t channelNr [2] = {sensor->
GetChannel(hitProjX,hitProjY,0),
459 for ( Int_t iside = 0 ; iside < 2 ; iside++ ) {
465 cout <<
" on " << hit->
GetStationNr() <<
"." << 3-hit->
GetSensorNr() <<
"." << iside <<
" channel " << channelNr[iside] <<
" was last active at " << lastChannelActivateTime << endl;
468 if ( lastChannelActivateTime < 0 )
continue;
469 if ( hit->GetTimeStamp()-lastChannelActivateTime < 100 &&
470 hit->GetTimeStamp()-lastChannelActivateTime > -10 ) {
471 if (printInfo) cout <<
"HIT CONFIRMED ON SIDE " << iside <<
" IN SOME PREVIOUS EVENT (" << hit->GetTimeStamp()-lastChannelActivateTime <<
" ns ago)" << endl;
472 hitConfirmed[iside] = kTRUE;
476 if ( hitConfirmed[0] == kFALSE || hitConfirmed[1] == kFALSE ) {
477 for ( Int_t iclus = 0 ; iclus <
fDigis->GetEntries() ; iclus++ ) {
480 if ( cluster->GetTimeStamp() < hit->GetTimeStamp() - 111. ||
481 cluster->GetTimeStamp() > hit->GetTimeStamp() + 11. )
490 hitConfirmed[cluster->
GetSide()] = kTRUE;
492 cout <<
"HIT CONFIRMED ON SIDE " << cluster->
GetSide() <<
" BY CLUSTER " << iclus <<
" at "
493 << (cluster->
GetSide()==0?
"F":
"B") <<
"side on "
499 <<
", time_diff = " << hit->GetTimeStamp() <<
" - " << cluster->GetTimeStamp() <<
"ns"
506 if ( hitConfirmed[0] == kTRUE && hitConfirmed[1] == kTRUE ) {
507 if ( printInfo ) cout <<
"GOOD HIT" << endl;
511 if ( printInfo ) cout <<
" NO CLUSTER MATCHES TO THIS HIT" << endl;
525 if (
fVerbose > 0 ) cout <<
"-I- PndGemFindHits::ConfirmHits2()" << endl;
536 Int_t sensorDetId, hitDetId;
538 Bool_t hitMatch2 = kFALSE;
547 if (
fVerbose > 1 ) cout <<
" Hit finding window is constant: xHitW=" << xHitW <<
" yHitW=" << yHitW << endl;
550 for ( Int_t ihitTemp = 0 ; ihitTemp <
fHitsTemp->GetEntriesFast() ; ihitTemp++ ) {
553 Int_t hitTempDetId = hitTemp->GetDetectorID();
554 Int_t testGemHit = hitTempDetId &
kGemHit << 21;
556 cout <<
"Check kGemHit bit of hitTempDetId=" << hitTempDetId
557 <<
" kGemHit=" << kGemHit <<
" masked value testGemHit=" << testGemHit <<endl;
559 if( testGemHit != 0 ) {
561 cout <<
"ihitTemp " << ihitTemp <<
" : already used... skip" <<endl;
569 xHit[0] = hitTemp->GetX();
570 yHit[0] = hitTemp->GetY();
571 zHit[0] = hitTemp->GetZ();
572 dx[0] = hitTemp->GetDx();
573 dy[0] = hitTemp->GetDy();
574 dz[0] = hitTemp->GetDz();
582 cout <<
"COMPARING HitTemp ihitTemp " << ihitTemp
583 <<
" of staNr " << staNr
584 <<
" senNr " << senNr
585 <<
" at (" << xHit[0] <<
"," << yHit[0] <<
"," << zHit[0]
586 <<
") time " << hitTemp->GetTimeStamp()
587 <<
" dx " << dx[0] <<
" dy " << dy[0]
588 <<
" sensorDetId " << sensorDetId <<
" senThick " << senD
593 for ( Int_t ihitTemp2 = ihitTemp+1 ; ihitTemp2 <
fHitsTemp->GetEntriesFast() ; ihitTemp2++ ) {
595 if (
fVerbose > 1 ) cout <<
"WITH ihitTemp2 " << ihitTemp2;
598 Int_t hitTemp2DetId = hitTemp2->GetDetectorID();
599 Int_t test2GemHit = hitTemp2DetId & kGemHit << 21;
601 cout <<
" hitTemp2DetId=" << hitTempDetId
602 <<
" kGemHit=" << kGemHit <<
" masked value test2GemHit=" << test2GemHit <<endl;
610 if (
fVerbose > 1 ) cout <<
" ihitTemp2 " << ihitTemp2 <<
" staNr " << staNr2;
611 if( staNr != staNr2 ) {
612 if (
fVerbose > 1 ) cout <<
" : diff Station .. skip " << endl;
616 if (
fVerbose > 1 ) cout <<
" of senNr " << senNr2 ;
617 if( senNr == senNr2 ) {
618 if (
fVerbose > 1 ) cout <<
" : same sensor.. skip " << endl;
621 xHit[1] = hitTemp2->GetX();
622 yHit[1] = hitTemp2->GetY();
623 zHit[1] = hitTemp2->GetZ();
624 dx[1] = hitTemp2->GetDx();
625 dy[1] = hitTemp2->GetDy();
626 dz[1] = hitTemp2->GetDz();
628 cout <<
" at (" << xHit[1] <<
"," << yHit[1] <<
"," << zHit[1]
629 <<
") time " << hitTemp2->GetTimeStamp() <<
" dx " << dx[1] <<
" dy " << dy[1] << endl;
638 cout <<
" Hit finding window based on dx dy: xHitW=" << xHitW <<
" yHitW=" << yHitW << endl;
642 if( xHit[0] - xHitW < xHit[1] && xHit[1] < xHit[0] + xHitW ){
643 if( yHit[0] - yHitW < yHit[1] && yHit[1] < yHit[0] + yHitW ){
645 hitTempDetId = hitTemp->GetDetectorID();
646 testGemHit = hitTempDetId & kGemHit << 21;
647 if( testGemHit != 0 ) {
649 cout <<
"ihitTemp " << ihitTemp <<
" : already stored... " <<endl;
653 pos.SetXYZ(xHit[0], yHit[0], zHit[0]);
654 dpos.SetXYZ(dx[0], dy[0], dz[0]);
655 hitDetId = hitTemp->GetDetectorID() | kGemHit << 21;
660 new ((*fHits)[nHits++])
PndGemHit(hitDetId,
663 hitTemp->GetTimeStamp(),
666 hitTemp->GetRefIndex(),fromStr);
668 cout <<
"ihitTemp "<< ihitTemp<<
" xHit yHit zHit " << pos.X() <<
" / " << pos.Y() <<
" / " << pos.Z() <<
" stored as " << nHits <<
" from " << fromStr.Data() <<
"." << hitTemp->
GetDigiNr(0) <<
" / " << hitTemp->
GetDigiNr(1) << endl;
675 if( test2GemHit != 0 ) {
677 cout <<
"ihitTemp2 " << ihitTemp2 <<
" : already stored... " <<endl;
681 pos.SetXYZ(xHit[1], yHit[1], zHit[1]);
682 dpos.SetXYZ(dx[1], dy[1], dz[1]);
683 hitDetId = hitTemp2->GetDetectorID() | kGemHit << 21;
688 new ((*fHits)[nHits++])
PndGemHit(hitDetId,
691 hitTemp2->GetTimeStamp(),
694 hitTemp2->GetRefIndex(),fromStr);
697 cout <<
"ihitTemp2 "<< ihitTemp<<
" xHit yHit zHit " << pos.X() <<
" / " << pos.Y() <<
" / " << pos.Z() <<
" stored as " << nHits <<
" from " << fromStr.Data() <<
"." << hitTemp2->
GetDigiNr(0) <<
" / " << hitTemp2->
GetDigiNr(1) << endl;
707 if ( hitMatch2 == kTRUE ) {
708 if (
fVerbose > 1 ) cout <<
"GOOD HIT" << endl;
712 if (
fVerbose > 2 ) cout <<
"NO MATCHE TO THIS HIT ihitTemp2 = " << ihitTemp2<< endl;
715 if ( hitMatch == kFALSE )
716 if (
fVerbose > 1 ) cout <<
"NO MATCHES OF HIT ihitTemp = " << ihitTemp << endl;
759 cout <<
"-E- " << fName <<
"::SortDigis: No input array!" << endl;
764 map<PndGemSensor*, set<Int_t> >::iterator mapIt;
766 ((*mapIt).second).clear();
768 ((*mapIt).second).clear();
774 Int_t stationNr = -1;
777 Int_t nDigis =
fDigis->GetEntriesFast();
781 for (Int_t iDigi=0; iDigi<nDigis; iDigi++) {
803 cerr <<
"-E- " << fName <<
"::SortDigits:: sensor " << sensorNr
804 <<
" of station " << stationNr
805 <<
" not found in digi scheme (F)!" << endl;
810 else if (iSide == 1 ) {
812 cerr <<
"-E- " << fName <<
"::SortDigits:: sensor " << sensorNr
813 <<
" of station " << stationNr
814 <<
" not found in digi scheme (B)!" << endl;
830 set<Int_t>& fSet, set<Int_t>& bSet) {
841 Int_t nHitsInSensor = 0;
851 set<Int_t>::iterator it1;
852 set<Int_t>::iterator it2;
854 for (it1=fSet.begin(); it1!=fSet.end(); it1++) {
858 cout <<
"-W- " << GetName() <<
"::FindHits: Invalid digi index "
859 << iDigiF <<
" in front set of sensor "
864 for (it2=bSet.begin(); it2!=bSet.end(); it2++) {
869 cout <<
"-W- " << GetName() <<
"::FindHits: Invalid digi index "
870 << iDigiB <<
" in front set of sensor "
875 Int_t sensorDetId = sensor->
Intersect(iChanF,iChanB,xHit,yHit,zHit,dx,dy,dr,dp);
879 if ( sensorDetId == -1 )
continue;
882 if ( rad < sensor->GetInnerRadius() || rad > sensor->
GetOuterRadius() ) {
883 cout <<
" point " << xHit <<
"," << yHit <<
" (" << rad <<
") is still ok??? at station "
899 pos.SetXYZ(xHit, yHit, zHit);
900 dpos.SetXYZ(sigmaX, sigmaY, sensor->
GetD());
907 for ( Int_t irf1 = digiF->
GetNIndices()-1 ; irf1 >= 0 ; irf1-- ) {
909 for ( Int_t irf2 = digiB->
GetNIndices()-1 ; irf2 >= 0 ; irf2-- ) {
916 Int_t hitDetId = sensorDetId |
kGemHit << 21;
928 TMath::Abs(digiF->GetTimeStamp()-digiB->GetTimeStamp()) > 5. )
933 new ((*fHits)[nHits++])
PndGemHit(hitDetId, pos, dpos,
935 (digiF->GetTimeStamp()+digiB->GetTimeStamp())/2.,
937 dr, dp, refIndex,fromStr);
945 return nHitsInSensor;
954 set<Int_t>& fSet, set<Int_t>& bSet) {
959 Double_t sigmaX = 1., sigmaY = 2., sigmaZ;
968 Int_t nHitsTemp =
fHitsTemp->GetEntriesFast();
969 Int_t nHitsInSensor = 0;
983 set<Int_t>::iterator it1;
984 set<Int_t>::iterator it2;
986 for (it1=fSet.begin(); it1!=fSet.end(); it1++) {
991 cout <<
"-W- " << GetName() <<
"::FindHits: Invalid digi index "
992 << iDigiF <<
" in front set of sensor "
1001 for (it2=bSet.begin(); it2!=bSet.end(); it2++) {
1006 cout <<
"-W- " << GetName() <<
"::FindHits: Invalid digi index "
1007 << iDigiB <<
" in front set of sensor "
1017 Int_t sensorDetId = sensor->
Intersect(iChanF,iChanB,xHit,yHit,zHit,dx,dy,dr,dp);
1019 cout <<
"Intersect chF " << iChanF <<
" chB " << iChanB <<
" detID " << sensorDetId << endl;
1020 cout <<
"at (" << xHit <<
", " << yHit <<
", " << zHit <<
")"
1021 <<
"dx " << dx <<
" dy " << dy <<
" dr " << dr <<
" dp " << dp
1024 if ( sensorDetId == -1 ){
1026 cout <<
"no intersect.. skip " <<endl;
1031 pos.SetXYZ(xHit, yHit, zHit);
1033 if ( rad < sensor->GetInnerRadius() || rad > sensor->
GetOuterRadius() ) {
1034 cout <<
"-W- !! point " << xHit <<
"," << yHit <<
" (" << rad <<
") is still ok??? at station "
1040 sigmaZ = sensor->
GetD();
1048 Int_t testMnMn = sensor->
Intersect(iChanFMn,iChanBMn,xMnMn,yMnMn,zHit,dx,dy,dr,dp);
1049 Int_t testMxMx = sensor->
Intersect(iChanFMx,iChanBMx,xMxMx,yMxMx,zHit,dx,dy,dr,dp);
1050 Int_t testMnMx = sensor->
Intersect(iChanFMn,iChanBMx,xMnMx,yMnMx,zHit,dx,dy,dr,dp);
1051 Int_t testMxMn = sensor->
Intersect(iChanFMx,iChanBMn,xMxMn,yMxMn,zHit,dx,dy,dr,dp);
1056 if( testMnMn != -1 && testMxMx != -1 ) {
1059 if( testMnMx != -1 && testMxMn != -1 ) {
1065 cout <<
"fUseCluster is TRUE: dx dy of clusters " << sigmaX <<
" " << sigmaY <<
" are calculated for Hits"<< endl;
1070 dpos.SetXYZ(sigmaX, sigmaY, sigmaZ);
1073 Int_t refIndex = -1;
1074 for ( Int_t irf1 = digiF->
GetNIndices()-1 ; irf1 >= 0 ; irf1-- ) {
1076 for ( Int_t irf2 = digiB->
GetNIndices()-1 ; irf2 >= 0 ; irf2-- ) {
1084 Int_t hitDetId = sensorDetId;
1094 Double_t hitTimeStamp = (digiF->GetTimeStamp()+digiB->GetTimeStamp())/2.;
1097 fromStr =
"GEMCluster";
1098 hitTimeStamp = (clusterF->GetTimeStamp()+clusterB->GetTimeStamp())/2.;
1101 new ((*fHitsTemp)[nHitsTemp++])
PndGemHit(hitDetId, pos, dpos,
1105 sigmaR, sigmaP, refIndex, fromStr);
1113 return nHitsInSensor;
1124 cout <<
"-------------------- " << fName.Data() <<
" : Summary -----------------------" << endl;
1125 cout <<
" Events: " << setw(10) <<
fTNofEvents << endl;
1131 cout <<
"---------------------------------------------------------------------" << endl;
1133 cout <<
" >>> HF >>> prep time = " <<
fPrepTime <<
"s (get data from input)" << endl;
1139 cout <<
"---------------------------------------------------------------------" << endl;
Int_t GetSensorNr() const
Int_t GetClusterBeg() const
Int_t CreateSensorMonitor(const PndGemSensor &tempSensor)
Int_t Intersect(Double_t iFStrip, Double_t iBStrip, Double_t &xCross, Double_t &yCross, Double_t &zCross)
Int_t GetStationNr() const
TString GetDetectorName() const
Int_t GetStationNr() const
static T Sqrt(const T &x)
void SetPersistency(Bool_t val=kTRUE)
Digitization Parameter Class for GEM part.
virtual void SetParContainers()
virtual void Exec(Option_t *opt)
PndGemSensor * GetSensor(Int_t iSensor)
Double_t ChannelLastActiveAt(Int_t statNr, Int_t sensNr, Int_t sideId, Int_t chanNr)
Int_t GetStationNr() const
std::map< PndGemSensor *, std::set< Int_t > > fDigiMapF
Int_t GetSensorNr() const
std::map< PndGemSensor *, std::set< Int_t > > fDigiMapB
Int_t GetSensorNr() const
PndGemSensor * GetSensor(Int_t stationNr, Int_t sensorNr)
Int_t GetNSensors() const
Int_t GetChannel(Double_t x, Double_t y, Int_t iSide)
void EnableCluster(Int_t eventNr, Int_t clusterNr, PndGemCluster *tempCluster)
Int_t FindHits2(PndGemSensor *sensor, std::set< Int_t > &fSet, std::set< Int_t > &bSet)
static PndGemMonitor * Instance()
Double_t GetChannelNr() const
Double_t GetCharge() const
Int_t GetStationNr() const
Int_t GetClusterEnd() const
static T Max(const T &x, const T &y)
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Int_t GetSensorNr() const
Int_t GetIndex(int i=0) const
Int_t GetDigiNr(Int_t iside) const
Double_t GetCharge() const
Int_t GetDetectorId() const
Double_t GetOuterRadius() const
Int_t FindHits(PndGemSensor *sensor, std::set< Int_t > &fSet, std::set< Int_t > &bSet)
virtual ~PndGemFindHits()
PndGemDigiPar * fDigiPar
/** GEM monitor **/
virtual InitStatus Init()
Double_t GetCharge() const
Int_t GetStationNr() const
virtual InitStatus ReInit()
PndGemStation * GetStation(Int_t iStation)