|
ATLAS Offline Software
|
Go to the documentation of this file.
16 #include "GaudiKernel/MsgStream.h"
29 constexpr
int NKEYS = 5;
31 std::string s_keys[NKEYS] = {
"TruthEvent",
"G4Truth",
"GEN_AOD",
"GEN_EVENT",
"Bkg_TruthEvent"};
41 std::atomic<unsigned> s_hint = NKEYS;
44 const unsigned short CPTRMAXMSGCOUNT = 100;
60 os <<
"Event index " ;
64 os << position <<
" (position in collection) ";
67 os << event_number <<
" (event number) ";
69 os <<
", Unique ID " ;
71 uniqueID (particle_id, particle_barcode);
72 if (particle_barcode == 0 && particle_id == 0) {
73 os <<
" 0 (id/barcode) ";
76 os << particle_barcode <<
" (barcode) ";
79 os << particle_id <<
" (id) ";
81 os <<
", McEventCollection "
91 std::ostringstream
ss;
125 const HepMC::GenEvent *pEvt = pEvtColl->at (
eventIndex);
130 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
153 <<
"cptr: no truth particle associated with this hit (barcode==0)."
154 <<
" Probably this is a noise hit" <<
endmsg;
163 const HepMC::GenEvent *pEvt =
nullptr;
166 if (event_number == 0) {
167 pEvt = pEvtColl->at(0);
170 if (position < pEvtColl->
size()) {
171 pEvt = pEvtColl->at (position);
176 log << MSG::WARNING <<
"cptr: position = " << position <<
", McEventCollection size = "<< pEvtColl->size() <<
endmsg;
182 pEvt = pEvtColl->find (event_number);
185 if (
nullptr != pEvt) {
191 if (event_number == 0) {
202 if (genParticleID > -1) {
213 const auto &
particles = pEvt->particles();
234 <<
"cptr: Mc Truth not stored for event at " << position
238 <<
"cptr: Mc Truth not stored for event with event number " << event_number
244 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
287 return int(particle_barcode);
317 const HepMC::GenEvent* pEvt{};
319 if (event_position < coll->
size()) {
320 pEvt = coll->at (event_position);
323 const int genEventNumber = pEvt->event_number();
328 if (genEventNumber > -1) {
329 event_number =
static_cast<index_type>(genEventNumber);
368 if (event_number == 0) {
381 std::vector<HepMcParticleLink::index_type>
384 std::vector<index_type> positions; positions.reserve(1);
385 const int int_event_number =
static_cast<int>(event_number);
387 size_t sz = coll->size();
388 for (
size_t i = 0;
i <
sz;
i++) {
389 if ((*coll)[
i]->event_number() == int_event_number) {
390 positions.push_back(
i);
394 if (positions.empty() ) {
408 if (position < coll->
size()) {
409 return coll->at (position)->event_number();
414 log << MSG::WARNING <<
"getEventNumberAtPosition: position = " << position <<
", McEventCollection size = "<< coll->size() <<
endmsg;
462 pEvtColl = SG::DataProxy_cast<McEventCollection> (
proxy);
465 log << MSG::WARNING <<
"cptr: McEventCollection not found" <<
endmsg;
479 unsigned int hint_orig = s_hint;
480 if (hint_orig >= NKEYS) hint_orig = 0;
481 unsigned int hint = hint_orig;
485 if (hint != s_hint) {
488 static std::atomic<unsigned> findCount {0};
489 if(++findCount == 1) {
491 log << MSG::INFO <<
"find_proxy: Using " << s_keys[hint]
492 <<
" as McEventCollection key for this job " <<
endmsg;
497 if (hint >= NKEYS) hint = 0;
498 }
while (hint != hint_orig);
501 static std::atomic<unsigned long> msgCount {0};
502 unsigned int count = ++msgCount;
503 if (
count <= CPTRMAXMSGCOUNT) {
504 log << MSG::WARNING <<
"find_proxy: No Valid MC event Collection found "
507 if (
count == CPTRMAXMSGCOUNT) {
508 log << MSG::WARNING <<
"find_proxy: suppressing further messages about valid MC event Collection. Use \n"
509 <<
" msgSvc.setVerbose += [HepMcParticleLink]\n"
510 <<
"to see all messages" <<
endmsg;
512 if (
count > CPTRMAXMSGCOUNT) {
513 log <<
MSG::VERBOSE <<
"find_proxy: No Valid MC event Collection found "
525 static const std::string unset =
"CollectionNotSet";
526 unsigned idx = s_hint;
std::ostream & operator<<(std::ostream &os, const HepMcParticleLink &link)
Output operator.
bool linkIsNull() const
return true if neither barcode nor id are valid
void reset()
Reset the value to invalid.
void makeIndex(index_type index, index_type position) const
Change index from position to number.
const T * ptr() const
Return a pointer to the cached value.
void uniqueID(barcode_type &id, barcode_type &barcode) const
Return the GenParticle id/barcode.
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const =0
Get proxy with given id and key.
singleton-like access to IMessageSvc via open function and helper
constexpr static index_type UNDEFINED
All 1's. Used to represent an undefined index/position.
static SG::DataProxy * find_proxy(const IProxyDict *sg)
Find the proxy for the target event collection.
bool isValid() const
Test to see if the value is valid.
HepMcParticleLink(IProxyDict *sg=nullptr)
Default constructor.
ExtendedBarCode m_extBarcode
Persistent part: barcode and location of target GenEvent.
void print(std::ostream &os) const
Dump in textual format to a stream.
static IProxyDict * store()
Fetch the current store.
int barcode() const
Return the barcode of the target particle.
static int getEventNumberAtPosition(index_type position, const IProxyDict *sg)
Return the event number of the GenEvent at the specified position in the McEventCollection.
int id() const
Return the id of the target particle.
IMessageSvc * getMessageSvc(bool quiet=false)
static const McEventCollection * retrieveMcEventCollection(const IProxyDict *sg)
Look up the event collection we're targeting.
HepMC::ConstGenParticlePtr cptr() const
Dereference.
static const CLID & ID()
the CLID of T
ATH_NO_UNIQUE_ADDRESS CxxUtils::CachedValue< HepMC::ConstGenParticlePtr > m_ptr
Transient part. Pointer to the particle.
a link optimized in size for a GenParticle in a McEventCollection
static std::string getLastEventCollectionName()
Return the most recent SG key used for a particular collection type.
GenParticle * barcode_to_particle(const GenEvent *e, int id)
void setExtendedBarCode(const ExtendedBarCode &extBarcode)
Alter the persistent part of the link.
Persistent representation of a link.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
uint32_t CLID
The Class ID type.
void makeID(barcode_type ID, barcode_type barcode) const
Change m_BC from barcode to ID.
index_type eventIndex() const
Return the event number of the referenced GenEvent.
const GenParticle * ConstGenParticlePtr
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 HepMcParticleLink getRedirectedLink(const HepMcParticleLink &particleLink, uint32_t eventIndex, const EventContext &ctx)
Return a HepMcParticleLink pointing at the same particle, but in a different GenEvent.
IProxyDict * m_store
Pointer to the store containing the event.
void set(const T &val) const
Set the value, assuming it is currently invalid.
constexpr static barcode_type UNDEFINEDBC
barcode_type uid() const
Unique ID of target variable (0 for a null link).
std::string print(const MuPatSegment &)
void eventIndex(index_type &index, index_type &position) const
Return the event index/position.
thread_local event_number_t eventIndex