From 7294da21f31b8df24b437813f2c8d3ba3b0fb3e7 Mon Sep 17 00:00:00 2001 From: Shingo Sakai Date: Wed, 18 Nov 2026 20:43:59 +0900 Subject: [PATCH] PWGHF: add derived data support to taskElectronWeakBoson --- PWGHF/HFL/DataModel/ElectronWeakBosonTables.h | 191 ++++++++ PWGHF/HFL/TableProducer/CMakeLists.txt | 5 + .../derivedDataCreatorElectronWeakBoson.cxx | 432 ++++++++++++++++ PWGHF/HFL/Tasks/taskElectronWeakBoson.cxx | 461 ++++++++++++++---- 4 files changed, 987 insertions(+), 102 deletions(-) create mode 100644 PWGHF/HFL/DataModel/ElectronWeakBosonTables.h create mode 100644 PWGHF/HFL/TableProducer/derivedDataCreatorElectronWeakBoson.cxx diff --git a/PWGHF/HFL/DataModel/ElectronWeakBosonTables.h b/PWGHF/HFL/DataModel/ElectronWeakBosonTables.h new file mode 100644 index 00000000000..a719a789156 --- /dev/null +++ b/PWGHF/HFL/DataModel/ElectronWeakBosonTables.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. + +/// \file ElectronWeakBosonTables.h +/// \brief Derived-data tables for the W/Z -> e (+ hadron) analysis (taskElectronWeakBoson) +/// +/// Three tables: +/// - HfWbColls : one row per stored (triggered, skimmed) collision +/// - HfWbTracks : charged tracks of that collision (associated hadrons + every electron-candidate track) +/// - HfWbElectrons : high-pT tracks only, with what the electron / Z reconstruction needs on top of HfWbTracks: +/// track parameters + covariance (KFParticle), track isolation sums, +/// closest EMCal cluster and the cluster-isolation sum. +/// +/// The getter names deliberately follow the AO2D ones (centFT0M(), multNTracksPV(), isGlobalTrackWoPtEta(), +/// tpcNClsCrossedRows(), x(), alpha(), cYY(), ...) so that the helpers already used on AO2D +/// (o2::hf_centrality::getCentralityColl, getTrackParCov, isSelectedTrackKine of the task) work unchanged. +/// +/// \author S. Sakai & S. Ito (Univ. of Tsukuba) + +#ifndef PWGHF_HFL_DATAMODEL_ELECTRONWEAKBOSONTABLES_H_ +#define PWGHF_HFL_DATAMODEL_ELECTRONWEAKBOSONTABLES_H_ + +#include +#include + +#include +#include + +namespace o2::aod +{ +// --------------------------------------------------------------------------- +// Collisions +// --------------------------------------------------------------------------- +namespace hf_wb_coll +{ +DECLARE_SOA_COLUMN(PosZ, posZ, float); //! primary-vertex z (cm) +DECLARE_SOA_COLUMN(Sel8, sel8, bool); //! sel8 decision (stored, not applied at production) +DECLARE_SOA_COLUMN(CentFT0A, centFT0A, float); //! FT0A centrality percentile +DECLARE_SOA_COLUMN(CentFT0C, centFT0C, float); //! FT0C centrality percentile +DECLARE_SOA_COLUMN(CentFT0M, centFT0M, float); //! FT0M centrality percentile +DECLARE_SOA_COLUMN(CentFV0A, centFV0A, float); //! FV0A centrality percentile +DECLARE_SOA_COLUMN(MultFT0M, multFT0M, float); //! FT0M raw multiplicity +DECLARE_SOA_COLUMN(MultNTracksPV, multNTracksPV, int); //! number of PV contributors +DECLARE_SOA_COLUMN(RunNumber, runNumber, int); //! run number +DECLARE_SOA_COLUMN(MagField, magField, float); //! nominal Bz (kG), for KFParticle::SetField +DECLARE_SOA_COLUMN(RhoUE, rhoUE, float); //! UE density from random cones (GeV / unit area) +} // namespace hf_wb_coll + +DECLARE_SOA_TABLE(HfWbColls, "AOD", "HFWBCOLL", //! collisions for the W/Z -> e analysis + o2::soa::Index<>, + hf_wb_coll::PosZ, + hf_wb_coll::Sel8, + hf_wb_coll::CentFT0A, + hf_wb_coll::CentFT0C, + hf_wb_coll::CentFT0M, + hf_wb_coll::CentFV0A, + hf_wb_coll::MultFT0M, + hf_wb_coll::MultNTracksPV, + hf_wb_coll::RunNumber, + hf_wb_coll::MagField, + hf_wb_coll::RhoUE); +using HfWbColl = HfWbColls::iterator; + +// --------------------------------------------------------------------------- +// Tracks +// --------------------------------------------------------------------------- +namespace hf_wb_track +{ +DECLARE_SOA_INDEX_COLUMN(HfWbColl, hfWbColl); //! derived collision +DECLARE_SOA_COLUMN(Pt, pt, float); //! pT (GeV/c) +DECLARE_SOA_COLUMN(Eta, eta, float); //! pseudorapidity +DECLARE_SOA_COLUMN(Phi, phi, float); //! azimuth (0..2pi) +DECLARE_SOA_COLUMN(Sign, sign, int8_t); //! charge sign +DECLARE_SOA_COLUMN(DcaXY, dcaXY, float); //! DCA xy (cm) +DECLARE_SOA_COLUMN(DcaZ, dcaZ, float); //! DCA z (cm) +DECLARE_SOA_COLUMN(TpcNClsFound, tpcNClsFound, int16_t); //! TPC found clusters +DECLARE_SOA_COLUMN(TpcNClsCrossedRows, tpcNClsCrossedRows, int16_t); //! TPC crossed rows +DECLARE_SOA_COLUMN(ItsNCls, itsNCls, uint8_t); //! ITS clusters +DECLARE_SOA_COLUMN(TpcChi2NCl, tpcChi2NCl, float); //! TPC chi2 / cluster +DECLARE_SOA_COLUMN(ItsChi2NCl, itsChi2NCl, float); //! ITS chi2 / cluster +DECLARE_SOA_COLUMN(TpcNSigmaEl, tpcNSigmaEl, float); //! TPC n sigma electron +DECLARE_SOA_COLUMN(TpcNSigmaPi, tpcNSigmaPi, float); //! TPC n sigma pion +DECLARE_SOA_COLUMN(IsGlobalTrackWoPtEta, isGlobalTrackWoPtEta, bool); //! global track without pT/eta cut +DECLARE_SOA_DYNAMIC_COLUMN(P, p, [](float pt, float eta) -> float { return pt * std::cosh(eta); }); //! momentum +} // namespace hf_wb_track + +DECLARE_SOA_TABLE(HfWbTracks, "AOD", "HFWBTRACK", //! tracks for the W/Z -> e analysis + o2::soa::Index<>, + hf_wb_track::HfWbCollId, + hf_wb_track::Pt, + hf_wb_track::Eta, + hf_wb_track::Phi, + hf_wb_track::Sign, + hf_wb_track::DcaXY, + hf_wb_track::DcaZ, + hf_wb_track::TpcNClsFound, + hf_wb_track::TpcNClsCrossedRows, + hf_wb_track::ItsNCls, + hf_wb_track::TpcChi2NCl, + hf_wb_track::ItsChi2NCl, + hf_wb_track::TpcNSigmaEl, + hf_wb_track::TpcNSigmaPi, + hf_wb_track::IsGlobalTrackWoPtEta, + hf_wb_track::P); +using HfWbTrack = HfWbTracks::iterator; + +// --------------------------------------------------------------------------- +// Electron candidates (high-pT tracks) +// --------------------------------------------------------------------------- +namespace hf_wb_ele +{ +DECLARE_SOA_INDEX_COLUMN(HfWbTrack, hfWbTrack); //! row in HfWbTracks (kinematics, PID, quality) + +// track parametrisation at the reference point (same getters as aod::TracksIU/TracksCov -> getTrackParCov works) +DECLARE_SOA_COLUMN(X, x, float); +DECLARE_SOA_COLUMN(Alpha, alpha, float); +DECLARE_SOA_COLUMN(Y, y, float); +DECLARE_SOA_COLUMN(Z, z, float); +DECLARE_SOA_COLUMN(Snp, snp, float); +DECLARE_SOA_COLUMN(Tgl, tgl, float); +DECLARE_SOA_COLUMN(Signed1Pt, signed1Pt, float); +DECLARE_SOA_COLUMN(CYY, cYY, float); +DECLARE_SOA_COLUMN(CZY, cZY, float); +DECLARE_SOA_COLUMN(CZZ, cZZ, float); +DECLARE_SOA_COLUMN(CSnpY, cSnpY, float); +DECLARE_SOA_COLUMN(CSnpZ, cSnpZ, float); +DECLARE_SOA_COLUMN(CSnpSnp, cSnpSnp, float); +DECLARE_SOA_COLUMN(CTglY, cTglY, float); +DECLARE_SOA_COLUMN(CTglZ, cTglZ, float); +DECLARE_SOA_COLUMN(CTglSnp, cTglSnp, float); +DECLARE_SOA_COLUMN(CTglTgl, cTglTgl, float); +DECLARE_SOA_COLUMN(C1PtY, c1PtY, float); +DECLARE_SOA_COLUMN(C1PtZ, c1PtZ, float); +DECLARE_SOA_COLUMN(C1PtSnp, c1PtSnp, float); +DECLARE_SOA_COLUMN(C1PtTgl, c1PtTgl, float); +DECLARE_SOA_COLUMN(C1Pt21Pt2, c1Pt21Pt2, float); + +// track isolation, summed over ALL tracks of the collision within rIsolation (production value), self included +DECLARE_SOA_COLUMN(PSumCone, pSumCone, float); //! sum of p in the cone (GeV/c) +DECLARE_SOA_COLUMN(NTrkCone, nTrkCone, int16_t); //! number of tracks in the cone + +// closest EMCal cluster among the matched clusters passing the production time window +// (no rMatchMax cut applied: the analysis cuts on dEta/dPhi) +DECLARE_SOA_COLUMN(HasEmcMatch, hasEmcMatch, bool); //! a cluster candidate exists +DECLARE_SOA_COLUMN(EmcDEta, emcDEta, float); //! eta(track at EMCal) - eta(cluster) +DECLARE_SOA_COLUMN(EmcDPhi, emcDPhi, float); //! phi(track at EMCal) - phi(cluster), in [-pi, pi) +DECLARE_SOA_COLUMN(EmcEnergy, emcEnergy, float); //! cluster energy (GeV) +DECLARE_SOA_COLUMN(EmcEta, emcEta, float); //! cluster eta +DECLARE_SOA_COLUMN(EmcPhi, emcPhi, float); //! cluster phi +DECLARE_SOA_COLUMN(EmcM02, emcM02, float); //! cluster M02 +DECLARE_SOA_COLUMN(EmcTime, emcTime, float); //! cluster time (ns) +DECLARE_SOA_COLUMN(EmcNCells, emcNCells, int16_t); //! cluster number of cells +DECLARE_SOA_COLUMN(EmcNMatchInR, emcNMatchInR, uint8_t); //! clusters within the production rMatchMax (QA) +DECLARE_SOA_COLUMN(EmcConeEnergy, emcConeEnergy, float); //! cluster energy in the cone, the cluster itself EXCLUDED, no UE subtraction +} // namespace hf_wb_ele + +DECLARE_SOA_TABLE(HfWbElectrons, "AOD", "HFWBELE", //! electron candidates for the W/Z -> e analysis + o2::soa::Index<>, + hf_wb_track::HfWbCollId, + hf_wb_ele::HfWbTrackId, + hf_wb_ele::X, hf_wb_ele::Alpha, + hf_wb_ele::Y, hf_wb_ele::Z, hf_wb_ele::Snp, hf_wb_ele::Tgl, hf_wb_ele::Signed1Pt, + hf_wb_ele::CYY, hf_wb_ele::CZY, hf_wb_ele::CZZ, + hf_wb_ele::CSnpY, hf_wb_ele::CSnpZ, hf_wb_ele::CSnpSnp, + hf_wb_ele::CTglY, hf_wb_ele::CTglZ, hf_wb_ele::CTglSnp, hf_wb_ele::CTglTgl, + hf_wb_ele::C1PtY, hf_wb_ele::C1PtZ, hf_wb_ele::C1PtSnp, hf_wb_ele::C1PtTgl, hf_wb_ele::C1Pt21Pt2, + hf_wb_ele::PSumCone, + hf_wb_ele::NTrkCone, + hf_wb_ele::HasEmcMatch, + hf_wb_ele::EmcDEta, + hf_wb_ele::EmcDPhi, + hf_wb_ele::EmcEnergy, + hf_wb_ele::EmcEta, + hf_wb_ele::EmcPhi, + hf_wb_ele::EmcM02, + hf_wb_ele::EmcTime, + hf_wb_ele::EmcNCells, + hf_wb_ele::EmcNMatchInR, + hf_wb_ele::EmcConeEnergy); +using HfWbElectron = HfWbElectrons::iterator; +} // namespace o2::aod + +#endif // PWGHF_HFL_DATAMODEL_ELECTRONWEAKBOSONTABLES_H_ diff --git a/PWGHF/HFL/TableProducer/CMakeLists.txt b/PWGHF/HFL/TableProducer/CMakeLists.txt index 69f571377c8..09d520fed2f 100644 --- a/PWGHF/HFL/TableProducer/CMakeLists.txt +++ b/PWGHF/HFL/TableProducer/CMakeLists.txt @@ -18,3 +18,8 @@ o2physics_add_dpl_workflow(tree-creator-electron-d-c-a SOURCES treeCreatorElectronDCA.cxx PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore COMPONENT_NAME Analysis) + +o2physics_add_dpl_workflow(derived-data-creator-electron-weak-boson + SOURCES derivedDataCreatorElectronWeakBoson.cxx + PUBLIC_LINK_LIBRARIES O2Physics::AnalysisCore O2Physics::EventFilteringUtils + COMPONENT_NAME Analysis) diff --git a/PWGHF/HFL/TableProducer/derivedDataCreatorElectronWeakBoson.cxx b/PWGHF/HFL/TableProducer/derivedDataCreatorElectronWeakBoson.cxx new file mode 100644 index 00000000000..3e8c29632a8 --- /dev/null +++ b/PWGHF/HFL/TableProducer/derivedDataCreatorElectronWeakBoson.cxx @@ -0,0 +1,432 @@ +// 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. + +/// \file derivedDataCreatorElectronWeakBoson.cxx +/// \brief Producer of the derived data read by taskElectronWeakBoson (processDerived) +/// +/// What is decided here and can NOT be changed afterwards on the derived data: +/// - Zorro trigger selection (cfgTriggerName) and |zvtx| < vtxZ +/// - event skim: at least one track with pT > ptSkimMin matched to an EMCal cluster within rMatchSkim, +/// and (skimRequireIsoElectron) passing the loose isolated-electron cuts eopSkim*, m02Skim*, nsigTpcSkim*, isoEnergySkimMax +/// - which tracks are stored: (global track w/o pT-eta, |eta| < etaTrMax, pT > ptAssMin) OR pT > ptEleStoreMin +/// - isolation cone radius rIsolation (track and cluster isolation sums) +/// - EMCal cluster definition and the time window used to pick the closest cluster +/// - random-cone UE density (rcHardE, nRandomCones) +/// Everything else (electron ID, E/p, M02, isolation thresholds, matching cut, Z mass window, KF chi2, +/// track-quality cuts of the associated hadrons, UE subtraction on/off) stays free in the analysis. +/// +/// The event normalisation (hEventCounter, zorroSummary) lives in the AnalysisResults.root of THIS task. +/// +/// \author S. Sakai & S. Ito (Univ. of Tsukuba) + +#include "PWGHF/HFL/DataModel/ElectronWeakBosonTables.h" +#include "PWGJE/DataModel/EMCALClusters.h" + +#include "Common/Core/RecoDecay.h" +#include "Common/Core/Zorro.h" +#include "Common/Core/ZorroSummary.h" +#include "Common/DataModel/Centrality.h" +#include "Common/DataModel/EventSelection.h" +#include "Common/DataModel/Multiplicity.h" +#include "Common/DataModel/PIDResponseTPC.h" +#include "Common/DataModel/TrackSelectionTables.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +using namespace o2; +using namespace o2::framework; +using namespace o2::framework::expressions; + +struct HfDerivedDataCreatorElectronWeakBoson { + Produces rowColl; + Produces rowTrack; + Produces rowEle; + + // event + Configurable vtxZ{"vtxZ", 10.f, "|zvtx| cut applied at production"}; + Configurable applySel8{"applySel8", false, "apply sel8 at production (it is stored anyway)"}; + Configurable cfgSkimmedProcessing{"cfgSkimmedProcessing", true, "select with Zorro (skimmed data)"}; + Configurable cfgTriggerName{"cfgTriggerName", "fGammaHighPtEMCAL", "Trigger of interest (comma separated for multiple)"}; + Configurable cfgCCDBPath{"cfgCCDBPath", "EventFiltering/Zorro/", "Path to CCDB for trigger data"}; + Configurable ccdbPathGrpMag{"ccdbPathGrpMag", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object (Run 3)"}; + + // event skim. Grouped: in the JSON these options sit in their own block, + // "derived-data-creator-electron-weak-boson": { ..., "skim": { "ptSkimMin": "10", ... } } + // The isolated-electron cuts must be LOOSER than (or equal to) the analysis ones, incl. every systematic variation. + struct : ConfigurableGroup { + std::string prefix = "skim"; // JSON group name + Configurable ptSkimMin{"ptSkimMin", 10.f, "keep the event only if a track above this pT is matched to EMCal"}; + Configurable rMatchSkim{"rMatchSkim", 0.05f, "|dEta|,|dPhi| matching window used by the skim"}; + Configurable skimRequireIsoElectron{"skimRequireIsoElectron", true, "require at least one isolated-electron candidate (cuts below)"}; + Configurable eopSkimMin{"eopSkimMin", 0.6f, "skim: min E/p"}; + Configurable eopSkimMax{"eopSkimMax", 999.f, "skim: max E/p"}; + Configurable m02SkimMin{"m02SkimMin", 0.1f, "skim: min M02"}; + Configurable m02SkimMax{"m02SkimMax", 0.9f, "skim: max M02"}; + Configurable isoEnergySkimMax{"isoEnergySkimMax", 0.2f, "skim: max cluster isolation (E_cone - E_UE)/E"}; + Configurable useUEsubSkim{"useUEsubSkim", true, "skim: subtract the random-cone UE in the isolation (true is the looser choice)"}; + Configurable nsigTpcSkimMin{"nsigTpcSkimMin", -999.f, "skim: min TPC n sigma electron (-999 = no cut)"}; + Configurable nsigTpcSkimMax{"nsigTpcSkimMax", 999.f, "skim: max TPC n sigma electron (999 = no cut)"}; + } skimCfg; + + // what is stored + Configurable etaTrMax{"etaTrMax", 1.0f, "|eta| of the stored associated tracks"}; + Configurable ptAssMin{"ptAssMin", 0.15f, "min pT of the stored associated tracks"}; + Configurable ptEleStoreMin{"ptEleStoreMin", 3.0f, "every track above this pT gets an HfWbElectrons row (must be <= ptMin and ptZeeMin of the analysis)"}; + + // EMCal / isolation (fixed at production) + Configurable clusterDefinition{"clusterDefinition", 10, "cluster definition, e.g. 10=kV3Default"}; + Configurable timeEmcMin{"timeEmcMin", -25., "min EMC cluster time for the closest-cluster search"}; + Configurable timeEmcMax{"timeEmcMax", +20., "max EMC cluster time for the closest-cluster search"}; + Configurable rMatchQa{"rMatchQa", 0.05f, "window used for the stored emcNMatchInR (QA only)"}; + Configurable rIsolation{"rIsolation", 0.3, "cone radius for track and cluster isolation"}; + Configurable etaEmcMax{"etaEmcMax", 0.6f, "random cones: EMCal |eta|"}; + Configurable phiEmcMin{"phiEmcMin", 1.39, "random cones: EMCal phi min"}; + Configurable phiEmcMax{"phiEmcMax", 3.36, "random cones: EMCal phi max"}; + Configurable nRandomCones{"nRandomCones", 100, "number of random cones"}; + Configurable rcHardE{"rcHardE", 5.0, "hard cluster veto energy in the random cones"}; + + Service ccdb{}; + Zorro zorro; + TRandom3* rnd = nullptr; + int lastRunNumber = -1; + float magneticField = 0.f; + + using CollisionsWithCent = soa::Join; + using TrackEle = soa::Join; + using Clusters = o2::aod::EMCALClusters; + + // collision selection is cheap and identical to processData (posZ). sel8 is applied by hand. + Filter posZFilter = (nabs(o2::aod::collision::posZ) < vtxZ); + + PresliceUnsorted perTrackMatched = o2::aod::emcalmatchedtrack::trackId; + + HistogramRegistry registry{"registry"}; + OutputObj zorroSummary{"zorroSummary"}; + + struct HfEmcMatch { + bool has = false; + float dEta = 999.f, dPhi = 999.f, energy = -1.f, eta = 0.f, phi = 0.f, m02 = -1.f, time = 0.f, coneEnergy = 0.f; + int16_t nCells = 0; + uint8_t nMatchInR = 0; + }; + + void init(InitContext const&) + { + ccdb->setURL("http://alice-ccdb.cern.ch"); + ccdb->setCaching(true); + ccdb->setLocalObjectValidityChecking(); + zorro.setBaseCCDBPath(cfgCCDBPath.value); + if (cfgSkimmedProcessing) { + zorroSummary.setObject(zorro.getZorroSummary()); + } + rnd = new TRandom3(0); + + const AxisSpec axisCounter{1, 0, 1, "events"}; + const AxisSpec axisTrigger{3, -0.5, 2.5, "Trigger status of zorro"}; + const AxisSpec axisZvtx{40, -20, 20, "Zvtx"}; + const AxisSpec axisCent{101, 0, 101, "FT0M percentile"}; + const AxisSpec axisMultPV{200, 0, 200, "N_{PV contrib}"}; + const AxisSpec axisRho{100, 0, 10, "#rho_{UE}"}; + const AxisSpec axisNEle{20, -0.5, 19.5, "N rows"}; + const AxisSpec axisNTrk{200, -0.5, 199.5, "N rows"}; + registry.add("hEventCounterInit", "collisions after |zvtx| (before Zorro)", kTH1D, {axisCounter}); + registry.add("hEMCalTrigger", "EMCal trigger", kTH1D, {axisTrigger}); + registry.add("hEventCounter", "collisions after Zorro (normalisation)", kTH1D, {axisCounter}); + registry.add("hEventStored", "collisions written to the derived data", kTH1D, {axisCounter}); + const AxisSpec axisSkim{3, -0.5, 2.5, "skim step"}; + registry.add("hSkimCutflow", "0: after Zorro, 1: EMCal-matched track > ptSkimMin, 2: + isolated electron", kTH1D, {axisSkim}); + registry.add("hZvtx", "Z vertex (after Zorro)", kTH1D, {axisZvtx}); + registry.add("hCentFT0M", "FT0M percentile (after Zorro)", kTH1D, {axisCent}); + registry.add("hMultPV", "PV contributors (after Zorro)", kTH1D, {axisMultPV}); + registry.add("hRho", "UE density", kTH1D, {axisRho}); + registry.add("hNTracksStored", "stored HfWbTracks rows per event", kTH1D, {axisNTrk}); + registry.add("hNElectronsStored", "stored HfWbElectrons rows per event", kTH1D, {axisNEle}); + } + + void initRun(aod::BCsWithTimestamps::iterator const& bc) + { + const int runNumber = bc.runNumber(); + if (runNumber == lastRunNumber) { + return; + } + const uint64_t timestamp = bc.timestamp(); + if (cfgSkimmedProcessing) { + LOGF(info, "Initializing Zorro for run %d", runNumber); + zorro.initCCDB(ccdb.service, runNumber, timestamp, cfgTriggerName); + } + // magnetic field: needed by the analysis for KFParticle, independent of Zorro + auto* grpo = ccdb->getForTimeStamp(ccdbPathGrpMag, timestamp); + o2::base::Propagator::initFieldFromGRP(grpo); + magneticField = static_cast(o2::base::Propagator::Instance()->getNominalBz()); + LOG(info) << "run " << runNumber << " : magneticField = " << magneticField; + lastRunNumber = runNumber; + } + + float estimateRhoRC(Clusters const& clusters) + { + const float area = o2::constants::math::PI * rIsolation * rIsolation; + std::vector sumErc; + sumErc.reserve(nRandomCones); + for (int i = 0; i < nRandomCones; i++) { + const float etarc = rnd->Uniform(-etaEmcMax, etaEmcMax); + const float phirc = rnd->Uniform(phiEmcMin, phiEmcMax); + float sum = 0.f; + for (const auto& c : clusters) { + if (c.definition() != clusterDefinition || c.energy() > rcHardE) { + continue; + } + const double dEta = etarc - c.eta(); + const double dPhi = RecoDecay::constrainAngle(phirc - c.phi(), -o2::constants::math::PI); + if (std::sqrt(dEta * dEta + dPhi * dPhi) < rIsolation) { + sum += c.energy(); + } + } + sumErc.push_back(sum); + } + if (sumErc.empty()) { + return 0.f; + } + std::nth_element(sumErc.begin(), sumErc.begin() + sumErc.size() / 2, sumErc.end()); + return sumErc[sumErc.size() / 2] / area; + } + + // energy of the clusters in the cone around the given cluster, the cluster itself excluded + float coneEnergyExcl(float eta, float phi, float energy, Clusters const& clusters) + { + double sum = 0.; + for (const auto& c : clusters) { + if (c.definition() != clusterDefinition) { + continue; + } + const double dEta = c.eta() - eta; + const double dPhi = RecoDecay::constrainAngle(c.phi() - phi, -o2::constants::math::PI); + if (std::sqrt(dEta * dEta + dPhi * dPhi) < rIsolation) { + sum += c.energy(); + } + } + return static_cast(sum - energy); + } + + template + HfEmcMatch findClosestCluster(TMatches const& matches, Clusters const& clusters) + { + HfEmcMatch res; + double rMin = 1.e9; + for (const auto& match : matches) { + const auto& cluster = match.template emcalcluster_as(); + if (cluster.definition() != clusterDefinition) { + continue; + } + if (cluster.time() < timeEmcMin || cluster.time() > timeEmcMax) { + continue; + } + const auto& trk = match.template track_as(); + const double dEta = trk.trackEtaEmcal() - cluster.eta(); + const double dPhi = RecoDecay::constrainAngle(trk.trackPhiEmcal() - cluster.phi(), -o2::constants::math::PI); + if (std::abs(dPhi) <= rMatchQa && std::abs(dEta) <= rMatchQa && res.nMatchInR < UINT8_MAX) { + res.nMatchInR++; + } + const double r = std::sqrt(dEta * dEta + dPhi * dPhi); + if (r < rMin) { + rMin = r; + res.has = true; + res.dEta = dEta; + res.dPhi = dPhi; + res.energy = cluster.energy(); + res.eta = cluster.eta(); + res.phi = cluster.phi(); + res.m02 = cluster.m02(); + res.time = cluster.time(); + res.nCells = static_cast(cluster.nCells()); + } + } + if (res.has) { + res.coneEnergy = coneEnergyExcl(res.eta, res.phi, res.energy, clusters); + } + return res; + } + + // isolated-electron candidate used by the skim. Same definitions as in the analysis: + // E/p with the closest cluster, M02, TPC n sigma, cluster isolation (E_cone,excl - E_UE) / E. + template + bool isIsolatedElectronSkim(TTrack const& track, HfEmcMatch const& emc, float energyUE) + { + if (emc.energy <= 0.f) { + return false; + } + const float eop = emc.energy / track.p(); + if (eop < skimCfg.eopSkimMin || eop > skimCfg.eopSkimMax) { + return false; + } + if (emc.m02 < skimCfg.m02SkimMin || emc.m02 > skimCfg.m02SkimMax) { + return false; + } + if (track.tpcNSigmaEl() < skimCfg.nsigTpcSkimMin || track.tpcNSigmaEl() > skimCfg.nsigTpcSkimMax) { + return false; + } + const float isoEnergy = (emc.coneEnergy - energyUE) / emc.energy; + return isoEnergy < skimCfg.isoEnergySkimMax; + } + + void processData(soa::Filtered::iterator const& collision, + aod::BCsWithTimestamps const&, + Clusters const& clusters, + TrackEle const& tracks, + o2::aod::EMCALMatchedTracks const& matchedTracks) + { + registry.fill(HIST("hEventCounterInit"), 0.5); + auto bc = collision.bc_as(); + initRun(bc); + + if (cfgSkimmedProcessing) { + const bool isTriggered = zorro.isSelected(bc.globalBC()); + registry.fill(HIST("hEMCalTrigger"), isTriggered ? 1 : 0); + if (!isTriggered) { + return; + } + } + if (applySel8 && !collision.sel8()) { + return; + } + // normalisation of the derived sample: every event that the analysis WOULD have seen on AO2D + registry.fill(HIST("hEventCounter"), 0.5); + registry.fill(HIST("hZvtx"), collision.posZ()); + registry.fill(HIST("hCentFT0M"), collision.centFT0M()); + registry.fill(HIST("hMultPV"), collision.multNTracksPV()); + + // ---- pass 1 : electron candidates (needs the EMCal matching for the skim decision) + struct HfEleCand { + int64_t trackGlobalIndex; + float pSum; + int16_t nTrk; + HfEmcMatch emc; + }; + std::vector eleCands; + bool hasMatchedTrack = false; // skim step 1 + bool hasIsoElectron = false; // skim step 2 + + // UE density: needed for the isolation in the skim, and stored for the analysis + const float rho = estimateRhoRC(clusters); + const float energyUESkim = skimCfg.useUEsubSkim ? rho * static_cast(o2::constants::math::PI * rIsolation * rIsolation) : 0.f; + registry.fill(HIST("hSkimCutflow"), 0); + + for (const auto& track : tracks) { + if (track.pt() < ptEleStoreMin) { + continue; + } + // track isolation: over ALL tracks of the collision, as getIsolatedTrack() in the task + double pSum = 0.; + int nTrk = 0; + for (const auto& other : tracks) { + const double dEta = other.eta() - track.eta(); + const double dPhi = RecoDecay::constrainAngle(other.phi() - track.phi(), -o2::constants::math::PI); + if (std::sqrt(dEta * dEta + dPhi * dPhi) < rIsolation) { + ++nTrk; + pSum += other.p(); + } + } + HfEleCand cand{track.globalIndex(), static_cast(pSum), static_cast(nTrk), HfEmcMatch{}}; + auto matches = matchedTracks.sliceBy(perTrackMatched, track.globalIndex()); + if (matches.size() != 0) { + cand.emc = findClosestCluster(matches, clusters); + } + if (cand.emc.has && track.pt() > skimCfg.ptSkimMin && std::abs(cand.emc.dEta) <= skimCfg.rMatchSkim && std::abs(cand.emc.dPhi) <= skimCfg.rMatchSkim) { + hasMatchedTrack = true; + if (isIsolatedElectronSkim(track, cand.emc, energyUESkim)) { + hasIsoElectron = true; + } + } + eleCands.push_back(cand); + } + if (!hasMatchedTrack) { + return; + } + registry.fill(HIST("hSkimCutflow"), 1); + if (skimCfg.skimRequireIsoElectron && !hasIsoElectron) { + return; + } + if (hasIsoElectron) { + registry.fill(HIST("hSkimCutflow"), 2); + } + + // ---- write the collision + registry.fill(HIST("hRho"), rho); + rowColl(collision.posZ(), collision.sel8(), + collision.centFT0A(), collision.centFT0C(), collision.centFT0M(), collision.centFV0A(), + collision.multFT0M(), collision.multNTracksPV(), + bc.runNumber(), magneticField, rho); + const auto collIdx = rowColl.lastIndex(); + registry.fill(HIST("hEventStored"), 0.5); + + // ---- pass 2 : tracks, and right after each electron-candidate track its HfWbElectrons row. + // eleCands was filled in the same track order with the same pT condition, so it is read sequentially. + int nTracksStored = 0; + size_t iEle = 0; + for (const auto& track : tracks) { + const bool isAssociated = track.isGlobalTrackWoPtEta() && std::abs(track.eta()) <= etaTrMax && track.pt() > ptAssMin; + const bool isEleCand = track.pt() >= ptEleStoreMin; + if (!isAssociated && !isEleCand) { + continue; + } + rowTrack(collIdx, track.pt(), track.eta(), track.phi(), static_cast(track.sign()), + track.dcaXY(), track.dcaZ(), + static_cast(track.tpcNClsFound()), static_cast(track.tpcNClsCrossedRows()), + static_cast(track.itsNCls()), track.tpcChi2NCl(), track.itsChi2NCl(), + track.tpcNSigmaEl(), track.tpcNSigmaPi(), static_cast(track.isGlobalTrackWoPtEta())); + ++nTracksStored; + if (!isEleCand) { + continue; + } + const auto& cand = eleCands.at(iEle++); + if (cand.trackGlobalIndex != track.globalIndex()) { + LOG(fatal) << "electron candidate out of sync: " << cand.trackGlobalIndex << " vs " << track.globalIndex(); + } + const auto& e = cand.emc; + rowEle(collIdx, rowTrack.lastIndex(), + track.x(), track.alpha(), track.y(), track.z(), track.snp(), track.tgl(), track.signed1Pt(), + track.cYY(), track.cZY(), track.cZZ(), + track.cSnpY(), track.cSnpZ(), track.cSnpSnp(), + track.cTglY(), track.cTglZ(), track.cTglSnp(), track.cTglTgl(), + track.c1PtY(), track.c1PtZ(), track.c1PtSnp(), track.c1PtTgl(), track.c1Pt21Pt2(), + cand.pSum, cand.nTrk, + e.has, e.dEta, e.dPhi, e.energy, e.eta, e.phi, e.m02, e.time, e.nCells, e.nMatchInR, e.coneEnergy); + } + registry.fill(HIST("hNTracksStored"), nTracksStored); + registry.fill(HIST("hNElectronsStored"), eleCands.size()); + } + PROCESS_SWITCH(HfDerivedDataCreatorElectronWeakBoson, processData, "produce derived data for W/Z -> e (+h)", true); +}; + +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) +{ + return WorkflowSpec{adaptAnalysisTask(cfgc)}; +} diff --git a/PWGHF/HFL/Tasks/taskElectronWeakBoson.cxx b/PWGHF/HFL/Tasks/taskElectronWeakBoson.cxx index 6fa6239f900..36dd73454ba 100644 --- a/PWGHF/HFL/Tasks/taskElectronWeakBoson.cxx +++ b/PWGHF/HFL/Tasks/taskElectronWeakBoson.cxx @@ -18,6 +18,7 @@ #endif #include "PWGHF/Core/CentralityEstimation.h" +#include "PWGHF/HFL/DataModel/ElectronWeakBosonTables.h" #include "PWGJE/DataModel/EMCALClusters.h" #include "Common/Core/RecoDecay.h" @@ -301,6 +302,16 @@ struct HfTaskElectronWeakBoson { LOGF(fatal, "Invalid centrality estimator: %d", static_cast(centralityEstimator.value)); } + // AO2D and derived data are read by different process functions of this task + if (doprocessDerived && (doprocessData || doprocessMcGen || doprocessMcRec)) { + LOGF(fatal, "processDerived cannot be combined with processData / processMcGen / processMcRec."); + } + if (doprocessDerived && cfgSkimmedProcessing) { + LOGF(warn, "processDerived: the Zorro selection was applied by the producer; set cfgSkimmedProcessing=false (zorroSummary of this task stays empty)."); + } + const bool useMcGen = doprocessMcGen; + const bool useMcRec = doprocessMcRec; + // add configurable for CCDB path zorro.setBaseCCDBPath(cfgCCDBPath.value); @@ -458,14 +469,14 @@ struct HfTaskElectronWeakBoson { const AxisSpec axisEtaHadronMc{mcCfg.confaxisEtaHadron, "#eta_{hadron}"}; const AxisSpec axisMcCollCounter{4, -0.5, 3.5, "MC collision selection step"}; - if (doprocessMcGen) { + if (useMcGen) { registry.add("hMcGenCollCounter", "generated collisions (0: all, 1: |zvtx| cut, 2: reconstructed & selected)", kTH1D, {axisMcCollCounter}); registry.add("hMcGenZvtx", "generated Z vertex", kTH1D, {axisZvtx}); // denominator of the efficiency registry.add("hMcGenHadron", "generated primary charged hadrons", HistType::kTHnSparseF, {axisCentrality, axisPtHadronMc, axisEtaHadronMc}); } - if (doprocessMcRec) { + if (useMcRec) { registry.add("hMcRecCollCounter", "reconstructed collisions in MC", kTH1D, {axisCounter}); // numerator of the efficiency, in generated kinematics (use with hMcGenHadron) registry.add("hMcRecHadronMatchedGenKine", "reconstructed primary charged hadrons, generated kinematics", HistType::kTHnSparseF, {axisCentrality, axisPtHadronMc, axisEtaHadronMc, axisSysVar}); @@ -514,6 +525,21 @@ struct HfTaskElectronWeakBoson { return true; } + // Track QA, shared by processData (AO2D tracks) and processDerived (HfWbTracks): + // both provide the same getters. + template + void fillTrackQa(TTrack const& track) + { + registry.fill(HIST("hEta"), track.eta()); + registry.fill(HIST("hITSchi2"), track.itsChi2NCl()); + registry.fill(HIST("hTPCchi2"), track.tpcChi2NCl()); + registry.fill(HIST("hTPCnCls"), track.tpcNClsFound()); + registry.fill(HIST("hITSnCls"), track.itsNCls()); + registry.fill(HIST("hTPCnClsCrossedRows"), track.tpcNClsCrossedRows()); + registry.fill(HIST("hPt"), track.pt()); + registry.fill(HIST("hTPCNsigma"), track.p(), track.tpcNSigmaEl()); + } + // Centrality selection, applied on the centrality estimator itself (as in processData, // where the cut is done before the variable is possibly overwritten by the multiplicity) template @@ -762,44 +788,107 @@ struct HfTaskElectronWeakBoson { KFPTrack const kfpTrackAssEle = createKFPTrackFromTrack(track); KFParticle const kfpAssEle(kfpTrackAssEle, pdgAss); - // reco by RecoDecay - auto child1 = RecoDecayPtEtaPhi::pVector(kfpIsoEle.GetPt() * correctionPtElectron, kfpIsoEle.GetEta(), kfpIsoEle.GetPhi()); - auto child2 = RecoDecayPtEtaPhi::pVector(kfpAssEle.GetPt() * correctionPtElectron, kfpAssEle.GetEta(), kfpAssEle.GetPhi()); - double const invMassEE = RecoDecay::m(std::array{child1, child2}, std::array{o2::constants::physics::MassElectron, o2::constants::physics::MassElectron}); - - registry.fill(HIST("hInvMassZee"), centrality, track.sign() * charge, kfpIsoEle.GetPt(), invMassEE); - - // reco by KFparticle - std::array electronPairs = {&kfpIsoEle, &kfpAssEle}; - KFParticle zeeKF; - zeeKF.SetConstructMethod(kfConstructMethod); - zeeKF.Construct(electronPairs.data(), 2); - // LOG(info) << "Invarimass cal by KF particle Chi2/NDF = " << zeeKF.GetChi2()/zeeKF.GetNDF(); - float const chiSqNdf = zeeKF.GetChi2() / zeeKF.GetNDF(); - if (zeeKF.GetNDF() < 1) { + buildZee(kfpIsoEle, kfpAssEle, track.sign() * charge, indexIsoEle, track.globalIndex(), centrality); + } + } + + // One electron pair -> Z candidate. Shared by recoMassZee (AO2D) and recoMassZeeDerived (derived data), + // so that the two inputs go through exactly the same mass / KF selection. + void buildZee(const KFParticle& kfpIsoEle, + const KFParticle& kfpAssEle, + int chargeProduct, + int64_t indexIsoEle, + int64_t indexAssEle, + float centrality) + { + // reco by RecoDecay + auto child1 = RecoDecayPtEtaPhi::pVector(kfpIsoEle.GetPt() * correctionPtElectron, kfpIsoEle.GetEta(), kfpIsoEle.GetPhi()); + auto child2 = RecoDecayPtEtaPhi::pVector(kfpAssEle.GetPt() * correctionPtElectron, kfpAssEle.GetEta(), kfpAssEle.GetPhi()); + double const invMassEE = RecoDecay::m(std::array{child1, child2}, std::array{o2::constants::physics::MassElectron, o2::constants::physics::MassElectron}); + + registry.fill(HIST("hInvMassZee"), centrality, chargeProduct, kfpIsoEle.GetPt(), invMassEE); + + // reco by KFparticle + std::array electronPairs = {&kfpIsoEle, &kfpAssEle}; + KFParticle zeeKF; + zeeKF.SetConstructMethod(kfConstructMethod); + zeeKF.Construct(electronPairs.data(), 2); + if (zeeKF.GetNDF() < 1) { + return; + } + if (zeeKF.GetChi2() < 0) { + return; + } + float const chiSqNdf = zeeKF.GetChi2() / zeeKF.GetNDF(); + if (chiSqNdf > chiSqNdfMax) { + return; + } + float massZee{}, massZeeErr{}; + zeeKF.GetMass(massZee, massZeeErr); + registry.fill(HIST("hKfInvMassZee"), centrality, chargeProduct, kfpIsoEle.GetPt(), massZee); + reconstructedZ.emplace_back( + zeeKF.GetPt(), + zeeKF.GetEta(), + zeeKF.GetPhi(), + massZee, + chargeProduct, + kfpIsoEle.GetPt(), + kfpAssEle.GetPt(), + indexIsoEle, + indexAssEle); + } + + // ------------------------------------------------------------------------- + // Derived data helpers + // ------------------------------------------------------------------------- + // KFPTrack from an HfWbElectrons row (track parameters + covariance) and its HfWbTracks row. + template + KFPTrack createKfpTrackDerived(TEle const& ele, TTrk const& trk) + { + auto const trackParCov = getTrackParCov(ele); + return createKFPTrack(trackParCov, trk.sign(), trk.tpcNClsFound(), trk.tpcChi2NCl()); + } + + // Track isolation from the cone sums stored by the producer; same definition as getIsolatedTrack(). + template + std::pair getIsolatedTrackDerived(TEle const& ele, TTrk const& trk) + { + double isoMomentum = 10; + if (ele.pSumCone() > 0) { + isoMomentum = ele.pSumCone() / trk.p() - 1.0; + } + return std::make_pair(ele.nTrkCone() - 1, isoMomentum); + } + + void recoMassZeeDerived(const KFParticle& kfpIsoEle, + int charge, + int64_t indexIsoEle, + float centrality, + aod::HfWbElectrons const& electrons) + { + // partners: every HfWbElectrons row of the collision (= every track above ptEleStoreMin, no global-track + // requirement), exactly as recoMassZee loops over all tracks + for (const auto& partner : electrons) { + auto const track = partner.hfWbTrack_as(); + if (track.globalIndex() == indexIsoEle) { continue; } - if (zeeKF.GetChi2() < 0) { + if (track.pt() < ptZeeMin) { continue; } - if (chiSqNdf > chiSqNdfMax) { + if (std::abs(track.tpcNSigmaEl()) > nsigTpcMax) { continue; } - float massZee{}, massZeeErr{}; - zeeKF.GetMass(massZee, massZeeErr); - registry.fill(HIST("hKfInvMassZee"), centrality, track.sign() * charge, kfpIsoEle.GetPt(), massZee); - // LOG(info) << "Invarimass cal by KF particle mass = " << massZee; - // LOG(info) << "Invarimass cal by RecoDecay = " << invMassEE; - reconstructedZ.emplace_back( - zeeKF.GetPt(), - zeeKF.GetEta(), - zeeKF.GetPhi(), - massZee, - track.sign() * charge, - kfpIsoEle.GetPt(), - kfpAssEle.GetPt(), - indexIsoEle, - track.globalIndex()); + if (std::abs(track.eta()) > etaTrMax) { + continue; + } + auto const [trackCount, isoMomentum] = getIsolatedTrackDerived(partner, track); + if (isoMomentum > momentumIsolationMax) { + continue; + } + int const pdgAss = track.sign() > 0 ? kPositron : kElectron; + KFParticle const kfpAssEle(createKfpTrackDerived(partner, track), pdgAss); + buildZee(kfpIsoEle, kfpAssEle, track.sign() * charge, indexIsoEle, track.globalIndex(), centrality); } } @@ -1064,6 +1153,71 @@ struct HfTaskElectronWeakBoson { } } + // ------------------------------------------------------------------------- + // Start of the event, shared by processData and processDerived: clears the containers, fills the + // event QA, applies the centrality selection and computes the UE energy in the isolation cone. + // getRho() is called only when the UE subtraction is on (on AO2D it throws the random cones). + // Returns false if the event fails the centrality selection. + // ------------------------------------------------------------------------- + template + bool initEvent(TCollision const& collision, FRho&& getRho, float& centrality, float& energyUE) + { + selectedElectronsIso.clear(); + selectedPositronsIso.clear(); + selectedElectronsAss.clear(); + reconstructedZ.clear(); + + registry.fill(HIST("hEventCounter"), 0.5); + registry.fill(HIST("hZvtx"), collision.posZ()); + + // same selection and value as in the MC process functions + if (!isSelectedCentrality(collision)) { + return false; + } + if (enableCentralityAnalysis) { + float const centralityPercentile = o2::hf_centrality::getCentralityColl(collision, centralityEstimator); + registry.fill(HIST("hCentMultFT0Corr"), centralityPercentile, collision.multFT0M()); + registry.fill(HIST("hCentMultPVCorr"), centralityPercentile, collision.multNTracksPV()); + } + if (enableMultiplicityFT0MAnalysis || enableMultiplicityPVAnalysis) { + registry.fill(HIST("hMultPV"), collision.posZ(), collision.multNTracksPV()); + registry.fill(HIST("hMultFT0"), collision.posZ(), collision.multFT0M()); + registry.fill(HIST("hMultFT0PV"), collision.multFT0M(), collision.multNTracksPV()); + } + centrality = getCentralityValue(collision); + registry.fill(HIST("hCentrality"), centrality); + + energyUE = 0.f; + if (ueCfg.useUEsub) { + energyUE = getRho() * static_cast(o2::constants::math::PI * rIsolation * rIsolation); + registry.fill(HIST("hEnergyUE"), centrality, energyUE); + } + return true; + } + + // ------------------------------------------------------------------------- + // End of the event, shared by processData and processDerived: everything below reads only the + // containers (reconstructedZ, selectedElectronsIso/PositronsIso, selectedElectronsAss). + // ------------------------------------------------------------------------- + void fillCorrelations(float centrality) + { + // Z - hadron correlation + fillZHadron(centrality); + + // W->e - h correlation. Electrons and positrons are kept in two containers, so the same + // routine runs twice; the electron charge goes on the sign axis (W- / W+). + if (weCfg.enableWeHadron) { + fillWeHadron(selectedElectronsIso, centrality); + fillWeHadron(selectedPositronsIso, centrality); + } + + // Z->ee QA + fillZeeQa(); + } + + // ------------------------------------------------------------------------- + // AO2D input + // ------------------------------------------------------------------------- void processData(soa::Filtered::iterator const& collision, aod::BCsWithTimestamps const&, SelectedClusters const& emcClusters, @@ -1114,57 +1268,12 @@ struct HfTaskElectronWeakBoson { return; } } - // initialze for inclusive-electron - selectedElectronsIso.clear(); - selectedPositronsIso.clear(); - selectedElectronsAss.clear(); - reconstructedZ.clear(); - - registry.fill(HIST("hEventCounter"), 0.5); - - // LOGF(info, "Collision index : %d", collision.index()); - // LOGF(info, "Number of tracks: %d", tracks.size()); - // LOGF(info, "Number of clusters: %d", clusters.size()); - - registry.fill(HIST("hZvtx"), collision.posZ()); - - // Calculate centrality + // event start: containers, event QA, centrality selection, UE. + // The random cones are thrown only when the UE subtraction is on (estimateRhoRC fills hRho/hSumERC). float centrality = 1.0; - if (enableCentralityAnalysis) { - centrality = o2::hf_centrality::getCentralityColl(collision, centralityEstimator); - // LOG(info) << "centrality = " << o2::hf_centrality::getCentralityColl(collision, centralityEstimator) << " ; FTC = " << collision.multFT0C(); - if (centrality < centralityMin || centrality > centralityMax) { - return; - } - registry.fill(HIST("hCentMultFT0Corr"), centrality, collision.multFT0M()); - registry.fill(HIST("hCentMultPVCorr"), centrality, collision.multNTracksPV()); - } - - if (enableMultiplicityFT0MAnalysis || enableMultiplicityPVAnalysis) { - if (enableMultiplicityFT0MAnalysis) { - centrality = collision.multFT0M(); - } - if (enableMultiplicityPVAnalysis) { - centrality = collision.multNTracksPV(); - } - // LOG(info) << "raw mult PV = " << collision.multNTracksPV(); - // LOG(info) << "raw mult FT0M = " << collision.multFT0M(); - registry.fill(HIST("hMultPV"), collision.posZ(), collision.multNTracksPV()); - registry.fill(HIST("hMultFT0"), collision.posZ(), collision.multFT0M()); - registry.fill(HIST("hMultFT0PV"), collision.multFT0M(), collision.multNTracksPV()); - } - - registry.fill(HIST("hCentrality"), centrality); - - // UE estimate - float rho = 0.f; float energyUE = 0.f; - - if (ueCfg.useUEsub) { - rho = estimateRhoRC(emcClusters); - energyUE = rho * (o2::constants::math::PI * rIsolation * rIsolation); - registry.fill(HIST("hEnergyUE"), centrality, energyUE); - // LOG(info) << "UE = " << energyUE; + if (!initEvent(collision, [&]() { return estimateRhoRC(emcClusters); }, centrality, energyUE)) { + return; } const float ptIsoStoreMin = weCfg.enableWeHadron @@ -1177,14 +1286,7 @@ struct HfTaskElectronWeakBoson { if (!isSelectedTrackKine(track)) { continue; } - registry.fill(HIST("hEta"), track.eta()); - registry.fill(HIST("hITSchi2"), track.itsChi2NCl()); - registry.fill(HIST("hTPCchi2"), track.tpcChi2NCl()); - registry.fill(HIST("hTPCnCls"), track.tpcNClsFound()); - registry.fill(HIST("hITSnCls"), track.itsNCls()); - registry.fill(HIST("hTPCnClsCrossedRows"), track.tpcNClsCrossedRows()); - registry.fill(HIST("hPt"), track.pt()); - registry.fill(HIST("hTPCNsigma"), track.p(), track.tpcNSigmaEl()); + fillTrackQa(track); float eop = -0.01; float m02 = -0.01; @@ -1342,20 +1444,175 @@ struct HfTaskElectronWeakBoson { } } // end of track loop - // Z - hadron correlation - fillZHadron(centrality); - - // W->e - h correlation. Electrons and positrons are kept in two containers, so the same - // routine runs twice; the electron charge goes on the sign axis (W- / W+). - if (weCfg.enableWeHadron) { - fillWeHadron(selectedElectronsIso, centrality); - fillWeHadron(selectedPositronsIso, centrality); - } // end of W->e - hadron correlation - // Z->ee QA - fillZeeQa(); + fillCorrelations(centrality); } // processData PROCESS_SWITCH(HfTaskElectronWeakBoson, processData, "process data (Z->ee and Z-h correlation)", true); + // ------------------------------------------------------------------------- + // Derived data (HfWbColls / HfWbTracks / HfWbElectrons from derivedDataCreatorElectronWeakBoson). + // Same selection as processData; what the producer fixed (Zorro trigger, event skim, rIsolation, + // cluster definition, EMCal time window, random-cone UE) is NOT re-applied here. + // Requirements on the producer configuration: + // ptEleStoreMin <= min(ptMin, ptZeeMin), etaTrMax(producer) >= etaTrMax, ptAssMin(producer) <= ptAssMin, + // rIsolation(producer) == rIsolation, ptSkimMin <= min(ptZeeMin, ptWeMin) + // ------------------------------------------------------------------------- + void processDerived(aod::HfWbColl const& collision, + aod::HfWbTracks const& tracks, + aod::HfWbElectrons const& electrons) + { + registry.fill(HIST("hEventCounterInit"), 0.5); + + // same as Filter posZFilter / eventFilter of processData + if (!(std::abs(collision.posZ()) < vtxZ)) { + return; + } + if (applySel8 && !collision.sel8()) { + return; + } + + // magnetic field for KFParticle, stored per collision by the producer. + // function-local static instead of a task member: the struct is at the member limit. + static float lastMagField = 0.f; + if (collision.magField() != lastMagField && collision.magField() != 0.f) { + KFParticle::SetField(collision.magField()); + lastMagField = collision.magField(); + LOG(info) << "derived: magneticField = " << lastMagField << " (run " << collision.runNumber() << ")"; + } + + // event start, same as processData. NB: only events kept by the producer skim are counted in + // hEventCounter; the normalisation is in the producer output (hEventCounter, zorroSummary). + // UE: rho from the producer's random cones (rIsolation must be the producer's value). + float centrality = 1.0; + float energyUE = 0.f; + auto const getRho = [&]() { + registry.fill(HIST("hRho"), collision.rhoUE()); // in processData filled by estimateRhoRC + return collision.rhoUE(); + }; + if (!initEvent(collision, getRho, centrality, energyUE)) { + return; + } + + const float ptIsoStoreMin = weCfg.enableWeHadron + ? std::min(static_cast(ptZeeMin), static_cast(weCfg.ptWeMin)) + : static_cast(ptZeeMin); + + // associated hadrons. The track isolation of low-pT tracks is not stored; it is not used for them. + for (const auto& track : tracks) { + if (!isSelectedTrackKine(track)) { + continue; + } + fillTrackQa(track); + if (track.pt() > ptAssMin) { + selectedElectronsAss.emplace_back( + track.pt(), track.eta(), track.phi(), track.dcaXY(), track.dcaZ(), + -0.01f, 99.0f, 10.0f, track.tpcNSigmaPi(), -0.01f, 0, + track.tpcNClsCrossedRows(), track.itsNCls(), track.sign(), track.globalIndex()); + } + } + + // electron candidates + for (const auto& ele : electrons) { + auto const track = ele.hfWbTrack_as(); + if (!isSelectedTrackKine(track)) { + continue; + } + if (track.pt() < ptMin) { + continue; + } + + float eop = -0.01; + float m02 = -0.01; + float isoEnergy = 99.0; + auto const [trackCount, isoMomentum] = getIsolatedTrackDerived(ele, track); + + bool isEMCacceptance = true; + if (track.phi() < phiEmcMin || track.phi() > phiEmcMax) { + isEMCacceptance = false; + } + if (std::abs(track.eta()) > etaEmcMax) { + isEMCacceptance = false; + } + + double rMin = 999.9; + double dPhiMin = 999.9; + double dEtaMin = 999.9; + bool isIsolated = false; + bool isIsolatedTr = false; + + if (ele.hasEmcMatch() && isEMCacceptance) { + dPhiMin = ele.emcDPhi(); + dEtaMin = ele.emcDEta(); + rMin = RecoDecay::sqrtSumOfSquares(dPhiMin, dEtaMin); + registry.fill(HIST("hNMatchPerTrack"), track.pt(), ele.emcNMatchInR()); + registry.fill(HIST("hMatchPhi"), ele.emcPhi(), ele.emcPhi() + ele.emcDPhi()); + registry.fill(HIST("hMatchEta"), ele.emcEta(), ele.emcEta() + ele.emcDEta()); + registry.fill(HIST("hTHnTrMatch"), track.pt(), dPhiMin, dEtaMin); + registry.fill(HIST("hEMCtime"), ele.emcTime()); + + const bool isMatched = (std::abs(dPhiMin) <= rMatchMax) && (std::abs(dEtaMin) <= rMatchMax); + if (isMatched) { + float const m02Emc = ele.emcM02(); + float const energyEmc = ele.emcEnergy(); + float const energyTEmc = energyEmc / std::cosh(ele.emcEta()); + + registry.fill(HIST("hTrMatchR"), track.pt(), rMin); + registry.fill(HIST("hEnergyNcell"), energyEmc, ele.emcNCells()); + registry.fill(HIST("hEnergy"), energyEmc); + registry.fill(HIST("hEnergyT"), energyTEmc); + registry.fill(HIST("hEnergyEt"), energyEmc, energyTEmc); + registry.fill(HIST("hEnergyMult"), centrality, energyEmc); + + eop = energyEmc / track.p(); + m02 = m02Emc; + // same as getIsolatedCluster(): (cone energy without the cluster - UE) / E + isoEnergy = (ele.emcConeEnergy() - energyUE) / energyEmc; + registry.fill(HIST("hIsolationEnergy"), energyEmc, isoEnergy); + + if (track.pt() > ptTHnThresh && isTHnElectron) { + registry.fill(HIST("hTHnElectrons"), track.pt(), track.tpcNSigmaEl(), m02Emc, eop, isoEnergy, isoMomentum, trackCount, track.eta(), energyTEmc); + } + registry.fill(HIST("hEopNsigTPC"), track.tpcNSigmaEl(), eop); + + if (m02Emc >= m02Min && m02Emc <= m02Max && + track.tpcNSigmaEl() > nsigTpcMin && track.tpcNSigmaEl() < nsigTpcMax) { + registry.fill(HIST("hEop"), track.pt(), eop); + if (eop > eopMin && eop < eopMax && isoEnergy < energyIsolationMax) { + isIsolated = true; + } + if (eop > eopMin && eop < eopMax && trackCount < trackIsolationMax && isoMomentum < momentumIsolationMax) { + isIsolatedTr = true; + } + if (isIsolated && isIsolatedTr) { + registry.fill(HIST("hEopIsolation"), track.pt(), eop); + if (track.pt() > ptZeeMin) { + int const pdgIso = track.sign() > 0 ? kPositron : kElectron; + KFParticle const kfpIsoEle(createKfpTrackDerived(ele, track), pdgIso); + recoMassZeeDerived(kfpIsoEle, track.sign(), track.globalIndex(), centrality, electrons); + } + } + if (isIsolatedTr) { + registry.fill(HIST("hEopIsolationTr"), track.pt(), eop); + } + } + } + } + + if (rMin < rMatchMax) { + registry.fill(HIST("hTrMatch_mim"), dPhiMin, dEtaMin); + } + if ((zeeQaCfg.enableZeeTrkRecoQA || zeeQaCfg.enableZeeEmcRecoQA || weCfg.enableWeHadron) && track.pt() > ptIsoStoreMin) { + auto& container = track.sign() < 0 ? selectedElectronsIso : selectedPositronsIso; + container.emplace_back( + track.pt(), track.eta(), track.phi(), track.dcaXY(), track.dcaZ(), + eop, isoEnergy, isoMomentum, track.tpcNSigmaEl(), m02, trackCount, + track.tpcNClsFound(), track.itsNCls(), track.sign(), track.globalIndex()); + } + } + + fillCorrelations(centrality); + } // processDerived + PROCESS_SWITCH(HfTaskElectronWeakBoson, processDerived, "process derived data (HfWbColls/HfWbTracks/HfWbElectrons)", false); + // ------------------------------------------------------------------------- // MC : denominator of the associated-hadron efficiency. // Looping over the generated collisions (with the reconstructed ones collected by