|
| 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 slimTablesProducer.cxx |
| 13 | +/// \brief Task to produce a reduced version of Tables for tracks, collisions, mcparticles and mccollisions. |
| 14 | +/// \author Millot Louise <louise.millot@cern.ch> |
| 15 | + |
| 16 | +#include "PWGJE/Core/JetDerivedDataUtilities.h" |
| 17 | +#include "PWGJE/DataModel/Jet.h" |
| 18 | +#include "PWGJE/DataModel/JetReducedData.h" |
| 19 | +#include "PWGJE/DataModel/SlimTables.h" |
| 20 | + |
| 21 | +#include <Framework/ASoA.h> |
| 22 | +#include <Framework/AnalysisDataModel.h> |
| 23 | +#include <Framework/AnalysisHelpers.h> |
| 24 | +#include <Framework/AnalysisTask.h> |
| 25 | +#include <Framework/Configurable.h> |
| 26 | +#include <Framework/InitContext.h> |
| 27 | +#include <Framework/runDataProcessing.h> |
| 28 | + |
| 29 | +#include <string> |
| 30 | +#include <vector> |
| 31 | + |
| 32 | +using namespace o2; |
| 33 | +using namespace o2::framework; |
| 34 | +using namespace o2::framework::expressions; |
| 35 | + |
| 36 | +struct SlimTablesProducer { |
| 37 | + |
| 38 | + HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject}; |
| 39 | + Configurable<bool> checkCentFT0M{"checkCentFT0M", false, "0: centFT0C as default, 1: use centFT0M estimator"}; |
| 40 | + Configurable<float> centralityMin{"centralityMin", -999, ""}; |
| 41 | + Configurable<float> centralityMax{"centralityMax", 999, ""}; |
| 42 | + Configurable<float> minPt{"minPt", 0.15, "min pT to save"}; |
| 43 | + Configurable<float> maxPt{"maxPt", 200.0, "max pT to save"}; |
| 44 | + Configurable<float> minEta{"minEta", -0.9, "min eta to save"}; |
| 45 | + Configurable<float> maxEta{"maxEta", 0.9, "max eta to save"}; |
| 46 | + Configurable<float> vertexZCut{"vertexZCut", 10.0f, "Accepted z-vertex range"}; |
| 47 | + Configurable<std::string> eventSelections{"eventSelections", "sel8", "Event selection"}; |
| 48 | + Configurable<bool> skipMBGapEvents{"skipMBGapEvents", false, "flag to choose to reject min. bias gap events; jet-level rejection can also be applied at the jet finder level for jets only, here rejection is applied for collision and track process functions for the first time, and on jets in case it was set to false at the jet finder level"}; |
| 49 | + Configurable<bool> applyRCTSelections{"applyRCTSelections", true, "decide to apply RCT selections"}; |
| 50 | + |
| 51 | + std::vector<int> eventSelectionBits; |
| 52 | + bool doSumw2 = false; |
| 53 | + |
| 54 | + void init(InitContext&) |
| 55 | + { |
| 56 | + doSumw2 = skipMBGapEvents; // true or false : storage of square erros when jet-jet |
| 57 | + |
| 58 | + AxisSpec centralityAxis = {1200, -10., 110., "Centrality"}; |
| 59 | + |
| 60 | + histos.add("h_collisions", "event status;event status;entries", {HistType::kTH1F, {{4, 0.0, 4.0}}}); |
| 61 | + histos.add("h2_centrality_collisions", "event status vs. centrality;entries;centrality", {HistType::kTH2F, {centralityAxis, {4, 0.0, 4.0}}}, doSumw2); |
| 62 | + auto hColl = histos.get<TH1>(HIST("h_collisions")); |
| 63 | + hColl->GetXaxis()->SetBinLabel(1, "All"); |
| 64 | + hColl->GetXaxis()->SetBinLabel(2, "eventSelection"); |
| 65 | + |
| 66 | + histos.add("h_mcCollMCD_counts_weight", "MC event status;event status;weighted entries", {HistType::kTH1F, {{5, 0.0, 5.0}}}); |
| 67 | + histos.add("h2_centrality_MCD", "mc event status vs. centrality;entries;centrality", {HistType::kTH2F, {centralityAxis, {4, 0.0, 4.0}}}, doSumw2); |
| 68 | + auto hMCD = histos.get<TH1>(HIST("h_mcCollMCD_counts_weight")); |
| 69 | + hMCD->GetXaxis()->SetBinLabel(1, "All"); |
| 70 | + hMCD->GetXaxis()->SetBinLabel(2, "Has MC coll + eventSelection "); |
| 71 | + |
| 72 | + histos.add("h_mcCollMCP_counts_weight", "MC event status;event status;weighted entries", {HistType::kTH1F, {{7, 0.0, 7.0}}}); |
| 73 | + histos.add("h2_centrality_MCP", "mc event status vs. centrality;entries;centrality", {HistType::kTH2F, {centralityAxis, {4, 0.0, 4.0}}}, doSumw2); |
| 74 | + auto hMCP = histos.get<TH1>(HIST("h_mcCollMCP_counts_weight")); |
| 75 | + hMCP->GetXaxis()->SetBinLabel(1, "All"); |
| 76 | + hMCP->GetXaxis()->SetBinLabel(2, "ZVertex"); |
| 77 | + hMCP->GetXaxis()->SetBinLabel(3, "Collision size"); |
| 78 | + hMCP->GetXaxis()->SetBinLabel(4, "eventSelection"); |
| 79 | + hMCP->GetXaxis()->SetBinLabel(5, "eventSelectionMC"); |
| 80 | + |
| 81 | + eventSelectionBits = jetderiveddatautilities::initialiseEventSelectionBits(static_cast<std::string>(eventSelections)); |
| 82 | + } |
| 83 | + |
| 84 | + Produces<o2::aod::SlimCollisions> slimCollisions; |
| 85 | + Produces<o2::aod::SlMcCollisions> slimMcCollisions; |
| 86 | + Produces<o2::aod::SlimTracks> slimTracks; |
| 87 | + Produces<o2::aod::SlimParticles> slimParticles; |
| 88 | + |
| 89 | + Filter trackFilter = (aod::jtrack::pt >= minPt && aod::jtrack::pt < maxPt && aod::jtrack::eta > minEta && aod::jtrack::eta < maxEta); |
| 90 | + Filter eventCuts = (nabs(aod::jcollision::posZ) < vertexZCut && |
| 91 | + (checkCentFT0M ? aod::jcollision::centFT0M : aod::jcollision::centFT0C) >= centralityMin && |
| 92 | + (checkCentFT0M ? aod::jcollision::centFT0M : aod::jcollision::centFT0C) < centralityMax); |
| 93 | + Filter mcCollisionFilter = (nabs(aod::jmccollision::posZ) < vertexZCut && aod::jmccollision::centFT0M >= centralityMin && aod::jmccollision::centFT0M < centralityMax); // no centFT0C for mccollisions, using centFT0M for both |
| 94 | + Filter particleCuts = (aod::jmcparticle::pt >= minPt && aod::jmcparticle::pt < maxPt && aod::jmcparticle::eta > minEta && aod::jmcparticle::eta < maxEta); |
| 95 | + |
| 96 | + void processData(soa::Filtered<o2::aod::JetCollisions>::iterator const& collision, |
| 97 | + soa::Filtered<soa::Join<aod::JetTracks, aod::JTrackExtras, aod::JTrackPIs>> const& tracks) |
| 98 | + { |
| 99 | + histos.fill(HIST("h_collisions"), 0.5); |
| 100 | + float centrality = -1.0; |
| 101 | + checkCentFT0M ? centrality = collision.centFT0M() : centrality = collision.centFT0C(); |
| 102 | + histos.fill(HIST("h2_centrality_collisions"), centrality, 0.5, 1.0); |
| 103 | + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, false, applyRCTSelections)) { |
| 104 | + return; |
| 105 | + } |
| 106 | + histos.fill(HIST("h_collisions"), 1.5); |
| 107 | + |
| 108 | + slimCollisions(collision.posZ()); |
| 109 | + auto slimCollIndex = slimCollisions.lastIndex(); |
| 110 | + for (const auto& track : tracks) { |
| 111 | + float mass = jetderiveddatautilities::mPion; |
| 112 | + float p = track.pt() * std::cosh(track.eta()); |
| 113 | + float energy = std::sqrt(p * p + mass * mass); |
| 114 | + slimTracks(slimCollIndex, track.pt(), track.eta(), track.phi(), track.px(), track.py(), track.pz(), energy); |
| 115 | + } |
| 116 | + } |
| 117 | + PROCESS_SWITCH(SlimTablesProducer, processData, "process collisions and tracks for Data and MCD", false); |
| 118 | + |
| 119 | + void processMCD(soa::Filtered<aod::JetCollisionsMCD>::iterator const& collision, |
| 120 | + soa::Join<aod::JetMcCollisions, aod::JMcCollisionPIs> const&, // join the weight |
| 121 | + soa::Filtered<soa::Join<aod::JetTracks, aod::JTrackExtras, aod::JTrackPIs>> const& tracks) |
| 122 | + { |
| 123 | + float eventWeight = collision.mcCollision_as<soa::Join<aod::JetMcCollisions, aod::JMcCollisionPIs>>().weight(); |
| 124 | + histos.fill(HIST("h_mcCollMCD_counts_weight"), 0.5, eventWeight); |
| 125 | + |
| 126 | + float centrality = -1.0; |
| 127 | + checkCentFT0M ? centrality = collision.centFT0M() : centrality = collision.centFT0C(); |
| 128 | + histos.fill(HIST("h2_centrality_MCD"), centrality, 0.5, eventWeight); |
| 129 | + |
| 130 | + if (!collision.has_mcCollision()) { |
| 131 | + return; |
| 132 | + } |
| 133 | + if (!jetderiveddatautilities::selectCollision(collision, eventSelectionBits, skipMBGapEvents, applyRCTSelections)) { |
| 134 | + return; |
| 135 | + } |
| 136 | + histos.fill(HIST("h_mcCollMCD_counts_weight"), 1.5, eventWeight); |
| 137 | + auto slimCollIndex = slimCollisions.lastIndex(); |
| 138 | + slimCollisions(collision.posZ()); |
| 139 | + for (const auto& track : tracks) { |
| 140 | + float mass = jetderiveddatautilities::mPion; |
| 141 | + float p = track.pt() * std::cosh(track.eta()); |
| 142 | + float energy = std::sqrt(p * p + mass * mass); |
| 143 | + slimTracks(slimCollIndex, track.pt(), track.eta(), track.phi(), track.px(), track.py(), track.pz(), energy); |
| 144 | + } |
| 145 | + } |
| 146 | + PROCESS_SWITCH(SlimTablesProducer, processMCD, "process collisions and tracks for MCD", false); |
| 147 | + |
| 148 | + void processMCP(soa::Filtered<o2::aod::JetMcCollisions>::iterator const& mcCollision, |
| 149 | + soa::SmallGroups<aod::JetCollisionsMCD> const& collisions, |
| 150 | + soa::Filtered<aod::JetParticles> const& particles) |
| 151 | + { |
| 152 | + float eventWeight = mcCollision.weight(); |
| 153 | + float centrality = mcCollision.centFT0M(); // checkCentFT0M ? centrality = mccollision.centFT0M() : centrality = mccollision.centFT0C(); |
| 154 | + histos.fill(HIST("h_mcCollMCP_counts_weight"), 0.5, eventWeight); |
| 155 | + histos.fill(HIST("h2_centrality_MCP"), centrality, 0.5, eventWeight); |
| 156 | + if (std::abs(mcCollision.posZ()) > vertexZCut) { |
| 157 | + return; |
| 158 | + } |
| 159 | + histos.fill(HIST("h_mcCollMCP_counts_weight"), 1.5, eventWeight); |
| 160 | + if (collisions.size() < 1) { |
| 161 | + return; |
| 162 | + } |
| 163 | + histos.fill(HIST("h_mcCollMCP_counts_weight"), 2.5, eventWeight); |
| 164 | + bool hasSel8Coll = false; |
| 165 | + for (auto const& collision : collisions) { |
| 166 | + if (jetderiveddatautilities::selectCollision(collision, eventSelectionBits, skipMBGapEvents, applyRCTSelections)) { // look if the rec collision associated to the mc collision passes the event selection |
| 167 | + hasSel8Coll = true; |
| 168 | + } |
| 169 | + } |
| 170 | + if (!hasSel8Coll) { |
| 171 | + return; |
| 172 | + } |
| 173 | + histos.fill(HIST("h_mcCollMCP_counts_weight"), 3.5, eventWeight); |
| 174 | + if (!jetderiveddatautilities::selectMcCollision(mcCollision, skipMBGapEvents, applyRCTSelections)) { |
| 175 | + return; |
| 176 | + } |
| 177 | + histos.fill(HIST("h_mcCollMCP_counts_weight"), 4.5, eventWeight); |
| 178 | + auto slimMcCollIndex = slimMcCollisions.lastIndex(); |
| 179 | + slimMcCollisions(mcCollision.posZ()); |
| 180 | + for (const auto& particle : particles) { |
| 181 | + slimParticles(slimMcCollIndex, particle.pt(), particle.eta(), particle.phi(), particle.px(), particle.py(), particle.pz()); |
| 182 | + } |
| 183 | + } |
| 184 | + PROCESS_SWITCH(SlimTablesProducer, processMCP, "process mccollisions and mcparticles for MCD", false); |
| 185 | +}; |
| 186 | + |
| 187 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 188 | +{ |
| 189 | + return WorkflowSpec{ |
| 190 | + adaptAnalysisTask<SlimTablesProducer>(cfgc)}; |
| 191 | +} |
0 commit comments