3636#include " THashList.h"
3737
3838using namespace o2 ::framework;
39+ static constexpr int nSpecies = 2 ; // One per PDG
40+ // static constexpr const char* particleTitle[nSpecies] = {"K0s", "-K0s"};
41+ static constexpr int PDGs[nSpecies] = {kK0Short , -kK0Short };
42+ int pdgToIndex (int pdg)
43+ {
44+ for (int i = 0 ; i < nSpecies; i++) {
45+ if (pdg == PDGs[i]) {
46+ return i;
47+ }
48+ }
49+ return -1 ;
50+ }
51+ static constexpr int kHistoPtNum = 0 ;
52+ static constexpr int kHistoPtDen = 1 ;
53+ static constexpr int kHistoTot = 2 ;
54+
55+ std::shared_ptr<TH1> histograms[nSpecies][kHistoTot ] = {{nullptr }};
56+ std::shared_ptr<TH1> histogramsPrm[nSpecies][kHistoTot ] = {{nullptr }};
57+ std::shared_ptr<TH1> histogramsPrmRap[nSpecies][kHistoTot ] = {{nullptr }};
3958
4059struct QaEfficiencyV0s {
4160 // Particle information
42- static constexpr int nSpecies = 1 ; // One per PDG
43- static constexpr const char * particleTitle[nSpecies] = {" K0s" };
44- static constexpr int PDGs[nSpecies] = {kK0Short };
45- // Particle only selection
46- Configurable<bool > doK0s{" do-k0s" , false , " Flag to run with the PDG code of k0s" };
4761 Configurable<float > rapidityCut{" rapidityCut" , 0.5 , " Rapidity cut" };
4862 ConfigurableAxis ptBins{" ptBins" , {200 , 0 .f , 5 .f }, " Pt binning" };
4963 OutputObj<THashList> listEfficiencyMC{" EfficiencyMC" };
50- // Histograms
51-
5264 HistogramRegistry registry{" Histos" , {}, OutputObjHandlingPolicy::AnalysisObject};
53-
5465 void init (InitContext&)
5566 {
5667 const AxisSpec axisPt{ptBins, " #it{p}_{T} GeV/#it{c}" };
57- auto h = registry.add <TH1>(" Pos/PtNum_310" , " Pos/Num_310" , kTH1F , {axisPt});
58- registry.add (" Pos/PtDen_310" , " Pos/Den_310" , kTH1F , {axisPt});
59- registry.add (" Neg/PtNum_310" , " Neg/Num_310" , kTH1F , {axisPt});
60- registry.add (" Neg/PtDen_310" , " Neg/Den_310" , kTH1F , {axisPt});
61- registry.add (" Prm/Pos/PtNum_310" , " Prm/Pos/Num_310" , kTH1F , {axisPt});
62- registry.add (" Prm/Pos/PtDen_310" , " Prm/Pos/Den_310" , kTH1F , {axisPt});
63- registry.add (" Prm/Neg/PtNum_310" , " Prm/Neg/Num_310" , kTH1F , {axisPt});
64- registry.add (" Prm/Neg/PtDen_310" , " Prm/Neg/Den_310" , kTH1F , {axisPt});
65- registry.add (" PrmRap/Pos/PtNum_310" , " PrmRap/Pos/Num_310" , kTH1F , {axisPt});
66- registry.add (" PrmRap/Pos/PtDen_310" , " PrmRap/Pos/Den_310" , kTH1F , {axisPt});
67- registry.add (" PrmRap/Neg/PtNum_310" , " PrmRap/Neg/Num_310" , kTH1F , {axisPt});
68- registry.add (" PrmRap/Neg/PtDen_310" , " PrmRap/Neg/Den_310" , kTH1F , {axisPt});
69-
70- TAxis* axis = h->GetXaxis ();
7168 listEfficiencyMC.setObject (new THashList);
72- listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPt_pdg%d" , PDGs[0 ]), Form (" efficiencyPt_pdg%d" , PDGs[0 ]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
73- listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPt_pdg-%d" , PDGs[0 ]), Form (" efficiencyPt_pdg-%d" , PDGs[0 ]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
74- listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPtPrm_pdg%d" , PDGs[0 ]), Form (" efficiencyPtPrm_pdg%d" , PDGs[0 ]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
75- listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPtPrm_pdg-%d" , PDGs[0 ]), Form (" efficiencyPtPrm_pdg-%d" , PDGs[0 ]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
76- listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPtPrmRap_pdg%d" , PDGs[0 ]), Form (" efficiencyPtPrmRap_pdg%d" , PDGs[0 ]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
77- listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPtPrmRap_pdg-%d" , PDGs[0 ]), Form (" efficiencyPtPrmRap_pdg-%d" , PDGs[0 ]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
69+
70+ for (int i = 0 ; i < nSpecies; i++) {
71+ // MC efficiency (PDG code
72+ histograms[i][kHistoPtNum ] = registry.add <TH1>(Form (" Pt/Num_%i" , PDGs[i]), Form (" Num %i" , PDGs[i]), kTH1F , {axisPt});
73+ histograms[i][kHistoPtDen ] = registry.add <TH1>(Form (" Pt/Den_%i" , PDGs[i]), Form (" Den %i" , PDGs[i]), kTH1F , {axisPt});
74+
75+ histogramsPrm[i][kHistoPtNum ] = registry.add <TH1>(Form (" Pt/Prm/Num_%i" , PDGs[i]), Form (" Pt Prm Num %i" , PDGs[i]), kTH1F , {axisPt});
76+ histogramsPrm[i][kHistoPtDen ] = registry.add <TH1>(Form (" Pt/Prm/Den_%i" , PDGs[i]), Form (" Pt Prm Den %i" , PDGs[i]), kTH1F , {axisPt});
77+
78+ histogramsPrmRap[i][kHistoPtNum ] = registry.add <TH1>(Form (" Pt/Prm/Rap/PtNum_%i" , PDGs[i]), Form (" Pt Prm Rap Num %i" , PDGs[i]), kTH1F , {axisPt});
79+ histogramsPrmRap[i][kHistoPtDen ] = registry.add <TH1>(Form (" Pt/Prm/Rap/PtDen_%i" , PDGs[i]), Form (" Pt Prm Rap Den %i" , PDGs[i]), kTH1F , {axisPt});
80+
81+ TAxis* axis = histograms[i][0 ]->GetXaxis ();
82+ listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPt_pdg%d" , PDGs[i]), Form (" efficiencyPt_pdg%d" , PDGs[i]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
83+ listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPtPrm_pdg%d" , PDGs[i]), Form (" efficiencyPtPrm_pdg%d" , PDGs[i]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
84+ listEfficiencyMC->Add (new TEfficiency (Form (" efficiencyPtPrmRap_pdg%d" , PDGs[i]), Form (" efficiencyPtPrmRap_pdg%d" , PDGs[i]), axis->GetNbins (), axis->GetXmin (), axis->GetXmax ()));
85+ }
7886 }
7987
8088 // MC process
@@ -83,62 +91,44 @@ struct QaEfficiencyV0s {
8391 void process (o2::aod::McV0Labels const & V0s,
8492 o2::aod::McParticles const & mcParticles)
8593 {
86- for (auto const & v0 : V0s) {
94+ for (auto const & v0 : V0s) { // Numerator
8795 if (v0.has_mcParticle ()) {
8896 auto mcparticle = v0.mcParticle ();
89- if (mcparticle.pdgCode () == PDGs[0 ]) {
90- registry.fill (HIST (" Pos/PtNum_310" ), mcparticle.pt ());
91- if (mcparticle.isPhysicalPrimary ()) {
92- registry.fill (HIST (" Prm/Pos/PtNum_310" ), mcparticle.pt ());
93- if (TMath::Abs (mcparticle.y ()) < rapidityCut) {
94- registry.fill (HIST (" PrmRap/Pos/PtNum_310" ), mcparticle.pt ());
95- }
96- }
97- } else if (mcparticle.pdgCode () == -PDGs[0 ]) {
98- registry.fill (HIST (" Neg/PtNum_310" ), mcparticle.pt ());
99- if (mcparticle.isPhysicalPrimary ()) {
100- registry.fill (HIST (" Prm/Neg/PtNum_310" ), mcparticle.pt ());
101- if (TMath::Abs (mcparticle.y ()) < rapidityCut) {
102- registry.fill (HIST (" PrmRap/Neg/PtNum_310" ), mcparticle.pt ());
103- }
104- }
97+ const auto index = pdgToIndex (mcparticle.pdgCode ());
98+ if (index < 0 ) {
99+ continue ;
105100 }
106- }
107- }
108- for (auto const & mcparticle : mcParticles) {
109- if (mcparticle.pdgCode () == PDGs[0 ]) {
110- registry.fill (HIST (" Pos/PtDen_310" ), mcparticle.pt ());
101+ histograms[index][kHistoPtNum ]->Fill (mcparticle.pt ());
111102 if (mcparticle.isPhysicalPrimary ()) {
112- registry. fill ( HIST ( " Prm/Pos/PtDen_310 " ), mcparticle.pt ());
103+ histogramsPrm[index][ kHistoPtNum ]-> Fill ( mcparticle.pt ());
113104 if (TMath::Abs (mcparticle.y ()) < rapidityCut) {
114- registry. fill ( HIST ( " PrmRap/Pos/PtDen_310 " ), mcparticle.pt ());
105+ histogramsPrmRap[index][ kHistoPtNum ]-> Fill ( mcparticle.pt ());
115106 }
116107 }
117- } else if (mcparticle.pdgCode () == -PDGs[0 ]) {
118- registry.fill (HIST (" Neg/PtDen_310" ), mcparticle.pt ());
119- if (mcparticle.isPhysicalPrimary ()) {
120- registry.fill (HIST (" Prm/Neg/PtDen_310" ), mcparticle.pt ());
121- if (TMath::Abs (mcparticle.y ()) < rapidityCut) {
122- registry.fill (HIST (" PrmRap/Neg/PtDen_310" ), mcparticle.pt ());
123- }
108+ }
109+ }
110+ for (auto const & mcparticle : mcParticles) { // Denominator
111+ const auto index = pdgToIndex (mcparticle.pdgCode ());
112+ if (index < 0 ) {
113+ continue ;
114+ }
115+ histograms[index][kHistoPtDen ]->Fill (mcparticle.pt ());
116+ if (mcparticle.isPhysicalPrimary ()) {
117+ histogramsPrm[index][kHistoPtDen ]->Fill (mcparticle.pt ());
118+ if (TMath::Abs (mcparticle.y ()) < rapidityCut) {
119+ histogramsPrmRap[index][kHistoPtDen ]->Fill (mcparticle.pt ());
124120 }
125121 }
126122 }
127123
128- static_cast <TEfficiency*>(listEfficiencyMC->At (0 ))->SetPassedHistogram (*registry.get <TH1>(HIST (" Pos/PtNum_310" )), " f" );
129- static_cast <TEfficiency*>(listEfficiencyMC->At (0 ))->SetTotalHistogram (*registry.get <TH1>(HIST (" Pos/PtDen_310" )), " f" );
130- static_cast <TEfficiency*>(listEfficiencyMC->At (1 ))->SetPassedHistogram (*registry.get <TH1>(HIST (" Neg/PtNum_310" )), " f" );
131- static_cast <TEfficiency*>(listEfficiencyMC->At (1 ))->SetTotalHistogram (*registry.get <TH1>(HIST (" Neg/PtDen_310" )), " f" );
132-
133- static_cast <TEfficiency*>(listEfficiencyMC->At (2 ))->SetPassedHistogram (*registry.get <TH1>(HIST (" Prm/Pos/PtNum_310" )), " f" );
134- static_cast <TEfficiency*>(listEfficiencyMC->At (2 ))->SetTotalHistogram (*registry.get <TH1>(HIST (" Prm/Pos/PtDen_310" )), " f" );
135- static_cast <TEfficiency*>(listEfficiencyMC->At (3 ))->SetPassedHistogram (*registry.get <TH1>(HIST (" Prm/Neg/PtNum_310" )), " f" );
136- static_cast <TEfficiency*>(listEfficiencyMC->At (3 ))->SetTotalHistogram (*registry.get <TH1>(HIST (" Prm/Neg/PtDen_310" )), " f" );
137-
138- static_cast <TEfficiency*>(listEfficiencyMC->At (4 ))->SetPassedHistogram (*registry.get <TH1>(HIST (" PrmRap/Pos/PtNum_310" )), " f" );
139- static_cast <TEfficiency*>(listEfficiencyMC->At (4 ))->SetTotalHistogram (*registry.get <TH1>(HIST (" PrmRap/Pos/PtDen_310" )), " f" );
140- static_cast <TEfficiency*>(listEfficiencyMC->At (5 ))->SetPassedHistogram (*registry.get <TH1>(HIST (" PrmRap/Neg/PtNum_310" )), " f" );
141- static_cast <TEfficiency*>(listEfficiencyMC->At (5 ))->SetTotalHistogram (*registry.get <TH1>(HIST (" PrmRap/Neg/PtDen_310" )), " f" );
124+ for (int i = 0 ; i < nSpecies; i++) {
125+ static_cast <TEfficiency*>(listEfficiencyMC->At (i * nSpecies))->SetPassedHistogram (*histograms[i][kHistoPtNum ].get (), " f" );
126+ static_cast <TEfficiency*>(listEfficiencyMC->At (i * nSpecies))->SetTotalHistogram (*histograms[i][kHistoPtDen ].get (), " f" );
127+ static_cast <TEfficiency*>(listEfficiencyMC->At (i * nSpecies + 1 ))->SetPassedHistogram (*histogramsPrm[i][kHistoPtNum ].get (), " f" );
128+ static_cast <TEfficiency*>(listEfficiencyMC->At (i * nSpecies + 1 ))->SetTotalHistogram (*histogramsPrm[i][kHistoPtDen ].get (), " f" );
129+ static_cast <TEfficiency*>(listEfficiencyMC->At (i * nSpecies + 2 ))->SetPassedHistogram (*histogramsPrmRap[i][kHistoPtNum ].get (), " f" );
130+ static_cast <TEfficiency*>(listEfficiencyMC->At (i * nSpecies + 2 ))->SetTotalHistogram (*histogramsPrmRap[i][kHistoPtDen ].get (), " f" );
131+ }
142132 }
143133};
144134
0 commit comments