10#include "TClonesArray.h"
13#include "FairRootManager.h"
14#include "FairRunAna.h"
15#include "FairRuntimeDb.h"
19#include "FairGeoPassivePar.h"
27#include "CbmStsPoint.h"
31#include "BmnSiliconPoint.h"
32#include "FairGeoVector.h"
33#include "FairGeoNode.h"
35#include "TGeoManager.h"
49using std::setprecision;
54: FairTask(
"STSMatchHits", 1),
86: FairTask(
"STSMatchHits", iVerbose),
104 fTargetPos(0.,0.,0.),
118: FairTask(name, iVerbose),
136 fTargetPos(0.,0.,0.),
151 if ( fPassGeo )
delete fPassGeo;
152 if ( fGeoPar )
delete fGeoPar;
153 if ( fDigiPar )
delete fDigiPar;
170 Bool_t warn = kFALSE;
173 Int_t nHits = fHits->GetEntriesFast();
180 for (Int_t iHit=0; iHit<nHits; iHit++) {
183 cout <<
"-W- " << GetName() <<
"::Exec: Empty hit at index "
194 Int_t iType = sector->
GetType();
200 Double_t xH = hit->GetX();
201 Double_t yH = hit->GetY();
202 Double_t dX = hit->GetDx();
203 Double_t dY = hit->GetDy();
206 Int_t iMatchF = (Int_t)hit->
GetDigi(0);
210 cout <<
"-E- " << GetName() <<
"::Exec: "
211 <<
"No DigiMatchF for hit " << iHit << endl;
212 hit->SetRefIndex(-1);
220 Int_t iMatchB = (Int_t)hit->
GetDigi(1);
224 cout <<
"-E- " << GetName() <<
"::Exec: "
225 <<
"No DigiMatchB for hit " << iHit << endl;
226 hit->SetRefIndex(-1);
240 for (Int_t jMatchF=0; jMatchF<3; jMatchF++) {
242 if ( iPointF < 0 )
continue;
247 cout <<
"-E- " << GetName() <<
"::Exec: "
248 <<
"No StsPoint (" << iPointF <<
") for pixel hit "
254 Double_t xP = point->
GetX(station->
GetZ());
255 Double_t yP = point->
GetY(station->
GetZ());
256 Double_t
dist = TMath::Sqrt( (xP-xH)*(xP-xH) + (yP-yH)*(yP-yH) );
258 fCandMap[
dist] = iPointF;
262 else if ( iType == 2 || iType == 3 ) {
265 for ( Int_t jMatchF=0; jMatchF<3; jMatchF++) {
267 if ( iPointF < 0 )
continue;
270 for ( Int_t iMatchB=0; iMatchB<3; iMatchB++) {
272 if ( iPointB < 0 )
continue;
274 if ( iMatchF == 0 ) nPointsB++;
275 if ( iPointB != iPointF )
continue;
279 cout <<
"-E- " << GetName() <<
"::Exec: "
280 <<
"No StsPoint (" << iPointF <<
") for strip hit "
286 Double_t xP = point->
GetX(station->
GetZ());
287 Double_t yP = point->
GetY(station->
GetZ());
288 Double_t
dist = TMath::Sqrt( (xP-xH)*(xP-xH) +
290 fCandMap[
dist] = iPointF;
297 cout <<
"-E- " << GetName() <<
"::Exec: Unknwon sensor type "
299 Fatal(
"Exec",
"Unknwon sensor type");
302 if ( fVerbose > 1 ) cout <<
"-I- " << GetName() <<
": Hit "
303 << iHit <<
", type " << iType
304 <<
", points " << nPointsF <<
" / "
305 << nPointsB <<
", candidates "
312 if ( fCandMap.empty() ) {
313 hit->SetRefIndex(-1);
314 if (fVerbose>1) cout <<
", background " << endl;
320 Double_t distMin = 999999.;
322 for (fIter=fCandMap.begin(); fIter!=fCandMap.end(); fIter++) {
323 if ( (*fIter).first < distMin ) {
324 distMin = (*fIter).first;
325 iPoint = (*fIter).second;
329 cout <<
"-E- " << GetName() <<
"::Exec: "
330 <<
"No closest point found in candidate map!" << endl;
331 Fatal(
"Exec",
"No closest point");
334 if (fVerbose>1) cout <<
", matched to " << iPoint <<
", distance "
341 Double_t xP = point->
GetX(station->
GetZ());
342 Double_t yP = point->
GetY(station->
GetZ());
343 if ( TMath::Abs(xP-xH) > 5. * dX ||
344 TMath::Abs(yP-yH) > 5. * dY ) {
345 hit->SetRefIndex(-2);
347 if (fVerbose>1) cout <<
", distant" << endl;
348 if ( iType == 1 || iType == 2) {
349 cout <<
"-W- " << fName <<
"::Exec: "
350 <<
"Distant hit in pixel / strip MSU station" << endl;
351 cout <<
"Hit " << iHit <<
" coordinates " << xH
352 <<
", " << yH << endl;
353 cout <<
"Matched point " << iPoint <<
", distance "
355 cout <<
"Distance y " << TMath::Abs(xP-xH) <<
" Error " << dX << endl;
356 cout <<
"Distance y " << TMath::Abs(yP-yH) <<
" Error " << dY << endl;
364 hit->SetRefIndex(iPoint);
366 if (fVerbose>1) cout <<
", good match" << endl;
370 if ( TMath::Abs(hit->GetZ() - point->GetZ()) > 1. ) {
371 cout <<
"-E- " << GetName() <<
"::Exec: Hit " << iHit
372 <<
" is at z = " << hit->GetZ() <<
" cm, but matched point "
373 << iPoint <<
" is at z = " << point->GetZ() <<
"cm " << endl;
374 Fatal(
"Exec",
"Different stations for hit and point");
381 if ( warn ) cout <<
"- ";
383 cout << setw(15) << left << fName <<
": " << setprecision(4) << setw(8)
384 << fixed << right << fTimer.RealTime()
385 <<
" s, hits " << nHits <<
", matched " << nMatched <<
", distant "
386 << nDistant <<
", background " << setw(6) << nBackgrd << endl;
389 if ( warn) fNEventsFailed++;
392 fTime += fTimer.RealTime();
393 fNHits += Double_t(nHits);
394 fNMatched += Double_t(nMatched);
395 fNDistant += Double_t(nDistant);
396 fNBackgrd += Double_t(nBackgrd);
409 Bool_t warn = kFALSE;
412 Int_t nHits = fHits->GetEntriesFast();
418 Int_t nofStsHits = fHits->GetEntriesFast();
419 Int_t nofStsPoints = fPoints->GetEntriesFast();
421 if (fPointsSi) nofSiPoints = fPointsSi->GetEntriesFast();
423 Int_t hitStationLimits[2][100];
429 for ( Int_t ist = 0 ; ist < fNStations ; ist++ ) {
430 hitStationLimits[0][ist] = -1;
431 hitStationLimits[1][ist] = -1;
435 for ( Int_t ihit = 0 ; ihit < nofStsHits ; ihit++ ) {
437 stsHit->SetRefIndex(-1);
438 if ( hitStationLimits[0][stsHit->
GetStationNr()-1] == -1 )
441 if ( hitStationLimits[1][stsHitBack->
GetStationNr()-1] == -1 ) {
442 hitStationLimits[1][stsHitBack->
GetStationNr()-1] = nofStsHits-ihit;
448 int nTotPoints = nofSiPoints + nofStsPoints;
452 for ( Int_t iii = 0 ; iii < nTotPoints ; iii++ ) {
454 int ipnt = (iii < nofSiPoints) ? iii : iii - nofSiPoints;
455 if (iii < nofSiPoints) stsPoint = (
CbmStsPoint*)fPointsSi->At(ipnt);
462 Double_t xin = stsPoint->
GetXIn();
463 Double_t yin = stsPoint->
GetYIn();
464 Double_t zin = stsPoint->
GetZIn();
465 gGeoManager->FindNode(xin,yin,zin);
466 TGeoNode* curNode = gGeoManager->GetCurrentNode();
478 std::cerr <<
"-E- " << fName <<
"::ExecReal:: sensor " << curNode->GetName()
479 <<
" not found in digi scheme!" << endl;
490 Int_t startHit = hitStationLimits[0][stationNr];
491 Int_t finalHit = hitStationLimits[1][stationNr];
493 if ( startHit == -1 && finalHit == -1 )
continue;
494 if ( startHit < 0 || finalHit < 0 || startHit > fHits->GetEntriesFast() || finalHit > fHits->GetEntriesFast())
continue;
496 Int_t NofMatched = 0;
499 Double_t GoodHit[50000];
500 Int_t GoodHitIndex[50000];
501 for ( Int_t ihit = startHit ; ihit < finalHit ; ihit++ ) {
503 if (NULL == stsHit) {
504 std::cout <<
"CbmStsMatchHits::ExecReal: CbmStsHit NULL pointer: ihit=" << ihit
505 <<
" " <<
"startHit=" << startHit <<
" finalHit=" << finalHit << std::endl;
510 Int_t iL = 0, nMatch = 0;
511 FairLink link = stsHit->GetLink(iL);
513 Int_t nLinks2 = stsCluster->GetNLinks();
514 for (Int_t iL2 = 0; iL2 < nLinks2; ++iL2) {
515 FairLink link2 = stsCluster->GetLink(iL2);
519 const Int_t nLinks3 = 3;
520 for (Int_t iL3 = 0; iL3 < nLinks3; ++iL3) {
524 if (stsPointId == ipnt) { ++nMatch;
break; }
525 else if (stsPointId < 0)
break;
532 link = stsHit->GetLink(iL);
533 stsCluster =
dynamic_cast<CbmStsCluster*
> (fClusters->UncheckedAt(link.GetIndex()));
534 nLinks2 = stsCluster->GetNLinks();
535 for (Int_t iL2 = 0; iL2 < nLinks2; ++iL2) {
536 FairLink link2 = stsCluster->GetLink(iL2);
540 const Int_t nLinks3 = 3;
541 for (Int_t iL3 = 0; iL3 < nLinks3; ++iL3) {
545 if (stsPointId == ipnt) { ++nMatch;
break; }
546 else if (stsPointId < 0)
break;
548 if (nMatch == 2)
break;
552 Double_t xH = stsHit->GetX();
553 Double_t yH = stsHit->GetY();
556 Double_t xP = stsPoint->
GetXIn();
557 Double_t yP = stsPoint->
GetYIn();
558 Double_t
dist = TMath::Sqrt( (xP-xH)*(xP-xH) + (yP-yH)*(yP-yH) );
561 GoodHitIndex[NofMatched]=ihit;
562 GoodHit[NofMatched]=
dist;
569 for (Int_t
i=NofMatched-1;
i>0;
i--) {
570 if (GoodHit[
i]<GoodHit[k]) k=
i;
575 stsHit->SetRefIndex(ipnt);
581 if ( warn ) cout <<
"- ";
583 cout << setw(15) << left << fName <<
": " << setprecision(4) << setw(8)
584 << fixed << right << fTimer.RealTime()
585 <<
" s, hits " << nHits <<
", matched " << nMatched <<
", distant "
586 << nDistant <<
", background " << setw(6) << nBackgrd << endl;
589 if ( warn) fNEventsFailed++;
592 fTime += fTimer.RealTime();
593 fNHits += Double_t(nHits);
594 fNMatched += Double_t(nMatched);
595 fNDistant += Double_t(nDistant);
596 fNBackgrd += Double_t(nBackgrd);
733void CbmStsMatchHits::SetParContainers() {
736 FairRunAna*
run = FairRunAna::Instance();
737 if ( !
run ) Fatal(
"SetParContainers",
"No analysis run");
738 FairRuntimeDb* db =
run->GetRuntimeDb();
739 if ( ! db ) Fatal(
"SetParContainers",
"No runtime database");
743 fGeoPar = (
CbmGeoStsPar*) db->getContainer(
"CbmGeoStsPar");
744 fDigiPar = (
CbmStsDigiPar*) db->getContainer(
"CbmStsDigiPar");
751InitStatus CbmStsMatchHits::Init() {
754 fNEvents = fNEventsFailed = 0;
755 fTime = fNHits = fNMatched = fNDistant = fNBackgrd = 0.;
758 FairRootManager* ioman = FairRootManager::Instance();
759 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
760 fPoints = (TClonesArray*) ioman->GetObject(
"StsPoint");
765 fPointsSi = (TClonesArray*) ioman->GetObject(
"SiliconPoint");
766 fDigis = (TClonesArray*) ioman->GetObject(
"StsDigi");
768 cout <<
"-E- " << GetName() <<
"::Init: No StsDigi array!" << endl;
771 fDigiMatches = (TClonesArray*) ioman->GetObject(
"StsDigiMatch");
772 if ( ! fDigiMatches ) {
773 cout <<
"-E- " << GetName() <<
"::Init: No StsDigiMatch array!"
777 fHits = (TClonesArray*) ioman->GetObject(
"StsHit");
779 cout <<
"-E- " << GetName() <<
"::Init: No StsHit array!" << endl;
783 fClusters = (TClonesArray*) ioman->GetObject(
"StsCluster");
785 cout <<
"-E- " << GetName() <<
"::Init: No StsCluster array!" << endl;
790 InitStatus geoStatus = GetGeometry();
791 if ( geoStatus != kSUCCESS ) {
792 cout <<
"-E- " << GetName() <<
"::Init: Error in reading geometry!"
799 if ( fDigiScheme->
Init(fGeoPar, fDigiPar) ) {
801 if (fVerbose == 1 || fVerbose == 2) fDigiScheme->
Print(kFALSE);
802 else if (fVerbose > 2) fDigiScheme->
Print(kTRUE);
803 cout <<
"-I- " << fName <<
"::Init: "
804 <<
"STS digitisation scheme succesfully initialised" << endl;
806 <<
", Sectors: " << fDigiScheme->
GetNSectors() <<
", Channels: "
819InitStatus CbmStsMatchHits::ReInit() {
822 fDigiScheme->
Clear();
825 if ( fDigiScheme->
Init(fGeoPar, fDigiPar) )
return kSUCCESS;
827 InitStatus geoStatus = GetGeometry();
828 if ( geoStatus != kSUCCESS ) {
829 cout <<
"-E- " << GetName() <<
"::Init: Error in reading geometry!"
840InitStatus CbmStsMatchHits::GetGeometry() {
841cout <<
"-W- " << endl;
844 cout <<
"-W- " << GetName() <<
"::GetGeometry: No passive geometry!"
846 fTargetPos.SetXYZ(0., 0., 0.);
851 cout <<
"-W- " << GetName() <<
"::GetGeometry: No passive node array"
853 fTargetPos.SetXYZ(0., 0., 0.);
872 cout <<
"-W- " << GetName() <<
"::GetGeometry: No passive geometry!"
879 cout <<
"-E- " << GetName() <<
"::GetGeometry: No STS node array"
884 Int_t tempNofStations = stsNodes->GetEntries();
885 cout <<
"Nodes in STS: " << tempNofStations << endl;
887 cout <<
"There are " << tempNofStations <<
" nodes" << (tempNofStations > 10 ?
"!!!" :
"" ) << endl;
891 TString stationNames[1000];
892 for ( Int_t ist = 0 ; ist < tempNofStations ; ist++ ) {
893 FairGeoNode* stsNode = (FairGeoNode*)stsNodes->At(ist);
895 cout <<
"-W- CbmStsDigiScheme::Init: station#" << ist
896 <<
" not found among sensitive nodes " << endl;
899 geoNodeName = stsNode->getName();
902 Bool_t stationKnown = kFALSE;
904 for ( Int_t ikst = 0 ; ikst < fNStations ; ikst++ )
905 if ( geoNodeName.Contains(stationNames[ikst]) ) {
906 fStationNrFromMcId[stsNode->getMCid()] = ikst;
907 stationKnown = kTRUE;
910 if ( stationKnown )
continue;
913 fStationNrFromMcId[stsNode->getMCid()] = fNStations;
918 geoNodeName.Remove(12,geoNodeName.Length()-12);
919 stationNames[fNStations] = geoNodeName.Data();
922 cout <<
"station #" << fNStations <<
" has MCID = " << stsNode->getMCid() <<
" and name " << stsNode->GetName() << endl;
926 cout <<
"There are " << fNStations <<
" stations" << endl;
936void CbmStsMatchHits::Finish() {
939 cout <<
"============================================================"
941 cout <<
"===== " << GetName() <<
": Run summary " << endl;
942 cout <<
"===== " << endl;
943 cout <<
"===== Good events : " << setw(6) << fNEvents << endl;
944 cout <<
"===== Failed events : " << setw(6) << fNEventsFailed << endl;
945 cout <<
"===== Average time : " << setprecision(4) << setw(8) << right
946 << fTime / Double_t(fNEvents) <<
" s" << endl;
947 cout <<
"===== " << endl;
948 cout <<
"===== Hits per event : " << fixed << setprecision(0)
949 << fNHits / Double_t(fNEvents) << endl;
950 cout << setprecision(2);
951 cout <<
"===== Matched hits : " << fixed << setw(6) << right
952 << fNMatched / fNHits * 100. <<
" %" << endl;
953 cout <<
"===== Distant hits : " << fixed << setw(6) << right
954 << fNDistant / fNHits * 100. <<
" %" << endl;
955 cout <<
"===== Background hits : " << fixed << setw(6) << right
956 << fNBackgrd / fNHits * 100. <<
" % " << endl;
957 cout <<
"============================================================"
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
BmnSsdDigitizeParameters * fDigiPar
Digitisation parameters.
TObjArray * GetGeoSensitiveNodes()
Int_t GetRefIndex(Int_t i=0) const
void Print(Bool_t kLong=kFALSE)
static CbmStsDigiScheme * Instance(int version=1)
CbmStsSensor * GetSensorByName(TString sensorName)
CbmStsStation * GetStationByNr(Int_t stationNr)
CbmStsSector * GetSector(Int_t stationNr, Int_t sectorNr)
virtual Int_t GetStationNr() const
Int_t GetSectorNr() const
Int_t GetDigi(Int_t iSide) const
virtual ~CbmStsMatchHits()
virtual void Exec(Option_t *opt)
virtual void ExecReal(Option_t *opt)
Double_t GetY(Double_t z) const
Double_t GetX(Double_t z) const
Int_t GetStationNr() const
Double_t GetZ(Int_t it=0)
TObjArray * GetGeoPassiveNodes()