18#include "TClonesArray.h"
19#include "TGeoManager.h"
26#include "FairEventHeader.h"
43#include "FairRunAna.h"
47using std::setprecision;
59 case kPositron: idx = 0;
break;
61 case kMuonPlus: idx = 1;
break;
63 case kPiPlus: idx = 2;
break;
65 case kKPlus: idx = 3;
break;
67 case kProtonBar: idx = 4;
break;
68 default: idx = 5;
break;
74 if (idx < 0 || idx >= 5)
return 0;
77 case 0: pdg = kElectron;
break;
78 case 1: pdg = kMuonMinus;
break;
79 case 2: pdg = kPiPlus;
break;
80 case 3: pdg = kKPlus;
break;
81 case 4: pdg = kProton;
break;
87 if (idx < 0 || idx >= 5)
return "non";
92 if (idx < 0 || idx >= 5)
return "o";
105 : FairTask(
"CbmTrackingTrdQa", iVerbose)
106 , fMinStations(minStations)
126 LOG(debug) << GetName() <<
": Process event ";
144 Int_t nRecFastLong = 0;
156 std::sort(events.begin(), events.end());
167 std::cout <<
"MC events in slice : " << events.size() << std::endl;
169 for (uint iLink = 0; iLink < events.size(); iLink++) {
172 std::cout <<
"MC event " << iLink <<
" n mc tracks " <<
nMCTracks << std::endl;
173 for (Int_t iTr = 0; iTr <
nMCTracks; iTr++) {
189 const CbmLink& link = itTrack->first;
200 if (TMath::Abs(vertex.Z() -
fTargetPos.Z()) < 1.) {
206 info.
fP = momentum.Mag();
207 info.
fPt = momentum.Pt();
214 Int_t nStations = info.
fHitMap.size();
216 int nContStations = 0;
220 for (
auto itSta = info.
fHitMap.begin(); itSta != info.
fHitMap.end(); itSta++) {
221 if (itSta->first == istaprev + 1) {
227 if (nContStations < len) {
230 istaprev = itSta->first;
277 Double_t quali = info.
fQuali;
279 if (globalTrackId < 0)
continue;
280 if (trdTrackId < 0)
continue;
293 assert(nTrue + nWrong + nFake == nAllHits);
298 if (stsTrackId >= 0) {
307 double p = (fabs(qp) > 1. / 1000.) ? 1. / fabs(qp) : 1000.;
310 double pt =
sqrt((tx * tx + ty * ty) / (1. + tx * tx + ty * ty)) * p;
313 LOG(debug1) << GetName() <<
": MCTrack " << iMcTrack <<
", stations " << nStations <<
", hits " << nAllHits
314 <<
", true hits " << nTrue;
326 if (info.
fPt > 0.001) {
329 if (info.
fP > 0.001) {
330 double dp = p / info.
fP - 1.;
354 if (isFastLong) nRecFastLong++;
360 for (uint iLink = 0; iLink < events.size(); iLink++) {
363 std::cout <<
"MC event " << iLink <<
" n mc points " << nMcPoints << std::endl;
364 for (Int_t ip = 0; ip < nMcPoints; ip++) {
378 Double_t effAll = Double_t(nRecAll) / Double_t(nAcc);
379 Double_t effPrim = Double_t(nRecPrim) / Double_t(nPrim);
380 Double_t effFast = Double_t(nRecFast) / Double_t(nFast);
381 Double_t effFastLong = Double_t(nRecFastLong) / Double_t(nFastLong);
382 Double_t effSec = Double_t(nRecSec) / Double_t(nSec);
388 LOG(info) <<
"+ " << setw(20) << GetName() <<
": Event " << setw(6) << right <<
fNEvents <<
", real time " << fixed
389 << setprecision(6) <<
fTimer.RealTime() <<
" s, MC tracks: all " << nMcTracks <<
", acc. " << nAcc
390 <<
", rec. " << nRecAll <<
", eff. " << setprecision(2) << 100. * effAll <<
" %";
391 if (fair::Logger::Logging(fair::Severity::debug)) {
392 LOG(debug) <<
"---------- CbmTrackingTrdQa : Event summary ------------";
393 LOG(debug) <<
"MCTracks : " << nAll <<
", reconstructible: " << nAcc <<
", reconstructed: " << nRecAll;
394 LOG(debug) <<
"Vertex : reconstructible: " << nPrim <<
", reconstructed: " << nRecPrim <<
", efficiency "
395 << effPrim * 100. <<
"%";
396 LOG(debug) <<
"Fast : reconstructible: " << nFast <<
", reconstructed: " << nRecFast <<
", efficiency "
397 << effFast * 100. <<
"%";
398 LOG(debug) <<
"Fast long : reconstructible: " << nFastLong <<
", reconstructed: " << nRecFastLong <<
", efficiency "
399 << effFastLong * 100. <<
"%";
400 LOG(debug) <<
"Non-vertex : reconstructible: " << nSec <<
", reconstructed: " << nRecSec <<
", efficiency "
401 << effSec * 100. <<
"%";
402 LOG(debug) <<
"TrdTracks " << nTracks <<
", ghosts " << nGhosts <<
", clones " << nClones;
403 LOG(debug) <<
"-----------------------------------------------------------\n";
436 LOG(info) <<
"\n\n====================================================";
437 LOG(info) << GetName() <<
": Initialising...";
439 fManager = FairRootManager::Instance();
449 LOG(fatal) <<
"CbmTrackingTrdQa: No time slice object";
462 if (geoStatus != kSUCCESS) {
463 LOG(error) << GetName() <<
"::Init: Error in reading geometry!";
510 LOG(info) <<
" Minimum number of Trd stations : " <<
fMinStations;
511 LOG(info) <<
" Matching quota : " <<
fQuota;
512 LOG(info) <<
"====================================================";
523 LOG(info) <<
"\n\n====================================================";
524 LOG(info) << GetName() <<
": Re-initialising...";
528 if (geoStatus != kSUCCESS) {
529 LOG(error) << GetName() <<
"::Init: Error in reading geometry!";
536 LOG(info) <<
" Minimum number of TRD stations : " <<
fMinStations;
537 LOG(info) <<
" Matching quota : " <<
fQuota;
538 LOG(info) <<
"====================================================";
557 for (
int idx(0); idx <
fgkNpdg; idx++) {
582 std::cout << std::endl;
583 LOG(info) <<
"=====================================";
584 LOG(info) << fName <<
": Run summary ";
585 LOG(info) <<
"Events processed : " <<
fNEvents << setprecision(2);
586 LOG(info) <<
"Eff. all tracks : " << effAll * 100 <<
" % (" <<
fNRecAll <<
"/" <<
fNAccAll <<
")";
587 LOG(info) <<
"Eff. vertex tracks : " << effPrim * 100 <<
" % (" <<
fNRecPrim <<
"/" <<
fNAccPrim <<
")";
588 LOG(info) <<
"Eff. fast tracks : " << effFast * 100 <<
" % (" <<
fNRecFast <<
"/" <<
fNAccFast <<
")";
591 LOG(info) <<
"Eff. secondary tracks : " << effSec * 100 <<
" % (" <<
fNRecSec <<
"/" <<
fNAccSec <<
")";
592 LOG(info) <<
"Ghost rate : " << rateGhosts * 100 <<
" % (" <<
fNGhosts <<
"/" <<
fNRecAll <<
")";
593 LOG(info) <<
"Clone rate : " << rateClones * 100 <<
" % (" <<
fNClones <<
"/" <<
fNRecAll <<
")";
595 LOG(info) <<
"Time per event : " << setprecision(6) <<
fTime / Double_t(
fNEvents) <<
" s";
598 LOG(info) <<
"=====================================";
609 FairSink* sink = FairRootManager::Instance()->GetSink();
623 assert(trdInterface);
634 TGeoNode* target = NULL;
636 gGeoManager->CdTop();
637 TGeoNode* cave = gGeoManager->GetCurrentNode();
638 for (Int_t iNode1 = 0; iNode1 < cave->GetNdaughters(); iNode1++) {
639 TString name = cave->GetDaughter(iNode1)->GetName();
640 if (name.Contains(
"pipe", TString::kIgnoreCase)) {
641 LOG(debug) <<
"Found pipe node " << name;
642 gGeoManager->CdDown(iNode1);
646 for (Int_t iNode2 = 0; iNode2 < gGeoManager->GetCurrentNode()->GetNdaughters(); iNode2++) {
647 TString name = gGeoManager->GetCurrentNode()->GetDaughter(iNode2)->GetName();
648 if (name.Contains(
"pipevac1", TString::kIgnoreCase)) {
649 LOG(debug) <<
"Found vacuum node " << name;
650 gGeoManager->CdDown(iNode2);
654 for (Int_t iNode3 = 0; iNode3 < gGeoManager->GetCurrentNode()->GetNdaughters(); iNode3++) {
655 TString name = gGeoManager->GetCurrentNode()->GetDaughter(iNode3)->GetName();
656 if (name.Contains(
"target", TString::kIgnoreCase)) {
657 LOG(debug) <<
"Found target node " << name;
658 gGeoManager->CdDown(iNode3);
659 target = gGeoManager->GetCurrentNode();
669 TGeoHMatrix* glbMatrix = gGeoManager->GetCurrentMatrix();
670 Double_t*
pos = glbMatrix->GetTranslation();
676 gGeoManager->CdTop();
701 fhStationEffXY.emplace_back(Form(
"fhStationEffXY%i", i), Form(
"Efficiency XY: Station %i;X [cm];Y [cm]", i), 300,
702 -dx, dx, 300, -dy, dy);
712 fhPtAccAll =
new TH1F(
"hPtAccAll",
"all reconstructable tracks", nBinsPt, minPt, maxPt);
713 fhPtRecAll =
new TH1F(
"hPtRecAll",
"all reconstructed tracks", nBinsPt, minPt, maxPt);
714 fhPtEffAll =
new TH1F(
"hPtEffAll",
"efficiency all tracks", nBinsPt, minPt, maxPt);
715 fhPtAccPrim =
new TH1F(
"hPtAccPrim",
"reconstructable vertex tracks", nBinsPt, minPt, maxPt);
716 fhPtRecPrim =
new TH1F(
"hPtRecPrim",
"reconstructed vertex tracks", nBinsPt, minPt, maxPt);
717 fhPtEffPrim =
new TH1F(
"hPtEffPrim",
"efficiency vertex tracks", nBinsPt, minPt, maxPt);
718 fhPtAccSec =
new TH1F(
"hPtAccSec",
"reconstructable non-vertex tracks", nBinsPt, minPt, maxPt);
719 fhPtRecSec =
new TH1F(
"hPtRecSec",
"reconstructed non-vertex tracks", nBinsPt, minPt, maxPt);
720 fhPtEffSec =
new TH1F(
"hPtEffSec",
"efficiency non-vertex tracks", nBinsPt, minPt, maxPt);
731 const char* pltTitle[] = {
"Yield",
"Yield",
"Yield",
"Efficiency",
"Efficiency",
"Efficiency"};
732 const char* pltLab[] = {
"yield",
"yield",
"yield",
"#epsilon (%)",
"#epsilon (%)",
"#epsilon (%)"};
733 const char* vxTyp[] = {
"allY",
"prmY",
"secY",
"allE",
"prmE",
"secE"};
734 for (
int ivx(0); ivx < 6; ivx++) {
735 for (
int ipid(0); ipid <
fgkNpdg; ipid++) {
736 fhPidPtY[vxTyp[ivx]][ipid] =
new TH2F(
737 Form(
"hPtY_%s%s", vxTyp[ivx],
Idx2Symb(ipid)),
738 Form(
"%s %s(%s); y - y_{cm}; p_{T} (GeV/c); %s", pltTitle[ivx],
Idx2Name(ipid), vxTyp[ivx], pltLab[ivx]), 50,
739 -2.5, 2.5, nBinsPt, minPt, maxPt);
744 Double_t minNp = -0.5;
745 Double_t maxNp = 15.5;
747 fhNpAccAll =
new TH1F(
"hNpAccAll",
"all reconstructable tracks", nBinsNp, minNp, maxNp);
748 fhNpRecAll =
new TH1F(
"hNpRecAll",
"all reconstructed tracks", nBinsNp, minNp, maxNp);
749 fhNpEffAll =
new TH1F(
"hNpEffAll",
"efficiency all tracks", nBinsNp, minNp, maxNp);
750 fhNpAccPrim =
new TH1F(
"hNpAccPrim",
"reconstructable vertex tracks", nBinsNp, minNp, maxNp);
751 fhNpRecPrim =
new TH1F(
"hNpRecPrim",
"reconstructed vertex tracks", nBinsNp, minNp, maxNp);
752 fhNpEffPrim =
new TH1F(
"hNpEffPrim",
"efficiency vertex tracks", nBinsNp, minNp, maxNp);
753 fhNpAccSec =
new TH1F(
"hNpAccSec",
"reconstructable non-vertex tracks", nBinsNp, minNp, maxNp);
754 fhNpRecSec =
new TH1F(
"hNpRecSec",
"reconstructed non-vertex tracks", nBinsNp, minNp, maxNp);
755 fhNpEffSec =
new TH1F(
"hNpEffSec",
"efficiency non-vertex tracks", nBinsNp, minNp, maxNp);
770 fhZAccSec =
new TH1F(
"hZAccSec",
"reconstructable non-vertex tracks", nBinsZ, minZ, maxZ);
771 fhZRecSec =
new TH1F(
"hZRecSecl",
"reconstructed non-vertex tracks", nBinsZ, minZ, maxZ);
772 fhZEffSec =
new TH1F(
"hZEffRec",
"efficiency non-vertex tracks", nBinsZ, minZ, maxZ);
778 fhNhClones =
new TH1F(
"hNhClones",
"number of hits for clones", nBinsNp, minNp, maxNp);
779 fhNhGhosts =
new TH1F(
"hNhGhosts",
"number of hits for ghosts", nBinsNp, minNp, maxNp);
783 fhPtResPrim =
new TH1F(
"hPtPrim",
"Resolution Pt Primaries [100%]", 100, -1., 1.);
786 fhPResPrim =
new TH1F(
"hPPrim",
"Resolution P Primaries [100%]", 100, -1., 1.);
789 fhPResPrimSts0 =
new TH1F(
"hPPrimSts0",
"Resolution P Primaries [100%], No Sts hits", 100, -1., 1.);
792 fhPResPrimSts1 =
new TH1F(
"hPPrimSts1",
"Resolution P Primaries [100%], 1 Sts hit", 100, -1., 1.);
795 fhPResPrimSts2 =
new TH1F(
"hPPrimSts2",
"Resolution P Primaries [100%], 2 Sts hits", 100, -1., 1.);
798 fhPResPrimSts3 =
new TH1F(
"hPPrimSts3",
"Resolution P Primaries [100%], >=3 Sts hits", 100, -1., 1.);
802 while (TH1* histo = ((TH1*) next())) {
814 while (TH1* histo = ((TH1*) next()))
832 for (Int_t iHit = 0; iHit <
fTrdHits->GetEntriesFast(); iHit++) {
859 LOG(debug) << GetName() <<
": Filled hit map from " <<
fTrdHits->GetEntriesFast() <<
" Trd hits";
884 for (Int_t iGlobalTrack = 0; iGlobalTrack <
fGlobalTracks->GetEntriesFast(); iGlobalTrack++) {
898 if (iTrdTrack < 0)
continue;
907 assert(iTrdTrack >= 0 && iTrdTrack < fTrdTrackMatches->GetEntriesFast());
915 Double_t quali = Double_t(nTrue) / Double_t(nHits);
960 LOG(debug) << GetName() <<
": Filled match map for " << nRec <<
" Trd tracks. Ghosts " << nGhosts <<
" Clones "
970 if (!histo1 || !histo2 || !histo3) {
971 LOG(fatal) << GetName() <<
"::DivideHistos: "
972 <<
"NULL histogram pointer";
975 Int_t nBins = histo1->GetNbinsX();
976 if (histo2->GetNbinsX() != nBins || histo3->GetNbinsX() != nBins) {
977 LOG(error) << GetName() <<
"::DivideHistos: "
978 <<
"Different bin numbers in histos";
979 LOG(error) << histo1->GetName() <<
" " << histo1->GetNbinsX();
980 LOG(error) << histo2->GetName() <<
" " << histo2->GetNbinsX();
981 LOG(error) << histo3->GetName() <<
" " << histo3->GetNbinsX();
984 if (strcmp(opt,
"2D") == 0) {
985 Int_t nBinsY = histo1->GetNbinsY();
986 if (histo2->GetNbinsY() != nBinsY || histo3->GetNbinsY() != nBinsY) {
987 LOG(error) << GetName() <<
"::DivideHistos: "
988 <<
"Different bin numbers in histos";
989 LOG(error) << histo1->GetName() <<
" " << histo1->GetNbinsY();
990 LOG(error) << histo2->GetName() <<
" " << histo2->GetNbinsY();
991 LOG(error) << histo3->GetName() <<
" " << histo3->GetNbinsY();
997 Double_t c1, c2, c3, ce;
998 for (Int_t iBin = 0; iBin < nBins; iBin++) {
999 c1 = histo1->GetBinContent(iBin);
1000 c2 = histo2->GetBinContent(iBin);
1003 Double_t c4 = (c3 * (1. - c3) / c2);
1005 ce = TMath::Sqrt(c3 * (1. - c3) / c2);
1015 histo3->SetBinContent(iBin, 1.e2 * c3);
1016 histo3->SetBinError(iBin, 1.e2 * ce);
ClassImp(CbmConverterManager)
Data class for STS tracks.
Class for hits in TRD detector.
friend fvec sqrt(const fvec &a)
int32_t GetStsTrackIndex() const
const FairTrackParam * GetParamFirst() const
int32_t GetTrdTrackIndex() const
void SetIndex(int32_t index)
void SetFile(int32_t file)
TObject * Get(const CbmLink *lnk)
Int_t Size(Int_t fileNumber, Int_t eventNumber)
Task class creating and managing CbmMCDataArray objects.
CbmMCDataArray * InitBranch(const char *name)
void GetMomentum(TVector3 &momentum) const
int32_t GetPdgCode() const
double GetRapidity() const
void GetStartVertex(TVector3 &vertex) const
int32_t GetNofLinks() const
const CbmLink & GetMatchedLink() const
const std::vector< CbmLink > & GetLinks() const
virtual int32_t GetTotalNofHits() const
Bookkeeping of time-slice content.
const CbmMatch & GetMatch() const
int32_t GetNofWrongHits() const
int32_t GetNofTrueHits() const
virtual int32_t GetNofHits() const
TClonesArray * fTrdHitMatch
TrdHits.
CbmMCDataArray * fMCTracks
MC tracks.
static int Pdg2Idx(int pdg)
TClonesArray * fTrdHits
TrdPoints.
McTrackInfo & getMcTrackInfo(const CbmLink &link)
std::map< const char *, std::array< TH2F *, fgkNpdg > > fhPidPtY
FairRootManager * fManager
map track link -> track info
Int_t fTrdNstations
MCtrack.
TClonesArray * fStsTrackMatches
StsTrack.
TClonesArray * fTrdTracks
GlobalTrack.
std::map< CbmLink, McTrackInfo > fMcTrackInfoMap
static const char * Idx2Symb(int idx)
CbmMCDataArray * fTrdPoints
static const char * fgkIdxName[fgkNpdg]
TClonesArray * fTrdTrackMatches
TrdTrack.
std::vector< CbmQaHist< TProfile2D > > fhStationEffXY
output folder with histos and canvases
virtual void Exec(Option_t *opt)
static int Idx2Pdg(int idx)
static const char * Idx2Name(int idx)
virtual InitStatus Init()
virtual ~CbmTrackingTrdQa()
virtual void SetParContainers()
CbmMCDataManager * fMcManager
TClonesArray * fStsTracks
TrdTrackMatch.
TClonesArray * fGlobalTracks
TrdHitMatch.
void DivideHistos(TH1 *histo1, TH1 *histo2, TH1 *histo3, Option_t *opt="")
TVector3 fTargetPos
StsTrackMatch.
CbmTrackingTrdQa(Int_t iVerbose=1)
CbmTimeSlice * fTimeSlice
static const char * fgkIdxSymb[fgkNpdg]
virtual InitStatus ReInit()
void FillTrackMatchMap(Int_t &nRec, Int_t &nGhosts, Int_t &nClones)
data class for a reconstructed Energy-4D measurement in the TRD
bool GetClassType() const
static CbmTrdTrackingInterface * Instance()
Gets pointer to the instance of the CbmTrdTrackingInterface.
int GetTrackingStationIndex(const CbmHit *hit) const override
Gets a tracking station of a CbmHit.
Int_t fStsTrackMatch
matched TrdTrack index
Int_t fMatchedNHitsTrue
number of matched hits
Int_t fNtimesReconstructed
Double_t fQuali
matched StsTrack index
std::map< Int_t, Int_t > fHitMap
Int_t fMatchedNHitsAll
percentage of matched hits
Int_t fTrdTrackMatch
matched GlobalTrack index
Bool_t fIsAccepted
number of matched hits
Int_t fGlobalTrackMatch
Trd station -> number of attached hits.