|
| 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 extended3bodyCreator.cxx |
| 13 | + |
| 14 | +#include <cmath> |
| 15 | +#include <array> |
| 16 | +#include <cstdlib> |
| 17 | +#include <string> |
| 18 | +#include <algorithm> |
| 19 | + |
| 20 | +#include "Framework/runDataProcessing.h" |
| 21 | +#include "Framework/AnalysisTask.h" |
| 22 | +#include "Framework/AnalysisDataModel.h" |
| 23 | +#include "Framework/ASoAHelpers.h" |
| 24 | +#include "ReconstructionDataFormats/Track.h" |
| 25 | +#include "Common/Core/trackUtilities.h" |
| 26 | +#include "Common/DataModel/Multiplicity.h" |
| 27 | +#include "Common/DataModel/Centrality.h" |
| 28 | +#include "PWGLF/DataModel/pidTOFGeneric.h" |
| 29 | +#include "PWGLF/DataModel/Reduced3BodyTables.h" |
| 30 | +#include "PWGLF/DataModel/Reduced3BodyTablesLocal.h" |
| 31 | +#include "Common/DataModel/EventSelection.h" |
| 32 | +#include "Common/DataModel/PIDResponse.h" |
| 33 | +#include "Common/Core/PID/PIDTOF.h" |
| 34 | +#include "TableHelper.h" |
| 35 | +#include "Tools/KFparticle/KFUtilities.h" |
| 36 | + |
| 37 | +#include "EventFiltering/Zorro.h" |
| 38 | +#include "EventFiltering/ZorroSummary.h" |
| 39 | + |
| 40 | +#include "DetectorsBase/Propagator.h" |
| 41 | +#include "DetectorsBase/GeometryManager.h" |
| 42 | +#include "DataFormatsParameters/GRPObject.h" |
| 43 | +#include "DataFormatsParameters/GRPMagField.h" |
| 44 | +#include "CCDB/BasicCCDBManager.h" |
| 45 | + |
| 46 | +#ifndef HomogeneousField |
| 47 | +#define HomogeneousField |
| 48 | +#endif |
| 49 | + |
| 50 | +// includes KFParticle |
| 51 | +#include "KFParticle.h" |
| 52 | +#include "KFPTrack.h" |
| 53 | +#include "KFPVertex.h" |
| 54 | +#include "KFParticleBase.h" |
| 55 | +#include "KFVertex.h" |
| 56 | + |
| 57 | +using namespace o2; |
| 58 | +using namespace o2::framework; |
| 59 | +using namespace o2::framework::expressions; |
| 60 | + |
| 61 | +using ReducedCollisionsMultsCents = soa::Join<aod::RedCollisions, aod::RedPVMults, aod::RedCentFT0Cs>; |
| 62 | + |
| 63 | +struct extended3bodyCreator { |
| 64 | + |
| 65 | + Produces<aod::RedLocCollisions> reducedCollisions; |
| 66 | + Produces<aod::RedLocPVMults> reducedPVMults; |
| 67 | + Produces<aod::RedLocCentFT0Cs> reducedCentFT0Cs; |
| 68 | + Produces<aod::RedLocDecay3Bodys> reducedDecay3Bodys; |
| 69 | + Produces<aod::RedLoc3BodyInfo> reduced3BodyInfo; |
| 70 | + Produces<aod::StoredRedLocIUTracks> reducedFullTracksPIDIU; |
| 71 | + |
| 72 | + Service<o2::ccdb::BasicCCDBManager> ccdb; |
| 73 | + |
| 74 | + // CCDB options |
| 75 | + Configurable<std::string> ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"}; |
| 76 | + Configurable<std::string> grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"}; |
| 77 | + Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"}; |
| 78 | + |
| 79 | + int mRunNumber; |
| 80 | + float d_bz; |
| 81 | + |
| 82 | + HistogramRegistry registry{"registry", {}}; |
| 83 | + |
| 84 | + void init(InitContext&) |
| 85 | + { |
| 86 | + mRunNumber = 0; |
| 87 | + |
| 88 | + ccdb->setURL(ccdburl); |
| 89 | + ccdb->setCaching(true); |
| 90 | + ccdb->setLocalObjectValidityChecking(); |
| 91 | + ccdb->setFatalWhenNull(false); |
| 92 | + } |
| 93 | + |
| 94 | + void initCCDBfromRunNumber(int runNumber) |
| 95 | + { |
| 96 | + // Check if the CCDB data for this run is already cached |
| 97 | + if (ccdbCache.find(runNumber) != ccdbCache.end()) { |
| 98 | + LOG(debug) << "CCDB data already cached for run " << runNumber; |
| 99 | + |
| 100 | + // get magnetic field info from cache |
| 101 | + float d_bz = ccdbCache[runNumber]; |
| 102 | + |
| 103 | + // Set magnetic field for KF vertexing |
| 104 | +#ifdef HomogeneousField |
| 105 | + KFParticle::SetField(d_bz); |
| 106 | +#endif |
| 107 | + // Set field for DCAfitter |
| 108 | + fitter3body.setBz(d_bz); |
| 109 | + |
| 110 | + if (useMatCorrType == 2) { |
| 111 | + // setMatLUT only after magfield has been initalized |
| 112 | + o2::base::Propagator::Instance()->setMatLUT(lut); |
| 113 | + } |
| 114 | + } else { // fetch data from CCDB and cache it |
| 115 | + o2::parameters::GRPMagField* grpmag = ccdb->getForRun<o2::parameters::GRPMagField>(grpmagPath, runNumber); |
| 116 | + if (!grpmag) { |
| 117 | + LOG(fatal) << "Got nullptr from CCDB for path " << grpmagPath << " of object GRPMagField and " << grpPath << " of object GRPObject for run number " << runNumber; |
| 118 | + } |
| 119 | + o2::base::Propagator::initFieldFromGRP(grpmag); |
| 120 | + // Fetch magnetic field from ccdb for current collision |
| 121 | + d_bz = o2::base::Propagator::Instance()->getNominalBz(); |
| 122 | + LOG(info) << "Retrieved GRP for run number " << runNumber << " with magnetic field of " << d_bz << " kZG"; |
| 123 | + |
| 124 | + // Set magnetic field for KF vertexing |
| 125 | +#ifdef HomogeneousField |
| 126 | + KFParticle::SetField(d_bz); |
| 127 | +#endif |
| 128 | + // Set field for DCAfitter |
| 129 | + fitter3body.setBz(d_bz); |
| 130 | + |
| 131 | + if (useMatCorrType == 2) { |
| 132 | + // setMatLUT only after magfield has been initalized |
| 133 | + o2::base::Propagator::Instance()->setMatLUT(lut); |
| 134 | + } |
| 135 | + |
| 136 | + // cache magnetic field info |
| 137 | + ccdbCache[runNumber] = d_bz; |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + //------------------------------------------------------------------ |
| 142 | + // function to fit KFParticle 3body vertex |
| 143 | + template <typename TKFParticle> |
| 144 | + void fit3bodyVertex(TKFParticle& kfpProton, TKFParticle& kfpPion, TKFParticle& kfpDeuteron, TKFParticle& KFHt) |
| 145 | + { |
| 146 | + // Construct 3body vertex |
| 147 | + int nDaughters3body = 3; |
| 148 | + const KFParticle* Daughters3body[3] = {&kfpProton, &kfpPion, &kfpDeuteron}; |
| 149 | + KFHt.SetConstructMethod(2); |
| 150 | + try { |
| 151 | + KFHt.Construct(Daughters3body, nDaughters3body); |
| 152 | + } catch (std::runtime_error& e) { |
| 153 | + LOG(debug) << "Failed to create Hyper triton 3-body vertex." << e.what(); |
| 154 | + return; |
| 155 | + } |
| 156 | + LOG(debug) << "Hypertriton vertex constructed."; |
| 157 | + } |
| 158 | + |
| 159 | + void processCollisions(ReducedCollisionsMultsCents const& collisions) |
| 160 | + { |
| 161 | + |
| 162 | + for (const auto& collision : collisions) { |
| 163 | + reducedCollisions( |
| 164 | + collision.posX(), collision.posY(), collision.posZ(), |
| 165 | + collision.covXX(), collision.covXY(), collision.covYY(), collision.covXZ(), collision.covYZ(), collision.covZZ(), |
| 166 | + collision.flags(), collision.chi2(), collision.numContrib(), |
| 167 | + collision.collisionTime(), collision.collisionTimeRes(), |
| 168 | + collision.runNumber()); |
| 169 | + reducedPVMults(collision.multNTracksPV()); |
| 170 | + reducedCentFT0Cs(collision.centFT0C()); |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + void processTracks(aod::RedIUTracks const& tracks) |
| 175 | + { |
| 176 | + for (const auto& track : tracks) { |
| 177 | + reducedFullTracksPIDIU( |
| 178 | + // TrackIU |
| 179 | + track.collisionId(), |
| 180 | + track.x(), track.alpha(), |
| 181 | + track.y(), track.z(), track.snp(), track.tgl(), |
| 182 | + track.signed1Pt(), |
| 183 | + // TracksCovIU |
| 184 | + track.sigmaY(), track.sigmaZ(), track.sigmaSnp(), track.sigmaTgl(), track.sigma1Pt(), |
| 185 | + track.rhoZY(), track.rhoSnpY(), track.rhoSnpZ(), track.rhoTglY(), track.rhoTglZ(), |
| 186 | + track.rhoTglSnp(), track.rho1PtY(), track.rho1PtZ(), track.rho1PtSnp(), track.rho1PtTgl(), |
| 187 | + // TracksExtra |
| 188 | + track.tpcInnerParam(), track.flags(), track.itsClusterSizes(), |
| 189 | + track.tpcNClsFindable(), track.tpcNClsFindableMinusFound(), track.tpcNClsFindableMinusCrossedRows(), |
| 190 | + track.trdPattern(), track.tpcChi2NCl(), track.tofChi2(), |
| 191 | + track.tpcSignal(), track.tofExpMom(), |
| 192 | + // PID |
| 193 | + track.tpcNSigmaPr(), track.tpcNSigmaPi(), track.tpcNSigmaDe(), |
| 194 | + track.tofNSigmaDe()); |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + void process3Bodys(ReducedCollisionsMultsCents const&, aod::RedIUTracks const&, aod::RedDecay3Bodys const& decay3bodys) |
| 199 | + { |
| 200 | + for (const auto& d3body : decay3bodys) { |
| 201 | + |
| 202 | + // save reduced decay3body table |
| 203 | + reducedDecay3Bodys(d3body.collisionId(), d3body.track0Id(), d3body.track1Id(), d3body.track2Id()); |
| 204 | + |
| 205 | + // get collision |
| 206 | + auto collision = d3body.template collision_as<ReducedCollisionsMultsCents>(); |
| 207 | + initCCDBfromRunNumber(collision.runNumber()); |
| 208 | + |
| 209 | + // Get daughter tracks |
| 210 | + const auto daughter0 = d3body.template track0_as<RedIUTracks>(); |
| 211 | + const auto daughter1 = d3body.template track1_as<RedIUTracks>(); |
| 212 | + const auto daughter2 = d3body.template track2_as<RedIUTracks>(); |
| 213 | + |
| 214 | + // get trackParCov daughters |
| 215 | + auto trackParCovPos = getTrackParCov(daughter0); |
| 216 | + auto trackParCovNeg = getTrackParCov(daughter1); |
| 217 | + auto trackParCovBach = getTrackParCov(daughter2); |
| 218 | + |
| 219 | + // create KFParticle daughters |
| 220 | + KFParticle kfpProton, kfpPion, kfpDeuteron; |
| 221 | + if (daughter2.sign() > 0) { |
| 222 | + kfpProton = createKFParticleFromTrackParCov(trackParCovPos, daughter0.sign(), constants::physics::MassProton); |
| 223 | + kfpPion = createKFParticleFromTrackParCov(trackParCovNeg, daughter1.sign(), constants::physics::MassPionCharged); |
| 224 | + } else if (!(daughter2.sign() > 0)) { |
| 225 | + kfpProton = createKFParticleFromTrackParCov(trackParCovNeg, daughter1.sign(), constants::physics::MassProton); |
| 226 | + kfpPion = createKFParticleFromTrackParCov(trackParCovPos, daughter0.sign(), constants::physics::MassPionCharged); |
| 227 | + } |
| 228 | + kfpDeuteron = createKFParticleFromTrackParCov(trackParCovBach, daughter2.sign(), constants::physics::MassDeuteron); |
| 229 | + |
| 230 | + // fit 3body vertex |
| 231 | + KFParticle KFHt; |
| 232 | + fit3bodyVertex(kfpProton, kfpPion, kfpDeuteron, KFHt); |
| 233 | + |
| 234 | + // calculate radius and phi |
| 235 | + auto radius = std::sqrt(KFHt.GetX() * KFHt.GetX() + KFHt.GetY() * KFHt.GetY()); |
| 236 | + float phi, sigma; |
| 237 | + KFHt.GetPhi(phi, sigma); |
| 238 | + |
| 239 | + // fill 3body info table |
| 240 | + reduced3BodyInfo(radius, phi, KFHt.GetZ()); |
| 241 | + } // end decay3body loop |
| 242 | + } |
| 243 | +}; |
| 244 | + |
| 245 | +struct extended3bodyInitializer { |
| 246 | + Spawns<aod::RedLocIUTracks> reducedLocTracksIU; |
| 247 | + void init(InitContext const&) {} |
| 248 | +}; |
| 249 | + |
| 250 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 251 | +{ |
| 252 | + return WorkflowSpec{ |
| 253 | + adaptAnalysisTask<extended3bodyInitializer>(cfgc), |
| 254 | + adaptAnalysisTask<extended3bodyCreator>(cfgc), |
| 255 | + }; |
| 256 | +} |
0 commit comments