10#include "TClonesArray.h"
13#include "FairRootManager.h"
14#include "FairRunAna.h"
15#include "FairRuntimeDb.h"
19#include "FairGeoPassivePar.h"
25#include "CbmStsPoint.h"
28#include "FairGeoVector.h"
29#include "FairGeoNode.h"
43using std::setprecision;
64 : FairTask(
"STSMatchHits", iVerbose) {
81 : FairTask(name, iVerbose) {
98 if ( fPassGeo )
delete fPassGeo;
99 if ( fGeoPar )
delete fGeoPar;
100 if ( fDigiPar )
delete fDigiPar;
101 if ( fDigiScheme )
delete fDigiScheme;
117 Bool_t warn = kFALSE;
120 Int_t nHits = fHits->GetEntriesFast();
127 for (Int_t iHit=0; iHit<nHits; iHit++) {
130 cout <<
"-W- " << GetName() <<
"::Exec: Empty hit at index "
141 Int_t iType = sector->
GetType();
147 Double_t xH = hit->GetX();
148 Double_t yH = hit->GetY();
149 Double_t dX = hit->GetDx();
150 Double_t dY = hit->GetDy();
153 Int_t iMatchF = (Int_t)hit->
GetDigi(0);
157 cout <<
"-E- " << GetName() <<
"::Exec: "
158 <<
"No DigiMatchF for hit " << iHit << endl;
159 hit->SetRefIndex(-1);
167 Int_t iMatchB = (Int_t)hit->
GetDigi(1);
171 cout <<
"-E- " << GetName() <<
"::Exec: "
172 <<
"No DigiMatchB for hit " << iHit << endl;
173 hit->SetRefIndex(-1);
187 for (Int_t iMatchF=0; iMatchF<3; iMatchF++) {
189 if ( iPointF < 0 )
continue;
194 cout <<
"-E- " << GetName() <<
"::Exec: "
195 <<
"No StsPoint (" << iPointF <<
") for pixel hit "
201 Double_t xP = point->
GetX(station->
GetZ());
202 Double_t yP = point->
GetY(station->
GetZ());
203 Double_t
dist = TMath::Sqrt( (xP-xH)*(xP-xH) + (yP-yH)*(yP-yH) );
205 fCandMap[
dist] = iPointF;
209 else if ( iType == 2 || iType == 3 ) {
212 for ( Int_t iMatchF=0; iMatchF<3; iMatchF++) {
214 if ( iPointF < 0 )
continue;
217 for ( Int_t iMatchB=0; iMatchB<3; iMatchB++) {
219 if ( iPointB < 0 )
continue;
221 if ( iMatchF == 0 ) nPointsB++;
222 if ( iPointB != iPointF )
continue;
226 cout <<
"-E- " << GetName() <<
"::Exec: "
227 <<
"No StsPoint (" << iPointF <<
") for strip hit "
233 Double_t xP = point->
GetX(station->
GetZ());
234 Double_t yP = point->
GetY(station->
GetZ());
235 Double_t
dist = TMath::Sqrt( (xP-xH)*(xP-xH) +
237 fCandMap[
dist] = iPointF;
244 cout <<
"-E- " << GetName() <<
"::Exec: Unknwon sensor type "
246 Fatal(
"Exec",
"Unknwon sensor type");
249 if ( fVerbose > 1 ) cout <<
"-I- " << GetName() <<
": Hit "
250 << iHit <<
", type " << iType
251 <<
", points " << nPointsF <<
" / "
252 << nPointsB <<
", candidates "
259 if ( fCandMap.empty() ) {
260 hit->SetRefIndex(-1);
261 if (fVerbose>1) cout <<
", background " << endl;
267 Double_t distMin = 999999.;
269 for (fIter=fCandMap.begin(); fIter!=fCandMap.end(); fIter++) {
270 if ( (*fIter).first < distMin ) {
271 distMin = (*fIter).first;
272 iPoint = (*fIter).second;
276 cout <<
"-E- " << GetName() <<
"::Exec: "
277 <<
"No closest point found in candidate map!" << endl;
278 Fatal(
"Exec",
"No closest point");
281 if (fVerbose>1) cout <<
", matched to " << iPoint <<
", distance "
288 Double_t xP = point->
GetX(station->
GetZ());
289 Double_t yP = point->
GetY(station->
GetZ());
290 if ( TMath::Abs(xP-xH) > 5. * dX ||
291 TMath::Abs(yP-yH) > 5. * dY ) {
292 hit->SetRefIndex(-2);
294 if (fVerbose>1) cout <<
", distant" << endl;
295 if ( iType == 1 || iType == 2) {
296 cout <<
"-W- " << fName <<
"::Exec: "
297 <<
"Distant hit in pixel / strip MSU station" << endl;
298 cout <<
"Hit " << iHit <<
" coordinates " << xH
299 <<
", " << yH << endl;
300 cout <<
"Matched point " << iPoint <<
", distance "
302 cout <<
"Distance y " << TMath::Abs(xP-xH) <<
" Error " << dX << endl;
303 cout <<
"Distance y " << TMath::Abs(yP-yH) <<
" Error " << dY << endl;
311 hit->SetRefIndex(iPoint);
313 if (fVerbose>1) cout <<
", good match" << endl;
317 if ( TMath::Abs(hit->GetZ() - point->GetZ()) > 1. ) {
318 cout <<
"-E- " << GetName() <<
"::Exec: Hit " << iHit
319 <<
" is at z = " << hit->GetZ() <<
" cm, but matched point "
320 << iPoint <<
" is at z = " << point->GetZ() <<
"cm " << endl;
321 Fatal(
"Exec",
"Different stations for hit and point");
328 if ( warn ) cout <<
"- ";
330 cout << setw(15) << left << fName <<
": " << setprecision(4) << setw(8)
331 << fixed << right << fTimer.RealTime()
332 <<
" s, hits " << nHits <<
", matched " << nMatched <<
", distant "
333 << nDistant <<
", background " << setw(6) << nBackgrd << endl;
336 if ( warn) fNEventsFailed++;
339 fTime += fTimer.RealTime();
340 fNHits += Double_t(nHits);
341 fNMatched += Double_t(nMatched);
342 fNDistant += Double_t(nDistant);
343 fNBackgrd += Double_t(nBackgrd);
355 Bool_t warn = kFALSE;
358 Int_t nHits = fHits->GetEntriesFast();
364 Int_t nofStsHits = fHits->GetEntriesFast();
365 Int_t nofStsPoints = fPoints->GetEntriesFast();
366 cout <<
"there are " << nofStsPoints <<
" points and " << nofStsHits <<
" hits." << endl;
367 Int_t hitStationLimits[2][100];
369 for ( Int_t ist = 0 ; ist < fNStations ; ist++ ) {
370 hitStationLimits[0][ist] = -1;
371 hitStationLimits[1][ist] = -1;
375 for ( Int_t ihit = 0 ; ihit < nofStsHits ; ihit++ ) {
377 stsHit->SetRefIndex(-1);
378 if ( hitStationLimits[0][stsHit->
GetStationNr()-1] == -1 )
381 if ( hitStationLimits[1][stsHitBack->
GetStationNr()-1] == -1 ) {
382 hitStationLimits[1][stsHitBack->
GetStationNr()-1] = nofStsHits-ihit;
388 for ( Int_t ipnt = 0 ; ipnt < nofStsPoints ; ipnt++ ) {
391 Int_t startHit = hitStationLimits[0][fStationNrFromMcId[stsPoint->GetDetectorID()]];
392 Int_t finalHit = hitStationLimits[1][fStationNrFromMcId[stsPoint->GetDetectorID()]];
394 if ( startHit == -1 && finalHit == -1 )
continue;
396 for ( Int_t ihit = startHit ; ihit < finalHit ; ihit++ ) {
398 if ( ( TMath::Abs(stsHit->GetX()-stsPoint->
GetX(stsHit->GetZ())) < .01 ) &&
399 ( TMath::Abs(stsHit->GetY()-stsPoint->
GetY(stsHit->GetZ())) < .04 ) ) {
403 stsHit->SetRefIndex(ipnt);
412 if ( warn ) cout <<
"- ";
414 cout << setw(15) << left << fName <<
": " << setprecision(4) << setw(8)
415 << fixed << right << fTimer.RealTime()
416 <<
" s, hits " << nHits <<
", matched " << nMatched <<
", distant "
417 << nDistant <<
", background " << setw(6) << nBackgrd << endl;
420 if ( warn) fNEventsFailed++;
423 fTime += fTimer.RealTime();
424 fNHits += Double_t(nHits);
425 fNMatched += Double_t(nMatched);
426 fNDistant += Double_t(nDistant);
427 fNBackgrd += Double_t(nBackgrd);
436void CbmStsRealMatchHits::SetParContainers() {
439 FairRunAna*
run = FairRunAna::Instance();
440 if ( !
run ) Fatal(
"SetParContainers",
"No analysis run");
441 FairRuntimeDb* db =
run->GetRuntimeDb();
442 if ( ! db ) Fatal(
"SetParContainers",
"No runtime database");
446 fGeoPar = (
CbmGeoStsPar*) db->getContainer(
"CbmGeoStsPar");
447 fDigiPar = (
CbmStsDigiPar*) db->getContainer(
"CbmStsDigiPar");
455InitStatus CbmStsRealMatchHits::Init() {
458 fNEvents = fNEventsFailed = 0;
459 fTime = fNHits = fNMatched = fNDistant = fNBackgrd = 0.;
462 FairRootManager* ioman = FairRootManager::Instance();
463 if ( ! ioman ) Fatal(
"Init",
"No FairRootManager");
464 fPoints = (TClonesArray*) ioman->GetObject(
"StsPoint");
469 fDigis = (TClonesArray*) ioman->GetObject(
"StsDigi");
471 cout <<
"-E- " << GetName() <<
"::Init: No StsDigi array!" << endl;
474 fDigiMatches = (TClonesArray*) ioman->GetObject(
"StsDigiMatch");
475 if ( ! fDigiMatches ) {
476 cout <<
"-E- " << GetName() <<
"::Init: No StsDigiMatch array!"
480 fHits = (TClonesArray*) ioman->GetObject(
"StsHit");
482 cout <<
"-E- " << GetName() <<
"::Init: No StsHit array!" << endl;
486 InitStatus geoStatus = GetGeometry();
487 if ( geoStatus != kSUCCESS ) {
488 cout <<
"-E- " << GetName() <<
"::Init: Error in reading geometry!"
494 if ( fDigiScheme->
Init(fGeoPar, fDigiPar) ) {
495 if (fVerbose == 1 || fVerbose == 2) fDigiScheme->
Print(kFALSE);
496 else if (fVerbose > 2) fDigiScheme->
Print(kTRUE);
497 cout <<
"-I- " << fName <<
"::Init: "
498 <<
"STS digitisation scheme succesfully initialised" << endl;
500 <<
", Sectors: " << fDigiScheme->
GetNSectors() <<
", Channels: "
513InitStatus CbmStsRealMatchHits::ReInit() {
516 fDigiScheme->
Clear();
519 if ( fDigiScheme->
Init(fGeoPar, fDigiPar) )
return kSUCCESS;
521 InitStatus geoStatus = GetGeometry();
522 if ( geoStatus != kSUCCESS ) {
523 cout <<
"-E- " << GetName() <<
"::Init: Error in reading geometry!"
534InitStatus CbmStsRealMatchHits::GetGeometry() {
538 cout <<
"-W- " << GetName() <<
"::GetGeometry: No passive geometry!"
540 fTargetPos.SetXYZ(0., 0., 0.);
545 cout <<
"-W- " << GetName() <<
"::GetGeometry: No passive node array"
547 fTargetPos.SetXYZ(0., 0., 0.);
566 cout <<
"-W- " << GetName() <<
"::GetGeometry: No passive geometry!"
573 cout <<
"-E- " << GetName() <<
"::GetGeometry: No STS node array"
578 Int_t tempNofStations = stsNodes->GetEntries();
580 cout <<
"There are " << tempNofStations <<
" nodes" << (tempNofStations > 10 ?
"!!!" :
"" ) << endl;
584 TString stationNames[100];
585 for ( Int_t ist = 0 ; ist < tempNofStations ; ist++ ) {
586 FairGeoNode* stsNode = (FairGeoNode*)stsNodes->At(ist);
588 cout <<
"-W- CbmStsDigiScheme::Init: station#" << ist
589 <<
" not found among sensitive nodes " << endl;
592 geoNodeName = stsNode->getName();
595 Bool_t stationKnown = kFALSE;
597 for ( Int_t ikst = 0 ; ikst < fNStations ; ikst++ )
598 if ( geoNodeName.Contains(stationNames[ikst]) ) {
599 fStationNrFromMcId[stsNode->getMCid()] = ikst;
600 stationKnown = kTRUE;
603 if ( stationKnown )
continue;
606 fStationNrFromMcId[stsNode->getMCid()] = fNStations;
611 geoNodeName.Remove(12,geoNodeName.Length()-12);
612 stationNames[fNStations] = geoNodeName.Data();
615 cout <<
"station #" << fNStations <<
" has MCID = " << stsNode->getMCid() <<
" and name " << stsNode->GetName() << endl;
619 cout <<
"There are " << fNStations <<
" stations" << endl;
629void CbmStsRealMatchHits::Finish() {
632 cout <<
"============================================================"
634 cout <<
"===== " << GetName() <<
": Run summary " << endl;
635 cout <<
"===== " << endl;
636 cout <<
"===== Good events : " << setw(6) << fNEvents << endl;
637 cout <<
"===== Failed events : " << setw(6) << fNEventsFailed << endl;
638 cout <<
"===== Average time : " << setprecision(4) << setw(8) << right
639 << fTime / Double_t(fNEvents) <<
" s" << endl;
640 cout <<
"===== " << endl;
641 cout <<
"===== Hits per event : " << fixed << setprecision(0)
642 << fNHits / Double_t(fNEvents) << endl;
643 cout << setprecision(2);
644 cout <<
"===== Matched hits : " << fixed << setw(6) << right
645 << fNMatched / fNHits * 100. <<
" %" << endl;
646 cout <<
"===== Distant hits : " << fixed << setw(6) << right
647 << fNDistant / fNHits * 100. <<
" %" << endl;
648 cout <<
"===== Background hits : " << fixed << setw(6) << right
649 << fNBackgrd / fNHits * 100. <<
" % " << endl;
650 cout <<
"============================================================"
vector< Double_t > dist(vector< Double_t > qp, Double_t mu)
TObjArray * GetGeoSensitiveNodes()
Int_t GetRefIndex(Int_t i=0) const
void Print(Bool_t kLong=kFALSE)
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
Double_t GetY(Double_t z) const
Double_t GetX(Double_t z) const
virtual ~CbmStsRealMatchHits()
virtual void Exec(Option_t *opt)
virtual void ExecReal(Option_t *opt)
Double_t GetZ(Int_t it=0)
TObjArray * GetGeoPassiveNodes()