Skip to content

Commit 2dcf0df

Browse files
pengchonPengchong Hu
andauthored
[PWGCF] correct weights (#16647)
Co-authored-by: Pengchong Hu <go34fir@tum.de>
1 parent 70565ad commit 2dcf0df

1 file changed

Lines changed: 44 additions & 32 deletions

File tree

PWGCF/MultiparticleCorrelations/Tasks/multiharmonicCorrelations.cxx

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
9898
Configurable<bool> cfDryRun{"cfDryRun", false, "book all histos and run without filling and calculating anything"}; // example for built-in type (float, string, etc.)
9999
Configurable<std::vector<float>> cfPtBins{"cfPtBins", {1000, 0., 8.}, "nPtBins, ptMin, ptMax"}; // example for an array
100100
Configurable<std::vector<float>> cfPhiBins{"cfPhiBins", {360, 0., o2::constants::math::TwoPI}, "nPhiBins, phiMin, phiMax"};
101-
Configurable<std::vector<float>> cfCentrBins{"cfCentrBins", {100, 0., 80.}, "nCentrBins, centrMin, centrMax"};
101+
Configurable<std::vector<float>> cfCentrBins{"cfCentrBins", {80, 0., 80.}, "nCentrBins, centrMin, centrMax"};
102102
Configurable<std::vector<float>> cfXBins{"cfXBins", {1000, -0.04, -0.01}, "nXBins, xMin, xMax"};
103103
Configurable<std::vector<float>> cfYBins{"cfYBins", {1000, -0.01, 0.006}, "nYBins, yMin, yMax"};
104104
Configurable<std::vector<float>> cfZBins{"cfZBins", {1000, -20., 20.}, "nZBins, zMin, zMax"};
@@ -117,7 +117,7 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
117117
Configurable<std::vector<float>> cfEta{"cfEta", {-0.8, 0.8}, "eta range"};
118118

119119
Configurable<std::vector<int>> cfRuns{"cfRuns", {544091, 544095, 544098, 544116, 544121, 544122, 544123, 544124}, "List of run numbers to analyze"};
120-
Configurable<std::string> cfFileWithWeights{"cfFileWithWeights", "/alice-ccdb.cern.ch/Users/p/pengchon/weightsfile01", "path to external ROOT file which holds all particle weights"};
120+
Configurable<std::string> cfFileWithWeights{"cfFileWithWeights", "/alice-ccdb.cern.ch/Users/p/pengchon/weightsfile05", "path to external ROOT file which holds all particle weights"};
121121

122122
// *) Define and initialize all data members to be called in the main process* functions:
123123
// **) Task configuration:
@@ -136,6 +136,7 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
136136
TH1F* fHistTracksdcaXY[2] = {NULL};
137137
TH1F* fHistTracksdcaZ[2] = {NULL};
138138
TH1F* histWeights = NULL;
139+
std::unordered_map<int, TH1F*> weightsmap;
139140
} pc; // you have to prepend "pc." for all objects name in this group later in the code
140141

141142
struct EventHistograms {
@@ -394,21 +395,27 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
394395
// LOGF(info, "Run number: %d", collision.bc().runNumber());
395396
int currentRun = collision.bc().runNumber();
396397
auto it = phih.histMap.find(currentRun);
397-
float zrec = 0., zsim = 0., centr = 0, M = 0.;
398+
auto histweight = pc.weightsmap.find(currentRun);
399+
float centr = 0, M = 0.;
398400

399401
if constexpr (rs == eRec || rs == eRecAndSim) {
400402
event.fHistX[eRec]->Fill(collision.posX());
401403
event.fHistY[eRec]->Fill(collision.posY());
402404
event.fHistZ[eRec]->Fill(collision.posZ());
403405
event.fEventHistograms[eVertexZ][eRec][0]->Fill(collision.posZ());
404-
zrec = collision.posZ();
405-
event.fHistNContr->Fill(collision.numContrib());
406406
if (cfCent.value == "FT0C")
407407
centr = collision.centFT0C();
408408
else if (cfCent.value == "FT0M")
409409
centr = collision.centFT0M();
410410
else if (cfCent.value == "FT0A")
411411
centr = collision.centFT0A();
412+
413+
// *) Event cuts:
414+
float centrcut = 80.;
415+
if (!EventCuts<rs>(collision) || centr > centrcut) { // Main call for event cuts
416+
return;
417+
}
418+
event.fEventHistograms[eVertexZ][eRec][1]->Fill(collision.posZ());
412419
event.fHistCentr[eRec]->Fill(centr);
413420

414421
std::string multType = "TPC";
@@ -423,6 +430,7 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
423430
else if (cfMult.value == "NTracksPV")
424431
M = collision.multNTracksPV();
425432
event.fHistMult[eRec]->Fill(M);
433+
event.fHistNContr->Fill(collision.numContrib());
426434
qa.fQAM_NC->Fill(M, collision.numContrib());
427435

428436
if constexpr (rs == eRecAndSim) {
@@ -432,25 +440,15 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
432440
event.fHistX[eSim]->Fill(mccollision.posX());
433441
event.fHistY[eSim]->Fill(mccollision.posY());
434442
event.fHistZ[eSim]->Fill(mccollision.posZ());
435-
event.fEventHistograms[eVertexZ][eSim][0]->Fill(mccollision.posZ());
436-
zsim = mccollision.posZ();
443+
event.fEventHistograms[eVertexZ][eSim][1]->Fill(mccollision.posZ());
437444
event.fHistCentr[eSim]->Fill(centrsim);
438445
qa.fQA->Fill(centrsim, centr);
439446
centr = centrsim;
440447
}
441-
442-
// *) Event cuts:
443-
float centrcut = 80.;
444-
if (!EventCuts<rs>(collision) || centr > centrcut) { // Main call for event cuts
445-
return;
446-
}
447-
event.fEventHistograms[eVertexZ][eRec][1]->Fill(zrec);
448-
if constexpr (rs == eRecAndSim)
449-
event.fEventHistograms[eVertexZ][eSim][1]->Fill(zsim);
450448
}
451449

452450
// before loop over particles
453-
float phi = 0, weight = 0;
451+
float phi = 0, weight = 1.;
454452
for (int ih = 0; ih < maxHarmonic; ih++) {
455453
cor.Qvector[ih] = TComplex(0., 0.);
456454
}
@@ -465,6 +463,13 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
465463
pc.fHistPt[eRec]->Fill(track.pt());
466464
event.fEventHistograms[ePt][eRec][0]->Fill(track.pt());
467465
ptrec = track.pt();
466+
467+
// *) Particle cuts:
468+
if (!ParticleCuts<rs>(track)) { // Main call for particle cuts.
469+
continue; // not return!!
470+
}
471+
event.fEventHistograms[ePt][eRec][1]->Fill(ptrec);
472+
468473
phi = track.phi();
469474
if (it != phih.histMap.end()) {
470475
it->second->Fill(phi);
@@ -475,7 +480,9 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
475480
pc.fHistTracksdcaXY[eRec]->Fill(track.dcaXY());
476481
pc.fHistTracksdcaZ[eRec]->Fill(track.dcaZ());
477482

478-
weight = 1.; // pc.histWeights->GetBinContent(phi);
483+
if (histweight != pc.weightsmap.end()) {
484+
weight = histweight->second->GetBinContent(histweight->second->FindBin(phi));
485+
}
479486

480487
// ... and corresponding MC truth simulated:
481488
// See https://github.com/AliceO2Group/O2Physics/blob/master/Tutorials/src/mcHistograms.cxx
@@ -489,22 +496,11 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
489496
pc.fHistPt[eSim]->Fill(mcparticle.pt());
490497
event.fEventHistograms[ePt][eSim][0]->Fill(mcparticle.pt());
491498
ptsim = mcparticle.pt();
499+
event.fEventHistograms[ePt][eSim][0]->Fill(ptsim);
492500
phi = mcparticle.phi();
493501
pc.fHistPhi[eSim]->Fill(mcparticle.phi());
494-
// pc.fHistCharge[eSim]->Fill(mcparticle.sign());
495-
// pc.fHistTPCncls[eSim]->Fill(mcparticle.tpcNClsFindable());
496-
// pc.fHistTracksdcaXY[eSim]->Fill(mcparticle.dcaXY());
497-
// pc.fHistTracksdcaZ[eSim]->Fill(mcparticle.dcaZ());
498502
} // end of if constexpr (rs == eRecAndSim)
499503

500-
// *) Particle cuts:
501-
if (!ParticleCuts<rs>(track)) { // Main call for particle cuts.
502-
continue; // not return!!
503-
}
504-
event.fEventHistograms[ePt][eRec][1]->Fill(ptrec);
505-
if constexpr (rs == eRecAndSim)
506-
event.fEventHistograms[ePt][eSim][0]->Fill(ptsim);
507-
508504
} // if constexpr (rs == eRec || rs == eRecAndSim)
509505

510506
// analysis in the loop over particle
@@ -513,11 +509,19 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
513509
}
514510
} // end of for (auto track: tracks)
515511
// calculate correlations
512+
float Mmin = 4.;
513+
if (M < Mmin)
514+
return;
516515
float four32 = Four(3, 2, -3, -2).Re() / Four(0, 0, 0, 0).Re();
517516
float four42 = Four(4, 2, -4, -2).Re() / Four(0, 0, 0, 0).Re();
518517
float v22 = (Q(2).Rho2() - M) / (M * (M - 1.));
519518
float v32 = (Q(3).Rho2() - M) / (M * (M - 1.));
520519
float v42 = (Q(4).Rho2() - M) / (M * (M - 1.));
520+
if (std::isnan(v22) || std::isnan(v32) || std::isnan(v42) || std::isnan(four32) || std::isnan(four42)) {
521+
LOGF(info, "\033[1;31m%s std::isnan(v22) || std::isnan(v32) || std::isnan(v42) || std::isnan(four32) || std::isnan(four42)\033[0m", __FUNCTION__);
522+
LOGF(error, "v22 = %f\nv32 = %f\nv42 = %f\nfour32=%f\nv42 = %f\n", v22, v32, v42, four32, four42);
523+
return;
524+
}
521525

522526
cor.pv22_centr->Fill(centr, v22, M * (M - 1));
523527
cor.pv32_centr->Fill(centr, v32, M * (M - 1));
@@ -660,8 +664,16 @@ struct MultiharmonicCorrelations { // this name is used in lower-case format to
660664
pc.fParticleHistogramsList->Add(pc.fHistTracksdcaXY[eSim]);
661665
pc.fParticleHistogramsList->Add(pc.fHistTracksdcaZ[eSim]);
662666

663-
pc.histWeights = GetHistogramWithWeights(cfFileWithWeights.value.c_str(), "000123456");
664-
pc.fParticleHistogramsList->Add(pc.histWeights);
667+
for (const int& run : targetRuns) {
668+
std::string runStr = std::to_string(run);
669+
TH1F* histweights = GetHistogramWithWeights(cfFileWithWeights.value.c_str(), runStr.c_str());
670+
if (!histweights) {
671+
LOG(fatal) << "Failed to load weights for run " << run;
672+
return;
673+
}
674+
675+
pc.weightsmap[run] = histweights;
676+
}
665677

666678
event.fHistCentr[eRec] = new TH1F("fHistCentr[eRec]", "centrality distribution for reconstructed particles", nBinscentr, mincentr, maxcentr);
667679
event.fHistX[eRec] = new TH1F("fHistX[eRec]", "posX distribution for reconstructed particles", nBinsx, minx, maxx);

0 commit comments

Comments
 (0)