|
| 1 | +// Copyright 2019-2022 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 tripletCleaner.h |
| 13 | +/// \brief triplet cleaner class |
| 14 | +/// \author anton.riedel@tum.de, TU München, anton.riedel@tum.de |
| 15 | + |
| 16 | +#ifndef PWGCF_FEMTO_CORE_MCPARTICLECLEANER_H_ |
| 17 | +#define PWGCF_FEMTO_CORE_MCPARTICLECLEANER_H_ |
| 18 | + |
| 19 | +#include "Framework/Configurable.h" |
| 20 | + |
| 21 | +#include <vector> |
| 22 | + |
| 23 | +namespace o2::analysis::femto |
| 24 | +{ |
| 25 | +namespace mcparticlecleaner |
| 26 | +{ |
| 27 | + |
| 28 | +template <const char* Prefix> |
| 29 | +struct ConfMcParticleCleaner : o2::framework::ConfigurableGroup { |
| 30 | + std::string prefix = std::string(Prefix); |
| 31 | + o2::framework::Configurable<bool> cutOnMcTruth{"cutOnMcTruth", false, "Perform cuts based on MC truth information. If false, all following options are ignored"}; |
| 32 | + o2::framework::Configurable<int> pdgCode{"pdgCode", 221, "Only consider particles with this exact pdg code (including the sign!)"}; |
| 33 | + o2::framework::Configurable<bool> rejectedParticleWithoutMcInformation{"rejectedParticleWithoutMcInformation", true, "If true, all particles which have no associated MC information, are rejected by default"}; |
| 34 | + o2::framework::Configurable<std::vector<int>> requiredMotherPdgCodes{"requiredMotherPdgCodes", {}, "Only consider particles whose mothers have one of the supplied pdg codes (inclduing the sign!)"}; |
| 35 | + o2::framework::Configurable<std::vector<int>> rejectMotherPdgCodes{"rejectMotherPdgCodes", {}, "Only consider particles whose mothers do not have one of the supplied pdg codes (inclduing the sign!)"}; |
| 36 | + o2::framework::Configurable<std::vector<int>> requiredPartonicMotherPdgCodes{"requiredPartonicMotherPdgCodes", {}, "Only consider particles whose partonic mothers have one of the supplied pdg codes (inclduing the sign!)"}; |
| 37 | + o2::framework::Configurable<std::vector<int>> rejectPartonicMotherPdgCodes{"rejectPartonicMotherPdgCodes", {}, "Only consider particles whose mothers do not have one of the supplied pdg codes (inclduing the sign!)"}; |
| 38 | +}; |
| 39 | + |
| 40 | +class McParticleCleaner |
| 41 | +{ |
| 42 | + public: |
| 43 | + McParticleCleaner() = default; |
| 44 | + ~McParticleCleaner() = default; |
| 45 | + |
| 46 | + template <typename T> |
| 47 | + void init(T const& confMpc) |
| 48 | + { |
| 49 | + mCutOnMcTruth = confMpc.cutOnMcTruth.value; |
| 50 | + mRejectParticleWithoutMcInformation = confMpc.rejectedParticleWithoutMcInformation.value; |
| 51 | + mPdgCode = confMpc.pdgCode.value; |
| 52 | + mRequiredMotherPdgCodes = confMpc.requiredMotherPdgCodes.value; |
| 53 | + mRejectMotherPdgCodes = confMpc.rejectMotherPdgCodes.value; |
| 54 | + mRequiredPartonicMotherPdgCodes = confMpc.requiredPartonicMotherPdgCodes.value; |
| 55 | + mRejectPartonicMotherPdgCodes = confMpc.rejectPartonicMotherPdgCodes.value; |
| 56 | + } |
| 57 | + |
| 58 | + template <typename T1, typename T2, typename T3, typename T4> |
| 59 | + bool checkCuts(T1 const& particle, T2 const& /*mcParticles*/, T3 const& /*mcMothers*/, T4 const& /*mcPartonicMothers*/) |
| 60 | + { |
| 61 | + // check whether we apply cuts at all |
| 62 | + if (!mCutOnMcTruth) { |
| 63 | + return true; |
| 64 | + } |
| 65 | + // check if we even have an associated mc particle |
| 66 | + if (!particle.has_fMcParticle()) { |
| 67 | + if (mRejectParticleWithoutMcInformation) { |
| 68 | + return false; |
| 69 | + } else { |
| 70 | + return true; |
| 71 | + } |
| 72 | + } |
| 73 | + // perfrom cuts based on mc information of the particle itself |
| 74 | + auto mcParticle = particle.template fMcParticle_as<T2>(); |
| 75 | + if (mPdgCode != mcParticle.pdgCode()) { |
| 76 | + return false; |
| 77 | + } |
| 78 | + |
| 79 | + // perfrom cuts based on mc information of the mothers |
| 80 | + auto mother = particle.template fMcMother_as<T3>(); |
| 81 | + |
| 82 | + // if list is empty, set it to true and skip the looop |
| 83 | + bool hasMotherWithRequiredPdgCode = mRequiredMotherPdgCodes.empty(); |
| 84 | + for (int pdgCode : mRequiredMotherPdgCodes) { |
| 85 | + if (pdgCode == mother.pdgCode()) { |
| 86 | + hasMotherWithRequiredPdgCode = true; |
| 87 | + break; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + bool hasMotherWithRejectedPdgCode = true; |
| 92 | + for (int pdgCode : mRejectMotherPdgCodes) { |
| 93 | + if (pdgCode == mother.pdgCode()) { |
| 94 | + hasMotherWithRejectedPdgCode = false; |
| 95 | + break; |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + // perfrom cuts based on mc information of the partonic mothers |
| 100 | + auto partonicMother = particle.template fMcPartMoth_as<T4>(); |
| 101 | + |
| 102 | + // if list is empty, set it to true and skip the looop |
| 103 | + bool hasPartonicMotherWithRequiredPdgCode = mRequiredPartonicMotherPdgCodes.empty(); |
| 104 | + for (int pdgCode : mRequiredPartonicMotherPdgCodes) { |
| 105 | + if (pdgCode == partonicMother.pdgCode()) { |
| 106 | + hasPartonicMotherWithRequiredPdgCode = true; |
| 107 | + break; |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + bool hasPartonicMotherWithRejectedPdgCode = true; |
| 112 | + for (int pdgCode : mRejectPartonicMotherPdgCodes) { |
| 113 | + if (pdgCode == partonicMother.pdgCode()) { |
| 114 | + hasPartonicMotherWithRejectedPdgCode = false; |
| 115 | + break; |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + return hasMotherWithRequiredPdgCode && !hasMotherWithRejectedPdgCode && |
| 120 | + hasPartonicMotherWithRequiredPdgCode && !hasPartonicMotherWithRejectedPdgCode; |
| 121 | + } |
| 122 | + |
| 123 | + private: |
| 124 | + bool mCutOnMcTruth = false; |
| 125 | + bool mRejectParticleWithoutMcInformation = true; |
| 126 | + int mPdgCode = 0; |
| 127 | + std::vector<int> mRequiredMotherPdgCodes{}; |
| 128 | + std::vector<int> mRejectMotherPdgCodes{}; |
| 129 | + std::vector<int> mRequiredPartonicMotherPdgCodes{}; |
| 130 | + std::vector<int> mRejectPartonicMotherPdgCodes{}; |
| 131 | +}; |
| 132 | + |
| 133 | +} // namespace mcparticlecleaner |
| 134 | +} // namespace o2::analysis::femto |
| 135 | + |
| 136 | +#endif // PWGCF_FEMTO_CORE_MCPARTICLECLEANER_H_ |
0 commit comments