|
ATLAS Offline Software
|
Go to the documentation of this file.
16 #include "GaudiKernel/IPartPropSvc.h"
17 #include "GaudiKernel/ThreadLocalContext.h"
25 #include "HepPDT/ParticleData.hh"
49 const std::string&
name,
50 const IInterface*
parent ) :
53 m_vxCandidatesName ( ),
55 m_selectSignalTypeProp ( 0 )
61 declareProperty(
"DataType",
63 "Type of data we are dealing with (Full/Fast/Truth...)" );
65 declareProperty(
"TruthIsolationTool",
67 "Pointer to the TruthIsolationTool to be able to compute "
68 "transverse energy isolations for various isolation cones cuts. "
69 "See McParticleEvent/TruthParticleParameters.h for cone cuts." );
72 declareProperty(
"DoEtIsolations",
74 "Switch to compute or not the Et-isolations for TruthParticle "
75 "(and their underlying @c HepMC::GenParticle).\n"
76 "Default is to not compute these Et-isolations (and save CPU)." );
80 declareProperty(
"SelectSignalType",
82 "Switch to select different type of signal\n"
84 " hard scatter plus minbias 1\n"
86 "Default is hard scatter only." );
88 declareInterface<ITruthParticleCnvTool>(
this);
106 if ( !partPropSvc.retrieve().isSuccess() ) {
107 ATH_MSG_ERROR(
" Could not initialize Particle Properties Service");
108 return StatusCode::FAILURE;
111 m_pdt = partPropSvc->PDT();
112 if (
nullptr ==
m_pdt ) {
113 ATH_MSG_ERROR(
"Could not retrieve HepPDT::ParticleDataTable from "\
114 "ParticleProperties Service !!");
115 return StatusCode::FAILURE;
136 (
" DoEtIsolations: [" << std::boolalpha
143 return StatusCode::SUCCESS;
148 return execute (Gaudi::Hive::currentContext());
158 ATH_CHECK(mcPartsOutputWriteHandle.
record(std::make_unique<TruthParticleContainer>()));
160 if (!mcPartsOutputWriteHandle.
isValid()){
162 return StatusCode::FAILURE;
168 if (!mcEventsReadHandle.
isValid()){
173 <<
"] will be EMPTY !!");
174 return StatusCode::RECOVERABLE;
177 ATH_MSG_DEBUG(
" Found McEventCollection of size = "<< mcEventsReadHandle->
size() );
181 std::size_t genEventIndex = 0;
183 bool all_good =
true;
189 ATH_MSG_DEBUG(
" Found McEventCollection iterators : "<< (fEvt-mcEventsReadHandle->
begin()) <<
" to "<< (lEvt-mcEventsReadHandle->
begin()) );
192 const HepMC::GenEvent*
evt = *
it;
195 if (
nullptr ==
evt) {
198 genEventIndex = (
it - mcEventsReadHandle->
begin());
202 if (!this->
convert( mcEventsReadHandle.
ptr(), genEventIndex, mcPartsOutputWriteHandle.
ptr(), dummyVisitor ).isSuccess()) {
210 mcPartsOutputWriteHandle->
setGenEvent( mcEventsReadHandle.
ptr(), (fEvt - mcEventsReadHandle->
begin() ) );
214 ? StatusCode::SUCCESS
215 : StatusCode::RECOVERABLE;
225 const unsigned int genEventIndex,
229 ATH_MSG_DEBUG(
"Converting McEventCollection to TruthParticleContainer");
231 if (
nullptr ==
m_pdt ) {
233 "TruthParticleContainer if NO ParticleDataTable is "\
235 return StatusCode::FAILURE;
238 if (
nullptr == mcCollection ) {
240 return StatusCode::RECOVERABLE;
243 if ( mcCollection->
size() <= genEventIndex ) {
246 <<
"Requested element nbr : " << genEventIndex <<
" !!");
247 return StatusCode::RECOVERABLE;
253 ATH_MSG_DEBUG(
"Retrieve the GenEvent from given McEventCollection");
254 const HepMC::GenEvent *
evt = (*mcCollection)[genEventIndex];
255 container->
setGenEvent( mcCollection, genEventIndex, sg );
266 auto bcmapatt =
evt->attribute<HepMC::GenEventBarcodes>(
"barcodes");
267 if (!bcmapatt)
ATH_MSG_ERROR(
"TruthParticleCnvTool.cxx: Event does not contain barcodes attribute");
268 std::map<int, HepMC3::ConstGenParticlePtr> bcmap = bcmapatt->barcode_to_particle_map();
269 for (
const auto &[bc,hepMcPart]: bcmap) {
271 for (
auto hepMcPart: *
evt) {
279 visitor->
visit( mcPart );
286 ATH_MSG_ERROR(
"TruthParticle is not wrapping the GenParticle : "
287 << hepMcPart <<
" !!");
290 bcToMcPart[ mcLink.
compress() ] = mcPart;
301 const std::string& etIsolName
303 if ( etIsolName.empty() ) {
305 "TruthEtIsolations container (requested: ["
307 return StatusCode::RECOVERABLE;
311 if ( !evtStore()->
retrieve( etIsols, etIsolName ).isSuccess() ) {
312 ATH_MSG_WARNING(
"Could not retrieve the TruthEtIsolations container at ["
313 << etIsolName <<
"] !!");
314 return StatusCode::RECOVERABLE;
322 return StatusCode::SUCCESS;
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
def retrieve(aClass, aKey=None)
SG::ReadHandleKey< McEventCollection > m_mcEventsReadHandleKey
ReadHandleKey for the McEventCollection the TruthParticles will be made from.
Const iterator class for DataVector/DataList.
void setEtIsolations(const ElementLink< TruthEtIsolationsContainer > &etIsolations)
Setup the persistent pointer toward the TruthEtIsolations.
virtual int pdgId() const
Return enum indicating particle id the enum file is available in Event/EventKernel/PdtPdg....
Map_t m_particles
Dictionary to ease the extraction of a TruthParticle (contained by this collection) from the HepMC::G...
barcode_type compress() const
Hash the 32 bit barcode and 16 bit eventindex into a 32bit int.
const HepPDT::ParticleDataTable * m_pdt
Particle Property service.
int signal_process_id(const GenEvent &e)
ToolHandle< ITruthIsolationTool > IsolTool_t
PileuType_t
define some Pile-up classification Important : this classification is copied in McParticleAlgs/python...
static IProxyDict * store()
Fetch the current store.
IsolTool_t m_isolationTool
Pointer to the ITruthIsolationTool to be able to retrieve the previously computed transverse energy i...
const std::string & key() const
Return the StoreGate ID for the referenced object.
HepMC::ConstGenParticlePtr genParticle() const
Retrieve the GenParticle this TruthParticle has been made from (if any)
void setGenEventIndex(size_t index)
set the GenEvent index
TruthParticleCnvTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
a link optimized in size for a GenParticle in a McEventCollection
BooleanProperty m_doEtIsolation
Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle...
::StatusCode StatusCode
StatusCode definition for legacy code.
pointer_type ptr()
Dereference the pointer.
virtual StatusCode execute() const override
PileUpClassification::PileuType_t m_selectSignalType
Type of truth particle we want to create.
TruthParticle_v1 TruthParticle
Typedef to implementation.
void setGenEvent(const ElementLink< McEventCollection > &genEvent)
Setup the persistent pointer toward the HepMC::GenEvent this TruthParticleContainer is proxying.
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::unordered_map< long, const TruthParticle * > Map_t
barcode to TruthParticle dictionary
Information about type of data used to fill particle.
double charge(const T &p)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
virtual StatusCode initialize() override
Athena Algorithm's Hooks.
const_pointer_type ptr()
Dereference the pointer.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
virtual ~TruthParticleCnvTool()
Destructor:
int m_selectSignalTypeProp
Type of truth particle we want to create (property to be set by jobO)
void setParticles(const Map_t &parts)
Setup the dictionary of barcodes-to-TruthParticle.
const std::string & genEventName() const
Retrieve the name (StoreGate location) of the HepMC::GenEvent this TruthParticleContainer is proxying...
virtual void visit(TruthParticle *truthParticle) const =0
The method to visit a TruthParticle to apply further modifications to the instance at hand.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
#define ATH_MSG_WARNING(x)
SG::WriteHandleKey< TruthParticleContainer > m_mcPartsOutputWriteHandleKey
Output TruthParticle WriteHandleKey (built from the McEventCollection)
void setDataType(const int type)
Inline methods:
void setCharge(const ChargeType charge)
Set the charge of this TruthParticle.
size_type size() const noexcept
Returns the number of elements in the collection.
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...
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
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.