Commit 4dc159cb authored by Andrii Verbytskyi's avatar Andrii Verbytskyi Committed by Walter Lampl
Browse files

hepmc3 nightly fixes 12012021 part 1

parent 86885750
......@@ -37,17 +37,18 @@ namespace Muon {
//================================================================
void MuonDecayTruthTrajectoryBuilder::
buildTruthTrajectory(TruthTrajectory *result, const HepMC::GenParticle *input) const
buildTruthTrajectory(TruthTrajectory *result, HepMC::ConstGenParticlePtr input) const
{
result->clear();
if(input) {
const HepMC::GenParticle *next(0), *current = input;
HepMC::ConstGenParticlePtr next{nullptr};
auto current = input;
ATH_MSG_DEBUG( " New TruthTrajectory: input: barcode " << HepMC::barcode(input) << " PDG id " << input->pdg_id());
// Extend trajectory outwards. The last particle should go at [0]
// in the TruthTrajectory, so we need to use a tmp storage while
// traversing the structure.
std::stack<const HepMC::GenParticle*> tmp;
std::stack<HepMC::ConstGenParticlePtr> tmp;
while((next = getDaughter(current))) {
tmp.push(current = next);
}
......@@ -86,32 +87,34 @@ namespace Muon {
//================================================================
MuonDecayTruthTrajectoryBuilder::MotherDaughter
MuonDecayTruthTrajectoryBuilder::truthTrajectoryCuts(const HepMC::GenVertex *vtx) const
MuonDecayTruthTrajectoryBuilder::truthTrajectoryCuts(HepMC::ConstGenVertexPtr vtx) const
{
const HepMC::GenParticle *mother(0), *daughter(0);
if( vtx && msgLvl(MSG::DEBUG) ) msg(MSG::DEBUG) << " new vertex: nparticles in " << vtx->particles_in_size() << endmsg;
HepMC::ConstGenParticlePtr mother{nullptr};
HepMC::ConstGenParticlePtr daughter{nullptr};
#ifdef HEPMC3
int particles_in_size = vtx?vtx->particles_in().size():0;
int particles_out_size = vtx?vtx->particles_out().size():0;
#else
int particles_in_size = vtx?vtx->particles_in_size():0;
int particles_out_size = vtx?vtx->particles_out_size():0;
#endif
if( vtx && msgLvl(MSG::DEBUG) ) msg(MSG::DEBUG) << " new vertex: nparticles in " << particles_in_size << endmsg;
// only truth vertices with 1 incoming particle
if(vtx && (vtx->particles_in_size() == 1)) {
if(vtx && (particles_in_size == 1)) {
mother = *vtx->particles_in_const_begin();
if( mother && msgLvl(MSG::DEBUG) ) msg(MSG::DEBUG) << " new mother: " << mother->pdg_id() << " status " << mother->status() << " particles out " << vtx->particles_out_size() << endmsg;
if( mother && msgLvl(MSG::DEBUG) ) msg(MSG::DEBUG) << " new mother: " << mother->pdg_id() << " status " << mother->status() << " particles out " << particles_out_size << endmsg;
// Allow status code 1 and 2. E.g. a pion that produced a long track can decay outside of InDet and have status==2.
if( mother && (mother->status() < 3) ) {
unsigned int nDecayMuons = 0;
const HepMC::GenParticle *passed_cuts(0);
for(HepMC::GenVertex::particles_in_const_iterator it = vtx->particles_out_const_begin();
it != vtx->particles_out_const_end(); ++it) {
const HepMC::GenParticle *candidate = *it;
const HepMC::GenParticle& par = *candidate;
HepMC::ConstGenParticlePtr passed_cuts{nullptr};
for(auto candidate: *vtx) {
if( msgLvl(MSG::DEBUG) ){
msg(MSG::DEBUG) << " PDG ID " << par.pdg_id() << " barcode: " << HepMC::barcode(par) << " pt: " << par.momentum().perp();
if( par.production_vertex() ) msg(MSG::DEBUG) << " vertices prod: r " << par.production_vertex()->position().perp()
<< " z " << par.production_vertex()->position().z();
if( par.end_vertex() ) msg(MSG::DEBUG) << " end: r " << par.end_vertex()->position().perp() << " z " << par.end_vertex()->position().z();
msg(MSG::DEBUG) << " PDG ID " << candidate->pdg_id() << " barcode: " << HepMC::barcode(candidate) << " pt: " << candidate->momentum().perp();
if( candidate->production_vertex() ) msg(MSG::DEBUG) << " vertices prod: r " << candidate->production_vertex()->position().perp()
<< " z " << candidate->production_vertex()->position().z();
if( candidate->end_vertex() ) msg(MSG::DEBUG) << " end: r " << candidate->end_vertex()->position().perp() << " z " << candidate->end_vertex()->position().z();
msg(MSG::DEBUG) << endmsg;
}
......@@ -125,7 +128,7 @@ namespace Muon {
else {
passed_cuts = candidate;
}
}else if( abs(candidate->pdg_id()) == 13 ){
}else if( std::abs(candidate->pdg_id()) == 13 ){
ATH_MSG_DEBUG( " selecting Decay into muon ");
++nDecayMuons;
passed_cuts = candidate;
......@@ -149,9 +152,9 @@ namespace Muon {
}
//================================================================
const HepMC::GenParticle* MuonDecayTruthTrajectoryBuilder::getDaughter(const HepMC::GenParticle* mother) const {
HepMC::ConstGenParticlePtr MuonDecayTruthTrajectoryBuilder::getDaughter(HepMC::ConstGenParticlePtr mother) const {
const HepMC::GenParticle *daughter = 0;
HepMC::ConstGenParticlePtr daughter{nullptr};
if(mother) {
......@@ -166,9 +169,9 @@ namespace Muon {
}
//================================================================
const HepMC::GenParticle* MuonDecayTruthTrajectoryBuilder::getMother(const HepMC::GenParticle* daughter) const {
HepMC::ConstGenParticlePtr MuonDecayTruthTrajectoryBuilder::getMother(HepMC::ConstGenParticlePtr daughter) const {
const HepMC::GenParticle *mother = 0;
HepMC::ConstGenParticlePtr mother{nullptr};
if(daughter) {
MotherDaughter res = truthTrajectoryCuts(daughter->production_vertex());
......
......@@ -20,23 +20,23 @@ namespace Muon {
virtual StatusCode initialize();
void buildTruthTrajectory(TruthTrajectory *result, const HepMC::GenParticle *input) const;
void buildTruthTrajectory(TruthTrajectory *result, HepMC::ConstGenParticlePtr input) const;
/** Returns an umambiguous mother of the truth particle on a TruthTrajectory, or 0.
* Implemented via truthTrajectoryCuts().
*/
const HepMC::GenParticle* getMother(const HepMC::GenParticle* particle) const;
HepMC::ConstGenParticlePtr getMother(HepMC::ConstGenParticlePtr particle) const;
/** Returns an umambiguous daughter of the truth particle on a TruthTrajectory, or 0.
* This assumes no one mother can correspond to no more than one daughter.
* Implemented via truthTrajectoryCuts().
*/
const HepMC::GenParticle* getDaughter(const HepMC::GenParticle* particle) const;
HepMC::ConstGenParticlePtr getDaughter(HepMC::ConstGenParticlePtr particle) const;
private:
/** Return type for the next method */
typedef std::pair<const HepMC::GenParticle*, const HepMC::GenParticle*> MotherDaughter;
typedef std::pair<HepMC::ConstGenParticlePtr, HepMC::ConstGenParticlePtr> MotherDaughter;
/**
* Decides if the vertex connects two particles on the same
......@@ -47,7 +47,7 @@ namespace Muon {
* between mother and daughter particles; i.e. TruthTrajectories
* are not allowed to branch.
*/
MotherDaughter truthTrajectoryCuts(const HepMC::GenVertex *vtx) const;
MotherDaughter truthTrajectoryCuts(HepMC::ConstGenVertexPtr vtx) const;
// mutable bool m_isDecayIntoTwoMuons; // Really don't think this does anything? EJWM.
};
......
......@@ -174,8 +174,7 @@ TruthParticleFilterBase::buildMcAod (const McEventCollection* mc_in,
* @brief Filter a single @c GenEvent.
*/
StatusCode
TruthParticleFilterBase::filterEvent (const HepMC::GenEvent* ev_in,
HepMC::GenEvent* ev_out)
TruthParticleFilterBase::filterEvent (const HepMC::GenEvent* ev_in, HepMC::GenEvent* ev_out)
{
// Loop over particles.
// (range-based for doesn't work here because particle_const_iterator
......@@ -196,8 +195,7 @@ TruthParticleFilterBase::filterEvent (const HepMC::GenEvent* ev_in,
* @brief Add a @c GenParticle (and its production vertex) to a @c GenEvent.
*/
StatusCode
TruthParticleFilterBase::addParticle (const HepMC::GenParticle* p,
HepMC::GenEvent* ev)
TruthParticleFilterBase::addParticle (const HepMC::GenParticle* p, HepMC::GenEvent* ev)
{
// Add parent vertex if it exists. Otherwise, add decay vertex.
if (p->production_vertex())
......@@ -238,8 +236,7 @@ TruthParticleFilterBase::addParticle (const HepMC::GenParticle* p,
* @brief Add a @c GenVertex to a @c GenEvent.
*/
StatusCode
TruthParticleFilterBase::addVertex (const HepMC::GenVertex* v,
HepMC::GenEvent* ev)
TruthParticleFilterBase::addVertex (const HepMC::GenVertex* v, HepMC::GenEvent* ev)
{
// See if this vertex has already been copied.
HepMC::GenVertex* vnew = ev->barcode_to_vertex (v->barcode());
......
......@@ -273,8 +273,7 @@ TruthJetFilterTool::addParticle (const HepMC::GenParticle* p,
* @brief Add a @c GenVertex to a @c GenEvent.
*/
StatusCode
TruthJetFilterTool::addVertex (const HepMC::GenVertex* v,
HepMC::GenEvent* ev)
TruthJetFilterTool::addVertex (const HepMC::GenVertex* v,HepMC::GenEvent* ev)
{
// See if this vertex has already been copied.
HepMC::GenVertex* vnew = ev->barcode_to_vertex (v->barcode());
......@@ -318,12 +317,12 @@ bool TruthJetFilterTool::isLeptonFromTau(const HepMC::GenParticle* part) const{
int pdg = part->pdg_id();
if(abs(pdg) != 11 &&
abs(pdg) != 12 &&
abs(pdg) != 13 &&
abs(pdg) != 14 &&
abs(pdg) != 15 &&
abs(pdg) != 16) return false; // all leptons including tau.
if(std::abs(pdg) != 11 &&
std::abs(pdg) != 12 &&
std::abs(pdg) != 13 &&
std::abs(pdg) != 14 &&
std::abs(pdg) != 15 &&
std::abs(pdg) != 16) return false; // all leptons including tau.
HepMC::GenVertex* prod = part->production_vertex();
if(!prod) return false; // no parent.
......@@ -333,7 +332,7 @@ bool TruthJetFilterTool::isLeptonFromTau(const HepMC::GenParticle* part) const{
HepMC::GenVertex::particle_iterator endParent = prod->particles_end(HepMC::parents);
for(;itrParent!=endParent; ++itrParent){
int parentId = (*itrParent)->pdg_id();
if(abs(parentId) == 15) {
if(std::abs(parentId) == 15) {
ATH_MSG_DEBUG("Particle with pdgId = " << pdg << ", matched to tau");
return true; // Has tau parent
}
......
......@@ -20,11 +20,6 @@
#include "GaudiKernel/ITHistSvc.h"
#include "GaudiKernel/ServiceHandle.h"
// mc tools
//#include "McParticleKernel/IMcVtxFilterTool.h"
//#include "McParticleKernel/ITruthParticleCnvTool.h"
//#include "McParticleEvent/TruthParticle.h"
//#include "McParticleEvent/TruthParticleContainer.h"
#include "AtlasHepMC/GenEvent.h"
#include "AtlasHepMC/GenParticle.h"
#include "AtlasHepMC/GenVertex.h"
......
......@@ -255,8 +255,7 @@ GenAodValidationTool::executeTool( const HepMC::GenEvent* refMcEvts,
}
}
(*m_outFile) << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
<< std::endl;
(*m_outFile) << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
// loop over slimmed HepMC::GenEvent and check that vertices
// are comparable
......@@ -296,8 +295,7 @@ GenAodValidationTool::executeTool( const HepMC::GenEvent* refMcEvts,
bool GenAodValidationTool::compareVtx( const HepMC::GenVertex* vtx1,
const HepMC::GenVertex* vtx2 ) const
{
if ( 0 == vtx1 ||
0 == vtx2 ) {
if ( !vtx1 || !vtx2 ) {
ATH_MSG_ERROR("One of vertices is a NULL pointer !!" << endmsg
<< " vtx1: " << vtx1 << endmsg
<< " vtx2: " << vtx2);
......@@ -310,8 +308,7 @@ bool GenAodValidationTool::compareVtx( const HepMC::GenVertex* vtx1,
const int outVtx1 = vtx1->particles_out_size();
const int outVtx2 = vtx2->particles_out_size();
if ( inVtx1 != inVtx2 ||
outVtx1 != outVtx2 ) {
if ( inVtx1 != inVtx2 || outVtx1 != outVtx2 ) {
ATH_MSG_ERROR("Not the same number of branches !!" << endmsg
<< " in: " << inVtx1 << "\t" << inVtx2 << endmsg
<< " out: " << outVtx1 << "\t" << outVtx2);
......@@ -366,8 +363,7 @@ bool
GenAodValidationTool::compareParts( const HepMC::GenParticle* p1,
const HepMC::GenParticle* p2 ) const
{
if ( 0 == p1 ||
0 == p2 ) {
if ( !p1 || !p2 ) {
ATH_MSG_ERROR("One of particlees is a NULL pointer !!" << endmsg
<< " p1: " << p1 << endmsg
<< " p2: " << p2);
......@@ -416,7 +412,6 @@ StatusCode GenAodValidationTool::setupHepMcWriterTools()
if ( !m_refMcEventWriter.retrieve().isSuccess() ) {
ATH_MSG_ERROR("Creation of algTool ["
<< m_refMcEventWriter.type() << "/"
//<< m_refMcEventWriter.name()
<< "] FAILED !");
return StatusCode::FAILURE;
}
......@@ -424,7 +419,6 @@ StatusCode GenAodValidationTool::setupHepMcWriterTools()
if ( !m_checkMcEventWriter.retrieve().isSuccess() ) {
ATH_MSG_ERROR("Creation of algTool ["
<< m_checkMcEventWriter.type() << "/"
//<< m_checkMcEventWriter.name()
<< "] FAILED !");
return StatusCode::FAILURE;
}
......@@ -434,7 +428,6 @@ StatusCode GenAodValidationTool::setupHepMcWriterTools()
if ( m_refMcEventWriter->setProperty( refProp ).isFailure() ) {
ATH_MSG_ERROR("Could not set property [" << refProp.name()
<< "] for tool [" << m_refMcEventWriter.type() << "/"
//<< m_refMcEventWriter.name()
<< "] !");
return StatusCode::FAILURE;
}
......@@ -443,7 +436,6 @@ StatusCode GenAodValidationTool::setupHepMcWriterTools()
if ( m_checkMcEventWriter->setProperty( checkProp ).isFailure() ) {
ATH_MSG_ERROR("Could not set property [" << checkProp.name()
<< "] for tool [" << m_checkMcEventWriter.type() << "/"
//<< m_checkMcEventWriter.name()
<< "] !");
return StatusCode::FAILURE;
}
......
......@@ -380,13 +380,9 @@ StatusCode OldSpclMcFilterTool::shapeGenEvent( McEventCollection* genAod )
}
if ( bcNext.first != bcNext.second ) {
ATH_MSG_WARNING("\tIterator has been CORRUPTED !!" << endmsg
<< "\tbcNext: " << bcNext.first
<< " --> " << bcNext.second);
ATH_MSG_WARNING("\tIterator has been CORRUPTED !!" << endmsg << "\tbcNext: " << bcNext.first << " --> " << bcNext.second);
} else {
ATH_MSG_DEBUG("\tIterator OK:" << endmsg
<< "\tbcNext: " << bcNext.first
<< " --> " << bcNext.second);
ATH_MSG_DEBUG("\tIterator OK:" << endmsg << "\tbcNext: " << bcNext.first << " --> " << bcNext.second);
}
}
......
......@@ -387,7 +387,8 @@ StatusCode MergeMcEventCollTool::processEvent(const McEventCollection *pMcEvtCol
}
//GenEvt is there
//Examine the properties of the GenEvent - if it looks like a TruthFiltered background event (contains a Geantino?!) then save the whole event as below, otherwise do the usual classification.
//Examine the properties of the GenEvent - if it looks like a TruthFiltered background event (contains a Geantino?!)
//then save the whole event as below, otherwise do the usual classification.
if(isTruthFiltertedMcEventCollection(pMcEvtColl)) {
if ( processTruthFilteredEvent(pMcEvtColl, currentEventTime, currentBkgEventIndex).isSuccess() ) {
++m_nBkgEventsReadSoFar;
......
......@@ -30,7 +30,6 @@
#include <algorithm>
namespace {
//template<class Map> void printMap(const Map& m);
template<class Map> void printMap(const Map& m) {
std::cout<<"printMap(): [";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment