|
ATLAS Offline Software
|
Go to the documentation of this file.
7 #include "AthLinks/ElementLink.h"
9 #include "GaudiKernel/MsgStream.h"
10 #include "GaudiKernel/DataSvc.h"
11 #include "GaudiKernel/PhysicalConstants.h"
54 xAODTruthCnvAlg::xAODTruthCnvAlg(
const string&
name, ISvcLocator* svcLoc )
56 , m_metaStore(
"MetaDataStore",
name )
57 , m_firstBeginRun(true)
67 ATH_MSG_FATAL(
"Contradictory xAOD truth pile-up setting: all pile-up AND in-time alone requested simultaneously. Check settings." );
68 return StatusCode::FAILURE;
89 incSvc->addListener(
this,
"BeginRun", 10);
101 return StatusCode::SUCCESS;
108 ATH_CHECK(truthLinkVec.
record(std::make_unique<xAODTruthParticleLinkVector>()));
115 return StatusCode::FAILURE;
125 ATH_CHECK(xTruthEventContainer.
record(std::make_unique<xAOD::TruthEventContainer>(),
126 std::make_unique<xAOD::TruthEventAuxContainer>()));
133 ATH_CHECK(xTruthPileupEventContainer.
record(std::make_unique<xAOD::TruthPileupEventContainer>(),
134 std::make_unique<xAOD::TruthPileupEventAuxContainer>()));
140 ATH_CHECK(xTruthParticleContainer.
record(std::make_unique<xAOD::TruthParticleContainer>(),
141 std::make_unique<xAOD::TruthParticleAuxContainer>()));
145 ATH_CHECK(xTruthVertexContainer.
record(std::make_unique<xAOD::TruthVertexContainer>(),
146 std::make_unique<xAOD::TruthVertexAuxContainer>()));
182 bool newAttributesPresent(
false);
184 for (
unsigned int cntr = 0; cntr < mcColl->
size(); ++cntr) {
185 const HepMC::GenEvent* genEvt = (*mcColl)[cntr];
186 bool isSignalProcess(
false);
188 isSignalProcess=
true;
190 auto bunchCrossingTime = genEvt->attribute<HepMC3::IntAttribute>(
"BunchCrossingTime");
191 if (bunchCrossingTime) {
192 newAttributesPresent =
true;
205 isSignalProcess=
false;
207 auto bunchCrossingTime = genEvt->attribute<HepMC3::IntAttribute>(
"BunchCrossingTime");
208 if (bunchCrossingTime) {
222 if (newAttributesPresent) {
250 if (isSignalProcess) {
251 xTruthEventContainer->
push_back( xTruthEvent );
272 return StatusCode::FAILURE;
279 for (
const double&
w : genEvt->weights())
weights.push_back((
float)(
w));
285 auto const hiInfo = genEvt->heavy_ion();
323 auto const pdfInfo = genEvt->pdf_info();
350 xTruthPileupEventContainer->
push_back( xTruthPileupEvent );
359 vector<HepMC::ConstGenVertexPtr> vertices;
364 if (disconnectedSignalProcessVtx) {
365 if (disconnectedSignalProcessVtx->particles_in_size() == 0 && disconnectedSignalProcessVtx->particles_out_size() == 0 ) {
367 vertices.push_back (disconnectedSignalProcessVtx);
370 ATH_MSG_WARNING(
"Signal process vertex pointer not valid in HepMC Collection for GenEvent #" << cntr <<
" / " << mcColl->
size());
374 pair<HepMC::ConstGenParticlePtr,HepMC::ConstGenParticlePtr> beamParticles;
375 bool genEvt_valid_beam_particles=
false;
377 auto beamParticles_vec = genEvt->beams();
378 genEvt_valid_beam_particles=(beamParticles_vec.size()>1);
379 if (genEvt_valid_beam_particles){beamParticles.first=beamParticles_vec[0]; beamParticles.second=beamParticles_vec[1]; }
381 auto bcmapatt = genEvt->attribute<HepMC::GenEventBarcodes>(
"barcodes");
382 if (!bcmapatt)
ATH_MSG_ERROR(
"TruthParticleCnvTool.cxx: Event does not contain barcodes attribute");
383 std::map<int, HepMC3::ConstGenParticlePtr> bcmap = bcmapatt->barcode_to_particle_map();
384 xTruthParticleContainer->
reserve(bcmap.size());
385 for (
const auto &[genPartBarcode,
part]: bcmap) {
387 genEvt_valid_beam_particles=genEvt->valid_beam_particles();
388 if ( genEvt_valid_beam_particles ) beamParticles = genEvt->beam_particles();
389 xTruthParticleContainer->
reserve(genEvt->particles_size());
390 for (
auto part: *genEvt) {
396 xTruthParticleContainer->
push_back( xTruthParticle );
408 if (genEvt_valid_beam_particles) {
409 if (isSignalProcess) {
415 auto productionVertex =
part->production_vertex();
419 if (productionVertex && productionVertex->parent_event() !=
nullptr) {
421 if (
parts.incoming.empty() &&
parts.outgoing.empty())
422 vertices.push_back (productionVertex);
423 parts.outgoingEL.push_back(eltp);
424 parts.outgoing.push_back(xTruthParticle);
430 auto decayVertex =
part->end_vertex();
433 if (
parts.incoming.empty() &&
parts.outgoing.empty())
434 vertices.push_back (decayVertex);
435 parts.incomingEL.push_back(eltp);
436 parts.incoming.push_back(xTruthParticle);
443 xTruthVertexContainer->
reserve(vertices.size());
444 for (
const auto&
vertex : vertices) {
449 xTruthVertexContainer->
push_back( xTruthVertex );
468 if (isSignalProcess)
delete xTruthPileupEvent;
469 if (!isSignalProcess)
delete xTruthEvent;
477 return StatusCode::SUCCESS;
484 if(inputStore.retrieve().isFailure()) {
489 if(inputStore->retrieve(tagInfo,
"/TagInfo").isFailure()) {
490 ATH_MSG_WARNING(
"Failed to retrieve /TagInfo metadata from the input store");
493 if(tagInfo->payloadContainer()->size()>0) {
495 if(tagInfoPayload->
size()>0) {
497 if (al.exists(
"lhefGenerator")){
501 if (al.exists(
"generators")){
505 if (al.exists(
"evgenProcess")){
509 if (al.exists(
"evgenTune")){
513 if (al.exists(
"hardPDF")){
517 if (al.exists(
"softPDF")){
534 tv->
setX(gv->position().x());
535 tv->
setY(gv->position().y());
536 tv->
setZ(gv->position().z());
537 tv->
setT(gv->position().t());
543 tp->setPdgId(gp->pdg_id());
548 if (pol.is_defined()) {
553 tp->setM(gp->generated_mass());
554 tp->setPx(gp->momentum().px());
555 tp->setPy(gp->momentum().py());
556 tp->setPz(gp->momentum().pz());
557 tp->setE(gp->momentum().e());
563 const std::string& metaName)
567 auto md = std::make_unique<xAOD::TruthMetaDataContainer>();
570 auto aux = std::make_unique<xAOD::TruthMetaDataAuxContainer>();
571 md->setStore( aux.get() );
574 CHECK( metaStore->record( std::move (aux), metaName +
"Aux." ) );
575 CHECK( metaStore->record( std::move (md), metaName ) );
576 return StatusCode::SUCCESS;
582 const HepMC::GenEvent& genEvt,
591 m_tmd->push_back (std::make_unique <xAOD::TruthMetaData>());
597 std::vector<std::string> orderedWeightNameVec;
598 if (!genEvt.run_info()) {
601 if (!genEvt.run_info()->weight_names().empty()) {
602 orderedWeightNameVec = genEvt.weight_names();
613 const auto& weightNameMap = genEvt.weights().m_names;
614 std::vector<std::string> orderedWeightNameVec;
615 orderedWeightNameVec.reserve( weightNameMap.size() );
616 for (
const auto&
entry: weightNameMap) {
617 orderedWeightNameVec.push_back(
entry.first);
622 std::sort(orderedWeightNameVec.begin(), orderedWeightNameVec.end(),
623 [&](
const std::string&
i,
const std::string& j){return weightNameMap.at(i) < weightNameMap.at(j);});
641 if(!metaFields.
hardPDF.empty()) {
644 if(!metaFields.
softPDF.empty()) {
649 return StatusCode::SUCCESS;
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
JetConstituentVector::iterator iterator
int old_vertex_status_from_new(const int newStatus)
Get vertex status in the old scheme from the status in the new scheme.
void setCrossSection(float value)
Set the cross-section.
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerKey
void setSignalProcessVertexLink(const TruthVertexLink_t &link)
Set pointer to a vertex representing the primary beam interaction point.
Polarization polarization(const T &a)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
void setWeights(const std::vector< float > &weights)
Set the event weights.
SG::WriteHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerKey
The key for the output xAOD truth containers.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
int signal_process_id(const GenEvent &e)
TruthEvent_v1 TruthEvent
Typedef to implementation.
void setBeamParticle2Link(const TruthParticleLink_t &pcl2)
Set one incoming beam particle.
bool setHeavyIonParameter(int value, HIParam parameter)
Set an integer HI parameter.
void setT(float value)
Set the vertex time.
Class describing a pile-up truth event in the MC record.
void setIncomingParticleLinks(const TPLinks_t &links)
Set all the incoming particles.
@ NWOUNDEDNWOUNDEDCOLLISIONS
[int]
#define ATH_MSG_VERBOSE(x)
const std::string & key() const
Return the StoreGate ID for the referenced object.
std::string m_metaName
SG key and name for meta data.
void setY(float value)
Set the y displacement of the vertex.
This class is a collection of AttributeLists where each one is associated with a channel number....
void setOutgoingParticleLinks(const TPLinks_t &links)
Set all the outgoing particles.
void stable_sort(std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, std::reverse_iterator< DataModel_detail::iterator< DVL > > end, Compare comp)
Specialization of stable_sort for DataVector/List.
uint32_t runNumber() const
The current event's run number.
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
static void fillParticle(xAOD::TruthParticle *tp, const HepMC::ConstGenParticlePtr &gp)
An algorithm that can be simultaneously executed in multiple threads.
void addTruthParticleLink(const TruthParticleLink_t &plink)
Add one truth particle.
Gaudi::Property< bool > m_doInTimePileUp
uint32_t mcChannelNumber() const
The MC generator's channel number.
Handle class for recording to StoreGate.
a link optimized in size for a GenParticle in a McEventCollection
static void fillVertex(xAOD::TruthVertex *tv, const HepMC::ConstGenVertexPtr &gv)
These functions do not set up ELs, just the other variables.
@ NNWOUNDEDCOLLISIONS
[int]
int old_particle_status_from_new(const int newStatus)
Get particle status in the old scheme from the status in the new scheme.
bool m_firstBeginRun
Tag Info.
::StatusCode StatusCode
StatusCode definition for legacy code.
Class describing a truth particle in the MC record.
SG::WriteHandleKey< xAOD::TruthPileupEventContainer > m_xaodTruthPUEventContainerKey
bool setPdfInfoParameter(int value, PdfParam parameter)
Set an integer PDF info parameter.
TruthParticle_v1 TruthParticle
Typedef to implementation.
virtual void handle(const Incident &incident) override
Incident handler.
Class describing a signal truth event in the MC record.
SG::ReadHandleKey< McEventCollection > m_aodContainerKey
The key of the input AOD truth container.
TruthPileupEvent_v1 TruthPileupEvent
Typedef to implementation.
void setCrossSectionError(float value)
Set the cross-section error.
#define CHECK(...)
Evaluate an expression and check for errors.
const AttributeList & attributeList(ChanNum chanNum) const
attribute list for a given channel number
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
TruthVertex_v1 TruthVertex
Typedef to implementation.
virtual StatusCode initialize() override
Function initialising the algorithm.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteHandleKey< xAOD::TruthVertexContainer > m_xaodTruthVertexContainerKey
ElementLink implementation for ROOT usage.
MetadataFields m_metaFields
const GenParticle * ConstGenParticlePtr
Class describing a truth vertex in the MC record.
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfo
Event Info.
std::string to_string(const DetectorType &type)
Helpers for checking error return status codes and reporting errors.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Type for tracking particles connected to a single vertex.
void setId(int value)
Obsolete function Set vertex ID code HepMC2 id == HepMC3 status, i.e.
SG::WriteHandleKey< xAODTruthParticleLinkVector > m_truthLinkContainerKey
std::map< HepMC::ConstGenVertexPtr, VertexParticles > VertexMap
Convenience handle for a map of vtx ptrs -> connected particles.
size_type size() const
number of Chan/AttributeList pairs
Gaudi::Property< bool > m_writeMetaData
option to disable writing of metadata (e.g. if running a filter on xAOD in generators)
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
void setZ(float value)
Set the vertex's longitudinal distance from the origin.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setBarcode(int value)
Set barcode.
@ polarizationTheta
Polarization in ( )
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
#define ATH_MSG_WARNING(x)
@ polarizationPhi
Polarization in ( )
std::pair< HepMcParticleLink, ElementLink< xAOD::TruthParticleContainer > > xAODTruthParticleLink
ServiceHandle< StoreGateSvc > m_metaStore
Connection to the metadata store.
Gaudi::Property< bool > m_doAllPileUp
Pile-up options.
const HepMC::GenVertex * ConstGenVertexPtr
coral::AttributeList AttributeList
Handle class for reading from StoreGate.
bool isSeparatorGenEvent(const HepMC::GenEvent *genEvt)
size_type size() const noexcept
Returns the number of elements in the collection.
void addTruthVertexLink(const TruthVertexLink_t &vlink)
Add one truth vertex.
@ NWOUNDEDNCOLLISIONS
[int]
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
void setBeamParticle1Link(const TruthParticleLink_t &pcl1)
Set one incoming beam particle.
void setX(float value)
Set the x displacement of the vertex.
GenVertex * signal_process_vertex(const GenEvent *e)