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)
126 LOG(debug) << GetName() <<
": Process event ";
144 Int_t nRecFastLong = 0;
155 std::vector<CbmLink> events =
fTimeSlice->GetMatch().GetLinks();
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;
191 const CbmLink& link = itTrack->first;
202 if (TMath::Abs(vertex.Z() -
fTargetPos.Z()) < 1.) {
208 info.
fP = momentum.Mag();
209 info.
fPt = momentum.Pt();
218 int nContStations = 0;
222 for (
auto itSta = info.
fHitMap.begin(); itSta != info.
fHitMap.end(); itSta++) {
223 if (itSta->first == istaprev + 1) {
229 if (nContStations < len) {
232 istaprev = itSta->first;
279 Double_t quali = info.
fQuali;
281 if (globalTrackId < 0)
continue;
282 if (trdTrackId < 0)
continue;
295 assert(nTrue + nWrong + nFake == nAllHits);
300 if (stsTrackId >= 0) {
309 double p = (fabs(qp) > 1. / 1000.) ? 1. / fabs(qp) : 1000.;
312 double pt =
sqrt((tx * tx + ty * ty) / (1. + tx * tx + ty * ty)) * p;
315 LOG(debug1) << GetName() <<
": MCTrack " << iMcTrack <<
", stations " << nStations <<
", hits " << nAllHits
316 <<
", true hits " << nTrue;
328 if (info.
fPt > 0.001) {
331 if (info.
fP > 0.001) {
332 double dp = p / info.
fP - 1.;
356 if (isFastLong) nRecFastLong++;
362 for (uint iLink = 0; iLink < events.size(); iLink++) {
365 std::cout <<
"MC event " << iLink <<
" n mc points " << nMcPoints << std::endl;
366 for (
Int_t ip = 0; ip < nMcPoints; ip++) {
370 Int_t station = pTrdIfs->GetTrackingStationId(pt->GetDetectorID());
380 Double_t effAll = Double_t(nRecAll) / Double_t(nAcc);
381 Double_t effPrim = Double_t(nRecPrim) / Double_t(nPrim);
382 Double_t effFast = Double_t(nRecFast) / Double_t(nFast);
383 Double_t effFastLong = Double_t(nRecFastLong) / Double_t(nFastLong);
384 Double_t effSec = Double_t(nRecSec) / Double_t(nSec);
390 LOG(info) <<
"+ " << setw(20) << GetName() <<
": Event " << setw(6) << right <<
fNEvents <<
", real time " << fixed
391 << setprecision(6) <<
fTimer.RealTime() <<
" s, MC tracks: all " << nMcTracks <<
", acc. " << nAcc
392 <<
", rec. " << nRecAll <<
", eff. " << setprecision(2) << 100. * effAll <<
" %";
393 if (fair::Logger::Logging(fair::Severity::debug)) {
394 LOG(debug) <<
"---------- CbmTrackingTrdQa : Event summary ------------";
395 LOG(debug) <<
"MCTracks : " << nAll <<
", reconstructible: " << nAcc <<
", reconstructed: " << nRecAll;
396 LOG(debug) <<
"Vertex : reconstructible: " << nPrim <<
", reconstructed: " << nRecPrim <<
", efficiency "
397 << effPrim * 100. <<
"%";
398 LOG(debug) <<
"Fast : reconstructible: " << nFast <<
", reconstructed: " << nRecFast <<
", efficiency "
399 << effFast * 100. <<
"%";
400 LOG(debug) <<
"Fast long : reconstructible: " << nFastLong <<
", reconstructed: " << nRecFastLong <<
", efficiency "
401 << effFastLong * 100. <<
"%";
402 LOG(debug) <<
"Non-vertex : reconstructible: " << nSec <<
", reconstructed: " << nRecSec <<
", efficiency "
403 << effSec * 100. <<
"%";
404 LOG(debug) <<
"TrdTracks " << nTracks <<
", ghosts " << nGhosts <<
", clones " << nClones;
405 LOG(debug) <<
"-----------------------------------------------------------\n";
438 LOG(info) <<
"\n\n====================================================";
439 LOG(info) << GetName() <<
": Initialising...";
441 fManager = FairRootManager::Instance();
451 LOG(fatal) <<
"CbmTrackingTrdQa: No time slice object";
464 if (geoStatus != kSUCCESS) {
465 LOG(error) << GetName() <<
"::Init: Error in reading geometry!";
511 LOG(info) <<
" Minimum number of Trd stations : " <<
fMinStations;
512 LOG(info) <<
" Matching quota : " <<
fQuota;
513 LOG(info) <<
"====================================================";
524 LOG(info) <<
"\n\n====================================================";
525 LOG(info) << GetName() <<
": Re-initialising...";
529 if (geoStatus != kSUCCESS) {
530 LOG(error) << GetName() <<
"::Init: Error in reading geometry!";
537 LOG(info) <<
" Minimum number of TRD stations : " <<
fMinStations;
538 LOG(info) <<
" Matching quota : " <<
fQuota;
539 LOG(info) <<
"====================================================";
558 for (
int idx(0); idx <
fgkNpdg; idx++) {
583 std::cout << std::endl;
584 LOG(info) <<
"=====================================";
585 LOG(info) << fName <<
": Run summary ";
586 LOG(info) <<
"Events processed : " <<
fNEvents << setprecision(2);
587 LOG(info) <<
"Eff. all tracks : " << effAll * 100 <<
" % (" <<
fNRecAll <<
"/" <<
fNAccAll <<
")";
588 LOG(info) <<
"Eff. vertex tracks : " << effPrim * 100 <<
" % (" <<
fNRecPrim <<
"/" <<
fNAccPrim <<
")";
589 LOG(info) <<
"Eff. fast tracks : " << effFast * 100 <<
" % (" <<
fNRecFast <<
"/" <<
fNAccFast <<
")";
592 LOG(info) <<
"Eff. secondary tracks : " << effSec * 100 <<
" % (" <<
fNRecSec <<
"/" <<
fNAccSec <<
")";
593 LOG(info) <<
"Ghost rate : " << rateGhosts * 100 <<
" % (" <<
fNGhosts <<
"/" <<
fNRecAll <<
")";
594 LOG(info) <<
"Clone rate : " << rateClones * 100 <<
" % (" <<
fNClones <<
"/" <<
fNRecAll <<
")";
596 LOG(info) <<
"Time per event : " << setprecision(6) <<
fTime / Double_t(
fNEvents) <<
" s";
599 LOG(info) <<
"=====================================";
610 FairSink* sink = FairRootManager::Instance()->GetSink();
629 LOG(error) << fName <<
": TRD reco unit is not in the setup";
644 TGeoNode* target = NULL;
646 gGeoManager->CdTop();
647 TGeoNode* cave = gGeoManager->GetCurrentNode();
648 for (
Int_t iNode1 = 0; iNode1 < cave->GetNdaughters(); iNode1++) {
649 TString name = cave->GetDaughter(iNode1)->GetName();
650 if (name.Contains(
"pipe", TString::kIgnoreCase)) {
651 LOG(debug) <<
"Found pipe node " << name;
652 gGeoManager->CdDown(iNode1);
656 for (
Int_t iNode2 = 0; iNode2 < gGeoManager->GetCurrentNode()->GetNdaughters(); iNode2++) {
657 TString name = gGeoManager->GetCurrentNode()->GetDaughter(iNode2)->GetName();
658 if (name.Contains(
"pipevac1", TString::kIgnoreCase)) {
659 LOG(debug) <<
"Found vacuum node " << name;
660 gGeoManager->CdDown(iNode2);
664 for (
Int_t iNode3 = 0; iNode3 < gGeoManager->GetCurrentNode()->GetNdaughters(); iNode3++) {
665 TString name = gGeoManager->GetCurrentNode()->GetDaughter(iNode3)->GetName();
666 if (name.Contains(
"target", TString::kIgnoreCase)) {
667 LOG(debug) <<
"Found target node " << name;
668 gGeoManager->CdDown(iNode3);
669 target = gGeoManager->GetCurrentNode();
679 TGeoHMatrix* glbMatrix = gGeoManager->GetCurrentMatrix();
680 Double_t*
pos = glbMatrix->GetTranslation();
686 gGeoManager->CdTop();
711 fhStationEffXY.emplace_back(Form(
"fhStationEffXY%i", i), Form(
"Efficiency XY: Station %i;X [cm];Y [cm]", i), 300,
712 -dx, dx, 300, -dy, dy);
722 fhPtAccAll =
new TH1F(
"hPtAccAll",
"all reconstructable tracks", nBinsPt, minPt, maxPt);
723 fhPtRecAll =
new TH1F(
"hPtRecAll",
"all reconstructed tracks", nBinsPt, minPt, maxPt);
724 fhPtEffAll =
new TH1F(
"hPtEffAll",
"efficiency all tracks", nBinsPt, minPt, maxPt);
725 fhPtAccPrim =
new TH1F(
"hPtAccPrim",
"reconstructable vertex tracks", nBinsPt, minPt, maxPt);
726 fhPtRecPrim =
new TH1F(
"hPtRecPrim",
"reconstructed vertex tracks", nBinsPt, minPt, maxPt);
727 fhPtEffPrim =
new TH1F(
"hPtEffPrim",
"efficiency vertex tracks", nBinsPt, minPt, maxPt);
728 fhPtAccSec =
new TH1F(
"hPtAccSec",
"reconstructable non-vertex tracks", nBinsPt, minPt, maxPt);
729 fhPtRecSec =
new TH1F(
"hPtRecSec",
"reconstructed non-vertex tracks", nBinsPt, minPt, maxPt);
730 fhPtEffSec =
new TH1F(
"hPtEffSec",
"efficiency non-vertex tracks", nBinsPt, minPt, maxPt);
741 const char* pltTitle[] = {
"Yield",
"Yield",
"Yield",
"Efficiency",
"Efficiency",
"Efficiency"};
742 const char* pltLab[] = {
"yield",
"yield",
"yield",
"#epsilon (%)",
"#epsilon (%)",
"#epsilon (%)"};
743 const char* vxTyp[] = {
"allY",
"prmY",
"secY",
"allE",
"prmE",
"secE"};
744 for (
int ivx(0); ivx < 6; ivx++) {
745 for (
int ipid(0); ipid <
fgkNpdg; ipid++) {
746 fhPidPtY[vxTyp[ivx]][ipid] =
new TH2F(
747 Form(
"hPtY_%s%s", vxTyp[ivx],
Idx2Symb(ipid)),
748 Form(
"%s %s(%s); y - y_{cm}; p_{T} (GeV/c); %s", pltTitle[ivx],
Idx2Name(ipid), vxTyp[ivx], pltLab[ivx]), 50,
749 -2.5, 2.5, nBinsPt, minPt, maxPt);
754 Double_t minNp = -0.5;
755 Double_t maxNp = 15.5;
757 fhNpAccAll =
new TH1F(
"hNpAccAll",
"all reconstructable tracks", nBinsNp, minNp, maxNp);
758 fhNpRecAll =
new TH1F(
"hNpRecAll",
"all reconstructed tracks", nBinsNp, minNp, maxNp);
759 fhNpEffAll =
new TH1F(
"hNpEffAll",
"efficiency all tracks", nBinsNp, minNp, maxNp);
760 fhNpAccPrim =
new TH1F(
"hNpAccPrim",
"reconstructable vertex tracks", nBinsNp, minNp, maxNp);
761 fhNpRecPrim =
new TH1F(
"hNpRecPrim",
"reconstructed vertex tracks", nBinsNp, minNp, maxNp);
762 fhNpEffPrim =
new TH1F(
"hNpEffPrim",
"efficiency vertex tracks", nBinsNp, minNp, maxNp);
763 fhNpAccSec =
new TH1F(
"hNpAccSec",
"reconstructable non-vertex tracks", nBinsNp, minNp, maxNp);
764 fhNpRecSec =
new TH1F(
"hNpRecSec",
"reconstructed non-vertex tracks", nBinsNp, minNp, maxNp);
765 fhNpEffSec =
new TH1F(
"hNpEffSec",
"efficiency non-vertex tracks", nBinsNp, minNp, maxNp);
780 fhZAccSec =
new TH1F(
"hZAccSec",
"reconstructable non-vertex tracks", nBinsZ, minZ, maxZ);
781 fhZRecSec =
new TH1F(
"hZRecSecl",
"reconstructed non-vertex tracks", nBinsZ, minZ, maxZ);
782 fhZEffSec =
new TH1F(
"hZEffRec",
"efficiency non-vertex tracks", nBinsZ, minZ, maxZ);
788 fhNhClones =
new TH1F(
"hNhClones",
"number of hits for clones", nBinsNp, minNp, maxNp);
789 fhNhGhosts =
new TH1F(
"hNhGhosts",
"number of hits for ghosts", nBinsNp, minNp, maxNp);
793 fhPtResPrim =
new TH1F(
"hPtPrim",
"Resolution Pt Primaries [100%]", 100, -1., 1.);
796 fhPResPrim =
new TH1F(
"hPPrim",
"Resolution P Primaries [100%]", 100, -1., 1.);
799 fhPResPrimSts0 =
new TH1F(
"hPPrimSts0",
"Resolution P Primaries [100%], No Sts hits", 100, -1., 1.);
802 fhPResPrimSts1 =
new TH1F(
"hPPrimSts1",
"Resolution P Primaries [100%], 1 Sts hit", 100, -1., 1.);
805 fhPResPrimSts2 =
new TH1F(
"hPPrimSts2",
"Resolution P Primaries [100%], 2 Sts hits", 100, -1., 1.);
808 fhPResPrimSts3 =
new TH1F(
"hPPrimSts3",
"Resolution P Primaries [100%], >=3 Sts hits", 100, -1., 1.);
812 while (TH1* histo = ((TH1*) next())) {
824 while (TH1* histo = ((TH1*) next()))
841 for (
Int_t iHit = 0; iHit <
fTrdHits->GetEntriesFast(); iHit++) {
863 assert(pTrdIfs->GetTrackingStationId(pt->GetDetectorID()) == station);
869 LOG(debug) << GetName() <<
": Filled hit map from " <<
fTrdHits->GetEntriesFast() <<
" Trd hits";
894 for (
Int_t iGlobalTrack = 0; iGlobalTrack <
fGlobalTracks->GetEntriesFast(); iGlobalTrack++) {
908 if (iTrdTrack < 0)
continue;
917 assert(iTrdTrack >= 0 && iTrdTrack < fTrdTrackMatches->GetEntriesFast());
925 Double_t quali = Double_t(nTrue) / Double_t(nHits);
970 LOG(debug) << GetName() <<
": Filled match map for " << nRec <<
" Trd tracks. Ghosts " << nGhosts <<
" Clones "
980 if (!histo1 || !histo2 || !histo3) {
981 LOG(fatal) << GetName() <<
"::DivideHistos: "
982 <<
"NULL histogram pointer";
985 Int_t nBins = histo1->GetNbinsX();
986 if (histo2->GetNbinsX() != nBins || histo3->GetNbinsX() != nBins) {
987 LOG(error) << GetName() <<
"::DivideHistos: "
988 <<
"Different bin numbers in histos";
989 LOG(error) << histo1->GetName() <<
" " << histo1->GetNbinsX();
990 LOG(error) << histo2->GetName() <<
" " << histo2->GetNbinsX();
991 LOG(error) << histo3->GetName() <<
" " << histo3->GetNbinsX();
994 if (strcmp(opt,
"2D") == 0) {
995 Int_t nBinsY = histo1->GetNbinsY();
996 if (histo2->GetNbinsY() != nBinsY || histo3->GetNbinsY() != nBinsY) {
997 LOG(error) << GetName() <<
"::DivideHistos: "
998 <<
"Different bin numbers in histos";
999 LOG(error) << histo1->GetName() <<
" " << histo1->GetNbinsY();
1000 LOG(error) << histo2->GetName() <<
" " << histo2->GetNbinsY();
1001 LOG(error) << histo3->GetName() <<
" " << histo3->GetNbinsY();
1007 Double_t c1, c2, c3, ce;
1008 for (
Int_t iBin = 0; iBin < nBins; iBin++) {
1009 c1 = histo1->GetBinContent(iBin);
1010 c2 = histo2->GetBinContent(iBin);
1013 Double_t c4 = (c3 * (1. - c3) / c2);
1015 ce = TMath::Sqrt(c3 * (1. - c3) / c2);
1025 histo3->SetBinContent(iBin, 1.e2 * c3);
1026 histo3->SetBinError(iBin, 1.e2 * ce);
ClassImp(CbmConverterManager)
A manager for setup representation in CBM reconstruction.
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
int32_t GetAddress() const
void SetIndex(int32_t index)
void SetFile(int32_t file)
Task class creating and managing CbmMCDataArray objects.
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
virtual int32_t GetTotalNofHits() const
Bookkeeping of time-slice content.
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
const algo::RecoSetup & GetSetup() const
Setup accessor.
static RecoSetupManager * Instance()
Instance access.
const trd::RecoSetupUnit * GetTrd() const
Access to TRD reconstruction setup unit.
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.