16#define TDS() evtStore()->tds()
18#define TDS() evtStore()
22const std::vector<const xAOD::TruthParticle*>* findVector(
23 const std::map<std::string, std::vector<const xAOD::TruthParticle*>>&
map,
24 const std::string& key) {
25 auto it =
map.find(key);
26 return it ==
map.end() ? nullptr : &it->second;
29constexpr const char* kBeforeFSR =
"_beforeFSR";
30constexpr const char* kAfterFSR =
"_afterFSR";
34using ROOT::Math::PtEtaPhiMVector;
37 const std::string&
name,
const std::vector<std::string>& truthCollection)
40 "Prefix to apply to all names to avoid overwriting");
52 return std::find(v->begin(), v->end(), p) != v->end();
58 PtEtaPhiMVector& p4) {
67 const auto uidx =
static_cast<std::size_t
>(idx);
68 if (uidx >= v->size())
78 if (key.find(
"GammaRad") != std::string::npos) {
79 auto it = std::max_element(
80 particles.begin(), particles.end(),
81 [](
const auto*
a,
const auto* b) { return a->pt() < b->pt(); });
82 if (it != particles.end() &&
83 (!bestPhoton || (*it)->
pt() > bestPhoton->
pt()))
101 std::vector<int>& pdgIds) {
105 pdgIds.reserve(pdgIds.size() + v->size());
106 for (
const auto* p : *v)
108 pdgIds.push_back(p->pdgId());
117 const auto uidx =
static_cast<std::size_t
>(idx);
118 if (uidx >= v->size())
120 pdgId = v->at(uidx)->pdgId();
125 const std::string& prefix, std::vector<const xAOD::TruthParticle*>& out) {
129 out.insert(out.end(), v->begin(), v->end());
134 const std::string& prefix, std::vector<PtEtaPhiMVector>& particles,
135 std::vector<int>& pdgIds) {
139 particles.reserve(particles.size() + v->size());
140 pdgIds.reserve(pdgIds.size() + v->size());
141 for (
const auto* p : *v) {
143 pdgIds.push_back(p->pdgId());
149 PtEtaPhiMVector& particle,
155 PtEtaPhiMVector& particle,
156 int& pdgId,
const int& idx) {
161 const std::string& alt_prefix,
162 PtEtaPhiMVector& particle,
171 static const std::unordered_map<int, std::string> pdgMap = {
172 {1,
"_q"}, {2,
"_q"}, {3,
"_q"}, {-1,
"_qbar"},
173 {-2,
"_qbar"}, {-3,
"_qbar"}, {6,
"_t"}, {-6,
"_tbar"},
174 {5,
"_b"}, {-5,
"_bbar"}, {4,
"_c"}, {-4,
"_cbar"},
175 {25,
"_H"}, {24,
"_W"}, {-24,
"_W"}, {23,
"_Z"},
176 {22,
"_gamma"}, {21,
"_g"}, {11,
"_l"}, {13,
"_l"},
177 {15,
"_l"}, {-11,
"_lbar"}, {-13,
"_lbar"}, {-15,
"_lbar"},
178 {12,
"_nu"}, {14,
"_nu"}, {16,
"_nu"}, {-12,
"_nubar"},
179 {-14,
"_nubar"}, {-16,
"_nubar"}, {2212,
"_p"}, {1103,
"_dd"},
180 {2101,
"_ud"}, {2103,
"_ud"}, {2203,
"_uu"}, {3101,
"_sd"},
181 {3103,
"_sd"}, {3201,
"_su"}, {3203,
"_su"}, {3303,
"_ss"},
182 {4101,
"_cd"}, {4103,
"_cd"}, {4201,
"_cu"}, {4203,
"_cu"},
183 {4301,
"_cs"}, {4303,
"_cs"}, {4403,
"_cc"}, {5101,
"_bd"},
184 {5103,
"_bd"}, {5201,
"_bu"}, {5203,
"_bu"}, {5301,
"_bs"},
185 {5303,
"_bs"}, {5401,
"_bc"}, {5403,
"_bc"}, {5503,
"_bb"}};
186 int pdgId = particle->pdgId();
187 auto it = pdgMap.find(pdgId);
188 return it != pdgMap.end() ? it->second :
"_" + std::to_string(pdgId);
193 std::vector<std::vector<const xAOD::TruthParticle*>>& allPaths) {
216 p,
"CustomLinkedTruthBosonWithDecayParticles");
222 if (p->nChildren() == 0) {
223 allPaths.push_back(path);
230 if (std::abs(afterFSR->
pdgId()) == 24) {
232 afterFSR,
"CustomLinkedTruthBosonWithDecayParticles");
240 for (std::size_t i = 0; i < afterFSR->
nChildren(); ++i) {
241 if (
const auto* c = afterFSR->
child(i))
249 const std::string& key) {
255 const std::string& newKey, std::string& key) {
259 if (p->nParents() == 0) {
277 std::string& key,
int decayID) {
284 if (!fromH && !fromW && !fromZ)
287 const std::string decayStr =
"Decay" + std::to_string(decayID);
301 const std::string& newKey,
308 std::vector<std::vector<const xAOD::TruthParticle*>>& allPaths) {
329 "classifierParticleOrigin");
331 "classifierParticleType");
333 for (
const auto& path : allPaths) {
335 std::string key =
m_prefix +
"_" +
"MC";
337 for (
const auto* p : path) {
347 int decayID = (p->pdgId() < 0) ? 2 : 1;
348 if (p->nParents() != 0 && p->parent(0)) {
349 const auto* par = p->parent(0);
350 for (std::size_t i = 0; i < par->nChildren(); ++i) {
351 if (par->child(i) == p) {
352 decayID =
static_cast<int>(i) + 1;
362 if (beforeFSR && afterFSR)
372 if (!new_key.empty())
380 std::vector<std::vector<const xAOD::TruthParticle*>> allPaths;
381 allPaths.reserve(truthParticles->
size());
385 std::vector<const xAOD::TruthParticle*> path;
395 return StatusCode::SUCCESS;
406 return StatusCode::SUCCESS;
410 const std::vector<std::string>& collections,
411 const std::string& out_contName) {
426 std::vector<const xAOD::TruthParticle*> p_candidates;
427 std::vector<const xAOD::TruthParticle*> p_parents;
429 for (
const std::string& collection : collections) {
440 if (std::none_of(p_candidates.
begin(), p_candidates.
end(),
442 return other_candidate != potential_parent &&
443 !PartonHistoryUtils::isQuarkFromPDF(
445 PartonHistoryUtils::isChildOf(other_candidate,
449 p_parents.push_back(potential_parent);
451 out_cont->
insert(out_cont->
end(), p_parents.begin(), p_parents.end());
452 StatusCode save =
TDS()->record(out_cont, out_contName);
454 return StatusCode::FAILURE;
455 return StatusCode::SUCCESS;
460 "TruthBoson",
"TruthBosonsWithDecayParticles",
461 "CustomLinkedTruthBosonWithDecayParticles");
465 const std::string& collectionToDecorate,
466 const std::string& collectionToLink,
const std::string& nameOfDecoration) {
472 for (
const auto* p : *cont1) {
474 for (
const auto* q : *cont2) {
475 if (p->pdgId() == q->pdgId() && p->uid() == q->uid()) {
482 return StatusCode::SUCCESS;
489 if (!
acc.isAvailable(*part))
492 return link ? link : part;
497 const std::string key =
m_prefix +
"_TruthParticles";
499 const auto& collections =
504 return StatusCode::SUCCESS;
507 return StatusCode::SUCCESS;
519 for (
const auto& group :
m_config.decoratorGroups) {
566 for (
const auto& zw :
m_config.decoratorZWs) {
575 m_dec.initializeVectorPtEtaPhiMDecorator(
fill.decorationKey);
576 m_dec.initializeVectorIntDecorator(
fill.decorationKey +
"_pdgId");
578 m_dec.initializePtEtaPhiMDecorator(
fill.decorationKey);
579 m_dec.initializeIntDecorator(
fill.decorationKey +
"_pdgId");
590 m_dec.setEventInfo(partonHistory);
594 for (
const auto& op :
m_config.specialFills) {
627 }
else if (
fill.retrievalKeys.size() == 1) {
636 return StatusCode::SUCCESS;
DataVector adapter that acts like it holds const pointers.
ROOT::Math::PtEtaPhiMVector GetPtEtaPhiMfromTruth(const xAOD::TruthParticle *TruthParticle)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
void InitializeVectorAntiCharmDecorators()
void InitializeVectorCharmDecorators()
void InitializeAntiCharmDecorators()
StatusCode buildContainerFromMultipleCollections(const std::vector< std::string > &collections, const std::string &out_contName)
used to build container from multiple collections in DAOD_PHYS we don't have the TruthParticles colle...
CalcPartonHistory(const std::string &name, const std::vector< std::string > &truthCollections={"TruthTop"})
void FillGenericVectorPartonHistory(const std::string &retrievalstring, const std::string &decorationstring)
void InitializeVectorAntiBottomDecorators()
void Initialize4TopDecorators()
void InitializeVectorBottomDecorators()
bool ExistsInKey(const std::string &key, const xAOD::TruthParticle *particle) const
void configure(const PartonSchemeConfig &config)
const xAOD::TruthParticle * getTruthParticleLinkedFromDecoration(const xAOD::TruthParticle *part, const std::string &decorationName)
helper method to handle retriveing the truth particle linked in the decoration of another particle
void InitializeAntiTopDecorators()
virtual StatusCode runHistorySaver(const xAOD::TruthParticleContainer *truthParticles, const xAOD::EventInfo *ttbarPartonHistory)
void FillParticleMap(std::vector< std::vector< const xAOD::TruthParticle * > > &allPaths)
bool Retrievep4Gamma(PtEtaPhiMVector &p4, int &parentpdgId)
bool RetrieveParticleInfo(const std::string &prefix, std::vector< const xAOD::TruthParticle * > &particles)
const std::vector< std::string > m_truthCollections
void FillAntiTopPartonHistory()
void InitializeBottomDecorators()
void FillHiggsPartonHistory(const std::string &mode)
std::map< std::string, std::vector< const xAOD::TruthParticle * > > m_particleMap
virtual StatusCode linkTruthContainers(const xAOD::TruthParticleContainer *&tp)
void FillWPartonHistory(const std::string &parent, int nWs=1, const std::string &mode="resonant")
std::string GetParticleType(const xAOD::TruthParticle *particle)
void FillTopPartonHistory()
void InitializePhotonDecorators()
bool Retrievep4(const std::string &key, PtEtaPhiMVector &p4)
std::string m_prefix
prefix applied to all decorator and m_particleMap names
void FillTtbarPartonHistory()
void InitializeCharmDecorators()
void FillGammaPartonHistory(const std::string &parent)
void InitializeTtbarDecorators()
bool ExistsInMap(const std::string &key) const
void InitializeZDecorators(int nZs=1, bool extend=false)
void FillZtautauPartonHistory(const std::string &parent, int nZs=1, const std::string &mode="resonant")
bool RetrievepdgId(const std::string &key, std::vector< int > &pdgIds)
bool handleDecay(const xAOD::TruthParticle *particle, std::string &key, int decayID)
bool m_configured
true after configure() has been called
void FillZPartonHistory(const std::string &parent, int nZs=1, const std::string &mode="resonant")
void InitializeAntiBottomDecorators()
void TraceParticle(const xAOD::TruthParticle *particle, std::vector< const xAOD::TruthParticle * > ¤tPath, std::vector< std::vector< const xAOD::TruthParticle * > > &allPaths)
void handleDefault(const xAOD::TruthParticle *particle, const std::string &newKey, std::string &key)
virtual void initializeDecorators()
virtual StatusCode execute()
void TraceParticles(const xAOD::TruthParticleContainer *truthParticles)
void InitializeHiggsDecorators()
StatusCode linkBosonCollections()
currently in DAOD_PHYS TruthTop have links to Ws from the TruthBoson collection, which have no link t...
void FillGenericPartonHistory(const std::string &retrievalstring, const std::string &decorationstring, const int idx)
StatusCode decorateCollectionWithLinksToAnotherCollection(const std::string &collectionToDecorate, const std::string &collectionToLink, const std::string &nameOfDecoration)
helper method currently used in DAOD_PHYS to link particles from a given collection to the same parti...
bool handleFSR(const xAOD::TruthParticle *particle, const std::string &newKey, std::string &key)
void handleSameAsParent(const xAOD::TruthParticle *particle, std::string &key)
void InitializeWDecorators(int nWs=1)
PartonSchemeConfig m_config
scheme configuration set via configure()
void AddToParticleMap(const xAOD::TruthParticle *particle, const std::string &key)
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
void InitializeTopDecorators()
DataVector adapter that acts like it holds const pointers.
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
iterator end() noexcept
Return an iterator pointing past the end of the collection.
iterator insert(iterator position, value_type pElem)
Add a new element to the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Helper class to provide type-safe access to aux data.
Helper class to provide constant type-safe access to aux data.
const TruthParticle_v1 * child(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
int pdgId() const
PDG ID code.
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
size_t nParents() const
Number of parents of this particle.
size_t nChildren() const
Number of children of this particle.
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
bool hasIdenticalChild(const xAOD::TruthParticle *particle)
bool hasParticleIdenticalParent(const xAOD::TruthParticle *particle)
Return true when particle is a top before FSR.
bool isQuarkFromPDF(const xAOD::TruthParticle *particle)
bool hasParentPdgId(const xAOD::TruthParticle *particle, int PdgId)
const xAOD::TruthParticle * findAfterFSR(const xAOD::TruthParticle *particle)
Return particle after FSR (before the decay vertex).
bool isAfterFSR(const xAOD::TruthParticle *particle)
Determine whether particle is afterFSR.
bool isBrokenTop(const xAOD::TruthParticle *particle)
Looking for tops without children -> must be broken.
bool hasParentAbsPdgId(const xAOD::TruthParticle *particle, int absPdgId)
Select isolated Photons, Electrons and Muons.
@ Z
FillZPartonHistory(history, parent, dec, count, mode).
@ Ttbar
FillTtbarPartonHistory.
@ W
FillWPartonHistory(history, parent, dec, count, mode).
@ Ztautau
FillZtautauPartonHistory(history, parent, dec, count, mode).
@ Higgs
FillHiggsPartonHistory(history, mode, dec).
@ Top
FillTopPartonHistory.
@ AntiTop
FillAntiTopPartonHistory.
@ Gamma
FillGammaPartonHistory(history, parent, dec).
@ FourTop
Initialize4TopDecorators().
@ VectorAntiBottom
InitializeVectorAntiBottomDecorators().
@ VectorAntiCharm
InitializeVectorAntiCharmDecorators().
@ Bottom
InitializeBottomDecorators().
@ Charm
InitializeCharmDecorators().
@ AntiCharm
InitializeAntiCharmDecorators().
@ VectorBottom
InitializeVectorBottomDecorators().
@ Ttbar
InitializeTtbarDecorators().
@ VectorCharm
InitializeVectorCharmDecorators().
@ Higgs
InitializeHiggsDecorators().
@ Top
InitializeTopDecorators().
@ AntiBottom
InitializeAntiBottomDecorators().
@ AntiTop
InitializeAntiTopDecorators().
@ Photon
InitializePhotonDecorators().
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
EventInfo_v1 EventInfo
Definition of the latest event info version.
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
enum CP::DecoratorZW::Type Z
Top-level configuration for a named parton history scheme.
void fill(H5::Group &out_file, size_t iterations)