16#include "GaudiKernel/MsgStream.h"
29constexpr int NKEYS = 5;
31std::string s_keys[NKEYS] = {
"TruthEvent",
"G4Truth",
"GEN_AOD",
"GEN_EVENT",
"Bkg_TruthEvent"};
41std::atomic<unsigned> s_hint = NKEYS;
44const unsigned short CPTRMAXMSGCOUNT = 100;
61 static const char codes[
EBC_NSUPP] = {
'a',
'b'};
63 return codes[suppEnum];
79 log << MSG::ERROR <<
" Wrong truth Suppression Char (" << std::string(&suppChar,1) <<
") set in HepMcParticleLink ExtendedBarCode object !!!" <<
endmsg;
90 os <<
"Event index " ;
94 os << position <<
" (position in collection) ";
97 os << event_number <<
" (event number) ";
99 os <<
", Unique ID " ;
101 uniqueID (particle_id, particle_barcode);
102 if (particle_barcode == 0 && particle_id == 0) {
103 os <<
" 0 (id/barcode) ";
106 os << particle_barcode <<
" (barcode) ";
109 os << particle_id <<
" (id) ";
111 os <<
", McEventCollection "
121 std::ostringstream
ss;
153 if (part !=
nullptr && positionFlag ==
IS_POSITION) {
155 const HepMC::GenEvent *pEvt = pEvtColl->at (
eventIndex);
160 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
180 const bool is_valid =
m_ptr.isValid();
191 <<
"cptr: no truth particle associated with this hit (barcode==0)."
192 <<
" Probably this is a noise hit" <<
endmsg;
201 const HepMC::GenEvent *pEvt =
nullptr;
204 if (event_number == 0) {
205 pEvt = pEvtColl->at(0);
208 if (position < pEvtColl->size()) {
209 pEvt = pEvtColl->at (position);
214 log << MSG::WARNING <<
"cptr: position = " << position <<
", McEventCollection size = "<< pEvtColl->size() <<
endmsg;
220 pEvt = pEvtColl->find (event_number);
223 if (
nullptr != pEvt) {
227 m_extBarcode.makeIndex (pEvt->event_number(), position);
229 if (event_number == 0) {
230 m_extBarcode.makeIndex (pEvt->event_number(), position);
240 if (genParticleID > -1) {
251 const auto &particles = pEvt->particles();
252 if (particle_id-1 < particles.size()) {
272 <<
"cptr: Mc Truth not stored for event at " << position
276 <<
"cptr: Mc Truth not stored for event with event number " << event_number
282 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
325 return int(particle_barcode);
355 const HepMC::GenEvent* pEvt{};
357 if (event_position < coll->size()) {
358 pEvt = coll->at (event_position);
361 const int genEventNumber = pEvt->event_number();
366 if (genEventNumber > -1) {
367 event_number =
static_cast<index_type>(genEventNumber);
406 if (event_number == 0) {
419std::vector<HepMcParticleLink::index_type>
422 std::vector<index_type> positions; positions.reserve(1);
423 const int int_event_number =
static_cast<int>(event_number);
425 size_t sz = coll->size();
426 for (
size_t i = 0; i <
sz; i++) {
427 if ((*coll)[i]->event_number() == int_event_number) {
428 positions.push_back(i);
432 if (positions.empty() ) {
446 if (position < coll->size()) {
447 return coll->at (position)->event_number();
452 log << MSG::WARNING <<
"getEventNumberAtPosition: position = " << position <<
", McEventCollection size = "<< coll->size() <<
endmsg;
476 return redirectedLink;
505 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
519 unsigned int hint_orig = s_hint;
520 if (hint_orig >= NKEYS) hint_orig = 0;
521 unsigned int hint = hint_orig;
525 if (hint != s_hint) {
528 static std::atomic<unsigned> findCount {0};
529 if(++findCount == 1) {
531 log << MSG::INFO <<
"find_proxy: Using " << s_keys[hint]
532 <<
" as McEventCollection key for this job " <<
endmsg;
537 if (hint >= NKEYS) hint = 0;
538 }
while (hint != hint_orig);
541 static std::atomic<unsigned long> msgCount {0};
542 unsigned int count = ++msgCount;
543 if (
count <= CPTRMAXMSGCOUNT) {
544 log << MSG::WARNING <<
"find_proxy: No Valid MC event Collection found "
547 if (
count == CPTRMAXMSGCOUNT) {
548 log << MSG::WARNING <<
"find_proxy: suppressing further messages about valid MC event Collection. Use \n"
549 <<
" msgSvc.setVerbose += [HepMcParticleLink]\n"
550 <<
"to see all messages" <<
endmsg;
552 if (
count > CPTRMAXMSGCOUNT) {
553 log << MSG::VERBOSE <<
"find_proxy: No Valid MC event Collection found "
565 static const std::string unset =
"CollectionNotSet";
566 unsigned idx = s_hint;
uint32_t CLID
The Class ID type.
std::ostream & operator<<(std::ostream &os, const HepMcParticleLink &link)
Output operator.
void print(char *figname, TCanvas *c1)
Persistent representation of a link.
void print(std::ostream &os) const
Dump in textual format to a stream.
static char truthSuppressionTypeAsChar(EBC_SUPPRESSED_TRUTH suppEnum)
Translate truth suppression enum to a char ('a'..'b').
static EBC_SUPPRESSED_TRUTH truthSuppressionTypeFromChar(char suppChar)
Translate truth suppression char ('a'..'b') to an enum.
static constexpr index_type UNDEFINED
All 1's. Used to represent an undefined index/position.
void uniqueID(barcode_type &id, barcode_type &barcode) const
Return the GenParticle id/barcode.
static constexpr barcode_type UNDEFINEDBC
EBC_SUPPRESSED_TRUTH getTruthSuppressionType() const
Return whether the truth particle has been suppressed, as an enum.
void setExtendedBarCode(const ExtendedBarCode &extBarcode)
Alter the persistent part of the link.
int id() const
Return the id of the target particle.
bool linkIsNull() const
return true if neither barcode nor id are valid
static const McEventCollection * retrieveMcEventCollection(const IProxyDict *sg)
Look up the event collection we're targeting.
static SG::DataProxy * find_proxy(const IProxyDict *sg)
Find the proxy for the target event collection.
HepMC::ConstGenParticlePtr cptr() const
Dereference.
HepMcParticleLink(IProxyDict *sg=nullptr)
Default constructor.
ExtendedBarCode m_extBarcode
Persistent part: barcode and location of target GenEvent.
static std::string getLastEventCollectionName()
Return the most recent SG key used for a particular collection type.
static std::vector< index_type > getEventPositionInCollection(index_type index, const IProxyDict *sg)
Return a vector of the positions in the McEventCollection of the GenEvent(s) with a given event numbe...
static int getEventNumberAtPosition(index_type position, const IProxyDict *sg)
Return the event number of the GenEvent at the specified position in the McEventCollection.
index_type eventIndex() const
Return the event number of the referenced GenEvent.
static HepMcParticleLink getRedirectedLink(const HepMcParticleLink &particleLink, uint32_t eventIndex, const EventContext &ctx)
Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.
int barcode() const
Return the barcode of the target particle.
IProxyDict * m_store
Pointer to the store containing the event.
void setTruthSuppressionType(EBC_SUPPRESSED_TRUTH truthSupp)
Return whether the truth particle has been suppressed.
ATH_NO_UNIQUE_ADDRESS CxxUtils::CachedValue< HepMC::ConstGenParticlePtr > m_ptr
Transient part. Pointer to the particle.
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const =0
Get proxy with given id and key.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
static IProxyDict * store()
Fetch the current store.
singleton-like access to IMessageSvc via open function and helper
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
IMessageSvc * getMessageSvc(bool quiet=false)
GenParticle * barcode_to_particle(const GenEvent *e, int id)
const GenParticle * ConstGenParticlePtr
DATA * DataProxy_cast(DataProxy *proxy)
cast the proxy into the concrete data object it proxies