16#include "GaudiKernel/ThreadLocalContext.h"
45 const std::string& name,
46 const IInterface* parent ) :
47 base_class(
type, name, parent ),
56 declareProperty(
"DataType",
58 "Type of data we are dealing with (Full/Fast/Truth...)" );
60 declareProperty(
"TruthIsolationTool",
62 "Pointer to the TruthIsolationTool to be able to compute "
63 "transverse energy isolations for various isolation cones cuts. "
64 "See McParticleEvent/TruthParticleParameters.h for cone cuts." );
67 declareProperty(
"DoEtIsolations",
69 "Switch to compute or not the Et-isolations for TruthParticle "
70 "(and their underlying @c HepMC::GenParticle).\n"
71 "Default is to not compute these Et-isolations (and save CPU)." );
75 declareProperty(
"SelectSignalType",
77 "Switch to select different type of signal\n"
79 " hard scatter plus minbias 1\n"
81 "Default is hard scatter only." );
83 declareInterface<ITruthParticleCnvTool>(
this);
117 (
" DoEtIsolations: [" << std::boolalpha
124 return StatusCode::SUCCESS;
129 return execute (Gaudi::Hive::currentContext());
139 ATH_CHECK(mcPartsOutputWriteHandle.
record(std::make_unique<TruthParticleContainer>()));
141 if (!mcPartsOutputWriteHandle.
isValid()){
143 return StatusCode::FAILURE;
149 if (!mcEventsReadHandle.
isValid()){
154 <<
"] will be EMPTY !!");
155 return StatusCode::RECOVERABLE;
158 ATH_MSG_DEBUG(
" Found McEventCollection of size = "<< mcEventsReadHandle->size() );
162 std::size_t genEventIndex = 0;
164 bool all_good =
true;
170 ATH_MSG_DEBUG(
" Found McEventCollection iterators : "<< (fEvt-mcEventsReadHandle->begin()) <<
" to "<< (lEvt-mcEventsReadHandle->begin()) );
176 if (
nullptr == evt) {
179 genEventIndex = (it - mcEventsReadHandle->begin());
183 if (!this->
convert( mcEventsReadHandle.
ptr(), genEventIndex, mcPartsOutputWriteHandle.
ptr(), dummyVisitor ).isSuccess()) {
191 mcPartsOutputWriteHandle->setGenEvent( mcEventsReadHandle.
ptr(), (fEvt - mcEventsReadHandle->begin() ) );
195 ? StatusCode::SUCCESS
196 : StatusCode::RECOVERABLE;
206 const unsigned int genEventIndex,
210 ATH_MSG_DEBUG(
"Converting McEventCollection to TruthParticleContainer");
213 if (
nullptr == mcCollection ) {
215 return StatusCode::RECOVERABLE;
218 if ( mcCollection->
size() <= genEventIndex ) {
221 <<
"Requested element nbr : " << genEventIndex <<
" !!");
222 return StatusCode::RECOVERABLE;
225 const EventContext& ctx = Gaudi::Hive::currentContext();
228 ATH_MSG_DEBUG(
"Retrieve the GenEvent from given McEventCollection");
230 container->setGenEvent( mcCollection, genEventIndex, ctx );
233 container->reserve( container->size() + evt->particles_size() );
242 ATH_MSG_ERROR(
"TruthParticleCnvTool.cxx: Event does not contain barcodes attribute");
243 return StatusCode::FAILURE;
246 for (
const auto &[bc,hepMcPart]: bcmap) {
249 container->push_back( mcPart );
252 visitor->
visit( mcPart );
259 ATH_MSG_ERROR(
"TruthParticle is not wrapping the GenParticle : "
260 << hepMcPart <<
" !!");
263 bcToMcPart[ mcLink.
compress() ] = mcPart;
269 container->setParticles( bcToMcPart );
274 const std::string& etIsolName
276 if ( etIsolName.empty() ) {
278 "TruthEtIsolations container (requested: ["
279 << container->genEventName() <<
"])");
280 return StatusCode::RECOVERABLE;
284 if ( !evtStore()->retrieve( etIsols, etIsolName ).isSuccess() ) {
285 ATH_MSG_WARNING(
"Could not retrieve the TruthEtIsolations container at ["
286 << etIsolName <<
"] !!");
287 return StatusCode::RECOVERABLE;
292 container->setEtIsolations( etIsols, genEventIndex );
295 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
ATLAS-specific HepMC functions.
DataModel_detail::const_iterator< DataVector > const_iterator
size_type size() const noexcept
Returns the number of elements in the collection.
std::map< int, ConstGenParticlePtr > barcode_to_particle_map() const
a link optimized in size for a GenParticle in a McEventCollection
barcode_type compress() const
Hash the 32 bit barcode and 16 bit eventindex into a 32bit int.
virtual void visit(TruthParticle *truthParticle) const =0
The method to visit a TruthParticle to apply further modifications to the instance at hand.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual int pdgId() const
Return enum indicating particle id the enum file is available in Event/EventKernel/PdtPdg....
PileuType_t
define some Pile-up classification Important : this classification is copied in McParticleAlgs/python...
static void findEventIterators(PileuType_t putype, McEventCollection::const_iterator &fEvt, McEventCollection::const_iterator &lEvt)
Find interval [fEvt,lEvt] containing all GenEvents of type putype from the McEventCollection.
const_pointer_type ptr()
Dereference the pointer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
pointer_type ptr()
Dereference the pointer.
int m_selectSignalTypeProp
Type of truth particle we want to create (property to be set by jobO).
virtual ~TruthParticleCnvTool()
Destructor:
TruthParticleCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
SG::WriteHandleKey< TruthParticleContainer > m_mcPartsOutputWriteHandleKey
Output TruthParticle WriteHandleKey (built from the McEventCollection).
ToolHandle< ITruthIsolationTool > IsolTool_t
virtual StatusCode execute() const override
ParticleDataType::DataType m_dataType
Type of data we are dealing with (Full/Fast/Truth/...).
IsolTool_t m_isolationTool
Pointer to the ITruthIsolationTool to be able to retrieve the previously computed transverse energy i...
void setDataType(const int type)
Inline methods:
virtual StatusCode initialize() override
Athena Algorithm's Hooks.
PileUpClassification::PileuType_t m_selectSignalType
Type of truth particle we want to create.
StatusCode convert(const McEventCollection *mcEvts, const unsigned int genEvtIndex, TruthParticleContainer *mcParts, const ITruthParticleVisitor *visitor) const override
Converts a McEventCollection into an TruthParticleContainer (ie: converts it into an AOD compliant co...
std::string m_vxCandidatesName
BooleanProperty m_doEtIsolation
Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle...
SG::ReadHandleKey< McEventCollection > m_mcEventsReadHandleKey
ReadHandleKey for the McEventCollection the TruthParticles will be made from.
std::unordered_map< long, const TruthParticle * > Map_t
barcode to TruthParticle dictionary
(HepMC) Monte Carlo particle.
void setGenEventIndex(size_t index)
set the GenEvent index
HepMC::ConstGenParticlePtr genParticle() const
Retrieve the GenParticle this TruthParticle has been made from (if any).
void setCharge(const ChargeType charge)
Set the charge of this TruthParticle.
int signal_process_id(const GenEvent &evt)
HepMC3::GenEvent GenEvent
double charge(const T &p)
Information about type of data used to fill particle.