|
| 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 | +/// \brief write relevant information about primary electrons. |
| 13 | +/// \author daiki.sekihata@cern.ch |
| 14 | + |
| 15 | +#include "PWGEM/Dilepton/DataModel/dileptonTables.h" |
| 16 | +#include "PWGEM/Dilepton/Utils/ElectronModule.h" |
| 17 | +#include "PWGEM/Dilepton/Utils/MlResponseO2Track.h" |
| 18 | +#include "PWGEM/Dilepton/Utils/PairUtilities.h" |
| 19 | +#include "PWGLF/DataModel/LFStrangenessTables.h" |
| 20 | + |
| 21 | +#include "Common/Core/TableHelper.h" |
| 22 | +#include "Common/Core/trackUtilities.h" |
| 23 | +#include "Common/DataModel/CollisionAssociationTables.h" |
| 24 | +#include "Common/DataModel/EventSelection.h" |
| 25 | +#include "Common/DataModel/PIDResponseTOF.h" |
| 26 | +#include "Common/DataModel/PIDResponseTPC.h" |
| 27 | +#include "Tools/ML/MlResponse.h" |
| 28 | + |
| 29 | +#include <CCDB/BasicCCDBManager.h> |
| 30 | +#include <CCDB/CcdbApi.h> |
| 31 | +#include <CommonConstants/PhysicsConstants.h> |
| 32 | +#include <DataFormatsCalibration/MeanVertexObject.h> |
| 33 | +#include <DataFormatsParameters/GRPMagField.h> |
| 34 | +#include <DataFormatsParameters/GRPObject.h> |
| 35 | +#include <DetectorsBase/MatLayerCylSet.h> |
| 36 | +#include <DetectorsBase/Propagator.h> |
| 37 | +#include <Framework/ASoAHelpers.h> |
| 38 | +#include <Framework/AnalysisDataModel.h> |
| 39 | +#include <Framework/AnalysisHelpers.h> |
| 40 | +#include <Framework/AnalysisTask.h> |
| 41 | +#include <Framework/Array2D.h> |
| 42 | +#include <Framework/Configurable.h> |
| 43 | +#include <Framework/DataTypes.h> |
| 44 | +#include <Framework/HistogramRegistry.h> |
| 45 | +#include <Framework/HistogramSpec.h> |
| 46 | +#include <Framework/InitContext.h> |
| 47 | +#include <Framework/OutputObjHeader.h> |
| 48 | +#include <Framework/runDataProcessing.h> |
| 49 | +#include <MathUtils/Utils.h> |
| 50 | +#include <PID/PIDTOFParamService.h> |
| 51 | +#include <ReconstructionDataFormats/DCA.h> |
| 52 | +#include <ReconstructionDataFormats/PID.h> |
| 53 | + |
| 54 | +#include <Math/Vector4D.h> // IWYU pragma: keep (do not replace with Math/Vector4Dfwd.h) |
| 55 | +#include <Math/Vector4Dfwd.h> |
| 56 | + |
| 57 | +#include <algorithm> |
| 58 | +#include <array> |
| 59 | +#include <cmath> |
| 60 | +#include <cstdint> |
| 61 | +#include <map> |
| 62 | +#include <string> |
| 63 | +#include <unordered_map> |
| 64 | +#include <utility> |
| 65 | +#include <vector> |
| 66 | + |
| 67 | +#include <math.h> |
| 68 | + |
| 69 | +// using namespace o2; |
| 70 | +// using namespace o2::soa; |
| 71 | +// using namespace o2::framework; |
| 72 | +// using namespace o2::framework::expressions; |
| 73 | +// using namespace o2::constants::physics; |
| 74 | +// using namespace o2::common::core; |
| 75 | + |
| 76 | +struct skimmerPrimaryElectronSCT { |
| 77 | + |
| 78 | + using MyBCs = o2::soa::Join<o2::aod::BCsWithTimestamps, o2::aod::BcSels>; |
| 79 | + using MyCollisions = o2::soa::Join<o2::aod::Collisions, o2::aod::EvSels, o2::aod::EMEvSels>; |
| 80 | + using MyCollisionsWithSWT = o2::soa::Join<MyCollisions, o2::aod::EMSWTriggerBitsTMP>; |
| 81 | + |
| 82 | + using MyTracks = o2::soa::Join<o2::aod::TracksIU, o2::aod::TracksExtra, o2::aod::TracksCovIU, |
| 83 | + o2::aod::pidTPCFullEl, o2::aod::pidTPCFullPi, o2::aod::pidTPCFullKa, o2::aod::pidTPCFullPr, |
| 84 | + o2::aod::pidTOFFullEl, o2::aod::pidTOFFullPi, o2::aod::pidTOFFullKa, o2::aod::pidTOFFullPr, o2::aod::pidTOFbeta, o2::aod::TOFSignal, o2::aod::TOFEvTime>; |
| 85 | + using MyTrack = MyTracks::iterator; |
| 86 | + using MyTracksMC = o2::soa::Join<MyTracks, o2::aod::McTrackLabels, o2::aod::mcTPCTuneOnData>; |
| 87 | + using MyTrackMC = MyTracksMC::iterator; |
| 88 | + |
| 89 | + using MyV0s = o2::soa::Join<o2::aod::V0Datas, o2::aod::V0Covs>; |
| 90 | + using MyCascades = o2::soa::Join<o2::aod::CascDatas, o2::aod::CascCovs>; |
| 91 | + |
| 92 | + struct : o2::framework::ConfigurableGroup { |
| 93 | + o2::framework::Configurable<std::string> ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; |
| 94 | + o2::framework::Configurable<std::string> grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"}; |
| 95 | + o2::framework::Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; |
| 96 | + o2::framework::Configurable<std::string> lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"}; |
| 97 | + o2::framework::Configurable<std::string> mVtxPath{"mVtxPath", "GLO/Calib/MeanVertex", "Path of the mean vertex file"}; |
| 98 | + } ccdbConfig; |
| 99 | + |
| 100 | + o2::framework::Configurable<bool> doSCTwithTracks{"doSCTwithTracks", true, "flag to tag electrons with tracks"}; |
| 101 | + o2::framework::Configurable<bool> doSCTwithV0s{"doSCTwithV0s", false, "flag to tag electrons with v0s"}; |
| 102 | + o2::framework::Configurable<bool> doSCTwithCascades{"doSCTwithCascades", false, "flag to tag electrons with cascades"}; |
| 103 | + |
| 104 | + o2::framework::Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 105 | + o2::ccdb::CcdbApi ccdbApi; |
| 106 | + o2::framework::Service<o2::pid::tof::TOFResponse> mTOFResponse; |
| 107 | + |
| 108 | + o2::framework::SliceCache cache; |
| 109 | + o2::framework::Preslice<o2::aod::TracksIU> perCol_track = o2::aod::track::collisionId; |
| 110 | + o2::framework::Preslice<o2::aod::TrackAssoc> trackIndicesPerCollision = o2::aod::track_association::collisionId; |
| 111 | + o2::framework::Preslice<o2::aod::V0Datas> perCol_v0 = o2::aod::v0data::collisionId; |
| 112 | + o2::framework::Preslice<o2::aod::CascDatas> perCol_casc = o2::aod::cascdata::collisionId; |
| 113 | + |
| 114 | + void init(o2::framework::InitContext& initContext) |
| 115 | + { |
| 116 | + mRunNumber = 0; |
| 117 | + d_bz = 0; |
| 118 | + |
| 119 | + LOGF(info, "initializing CCDB"); |
| 120 | + ccdb->setURL(ccdbConfig.ccdburl.value); |
| 121 | + ccdb->setCaching(true); |
| 122 | + ccdb->setLocalObjectValidityChecking(); |
| 123 | + ccdb->setFatalWhenNull(false); |
| 124 | + // ccdbApi.init(ccdbConfig.ccdburl); |
| 125 | + // mTOFResponse->initSetup(ccdb, initContext); |
| 126 | + |
| 127 | + LOGF(info, "initializing electronModule"); |
| 128 | + electronModule.init(cfgEelectronCut, cfgEelectronPFCut, cfgHadronCut, cfgV0Cut, cfgCascadeCut, cfgDFeT, cfgDFeV0, cfgDFeC, initContext, ccdb, mTOFResponse, ccdbConfig.ccdburl.value); |
| 129 | + // electronModule.setTOFResponse(mTOFResponse); |
| 130 | + electronModule.addHistograms(mRegistry); |
| 131 | + // electronModule.doPFB(doPF.value); |
| 132 | + |
| 133 | + electronModule.doSCTwithTracks(doSCTwithTracks.value); |
| 134 | + electronModule.doSCTwithV0s(doSCTwithV0s.value); |
| 135 | + electronModule.doSCTwithCascades(doSCTwithCascades.value); |
| 136 | + } |
| 137 | + |
| 138 | + o2::pwgem::dilepton::utils::ElectronModule electronModule; |
| 139 | + o2::pwgem::dilepton::utils::ElectronProducts products; |
| 140 | + o2::pwgem::dilepton::utils::electronCut cfgEelectronCut; |
| 141 | + o2::pwgem::dilepton::utils::electronPFCut cfgEelectronPFCut; |
| 142 | + o2::pwgem::dilepton::utils::hadronCut cfgHadronCut; |
| 143 | + o2::pwgem::dilepton::utils::v0Cut cfgV0Cut; |
| 144 | + o2::pwgem::dilepton::utils::cascadeCut cfgCascadeCut; |
| 145 | + o2::pwgem::dilepton::utils::cfgDFeT cfgDFeT; |
| 146 | + o2::pwgem::dilepton::utils::cfgDFeV0 cfgDFeV0; |
| 147 | + o2::pwgem::dilepton::utils::cfgDFeC cfgDFeC; |
| 148 | + |
| 149 | + o2::framework::HistogramRegistry mRegistry{"output", {}, o2::framework::OutputObjHandlingPolicy::AnalysisObject, false, false}; |
| 150 | + // ---------- for data ---------- |
| 151 | + |
| 152 | + int mRunNumber{0}; |
| 153 | + float d_bz{0}; |
| 154 | + o2::base::Propagator::MatCorrType matCorr = o2::base::Propagator::MatCorrType::USEMatCorrLUT; |
| 155 | + o2::dataformats::VertexBase mVtx; |
| 156 | + // const o2::dataformats::MeanVertexObject* mMeanVtx = nullptr; |
| 157 | + o2::base::MatLayerCylSet* lut = nullptr; |
| 158 | + |
| 159 | + template <typename TBC> |
| 160 | + void initCCDB(TBC const& bc) |
| 161 | + { |
| 162 | + if (mRunNumber == bc.runNumber()) { |
| 163 | + return; |
| 164 | + } |
| 165 | + |
| 166 | + // load matLUT for this timestamp |
| 167 | + if (!lut) { |
| 168 | + LOG(info) << "Loading material look-up table for timestamp: " << bc.timestamp(); |
| 169 | + lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->getForTimeStamp<o2::base::MatLayerCylSet>(ccdbConfig.lutPath, bc.timestamp())); |
| 170 | + } else { |
| 171 | + LOG(info) << "Material look-up table already in place. Not reloading."; |
| 172 | + } |
| 173 | + |
| 174 | + auto run3grp_timestamp = bc.timestamp(); |
| 175 | + o2::parameters::GRPMagField* grpmag = 0x0; |
| 176 | + o2::parameters::GRPObject* grpo = ccdb->getForTimeStamp<o2::parameters::GRPObject>(ccdbConfig.grpPath, run3grp_timestamp); |
| 177 | + if (grpo) { |
| 178 | + o2::base::Propagator::initFieldFromGRP(grpo); |
| 179 | + o2::base::Propagator::Instance()->setMatLUT(lut); |
| 180 | + // mMeanVtx = ccdb->getForTimeStamp<o2::dataformats::MeanVertexObject>(ccdbConfig.mVtxPath, bc.timestamp()); |
| 181 | + // Fetch magnetic field from ccdb for current collision |
| 182 | + d_bz = grpo->getNominalL3Field(); |
| 183 | + LOG(info) << "Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << d_bz << " kZG"; |
| 184 | + } else { |
| 185 | + grpmag = ccdb->getForTimeStamp<o2::parameters::GRPMagField>(ccdbConfig.grpmagPath, run3grp_timestamp); |
| 186 | + if (!grpmag) { |
| 187 | + LOG(fatal) << "Got nullptr from CCDB for path " << ccdbConfig.grpmagPath << " of object GRPMagField and " << ccdbConfig.grpPath << " of object GRPObject for timestamp " << run3grp_timestamp; |
| 188 | + } |
| 189 | + o2::base::Propagator::initFieldFromGRP(grpmag); |
| 190 | + o2::base::Propagator::Instance()->setMatLUT(lut); |
| 191 | + // mMeanVtx = ccdb->getForTimeStamp<o2::dataformats::MeanVertexObject>(ccdbConfig.mVtxPath, bc.timestamp()); |
| 192 | + |
| 193 | + // Fetch magnetic field from ccdb for current collision |
| 194 | + d_bz = std::lround(5.f * grpmag->getL3Current() / 30000.f); |
| 195 | + LOG(info) << "Retrieved GRP for timestamp " << run3grp_timestamp << " with magnetic field of " << d_bz << " kZG"; |
| 196 | + } |
| 197 | + |
| 198 | + mRunNumber = bc.runNumber(); |
| 199 | + } |
| 200 | + |
| 201 | + //! type of V0. 0: built solely for cascades (does not pass standard V0 cut), 1: standard 2, 3: photon-like with TPC-only use. Regular analysis should always use type 1. |
| 202 | + o2::framework::expressions::Filter v0Filter = o2::aod::v0data::v0Type == uint8_t(1) && o2::aod::v0data::v0cosPA > cfgV0Cut.cfg_min_cospa&& o2::aod::v0data::dcaV0daughters<cfgV0Cut.cfg_max_dca2legs && nabs(o2::aod::v0data::dcanegtopv)> cfgV0Cut.cfg_min_dcaxy&& nabs(o2::aod::v0data::dcanegtopv) > cfgV0Cut.cfg_min_dcaxy; |
| 203 | + using filteredMyV0s = o2::soa::Filtered<MyV0s>; |
| 204 | + |
| 205 | + o2::framework::expressions::Filter cascadeFilter = nabs(o2::aod::cascdata::dcanegtopv) > cfgCascadeCut.cfg_min_dcaxy_v0leg&& nabs(o2::aod::cascdata::dcanegtopv) > cfgCascadeCut.cfg_min_dcaxy_v0leg&& nabs(o2::aod::cascdata::dcabachtopv) > cfgCascadeCut.cfg_min_dcaxy_bachelor&& o2::aod::cascdata::dcacascdaughters < cfgCascadeCut.cfg_max_dcadau&& o2::aod::cascdata::dcaV0daughters < cfgCascadeCut.cfg_max_dcadau_v0; |
| 206 | + using filteredMyCascades = o2::soa::Filtered<MyCascades>; |
| 207 | + |
| 208 | + void processRec_SA(MyCollisions const& collisions, MyBCs const& bcs, MyTracks const& tracks, filteredMyV0s const& v0s, filteredMyCascades const& cascades) |
| 209 | + { |
| 210 | + initCCDB(bcs.begin()); |
| 211 | + electronModule.processWithoutTTCA<false, false>(bcs, collisions, tracks, v0s, cascades, nullptr, nullptr, products, mRegistry); |
| 212 | + } |
| 213 | + PROCESS_SWITCH(skimmerPrimaryElectronSCT, processRec_SA, "process reconstructed info only", true); // standalone |
| 214 | + |
| 215 | + void processRec_TTCA(MyCollisions const& collisions, MyBCs const& bcs, MyTracks const& tracks, o2::aod::TrackAssoc const& trackIndices, filteredMyV0s const& v0s, filteredMyCascades const& cascades) |
| 216 | + { |
| 217 | + initCCDB(bcs.begin()); |
| 218 | + electronModule.processWithTTCA<false, false>(bcs, collisions, tracks, v0s, cascades, trackIndices, nullptr, nullptr, products, mRegistry, cache, perCol_track, trackIndicesPerCollision, perCol_v0, perCol_casc); |
| 219 | + } |
| 220 | + PROCESS_SWITCH(skimmerPrimaryElectronSCT, processRec_TTCA, "process reconstructed info only", false); // with TTCA |
| 221 | + |
| 222 | + void processRec_SA_SWT(MyCollisionsWithSWT const& collisions, MyBCs const& bcs, MyTracks const& tracks, filteredMyV0s const& v0s, filteredMyCascades const& cascades) |
| 223 | + { |
| 224 | + initCCDB(bcs.begin()); |
| 225 | + electronModule.processWithoutTTCA<false, true>(bcs, collisions, tracks, v0s, cascades, nullptr, nullptr, products, mRegistry); |
| 226 | + } |
| 227 | + PROCESS_SWITCH(skimmerPrimaryElectronSCT, processRec_SA_SWT, "process reconstructed info only", false); // standalone with swt |
| 228 | + |
| 229 | + void processRec_TTCA_SWT(MyCollisionsWithSWT const& collisions, MyBCs const& bcs, MyTracks const& tracks, o2::aod::TrackAssoc const& trackIndices, filteredMyV0s const& v0s, filteredMyCascades const& cascades) |
| 230 | + { |
| 231 | + initCCDB(bcs.begin()); |
| 232 | + electronModule.processWithTTCA<false, true>(bcs, collisions, tracks, v0s, cascades, trackIndices, nullptr, nullptr, products, mRegistry, cache, perCol_track, trackIndicesPerCollision, perCol_v0, perCol_casc); |
| 233 | + } |
| 234 | + PROCESS_SWITCH(skimmerPrimaryElectronSCT, processRec_TTCA_SWT, "process reconstructed info only", false); // with TTCA with swt |
| 235 | + |
| 236 | + // ---------- for MC ---------- |
| 237 | + |
| 238 | + void processMC_SA(o2::soa::Join<MyCollisions, o2::aod::McCollisionLabels> const& collisions, MyBCs const& bcs, MyTracksMC const& tracks, filteredMyV0s const& v0s, filteredMyCascades const& cascades, o2::aod::McCollisions const& mcCollisions, o2::aod::McParticles const& mcParticles) |
| 239 | + { |
| 240 | + initCCDB(bcs.begin()); |
| 241 | + electronModule.processWithoutTTCA<true, false>(bcs, collisions, tracks, v0s, cascades, mcCollisions, mcParticles, products, mRegistry); |
| 242 | + } |
| 243 | + PROCESS_SWITCH(skimmerPrimaryElectronSCT, processMC_SA, "process reconstructed and MC info ", false); // without TTCA in MC |
| 244 | + |
| 245 | + void processMC_TTCA(o2::soa::Join<MyCollisions, o2::aod::McCollisionLabels> const& collisions, MyBCs const& bcs, MyTracksMC const& tracks, o2::aod::TrackAssoc const& trackIndices, filteredMyV0s const& v0s, filteredMyCascades const& cascades, o2::aod::McCollisions const& mcCollisions, o2::aod::McParticles const& mcParticles) |
| 246 | + { |
| 247 | + initCCDB(bcs.begin()); |
| 248 | + electronModule.processWithTTCA<true, false>(bcs, collisions, tracks, v0s, cascades, trackIndices, mcCollisions, mcParticles, products, mRegistry, cache, perCol_track, trackIndicesPerCollision, perCol_v0, perCol_casc); |
| 249 | + } |
| 250 | + PROCESS_SWITCH(skimmerPrimaryElectronSCT, processMC_TTCA, "process reconstructed info only", false); // with TTCA in MC |
| 251 | +}; |
| 252 | + |
| 253 | +struct associateAmbiguousElectron { |
| 254 | + o2::framework::Produces<o2::aod::EMAmbiguousElectronSelfIds> em_amb_ele_ids; |
| 255 | + |
| 256 | + o2::framework::SliceCache cache; |
| 257 | + o2::framework::PresliceUnsorted<o2::aod::EMPrimaryElectrons> perTrack = o2::aod::emprimaryelectron::trackId; |
| 258 | + std::vector<int> ambele_self_Ids; |
| 259 | + |
| 260 | + void process(o2::aod::EMPrimaryElectrons const& electrons) |
| 261 | + { |
| 262 | + for (const auto& electron : electrons) { |
| 263 | + auto electrons_with_same_trackId = electrons.sliceBy(perTrack, electron.trackId()); |
| 264 | + ambele_self_Ids.reserve(electrons_with_same_trackId.size()); |
| 265 | + for (const auto& amb_ele : electrons_with_same_trackId) { |
| 266 | + if (amb_ele.globalIndex() == electron.globalIndex()) { // don't store myself. |
| 267 | + continue; |
| 268 | + } |
| 269 | + ambele_self_Ids.emplace_back(amb_ele.globalIndex()); |
| 270 | + } |
| 271 | + em_amb_ele_ids(ambele_self_Ids); |
| 272 | + ambele_self_Ids.clear(); |
| 273 | + ambele_self_Ids.shrink_to_fit(); |
| 274 | + } |
| 275 | + } |
| 276 | +}; |
| 277 | +o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc) |
| 278 | +{ |
| 279 | + o2::pid::tof::TOFResponseImpl::metadataInfo.initMetadata(cfgc); |
| 280 | + return o2::framework::WorkflowSpec{ |
| 281 | + adaptAnalysisTask<skimmerPrimaryElectronSCT>(cfgc, o2::framework::TaskName{"skimmer-primary-electron-sct"}), |
| 282 | + adaptAnalysisTask<associateAmbiguousElectron>(cfgc, o2::framework::TaskName{"associate-ambiguous-electron"})}; |
| 283 | +} |
0 commit comments