26#include "FairEventHeader.h"
27#include "FairMCPoint.h"
28#include "FairRunAna.h"
29#include "FairRunSim.h"
30#include "FairTrackParam.h"
32#include "TClonesArray.h"
37#include "TMCProcess.h"
53 : FairTask(
"CbmRichRecoTbQa")
59 , fRichPoints(nullptr)
64 , fRichRingMatches(nullptr)
73 cout <<
"CbmRichRecoTbQa::Init" << endl;
74 FairRootManager* ioman = FairRootManager::Instance();
75 if (
nullptr == ioman) {
76 LOG(fatal) << GetName() <<
"::Init: RootManager not instantised!";
80 if (mcManager ==
nullptr) {
81 LOG(fatal) << GetName() <<
"::Init: No MCDataManager!";
91 fRichHits = (TClonesArray*) ioman->GetObject(
"RichHit");
93 LOG(fatal) << GetName() <<
"::Init: No Rich hits!";
96 fRichRings = (TClonesArray*) ioman->GetObject(
"RichRing");
98 LOG(fatal) << GetName() <<
"::Init: No Rich rings!";
103 LOG(fatal) << GetName() <<
"::Init: No RichRingMatch!";
108 LOG(fatal) << GetName() <<
"::Init: No MCEventList!";
120 Int_t nBinsLog = 20000;
121 Double_t minLog = 0.;
122 Double_t maxLog = 10000.;
125 fHM->
Create1<TH1D>(
"fhNofRichDigisPerTS",
"fhNofRichDigisPerTS;RICH digis per time slice;Yield", 100, -1, -1.);
126 fHM->
Create1<TH1D>(
"fhNofRichHitsPerTS",
"fhNofRichHitsPerTS;RICH hits per time slice;Yield", 100, -1., -1.);
127 fHM->
Create1<TH1D>(
"fhNofRichRingsPerTS",
"fhNofRichRingsPerTS;RICH rings per time slice;Yield", 100, -1., -1.);
129 fHM->
Create1<TH1D>(
"fhRichDigiTimeLog",
"fhRichDigiTimeLog;RICH digi time [ns];Yield", nBinsLog, minLog, maxLog);
131 fHM->
Create1<TH1D>(
"fhRichRingTimeLog",
"fhRichRingTimeLog;RICH ring time [ns];Yield", nBinsLog, minLog, maxLog);
133 fHM->
Create1<TH1D>(
"fhRichPointTime",
"fhRichPointTime;RICH MC point time [ns];Yield", 100, 0., 100.);
134 fHM->
Create1<TH1D>(
"fhRichPointTimeChPhoton",
"fhRichPointTimeChPhoton;RICH MC point time [ns];Yield", 100, 0., 100.);
135 fHM->
Create1<TH1D>(
"fhRichPointTimeNotChPhoton",
"fhRichPointTimeNotChPhoton;RICH MC point time [ns];Yield", 100, 0.,
137 fHM->
Create1<TH1D>(
"fhRichPointTimePrimEl",
"fhRichPointTimePrimEl;RICH MC point time [ns];Yield", 100, 0., 100.);
138 fHM->
Create1<TH1D>(
"fhRichPointTimeSecEl",
"fhRichPointTimeSecEl;RICH MC point time [ns];Yield", 100, 0., 100.);
139 fHM->
Create1<TH1D>(
"fhRichPointTimeOther",
"fhRichPointTimeOther;RICH MC point time [ns];Yield", 100, 0., 100.);
140 fHM->
Create1<TH1D>(
"fhRichPointTimePion",
"fhRichPointTimePion;RICH MC point time [ns];Yield", 100, 0., 100.);
142 fHM->
Create1<TH1D>(
"fhStsPointTime",
"fhStsPointTime;STS MC point time [ns];Yield", 400, 0., 400.);
146 string richDigiStr =
"fhRichDigiTimeLog_" + to_string(iEv);
147 fHM->
Create1<TH1D>(richDigiStr, richDigiStr +
";Time [ns];Yield", nBinsLog, minLog, maxLog);
149 string richRingStr =
"fhRichRingTimeLog_" + to_string(iEv);
150 fHM->
Create1<TH1D>(richRingStr, richRingStr +
";Time [ns];Yield", nBinsLog, minLog, maxLog);
152 string richStr =
"fhRichPointTimeLog_" + to_string(iEv);
153 fHM->
Create1<TH1D>(richStr, richStr +
";Time [ns];Yield", nBinsLog, minLog, maxLog);
155 string stsStr =
"fhStsPointTimeLog_" + to_string(iEv);
156 fHM->
Create1<TH1D>(stsStr, stsStr +
";Time [ns];Yield", nBinsLog, minLog, maxLog);
159 fHM->
Create1<TH1D>(
"fhTimeBetweenEvents",
"fhTimeBetweenEvents;Time between events [ns];Yield", 100, 0., 500.);
163 fHM->
Create1<TH1D>(
"fhMomElAcc",
"fhMomElAcc;P [GeV/c];Yield", 10, 0., 10.);
164 fHM->
Create1<TH1D>(
"fhMomElRec",
"fhMomElRec;P [GeV/c];Yield", 10, 0., 10.);
165 fHM->
Create1<TH1D>(
"fhMomRefElAcc",
"fhMomRefElAcc;P [GeV/c];Yield", 10, 0., 10.);
166 fHM->
Create1<TH1D>(
"fhMomRefElRec",
"fhMomRefElRec;P [GeV/c];Yield", 10, 0., 10.);
169 fHM->
Create1<TH1D>(
"fhNofHitsElAcc",
"fhNofHitsElAcc;Nof hits in ring;Yield", 20, -.5, 39.5);
170 fHM->
Create1<TH1D>(
"fhNofHitsElRec",
"fhNofHitsElRec;Nof hits in ring;Yield", 20, -.5, 39.5);
171 fHM->
Create1<TH1D>(
"fhNofHitsRefElAcc",
"fhNofHitsRefElAcc;Nof hits in ring;Yield", 20, -.5, 39.5);
172 fHM->
Create1<TH1D>(
"fhNofHitsRefElRec",
"fhNofHitsRefElRec;Nof hits in ring;Yield", 20, -.5, 39.5);
174 fHM->
Create1<TH1D>(
"fhEventMultElAcc",
"fhEventMultElAcc;Nof MC tracks;Yield", 10, 0., 2000);
175 fHM->
Create1<TH1D>(
"fhEventMultElRec",
"fhEventMultElRec;Nof MC tracks;Yield", 10, 0, 2000);
183 cout <<
"CbmRichRecoTbQa, time slice:" <<
fTimeSliceNum <<
" nofMcEvents:" << nofMcEvents << endl;
193 Int_t nofRichHits =
fRichHits->GetEntriesFast();
194 Int_t nofRichRings =
fRichRings->GetEntriesFast();
195 fHM->
H1(
"fhNofRichDigisPerTS")->Fill(nofRichDigis);
196 fHM->
H1(
"fhNofRichHitsPerTS")->Fill(nofRichHits);
197 fHM->
H1(
"fhNofRichRingsPerTS")->Fill(nofRichRings);
199 LOG(debug) <<
"nofRichDigis:" << nofRichDigis;
200 for (Int_t iDigi = 0; iDigi < nofRichDigis; iDigi++) {
205 Int_t eventNum = digiMatch->GetMatchedLink().GetEntry();
206 Int_t index = digiMatch->GetMatchedLink().GetIndex();
208 if (eventNum < 0 || index < 0) {
213 string hName =
"fhRichDigiTimeLog_" + to_string(eventNum);
219 for (Int_t iR = 0; iR < nofRichRings; iR++) {
222 if (ring ==
nullptr || ringMatch ==
nullptr)
continue;
229 if (eventNum < 0 || index < 0) {
234 string hName =
"fhRichRingTimeLog_" + to_string(eventNum);
249 fHM->
H1(
"fhTimeBetweenEvents")->Fill(dT);
254 for (Int_t iP = 0; iP < nofRichPoints; iP++) {
256 fHM->
H1(
"fhRichPointTime")->Fill(point->GetTime());
258 fHM->
H1(
"fhRichPointTimeChPhoton")->Fill(point->GetTime());
261 fHM->
H1(
"fhRichPointTimeNotChPhoton")->Fill(point->GetTime());
265 fHM->
H1(
"fhRichPointTimePrimEl")->Fill(point->GetTime());
268 fHM->
H1(
"fhRichPointTimePion")->Fill(point->GetTime());
271 fHM->
H1(
"fhRichPointTimeSecEl")->Fill(point->GetTime());
274 fHM->
H1(
"fhRichPointTimeOther")->Fill(point->GetTime());
278 string richStr =
"fhRichPointTimeLog_" + to_string(iEv);
280 fHM->
H1(richStr)->Fill(eventTime + point->GetTime());
288 for (Int_t j = 0; j < nofStsPoints; j++) {
290 fHM->
H1(
"fhStsPointTime")->Fill(point->GetTime());
292 string stsStr =
"fhStsPointTimeLog_" + to_string(iEv);
294 fHM->
H1(stsStr)->Fill(eventTime + point->GetTime());
305 for (Int_t j = 0; j < nofMcTracks; j++) {
314 map<CbmLink, Int_t> nofHitsInRing;
315 Int_t nofRichHits =
fRichHits->GetEntriesFast();
316 for (Int_t iHit = 0; iHit < nofRichHits; iHit++) {
318 if (
nullptr == hit)
continue;
320 for (
const auto& motherId : motherIds) {
321 nofHitsInRing[motherId]++;
326 for (Int_t iEv = 0;
fMCTracks->
Size(fileId, iEv) >= 0; iEv++) {
329 for (Int_t j = 0; j < nofMcTracks; j++) {
330 CbmLink val(1., j, iEv, fileId);
332 Int_t nofRichHitsInRing = nofHitsInRing[val];
333 Double_t mom = track->
GetP();
335 fHM->
H1(
"fhMomElAcc")->Fill(mom);
336 fHM->
H1(
"fhNofHitsElAcc")->Fill(nofRichHitsInRing);
337 fHM->
H1(
"fhEventMultElAcc")->Fill(nofPrimMcTracks);
338 if (nofRichHitsInRing >= 15) {
339 fHM->
H1(
"fhMomRefElAcc")->Fill(mom);
340 fHM->
H1(
"fhNofHitsRefElAcc")->Fill(nofRichHitsInRing);
346 Int_t nofRings =
fRichRings->GetEntriesFast();
347 for (Int_t iRing = 0; iRing < nofRings; iRing++) {
355 Int_t nofRichHitsInRing = nofHitsInRing[val];
356 Double_t mom = track->
GetP();
359 fHM->
H1(
"fhMomElRec")->Fill(mom);
360 fHM->
H1(
"fhNofHitsElRec")->Fill(nofRichHitsInRing);
361 fHM->
H1(
"fhEventMultElRec")->Fill(nofPrimMcTracks);
363 if (nofRichHitsInRing >= 15) {
364 fHM->
H1(
"fhMomRefElRec")->Fill(mom);
365 fHM->
H1(
"fhNofHitsRefElRec")->Fill(nofRichHitsInRing);
374 if (point ==
nullptr)
return false;
375 Int_t trackId = point->GetTrackID();
376 if (trackId < 0)
return false;
378 return (p !=
nullptr && TMath::Abs(p->
GetPdgCode()) == 50000050);
383 if (point ==
nullptr)
return false;
384 Int_t trackId = point->GetTrackID();
385 if (trackId < 0)
return false;
387 if (mcTrack ==
nullptr || TMath::Abs(mcTrack->
GetPdgCode()) != 50000050)
return false;
390 if (motherId < 0)
return false;
397 if (point ==
nullptr)
return false;
398 Int_t trackId = point->GetTrackID();
399 if (trackId < 0)
return false;
401 if (mcTrack ==
nullptr || TMath::Abs(mcTrack->
GetPdgCode()) != 50000050)
return false;
404 if (motherId < 0)
return false;
406 if (mcMotherTrack ==
nullptr)
return false;
407 int pdg = TMath::Abs(mcMotherTrack->
GetPdgCode());
415 if (mctrack ==
nullptr)
return false;
423 if (mctrack ==
nullptr)
return false;
425 if (pdg == 211)
return true;
431 if (point ==
nullptr)
return false;
432 Int_t trackId = point->GetTrackID();
433 if (trackId < 0)
return false;
435 if (mcTrack ==
nullptr || TMath::Abs(mcTrack->
GetPdgCode()) != 50000050)
return false;
438 if (motherId < 0)
return false;
449 fHM->
CreateCanvas(
"rich_tb_fhTimeBetweenEvents",
"rich_tb_fhTimeBetweenEvents", 800, 800);
453 Double_t partIntegral =
454 fHM->
H1(
"fhTimeBetweenEvents")
455 ->Integral(
fHM->
H1(
"fhTimeBetweenEvents")->FindBin(min),
fHM->
H1(
"fhTimeBetweenEvents")->FindBin(max));
456 Double_t allIntegral =
fHM->
H1(
"fhTimeBetweenEvents")->Integral();
457 Double_t ratio = 100. * partIntegral / allIntegral;
458 cout << ratio <<
"% of all time between events are in range (" << min <<
" ," << max <<
") ns" << endl;
463 fHM->
CreateCanvas(
"rich_tb_fhRichPointTime",
"rich_tb_fhRichPointTime", 800, 800);
468 TCanvas* c =
fHM->
CreateCanvas(
"rich_tb_fhRichPointTimeSources",
"rich_tb_fhRichPointTimeSources", 1600, 800);
471 DrawH1({
fHM->
H1(
"fhRichPointTimeChPhoton"),
fHM->
H1(
"fhRichPointTimeNotChPhoton")},
472 {
"Ch. Photons",
"Not Ch. Photons"},
kLinear,
kLog);
475 DrawH1({
fHM->
H1(
"fhRichPointTimeSecEl"),
fHM->
H1(
"fhRichPointTimePrimEl"),
fHM->
H1(
"fhRichPointTimePion"),
476 fHM->
H1(
"fhRichPointTimeOther")},
477 {
"e^{#pm}_{sec}",
"e^{#pm}_{prim}",
"#pi^{#pm}",
"Other"},
kLinear,
kLog);
482 fHM->
CreateCanvas(
"rich_tb_fhStsPointTime",
"rich_tb_fhStsPointTime", 800, 800);
487 fHM->
CreateCanvas(
"rich_tb_fhRichPointTimeLog",
"rich_tb_fhRichPointTimeLog", 1600, 600);
492 fHM->
CreateCanvas(
"rich_tb_fhStsPointTimeLog",
"rich_tb_fhStsPointTimeLog", 1600, 600);
497 fHM->
CreateCanvas(
"rich_tb_reco_fhRichDigiTimeLogAll",
"rich_tb_reco_fhRichDigiTimeLogAll", 1600, 600);
499 gPad->SetLeftMargin(0.07);
500 gPad->SetRightMargin(0.05);
504 fHM->
CreateCanvas(
"rich_tb_reco_fhRichDigiTimeLog",
"rich_tb_reco_fhRichDigiTimeLog", 1600, 600);
509 fHM->
CreateCanvas(
"rich_tb_reco_fhRichRingTimeLogAll",
"rich_tb_reco_fhRichRingTimeLogAll", 1600, 600);
511 gPad->SetLeftMargin(0.07);
512 gPad->SetRightMargin(0.05);
516 fHM->
CreateCanvas(
"rich_tb_reco_timelog_hits_rings",
"rich_tb_reco_timelog_hits_rings", 1600, 600);
517 DrawH1({
fHM->
H1(
"fhRichDigiTimeLog"),
fHM->
H1(
"fhRichRingTimeLog")}, {
"Hits",
"Rings"});
518 gPad->SetLeftMargin(0.07);
519 gPad->SetRightMargin(0.05);
523 fHM->
CreateCanvas(
"rich_tb_reco_fhRichRingTimeLog",
"rich_tb_reco_fhRichRingTimeLog", 1600, 600);
529 fHM->
CreateCanvas(
"rich_tb_reco_fhRichObectsPerTimeSlice",
"rich_tb_reco_fhRichObectsPerTimeSlice", 1500, 500);
540 TCanvas* c =
fHM->
CreateCanvas(
"rich_tb_reco_acc_rec",
"rich_tb_reco_acc_rec", 1600, 600);
543 Int_t nofAccMom =
fHM->
H1(
"fhMomElAcc")->GetEntries();
544 Int_t nofRecMom =
fHM->
H1(
"fhMomElRec")->GetEntries();
545 Int_t nofRefAccMom =
fHM->
H1(
"fhMomRefElAcc")->GetEntries();
546 Int_t nofRefRecMom =
fHM->
H1(
"fhMomRefElRec")->GetEntries();
547 Double_t effMom = 100. * (Double_t) nofRecMom / (Double_t) nofAccMom;
548 Double_t effRefMom = 100. * (Double_t) nofRefRecMom / (Double_t) nofRefAccMom;
550 {
"Acc (" + to_string(nofAccMom) +
")",
"Rec (" + to_string(nofRecMom) +
")"});
552 Int_t nofAccNofHits =
fHM->
H1(
"fhNofHitsElAcc")->GetEntries();
553 Int_t nofRecNofHits =
fHM->
H1(
"fhNofHitsElRec")->GetEntries();
554 Int_t nofRefAccNofHits =
fHM->
H1(
"fhNofHitsRefElAcc")->GetEntries();
555 Int_t nofRefRecNofHits =
fHM->
H1(
"fhNofHitsRefElRec")->GetEntries();
556 Double_t effNofHits = 100. * (Double_t) nofRecNofHits / (Double_t) nofAccNofHits;
557 Double_t effRefNofHits = 100. * (Double_t) nofRefRecNofHits / (Double_t) nofRefAccNofHits;
559 {
"Acc (" + to_string(nofAccNofHits) +
")",
"Rec" + to_string(nofRecNofHits) +
")"});
561 fHM->
CreateCanvas(
"rich_tb_reco_eff_mom",
"rich_tb_reco_eff_mom", 800, 800);
564 DrawH1({hEffMom, hRefEffMom},
568 hEffMom->SetMinimum(0.);
569 hEffMom->SetMaximum(105.);
571 fHM->
CreateCanvas(
"rich_tb_reco_eff_nofHits",
"rich_tb_reco_eff_nofHits", 800, 800);
574 DrawH1({hEffHits, hRefEffHits},
578 hEffHits->SetMinimum(0.);
579 hEffHits->SetMaximum(105.);
581 fHM->
CreateCanvas(
"rich_tb_reco_eff_eventMult",
"rich_tb_reco_eff_eventMult", 800, 800);
585 hEffHits->SetMinimum(0.);
586 hEffHits->SetMaximum(105.);
592 Double_t max = std::numeric_limits<Double_t>::min();
593 Int_t startInd = (withNoise) ? -1 : 0;
594 for (
int iEv = startInd; iEv < nofLogEvents; iEv++) {
595 string hName = hMainName +
"_" + to_string(iEv);
596 string option = ((iEv == 0 && !withNoise) || (iEv == -1 && withNoise)) ?
"" :
"same";
598 int color = (ind == 0) ? kBlue
599 : (ind == 1) ? kRed + 1
600 : (ind == 2) ? kGreen + 3
601 : (ind == 3) ? kMagenta + 2
602 : (ind == 4) ? kYellow + 2
604 if (ind == -1) color = kAzure + 6;
605 max = std::max(max,
fHM->
H1(hName)->GetMaximum());
608 fHM->
H1(hMainName +
"_" + to_string(startInd))->SetMaximum(max * 1.10);
609 gPad->SetLeftMargin(0.07);
610 gPad->SetRightMargin(0.05);
618 TDirectory* oldir = gDirectory;
619 TFile* outFile = FairRootManager::Instance()->GetOutFile();
620 if (outFile != NULL) {
621 outFile->mkdir(GetName());
622 outFile->cd(GetName());
629 gDirectory->cd(oldir->GetPath());
ClassImp(CbmConverterManager)
@ kRich
Ring-Imaging Cherenkov Detector.
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)
Helper functions for drawing 1D and 2D histograms and graphs.
FairTask for matching RECO data to MC.
CbmDigiManager * fDigiMan
static Int_t GetNofDigis(ECbmModuleId systemId)
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
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.
void WriteToFile()
Write all objects to current opened file.
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...
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)
Task class creating and managing CbmMCDataArray objects.
CbmMCDataObject * GetObject(const char *name)
CbmMCDataArray * InitBranch(const char *name)
Container class for MC events with number, file and start time.
std::size_t GetNofEvents() const
Number of events in the list @value Number of events.
double GetEventTime(uint32_t event, uint32_t file)
Event start time.
uint32_t GetGeantProcessId() const
int32_t GetMotherId() 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.
const CbmLink & GetMatchedLink() const
Bool_t IsCherenkovPhotonFromPrimaryElectron(const CbmRichPoint *point, Int_t fileId, Int_t eventId)
void RingRecoEfficiency()
Bool_t IsMcPrimaryElectron(const CbmMCTrack *mctrack)
TClonesArray * fRichRings
TClonesArray * fRichRingMatches
CbmMCDataArray * fStsPoints
void InitHistograms()
Initialize histograms.
virtual InitStatus Init()
Inherited from FairTask.
CbmMCDataArray * fRichPoints
void DrawTimeLog(const string &hMainName, Int_t nofLogEvents, bool withNoise=false)
Int_t GetNofPrimaryMcTracks(Int_t iEv)
Bool_t IsCherenkovPhoton(const CbmRichPoint *point, Int_t fileId, Int_t eventId)
CbmRichRecoTbQa()
Standard constructor.
virtual void Exec(Option_t *option)
Inherited from FairTask.
Bool_t IsCherenkovPhotonFromPion(const CbmRichPoint *point, Int_t fileId, Int_t eventId)
CbmDigiManager * fDigiMan
CbmMCDataArray * fMCTracks
vector< CbmLink > fRecRings
Bool_t IsCherenkovPhotonFromSecondaryElectron(const CbmRichPoint *point, Int_t fileId, Int_t eventId)
CbmMCEventList * fEventList
Bool_t IsMcPion(const CbmMCTrack *mctrack)
virtual void Finish()
Inherited from FairTask.
double GetTrueOverAllHitsRatio() const
TH1D * DivideH1(TH1 *h1, TH1 *h2, const string &histName, double scale, const string &titleYaxis)
std::string NumberToString(const T &value, int precision=1)