|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// \file correlatorFlowCharmHadrons.cxx |
| 13 | +/// \brief CharmHadrons-Hadrons correlator tree creator for data and MC-reco analyses |
| 14 | +/// \author Marcello Di Costanzo <marcello.di.costanzo@cern.ch>, Politecnico and INFN Torino |
| 15 | +/// \author Stefano Politanò <stefano.politano@cern.ch>, CERN |
| 16 | + |
| 17 | +#include "PWGHF/Core/HfHelper.h" |
| 18 | +#include "PWGHF/DataModel/CandidateReconstructionTables.h" |
| 19 | +#include "PWGHF/DataModel/CandidateSelectionTables.h" |
| 20 | +#include "PWGHF/HFC/DataModel/DerivedDataCorrelationTables.h" |
| 21 | +#include "PWGHF/Utils/utilsEvSelHf.h" |
| 22 | + |
| 23 | +#include "Common/DataModel/Multiplicity.h" |
| 24 | +#include "Common/DataModel/TrackSelectionTables.h" |
| 25 | + |
| 26 | +#include <CCDB/BasicCCDBManager.h> |
| 27 | +#include <CommonConstants/MathConstants.h> |
| 28 | +#include <CommonConstants/PhysicsConstants.h> |
| 29 | +#include <Framework/ASoA.h> |
| 30 | +#include <Framework/ASoAHelpers.h> |
| 31 | +#include <Framework/AnalysisDataModel.h> |
| 32 | +#include <Framework/AnalysisHelpers.h> |
| 33 | +#include <Framework/AnalysisTask.h> |
| 34 | +#include <Framework/BinningPolicy.h> |
| 35 | +#include <Framework/Configurable.h> |
| 36 | +#include <Framework/GroupedCombinations.h> |
| 37 | +#include <Framework/HistogramRegistry.h> |
| 38 | +#include <Framework/HistogramSpec.h> |
| 39 | +#include <Framework/InitContext.h> |
| 40 | +#include <Framework/Logger.h> |
| 41 | +#include <Framework/OutputObjHeader.h> |
| 42 | +#include <Framework/runDataProcessing.h> |
| 43 | + |
| 44 | +#include <string> |
| 45 | +#include <vector> |
| 46 | + |
| 47 | +using namespace o2; |
| 48 | +using namespace o2::hf_centrality; |
| 49 | +using namespace o2::hf_evsel; |
| 50 | + |
| 51 | +enum DecayChannel { |
| 52 | + DplusToPiKPi = 0, |
| 53 | + DsToKKPi, |
| 54 | + DsToPiKK |
| 55 | +}; |
| 56 | + |
| 57 | +/// Code to select collisions with at least one Ds meson |
| 58 | +struct HfCorrelatorFlowCharmHadrons { |
| 59 | + Produces<aod::HfcRedFlowColls> rowCollisions; |
| 60 | + Produces<aod::HfcRedCharmHads> rowCharmCandidates; |
| 61 | + Produces<aod::HfcRedCharmMls> rowCharmCandidatesMl; |
| 62 | + Produces<aod::HfcRedTrkAssoc> rowAssocTrackReduced; |
| 63 | + Produces<aod::HfcRedTrkSels> rowAssocTrackSelInfo; |
| 64 | + |
| 65 | + Configurable<int> centEstimator{"centEstimator", 2, "Centrality estimation (FT0A: 1, FT0C: 2, FT0M: 3, FV0A: 4)"}; |
| 66 | + Configurable<int> selectionFlag{"selectionFlag", 1, "Selection Flag for hadron (e.g. 1 for skimming, 3 for topo. and kine., 7 for PID)"}; |
| 67 | + Configurable<bool> forceCharmInCollision{"forceCharmInCollision", false, "Flag to force charm in collision"}; |
| 68 | + Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; |
| 69 | + Configurable<std::vector<int>> classMl{"classMl", {0, 2}, "Indexes of BDT scores to be stored. Two indexes max."}; |
| 70 | + Configurable<float> yCandMax{"yCandMax", 0.8, "max. cand. rapidity"}; |
| 71 | + Configurable<float> ptCandMin{"ptCandMin", 1., "min. cand. pT"}; |
| 72 | + Configurable<float> ptCandMax{"ptCandMax", 24., "max. cand. pT"}; |
| 73 | + Configurable<float> etaTrackMax{"etaTrackMax", 1., "max. track eta"}; |
| 74 | + Configurable<float> ptTrackMin{"ptTrackMin", 0.15, "min. track pT"}; |
| 75 | + Configurable<float> ptTrackMax{"ptTrackMax", 5., "max. track pT"}; |
| 76 | + Configurable<float> dcaXYTrackMax{"dcaXYTrackMax", 1., "max. track DCA XY"}; |
| 77 | + Configurable<float> dcaZTrackMax{"dcaZTrackMax", 1., "max. track DCA Z"}; |
| 78 | + |
| 79 | + HfHelper hfHelper; |
| 80 | + HfEventSelection hfEvSel; // event selection and monitoring |
| 81 | + o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 82 | + SliceCache cache; |
| 83 | + |
| 84 | + double massCharm{0.}; |
| 85 | + |
| 86 | + using CollsWithCentMult = soa::Join<aod::Collisions, aod::EvSels, aod::FT0Mults, aod::FV0Mults, aod::CentFT0Ms, aod::CentFT0As, aod::CentFT0Cs, aod::CentFV0As>; |
| 87 | + using CandDsDataWMl = soa::Filtered<soa::Join<aod::HfCand3Prong, aod::HfSelDsToKKPi, aod::HfMlDsToKKPi>>; |
| 88 | + using CandDplusDataWMl = soa::Filtered<soa::Join<aod::HfCand3Prong, aod::HfSelDplusToPiKPi, aod::HfMlDplusToPiKPi>>; |
| 89 | + using TracksData = soa::Filtered<soa::Join<aod::TracksWDca, aod::TrackSelection, aod::TracksExtra>>; |
| 90 | + |
| 91 | + Filter filterSelectDsCandidates = aod::hf_sel_candidate_ds::isSelDsToKKPi >= selectionFlag || aod::hf_sel_candidate_ds::isSelDsToPiKK >= selectionFlag; |
| 92 | + Filter filterSelectDplusCandidates = aod::hf_sel_candidate_dplus::isSelDplusToPiKPi >= selectionFlag; |
| 93 | + Filter filterSelectTrackData = (nabs(aod::track::eta) < etaTrackMax) && (aod::track::pt > ptTrackMin) && (aod::track::pt < ptTrackMax) && (nabs(aod::track::dcaXY) < dcaXYTrackMax) && (nabs(aod::track::dcaZ) < dcaZTrackMax); |
| 94 | + |
| 95 | + Preslice<CandDsDataWMl> candsDsPerCollWMl = aod::hf_cand::collisionId; |
| 96 | + Preslice<CandDplusDataWMl> candsDplusPerCollWMl = aod::hf_cand::collisionId; |
| 97 | + Preslice<TracksData> trackIndicesPerColl = aod::track::collisionId; |
| 98 | + |
| 99 | + Partition<CandDsDataWMl> selectedDsToKKPiWMl = aod::hf_sel_candidate_ds::isSelDsToKKPi >= selectionFlag; |
| 100 | + Partition<CandDsDataWMl> selectedDsToPiKKWMl = aod::hf_sel_candidate_ds::isSelDsToPiKK >= selectionFlag; |
| 101 | + |
| 102 | + HistogramRegistry registry{"registry", {}}; |
| 103 | + |
| 104 | + void init(InitContext&) |
| 105 | + { |
| 106 | + if (doprocessDplusWithMl) { |
| 107 | + massCharm = o2::constants::physics::MassDPlus; |
| 108 | + } else if (doprocessDsWithMl) { |
| 109 | + massCharm = o2::constants::physics::MassDS; |
| 110 | + } |
| 111 | + |
| 112 | + hfEvSel.addHistograms(registry); // collision monitoring |
| 113 | + ccdb->setURL(ccdbUrl); |
| 114 | + ccdb->setCaching(true); |
| 115 | + ccdb->setLocalObjectValidityChecking(); |
| 116 | + }; // end init |
| 117 | + |
| 118 | + /// Check event selections for collision and fill the collision table |
| 119 | + /// \param collision is the collision |
| 120 | + template <typename Coll> |
| 121 | + bool checkAndFillCollision(Coll const& collision) |
| 122 | + { |
| 123 | + float cent{-1.f}; |
| 124 | + float mult{-1.f}; |
| 125 | + o2::hf_evsel::HfCollisionRejectionMask collRejMask{}; |
| 126 | + if (centEstimator == CentralityEstimator::FT0A) { |
| 127 | + collRejMask = hfEvSel.getHfCollisionRejectionMask<true, CentralityEstimator::FT0A, aod::BCsWithTimestamps>(collision, cent, ccdb, registry); |
| 128 | + mult = collision.multFT0A(); |
| 129 | + } else if (centEstimator == CentralityEstimator::FT0C) { |
| 130 | + collRejMask = hfEvSel.getHfCollisionRejectionMask<true, CentralityEstimator::FT0C, aod::BCsWithTimestamps>(collision, cent, ccdb, registry); |
| 131 | + mult = collision.multFT0C(); |
| 132 | + } else if (centEstimator == CentralityEstimator::FT0M) { |
| 133 | + collRejMask = hfEvSel.getHfCollisionRejectionMask<true, CentralityEstimator::FT0M, aod::BCsWithTimestamps>(collision, cent, ccdb, registry); |
| 134 | + mult = collision.multFT0M(); |
| 135 | + } else if (centEstimator == CentralityEstimator::FV0A) { |
| 136 | + collRejMask = hfEvSel.getHfCollisionRejectionMask<true, CentralityEstimator::FV0A, aod::BCsWithTimestamps>(collision, cent, ccdb, registry); |
| 137 | + mult = collision.multFV0A(); |
| 138 | + } else { |
| 139 | + LOG(fatal) << "Centrality estimator not recognized for collision selection"; |
| 140 | + std::abort(); |
| 141 | + } |
| 142 | + hfEvSel.fillHistograms(collision, collRejMask, cent); |
| 143 | + if (collRejMask != 0) { |
| 144 | + return false; |
| 145 | + } |
| 146 | + rowCollisions(mult, collision.numContrib(), cent, collision.posZ()); |
| 147 | + return true; |
| 148 | + } |
| 149 | + |
| 150 | + /// Get charm hadron candidate mass |
| 151 | + /// \param candidate is the charm hadron candidate |
| 152 | + template <DecayChannel channel, typename TCand> |
| 153 | + double getCandMass(const TCand& candidate) |
| 154 | + { |
| 155 | + if constexpr (channel == DecayChannel::DsToKKPi) { |
| 156 | + return hfHelper.invMassDsToKKPi(candidate); |
| 157 | + } |
| 158 | + if constexpr (channel == DecayChannel::DsToPiKK) { |
| 159 | + return hfHelper.invMassDsToPiKK(candidate); |
| 160 | + } |
| 161 | + if constexpr (channel == DecayChannel::DplusToPiKPi) { |
| 162 | + return hfHelper.invMassDplusToPiKPi(candidate); |
| 163 | + } |
| 164 | + return -1.; |
| 165 | + } |
| 166 | + |
| 167 | + /// Get charm hadron bdt scores |
| 168 | + /// \param candidate is the charm hadron candidate |
| 169 | + template <DecayChannel channel, typename TCand> |
| 170 | + std::vector<float> getCandMlScores(const TCand& candidate) |
| 171 | + { |
| 172 | + std::vector<float> outputMl{-999., -999.}; |
| 173 | + if constexpr (channel == DecayChannel::DsToKKPi) { |
| 174 | + for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { |
| 175 | + outputMl[iclass] = candidate.mlProbDsToKKPi()[classMl->at(iclass)]; |
| 176 | + } |
| 177 | + } |
| 178 | + if constexpr (channel == DecayChannel::DsToPiKK) { |
| 179 | + for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { |
| 180 | + outputMl[iclass] = candidate.mlProbDsToPiKK()[classMl->at(iclass)]; |
| 181 | + } |
| 182 | + } |
| 183 | + if constexpr (channel == DecayChannel::DplusToPiKPi) { |
| 184 | + for (unsigned int iclass = 0; iclass < classMl->size(); iclass++) { |
| 185 | + outputMl[iclass] = candidate.mlProbDplusToPiKPi()[classMl->at(iclass)]; |
| 186 | + } |
| 187 | + } |
| 188 | + return outputMl; |
| 189 | + } |
| 190 | + |
| 191 | + /// Fill charm hadron tables |
| 192 | + /// \param candidates are the selected charm hadron candidates |
| 193 | + template <DecayChannel channel, typename TCand> |
| 194 | + void fillCharmHadronTables(TCand const& candidates) |
| 195 | + { |
| 196 | + int indexRedColl = rowCollisions.lastIndex(); |
| 197 | + for (const auto& candidate : candidates) { |
| 198 | + if (std::abs(candidate.y(massCharm)) > yCandMax || candidate.pt() < ptCandMin || candidate.pt() > ptCandMax) { |
| 199 | + continue; |
| 200 | + } |
| 201 | + double massCand = getCandMass<channel>(candidate); |
| 202 | + rowCharmCandidates(indexRedColl, candidate.phi(), candidate.eta(), candidate.pt(), massCand, candidate.prong0Id(), candidate.prong1Id(), candidate.prong2Id()); |
| 203 | + |
| 204 | + std::vector<float> outputMl = getCandMlScores<channel>(candidate); |
| 205 | + rowCharmCandidatesMl(indexRedColl, outputMl[0], outputMl[1]); |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + /// Fill tracks tables |
| 210 | + /// \param tracks are the selected tracks |
| 211 | + template <typename TTrack> |
| 212 | + void fillTracksTables(TTrack const& tracks) |
| 213 | + { |
| 214 | + int indexRedColl = rowCollisions.lastIndex(); |
| 215 | + for (const auto& track : tracks) { |
| 216 | + if (!track.isGlobalTrackWoDCA()) { |
| 217 | + continue; |
| 218 | + } |
| 219 | + rowAssocTrackReduced(indexRedColl, track.globalIndex(), track.phi(), track.eta(), track.pt()); |
| 220 | + rowAssocTrackSelInfo(indexRedColl, track.tpcNClsCrossedRows(), track.itsClusterMap(), track.itsNCls(), track.dcaXY(), track.dcaZ()); |
| 221 | + } |
| 222 | + } |
| 223 | + |
| 224 | + // Dplus with ML selections |
| 225 | + void processDplusWithMl(CollsWithCentMult const& colls, |
| 226 | + CandDplusDataWMl const& candsDplus, |
| 227 | + TracksData const& tracks) |
| 228 | + { |
| 229 | + for (const auto& coll : colls) { |
| 230 | + auto thisCollId = coll.globalIndex(); |
| 231 | + auto candsCThisColl = candsDplus.sliceBy(candsDplusPerCollWMl, thisCollId); |
| 232 | + if (forceCharmInCollision && candsCThisColl.size() < 1) { |
| 233 | + continue; |
| 234 | + } |
| 235 | + if (!checkAndFillCollision(coll)) { |
| 236 | + continue; |
| 237 | + } |
| 238 | + auto trackIdsThisColl = tracks.sliceBy(trackIndicesPerColl, thisCollId); |
| 239 | + fillCharmHadronTables<DecayChannel::DplusToPiKPi>(candsCThisColl); |
| 240 | + fillTracksTables(trackIdsThisColl); |
| 241 | + } |
| 242 | + } |
| 243 | + PROCESS_SWITCH(HfCorrelatorFlowCharmHadrons, processDplusWithMl, "Process Dplus candidates with ML info", false); |
| 244 | + |
| 245 | + // Ds with ML selections |
| 246 | + void processDsWithMl(CollsWithCentMult const& colls, |
| 247 | + TracksData const& tracks, |
| 248 | + CandDsDataWMl const&) |
| 249 | + { |
| 250 | + for (const auto& coll : colls) { |
| 251 | + auto thisCollId = coll.globalIndex(); |
| 252 | + auto candsDsToKKPiWMl = selectedDsToKKPiWMl->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); |
| 253 | + auto candsDsToPiKKWMl = selectedDsToPiKKWMl->sliceByCached(aod::hf_cand::collisionId, thisCollId, cache); |
| 254 | + if (forceCharmInCollision && candsDsToKKPiWMl.size() < 1 && candsDsToPiKKWMl.size() < 1) { |
| 255 | + continue; |
| 256 | + } |
| 257 | + if (!checkAndFillCollision(coll)) { |
| 258 | + continue; |
| 259 | + } |
| 260 | + auto trackIdsThisColl = tracks.sliceBy(trackIndicesPerColl, thisCollId); |
| 261 | + fillCharmHadronTables<DecayChannel::DsToPiKK>(candsDsToPiKKWMl); |
| 262 | + fillCharmHadronTables<DecayChannel::DsToKKPi>(candsDsToKKPiWMl); |
| 263 | + fillTracksTables(trackIdsThisColl); |
| 264 | + } |
| 265 | + } |
| 266 | + PROCESS_SWITCH(HfCorrelatorFlowCharmHadrons, processDsWithMl, "Process Ds candidates with ML info", false); |
| 267 | +}; |
| 268 | + |
| 269 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 270 | +{ |
| 271 | + return WorkflowSpec{adaptAnalysisTask<HfCorrelatorFlowCharmHadrons>(cfgc)}; |
| 272 | +} |
0 commit comments