18#include <FairRootManager.h>
27 fManager = FairRootManager::Instance();
30 LOG(error) <<
"No FairRootManager found";
35 if (!
fMcManager) LOG(fatal) << GetName() <<
": No MCDataManager!";
41 LOG(fatal) << GetName()
42 <<
": No MCEventList.! Add digitization and reconstruction files in the macro. MCEventList comes in "
43 "digitzation or reconstruction.";
49 LOG(error) <<
"No MC tracks array found in CbmMCDataManager!";
55 LOG(error) <<
"No MC points array found in CbmMCDataManager!";
61 fLists[oi]->SetOwner(kTRUE);
74 TString name = Form(
"mc_tracks_per_event");
75 TString title = Form(
"MC tracks per event;# MC tracks;Counts");
79 const int nSpeciesBins = 18;
82 0.5, nSpeciesBins + 0.5);
84 nSpeciesBins, 0.5, nSpeciesBins + 0.5);
86 nSpeciesBins, 0.5, nSpeciesBins + 0.5);
88 auto labelSpecies = [](TH1*
h) {
89 auto* ax =
h->GetXaxis();
90 ax->SetBinLabel(1,
"#gamma");
91 ax->SetBinLabel(2,
"e^{-}");
92 ax->SetBinLabel(3,
"e^{+}");
93 ax->SetBinLabel(4,
"#mu^{-}");
94 ax->SetBinLabel(5,
"#mu^{+}");
95 ax->SetBinLabel(6,
"#pi^{+}");
96 ax->SetBinLabel(7,
"#pi^{-}");
97 ax->SetBinLabel(8,
"#pi^{0}");
98 ax->SetBinLabel(9,
"K^{+}");
99 ax->SetBinLabel(10,
"K^{-}");
100 ax->SetBinLabel(11,
"K^{0}_{S}");
101 ax->SetBinLabel(12,
"K^{0}_{L}");
102 ax->SetBinLabel(13,
"p");
103 ax->SetBinLabel(14,
"#bar{p}");
104 ax->SetBinLabel(15,
"n");
105 ax->SetBinLabel(16,
"#bar{n}");
106 ax->SetBinLabel(17,
"ions");
107 ax->SetBinLabel(18,
"other");
122 -50., 50., 400, -200., 200.);
125 -50., 50., 400, -200., 200.);
128 -50., 50., 400, -50., 50.);
134 TString namest = Form(
"h_mvd_nPointsEvt_station_%d", iSt);
135 TString titlest = Form(
"MVD points per event, station %d;N_{MVD points};Events", iSt);
144 TString nameP = Form(
"h_mvd_xy_prim_station_%d", iSt);
145 TString titleP = Form(
"MVD primary points X-Y, station %d;x [cm];y [cm]", iSt);
149 TString nameS = Form(
"h_mvd_xy_sec_station_%d", iSt);
150 TString titleS = Form(
"MVD secondary points X-Y, station %d;x [cm];y [cm]", iSt);
155 0.5, nSpeciesBins + 0.5);
158 nSpeciesBins, 0.5, nSpeciesBins + 0.5);
161 nSpeciesBins, 0.5, nSpeciesBins + 0.5);
169 MakeQaObject<TH1D>(
"h_mvd_p_prim",
"Momentum at MVD point (primaries);p [GeV/c];counts", 200, 0., 10.);
172 MakeQaObject<TH1D>(
"h_mvd_p_sec",
"Momentum at MVD point (secondaries);p [GeV/c];counts", 200, 0., 10.);
179 nSpeciesBins, 0.5, nSpeciesBins + 0.5, 200, 0., 500.);
186 MakeQaObject<TH1D>(
"h_nDeltaEvt",
"Secondary e^{#pm} with MVD hits per event;N tracks;Events", 1000, 0, 1000);
190 MakeQaObject<TH1D>(
"h_sec_count_bySpecies",
"Secondary tracks with MVD hits by species;Class;Counts", 9, 0.5, 9.5);
202 "h_dEkeV_vs_pidClass",
"#DeltaE per MVD point (keV) vs PID class (non-primaries with hits);PID class;#DeltaE [keV]",
203 9, 0.5, 9.5, nbin, 0.,
fKeVMax);
204 for (
int b = 1; b <= 9; ++b) {
205 const char* lbl =
nullptr;
207 case 1: lbl =
"#gamma";
break;
208 case 2: lbl =
"e^{#pm}";
break;
209 case 3: lbl =
"#mu^{#pm}";
break;
210 case 4: lbl =
"#pi^{#pm}";
break;
211 case 5: lbl =
"K^{#pm}";
break;
212 case 6: lbl =
"p/p#bar";
break;
213 case 7: lbl =
"n/n#bar";
break;
214 case 8: lbl =
"ions";
break;
215 default: lbl =
"other";
break;
224 MakeQaObject<TH2D>(
"h_dEkeV_vs_p",
"#DeltaE (keV) vs p at point (non-primaries);p [GeV/c];#DeltaE [keV]", 200, 0.,
233 for (
int iEv = 0; iEv < nMcEvents; iEv++) {
234 const auto fileId =
fMcEventList->GetFileIdByIndex(iEv);
235 const auto eventId =
fMcEventList->GetEventIdByIndex(iEv);
243 const int nMcTracks =
fMcTracks->Size(fileId, eventId);
249 for (
int iTrack = 0; iTrack < nMcTracks; iTrack++) {
251 if (!mcTrack)
continue;
256 const double p = mcTrack->GetP();
257 const double x0 = mcTrack->GetStartX();
258 const double y0 = mcTrack->GetStartY();
259 const double z0 = mcTrack->GetStartZ();
293 std::vector<int> nPointsStation(
fNStations, 0);
294 int nDeltaThisEvt = 0;
298 const int nMvdPoints =
fMvdPoints->Size(fileId, eventId);
299 const int nMcTracks =
fMcTracks->Size(fileId, eventId);
302 for (
int iPoint = 0; iPoint < nMvdPoints; iPoint++) {
304 if (!mvdPoint)
continue;
306 const auto* mcTrack =
static_cast<CbmMCTrack*
>(
fMcTracks->Get(fileId, eventId, mvdPoint->GetTrackID()));
307 if (!mcTrack)
continue;
310 const int trackId = mvdPoint->GetTrackID();
312 if (trackId < 0 || trackId >= nMcTracks) {
313 LOG(fatal) <<
"Mvd point " << iPoint <<
": trackId " << trackId <<
" doesn't belong to [0," << nMcTracks - 1
318 const int pdg =
fPdgBuf[trackId];
321 Int_t motherId = mcTrack->GetMotherId();
322 Int_t pdgCode = mcTrack->GetPdgCode();
324 mvdPoint->Position(vIn);
325 mvdPoint->PositionOut(vOut);
326 Double_t xMC = 0.5 * (vIn.X() + vOut.X());
327 Double_t yMC = 0.5 * (vIn.Y() + vOut.Y());
328 Double_t zMC = 0.5 * (vIn.Z() + vOut.Z());
333 if (stationId < 0 || stationId >=
fNStations)
continue;
342 nPointsStation[stationId]++;
367 const double px = mvdPoint->GetPx();
368 const double py = mvdPoint->GetPy();
369 const double pz = mvdPoint->GetPz();
370 const double mom = std::sqrt(px * px + py * py + pz * pz);
374 if (std::abs(pdgCode) == 11) ++nDeltaThisEvt;
398 int apdg = std::abs(pdg);
399 if (apdg < 1000000000)
return false;
400 int code = apdg - 1000000000;
401 Z = (code / 10000) % 1000;
402 A = (code / 10) % 1000;
403 return (Z > 0 &&
A >= Z);
419 LOG(info) <<
"=== MC primary species counts ===";
421 LOG(info) <<
"PDG " << kv.first <<
" : " << kv.second;
423 LOG(info) <<
"=== MC secondary species counts ===";
425 LOG(info) <<
"PDG " << kv.first <<
" : " << kv.second;
430 int oi =
static_cast<int>(origin);
436 if (
auto it = map.find(pdg); it != map.end())
return it->second;
438 const int nbins = 400;
439 const double xmin = 0.0;
440 const double xmax = 4000.0;
442 std::string name = Form(
"hEloss_keV_%s_pdg_%s%d",
kOriginName[oi], pdg < 0 ?
"m" :
"", std::abs(pdg));
443 std::string title = Form(
"dE (keV) [%s], PDG %d;dE [keV];counts",
kOriginName[oi], pdg);
445 TH1F*
h =
new TH1F(name.c_str(), title.c_str(), nbins, xmin, xmax);
446 h->SetDirectory(
nullptr);
455 if (pdg == 22)
return 1;
456 const int a = std::abs(pdg);
457 if (a == 11)
return 2;
458 if (a == 13)
return 3;
459 if (a == 211)
return 4;
460 if (a == 321)
return 5;
461 if (a == 2212)
return 6;
462 if (a == 2112)
return 7;
463 if (a > 1000000000)
return 8;
489 if (pdg == 22)
return 1;
491 if (pdg == 11)
return 2;
492 if (pdg == -11)
return 3;
494 if (pdg == 13)
return 4;
495 if (pdg == -13)
return 5;
497 if (pdg == 211)
return 6;
498 if (pdg == -211)
return 7;
500 if (pdg == 111)
return 8;
502 if (pdg == 321)
return 9;
503 if (pdg == -321)
return 10;
505 if (pdg == 310)
return 11;
506 if (pdg == 130)
return 12;
508 if (pdg == 2212)
return 13;
509 if (pdg == -2212)
return 14;
511 if (pdg == 2112)
return 15;
512 if (pdg == -2112)
return 16;
514 if (std::abs(pdg) > 1000000000)
return 17;
523 LOG(info) << GetName() <<
": MCTrack not found for file " << fileId <<
" event " << eventId <<
" track "
527 const int pdg = std::abs(trk->GetPdgCode());
528 const int motherId = trk->GetMotherId();
543 const auto* p =
static_cast<const FairMCPoint*
>(vp);
544 return p ? p->GetEnergyLoss() : 0.0;
Copied from CbmTutorialMyQaTask.
Task class creating and managing CbmMCDataArray objects.
Container class for MC events with number, file and start time.
int32_t GetPdgCode() const
CbmMvdMcQaTask(int verbose, bool isMcUsed)
T * MakeQaObject(TString sName, TString sTitle, Args... args)
CbmQaTask(const char *name, int verbose, bool isMCUsed, ECbmRecoMode recoMode=ECbmRecoMode::Timeslice)
Constructor from parameters.
bool IsMCUsed() const
Returns flag, whether MC information is used or not in the task.
Data class with information on a STS local track.
TH1D * fh_nMvdPointsEvt
MVD points per event.
void Check() override
Function to check, if the QA results are acceptable.
void ExecQa() override
Method to fill histograms per event or time-slice.
Long64_t fAllNPrim
global counters (over all events)
TH1D * fh_sec_count_bySpecies
overall counts (non-primary tracks with hits) by coarse species class
Int_t fNStations
Number of stations in MVD: TODO: Get Number of station from data file itself.
std::array< TList *, kNumOrigins > fLists
TH2D * fh_dEkeV_vs_pidClass
dE per point vs species class (non-primaries with hits)
TH2D * fh_mc_startY_vs_Z
start Y vs Z
Origin
track origin tag (public to avoid any ROOT dictionary issues)
std::vector< Origin > fOriginBuf
origin by track index
double fZMinStation0
TODO: Remove when we have getter for number of station directly from CbmMvdPoint.
TH2D * fh_mvd_dEkeV_vs_p
dE (keV) vs p (GeV/c) at MVD point
TH1D * fh_mc_pdg_sec
species for secondary MCTracks
TH2D * fh_mc_startY_vs_X
start Y vs X
CbmMCDataArray * fMcTracks
CbmMCEventList * fMcEventList
containers
int PidClass_(int pdg) const
static bool DecodeIonPDG_(int pdg, int &Z, int &A)
TH2D * fh_mvd_dEkeV_vs_pdg
dE (keV) vs species bin
std::unordered_map< int, uint64_t > fAllCountsSec
PDG -> count (all secondaries)
static constexpr const char * kOriginName[kNumOrigins]
std::vector< int > fPdgBuf
per-event caches
TH1D * fh_mc_p_sec
momentum of secondaries
CbmMCDataManager * fMcManager
std::vector< TH1D * > fh_mvd_nPointsEvt_station
MvdPoint histograms.
TH2D * fh_mc_startX_vs_Z
start X vs Z
int MapPdgToSpeciesBin_(int pdg) const
std::vector< TH2D * > fh_mvd_xy_sec_station
X-Y for secondary MVD points per station.
std::array< std::unordered_map< int, TH1F * >, kNumOrigins > fHistsElossKeVByPDG
TH1D * fh_mc_pdg_all
MCTrack-level histograms.
TH1D * fh_mc_startZ
start-z of MCTracks
TH1F * GetOrBookElossHist(int pdg, Origin origin)
double PointELossGeV_(const void *vp) const
std::unordered_map< int, uint64_t > fAllCountsPrim
PDG -> count (all primaries)
TH1D * fh_mvd_pdg_sec
species for secondary MVD points
TH1D * fh_mvd_pdg_prim
species for primary MVD points
void ProcessMcTracks(const int &fileId, const int &eventId)
FairRootManager * fManager
setup
TH1D * fh_mc_p_prim
momentum of primaries
InitStatus InitQa() override
Initializes the task.
void ProcessMvdPoints(const int &fileId, const int &eventId)
Origin ClassifyTrack_(const int &fileId, const int &eventId, Int_t trackindex) const
TH1D * fh_mc_pdg_prim
species for primary MCTracks
int GetStationIdFromZ_(double z) const
TH1D * fh_nDeltaEvt
number of secondary e+- with hits per event
std::vector< TH2D * > fh_mvd_xy_prim_station
X-Y for primary MVD points per station.
void CreateSummary() override
Initializes QA-task summary: canvases, tables etc.
static constexpr int kNumOrigins
CbmMCDataArray * fMvdPoints
TH1D * fh_mvd_pdg_all
species for all MVD points
TH2D * fh_dEkeV_vs_p
dE (keV) vs p (GeV/c) at point (non-primaries)
TH1D * fh_nTracksAll
Histograms.
int fKeVBin
1 keV bins by default