diff --git a/PWGCF/GenericFramework/Core/CMakeLists.txt b/PWGCF/GenericFramework/Core/CMakeLists.txt index c82c4a5c751..e1830dff82f 100644 --- a/PWGCF/GenericFramework/Core/CMakeLists.txt +++ b/PWGCF/GenericFramework/Core/CMakeLists.txt @@ -1,35 +1,49 @@ -# Copyright 2019-2020 CERN and copyright holders of ALICE O2. -# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -# All rights not expressly granted are reserved. +#Copyright 2019 - 2020 CERN and copyright holders of ALICE O2. +#See https: // alice-o2.web.cern.ch/copyright for details of the copyright holders. +#All rights not expressly granted are reserved. # -# This software is distributed under the terms of the GNU General Public -# License v3 (GPL Version 3), copied verbatim in the file "COPYING". +#This software is distributed under the terms of the GNU General Public +#License v3(GPL Version 3), copied verbatim in the file "COPYING". # -# In applying this license CERN does not waive the privileges and immunities -# granted to it by virtue of its status as an Intergovernmental Organization +#In applying this license CERN does not waive the privileges and immunities +#granted to it by virtue of its status as an Intergovernmental Organization # or submit itself to any jurisdiction. o2physics_add_library(GFWCore - SOURCES GFWPowerArray.cxx - GFWCumulant.cxx - GFW.cxx - ProfileSubset.cxx - FlowContainer.cxx - GFWWeights.cxx - GFWWeightsList.cxx - FlowPtContainer.cxx - BootstrapProfile.cxx - PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore) + SOURCES GFWPowerArray.cxx + GFWCumulant.cxx + GFW.cxx + ProfileSubset.cxx + FlowContainer.cxx + GFWWeights.cxx + GFWWeightsList.cxx + FlowPtContainer.cxx + BootstrapProfile.cxx + MyCanvas.cxx + Calculator.cxx + SysHandler.cxx + StatHandler.cxx + OutputHandler.cxx + PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore) -o2physics_target_root_dictionary(GFWCore - HEADERS GFWPowerArray.h - GFWCumulant.h - GFW.h - ProfileSubset.h - FlowContainer.h - GFWWeights.h - GFWWeightsList.h - GFWConfig.h - FlowPtContainer.h - BootstrapProfile.h - LINKDEF GenericFrameworkLinkDef.h) + o2physics_target_root_dictionary(GFWCore + HEADERS GFWPowerArray.h + GFWCumulant.h + GFW.h + ProfileSubset.h + FlowContainer.h + GFWWeights.h + GFWWeightsList.h + GFWConfig.h + GFWSpace.h + FlowPtContainer.h + BootstrapProfile.h + PlotLegendPlacementUtils.h + PlotYRangeUtils.h + PlotTemplateSteerer.h + MyCanvas.h + Calculator.h + SysHandler.h + StatHandler.h + OutputHandler.h + LINKDEF GenericFrameworkLinkDef.h) diff --git a/PWGCF/GenericFramework/Core/Calculator.cxx b/PWGCF/GenericFramework/Core/Calculator.cxx new file mode 100644 index 00000000000..693e3c19bcb --- /dev/null +++ b/PWGCF/GenericFramework/Core/Calculator.cxx @@ -0,0 +1,3871 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// NOLINTBEGIN(readability/casting, readability/braces) +#include "Calculator.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ +constexpr int ChargedSpeciesCount = 4; +constexpr int K0SpeciesIndex = ChargedSpeciesCount; +constexpr int LambdaSpeciesIndex = ChargedSpeciesCount + 1; + +int fitCentEdge(double value) +{ + return static_cast(std::lround(value)); +} + +double fitPtEdge(double value) +{ + return std::round(value * 10.) / 10.; +} + +void applySignalFractionCorrection(Calculator& calculator, TH1D* totalHist, TH1D* backgroundHist, const std::string& species, double centMin, double centMax, const char* caller) +{ + if (!totalHist || !backgroundHist) { + return; + } + + const int centMinInt = fitCentEdge(centMin); + const int centMaxInt = fitCentEdge(centMax); + for (int bin = 1; bin <= totalHist->GetNbinsX(); ++bin) { + const double ptMin = totalHist->GetXaxis()->GetBinLowEdge(bin); // fitPtEdge(totalHist->GetXaxis()->GetBinLowEdge(bin)); + const double ptMax = totalHist->GetXaxis()->GetBinUpEdge(bin); // fitPtEdge(totalHist->GetXaxis()->GetBinUpEdge(bin)); + const double signalFraction = calculator.readInvMassFit(species, -1., -1., ptMin, ptMax, centMinInt, centMaxInt); + if (signalFraction <= 0. || signalFraction >= 1.) { + std::cout << "[" << caller << "] Invalid S/(S+B) value for " << species + << " cent " << centMinInt << "-" << centMaxInt + << " pt " << ptMin << "-" << ptMax + << ": " << signalFraction << std::endl; + totalHist->SetBinContent(bin, 0.); + totalHist->SetBinError(bin, 0.); + continue; + } + + const double backgroundFraction = 1. - signalFraction; + const double totalValue = totalHist->GetBinContent(bin); + const double totalError = totalHist->GetBinError(bin); + const double backgroundValue = backgroundHist->GetBinContent(bin); + const double backgroundError = backgroundHist->GetBinError(bin); + + const double correctedValue = (totalValue - backgroundFraction * backgroundValue) / signalFraction; + const double correctedError = std::sqrt(totalError * totalError + backgroundFraction * backgroundFraction * backgroundError * backgroundError) / signalFraction; + totalHist->SetBinContent(bin, correctedValue); + totalHist->SetBinError(bin, correctedError); + } +} + +struct DifferentialMoments { + double normalization = 0.; + double meanPtNumerator = 0.; + double zeroth = 0.; + double first = 0.; + double meanPtVariance = 0.; + double firstVariance = 0.; +}; + +DifferentialMoments calculateDifferentialMoments(const TH1D& observable, const TH1D& fraction) +{ + DifferentialMoments moments; + for (int fractionBin = 1; fractionBin <= fraction.GetNbinsX(); ++fractionBin) { + const double pt = fraction.GetXaxis()->GetBinCenter(fractionBin); + const int observableBin = observable.GetXaxis()->FindFixBin(pt); + if (observableBin < 1 || observableBin > observable.GetNbinsX()) + continue; + + const double n = fraction.GetBinContent(fractionBin); + const double nError = fraction.GetBinError(fractionBin); + const double value = observable.GetBinContent(observableBin); + const double valueError = observable.GetBinError(observableBin); + if (!std::isfinite(n) || !std::isfinite(nError) || + !std::isfinite(value) || !std::isfinite(valueError)) + continue; + + moments.normalization += n; + moments.meanPtNumerator += pt * n; + moments.zeroth += n * value; + moments.first += pt * n * value; + moments.meanPtVariance += pt * pt * nError * nError; + moments.firstVariance += pt * pt * + (n * n * valueError * valueError + + value * value * nError * nError); + } + return moments; +} + +double matchedIntegratedObservable(const TH1D& observable, const TH1D& fraction, double* error = nullptr) +{ + const DifferentialMoments moments = calculateDifferentialMoments(observable, fraction); + if (!std::isfinite(moments.first) || + !std::isfinite(moments.meanPtNumerator) || + std::abs(moments.meanPtNumerator) <= std::numeric_limits::epsilon()) { + if (error) + *error = 0.; + return std::numeric_limits::quiet_NaN(); + } + + const double value = moments.first / moments.meanPtNumerator; + if (error) { + const double denominator2 = moments.meanPtNumerator * moments.meanPtNumerator; + const double variance = moments.firstVariance / denominator2 + + value * value * moments.meanPtVariance / denominator2; + *error = variance > 0. ? std::sqrt(variance) : 0.; + } + return value; +} + +TH1D* projectFraction(TH2D* histogram, const std::string& species, double min, double max) +{ + if (!histogram || min >= max) { + return nullptr; + } + TAxis* centralityAxis = histogram->GetYaxis(); + const int firstBin = centralityAxis->FindFixBin(min + 1.e-6); + const int lastBin = centralityAxis->FindFixBin(max - 1.e-6); + if (firstBin < 1 || lastBin > centralityAxis->GetNbins() || firstBin > lastBin) { + std::cerr << "[projectFraction] Centrality interval " << min << "-" << max + << " is outside the fractional-spectrum axis" << std::endl; + return nullptr; + } + std::unique_ptr profile(histogram->ProfileX( + Form("pf_%s_mean_fraction_pt_%.1f_%.1f", species.c_str(), min, max), firstBin, lastBin)); + return profile ? profile->ProjectionX(Form("%s_mean_fraction_pt_%.1f_%.1f", species.c_str(), min, max)) : nullptr; +} +} // namespace + +Calculator::Calculator() : flowcont(nullptr), flowptcont(nullptr), flowptcontfull(nullptr), corr_list(nullptr), flowid(""), collision_system(""), invMassFitPath(""), useTotal(false), useInverseVarianceWeight(true) +{ +} +Calculator::~Calculator() +{ + clearInputData(); +}; + +std::unique_ptr Calculator::prepareFlowContainerSample(int sampleIndex) +{ + if (sampleIndex < 0) { + return nullptr; + } + auto prepared = std::unique_ptr(dynamic_cast(flowcont->Clone("TempClone"))); + if (!prepared || !prepared->OverrideMainWithSub(sampleIndex, kFALSE)) { + return nullptr; + } + Int_t nBins = 0; + Double_t* binEdges = flowcont->GetMultiRebin(nBins); + prepared->SetMultiRebin(nBins, binEdges); + delete[] binEdges; + return prepared; +} + +FlowContainer* Calculator::getFlowContainerSample(int sampleIndex, std::unique_ptr& ownedContainer) +{ + if (activeFlowContainer && activeFlowContainerSample == sampleIndex) { + return activeFlowContainer; + } + if (sampleIndex < 0) { + return flowcont; + } + ownedContainer = prepareFlowContainerSample(sampleIndex); + return ownedContainer.get(); +} + +void Calculator::setInvMassFitFunctions(const std::string& species, const std::string& signalFunction, const std::string& backgroundFunction) +{ + const std::string key = (species == "AntiLambda" || species == "LambdaAntiLambda") ? "Lambda" : species; + invMassFitFunctions[key] = {signalFunction, backgroundFunction}; + invMassFitCache.clear(); + std::cout << "[Calculator::setInvMassFitFunctions] " << key << ": " + << signalFunction << "+" << backgroundFunction << std::endl; +} + +void Calculator::setInvMassFitFunctionsForSystematic(int index, + const std::string& species, + const std::string& signalFunction, + const std::string& backgroundFunction) +{ + const std::string key = (species == "AntiLambda" || species == "LambdaAntiLambda") ? "Lambda" : species; + invMassFitFunctionsBySystematic[index][key] = {signalFunction, backgroundFunction}; + invMassFitCache.clear(); +} + +void Calculator::setInvMassFitCentralityBins(const std::vector& centralityBins) +{ + if (centralityBins.empty()) { + invMassFitCentralityBins.clear(); + return; + } + if (centralityBins.size() < 2 || + !std::is_sorted(centralityBins.begin(), centralityBins.end()) || + std::adjacent_find(centralityBins.begin(), centralityBins.end(), std::greater_equal()) != centralityBins.end()) { + std::cerr << "[Calculator::setInvMassFitCentralityBins] Centrality bin edges must be strictly increasing" << std::endl; + return; + } + invMassFitCentralityBins = centralityBins; +} + +TH2D* Calculator::getNptFile(TFile* infile, + const std::string& dirname, + const std::string& suffix, + const std::string& species, + const std::string& fallbackSuffix, + const std::string& profileSuffix) +{ + auto* hist = dynamic_cast( + infile->Get(Form("%s/npt%s_%s%s", dirname.c_str(), suffix.c_str(), species.c_str(), profileSuffix.c_str()))); + + if (!hist && suffix != fallbackSuffix) { + hist = dynamic_cast( + infile->Get(Form("%s/npt%s_%s%s", dirname.c_str(), fallbackSuffix.c_str(), species.c_str(), profileSuffix.c_str()))); + } + + if (hist) { + hist->SetDirectory(0); + } + + return hist; +} + +void Calculator::loadFractionHists(TFile* infile, std::string dirname, std::string suffix, RadialFlowAnalysis& radialFlowStruct, const std::string& profileSuffix) +{ + const std::string fallbackSuffix = profileSuffix.empty() ? "" : suffix; + std::vector species = {"ch", "pi", "ka", "pr"}; + int i = 0; + for (const auto& sp : species) { + radialFlowStruct.fraction_cent[i] = getNptFile(infile, dirname, suffix, sp, fallbackSuffix, profileSuffix); + ++i; + } + + radialFlowStruct.fraction_cent_K0[0] = getNptFile(infile, dirname, suffix, "K0_sb1", fallbackSuffix, profileSuffix); + radialFlowStruct.fraction_cent_K0[1] = getNptFile(infile, dirname, suffix, "K0_sig", fallbackSuffix, profileSuffix); + radialFlowStruct.fraction_cent_K0[2] = getNptFile(infile, dirname, suffix, "K0_sb2", fallbackSuffix, profileSuffix); + radialFlowStruct.fraction_cent_Lambda[0] = getNptFile(infile, dirname, suffix, "Lambda_sb1", fallbackSuffix, profileSuffix); + radialFlowStruct.fraction_cent_Lambda[1] = getNptFile(infile, dirname, suffix, "Lambda_sig", fallbackSuffix, profileSuffix); + radialFlowStruct.fraction_cent_Lambda[2] = getNptFile(infile, dirname, suffix, "Lambda_sb2", fallbackSuffix, profileSuffix); +} + +void Calculator::clearFractionHists(RadialFlowAnalysis& radialFlowStruct) +{ + for (auto*& hist : radialFlowStruct.fraction_cent) { + delete hist; + hist = nullptr; + } + for (auto*& hist : radialFlowStruct.fraction_cent_K0) { + delete hist; + hist = nullptr; + } + for (auto*& hist : radialFlowStruct.fraction_cent_Lambda) { + delete hist; + hist = nullptr; + } +} + +void Calculator::clearInputData() +{ + activeFlowContainer = nullptr; + activeFlowContainerSample = -2; + hasChGap3pcW22 = false; + corr_list = nullptr; // Owned by flowptcont. + delete flowcont; + flowcont = nullptr; + delete flowptcont; + flowptcont = nullptr; + delete flowptcontfull; + flowptcontfull = nullptr; + clearFractionHists(radialFlowV02); + clearFractionHists(radialFlowV0); + clearFractionHists(radialFlowV02Weighted); + clearFractionHists(radialFlowV0Weighted); +} + +bool Calculator::readData(TFile* infile, std::string dirname, bool isGen, bool isRadialFlow) +{ + if (!infile) { + return false; + } + clearInputData(); + systematicIndex = is_digits(dirname) ? std::atoi(dirname.c_str()) : 0; + if (dirname.empty()) { + // std::cout << "Accessing base directory "; + dirname = (collision_system == "OO" || collision_system == "NeNe" || collision_system == "pO") ? "flow-gfw-light-ions" : "flow-generic-framework"; + // std::cout << dirname.c_str() << std::endl; + } else { + if (is_digits(dirname)) { + std::cout << "Reading sys index " << dirname.c_str(); + dirname = padWithZeros(std::atoi(dirname.c_str()), 3); + //(collision_system == "OO" || collision_system == "NeNe" || collision_system == "pO") ? dirname.insert(0, "flow-gfw-light-ions_") : dirname.insert(0, "flow-generic-framework_"); + (collision_system == "LI") ? dirname.insert(0, "flow-gfw-light-ions_") : dirname.insert(0, "flow-generic-framework_"); + std::cout << " in " << dirname.c_str() << std::endl; + } + // else { + // (collision_system == "OO" || collision_system == "NeNe" || collision_system == "pO") ? dirname.insert(0, "flow-gfw-light-ions_") : dirname.insert(0, "flow-generic-framework_"); + // std::cout << "Reading from directory " << dirname.c_str() << std::endl; + // } + } + TDirectory* inputDirectory = infile->GetDirectory(dirname.c_str()); + if (!inputDirectory) { + std::cout << "No input directory " << dirname << std::endl; + return false; + } + auto takeFromInputDirectory = [inputDirectory](const char* name) -> TObject* { + TObject* object = inputDirectory->Get(name); + if (object) { + // The Calculator owns the active variation. Removing it from the ROOT + // directory lets us release it when the next variation is loaded. + inputDirectory->Remove(object); + } + return object; + }; + + // Get flow containers and transfer ownership from the input directory. + flowcont = dynamic_cast(takeFromInputDirectory(Form("FlowContainer%s", isGen ? "_gen" : ""))); + if (flowcont && flowcont->fProf) { + const std::string label = "ChGap3pcW22"; + for (TObject* object : TRangeDynCast(flowcont->fProf->GetYaxis()->GetLabels())) { + if (label == object->GetName()) { + hasChGap3pcW22 = true; + break; + } + } + } + // Combined processMC wagons keep reco and generated containers together. + // Older generated-only wagons used the unsuffixed FlowPtContainer name. + auto* generatedFlowPt = isGen ? dynamic_cast(inputDirectory->Get("FlowPtContainer_gen")) : nullptr; + const bool hasGeneratedFlowPt = generatedFlowPt && generatedFlowPt->getCovList() && generatedFlowPt->getCovList()->GetEntries() > 0; + const char* flowPtName = hasGeneratedFlowPt ? "FlowPtContainer_gen" : "FlowPtContainer"; + flowptcont = dynamic_cast(takeFromInputDirectory(flowPtName)); + if (!flowptcont) + std::cout << "No FlowPtContainer with name " << Form("%s/%s", dirname.c_str(), flowPtName) << std::endl; + const char* flowPtFullName = isGen && inputDirectory->Get("FlowPtContainerFull_gen") ? "FlowPtContainerFull_gen" : "FlowPtContainerFull"; + flowptcontfull = dynamic_cast(takeFromInputDirectory(flowPtFullName)); + if (!flowptcont && !flowptcontfull) { + std::cout << "No FlowPtContainer! Take care" << std::endl; + return 1; + } + if (flowptcontfull) + subeventInfo = checkSubeventInput(flowptcontfull); + if (!flowptcontfull) + subeventInfo = checkSubeventInput(flowptcont); + + // Get the vn-pt correlator profiles + corr_list = flowptcont->getCovList(); + + if (isRadialFlow) { + // Generated fractional spectra from processMC are isolated under MCGen. + // Keep the wagon root as a fallback for legacy generated-only files. + std::string fractionDirectory = dirname; + if (isGen && infile->Get((dirname + "/MCGen/npt_v02_K0_sig").c_str())) { + fractionDirectory += "/MCGen"; + } + loadFractionHists(infile, fractionDirectory, "_v02", radialFlowV02); + loadFractionHists(infile, fractionDirectory, "_v0", radialFlowV0); + loadFractionHists(infile, fractionDirectory, "_v02", radialFlowV02Weighted, "_w3pc"); + loadFractionHists(infile, fractionDirectory, "_v0", radialFlowV0Weighted, "_w2pc"); + + if (collision_system == "MCGen") + setUseTotal(true); + } + // if(fNrb) this->Rebin(fNrb,fBinEdges); + return 1; +} +TH1D* Calculator::calculate(ObsFunc func, int i) +{ + std::unique_ptr prepared = prepareFlowContainerSample(i); + if (i >= 0 && !prepared) + return nullptr; + FlowContainer* previousContainer = activeFlowContainer; + const int previousSample = activeFlowContainerSample; + struct ActiveContainerRestore { + FlowContainer*& container; + int& sample; + FlowContainer* previousContainer; + int previousSample; + ~ActiveContainerRestore() + { + container = previousContainer; + sample = previousSample; + } + } restore{activeFlowContainer, activeFlowContainerSample, previousContainer, previousSample}; + activeFlowContainer = i < 0 ? flowcont : prepared.get(); + activeFlowContainerSample = i; + return (this->*func)(i); +} +TH1D* Calculator::calculate(PtDiffFunc func, int i, double min, double max) +{ + std::unique_ptr prepared = prepareFlowContainerSample(i); + if (i >= 0 && !prepared) + return nullptr; + FlowContainer* previousContainer = activeFlowContainer; + const int previousSample = activeFlowContainerSample; + struct ActiveContainerRestore { + FlowContainer*& container; + int& sample; + FlowContainer* previousContainer; + int previousSample; + ~ActiveContainerRestore() + { + container = previousContainer; + sample = previousSample; + } + } restore{activeFlowContainer, activeFlowContainerSample, previousContainer, previousSample}; + activeFlowContainer = i < 0 ? flowcont : prepared.get(); + activeFlowContainerSample = i; + return (this->*func)(i, min, max); +} +TH1D* Calculator::calculateWithLateCentralityRebin(PtDiffFunc func, int i, double min, double max) +{ + if (!flowcont || !flowcont->GetProfile() || min >= max) { + std::cerr << "[Calculator::calculateWithLateCentralityRebin] Invalid FlowContainer or centrality range " + << min << "-" << max << std::endl; + return nullptr; + } + + std::unique_ptr prepared = prepareFlowContainerSample(i); + if (i >= 0 && !prepared) + return nullptr; + FlowContainer* previousContainer = activeFlowContainer; + const int previousSample = activeFlowContainerSample; + struct ActiveContainerRestore { + FlowContainer*& container; + int& sample; + FlowContainer* previousContainer; + int previousSample; + ~ActiveContainerRestore() + { + container = previousContainer; + sample = previousSample; + } + } restore{activeFlowContainer, activeFlowContainerSample, previousContainer, previousSample}; + activeFlowContainer = i < 0 ? flowcont : prepared.get(); + activeFlowContainerSample = i; + + // The centrality weights must not depend on pT, the requested observable, + // or the bootstrap sample. Use the nominal mean-pT precision as a single + // centrality reference for every late-rebinned observable. + std::unique_ptr centralityWeightReference; + if (useInverseVarianceWeight) + centralityWeightReference.reset(getMpt(-1)); + + TAxis* centralityAxis = flowcont->GetProfile()->GetXaxis(); + const int firstBin = centralityAxis->FindFixBin(min + 1.e-6); + const int lastBin = centralityAxis->FindFixBin(max - 1.e-6); + const int previousFitLookupCentMin = invMassFitLookupCentMin; + const int previousFitLookupCentMax = invMassFitLookupCentMax; + invMassFitLookupCentMin = fitCentEdge(min); + invMassFitLookupCentMax = fitCentEdge(max); + TH1D* result = nullptr; + std::vector weightedSums; + std::vector weightSums; + std::vector errorSquareSums; + + for (int centralityBin = firstBin; centralityBin <= lastBin; ++centralityBin) { + if (centralityBin < 1 || centralityBin > centralityAxis->GetNbins()) + continue; + const double binMin = centralityAxis->GetBinLowEdge(centralityBin); + const double binMax = centralityAxis->GetBinUpEdge(centralityBin); + TH1D* fineBinObservable = nullptr; + { + // ROOT normally registers every projection and clone in gDirectory. + // A late-rebin calculation creates many such intermediates per native + // centrality bin. Keep them in a short-lived directory and retain only + // the observable returned by the requested Calculator function. Attach + // it to gROOT so an open output file does not persist the scratch keys. + TDirectoryFile scratchDirectory( + Form("lateCentralityScratch_%d_%d", i, centralityBin), "", "", gROOT); + TDirectory::TContext directoryContext(&scratchDirectory); + fineBinObservable = (this->*func)(i, binMin, binMax); + if (fineBinObservable) { + fineBinObservable->SetDirectory(nullptr); + } + } + if (!fineBinObservable) + continue; + + if (!result) { + result = dynamic_cast(fineBinObservable->Clone( + Form("%s_lateCentralityRebin_%.1f_%.1f", fineBinObservable->GetName(), min, max))); + result->SetDirectory(nullptr); + result->Reset(); + weightedSums.assign(result->GetNbinsX() + 2, 0.); + weightSums.assign(result->GetNbinsX() + 2, 0.); + errorSquareSums.assign(result->GetNbinsX() + 2, 0.); + } + + // Use one scalar centrality weight for the complete pT vector. Weighting + // every pT bin independently gives every bin a different effective + // centrality distribution and does not preserve moment sum rules. + double centralityWeight = 1.; + if (centralityWeightReference) { + const int weightBin = centralityWeightReference->GetXaxis()->FindFixBin( + 0.5 * (binMin + binMax)); + const double referenceError = centralityWeightReference->GetBinError(weightBin); + if (std::isfinite(referenceError) && referenceError > 0.) + centralityWeight = 1. / (referenceError * referenceError); + } + for (int ptBin = 0; ptBin <= fineBinObservable->GetNbinsX() + 1; ++ptBin) { + const double value = fineBinObservable->GetBinContent(ptBin); + const double error = fineBinObservable->GetBinError(ptBin); + if (!std::isfinite(value) || !std::isfinite(error) || error <= 0.) + continue; + weightedSums[ptBin] += value * centralityWeight; + weightSums[ptBin] += centralityWeight; + errorSquareSums[ptBin] += centralityWeight * centralityWeight * error * error; + } + delete fineBinObservable; + } + + if (!result) { + invMassFitLookupCentMin = previousFitLookupCentMin; + invMassFitLookupCentMax = previousFitLookupCentMax; + std::cerr << "[Calculator::calculateWithLateCentralityRebin] No native centrality bins in range " + << min << "-" << max << std::endl; + return nullptr; + } + for (int ptBin = 0; ptBin <= result->GetNbinsX() + 1; ++ptBin) { + if (weightSums[ptBin] <= 0.) + continue; + result->SetBinContent(ptBin, weightedSums[ptBin] / weightSums[ptBin]); + result->SetBinError(ptBin, std::sqrt(errorSquareSums[ptBin]) / weightSums[ptBin]); + } + invMassFitLookupCentMin = previousFitLookupCentMin; + invMassFitLookupCentMax = previousFitLookupCentMax; + return result; +} +void Calculator::Rebin(int nrb, double* chbins) +{ + if (!flowcont || !flowptcont || !corr_list) + return; + flowcont->SetMultiRebin(nrb, chbins); + flowptcont->rebinMulti(nrb, chbins); + TIter next(corr_list); + TObject* obj; + while ((obj = next())) { + BootstrapProfile* bspf = dynamic_cast(obj); + bspf->RebinMulti(nrb, chbins); + } + return; +} + +TH1D* Calculator::getK2Norm(int i) +{ + TH1* reth = getK2(i); + TH1* mpt = getMpt(i); + mpt->Multiply(mpt); + reth->Divide(mpt); + return dynamic_cast(reth); +} +TH1D* Calculator::getK3Norm(int i) +{ + TH1* reth = getK3(i); + TH1* mpt = getMpt(i); + mpt->Multiply(mpt); + mpt->Multiply(mpt); + reth->Divide(mpt); + return dynamic_cast(reth); +} +TH1D* Calculator::getDeltaPtOverPt(int i) +{ + TH1D* mu2 = getMu2(i); + TH1D* mpt = getMpt(i); + TH1D* reth = powerHistogram(mu2, 0.5); + reth->Divide(mpt); + return dynamic_cast(reth); +} + +TH1D* Calculator::getStdSkew(int i) +{ + TH1D* reth = getK3(i); + TH1D* k2 = getK2(i); + reth->Divide(powerHistogram(k2, 3. / 2)); + reth->SetName(Form("stdskew%i", i)); + return reth; +} +TH1D* Calculator::getIntSkew(int i) +{ + TH1D* reth = getK3(i); + TH1D* k2 = getK2(i); + TH1D* k1 = getMpt(i); + reth->Multiply(k1); + reth->Divide(powerHistogram(k2, 2)); + reth->SetName(Form("intskew%i", i)); + return reth; +} +TH1D* Calculator::getExKur(int i) +{ + TH1D* reth = getK4(i); + TH1D* k2 = getK2(i); + reth->Divide(powerHistogram(k2, 2)); + reth->SetName(Form("exkur%i", i)); + return reth; +} +TH1D* Calculator::getMptSubAvg(int i) +{ + if (subeventInfo.first < 2) { + std::cout << "Not enough subevents (" << subeventInfo.first << ")" << std::endl; + return nullptr; + } + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + if (subeventInfo.second == 2) { + + TH1* reth = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2"))->getHist(i); + reth->Add(pt1_sub2, 1); + reth->Scale(0.5); + reth->SetName(Form("MptSubAvg%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 3) { + TH1* reth = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3"))->getHist(i); + reth->Add(pt1_sub2, 1); + reth->Scale(0.5); + reth->SetName(Form("MptSubAvg%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 4) { + TH1* reth = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i); + reth->Add(pt1_sub2, 1); + reth->Scale(0.5); + reth->SetName(Form("MptSubAvg%i", i)); + return dynamic_cast(reth); + } + TH1* reth = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Add(pt1_sub1, -1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); +} +// Subevent pt-pt correlations +TH1D* Calculator::getK2sub(int i) +{ + if (subeventInfo.first < 2) { + std::cout << "Not enough particles (" << subeventInfo.first << ") correlated" << std::endl; + return nullptr; + } + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + if (subeventInfo.second == 2) { + + TH1* reth = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2"))->getHist(i); + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Add(pt1_sub1, -1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 3) { + TH1* reth = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_1sub3"))->getHist(i); + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Add(pt1_sub1, -1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 4) { + TH1* reth = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_1sub4"))->getHist(i); + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Add(pt1_sub1, -1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + TH1* reth = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Add(pt1_sub1, -1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); +} +TH1D* Calculator::getMu2sub(int i) +{ + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubCMList; + TH1* reth = ((BootstrapProfile*)l->FindObject("cm2_11sub1_11sub2"))->getHist(i); + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("cm1_sub1_Mpt0"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("cm1_sub2_Mpt0"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Add(pt1_sub1, -1); + return dynamic_cast(reth); +} +TH1D* Calculator::getK2NormSub(int i) +{ + TList* l = (TList*)flowptcontfull->fSubList; + TH1* reth = getK2sub(i); + if (subeventInfo.second == 2) { + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 3) { + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 4) { + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2normsub%i", i)); + return dynamic_cast(reth); +} +TH1D* Calculator::getK3NormSub(int i) +{ + if (subeventInfo.first < 3) { + std::cout << "Not enough particles (" << subeventInfo.first << ") correlated" << std::endl; + return nullptr; + } + if (subeventInfo.second < 3) { + std::cout << "Not enough subevents (" << subeventInfo.second << ") to calculate" << std::endl; + return nullptr; + } + TList* l = (TList*)flowptcontfull->fSubList; + TH1* reth = getK3sub(i); + if (subeventInfo.second == 3) { + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3"))->getHist(i); + TH1* pt1_sub3 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + pt1_sub1->Multiply(pt1_sub3); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 4) { + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_sub3 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i); + TH1* pt1_sub4 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i); + TH1D* pt_sub124 = (TH1D*)pt1_sub1->Clone(Form("sub124_%s", pt1_sub1->GetName())); + TH1D* pt_sub134 = (TH1D*)pt1_sub1->Clone(Form("sub134_%s", pt1_sub1->GetName())); + pt_sub124->Multiply(pt1_sub2); + pt_sub124->Multiply(pt1_sub4); + pt_sub134->Multiply(pt1_sub3); + pt_sub134->Multiply(pt1_sub4); + pt_sub134->Add(pt_sub124); + pt_sub134->Scale(0.5); + reth->Divide(pt_sub134); + reth->SetName(Form("k3normsub%i", i)); + return dynamic_cast(reth); + } + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2normsub%i", i)); + return dynamic_cast(reth); +} +TH1D* Calculator::getK3sub(int i) +{ + + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + // Consider 2 particles from subevent 1 + TH1* term1_1 = ((BootstrapProfile*)l->FindObject("mpt_2sub1_1sub2_3par"))->getHist(i); + + TH1* term2_1 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + term2_1->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + TH1* term3_1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_2par"))->getHist(i); + term3_1->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + TH1* term4_1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + term4_1->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + term4_1->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + term1_1->Add(term2_1, -2); + term1_1->Add(term3_1, -1); + term1_1->Add(term4_1, 2); + + // Now swap subevents to consider two particles from subevent 2 + TH1* term1_2 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_2sub2_3par"))->getHist(i); + + TH1* term2_2 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + term2_2->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + TH1* term3_2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_2par"))->getHist(i); + term3_2->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + TH1* term4_2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + term4_2->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + term4_2->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + term1_2->Add(term2_2, -2); + term1_2->Add(term3_2, -1); + term1_2->Add(term4_2, 2); + + // Take average of two cases + term1_2->Add(term1_1); + term1_2->Scale(0.5); + term1_2->SetName(Form("k3sub_%i", i)); + return dynamic_cast(term1_2); +} +TH1D* Calculator::getK3subA(int i) +{ + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + // Consider 2 particles from subevent 1 + TH1* term1 = ((BootstrapProfile*)l->FindObject("mpt_2sub1_1sub2_3par"))->getHist(i); + + TH1* term2 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + term2->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + TH1* term3 = ((BootstrapProfile*)l->FindObject("mpt_sub1_2par"))->getHist(i); + term3->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + TH1* term4 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + term4->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + term4->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + term1->Add(term2, -2); + term1->Add(term3, -1); + term1->Add(term4, 2); + TH1* reth = (TH1*)term1->Clone(Form("k3subA_%i", i)); + return dynamic_cast(reth); +} +TH1D* Calculator::getK3subB(int i) +{ + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + + TH1* term1 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_2sub2_3par"))->getHist(i); + + TH1* term2 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + term2->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + TH1* term3 = ((BootstrapProfile*)l->FindObject("mpt_sub2_2par"))->getHist(i); + term3->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + TH1* term4 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + term4->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + term4->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + term1->Add(term2, -2); + term1->Add(term3, -1); + term1->Add(term4, 2); + TH1* reth = (TH1*)term1->Clone(Form("k3subB_%i", i)); + return dynamic_cast(reth); +} +TH1D* Calculator::getK3_3sub(int i) +{ + if (subeventInfo.first < 3) { + std::cout << "Not enough particles (" << subeventInfo.first << ") correlated" << std::endl; + return nullptr; + } + if (subeventInfo.second < 3) { + std::cout << "Not enough subevents (" << subeventInfo.second << ") to calculate" << std::endl; + return nullptr; + } + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + + if (subeventInfo.second == 3) { + TH1* term1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_1sub3"))->getHist(i); + + TH1* term2 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_0sub3"))->getHist(i); + term2->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3"))->getHist(i)); + + TH1* term3 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_1sub3"))->getHist(i); + term3->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3"))->getHist(i)); + + TH1* term4 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_1sub3"))->getHist(i); + term4->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3"))->getHist(i)); + + TH1* term5 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3"))->getHist(i); + term5->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3"))->getHist(i)); + term5->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3"))->getHist(i)); + + term1->Add(term2, -1); + term1->Add(term3, -1); + term1->Add(term4, -1); + term1->Add(term5, 2); + TH1* reth = (TH1*)term1->Clone(Form("k3sub_3sub_%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 4) { + TH1* term1_A = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_0sub3_1sub4"))->getHist(i); + + TH1* term2_A = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_0sub3_0sub4"))->getHist(i); + term2_A->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + TH1* term3_A = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_1sub4"))->getHist(i); + term3_A->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i)); + + TH1* term4_A = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_1sub4"))->getHist(i); + term4_A->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i)); + + TH1* term5_A = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + term5_A->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i)); + term5_A->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + term1_A->Add(term2_A, -1); + term1_A->Add(term3_A, -1); + term1_A->Add(term4_A, -1); + term1_A->Add(term5_A, 2); + + TH1* term1_B = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_1sub3_1sub4"))->getHist(i); + + TH1* term2_B = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_1sub3_0sub4"))->getHist(i); + term2_B->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + TH1* term3_B = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_1sub4"))->getHist(i); + term3_B->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i)); + + TH1* term4_B = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_1sub4"))->getHist(i); + term4_B->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i)); + + TH1* term5_B = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + term5_B->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i)); + term5_B->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + term1_B->Add(term2_B, -1); + term1_B->Add(term3_B, -1); + term1_B->Add(term4_B, -1); + term1_B->Add(term5_B, 2); + + term1_A->Add(term1_B); + term1_A->Scale(0.5); + TH1* reth = (TH1*)term1_A->Clone(Form("k3sub_3sub_%i", i)); + return dynamic_cast(reth); + } +} +TH1D* Calculator::getK3Norm_3sub(int i) +{ + if (subeventInfo.first < 3) { + std::cout << "Not enough particles (" << subeventInfo.first << ") correlated" << std::endl; + return nullptr; + } + if (subeventInfo.second < 3) { + std::cout << "Not enough subevents (" << subeventInfo.second << ") to calculate" << std::endl; + return nullptr; + } + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + TH1* reth = getK3_3sub(i); + if (subeventInfo.second == 3) { + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3"))->getHist(i); + TH1* pt1_sub3 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + pt1_sub1->Multiply(pt1_sub3); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2sub%i", i)); + return dynamic_cast(reth); + } + if (subeventInfo.second == 4) { + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_sub3 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i); + TH1* pt1_sub4 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i); + TH1D* pt_sub124 = (TH1D*)pt1_sub1->Clone(Form("sub124_%s", pt1_sub1->GetName())); + TH1D* pt_sub134 = (TH1D*)pt1_sub1->Clone(Form("sub134_%s", pt1_sub1->GetName())); + pt_sub124->Multiply(pt1_sub2); + pt_sub124->Multiply(pt1_sub4); + pt_sub134->Multiply(pt1_sub3); + pt_sub134->Multiply(pt1_sub4); + pt_sub134->Add(pt_sub124); + pt_sub134->Scale(0.5); + reth->Divide(pt_sub134); + reth->SetName(Form("k3normsub%i", i)); + return dynamic_cast(reth); + } + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + pt1_sub1->Multiply(pt1_sub2); + reth->Divide(pt1_sub1); + reth->SetName(Form("k2normsub%i", i)); + return dynamic_cast(reth); +} + +TH1D* Calculator::getMu3sub(int i) +{ + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubCMList; + // Consider 2 particles from subevent 1 + TH1* term1_1 = ((BootstrapProfile*)l->FindObject("cm3_22sub1_11sub2"))->getHist(i); + + TH1* term2_1 = ((BootstrapProfile*)l->FindObject("cm3_12sub1_11sub2"))->getHist(i); + term2_1->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub1_Mpt0"))->getHist(i)); + + TH1* term3_1 = ((BootstrapProfile*)l->FindObject("cm2_sub1_Mpt0"))->getHist(i); + term3_1->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub2_Mpt0"))->getHist(i)); + + TH1* term4_1 = ((BootstrapProfile*)l->FindObject("cm2_sub1_Mpt1"))->getHist(i); + term4_1->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub1_Mpt0"))->getHist(i)); + term4_1->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub2_Mpt0"))->getHist(i)); + + term1_1->Add(term2_1, -2); + term1_1->Add(term3_1, -1); + term1_1->Add(term4_1, 2); + + // Now swap subevents to consider two particles from subevent 2 + TH1* term1_2 = ((BootstrapProfile*)l->FindObject("cm3_11sub1_22sub2"))->getHist(i); + + TH1* term2_2 = ((BootstrapProfile*)l->FindObject("cm3_11sub1_12sub2"))->getHist(i); + term2_2->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub2_Mpt0"))->getHist(i)); + + TH1* term3_2 = ((BootstrapProfile*)l->FindObject("cm2_sub2_Mpt0"))->getHist(i); + term3_2->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub1_Mpt0"))->getHist(i)); + + TH1* term4_2 = ((BootstrapProfile*)l->FindObject("cm2_sub2_Mpt1"))->getHist(i); + term4_2->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub2_Mpt0"))->getHist(i)); + term4_2->Multiply(((BootstrapProfile*)l->FindObject("cm1_sub1_Mpt0"))->getHist(i)); + + term1_2->Add(term2_2, -2); + term1_2->Add(term3_2, -1); + term1_2->Add(term4_2, 2); + + // Take average of two cases + term1_2->Add(term1_1); + term1_2->Scale(0.5); + return dynamic_cast(term1_2); +} +TH1D* Calculator::getK4sub(int i) +{ + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + /* TH1* term1 = ((BootstrapProfile*)l->FindObject("corr_2sub1_2sub2_4par"))->getHist(i); + + TH1* term2 = ((BootstrapProfile*)l->FindObject("corr_2sub1_1sub2_3par"))->getHist(i); + term2->Multiply(((BootstrapProfile*)l->FindObject("corr_sub2_1par"))->getHist(i)); + + TH1* term3 = ((BootstrapProfile*)l->FindObject("corr_1sub1_2sub2_3par"))->getHist(i); + term3->Multiply(((BootstrapProfile*)l->FindObject("corr_sub1_1par"))->getHist(i)); + + TH1* term4 = ((BootstrapProfile*)l->FindObject("corr_sub1_2par"))->getHist(i); + term4->Multiply(((BootstrapProfile*)l->FindObject("corr_sub2_1par"))->getHist(i)); + term4->Multiply(((BootstrapProfile*)l->FindObject("corr_sub2_1par"))->getHist(i)); + + TH1* term5 = ((BootstrapProfile*)l->FindObject("corr_sub2_2par"))->getHist(i); + term5->Multiply(((BootstrapProfile*)l->FindObject("corr_sub1_1par"))->getHist(i)); + term5->Multiply(((BootstrapProfile*)l->FindObject("corr_sub1_1par"))->getHist(i)); + + TH1* term6 = ((BootstrapProfile*)l->FindObject("corr_1sub1_1sub2_2par"))->getHist(i); + term6->Multiply(((BootstrapProfile*)l->FindObject("corr_sub2_1par"))->getHist(i)); + term6->Multiply(((BootstrapProfile*)l->FindObject("corr_sub1_1par"))->getHist(i)); + + TH1* term7 = ((BootstrapProfile*)l->FindObject("corr_sub1_1par"))->getHist(i); + term7->Multiply(((BootstrapProfile*)l->FindObject("corr_sub1_1par"))->getHist(i)); + term7->Multiply(((BootstrapProfile*)l->FindObject("corr_sub2_1par"))->getHist(i)); + term7->Multiply(((BootstrapProfile*)l->FindObject("corr_sub2_1par"))->getHist(i)); + + term1->Add(term2,-2); + term1->Add(term3,-2); + term1->Add(term4,1); + term1->Add(term5,1); + term1->Add(term6,4); + term1->Add(term7,-3); */ + + TH1* term1 = ((BootstrapProfile*)l->FindObject("mpt_2sub1_2sub2_4par"))->getHist(i); + + TH1* term2 = ((BootstrapProfile*)l->FindObject("mpt_2sub1_1sub2_3par"))->getHist(i); + term2->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + TH1* term3 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_2sub2_3par"))->getHist(i); + term3->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + TH1* term4 = ((BootstrapProfile*)l->FindObject("mpt_sub1_2par"))->getHist(i); + term4->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_2par"))->getHist(i)); + + TH1* term5 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + term5->Multiply(term5); + + TH1* term6 = ((BootstrapProfile*)l->FindObject("mpt_sub1_2par"))->getHist(i); + term6->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + term6->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + TH1* term7 = ((BootstrapProfile*)l->FindObject("mpt_sub2_2par"))->getHist(i); + term7->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + term7->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + + TH1* term8 = ((BootstrapProfile*)l->FindObject("mpt_1sub1_1sub2_2par"))->getHist(i); + term8->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + term8->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + TH1* term9 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + term9->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i)); + term9->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + term9->Multiply(((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i)); + + term1->Add(term2, -2); + term1->Add(term3, -2); + term1->Add(term4, -1); + term1->Add(term5, -2); + term1->Add(term6, 2); + term1->Add(term7, 2); + term1->Add(term8, 8); + term1->Add(term9, -6); + + return dynamic_cast(term1); +} +TH1D* Calculator::getK4_4sub(int i) +{ + if (subeventInfo.first < 4) { + std::cout << "Not enough particles (" << subeventInfo.first << ") correlated" << std::endl; + return nullptr; + } + if (subeventInfo.second < 4) { + std::cout << "Not enough subevents (" << subeventInfo.second << ") to calculate" << std::endl; + return nullptr; + } + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubList; + // Consider 4 particles from subevent 1 + TH1* term1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_1sub3_1sub4"))->getHist(i); + + TH1* term2 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_1sub3_0sub4"))->getHist(i); + term2->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + TH1* term3 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_0sub3_1sub4"))->getHist(i); + term3->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i)); + + TH1* term4 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_1sub3_1sub4"))->getHist(i); + term4->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i)); + + TH1* term5 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_1sub3_1sub4"))->getHist(i); + term5->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i)); + + TH1* term6 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_0sub3_0sub4"))->getHist(i); + term6->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_1sub4"))->getHist(i)); + + TH1* term7 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_1sub3_0sub4"))->getHist(i); + term7->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_1sub4"))->getHist(i)); + + TH1* term8 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_1sub4"))->getHist(i); + term8->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_1sub3_0sub4"))->getHist(i)); + + TH1* term9 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_1sub2_0sub3_0sub4"))->getHist(i); + term9->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i)); + term9->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + TH1* term10 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_1sub3_0sub4"))->getHist(i); + term10->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i)); + term10->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + TH1* term11 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_1sub4"))->getHist(i); + term11->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i)); + term11->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i)); + + TH1* term12 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_1sub3_0sub4"))->getHist(i); + term12->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i)); + term12->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + TH1* term13 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_1sub4"))->getHist(i); + term13->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i)); + term13->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i)); + + TH1* term14 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_1sub4"))->getHist(i); + term14->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i)); + term14->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i)); + + TH1* term15 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2_0sub3_0sub4"))->getHist(i); + term15->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i)); + term15->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i)); + term15->Multiply(((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_0sub3_1sub4"))->getHist(i)); + + term1->Add(term2, -1); + term1->Add(term3, -1); + term1->Add(term4, -1); + term1->Add(term5, -1); + + term1->Add(term6, -1); + term1->Add(term7, -1); + term1->Add(term8, -1); + + term1->Add(term9, 2); + term1->Add(term10, 2); + term1->Add(term11, 2); + term1->Add(term12, 2); + term1->Add(term13, 2); + term1->Add(term14, 2); + term1->Add(term15, -6); + + TH1* reth = (TH1*)term1->Clone(Form("k4sub_4sub_%i", i)); + return dynamic_cast(reth); +} + +TH1D* Calculator::getMu4sub(int i) +{ + TList* l = (TList*)((!flowptcontfull) ? flowptcont : flowptcontfull)->fSubCMList; + // Consider 2 particles from subevent 1 + TH1* term1 = ((BootstrapProfile*)l->FindObject("cm4_22sub1_11sub2"))->getHist(i); + + return dynamic_cast(term1); +} +TH1D* Calculator::getStdSkewSub(int i) +{ + TH1D* reth = getK3sub(i); + reth->SetName(Form("stdskew_k3sub_%i", i)); + TH1D* k2sub = getK2sub(i); + k2sub->SetName(Form("stdskew_k2sub_%i", i)); + reth->Divide(powerHistogram(k2sub, 3. / 2)); + reth->SetName(Form("stdskewsub%i", i)); + return reth; +} +TH1D* Calculator::getStdSkew_3sub(int i) +{ + TH1D* reth = getK3_3sub(i); + reth->SetName(Form("stdskew_k3_3sub_%i", i)); + // should take the appropriate subevent config for K2 based on the input file + TH1D* k2sub = getK2sub(i); + k2sub->SetName(Form("stdskew_k2_3sub_%i", i)); + reth->Divide(powerHistogram(k2sub, 3. / 2)); + reth->SetName(Form("stdskew_3sub%i", i)); + return reth; +} +TH1D* Calculator::getIntSkewSub(int i) +{ + TH1D* reth = getK3sub(i); + TH1D* k2sub = getK2sub(i); + TList* l = (TList*)flowptcontfull->fSubList; + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + pt1_sub1->Add(pt1_sub2, 1); + pt1_sub1->Scale(0.5); + reth->Multiply(pt1_sub1); + reth->Divide(powerHistogram(k2sub, 2)); + reth->SetName(Form("intskewsub%i", i)); + return reth; +} +TH1D* Calculator::getIntSkew_3sub(int i) +{ + TH1D* reth = getK3_3sub(i); + TH1D* k2sub = getK2sub(i); + TList* l = (TList*)flowptcontfull->fSubList; + TH1* pt1_subMid; + if (subeventInfo.second == 3) + pt1_subMid = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3"))->getHist(i); + if (subeventInfo.second == 4) { + pt1_subMid = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2_0sub3_0sub4"))->getHist(i); + TH1* pt1_subMidB = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_0sub2_1sub3_0sub4"))->getHist(i); + pt1_subMid->Add(pt1_subMidB); + pt1_subMid->Scale(0.5); + } + reth->Multiply(pt1_subMid); + reth->Divide(powerHistogram(k2sub, 2)); + reth->SetName(Form("intskew_3sub%i", i)); + return reth; +} +TH1D* Calculator::getIntSkewAvgSub(int i) +{ + TH1D* k3sub1 = getK3subA(i); + TH1D* k2sub = getK2sub(i); + TList* l = (TList*)flowptcontfull->fSubList; + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("mpt_sub1_1par"))->getHist(i); + + k3sub1->Multiply(pt1_sub1); + k3sub1->Divide(powerHistogram(k2sub, 2)); + + TH1D* k3sub2 = getK3subB(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("mpt_sub2_1par"))->getHist(i); + k3sub2->Multiply(pt1_sub2); + k3sub2->Divide(powerHistogram(k2sub, 2)); + + TH1* reth = (TH1*)k3sub1->Clone(Form("intskew_avg_sub_%i", i)); + reth->Add(k3sub2); + reth->Scale(0.5); + reth->SetName(Form("intskewavgsub%i", i)); + return dynamic_cast(reth); +} +TH1D* Calculator::getExKurSub(int i) +{ + TH1D* reth = getK4sub(i); + TH1D* k2sub = getK2sub(i); + k2sub->SetName(Form("k2subExKur_%i", i)); + reth->Divide(powerHistogram(k2sub, 2)); + reth->SetName(Form("exkursub%i", i)); + return reth; +} +TH1D* Calculator::getExKur_4sub(int i) +{ + TH1D* reth = getK4_4sub(i); + TH1D* k2sub = getK2sub(i); + k2sub->SetName(Form("k2_4sub_ExKur_%i", i)); + reth->Divide(powerHistogram(k2sub, 2)); + reth->SetName(Form("exkur_4sub%i", i)); + return reth; +} +TH1D* Calculator::getV32overV22(int i) +{ + TH1D* reth = getVNN(3, 2, "ChGap", i); + TH1D* v2 = getVNN(2, 2, "ChGap", i); + reth->Divide(v2); + reth->GetYaxis()->SetTitle("v_{3}{2}/v_{2}{2}"); + return reth; +} +TH1D* Calculator::getV24overV22(int i) +{ + TH1D* reth = getVNN(2, 4, "ChFull", i); + TH1D* v2 = getVNN(2, 2, "ChGap", i); + reth->Divide(v2); + reth->GetYaxis()->SetTitle("v_{2}{4}/v_{2}{2}"); + return reth; +} +TH1D* Calculator::getVarV22(int i) +{ + auto reth = getCNN(2, 4, "ChFull", i); + auto c22gap = getCNN(2, 2, "ChGap", i); + c22gap->Multiply(c22gap); + reth->Add(c22gap); + return reth; +} +TH1D* Calculator::getV24_3sub(int i) +{ + TH1D* reth = getC24_3sub(i); + reth->Scale(-1.); + reth = powerHistogram(reth, 0.25); + return reth; +} +TH1D* Calculator::getVPt24_3sub(int i, double min, double max) +{ + TH1D* reth = getD24_3sub(i, min, max); + reth->Scale(-1.); + TH1D* c4 = getC24_3sub(i); + double c4_val = getIntegratedValue(c4, min, max); + reth->Scale(std::pow(-c4_val, -3. / 4)); + return reth; +} +TH1D* Calculator::getVPt24_3sub_avgOnVn(int i, double min, double max) +{ + TH1D* hD2LpLMR = getD2LpLMR(i, min, max); + hD2LpLMR->Scale(-1.); + TH1D* c2LLMR = getC2LLMR(i); + double c2LLMR_val = getIntegratedValue(c2LLMR, min, max); + hD2LpLMR->Scale(std::pow(-c2LLMR_val, -3. / 4)); + + TH1D* hD2LLMpR = getD2LLMpR(i, min, max); + hD2LLMpR->Scale(-1.); + hD2LLMpR->Scale(std::pow(-c2LLMR_val, -3. / 4)); + + TH1D* hD2LLMRp = getD2LLMRp(i, min, max); + hD2LLMRp->Scale(-1.); + hD2LLMRp->Scale(std::pow(-c2LLMR_val, -3. / 4)); + + TH1D* hD2LpMMR = getD2LpMMR(i, min, max); + hD2LpMMR->Scale(-1.); + TH1D* c2LMMR = getC2LMMR(i); + double c2LMMR_val = getIntegratedValue(c2LMMR, min, max); + hD2LpMMR->Scale(std::pow(-c2LMMR_val, -3. / 4)); + + TH1D* hD2LMpMR = getD2LMpMR(i, min, max); + hD2LMpMR->Scale(-1.); + hD2LMpMR->Scale(std::pow(-c2LMMR_val, -3. / 4)); + + TH1D* hD2LMMRp = getD2LMMRp(i, min, max); + hD2LMMRp->Scale(-1.); + hD2LMMRp->Scale(std::pow(-c2LMMR_val, -3. / 4)); + + TH1D* hD2LpMRR = getD2LpMRR(i, min, max); + hD2LpMRR->Scale(-1.); + TH1D* c2LMRR = getC2LMRR(i); + double c2LMRR_val = getIntegratedValue(c2LMRR, min, max); + hD2LpMRR->Scale(std::pow(-c2LMRR_val, -3. / 4)); + + TH1D* hD2LMpRR = getD2LMpRR(i, min, max); + hD2LMpRR->Scale(-1.); + hD2LMpRR->Scale(std::pow(-c2LMRR_val, -3. / 4)); + + TH1D* hD2LMRpR = getD2LMRpR(i, min, max); + hD2LMRpR->Scale(-1.); + hD2LMRpR->Scale(std::pow(-c2LMRR_val, -3. / 4)); + + /* for(int bin = 1; bin<=reth->GetNbinsX(); ++bin){ + double be_LpLMR = d2LpLMR->GetBinError(bin); + double be_LLMpR = d2LLMpR->GetBinError(bin); + double be_LLMRp = d2LLMRp->GetBinError(bin); + + double be_LpMMR = d2LpMMR->GetBinError(bin); + double be_LMpMR = d2LMpMR->GetBinError(bin); + double be_LMMRp = d2LMMRp->GetBinError(bin); + + double be_LpMRR = d2LpMRR->GetBinError(bin); + double be_LMpRR = d2LMpRR->GetBinError(bin); + double be_LMRRp = d2LMRRp->GetBinError(bin); + + if( be_LpLMR == 0.|| be_LLMpR == 0. || be_LLMRp == 0. || be_LpMMR == 0. || be_LMpMR == 0. || be_LMMRp == 0. || be_LpMRR == 0. || be_LMpRR == 0. || be_LMRRp == 0.) { reth->SetBinContent(bin,-2.); reth->SetBinError(bin,0.); } + + double bc_LpLMR = d2LpLMR->GetBinContent(bin); + double bc_LLMpR = d2LLMpR->GetBinContent(bin); + double bc_LLMRp = d2LLMRp->GetBinContent(bin); + + double bc_LpMMR = d2LpMMR->GetBinContent(bin); + double bc_LMpMR = d2LMpMR->GetBinContent(bin); + double bc_LMMRp = d2LMMRp->GetBinContent(bin); + + double bc_LpMRR = d2LpMRR->GetBinContent(bin); + double bc_LMpRR = d2LMpRR->GetBinContent(bin); + double bc_LMRRp = d2LMRRp->GetBinContent(bin); + + double sum = bc_LpLMR/(be_LpLMR*be_LpLMR) + bc_LLMpR/(be_LLMpR*be_LLMpR) + bc_LLMRp/(be_LLMRp*be_LLMRp) + + bc_LpMMR/(be_LpMMR*be_LpMMR) + bc_LMpMR/(be_LMpMR*be_LMpMR) + bc_LMMRp/(be_LMMRp*be_LMMRp) + + bc_LpMRR/(be_LpMRR*be_LpMRR) + bc_LMpRR/(be_LMpRR*be_LMpRR) + bc_LMRRp/(be_LMRRp*be_LMRRp); + double sumw = 1/(be_LpLMR*be_LpLMR) + 1/(be_LLMpR*be_LLMpR) + 1/(be_LLMRp*be_LLMRp) + + 1/(be_LpMMR*be_LpMMR) + 1/(be_LMpMR*be_LMpMR) + 1/(be_LMMRp*be_LMMRp) + + 1/(be_LpMRR*be_LpMRR) + 1/(be_LMpRR*be_LMpRR) + 1/(be_LMRRp*be_LMRRp); + double avg = sum/sumw; + reth->SetBinContent(bin,avg); + reth->SetBinError(bin,std::sqrt(1/sumw)); + } */ + + TH1D* reth = (TH1D*)hD2LpLMR->Clone("vpt24_3sub_avgOnVn"); + reth->Sumw2(); + reth->Add(hD2LLMpR); + reth->Add(hD2LLMRp); + reth->Add(hD2LpMMR); + reth->Add(hD2LMpMR); + reth->Add(hD2LMMRp); + reth->Add(hD2LpMRR); + reth->Add(hD2LMpRR); + reth->Add(hD2LMRpR); + reth->Scale(1.0 / 9); + return reth; +} +TH1D* Calculator::getC24_3sub(int i) +{ + TH1D* c2llmr = getC2LLMR(i); + TH1D* c2lmmr = getC2LMMR(i); + TH1D* c2lmrr = getC2LMRR(i); + + TH1D* reth = (TH1D*)c2llmr->Clone("c24_3sub"); + for (int bin = 1; bin <= reth->GetNbinsX(); ++bin) { + double be_llmr = c2llmr->GetBinError(bin); + double be_lmmr = c2lmmr->GetBinError(bin); + double be_lmrr = c2lmrr->GetBinError(bin); + if (be_llmr == 0. || be_lmmr == 0. || be_lmrr == 0.) { + reth->SetBinContent(bin, -2.); + reth->SetBinError(bin, 0.); + } + + double bc_llmr = c2llmr->GetBinContent(bin); + double bc_lmmr = c2lmmr->GetBinContent(bin); + double bc_lmrr = c2lmrr->GetBinContent(bin); + + double sum = bc_llmr / (be_llmr * be_llmr) + bc_lmmr / (be_lmmr * be_lmmr) + bc_lmrr / (be_lmrr * be_lmrr); + double sumw = 1 / (be_llmr * be_llmr) + 1 / (be_lmmr * be_lmmr) + 1 / (be_lmrr * be_lmrr); + double avg = sum / sumw; + reth->SetBinContent(bin, avg); + reth->SetBinError(bin, std::sqrt(1 / sumw)); + } + return reth; +} +TH1D* Calculator::getD24_3sub(int i, double min, double max) +{ + TH1D* d2LpLMR = getD2LpLMR(i, min, max); + TH1D* d2LLMpR = getD2LLMpR(i, min, max); + TH1D* d2LLMRp = getD2LLMRp(i, min, max); + + TH1D* d2LpMMR = getD2LpMMR(i, min, max); + TH1D* d2LMpMR = getD2LMpMR(i, min, max); + TH1D* d2LMMRp = getD2LMMRp(i, min, max); + + TH1D* d2LpMRR = getD2LpMRR(i, min, max); + TH1D* d2LMpRR = getD2LMpRR(i, min, max); + TH1D* d2LMRRp = getD2LMRpR(i, min, max); + + TH1D* reth = (TH1D*)d2LpLMR->Clone("dpt24_3sub"); + for (int bin = 1; bin <= reth->GetNbinsX(); ++bin) { + double be_LpLMR = d2LpLMR->GetBinError(bin); + double be_LLMpR = d2LLMpR->GetBinError(bin); + double be_LLMRp = d2LLMRp->GetBinError(bin); + + double be_LpMMR = d2LpMMR->GetBinError(bin); + double be_LMpMR = d2LMpMR->GetBinError(bin); + double be_LMMRp = d2LMMRp->GetBinError(bin); + + double be_LpMRR = d2LpMRR->GetBinError(bin); + double be_LMpRR = d2LMpRR->GetBinError(bin); + double be_LMRRp = d2LMRRp->GetBinError(bin); + + if (be_LpLMR == 0. || be_LLMpR == 0. || be_LLMRp == 0. || be_LpMMR == 0. || be_LMpMR == 0. || be_LMMRp == 0. || be_LpMRR == 0. || be_LMpRR == 0. || be_LMRRp == 0.) { + reth->SetBinContent(bin, -2.); + reth->SetBinError(bin, 0.); + } + + double bc_LpLMR = d2LpLMR->GetBinContent(bin); + double bc_LLMpR = d2LLMpR->GetBinContent(bin); + double bc_LLMRp = d2LLMRp->GetBinContent(bin); + + double bc_LpMMR = d2LpMMR->GetBinContent(bin); + double bc_LMpMR = d2LMpMR->GetBinContent(bin); + double bc_LMMRp = d2LMMRp->GetBinContent(bin); + + double bc_LpMRR = d2LpMRR->GetBinContent(bin); + double bc_LMpRR = d2LMpRR->GetBinContent(bin); + double bc_LMRRp = d2LMRRp->GetBinContent(bin); + + double sum = bc_LpLMR / (be_LpLMR * be_LpLMR) + bc_LLMpR / (be_LLMpR * be_LLMpR) + bc_LLMRp / (be_LLMRp * be_LLMRp) + + bc_LpMMR / (be_LpMMR * be_LpMMR) + bc_LMpMR / (be_LMpMR * be_LMpMR) + bc_LMMRp / (be_LMMRp * be_LMMRp) + + bc_LpMRR / (be_LpMRR * be_LpMRR) + bc_LMpRR / (be_LMpRR * be_LMpRR) + bc_LMRRp / (be_LMRRp * be_LMRRp); + double sumw = 1 / (be_LpLMR * be_LpLMR) + 1 / (be_LLMpR * be_LLMpR) + 1 / (be_LLMRp * be_LLMRp) + + 1 / (be_LpMMR * be_LpMMR) + 1 / (be_LMpMR * be_LMpMR) + 1 / (be_LMMRp * be_LMMRp) + + 1 / (be_LpMRR * be_LpMRR) + 1 / (be_LMpRR * be_LMpRR) + 1 / (be_LMRRp * be_LMRRp); + double avg = sum / sumw; + reth->SetBinContent(bin, avg); + reth->SetBinError(bin, std::sqrt(1 / sumw)); + } + return reth; +} + +TH1D* Calculator::getV2LLMR(int i) +{ + TH1D* reth = getC2LLMR(i); + reth->Scale(-1.); + reth = powerHistogram(reth, 0.25); + return reth; +} +TH1D* Calculator::getV2LMMR(int i) +{ + TH1D* reth = getC2LMMR(i); + reth->Scale(-1.); + reth = powerHistogram(reth, 0.25); + return reth; +} +TH1D* Calculator::getV2LMRR(int i) +{ + TH1D* reth = getC2LMRR(i); + reth->Scale(-1.); + reth = powerHistogram(reth, 0.25); + return reth; +} +TH1D* Calculator::getC2LLMR(int i) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LLMR"); + reth = dynamic_cast(clone->GetHistCorrXXVsMulti("24", 0)); + clone->SetIDName("LM"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + clone->SetIDName("ChGap"); + TH1D* c2LR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + c2LM->Multiply(c2LR); + reth->Add(c2LM, -2); + return reth; +} +TH1D* Calculator::getC2LMMR(int i) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LMMR"); + reth = dynamic_cast(clone->GetHistCorrXXVsMulti("24", 0)); + clone->SetIDName("LM"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + clone->SetIDName("MR"); + TH1D* c2MR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + c2LM->Multiply(c2MR); + reth->Add(c2LM, -2); + return reth; +} +TH1D* Calculator::getC2LMRR(int i) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LMRR"); + reth = dynamic_cast(clone->GetHistCorrXXVsMulti("24", 0)); + clone->SetIDName("ChGap"); + TH1D* c2LR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + clone->SetIDName("MR"); + TH1D* c2MR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + c2LR->Multiply(c2MR); + reth->Add(c2LR, -2); + return reth; +} + +TH1D* Calculator::getD2LpLMR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("L'LMR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("L'M"); + TH1D* c2LpM = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + clone->SetIDName("L'R"); + TH1D* c2LR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LR_val = getIntegratedValue(c2LR, min, max); + c2LpM->Scale(c2LR_val); + reth->Add(c2LpM, -1); + + clone->SetIDName("L'M"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + clone->SetIDName("L'R"); + TH1D* c2LpR = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + double c2LM_val = getIntegratedValue(c2LM, min, max); + c2LpR->Scale(c2LM_val); + reth->Add(c2LpR, -1); + + return reth; +} +TH1D* Calculator::getD2LLMpR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LLM'R"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("LM'"); + TH1D* c2LMp = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + clone->SetIDName("L'R"); + TH1D* c2LR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LR_val = getIntegratedValue(c2LR, min, max); + c2LMp->Scale(c2LR_val); + reth->Add(c2LMp, -2); + + return reth; +} +TH1D* Calculator::getD2LLMRp(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LLMR'"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("L'M"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LM_val = getIntegratedValue(c2LM, min, max); + clone->SetIDName("LR'"); + TH1D* c2LRp = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + c2LRp->Scale(c2LM_val); + reth->Add(c2LRp, -2); + return reth; +} + +TH1D* Calculator::getD2LpMMR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("L'MMR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("L'M"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + clone->SetIDName("M'R"); + TH1D* c2LR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LR_val = getIntegratedValue(c2LR, min, max); + c2LM->Scale(c2LR_val); + reth->Add(c2LM, -2); + return reth; +} +TH1D* Calculator::getD2LMpMR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LM'MR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("LM'"); + TH1D* c2LMp = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + clone->SetIDName("M'R"); + TH1D* c2MR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2MR_val = getIntegratedValue(c2MR, min, max); + c2LMp->Scale(c2MR_val); + reth->Add(c2LMp, -1); + + clone->SetIDName("L'M"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LM_val = getIntegratedValue(c2LM, min, max); + clone->SetIDName("M'R"); + TH1D* c2MpR = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + c2MpR->Scale(c2LM_val); + reth->Add(c2MpR, -1); + + return reth; +} +TH1D* Calculator::getD2LMMRp(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LMMR'"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("L'M"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LM_val = getIntegratedValue(c2LM, min, max); + clone->SetIDName("MR'"); + TH1D* c2MRp = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + c2MRp->Scale(c2LM_val); + reth->Add(c2MRp, -2); + return reth; +} + +TH1D* Calculator::getD2LpMRR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("L'MRR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("L'R"); + TH1D* c2LpR = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + clone->SetIDName("M'R"); + TH1D* c2MR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2MR_val = getIntegratedValue(c2MR, min, max); + c2LpR->Scale(c2MR_val); + reth->Add(c2LpR, -2); + return reth; +} +TH1D* Calculator::getD2LMpRR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LM'RR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("L'R"); + TH1D* c2LM = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LM_val = getIntegratedValue(c2LM, min, max); + clone->SetIDName("M'R"); + TH1D* c2MpR = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + c2MpR->Scale(c2LM_val); + reth->Add(c2MpR, -2); + return reth; +} +TH1D* Calculator::getD2LMRpR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LMR'R"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + clone->SetIDName("LR'"); + TH1D* c2LRp = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + clone->SetIDName("M'R"); + TH1D* c2MR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2MR_val = getIntegratedValue(c2MR, min, max); + c2LRp->Scale(c2MR_val); + reth->Add(c2LRp, -1); + + clone->SetIDName("L'R"); + TH1D* c2LR = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + double c2LR_val = getIntegratedValue(c2LR, min, max); + clone->SetIDName("MR'"); + TH1D* c2MRp = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + c2MRp->Scale(c2LR_val); + reth->Add(c2MRp, -1); + return reth; +} + +TH1D* Calculator::get2LpLMR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("L'LMR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} +TH1D* Calculator::get2LLMpR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LLM'R"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} +TH1D* Calculator::get2LLMRp(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LLMR'"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} + +TH1D* Calculator::get2LpMMR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("L'MMR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} +TH1D* Calculator::get2LMpMR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LM'MR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} +TH1D* Calculator::get2LMMRp(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LMMR'"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} + +TH1D* Calculator::get2LpMRR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("L'MRR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} +TH1D* Calculator::get2LMpRR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LM'RR"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} +TH1D* Calculator::get2LMRpR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LMR'R"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("24", min, max)); + return reth; +} + +TH1D* Calculator::get2LRp(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("ChPGap"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + return reth; +} +TH1D* Calculator::get2LpR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("ChNGap"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + return reth; +} +TH1D* Calculator::get2LpM(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("L'M"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + return reth; +} +TH1D* Calculator::get2LMp(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LM'"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + return reth; +} +TH1D* Calculator::get2MpR(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("M'R"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + return reth; +} +TH1D* Calculator::get2MRp(int i, double min, double max) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("MR'"); + reth = dynamic_cast(clone->GetHistCorrXXVsPt("22", min, max)); + return reth; +} + +TH1D* Calculator::get2LR(int i) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("ChGap"); + reth = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + return reth; +} +TH1D* Calculator::get2LM(int i) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("LM"); + reth = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + return reth; +} +TH1D* Calculator::get2MR(int i) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName("MR"); + reth = dynamic_cast(clone->GetHistCorrXXVsMulti("22", 0)); + return reth; +} + +TH1D* Calculator::getCVN2pt(int nhar, int i) +{ + if (flowptcont->usesCentralMoments()) { + auto vn2mpt_profile = dynamic_cast(corr_list->FindObject(Form("%s%i2pt1_Mpt0", flowid.c_str(), nhar))); + auto vn2_mpt_profile = dynamic_cast(corr_list->FindObject(Form("%s%i2pt1_Mpt1", flowid.c_str(), nhar))); + auto mpt = getMpt(i); + TH1D* reth = dynamic_cast(vn2mpt_profile->getHist(i)); + TH1D* vn2_mpt = dynamic_cast(vn2_mpt_profile->getHist(i)); + vn2_mpt->Multiply(mpt); + reth->Add(vn2_mpt, -1); + return reth; + } + auto vn2mpt_profile = dynamic_cast(corr_list->FindObject(Form("%s%i2_mpt1", flowid.c_str(), nhar))); + TH1D* reth = dynamic_cast(vn2mpt_profile->getHist(i)); + auto vn2 = getNN(nhar, 2, flowid.c_str(), i); + auto mpt = getMpt(i); + vn2->Multiply(mpt); + reth->Add(vn2, -1); + return reth; +} +TH1D* Calculator::getRhoVN2pt(int nhar, int i) +{ + TH1D* reth = getCVN2pt(nhar, i); + TH1D* varv22 = getVarV22(i); + TH1D* ck = getMu2(i); + TH1D* sqrtck = powerHistogram(ck, 0.5); + TH1D* sqrtvarv22 = powerHistogram(varv22, 0.5); + sqrtck->Multiply(sqrtvarv22); + reth->Divide(sqrtck); + return reth; +} +TH1D* Calculator::getCV22pt2(int i) +{ + if (flowptcont->usesCentralMoments()) { + auto v22pt2_Mpt0_profile = dynamic_cast(corr_list->FindObject("ChGap22pt2_Mpt0")); + // First get the term + TH1D* reth = dynamic_cast(v22pt2_Mpt0_profile->getHist(i)); + auto mpt_hist = getMpt(i); + auto v22pt2_Mpt1_profile = dynamic_cast(corr_list->FindObject("ChGap22pt2_Mpt1")); + auto v22pt_pt = dynamic_cast(v22pt2_Mpt1_profile->getHist(i)); + v22pt_pt->Multiply(mpt_hist); + reth->Add(v22pt_pt); + auto v22_hist = getNN(2, 2, "ChGap", i); + auto mpt_sq_hist = dynamic_cast(mpt_hist->Clone("mpt_sq_hist")); + mpt_sq_hist->Multiply(mpt_hist); + auto v22_mptsq_hist = dynamic_cast(v22_hist->Clone("v22_mptsq_hist")); + v22_mptsq_hist->Multiply(mpt_sq_hist); + reth->Add(v22_mptsq_hist); + // Then subtract + auto v22_cm2_hist = dynamic_cast(v22_hist->Clone("v22_cm2_hist")); + v22_cm2_hist->Multiply(flowptcont->getCentralMomentHist(i, 2)); + reth->Add(v22_cm2_hist, -1); + return reth; + } + return nullptr; +} +TH1D* Calculator::getCV22pt3(int i) +{ + if (flowptcont->usesCentralMoments()) { + // First get the term + auto v22pt3_Mpt0_profile = dynamic_cast(corr_list->FindObject("ChGap22pt3_Mpt0")); + auto v22pt3_Mpt1_profile = dynamic_cast(corr_list->FindObject("ChGap22pt3_Mpt1")); + auto v22pt3_Mpt2_profile = dynamic_cast(corr_list->FindObject("ChGap22pt3_Mpt2")); + TH1D* reth = dynamic_cast(v22pt3_Mpt0_profile->getHist(i)); + auto mpt_hist = getMpt(i); + auto v22pt2_pt = dynamic_cast(v22pt3_Mpt1_profile->getHist(i)); + v22pt2_pt->Multiply(mpt_hist); + mpt_hist->Multiply(mpt_hist); + auto v22pt_pt2 = dynamic_cast(v22pt3_Mpt2_profile->getHist(i)); + v22pt_pt2->Multiply(mpt_hist); + mpt_hist->Multiply(mpt_hist); + auto v22_pt3 = getNN(2, 2, "ChGap", i); + v22_pt3->Multiply(mpt_hist); + reth->Add(v22pt2_pt, -1); + reth->Add(v22pt_pt2, -1); + reth->Add(v22_pt3, -1); + // Then subtract the 3 x * term + auto v22deltapt_deltapt2 = getCV22pt(i); + v22deltapt_deltapt2->Multiply(flowptcont->getCentralMomentHist(i, 2)); + reth->Add(v22deltapt_deltapt2, -3); + // And then subtract the * term + auto v22_deltapt3 = getNN(2, 2, "ChGap", i); + v22_deltapt3->Multiply(flowptcont->getCentralMomentHist(i, 3)); + reth->Add(v22_deltapt3, -1); + return reth; + } + return nullptr; +} +TH1D* Calculator::getCV22pt4(int i) +{ + if (flowptcont->usesCentralMoments()) { + // First get the term + auto v22pt4_Mpt0_profile = dynamic_cast(corr_list->FindObject("ChGap22pt4_Mpt0")); + auto v22pt4_Mpt1_profile = dynamic_cast(corr_list->FindObject("ChGap22pt4_Mpt1")); + auto v22pt4_Mpt2_profile = dynamic_cast(corr_list->FindObject("ChGap22pt4_Mpt2")); + auto v22pt4_Mpt3_profile = dynamic_cast(corr_list->FindObject("ChGap22pt4_Mpt3")); + TH1D* reth = dynamic_cast(v22pt4_Mpt0_profile->getHist(i)); + auto mpt_hist = getMpt(i); + auto v22pt3_pt = dynamic_cast(v22pt4_Mpt1_profile->getHist(i)); + v22pt3_pt->Multiply(mpt_hist); + mpt_hist->Multiply(mpt_hist); + auto v22pt2_pt2 = dynamic_cast(v22pt4_Mpt2_profile->getHist(i)); + v22pt2_pt2->Multiply(mpt_hist); + auto v22pt_pt3 = dynamic_cast(v22pt4_Mpt3_profile->getHist(i)); + v22pt_pt3->Multiply(mpt_hist); + mpt_hist->Multiply(mpt_hist); + auto v22_pt4 = getNN(2, 2, "ChGap", i); + v22_pt4->Multiply(mpt_hist); + reth->Add(v22pt3_pt, -1); + reth->Add(v22pt2_pt2, -1); + reth->Add(v22pt_pt3, -1); + reth->Add(v22_pt4, -1); + // Then subtract the 6 x * term + auto v22deltapt2_deltapt2 = getCV22pt2(i); + v22deltapt2_deltapt2->Multiply(flowptcont->getCentralMomentHist(i, 2)); + reth->Add(v22deltapt2_deltapt2, -6); + // Then subtract the 4 x * term + auto v22deltapt_deltapt3 = getCV22pt(i); + v22deltapt_deltapt3->Multiply(flowptcont->getCentralMomentHist(i, 3)); + reth->Add(v22deltapt_deltapt3, -4); + // Then add the 6 x ** term + auto v22_deltapt2_deltapt2 = getNN(2, 2, "ChGap", i); + v22_deltapt2_deltapt2->Multiply(flowptcont->getCentralMomentHist(i, 2)); + v22_deltapt2_deltapt2->Multiply(flowptcont->getCentralMomentHist(i, 2)); + reth->Add(v22_deltapt2_deltapt2, -4); + // Then subtract the * term + auto v22_deltapt4 = getNN(2, 2, "ChGap", i); + v22_deltapt4->Multiply(flowptcont->getCentralMomentHist(i, 4)); + reth->Add(v22_deltapt4, 1); + return reth; + } + return nullptr; +} +TH1D* Calculator::getCV24pt(int i) +{ + if (flowptcont->usesCentralMoments()) { + // First get the term + BootstrapProfile* v24pt_Mpt0_profile = dynamic_cast(corr_list->FindObject("ChGap24pt_Mpt0")); + TH1D* reth = dynamic_cast(v24pt_Mpt0_profile->getHist(i)); + auto v24_pt = getNN(2, 4, "ChGap", i); + auto mpt_hist = getMpt(i); + v24_pt->Multiply(mpt_hist); + reth->Add(v24_pt, -1); + // Then subtract the 4 x * term + auto v22pt_v22 = getCV22pt(i); + v22pt_v22->Multiply(getNN(2, 2, "ChGap", i)); + reth->Add(v22pt_v22, -4); + return reth; + } + return nullptr; +} +TH1D* Calculator::getCV24pt2(int i) +{ + if (flowptcont->usesCentralMoments()) { + // First get the term + auto v24pt2_profile = dynamic_cast(corr_list->FindObject("ChFull24pt2_Mpt0")); + auto v24pt_6w_profile = dynamic_cast(corr_list->FindObject("ChFull24pt2_Mpt1")); + auto v24_6w_profile = dynamic_cast(corr_list->FindObject("ChFull24pt2_Mpt2")); + auto reth = dynamic_cast(v24pt2_profile->getHist(i)); + auto v24pt_mpt = dynamic_cast(v24pt_6w_profile->getHist(i)); + auto mpt = getMpt(i); + v24pt_mpt->Multiply(mpt); + auto v24_mpt_mpt = dynamic_cast(v24_6w_profile->getHist(i)); + v24_mpt_mpt->Multiply(mpt); + v24_mpt_mpt->Multiply(mpt); + reth->Add(v24pt_mpt, -2); + reth->Add(v24_mpt_mpt); + + // Then subtract the 4 x * term + auto v22pt2_profile = dynamic_cast(corr_list->FindObject("ChFull22pt2_Mpt0")); + auto v22pt_4w_profile = dynamic_cast(corr_list->FindObject("ChFull22pt2_Mpt1")); + auto v22_4w_profile = dynamic_cast(corr_list->FindObject("ChFull22pt2_Mpt2")); + auto v22deltapt2_v22 = dynamic_cast(v22pt2_profile->getHist(i)); + auto v22pt_mpt = dynamic_cast(v22pt_4w_profile->getHist(i)); + v22pt_mpt->Multiply(mpt); + auto v22_mpt_mpt = dynamic_cast(v22_4w_profile->getHist(i)); + v22_mpt_mpt->Multiply(mpt); + v22_mpt_mpt->Multiply(mpt); + v22deltapt2_v22->Add(v22pt_mpt, -2); + v22deltapt2_v22->Add(v22_mpt_mpt); + v22deltapt2_v22->Multiply(getNN(2, 2, "ChFull", i)); + reth->Add(v22deltapt2_v22, -4); + + // Then subtract the 4 x * term + auto v22pt_profile = dynamic_cast(corr_list->FindObject("ChFull22pt1_Mpt0")); + auto v22_3w_profile = dynamic_cast(corr_list->FindObject("ChFull22pt1_Mpt1")); + auto v22deltapt_v22deltapt = dynamic_cast(v22pt_profile->getHist(i)); + auto v22_mpt = dynamic_cast(v22_3w_profile->getHist(i)); + v22_mpt->Multiply(mpt); + v22deltapt_v22deltapt->Add(v22_mpt, -1); + v22deltapt_v22deltapt->Multiply(v22deltapt_v22deltapt); + reth->Add(v22deltapt_v22deltapt, -4); + + // Then add the 4 x ** term + auto v22_v22_deltapt2 = getNN(2, 2, "ChFull", i); + v22_v22_deltapt2->Multiply(v22_v22_deltapt2); + v22_v22_deltapt2->Multiply(flowptcont->getCentralMomentHist(i, 2)); + reth->Add(v22_v22_deltapt2, 4); + + // Then subtract the * term + auto v24_deltapt2 = getNN(2, 4, "ChFull", i); + v24_deltapt2->Multiply(flowptcont->getCentralMomentHist(i, 2)); + reth->Add(v24_deltapt2, -1); + + return reth; + } + return nullptr; +} +// Radial flow analyis// +TH1D* Calculator::getProjectedFractionalSpectra(std::string sp, int pidIndex, double min, double max, FractionScheme scheme, bool combinedWeight) +{ + auto& analysis = scheme == FractionScheme::V02 ? (combinedWeight ? radialFlowV02Weighted : radialFlowV02) + : (combinedWeight ? radialFlowV0Weighted : radialFlowV0); + return pidIndex >= 0 && pidIndex < static_cast(analysis.fraction_cent.size()) + ? projectFraction(analysis.fraction_cent[pidIndex], sp, min, max) + : nullptr; +} +TH1D* Calculator::getProjectedFractionalK0Spectra(std::string sp, int resoIndex, double min, double max, FractionScheme scheme, bool combinedWeight) +{ + auto& analysis = scheme == FractionScheme::V02 ? (combinedWeight ? radialFlowV02Weighted : radialFlowV02) + : (combinedWeight ? radialFlowV0Weighted : radialFlowV0); + return resoIndex >= 0 && resoIndex < static_cast(analysis.fraction_cent_K0.size()) + ? projectFraction(analysis.fraction_cent_K0[resoIndex], sp, min, max) + : nullptr; +} +TH1D* Calculator::getProjectedFractionalLambdaSpectra(std::string sp, int resoIndex, double min, double max, FractionScheme scheme, bool combinedWeight) +{ + auto& analysis = scheme == FractionScheme::V02 ? (combinedWeight ? radialFlowV02Weighted : radialFlowV02) + : (combinedWeight ? radialFlowV0Weighted : radialFlowV0); + return resoIndex >= 0 && resoIndex < static_cast(analysis.fraction_cent_Lambda.size()) + ? projectFraction(analysis.fraction_cent_Lambda[resoIndex], sp, min, max) + : nullptr; +} + +TH1D* Calculator::getnpt(int i, int pidIndex, double min, double max) +{ + return getnpt(i, pidIndex, min, max, FractionScheme::V02); +} +TH1D* Calculator::getnpt(int i, int pidIndex, double min, double max, FractionScheme scheme, bool combinedWeight) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV0]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + TH1D* mean_fraction_pt = getProjectedFractionalSpectra(sp, pidIndex, min, max, scheme, combinedWeight); + if (!mean_fraction_pt) + return nullptr; + TH1D* reth = (TH1D*)mean_fraction_pt->Clone(Form("mpt_%snpt_%.1f_%.1f", sp.c_str(), min, max)); + reth->SetName(Form("npt%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getnptK0(int i, double min, double max) +{ + return getnptK0(i, min, max, FractionScheme::V02); +} +TH1D* Calculator::getnptK0(int i, double min, double max, FractionScheme scheme, bool combinedWeight) +{ + TH1D* mean_fraction_pt_tot = getProjectedFractionalK0Spectra("K0_sig", 1, min, max, scheme, combinedWeight); + if (!mean_fraction_pt_tot) + return nullptr; + + TH1D* npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("npt_K0_tot_%.1f_%.1f", min, max)); + if (useTotal) { + npt_tot->SetName(Form("nptK0_%i", i)); + return npt_tot; + } + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalK0Spectra("K0_sb1", 0, min, max, scheme, combinedWeight); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalK0Spectra("K0_sb2", 2, min, max, scheme, combinedWeight); + if (!mean_fraction_pt_sb1 || !mean_fraction_pt_sb2) { + delete npt_tot; + return nullptr; + } + TH1D* npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("npt_K0_sb1_%.1f_%.1f", min, max)); + TH1D* npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("npt_K0_sb2_%.1f_%.1f", min, max)); + + TH1D* npt_bkg = (TH1D*)npt_sb1->Clone(Form("v0_K0_bkg_%.1f_%.1f", min, max)); + npt_bkg->Add(npt_sb2, 1); + npt_bkg->Scale(0.5); + + TH1D* npt_sig = (TH1D*)npt_tot->Clone(Form("npt_K0_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, npt_sig, npt_bkg, "K0", min, max, "Calculator::getnptK0"); + npt_sig->SetName(Form("nptK0_%i", i)); + return npt_sig; +} +TH1D* Calculator::getnptLambda(int i, double min, double max) +{ + return getnptLambda(i, min, max, FractionScheme::V02); +} +TH1D* Calculator::getnptLambda(int i, double min, double max, FractionScheme scheme, bool combinedWeight) +{ + TH1D* mean_fraction_pt_tot = getProjectedFractionalLambdaSpectra("Lambda_sig", 1, min, max, scheme, combinedWeight); + if (!mean_fraction_pt_tot) + return nullptr; + + TH1D* npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("npt_Lambda_tot_%.1f_%.1f", min, max)); + if (useTotal) { + npt_tot->SetName(Form("nptLambda_%i", i)); + return npt_tot; + } + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalLambdaSpectra("Lambda_sb1", 0, min, max, scheme, combinedWeight); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalLambdaSpectra("Lambda_sb2", 2, min, max, scheme, combinedWeight); + if (!mean_fraction_pt_sb1 || !mean_fraction_pt_sb2) { + delete npt_tot; + return nullptr; + } + TH1D* npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("npt_Lambda_sb1_%.1f_%.1f", min, max)); + TH1D* npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("npt_Lambda_sb2_%.1f_%.1f", min, max)); + + TH1D* npt_bkg = (TH1D*)npt_sb1->Clone(Form("npt_Lambda_bkg_%.1f_%.1f", min, max)); + npt_bkg->Add(npt_sb2, 1); + npt_bkg->Scale(0.5); + + TH1D* npt_sig = (TH1D*)npt_tot->Clone(Form("npt_Lambda_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, npt_sig, npt_bkg, "Lambda", min, max, "Calculator::getnptLambda"); + npt_sig->SetName(Form("nptLambda_%i", i)); + return npt_sig; +} + +TH1D* Calculator::getV0Corr(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV0Corr]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + TH1D* reth = getCorrVsPt(2, 2, Form("ChMpt%s", sp.c_str()), i, min, max); + reth->SetName(Form("V0Corr%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getV0CorrK0(int i, double min, double max) +{ + TH1D* v0_tot = getCorrVsPt(2, 2, Form("ChMptK0s"), i, min, max); + if (useTotal) { + v0_tot->SetName(Form("V0CorrK0_%i", i)); + return v0_tot; + } + TH1D* v0_sb1 = getCorrVsPt(2, 2, Form("ChMptK0sSBL"), i, min, max); + TH1D* v0_sb2 = getCorrVsPt(2, 2, Form("ChMptK0sSBR"), i, min, max); + + TH1D* v0_bkg = (TH1D*)v0_sb1->Clone(Form("v0corr_K0_bkg_%.1f_%.1f", min, max)); + v0_bkg->Add(v0_sb2, 1); + v0_bkg->Scale(0.5); + + TH1D* v0_sig = (TH1D*)v0_tot->Clone(Form("v0corr_K0_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v0_sig, v0_bkg, "K0", min, max, "Calculator::getV0CorrK0"); + v0_sig->SetName(Form("V0CorrK0_%i", i)); + return v0_sig; +} +TH1D* Calculator::getV0CorrLambda(int i, double min, double max) +{ + TH1D* v0_tot = getCorrVsPt(2, 2, Form("ChMptLambda"), i, min, max); + if (useTotal) { + v0_tot->SetName(Form("V0CorrLambda_%i", i)); + return v0_tot; + } + TH1D* v0_sb1 = getCorrVsPt(2, 2, Form("ChMptLambdaSBL"), i, min, max); + TH1D* v0_sb2 = getCorrVsPt(2, 2, Form("ChMptLambdaSBR"), i, min, max); + + TH1D* v0_bkg = (TH1D*)v0_sb1->Clone(Form("v0corr_Lambda_bkg_%.1f_%.1f", min, max)); + v0_bkg->Add(v0_sb2, 1); + v0_bkg->Scale(0.5); + + TH1D* v0_sig = (TH1D*)v0_tot->Clone(Form("v0corr_Lambda_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v0_sig, v0_bkg, "Lambda", min, max, "Calculator::getV0CorrLambda"); + v0_sig->SetName(Form("V0CorrLambda_%i", i)); + return v0_sig; +} +TH1D* Calculator::getV0Cov(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV0Cov]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + TH1D* reth = getCorrVsPt(2, 2, Form("ChMpt%s", sp.c_str()), i, min, max); + TH1D* sub = getV0Means(i, pidIndex, min, max); + reth->Add(sub, -1); + reth->SetName(Form("V0Cov%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getV0CovK0(int i, double min, double max) +{ + TH1D* reth = getV0CorrK0(i, min, max); + TH1D* sub = getV0MeansK0(i, min, max); + reth->Add(sub, -1); + reth->SetName(Form("V0CovK0_%i", i)); + return reth; +} +TH1D* Calculator::getV0CovLambda(int i, double min, double max) +{ + TH1D* reth = getV0CorrLambda(i, min, max); + TH1D* sub = getV0MeansLambda(i, min, max); + reth->Add(sub, -1); + reth->SetName(Form("V0CovLambda_%i", i)); + return reth; +} + +TH1D* Calculator::getV0Means(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV0Means]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + TH1D* mean_fraction_pt = getProjectedFractionalSpectra(sp, pidIndex, min, max, FractionScheme::V0); + TH1D* mpt = getMpt(i); + TH1D* reth = (TH1D*)mean_fraction_pt->Clone(Form("mpt_%snpt_%.1f_%.1f", sp.c_str(), min, max)); + reth->Scale(getIntegratedValue(mpt, min, max)); + reth->SetName(Form("V0Means%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getV0MeansK0(int i, double min, double max) +{ + TH1D* mean_fraction_pt_tot = getProjectedFractionalK0Spectra("K0_sig", 1, min, max, FractionScheme::V0); + TH1D* mpt = getMpt(i); + TH1D* mpt_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("mpt_npt_K0_tot_%.1f_%.1f", min, max)); + mpt_npt_tot->Scale(getIntegratedValue(mpt, min, max)); + if (useTotal) { + mpt_npt_tot->SetName(Form("V0MeansK0_%i", i)); + return mpt_npt_tot; + } + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalK0Spectra("K0_sb1", 0, min, max, FractionScheme::V0); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalK0Spectra("K0_sb2", 2, min, max, FractionScheme::V0); + TH1D* mpt_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("mpt_npt_K0_sb1_%.1f_%.1f", min, max)); + mpt_npt_sb1->Scale(getIntegratedValue(mpt, min, max)); + TH1D* mpt_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("mpt_npt_K0_sb2_%.1f_%.1f", min, max)); + mpt_npt_sb2->Scale(getIntegratedValue(mpt, min, max)); + + TH1D* mpt_npt_bkg = (TH1D*)mpt_npt_sb1->Clone(Form("mpt_npt_K0_bkg_%.1f_%.1f", min, max)); + mpt_npt_bkg->Add(mpt_npt_sb2, 1); + mpt_npt_bkg->Scale(0.5); + + TH1D* mpt_npt_sig = (TH1D*)mpt_npt_tot->Clone(Form("mpt_npt_K0_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, mpt_npt_sig, mpt_npt_bkg, "K0", min, max, "Calculator::getV0MeansK0"); + mpt_npt_sig->SetName(Form("V0MeansK0_%i", i)); + return mpt_npt_sig; +} +TH1D* Calculator::getV0MeansLambda(int i, double min, double max) +{ + TH1D* mean_fraction_pt_tot = getProjectedFractionalLambdaSpectra("Lambda_sig", 1, min, max, FractionScheme::V0); + TH1D* mpt = getMpt(i); + TH1D* mpt_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("mpt_npt_Lambda_tot_%.1f_%.1f", min, max)); + mpt_npt_tot->Scale(getIntegratedValue(mpt, min, max)); + if (useTotal) { + mpt_npt_tot->SetName(Form("V0MeansLambda_%i", i)); + return mpt_npt_tot; + } + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalLambdaSpectra("Lambda_sb1", 0, min, max, FractionScheme::V0); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalLambdaSpectra("Lambda_sb2", 2, min, max, FractionScheme::V0); + TH1D* mpt_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("mpt_npt_Lambda_sb1_%.1f_%.1f", min, max)); + mpt_npt_sb1->Scale(getIntegratedValue(mpt, min, max)); + TH1D* mpt_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("mpt_npt_Lambda_sb2_%.1f_%.1f", min, max)); + mpt_npt_sb2->Scale(getIntegratedValue(mpt, min, max)); + + TH1D* mpt_npt_bkg = (TH1D*)mpt_npt_sb1->Clone(Form("mpt_npt_Lambda_bkg_%.1f_%.1f", min, max)); + mpt_npt_bkg->Add(mpt_npt_sb2, 1); + mpt_npt_bkg->Scale(0.5); + + TH1D* mpt_npt_sig = (TH1D*)mpt_npt_tot->Clone(Form("mpt_npt_Lambda_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, mpt_npt_sig, mpt_npt_bkg, "Lambda", min, max, "Calculator::getV0MeansLambda"); + mpt_npt_sig->SetName(Form("V0MeansLambda_%i", i)); + return mpt_npt_sig; +} +TH1D* Calculator::getV0(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV0]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + TH1D* reth = getV0Corr(i, pidIndex, min, max); + TH1D* npt = getnpt(i, pidIndex, min, max, FractionScheme::V0); + TH1D* mpt = getMpt(i); + + TH1D* mpt_npt = (TH1D*)npt->Clone(Form("mpt_%snpt_%.1f_%.1f", sp.c_str(), min, max)); + mpt_npt->Scale(getIntegratedValue(mpt, min, max)); + + TH1D* mu2 = getMu2sub(i); + mu2 = powerHistogram(mu2, 0.5); + TH1D* mu_npt = (TH1D*)npt->Clone(Form("mu_npt_%.1f_%.1f", min, max)); + mu_npt->Scale(getIntegratedValue(mu2, min, max)); + + reth->Add(mpt_npt, -1); + reth->Divide(mu_npt); + reth->SetName(Form("V0%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getFractionForSpecies(int i, int pidIndex, double min, double max, FractionScheme scheme, bool combinedWeight) +{ + // Fraction projections are temporary; keep them out of the output TFile. + TDirectoryFile scratchDirectory(Form("weightedFractionScratch_%d_%d", i, pidIndex), "", "", gROOT); + TDirectory::TContext directoryContext(&scratchDirectory); + TH1D* result = nullptr; + if (pidIndex >= 0 && pidIndex < ChargedSpeciesCount) + result = getnpt(i, pidIndex, min, max, scheme, combinedWeight); + else if (pidIndex == K0SpeciesIndex) + result = getnptK0(i, min, max, scheme, combinedWeight); + else if (pidIndex == LambdaSpeciesIndex) + result = getnptLambda(i, min, max, scheme, combinedWeight); + else + std::cerr << "[Calculator::getFractionForSpecies] Invalid species index " << pidIndex << std::endl; + if (result) + result->SetDirectory(nullptr); + return result; +} + +TH1D* Calculator::getCorrelationForSpecies(int i, int pidIndex, double min, double max, FractionScheme scheme) +{ + if (scheme == FractionScheme::V02) { + if (pidIndex >= 0 && pidIndex < ChargedSpeciesCount) + return getV02Corr(i, pidIndex, min, max); + if (pidIndex == K0SpeciesIndex) + return getV02CorrK0(i, min, max); + if (pidIndex == LambdaSpeciesIndex) + return getV02CorrLambda(i, min, max); + } else { + if (pidIndex >= 0 && pidIndex < ChargedSpeciesCount) + return getV0Corr(i, pidIndex, min, max); + if (pidIndex == K0SpeciesIndex) + return getV0CorrK0(i, min, max); + if (pidIndex == LambdaSpeciesIndex) + return getV0CorrLambda(i, min, max); + } + std::cerr << "[Calculator::getCorrelationForSpecies] Invalid species index " << pidIndex << std::endl; + return nullptr; +} + +TH1D* Calculator::getV0NumeratorWeighted(int i, int pidIndex, double min, double max) +{ + // _AB - _AB_B - _A_AB + _A_B. + static constexpr const char* ProfileNames[] = {"mpt1_w2pc_ch", "mpt1_w2pc_pi", "mpt1_w2pc_ka", "mpt1_w2pc_pr"}; + if (pidIndex < 0 || pidIndex > LambdaSpeciesIndex || !flowptcont || !flowptcont->getCorrList()) + return nullptr; + // K0 and Lambda use the charged-track normalization when cfgUsePIDTotal is false. + const char* profileName = ProfileNames[pidIndex < ChargedSpeciesCount ? pidIndex : 0]; + auto* profile = dynamic_cast(flowptcont->getCorrList()->FindObject(profileName)); + if (!profile) { + std::cerr << "[Calculator::getV0NumeratorWeighted] Missing " << profileName << std::endl; + return nullptr; + } + std::unique_ptr mA(dynamic_cast(flowptcont->getCorrHist(i, 1))); + std::unique_ptr mAB(dynamic_cast(profile->getHist(i))); + std::unique_ptr nB(getFractionForSpecies(i, pidIndex, min, max, FractionScheme::V0, false)); + std::unique_ptr nAB(getFractionForSpecies(i, pidIndex, min, max, FractionScheme::V0, true)); + if (!mA || !mAB || !nB || !nAB) { + std::cerr << "[Calculator::getV0NumeratorWeighted] Missing V0 fraction or mean-pT input for species " << pidIndex << std::endl; + return nullptr; + } + std::unique_ptr result(getCorrelationForSpecies(i, pidIndex, min, max, FractionScheme::V0)); + if (!result) + return nullptr; + const double meanA = getIntegratedValue(mA.get(), min, max); + const double meanAB = getIntegratedValue(mAB.get(), min, max); + if (!std::isfinite(meanA) || !std::isfinite(meanAB)) + return nullptr; + result->Add(nB.get(), meanA - meanAB); + result->Add(nAB.get(), -meanA); + result->SetName(Form("V0NumeratorWeighted_%d_%d_%.1f_%.1f", pidIndex, i, min, max)); + return result.release(); +} + +TH1D* Calculator::getV02NumeratorWeighted(int i, int pidIndex, double min, double max) +{ + // _ABC - _ABC_C - _AB_ABC + _AB_C. + if (pidIndex < 0 || pidIndex > LambdaSpeciesIndex || !hasChGap3pcW22) { + std::cerr << "[Calculator::getV02NumeratorWeighted] Missing ChGap3pcW22 or invalid species index" << std::endl; + return nullptr; + } + std::unique_ptr vAB(getCNN(2, 2, "ChGap", i)); + std::unique_ptr vABC(getCNN(2, 2, "ChGap3pcW", i)); + std::unique_ptr nC(getFractionForSpecies(i, pidIndex, min, max, FractionScheme::V02, false)); + std::unique_ptr nABC(getFractionForSpecies(i, pidIndex, min, max, FractionScheme::V02, true)); + if (!vAB || !vABC || !nC || !nABC) { + std::cerr << "[Calculator::getV02NumeratorWeighted] Missing V02 flow or fraction input for species " << pidIndex << std::endl; + return nullptr; + } + std::unique_ptr result(getCorrelationForSpecies(i, pidIndex, min, max, FractionScheme::V02)); + if (!result) + return nullptr; + const double meanAB = getIntegratedValue(vAB.get(), min, max); + const double meanABC = getIntegratedValue(vABC.get(), min, max); + if (!std::isfinite(meanAB) || !std::isfinite(meanABC)) + return nullptr; + result->Add(nC.get(), meanAB - meanABC); + result->Add(nABC.get(), -meanAB); + result->SetName(Form("V02NumeratorWeighted_%d_%d_%.1f_%.1f", pidIndex, i, min, max)); + return result.release(); +} + +TH1D* Calculator::getV0Weighted(int i, int pidIndex, double min, double max) +{ + std::unique_ptr result(getV0NumeratorWeighted(i, pidIndex, min, max)); + std::unique_ptr nB(getFractionForSpecies(i, pidIndex, min, max, FractionScheme::V0, false)); + std::unique_ptr mu2(getMu2sub(i)); + if (!result || !nB || !mu2) + return nullptr; + std::unique_ptr sigmaPt(powerHistogram(mu2.get(), 0.5)); + if (!sigmaPt) + return nullptr; + const double denominatorScale = getIntegratedValue(sigmaPt.get(), min, max); + if (!std::isfinite(denominatorScale)) + return nullptr; + nB->Scale(denominatorScale); + result->Divide(nB.get()); + result->SetName(Form("V0Weighted_%d_%d_%.1f_%.1f", pidIndex, i, min, max)); + result->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})"); + return result.release(); +} + +TH1D* Calculator::getV00Weighted(int i, int pidIndex, double min, double max) +{ + std::unique_ptr result(getV0NumeratorWeighted(i, pidIndex, min, max)); + std::unique_ptr nB(getFractionForSpecies(i, pidIndex, min, max, FractionScheme::V0, false)); + std::unique_ptr mA(dynamic_cast(flowptcont->getCorrHist(i, 1))); + if (!result || !nB || !mA) + return nullptr; + const double denominatorScale = getIntegratedValue(mA.get(), min, max); + if (!std::isfinite(denominatorScale)) + return nullptr; + nB->Scale(denominatorScale); + result->Divide(nB.get()); + result->SetName(Form("V00Weighted_%d_%d_%.1f_%.1f", pidIndex, i, min, max)); + result->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})"); + return result.release(); +} + +TH1D* Calculator::getV02Weighted(int i, int pidIndex, double min, double max) +{ + std::unique_ptr result(getV02NumeratorWeighted(i, pidIndex, min, max)); + std::unique_ptr nC(getFractionForSpecies(i, pidIndex, min, max, FractionScheme::V02, false)); + std::unique_ptr vAB(getCNN(2, 2, "ChGap", i)); + if (!result || !nC || !vAB) + return nullptr; + const double denominatorScale = getIntegratedValue(vAB.get(), min, max); + if (!std::isfinite(denominatorScale)) + return nullptr; + nC->Scale(denominatorScale); + result->Divide(nC.get()); + result->SetName(Form("V02Weighted_%d_%d_%.1f_%.1f", pidIndex, i, min, max)); + result->GetXaxis()->SetTitle("#it{p}_{T} (GeV/#it{c})"); + return result.release(); +} + +// Alternatives using the final V0 +TH1D* Calculator::getV0K0Alt(int i, double min, double max) +{ + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalK0Spectra("K0_sb1", 0, min, max, FractionScheme::V0); + TH1D* mean_fraction_pt_tot = getProjectedFractionalK0Spectra("K0_sig", 1, min, max, FractionScheme::V0); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalK0Spectra("K0_sb2", 2, min, max, FractionScheme::V0); + TH1D* v0_tot = getCorrVsPt(2, 2, Form("ChMptK0s"), i, min, max); + TH1D* v0_sb1 = getCorrVsPt(2, 2, Form("ChMptK0sSBL"), i, min, max); + TH1D* v0_sb2 = getCorrVsPt(2, 2, Form("ChMptK0sSBR"), i, min, max); + + TList* l = (TList*)flowptcont->fSubList; + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2"))->getHist(i); + TH1D* mpt = (TH1D*)pt1_sub1->Clone(Form("mpt_avg_%i", i)); + mpt->Add(pt1_sub2); + mpt->Scale(0.5); + TH1D* mpt_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v0_K0_tot_%.1f_%.1f", min, max)); + mpt_npt_tot->Scale(getIntegratedValue(mpt, min, max)); + TH1D* mpt_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v0_K0_sb1_%.1f_%.1f", min, max)); + mpt_npt_sb1->Scale(getIntegratedValue(mpt, min, max)); + TH1D* mpt_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v0_K0_sb2_%.1f_%.1f", min, max)); + mpt_npt_sb2->Scale(getIntegratedValue(mpt, min, max)); + + TH1D* mu2 = getMu2sub(i); + mu2 = powerHistogram(mu2, 0.5); + TH1D* mu_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v0_K0_den_tot_%.1f_%.1f", min, max)); + mu_npt_tot->Scale(getIntegratedValue(mu2, min, max)); + TH1D* mu_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v0_K0_den_sb1_%.1f_%.1f", min, max)); + mu_npt_sb1->Scale(getIntegratedValue(mu2, min, max)); + TH1D* mu_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v0_K0_den_sb2_%.1f_%.1f", min, max)); + mu_npt_sb2->Scale(getIntegratedValue(mu2, min, max)); + + v0_tot->Add(mpt_npt_tot, -1); + v0_tot->Divide(mu_npt_tot); + + v0_sb1->Add(mpt_npt_sb1, -1); + v0_sb1->Divide(mu_npt_sb1); + v0_sb2->Add(mpt_npt_sb2, -1); + v0_sb2->Divide(mu_npt_sb2); + + TH1D* v0_bkg = (TH1D*)v0_sb1->Clone(Form("v0_K0_bkg_%.1f_%.1f", min, max)); + v0_bkg->Add(v0_sb2, 1); + v0_bkg->Scale(0.5); + + TH1D* v0_sig = (TH1D*)v0_tot->Clone(Form("v0_K0_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v0_sig, v0_bkg, "K0", min, max, "Calculator::getV0K0"); + v0_sig->SetName(Form("V0K0_%i", i)); + return v0_sig; +} +TH1D* Calculator::getV0LambdaAlt(int i, double min, double max) +{ + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalLambdaSpectra("Lambda_sb1", 0, min, max, FractionScheme::V0); + TH1D* mean_fraction_pt_tot = getProjectedFractionalLambdaSpectra("Lambda_sig", 1, min, max, FractionScheme::V0); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalLambdaSpectra("Lambda_sb2", 2, min, max, FractionScheme::V0); + TH1D* v0_tot = getCorrVsPt(2, 2, Form("ChMptLambda"), i, min, max); + TH1D* v0_sb1 = getCorrVsPt(2, 2, Form("ChMptLambdaSBL"), i, min, max); + TH1D* v0_sb2 = getCorrVsPt(2, 2, Form("ChMptLambdaSBR"), i, min, max); + + TList* l = (TList*)flowptcont->fSubList; + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2"))->getHist(i); + TH1D* mpt = (TH1D*)pt1_sub1->Clone(Form("mpt_avg_%i", i)); + mpt->Add(pt1_sub2); + mpt->Scale(0.5); + TH1D* mpt_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v0_Lambda_tot_%.1f_%.1f", min, max)); + mpt_npt_tot->Scale(getIntegratedValue(mpt, min, max)); + TH1D* mpt_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v0_Lambda_sb1_%.1f_%.1f", min, max)); + mpt_npt_sb1->Scale(getIntegratedValue(mpt, min, max)); + TH1D* mpt_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v0_Lambda_sb2_%.1f_%.1f", min, max)); + mpt_npt_sb2->Scale(getIntegratedValue(mpt, min, max)); + + TH1D* mu2 = getMu2sub(i); + mu2 = powerHistogram(mu2, 0.5); + TH1D* mu_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v0_Lambda_den_tot_%.1f_%.1f", min, max)); + mu_npt_tot->Scale(getIntegratedValue(mu2, min, max)); + TH1D* mu_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v0_Lambda_den_sb1_%.1f_%.1f", min, max)); + mu_npt_sb1->Scale(getIntegratedValue(mu2, min, max)); + TH1D* mu_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v0_Lambda_den_sb2_%.1f_%.1f", min, max)); + mu_npt_sb2->Scale(getIntegratedValue(mu2, min, max)); + + v0_tot->Add(mpt_npt_tot, -1); + v0_tot->Divide(mu_npt_tot); + + v0_sb1->Add(mpt_npt_sb1, -1); + v0_sb1->Divide(mu_npt_sb1); + v0_sb2->Add(mpt_npt_sb2, -1); + v0_sb2->Divide(mu_npt_sb2); + + TH1D* v0_bkg = (TH1D*)v0_sb1->Clone(Form("v0_Lambda_bkg_%.1f_%.1f", min, max)); + v0_bkg->Add(v0_sb2, 1); + v0_bkg->Scale(0.5); + + TH1D* v0_sig = (TH1D*)v0_tot->Clone(Form("v0_Lambda_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v0_sig, v0_bkg, "Lambda", min, max, "Calculator::getV0Lambda"); + v0_sig->SetName(Form("V0Lambda_%i", i)); + return v0_sig; +} + +TH1D* Calculator::getV02Corr(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV02Corr]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + TH1D* reth = getCorrVsPt(2, 2, Form("ChGap%s", sp.c_str()), i, min, max); + reth->SetName(Form("V02Corr%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getV02CorrK0(int i, double min, double max) +{ + TH1D* v02_tot = getCorrVsPt(2, 2, Form("ChGapK0s"), i, min, max); + if (useTotal) { + v02_tot->SetName(Form("V02CorrK0_%i", i)); + return v02_tot; + } + TH1D* v02_sb1 = getCorrVsPt(2, 2, Form("ChGapK0sSBL"), i, min, max); + TH1D* v02_sb2 = getCorrVsPt(2, 2, Form("ChGapK0sSBR"), i, min, max); + + TH1D* v02_bkg = (TH1D*)v02_sb1->Clone(Form("v02corr_K0_bkg_%.1f_%.1f", min, max)); + v02_bkg->Add(v02_sb2, 1); + v02_bkg->Scale(0.5); + + TH1D* v02_sig = (TH1D*)v02_tot->Clone(Form("v02_K0_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v02_sig, v02_bkg, "K0", min, max, "Calculator::getV02CorrK0"); + v02_sig->SetName(Form("V02CorrK0_%i", i)); + return v02_sig; +} +TH1D* Calculator::getV02CorrLambda(int i, double min, double max) +{ + TH1D* v02_tot = getCorrVsPt(2, 2, Form("ChGapLambda"), i, min, max); + if (useTotal) { + v02_tot->SetName(Form("V02CorrLambda_%i", i)); + return v02_tot; + } + TH1D* v02_sb1 = getCorrVsPt(2, 2, Form("ChGapLambdaSBL"), i, min, max); + TH1D* v02_sb2 = getCorrVsPt(2, 2, Form("ChGapLambdaSBR"), i, min, max); + TH1D* v02_bkg = (TH1D*)v02_sb1->Clone(Form("v02corr_Lambda_bkg_%.1f_%.1f", min, max)); + v02_bkg->Add(v02_sb2, 1); + v02_bkg->Scale(0.5); + + TH1D* v02_sig = (TH1D*)v02_tot->Clone(Form("v02corr_Lambda_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v02_sig, v02_bkg, "Lambda", min, max, "Calculator::getV02Lambda"); + v02_sig->SetName(Form("V02CorrLambda_%i", i)); + return v02_sig; +} +TH1D* Calculator::getV02Cov(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV02Cov]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + TH1D* reth = getCorrVsPt(2, 2, Form("ChGap%s", sp.c_str()), i, min, max); + TH1D* npt = getnpt(i, pidIndex, min, max, FractionScheme::V02); + TH1D* v22_3pc = hasChGap3pcW22 ? getCNN(2, 2, "ChGap3pcW", i) : getCNN(2, 2, "ChGap", i); + TH1D* sub = (TH1D*)npt->Clone(Form("v22_3pc_%snpt_%.1f_%.1f", sp.c_str(), min, max)); + sub->Scale(getIntegratedValue(v22_3pc, min, max)); + reth->Add(sub, -1); + reth->SetName(Form("V02Cov%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getV02CovK0(int i, double min, double max) +{ + TH1D* reth = getV02CorrK0(i, min, max); + TH1D* npt = getnptK0(i, min, max, FractionScheme::V02); + TH1D* v22_3pc = hasChGap3pcW22 ? getCNN(2, 2, "ChGap3pcW", i) : getCNN(2, 2, "ChGap", i); + TH1D* sub = (TH1D*)npt->Clone(Form("v22_3pc_K0npt_%.1f_%.1f", min, max)); + sub->Scale(getIntegratedValue(v22_3pc, min, max)); + reth->Add(sub, -1); + reth->SetName(Form("V02CovK0_%i", i)); + return reth; +} +TH1D* Calculator::getV02CovLambda(int i, double min, double max) +{ + TH1D* reth = getV02CorrLambda(i, min, max); + TH1D* npt = getnptLambda(i, min, max, FractionScheme::V02); + TH1D* v22_3pc = hasChGap3pcW22 ? getCNN(2, 2, "ChGap3pcW", i) : getCNN(2, 2, "ChGap", i); + TH1D* sub = (TH1D*)npt->Clone(Form("v22_3pc_Lambdanpt_%.1f_%.1f", min, max)); + sub->Scale(getIntegratedValue(v22_3pc, min, max)); + reth->Add(sub, -1); + reth->SetName(Form("V02CovLambda_%i", i)); + return reth; +} +TH1D* Calculator::getV02Means(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV02]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + + TH1D* mean_fraction_pt = getProjectedFractionalSpectra(sp, pidIndex, min, max, FractionScheme::V02); + TH1D* v22 = getCNN(2, 2, "ChGap", i); + TH1D* reth = (TH1D*)mean_fraction_pt->Clone(Form("v22_%snpt_%.1f_%.1f", sp.c_str(), min, max)); + reth->Scale(getIntegratedValue(v22, min, max)); + reth->SetName(Form("V02Means%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +TH1D* Calculator::getV02MeansK0(int i, double min, double max) +{ + TH1D* mean_fraction_pt_tot = getProjectedFractionalK0Spectra("K0_sig", 1, min, max, FractionScheme::V02); + TH1D* v22 = getCNN(2, 2, "ChGap", i); + TH1D* v22_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v22_npt_K0_tot_%.1f_%.1f", min, max)); + v22_npt_tot->Scale(getIntegratedValue(v22, min, max)); + if (useTotal) { + v22_npt_tot->SetName(Form("V02MeansK0_%i", i)); + return v22_npt_tot; + } + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalK0Spectra("K0_sb1", 0, min, max, FractionScheme::V02); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalK0Spectra("K0_sb2", 2, min, max, FractionScheme::V02); + TH1D* v22_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v22_npt_K0_sb1_%.1f_%.1f", min, max)); + v22_npt_sb1->Scale(getIntegratedValue(v22, min, max)); + TH1D* v22_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v22_npt_K0_sb2_%.1f_%.1f", min, max)); + v22_npt_sb2->Scale(getIntegratedValue(v22, min, max)); + + TH1D* v22_npt_bkg = (TH1D*)v22_npt_sb1->Clone(Form("v22_npt_K0_bkg_%.1f_%.1f", min, max)); + v22_npt_bkg->Add(v22_npt_sb2, 1); + v22_npt_bkg->Scale(0.5); + + TH1D* v22_npt_sig = (TH1D*)v22_npt_tot->Clone(Form("v22_npt_K0_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v22_npt_sig, v22_npt_bkg, "K0", min, max, "Calculator::getV02MeansK0"); + v22_npt_sig->SetName(Form("V02MeansK0_%i", i)); + return v22_npt_sig; +} +TH1D* Calculator::getV02MeansLambda(int i, double min, double max) +{ + TH1D* mean_fraction_pt_tot = getProjectedFractionalLambdaSpectra("Lambda_sig", 1, min, max, FractionScheme::V02); + TH1D* v22 = getCNN(2, 2, "ChGap", i); + TH1D* v22_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v22_npt_Lambda_tot_%.1f_%.1f", min, max)); + v22_npt_tot->Scale(getIntegratedValue(v22, min, max)); + if (useTotal) { + v22_npt_tot->SetName(Form("V02MeansLambda_%i", i)); + return v22_npt_tot; + } + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalLambdaSpectra("Lambda_sb1", 0, min, max, FractionScheme::V02); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalLambdaSpectra("Lambda_sb2", 2, min, max, FractionScheme::V02); + TH1D* v22_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v22_npt_Lambda_sb1_%.1f_%.1f", min, max)); + v22_npt_sb1->Scale(getIntegratedValue(v22, min, max)); + TH1D* v22_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v22_npt_Lambda_sb2_%.1f_%.1f", min, max)); + v22_npt_sb2->Scale(getIntegratedValue(v22, min, max)); + + TH1D* v22_npt_bkg = (TH1D*)v22_npt_sb1->Clone(Form("v22_npt_Lambda_bkg_%.1f_%.1f", min, max)); + v22_npt_bkg->Add(v22_npt_sb2, 1); + v22_npt_bkg->Scale(0.5); + + TH1D* v22_npt_sig = (TH1D*)v22_npt_tot->Clone(Form("v22_npt_Lambda_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v22_npt_sig, v22_npt_bkg, "Lambda", min, max, "Calculator::getV02MeansLambda"); + v22_npt_sig->SetName(Form("V02MeansLambda_%i", i)); + return v22_npt_sig; +} +TH1D* Calculator::getV02(int i, int pidIndex, double min, double max) +{ + std::vector species = {"Ch", "Pi", "Ka", "Pr"}; + if (pidIndex > 3) { + std::cout << "[Calculator::getV02]: Invalid pid index - must be 0 (ch), 1 (pi), 2 (ka), or 3 (pr)" << std::endl; + return nullptr; + } + std::string sp = species[pidIndex]; + + TH1D* mean_fraction_pt = getnpt(i, pidIndex, min, max, FractionScheme::V02); + TH1D* reth = getCorrVsPt(2, 2, Form("ChGap%s", sp.c_str()), i, min, max); + TH1D* v22_3pc = hasChGap3pcW22 ? getCNN(2, 2, "ChGap3pcW", i) : getCNN(2, 2, "ChGap", i); + TH1D* sub = (TH1D*)mean_fraction_pt->Clone(Form("v22_%snpt_%.1f_%.1f", sp.c_str(), min, max)); + sub->Scale(getIntegratedValue(v22_3pc, min, max)); + TH1D* den = getV02Means(i, pidIndex, min, max); + reth->Add(sub, -1); + reth->Divide(den); + reth->SetName(Form("V02%s_%i_%.1f_%.1f", sp.c_str(), i, min, max)); + return reth; +} +// Alternatives using the final V02 +TH1D* Calculator::getV02K0Alt(int i, double min, double max) +{ + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalK0Spectra("K0_sb1", 0, min, max, FractionScheme::V02); + TH1D* mean_fraction_pt_tot = getProjectedFractionalK0Spectra("K0_sig", 1, min, max, FractionScheme::V02); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalK0Spectra("K0_sb2", 2, min, max, FractionScheme::V02); + TH1D* v02_tot = getCorrVsPt(2, 2, Form("ChGapK0s"), i, min, max); + TH1D* v02_sb1 = getCorrVsPt(2, 2, Form("ChGapK0sSBL"), i, min, max); + TH1D* v02_sb2 = getCorrVsPt(2, 2, Form("ChGapK0sSBR"), i, min, max); + + TH1D* v22 = getCNN(2, 2, "ChGap", i); + TH1D* v22_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v02_K0_tot_%.1f_%.1f", min, max)); + v22_npt_tot->Scale(getIntegratedValue(v22, min, max)); + TH1D* v22_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v02_K0_sb1_%.1f_%.1f", min, max)); + v22_npt_sb1->Scale(getIntegratedValue(v22, min, max)); + TH1D* v22_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v02_K0_sb2_%.1f_%.1f", min, max)); + v22_npt_sb2->Scale(getIntegratedValue(v22, min, max)); + + v02_tot->Add(v22_npt_tot, -1); + v02_tot->Divide(v22_npt_tot); + + v02_sb1->Add(v22_npt_sb1, -1); + v02_sb1->Divide(v22_npt_sb1); + v02_sb2->Add(v22_npt_sb2, -1); + v02_sb2->Divide(v22_npt_sb2); + + TH1D* v02_bkg = (TH1D*)v02_sb1->Clone(Form("v02_K0_bkg_%.1f_%.1f", min, max)); + v02_bkg->Add(v02_sb2, 1); + v02_bkg->Scale(0.5); + + TH1D* v02_sig = (TH1D*)v02_tot->Clone(Form("v02_K0_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v02_sig, v02_bkg, "K0", min, max, "Calculator::getV02K0"); + v02_sig->SetName(Form("V02K0_%i", i)); + return v02_sig; +} +TH1D* Calculator::getV02LambdaAlt(int i, double min, double max) +{ + TH1D* mean_fraction_pt_sb1 = getProjectedFractionalLambdaSpectra("Lambda_sb1", 0, min, max, FractionScheme::V02); + TH1D* mean_fraction_pt_tot = getProjectedFractionalLambdaSpectra("Lambda_sig", 1, min, max, FractionScheme::V02); + TH1D* mean_fraction_pt_sb2 = getProjectedFractionalLambdaSpectra("Lambda_sb2", 2, min, max, FractionScheme::V02); + TH1D* v02_tot = getCorrVsPt(2, 2, Form("ChGapLambda"), i, min, max); + TH1D* v02_sb1 = getCorrVsPt(2, 2, Form("ChGapLambdaSBL"), i, min, max); + TH1D* v02_sb2 = getCorrVsPt(2, 2, Form("ChGapLambdaSBR"), i, min, max); + + TH1D* v22 = getCNN(2, 2, "ChGap", i); + TH1D* v22_npt_tot = (TH1D*)mean_fraction_pt_tot->Clone(Form("v02_Lambda_tot_%.1f_%.1f", min, max)); + v22_npt_tot->Scale(getIntegratedValue(v22, min, max)); + TH1D* v22_npt_sb1 = (TH1D*)mean_fraction_pt_sb1->Clone(Form("v02_Lambda_sb1_%.1f_%.1f", min, max)); + v22_npt_sb1->Scale(getIntegratedValue(v22, min, max)); + TH1D* v22_npt_sb2 = (TH1D*)mean_fraction_pt_sb2->Clone(Form("v02_Lambda_sb2_%.1f_%.1f", min, max)); + v22_npt_sb2->Scale(getIntegratedValue(v22, min, max)); + + v02_tot->Add(v22_npt_tot, -1); + v02_tot->Divide(v22_npt_tot); + + v02_sb1->Add(v22_npt_sb1, -1); + v02_sb1->Divide(v22_npt_sb1); + v02_sb2->Add(v22_npt_sb2, -1); + v02_sb2->Divide(v22_npt_sb2); + + TH1D* v02_bkg = (TH1D*)v02_sb1->Clone(Form("v02_Lambda_bkg_%.1f_%.1f", min, max)); + v02_bkg->Add(v02_sb2, 1); + v02_bkg->Scale(0.5); + + TH1D* v02_sig = (TH1D*)v02_tot->Clone(Form("v02_Lambda_sig_%.1f_%.1f", min, max)); + if (!useTotal) + applySignalFractionCorrection(*this, v02_sig, v02_bkg, "Lambda", min, max, "Calculator::getV02Lambda"); + v02_sig->SetName(Form("V02Lambda_%i", i)); + return v02_sig; +} + +// Using signal fraction and fraction correlations +TH1D* Calculator::getV02K0(int i, double min, double max) +{ + TH1D* reth = getV02CorrK0(i, min, max); + TH1D* v22 = getCNN(2, 2, "ChGap", i); + TH1D* v22_3pc = hasChGap3pcW22 ? getCNN(2, 2, "ChGap3pcW", i) : getCNN(2, 2, "ChGap", i); + TH1D* npt = getnptK0(i, min, max, FractionScheme::V02); + TH1D* v22_npt = (TH1D*)npt->Clone(Form("v22_K0npt_%.1f_%.1f", min, max)); + v22_npt->Scale(getIntegratedValue(v22_3pc, min, max)); + TH1D* den = (TH1D*)npt->Clone(Form("den_K0_%.1f_%.1f", min, max)); + den->Scale(getIntegratedValue(v22, min, max)); + reth->Add(v22_npt, -1); + reth->Divide(den); + reth->SetName(Form("V02K0_%i", i)); + return reth; +} +TH1D* Calculator::getV02Lambda(int i, double min, double max) +{ + TH1D* reth = getV02CorrLambda(i, min, max); + TH1D* v22 = getCNN(2, 2, "ChGap", i); + TH1D* v22_3pc = hasChGap3pcW22 ? getCNN(2, 2, "ChGap3pcW", i) : getCNN(2, 2, "ChGap", i); + TH1D* npt = getnptLambda(i, min, max, FractionScheme::V02); + TH1D* v22_npt = (TH1D*)npt->Clone(Form("v22_Lambdanpt_%.1f_%.1f", min, max)); + v22_npt->Scale(getIntegratedValue(v22_3pc, min, max)); + TH1D* den = (TH1D*)npt->Clone(Form("den_Lambda_%.1f_%.1f", min, max)); + den->Scale(getIntegratedValue(v22, min, max)); + reth->Add(v22_npt, -1); + reth->Divide(den); + reth->SetName(Form("V02Lambda_%i", i)); + return reth; +} +TH1D* Calculator::getV0K0(int i, double min, double max) +{ + TH1D* reth = getV0CorrK0(i, min, max); + TH1D* npt = getnptK0(i, min, max, FractionScheme::V0); + TH1D* mpt = getMpt(i); + /* TList* l = (TList*)flowptcont->fSubList; + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2"))->getHist(i); + TH1D* mpt = (TH1D*)pt1_sub1->Clone(Form("mpt_avg_%i_%.1f_%.1f",i)); + mpt->Add(pt1_sub2); + mpt->Scale(0.5); */ + + TH1D* mpt_npt = (TH1D*)npt->Clone(Form("mpt_K0npt_%.1f_%.1f", min, max)); + mpt_npt->Scale(getIntegratedValue(mpt, min, max)); + + TH1D* mu2 = getMu2sub(i); + mu2 = powerHistogram(mu2, 0.5); + TH1D* mu_npt = (TH1D*)npt->Clone(Form("mu_K0npt_%.1f_%.1f", min, max)); + mu_npt->Scale(getIntegratedValue(mu2, min, max)); + + reth->Add(mpt_npt, -1); + reth->Divide(mu_npt); + reth->SetName(Form("V0K0_%i", i)); + return reth; +} +TH1D* Calculator::getV0Lambda(int i, double min, double max) +{ + TH1D* reth = getV0CorrLambda(i, min, max); + TH1D* npt = getnptLambda(i, min, max, FractionScheme::V0); + TH1D* mpt = getMpt(i); + /* TList* l = (TList*)flowptcont->fSubList; + TH1* pt1_sub1 = ((BootstrapProfile*)l->FindObject("ptptsub_1sub1_0sub2"))->getHist(i); + TH1* pt1_sub2 = ((BootstrapProfile*)l->FindObject("ptptsub_0sub1_1sub2"))->getHist(i); + TH1D* mpt = (TH1D*)pt1_sub1->Clone(Form("mpt_avg_%i_%.1f_%.1f",i)); + mpt->Add(pt1_sub2); + mpt->Scale(0.5); */ + + TH1D* mpt_npt = (TH1D*)npt->Clone(Form("mpt_Lambdanpt_%.1f_%.1f", min, max)); + mpt_npt->Scale(getIntegratedValue(mpt, min, max)); + + TH1D* mu2 = getMu2sub(i); + mu2 = powerHistogram(mu2, 0.5); + TH1D* mu_npt = (TH1D*)npt->Clone(Form("mu_Lambdanpt_%.1f_%.1f", min, max)); + mu_npt->Scale(getIntegratedValue(mu2, min, max)); + + reth->Add(mpt_npt, -1); + reth->Divide(mu_npt); + reth->SetName(Form("V0Lambda_%i", i)); + return reth; +} + +// Get integrated and normalized V0(2) +TH1D* Calculator::getIntegratedV0(int i) +{ + std::unique_ptr centralityTemplate(getMu2sub(i)); + if (!centralityTemplate) + return nullptr; + auto result = std::unique_ptr(dynamic_cast(centralityTemplate->Clone(Form("integratedV0_%d", i)))); + if (!result) + return nullptr; + result->Reset("ICES"); + + for (int bin = 1; bin <= result->GetNbinsX(); ++bin) { + const double min = result->GetXaxis()->GetBinLowEdge(bin); + const double max = result->GetXaxis()->GetBinUpEdge(bin); + std::unique_ptr differential(getV0Weighted(i, 0, min, max)); + std::unique_ptr fraction(getFractionForSpecies(i, 0, min, max, FractionScheme::V0, false)); + if (!differential || !fraction) + continue; + double error = 0.; + const double value = matchedIntegratedObservable(*differential, *fraction, &error); + if (!std::isfinite(value)) + continue; + result->SetBinContent(bin, value); + result->SetBinError(bin, error); + } + result->SetTitle("; Centrality (%); v_{0}"); + return result.release(); +} +TH1D* Calculator::getIntegratedV02(int i) +{ + std::unique_ptr centralityTemplate(getCNN(2, 2, "ChGap", i)); + if (!centralityTemplate) + return nullptr; + auto result = std::unique_ptr(dynamic_cast(centralityTemplate->Clone(Form("integratedV02_%d", i)))); + if (!result) + return nullptr; + result->Reset("ICES"); + + for (int bin = 1; bin <= result->GetNbinsX(); ++bin) { + const double min = result->GetXaxis()->GetBinLowEdge(bin); + const double max = result->GetXaxis()->GetBinUpEdge(bin); + std::unique_ptr differential(getV02Weighted(i, 0, min, max)); + std::unique_ptr fraction(getFractionForSpecies(i, 0, min, max, FractionScheme::V02, false)); + if (!differential || !fraction) + continue; + double error = 0.; + const double value = matchedIntegratedObservable(*differential, *fraction, &error); + if (!std::isfinite(value)) + continue; + result->SetBinContent(bin, value); + result->SetBinError(bin, error); + } + result->SetTitle("; Centrality (%); v_{02}"); + return result.release(); +} + +TH1D* Calculator::getAlpha(int i, double min, double max) +{ + // The integrated coefficients in Eqs. (19)--(20) must be moments of the + // same differential observables, fractional spectra and eta acceptances. + std::unique_ptr v0pt(getV0Weighted(i, 0, min, max)); + std::unique_ptr v02pt(getV02Weighted(i, 0, min, max)); + std::unique_ptr nV0(getFractionForSpecies(i, 0, min, max, FractionScheme::V0, false)); + std::unique_ptr nV02(getFractionForSpecies(i, 0, min, max, FractionScheme::V02, false)); + if (!v0pt || !v02pt || !nV0 || !nV02) + return nullptr; + const double v0_const = matchedIntegratedObservable(*v0pt, *nV0); + const double v02_const = matchedIntegratedObservable(*v02pt, *nV02); + + std::unique_ptr cv22pt(getCV22pt(i)); + std::unique_ptr varV22(getVarV22(i)); + std::unique_ptr c22(getC22(i)); + std::unique_ptr varPt(getMu2sub(i)); + if (!cv22pt || !varV22 || !c22 || !varPt) + return nullptr; + std::unique_ptr sigmapt(powerHistogram(varPt.get(), 0.5)); + if (!sigmapt) + return nullptr; + + const double cv22pt_const = getIntegratedValue(cv22pt.get(), min, max); + const double varv22_const = getIntegratedValue(varV22.get(), min, max); + const double c22_const = getIntegratedValue(c22.get(), min, max); + const double sigmapt_const = getIntegratedValue(sigmapt.get(), min, max); + const double denominator = sigmapt_const * varv22_const * v0_const - + cv22pt_const * v02_const * c22_const; + if (!std::isfinite(denominator) || + std::abs(denominator) <= std::numeric_limits::epsilon()) + return nullptr; + + v0pt->Scale(varv22_const * sigmapt_const / denominator); + v02pt->Scale(cv22pt_const * c22_const / denominator); + TH1D* alpha = dynamic_cast(v0pt->Clone(Form("alphapt_%i_%g%g", i, min, max))); + alpha->Add(v02pt.get(), -1); + alpha->SetTitle("; #it{p}_{T} (GeV/#it{c}); #alpha"); + return alpha; +} + +TH1D* Calculator::getBeta(int i, double min, double max) +{ + std::unique_ptr v0pt(getV0Weighted(i, 0, min, max)); + std::unique_ptr v02pt(getV02Weighted(i, 0, min, max)); + std::unique_ptr nV0(getFractionForSpecies(i, 0, min, max, FractionScheme::V0, false)); + std::unique_ptr nV02(getFractionForSpecies(i, 0, min, max, FractionScheme::V02, false)); + if (!v0pt || !v02pt || !nV0 || !nV02) + return nullptr; + const double v0_const = matchedIntegratedObservable(*v0pt, *nV0); + const double v02_const = matchedIntegratedObservable(*v02pt, *nV02); + + std::unique_ptr cv22pt(getCV22pt(i)); + std::unique_ptr varV22(getVarV22(i)); + std::unique_ptr c22(getC22(i)); + std::unique_ptr varPt(getMu2sub(i)); + if (!cv22pt || !varV22 || !c22 || !varPt) + return nullptr; + std::unique_ptr sigmapt(powerHistogram(varPt.get(), 0.5)); + if (!sigmapt) + return nullptr; + + const double cv22pt_const = getIntegratedValue(cv22pt.get(), min, max); + const double varv22_const = getIntegratedValue(varV22.get(), min, max); + const double c22_const = getIntegratedValue(c22.get(), min, max); + const double sigmapt_const = getIntegratedValue(sigmapt.get(), min, max); + const double denominator = sigmapt_const * varv22_const * v0_const - + cv22pt_const * v02_const * c22_const; + if (!std::isfinite(denominator) || + std::abs(denominator) <= std::numeric_limits::epsilon()) + return nullptr; + + v0pt->Scale(sigmapt_const * v02_const * c22_const / denominator); + v02pt->Scale(sigmapt_const * v0_const * c22_const / denominator); + TH1D* beta = dynamic_cast(v02pt->Clone(Form("betapt_%i_%g%g", i, min, max))); + beta->Add(v0pt.get(), -1); + beta->SetTitle("; #it{p}_{T} (GeV/#it{c}); #beta"); + return beta; +} + +TH1D* Calculator::getAlphaAlt(int i, double min, double max) +{ + // The integrated coefficients in Eqs. (19)--(20) must be moments of the + // same differential observables, fractional spectra and eta acceptances. + std::unique_ptr v00pt(getV00Weighted(i, 0, min, max)); + std::unique_ptr v02pt(getV02Weighted(i, 0, min, max)); + std::unique_ptr nV0(getFractionForSpecies(i, 0, min, max, FractionScheme::V0, false)); + std::unique_ptr nV02(getFractionForSpecies(i, 0, min, max, FractionScheme::V02, false)); + if (!v00pt || !v02pt || !nV0 || !nV02) + return nullptr; + const double v00_const = matchedIntegratedObservable(*v00pt, *nV0); + const double v02_const = matchedIntegratedObservable(*v02pt, *nV02); + + std::unique_ptr cv22pt(getCV22pt(i)); + std::unique_ptr varV22(getVarV22(i)); + std::unique_ptr c22(getC22(i)); + std::unique_ptr mA(dynamic_cast(flowptcont->getCorrHist(i, 1))); + if (!cv22pt || !varV22 || !c22 || !mA) + return nullptr; + + const double cv22pt_const = getIntegratedValue(cv22pt.get(), min, max); + const double varv22_const = getIntegratedValue(varV22.get(), min, max); + const double c22_const = getIntegratedValue(c22.get(), min, max); + const double mA_const = getIntegratedValue(mA.get(), min, max); + const double denominator = mA_const * varv22_const * v00_const - + cv22pt_const * v02_const * c22_const; + if (!std::isfinite(denominator) || + std::abs(denominator) <= std::numeric_limits::epsilon()) + return nullptr; + + v00pt->Scale(varv22_const * mA_const / denominator); + v02pt->Scale(cv22pt_const * c22_const / denominator); + TH1D* alpha = dynamic_cast(v00pt->Clone(Form("alphapt_%i_%g%g", i, min, max))); + alpha->Add(v02pt.get(), -1); + alpha->SetTitle("; #it{p}_{T} (GeV/#it{c}); #alpha"); + return alpha; +} + +TH1D* Calculator::getBetaAlt(int i, double min, double max) +{ + std::unique_ptr v00pt(getV00Weighted(i, 0, min, max)); + std::unique_ptr v02pt(getV02Weighted(i, 0, min, max)); + std::unique_ptr nV0(getFractionForSpecies(i, 0, min, max, FractionScheme::V0, false)); + std::unique_ptr nV02(getFractionForSpecies(i, 0, min, max, FractionScheme::V02, false)); + if (!v00pt || !v02pt || !nV0 || !nV02) + return nullptr; + const double v00_const = matchedIntegratedObservable(*v00pt, *nV0); + const double v02_const = matchedIntegratedObservable(*v02pt, *nV02); + + std::unique_ptr cv22pt(getCV22pt(i)); + std::unique_ptr varV22(getVarV22(i)); + std::unique_ptr c22(getC22(i)); + std::unique_ptr mA(dynamic_cast(flowptcont->getCorrHist(i, 1))); + if (!cv22pt || !varV22 || !c22 || !mA) + return nullptr; + + const double cv22pt_const = getIntegratedValue(cv22pt.get(), min, max); + const double varv22_const = getIntegratedValue(varV22.get(), min, max); + const double c22_const = getIntegratedValue(c22.get(), min, max); + const double mA_const = getIntegratedValue(mA.get(), min, max); + const double denominator = mA_const * varv22_const * v00_const - + cv22pt_const * v02_const * c22_const; + if (!std::isfinite(denominator) || + std::abs(denominator) <= std::numeric_limits::epsilon()) + return nullptr; + + v00pt->Scale(mA_const * v02_const * c22_const / denominator); + v02pt->Scale(mA_const * v00_const * c22_const / denominator); + TH1D* beta = dynamic_cast(v02pt->Clone(Form("betapt_%i_%g%g", i, min, max))); + beta->Add(v00pt.get(), -1); + beta->SetTitle("; #it{p}_{T} (GeV/#it{c}); #beta"); + return beta; +} + +TH1D* Calculator::getVNN(int nhar, int npar, std::string id, int i) +{ + TH1D* reth = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + // Should be set via input config (json?) + // if(fPropagateFCerrors) clone->SetPropagateErrors(kTRUE); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName(id.c_str()); + switch (npar) { + case 2: + reth = dynamic_cast(clone->GetVN2VsX(nhar, kFALSE, 0)); + break; + case 4: + reth = dynamic_cast(clone->GetVN4VsX(nhar, kFALSE, 0)); + break; + case 6: + reth = dynamic_cast(clone->GetVN6VsX(nhar, kFALSE, 0)); + break; + case 8: + reth = dynamic_cast(clone->GetVN8VsX(nhar, kFALSE, 0)); + break; + default: + printf("Number of particles in correlation should be multiple of 2 and only up to 8 (for now)\n"); + reth = nullptr; + break; + } + return reth; +} +TH1D* Calculator::getVNN(int nhar, int npar, std::string id, int i, double min, double max) +{ + printf("here\n"); + TH1D* reth = nullptr; + TH1D* rethP = nullptr; + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + // Should be set via input config (json?) + // if(fPropagateFCerrors) clone->SetPropagateErrors(kTRUE); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName(id.c_str()); + switch (npar) { + case 2: + // clone->SetIDName("ChNGap"); + // reth = dynamic_cast(clone->GetVN2VsX(nhar, kTRUE, min, max)); + // clone->SetIDName("ChPGap"); + reth = dynamic_cast(clone->GetVN2VsX(nhar, kTRUE, min, max)); + // reth->Sumw2(); + // rethP->Sumw2(); + // reth->Add(rethP); + // reth->Scale(0.5); + break; + case 4: + reth = dynamic_cast(clone->GetVN4VsX(nhar, kTRUE, min, max)); + break; + case 6: + reth = dynamic_cast(clone->GetVN6VsX(nhar, kTRUE, min, max)); + break; + case 8: + reth = dynamic_cast(clone->GetVN8VsX(nhar, kTRUE, min, max)); + break; + default: + printf("Number of particles in correlation should be multiple of 2 and only up to 8 (for now)\n"); + reth = nullptr; + break; + } + return reth; +} +TH1D* Calculator::getCNN(int nhar, int npar, std::string id, int i) +{ + TH1D* reth = nullptr; + std::unique_ptr ownedClone; + FlowContainer* clone = getFlowContainerSample(i, ownedClone); + if (!clone) + return nullptr; + // Should be set via input config (json?) + // if(fPropagateFCerrors) clone->SetPropagateErrors(kTRUE); + clone->SetIDName(id.c_str()); + switch (npar) { + case 2: + reth = dynamic_cast(clone->GetCN2VsX(nhar, kFALSE, 0)); + break; + case 4: + reth = dynamic_cast(clone->GetCN4VsX(nhar, kFALSE, 0)); + break; + case 6: + reth = dynamic_cast(clone->GetCN6VsX(nhar, kFALSE, 0)); + break; + case 8: + reth = dynamic_cast(clone->GetCN8VsX(nhar, kFALSE, 0)); + break; + default: + printf("Number of particles in correlation should be multiple of 2 and only up to 8 (for now)\n"); + reth = nullptr; + break; + } + return reth; +} +TH1D* Calculator::getCNN(int nhar, int npar, std::string id, int i, double min, double max) +{ + TH1D* reth = nullptr; + TH1D* rethP = nullptr; + std::unique_ptr ownedClone; + FlowContainer* clone = getFlowContainerSample(i, ownedClone); + if (!clone) + return nullptr; + // Should be set via input config (json?) + // if(fPropagateFCerrors) clone->SetPropagateErrors(kTRUE); + clone->SetIDName(id.c_str()); + switch (npar) { + case 2: + clone->SetIDName("ChNGap"); + reth = dynamic_cast(clone->GetCN2VsX(nhar, kTRUE, min, max)); + clone->SetIDName("ChPGap"); + rethP = dynamic_cast(clone->GetCN2VsX(nhar, kTRUE, min, max)); + reth->Sumw2(); + rethP->Sumw2(); + reth->Add(rethP); + reth->Scale(0.5); + delete rethP; + break; + case 4: + reth = dynamic_cast(clone->GetCN4VsX(nhar, kTRUE, min, max)); + break; + case 6: + reth = dynamic_cast(clone->GetCN6VsX(nhar, kTRUE, min, max)); + break; + case 8: + reth = dynamic_cast(clone->GetCN8VsX(nhar, kTRUE, min, max)); + break; + default: + printf("Number of particles in correlation should be multiple of 2 and only up to 8 (for now)\n"); + reth = nullptr; + break; + } + return reth; +} +TH1D* Calculator::getCorrVsPt(int nhar, int npar, std::string id, int i, double min, double max) +{ + TH1D* reth = nullptr; + std::unique_ptr ownedClone; + FlowContainer* clone = getFlowContainerSample(i, ownedClone); + if (!clone) + return nullptr; + // Should be set via input config (json?) + // if(fPropagateFCerrors) clone->SetPropagateErrors(kTRUE); + clone->SetIDName(id.c_str()); + std::string order = std::to_string(nhar) + std::to_string(npar); + reth = dynamic_cast(clone->GetHistCorrXXVsPt(order.c_str(), min, max)); + return reth; +} +TH1D* Calculator::getNN(int nhar, int npar, std::string id, int i) +{ + auto clone = (i < 0) ? flowcont : dynamic_cast(flowcont->Clone("TempClone")); + // Should be set via input config (json?) + // if(fPropagateFCerrors) clone->SetPropagateErrors(kTRUE); + if (i >= 0) { + clone->OverrideMainWithSub(i, kFALSE); + Int_t nxb; + Double_t* xbs = flowcont->GetMultiRebin(nxb); + clone->SetMultiRebin(nxb, xbs); + delete[] xbs; + }; + clone->SetIDName(id.c_str()); + return dynamic_cast(clone->GetHistCorrXXVsMulti(Form("%i%u", nhar, npar), 0)); +} +TH1D* Calculator::powerHistogram(TH1D* inhist, double power) +{ + TH1D* outhist = dynamic_cast(inhist->Clone(Form("power%.1f%s", power, inhist->GetName()))); + for (int bin = 1; bin <= inhist->GetNbinsX(); ++bin) { + if (inhist->GetBinContent(bin) >= 0) { + outhist->SetBinContent(bin, std::pow(inhist->GetBinContent(bin), power)); + outhist->SetBinError(bin, power * std::pow(inhist->GetBinContent(bin), power - 1) * inhist->GetBinError(bin)); + } else { + outhist->SetBinContent(bin, -2); + outhist->SetBinError(bin, 0); + } + } + return outhist; +} +double Calculator::getIntegratedValue(TH1D* inhist, double min, double max) +{ + double sum = 0.; + double sumw = 0.; + int minbin = inhist->GetXaxis()->FindBin(min + 0.00001); + int maxbin = inhist->GetXaxis()->FindBin(max - 0.00001); + for (int bin = minbin; bin <= maxbin; ++bin) { + double bc = inhist->GetBinContent(bin); + double be = inhist->GetBinError(bin); + if (be == 0.0) + continue; + sum += bc / (be * be); + sumw += 1. / (be * be); + } + return sum / sumw; +} +double Calculator::readInvMassFit(std::string species, double massMin, double massMax, double pTMin, double pTMax, int centMin, int centMax) +{ + if (massMin < 0. || massMax < 0.) { + if (species == "K0") { + massMin = 0.488; + massMax = 0.507; + } else if (species == "Lambda" || species == "AntiLambda") { + massMin = 1.112; + massMax = 1.120; + } else { + std::cout << "[Calculator::readInvMassFit] Unknown species " << species << " and no mass window provided" << std::endl; + return -1.; + } + } + + // Late-centrality calculations are performed in the native (usually 1%) + // FlowContainer bins. Reuse the invariant-mass fit from the configured bin + // that fully contains the native interval, rather than requiring unstable + // invariant-mass fits for every native bin. + bool foundConfiguredFitBin = false; + for (std::size_t i = 0; i + 1 < invMassFitCentralityBins.size(); ++i) { + const int fitCentMin = fitCentEdge(invMassFitCentralityBins[i]); + const int fitCentMax = fitCentEdge(invMassFitCentralityBins[i + 1]); + if (centMin >= fitCentMin && centMax <= fitCentMax) { + centMin = fitCentMin; + centMax = fitCentMax; + foundConfiguredFitBin = true; + break; + } + } + if (!foundConfiguredFitBin && invMassFitLookupCentMin >= 0 && invMassFitLookupCentMax > invMassFitLookupCentMin && + centMin >= invMassFitLookupCentMin && centMax <= invMassFitLookupCentMax) { + centMin = invMassFitLookupCentMin; + centMax = invMassFitLookupCentMax; + } + + const std::string fitFunctionKey = (species == "AntiLambda" || species == "LambdaAntiLambda") ? "Lambda" : species; + const std::pair* defaultFitFunctions = nullptr; + const auto defaultFunctionsIt = invMassFitFunctions.find(fitFunctionKey); + if (defaultFunctionsIt != invMassFitFunctions.end()) { + defaultFitFunctions = &defaultFunctionsIt->second; + } + const std::pair* fitFunctions = defaultFitFunctions; + const auto systematicFunctionsIt = invMassFitFunctionsBySystematic.find(systematicIndex); + if (systematicFunctionsIt != invMassFitFunctionsBySystematic.end()) { + const auto functionsIt = systematicFunctionsIt->second.find(fitFunctionKey); + if (functionsIt != systematicFunctionsIt->second.end()) { + fitFunctions = &functionsIt->second; + } + } + const bool hasFitFunctions = fitFunctions != nullptr; + const std::string signalFunction = hasFitFunctions ? fitFunctions->first : ""; + const std::string backgroundFunction = hasFitFunctions ? fitFunctions->second : ""; + std::string modelTag = hasFitFunctions ? signalFunction + "_" + backgroundFunction : ""; + if (!hasFitFunctions) { + std::cout << "[Calculator::readInvMassFit] No fit-function configuration for " + << fitFunctionKey << "; using legacy untagged lookup" << std::endl; + } + + TString cacheKey = Form("%s|%.6f|%.6f|%g|%g|%i|%i|%i|%s|%s", + species.c_str(), massMin, massMax, pTMin, pTMax, centMin, centMax, + systematicIndex, invMassFitPath.c_str(), modelTag.c_str()); + auto cacheIt = invMassFitCache.find(cacheKey.Data()); + if (cacheIt != invMassFitCache.end()) { + return cacheIt->second; + } + + // Get normalised system name + std::string system_str = collision_system; + for (char& c : system_str) { + c = static_cast(std::tolower(static_cast(c))); + } + if (system_str == "oo" || system_str == "o-o") + system_str = "OO"; + else if (system_str == "ne-ne" || system_str == "nene") + system_str = "Ne-Ne"; + else if (system_str == "mc" || system_str == "mcreco" || system_str == "reco") + system_str = "MC"; + else if (system_str == "mcgen" || system_str == "gen") + system_str = "MCGen"; + else if (system_str == "LHC25h3c" || system_str == "lhc25h3c") + system_str = "LHC25h3c"; + else if (system_str == "LHC25h4c" || system_str == "lhc25h4c") + system_str = "LHC25h4c"; + else if (system_str == "LHC26c4" || system_str == "lhc26c4") + system_str = "LHC26c4"; + else + system_str = "Pb-Pb"; + + TString fileName; + const TString systematicDirectory = systematicIndex > 0 ? Form("sys_%03d/", systematicIndex) : ""; + if (hasFitFunctions) { + fileName = Form("../pidQA/invmass_outputs/%s/%sinvmass_%s_%s_%i_%i_Pt_%g_%g.root", + system_str.c_str(), systematicDirectory.Data(), species.c_str(), modelTag.c_str(), + centMin, centMax, pTMin, pTMax); + } else { + fileName = Form("../pidQA/invmass_outputs/%s/%sinvmass_%s_%i_%i_Pt_%g_%g.root", + system_str.c_str(), systematicDirectory.Data(), species.c_str(), centMin, centMax, pTMin, pTMax); + } + if (!invMassFitPath.empty()) { + TString basePath = invMassFitPath.c_str(); + if (!basePath.EndsWith("/")) { + basePath += "/"; + } + fileName = basePath + fileName; + } + TFile* infile = TFile::Open(fileName, "READ"); + if (!infile || infile->IsZombie()) { + delete infile; + infile = nullptr; + + TString sourceLog = Form("../pidQA/invmass_outputs/%s/sys_%03d/mass_fit_source.txt", + system_str.c_str(), systematicIndex); + if (!invMassFitPath.empty()) { + TString basePath = invMassFitPath.c_str(); + if (!basePath.EndsWith("/")) { + basePath += "/"; + } + sourceLog = basePath + sourceLog; + } + std::ifstream sourceLogFile(sourceLog.Data()); + std::string sourceDescription((std::istreambuf_iterator(sourceLogFile)), + std::istreambuf_iterator()); + const std::string fallbackSpecies = species == "LambdaAntiLambda" ? "Lambda" : species; + const bool useNominalFallback = systematicIndex > 0 && defaultFitFunctions && + sourceDescription.find("fallback") != std::string::npos && + sourceDescription.find(" " + fallbackSpecies) != std::string::npos; + if (useNominalFallback) { + modelTag = defaultFitFunctions->first + "_" + defaultFitFunctions->second; + fileName = Form("../pidQA/invmass_outputs/%s/invmass_%s_%s_%i_%i_Pt_%g_%g.root", + system_str.c_str(), species.c_str(), modelTag.c_str(), + centMin, centMax, pTMin, pTMax); + if (!invMassFitPath.empty()) { + TString basePath = invMassFitPath.c_str(); + if (!basePath.EndsWith("/")) { + basePath += "/"; + } + fileName = basePath + fileName; + } + infile = TFile::Open(fileName, "READ"); + const std::string warningKey = std::to_string(systematicIndex) + "|" + fitFunctionKey; + if (infile && !infile->IsZombie() && invMassFitFallbackWarnings.insert(warningKey).second) { + std::cout << "[Calculator::readInvMassFit] Systematic index " << systematicIndex + << " uses nominal invariant-mass fits for " << fitFunctionKey << std::endl; + } + } + if (!infile || infile->IsZombie()) { + std::cout << "[Calculator::readInvMassFit] Could not open " << fileName + << " in invmass_outputs/" << system_str << std::endl; + delete infile; + invMassFitCache[cacheKey.Data()] = -1.; + return -1.; + } + } + + TString totalName; + TString bkgName; + if (hasFitFunctions) { + totalName = Form("InvMassRecoFits/f_%s_%s_total_pt_%g_%g", + species.c_str(), modelTag.c_str(), pTMin, pTMax); + bkgName = Form("InvMassRecoFits/f_%s_%s_background_pt_%g_%g", + species.c_str(), modelTag.c_str(), pTMin, pTMax); + } else { + totalName = Form("InvMassRecoFits/f_%s_sig_pt_%g_%g", species.c_str(), pTMin, pTMax); + bkgName = Form("InvMassRecoFits/f_%s_bkg_final_pt_%g_%g", species.c_str(), pTMin, pTMax); + } + TF1* totalFit = dynamic_cast(infile->Get(totalName)); + TF1* bkgFit = dynamic_cast(infile->Get(bkgName)); + if (!totalFit || !bkgFit) { + std::cout << "[Calculator::readInvMassFit] Missing fit functions in " << fileName << std::endl; + infile->Close(); + delete infile; + invMassFitCache[cacheKey.Data()] = -1.; + return -1.; + } + + const double totalIntegral = totalFit->Integral(massMin, massMax); + const double bkgIntegral = bkgFit->Integral(massMin, massMax); + infile->Close(); + delete infile; + + if (totalIntegral <= 0.) { + std::cout << "[Calculator::readInvMassFit] Non-positive total integral for " << species << std::endl; + invMassFitCache[cacheKey.Data()] = -1.; + return -1.; + } + + const double signalFraction = (totalIntegral - bkgIntegral) / totalIntegral; + invMassFitCache[cacheKey.Data()] = signalFraction; + return signalFraction; +} +bool Calculator::is_digits(std::string& str) +{ + for (char ch : str) { + if (!isdigit(ch)) { + return false; + } + } + return true; +} +std::string Calculator::padWithZeros(int number, int totalDigits) +{ + std::ostringstream oss; + oss << std::setw(totalDigits) << std::setfill('0') << number; + return oss.str(); +} +std::pair Calculator::checkSubeventInput(FlowPtContainer* cont) +{ + TList* sublist = cont->fSubList; + std::vector names; + TIter next(sublist); + TObject* obj = 0; + while ((obj = next())) + names.push_back(obj->GetName()); + std::regex re(R"((\d+)sub(\d+))"); + int mpar = 0; + int nsub = 0; + for (const auto& s : names) { + auto begin = std::sregex_iterator(s.begin(), s.end(), re); + auto end = std::sregex_iterator(); + + for (auto it = begin; it != end; ++it) { + int m = std::stoi((*it)[1].str()); + int sub = std::stoi((*it)[2].str()); + mpar = std::max(mpar, m); + nsub = std::max(nsub, sub); + } + } + std::cout << "Maximum number of correlated particles: " << mpar << std::endl; + std::cout << "Maximum number of subevents: " << nsub << std::endl; + return std::make_pair(mpar, nsub); +} +// NOLINTEND(readability/casting, readability/braces) diff --git a/PWGCF/GenericFramework/Core/Calculator.h b/PWGCF/GenericFramework/Core/Calculator.h new file mode 100644 index 00000000000..1bf7ae3c3ce --- /dev/null +++ b/PWGCF/GenericFramework/Core/Calculator.h @@ -0,0 +1,386 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// NOLINTBEGIN(readability/braces) +#ifndef PWGCF_GENERICFRAMEWORK_CORE_CALCULATOR_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_CALCULATOR_H_ + +#include "BootstrapProfile.h" +#include "FlowContainer.h" +#include "FlowPtContainer.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +class Calculator +{ + public: + using ObsFunc = TH1D* (Calculator::*)(int); + using PtDiffFunc = TH1D* (Calculator::*)(int, double, double); + Calculator(); + ~Calculator(); + bool readData(TFile* infile, std::string dirname, bool isGen = false, bool isRadialFlow = false); + TH1D* calculate(ObsFunc func, int i); + TH1D* calculate(PtDiffFunc func, int i, double min, double max); + TH1D* calculateWithLateCentralityRebin(PtDiffFunc func, int i, double min, double max); + void Rebin(int nrb, double* chbins); + void setFlowID(std::string id) { flowid = id; } + void setSystem(std::string system) { collision_system = system; } + void setInvMassFitPath(std::string path) + { + invMassFitPath = path; + invMassFitCache.clear(); + } + void setInvMassFitFunctions(const std::string& species, const std::string& signalFunction, const std::string& backgroundFunction); + void setInvMassFitFunctionsForSystematic(int systematicIndex, + const std::string& species, + const std::string& signalFunction, + const std::string& backgroundFunction); + void setInvMassFitCentralityBins(const std::vector& centralityBins); + void setUseTotal(bool newval) { useTotal = newval; } + void setUseInverseVarianceWeight(bool newval) { useInverseVarianceWeight = newval; } + + struct RadialFlowAnalysis { + std::vector fraction_cent{4}; // ch, pi, ka, pr + std::vector fraction_cent_K0{3}; // sb1, sig, sb2 + std::vector fraction_cent_Lambda{3}; // sb1, sig, sb2 + }; + + // Flow functions + TH1D* getVNN(int nhar, int npar, std::string id, int i); + TH1D* getV12(int i) { return flowid.empty() ? getVNN(1, 2, "RefGap", i) : getVNN(1, 2, flowid, i); } + TH1D* getV22(int i) { return flowid.empty() ? getVNN(2, 2, "RefGap", i) : getVNN(2, 2, flowid, i); } + TH1D* getV32(int i) { return flowid.empty() ? getVNN(3, 2, "RefGap", i) : getVNN(3, 2, flowid, i); } + TH1D* getV42(int i) { return flowid.empty() ? getVNN(4, 2, "RefGap", i) : getVNN(4, 2, flowid, i); } + TH1D* getV24(int i) { return flowid.empty() ? getVNN(2, 4, "RefFull", i) : getVNN(2, 4, flowid, i); } + TH1D* getV26(int i) { return flowid.empty() ? getVNN(2, 6, "RefFull", i) : getVNN(2, 6, flowid, i); } + TH1D* getV28(int i) { return flowid.empty() ? getVNN(2, 8, "RefFull", i) : getVNN(2, 8, flowid, i); } + TH1D* getCNN(int nhar, int npar, std::string id, int i); + TH1D* getC12(int i) { return flowid.empty() ? getCNN(1, 2, "RefGap", i) : getCNN(1, 2, flowid, i); } + TH1D* getC12Full(int i) { return getCNN(1, 2, "ChFull", i); } + TH1D* getC22(int i) { return flowid.empty() ? getCNN(2, 2, "RefGap", i) : getCNN(2, 2, flowid, i); } + TH1D* getC22Full(int i) { return getCNN(2, 2, "ChFull", i); } + TH1D* getC32(int i) { return flowid.empty() ? getCNN(3, 2, "RefGap", i) : getCNN(3, 2, flowid, i); } + TH1D* getC42(int i) { return flowid.empty() ? getCNN(4, 2, "RefGap", i) : getCNN(4, 2, flowid, i); } + TH1D* getC24(int i) { return flowid.empty() ? getCNN(2, 4, "RefFull", i) : getCNN(2, 4, flowid, i); } + TH1D* getC14(int i) { return flowid.empty() ? getCNN(1, 4, "RefGap", i) : getCNN(1, 4, flowid, i); } + TH1D* getC26(int i) { return flowid.empty() ? getCNN(2, 6, "RefFull", i) : getCNN(2, 6, flowid, i); } + TH1D* getC28(int i) { return flowid.empty() ? getCNN(2, 8, "RefFull", i) : getCNN(2, 8, flowid, i); } + TH1D* getNN(int nhar, int npar, std::string id, int i); + TH1D* get22(int i) { return flowid.empty() ? getNN(2, 2, "RefGap", i) : getNN(2, 2, flowid, i); } + TH1D* get24(int i) { return flowid.empty() ? getNN(2, 4, "RefGap", i) : getNN(2, 4, flowid, i); } + TH1D* get32(int i) { return flowid.empty() ? getNN(3, 2, "RefGap", i) : getNN(3, 2, flowid, i); } + TH1D* get42(int i) { return flowid.empty() ? getNN(4, 2, "RefFull", i) : getNN(4, 2, flowid, i); } + + TH1D* getV32overV22(int i); + TH1D* getV24overV22(int i); + + TH1D* getV24_3sub(int i); + TH1D* getC24_3sub(int i); + TH1D* getV2LLMR(int i); + TH1D* getV2LMMR(int i); + TH1D* getV2LMRR(int i); + TH1D* getC2LLMR(int i); + TH1D* getC2LMMR(int i); + TH1D* getC2LMRR(int i); + + TH1D* get2LR(int i); + TH1D* get2LM(int i); + TH1D* get2MR(int i); + + // pt-diff flow + TH1D* getVNN(int nhar, int npar, std::string id, int i, double min, double max); + TH1D* getVPt22(int i, double min, double max) { return flowid.empty() ? getVNN(2, 2, "ChPGap", i, min, max) : getVNN(2, 2, flowid, i, min, max); } + TH1D* getVPt32(int i, double min, double max) { return flowid.empty() ? getVNN(3, 2, "ChPGap", i, min, max) : getVNN(3, 2, flowid, i, min, max); } + TH1D* getVPt42(int i, double min, double max) { return flowid.empty() ? getVNN(4, 2, "ChPGap", i, min, max) : getVNN(4, 2, flowid, i, min, max); } + TH1D* getVPt24(int i, double min, double max) { return flowid.empty() ? getVNN(2, 4, "ChFull", i, min, max) : getVNN(2, 4, flowid, i, min, max); } + TH1D* getCNN(int nhar, int npar, std::string id, int i, double min, double max); + TH1D* getD22(int i, double min, double max) { return flowid.empty() ? getCNN(2, 2, "ChPGap", i, min, max) : getCNN(2, 2, flowid, i, min, max); } + TH1D* getD32(int i, double min, double max) { return flowid.empty() ? getCNN(3, 2, "ChPGap", i, min, max) : getCNN(3, 2, flowid, i, min, max); } + TH1D* getD42(int i, double min, double max) { return flowid.empty() ? getCNN(4, 2, "ChPGap", i, min, max) : getCNN(4, 2, flowid, i, min, max); } + TH1D* getD24(int i, double min, double max) { return flowid.empty() ? getCNN(2, 4, "ChFull", i, min, max) : getCNN(2, 4, flowid, i, min, max); } + + TH1D* getVPt24_3sub(int i, double min, double max); + TH1D* getVPt24_3sub_avgOnVn(int i, double min, double max); + TH1D* getD24_3sub(int i, double min, double max); + TH1D* getD2LpLMR(int i, double min, double max); + TH1D* getD2LLMpR(int i, double min, double max); + TH1D* getD2LLMRp(int i, double min, double max); + TH1D* getD2LpMMR(int i, double min, double max); + TH1D* getD2LMpMR(int i, double min, double max); + TH1D* getD2LMMRp(int i, double min, double max); + TH1D* getD2LpMRR(int i, double min, double max); + TH1D* getD2LMpRR(int i, double min, double max); + TH1D* getD2LMRpR(int i, double min, double max); + + TH1D* get2LpLMR(int i, double min, double max); + TH1D* get2LLMpR(int i, double min, double max); + TH1D* get2LLMRp(int i, double min, double max); + TH1D* get2LpMMR(int i, double min, double max); + TH1D* get2LMpMR(int i, double min, double max); + TH1D* get2LMMRp(int i, double min, double max); + TH1D* get2LpMRR(int i, double min, double max); + TH1D* get2LMpRR(int i, double min, double max); + TH1D* get2LMRpR(int i, double min, double max); + TH1D* get2LRp(int i, double min, double max); + TH1D* get2LpR(int i, double min, double max); + TH1D* get2LpM(int i, double min, double max); + TH1D* get2LMp(int i, double min, double max); + TH1D* get2MpR(int i, double min, double max); + TH1D* get2MRp(int i, double min, double max); + + // Flow variance + TH1D* getVarV22(int i); + + // Flow-pt cumulants + TH1D* getCVN2pt(int nhar, int i); + TH1D* getCV12pt(int i) { return getCVN2pt(1, i); } + TH1D* getCV22pt(int i) { return getCVN2pt(2, i); } + TH1D* getCV32pt(int i) { return getCVN2pt(3, i); } + TH1D* getCV42pt(int i) { return getCVN2pt(4, i); } + // Could in theory be generalised to CVN2ptX, but will we ever need those? In any case trivial to change + TH1D* getCV22pt2(int i); + TH1D* getCV22pt3(int i); + TH1D* getCV22pt4(int i); + TH1D* getCV24pt(int i); + TH1D* getCV24pt2(int i); + + // Flow-pt normalised cumulants + TH1D* getRhoVN2pt(int nhar, int i); + TH1D* getRhoV22pt(int i) { return getRhoVN2pt(2, i); } + TH1D* getRhoV32pt(int i) { return getRhoVN2pt(3, i); } + TH1D* getRhoV42pt(int i) { return getRhoVN2pt(4, i); } + + // Pt cumulant + TH1D* getMpt(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCorrHist(i, 1) : flowptcont->getCorrHist(i, 1)); } + TH1D* getMpt2(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCorrHist(i, 2) : flowptcont->getCorrHist(i, 2)); } + TH1D* getMpt3(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCorrHist(i, 3) : flowptcont->getCorrHist(i, 3)); } + TH1D* getMpt4(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCorrHist(i, 4) : flowptcont->getCorrHist(i, 4)); } + + TH1D* getK2(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCumulantHist(i, 2) : flowptcont->getCumulantHist(i, 2)); } + TH1D* getK3(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCumulantHist(i, 3) : flowptcont->getCumulantHist(i, 3)); } + TH1D* getK4(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCumulantHist(i, 4) : flowptcont->getCumulantHist(i, 4)); } + TH1D* getMu2(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCentralMomentHist(i, 2) : flowptcont->getCentralMomentHist(i, 2)); } + TH1D* getMu3(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCentralMomentHist(i, 3) : flowptcont->getCentralMomentHist(i, 3)); } + TH1D* getMu4(int i) { return dynamic_cast((flowptcontfull) ? flowptcontfull->getCentralMomentHist(i, 4) : flowptcont->getCentralMomentHist(i, 4)); } + + // Normalised pt cumulants + TH1D* getK2Norm(int i); + TH1D* getK3Norm(int i); + TH1D* getDeltaPtOverPt(int i); + TH1D* getStdSkew(int i); + TH1D* getIntSkew(int i); + TH1D* getExKur(int i); + + TH1D* getMptSubAvg(int i); + // 2-subevent pt cumulants + TH1D* getK2sub(int i); + TH1D* getMu2sub(int i); + TH1D* getK3sub(int i); + TH1D* getK3subA(int i); + TH1D* getK3subB(int i); + TH1D* getMu3sub(int i); + TH1D* getK4sub(int i); + TH1D* getMu4sub(int i); + + TH1D* getK3_3sub(int i); + TH1D* getK4_3sub(int i); + + // 4-subevent pt cumulants + TH1D* getK4_4sub(int i); + + // normalised subevent pt cumulants + TH1D* getK2NormSub(int i); + TH1D* getK3NormSub(int i); + TH1D* getStdSkewSub(int i); + TH1D* getIntSkewSub(int i); + TH1D* getIntSkewAvgSub(int i); + TH1D* getExKurSub(int i); + TH1D* getK3Norm_3sub(int i); + TH1D* getStdSkew_3sub(int i); + TH1D* getIntSkew_3sub(int i); + TH1D* getExKur_4sub(int i); + + TH1D* getIntegratedV0(int i); + TH1D* getIntegratedV02(int i); + // Radial flow analysis + TH1D* getnpt(int i, int pidIndex, double min, double max); + TH1D* getnptCh(int i, double min, double max) { return getnpt(i, 0, min, max); }; + TH1D* getnptPi(int i, double min, double max) { return getnpt(i, 1, min, max); }; + TH1D* getnptKa(int i, double min, double max) { return getnpt(i, 2, min, max); }; + TH1D* getnptPr(int i, double min, double max) { return getnpt(i, 3, min, max); }; + TH1D* getnptK0(int i, double min, double max); + TH1D* getnptLambda(int i, double min, double max); + TH1D* getV0(int i, int pidIndex, double min, double max); + TH1D* getV0Ch(int i, double min, double max) { return getV0(i, 0, min, max); }; + TH1D* getV0Pi(int i, double min, double max) { return getV0(i, 1, min, max); }; + TH1D* getV0Ka(int i, double min, double max) { return getV0(i, 2, min, max); }; + TH1D* getV0Pr(int i, double min, double max) { return getV0(i, 3, min, max); }; + TH1D* getV0K0(int i, double min, double max); + TH1D* getV0Lambda(int i, double min, double max); + // Four-term centred numerators. The existing getV0/getV02 methods remain available. + // pidIndex: 0=ch, 1=pi, 2=ka, 3=pr, 4=K0, 5=Lambda. + // Requires the _w2pc/_w3pc fractions and ChGap3pcW22 from the weighted flow task. + // With cfgUsePIDTotal=true, V02 for identified species and V0 for K0/Lambda + // need additional species-specific combined-weight profiles. + TH1D* getV0NumeratorWeighted(int i, int pidIndex, double min, double max); + TH1D* getV02NumeratorWeighted(int i, int pidIndex, double min, double max); + TH1D* getV0Weighted(int i, int pidIndex, double min, double max); + TH1D* getV00Weighted(int i, int pidIndex, double min, double max); + TH1D* getV02Weighted(int i, int pidIndex, double min, double max); + TH1D* getV0WeightedCh(int i, double min, double max) { return getV0Weighted(i, 0, min, max); } + TH1D* getV0WeightedPi(int i, double min, double max) { return getV0Weighted(i, 1, min, max); } + TH1D* getV0WeightedKa(int i, double min, double max) { return getV0Weighted(i, 2, min, max); } + TH1D* getV0WeightedPr(int i, double min, double max) { return getV0Weighted(i, 3, min, max); } + TH1D* getV0WeightedK0(int i, double min, double max) { return getV0Weighted(i, 4, min, max); } + TH1D* getV0WeightedLambda(int i, double min, double max) { return getV0Weighted(i, 5, min, max); } + // New definition + TH1D* getV00WeightedCh(int i, double min, double max) { return getV00Weighted(i, 0, min, max); } + TH1D* getV00WeightedPi(int i, double min, double max) { return getV00Weighted(i, 1, min, max); } + TH1D* getV00WeightedKa(int i, double min, double max) { return getV00Weighted(i, 2, min, max); } + TH1D* getV00WeightedPr(int i, double min, double max) { return getV00Weighted(i, 3, min, max); } + TH1D* getV00WeightedK0(int i, double min, double max) { return getV00Weighted(i, 4, min, max); } + TH1D* getV00WeightedLambda(int i, double min, double max) { return getV00Weighted(i, 5, min, max); } + TH1D* getV02WeightedCh(int i, double min, double max) { return getV02Weighted(i, 0, min, max); } + TH1D* getV02WeightedPi(int i, double min, double max) { return getV02Weighted(i, 1, min, max); } + TH1D* getV02WeightedKa(int i, double min, double max) { return getV02Weighted(i, 2, min, max); } + TH1D* getV02WeightedPr(int i, double min, double max) { return getV02Weighted(i, 3, min, max); } + TH1D* getV02WeightedK0(int i, double min, double max) { return getV02Weighted(i, 4, min, max); } + TH1D* getV02WeightedLambda(int i, double min, double max) { return getV02Weighted(i, 5, min, max); } + TH1D* getV02(int i, int pidIndex, double min, double max); + TH1D* getV02Ch(int i, double min, double max) { return getV02(i, 0, min, max); }; + TH1D* getV02Pi(int i, double min, double max) { return getV02(i, 1, min, max); }; + TH1D* getV02Ka(int i, double min, double max) { return getV02(i, 2, min, max); }; + TH1D* getV02Pr(int i, double min, double max) { return getV02(i, 3, min, max); }; + TH1D* getV02K0(int i, double min, double max); + TH1D* getV02Lambda(int i, double min, double max); + TH1D* getV02K0Alt(int i, double min, double max); + TH1D* getV02LambdaAlt(int i, double min, double max); + TH1D* getV0K0Alt(int i, double min, double max); + TH1D* getV0LambdaAlt(int i, double min, double max); + + TH1D* getV0Corr(int i, int pidIndex, double min, double max); + TH1D* getV0CorrCh(int i, double min, double max) { return getV0Corr(i, 0, min, max); }; + TH1D* getV0CorrPi(int i, double min, double max) { return getV0Corr(i, 1, min, max); }; + TH1D* getV0CorrKa(int i, double min, double max) { return getV0Corr(i, 2, min, max); }; + TH1D* getV0CorrPr(int i, double min, double max) { return getV0Corr(i, 3, min, max); }; + TH1D* getV0CorrK0(int i, double min, double max); + TH1D* getV0CorrLambda(int i, double min, double max); + TH1D* getV0Cov(int i, int pidIndex, double min, double max); + TH1D* getV0CovCh(int i, double min, double max) { return getV02Cov(i, 0, min, max); }; + TH1D* getV0CovPi(int i, double min, double max) { return getV02Cov(i, 1, min, max); }; + TH1D* getV0CovKa(int i, double min, double max) { return getV02Cov(i, 2, min, max); }; + TH1D* getV0CovPr(int i, double min, double max) { return getV02Cov(i, 3, min, max); }; + TH1D* getV0CovK0(int i, double min, double max); + TH1D* getV0CovLambda(int i, double min, double max); + TH1D* getV02Corr(int i, int pidIndex, double min, double max); + TH1D* getV02CorrCh(int i, double min, double max) { return getV02Corr(i, 0, min, max); }; + TH1D* getV02CorrPi(int i, double min, double max) { return getV02Corr(i, 1, min, max); }; + TH1D* getV02CorrKa(int i, double min, double max) { return getV02Corr(i, 2, min, max); }; + TH1D* getV02CorrPr(int i, double min, double max) { return getV02Corr(i, 3, min, max); }; + TH1D* getV02CorrK0(int i, double min, double max); + TH1D* getV02CorrLambda(int i, double min, double max); + TH1D* getV02Cov(int i, int pidIndex, double min, double max); + TH1D* getV02CovCh(int i, double min, double max) { return getV02Cov(i, 0, min, max); }; + TH1D* getV02CovPi(int i, double min, double max) { return getV02Cov(i, 1, min, max); }; + TH1D* getV02CovKa(int i, double min, double max) { return getV02Cov(i, 2, min, max); }; + TH1D* getV02CovPr(int i, double min, double max) { return getV02Cov(i, 3, min, max); }; + TH1D* getV02CovK0(int i, double min, double max); + TH1D* getV02CovLambda(int i, double min, double max); + + TH1D* getV0Means(int i, int pidIndex, double min, double max); + TH1D* getV0MeansCh(int i, double min, double max) { return getV0Means(i, 0, min, max); }; + TH1D* getV0MeansPi(int i, double min, double max) { return getV0Means(i, 1, min, max); }; + TH1D* getV0MeansKa(int i, double min, double max) { return getV0Means(i, 2, min, max); }; + TH1D* getV0MeansPr(int i, double min, double max) { return getV0Means(i, 3, min, max); }; + TH1D* getV0MeansK0(int i, double min, double max); + TH1D* getV0MeansLambda(int i, double min, double max); + TH1D* getV02Means(int i, int pidIndex, double min, double max); + TH1D* getV02MeansCh(int i, double min, double max) { return getV02Means(i, 0, min, max); }; + TH1D* getV02MeansPi(int i, double min, double max) { return getV02Means(i, 1, min, max); }; + TH1D* getV02MeansKa(int i, double min, double max) { return getV02Means(i, 2, min, max); }; + TH1D* getV02MeansPr(int i, double min, double max) { return getV02Means(i, 3, min, max); }; + TH1D* getV02MeansK0(int i, double min, double max); + TH1D* getV02MeansLambda(int i, double min, double max); + + // Two-component model + TH1D* getAlpha(int i, double min, double max); + TH1D* getBeta(int i, double min, double max); + // Based on <[mpt]> normalised v00 + TH1D* getAlphaAlt(int i, double min, double max); + TH1D* getBetaAlt(int i, double min, double max); + + TH1D* getCorrVsPt(int nhar, int npar, std::string id, int i, double min, double max); + + double getIntegratedValue(TH1D* inhist, double min, double max); + double readInvMassFit(std::string species, double massMin = -1., double massMax = -1., double pTMin = 0.2, double pTMax = 3.0, int centMin = 0, int centMax = 20); + + TH1D* powerHistogram(TH1D* inhist, double power); + + private: + enum class FractionScheme { V02, + V0 }; + // Data members + FlowContainer* flowcont; //! + FlowPtContainer* flowptcont; //! + FlowPtContainer* flowptcontfull; //! + RadialFlowAnalysis radialFlowV02; //! + RadialFlowAnalysis radialFlowV0; //! + RadialFlowAnalysis radialFlowV02Weighted; //! + RadialFlowAnalysis radialFlowV0Weighted; //! + TList* corr_list; //! + std::string flowid; //! + std::string collision_system; //! + std::string invMassFitPath; //! + std::map> invMassFitFunctions; //! + std::map>> invMassFitFunctionsBySystematic; //! + std::vector invMassFitCentralityBins; //! + int systematicIndex = 0; //! + int invMassFitLookupCentMin = -1; //! + int invMassFitLookupCentMax = -1; //! + std::map invMassFitCache; //! + std::set invMassFitFallbackWarnings; //! + FlowContainer* activeFlowContainer = nullptr; //! + int activeFlowContainerSample = -2; //! + bool hasChGap3pcW22 = false; //! + std::pair subeventInfo; //! + bool is_digits(std::string& str); + bool useTotal; + bool useInverseVarianceWeight; + std::string padWithZeros(int number, int totalDigits); + std::pair checkSubeventInput(FlowPtContainer* cont); + void loadFractionHists(TFile* infile, std::string dirname, std::string suffix, RadialFlowAnalysis& radialFlowStruct, const std::string& profileSuffix = ""); + void clearFractionHists(RadialFlowAnalysis& radialFlowStruct); + void clearInputData(); + std::unique_ptr prepareFlowContainerSample(int sampleIndex); + FlowContainer* getFlowContainerSample(int sampleIndex, std::unique_ptr& ownedContainer); + TH2D* getNptFile(TFile* infile, const std::string& dirname, const std::string& suffix, const std::string& species, const std::string& fallbackSuffix = "", const std::string& profileSuffix = ""); + TH1D* getProjectedFractionalSpectra(std::string sp, int pidIndex, double min, double max, FractionScheme scheme, bool combinedWeight = false); + TH1D* getProjectedFractionalK0Spectra(std::string sp, int resoIndex, double min, double max, FractionScheme scheme, bool combinedWeight = false); + TH1D* getProjectedFractionalLambdaSpectra(std::string sp, int resoIndex, double min, double max, FractionScheme scheme, bool combinedWeight = false); + TH1D* getnpt(int i, int pidIndex, double min, double max, FractionScheme scheme, bool combinedWeight = false); + TH1D* getnptK0(int i, double min, double max, FractionScheme scheme, bool combinedWeight = false); + TH1D* getnptLambda(int i, double min, double max, FractionScheme scheme, bool combinedWeight = false); + TH1D* getFractionForSpecies(int i, int pidIndex, double min, double max, FractionScheme scheme, bool combinedWeight); + TH1D* getCorrelationForSpecies(int i, int pidIndex, double min, double max, FractionScheme scheme); + ClassDef(Calculator, 1); +}; + +#endif // PWGCF_GENERICFRAMEWORK_CORE_CALCULATOR_H_ +// NOLINTEND(readability/braces) diff --git a/PWGCF/GenericFramework/Core/GFWSpace.h b/PWGCF/GenericFramework/Core/GFWSpace.h new file mode 100644 index 00000000000..5283d2cab6e --- /dev/null +++ b/PWGCF/GenericFramework/Core/GFWSpace.h @@ -0,0 +1,255 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef PWGCF_GENERICFRAMEWORK_CORE_GFWSPACE_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_GFWSPACE_H_ + +#include "Calculator.h" +namespace GFWSpace +{ +Calculator::ObsFunc kNone = 0; +Calculator::PtDiffFunc kNonePt = 0; + +// Flow observables +Calculator::ObsFunc kV12 = &Calculator::getV12; // v1{2} +Calculator::ObsFunc kV22 = &Calculator::getV22; // v2{2} +Calculator::ObsFunc kV32 = &Calculator::getV32; // v3{2} +Calculator::ObsFunc kV42 = &Calculator::getV42; // v4{2} + +Calculator::ObsFunc kV24 = &Calculator::getV24; // v2{4} +Calculator::ObsFunc kV26 = &Calculator::getV26; // v2{6} +Calculator::ObsFunc kV28 = &Calculator::getV28; // v2{8} +Calculator::ObsFunc kV24_3sub = &Calculator::getV24_3sub; // v2{4}_3sub +Calculator::ObsFunc kV2LLMR = &Calculator::getV2LLMR; // v2{LLMR} +Calculator::ObsFunc kV2LMMR = &Calculator::getV2LMMR; // v2{LMMR} +Calculator::ObsFunc kV2LMRR = &Calculator::getV2LMRR; // v2{LMRR} + +Calculator::ObsFunc kC12 = &Calculator::getC12; // c1{2} +Calculator::ObsFunc kC12Full = &Calculator::getC12Full; // c1{2} +Calculator::ObsFunc kC22 = &Calculator::getC22; // c2{2} +Calculator::ObsFunc kC22Full = &Calculator::getC22Full; // c2{2} +Calculator::ObsFunc kC32 = &Calculator::getC32; // c3{2} +Calculator::ObsFunc kC42 = &Calculator::getC42; // c4{2} +Calculator::ObsFunc kC24 = &Calculator::getC24; // c2{4} +Calculator::ObsFunc kC14 = &Calculator::getC14; // c1{4} +Calculator::ObsFunc kC26 = &Calculator::getC26; // c2{6} +Calculator::ObsFunc kC28 = &Calculator::getC28; // c2{8} +Calculator::ObsFunc kC24_3sub = &Calculator::getC24_3sub; // v2{4}_3sub +Calculator::ObsFunc kC2LLMR = &Calculator::getC2LLMR; // c2{LLMR} +Calculator::ObsFunc kC2LMMR = &Calculator::getC2LMMR; // c2{LMMR} +Calculator::ObsFunc kC2LMRR = &Calculator::getC2LMRR; // c2{LMRR} + +Calculator::ObsFunc k2LR = &Calculator::get2LR; +Calculator::ObsFunc k2LM = &Calculator::get2LM; +Calculator::ObsFunc k2MR = &Calculator::get2MR; + +Calculator::ObsFunc k22 = &Calculator::get22; //<2>_{2,-2} +Calculator::ObsFunc k32 = &Calculator::get32; //<2>_{3,-3} +Calculator::ObsFunc k42 = &Calculator::get42; //<2>_{4,-4} +Calculator::ObsFunc k24 = &Calculator::get24; //<4>_{2,2,-2,-2} + +Calculator::ObsFunc kV32overV22 = &Calculator::getV32overV22; // v3{2}/v2{2} +Calculator::ObsFunc kV24overV22 = &Calculator::getV24overV22; // v2{4}/v2{2} + +Calculator::ObsFunc kIntegratedV0 = &Calculator::getIntegratedV0; +Calculator::ObsFunc kIntegratedV02 = &Calculator::getIntegratedV02; + +// pt-diff flow +Calculator::PtDiffFunc kVPt22 = &Calculator::getVPt22; // pt-diff v2{2} +Calculator::PtDiffFunc kVPt32 = &Calculator::getVPt32; // pt-diff v3{2} +Calculator::PtDiffFunc kVPt42 = &Calculator::getVPt42; // pt-diff v4{2} +Calculator::PtDiffFunc kVPt24 = &Calculator::getVPt24; // pt-diff v2{4} +Calculator::PtDiffFunc kD22 = &Calculator::getD22; // pt-diff v2{2} +Calculator::PtDiffFunc kD32 = &Calculator::getD32; // pt-diff v3{2} +Calculator::PtDiffFunc kD42 = &Calculator::getD42; // pt-diff v4{2} +Calculator::PtDiffFunc kD24 = &Calculator::getD24; // pt-diff v2{4} + +Calculator::PtDiffFunc kVPt24_3sub = &Calculator::getVPt24_3sub; +Calculator::PtDiffFunc kVPt24_3sub_avgvn = &Calculator::getVPt24_3sub_avgOnVn; // pt-diff v2{4} +Calculator::PtDiffFunc kD24_3sub = &Calculator::getD24_3sub; +Calculator::PtDiffFunc kD2LpLMR = &Calculator::getD2LpLMR; +Calculator::PtDiffFunc kD2LLMpR = &Calculator::getD2LLMpR; +Calculator::PtDiffFunc kD2LLMRp = &Calculator::getD2LLMRp; +Calculator::PtDiffFunc kD2LpMMR = &Calculator::getD2LpMMR; +Calculator::PtDiffFunc kD2LMpMR = &Calculator::getD2LMpMR; +Calculator::PtDiffFunc kD2LMMRp = &Calculator::getD2LMMRp; +Calculator::PtDiffFunc kD2LpMRR = &Calculator::getD2LpMRR; +Calculator::PtDiffFunc kD2LMpRR = &Calculator::getD2LMpRR; +Calculator::PtDiffFunc kD2LMRpR = &Calculator::getD2LMRpR; + +Calculator::PtDiffFunc k2LpLMR = &Calculator::get2LpLMR; +Calculator::PtDiffFunc k2LLMpR = &Calculator::get2LLMpR; +Calculator::PtDiffFunc k2LLMRp = &Calculator::get2LLMRp; +Calculator::PtDiffFunc k2LpMMR = &Calculator::get2LpMMR; +Calculator::PtDiffFunc k2LMpMR = &Calculator::get2LMpMR; +Calculator::PtDiffFunc k2LMMRp = &Calculator::get2LMMRp; +Calculator::PtDiffFunc k2LpMRR = &Calculator::get2LpMRR; +Calculator::PtDiffFunc k2LMpRR = &Calculator::get2LMpRR; +Calculator::PtDiffFunc k2LMRpR = &Calculator::get2LMRpR; + +Calculator::PtDiffFunc k2LRp = &Calculator::get2LRp; +Calculator::PtDiffFunc k2LpR = &Calculator::get2LpR; +Calculator::PtDiffFunc k2LpM = &Calculator::get2LpM; +Calculator::PtDiffFunc k2LMp = &Calculator::get2LMp; +Calculator::PtDiffFunc k2MpR = &Calculator::get2MpR; +Calculator::PtDiffFunc k2MRp = &Calculator::get2MRp; + +Calculator::PtDiffFunc knptCh = &Calculator::getnptCh; +Calculator::PtDiffFunc knptPi = &Calculator::getnptPi; +Calculator::PtDiffFunc knptKa = &Calculator::getnptKa; +Calculator::PtDiffFunc knptPr = &Calculator::getnptPr; +Calculator::PtDiffFunc knptK0 = &Calculator::getnptK0; +Calculator::PtDiffFunc knptLambda = &Calculator::getnptLambda; + +Calculator::PtDiffFunc kV0CorrCh = &Calculator::getV0CorrCh; +Calculator::PtDiffFunc kV0CorrPi = &Calculator::getV0CorrPi; +Calculator::PtDiffFunc kV0CorrKa = &Calculator::getV0CorrKa; +Calculator::PtDiffFunc kV0CorrPr = &Calculator::getV0CorrPr; +Calculator::PtDiffFunc kV0CorrK0 = &Calculator::getV0CorrK0; +Calculator::PtDiffFunc kV0CorrLambda = &Calculator::getV0CorrLambda; + +Calculator::PtDiffFunc kV0CovCh = &Calculator::getV0CovCh; +Calculator::PtDiffFunc kV0CovPi = &Calculator::getV0CovPi; +Calculator::PtDiffFunc kV0CovKa = &Calculator::getV0CovKa; +Calculator::PtDiffFunc kV0CovPr = &Calculator::getV0CovPr; +Calculator::PtDiffFunc kV0CovK0 = &Calculator::getV0CovK0; +Calculator::PtDiffFunc kV0CovLambda = &Calculator::getV0CovLambda; + +Calculator::PtDiffFunc kV0MeansCh = &Calculator::getV0MeansCh; +Calculator::PtDiffFunc kV0MeansPi = &Calculator::getV0MeansPi; +Calculator::PtDiffFunc kV0MeansKa = &Calculator::getV0MeansKa; +Calculator::PtDiffFunc kV0MeansPr = &Calculator::getV0MeansPr; +Calculator::PtDiffFunc kV0MeansK0 = &Calculator::getV0MeansK0; +Calculator::PtDiffFunc kV0MeansLambda = &Calculator::getV0MeansLambda; + +Calculator::PtDiffFunc kV0Ch = &Calculator::getV0Ch; +Calculator::PtDiffFunc kV0Pi = &Calculator::getV0Pi; +Calculator::PtDiffFunc kV0Ka = &Calculator::getV0Ka; +Calculator::PtDiffFunc kV0Pr = &Calculator::getV0Pr; +Calculator::PtDiffFunc kV0K0 = &Calculator::getV0K0; +Calculator::PtDiffFunc kV0Lambda = &Calculator::getV0Lambda; +Calculator::PtDiffFunc kV0WeightedCh = &Calculator::getV0WeightedCh; +Calculator::PtDiffFunc kV0WeightedPi = &Calculator::getV0WeightedPi; +Calculator::PtDiffFunc kV0WeightedKa = &Calculator::getV0WeightedKa; +Calculator::PtDiffFunc kV0WeightedPr = &Calculator::getV0WeightedPr; +Calculator::PtDiffFunc kV0WeightedK0 = &Calculator::getV0WeightedK0; +Calculator::PtDiffFunc kV0WeightedLambda = &Calculator::getV0WeightedLambda; +Calculator::PtDiffFunc kV00WeightedCh = &Calculator::getV00WeightedCh; +Calculator::PtDiffFunc kV00WeightedPi = &Calculator::getV00WeightedPi; +Calculator::PtDiffFunc kV00WeightedKa = &Calculator::getV00WeightedKa; +Calculator::PtDiffFunc kV00WeightedPr = &Calculator::getV00WeightedPr; +Calculator::PtDiffFunc kV00WeightedK0 = &Calculator::getV00WeightedK0; +Calculator::PtDiffFunc kV00WeightedLambda = &Calculator::getV00WeightedLambda; +Calculator::PtDiffFunc kV0K0Alt = &Calculator::getV0K0Alt; +Calculator::PtDiffFunc kV0LambdaAlt = &Calculator::getV0LambdaAlt; + +Calculator::PtDiffFunc kV02CorrCh = &Calculator::getV02CorrCh; +Calculator::PtDiffFunc kV02CorrPi = &Calculator::getV02CorrPi; +Calculator::PtDiffFunc kV02CorrKa = &Calculator::getV02CorrKa; +Calculator::PtDiffFunc kV02CorrPr = &Calculator::getV02CorrPr; +Calculator::PtDiffFunc kV02CorrK0 = &Calculator::getV02CorrK0; +Calculator::PtDiffFunc kV02CorrLambda = &Calculator::getV02CorrLambda; + +Calculator::PtDiffFunc kV02CovCh = &Calculator::getV02CovCh; +Calculator::PtDiffFunc kV02CovPi = &Calculator::getV02CovPi; +Calculator::PtDiffFunc kV02CovKa = &Calculator::getV02CovKa; +Calculator::PtDiffFunc kV02CovPr = &Calculator::getV02CovPr; +Calculator::PtDiffFunc kV02CovK0 = &Calculator::getV02CovK0; +Calculator::PtDiffFunc kV02CovLambda = &Calculator::getV02CovLambda; + +Calculator::PtDiffFunc kV02MeansCh = &Calculator::getV02MeansCh; +Calculator::PtDiffFunc kV02MeansPi = &Calculator::getV02MeansPi; +Calculator::PtDiffFunc kV02MeansKa = &Calculator::getV02MeansKa; +Calculator::PtDiffFunc kV02MeansPr = &Calculator::getV02MeansPr; +Calculator::PtDiffFunc kV02MeansK0 = &Calculator::getV02MeansK0; +Calculator::PtDiffFunc kV02MeansLambda = &Calculator::getV02MeansLambda; + +Calculator::PtDiffFunc kV02Ch = &Calculator::getV02Ch; +Calculator::PtDiffFunc kV02Pi = &Calculator::getV02Pi; +Calculator::PtDiffFunc kV02Ka = &Calculator::getV02Ka; +Calculator::PtDiffFunc kV02Pr = &Calculator::getV02Pr; +Calculator::PtDiffFunc kV02K0 = &Calculator::getV02K0; +Calculator::PtDiffFunc kV02Lambda = &Calculator::getV02Lambda; +Calculator::PtDiffFunc kV02WeightedCh = &Calculator::getV02WeightedCh; +Calculator::PtDiffFunc kV02WeightedPi = &Calculator::getV02WeightedPi; +Calculator::PtDiffFunc kV02WeightedKa = &Calculator::getV02WeightedKa; +Calculator::PtDiffFunc kV02WeightedPr = &Calculator::getV02WeightedPr; +Calculator::PtDiffFunc kV02WeightedK0 = &Calculator::getV02WeightedK0; +Calculator::PtDiffFunc kV02WeightedLambda = &Calculator::getV02WeightedLambda; +Calculator::PtDiffFunc kV02K0Alt = &Calculator::getV02K0Alt; +Calculator::PtDiffFunc kV02LambdaAlt = &Calculator::getV02LambdaAlt; + +// Two-component model +Calculator::PtDiffFunc kAlpha = &Calculator::getAlpha; +Calculator::PtDiffFunc kBeta = &Calculator::getBeta; +Calculator::PtDiffFunc kAlphaAlt = &Calculator::getAlphaAlt; +Calculator::PtDiffFunc kBetaAlt = &Calculator::getBetaAlt; + +Calculator::ObsFunc kVarV22 = &Calculator::getVarV22; // Var(v_2^2) + +// Transverse momentum observables +Calculator::ObsFunc kMpt = &Calculator::getMpt; //[pt] +Calculator::ObsFunc kMpt2 = &Calculator::getMpt2; // 2nd moment of [pt] +Calculator::ObsFunc kMpt3 = &Calculator::getMpt3; // 3rd moment of [pt] +Calculator::ObsFunc kMpt4 = &Calculator::getMpt4; // 4th moment of [pt] +Calculator::ObsFunc kK2 = &Calculator::getK2; // 2nd order [pt] cumulant +Calculator::ObsFunc kK3 = &Calculator::getK3; // 3rd order [pt] cumulant +Calculator::ObsFunc kK4 = &Calculator::getK4; // 4th order [pt] cumulant +Calculator::ObsFunc kMu2 = &Calculator::getMu2; // 2nd order central [pt] moment (also known as ck) +Calculator::ObsFunc kMu3 = &Calculator::getMu3; // 3rd order central [pt] moment +Calculator::ObsFunc kMu4 = &Calculator::getMu4; // 4th order central [pt] moment + +Calculator::ObsFunc kK2Norm = &Calculator::getK2Norm; // normalised [pt] variance +Calculator::ObsFunc kDeltaPtOverPt = &Calculator::getDeltaPtOverPt; // normalised [pt] variance +Calculator::ObsFunc kK3Norm = &Calculator::getK3Norm; // normalised [pt] variance +Calculator::ObsFunc kStdSkew = &Calculator::getStdSkew; // standardized [pt] skewness +Calculator::ObsFunc kIntSkew = &Calculator::getIntSkew; // intensive [pt] skewness +Calculator::ObsFunc kExKur = &Calculator::getExKur; // Excess [pt] kurtosis + +Calculator::ObsFunc kMptSubAvg = &Calculator::getMptSubAvg; //[pt] +Calculator::ObsFunc kK2Sub = &Calculator::getK2sub; // +Calculator::ObsFunc kMu2Sub = &Calculator::getMu2sub; // +Calculator::ObsFunc kK2NormSub = &Calculator::getK2NormSub; // +Calculator::ObsFunc kK3Sub = &Calculator::getK3sub; // +Calculator::ObsFunc kK3NormSub = &Calculator::getK3NormSub; // +Calculator::ObsFunc kK3_3sub = &Calculator::getK3_3sub; // +Calculator::ObsFunc kK3Norm_3sub = &Calculator::getK3Norm_3sub; // +Calculator::ObsFunc kK3ASub = &Calculator::getK3subA; // +Calculator::ObsFunc kK3BSub = &Calculator::getK3subB; // +Calculator::ObsFunc kMu3Sub = &Calculator::getMu3sub; // +Calculator::ObsFunc kK4Sub = &Calculator::getK4sub; // +Calculator::ObsFunc kK4_4sub = &Calculator::getK4_4sub; // +Calculator::ObsFunc kMu4Sub = &Calculator::getMu4sub; // +Calculator::ObsFunc kStdSkewSub = &Calculator::getStdSkewSub; // +Calculator::ObsFunc kIntSkewSub = &Calculator::getIntSkewSub; // +Calculator::ObsFunc kIntSkewAvgSub = &Calculator::getIntSkewAvgSub; // +Calculator::ObsFunc kExKurSub = &Calculator::getExKurSub; // +Calculator::ObsFunc kStdSkew_3sub = &Calculator::getStdSkew_3sub; // +Calculator::ObsFunc kIntSkew_3sub = &Calculator::getIntSkew_3sub; // +Calculator::ObsFunc kExKur_4sub = &Calculator::getExKur_4sub; // + +// Flow-transverse momentum observables +Calculator::ObsFunc kCV12pt = &Calculator::getCV12pt; // v1^2-dpt cumulant +Calculator::ObsFunc kCV22pt = &Calculator::getCV22pt; // v2^2-dpt cumulant +Calculator::ObsFunc kCV32pt = &Calculator::getCV32pt; // v3^2-dpt cumulant +Calculator::ObsFunc kCV42pt = &Calculator::getCV42pt; // v4^2-dpt cumulant +Calculator::ObsFunc kCV22pt2 = &Calculator::getCV22pt2; // v2^2-dpt^2 cumulant +Calculator::ObsFunc kCV22pt3 = &Calculator::getCV22pt3; // v2^2-dpt^3 cumulant +Calculator::ObsFunc kCV22pt4 = &Calculator::getCV22pt4; // v2^2-dpt^4 cumulant +Calculator::ObsFunc kCV24pt = &Calculator::getCV24pt; // v2^4-dpt cumulant +Calculator::ObsFunc kCV24pt2 = &Calculator::getCV24pt2; // v2^4-dpt^2 cumulant + +Calculator::ObsFunc kRhoV22pt = &Calculator::getRhoV22pt; // ρ(v2^2,dpt) +Calculator::ObsFunc kRhoV32pt = &Calculator::getRhoV32pt; // ρ(v3^2,dpt) +Calculator::ObsFunc kRhoV42pt = &Calculator::getRhoV42pt; // ρ(v4^2,dpt) + +} // namespace GFWSpace +#endif // PWGCF_GENERICFRAMEWORK_CORE_GFWSPACE_H_ diff --git a/PWGCF/GenericFramework/Core/GenericFrameworkLinkDef.h b/PWGCF/GenericFramework/Core/GenericFrameworkLinkDef.h index a9a3da8c05e..c68c57916f6 100644 --- a/PWGCF/GenericFramework/Core/GenericFrameworkLinkDef.h +++ b/PWGCF/GenericFramework/Core/GenericFrameworkLinkDef.h @@ -24,6 +24,12 @@ #pragma link C++ class GFWWeightsList + ; #pragma link C++ class BootstrapProfile + ; #pragma link C++ class FlowPtContainer + ; +#pragma link C++ class PlotTemplateSteerer + ; +#pragma link C++ class MyCanvas + ; +#pragma link C++ class Calculator + ; +#pragma link C++ class SysHandler + ; +#pragma link C++ class StatHandler + ; +#pragma link C++ class OutputHandler + ; #pragma link C++ class o2::analysis::genericframework::GFWBinningCuts + ; #pragma link C++ class o2::analysis::genericframework::GFWRegions + ; #pragma link C++ class o2::analysis::genericframework::GFWCorrConfigs + ; diff --git a/PWGCF/GenericFramework/Core/MyCanvas.cxx b/PWGCF/GenericFramework/Core/MyCanvas.cxx new file mode 100644 index 00000000000..3f5bfe0ebce --- /dev/null +++ b/PWGCF/GenericFramework/Core/MyCanvas.cxx @@ -0,0 +1,1057 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// NOLINTBEGIN(readability/casting, readability/braces, whitespace/parens, whitespace/newline, whitespace/comma, whitespace/operators) +#include "MyCanvas.h" + +#include + +#include +#include +#include +#include +#include +ClassImp(MyCanvas) + + MyCanvas::MyCanvas() : initialised(0), + mName("c"), + mWidth(800), + mHeight(600), + mTopMargin(0.0), + mBottomMargin(0.0), + mLeftMargin(0.0), + mRightMargin(0.0), + mM(1), + mN(1), + addAbove(false), + mCanvas(0), + mLeg(0), + mTextSize(30), + mOffset{1, 1.4}, + mTitle(""), + mLabelOffset(0), + mYmin(-999), + mYmax(-999), + mXmin(-999), + mXmax(-999), + mYRatioMin(-999), + mYRatioMax(-999), + mYscale(0.25), + mRatioYScale(0.25), + mUseSameYscale(true), + mSeparatePad(false), + mAlternateAxisSide(false), + mAdjustTicks(false), + mLineWidth(1), + mLegIndex(0), + fModelDrawOpt("zsame3"), + mStyles{kFullCircle, kFullSquare, kFullDiamond, kFullStar, kFullCross, kFullCrossX, kFullDoubleDiamond, kOpenCircle, kOpenSquare, kOpenDiamond, kOpenStar, kOpenCross, kOpenCrossX, kOpenDoubleDiamond}, + // mColors{kBlack,kP10Blue,kP10Yellow,kP10Red,kP10Gray,kP10Violet,kP10Brown,kP10Orange,kP10Green,kP10Ash,kP10Cyan}, + stylemap{{kFullCircle, 1}, {kFullSquare, 1}, {kFullDiamond, 1.5}, {kFullStar, 1.5}, {kFullCross, 1.5}, {kFullCrossX, 1.5}, {kFullDoubleDiamond, 2}, {kFullTriangleUp, 1.5}, {kOpenCircle, 1}, {kOpenSquare, 1}, {kOpenDiamond, 1.5}, {kOpenStar, 1.5}, {kOpenCross, 1.5}, {kOpenCrossX, 1.5}, {kOpenDoubleDiamond, 2}, {kOpenTriangleUp, 1.5}}, + mFstyles{1001, -1, 3002, 3008, 3014} +{ + gStyle->SetErrorX(0.0); +} +MyCanvas::MyCanvas(const char* name, double w, double h, double lm, double bm, double tm, double rm) : initialised(0), + mName(name), + mWidth(w), + mHeight(h), + mTopMargin(tm), + mBottomMargin(bm), + mLeftMargin(lm), + mRightMargin(rm), + mM(1), + mN(1), + addAbove(false), + mCanvas(0), + mLeg(0), + mTextSize(30), + mOffset{1, 1.4}, + mTitle(""), + mLabelOffset(0), + mYmin(-999), + mYmax(-999), + mXmin(-999), + mXmax(-999), + mYRatioMin(-999), + mYRatioMax(-999), + mYscale(0.25), + mRatioYScale(0.25), + mUseSameYscale(true), + mSeparatePad(false), + mAlternateAxisSide(false), + mAdjustTicks(false), + mLineWidth(1), + mLegIndex(0), + fModelDrawOpt("zsame3"), + mStyles{kFullCircle, kFullSquare, kFullDiamond, kFullStar, kFullCross, kFullCrossX, kFullDoubleDiamond, kOpenCircle, kOpenSquare, kOpenDiamond, kOpenStar, kOpenCross, kOpenCrossX, kOpenDoubleDiamond}, + // mColors{kBlack,kP10Blue,kP10Yellow,kP10Red,kP10Gray,kP10Violet,kP10Brown,kP10Orange,kP10Green,kP10Ash,kP10Cyan}, + stylemap{{kFullCircle, 1}, {kFullSquare, 1}, {kFullDiamond, 1.5}, {kFullStar, 1.5}, {kFullCross, 1.5}, {kFullCrossX, 1.5}, {kFullDoubleDiamond, 2}, {kFullTriangleUp, 1.5}, {kOpenCircle, 1}, {kOpenSquare, 1}, {kOpenDiamond, 1.5}, {kOpenStar, 1.5}, {kOpenCross, 1.5}, {kOpenCrossX, 1.5}, {kOpenDoubleDiamond, 2}, {kOpenTriangleUp, 1.5}}, + mFstyles{1001, -1, 3002, 3008, 3014} +{ + gStyle->SetErrorX(0.0); +} +MyCanvas::~MyCanvas() +{ + delete mCanvas; + for (auto* legend : mLeg) + delete legend; +} +TCanvas* MyCanvas::BuildSingleCanvas() +{ + // if(rm<0) mRightMargin = mTopMargin; + mCanvas = new TCanvas(mName, mName, mWidth, mHeight); + TPad* pad = new TPad("pad", "pad", 0, 0, 1, 1); + pad->SetNumber(1); + pad->SetMargin(mLeftMargin, mRightMargin, mBottomMargin, mTopMargin); + mCanvas->cd(); + pad->Draw(); + mCanvas->cd(); + objVector.resize(1); + modelVector.resize(1); + initialised = true; + return mCanvas; +} +TCanvas* MyCanvas::BuildRatioCanvas(double pr) +{ + fRatioCanvas = true; + mUseSameYscale = false; + mCanvas = new TCanvas(mName, mName, mWidth, mHeight); + double th = mHeight * (1 - pr) - mTopMargin - mBottomMargin; + double bh = mHeight * pr - mTopMargin - mBottomMargin; + double bhrel = bh / mHeight; + mN = 2; + + TPad* top = new TPad("top", "top", 0, bhrel, 1, 1); + top->SetNumber(1); + top->SetMargin(mLeftMargin, mTopMargin, 0, (mTopMargin * mHeight) / th); + mCanvas->cd(); + top->Draw(); + mCanvas->cd(); + TPad* bot = new TPad("bot", "bot", 0, 0, 1, bhrel); + bot->SetNumber(2); + bot->SetMargin(mLeftMargin, mTopMargin, (mBottomMargin * mHeight) / bh, 0); + bot->Draw(); + mCanvas->cd(); + objVector.resize(2); + modelVector.resize(2); + initialised = true; + return mCanvas; +} +TCanvas* MyCanvas::BuildMultiRatioCanvas(int N, float pr, bool separatePad) +{ + mSeparatePad = separatePad; + mCanvas = new TCanvas(mName, mName, mWidth, mHeight); + + // Calculate height for equal visible area per pad + float H = (pr - mBottomMargin) / N; + + float currentTop = pr; // Start from top of small pad area + const float epsilon = 0; // Small overlap to avoid white gaps + for (int i = 0; i <= N; ++i) { + float vposu, vposd, vfactor; + float vmard = 0.0, vmaru = 0.0; + + float hposl = 0.0, hposr = 1.0; + float hfactor = hposr - hposl; + float hmarl = mLeftMargin / hfactor; + float hmarr = mRightMargin / hfactor; + + if (i == 0) { + // Main pad + vposd = pr; + vposu = 1.0; + vfactor = vposu - vposd; + vmaru = mTopMargin / vfactor; + } else { + // Small pad + if (i == N) { + // Last pad + vposd = SafeSub(currentTop - (H + mBottomMargin), epsilon); + vposu = SafeAdd(currentTop, epsilon); + vfactor = vposu - vposd; + vmard = mBottomMargin / vfactor; + } else { + vposd = SafeSub(currentTop - H, epsilon); + vposu = SafeAdd(currentTop, epsilon); + vfactor = vposu - vposd; + } + currentTop = vposd; // no epsilon subtraction here to avoid accumulating underflow + } + + TString padName = (i == 0) ? "padMain" : Form("pad%i", i); + TPad* pad = new TPad(padName, padName, hposl, vposd, hposr, vposu); + pad->SetNumber(i + 1); + + pad->SetLeftMargin(hmarl); + pad->SetRightMargin(hmarr); + pad->SetTopMargin(vmaru); + pad->SetBottomMargin(vmard); + + pad->SetFrameBorderMode(0); + pad->SetBorderMode(0); + pad->SetBorderSize(0); + // ApplyPadStyle(pad); + pad->SetTicks(1, 1); + mCanvas->cd(); + pad->Draw(); + } + + mCanvas->cd(); + objVector.resize(N + 1); + modelVector.resize(N + 1); + initialised = true; + return mCanvas; +} + +TCanvas* MyCanvas::BuildNbyMCanvas(int N, int M, bool separatePad) +{ + mSeparatePad = separatePad; + mCanvas = new TCanvas(mName, mName, mWidth, mHeight); + // Setup Pad layout: + // Float_t vSpacing = (mSeparatePad)?0.05:0.0; + int Nvmar = (mSeparatePad) ? M : 1; + Float_t vStep = (1. - Nvmar * mBottomMargin - Nvmar * mTopMargin) / M; //- (M-1) * vSpacing + + // Float_t hSpacing = (mSeparatePad)?0.02:0.0; + int Nmar = (mSeparatePad) ? N : 1; + Float_t hStep = (1. - Nmar * mLeftMargin - Nmar * mRightMargin) / N; //- (N-1) * hSpacing + + Float_t vposd, vposu, vmard, vmaru, vfactor; + Float_t hposl, hposr, hmarl, hmarr, hfactor; + + // printf("hStep = %.3f\nvStep = %.3f\n",hStep,vStep); + for (Int_t i = 0; i < N; i++) { + + if (i == 0) { + hposl = 0.0; + hposr = mLeftMargin + hStep; + if (i == N - 1 || mSeparatePad) + hposr += mRightMargin; + hfactor = hposr - hposl; + hmarl = mLeftMargin / hfactor; + hmarr = (i == N - 1 || mSeparatePad) ? mRightMargin / hfactor : 0.0; + } else if (i == N - 1) { + hposl = hposr; + hposr = hposl + hStep + mRightMargin; + if (mSeparatePad) + hposr += mLeftMargin; + hfactor = hposr - hposl; + hmarl = (mSeparatePad) ? mLeftMargin / hfactor : 0.0; + hmarr = mRightMargin / hfactor; + } else { + hposl = hposr; + hposr = hposl + hStep; + if (mSeparatePad) + hposr += mLeftMargin + mRightMargin; + hfactor = hposr - hposl; + hmarl = (mSeparatePad) ? mLeftMargin / hfactor : 0.0; + hmarr = (mSeparatePad) ? mRightMargin / hfactor : 0.0; + } + + // printf("i = %i\n hposl = %.3f, hposr = %.3f, hfactor = %.3f\n lmar = %.3f, rmar = %.3f\n",i,hposl,hposr,hfactor,hmarl,hmarr); + for (Int_t j = 0; j < M; j++) { + if (j == 0) { + vposu = 1.; + vposd = vposu - vStep - mTopMargin; + if (mSeparatePad) + vposd -= mBottomMargin; + if (j == M - 1) + vposd = 0.0; + vfactor = vposu - vposd; + vmard = (mSeparatePad || j == M - 1) ? mBottomMargin / vfactor : 0.0; + vmaru = mTopMargin / vfactor; // 0.0 + } else if (j == M - 1) { + vposu = vposd; + vposd = 0.0; + vfactor = vposu - vposd; + vmard = mBottomMargin / vfactor; // 0.0; + vmaru = (mSeparatePad) ? mTopMargin / vfactor : 0.0; + } else { + vposu = vposd; + vposd = vposu - vStep; + if (mSeparatePad) + vposd -= (mBottomMargin + mTopMargin); + vfactor = vposu - vposd; + vmard = (mSeparatePad) ? mBottomMargin / vfactor : 0.0; // 0.0; + vmaru = (mSeparatePad) ? mTopMargin / vfactor : 0.0; + } + // printf("i = %i and j = %i\n vposd = %.3f, vposu = %.3f, vfactor = %.3f\n dmar = %.3f, umar = %.3f\n",i,j,vposd,vposu,vfactor,vmard,vmaru); + TPad* nPad = new TPad(Form("pad%i%i", i, j), Form("pad%i%i", i, j), hposl, vposd, hposr, vposu); + nPad->SetNumber((i + 1) + N * j); + nPad->SetLeftMargin(hmarl); + nPad->SetRightMargin(hmarr); + nPad->SetBottomMargin(vmard); + nPad->SetTopMargin(vmaru); + + nPad->SetFrameBorderMode(0); + nPad->SetBorderMode(0); + nPad->SetBorderSize(0); + mCanvas->cd(); + nPad->Draw(); + } + } + mCanvas->cd(); + objVector.resize(N * M); + modelVector.resize(N * M); + initialised = true; + return mCanvas; +} +/* TCanvas* MyCanvas::BuildNbyMRatioCanvas( + int N, + int M, + double pr, + bool separatePad, + bool alternateAxisSide) +{ + mSeparatePad = separatePad; + mAlternateAxisSide = alternateAxisSide; + fRatioCanvas = true; + mUseSameYscale = false; + + mCanvas = new TCanvas(mName, mName, mWidth, mHeight); + + if (N <= 0 || M <= 0) { + std::cout << "BuildNbyMRatioCanvas: N and M must be positive" << std::endl; + return mCanvas; + } + + if (pr <= 0.0 || pr >= 1.0) { + std::cout << "BuildNbyMRatioCanvas: pr must be between 0 and 1" << std::endl; + return mCanvas; + } + + const double totalHorizontalMargins = + separatePad + ? N * (mLeftMargin + mRightMargin) + : mLeftMargin + mRightMargin; + + const double totalVerticalMargins = + separatePad + ? M * (mTopMargin + mBottomMargin) + : mTopMargin + mBottomMargin; + + const double hStep = + (1.0 - totalHorizontalMargins) / static_cast(N); + + const double vStep = + (1.0 - totalVerticalMargins) / static_cast(M); + + if (hStep <= 0.0 || vStep <= 0.0) { + std::cout << "BuildNbyMRatioCanvas: Margins leave no drawable canvas area" << std::endl; + return mCanvas; + } + + const double mainFrameHeight = (1.0 - pr) * vStep; + const double ratioFrameHeight = pr * vStep; + + double xLeft = 0.0; + + for (int i = 0; i < N; ++i) { + const double leftExtra = + (separatePad || i == 0) ? mLeftMargin : 0.0; + + const double rightExtra = + (separatePad || i == N - 1) ? mRightMargin : 0.0; + + const double padWidth = leftExtra + hStep + rightExtra; + const double xRight = xLeft + padWidth; + + // ROOT margins are fractions of the complete TPad dimensions. + const double leftPadMargin = leftExtra / padWidth; + const double rightPadMargin = rightExtra / padWidth; + + double yTop = 1.0; + + for (int row = 0; row < M; ++row) { + const int mainIndex = 2 * row; + const int ratioIndex = mainIndex + 1; + + const double topExtra = + (separatePad || row == 0) ? mTopMargin : 0.0; + + const double bottomExtra = + (separatePad || row == M - 1) + ? mBottomMargin + : 0.0; + + const double mainPadHeight = topExtra + mainFrameHeight; + const double mainBottom = yTop - mainPadHeight; + + TPad* mainPad = new TPad( + Form("pad%i%i", i, mainIndex), + Form("pad%i%i", i, mainIndex), + xLeft, + mainBottom, + xRight, + yTop + ); + + mainPad->SetNumber( + 2 * N * row + 2 * i + 1 + ); + + mainPad->SetLeftMargin(leftPadMargin); + mainPad->SetRightMargin(rightPadMargin); + mainPad->SetTopMargin(topExtra / mainPadHeight); + mainPad->SetBottomMargin(0.0); + + mainPad->SetFrameBorderMode(0); + mainPad->SetBorderMode(0); + mainPad->SetBorderSize(0); + + mCanvas->cd(); + mainPad->Draw(); + + const double ratioPadHeight = + ratioFrameHeight + bottomExtra; + + const double ratioBottom = + mainBottom - ratioPadHeight; + + TPad* ratioPad = new TPad( + Form("pad%i%i", i, ratioIndex), + Form("pad%i%i", i, ratioIndex), + xLeft, + ratioBottom, + xRight, + mainBottom + ); + + ratioPad->SetNumber( + 2 * N * row + 2 * i + 2 + ); + + ratioPad->SetLeftMargin(leftPadMargin); + ratioPad->SetRightMargin(rightPadMargin); + ratioPad->SetTopMargin(0.0); + ratioPad->SetBottomMargin( + bottomExtra / ratioPadHeight + ); + + ratioPad->SetFrameBorderMode(0); + ratioPad->SetBorderMode(0); + ratioPad->SetBorderSize(0); + + mCanvas->cd(); + ratioPad->Draw(); + + yTop = ratioBottom; + } + + xLeft = xRight; + } + + mCanvas->cd(); + + objVector.resize(2 * N * M); + modelVector.resize(2 * N * M); + + initialised = true; + return mCanvas; +} */ +TCanvas* MyCanvas::BuildNbyMRatioCanvas(int N, int M, double pr, bool separatePad, bool alternateAxisSide) +{ + mSeparatePad = separatePad; + mAlternateAxisSide = alternateAxisSide; + fRatioCanvas = true; + mUseSameYscale = false; + mCanvas = new TCanvas(mName, mName, mWidth, mHeight); + // Setup Pad layout: + // Float_t vSpacing = (mSeparatePad)?0.05:0.0; + int Nvmar = (mSeparatePad) ? M : 1; + Float_t vStep = (1. - Nvmar * mBottomMargin - Nvmar * mTopMargin) / M; //- (M-1) * vSpacing + // Float_t hSpacing = (mSeparatePad)?0.02:0.0; + int Nmar = (mSeparatePad) ? N : 1; + Float_t hStep = (1. - Nmar * mLeftMargin - Nmar * mRightMargin) / N; //- (N-1) * hSpacing + Float_t vposd, vposu, vmard, vmaru, vfactor; + Float_t hposl, hposr, hmarl, hmarr, hfactor; + for (Int_t i = 0; i < N; i++) { + if (i == 0) { + hposl = 0.0; + hposr = mLeftMargin + hStep; + if (i == N - 1 || mSeparatePad) + hposr += mRightMargin; + hfactor = hposr - hposl; + hmarl = mLeftMargin / hfactor; + hmarr = (i == N - 1 || mSeparatePad) ? mRightMargin / hfactor : 0.0; + } else if (i == N - 1) { + hposl = hposr; + hposr = hposl + hStep + mRightMargin; + if (mSeparatePad) + hposr += mLeftMargin; + hfactor = hposr - hposl; + hmarl = (mSeparatePad) ? mLeftMargin / hfactor : 0.0; + hmarr = mRightMargin / hfactor; + } else { + hposl = hposr; + hposr = hposl + hStep; + if (mSeparatePad) + hposr += mLeftMargin + mRightMargin; + hfactor = hposr - hposl; + hmarl = (mSeparatePad) ? mLeftMargin / hfactor : 0.0; + hmarr = (mSeparatePad) ? mRightMargin / hfactor : 0.0; + } + // printf("i = %i\n hposl = %.3f, hposr = %.3f, hfactor = %.3f\n lmar = %.3f, rmar = %.3f\n",i,hposl,hposr,hfactor,hmarl,hmarr); + for (Int_t j = 0; j < 2 * M; j++) { + if (j == 0) { + vposu = 1.; + vposd = vposu - (1 - pr) * vStep - mTopMargin; + if (mSeparatePad) + vposd -= mBottomMargin; + if (j == 2 * M - 1) + vposd = 0.0; + vfactor = vposu - vposd; + // vmard = (mSeparatePad || j == 2*M-1)?mBottomMargin / vfactor:0.0; + vmard = (j == 2 * M - 1) ? mBottomMargin / vfactor : 0.0; + vmaru = mTopMargin / vfactor; // 0.0 + } else if (j == 2 * M - 1) { + vposu = vposd; + vposd = 0.; + vfactor = vposu - vposd; + vmard = mBottomMargin / vfactor; // 0.0; + vmaru = 0.0; + } else { + if (j % 2) { + vposu = vposd; + vposd = vposu - pr * vStep; // - mBottomMargin; + vfactor = vposu - vposd; + vmard = (mSeparatePad) ? mBottomMargin / vfactor : 0.0; // 0.0; + vmaru = 0.0; + } else { + vposu = vposd; + vposd = vposu - (1 - pr) * vStep; // - mTopMargin; + vfactor = vposu - vposd; + vmard = 0.0; // 0.0; + vmaru = (mSeparatePad) ? mTopMargin / vfactor : 0.0; + } + } + TPad* nPad = new TPad(Form("pad%i%i", i, j), Form("pad%i%i", i, j), hposl, vposd, hposr, vposu); + if (j % 2) + nPad->SetNumber(2 * (i + 1) + N * (j - 1)); + else + nPad->SetNumber((2 * i + 1) + N * j); + nPad->SetLeftMargin(hmarl); + nPad->SetRightMargin(hmarr); + nPad->SetBottomMargin(vmard); + nPad->SetTopMargin(vmaru); + + nPad->SetFrameBorderMode(0); + nPad->SetBorderMode(0); + nPad->SetBorderSize(0); + mCanvas->cd(); + nPad->Draw(); + } + } + mCanvas->cd(); + objVector.resize(N * 2 * M); + modelVector.resize(N * 2 * M); + initialised = true; + return mCanvas; +} + +void MyCanvas::AddObject(ObjType stat, int Npad, int color, int style, ObjType sys) +{ + if (Npad > int(objVector.size())) { + printf("Pad no. exceeds number of pads in canvas\n"); + return; + } + DrawObject tmp_obj = {stat, sys, color, style, std::visit([](auto&& arg) { return arg->GetMinimum(); }, stat), std::visit([](auto&& arg) { return arg->GetMaximum(); }, stat)}; + objVector[Npad - 1].push_back(tmp_obj); + return; +} +void MyCanvas::AddModel(ObjType model, int Npad, int color, int fillstyle, float alpha) +{ + if (Npad > int(modelVector.size())) { + printf("Pad no. exceeds number of pads in canvas\n"); + return; + } + ModelObject tmp_obj = {model, color, fillstyle, alpha, std::visit([](auto&& arg) { return arg->GetMinimum(); }, model), std::visit([](auto&& arg) { return arg->GetMaximum(); }, model)}; + modelVector[Npad - 1].push_back(tmp_obj); + return; +} +void MyCanvas::Draw(const char* opt) +{ + SetLimits(); + ApplyFormat(); + int padcounter = 0; + for (auto& pad : objVector) { + ++padcounter; + int objcounter = 0; + mCanvas->cd(padcounter); + /* std::visit([this,opt,objcounter,padcounter](auto&& arg){ + arg->Draw("A"); + }, objVector[padcounter][0].stat); */ + + if (!modelVector[padcounter - 1].empty()) { + int modelcounter = 0; + for (auto& model : modelVector[padcounter - 1]) { + ++modelcounter; + std::visit([model, this](auto&& arg) { arg->SetFillColorAlpha(model.color, model.alpha); }, model.model); + std::visit([model, this](auto&& arg) { arg->SetLineColorAlpha(model.color, model.alpha); }, model.model); + if (fModelDrawOpt.find("l") == std::string::npos && fModelDrawOpt.find("L") == std::string::npos) + std::visit([model, this](auto&& arg) { arg->SetLineWidth(2); }, model.model); + else + std::visit([model, this](auto&& arg) { arg->SetLineWidth(2); }, model.model); + std::visit([model, this](auto&& arg) { arg->SetFillStyle(model.fillstyle); }, model.model); + std::visit([this, modelcounter, padcounter](auto&& arg) { + std::string optstr = fModelDrawOpt; + if (mAlternateAxisSide && ((padcounter - 1) / 2) % 2) + optstr.insert(0, "Y+"); + if (modelcounter == 1) + optstr.insert(0, "A"); + arg->Draw(optstr.c_str()); + }, + model.model); + if (model.fillstyle == -1) { + DrawGraphWithErrorOutline(model.model, 2, model.color); + std::visit([model, this](auto&& arg) { + using T = std::decay_t; + if constexpr (std::is_same_v || std::is_same_v) + DrawGraphWithErrorOutline(arg, 2, model.color); + }, + model.model); + } + } + } + bool onlyGraphs = true; + for (auto& obj : pad) { + std::visit([&onlyGraphs](auto&& arg) { + if(!isGraphType(arg)) + onlyGraphs = false; }, + obj.stat); + } + for (auto& obj : pad) { + ++objcounter; + std::visit([obj, this](auto&& arg) { arg->SetMarkerStyle(obj.style); }, obj.stat); + // std::visit([obj,this](auto&& arg){ arg->SetMarkerSize(stylemap[obj.style]); }, obj.stat); + std::visit([obj, this](auto&& arg) { if(stylemap.find(obj.style) == stylemap.end()) arg->SetMarkerStyle(1); else arg->SetMarkerSize(stylemap[obj.style]); }, obj.stat); + std::visit([obj, this](auto&& arg) { if(arg) arg->SetMarkerStyle(obj.style); }, obj.sys); + std::visit([obj, this](auto&& arg) { if(arg) { if(stylemap.find(obj.style) == stylemap.end()) arg->SetMarkerStyle(1); else arg->SetMarkerSize(stylemap[obj.style]); } }, obj.sys); + + std::visit([obj, this](auto&& arg) { arg->SetMarkerColor(obj.color); }, obj.stat); + std::visit([obj, this](auto&& arg) { arg->SetLineColor(obj.color); }, obj.stat); + std::visit([obj, this](auto&& arg) { if(arg) arg->SetMarkerColor(obj.color); }, obj.sys); + std::visit([obj, this](auto&& arg) { if(arg) arg->SetLineColor(obj.color); }, obj.sys); + + std::visit([this](auto&& arg) { arg->SetLineWidth(mLineWidth); }, obj.stat); + std::visit([this](auto&& arg) { if(arg) arg->SetLineWidth(mLineWidth); }, obj.sys); + + std::visit([this](auto&& arg) { if (!mTitle.IsNull() && mTitle.Length() > 0) arg->SetTitle(Form("%s",mTitle.Data())); }, obj.stat); + std::visit([this, opt, objcounter, padcounter, onlyGraphs](auto&& arg) { + std::string optstr = opt; + if (mAlternateAxisSide && ((padcounter - 1) / 2) % 2) + optstr.insert(0, "Y+"); + // if(objcounter==1) optstr.insert(0,"a"); + if (onlyGraphs) + optstr.insert(0, "a"); + arg->Draw(optstr.c_str()); + }, + obj.stat); + + std::visit([this](auto&& arg) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + // Safe to treat arg as TH1D* + TGraphErrors* gr = HistToGraph(arg); + gr->SetFillStyle(0); + gr->Draw("pzsame2"); + } else { + // Do nothing or handle other types if desired + } + }, + obj.sys); + } + gPad->RedrawAxis(); + } +} +void MyCanvas::AddLine(double x1, double y1, double x2, double y2, int nPad) +{ + auto drawLine = [=]() { + TLine* line = new TLine(x1, y1, x2, y2); + line->SetBit(kCanDelete); + line->SetLineStyle(2); + line->SetLineColorAlpha(kBlack, 0.4); + line->Draw("same"); + }; + if (nPad) { + mCanvas->cd(nPad); + drawLine(); + } else { + for (int n(0); n < int(objVector.size()); ++n) { + mCanvas->cd(n + 1); + drawLine(); + } + } + return; +} +void MyCanvas::AddText(double x, double y, const char* text, bool NDC, int textsize, int textcolor) +{ + TLatex l; + l.SetTextFont(43); + (!textsize) ? l.SetTextSize(mTextSize) : l.SetTextSize(textsize); + l.SetTextColor(textcolor); + if (NDC) + l.DrawLatexNDC(x, y, text); + else + l.DrawLatex(x, y, text); + return; +} +void MyCanvas::ApplyFormat() +{ + gStyle->SetTickLength(0.9, "x"); + int padCounter = 0; + for (auto& pad : modelVector) { + ++padCounter; + for (auto& model : pad) { + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTickLength(0.9); }, model.model); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTitleFont(43); }, model.model); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTitleSize(mTextSize); }, model.model); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTitleOffset(mOffset[0]); }, model.model); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetLabelFont(43); }, model.model); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetLabelSize(mTextSize); }, model.model); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetTitleFont(43); }, model.model); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetTitleSize(mTextSize); }, model.model); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetTitleOffset(mOffset[1]); }, model.model); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetLabelFont(43); }, model.model); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetLabelSize(mTextSize); }, model.model); + if (mLabelOffset) + std::visit([this](auto&& arg) { arg->GetYaxis()->SetLabelOffset(mLabelOffset); }, model.model); + if (mAdjustTicks) { + TPad* current_pad = (TPad*)mCanvas->GetPad(padCounter); + double tickx = 0.01 * mHeight / (current_pad->GetWh() * current_pad->GetAbsHNDC()); + // double ticky = 0.03*mCanvas->GetWw()/(current_pad->GetWw()*current_pad->GetAbsWNDC()); + double padW = current_pad->GetWw() * current_pad->GetAbsWNDC(); + double tickScaleY = (current_pad->GetUymax() - current_pad->GetUymin()) / (current_pad->GetY2() - current_pad->GetY1() - current_pad->GetBottomMargin()) * padW; + double ticky = 0.00003 * tickScaleY; + printf("tickx for pad %i = %g\n", padCounter, tickx); + printf("ticky for pad %i = %g\n", padCounter, ticky); + std::visit([tickx, this](auto&& arg) { arg->GetXaxis()->SetTickLength(tickx); }, model.model); + std::visit([ticky, this](auto&& arg) { arg->GetYaxis()->SetTickLength(ticky); }, model.model); + } + } + } + for (auto& pad : objVector) { + for (auto& obj : pad) { + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTickLength(0.9); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTitleFont(43); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTitleFont(43); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTitleSize(mTextSize); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTitleOffset(mOffset[0]); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetLabelFont(43); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetLabelSize(mTextSize); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetTitleFont(43); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetTitleSize(mTextSize); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetTitleOffset(mOffset[1]); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetLabelFont(43); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetLabelSize(mTextSize); }, obj.stat); + if (mLabelOffset) + std::visit([this](auto&& arg) { arg->GetYaxis()->SetLabelOffset(mLabelOffset); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetXaxis()->SetTickLength(0.02); }, obj.stat); + std::visit([this](auto&& arg) { arg->GetYaxis()->SetTickLength(0.02); }, obj.stat); + if (mAdjustTicks) { + TPad* current_pad = (TPad*)mCanvas->GetPad(padCounter); + double tickx = 0.01 * mHeight / (current_pad->GetWh() * current_pad->GetAbsHNDC()); + double padW = current_pad->GetWw() * current_pad->GetAbsWNDC(); + double tickScaleY = (current_pad->GetUymax() - current_pad->GetUymin()) / (current_pad->GetY2() - current_pad->GetY1() - current_pad->GetBottomMargin()) * padW; + double ticky = 0.00003 * tickScaleY; + std::visit([tickx, this](auto&& arg) { arg->GetXaxis()->SetTickLength(tickx); }, obj.stat); + std::visit([ticky, this](auto&& arg) { arg->GetYaxis()->SetTickLength(ticky); }, obj.stat); + } + } + } + return; +} +void MyCanvas::SetLimits() +{ + if (mXmin != -999 && mXmax != -999) { + for (auto& pad : objVector) { + for (auto& obj : pad) { + std::visit([this](auto&& arg) { arg->GetXaxis()->SetRangeUser(mXmin, mXmax); }, obj.stat); + } + } + } + bool setMin = 1; + bool setMax = 1; + if (mYmin != -999) { // If limits are manually set, then set all histograms with those limits + printf("Setting manual limits!\n"); + setMin = 0; + for (auto v : objVector) { + for (auto obj : v) { + std::visit([this](auto&& arg) { arg->SetMinimum(mYmin); }, obj.stat); + } + } + } + if (mYmax != -999) { + setMax = 0; + for (auto v : objVector) { + for (auto obj : v) { + std::visit([this](auto&& arg) { arg->SetMaximum(mYmax); }, obj.stat); + } + } + } + if (!padlimits.empty()) { + for (auto& el : padlimits) { + printf("Setting manual limits (%g,%g) for pad %i!\n", el.second.first, el.second.second, el.first); + for (auto& model : modelVector[el.first - 1]) { + std::visit([&el, this](auto&& arg) { arg->SetMinimum(el.second.first); }, model.model); + std::visit([&el, this](auto&& arg) { arg->SetMaximum(el.second.second); }, model.model); + } + for (auto& obj : objVector[el.first - 1]) { + std::visit([&el, this](auto&& arg) { arg->SetMinimum(el.second.first); }, obj.stat); + std::visit([&el, this](auto&& arg) { arg->SetMaximum(el.second.second); }, obj.stat); + } + } + setMin = 0; + setMax = 0; + } + if (setMin || setMax) { // Otherwise find max and min for each canvas and set histograms accordingly + vector max, min; + for (auto& pad : objVector) { + double tmp_max = std::visit([](auto&& arg) { return arg->GetMaximum(); }, pad[0].stat); + double tmp_min = std::visit([](auto&& arg) { return arg->GetMinimum(); }, pad[0].stat); + for (auto& obj : pad) { + tmp_max = std::visit([tmp_max](auto&& arg) { if(arg->GetMaximum()>tmp_max) return arg->GetMaximum(); else return tmp_max; }, obj.stat); + tmp_min = std::visit([tmp_min](auto&& arg) { if(arg->GetMinimum()GetMinimum(); else return tmp_min; }, obj.stat); + } + max.push_back(tmp_max); + min.push_back(tmp_min); + } + double global_max = *std::max_element(max.begin(), max.end()); // If pads should share common y scale, then find the global max and min + double global_min = *std::min_element(min.begin(), min.end()); + int padcounter = 0; + for (auto& pad : objVector) { + ++padcounter; + double scale = (padcounter % 2) ? mRatioYScale : mYscale; + for (auto& obj : pad) { + if (mUseSameYscale) { + double diff = global_max - global_min; + if (setMax) + std::visit([scale, diff, global_max](auto&& arg) { arg->SetMaximum(global_max + scale * diff); }, obj.stat); + if (setMin) + std::visit([scale, diff, global_min](auto&& arg) { arg->SetMinimum(global_min - scale * diff); }, obj.stat); + } else { + double diff = max[padcounter - 1] - min[padcounter - 1]; + if (setMax) + std::visit([scale, diff, min, max, padcounter](auto&& arg) { arg->SetMaximum(max[padcounter - 1] + scale * diff); }, obj.stat); + if (setMin) + std::visit([scale, diff, min, max, padcounter](auto&& arg) { arg->SetMinimum(min[padcounter - 1] - scale * diff); }, obj.stat); + } + } + } + } + if (fRatioCanvas && mYRatioMax != -999 && mYRatioMin != -999) { + int padcounter = 0; + for (auto& pad : objVector) { + ++padcounter; + if (!(padcounter % 2)) { + for (auto& obj : pad) { + std::visit([this](auto&& arg) { arg->SetMinimum(mYRatioMin); }, obj.stat); + std::visit([this](auto&& arg) { arg->SetMaximum(mYRatioMax); }, obj.stat); + } + } + } + } + return; +} +void MyCanvas::cd(int Npad) +{ + (Npad == 0) ? mCanvas->cd() : mCanvas->cd(Npad); + return; +} +TPad* MyCanvas::GetPad(int Npad) +{ + if (!mCanvas) { + return nullptr; + } + if (Npad <= 0) { + return dynamic_cast(mCanvas); + } + return dynamic_cast(mCanvas->GetPad(Npad)); +} +void MyCanvas::SaveAs(const char* name, const char* opt) +{ + mCanvas->SaveAs(name, opt); + return; +} +void MyCanvas::BuildLegend(double x1, double y1, double x2, double y2, int legInd, int nCol) +{ + if (static_cast(legInd + 1) > mLeg.size()) + mLeg.push_back(new TLegend(x1, y1, x2, y2)); + mLeg[legInd]->SetBorderSize(0); + mLeg[legInd]->SetFillStyle(0); + mLeg[legInd]->SetTextFont(43); + mLeg[legInd]->SetTextSize(mTextSize); + if (nCol > 1) + mLeg[legInd]->SetNColumns(nCol); + mLeg[legInd]->SetTextSize(mTextSize); + return; +} +void MyCanvas::DrawLegend(double x1, double y1, int legInd, int nCol) +{ + mLeg[legInd]->Draw(); + gPad->Update(); + mLeg[legInd]->SetX1NDC(x1); + mLeg[legInd]->SetY1NDC(y1); + mLeg[legInd]->SetX2NDC(x1 + 0.2); + mLeg[legInd]->SetY2NDC(y1 + 0.3); + if (nCol > 1) + mLeg[legInd]->SetNColumns(nCol); + mLeg[legInd]->SetTextSize(mTextSize); + gPad->Modified(); + return; +} +void MyCanvas::DrawLegend(double x1, double y1, double x2, double y2, int legInd, int nCol) +{ + mLeg[legInd]->Draw(); + gPad->Update(); + mLeg[legInd]->SetX1NDC(x1); + mLeg[legInd]->SetY1NDC(y1); + mLeg[legInd]->SetX2NDC(x2); + mLeg[legInd]->SetY2NDC(y2); + if (nCol > 1) + mLeg[legInd]->SetNColumns(nCol); + mLeg[legInd]->SetTextSize(mTextSize); + gPad->Modified(); + return; +} +void MyCanvas::DrawLegend(TString loc, int legInd, int nCol) +{ + mLeg[legInd]->Draw(); + double x1 = 0.0; + double y1 = 0.0; + if (loc.Contains("top")) + y1 = (addAbove) ? 0.95 - gPad->GetTopMargin() - 0.05 : 0.95 - gPad->GetTopMargin(); + if (loc.Contains("left")) + x1 = gPad->GetLeftMargin() + 0.05; + if (loc.Contains("right")) + x1 = 0.7; + if (loc.Contains("bottom")) + y1 = (addAbove) ? gPad->GetBottomMargin() + 0.05 : gPad->GetBottomMargin() + 0.1; + if (loc.Contains("mid")) + y1 = 0.5; + if (loc.Contains("center")) + x1 = 0.5; + if (x1 == 0.0 || y1 == 0.0) { + printf("Specify location by combining (bottom,mid,top) and (left,center,right)\n"); + return; + } + int nrows = mLeg[legInd]->GetNRows(); + gPad->Update(); + mLeg[legInd]->SetX1NDC(x1); + mLeg[legInd]->SetY1NDC((addAbove) ? y1 : y1 - 0.05 * nrows); + mLeg[legInd]->SetX2NDC(x1 + 0.2); + mLeg[legInd]->SetY2NDC((addAbove) ? y1 + 0.05 * nrows : y1); + mLeg[legInd]->SetNColumns(nCol); + mLeg[legInd]->SetTextSize(mTextSize); + gPad->Modified(); + return; +} +template +TGraphErrors* MyCanvas::HistToGraph(T h) +{ + int nBins = h->GetNbinsX(); + vector binEdges; + for (auto i(0); i <= nBins; ++i) + binEdges.push_back(h->GetBinLowEdge(i + 1)); + vector val; + vector ey; + vector ex; + vector x; + TGraphErrors* gr; + for (Int_t bin(0); bin < nBins; ++bin) { + val.push_back(h->GetBinContent(bin + 1)); + ey.push_back(h->GetBinError(bin + 1)); + // ex.push_back(h->GetBinWidth(bin+1)*0.18); + ex.push_back(0.05); + x.push_back((binEdges[bin] + binEdges[bin + 1]) / 2); + } + gr = new TGraphErrors(nBins, &x[0], &val[0], &ex[0], &ey[0]); + gr->SetFillStyle(1001); + gr->SetLineWidth(h->GetLineWidth()); + gr->SetFillColorAlpha(h->GetMarkerColor(), 0.4); + gr->SetLineColor(h->GetLineColor()); + gr->SetMarkerColor(h->GetMarkerColor()); + gr->SetMarkerStyle(h->GetMarkerStyle()); + gr->SetMarkerSize(h->GetMarkerSize()); + gr->SetMinimum(h->GetMinimum()); + gr->SetMinimum(h->GetMaximum()); + return gr; +} +float MyCanvas::SafeAdd(float x, float eps) +{ + return std::min(1.0f, x + eps); +} + +float MyCanvas::SafeSub(float x, float eps) +{ + return std::max(0.0f, x - eps); +} +void MyCanvas::ApplyPadStyle(TPad* pad) +{ + pad->SetFillColor(gStyle->GetPadColor()); + // pad->SetTickx(gStyle->GetPadTickX()); + // pad->SetTicky(gStyle->GetPadTickY()); + pad->SetFrameLineWidth(gStyle->GetFrameLineWidth()); + pad->SetFrameFillColor(gStyle->GetFrameFillColor()); + pad->SetFrameBorderMode(gStyle->GetFrameBorderMode()); + pad->SetFrameBorderSize(gStyle->GetFrameBorderSize()); +} +void MyCanvas::DrawGraphWithErrorOutline(ObjType gvar, int lineWidth = 2, int lineColor = kBlack) +{ + std::visit([lineWidth, lineColor](auto* g) { + using T = std::decay_t; + if constexpr (std::is_same_v || std::is_same_v) { + if (!g) + return; + + // Draw the error band with transparent fill + g->SetFillStyle(-1); // No fill + // g->SetFillColor(0); + g->Draw("3"); + + // Prepare vectors + int n = g->GetN(); + std::vector x(n), yUpper(n), yLower(n); + + for (int i = 0; i < n; ++i) { + double xi, yi; + g->GetPoint(i, xi, yi); + x[i] = xi; + + if constexpr (std::is_same_v, TGraphErrors>) { + double ey = g->GetErrorY(i); + yUpper[i] = yi + ey; + yLower[i] = yi - ey; + } else if constexpr (std::is_same_v, TGraphAsymmErrors>) { + double eyh = g->GetErrorYhigh(i); + double eyl = g->GetErrorYlow(i); + yUpper[i] = yi + eyh; + yLower[i] = yi - eyl; + } + } + + // Create and draw upper and lower outlines + TGraph* upper = new TGraph(n, x.data(), yUpper.data()); + TGraph* lower = new TGraph(n, x.data(), yLower.data()); + upper->SetLineWidth(lineWidth); + lower->SetLineWidth(lineWidth); + upper->SetLineColor(lineColor); + lower->SetLineColor(lineColor); + upper->SetLineStyle(1); // dashed + lower->SetLineStyle(1); + upper->Draw("L SAME"); + lower->Draw("L SAME"); + } + }, + gvar); +} +// NOLINTEND(readability/casting, readability/braces, whitespace/parens, whitespace/newline, whitespace/comma, whitespace/operators) diff --git a/PWGCF/GenericFramework/Core/MyCanvas.h b/PWGCF/GenericFramework/Core/MyCanvas.h new file mode 100644 index 00000000000..897fa948955 --- /dev/null +++ b/PWGCF/GenericFramework/Core/MyCanvas.h @@ -0,0 +1,221 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// NOLINTBEGIN(readability/casting, readability/braces) +#ifndef PWGCF_GENERICFRAMEWORK_CORE_MYCANVAS_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_MYCANVAS_H_ + +#include "TCanvas.h" +#include "TGraphAsymmErrors.h" +#include "TGraphErrors.h" +#include "TH1.h" +#include "TLatex.h" +#include "TLegend.h" +#include "TLine.h" +#include "TPad.h" +#include "TString.h" +#include "TStyle.h" + +#include +#include +#include +#include +#include +#include + +// Helper to detect if T has SetFillStyle(int) +template +struct has_GetNbinsX : std::false_type { +}; + +template +struct has_GetNbinsX().GetNbinsX())>> : std::true_type { +}; + +using namespace std; +class MyCanvas +{ + public: + using ObjType = std::variant; + MyCanvas(); + explicit MyCanvas(const char* name, double w = 500, double h = 500, double lm = 0.05, double bm = 0.08, double tm = 0.04, double rm = 0.04); + ~MyCanvas(); + TCanvas* BuildSingleCanvas(); + TCanvas* BuildRatioCanvas(double pr); + TCanvas* BuildMultiRatioCanvas(int N, float pr, bool separatePad = false); + TCanvas* BuildNbyMCanvas(int N, int M, bool separatePad = false); + TCanvas* BuildNbyMRatioCanvas(int N, int M, double pr = 0.33, bool separatePad = false, bool alternateAxisSide = false); + void cd(int Npad = 1); + TPad* GetPad(int Npad = 1); + void cdCanvas() { mCanvas->cd(); }; + void SetLogy(int Npad = 1) + { + TPad* tmp = (TPad*)mCanvas->GetPad(Npad); + tmp->SetLogy(); + } + void SetLogx(int Npad = 1) + { + TPad* tmp = (TPad*)mCanvas->GetPad(Npad); + tmp->SetLogx(); + } + void SetLogz(int Npad = 1) + { + TPad* tmp = (TPad*)mCanvas->GetPad(Npad); + tmp->SetLogz(); + } + void SaveAs(const char* name, const char* opt); + void Print(const char* name) { mCanvas->Print(name); } + void Write() { mCanvas->Write(); } + void AddLegEntriesAbove(bool add) { addAbove = add; } + template + void AddLegEntry(T entry, TString name, const char* drawopt, int legInd) + { + BuildLegend(0.5, 0.5, 0.6, 0.6, legInd, 1); + mLeg[legInd]->AddEntry(entry, name, drawopt); + return; + } + void AddObject(ObjType stat, int Npad = 0, int color = -1, int style = -1, ObjType sys = {}); + void AddModel(ObjType model, int Npad, int color, int fillstyle, float alpha = 1.); + void AddLine(double x1, double y1, double x2, double y2, int nPad = 0); + void AddText(double x, double y, const char* text, bool NDC = true, int textsize = 0, int textcolor = kBlack); + void Draw(const char* opt = ""); + void DrawLegend(double x1, double y1, int legInd = 0, int nCol = 1); + void DrawLegend(double x1, double y1, double x2, double y2, int legInd = 0, int nCol = 1); + void DrawLegend(TString loc, int legInd = 0, int nCol = 1); + void Update() { mCanvas->Update(); } + void UseSameYscale(bool newval) { mUseSameYscale = newval; } + int GetTextSize() { return mTextSize; } + void SetYScale(double newval, double ratioval = 0) + { + mYscale = newval; + if (ratioval) + mRatioYScale = ratioval; + else + mRatioYScale = newval; + } // Controls how large a percentage above/below the max/min values of the histograms should be drawn + void SetYLimits(double ymin = -999, double ymax = -999) + { + mYmin = ymin; + mYmax = ymax; + } + void SetYLimits(double ymin, double ymax, int padNo) { padlimits[padNo] = std::make_pair(ymin, ymax); } + void SetYRatioLimits(double yRatioMin, double yRatioMax) + { + mYRatioMin = yRatioMin; + mYRatioMax = yRatioMax; + } + void SetTextSize(int newval) { mTextSize = newval; } + void SetTitleOffset(double newval, TString axis = "Y") + { + if (axis.EqualTo("Y")) + mOffset[1] = newval; + else + mOffset[0] = newval; + } + void SetTitle(TString newval) { mTitle = newval; } + void SetLabelOffset(double newval) { mLabelOffset = newval; } + void ForceXLimits(double xmin, double xmax) + { + mXmin = xmin; + mXmax = xmax; + }; + void SetModelDrawOption(std::string option) { fModelDrawOpt = option; } + void SetAdjustTicks(bool newval) { mAdjustTicks = newval; } + void DrawGraphWithErrorOutline(ObjType gvar, int lineWidth, int lineColor); + bool isInitialised() { return initialised; } + void SetLineWidth(int w) { mLineWidth = w; } + + template + TGraphErrors* HistToGraph(T h); // public, don't want to reimplement elsewhere + TGraphErrors* HistToGraph(TGraphErrors* gr) + { + gr->SetFillColorAlpha(gr->GetMarkerColor(), 0.4); + return gr; + } + struct DrawObject { + ObjType stat; + ObjType sys; + int color; + int style; + double min; + double max; + }; + struct ModelObject { + ObjType model; + int color; + int fillstyle; + float alpha; + double min; + double max; + }; + + private: + bool initialised; + const char* mName; + double mWidth; + double mHeight; + double mTopMargin; + double mBottomMargin; + double mLeftMargin; + double mRightMargin; + int mM; + int mN; + bool addAbove; + TCanvas* mCanvas; + vector mLeg; + int mTextSize; + vector mOffset; + TString mTitle; + double mLabelOffset; + double mYmin; + double mYmax; + double mXmin; + double mXmax; + double mYRatioMin; + double mYRatioMax; + bool mAddCentLabel; + double mYscale; + double mRatioYScale; + bool mUseSameYscale; + bool mSeparatePad; + bool mAlternateAxisSide; + bool fRatioCanvas; + bool mAdjustTicks; + bool mLineWidth; + int mLegIndex; + std::string fModelDrawOpt; + vector mStyles; + vector mColors; + map stylemap; + vector mFstyles; + void BuildLegend(double x1, double y1, double x2, double y2, int legInd = 0, int nCol = 0); + void ApplyFormat(); + void SetLimits(); + float SafeAdd(float x, float eps); + float SafeSub(float x, float eps); + void ApplyPadStyle(TPad* pad); + static bool isGraphType(const ObjType& obj) + { + return std::visit( + [](auto* ptr) { + using T = std::decay_t; + return std::is_same_v || std::is_same_v; + }, + obj); + } + vector> objVector; + vector> modelVector; + std::map> padlimits; //! + + ClassDef(MyCanvas, 1); +}; +#endif // PWGCF_GENERICFRAMEWORK_CORE_MYCANVAS_H_ +// NOLINTEND(readability/casting, readability/braces) diff --git a/PWGCF/GenericFramework/Core/OutputHandler.cxx b/PWGCF/GenericFramework/Core/OutputHandler.cxx new file mode 100644 index 00000000000..3bcab5742ae --- /dev/null +++ b/PWGCF/GenericFramework/Core/OutputHandler.cxx @@ -0,0 +1,1457 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// NOLINTBEGIN(readability/braces) +#include "OutputHandler.h" + +#include +#include +#include +#include +#include +#include +#include + +ClassImp(OutputHandler); + +namespace +{ +void deleteSubsampleHistograms(const std::vector& sampleHistograms) +{ + // StatHandler::getNominal() returns sampleHistograms[0]. Keep that histogram + // for the caller and release only the bootstrap/subsample histograms. + for (std::size_t i = 1; i < sampleHistograms.size(); ++i) { + delete sampleHistograms[i]; + } +} +} // namespace + +OutputHandler::OutputHandler(std::string system) : TNamed("", ""), + flowcont(nullptr), + flowptcont(nullptr), + stathandler(nullptr), + sysHandler(nullptr), + fileName(""), + isInitialised(0), + isGen(0), + useFSRebin(true), + useLateCentralityRebin(false), + doSystemRatio(false), + radialFlowAnalysis(0), + fNrb(0), + fBinsrb(0), + xAxisTitle("Centrality (%)") +{ + calculator.setSystem(system); +} +OutputHandler::OutputHandler(std::string filename, std::string system) : TNamed("", ""), + flowcont(nullptr), + flowptcont(nullptr), + stathandler(nullptr), + sysHandler(nullptr), + fileName(filename), + isInitialised(0), + isGen(0), + useFSRebin(true), + useLateCentralityRebin(false), + doSystemRatio(false), + radialFlowAnalysis(0), + fNrb(0), + fBinsrb(0), + xAxisTitle("Centrality (%)") +{ + calculator.setSystem(system); + initialise(filename); +} +OutputHandler::~OutputHandler() +{ + for (auto& [index, variation] : additionalSystematicVariations) { + delete variation; + } + delete stathandler; + delete flowcont; + delete flowptcont; + delete sysHandler; + for (auto& [name, file] : inputFiles) { + if (file) { + file->Close(); + delete file; + } + } +}; + +void OutputHandler::setInvMassFitFunctions(const std::string& species, const std::string& signalFunction, const std::string& backgroundFunction) +{ + calculator.setInvMassFitFunctions(species, signalFunction, backgroundFunction); +} + +void OutputHandler::setInvMassFitFunctionsForSystematic(int systematicIndex, + const std::string& species, + const std::string& signalFunction, + const std::string& backgroundFunction) +{ + calculator.setInvMassFitFunctionsForSystematic(systematicIndex, species, signalFunction, backgroundFunction); +} + +void OutputHandler::setInvMassFitCentralityBins(const std::vector& centralityBins) +{ + calculator.setInvMassFitCentralityBins(centralityBins); +} + +void OutputHandler::setAdditionalSystematicVariation(int index, TH1* variation) +{ + if (!variation) { + return; + } + auto existing = additionalSystematicVariations.find(index); + if (existing != additionalSystematicVariations.end()) { + delete existing->second; + } + additionalSystematicVariations[index] = variation; +} + +void OutputHandler::setSystematicVariations(const std::vector& variations) +{ + systematicVariations = variations; + hasCustomSystematicVariations = true; + if (sysHandler) { + sysHandler->setSystematicVariations(systematicVariations); + } +} + +void OutputHandler::setFitSignificanceRejection(bool enabled, double minSignificance) +{ + if (!sysHandler) { + printf("Please initialise OutputHandler with systematics before setting fit-significance rejection\n"); + return; + } + sysHandler->setFitSignificanceRejection(enabled, minSignificance); +} + +void OutputHandler::initialise(std::string filename, std::string dirname, bool hasSystematics, SysHandler::SystSettings settings) +{ + delete stathandler; + stathandler = nullptr; + delete sysHandler; + sysHandler = nullptr; + isInitialised = false; + if (hasSystematics) { + sys_indices = getKeyIndices(filename); + sysHandler = new SysHandler(); + sysHandler->setSystSettings(settings); + if (hasCustomSystematicVariations) { + sysHandler->setSystematicVariations(systematicVariations); + } + if (!sysHandler) { + printf("Outputhandler failed to initialise SysHandler object\n"); + return; + } + } + fileName = filename; + dirName = dirname; + TFile* file = readFile(fileName); + if (!file) + return; + if (!calculator.readData(file, dirname, isGen, radialFlowAnalysis)) { + printf("Outputhandler failed to initialise StatHandler object\n"); + return; + } + stathandler = new StatHandler(); + isInitialised = 1; + printf("Outputhandler initialised succesfully\n"); + return; +} +TH1D* OutputHandler::getHist(Calculator::ObsFunc func, StatHandler::StatMethod method) +{ + if (!isInitialised) { + printf("Initialise OutputHandler before getting histograms\n"); + return nullptr; + } + Calculator::ObsFunc tmp_func = func; + if (isVN(func) && fNrb) + func = getCorrespondingCumulant(func); + std::vector samplehists; + for (int i = -1; i < 10; ++i) { + TH1D* samplehist = calculator.calculate(func, i); + if (doSystemRatio && (!isVN(tmp_func) || !fNrb)) { + calculator.readData(readFile(fileName2), dirName, isGen, radialFlowAnalysis); + TH1D* denhist = calculator.calculate(func, i); + samplehist->Divide(denhist); + delete denhist; + calculator.readData(readFile(fileName), dirName, isGen, radialFlowAnalysis); + } + samplehists.push_back(samplehist); + } + auto reth = stathandler->getNominal(samplehists, method); + deleteSubsampleHistograms(samplehists); + if (isVN(tmp_func) && fNrb) { + if (useFSRebin && !doSystemRatio) { + printf("Rebinning on cumulant level\n"); + FSRebin(&reth); + } + calculateVN(tmp_func, reth); + if (doSystemRatio) { + std::vector samplehists2; + calculator.readData(readFile(fileName2), dirName, isGen, radialFlowAnalysis); + for (int i = -1; i < 10; ++i) { + TH1D* samplehist2 = calculator.calculate(func, i); + samplehists2.push_back(samplehist2); + } + auto reth2 = stathandler->getNominal(samplehists2, method); + deleteSubsampleHistograms(samplehists2); + calculator.readData(readFile(fileName), dirName, isGen, radialFlowAnalysis); + calculateVN(tmp_func, reth2); + reth->Divide(reth2); + delete reth2; + FSRebin(&reth); + } + } + func = tmp_func; + // sysHandler->applySyst(reth); + reth->SetName(getName(func).c_str()); + if (reth->GetNbinsX() > 100) + xAxisTitle = "N_{ch}"; + reth->SetTitle(Form("; %s;%s", xAxisTitle.c_str(), getLatexName(func).c_str())); + if (useFSRebin && !isVN(func)) + FSRebin(&reth); + return reth; +} +TH1D* OutputHandler::getHist(Calculator::PtDiffFunc func, double min, double max, StatHandler::StatMethod method) +{ + if (!isInitialised) { + printf("Initialise OutputHandler before getting histograms\n"); + return nullptr; + } + Calculator::PtDiffFunc tmp_func = func; + if (isVN(func)) + func = getCorrespondingCumulant(func); + std::vector samplehists; + for (int i = -1; i < 10; ++i) { + TH1D* samplehist = useLateCentralityRebin + ? calculator.calculateWithLateCentralityRebin(func, i, min, max) + : calculator.calculate(func, i, min, max); + if (!samplehist) { + printf("Failed to calculate sample %d for centrality %.1f-%.1f\n", i, min, max); + for (auto* hist : samplehists) + delete hist; + return nullptr; + } + if (doSystemRatio) { + calculator.readData(readFile(fileName2), dirName, isGen, radialFlowAnalysis); + TH1D* denhist = useLateCentralityRebin + ? calculator.calculateWithLateCentralityRebin(func, i, min, max) + : calculator.calculate(func, i, min, max); + samplehist->Divide(denhist); + delete denhist; + calculator.readData(readFile(fileName), dirName, isGen, radialFlowAnalysis); + } + samplehists.push_back(samplehist); + } + auto reth = stathandler->getNominal(samplehists, method); + deleteSubsampleHistograms(samplehists); + if (isVN(tmp_func)) { + if (useFSRebin) { + if (fNrb) + printf("Rebinning on cumulant level\n"); + FSRebin(&reth); + } + calculateVN(tmp_func, reth, min, max); + } + func = tmp_func; + reth->SetName(getName(func, min, max).c_str()); + xAxisTitle = "#it{p}_{T} (GeV/#it{c})"; + reth->SetTitle(Form("; %s;%s", xAxisTitle.c_str(), getLatexName(func).c_str())); + if (useFSRebin && !isVN(func)) + FSRebin(&reth); + return reth; +} +TH1D* OutputHandler::getSysHist(Calculator::ObsFunc func, bool use_bootstrap_for_systs, StatHandler::StatMethod method, bool relative, const TH1* nominal) +{ + if (!sysHandler) { + printf("Warning: SysHandler is not initialised\n"); + return nullptr; + } + current_obs = getName(func); + std::cout << current_obs.c_str() << std::endl; + std::map sysMap; + TH1* nom = nominal ? dynamic_cast(nominal->Clone(Form("%s_sysNominal", nominal->GetName()))) : getHist(func); + if (nominal) + nom->SetDirectory(nullptr); + // if(useFSRebin) FSRebin(&nom); + + sysMap[0] = nom; + const std::size_t systematicCount = std::count_if(sys_indices.begin(), sys_indices.end(), [this](int index) { + return sysHandler->getTarget(index) != 0 && !additionalSystematicVariations.count(index); + }); + std::size_t processedSystematics = 0; + for (auto& i : sys_indices) { + if (sysHandler->getTarget(i) == 0 || additionalSystematicVariations.count(i)) + continue; + if (systematicProgressCallback) + systematicProgressCallback(processedSystematics, systematicCount, i); + std::string index = std::to_string(i); + calculator.readData(readFile(fileName), index, isGen, radialFlowAnalysis); + if (use_bootstrap_for_systs) { + std::vector sys_sample_hists; + for (int j = -1; j < 10; ++j) { + TH1D* sys_samplehist = calculator.calculate(func, j); + if (doSystemRatio) { + calculator.readData(readFile(fileName2), dirName, isGen, radialFlowAnalysis); + TH1D* denhist = calculator.calculate(func, j); + sys_samplehist->Divide(denhist); + delete denhist; + calculator.readData(readFile(fileName), index, isGen, radialFlowAnalysis); + } + sys_sample_hists.push_back(sys_samplehist); + } + auto reth = stathandler->getNominal(sys_sample_hists, method); + deleteSubsampleHistograms(sys_sample_hists); + if (useFSRebin) + FSRebin(&reth); + sysMap[i] = reth; + } else { + TH1* reth = calculator.calculate(func, -1); + if (doSystemRatio) { + calculator.readData(readFile(fileName2), dirName, isGen, radialFlowAnalysis); + TH1D* denhist = calculator.calculate(func, -1); + reth->Divide(denhist); + delete denhist; + calculator.readData(readFile(fileName), index, isGen, radialFlowAnalysis); + } + if (useFSRebin) + FSRebin(&reth); + sysMap[i] = reth; + } + if (systematicProgressCallback) + systematicProgressCallback(++processedSystematics, systematicCount, i); + } + for (auto& [index, variation] : additionalSystematicVariations) { + sysMap[index] = variation; + } + additionalSystematicVariations.clear(); + calculator.readData(readFile(fileName), dirName, isGen, radialFlowAnalysis); + sysHandler->setSysMap(sysMap); + TH1D* sysh = sysHandler->getNominal(relative); + if (sysh->GetNbinsX() > 100) + xAxisTitle = "N_{ch}"; + return sysh; +} +TH1D* OutputHandler::getSysHist(Calculator::PtDiffFunc func, double min, double max, bool use_bootstrap_for_systs, StatHandler::StatMethod method, bool relative, const TH1* nominal) +{ + if (!sysHandler) { + printf("Warning: SysHandler is not initialised\n"); + return nullptr; + } + current_obs = getName(func, min, max); + std::cout << current_obs.c_str() << std::endl; + std::map sysMap; + TH1* nom = nominal ? dynamic_cast(nominal->Clone(Form("%s_sysNominal", nominal->GetName()))) : getHist(func, min, max); + if (nominal) + nom->SetDirectory(nullptr); + // if(useFSRebin) FSRebin(&nom); + sysMap[0] = nom; + const std::size_t systematicCount = std::count_if(sys_indices.begin(), sys_indices.end(), [this](int index) { + return sysHandler->getTarget(index) != 0 && !additionalSystematicVariations.count(index); + }); + std::size_t processedSystematics = 0; + for (auto& i : sys_indices) { + if (sysHandler->getTarget(i) == 0 || additionalSystematicVariations.count(i)) + continue; + if (systematicProgressCallback) + systematicProgressCallback(processedSystematics, systematicCount, i); + std::string index = std::to_string(i); + calculator.readData(readFile(fileName), index, isGen, radialFlowAnalysis); + if (use_bootstrap_for_systs) { + std::vector sys_sample_hists; + for (int j = -1; j < 10; ++j) { + TH1D* sys_samplehist = useLateCentralityRebin + ? calculator.calculateWithLateCentralityRebin(func, j, min, max) + : calculator.calculate(func, j, min, max); + if (doSystemRatio) { + calculator.readData(readFile(fileName2), dirName, isGen, radialFlowAnalysis); + TH1D* denhist = useLateCentralityRebin + ? calculator.calculateWithLateCentralityRebin(func, j, min, max) + : calculator.calculate(func, j, min, max); + sys_samplehist->Divide(denhist); + delete denhist; + calculator.readData(readFile(fileName), index, isGen, radialFlowAnalysis); + } + sys_sample_hists.push_back(sys_samplehist); + } + auto reth = stathandler->getNominal(sys_sample_hists, method); + deleteSubsampleHistograms(sys_sample_hists); + if (useFSRebin) + FSRebin(&reth); + sysMap[i] = reth; + } else { + TH1* reth = useLateCentralityRebin + ? calculator.calculateWithLateCentralityRebin(func, -1, min, max) + : calculator.calculate(func, -1, min, max); + if (doSystemRatio) { + calculator.readData(readFile(fileName2), dirName, isGen, radialFlowAnalysis); + TH1D* denhist = useLateCentralityRebin + ? calculator.calculateWithLateCentralityRebin(func, -1, min, max) + : calculator.calculate(func, -1, min, max); + reth->Divide(denhist); + delete denhist; + calculator.readData(readFile(fileName), index, isGen, radialFlowAnalysis); + } + if (useFSRebin) + FSRebin(&reth); + sysMap[i] = reth; + } + if (systematicProgressCallback) + systematicProgressCallback(++processedSystematics, systematicCount, i); + } + for (auto& [index, variation] : additionalSystematicVariations) { + sysMap[index] = variation; + } + additionalSystematicVariations.clear(); + calculator.readData(readFile(fileName), dirName, isGen, radialFlowAnalysis); + sysHandler->setSysMap(sysMap); + TH1D* sysh = sysHandler->getNominal(relative); + xAxisTitle = "#it{p}_{T} (GeV/#it{c})"; + return sysh; +} + +void OutputHandler::RebinMulti(Int_t nrb, Double_t* chbins) +{ + // New approach: + fNrb = nrb; + fBinsrb = chbins; + if (useFSRebin) + return; + printf("Rebinning on correlator level\n"); + calculator.Rebin(nrb, chbins); +} +template +void OutputHandler::FSRebin(T** inh) +{ + if (!fNrb) + return; // Rebin only when needed + T* sH = *inh; + TString hName(sH->GetName()); + sH->SetName(Form("%s_BU", hName.Data())); + T* tH = dynamic_cast(sH->Rebin(fNrb, hName.Data(), fBinsrb)); + tH->Reset(); + for (Int_t i = 1; i <= sH->GetNbinsX(); i++) { + Double_t bc = sH->GetBinContent(i); + Double_t be = sH->GetBinError(i); + if (be == 0) + continue; + be = (1. / (be * be)); + Double_t bind = tH->FindBin(sH->GetBinCenter(i)); + tH->SetBinContent(bind, tH->GetBinContent(bind) + bc * be); + tH->SetBinError(bind, tH->GetBinError(bind) + be); + } + for (Int_t i = 1; i <= tH->GetNbinsX(); i++) { + Double_t bc = tH->GetBinContent(i); + Double_t be = tH->GetBinError(i); + if (be == 0) + continue; + tH->SetBinContent(i, bc / be); + tH->SetBinError(i, TMath::Sqrt(1. / be)); + } + delete sH; + (*inh) = tH; +}; +TH1* OutputHandler::getRelSysHist(int sys_index, bool sys_from_fit, bool relative) +{ + if (!sysHandler) { + printf("Warning: SysHandler is not initialised\n"); + return nullptr; + } + if (sysHandler->getSystMap().empty()) { + printf("Warning: SysMap not filled! Call getSysHist() before this call\n"); + return nullptr; + } + TH1* relsys = (sys_from_fit) ? sysHandler->getSystematicsFromFit(sys_index, true, false, relative) : sysHandler->getSystematics(sys_index, relative, true, true); + if (!relsys) { + printf("Warning: Could not calculate systematic index %i\n", sys_index); + return nullptr; + } + // FSRebin(&relsys); + relsys->SetTitle(Form(";%s;%s", xAxisTitle.c_str(), relative ? "Rel. sys." : "Abs. sys.")); + return relsys; +} +TH1* OutputHandler::getBarlowHist(int sys_index) +{ + if (!sysHandler) { + printf("Warning: SysHandler is not initialised\n"); + return nullptr; + } + if (sysHandler->getSystMap().empty()) { + printf("Warning: SysMap not filled! Call getSysHist() before this call\n"); + return nullptr; + } + TH1* barlow = sysHandler->getBarlowTest(sys_index, sysHandler->getCorrelationError(sys_index)); + // FSRebin(&barlow); + barlow->SetTitle(Form(";%s;Barlow", xAxisTitle.c_str())); + return barlow; +} +TH1* OutputHandler::getVarNomRatioHist(int sys_index) +{ + if (!sysHandler) { + printf("Warning: SysHandler is not initialised\n"); + return nullptr; + } + if (sysHandler->getSystMap().empty()) { + printf("Warning: SysMap not filled! Call getSysHist() before this call\n"); + return nullptr; + } + TH1* ratio = sysHandler->getSystematicsFromFit(sys_index, false, true); + if (useFSRebin) { + FSRebin(&ratio); + } + SysHandler::SystSettings sys_settings = sysHandler->getSystSettings(); + ratio->Fit("pol0", "Q0+R", "", sys_settings.sys_avg_range.first, sys_settings.sys_avg_range.second); + ratio->SetTitle(Form(";%s; nominal / variation", xAxisTitle.c_str())); + return ratio; +} +TH1* OutputHandler::getVarHist(int sys_index) +{ + if (!sysHandler) { + printf("Warning: SysHandler is not initialised\n"); + return nullptr; + } + if (sysHandler->getSystMap().empty()) { + printf("Warning: SysMap not filled! Call getSysHist() before this call\n"); + return nullptr; + } + TH1* storedVariation = sysHandler->getVariation(sys_index); + if (!storedVariation) { + printf("Warning: Systematic variation %d is missing\n", sys_index); + return nullptr; + } + TH1* var = dynamic_cast(storedVariation->Clone(Form("VariationPlot_Ind%d_%s", sys_index, storedVariation->GetName()))); + var->SetDirectory(nullptr); + if (useFSRebin) + FSRebin(&var); + var->SetTitle(Form(";%s; variation", xAxisTitle.c_str())); + return var; +} +TFile* OutputHandler::readFile(std::string name) +{ + auto cachedFile = inputFiles.find(name); + if (cachedFile != inputFiles.end()) { + return cachedFile->second; + } + TFile* infile = new TFile(name.c_str(), "READ"); + if (!infile) { + printf("File %s not found!\n", name.c_str()); + return nullptr; + }; + if (infile->IsZombie()) { + printf("File %s is a zombie!\n", name.c_str()); + delete infile; + return nullptr; + }; + inputFiles[name] = infile; + return infile; +} +std::vector OutputHandler::getKeyIndices(std::string name) +{ + TFile* f = readFile(name); + std::vector indices; + std::string dirname = dirName; + for (auto&& key : *f->GetListOfKeys()) { + std::string keyname = key->GetName(); + if (keyname.find(dirname) == std::string::npos) + continue; + auto tokens = split(keyname, '_'); + if (tokens.size() > 1) { + indices.push_back(std::atoi(tokens[1].c_str())); + } + } + std::unordered_set seen; + indices.erase(std::remove_if(indices.begin(), indices.end(), [&seen](int num) { + return !seen.insert(num).second; // Insert returns false if num is already in the set + }), + indices.end()); + std::sort(indices.begin(), indices.end()); + return indices; +} +std::vector OutputHandler::split(const std::string& s, char delimiter) +{ + std::vector tokens; + std::stringstream ss(s); + std::string item; + while (std::getline(ss, item, delimiter)) { + tokens.push_back(item); + } + return tokens; +} +std::string OutputHandler::getLatexName(Calculator::ObsFunc func) +{ + std::string str; + if (func == &Calculator::getV12) + str = "v_{1}{2}"; + if (func == &Calculator::getV22) + str = "v_{2}{2}"; + if (func == &Calculator::getV32) + str = "v_{3}{2}"; + if (func == &Calculator::getV42) + str = "v_{4}{2}"; + if (func == &Calculator::getV24) + str = "v_{2}{4}"; + if (func == &Calculator::getV26) + str = "v_{2}{6}"; + if (func == &Calculator::getV28) + str = "v_{2}{8}"; + if (func == &Calculator::getV24overV22) + str = "v_{2}{4}/v_{2}{2}"; + if (func == &Calculator::getV32overV22) + str = "v_{3}{2}/v_{2}{2}"; + if (func == &Calculator::getV24_3sub) + str = "v_{2}{4}^{3sub}"; + if (func == &Calculator::getV2LLMR) + str = "v_{2}{LLMR}"; + if (func == &Calculator::getV2LMMR) + str = "v_{2}{LMMR}"; + if (func == &Calculator::getV2LMRR) + str = "v_{2}{LMRR}"; + if (func == &Calculator::getVarV22) + str = "Var(v_{2}^{2})"; + if (func == &Calculator::getC12) + str = "c_{1}{2}"; + if (func == &Calculator::getC12Full) + str = "c_{1}{2}"; + if (func == &Calculator::getC22) + str = "c_{2}{2}"; + if (func == &Calculator::getC22Full) + str = "c_{2}{2}"; + if (func == &Calculator::getC32) + str = "c_{3}{2}"; + if (func == &Calculator::getC42) + str = "c_{4}{2}"; + if (func == &Calculator::getC24) + str = "c_{2}{4}"; + if (func == &Calculator::getC14) + str = "c_{1}{4}"; + if (func == &Calculator::getC26) + str = "c_{2}{6}"; + if (func == &Calculator::getC28) + str = "c_{2}{8}"; + if (func == &Calculator::get22) + str = "#LT#LT2#GT#GT_{2,-2}"; + if (func == &Calculator::get32) + str = "#LT#LT2#GT#GT_{3,-3}"; + if (func == &Calculator::get42) + str = "#LT#LT2#GT#GT_{4,-4}"; + if (func == &Calculator::get24) + str = "#LT#LT4#GT#GT_{2,2,-2,-2}"; + if (func == &Calculator::getC24_3sub) + str = "c_{2}{4}^{3sub}"; + if (func == &Calculator::getC2LLMR) + str = "c_{2}{LLMR}"; + if (func == &Calculator::getC2LMMR) + str = "c_{2}{LMMR}"; + if (func == &Calculator::getC2LMRR) + str = "c_{2}{LMRR}"; + if (func == &Calculator::get2LR) + str = "#LT LR#GT_{2,-2}"; + if (func == &Calculator::get2LM) + str = "#LT LM#GT_{2,-2}"; + if (func == &Calculator::get2MR) + str = "#LT MR#GT_{2,-2}"; + if (func == &Calculator::getMpt) + str = "#LT[#it{p}]#GT"; + if (func == &Calculator::getMptSubAvg) + str = "#LT[#it{p}]#GT^{avg}"; + if (func == &Calculator::getK2) + str = "c_{2}"; + if (func == &Calculator::getK2Norm) + str = "k_{2}"; + if (func == &Calculator::getK3) + str = "c_{3}"; + if (func == &Calculator::getK3Norm) + str = "k_{3}"; + if (func == &Calculator::getK4) + str = "c_{4}"; + if (func == &Calculator::getMu2) + str = "#mu_{2}"; + if (func == &Calculator::getDeltaPtOverPt) + str = "#sqrt{#delta#it{p}_{T}^{2}}/#LT[#it{p}]#GT"; + if (func == &Calculator::getMu3) + str = "#mu_{3}"; + if (func == &Calculator::getMu4) + str = "#mu_{4}"; + if (func == &Calculator::getStdSkew) + str = "#gamma_{#LT[#it{p}_{T}]#GT}"; + if (func == &Calculator::getIntSkew) + str = "#Gamma_{#LT[#it{p}_{T}]#GT}"; + if (func == &Calculator::getExKur) + str = "#kappa_{#LT[#it{p}_{T}]#GT}"; + if (func == &Calculator::getK2sub) + str = "c_{2}^{sub}"; + if (func == &Calculator::getK2NormSub) + str = "k_{2}^{sub}"; + if (func == &Calculator::getK3sub) + str = "c_{3}^{sub}"; + if (func == &Calculator::getK3_3sub) + str = "c_{3}^{3sub}"; + if (func == &Calculator::getK3Norm_3sub) + str = "k_{3}^{3sub}"; + if (func == &Calculator::getK3subA) + str = "c_{3}^{sub,A}"; + if (func == &Calculator::getK3subB) + str = "c_{3}^{sub,B}"; + if (func == &Calculator::getK4sub) + str = "c_{4}^{sub}"; + if (func == &Calculator::getK4_4sub) + str = "c_{4}^{4sub}"; + if (func == &Calculator::getMu2sub) + str = "#mu_{2}^{sub}"; + if (func == &Calculator::getMu3sub) + str = "#mu_{3}^{sub}"; + if (func == &Calculator::getMu4sub) + str = "#mu_{4}^{sub}"; + if (func == &Calculator::getStdSkewSub) + str = "#gamma_{#LT[#it{p}_{T}]#GT}^{sub}"; + if (func == &Calculator::getIntSkewSub) + str = "#Gamma_{#LT[#it{p}_{T}]#GT}^{sub}"; + if (func == &Calculator::getExKurSub) + str = "#kappa_{#LT[#it{p}_{T}]#GT}^{sub}"; + if (func == &Calculator::getStdSkew_3sub) + str = "#gamma_{#LT[#it{p}_{T}]#GT}^{3sub}"; + if (func == &Calculator::getIntSkew_3sub) + str = "#Gamma_{#LT[#it{p}_{T}]#GT}^{3sub}"; + if (func == &Calculator::getExKur_4sub) + str = "#kappa_{#LT[#it{p}_{T}]#GT}^{4sub}"; + if (func == &Calculator::getCV12pt) + str = "C(v_{1}^{2},#delta#it{p}_{T})"; + if (func == &Calculator::getCV22pt) + str = "C(v_{2}^{2},#delta#it{p}_{T})"; + if (func == &Calculator::getRhoV22pt) + str = "#rho(v_{2}^{2},#delta#it{p}_{T})"; + + if (func == &Calculator::getIntegratedV0) + str = "v_{0}"; + if (func == &Calculator::getIntegratedV02) + str = "v_{02}"; + return str; +} +std::string OutputHandler::getLatexName(Calculator::PtDiffFunc func) +{ + std::string str; + if (func == &Calculator::getVPt22) + str = "v_{2}{2}"; + if (func == &Calculator::getVPt32) + str = "v_{3}{2}"; + if (func == &Calculator::getVPt42) + str = "v_{4}{2}"; + if (func == &Calculator::getVPt24) + str = "v_{2}{4}"; + if (func == &Calculator::getD22) + str = "d_{2}{2}"; + if (func == &Calculator::getD32) + str = "d_{3}{2}"; + if (func == &Calculator::getD42) + str = "d_{4}{2}"; + if (func == &Calculator::getD24) + str = "d_{2}{4}"; + + if (func == &Calculator::getVPt24_3sub) + str = "v_{2}{4}^{3sub}"; + if (func == &Calculator::getD24_3sub) + str = "d_{2}{4}^{3sub}"; + if (func == &Calculator::getD2LpLMR) + str = "d_{2}{L'LMR}"; + if (func == &Calculator::getD2LLMpR) + str = "d_{2}{LLM'R}"; + if (func == &Calculator::getD2LLMRp) + str = "d_{2}{LLMR'}"; + if (func == &Calculator::getD2LpMMR) + str = "d_{2}{L'MMR}"; + if (func == &Calculator::getD2LMpMR) + str = "d_{2}{LM'MR}"; + if (func == &Calculator::getD2LMMRp) + str = "d_{2}{LMMR'}"; + if (func == &Calculator::getD2LpMRR) + str = "d_{2}{L'MRR}"; + if (func == &Calculator::getD2LMpRR) + str = "d_{2}{LM'RR}"; + if (func == &Calculator::getD2LMRpR) + str = "d_{2}{LMR'R}"; + + if (func == &Calculator::get2LpLMR) + str = "#LT L'LMR#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LLMpR) + str = "#LT LLM'R#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LLMRp) + str = "#LT LLMR'#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LpMMR) + str = "#LT L'MMR#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LMpMR) + str = "#LT LM'MR#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LMMRp) + str = "#LT LMMR'#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LpMRR) + str = "#LT L'MRR#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LMpRR) + str = "#LT LM'RR#GT_{2,2,-2,-2}"; + if (func == &Calculator::get2LMRpR) + str = "#LT LMR'R#GT_{2,2,-2,-2}"; + + if (func == &Calculator::get2LRp) + str = "#LT LR'#GT_{2,-2}"; + if (func == &Calculator::get2LpR) + str = "#LT L'R#GT_{2,-2}"; + if (func == &Calculator::get2LpM) + str = "#LT L'M#GT_{2,-2}"; + if (func == &Calculator::get2LMp) + str = "#LT LM'#GT_{2,-2}"; + if (func == &Calculator::get2MpR) + str = "#LT M'R#GT_{2,-2}"; + if (func == &Calculator::get2MRp) + str = "#LT MR'#GT_{2,-2}"; + + if (func == &Calculator::getnptCh) + str = "n(#it{p}_{T})"; + if (func == &Calculator::getnptPi) + str = "n(#it{p}_{T})"; + if (func == &Calculator::getnptKa) + str = "n(#it{p}_{T})"; + if (func == &Calculator::getnptPr) + str = "n(#it{p}_{T})"; + if (func == static_cast(&Calculator::getnptK0)) + str = "n(#it{p}_{T})"; + if (func == static_cast(&Calculator::getnptLambda)) + str = "n(#it{p}_{T})"; + + if (func == &Calculator::getV0Ch) + str = "v_{0}"; + if (func == &Calculator::getV0Pi) + str = "v_{0}"; + if (func == &Calculator::getV0Ka) + str = "v_{0}"; + if (func == &Calculator::getV0Pr) + str = "v_{0}"; + if (func == &Calculator::getV0K0) + str = "v_{0}"; + if (func == &Calculator::getV0Lambda) + str = "v_{0}"; + if (func == &Calculator::getV0WeightedCh || func == &Calculator::getV0WeightedPi || + func == &Calculator::getV0WeightedKa || func == &Calculator::getV0WeightedPr || + func == &Calculator::getV0WeightedK0 || func == &Calculator::getV0WeightedLambda) + str = "v_{0}"; + if (func == &Calculator::getV00WeightedCh || func == &Calculator::getV00WeightedPi || + func == &Calculator::getV00WeightedKa || func == &Calculator::getV00WeightedPr || + func == &Calculator::getV00WeightedK0 || func == &Calculator::getV00WeightedLambda) + str = "v_{00}"; + if (func == &Calculator::getV0K0Alt) + str = "v_{0}"; + if (func == &Calculator::getV0LambdaAlt) + str = "v_{0}"; + + if (func == &Calculator::getV02Ch) + str = "v_{02}"; + if (func == &Calculator::getV02Pi) + str = "v_{02}"; + if (func == &Calculator::getV02Ka) + str = "v_{02}"; + if (func == &Calculator::getV02Pr) + str = "v_{02}"; + if (func == &Calculator::getV02K0) + str = "v_{02}"; + if (func == &Calculator::getV02Lambda) + str = "v_{02}"; + if (func == &Calculator::getV02WeightedCh || func == &Calculator::getV02WeightedPi || + func == &Calculator::getV02WeightedKa || func == &Calculator::getV02WeightedPr || + func == &Calculator::getV02WeightedK0 || func == &Calculator::getV02WeightedLambda) + str = "v_{02}"; + if (func == &Calculator::getV02K0Alt) + str = "v_{02}"; + if (func == &Calculator::getV02LambdaAlt) + str = "v_{02}"; + + if (func == &Calculator::getV0CorrCh) + str = "#LT [#it{p}_{T}]n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0CorrPi) + str = "#LT [#it{p}_{T}]n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0CorrKa) + str = "#LT [#it{p}_{T}]n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0CorrPr) + str = "#LT [#it{p}_{T}]n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0CorrK0) + str = "#LT [#it{p}_{T}]n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0CorrLambda) + str = "#LT [#it{p}_{T}]n(#it{p}_{T})#GT"; + + if (func == &Calculator::getV0CovCh) + str = "Cov([#it{p}_{T}],n(#it{p}_{T}))"; + if (func == &Calculator::getV0CovPi) + str = "Cov([#it{p}_{T}],n(#it{p}_{T}))"; + if (func == &Calculator::getV0CovKa) + str = "Cov([#it{p}_{T}],n(#it{p}_{T}))"; + if (func == &Calculator::getV0CovPr) + str = "Cov([#it{p}_{T}],n(#it{p}_{T}))"; + if (func == &Calculator::getV0CovK0) + str = "Cov([#it{p}_{T}],n(#it{p}_{T}))"; + if (func == &Calculator::getV0CovLambda) + str = "Cov([#it{p}_{T}],n(#it{p}_{T}))"; + + if (func == &Calculator::getV0MeansCh) + str = "#LT [#it{p}_{T}]#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0MeansPi) + str = "#LT [#it{p}_{T}]#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0MeansKa) + str = "#LT [#it{p}_{T}]#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0MeansPr) + str = "#LT [#it{p}_{T}]#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0MeansK0) + str = "#LT [#it{p}_{T}]#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV0MeansLambda) + str = "#LT [#it{p}_{T}]#GT#LT n(#it{p}_{T})#GT"; + + if (func == &Calculator::getV02CorrCh) + str = "#LT v_{2}^{2}n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02CorrPi) + str = "#LT v_{2}^{2}n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02CorrKa) + str = "#LT v_{2}^{2}n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02CorrPr) + str = "#LT v_{2}^{2}n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02CorrK0) + str = "#LT v_{2}^{2}n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02CorrLambda) + str = "#LT v_{2}^{2}n(#it{p}_{T})#GT"; + + if (func == &Calculator::getV02CovCh) + str = "Cov(v_{2}^{2},n(#it{p}_{T}))"; + if (func == &Calculator::getV02CovPi) + str = "Cov(v_{2}^{2},n(#it{p}_{T}))"; + if (func == &Calculator::getV02CovKa) + str = "Cov(v_{2}^{2},n(#it{p}_{T}))"; + if (func == &Calculator::getV02CovPr) + str = "Cov(v_{2}^{2},n(#it{p}_{T}))"; + if (func == &Calculator::getV02CovK0) + str = "Cov(v_{2}^{2},n(#it{p}_{T}))"; + if (func == &Calculator::getV02CovLambda) + str = "Cov(v_{2}^{2},n(#it{p}_{T}))"; + + if (func == &Calculator::getV02MeansCh) + str = "#LT v_{2}^{2}#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02MeansPi) + str = "#LT v_{2}^{2}#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02MeansKa) + str = "#LT v_{2}^{2}#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02MeansPr) + str = "#LT v_{2}^{2}#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02MeansK0) + str = "#LT v_{2}^{2}#GT#LT n(#it{p}_{T})#GT"; + if (func == &Calculator::getV02MeansLambda) + str = "#LT v_{2}^{2}#GT#LT n(#it{p}_{T})#GT"; + + if (func == &Calculator::getAlpha) + str = "#alpha"; + if (func == &Calculator::getBeta) + str = "#beta"; + if (func == &Calculator::getAlphaAlt) + str = "#alpha"; + if (func == &Calculator::getBetaAlt) + str = "#beta"; + + return str; +} +std::string OutputHandler::getName(Calculator::ObsFunc func) +{ + std::string str; + if (func == &Calculator::getV12) + str = "v12"; + if (func == &Calculator::getV22) + str = "v22"; + if (func == &Calculator::getV32) + str = "v32"; + if (func == &Calculator::getV42) + str = "v42"; + if (func == &Calculator::getV24) + str = "v24"; + if (func == &Calculator::getV26) + str = "v26"; + if (func == &Calculator::getV28) + str = "v28"; + if (func == &Calculator::getV24overV22) + str = "v24overv22"; + if (func == &Calculator::getV32overV22) + str = "v32overv22"; + if (func == &Calculator::getV24_3sub) + str = "v24_3sub"; + if (func == &Calculator::getV2LLMR) + str = "v2LLMR"; + if (func == &Calculator::getV2LMMR) + str = "v2LMMR"; + if (func == &Calculator::getV2LMRR) + str = "v2LMRR"; + if (func == &Calculator::getVarV22) + str = "varv22"; + if (func == &Calculator::getC12) + str = "c12"; + if (func == &Calculator::getC12Full) + str = "c12full"; + if (func == &Calculator::getC22) + str = "c22"; + if (func == &Calculator::getC22Full) + str = "c22full"; + if (func == &Calculator::getC32) + str = "c32"; + if (func == &Calculator::getC42) + str = "c42"; + if (func == &Calculator::getC24) + str = "c24"; + if (func == &Calculator::getC14) + str = "c14"; + if (func == &Calculator::getC26) + str = "c26"; + if (func == &Calculator::getC28) + str = "c28"; + if (func == &Calculator::get22) + str = "22"; + if (func == &Calculator::get32) + str = "32"; + if (func == &Calculator::get42) + str = "42"; + if (func == &Calculator::get24) + str = "24"; + if (func == &Calculator::getC24_3sub) + str = "c24_3sub"; + if (func == &Calculator::getC2LLMR) + str = "c2LLMR"; + if (func == &Calculator::getC2LMMR) + str = "c2LMMR"; + if (func == &Calculator::getC2LMRR) + str = "c2LMRR"; + if (func == &Calculator::get2LR) + str = "2LR"; + if (func == &Calculator::get2LM) + str = "2LM"; + if (func == &Calculator::get2MR) + str = "2MR"; + if (func == &Calculator::getMpt) + str = "mpt"; + if (func == &Calculator::getMptSubAvg) + str = "mptSubAvg"; + if (func == &Calculator::getK2) + str = "k2"; + if (func == &Calculator::getK2Norm) + str = "k2norm"; + if (func == &Calculator::getK3) + str = "k3"; + if (func == &Calculator::getK3Norm) + str = "k3norm"; + if (func == &Calculator::getK4) + str = "k4"; + if (func == &Calculator::getMu2) + str = "mu2"; + if (func == &Calculator::getDeltaPtOverPt) + str = "deltaptoverpt"; + if (func == &Calculator::getMu3) + str = "mu3"; + if (func == &Calculator::getMu4) + str = "mu4"; + if (func == &Calculator::getStdSkew) + str = "stdskew"; + if (func == &Calculator::getIntSkew) + str = "intskew"; + if (func == &Calculator::getExKur) + str = "exkur"; + if (func == &Calculator::getK2sub) + str = "k2sub"; + if (func == &Calculator::getK2NormSub) + str = "k2normsub"; + if (func == &Calculator::getK3sub) + str = "k3sub"; + if (func == &Calculator::getK3_3sub) + str = "k3_3sub"; + if (func == &Calculator::getK3Norm_3sub) + str = "k3norm_3sub"; + if (func == &Calculator::getK3subA) + str = "k3subA"; + if (func == &Calculator::getK3subB) + str = "k3subB"; + if (func == &Calculator::getK4sub) + str = "k4sub"; + if (func == &Calculator::getK4_4sub) + str = "k4_4sub"; + if (func == &Calculator::getMu2sub) + str = "mu2sub"; + if (func == &Calculator::getMu3sub) + str = "mu3sub"; + if (func == &Calculator::getMu4sub) + str = "mu4sub"; + if (func == &Calculator::getStdSkewSub) + str = "stdskewsub"; + if (func == &Calculator::getIntSkewSub) + str = "intskewsub"; + if (func == &Calculator::getExKurSub) + str = "kursub"; + if (func == &Calculator::getStdSkew_3sub) + str = "stdskew_3sub"; + if (func == &Calculator::getIntSkew_3sub) + str = "intskew_3sub"; + if (func == &Calculator::getExKur_4sub) + str = "kur_4sub"; + if (func == &Calculator::getCV12pt) + str = "cv12dpt"; + if (func == &Calculator::getCV22pt) + str = "cv22dpt"; + if (func == &Calculator::getRhoV22pt) + str = "rhov22dpt"; + if (func == &Calculator::getIntegratedV0) + str = "v0"; + if (func == &Calculator::getIntegratedV02) + str = "v02"; + return str; +} +std::string OutputHandler::getName(Calculator::PtDiffFunc func, double min, double max, bool toplevelname) +{ + std::string str; + if (func == &Calculator::getVPt22) + str = toplevelname ? "vpt22" : Form("vpt22_%g%g", min, max); + if (func == &Calculator::getVPt32) + str = toplevelname ? "vpt32" : Form("vpt32_%g%g", min, max); + if (func == &Calculator::getVPt42) + str = toplevelname ? "vpt42" : Form("vpt42_%g%g", min, max); + if (func == &Calculator::getVPt24) + str = toplevelname ? "vpt24" : Form("vpt24_%g%g", min, max); + if (func == &Calculator::getD22) + str = toplevelname ? "d22" : Form("d22_%g%g", min, max); + if (func == &Calculator::getD32) + str = toplevelname ? "d32" : Form("d32_%g%g", min, max); + if (func == &Calculator::getD42) + str = toplevelname ? "d42" : Form("d42_%g%g", min, max); + if (func == &Calculator::getD24) + str = toplevelname ? "d24" : Form("d24_%g%g", min, max); + + if (func == &Calculator::getVPt24_3sub) + str = toplevelname ? "vpt24_3sub" : Form("vpt24_3sub_%g%g", min, max); + if (func == &Calculator::getD24_3sub) + str = toplevelname ? "d24_3sub" : Form("d24_3sub_%g%g", min, max); + if (func == &Calculator::getD2LpLMR) + str = toplevelname ? "d2LpLMR" : Form("d2LpLMR_%g%g", min, max); + if (func == &Calculator::getD2LLMpR) + str = toplevelname ? "d2LLMpR" : Form("d2LLMpR_%g%g", min, max); + if (func == &Calculator::getD2LLMRp) + str = toplevelname ? "d2LLMRp" : Form("d2LLMRp_%g%g", min, max); + if (func == &Calculator::getD2LpMMR) + str = toplevelname ? "d2LpMMR" : Form("d2LpMMR_%g%g", min, max); + if (func == &Calculator::getD2LMpMR) + str = toplevelname ? "d2LMpMR" : Form("d2LMpMR_%g%g", min, max); + if (func == &Calculator::getD2LMMRp) + str = toplevelname ? "d2LMMRp" : Form("d2LMMRp_%g%g", min, max); + if (func == &Calculator::getD2LpMRR) + str = toplevelname ? "d2LpMRR" : Form("d2LpMRR_%g%g", min, max); + if (func == &Calculator::getD2LMpRR) + str = toplevelname ? "d2LMpRR" : Form("d2LMpRR_%g%g", min, max); + if (func == &Calculator::getD2LMRpR) + str = toplevelname ? "d2LMRpR" : Form("d2LMRpR_%g%g", min, max); + + if (func == &Calculator::get2LpLMR) + str = toplevelname ? "2LpLMR" : Form("2LpLMR_%g%g", min, max); + if (func == &Calculator::get2LLMpR) + str = toplevelname ? "2LLMpR" : Form("2LLMpR_%g%g", min, max); + if (func == &Calculator::get2LLMRp) + str = toplevelname ? "2LLMRp" : Form("2LLMRp_%g%g", min, max); + if (func == &Calculator::get2LpMMR) + str = toplevelname ? "2LpMMR" : Form("2LpMMR_%g%g", min, max); + if (func == &Calculator::get2LMpMR) + str = toplevelname ? "2LMpMR" : Form("2LMpMR_%g%g", min, max); + if (func == &Calculator::get2LMMRp) + str = toplevelname ? "2LMMRp" : Form("2LMMRp_%g%g", min, max); + if (func == &Calculator::get2LpMRR) + str = toplevelname ? "2LpMRR" : Form("2LpMRR_%g%g", min, max); + if (func == &Calculator::get2LMpRR) + str = toplevelname ? "2LMpRR" : Form("2LMpRR_%g%g", min, max); + if (func == &Calculator::get2LMRpR) + str = toplevelname ? "2LMRpR" : Form("2LMRpR_%g%g", min, max); + + if (func == &Calculator::get2LRp) + str = toplevelname ? "2LRp" : Form("2LRp_%g%g", min, max); + if (func == &Calculator::get2LpR) + str = toplevelname ? "2LpR" : Form("2LpR_%g%g", min, max); + if (func == &Calculator::get2LpM) + str = toplevelname ? "2LpM" : Form("2LpM_%g%g", min, max); + if (func == &Calculator::get2LMp) + str = toplevelname ? "2LMp" : Form("2LMp_%g%g", min, max); + if (func == &Calculator::get2MpR) + str = toplevelname ? "2MpR" : Form("2MpR_%g%g", min, max); + if (func == &Calculator::get2MRp) + str = toplevelname ? "2MRp" : Form("2MRp_%g%g", min, max); + + if (func == &Calculator::getnptCh) + str = toplevelname ? "nptch" : Form("nptch_%g%g", min, max); + if (func == &Calculator::getnptPi) + str = toplevelname ? "nptpi" : Form("nptpi_%g%g", min, max); + if (func == &Calculator::getnptKa) + str = toplevelname ? "nptka" : Form("nptka_%g%g", min, max); + if (func == &Calculator::getnptPr) + str = toplevelname ? "nptpr" : Form("nptpr_%g%g", min, max); + if (func == static_cast(&Calculator::getnptK0)) + str = toplevelname ? "nptk0" : Form("nptk0_%g%g", min, max); + if (func == static_cast(&Calculator::getnptLambda)) + str = toplevelname ? "nptlambda" : Form("nptlambda_%g%g", min, max); + + if (func == &Calculator::getV0Ch) + str = toplevelname ? "v0ch" : Form("v0ch_%g%g", min, max); + if (func == &Calculator::getV0Pi) + str = toplevelname ? "v0pi" : Form("v0pi_%g%g", min, max); + if (func == &Calculator::getV0Ka) + str = toplevelname ? "v0ka" : Form("v0ka_%g%g", min, max); + if (func == &Calculator::getV0Pr) + str = toplevelname ? "v0pr" : Form("v0pr_%g%g", min, max); + if (func == &Calculator::getV0K0) + str = toplevelname ? "v0k0" : Form("v0k0_%g%g", min, max); + if (func == &Calculator::getV0Lambda) + str = toplevelname ? "v0lambda" : Form("v0lambda_%g%g", min, max); + if (func == &Calculator::getV0WeightedCh) + str = toplevelname ? "v0weightedch" : Form("v0weightedch_%g%g", min, max); + if (func == &Calculator::getV0WeightedPi) + str = toplevelname ? "v0weightedpi" : Form("v0weightedpi_%g%g", min, max); + if (func == &Calculator::getV0WeightedKa) + str = toplevelname ? "v0weightedka" : Form("v0weightedka_%g%g", min, max); + if (func == &Calculator::getV0WeightedPr) + str = toplevelname ? "v0weightedpr" : Form("v0weightedpr_%g%g", min, max); + if (func == &Calculator::getV0WeightedK0) + str = toplevelname ? "v0weightedk0" : Form("v0weightedk0_%g%g", min, max); + if (func == &Calculator::getV0WeightedLambda) + str = toplevelname ? "v0weightedlambda" : Form("v0weightedlambda_%g%g", min, max); + if (func == &Calculator::getV00WeightedCh) + str = toplevelname ? "v00weightedch" : Form("v00weightedch_%g%g", min, max); + if (func == &Calculator::getV00WeightedPi) + str = toplevelname ? "v00weightedpi" : Form("v00weightedpi_%g%g", min, max); + if (func == &Calculator::getV00WeightedKa) + str = toplevelname ? "v00weightedka" : Form("v00weightedka_%g%g", min, max); + if (func == &Calculator::getV00WeightedPr) + str = toplevelname ? "v00weightedpr" : Form("v00weightedpr_%g%g", min, max); + if (func == &Calculator::getV00WeightedK0) + str = toplevelname ? "v00weightedk0" : Form("v00weightedk0_%g%g", min, max); + if (func == &Calculator::getV00WeightedLambda) + str = toplevelname ? "v00weightedlambda" : Form("v00weightedlambda_%g%g", min, max); + if (func == &Calculator::getV0K0Alt) + str = toplevelname ? "v0k0alt" : Form("v0k0alt_%g%g", min, max); + if (func == &Calculator::getV0LambdaAlt) + str = toplevelname ? "v0lambdaalt" : Form("v0lambdaalt_%g%g", min, max); + + if (func == &Calculator::getV02Ch) + str = toplevelname ? "v02ch" : Form("v02ch_%g%g", min, max); + if (func == &Calculator::getV02Pi) + str = toplevelname ? "v02pi" : Form("v02pi_%g%g", min, max); + if (func == &Calculator::getV02Ka) + str = toplevelname ? "v02ka" : Form("v02ka_%g%g", min, max); + if (func == &Calculator::getV02Pr) + str = toplevelname ? "v02pr" : Form("v02pr_%g%g", min, max); + if (func == &Calculator::getV02K0) + str = toplevelname ? "v02k0" : Form("v02k0_%g%g", min, max); + if (func == &Calculator::getV02Lambda) + str = toplevelname ? "v02lambda" : Form("v02lambda_%g%g", min, max); + if (func == &Calculator::getV02WeightedCh) + str = toplevelname ? "v02weightedch" : Form("v02weightedch_%g%g", min, max); + if (func == &Calculator::getV02WeightedPi) + str = toplevelname ? "v02weightedpi" : Form("v02weightedpi_%g%g", min, max); + if (func == &Calculator::getV02WeightedKa) + str = toplevelname ? "v02weightedka" : Form("v02weightedka_%g%g", min, max); + if (func == &Calculator::getV02WeightedPr) + str = toplevelname ? "v02weightedpr" : Form("v02weightedpr_%g%g", min, max); + if (func == &Calculator::getV02WeightedK0) + str = toplevelname ? "v02weightedk0" : Form("v02weightedk0_%g%g", min, max); + if (func == &Calculator::getV02WeightedLambda) + str = toplevelname ? "v02weightedlambda" : Form("v02weightedlambda_%g%g", min, max); + if (func == &Calculator::getV02K0Alt) + str = toplevelname ? "v02k0alt" : Form("v02k0alt_%g%g", min, max); + if (func == &Calculator::getV02LambdaAlt) + str = toplevelname ? "v02lambdaalt" : Form("v02lambdaalt_%g%g", min, max); + + if (func == &Calculator::getV0CorrCh) + str = toplevelname ? "v0corrch" : Form("v0corrch_%g%g", min, max); + if (func == &Calculator::getV0CorrPi) + str = toplevelname ? "v0corrpi" : Form("v0corrpi_%g%g", min, max); + if (func == &Calculator::getV0CorrKa) + str = toplevelname ? "v0corrka" : Form("v0corrka_%g%g", min, max); + if (func == &Calculator::getV0CorrPr) + str = toplevelname ? "v0corrpr" : Form("v0corrpr_%g%g", min, max); + if (func == &Calculator::getV0CorrK0) + str = toplevelname ? "v0corrk0" : Form("v0corrk0_%g%g", min, max); + if (func == &Calculator::getV0CorrLambda) + str = toplevelname ? "v0corrlambda" : Form("v0corrlambda_%g%g", min, max); + + if (func == &Calculator::getV0CovCh) + str = toplevelname ? "v0covch" : Form("v0covch_%g%g", min, max); + if (func == &Calculator::getV0CovPi) + str = toplevelname ? "v0covpi" : Form("v0covpi_%g%g", min, max); + if (func == &Calculator::getV0CovKa) + str = toplevelname ? "v0covka" : Form("v0covka_%g%g", min, max); + if (func == &Calculator::getV0CovPr) + str = toplevelname ? "v0covpr" : Form("v0covpr_%g%g", min, max); + if (func == &Calculator::getV0CovK0) + str = toplevelname ? "v0covk0" : Form("v0covk0_%g%g", min, max); + if (func == &Calculator::getV0CovLambda) + str = toplevelname ? "v0covlambda" : Form("v0covlambda_%g%g", min, max); + + if (func == &Calculator::getV02CorrCh) + str = toplevelname ? "v02corrch" : Form("v02corrch_%g%g", min, max); + if (func == &Calculator::getV02CorrPi) + str = toplevelname ? "v02corrpi" : Form("v02corrpi_%g%g", min, max); + if (func == &Calculator::getV02CorrKa) + str = toplevelname ? "v02corrka" : Form("v02corrka_%g%g", min, max); + if (func == &Calculator::getV02CorrPr) + str = toplevelname ? "v02corrpr" : Form("v02corrpr_%g%g", min, max); + if (func == &Calculator::getV02CorrK0) + str = toplevelname ? "v02corrk0" : Form("v02corrk0_%g%g", min, max); + if (func == &Calculator::getV02CorrLambda) + str = toplevelname ? "v02corrlambda" : Form("v02corrlambda_%g%g", min, max); + + if (func == &Calculator::getV02CovCh) + str = toplevelname ? "v02covch" : Form("v02covch_%g%g", min, max); + if (func == &Calculator::getV02CovPi) + str = toplevelname ? "v02covpi" : Form("v02covpi_%g%g", min, max); + if (func == &Calculator::getV02CovKa) + str = toplevelname ? "v02covka" : Form("v02covka_%g%g", min, max); + if (func == &Calculator::getV02CovPr) + str = toplevelname ? "v02covpr" : Form("v02covpr_%g%g", min, max); + if (func == &Calculator::getV02CovK0) + str = toplevelname ? "v02covk0" : Form("v02covk0_%g%g", min, max); + if (func == &Calculator::getV02CovLambda) + str = toplevelname ? "v02covlambda" : Form("v02covlambda_%g%g", min, max); + + if (func == &Calculator::getV0MeansCh) + str = toplevelname ? "v0meansch" : Form("v0meansch_%g%g", min, max); + if (func == &Calculator::getV0MeansPi) + str = toplevelname ? "v0meanspi" : Form("v0meanspi_%g%g", min, max); + if (func == &Calculator::getV0MeansKa) + str = toplevelname ? "v0meanska" : Form("v0meanska_%g%g", min, max); + if (func == &Calculator::getV0MeansPr) + str = toplevelname ? "v0meanspr" : Form("v0meanspr_%g%g", min, max); + if (func == &Calculator::getV0MeansK0) + str = toplevelname ? "v0meansk0" : Form("v0meansk0_%g%g", min, max); + if (func == &Calculator::getV0MeansLambda) + str = toplevelname ? "v0meanslambda" : Form("v0meanslambda_%g%g", min, max); + + if (func == &Calculator::getV02MeansCh) + str = toplevelname ? "v02meansch" : Form("v02meansch_%g%g", min, max); + if (func == &Calculator::getV02MeansPi) + str = toplevelname ? "v02meanspi" : Form("v02meanspi_%g%g", min, max); + if (func == &Calculator::getV02MeansKa) + str = toplevelname ? "v02meanska" : Form("v02meanska_%g%g", min, max); + if (func == &Calculator::getV02MeansPr) + str = toplevelname ? "v02meanspr" : Form("v02meanspr_%g%g", min, max); + if (func == &Calculator::getV02MeansK0) + str = toplevelname ? "v02meansk0" : Form("v02meansk0_%g%g", min, max); + if (func == &Calculator::getV02MeansLambda) + str = toplevelname ? "v02meanslambda" : Form("v02meanslambda_%g%g", min, max); + + if (func == &Calculator::getAlpha) + str = toplevelname ? "alpha" : Form("alpha_%g%g", min, max); + if (func == &Calculator::getBeta) + str = toplevelname ? "beta" : Form("beta_%g%g", min, max); + if (func == &Calculator::getAlphaAlt) + str = toplevelname ? "alphaalt" : Form("alphaalt_%g%g", min, max); + if (func == &Calculator::getBetaAlt) + str = toplevelname ? "betaalt" : Form("betaalt_%g%g", min, max); + return str; +} +void OutputHandler::PrintSystematics(bool relative) +{ + std::map printmap = sysHandler->getPrintMap(); + if (!relative) { + const std::map> printBinMap = sysHandler->getPrintBinMap(); + const std::map systMap = sysHandler->getSystMap(); + const auto nominalIt = systMap.find(0); + const TH1* nominal = nominalIt != systMap.end() ? nominalIt->second : nullptr; + for (const auto& [index, values] : printBinMap) { + std::cout << "index " << index << ":"; + for (std::size_t bin = 0; bin < values.size(); ++bin) { + if (nominal && static_cast(bin) < nominal->GetNbinsX()) { + std::cout << " [" << nominal->GetXaxis()->GetBinLowEdge(bin + 1) << ", " + << nominal->GetXaxis()->GetBinUpEdge(bin + 1) << "]: "; + } else { + std::cout << " bin " << bin + 1 << ": "; + } + std::cout << values[bin]; + } + std::cout << " (absolute)" << std::endl; + } + return; + } + for (auto& sys : printmap) { + std::cout << "index " << sys.first << ": " << sys.second * 100. << "%" << std::endl; + } +} +bool OutputHandler::isVN(Calculator::ObsFunc func) +{ + // func == &Calculator::getV24 || + if (func == &Calculator::getV24 || func == &Calculator::getV26 || func == &Calculator::getV28 || func == &Calculator::getV24_3sub || func == &Calculator::getV2LLMR || func == &Calculator::getV2LMMR || func == &Calculator::getV2LMRR) + return true; + else + return false; +} +Calculator::ObsFunc OutputHandler::getCorrespondingCumulant(Calculator::ObsFunc func) +{ + if (func == &Calculator::getV24) + return &Calculator::getC24; + if (func == &Calculator::getV26) + return &Calculator::getC26; + if (func == &Calculator::getV28) + return &Calculator::getC28; + if (func == &Calculator::getV24_3sub) + return &Calculator::getC24_3sub; + if (func == &Calculator::getV2LLMR) + return &Calculator::getC2LLMR; + if (func == &Calculator::getV2LMMR) + return &Calculator::getC2LMMR; + if (func == &Calculator::getV2LMRR) + return &Calculator::getC2LMRR; + return 0; +} +void OutputHandler::calculateVN(Calculator::ObsFunc func, TH1D*& inh) +{ + if (func == &Calculator::getV24 || func == &Calculator::getV24_3sub || func == &Calculator::getV2LLMR || func == &Calculator::getV2LMMR || func == &Calculator::getV2LMRR) { + inh->Scale(-1.); + inh = calculator.powerHistogram(inh, 0.25); + } else if (func == &Calculator::getV26) { + inh = calculator.powerHistogram(inh, 1. / 6); + } else if (func == &Calculator::getV28) { + inh->Scale(-1.); + inh = calculator.powerHistogram(inh, 1. / 8); + } else + return; +} +bool OutputHandler::isVN(Calculator::PtDiffFunc func) +{ + // func == &Calculator::getVPt24 || + if (func == &Calculator::getVPt24_3sub) + return true; + else + return false; +} +Calculator::PtDiffFunc OutputHandler::getCorrespondingCumulant(Calculator::PtDiffFunc func) +{ + if (func == &Calculator::getVPt24) + return &Calculator::getD24; + if (func == &Calculator::getVPt24_3sub) + return &Calculator::getD24_3sub; + return 0; +} +// TODO fix this rebinning +void OutputHandler::calculateVN(Calculator::PtDiffFunc func, TH1D*& inh, double min, double max) +{ + if (func == &Calculator::getVPt24) { + inh->Scale(-1.); + inh = calculator.powerHistogram(inh, 0.25); + } else if (func == &Calculator::getVPt24_3sub) { + inh->Scale(-1.); + calculator.setFlowID("ChFull"); + TH1D* c24 = getHist(&Calculator::getC24); + double c24_val = calculator.getIntegratedValue(c24, min, max); + inh->Scale(std::pow(-c24_val, -3. / 4)); + } else + return; +} +// NOLINTEND(readability/braces) diff --git a/PWGCF/GenericFramework/Core/OutputHandler.h b/PWGCF/GenericFramework/Core/OutputHandler.h new file mode 100644 index 00000000000..40eb46357a7 --- /dev/null +++ b/PWGCF/GenericFramework/Core/OutputHandler.h @@ -0,0 +1,142 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef PWGCF_GENERICFRAMEWORK_CORE_OUTPUTHANDLER_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_OUTPUTHANDLER_H_ + +#include "Calculator.h" +#include "FlowContainer.h" +#include "FlowPtContainer.h" +#include "StatHandler.h" +#include "SysHandler.h" + +#include + +#include +#include +#include +#include +#include +#include + +class OutputHandler : public TNamed +{ + public: + explicit OutputHandler(std::string system = ""); + OutputHandler(std::string filename, std::string system); + ~OutputHandler(); + + void initialise(std::string filename, std::string dirname = "", bool hasSystematics = false, SysHandler::SystSettings settings = {{0., 90.}, true, 1, 1, true}); + void initialiseGen(std::string filename, std::string dirname = "") + { + isGen = true; + initialise(filename, dirname); + } + void addFileForRatio(std::string name) + { + doSystemRatio = true; + fileName2 = name; + }; + + TH1D* getHist(Calculator::ObsFunc func, StatHandler::StatMethod method = StatHandler::kVarianceOfSamples); + TH1D* getHist(Calculator::PtDiffFunc func, double min, double max, StatHandler::StatMethod method = StatHandler::kVarianceOfSamples); + TH1D* getSysHist(Calculator::ObsFunc func, bool use_bootstrap_for_systs, StatHandler::StatMethod method = StatHandler::kVarianceOfSamples, bool relative = true, const TH1* nominal = nullptr); + TH1D* getSysHist(Calculator::PtDiffFunc func, double min, double max, bool use_bootstrap_for_systs, StatHandler::StatMethod method = StatHandler::kVarianceOfSamples, bool relative = true, const TH1* nominal = nullptr); + void RebinMulti(int nrb, double* chbins); + template + void FSRebin(T** inh); + TH1* getRelSysHist(int sys_index, bool sys_from_fit, bool relative = true); + TH1* getBarlowHist(int sys_index); + TH1* getVarNomRatioHist(int sys_index); + TH1* getVarHist(int sys_index); + std::vector split(const std::string& s, char delimiter); + std::string getLatexName(Calculator::ObsFunc func); + std::string getLatexName(Calculator::PtDiffFunc func); + std::string getName(Calculator::ObsFunc func); + std::string getName(Calculator::PtDiffFunc func, double min, double max, bool toplevelname = 0); + void setFlowID(std::string id) + { + if (isInitialised) + calculator.setFlowID(id); + else + printf("Please initialise OutputHandler before setting Calculator data members\n"); + } + void setInvMassFitFunctions(const std::string& species, const std::string& signalFunction, const std::string& backgroundFunction); + void setInvMassFitFunctionsForSystematic(int systematicIndex, + const std::string& species, + const std::string& signalFunction, + const std::string& backgroundFunction); + void setInvMassFitCentralityBins(const std::vector& centralityBins); + void setAdditionalSystematicVariation(int index, TH1* variation); + void setSystematicVariations(const std::vector& variations); + void setFitSignificanceRejection(bool enabled, double minSignificance = 1.96); + void setSystematicProgressCallback(std::function callback) { systematicProgressCallback = std::move(callback); } + void setUseFSRebin(bool newval) { useFSRebin = newval; } + void setUseLateCentralityRebin(bool newval) { useLateCentralityRebin = newval; } + void setUseInverseVarianceWeighting(bool newval) { calculator.setUseInverseVarianceWeight(newval); } + void setRadialFlowAnalysis(bool newval, bool useTotal = false) + { + radialFlowAnalysis = newval; + calculator.setUseTotal(useTotal); + } + std::vector getSysIndices() { return sys_indices; } + int getSysColor(int index) + { + if (index < 0 || index >= static_cast(syscolors.size())) { + throw std::out_of_range("Index out of range"); + } + return syscolors[index]; + } + std::string getSysName(int index) { return sysHandler->getSystDescription(index); } + void PrintSystematics(bool relative = true); + + private: + FlowContainer* flowcont; //! + FlowPtContainer* flowptcont; //! + StatHandler* stathandler; //! + SysHandler* sysHandler; //! + std::string fileName; + std::string dirName; + Calculator calculator; //! + bool isInitialised; + bool isGen; + bool useFSRebin; + bool useLateCentralityRebin; + bool doSystemRatio; + bool radialFlowAnalysis; + bool isVN(Calculator::ObsFunc func); + bool isVN(Calculator::PtDiffFunc func); + void calculateVN(Calculator::ObsFunc func, TH1D*& inh); + Calculator::PtDiffFunc getCorrespondingCumulant(Calculator::PtDiffFunc func); + Calculator::ObsFunc getCorrespondingCumulant(Calculator::ObsFunc func); + void calculateVN(Calculator::PtDiffFunc func, TH1D*& inh, double min, double max); + std::string current_obs; + std::vector sys_indices; + int fNrb; + double* fBinsrb; + std::string xAxisTitle; + std::string fileName2; + std::map inputFiles; //! + std::map additionalSystematicVariations; //! + std::vector systematicVariations; //! + bool hasCustomSystematicVariations = false; //! + std::function systematicProgressCallback; //! + // predefined systematic colors + std::vector syscolors = {kBlack, kRed + 1, kBlue + 1, kGreen + 3, kMagenta + 1, kOrange - 1, kCyan + 2, kYellow + 2, kGray + 1, kRed - 10, kBlue - 9, kGreen - 8, kMagenta - 9, kOrange - 9, kCyan - 8, kYellow - 7, kAzure + 1, kPink, kP6Blue, kP6Yellow, kP6Red, kP6Grape, kP6Violet}; + // std::vector syscolors = {126,125,124,123,122,121,120,119,118,117}; + + TFile* readFile(std::string name); + std::vector getKeyIndices(std::string name); + + ClassDef(OutputHandler, 3); +}; + +#endif // PWGCF_GENERICFRAMEWORK_CORE_OUTPUTHANDLER_H_ diff --git a/PWGCF/GenericFramework/Core/PlotLegendPlacementUtils.h b/PWGCF/GenericFramework/Core/PlotLegendPlacementUtils.h new file mode 100644 index 00000000000..719fae1e47b --- /dev/null +++ b/PWGCF/GenericFramework/Core/PlotLegendPlacementUtils.h @@ -0,0 +1,191 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef PWGCF_GENERICFRAMEWORK_CORE_PLOTLEGENDPLACEMENTUTILS_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_PLOTLEGENDPLACEMENTUTILS_H_ + +#include "PlotYRangeUtils.h" + +#include +#include +#include +#include + +namespace plotutils +{ + +struct NDCBox { + double x1; + double y1; + double x2; + double y2; +}; + +inline bool insideBox(const NDCBox& b, double x, double y) +{ + return (x >= b.x1 && x <= b.x2 && y >= b.y1 && y <= b.y2); +} + +inline bool overlapBox(const NDCBox& a, const NDCBox& b) +{ + return !(a.x2 < b.x1 || a.x1 > b.x2 || a.y2 < b.y1 || a.y1 > b.y2); +} + +inline double mapXToNDC(double x, double xMin, double xMax, double left, double right) +{ + if (xMax <= xMin) { + return 0.5; + } + return left + (x - xMin) / (xMax - xMin) * (1.0 - left - right); +} + +inline double mapYToNDC(double y, double yMin, double yMax, double bottom, double top) +{ + if (yMax <= yMin) { + return 0.5; + } + return bottom + (y - yMin) / (yMax - yMin) * (1.0 - bottom - top); +} + +inline NDCBox chooseLegendBox(const std::vector& points, + double xMin, + double xMax, + double yMin, + double yMax, + double left, + double right, + double bottom, + double top, + const std::vector& legendLabels, + bool avoidAppliedText, + const std::string& centralityLabel) +{ + const double innerW = std::max(0.05, 1.0 - left - right); + const double innerH = std::max(0.05, 1.0 - bottom - top); + + size_t maxChars = 0; + for (const auto& l : legendLabels) { + maxChars = std::max(maxChars, l.size()); + } + if (maxChars == 0) { + maxChars = 6; + } + + const int nEntries = std::max(1, static_cast(legendLabels.size())); + + const double padGapX = 0.02; + const double padGapY = 0.03; + + const double w = std::min(0.42 * innerW, std::max(0.14, 0.04 + 0.009 * static_cast(maxChars))); + const double h = std::min(0.42 * innerH, std::max(0.11, 0.055 + 0.048 * static_cast(nEntries))); + + const double availXMin = left + padGapX; + const double availXMax = 1.0 - right - padGapX; + const double availYMin = bottom + padGapY; + const double availYMax = 1.0 - top - padGapY; + + const double spanX = std::max(0.0, (availXMax - availXMin - w)); + const double spanY = std::max(0.0, (availYMax - availYMin - h)); + + const double xLeft = availXMin; + const double xRight = std::max(xLeft, availXMax - w); + const double xCenter = availXMin + 0.5 * spanX; + const double xQRightCenter = availXMin + 0.75 * spanX; + const double xQLeftCenter = availXMin + 0.25 * spanX; + + const double yBottom = availYMin; + const double yTop = std::max(yBottom, availYMax - h); + const double yQTopCenter = availYMin + 0.75 * spanY; + const double yQBottomCenter = availYMin + 0.25 * spanY; + + struct Candidate { + NDCBox box; + double prefPenalty; + }; + + auto mk = [&](double x1, double y1, double penalty) { + return Candidate{{x1, y1, x1 + w, y1 + h}, penalty}; + }; + + std::vector candidates = { + mk(xQRightCenter, yQTopCenter, 0.0), + mk(xRight, yTop, 6.0), + mk(xCenter, yQTopCenter, 10.0), + mk(xQLeftCenter, yQTopCenter, 14.0), + mk(xLeft, yTop, 18.0), + mk(xQRightCenter, yQBottomCenter, 22.0), + mk(xCenter, yQBottomCenter, 26.0), + mk(xQLeftCenter, yQBottomCenter, 30.0), + mk(xRight, yBottom, 34.0), + mk(xLeft, yBottom, 38.0)}; + + std::vector reservedTextBoxes; + if (avoidAppliedText) { + const double yStart = 1.0 - top - 0.1; + const double lineStep = 0.08; + const double xLeftText = left + 0.015; + + const double textBlockW = std::min(0.50 * innerW, std::max(0.24, 0.20 + 0.007 * 32.0)); + const double textBlockH = 3.0 * lineStep; + reservedTextBoxes.push_back({xLeftText - 0.005, yStart - textBlockH - 0.02, xLeftText + textBlockW, yStart + 0.02}); + + const double xRightLabel = 1.0 - right - 0.02; + const double labelW = std::min(0.35 * innerW, std::max(0.08, 0.055 + 0.008 * static_cast(centralityLabel.size()))); + const double labelH = 0.06; + reservedTextBoxes.push_back({xRightLabel - labelW, yStart - labelH, xRightLabel, yStart + 0.01}); + } + + double bestScore = 1e99; + NDCBox best = candidates.front().box; + + for (const auto& c : candidates) { + double score = c.prefPenalty; + + for (const auto& r : reservedTextBoxes) { + if (overlapBox(c.box, r)) { + score += 1e6; + } + } + + if (c.box.x1 < availXMin || c.box.x2 > availXMax || c.box.y1 < availYMin || c.box.y2 > availYMax) { + score += 1e6; + } + + for (const auto& p : points) { + if (!std::isfinite(p.x) || !std::isfinite(p.y) || !std::isfinite(p.ey)) { + continue; + } + + const double xNdc = mapXToNDC(p.x, xMin, xMax, left, right); + const double yNdc = mapYToNDC(p.y, yMin, yMax, bottom, top); + const double yLowNdc = mapYToNDC(p.y - p.ey, yMin, yMax, bottom, top); + const double yHighNdc = mapYToNDC(p.y + p.ey, yMin, yMax, bottom, top); + + if (insideBox(c.box, xNdc, yNdc)) { + score += 1000.0; + } + if (insideBox(c.box, xNdc, yLowNdc) || insideBox(c.box, xNdc, yHighNdc)) { + score += 300.0; + } + } + + if (score < bestScore) { + bestScore = score; + best = c.box; + } + } + + return best; +} + +} // namespace plotutils + +#endif // PWGCF_GENERICFRAMEWORK_CORE_PLOTLEGENDPLACEMENTUTILS_H_ diff --git a/PWGCF/GenericFramework/Core/PlotTemplateSteerer.h b/PWGCF/GenericFramework/Core/PlotTemplateSteerer.h new file mode 100644 index 00000000000..687bbb64242 --- /dev/null +++ b/PWGCF/GenericFramework/Core/PlotTemplateSteerer.h @@ -0,0 +1,783 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef PWGCF_GENERICFRAMEWORK_CORE_PLOTTEMPLATESTEERER_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_PLOTTEMPLATESTEERER_H_ + +#include "MyCanvas.h" +#include "PlotYRangeUtils.h" +#include "RVersion.h" + +#include "TFile.h" +#include "TGraphAsymmErrors.h" +#include "TGraphErrors.h" +#include "TH1.h" +#include "TKey.h" + +#include +#include +#include +#include +#include +#include +#include + +class PlotTemplateSteerer +{ + public: + using ObjType = MyCanvas::ObjType; + + // Add ratios, pair ratios, etc. + enum class TemplateMode { + TwoMeasurements, // 2 inputs: same color, closed/open markers + Paired, // (0,1), (2,3), ... share color and closed/open marker + Distinct, // each series gets its own color/marker + DistinctRatio, // first pad: distinct, second pad: ratio to first series + PairedRatio, // first pad: paired, second pad: (0/1), (2/3), ... + PairedDifference, // first pad: paired, second pad: (0-1), (2-3), ... + PairedRelDev // first pad: paired, second pad 1.0-|0-1|/0, 1.0-|2-3|/2 + }; + enum class ComparisonMode { + Ratio, + Difference, + RelativeDeviation + }; + struct SeriesInput { + ObjType stat; + ObjType sys{}; + TString legend{}; + const char* legendDrawOpt = "pe"; + }; + + struct SeriesStyle { + int color = kBlack; + int marker = kFullCircle; + }; + + PlotTemplateSteerer() + : mFallbackColorPalette{kBlack, kRed + 1, kBlue + 1, kGreen + 2, kOrange + 7, kMagenta + 2, kCyan + 2}, + mPairedMarkers{{kFullCircle, kOpenCircle}, + {kFullSquare, kOpenSquare}, + {kFullDiamond, kOpenDiamond}, + {kFullDoubleDiamond, kOpenDoubleDiamond}, + {kFullCross, kOpenCross}, + {kFullStar, kOpenStar}, + {kFullCrossX, kOpenCrossX}, + {kFullFourTrianglesPlus, kOpenFourTrianglesPlus}}, + mDistinctMarkers{ + kFullCircle, kFullSquare, kFullDiamond, kFullDoubleDiamond, kFullCross, kFullStar, kFullCrossX, kFullFourTrianglesPlus, + kOpenCircle, kOpenSquare, kOpenDiamond, kOpenDoubleDiamond, kOpenCross, kOpenStar, kOpenCrossX, kOpenFourTrianglesPlus} {} + + void setFallbackColorPalette(const std::vector& colors) + { + if (colors.empty()) { + throw std::invalid_argument("PlotTemplateSteerer: fallback color palette cannot be empty"); + } + mFallbackColorPalette = colors; + } + + void setColorPalette(const std::vector& colors) { setFallbackColorPalette(colors); } + + void setPairedMarkers(const std::vector>& pairedMarkers) + { + if (pairedMarkers.empty()) { + throw std::invalid_argument("PlotTemplateSteerer: paired marker list cannot be empty"); + } + mPairedMarkers = pairedMarkers; + } + + void setDistinctMarkers(const std::vector& markers) + { + if (markers.empty()) { + throw std::invalid_argument("PlotTemplateSteerer: distinct marker list cannot be empty"); + } + mDistinctMarkers = markers; + } + + std::vector buildStyles(size_t nSeries, TemplateMode mode, int colorOffset = 0, int markerOffset = 0) const + { + if (nSeries == 0) { + return {}; + } + const auto colorPalette = selectColorPalette(nSeries, mode); + std::vector styles; + styles.reserve(nSeries); + for (size_t i = 0; i < nSeries; ++i) { + styles.push_back(styleForIndex(i, mode, colorOffset, markerOffset, colorPalette)); + } + return styles; + } + + void addSeries(MyCanvas& canvas, + const std::vector& series, + TemplateMode mode, + int pad = 1, + int colorOffset = 0, + int markerOffset = 0, + int legInd = 0, + const std::vector& legendIndices = {}) const + { + mComparisonObjects.clear(); + if (series.empty()) { + return; + } + if (mode == TemplateMode::TwoMeasurements && series.size() != 2) { + throw std::invalid_argument("PlotTemplateSteerer: TwoMeasurements mode requires exactly 2 series"); + } + if ((mode == TemplateMode::PairedRatio || mode == TemplateMode::PairedDifference) && (series.size() < 2 || (series.size() % 2) != 0)) { + throw std::invalid_argument("PlotTemplateSteerer: PairedRatio and PairedDifference mode requires an even number of series >= 2"); + } + if (!legendIndices.empty() && legendIndices.size() != series.size()) { + throw std::invalid_argument("PlotTemplateSteerer: legend index list must be empty or match the number of series"); + } + + if (!canvas.isInitialised()) { + if (mode == TemplateMode::DistinctRatio || mode == TemplateMode::PairedRatio || mode == TemplateMode::PairedDifference || mode == TemplateMode::PairedRelDev) { + canvas.BuildRatioCanvas(0.45); + } else { + canvas.BuildSingleCanvas(); + } + } + + auto styles = buildStyles(series.size(), mode, colorOffset, markerOffset); + for (size_t i = 0; i < series.size(); ++i) { + canvas.AddObject(series[i].stat, pad, styles[i].color, styles[i].marker, series[i].sys); + const int seriesLegInd = legendIndexForSeries(i, legInd, legendIndices); + if (seriesLegInd >= 0 && !series[i].legend.IsNull()) { + std::visit( + [&canvas, &series, i, seriesLegInd](auto&& arg) { canvas.AddLegEntry(arg, series[i].legend, series[i].legendDrawOpt, seriesLegInd); }, + series[i].stat); + } + if (mode == TemplateMode::DistinctRatio) { + if (i == 0) { + continue; + } + ComparisonMode comparisonMode = ComparisonMode::Ratio; + if (mode == TemplateMode::PairedDifference) + comparisonMode = ComparisonMode::Difference; + if (mode == TemplateMode::PairedRelDev) + comparisonMode = ComparisonMode::RelativeDeviation; + ObjType compStat = makeComparisonObject(series[i].stat, series[0].stat, static_cast(i), comparisonMode); + mComparisonObjects.push_back(compStat); + std::visit([](auto&& arg) { + if (!arg) { + return; + } + }, + compStat); + canvas.AddObject(compStat, 2, styles[i].color, styles[i].marker, {}); + if (legInd >= 0 && !series[i].legend.IsNull()) { + std::visit( + [&canvas, &series, i, legInd](auto&& arg) { canvas.AddLegEntry(arg, series[i].legend + TString("/") + series[0].legend, series[i].legendDrawOpt, legInd + 1); }, + series[i].stat); + } + } + if (mode == TemplateMode::PairedRatio || mode == TemplateMode::PairedDifference || mode == TemplateMode::PairedRelDev) { + if ((i % 2) == 1) { + continue; + } + const size_t denIdx = i + 1; + ComparisonMode comparisonMode = ComparisonMode::Ratio; + if (mode == TemplateMode::PairedDifference) + comparisonMode = ComparisonMode::Difference; + if (mode == TemplateMode::PairedRelDev) + comparisonMode = ComparisonMode::RelativeDeviation; + ObjType compStat = makeComparisonObject(series[i].stat, series[denIdx].stat, static_cast(i), comparisonMode); + mComparisonObjects.push_back(compStat); + std::visit([](auto&& arg) { + if (!arg) { + return; + } + }, + compStat); + canvas.AddObject(compStat, 2, styles[i].color, styles[i].marker, {}); + if (legInd >= 0 && !series[i].legend.IsNull() && !series[denIdx].legend.IsNull()) { + std::visit( + [&canvas, &series, i, denIdx, legInd, comparisonMode](auto&& arg) { + TString compStr = (comparisonMode == ComparisonMode::Difference) ? TString("-") : TString("/"); + canvas.AddLegEntry(arg, series[i].legend + compStr + series[denIdx].legend, series[i].legendDrawOpt, legInd + 1); + }, + series[i].stat); + } + } + } + } + + void addTwoMeasurements(MyCanvas& canvas, + const SeriesInput& first, + const SeriesInput& second, + int pad = 1, + int colorOffset = 0, + int markerOffset = 0, + int legInd = -1) const + { + addSeries(canvas, {first, second}, TemplateMode::TwoMeasurements, pad, colorOffset, markerOffset, legInd); + } + + void applyAutoYLimits(MyCanvas& canvas, + const std::vector& series, + TemplateMode mode, + double referenceLine = 1.0) const + { + if (series.empty()) { + return; + } + + const auto topRange = plotutils::determineTopPadYLimits(series); + if (topRange.valid) { + canvas.SetYLimits(topRange.ymin, topRange.ymax, 1); + } + + plotutils::ComparisonMode cmpMode = plotutils::ComparisonMode::None; + if (mode == TemplateMode::PairedRatio) { + cmpMode = plotutils::ComparisonMode::PairedRatio; + } else if (mode == TemplateMode::PairedDifference) { + cmpMode = plotutils::ComparisonMode::PairedDifference; + } + + if (cmpMode != plotutils::ComparisonMode::None) { + const auto bottomRange = plotutils::determineBottomPadYLimits(series, cmpMode, referenceLine); + if (bottomRange.valid) { + canvas.SetYLimits(bottomRange.ymin, bottomRange.ymax, 2); + } + } + } + + void applyText(MyCanvas& c, const std::vector& topleft, const std::string& label) const + { + double leftMargin = 0.10; + double rightMargin = 0.05; + double topMargin = 0.05; + if (gPad) { + leftMargin = gPad->GetLeftMargin(); + rightMargin = gPad->GetRightMargin(); + topMargin = gPad->GetTopMargin(); + } + + const double xLeft = leftMargin + 0.03; + const double yStart = 1.0 - topMargin - 0.05; + const double lineStep = 0.06; + + for (size_t i = 0; i < topleft.size(); ++i) { + const double y = yStart - static_cast(i) * lineStep; + c.AddText(xLeft, y, topleft[i].c_str(), true); + } + + if (!label.empty()) { + const double xRight = 1.0 - rightMargin - 0.02; + // c.AddText(xRight, yStart, label.c_str(), true); + TLatex l; + l.SetTextFont(43); + l.SetTextSize(c.GetTextSize()); + l.SetTextAlign(31); // right-aligned in x, top-aligned in y + l.DrawLatexNDC(xRight, yStart, label.c_str()); + } + } + + void createSeriesFromFile(std::string filename) + { + std::unique_ptr inFile(TFile::Open(filename.c_str(), "READ")); + if (!inFile || inFile->IsZombie()) { + throw std::runtime_error("PlotTemplateSteerer: could not open file: " + filename); + } + + TIter nextKey(inFile->GetListOfKeys()); + TKey* key = nullptr; + while ((key = static_cast(nextKey()))) { + const std::string keyName = key->GetName(); + mSeriesInputs.push_back(getSeriesInput(filename, keyName)); + } + } + void createSeriesFromFiles(const std::vector& filename, const std::string& qualifier) + { + for (const auto& file : filename) { + mSeriesInputs.push_back(getSeriesInput(file, qualifier)); + } + } + void createSeriesFromFilesWithSystematics(const std::vector& filename, + const std::string& statQualifier, + const std::string& sysQualifier, + const std::vector& legends = {}) + { + if (legends.size() != filename.size() && !legends.empty()) { + throw std::runtime_error("PlotTemplateSteerer: filenames and legends have different sizes"); + } + + for (size_t i = 0; i < filename.size(); ++i) { + if (!legends.empty()) { + mSeriesInputs.push_back(getSeriesInput(filename[i], statQualifier, sysQualifier, legends[i])); + } else { + mSeriesInputs.push_back(getSeriesInput(filename[i], statQualifier, sysQualifier, "")); + } + } + } + void createSeriesFromFiles(const std::vector& filename, const std::vector& qualifiers, const std::vector& legends = {}) + { + if (qualifiers.size() != filename.size()) + throw std::runtime_error("PlotTemplateSteerer: filenames and qualifiers have different sizes"); + if (legends.size() != filename.size() && !legends.empty()) + throw std::runtime_error("PlotTemplateSteerer: filenames and qualifiers have different sizes"); + + for (size_t i = 0; i < filename.size(); ++i) { + if (!legends.empty()) + mSeriesInputs.push_back(getSeriesInput(filename[i], qualifiers[i], legends[i])); + else + mSeriesInputs.push_back(getSeriesInput(filename[i], qualifiers[i])); + } + } + void createSeriesFromFilesWithSystematics(const std::vector& filename, + const std::vector& statQualifiers, + const std::vector& sysQualifiers, + const std::vector& legends = {}) + { + if (statQualifiers.size() != filename.size() || sysQualifiers.size() != filename.size()) { + throw std::runtime_error("PlotTemplateSteerer: filenames and qualifiers have different sizes"); + } + if (legends.size() != filename.size() && !legends.empty()) { + throw std::runtime_error("PlotTemplateSteerer: filenames and legends have different sizes"); + } + + for (size_t i = 0; i < filename.size(); ++i) { + if (!legends.empty()) { + mSeriesInputs.push_back(getSeriesInput(filename[i], statQualifiers[i], sysQualifiers[i], legends[i])); + } else { + mSeriesInputs.push_back(getSeriesInput(filename[i], statQualifiers[i], sysQualifiers[i], "")); + } + } + } + void createSeriesFromFilesWithSystematics(const std::vector& statFilenames, + const std::vector& statQualifiers, + const std::vector& sysFilenames, + const std::vector& sysQualifiers, + const std::vector& legends = {}) + { + if (statQualifiers.size() != statFilenames.size() || sysFilenames.size() != statFilenames.size() || sysQualifiers.size() != statFilenames.size()) { + throw std::runtime_error("PlotTemplateSteerer: stat/sys filenames and qualifiers have different sizes"); + } + if (legends.size() != statFilenames.size() && !legends.empty()) { + throw std::runtime_error("PlotTemplateSteerer: filenames and legends have different sizes"); + } + + for (size_t i = 0; i < statFilenames.size(); ++i) { + if (!legends.empty()) { + mSeriesInputs.push_back(getSeriesInput(statFilenames[i], statQualifiers[i], sysFilenames[i], sysQualifiers[i], legends[i])); + } else { + mSeriesInputs.push_back(getSeriesInput(statFilenames[i], statQualifiers[i], sysFilenames[i], sysQualifiers[i], "")); + } + } + } + SeriesInput getSeriesInput(const std::string& filename, const std::string& objname, const std::string& legend = "") + { + std::unique_ptr inFile(TFile::Open(filename.c_str(), "READ")); + if (!inFile || inFile->IsZombie()) { + throw std::runtime_error("PlotTemplateSteerer: could not open file: " + filename); + } + + ObjType stat = getObjectFromFile(*inFile, filename, objname); + return {stat, {}, (legend.empty()) ? objectName(stat) : legend, "lp"}; + } + SeriesInput getSeriesInput(const std::string& filename, const std::string& statObjname, const std::string& sysObjname, const std::string& legend) + { + std::unique_ptr inFile(TFile::Open(filename.c_str(), "READ")); + if (!inFile || inFile->IsZombie()) { + throw std::runtime_error("PlotTemplateSteerer: could not open file: " + filename); + } + + ObjType stat = getObjectFromFile(*inFile, filename, statObjname); + ObjType sys = getObjectFromFile(*inFile, filename, sysObjname); + return {stat, sys, (legend.empty()) ? objectName(stat) : legend, "lp"}; + } + SeriesInput getSeriesInput(const std::string& statFilename, + const std::string& statObjname, + const std::string& sysFilename, + const std::string& sysObjname, + const std::string& legend) + { + std::unique_ptr statFile(TFile::Open(statFilename.c_str(), "READ")); + if (!statFile || statFile->IsZombie()) { + throw std::runtime_error("PlotTemplateSteerer: could not open file: " + statFilename); + } + std::unique_ptr sysFile(TFile::Open(sysFilename.c_str(), "READ")); + if (!sysFile || sysFile->IsZombie()) { + throw std::runtime_error("PlotTemplateSteerer: could not open file: " + sysFilename); + } + + ObjType stat = getObjectFromFile(*statFile, statFilename, statObjname); + ObjType sys = getObjectFromFile(*sysFile, sysFilename, sysObjname); + return {stat, sys, (legend.empty()) ? objectName(stat) : legend, "lp"}; + } + + const std::vector& getLoadedSeriesInputs() const { return mSeriesInputs; } + void clearLoadedSeriesInputs() { mSeriesInputs.clear(); } + const std::vector& getComparisonObjects() const { return mComparisonObjects; } + void clearComparisonObjects() { mComparisonObjects.clear(); } + + private: + static size_t offsetIndex(size_t base, int offset, size_t modulus) + { + const int64_t m = static_cast(modulus); + const int64_t b = static_cast(base); + const int64_t o = static_cast(offset); + const int64_t wrapped = ((b + o) % m + m) % m; + return static_cast(wrapped); + } + + static int legendIndexForSeries(size_t index, int defaultLegendIndex, const std::vector& legendIndices) + { + if (legendIndices.empty()) { + return defaultLegendIndex; + } + return legendIndices[index]; + } + + static TObject* findObjectInFile(TFile& inFile, const std::string& objname) + { + TObject* obj = inFile.Get(objname.c_str()); + if (obj) { + return obj; + } + + TIter nextKey(inFile.GetListOfKeys()); + TKey* key = nullptr; + while ((key = static_cast(nextKey()))) { + const std::string keyName = key->GetName(); + if (keyName.find(objname) != std::string::npos) { + return inFile.Get(keyName.c_str()); + } + } + return nullptr; + } + + static ObjType getObjectFromFile(TFile& inFile, const std::string& filename, const std::string& objname) + { + TObject* obj = findObjectInFile(inFile, objname); + if (!obj) { + throw std::runtime_error("PlotTemplateSteerer: object not found in file " + filename + ": " + objname); + } + if (auto* gAsymm = dynamic_cast(obj)) { + auto* clone = static_cast(gAsymm->Clone()); + return clone; + } + if (auto* gErr = dynamic_cast(obj)) { + auto* clone = static_cast(gErr->Clone()); + return clone; + } + if (auto* h1d = dynamic_cast(obj)) { + auto* clone = static_cast(h1d->Clone()); + clone->SetDirectory(nullptr); + return clone; + } + if (auto* h1 = dynamic_cast(obj)) { + auto* clone = static_cast(h1->Clone()); + clone->SetDirectory(nullptr); + return clone; + } + + throw std::runtime_error("PlotTemplateSteerer: unsupported object type for " + filename + ":" + objname); + } + + static TString objectName(const ObjType& obj) + { + return std::visit( + [](auto* ptr) -> TString { + if (!ptr) { + return {}; + } + return ptr->GetName(); + }, + obj); + } + + std::vector selectColorPalette(size_t nSeries, TemplateMode mode) const + { + const size_t nColorGroups = (mode == TemplateMode::Distinct || mode == TemplateMode::DistinctRatio) ? nSeries : (nSeries + 1) / 2; + if (nColorGroups <= 6) { + std::vector palette; + palette.reserve(6); + for (int i = 0; i < 6; ++i) { + palette.push_back(kP6Blue + i); + } + return palette; + } + if (nColorGroups <= 8) { + std::vector palette; + palette.reserve(8); + for (int i = 0; i < 8; ++i) { + palette.push_back(kP8Blue + i); + } + return palette; + } + std::vector palette; + palette.reserve(10); + for (int i = 0; i < 10; ++i) { + palette.push_back(kP10Blue + i); + } + return palette; + } + + SeriesStyle styleForIndex(size_t index, + TemplateMode mode, + int colorOffset, + int markerOffset, + const std::vector& colorPalette) const + { + if (mode == TemplateMode::TwoMeasurements || mode == TemplateMode::Paired || mode == TemplateMode::PairedRatio || mode == TemplateMode::PairedDifference) { + const size_t pairIndex = index / 2; + const bool isOpen = (index % 2) == 1; + const auto markerIndex = offsetIndex(pairIndex, markerOffset, mPairedMarkers.size()); + const auto colorIndex = offsetIndex(pairIndex, colorOffset, colorPalette.size()); + const auto& markerPair = mPairedMarkers[markerIndex]; + const int marker = isOpen ? markerPair.second : markerPair.first; + const int color = colorPalette[colorIndex]; + return {color, marker}; + } + + const auto markerIndex = offsetIndex(index, markerOffset, mDistinctMarkers.size()); + const auto colorIndex = offsetIndex(index, colorOffset, colorPalette.size()); + const int marker = mDistinctMarkers[markerIndex]; + const int color = colorPalette[colorIndex]; + return {color, marker}; + } + + static TH1* asHistPtr(const ObjType& obj) + { + return std::visit( + [](auto* ptr) -> TH1* { + using T = std::decay_t; + if constexpr (std::is_same_v || std::is_same_v) { + return ptr; + } + return nullptr; + }, + obj); + } + + static bool isGraphType(const ObjType& obj) + { + return std::visit( + [](auto* ptr) { + using T = std::decay_t; + return std::is_same_v || std::is_same_v; + }, + obj); + } + static TGraphAsymmErrors* histToGraph(const TH1* h) + { + auto* g = new TGraphAsymmErrors(h); + g->SetName(Form("%s_graph", h->GetName())); + g->GetXaxis()->SetTitle(h->GetXaxis()->GetTitle()); + return g; + } + static TH1D* graphToHist(const TGraph* g, + const TH1* refHist, + const std::string& name) + { + if (!g || !refHist) { + throw std::runtime_error("graphToHist: null input"); + } + + const int nBins = refHist->GetNbinsX(); + + auto* h = dynamic_cast( + refHist->Clone(name.c_str())); + + if (!h) { + throw std::runtime_error("graphToHist: failed to clone reference histogram"); + } + + h->Reset("ICES"); // keep binning, clear contents + h->SetDirectory(nullptr); + + const int n = g->GetN(); + + for (int i = 0; i < n; ++i) { + double x = 0.0, y = 0.0; + g->GetPoint(i, x, y); + + int bin = h->FindBin(x); + + if (bin < 1 || bin > nBins) { + continue; // out of range → ignore + } + + h->SetBinContent(bin, y); + + // --- uncertainty handling --- + double ey = 0.0; + + if (auto* ge = dynamic_cast(g)) { + ey = ge->GetErrorY(i); + } else if (auto* gae = dynamic_cast(g)) { + ey = 0.5 * (gae->GetErrorYlow(i) + gae->GetErrorYhigh(i)); + } + + h->SetBinError(bin, ey); + } + + return h; + } + static ObjType makeComparisonObject(const ObjType& numerator, const ObjType& denominator, int index, ComparisonMode comparisonMode = ComparisonMode::Ratio) + { + ObjType numObj = numerator; + ObjType denObj = denominator; + + // In case one object is TH1 and the other is TGraph + bool numIsGraph = isGraphType(numObj); + bool denIsGraph = isGraphType(denObj); + + TH1* numH = asHistPtr(numObj); + TH1* denH = asHistPtr(denObj); + + if ((numH && denIsGraph) || (denH && numIsGraph)) { + if (numH) { + numObj = histToGraph(numH); + numIsGraph = true; + } + if (denH) { + denObj = histToGraph(denH); + denIsGraph = true; + } + } + + if (numH && denH) { + TH1* comparison = static_cast(numH->Clone(Form("%s_%s_%d", numH->GetName(), (comparisonMode == ComparisonMode::Difference) ? "difference" : "ratio", index))); + comparison->SetDirectory(nullptr); + if (comparisonMode == ComparisonMode::Ratio) + comparison->Divide(denH); + if (comparisonMode == ComparisonMode::Difference) + comparison->Add(denH, -1); + if (comparisonMode == ComparisonMode::RelativeDeviation) { + for (int i = 1; i <= comparison->GetNbinsX(); i++) { + double A = numH->GetBinContent(i); + double B = denH->GetBinContent(i); + double sA = numH->GetBinError(i); + double sB = denH->GetBinError(i); + + if (A == 0) { + comparison->SetBinContent(i, 0); + comparison->SetBinError(i, 0); + continue; + } + + double D = std::abs(A - B); + double R = D / A; + + // Error propagation (ignore sign) + double dRdA = D / (A * A); + double dRdB = 1.0 / A; + + double sR = std::sqrt(dRdA * dRdA * sA * sA + + dRdB * dRdB * sB * sB); + + comparison->SetBinContent(i, R); + comparison->SetBinError(i, sR); + } + } + return comparison; + } + + if (numIsGraph && denIsGraph) { + return std::visit( + [index, comparisonMode](auto* numPtr, auto* denPtr) -> ObjType { + using NumT = std::decay_t; + using DenT = std::decay_t; + constexpr bool numGraph = std::is_same_v || std::is_same_v; + constexpr bool denGraph = std::is_same_v || std::is_same_v; + if constexpr (!(numGraph && denGraph)) { + throw std::runtime_error("PlotTemplateSteerer: incompatible ratio object types"); + } else { + int nNum = numPtr->GetN(); + int nDen = denPtr->GetN(); + + if (nNum != nDen) { + throw std::runtime_error("PlotTemplateSteerer: graph ratio requires equal number of points"); + } + + auto* comparison = new TGraphErrors(nNum); + std::string cmpStr = "ratio"; + if (comparisonMode == ComparisonMode::Difference) + cmpStr = "difference"; + if (comparisonMode == ComparisonMode::RelativeDeviation) + cmpStr = "Rel. Dev."; + comparison->SetTitle(Form("; %s; %s", numPtr->GetXaxis()->GetTitle(), cmpStr.c_str())); + comparison->SetName(Form("%s_%s_%d", numPtr->GetName(), cmpStr.c_str(), index)); + for (int ip = 0; ip < nNum; ++ip) { + double xNum = 0.0, yNum = 0.0; + double xDen = 0.0, yDen = 0.0; + numPtr->GetPoint(ip, xNum, yNum); + denPtr->GetPoint(ip, xDen, yDen); + + if (std::abs(xNum - xDen) > 1e-9) { + throw std::runtime_error("PlotTemplateSteerer: graph comparison requires matching x points"); + } + + double eNumY = 0.0; + double eDenY = 0.0; + double eNumX = 0.0; + + if constexpr (std::is_same_v) { + eNumY = numPtr->GetErrorY(ip); + eNumX = numPtr->GetErrorX(ip); + } else { + eNumY = 0.5 * (numPtr->GetErrorYlow(ip) + numPtr->GetErrorYhigh(ip)); + eNumX = 0.5 * (numPtr->GetErrorXlow(ip) + numPtr->GetErrorXhigh(ip)); + } + + if constexpr (std::is_same_v) { + eDenY = denPtr->GetErrorY(ip); + } else { + eDenY = 0.5 * (denPtr->GetErrorYlow(ip) + denPtr->GetErrorYhigh(ip)); + } + + double compY = 0.0; + double compEY = 0.0; + if (comparisonMode == ComparisonMode::Ratio) { + if (std::abs(yDen) > 0.0) { + compY = yNum / yDen; + const double relNum = (std::abs(yNum) > 0.0) ? (eNumY / yNum) : 0.0; + const double relDen = eDenY / yDen; + compEY = std::abs(compY) * std::sqrt(std::abs(relNum * relNum - relDen * relDen)); + } + } + if (comparisonMode == ComparisonMode::Difference) { + compY = yNum - yDen; + compEY = std::sqrt(eNumY * eNumY + eDenY * eDenY); + } + if (comparisonMode == ComparisonMode::RelativeDeviation) { + if (std::abs(yDen) > 0.0) { + double D = std::abs(yNum - yDen); + compY = D / yDen; + double dDen = D / (yDen * yDen); + double dNum = 1.0 / yDen; + compEY = std::sqrt(dNum * dNum * eNumY * eNumY + + dDen * dDen * eDenY * eDenY); + } + } + comparison->SetPoint(ip, xNum, compY); + comparison->SetPointError(ip, eNumX, compEY); + } + return comparison; + } + }, + numObj, denObj); + } + + throw std::runtime_error("PlotTemplateSteerer: unsupported types for ratio objects"); + } + + std::vector mFallbackColorPalette; + std::vector> mPairedMarkers; + std::vector mDistinctMarkers; + std::vector mSeriesInputs; + mutable std::vector mComparisonObjects; +}; + +#endif // PWGCF_GENERICFRAMEWORK_CORE_PLOTTEMPLATESTEERER_H_ diff --git a/PWGCF/GenericFramework/Core/PlotYRangeUtils.h b/PWGCF/GenericFramework/Core/PlotYRangeUtils.h new file mode 100644 index 00000000000..047cb3f7fe6 --- /dev/null +++ b/PWGCF/GenericFramework/Core/PlotYRangeUtils.h @@ -0,0 +1,287 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef PWGCF_GENERICFRAMEWORK_CORE_PLOTYRANGEUTILS_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_PLOTYRANGEUTILS_H_ + +#include "TGraphAsymmErrors.h" +#include "TGraphErrors.h" +#include "TH1.h" +#include "TH1D.h" + +#include +#include +#include +#include +#include + +namespace plotutils +{ + +struct YRange { + double ymin; + double ymax; + bool valid; +}; + +struct YPoint { + double x; + double y; + double ey; +}; + +enum class ComparisonMode { + None, + PairedRatio, + PairedDifference, + PairedRelDev +}; + +template +std::vector extractPointsFromObject(const ObjVariant& obj) +{ + std::vector points; + std::visit( + [&](auto* ptr) { + using T = std::decay_t; + if (!ptr) { + return; + } + + if constexpr (std::is_same_v || std::is_same_v) { + for (int i = 1; i <= ptr->GetNbinsX(); ++i) { + points.push_back({ptr->GetBinCenter(i), ptr->GetBinContent(i), ptr->GetBinError(i)}); + } + } else if constexpr (std::is_same_v) { + for (int i = 0; i < ptr->GetN(); ++i) { + double x = 0.0, y = 0.0; + ptr->GetPoint(i, x, y); + points.push_back({x, y, ptr->GetErrorY(i)}); + } + } else if constexpr (std::is_same_v) { + for (int i = 0; i < ptr->GetN(); ++i) { + double x = 0.0, y = 0.0; + ptr->GetPoint(i, x, y); + const double ey = 0.5 * (ptr->GetErrorYlow(i) + ptr->GetErrorYhigh(i)); + points.push_back({x, y, ey}); + } + } + }, + obj); + + return points; +} + +inline void appendYAndErrorEnvelope(std::vector& ys, const std::vector& points) +{ + for (const auto& p : points) { + if (std::isfinite(p.y)) { + ys.push_back(p.y); + } + if (std::isfinite(p.y - p.ey)) { + ys.push_back(p.y - p.ey); + } + if (std::isfinite(p.y + p.ey)) { + ys.push_back(p.y + p.ey); + } + } +} + +template +std::vector collectTopPadPoints(const SeriesCollection& series) +{ + std::vector points; + for (const auto& s : series) { + const auto statPts = extractPointsFromObject(s.stat); + points.insert(points.end(), statPts.begin(), statPts.end()); + const auto sysPts = extractPointsFromObject(s.sys); + points.insert(points.end(), sysPts.begin(), sysPts.end()); + } + return points; +} + +template +std::vector collectComparisonPoints(const SeriesCollection& series, ComparisonMode mode) +{ + std::vector points; + + if (mode == ComparisonMode::None) { + return points; + } + + for (size_t i = 0; i + 1 < series.size(); i += 2) { + const auto numPoints = extractPointsFromObject(series[i].stat); + const auto denPoints = extractPointsFromObject(series[i + 1].stat); + + const size_t n = std::min(numPoints.size(), denPoints.size()); + for (size_t j = 0; j < n; ++j) { + const auto& npt = numPoints[j]; + const auto& dpt = denPoints[j]; + + if (!std::isfinite(npt.y) || !std::isfinite(dpt.y)) { + continue; + } + + if (mode == ComparisonMode::PairedRatio || mode == ComparisonMode::PairedRelDev) { + if (std::abs(dpt.y) < 1e-12) { + continue; + } + const double r = npt.y / dpt.y; + double relNum = 0.0; + double relDen = dpt.ey / std::abs(dpt.y); + if (std::abs(npt.y) > 1e-12) { + relNum = npt.ey / std::abs(npt.y); + } + const double er = std::abs(r) * std::sqrt(relNum * relNum + relDen * relDen); + if (std::isfinite(r) && std::isfinite(er)) { + points.push_back({npt.x, r, er}); + } + } else { + const double d = npt.y - dpt.y; + const double ed = std::sqrt(npt.ey * npt.ey + dpt.ey * dpt.ey); + if (std::isfinite(d) && std::isfinite(ed)) { + points.push_back({npt.x, d, ed}); + } + } + } + } + + return points; +} + +inline std::vector yValuesFromPoints(const std::vector& points) +{ + std::vector ys; + appendYAndErrorEnvelope(ys, points); + return ys; +} + +inline YRange robustRangeWithOutlierRejection(const std::vector& values, double madCut = 3.5, double minSpan = 1e-6) +{ + if (values.empty()) { + return {0.0, 0.0, false}; + } + + std::vector sorted = values; + std::sort(sorted.begin(), sorted.end()); + + auto percentile = [&](double q) { + if (sorted.size() == 1) { + return sorted[0]; + } + const double pos = q * (sorted.size() - 1); + const int lo = static_cast(std::floor(pos)); + const int hi = static_cast(std::ceil(pos)); + const double t = pos - lo; + return sorted[lo] * (1.0 - t) + sorted[hi] * t; + }; + + const double median = percentile(0.5); + std::vector absDev; + absDev.reserve(sorted.size()); + for (double v : sorted) { + absDev.push_back(std::abs(v - median)); + } + std::sort(absDev.begin(), absDev.end()); + + double mad = 0.0; + if (!absDev.empty()) { + if (absDev.size() % 2 == 0) { + mad = 0.5 * (absDev[absDev.size() / 2 - 1] + absDev[absDev.size() / 2]); + } else { + mad = absDev[absDev.size() / 2]; + } + } + + std::vector filtered; + if (mad > 0.0) { + const double robustSigma = 1.4826 * mad; + for (double v : sorted) { + if (std::abs(v - median) <= madCut * robustSigma) { + filtered.push_back(v); + } + } + } + + if (filtered.size() < 3) { + filtered = sorted; + } + + const auto mm = std::minmax_element(filtered.begin(), filtered.end()); + double ymin = *mm.first; + double ymax = *mm.second; + + if (!(std::isfinite(ymin) && std::isfinite(ymax))) { + return {0.0, 0.0, false}; + } + + if (std::abs(ymax - ymin) < minSpan) { + const double expand = std::max(1e-3, 0.2 * std::max(std::abs(ymax), 1.0)); + ymin -= expand; + ymax += expand; + } + + return {ymin, ymax, true}; +} + +inline YRange determineIdealYLimits(const std::vector& ys, + int padIndex, + double referenceLine) +{ + std::vector values = ys; + values.push_back(referenceLine); + + const YRange base = robustRangeWithOutlierRejection(values); + if (!base.valid) { + if (padIndex == 1) { + return {-0.5, 0.5, true}; + } + if (referenceLine == 0.0) { + return {-0.05, 0.05, true}; + } + return {0.8, 1.2, true}; + } + + const double span = base.ymax - base.ymin; + const double margin = (padIndex == 1) ? 0.18 : 0.22; + double ymin = base.ymin - margin * span; + double ymax = base.ymax + margin * span; + + if (padIndex == 2) { + if (referenceLine == 1.0) { + ymin = std::min(ymin, 0.95); + ymax = std::max(ymax, 1.05); + } else if (referenceLine == 0.0) { + ymin = std::min(ymin, -0.005); + ymax = std::max(ymax, 0.005); + } + } + + return {ymin, ymax, true}; +} + +template +inline YRange determineTopPadYLimits(const SeriesCollection& series) +{ + return determineIdealYLimits(yValuesFromPoints(collectTopPadPoints(series)), 1, 0.0); +} + +template +inline YRange determineBottomPadYLimits(const SeriesCollection& series, + ComparisonMode mode, + double referenceLine) +{ + return determineIdealYLimits(yValuesFromPoints(collectComparisonPoints(series, mode)), 2, referenceLine); +} + +} // namespace plotutils + +#endif // PWGCF_GENERICFRAMEWORK_CORE_PLOTYRANGEUTILS_H_ diff --git a/PWGCF/GenericFramework/Core/StatHandler.cxx b/PWGCF/GenericFramework/Core/StatHandler.cxx new file mode 100644 index 00000000000..a2d0cf53f47 --- /dev/null +++ b/PWGCF/GenericFramework/Core/StatHandler.cxx @@ -0,0 +1,126 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// NOLINTBEGIN(readability/casting, readability/braces) +#include "StatHandler.h" + +#include "TRandom.h" + +#include +#include +#include + +StatHandler::StatHandler() : nSamples(10) +{ + methodMap[StatMethod::kBootstrap] = &StatHandler::bootstrap; + methodMap[StatMethod::kVarianceOfSamples] = &StatHandler::varianceOfSamples; + methodMap[StatMethod::kJackknife] = &StatHandler::jackknife; +} +StatHandler::StatHandler(int n) : nSamples(n) +{ + methodMap[StatMethod::kBootstrap] = &StatHandler::bootstrap; + methodMap[StatMethod::kVarianceOfSamples] = &StatHandler::varianceOfSamples; + methodMap[StatMethod::kJackknife] = &StatHandler::jackknife; +} + +StatHandler::~StatHandler() {}; + +TH1D* StatHandler::getNominal(const std::vector& samplehists, StatMethod method) +{ + auto stat_profile = (this->*methodMap[method])(samplehists); + auto reth = samplehists[0]; + applyStatErrors(reth, stat_profile); + delete stat_profile; + return reth; +} +void StatHandler::applyStatErrors(TH1D* nominal, TProfile*& stat_profile) +{ + if (nominal->GetNbinsX() != stat_profile->GetNbinsX()) { + printf("Bootstrap warning: number of bins in histogram and profile is not the same! Not applying...\n"); + return; + }; + for (Int_t i = 1; i <= nominal->GetNbinsX(); i++) { + if (nominal->GetBinContent(i) == 0) + continue; + nominal->SetBinError(i, stat_profile->GetBinError(i)); + }; + return; +} +TProfile* StatHandler::varianceOfSamples(const std::vector& samplehists) +{ + setCurrentAxis(samplehists[0]); + auto retpf = new TProfile("Statistics_Profile", "StatProf", nxbins, &(xbins[0])); + for (Int_t i = 1; i <= nxbins; i++) + for (Int_t j = 1; j <= nSamples; j++) + retpf->Fill(samplehists[0]->GetBinCenter(i), samplehists[j]->GetBinContent(i)); + return retpf; +} +TProfile* StatHandler::bootstrap(const std::vector& samplehists) +{ + setCurrentAxis(samplehists[0]); + auto rnd = new TRandom(); + auto retpf = new TProfile("Statistics_Profile", "StatProf", nxbins, &(xbins[0])); + for (int i(0); i < 1000; ++i) { + std::vector random_sample_hists; + for (Int_t j = 0; j < nSamples; ++j) { + int rnd_int = (int)rnd->Uniform(nSamples) + 1; + auto random_sample = samplehists[rnd_int]; + random_sample->SetName(Form("%s_sample%i", random_sample->GetName(), j)); + random_sample_hists.push_back(random_sample); + } + auto tmppf = std::make_unique("tmp_Profile", "tmpProf", nxbins, &(xbins[0])); + for (Int_t i = 1; i <= nxbins; ++i) + for (Int_t j = 0; j < nSamples; j++) + tmppf->Fill(samplehists[0]->GetBinCenter(i), random_sample_hists[j]->GetBinContent(i)); + for (Int_t i = 1; i <= nxbins; ++i) { + retpf->Fill(samplehists[0]->GetBinCenter(i), tmppf->GetBinContent(i)); + } + } + + delete rnd; + return retpf; +} +TProfile* StatHandler::jackknife(const std::vector& samplehists) +{ + setCurrentAxis(samplehists[0]); + auto retpf = new TProfile("Statistics_Profile", "StatProf", nxbins, &(xbins[0])); + // calculate jackknife means + for (int i = 0; i < nSamples; ++i) { + std::vector jackknife_hists = samplehists; + // remove the nominal hist + jackknife_hists.erase(jackknife_hists.begin()); + // remove ith subsample hist + jackknife_hists.erase(jackknife_hists.begin() + i); + auto tmppf = std::make_unique("tmp_Profile", "tmpProf", nxbins, &(xbins[0])); + for (int bin = 1; bin <= nxbins; ++bin) { + for (size_t j = 0; j < jackknife_hists.size(); ++j) { + tmppf->Fill(samplehists[0]->GetBinCenter(bin), jackknife_hists[j]->GetBinContent(bin)); + } + } + // jackknife estimator of mean as mean of jackknife subsample means + for (int bin = 1; bin <= nxbins; ++bin) { + retpf->Fill(samplehists[0]->GetBinCenter(bin), tmppf->GetBinContent(bin)); + } + } + return retpf; +} +void StatHandler::setCurrentAxis(TH1D* tmph) +{ + nxbins = tmph->GetNbinsX(); + double* tmp_xbins = new double[nxbins + 1]; + tmph->GetXaxis()->GetLowEdge(tmp_xbins); + tmp_xbins[nxbins] = tmph->GetXaxis()->GetBinUpEdge(nxbins); + xbins.clear(); + xbins.insert(xbins.end(), &tmp_xbins[0], &tmp_xbins[nxbins + 1]); + delete[] tmp_xbins; + return; +} +// NOLINTEND(readability/casting, readability/braces) diff --git a/PWGCF/GenericFramework/Core/StatHandler.h b/PWGCF/GenericFramework/Core/StatHandler.h new file mode 100644 index 00000000000..05687d7ce0b --- /dev/null +++ b/PWGCF/GenericFramework/Core/StatHandler.h @@ -0,0 +1,55 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef PWGCF_GENERICFRAMEWORK_CORE_STATHANDLER_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_STATHANDLER_H_ + +#include "BootstrapProfile.h" + +#include "TH1.h" +#include "TProfile.h" + +#include +#include +#include + +class TRandom; + +class StatHandler +{ + public: + StatHandler(); + explicit StatHandler(int n); + virtual ~StatHandler(); + enum StatMethod { + kBootstrap, + kVarianceOfSamples, + kJackknife + }; + using StatFunc = TProfile* (StatHandler::*)(const std::vector&); + + TH1D* getNominal(const std::vector& samplehists, StatMethod method = kBootstrap); + + private: + std::map methodMap; //! + int nSamples; + int nxbins; + std::vector xbins; + void setCurrentAxis(TH1D* tmph); + TProfile* varianceOfSamples(const std::vector& samplehists); + TProfile* bootstrap(const std::vector& samplehists); + TProfile* jackknife(const std::vector& samplehists); + void applyStatErrors(TH1D* nominal, TProfile*& stat_profile); + + ClassDef(StatHandler, 1); +}; + +#endif // PWGCF_GENERICFRAMEWORK_CORE_STATHANDLER_H_ diff --git a/PWGCF/GenericFramework/Core/SysHandler.cxx b/PWGCF/GenericFramework/Core/SysHandler.cxx new file mode 100644 index 00000000000..62e28d4e9f8 --- /dev/null +++ b/PWGCF/GenericFramework/Core/SysHandler.cxx @@ -0,0 +1,512 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// NOLINTBEGIN(readability/casting, readability/braces) +#include "SysHandler.h" + +#include +#include +#include + +#include +#include +#include +#include + +namespace +{ +bool hasValidSystematicRange(const SysHandler::SystSettings& settings) +{ + return settings.sys_avg_range.second > settings.sys_avg_range.first; +} + +bool isInSystematicRange(const TH1* hist, int bin, const SysHandler::SystSettings& settings) +{ + if (!hasValidSystematicRange(settings)) { + return true; + } + const double center = hist->GetXaxis()->GetBinCenter(bin); + return center >= settings.sys_avg_range.first && center <= settings.sys_avg_range.second; +} + +double getReportedGroupUncertainty(const TH1* hist, const SysHandler::SystSettings& settings, bool relative) +{ + if (!hist) { + return 0.; + } + if (settings.use_fit_for_syst) { + for (int bin = 1; bin <= hist->GetNbinsX(); ++bin) { + if (isInSystematicRange(hist, bin, settings)) { + return hist->GetBinContent(bin); + } + } + return 0.; + } + if (!hasValidSystematicRange(settings)) { + return hist->GetMaximum(); + } + + double sum = 0.; + int acceptedBins = 0; + for (int bin = 1; bin <= hist->GetNbinsX(); ++bin) { + if (!isInSystematicRange(hist, bin, settings)) { + continue; + } + const double value = hist->GetBinContent(bin); + if (value == 0. || (relative && value > settings.max_allowed_syst)) { + continue; + } + sum += value; + ++acceptedBins; + } + return acceptedBins > 0 ? sum / acceptedBins : 0.; +} +} // namespace + +SysHandler::SysHandler() : current_settings{{0., 90.}, true, 1, 1, true} +{ + setSystematicVariations({ + {1, 1, -1, "VtxZ < 9cm", "VtxZ"}, + {2, 1, -1, "VtxZ < 8cm", "VtxZ"}, + {3, 1, -1, "VtxZ < 7cm", "VtxZ"}, + {4, 2, -1, "DCAxy < 5#sigma", "DCAxy"}, + {5, 2, -1, "DCAxy < 10#sigma", "DCAxy"}, + {6, 3, -1, "DCAz < 0.1cm", "DCAz"}, + {7, 3, -1, "DCAz < 2cm", "DCAz"}, + {8, 4, -1, "TPC X-rows > 60", "TPCXrows"}, + {9, 4, -1, "TPC X-rows > 90", "TPCXrows"}, + {10, 5, -1, "TPCncls > 40", "TPC cluster"}, + {11, 5, -1, "TPCncls > 70", "TPC cluster"}, + {12, 6, -1, "#chi^2 pr. TPCcls < 4", "TPCChi2"}, + {13, 10, -1, "c#tau", "Lifetime"}, + {14, 0, -1, "FT0M", "centEst"}, + {15, 11, -1, "Competing mass cut", "Competing mass cut"}, + {16, 12, -1, "cosPA", "Pointing Angle"}, + {17, 0, -1, "Daughter PID rejection", "Daughter PID rejection"}, + {18, 8, -1, "FitCentrality", "fitCentrality"}, + {19, 9, -1, "MassFitFunction", "fitFunction"}, + }); +} +SysHandler::~SysHandler() +{ + clearSysMap(); +}; + +void SysHandler::clearSysMap() +{ + for (auto& [index, histogram] : fSystMap) { + delete histogram; + } + fSystMap.clear(); +} + +void SysHandler::setSystematicVariations(const std::vector& variations) +{ + fSystematicVariations.clear(); + fIndMap.clear(); + for (const auto& variation : variations) { + fSystematicVariations[variation.index] = variation; + } +} +TH1D* SysHandler::getNominal(bool relative, bool apply_barlow) +{ + if (fSystMap.empty()) { + printf("Warning: SystMap not set!"); + return nullptr; + } + TH1* systs = getSystematicsSummed(relative, apply_barlow); + systs->SetName("Systematics_Summed"); + TH1* nominal = dynamic_cast(fSystMap[0]->Clone(Form("Nominal_fullSyst_%s", fSystMap[0]->GetName()))); + // FSRebin(&cvals); + applyErrors(nominal, systs, relative); + delete systs; + return dynamic_cast(nominal); +} +TH1* SysHandler::getSystematics(int sys_index, bool rel, bool apply_barlow, bool abs) +{ + TH1* var = dynamic_cast(fSystMap[sys_index]->Clone(Form("RelSyst_Ind%i_%s", sys_index, fSystMap[0]->GetName()))); + TH1* nom = dynamic_cast(fSystMap[0]->Clone(Form("Nominal_Ind%i_%s", sys_index, fSystMap[0]->GetName()))); + var->Add(nom, -1); + if (rel) + var->Divide(nom); + histOper(var, 0, 1, abs, kTRUE); + delete nom; + if (!apply_barlow) + return var; + TH1* barlow = getBarlowTest(sys_index, getCorrelationError(sys_index)); + if (!barlow) + return var; + if (!passesBarlowSelection(barlow)) { + for (int i = 1; i <= var->GetNbinsX(); ++i) { + var->SetBinContent(i, 0.); + } + } + delete barlow; + return var; +} +void SysHandler::applyBarlow(TH1* target, TH1* barlow) +{ + if (!target || !barlow) { + printf("ApplyBarlow: missing a histogram...\n"); + return; + }; + if (target->GetNbinsX() != barlow->GetNbinsX()) { + printf("applyBarlow: different number of bins\n"); + return; + }; + for (Int_t i = 1; i <= target->GetNbinsX(); i++) { + if (barlow->GetBinContent(i) > current_settings.fNbarlow) + continue; + target->SetBinContent(i, 0); + }; +} +bool SysHandler::passesBarlowSelection(const TH1* barlow) const +{ + if (!barlow) { + return true; + } + double sum = 0.; + int binCount = 0; + int barlowCount = 0; + for (int i = 1; i <= barlow->GetNbinsX(); ++i) { + if (!isInSystematicRange(barlow, i, current_settings)) { + continue; + } + sum += barlow->GetBinContent(i); + ++binCount; + if (barlow->GetBinContent(i) > current_settings.fNbarlow) { + ++barlowCount; + } + } + if (binCount == 0) { + return true; + } + if (current_settings.fUseBarlowCount) { + const int barlowCutoff = ceil(0.5 * binCount); + return barlowCount >= barlowCutoff; + } + return sum / binCount >= current_settings.fNbarlow; +} +void SysHandler::histOper(TH1* reth, Double_t cvl, Double_t lpower, Bool_t Abs, Bool_t RemoveErrors) +{ + for (Int_t i = 1; i <= reth->GetNbinsX(); i++) { + Double_t bc = reth->GetBinContent(i); + if (!bc) + continue; + bc += cvl; + Double_t bcn = TMath::Power(bc, lpower); + if (Abs) + bcn = TMath::Abs(bcn); + reth->SetBinContent(i, bcn); + if (RemoveErrors) { + reth->SetBinError(i, 0); + } else { + Double_t err = reth->GetBinError(i); + err = err * lpower * TMath::Power(bc, lpower - 1); + reth->SetBinError(i, err); + } + } +} +TH1* SysHandler::getSystematicsFromFit(Int_t sys_index, Bool_t apply_barlow, bool ratio, bool relative) +{ + if (fSystMap.empty()) + printf("Sys map not set\n"); + const auto nominalIt = fSystMap.find(0); + const auto variationIt = fSystMap.find(sys_index); + if (nominalIt == fSystMap.end() || !nominalIt->second || variationIt == fSystMap.end() || !variationIt->second) { + printf("Could not fetch nominal or systematic index %i\n", sys_index); + return nullptr; + } + TH1* var = dynamic_cast(variationIt->second->Clone(Form("RelSystFit_sys%i_%s", sys_index, nominalIt->second->GetName()))); + if (!var) { + printf("Could not fetch systematic index %i\n", sys_index); + return 0; + }; + // If we have final state rebinning, then need bootstrapping on the nominal here. Otherwise, final state rebinning will be bogus + TH1* nom = dynamic_cast(nominalIt->second->Clone(Form("NominalFit_sys%i_%s", sys_index, nominalIt->second->GetName()))); + // FSRebin(&nom); + var->SetName(Form("RelSyst_%s_Ind%i", nom->GetName(), sys_index)); + if (relative || ratio) { + var->Divide(nom); + } else { + var->Add(nom, -1.); + } + if (ratio) { + delete nom; + return var; + } + const char* fitFunction = current_settings.syst_fit_function == "pol1" ? "pol1" : "pol0"; + var->Fit(fitFunction, "Q0+R", "", current_settings.sys_avg_range.first, current_settings.sys_avg_range.second); + TF1* func = (TF1*)var->GetListOfFunctions()->FindObject(fitFunction); + const double fitError = func->GetParError(0); + const double fitReference = relative ? 1. : 0.; + const double fitSignificance = fitError > 0. ? TMath::Abs(func->GetParameter(0) - fitReference) / fitError : 0.; + for (int i = 1; i <= var->GetNbinsX(); ++i) { + const double fittedValue = func->Eval(var->GetXaxis()->GetBinCenter(i)); + const double fittedUncertainty = relative ? TMath::Abs(1. - fittedValue) : TMath::Abs(fittedValue); + var->SetBinContent(i, isInSystematicRange(var, i, current_settings) ? fittedUncertainty : 0.); + } + histOper(var, 0, 1, kFALSE, kTRUE); + delete nom; + if (!apply_barlow) + return var; + if (current_settings.reject_on_fit_significance && fitSignificance < current_settings.min_fit_significance) { + for (int i = 1; i <= var->GetNbinsX(); ++i) { + var->SetBinContent(i, 0.); + } + return var; + } + TH1* barlow = getBarlowTest(sys_index, getCorrelationError(sys_index)); + if (!barlow) + return var; + if (!passesBarlowSelection(barlow)) { + for (int i = 1; i <= var->GetNbinsX(); ++i) { + var->SetBinContent(i, 0.); + } + } + delete barlow; + return var; +} +TH1* SysHandler::getBarlowTest(Int_t sys_index, Double_t corrFactor) +{ + TH1* var = dynamic_cast(fSystMap[sys_index]->Clone(Form("VarBarlow_Ind%i_%s", sys_index, fSystMap[0]->GetName()))); + if (!var) + return 0; + TH1* nom = dynamic_cast(fSystMap[0]->Clone(Form("NominalBarlow_Ind%i_%s", sys_index, fSystMap[0]->GetName()))); + TH1* absDif = getSystematics(sys_index, kFALSE, kFALSE, kTRUE); + if (!absDif) { + delete nom; + delete var; + return 0; + } + for (Int_t i = 1; i <= absDif->GetNbinsX(); i++) { + Double_t bc = absDif->GetBinContent(i); + if (!bc) + continue; + Double_t s1 = var->GetBinError(i); + Double_t s2 = nom->GetBinError(i); + Double_t denom = TMath::Sqrt(TMath::Abs((s1 * s1 + corrFactor * s2 * s2))); + if (!denom) { + absDif->SetBinError(i, 0); + continue; + }; + absDif->SetBinContent(i, bc / denom); + absDif->SetBinError(i, 0); + } + delete nom; + delete var; + return absDif; +} +Bool_t SysHandler::BuildIndexMap(Bool_t force) +{ + // if(!fSysts) {printf("Systematics not read!\n"); return 0; }; + // if(!fSysts->GetEntries()) {printf("No systematics available!\n"); return 0; }; + if (force && !((int)fIndMap.size())) + fIndMap.clear(); + for (auto& el : fSystMap) { + Int_t tval = getTarget(el.first); + if (!fIndMap.count(tval)) + fIndMap.insert(make_pair(tval, std::vector{})); + fIndMap.at(tval).push_back(el.first); + }; + return kTRUE; +}; + +std::vector SysHandler::getSystSubset(Int_t KeyInd, Bool_t relative, Bool_t apply_barlow) +{ + if (!(int)fIndMap.size()) + if (!BuildIndexMap(kTRUE)) { + printf("getSystSubset: could not build map!\n"); + return nullvec; + }; + if (!fIndMap.count(KeyInd)) { + printf("getSystSubset: could not find key %i in the map!\n", KeyInd); + return nullvec; + }; + std::vector inds = fIndMap.at(KeyInd); + std::vector retvec; + for (Int_t j = 0; j < (int)inds.size(); j++) + retvec.push_back(current_settings.use_fit_for_syst ? getSystematicsFromFit(inds.at(j), apply_barlow, false, relative) : getSystematics(inds.at(j), relative, apply_barlow)); + return retvec; +} +std::vector SysHandler::getMergedErrors(Bool_t relative, Bool_t apply_barlow) +{ + if (!(int)fIndMap.size()) + if (!BuildIndexMap(kTRUE)) { + printf("getMergedErrors: could not build map!\n"); + return nullvec; + }; + if (!fPrintMap.empty()) + fPrintMap.erase(fPrintMap.begin(), fPrintMap.end()); + fPrintBinMap.clear(); + const auto storePrintValues = [this, relative](int index, const TH1* hist) { + fPrintMap[index] = getReportedGroupUncertainty(hist, current_settings, relative); + std::vector& binValues = fPrintBinMap[index]; + binValues.reserve(hist->GetNbinsX()); + for (int bin = 1; bin <= hist->GetNbinsX(); ++bin) { + binValues.push_back(hist->GetBinContent(bin)); + } + }; + std::vector reth; + for (auto errcind = fIndMap.begin(); errcind != fIndMap.end(); errcind++) { + Int_t targetInd = errcind->first; + if (targetInd == 0) + continue; // 0 contains all those that are not relevant + std::vector lSubsets = getSystSubset(targetInd, relative, apply_barlow); + if ((int)lSubsets.size() == 0) + continue; // if no subsets, then continue + TH1* rh = (TH1*)lSubsets.at(0)->Clone(Form("MergedErrors_%i", targetInd)); + if (!rh) { + for (auto* subset : lSubsets) + delete subset; + continue; + } + RemoveErrors(rh); // To remove errors + reth.push_back(rh); + if (fSystOverride.count(targetInd)) { + Double_t newerr = fSystOverride.at(targetInd); + printf("Found a bins with key index %i, value %f\n", targetInd, newerr); + for (Int_t i = 1; i <= rh->GetNbinsX(); i++) + rh->SetBinContent(i, newerr); + storePrintValues(targetInd, rh); + for (auto* subset : lSubsets) + delete subset; + continue; + } + if ((int)lSubsets.size() == 1) { // if only one, then no need to continue, but need to add to print map + storePrintValues(targetInd, rh); + delete lSubsets.front(); + continue; + } + // loop over subsets and pick max + for (auto sh = lSubsets.begin() + 1; sh != lSubsets.end(); sh++) { + // Looping over bins + for (Int_t i = 1; i <= rh->GetNbinsX(); i++) { + Double_t vmax = TMath::Max(rh->GetBinContent(i), (*sh)->GetBinContent(i)); + rh->SetBinContent(i, vmax); + } + } + // Ideally only use this for systematics from fit as it has a single value in all bins, otherwise we get the max value but might not be as informative + storePrintValues(targetInd, rh); + for (auto* subset : lSubsets) + delete subset; + } + return reth; +} +TH1* SysHandler::getSystematicsSummed(Bool_t relative, Bool_t apply_barlow) +{ + std::vector mergedErrors = getMergedErrors(relative, apply_barlow); + if ((int)mergedErrors.size() == 0) { + printf("getSystematicsSummed: could not find any errors to sum\n"); + return 0; + }; + TH1* reth = (TH1*)mergedErrors.at(0)->Clone("MergedErrors_Summed"); + reth->Reset(); + for (auto hist : mergedErrors) { + addInQuad(reth, hist); + hist->Delete(); + }; + if (relative && hasValidSystematicRange(current_settings) && !current_settings.use_fit_for_syst) { + int acceptedBins = 0; + double sum = 0.; + for (int bin = 1; bin <= reth->GetNbinsX(); ++bin) { + if (!isInSystematicRange(reth, bin, current_settings)) { + continue; + } + const double value = reth->GetBinContent(bin); + if (value == 0. || value > current_settings.max_allowed_syst) { + continue; + } + sum += value; + ++acceptedBins; + } + if (acceptedBins > 0) { + const double average = sum / acceptedBins; + for (int bin = 1; bin <= reth->GetNbinsX(); ++bin) { + reth->SetBinContent(bin, isInSystematicRange(reth, bin, current_settings) ? average : 0.); + } + } + } + return reth; +}; +void SysHandler::addInQuad(TH1* h1, TH1* h2) +{ + if (!h1 || !h2) { + printf("addInQuad: One of the histograms is missing!\n"); + return; + }; + if (h1->GetNbinsX() != h2->GetNbinsX()) { + printf("addInQuad: number of bins in provided histograms are not the same!\n"); + return; + }; + for (Int_t i = 1; i <= h1->GetNbinsX(); i++) { + Double_t bc1 = h1->GetBinContent(i); + Double_t bc2 = h2->GetBinContent(i); + if (bc1 == 0 && bc2 == 0) + continue; + h1->SetBinContent(i, TMath::Sqrt(bc1 * bc1 + bc2 * bc2)); + } +} +void SysHandler::applyErrors(TH1* inh, TH1* errors, Bool_t relative) +{ + if (!inh || !errors) { + printf("ApplyErrors: One of the histograms is missing!\n"); + return; + }; + // if(inh->GetNbinsX()!=errors->GetNbinsX() && fNRebinForSyst<2) { printf("ApplyErrors: number of bins in provided histograms are not the same!\n"); return; }; + if (inh->GetNbinsX() != errors->GetNbinsX()) { + printf("ApplyErrors: number of bins in provided histograms are not the same!\n"); + return; + }; + for (Int_t i = 1; i <= inh->GetNbinsX(); i++) { + Double_t bc1 = inh->GetBinContent(i); + Double_t bce = inh->GetBinError(i); + if (bc1 == 0 && bce == 0) + continue; + double bc2 = errors->GetBinContent(i); + /* Double_t bc2; + if(fNRebinForSyst>1) { + Double_t bcent = inh->GetBinCenter(i); + Int_t tind = errors->FindBin(bcent); + bc2 = errors->GetBinContent(tind); + } else bc2 = errors->GetBinContent(i); */ + bce = relative ? (bc1 * bc2) : bc2; + inh->SetBinError(i, bce); + } +} +int SysHandler::getTarget(int fSystInd) const +{ + const auto variation = fSystematicVariations.find(fSystInd); + return variation == fSystematicVariations.end() ? 0 : variation->second.group; +} +int SysHandler::getCorrelationError(int fSystInd) const +{ + const auto variation = fSystematicVariations.find(fSystInd); + return variation == fSystematicVariations.end() ? 0 : variation->second.correlation; +} +std::string SysHandler::getSystDescription(int fSystInd) const +{ + const auto variation = fSystematicVariations.find(fSystInd); + return variation == fSystematicVariations.end() ? "Not a valid sys ID" : variation->second.description; +} +// NOLINTEND(readability/casting, readability/braces) +std::string SysHandler::getSystGroupDescription(int targetInd) const +{ + if (targetInd == 0) { + return "Not a valid sys ID"; + } + for (const auto& [index, variation] : fSystematicVariations) { + if (variation.group == targetInd) { + return variation.groupDescription; + } + } + return "Not a valid sys ID"; +} diff --git a/PWGCF/GenericFramework/Core/SysHandler.h b/PWGCF/GenericFramework/Core/SysHandler.h new file mode 100644 index 00000000000..75ce95d5560 --- /dev/null +++ b/PWGCF/GenericFramework/Core/SysHandler.h @@ -0,0 +1,117 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#ifndef PWGCF_GENERICFRAMEWORK_CORE_SYSHANDLER_H_ +#define PWGCF_GENERICFRAMEWORK_CORE_SYSHANDLER_H_ + +#include + +#include +#include +#include +#include +#include + +class SysHandler +{ + public: + SysHandler(); + explicit SysHandler(int n); + virtual ~SysHandler(); + + // Main function call + TH1D* getNominal(bool relative = kTRUE, bool apply_barlow = kTRUE); + + // Utility functions + struct SystSettings { + std::pair sys_avg_range; + bool use_fit_for_syst; + double max_allowed_syst; + double fNbarlow; + bool fUseBarlowCount; + bool reject_on_fit_significance = false; + double min_fit_significance = 1.96; + std::string syst_fit_function = "pol0"; + }; + struct SystematicVariation { + int index; + int group; + int correlation; + std::string description; + std::string groupDescription; + }; + void setSystSettings(SystSettings settings) { current_settings = settings; } + const SystSettings getSystSettings() const { return current_settings; } + void setSystAverageRange(std::pair range, double lMaxAllowed = 1) + { + current_settings.sys_avg_range = range; + current_settings.max_allowed_syst = lMaxAllowed; + }; + void setBarlowCriteria(int newval) { current_settings.fNbarlow = newval; } + void setUseBarlowCount(bool newval) { current_settings.fUseBarlowCount = newval; } + void setFitSignificanceRejection(bool enabled, double minSignificance = 1.96) + { + current_settings.reject_on_fit_significance = enabled; + current_settings.min_fit_significance = minSignificance; + } + void setSysMap(std::map sysmap) + { + clearSysMap(); + fSystMap = std::move(sysmap); + fIndMap.clear(); + } + void setSystematicVariations(const std::vector& variations); + std::map getPrintMap() { return fPrintMap; } + std::map> getPrintBinMap() { return fPrintBinMap; } + void histOper(TH1* reth, Double_t cvl = 0, Double_t lpower = 1, Bool_t Abs = kFALSE, Bool_t RemoveErrors = kFALSE); + std::map getSystMap() { return fSystMap; } + TH1* getVariation(int index) { return fSystMap[index]; } + + // Systematics calculator functions + TH1* getSystematics(); + TH1* getBarlowTest(int sys_index, double corrFactor = 1); + TH1* getSystematics(int sys_index, bool relative = kTRUE, bool apply_barlow = kFALSE, bool abs = kTRUE); + TH1* getSystematicsFromFit(int sys_index, bool apply_barlow = kFALSE, bool ratio = kFALSE, bool relative = kTRUE); + TH1* getSystematicsSummed(bool relative = kTRUE, bool apply_barlow = kFALSE); + std::vector getMergedErrors(bool relative = kTRUE, bool apply_barlow = kFALSE); + std::vector getSystSubset(Int_t KeyInd, bool relative = kTRUE, bool apply_barlow = kFALSE); + void applyErrors(TH1* inh, TH1* errors, Bool_t relative = kTRUE); + void applyBarlow(TH1* target, TH1* barlow); + void addInQuad(TH1* h1, TH1* h2); + void RemoveErrors(TH1* inh) + { + for (Int_t i = 1; i <= inh->GetNbinsX(); i++) + if (inh->GetBinError(i)) + inh->SetBinError(i, 0); + }; + std::vector nullvec; + int getCorrelationError(int fSystInd) const; + std::string getSystDescription(int fSystInd) const; + std::string getSystGroupDescription(int targetInd) const; + int getTarget(int fSystInd) const; + + private: + std::map> fIndMap; //! map to hold correlated indices + std::map fSystematicVariations; //! systematic metadata indexed by variation ID + std::map fSystMap; //! map to hold variations + std::map fSystOverride; //! map to count correlated observables for error merging + std::map fPrintMap; //! map to store values for printing + std::map> fPrintBinMap; //! map to store bin-by-bin values for printing + SystSettings current_settings; + + bool BuildIndexMap(Bool_t force = kFALSE); + bool passesBarlowSelection(const TH1* barlow) const; + void clearSysMap(); + + ClassDef(SysHandler, 3); +}; + +#endif // PWGCF_GENERICFRAMEWORK_CORE_SYSHANDLER_H_ diff --git a/PWGCF/GenericFramework/Tasks/energyFlowGfw.cxx b/PWGCF/GenericFramework/Tasks/energyFlowGfw.cxx index 41fdfa963ec..cf69f3fbe77 100644 --- a/PWGCF/GenericFramework/Tasks/energyFlowGfw.cxx +++ b/PWGCF/GenericFramework/Tasks/energyFlowGfw.cxx @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -119,6 +120,14 @@ struct EnergyFlowGfw { Configurable vertexZ{"vertexZ", 10.f, "Accepted |z-vertex| (cm)"}; Configurable> ptCuts{"ptCuts", {0.2f, 5.f}, "Track pT cuts (GeV/c)"}; Configurable etaMax{"etaMax", 0.8f, "Maximum absolute track pseudorapidity"}; + Configurable cfgDCAxyNSigma{"cfgDCAxyNSigma", 7, "Cut on number of sigma deviations from expected DCA in the transverse direction"}; + Configurable cfgDCAxyPtDep{"cfgDCAxyPtDep", "(0.0105 + 0.0350/(x^1.1))", "Functional form of pt-dependent 7 sigma DCAxy cut"}; + Configurable cfgDCAz{"cfgDCAz", 2, "Cut on DCA in the longitudinal direction (cm)"}; + Configurable cfgNTPCCls{"cfgNTPCCls", 50, "Cut on number of TPC clusters found"}; + Configurable cfgNTPCXrows{"cfgNTPCXrows", 70, "Cut on number of TPC crossed rows"}; + Configurable cfgMinNITSCls{"cfgMinNITSCls", 5, "Cut on minimum number of ITS clusters found"}; + Configurable cfgChi2PrITSCls{"cfgChi2PrITSCls", 36, "Cut on chi^2 per ITS clusters found"}; + Configurable cfgChi2PrTPCCls{"cfgChi2PrTPCCls", 2.5, "Cut on chi^2 per TPC clusters found"}; } cuts; struct : ConfigurableGroup { @@ -157,6 +166,8 @@ struct EnergyFlowGfw { ConfigurableAxis axisCentrality{"axisCentrality", {VARIABLE_WIDTH, 0., 5., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100.1}, "centrality"}; ConfigurableAxis axisNGlobalTracks{"axisNGlobalTracks", {500, 0., 5000.}, "number of filtered global tracks"}; ConfigurableAxis axisPt{"axisPt", {100, 0., 5.}, "pT (GeV/c)"}; + ConfigurableAxis axisPhi{"axisPhi", {72, -o2::constants::math::PIHalf, 3 * o2::constants::math::PIHalf}, "#varphi (rad)"}; + ConfigurableAxis axisEta{"axisEta", {100, -1., 1.}, "#eta"}; ConfigurableAxis axisEnergy{"axisEnergy", {200, 0., 20.}, "transverse-energy weight (GeV)"}; ConfigurableAxis axisTotalSpectators{"axisTotalSpectators", {500, 0., 500.}, "total spectator count"}; ConfigurableAxis axisSpectatorActivity{"axisSpectatorActivity", {500, 0., 500.}, "spectator count used by the FlowContainer"}; @@ -170,16 +181,16 @@ struct EnergyFlowGfw { Filter collisionFilter = nabs(aod::collision::posZ) < cuts.vertexZ; Filter trackFilter = (nabs(aod::track::eta) < cuts.etaMax) && (aod::track::pt > cuts.ptCuts->first) && (aod::track::pt < cuts.ptCuts->second) && - ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast(true))); + ((requireGlobalTrackInFilter()) || (aod::track::isGlobalTrackSDD == static_cast(true))) && (aod::track::itsChi2NCl < cuts.cfgChi2PrITSCls) && (aod::track::tpcChi2NCl < cuts.cfgChi2PrTPCCls) && nabs(aod::track::dcaZ) < cuts.cfgDCAz; using CollisionsRun2 = soa::Filtered>; using CollisionsRun2MC = soa::Join; using CollisionsRun3 = soa::Filtered>; using CollisionsRun3MC = soa::Join; - using Tracks = soa::Filtered>; - using TracksMC = soa::Filtered>; @@ -190,6 +201,9 @@ struct EnergyFlowGfw { OutputObj flowContainer{"FlowContainer"}; OutputObj acceptanceWeights{GFWWeights("weights")}; + OutputObj runByRunAcceptanceWeightsOutput{"RunByRunAcceptanceWeights", OutputObjHandlingPolicy::AnalysisObject}; + std::map runByRunAcceptanceWeights; + GFWWeights* currentRunWeights = nullptr; HistogramRegistry registry{"registry"}; Service ccdb{}; Service pdgDB{}; @@ -206,6 +220,8 @@ struct EnergyFlowGfw { GFWWeights* acceptance = nullptr; int acceptanceRunNumber = -1; + TF1* fPtDepDCAxy = nullptr; + void init(InitContext const&) { const int enabledProcesses = static_cast(doprocessRun2) + static_cast(doprocessRun2MC) + static_cast(doprocessRun3) + static_cast(doprocessRun3MC); @@ -234,6 +250,11 @@ struct EnergyFlowGfw { LOGF(warning, "cfgMaxCentrality is %.1f (> 100); dummy centrality values will be accepted. Use the Nch or spectator activity axis when calibrated centrality is unavailable", cfgMaxCentrality.value); } + // List for run-by-run NUA + auto* outputList = new TList(); + outputList->SetOwner(true); + runByRunAcceptanceWeightsOutput.setObject(outputList); + const int numberOfRegions = cfgRegions->GetSize(); if (numberOfRegions <= 0 || cfgCorrConfig->GetSize() <= 0) { LOGF(fatal, "GFW regions and correlations must be non-empty and internally consistent"); @@ -300,13 +321,12 @@ struct EnergyFlowGfw { acceptanceWeights->init(true, false); } - const AxisSpec etaAxis{32, -cuts.etaMax.value, cuts.etaMax.value, "#eta"}; registry.add("event/centrality", "Accepted events;centrality;events", HistType::kTH1F, {axisCentrality}); registry.add("event/activity", "Accepted events;event activity;events", HistType::kTH1F, {activityAxis}); registry.add("event/vertex", "Accepted events;z-vtx (cm);events", HistType::kTH1F, {axisVertex}); registry.add("event/aodSelection", "AOD event selection;selection;events", HistType::kTH1F, {{5, -0.5, 4.5}}); registry.add("event/totalSpectators", "ZDC spectator estimate;N_{spectators};events", HistType::kTH1F, {axisTotalSpectators}); - registry.add("track/ptEta", "Selected tracks;p_{T} (GeV/c);#eta", HistType::kTH2F, {axisPt, etaAxis}); + registry.add("track/ptEta", "Selected tracks;p_{T} (GeV/c);#eta", HistType::kTH2F, {axisPt, axisEta}); registry.add("track/energy", "Energy entering the GFW;E_{T} (GeV);tracks", HistType::kTH1F, {axisEnergy}); registry.add("track/pid", "PID mass assignment;species;tracks", HistType::kTH1F, {{4, -0.5, 3.5}}); @@ -642,6 +662,15 @@ struct EnergyFlowGfw { return true; } + template + bool trackSelected(const TTrack& track) + { + if (cuts.cfgDCAxyNSigma && (std::fabs(track.dcaXY()) > fPtDepDCAxy->Eval(track.pt()))) { + return false; + } + return ((track.tpcNClsCrossedRows() >= cuts.cfgNTPCXrows) && (track.tpcNClsFound() >= cuts.cfgNTPCCls) && (track.itsNCls() >= cuts.cfgMinNITSCls)); + } + void loadEfficiency(uint64_t timestamp) { if (efficiencyLoaded) { @@ -833,10 +862,33 @@ struct EnergyFlowGfw { } } + GFWWeights* getOrCreateRunNUA(int run) + { + const auto found = runByRunAcceptanceWeights.find(run); + if (found != runByRunAcceptanceWeights.end()) { + return found->second; + } + + auto* weights = new GFWWeights(Form("weights_%d", run)); + weights->init(true, false); + + runByRunAcceptanceWeightsOutput->Add(weights); + runByRunAcceptanceWeights.emplace(run, weights); + + return weights; + } + template - void fillAcceptanceWeights(TCollision const& collision, TTracks const& tracks, float centrality) + void fillAcceptanceWeights(TCollision const& collision, TTracks const& tracks, float centrality, int run) { + if (acceptanceRunByRun && run != acceptanceRunNumber) { + currentRunWeights = getOrCreateRunNUA(run); + acceptanceRunNumber = run; + } for (const auto& track : tracks) { + if (acceptanceRunByRun) { + currentRunWeights->fill(track.phi(), track.eta(), collision.posZ(), track.pt(), centrality, 0); + } acceptanceWeights->fill(track.phi(), track.eta(), collision.posZ(), track.pt(), centrality, 0); } } @@ -856,6 +908,8 @@ struct EnergyFlowGfw { gfw->Clear(); for (const auto& track : tracks) { + if (!trackSelected(track)) + continue; const bool needsParticleId = energy.weightMode.value != PtWeight || cfgEfficiency.cfgUsePIDEfficiencies; const int pid = needsParticleId ? particleId(track) : Unidentified; const double et = transverseEnergy(track, pid); @@ -912,11 +966,11 @@ struct EnergyFlowGfw { if (!eventSelected(collision, run2EventSelected(collision), static_cast(tracks.size()), collision.centRun2V0M(), spectators)) { return; } + const auto& bc = collision.foundBC_as(); if (cfgFillAcceptance) { - fillAcceptanceWeights(collision, tracks, collision.centRun2V0M()); + fillAcceptanceWeights(collision, tracks, collision.centRun2V0M(), bc.runNumber()); return; } - const auto& bc = collision.foundBC_as(); loadEfficiency(bc.timestamp()); loadAcceptance(bc.timestamp(), bc.runNumber()); processCollision(collision, tracks, collision.centRun2V0M(), spectators); @@ -949,15 +1003,14 @@ struct EnergyFlowGfw { fillTrackingEfficiency(mcCollision.globalIndex(), mcParticles, groupedTracks, collision.centRun2V0M()); filledCorrections = true; } + const auto& bc = collision.foundBC_as(); if (cfgFillAcceptance) { - fillAcceptanceWeights(collision, groupedTracks, collision.centRun2V0M()); + fillAcceptanceWeights(collision, groupedTracks, collision.centRun2V0M(), bc.runNumber()); filledCorrections = true; } if (filledCorrections) { return; } - - const auto& bc = collision.foundBC_as(); loadEfficiency(bc.timestamp()); loadAcceptance(bc.timestamp(), bc.runNumber()); processCollision(collision, groupedTracks, collision.centRun2V0M(), spectators); @@ -972,11 +1025,11 @@ struct EnergyFlowGfw { if (!eventSelected(collision, collision.sel8(), static_cast(tracks.size()), collision.centFT0C(), spectators)) { return; } + const auto& bc = collision.foundBC_as(); if (cfgFillAcceptance) { - fillAcceptanceWeights(collision, tracks, collision.centFT0C()); + fillAcceptanceWeights(collision, tracks, collision.centFT0C(), bc.runNumber()); return; } - const auto& bc = collision.foundBC_as(); loadEfficiency(bc.timestamp()); loadAcceptance(bc.timestamp(), bc.runNumber()); processCollision(collision, tracks, collision.centFT0C(), spectators); @@ -1009,15 +1062,15 @@ struct EnergyFlowGfw { fillTrackingEfficiency(mcCollision.globalIndex(), mcParticles, groupedTracks, collision.centFT0C()); filledCorrections = true; } + + const auto& bc = collision.foundBC_as(); if (cfgFillAcceptance) { - fillAcceptanceWeights(collision, groupedTracks, collision.centFT0C()); + fillAcceptanceWeights(collision, groupedTracks, collision.centFT0C(), bc.runNumber()); filledCorrections = true; } if (filledCorrections) { return; } - - const auto& bc = collision.foundBC_as(); loadEfficiency(bc.timestamp()); loadAcceptance(bc.timestamp(), bc.runNumber()); processCollision(collision, groupedTracks, collision.centFT0C(), spectators); diff --git a/PWGCF/GenericFramework/Tasks/flowGenericFramework.cxx b/PWGCF/GenericFramework/Tasks/flowGenericFramework.cxx index 6034cf19f88..18a54894777 100644 --- a/PWGCF/GenericFramework/Tasks/flowGenericFramework.cxx +++ b/PWGCF/GenericFramework/Tasks/flowGenericFramework.cxx @@ -128,6 +128,7 @@ struct FlowGenericFramework { O2_DEFINE_CONFIGURABLE(cfgFillQA, bool, false, "Fill QA histograms"); O2_DEFINE_CONFIGURABLE(cfgFillV0QA, bool, true, "Fill QA histograms for V0 reconstruction"); O2_DEFINE_CONFIGURABLE(cfgRejectXiFeeddown, bool, false, "Veto reconstructed MC Lambdas from charged or neutral Xi decays"); + O2_DEFINE_CONFIGURABLE(cfgFillFeeddownTransfer, bool, false, "Store raw truth-matched Lambda counts for reference and analysis selections in processMC"); O2_DEFINE_CONFIGURABLE(cfgFillRunByRunQA, bool, false, "Fill histograms on a run-by-run basis"); O2_DEFINE_CONFIGURABLE(cfgAnalyseChargedHadrons, bool, true, "Store radial-flow and fraction outputs for charged tracks, pions, kaons, and protons"); O2_DEFINE_CONFIGURABLE(cfgAnalyseK0Lambda, bool, true, "Store radial-flow and fraction outputs for K0 and Lambda candidates"); @@ -598,6 +599,9 @@ struct FlowGenericFramework { readMatrix(resonanceCuts->getData(), resoCutVals); readMatrix(resonanceSwitches->getData(), resoSwitchVals); printResoCuts(); + if (cfgFill.cfgFillFeeddownTransfer && !doprocessMC) { + LOGF(fatal, "cfgFillFeeddownTransfer requires processMC"); + } const auto& ptPtGaps = cfgPtPtGaps->getData(); @@ -682,6 +686,26 @@ struct FlowGenericFramework { } } } + + if (cfgFill.cfgFillFeeddownTransfer) { + // Union of the supplied Romain raw-spectrum edges and the analysis edges. + std::vector transferPtEdges{ + 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, + 2., 2.2, 2.4, 2.6, 2.8, 3., 3.2, 3.4, 3.6, 3.8, 4., 4.4, 4.8, 5.2, 5.6, 6., 6.5, 7., 8., 10., 12., 16.}; + transferPtEdges.insert(transferPtEdges.end(), gfwMemberCache.ptbinning.begin(), gfwMemberCache.ptbinning.end()); + std::sort(transferPtEdges.begin(), transferPtEdges.end()); + transferPtEdges.erase(std::unique(transferPtEdges.begin(), transferPtEdges.end()), transferPtEdges.end()); + const AxisSpec transferPtAxis{transferPtEdges, "#it{p}_{T}^{#Lambda, reco} (GeV/#it{c})"}; + const AxisSpec transferCentAxis{100, 0., 100., "Centrality (%)"}; + const AxisSpec transferChargeAxis{2, -0.5, 1.5, "0: Lambda, 1: AntiLambda"}; + const AxisSpec transferOriginAxis{6, -0.5, 5.5, "0: primary, 1/2: primary charged/neutral Xi, 3/4: secondary charged/neutral Xi, 5: other"}; + registry.add("FeeddownTransfer/referenceEvents", "Selected reconstructed reference events", HistType::kTH1D, {transferCentAxis}); + registry.add("FeeddownTransfer/analysisEvents", "Selected reconstructed analysis events", HistType::kTH1D, {transferCentAxis}); + registry.add("FeeddownTransfer/reference", "Reference selection; raw counts", HistType::kTHnSparseF, {transferPtAxis, transferCentAxis, transferChargeAxis, transferOriginAxis, axisFeeddownXiPt}); + registry.add("FeeddownTransfer/v0", "v0 and v00 selection; raw counts", HistType::kTHnSparseF, {transferPtAxis, transferCentAxis, transferChargeAxis, transferOriginAxis, axisFeeddownXiPt}); + registry.add("FeeddownTransfer/v02", "v02 selection; raw counts", HistType::kTHnSparseF, {transferPtAxis, transferCentAxis, transferChargeAxis, transferOriginAxis, axisFeeddownXiPt}); + } + if (doprocessEfficiency) { registry.add("Efficiency/efficiencyHist", "; #it{p}_{T}^{MC}; Centrality (%)", {HistType::kTHnSparseF, {{ptAxis, centAxis, efficiencyParticleAxis, efficiencyStepAxis}}}); registry.add("Efficiency/v0RecoDebug", "; #it{p}_{T}; Centrality (%)", {HistType::kTHnSparseF, {{ptAxis, centAxis, efficiencyParticleAxis, v0EfficiencyStageAxis}}}); @@ -2285,6 +2309,12 @@ struct FlowGenericFramework { } } + if constexpr (requires { tracks.begin().has_mcParticle(); }) { + if (cfgFill.cfgFillFeeddownTransfer) { + registry.fill(HIST("FeeddownTransfer/analysisEvents"), centrality); + } + } + // Process V0s only for reconstructed-track workflows. if constexpr (dt != Gen) { for (const auto& v0 : v0s) { @@ -2451,6 +2481,11 @@ struct FlowGenericFramework { using V0TrackTable = std::decay_t; auto postrack = v0.template posTrack_as(); auto negtrack = v0.template negTrack_as(); + if constexpr (requires { postrack.has_mcParticle(); }) { + if (cfgFill.cfgFillFeeddownTransfer) { + fillLambdaFeeddownTransfer(v0, collision, tracks, centrality, false); + } + } if (resoSwitchVals[UseParticle][K0] != 0) { double weff = 1; @@ -3152,6 +3187,23 @@ struct FlowGenericFramework { void processMC(soa::Filtered::iterator const& mcCollision, soa::SmallGroups> const& collisions, aod::McParticles const& particles, aod::BCsWithTimestamps const&, GFWMCTracks const& tracks, aod::V0Datas const& v0s) { + // Reference events are counted before the analysis one-to-one MC matching requirement. + if (cfgFill.cfgFillFeeddownTransfer) { + for (const auto& collision : collisions) { + const float cent = getCentrality(collision); + if (!collision.sel8() || std::abs(collision.posZ()) >= 10.f || cent < 0.f || cent >= 100.f || + !collision.selection_bit(aod::evsel::kIsGoodZvtxFT0vsPV) || + !collision.selection_bit(aod::evsel::kNoSameBunchPileup) || + collision.multNTracksPVeta1() < 1) { + continue; + } + registry.fill(HIST("FeeddownTransfer/referenceEvents"), cent); + const auto referenceV0s = v0s.sliceBy(mcV0sPerCollision, collision.globalIndex()); + for (const auto& v0 : referenceV0s) { + fillLambdaFeeddownTransfer(v0, collision, tracks, cent, true); + } + } + } if (collisions.size() != 1) { return; } @@ -3510,6 +3562,97 @@ struct FlowGenericFramework { return std::nullopt; } + template + void fillLambdaFeeddownTransfer(const TV0& v0, const TCollision& collision, const TTracks& tracks, float centrality, bool reference) + { + using V0TrackTable = std::decay_t; + const auto pos = v0.template posTrack_as(); + const auto neg = v0.template negTrack_as(); + if (!pos.has_mcParticle() || !neg.has_mcParticle()) { + return; + } + const auto posMC = pos.template mcParticle_as(); + const auto negMC = neg.template mcParticle_as(); + if (!posMC.has_mothers() || !negMC.has_mothers()) { + return; + } + for (const auto& mother : posMC.template mothers_as()) { + if (std::abs(mother.pdgCode()) != PDG_t::kLambda0) { + continue; + } + for (const auto& negMother : negMC.template mothers_as()) { + if (mother.globalIndex() != negMother.globalIndex()) { + continue; + } + const bool isLambda = mother.pdgCode() > 0; + if (posMC.pdgCode() != (isLambda ? kProton : kPiPlus) || + negMC.pdgCode() != (isLambda ? -kPiPlus : -kProton)) { + return; + } + bool acceptedV0 = false; + bool acceptedV02 = false; + if (reference) { + // Reference cuts from Table 1 and Sec. III of the 2026-10-16 spectra note. + if (!v0.isStandardV0() || v0.pt() <= 0.4f || v0.pt() >= 16.f || + std::abs(v0.yLambda()) >= 0.5f || + std::abs(pos.eta()) >= 0.8f || std::abs(neg.eta()) >= 0.8f || + pos.tpcNClsCrossedRows() <= 70 || neg.tpcNClsCrossedRows() <= 70 || + v0.v0radius() <= 1.2f || v0.v0cosPA() <= 0.995f || + std::abs(v0.dcaV0daughters()) >= 1.f || + v0.distovertotmom(collision.posX(), collision.posY(), collision.posZ()) * massLambda >= 30. || + std::abs(v0.mK0Short() - o2::constants::physics::MassK0Short) <= 0.010f) { + return; + } + const auto& proton = isLambda ? pos : neg; + const auto& pion = isLambda ? neg : pos; + if (std::abs(proton.tpcNSigmaPr()) >= 4.f || std::abs(pion.tpcNSigmaPi()) >= 4.f || + std::abs(isLambda ? v0.dcapostopv() : v0.dcanegtopv()) <= 0.05f || + std::abs(isLambda ? v0.dcanegtopv() : v0.dcapostopv()) <= 0.2f) { + return; + } + } else { + // Evaluate the configured analysis cuts without incrementing nominal QA. + const auto selection = selectLambda(collision, v0, tracks, false); + const double mass = isLambda ? v0.mLambda() : v0.mAntiLambda(); + if (!selection.selected || selection.isL != isLambda || + mass <= cfgPIDCuts.cfgLambdaSignalMin || mass >= cfgPIDCuts.cfgLambdaSignalMax) { + return; + } + acceptedV0 = pos.eta() >= cfgKinematics.cfgEtaNptV0->first && pos.eta() <= cfgKinematics.cfgEtaNptV0->second && + neg.eta() >= cfgKinematics.cfgEtaNptV0->first && neg.eta() <= cfgKinematics.cfgEtaNptV0->second; + acceptedV02 = pos.eta() >= cfgKinematics.cfgEtaNptV02->first && pos.eta() <= cfgKinematics.cfgEtaNptV02->second && + neg.eta() >= cfgKinematics.cfgEtaNptV02->first && neg.eta() <= cfgKinematics.cfgEtaNptV02->second; + if (!acceptedV0 && !acceptedV02) { + return; + } + } + const auto xi = findLambdaXiParent(pos, neg, false); + int origin = mother.isPhysicalPrimary() ? 0 : 5; + double xiPt = 0.; + if (xi) { + origin = std::abs(xi->pdgCode()) == PDG_t::kXiMinus ? 1 : 2; + if (!xi->isPhysicalPrimary()) { + origin += 2; + } + xiPt = xi->pt(); + } + const int charge = isLambda ? 0 : 1; + // Unit weights. Counts precede the Xi veto and efficiency corrections. + if (reference) { + registry.fill(HIST("FeeddownTransfer/reference"), v0.pt(), centrality, charge, origin, xiPt); + } else { + if (acceptedV0) { + registry.fill(HIST("FeeddownTransfer/v0"), v0.pt(), centrality, charge, origin, xiPt); + } + if (acceptedV02) { + registry.fill(HIST("FeeddownTransfer/v02"), v0.pt(), centrality, charge, origin, xiPt); + } + } + return; + } + } + } + template void fillLambdaFeeddownReco(const TV0& v0, const TCollision& collision, const TTracks& tracks, float centrality) {