@@ -35,6 +35,7 @@ std::map<int, TEfficiency*> effVsEta;
3535struct alice3Efficiency {
3636 Configurable<std::vector<int >> pdgCodes{" pdgCodes" , {211 }, " List of PDG codes to consider for efficiency calculation" };
3737 OutputObj<THashList> outList{" output" };
38+ Configurable<std::pair<float , float >> etaRange{" etaRange" , {-5 .f , 5 .f }, " Eta range for efficiency calculation" };
3839 void init (o2::framework::InitContext&)
3940 {
4041 outList.setObject (new THashList);
@@ -55,27 +56,43 @@ struct alice3Efficiency {
5556 aod::McParticles const & mcParticles)
5657 {
5758 std::map<int , std::vector<int64_t >> pdgIndices;
58- for (auto & mc : mcParticles) {
59- if (effVsPt.find (mc.pdgCode ()) == effVsPt.end ()) {
60- continue ;
59+
60+ // Lambda function to select particles after all cuts
61+ auto isParticleSelected = [&](const o2::aod::McParticle& p) {
62+ if (!p.isPhysicalPrimary ()) {
63+ return false ;
6164 }
62- pdgIndices[mc.pdgCode ()].push_back (mc.globalIndex ());
63- }
65+ if (p.eta () < etaRange.value .first ) {
66+ return false ;
67+ }
68+ if (p.eta () > etaRange.value .second ) {
69+ return false ;
70+ }
71+ return true ;
72+ };
6473 for (const auto & track : tracks) {
6574 if (!track.has_mcParticle ()) {
6675 continue ;
6776 }
6877 const auto & mcParticle = track.mcParticle ();
69- // Check that the PDG is in the list of PDGs
70- if (pdgIndices.find (mcParticle.pdgCode ()) == pdgIndices.end ()) {
78+ if (!isParticleSelected (mcParticle)) {
7179 continue ;
7280 }
81+ pdgIndices[mcParticle.pdgCode ()].push_back (mcParticle.globalIndex ());
82+ }
7383
74- std::vector<int64_t >& indices = pdgIndices[mcParticle.pdgCode ()];
84+ for (auto & mc : mcParticles) {
85+ if (effVsPt.find (mc.pdgCode ()) == effVsPt.end ()) {
86+ continue ;
87+ }
88+ if (!isParticleSelected (mc)) {
89+ continue ;
90+ }
91+ std::vector<int64_t >& indices = pdgIndices[mc.pdgCode ()];
7592 // Fill efficiency histogram
76- const bool found = std::find (indices.begin (), indices.end (), track .globalIndex ()) != indices.end ();
77- effVsPt[mcParticle .pdgCode ()]->Fill (found, track .pt ());
78- effVsEta[mcParticle .pdgCode ()]->Fill (found, track .eta ());
93+ const bool found = std::find (indices.begin (), indices.end (), mc .globalIndex ()) != indices.end ();
94+ effVsPt[mc .pdgCode ()]->Fill (found, mc .pt ());
95+ effVsEta[mc .pdgCode ()]->Fill (found, mc .eta ());
7996 }
8097 }
8198};
0 commit comments