Skip to content

Commit 51d87a4

Browse files
committed
Fix issue with efficiency weight
1 parent 37f4293 commit 51d87a4

File tree

1 file changed

+29
-78
lines changed

1 file changed

+29
-78
lines changed

PWGLF/Tasks/Strangeness/lambdaspincorrderived.cxx

Lines changed: 29 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,9 @@ struct lambdaspincorrderived {
8080
// Configurable<std::string> ConfWeightPathLAL{"ConfWeightPathLAL", "Users/s/skundu/My/Object/spincorr/cent010LL", "Weight path"};
8181
// Configurable<std::string> ConfWeightPathALL{"ConfWeightPathALL", "Users/s/skundu/My/Object/spincorr/cent010LL", "Weight path"};
8282

83-
Configurable<std::string> ConfRPathL{"ConfRPathL", "", "CCDB path to R_L (optional)"};
84-
Configurable<std::string> ConfRPathAL{"ConfRPathAL", "", "CCDB path to R_AL (optional)"};
8583
Configurable<std::string> ConfEffPathL{"ConfEffPathL", "", "CCDB path to Eff (optional)"};
8684
Configurable<std::string> ConfEffPathAL{"ConfEffPathAL", "", "CCDB path to Eff (optional)"};
8785

88-
TH3D* hR_L = nullptr;
89-
TH3D* hR_AL = nullptr;
9086
TH3D* hEff_L = nullptr;
9187
TH3D* hEff_AL = nullptr;
9288

@@ -140,12 +136,6 @@ struct lambdaspincorrderived {
140136
histos.add("ptCent", "ptCent", HistType::kTH2D, {{100, 0.0, 10.0}, {8, 0.0, 80.0}}, true);
141137
histos.add("etaCent", "etaCent", HistType::kTH2D, {{32, -0.8, 0.8}, {8, 0.0, 80.0}}, true);
142138

143-
// --- Singles QA for data-driven MIXED reweight (one fill per candidate) ---
144-
histos.add("hSE_L", "SE #Lambda; p_{T}; #eta; #varphi", kTH3D, {{50, 0.0, 5.0}, {32, -0.8, 0.8}, {72, 0.0, 2.0 * TMath::Pi()}}, true);
145-
histos.add("hSE_AL", "SE #bar{#Lambda}; p_{T}; #eta; #varphi", kTH3D, {{50, 0.0, 5.0}, {32, -0.8, 0.8}, {72, 0.0, 2.0 * TMath::Pi()}}, true);
146-
histos.add("hME_L", "ME #Lambda; p_{T}; #eta; #varphi", kTH3D, {{50, 0.0, 5.0}, {32, -0.8, 0.8}, {72, 0.0, 2.0 * TMath::Pi()}}, true);
147-
histos.add("hME_AL", "ME #bar{#Lambda}; p_{T}; #eta; #varphi", kTH3D, {{50, 0.0, 5.0}, {32, -0.8, 0.8}, {72, 0.0, 2.0 * TMath::Pi()}}, true);
148-
149139
// Attempted-for-replacement (Den) and Succeeded (Num) per SE leg kinematics
150140
histos.add("hMatchDen_L", "Attempted #Lambda; p_{T}; #eta; #varphi", kTH3D, {{50, 0.0, 5.0}, {32, -0.8, 0.8}, {72, 0.0, 2.0 * TMath::Pi()}}, true);
151141
histos.add("hMatchDen_AL", "Attempted #bar{#Lambda}; p_{T}; #eta; #varphi", kTH3D, {{50, 0.0, 5.0}, {32, -0.8, 0.8}, {72, 0.0, 2.0 * TMath::Pi()}}, true);
@@ -203,8 +193,6 @@ struct lambdaspincorrderived {
203193
ccdb->setCreatedNotAfter(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
204194
LOGF(info, "Getting alignment offsets from the CCDB...");
205195
if (useweight) {
206-
hR_L = ccdb->getForTimeStamp<TH3D>(ConfRPathL.value, cfgCcdbParam.nolaterthan.value);
207-
hR_AL = ccdb->getForTimeStamp<TH3D>(ConfRPathAL.value, cfgCcdbParam.nolaterthan.value);
208196
hEff_L = ccdb->getForTimeStamp<TH3D>(ConfEffPathL.value, cfgCcdbParam.nolaterthan.value);
209197
hEff_AL = ccdb->getForTimeStamp<TH3D>(ConfEffPathAL.value, cfgCcdbParam.nolaterthan.value);
210198
// hweight1 = ccdb->getForTimeStamp<TH3D>(ConfWeightPathLL.value, cfgCcdbParam.nolaterthan.value);
@@ -421,7 +409,9 @@ struct lambdaspincorrderived {
421409
auto costhetaz1costhetaz2 = -999.0;
422410
if (cosDef == 0) {
423411
cosThetaDiff = cosDeltaTheta_STAR_naive;
424-
costhetaz1costhetaz2 = (proton1LambdaRF.Pz() * proton2LambdaRF.Pz()) / (proton1LambdaRF.P() * proton2LambdaRF.P());
412+
if (proton1LambdaRF.P() * proton2LambdaRF.P() != 0.0) {
413+
costhetaz1costhetaz2 = (proton1LambdaRF.Pz() * proton2LambdaRF.Pz()) / (proton1LambdaRF.P() * proton2LambdaRF.P());
414+
}
425415
} else {
426416
cosThetaDiff = cosDeltaTheta_hel;
427417
costhetaz1costhetaz2 = cosDeltaTheta_beam;
@@ -432,38 +422,20 @@ struct lambdaspincorrderived {
432422
double deltaRap = std::abs(particle1Dummy.Rapidity() - particle2Dummy.Rapidity());
433423
double deltaR = TMath::Sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi);
434424

435-
double nuaWeightParticle1 = 1.0, epsWeightParticle1 = 1.0;
436-
double nuaWeightParticle2 = 1.0, epsWeightParticle2 = 1.0;
437-
438-
if (useweight && datatype == 1) {
439-
// particle 1
440-
{
441-
auto* hR = (tag1 == 0 ? hR_L : hR_AL);
442-
auto* hEff = (tag1 == 0 ? hEff_L : hEff_AL);
425+
double epsWeightParticle1 = 1.0;
426+
double epsWeightParticle2 = 1.0;
443427

444-
float pt = particle1.Pt();
445-
float eta = particle1.Eta();
446-
float phi = RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic);
447-
448-
nuaWeightParticle1 = hR->GetBinContent(hR->FindBin(pt, eta, phi));
449-
if (replacedFlag == 1) {
450-
epsWeightParticle1 = hEff->GetBinContent(hEff->FindBin(pt, eta, phi));
451-
}
428+
if (useweight && datatype == 1 && replacedFlag == 1) {
429+
if (tag1 == 0) {
430+
epsWeightParticle1 = hEff_L->GetBinContent(hEff_L->FindBin(particle1.Pt(), particle1.Eta(), RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic)));
431+
} else {
432+
epsWeightParticle1 = hEff_AL->GetBinContent(hEff_AL->FindBin(particle1.Pt(), particle1.Eta(), RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic)));
452433
}
453-
454-
// particle 2
455-
{
456-
auto* hR = (tag2 == 0 ? hR_L : hR_AL);
457-
auto* hEff = (tag2 == 0 ? hEff_L : hEff_AL);
458-
459-
float pt = particle2.Pt();
460-
float eta = particle2.Eta();
461-
float phi = RecoDecay::constrainAngle(particle2.Phi(), 0.0F, harmonic);
462-
463-
nuaWeightParticle2 = hR->GetBinContent(hR->FindBin(pt, eta, phi));
464-
if (replacedFlag == 2) {
465-
epsWeightParticle2 = hEff->GetBinContent(hEff->FindBin(pt, eta, phi));
466-
}
434+
} else if (useweight && datatype == 1 && replacedFlag == 2) {
435+
if (tag2 == 0) {
436+
epsWeightParticle2 = hEff_L->GetBinContent(hEff_L->FindBin(particle2.Pt(), particle2.Eta(), RecoDecay::constrainAngle(particle2.Phi(), 0.0F, harmonic)));
437+
} else {
438+
epsWeightParticle2 = hEff_AL->GetBinContent(hEff_AL->FindBin(particle2.Pt(), particle2.Eta(), RecoDecay::constrainAngle(particle2.Phi(), 0.0F, harmonic)));
467439
}
468440
}
469441

@@ -492,17 +464,16 @@ struct lambdaspincorrderived {
492464
// histos.fill(HIST("hAntiLambdaSameForALAL"), particle1.Pt(), particle1.Eta(), RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic), mixpairweight);
493465
}
494466
} else if (datatype == 1) {
495-
// double weight1 = mixpairweight*nuaWeightParticle1*nuaWeightParticle2;
496-
// double weight2 = mixpairweight*nuaWeightParticle1*nuaWeightParticle2;
497-
// double weight3 = mixpairweight*nuaWeightParticle1*nuaWeightParticle2;
498-
// double weight4 = mixpairweight*nuaWeightParticle1*nuaWeightParticle2;
499-
// if (useweight) {
500-
// weight1 = mixpairweight * hweight1->GetBinContent(hweight1->FindBin(particle1.Pt(), particle1.Eta(), RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic)));
501-
// weight2 = mixpairweight * hweight2->GetBinContent(hweight2->FindBin(particle1.Pt(), particle1.Eta(), RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic)));
502-
// weight3 = mixpairweight * hweight3->GetBinContent(hweight3->FindBin(particle1.Pt(), particle1.Eta(), RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic)));
503-
// weight4 = mixpairweight * hweight4->GetBinContent(hweight4->FindBin(particle1.Pt(), particle1.Eta(), RecoDecay::constrainAngle(particle1.Phi(), 0.0F, harmonic)));
504-
// }
505-
double weight = mixpairweight * (nuaWeightParticle1 / epsWeightParticle1) * (nuaWeightParticle2 / epsWeightParticle2);
467+
double weight = mixpairweight;
468+
if (useweight && replacedFlag == 1) {
469+
weight = mixpairweight / epsWeightParticle1;
470+
}
471+
if (useweight && replacedFlag == 2) {
472+
weight = mixpairweight / epsWeightParticle2;
473+
}
474+
if (weight <= 0.0) {
475+
weight = 1.0;
476+
}
506477
if (tag1 == 0 && tag2 == 0) {
507478
histos.fill(HIST("hPtYMix"), particle1.Pt(), particle1.Rapidity(), weight);
508479
histos.fill(HIST("hSparseLambdaLambdaMixed"), particle1.M(), particle2.M(), cosThetaDiff, deltaR, weight);
@@ -552,13 +523,6 @@ struct lambdaspincorrderived {
552523
proton = ROOT::Math::PtEtaPhiMVector(v0.protonPt(), v0.protonEta(), v0.protonPhi(), o2::constants::physics::MassProton);
553524
lambda = ROOT::Math::PtEtaPhiMVector(v0.lambdaPt(), v0.lambdaEta(), v0.lambdaPhi(), v0.lambdaMass());
554525

555-
auto phiH0 = RecoDecay::constrainAngle(v0.lambdaPhi(), 0.0F, harmonic);
556-
if (v0.v0Status() == 0) {
557-
histos.fill(HIST("hSE_L"), v0.lambdaPt(), v0.lambdaEta(), phiH0);
558-
} else {
559-
histos.fill(HIST("hSE_AL"), v0.lambdaPt(), v0.lambdaEta(), phiH0);
560-
}
561-
562526
for (const auto& v02 : V0s) {
563527
if (v02.index() <= v0.index()) {
564528
continue;
@@ -803,11 +767,11 @@ struct lambdaspincorrderived {
803767
int mixes = 0;
804768
struct PoolView {
805769
AllTrackCandidates* pool;
806-
int nRepl;
770+
double nRepl;
807771
int collIdx;
808772
};
809773
std::vector<PoolView> usable;
810-
int totalRepl = 0;
774+
double totalRepl = 0;
811775

812776
for (auto it = eventPools[bin].rbegin();
813777
it != eventPools[bin].rend() && mixes < nEvtMixing; ++it, ++mixes) {
@@ -816,7 +780,7 @@ struct lambdaspincorrderived {
816780
if (collision2idx == collision1.index())
817781
continue; // safety
818782

819-
int nRepl = 0;
783+
double nRepl = 0;
820784
for (auto& tX : poolB) {
821785
if (!selectionV0(tX))
822786
continue;
@@ -836,8 +800,8 @@ struct lambdaspincorrderived {
836800

837801
if (totalRepl == 0)
838802
continue;
839-
const float wBase = 1.0f / static_cast<float>(totalRepl);
840803

804+
const float wBase = 1.0f / totalRepl;
841805
// --- Second pass: actually build mixed pairs for the chosen leg
842806
for (auto& pv : usable) {
843807
auto& poolB = *pv.pool;
@@ -878,19 +842,6 @@ struct lambdaspincorrderived {
878842

879843
// after mixing with prior events, push current event into the pool
880844
auto sliced = V0s.sliceBy(tracksPerCollisionV0, collision1.index());
881-
882-
// --- ME singles (one fill per candidate) for this event entering the pool ---
883-
for (auto& t : sliced) {
884-
if (!selectionV0(t))
885-
continue;
886-
const double phiH = RecoDecay::constrainAngle(t.lambdaPhi(), 0.0F, harmonic);
887-
if (t.v0Status() == 0) {
888-
histos.fill(HIST("hME_L"), t.lambdaPt(), t.lambdaEta(), phiH);
889-
} else {
890-
histos.fill(HIST("hME_AL"), t.lambdaPt(), t.lambdaEta(), phiH);
891-
}
892-
}
893-
894845
eventPools[bin].emplace_back(collision1.index(), std::move(sliced));
895846
if (static_cast<int>(eventPools[bin].size()) > nEvtMixing) {
896847
eventPools[bin].pop_front();

0 commit comments

Comments
 (0)