23#include "FairMCPoint.h"
24#include "FairTrackParam.h"
26#include "TClonesArray.h"
31#include "TMCProcess.h"
91 vector<string> matchTypes{
"Primel",
"Pi",
"PrimelPlus",
"PrimelMinus"};
92 for (
const string& t : matchTypes) {
93 fHM->
Create2<TH2D>(
"fhRTDistVsMomTruematch" + t,
94 "fhRTDistVsMomTruematch" + t +
";P [GeV/c];Ring-track distance [cm];Yield", 20, 0., 10., 100, 0.,
96 fHM->
Create2<TH2D>(
"fhRTDistVsMomWrongmatch" + t,
97 "fhRTDistVsMomWrongmatch" + t +
";P [GeV/c];Ring-track distance [cm];Yield", 20, 0., 10., 100,
100 fHM->
Create2<TH2D>(
"fhRTDistVsNofHitsTruematch" + t,
101 "fhRTDistVsNofHitsTruematch" + t +
";# hits/ring;Ring-track distance [cm];Yield", 40, -.5, 39.5,
103 fHM->
Create3<TH3D>(
"fhRTDistVsXYTruematch" + t,
104 "fhRTDistVsXYTruematch" + t +
";X [cm];Y [cm];Ring-track distance [cm]", nBinsX, xMin, xMax,
105 nBinsY, yMin, yMax, 100, 0., 5.);
106 fHM->
Create2<TH2D>(
"fhRTDistVsXTruematch" + t,
"fhRTDistVsXTruematch" + t +
";X [cm];Ring-track distance [cm]",
107 nBinsX1, xMin1, xMax1, 100, 0., 5.);
108 fHM->
Create2<TH2D>(
"fhRTDistVsYTruematch" + t,
"fhRTDistVsYTruematch" + t +
";Abs(Y) [cm];Ring-track distance [cm]",
109 nBinsY1, yMin1, yMax1, 100, 0., 5.);
113 fHM->
Create2<TH2D>(
"fhRTDistVsMomTruematchElId",
114 "fhRTDistVsMomTruematchElId;P [GeV/c];Ring-track distance [cm];Yield", 20, 0., 10., 100, 0., 5.);
116 fHM->
Create1<TH1D>(
"fhMismatchSrc",
"fhMismatchSrc;Global track category;% from MC", 13, -0.5, 12.5);
118 vector<string> mismatchTypes{
119 "Mc",
"Sts",
"StsAccRich",
"StsRich",
"StsRichTrue",
"StsNoRich",
"StsNoRichRF",
120 "StsNoRichRM",
"StsNoRichNoRF",
"StsNoRichNoProj",
"StsRichWrong",
"StsRichWrongRF",
"StsRichWrongRM"};
121 for (
const string& t : mismatchTypes) {
122 fHM->
Create1<TH1D>(
"fhMismatchSrcMom" + t,
"fhMismatchSrcMom" + t +
";P [GeV/c];Yield", 40, 0., 10.);
129 LOG(info) <<
"CbmRichRecoQa, event No. " <<
fEventNum;
138 int nofRichHits =
fRichHits->GetEntriesFast();
139 for (
int iHit = 0; iHit < nofRichHits; iHit++) {
141 if (
nullptr == hit)
continue;
144 for (
const auto& motherId : motherIds) {
154 for (
int iE = 0; iE < nofEvents; iE++) {
159 for (
int i = 0; i < nMcTracks; i++) {
161 CbmLink val(1., i, eventId, fileId);
165 fHM->
H1(
"fhMismatchSrc")->Fill(0);
166 fHM->
H1(
"fhMismatchSrcMomMc")->Fill(mcTrack->
GetP());
172 for (
int iTrack = 0; iTrack < nofGlobalTracks; iTrack++) {
176 if (stsId < 0)
continue;
178 if (stsTrackMatch ==
nullptr || stsTrackMatch->
GetNofLinks() < 1)
continue;
182 double mom = mcTrack->
GetP();
184 fHM->
H1(
"fhMismatchSrc")->Fill(1);
185 fHM->
H1(
"fhMismatchSrcMomSts")->Fill(mom);
189 fHM->
H1(
"fhMismatchSrc")->Fill(2);
190 fHM->
H1(
"fhMismatchSrcMomStsAccRich")->Fill(mcTrack->
GetP());
196 fHM->
H1(
"fhMismatchSrc")->Fill(5);
197 fHM->
H1(
"fhMismatchSrcMomStsNoRich")->Fill(mom);
202 fHM->
H1(
"fhMismatchSrc")->Fill(6);
203 fHM->
H1(
"fhMismatchSrcMomStsNoRichRF")->Fill(mom);
206 fHM->
H1(
"fhMismatchSrc")->Fill(8);
207 fHM->
H1(
"fhMismatchSrcMomStsNoRichNoRF")->Fill(mom);
211 fHM->
H1(
"fhMismatchSrc")->Fill(7);
212 fHM->
H1(
"fhMismatchSrcMomStsNoRichRM")->Fill(mom);
216 fHM->
H1(
"fhMismatchSrc")->Fill(9);
217 fHM->
H1(
"fhMismatchSrcMomStsNoRichNoProj")->Fill(mom);
223 fHM->
H1(
"fhMismatchSrc")->Fill(3);
224 fHM->
H1(
"fhMismatchSrcMomStsRich")->Fill(mom);
226 if (richRingMatch ==
nullptr || richRingMatch->
GetNofLinks() < 1)
continue;
229 if (
nullptr == ring)
continue;
231 if (stsMatchedLink == richMcTrackLink) {
232 fHM->
H1(
"fhMismatchSrc")->Fill(4);
233 fHM->
H1(
"fhMismatchSrcMomStsRichTrue")->Fill(mom);
236 fHM->
H1(
"fhMismatchSrc")->Fill(10);
237 fHM->
H1(
"fhMismatchSrcMomStsRichWrong")->Fill(mom);
239 fHM->
H1(
"fhMismatchSrc")->Fill(11);
240 fHM->
H1(
"fhMismatchSrcMomStsRichWrongRF")->Fill(mom);
244 fHM->
H1(
"fhMismatchSrc")->Fill(12);
245 fHM->
H1(
"fhMismatchSrcMomStsRichWrongRM")->Fill(mom);
255 for (
int iR = 0; iR < nofRings; iR++) {
257 if (ring ==
nullptr)
continue;
259 if (richRingMatch ==
nullptr || richRingMatch->
GetNofLinks() < 1)
continue;
261 if (richMcTrackLink == mcTrackLink)
return true;
269 for (
int iTrack = 0; iTrack < nofGlobalTracks; iTrack++) {
273 if (richId < 0)
continue;
275 if (richRingMatch ==
nullptr || richRingMatch->
GetNofLinks() < 1)
continue;
277 if (richMcTrackLink == mcTrackLink) {
288 if (stsTrackId < 0)
return false;
289 const FairTrackParam* pTrack =
static_cast<FairTrackParam*
>(
fRichProjections->At(stsTrackId));
290 if (pTrack ==
nullptr)
return false;
292 if (pTrack->GetX() == 0. && pTrack->GetY() == 0.)
return false;
300 for (
int iTrack = 0; iTrack < nofGlobalTracks; iTrack++) {
305 if (stsId < 0 || richId < 0)
continue;
308 if (stsTrackMatch ==
nullptr || stsTrackMatch->
GetNofLinks() < 1)
continue;
312 if (richRingMatch ==
nullptr || richRingMatch->
GetNofLinks() < 1)
continue;
315 if (
nullptr == ring)
continue;
323 if (mcTrack ==
nullptr)
continue;
324 double mom = mcTrack->
GetP();
330 if (!isEl && !isPi)
continue;
332 vector<string> matchTypes{
"Primel",
"Pi",
"PrimelPlus",
"PrimelMinus"};
333 for (
const string& t : matchTypes) {
336 if (t ==
"Primel" && isEl) isGood =
true;
337 if (t ==
"Pi" && isPi) isGood =
true;
338 if (t ==
"PrimelPlus" && isEl && charge > 0) isGood =
true;
339 if (t ==
"PrimelMinus" && isEl && charge < 0) isGood =
true;
340 if (!isGood)
continue;
341 if (stsMcMatchedLink == richMcTrackLink) {
342 fHM->
H2(
"fhRTDistVsMomTruematch" + t)->Fill(mom, rtDistance);
343 fHM->
H3(
"fhRTDistVsXYTruematch" + t)->Fill(xc, yc, rtDistance);
344 fHM->
H2(
"fhRTDistVsXTruematch" + t)->Fill(xc, rtDistance);
345 fHM->
H2(
"fhRTDistVsYTruematch" + t)->Fill(abs(yc), rtDistance);
346 fHM->
H2(
"fhRTDistVsNofHitsTruematch" + t)->Fill(nofHits, rtDistance);
348 if (t ==
"Primel" && isEl) {
350 fHM->
H2(
"fhRTDistVsMomTruematchElId")->Fill(mom, rtDistance);
355 fHM->
H2(
"fhRTDistVsMomWrongmatch" + t)->Fill(mom, rtDistance);
363 gStyle->SetPaintTextFormat(
"4.1f");
364 fHM->
CreateCanvas(
"richqa_mismatch_src",
"richqa_mismatch_src", 1000, 800);
365 double nofMcEl =
fHM->
H1(
"fhMismatchSrc")->GetBinContent(1);
366 fHM->
Scale(
"fhMismatchSrc", 100. / nofMcEl);
368 fHM->
H1(
"fhMismatchSrc")->SetMarkerSize(1.9);
370 vector<string> labels{
"MC",
382 "STS-RICH wrong RM"};
384 for (
size_t i = 0; i < labels.size(); i++) {
385 fHM->
H1(
"fhMismatchSrc")->GetXaxis()->SetBinLabel(i + 1, labels[i].c_str());
387 fHM->
H1(
"fhMismatchSrc")->GetXaxis()->SetLabelSize(0.03);
395 fHM->
CreateCanvas(
"richqa_RTDist_truematch_epem",
"richqa_RTDist_truematch_epem", 1000, 1000);
396 TH1D* py_minus = (TH1D*) (
fHM->
H2(
"fhRTDistVsMomTruematchPrimelMinus")
397 ->ProjectionY(
"fhRTDistVsMomTruematchPrimelMinus_py")
399 py_minus->Scale(1. / py_minus->Integral());
400 TH1D* py_plus = (TH1D*) (
fHM->
H2(
"fhRTDistVsMomTruematchPrimelPlus")
401 ->ProjectionY(
"fhRTDistVsMomTruematchPrimelPlus_py")
403 py_plus->Scale(1. / py_plus->Integral());
404 DrawH1({py_minus, py_plus},
407 kLinear,
kLog,
true, 0.5, 0.85, 0.99, 0.99,
"hist");
411 fHM->
CreateCanvas(
"richqa_RTDist_truematch_elpi",
"richqa_RTDist_truematch_elpi", 800, 800);
413 (TH1D*) (
fHM->
H2(
"fhRTDistVsMomTruematchPrimel")->ProjectionY(
"fhRTDistVsMomTruematchPrimel_py")->Clone());
414 py_el->Scale(1. / py_el->Integral());
415 TH1D* py_pi = (TH1D*) (
fHM->
H2(
"fhRTDistVsMomTruematchPi")->ProjectionY(
"fhRTDistVsMomTruematchPi_py")->Clone());
416 py_pi->Scale(1. / py_pi->Integral());
420 kLinear,
kLog,
true, 0.5, 0.85, 0.99, 0.99,
"hist");
424 fHM->
CreateCanvas(
"richqa_mismatch_src_mom",
"richqa_mismatch_src_mom", 1000, 800);
425 vector<string> labels{
"MC",
437 "STS-RICH wrong RM"};
439 {
"fhMismatchSrcMomMc",
"fhMismatchSrcMomSts",
"fhMismatchSrcMomStsAccRich",
"fhMismatchSrcMomStsRich",
440 "fhMismatchSrcMomStsRichTrue",
"fhMismatchSrcMomStsNoRich",
"fhMismatchSrcMomStsNoRichRF",
441 "fhMismatchSrcMomStsNoRichRM",
"fhMismatchSrcMomStsNoRichNoRF",
"fhMismatchSrcMomStsNoRichNoProj",
442 "fhMismatchSrcMomStsRichWrong",
"fhMismatchSrcMomStsRichWrongRF",
"fhMismatchSrcMomStsRichWrongRM"});
445 fHM->
H1(
"fhMismatchSrcMomMc")->SetMinimum(0.9);
455 TCanvas* c =
fHM->
CreateCanvas(
"richqa_RTDist_truematch_elid",
"richqa_RTDist_truematch_elid", 1800, 600);
462 TH1D* py = (TH1D*) (
fHM->
H2(
"fhRTDistVsMomTruematchPrimel")
463 ->ProjectionY(
string(
"fhRTDistVsMomTruematchPrimel_py2").c_str())
465 TH1D* pyElId = (TH1D*) (
fHM->
H2(
"fhRTDistVsMomTruematchElId")
466 ->ProjectionY(
string(
"fhRTDistVsMomTruematchElId_py").c_str())
472 fHM->
H2(
"fhRTDistVsMomTruematchPrimel")->GetYaxis()->SetRangeUser(0., 2.);
473 fHM->
H2(
"fhRTDistVsMomTruematchElId")->GetYaxis()->SetRangeUser(0., 2.);
480 double overflow =
h->GetBinContent(
h->GetNbinsX() + 1);
493 TCanvas* c =
fHM->
CreateCanvas(
"richqa_RTDist_truematch_" + opt,
"richqa_RTDist_truematch_" + opt, 1800, 600);
500 TH1D* py = (TH1D*) (
fHM->
H2(
"fhRTDistVsMomTruematch" + opt)
501 ->ProjectionY((
"fhRTDistVsMomTruematch_py" + opt).c_str())
507 fHM->
H2(
"fhRTDistVsMomTruematch" + opt)->GetYaxis()->SetRangeUser(0., 2.);
508 fHM->
H2(
"fhRTDistVsNofHitsTruematch" + opt)->GetYaxis()->SetRangeUser(0., 2.);
512 fHM->
CreateCanvas(
"richqa_RTDist_wrongmatch" + opt,
"richqa_RTDist_wrongmatch" + opt, 600, 600);
513 TH1D* py = (TH1D*) (
fHM->
H2(
"fhRTDistVsMomWrongmatch" + opt)
514 ->ProjectionY((
"fhRTDistVsMomWrongmatch_py" + opt).c_str())
522 TCanvas* c =
fHM->
CreateCanvas(
"richqa_RTDist_xy_truematch" + opt,
"richqa_RTDist_xy_truematch" + opt, 1800, 600);
528 fHM->
H2(
"fhRTDistVsXTruematch" + opt)->GetYaxis()->SetRangeUser(0., 2.);
531 fHM->
H2(
"fhRTDistVsYTruematch" + opt)->GetYaxis()->SetRangeUser(0., 2.);
537 if (mctrack ==
nullptr)
return false;
544 if (mctrack ==
nullptr || std::abs(mctrack->
GetPdgCode()) != 211)
return false;
552 TDirectory* oldir = gDirectory;
553 TFile* outFile = FairRootManager::Instance()->GetOutFile();
554 if (outFile !=
nullptr) {
555 outFile->mkdir(GetName());
556 outFile->cd(GetName());
563 gDirectory->cd(oldir->GetPath());
571 TFile* oldFile = gFile;
572 TDirectory* oldDir = gDirectory;
574 if (
fHM !=
nullptr)
delete fHM;
577 TFile* file =
new TFile(fileName.c_str());
ClassImp(CbmConverterManager)
void DrawH2WithProfile(TH2 *hist, Bool_t doGaussFit, Bool_t drawOnlyMean, const string &drawOpt2D, Int_t profileColor, Int_t profileLineWidth)
void DrawTextOnPad(const string &text, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
void SetDefaultDrawStyle()
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
TH2D * DrawH3Profile(TH3 *h, Bool_t drawMean, Bool_t doGaussFit, Double_t zMin, Double_t zMax)
Helper functions for drawing 1D and 2D histograms and graphs.
FairTask for matching RECO data to MC.
Generates beam ions for transport simulation.
InitStatus Init()
Initialisation.
static CbmDigiManager * Instance()
Static instance.
int32_t GetStsTrackIndex() const
int32_t GetRichRingIndex() const
TCanvas * CreateCanvas(const std::string &name, const std::string &title, Int_t width, Int_t height)
Create and draw TCanvas and store pointer to it.
void SaveCanvasToImage(const std::string &outputDir, const std::string &options="png,eps")
Save all stored canvases to images.
std::vector< TH1 * > H1Vector(const std::vector< std::string > &names) const
Return vector of pointers to TH1 histogram.
void Clear(Option_t *="")
Clear memory. Remove all histograms and canvases.
TH2 * H2(const std::string &name) const
Return pointer to TH2 histogram.
void Create2(const std::string &name, const std::string &title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY)
Helper function for creation of 2-dimensional histograms and profiles. Template argument is a real ob...
void ReadFromFile(TFile *file)
Read histograms from file.
void Scale(const std::string &histName, Double_t scale)
Scale histogram.
void WriteToFile()
Write all objects to current opened file.
TH3 * H3(const std::string &name) const
Return pointer to TH3 histogram.
void Create1(const std::string &name, const std::string &title, Int_t nofBins, Double_t minBin, Double_t maxBin)
Helper function for creation of 1-dimensional histograms and profiles. Template argument is a real ob...
void Create3(const std::string &name, const std::string &title, Int_t nofBinsX, Double_t minBinX, Double_t maxBinX, Int_t nofBinsY, Double_t minBinY, Double_t maxBinY, Int_t nofBinsZ, Double_t minBinZ, Double_t maxBinZ)
Helper function for creation of 3-dimensional histograms and profiles. Template argument is a real ob...
TH1 * H1(const std::string &name) const
Return pointer to TH1 histogram.
TObject * Get(const CbmLink *lnk)
Int_t Size(Int_t fileNumber, Int_t eventNumber)
int32_t GetFileIdByIndex(uint32_t index)
File number by index @value File number for event at given index in list.
int32_t GetEventIdByIndex(uint32_t index)
Event number by index @value Event number for event at given index in list.
std::size_t GetNofEvents() const
Number of events in the list @value Number of events.
double GetCharge() const
Charge of the associated particle.
uint32_t GetGeantProcessId() const
int32_t GetPdgCode() const
static std::vector< CbmLink > GetMcTrackMotherIdsForRichHit(CbmDigiManager *digiMan, const CbmRichHit *hit, CbmMCDataArray *richPoints, CbmMCDataArray *mcTracks)
Get CbmLinks of Mother MC Tracks for RICH hit.
int32_t GetNofLinks() const
const CbmLink & GetMatchedLink() const
TClonesArray * fRichProjections
void RingTrackMismatchSource()
Fill histograms related to study of the source of ring-track mismatch.
TClonesArray * fGlobalTracks
std::map< Int_t, Int_t > fNofHitsInRingMap
void DrawRingTrackDist(const std::string &opt)
Draw histograms related to ring-track distance for pions or electrons (+/-).
CbmMCDataArray * fMcTracks
void FillRingTrackDistance()
Fill histogramms related to ring track distance.
void InitHistograms()
Initialize histograms.
string GetMeanRmsOverflowString(TH1 *h, Bool_t withOverflow=true)
Return string with mean, RMS and overflow percent for input TH1.
void DrawMismatchSrc()
Draw MismatchSrc histogram and canvas.
static Bool_t IsMcPrimaryElectron(const CbmMCTrack *mctrack)
TClonesArray * fRichRings
virtual InitStatus Init()
Inherited from FairTask.
bool HasRichProjection(Int_t stsTrackId)
bool WasRingMatched(Int_t mcTrackId)
TClonesArray * fRichRingMatches
void DrawFromFile(const string &fileName, const string &outputDir)
Draw histogram from file.
TClonesArray * fStsTracks
CbmDigiManager * fDigiMan
TClonesArray * fStsTrackMatches
CbmMCEventList * fEventList
bool WasRingFound(Int_t mcTrackId)
static Bool_t IsMcPion(const CbmMCTrack *mctrack)
TClonesArray * fRichPoints
void DrawHist()
Draw histograms.
virtual void Exec(Option_t *option)
Inherited from FairTask.
CbmRichRecoQa()
Standard constructor.
virtual void Finish()
Inherited from FairTask.
void FillRichRingNofHits()
Fill map mcTrackId -> nof RICH hits.
int32_t GetNofHits() const
static double GetRingTrackDistance(int globalTrackId)
T * GetOrFatal(const std::string &objName, const std::string &description="")
CbmMCDataArray * InitOrFatalMc(const std::string &objName, const std::string &description)
std::string NumberToString(const T &value, int precision=1)