ATLAS Offline Software
Loading...
Searching...
No Matches
TruthParticleCnvTool Class Reference

AlgTool that converts, on the fly, on demand, each GenParticle to a TruthParticle and builds the TruthParticleContainer. More...

#include <TruthParticleCnvTool.h>

Inheritance diagram for TruthParticleCnvTool:
Collaboration diagram for TruthParticleCnvTool:

Public Member Functions

 TruthParticleCnvTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor with parameters:
virtual ~TruthParticleCnvTool ()
 Destructor:
virtual StatusCode initialize () override
 Athena Algorithm's Hooks.
virtual StatusCode execute () const override
virtual StatusCode execute (const EventContext &ctx) const override
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 collection).
void setDataType (const int type)
 Inline methods:
void setVxCandidateName (const std::string &name)

Protected Types

typedef ToolHandle< ITruthIsolationTool > IsolTool_t

Protected Attributes

BooleanProperty m_doEtIsolation
 Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle).
IsolTool_t m_isolationTool
 Pointer to the ITruthIsolationTool to be able to retrieve the previously computed transverse energy isolations.

Private Attributes

ParticleDataType::DataType m_dataType
 Type of data we are dealing with (Full/Fast/Truth/...).
int m_dataType_int
std::string m_vxCandidatesName
SG::ReadHandleKey< McEventCollection > m_mcEventsReadHandleKey {this,"McEvents","GEN_AOD","ReadHandleKey for the input McEventCollection, from which the TruthParticles will be made from"}
 ReadHandleKey for the McEventCollection the TruthParticles will be made from.
SG::WriteHandleKey< TruthParticleContainer > m_mcPartsOutputWriteHandleKey {this,"TruthParticlesOutput","SpclMC","WriteHandleKey for the output truth particles (built from the McEventCollection)"}
 Output TruthParticle WriteHandleKey (built from the McEventCollection).
PileUpClassification::PileuType_t m_selectSignalType
 Type of truth particle we want to create.
int m_selectSignalTypeProp
 Type of truth particle we want to create (property to be set by jobO).

Detailed Description

AlgTool that converts, on the fly, on demand, each GenParticle to a TruthParticle and builds the TruthParticleContainer.

So the GEN_AOD and TruthParticleContainer are identical in contents, only the interfaces are different: the TruthParticle class has the same interface as other AOD particles. Hence the analysis tools can operate on all the AOD particles (ie: including Mc Truth). When the AOD is created, the TruthParticleContainer is empty. When the user requests the TruthParticleContainer in his/her analysis code, a custom converter is triggered where by the GEN_AOD is convertered into the TruthParticleContainer using the TruthParticleCnvTool.

In pile-up events, the many GenEvent are grouped into 5 TruthParticleContainer according to the classification of : https://twiki.cern.ch/twiki/bin/viewauth/Atlas/PileupDigitization#Arrangement_of_Truth_Information

Definition at line 58 of file TruthParticleCnvTool.h.

Member Typedef Documentation

◆ IsolTool_t

Definition at line 144 of file TruthParticleCnvTool.h.

Constructor & Destructor Documentation

◆ TruthParticleCnvTool()

TruthParticleCnvTool::TruthParticleCnvTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor with parameters:

Public methods:

Constructors

Definition at line 44 of file TruthParticleCnvTool.cxx.

46 :
47 base_class( type, name, parent ),
51{
52 //
53 // Property declaration
54 //
55
56 declareProperty( "DataType",
58 "Type of data we are dealing with (Full/Fast/Truth...)" );
59
60 declareProperty( "TruthIsolationTool",
61 m_isolationTool = IsolTool_t( "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." );
65
66
67 declareProperty( "DoEtIsolations",
68 m_doEtIsolation = false,
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)." );
72
74
75 declareProperty( "SelectSignalType",
77 "Switch to select different type of signal\n"
78 " hard scatter 0\n"
79 " hard scatter plus minbias 1\n"
80 " only minbias -1\n"
81 "Default is hard scatter only." );
82
83 declareInterface<ITruthParticleCnvTool>(this);
84}
int m_selectSignalTypeProp
Type of truth particle we want to create (property to be set by jobO).
ToolHandle< ITruthIsolationTool > IsolTool_t
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:
BooleanProperty m_doEtIsolation
Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle...

◆ ~TruthParticleCnvTool()

TruthParticleCnvTool::~TruthParticleCnvTool ( )
virtual

Destructor:

Destructor.

Definition at line 88 of file TruthParticleCnvTool.cxx.

89{
90 ATH_MSG_DEBUG("Calling destructor");
91}
#define ATH_MSG_DEBUG(x,...)

Member Function Documentation

◆ convert()

StatusCode TruthParticleCnvTool::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 collection).

Const methods:

@in mcEvts the McEventCollection holding the HepMC::GenEvent we want to convert into a TruthParticleContainer @in genEvtIndex the index to the HepMC::GenEvent to be converted @out mcParts a valid pointer to a TruthParticleContainer which will be filled with adaptors to HepMC::GenParticles.

Get GenEvent from McEventCollection

Create a map to enhance access between GenParticles and TruthParticles

Definition at line 205 of file TruthParticleCnvTool.cxx.

209{
210 ATH_MSG_DEBUG("Converting McEventCollection to TruthParticleContainer");
211
212
213 if ( nullptr == mcCollection ) {
214 ATH_MSG_WARNING("Null pointer to McEventCollection !");
215 return StatusCode::RECOVERABLE;
216 }
217
218 if ( mcCollection->size() <= genEventIndex ) {
219 ATH_MSG_WARNING("McEventCollection size: " << mcCollection->size()
220 << endmsg
221 << "Requested element nbr : " << genEventIndex << " !!");
222 return StatusCode::RECOVERABLE;
223 }
224
225 const EventContext& ctx = Gaudi::Hive::currentContext();
226
228 ATH_MSG_DEBUG("Retrieve the GenEvent from given McEventCollection");
229 const HepMC::GenEvent * evt = (*mcCollection)[genEventIndex];
230 container->setGenEvent( mcCollection, genEventIndex, ctx );
231
232 // reserve enough space for the container so we don't have to relocate it
233 container->reserve( container->size() + evt->particles_size() );
234
236 TruthParticleContainer::Map_t bcToMcPart = container->m_particles;
237
238
239 // Process particles in barcode order.
240 auto bcmapatt = evt->attribute<HepMC::GenEventBarcodes>(HepMCStr::barcodes);
241 if (!bcmapatt){
242 ATH_MSG_ERROR("TruthParticleCnvTool.cxx: Event does not contain barcodes attribute");
243 return StatusCode::FAILURE;
244 }
245 std::map<int, HepMC3::ConstGenParticlePtr> bcmap = bcmapatt->barcode_to_particle_map();
246 for (const auto &[bc,hepMcPart]: bcmap) {
247
248 TruthParticle * mcPart = new TruthParticle( hepMcPart, container );
249 container->push_back( mcPart );
250
251 if ( visitor ) {
252 visitor->visit( mcPart );
253 }
254
255 mcPart->setCharge( MC::charge( int(mcPart->pdgId())) );
256 mcPart->setGenEventIndex( genEventIndex);
257
258 if ( hepMcPart != mcPart->genParticle() ) {
259 ATH_MSG_ERROR("TruthParticle is not wrapping the GenParticle : "
260 << hepMcPart << " !!");
261 }
262 HepMcParticleLink mcLink( bc, genEventIndex, HepMcParticleLink::IS_POSITION, HepMcParticleLink::IS_BARCODE, ctx ); // FIXME barcode-based
263 bcToMcPart[ mcLink.compress() ] = mcPart;
264
265 }//> end loop over particles
266
267 // at this point the whole GenEvent has been proxied.
268 // so we can setup its VectorMap
269 container->setParticles( bcToMcPart );
270
271 // connect the TruthParticleContainer to the container of TruthEtIsolations
272 // if it exists and if we are asked for
273 if ( m_doEtIsolation.value() ) {
274 const std::string& etIsolName
275 = m_isolationTool->etIsolationsName( container->genEventName() );
276 if ( etIsolName.empty() ) {
277 ATH_MSG_WARNING("Could not retrieve the name of the "
278 "TruthEtIsolations container (requested: ["
279 << container->genEventName() << "])");
280 return StatusCode::RECOVERABLE;
281 }
282
283 const TruthEtIsolationsContainer* etIsols = nullptr;
284 if ( !evtStore()->retrieve( etIsols, etIsolName ).isSuccess() ) {
285 ATH_MSG_WARNING("Could not retrieve the TruthEtIsolations container at ["
286 << etIsolName << "] !!");
287 return StatusCode::RECOVERABLE;
288 }
289
290 // index of HepMC::GenEvent within the McEventCollection is the same
291 // than the one of the TruthEtIsolations within the TruthEtIsolationsCont.
292 container->setEtIsolations( etIsols, genEventIndex );
293 }
294
295 return StatusCode::SUCCESS;
296}
#define endmsg
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
TruthEtIsolationsContainer
virtual void visit(TruthParticle *truthParticle) const =0
The method to visit a TruthParticle to apply further modifications to the instance at hand.
virtual int pdgId() const
Return enum indicating particle id the enum file is available in Event/EventKernel/PdtPdg....
std::unordered_map< long, const TruthParticle * > Map_t
barcode to TruthParticle dictionary
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.
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
double charge(const T &p)
const SG::AuxVectorData * container() const
Return the container holding this element.
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ execute() [1/2]

StatusCode TruthParticleCnvTool::execute ( ) const
overridevirtual

Definition at line 127 of file TruthParticleCnvTool.cxx.

128{
129 return execute (Gaudi::Hive::currentContext());
130}
virtual StatusCode execute() const override

◆ execute() [2/2]

StatusCode TruthParticleCnvTool::execute ( const EventContext & ctx) const
overridevirtual

Definition at line 133 of file TruthParticleCnvTool.cxx.

134{
135 ATH_MSG_DEBUG("Executing " << name() << "...");
136
137 //Setup WriteHandle, and record new TruthParticleContainer
138 SG::WriteHandle<TruthParticleContainer> mcPartsOutputWriteHandle(m_mcPartsOutputWriteHandleKey, ctx);
139 ATH_CHECK(mcPartsOutputWriteHandle.record(std::make_unique<TruthParticleContainer>()));
140
141 if (!mcPartsOutputWriteHandle.isValid()){
142 ATH_MSG_ERROR("Invalid WriteHandle for TruthParticleContainer with key: " << m_mcPartsOutputWriteHandleKey.key());
143 return StatusCode::FAILURE;
144 }
145
146 //Setup ReadHandle for input McEventCollection
147 SG::ReadHandle<McEventCollection> mcEventsReadHandle(m_mcEventsReadHandleKey, ctx);
148
149 if (!mcEventsReadHandle.isValid()){
150 ATH_MSG_WARNING("Invalid ReadHandle for McEventCollection with key ["
151 << m_mcEventsReadHandleKey.key() << "] !!"
152 << endmsg
153 << "TruthParticleContainer [" << m_mcPartsOutputWriteHandleKey.key()
154 << "] will be EMPTY !!");
155 return StatusCode::RECOVERABLE;
156 }
157
158 ATH_MSG_DEBUG(" Found McEventCollection of size = "<< mcEventsReadHandle->size() );
159 // do the actual convertion (it is merely an interface adaptation now...)
160 // selection for particles from minbias copied from the JetsFromTruthTool
161
162 std::size_t genEventIndex = 0;
163 const ITruthParticleVisitor* dummyVisitor = nullptr;
164 bool all_good = true;
165
166 McEventCollection::const_iterator fEvt = mcEventsReadHandle->begin();
167 McEventCollection::const_iterator lEvt = mcEventsReadHandle->end();
169
170 ATH_MSG_DEBUG(" Found McEventCollection iterators : "<< (fEvt-mcEventsReadHandle->begin()) << " to "<< (lEvt-mcEventsReadHandle->begin()) );
171
172 for(McEventCollection::const_iterator it=fEvt ; it != lEvt; ++it){
173 const HepMC::GenEvent* evt = *it;
174 // there are holes in a McEventCollection when pile-up is enabled
175 // so deal with it
176 if (nullptr == evt) {
177 continue;
178 }
179 genEventIndex = (it - mcEventsReadHandle->begin());
180 ATH_MSG_DEBUG(" adding event id="<< HepMC::signal_process_id(evt)<<" genEventIndex="<< genEventIndex );
181
182 if( HepMC::signal_process_id(evt) == 0 ) continue;
183 if (!this->convert( mcEventsReadHandle.ptr(), genEventIndex, mcPartsOutputWriteHandle.ptr(), dummyVisitor ).isSuccess()) {
184 ATH_MSG_DEBUG("Failed to convert an event...");
185 all_good = false;
186 }
187 }
188
189 // VERY IMPORTANT ! Reset the index to the first GenEvent included
190 // in this TruthParticleContainer. This will be used when read back from disk.
191 mcPartsOutputWriteHandle->setGenEvent( mcEventsReadHandle.ptr(), (fEvt - mcEventsReadHandle->begin() ) );
192
193
194 return all_good
195 ? StatusCode::SUCCESS
196 : StatusCode::RECOVERABLE;
197}
#define ATH_CHECK
Evaluate an expression and check for errors.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:861
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.
SG::WriteHandleKey< TruthParticleContainer > m_mcPartsOutputWriteHandleKey
Output TruthParticle WriteHandleKey (built from the McEventCollection).
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...
SG::ReadHandleKey< McEventCollection > m_mcEventsReadHandleKey
ReadHandleKey for the McEventCollection the TruthParticles will be made from.
int signal_process_id(const GenEvent &evt)
Definition GenEvent.h:572

◆ initialize()

StatusCode TruthParticleCnvTool::initialize ( )
overridevirtual

Athena Algorithm's Hooks.

Definition at line 95 of file TruthParticleCnvTool.cxx.

96{
97 ATH_MSG_INFO("Initializing " << name() << "...");
98
99 // retrieve the TruthIsolation tool only if asked for.
100 if ( m_doEtIsolation.value() ) {
101 ATH_CHECK(m_isolationTool.retrieve());
102 }
103 else {
104 m_isolationTool.disable();
105 }
106
107 //initialize DataHandleKeys
110
111 // for compatibility with earlier version we accept <0 values :
114
115
117 (" DoEtIsolations: [" << std::boolalpha
118 << m_doEtIsolation.value() << "]" << endmsg
119 << " McEvents: [" << m_mcEventsReadHandleKey.key() << "]" << endmsg
120 << " TruthParticlesOutput: [" << m_mcPartsOutputWriteHandleKey.key() << "]"
121 << endmsg
122 << " SelectSignalType: [" << m_selectSignalType << "]");
123
124 return StatusCode::SUCCESS;
125}
#define ATH_MSG_INFO(x,...)
PileuType_t
define some Pile-up classification Important : this classification is copied in McParticleAlgs/python...

◆ setDataType()

void TruthParticleCnvTool::setDataType ( const int type)
inline

Inline methods:

Definition at line 156 of file TruthParticleCnvTool.h.

◆ setVxCandidateName()

void TruthParticleCnvTool::setVxCandidateName ( const std::string & name)
inline

Definition at line 161 of file TruthParticleCnvTool.h.

162{
164}

Member Data Documentation

◆ m_dataType

ParticleDataType::DataType TruthParticleCnvTool::m_dataType
private

Type of data we are dealing with (Full/Fast/Truth/...).

Definition at line 109 of file TruthParticleCnvTool.h.

◆ m_dataType_int

int TruthParticleCnvTool::m_dataType_int
private

Definition at line 110 of file TruthParticleCnvTool.h.

◆ m_doEtIsolation

BooleanProperty TruthParticleCnvTool::m_doEtIsolation
protected

Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle).

Default is to not compute these Et-isolations (and save CPU)

Definition at line 142 of file TruthParticleCnvTool.h.

◆ m_isolationTool

IsolTool_t TruthParticleCnvTool::m_isolationTool
protected

Pointer to the ITruthIsolationTool to be able to retrieve the previously computed transverse energy isolations.

Definition at line 149 of file TruthParticleCnvTool.h.

◆ m_mcEventsReadHandleKey

SG::ReadHandleKey<McEventCollection> TruthParticleCnvTool::m_mcEventsReadHandleKey {this,"McEvents","GEN_AOD","ReadHandleKey for the input McEventCollection, from which the TruthParticles will be made from"}
private

ReadHandleKey for the McEventCollection the TruthParticles will be made from.

Definition at line 116 of file TruthParticleCnvTool.h.

116{this,"McEvents","GEN_AOD","ReadHandleKey for the input McEventCollection, from which the TruthParticles will be made from"};

◆ m_mcPartsOutputWriteHandleKey

SG::WriteHandleKey<TruthParticleContainer> TruthParticleCnvTool::m_mcPartsOutputWriteHandleKey {this,"TruthParticlesOutput","SpclMC","WriteHandleKey for the output truth particles (built from the McEventCollection)"}
private

Output TruthParticle WriteHandleKey (built from the McEventCollection).

Definition at line 120 of file TruthParticleCnvTool.h.

120{this,"TruthParticlesOutput","SpclMC","WriteHandleKey for the output truth particles (built from the McEventCollection)"};

◆ m_selectSignalType

PileUpClassification::PileuType_t TruthParticleCnvTool::m_selectSignalType
private

Type of truth particle we want to create.

Definition at line 124 of file TruthParticleCnvTool.h.

◆ m_selectSignalTypeProp

int TruthParticleCnvTool::m_selectSignalTypeProp
private

Type of truth particle we want to create (property to be set by jobO).

Definition at line 128 of file TruthParticleCnvTool.h.

◆ m_vxCandidatesName

std::string TruthParticleCnvTool::m_vxCandidatesName
private

Definition at line 112 of file TruthParticleCnvTool.h.


The documentation for this class was generated from the following files: