20#define TDS() evtStore()->tds()
22#define TDS() evtStore()
26const std::vector<const xAOD::TruthParticle*>* findVector(
27 const std::map<std::string, std::vector<const xAOD::TruthParticle*>>&
map,
28 const std::string& key) {
29 auto it =
map.find(key);
30 return it ==
map.end() ? nullptr : &it->second;
33constexpr const char* kBeforeFSR =
"_beforeFSR";
34constexpr const char* kAfterFSR =
"_afterFSR";
38using ROOT::Math::PtEtaPhiMVector;
41 const std::string&
name,
const std::vector<std::string>& truthCollection)
44 "Prefix to apply to all names to avoid overwriting");
56 return std::find(v->begin(), v->end(), p) != v->end();
62 PtEtaPhiMVector& p4) {
71 const auto uidx =
static_cast<std::size_t
>(idx);
72 if (uidx >= v->size())
82 if (key.find(
"GammaRad") != std::string::npos) {
83 auto it = std::max_element(
84 particles.begin(), particles.end(),
85 [](
const auto*
a,
const auto* b) { return a->pt() < b->pt(); });
86 if (it != particles.end() &&
87 (!bestPhoton || (*it)->
pt() > bestPhoton->
pt()))
105 std::vector<int>& pdgIds) {
109 pdgIds.reserve(pdgIds.size() + v->size());
110 for (
const auto* p : *v)
112 pdgIds.push_back(p->pdgId());
121 const auto uidx =
static_cast<std::size_t
>(idx);
122 if (uidx >= v->size())
124 pdgId = v->at(uidx)->pdgId();
129 const std::string& prefix, std::vector<const xAOD::TruthParticle*>& out) {
133 out.insert(out.end(), v->begin(), v->end());
138 const std::string& prefix, std::vector<PtEtaPhiMVector>& particles,
139 std::vector<int>& pdgIds) {
143 particles.reserve(particles.size() + v->size());
144 pdgIds.reserve(pdgIds.size() + v->size());
145 for (
const auto* p : *v) {
147 pdgIds.push_back(p->pdgId());
153 PtEtaPhiMVector& particle,
159 PtEtaPhiMVector& particle,
160 int& pdgId,
const int& idx) {
165 const std::string& alt_prefix,
166 PtEtaPhiMVector& particle,
175 static const std::unordered_map<int, std::string> pdgMap = {
176 {1,
"_q"}, {2,
"_q"}, {3,
"_q"}, {-1,
"_qbar"},
177 {-2,
"_qbar"}, {-3,
"_qbar"}, {6,
"_t"}, {-6,
"_tbar"},
178 {5,
"_b"}, {-5,
"_bbar"}, {4,
"_c"}, {-4,
"_cbar"},
179 {25,
"_H"}, {24,
"_W"}, {-24,
"_W"}, {23,
"_Z"},
180 {22,
"_gamma"}, {21,
"_g"}, {11,
"_l"}, {13,
"_l"},
181 {15,
"_l"}, {-11,
"_lbar"}, {-13,
"_lbar"}, {-15,
"_lbar"},
182 {12,
"_nu"}, {14,
"_nu"}, {16,
"_nu"}, {-12,
"_nubar"},
183 {-14,
"_nubar"}, {-16,
"_nubar"}, {2212,
"_p"}, {1103,
"_dd"},
184 {2101,
"_ud"}, {2103,
"_ud"}, {2203,
"_uu"}, {3101,
"_sd"},
185 {3103,
"_sd"}, {3201,
"_su"}, {3203,
"_su"}, {3303,
"_ss"},
186 {4101,
"_cd"}, {4103,
"_cd"}, {4201,
"_cu"}, {4203,
"_cu"},
187 {4301,
"_cs"}, {4303,
"_cs"}, {4403,
"_cc"}, {5101,
"_bd"},
188 {5103,
"_bd"}, {5201,
"_bu"}, {5203,
"_bu"}, {5301,
"_bs"},
189 {5303,
"_bs"}, {5401,
"_bc"}, {5403,
"_bc"}, {5503,
"_bb"}};
190 int pdgId = particle->pdgId();
191 auto it = pdgMap.find(pdgId);
192 return it != pdgMap.end() ? it->second :
"_" + std::to_string(pdgId);
197 std::vector<std::vector<const xAOD::TruthParticle*>>& allPaths) {
220 p,
"CustomLinkedTruthBosonWithDecayParticles");
226 if (p->nChildren() == 0) {
227 allPaths.push_back(path);
234 if (std::abs(afterFSR->
pdgId()) == 24) {
236 afterFSR,
"CustomLinkedTruthBosonWithDecayParticles");
244 for (std::size_t i = 0; i < afterFSR->
nChildren(); ++i) {
245 if (
const auto* c = afterFSR->
child(i))
253 const std::string& key) {
259 const std::string& newKey, std::string& key) {
263 if (p->nParents() == 0) {
281 std::string& key,
int decayID) {
288 if (!fromH && !fromW && !fromZ)
291 const std::string decayStr =
"Decay" + std::to_string(decayID);
305 const std::string& newKey,
312 std::vector<std::vector<const xAOD::TruthParticle*>>& allPaths) {
333 "classifierParticleOrigin");
335 "classifierParticleType");
337 for (
const auto& path : allPaths) {
339 std::string key =
m_prefix +
"_" +
"MC";
341 for (
const auto* p : path) {
351 int decayID = (p->pdgId() < 0) ? 2 : 1;
352 if (p->nParents() != 0 && p->parent(0)) {
353 const auto* par = p->parent(0);
354 for (std::size_t i = 0; i < par->nChildren(); ++i) {
355 if (par->child(i) == p) {
356 decayID =
static_cast<int>(i) + 1;
366 if (beforeFSR && afterFSR)
376 if (!new_key.empty())
384 std::vector<std::vector<const xAOD::TruthParticle*>> allPaths;
385 allPaths.reserve(truthParticles->
size());
389 std::vector<const xAOD::TruthParticle*> path;
399 return StatusCode::SUCCESS;
410 return StatusCode::SUCCESS;
414 const std::vector<std::string>& collections,
415 const std::string& out_contName) {
430 std::vector<const xAOD::TruthParticle*> p_candidates;
431 std::vector<const xAOD::TruthParticle*> p_parents;
433 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::isChildOf(other_candidate,
446 p_parents.push_back(potential_parent);
448 out_cont->
insert(out_cont->
end(), p_parents.begin(), p_parents.end());
449 StatusCode save =
TDS()->record(out_cont, out_contName);
451 return StatusCode::FAILURE;
452 return StatusCode::SUCCESS;
457 "TruthBoson",
"TruthBosonsWithDecayParticles",
458 "CustomLinkedTruthBosonWithDecayParticles");
462 const std::string& collectionToDecorate,
463 const std::string& collectionToLink,
const std::string& nameOfDecoration) {
469 for (
const auto* p : *cont1) {
471 for (
const auto* q : *cont2) {
472 if (p->pdgId() == q->pdgId() && p->uid() == q->uid()) {
479 return StatusCode::SUCCESS;
486 if (!
acc.isAvailable(*part))
489 return link ? link : part;
494 const std::string key =
m_prefix +
"_TruthParticles";
496 const auto& collections =
501 return StatusCode::SUCCESS;
504 return StatusCode::SUCCESS;
516 for (
const auto& group :
m_config.decoratorGroups) {
563 for (
const auto& zw :
m_config.decoratorZWs) {
572 m_dec.initializeVectorPtEtaPhiMDecorator(
fill.decorationKey);
573 m_dec.initializeVectorIntDecorator(
fill.decorationKey +
"_pdgId");
575 m_dec.initializePtEtaPhiMDecorator(
fill.decorationKey);
576 m_dec.initializeIntDecorator(
fill.decorationKey +
"_pdgId");
587 m_dec.setEventInfo(partonHistory);
591 for (
const auto& op :
m_config.specialFills) {
624 }
else if (
fill.retrievalKeys.size() == 1) {
633 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.
Helper class to provide 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 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()
@ 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.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Top-level configuration for a named parton history scheme.
void fill(H5::Group &out_file, size_t iterations)