Commit 0a544cbc authored by Rachid Mazini's avatar Rachid Mazini
Browse files

Merge branch 'mpt_addTruthRecord' into '21.0'

Add truth incident to FCS muon punch through sim

See merge request !43301
parents c018055a 93f8fa84
...@@ -39,7 +39,7 @@ namespace ISF { ...@@ -39,7 +39,7 @@ namespace ISF {
virtual ~ITruthSvc() { } virtual ~ITruthSvc() { }
/** Register a truth incident */ /** Register a truth incident */
virtual void registerTruthIncident( ITruthIncident& truthincident) const = 0; virtual void registerTruthIncident( ITruthIncident& truthincident, bool saveAllChildren=false) const = 0;
/** Initialize the Truth Svc at the beginning of each event */ /** Initialize the Truth Svc at the beginning of each event */
virtual StatusCode initializeTruthCollection() = 0; virtual StatusCode initializeTruthCollection() = 0;
......
...@@ -155,10 +155,11 @@ StatusCode ISF::TruthSvc::releaseEvent() { ...@@ -155,10 +155,11 @@ StatusCode ISF::TruthSvc::releaseEvent() {
/** Register a truth incident */ /** Register a truth incident */
void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti) const { void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti, bool saveAllChildren) const {
const bool passWholeVertex = m_passWholeVertex || saveAllChildren;
// pass whole vertex or individual child particles // pass whole vertex or individual child particles
ti.setPassWholeVertices(m_passWholeVertex); ti.setPassWholeVertices(passWholeVertex);
// the GeoID // the GeoID
AtlasDetDescr::AtlasRegion geoID = ti.geoID(); AtlasDetDescr::AtlasRegion geoID = ti.geoID();
...@@ -201,7 +202,7 @@ void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti) const { ...@@ -201,7 +202,7 @@ void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti) const {
ATH_MSG_VERBOSE("At least one TruthStrategy passed."); ATH_MSG_VERBOSE("At least one TruthStrategy passed.");
// at least one truth strategy returned true // at least one truth strategy returned true
// -> record incident // -> record incident
recordIncidentToMCTruth( ti); recordIncidentToMCTruth(ti, passWholeVertex);
} else { } else {
// none of the truth strategies returned true // none of the truth strategies returned true
...@@ -231,7 +232,7 @@ void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti) const { ...@@ -231,7 +232,7 @@ void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti) const {
} }
/** Record the given truth incident to the MC Truth */ /** Record the given truth incident to the MC Truth */
void ISF::TruthSvc::recordIncidentToMCTruth( ISF::ITruthIncident& ti) const { void ISF::TruthSvc::recordIncidentToMCTruth( ISF::ITruthIncident& ti, bool passWholeVertex) const {
#ifdef DEBUG_TRUTHSVC #ifdef DEBUG_TRUTHSVC
ATH_MSG_INFO("Starting recordIncidentToMCTruth(...)"); ATH_MSG_INFO("Starting recordIncidentToMCTruth(...)");
#endif #endif
...@@ -335,7 +336,7 @@ void ISF::TruthSvc::recordIncidentToMCTruth( ISF::ITruthIncident& ti) const { ...@@ -335,7 +336,7 @@ void ISF::TruthSvc::recordIncidentToMCTruth( ISF::ITruthIncident& ti) const {
std::vector<HepMC::GenParticle*> matchedChildParticles; std::vector<HepMC::GenParticle*> matchedChildParticles;
for ( unsigned short i=0; i<numSec; ++i) { for ( unsigned short i=0; i<numSec; ++i) {
bool writeOutChild = isQuasiStableVertex || m_passWholeVertex || ti.childPassedFilters(i); bool writeOutChild = isQuasiStableVertex || passWholeVertex || ti.childPassedFilters(i);
if (writeOutChild) { if (writeOutChild) {
HepMC::GenParticle *p = nullptr; HepMC::GenParticle *p = nullptr;
......
...@@ -76,7 +76,7 @@ namespace ISF { ...@@ -76,7 +76,7 @@ namespace ISF {
StatusCode finalize() override final; StatusCode finalize() override final;
/** Register a truth incident */ /** Register a truth incident */
void registerTruthIncident( ITruthIncident& truthincident) const override final; void registerTruthIncident( ITruthIncident& truthincident, bool saveAllChildren=false) const override final;
/** Initialize the Truth Svc at the beginning of each event */ /** Initialize the Truth Svc at the beginning of each event */
StatusCode initializeTruthCollection() override final; StatusCode initializeTruthCollection() override final;
...@@ -86,7 +86,7 @@ namespace ISF { ...@@ -86,7 +86,7 @@ namespace ISF {
private: private:
/** Record the given truth incident to the MC Truth */ /** Record the given truth incident to the MC Truth */
void recordIncidentToMCTruth( ITruthIncident& truthincident) const; void recordIncidentToMCTruth( ITruthIncident& truthincident, bool passWholeVertex) const;
/** Record and end vertex to the MC Truth for the parent particle */ /** Record and end vertex to the MC Truth for the parent particle */
HepMC::GenVertex *createGenVertexFromTruthIncident( ITruthIncident& truthincident, HepMC::GenVertex *createGenVertexFromTruthIncident( ITruthIncident& truthincident,
bool replaceExistingGenVertex=false) const; bool replaceExistingGenVertex=false) const;
......
...@@ -355,7 +355,7 @@ namespace ISFTesting { ...@@ -355,7 +355,7 @@ namespace ISFTesting {
.Times(1) .Times(1)
.WillOnce(::testing::Return(nullptr)); .WillOnce(::testing::Return(nullptr));
recordIncidentToMCTruth(ti); recordIncidentToMCTruth(ti,false);
HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this. HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this.
ASSERT_EQ( vtxPosition, generated->position() ); ASSERT_EQ( vtxPosition, generated->position() );
ASSERT_EQ( 1021, generated->id() ); ASSERT_EQ( 1021, generated->id() );
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
// ISF includes // ISF includes
#include "ISF_Event/ISFParticle.h" #include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ISFParticleContainer.h" #include "ISF_Event/ISFParticleVector.h"
namespace Trk{ namespace Trk{
class Track; class Track;
...@@ -37,7 +37,7 @@ namespace ISF { ...@@ -37,7 +37,7 @@ namespace ISF {
DeclareInterfaceID(IPunchThroughTool, 1, 0); DeclareInterfaceID(IPunchThroughTool, 1, 0);
/** Creates new vector of ISFParticle out of a given ISFParticle */ /** Creates new vector of ISFParticle out of a given ISFParticle */
virtual const ISF::ISFParticleContainer* computePunchThroughParticles(const ISFParticle& isfp ) const = 0; virtual const ISF::ISFParticleVector* computePunchThroughParticles(const ISFParticle& isfp ) const = 0;
}; };
} // end of namespace } // end of namespace
......
...@@ -280,14 +280,12 @@ StatusCode ISF::NativeFastCaloSimSvc::simulate(const ISF::ISFParticle& isfp) ...@@ -280,14 +280,12 @@ StatusCode ISF::NativeFastCaloSimSvc::simulate(const ISF::ISFParticle& isfp)
if (m_doPunchThrough) { if (m_doPunchThrough) {
// call punch-through simulation // call punch-through simulation
const ISF::ISFParticleContainer* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp); const ISF::ISFParticleVector* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp);
// add punch-through particles to the ISF particle broker // add punch-through particles to the ISF particle broker
if (isfpVec) { if (isfpVec) {
ISF::ISFParticleContainer::const_iterator partIt = isfpVec->begin(); for (ISF::ISFParticle *particle : *isfpVec) {
ISF::ISFParticleContainer::const_iterator partItEnd = isfpVec->end(); m_particleBroker->push( particle, &isfp);
for ( ; partIt!=partItEnd; ++partIt) {
m_particleBroker->push( *partIt, &isfp);
} }
} }
} }
...@@ -350,4 +348,3 @@ StatusCode ISF::NativeFastCaloSimSvc::processOneParticle( const ISF::ISFParticle ...@@ -350,4 +348,3 @@ StatusCode ISF::NativeFastCaloSimSvc::processOneParticle( const ISF::ISFParticle
// ATH_MSG_VERBOSE ( m_screenOutputPrefix << "kill the particle in the end"); // ATH_MSG_VERBOSE ( m_screenOutputPrefix << "kill the particle in the end");
return sc; return sc;
} }
...@@ -114,6 +114,7 @@ def getFastCaloSimSvcV2(name="ISF_FastCaloSimSvcV2", **kwargs): ...@@ -114,6 +114,7 @@ def getFastCaloSimSvcV2(name="ISF_FastCaloSimSvcV2", **kwargs):
kwargs.setdefault("RandomStream" , ISF_FastCaloSimFlags.RandomStreamName()) kwargs.setdefault("RandomStream" , ISF_FastCaloSimFlags.RandomStreamName())
kwargs.setdefault("RandomSvc" , simFlags.RandomSvc.get_Value() ) kwargs.setdefault("RandomSvc" , simFlags.RandomSvc.get_Value() )
kwargs.setdefault("ParticleTruthSvc" , simFlags.TruthStrategy.TruthServiceName() )
return CfgMgr.ISF__FastCaloSimSvcV2(name, **kwargs ) return CfgMgr.ISF__FastCaloSimSvcV2(name, **kwargs )
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
// ISF includes // ISF includes
#include "ISF_Event/ISFParticle.h" #include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ISFParticleContainer.h" #include "ISF_Event/ISFParticleVector.h"
// HepMC include needed for FastCaloSim // HepMC include needed for FastCaloSim
#include "HepMC/GenParticle.h" #include "HepMC/GenParticle.h"
...@@ -283,12 +283,12 @@ StatusCode ISF::FastCaloSimSvc::simulate(const ISF::ISFParticle& isfp) ...@@ -283,12 +283,12 @@ StatusCode ISF::FastCaloSimSvc::simulate(const ISF::ISFParticle& isfp)
if (m_doPunchThrough) { if (m_doPunchThrough) {
// call punch-through simulation // call punch-through simulation
const ISF::ISFParticleContainer* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp); const ISF::ISFParticleVector* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp);
// add punch-through particles to the ISF particle broker // add punch-through particles to the ISF particle broker
if (isfpVec) { if (isfpVec) {
ISF::ISFParticleContainer::const_iterator partIt = isfpVec->begin(); ISF::ISFParticleVector::const_iterator partIt = isfpVec->begin();
ISF::ISFParticleContainer::const_iterator partItEnd = isfpVec->end(); ISF::ISFParticleVector::const_iterator partItEnd = isfpVec->end();
for ( ; partIt!=partItEnd; ++partIt) { for ( ; partIt!=partItEnd; ++partIt) {
m_particleBroker->push( *partIt, &isfp); m_particleBroker->push( *partIt, &isfp);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
// ISF includes // ISF includes
#include "ISF_Event/ISFParticle.h" #include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ISFParticleContainer.h" #include "ISF_Event/ISFParticleVector.h"
// HepMC include needed for FastCaloSim // HepMC include needed for FastCaloSim
#include "HepMC/GenParticle.h" #include "HepMC/GenParticle.h"
...@@ -512,13 +512,13 @@ StatusCode ISF::FastCaloSimSvcPU::simulate(const ISF::ISFParticle& isfp) ...@@ -512,13 +512,13 @@ StatusCode ISF::FastCaloSimSvcPU::simulate(const ISF::ISFParticle& isfp)
if (m_doPunchThrough) if (m_doPunchThrough)
{ {
// call punch-through simulation // call punch-through simulation
const ISF::ISFParticleContainer* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp); const ISF::ISFParticleVector* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp);
// add punch-through particles to the ISF particle broker // add punch-through particles to the ISF particle broker
if (isfpVec) if (isfpVec)
{ {
ISF::ISFParticleContainer::const_iterator partIt = isfpVec->begin(); ISF::ISFParticleVector::const_iterator partIt = isfpVec->begin();
ISF::ISFParticleContainer::const_iterator partItEnd = isfpVec->end(); ISF::ISFParticleVector::const_iterator partItEnd = isfpVec->end();
for ( ; partIt!=partItEnd; ++partIt) for ( ; partIt!=partItEnd; ++partIt)
{ {
m_particleBroker->push( *partIt, &isfp); m_particleBroker->push( *partIt, &isfp);
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "StoreGate/StoreGateSvc.h" #include "StoreGate/StoreGateSvc.h"
#include "StoreGate/StoreGate.h" #include "StoreGate/StoreGate.h"
#include "ISF_Interfaces/IParticleBroker.h" #include "ISF_Interfaces/IParticleBroker.h"
#include "ISF_Interfaces/ITruthSvc.h"
#include "ISF_Event/ISFTruthIncident.h"
#include "CaloEvent/CaloCellContainer.h" #include "CaloEvent/CaloCellContainer.h"
...@@ -52,6 +54,7 @@ ISF::FastCaloSimSvcV2::FastCaloSimSvcV2(const std::string& name, ISvcLocator* sv ...@@ -52,6 +54,7 @@ ISF::FastCaloSimSvcV2::FastCaloSimSvcV2(const std::string& name, ISvcLocator* sv
, m_doPunchThrough(false) , m_doPunchThrough(false)
, m_punchThroughTool("") , m_punchThroughTool("")
, m_particleBroker ("ISF_ParticleBroker",name) , m_particleBroker ("ISF_ParticleBroker",name)
, m_truthRecordSvc("ISF_TruthRecordSvc", name)
{ {
declareProperty("ParamSvc" , m_paramSvc); declareProperty("ParamSvc" , m_paramSvc);
...@@ -64,6 +67,8 @@ ISF::FastCaloSimSvcV2::FastCaloSimSvcV2(const std::string& name, ISvcLocator* sv ...@@ -64,6 +67,8 @@ ISF::FastCaloSimSvcV2::FastCaloSimSvcV2(const std::string& name, ISvcLocator* sv
declareProperty("RandomStream" , m_randomEngineName ); declareProperty("RandomStream" , m_randomEngineName );
declareProperty("FastCaloSimCaloExtrapolation" , m_FastCaloSimCaloExtrapolation ); declareProperty("FastCaloSimCaloExtrapolation" , m_FastCaloSimCaloExtrapolation );
declareProperty("ParticleBroker" , m_particleBroker, "ISF ParticleBroker Svc" ); declareProperty("ParticleBroker" , m_particleBroker, "ISF ParticleBroker Svc" );
declareProperty("ParticleTruthSvc" , m_truthRecordSvc, "ISF Particle Truth Svc" );
} }
/** framework methods */ /** framework methods */
...@@ -79,6 +84,11 @@ StatusCode ISF::FastCaloSimSvcV2::initialize() ...@@ -79,6 +84,11 @@ StatusCode ISF::FastCaloSimSvcV2::initialize()
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
if (m_truthRecordSvc.retrieve().isFailure()){
ATH_MSG_FATAL( "Could not retrieve " << m_truthRecordSvc );
return StatusCode::FAILURE;
}
if (m_doPunchThrough && m_punchThroughTool.retrieve().isFailure() ) if (m_doPunchThrough && m_punchThroughTool.retrieve().isFailure() )
{ {
ATH_MSG_ERROR (m_punchThroughTool.propertyName() << ": Failed to retrieve tool " << m_punchThroughTool.type()); ATH_MSG_ERROR (m_punchThroughTool.propertyName() << ": Failed to retrieve tool " << m_punchThroughTool.type());
...@@ -166,14 +176,27 @@ StatusCode ISF::FastCaloSimSvcV2::simulate(const ISF::ISFParticle& isfp) ...@@ -166,14 +176,27 @@ StatusCode ISF::FastCaloSimSvcV2::simulate(const ISF::ISFParticle& isfp)
Amg::Vector3D particle_direction(isfp.momentum().x(),isfp.momentum().y(),isfp.momentum().z()); Amg::Vector3D particle_direction(isfp.momentum().x(),isfp.momentum().y(),isfp.momentum().z());
if (m_doPunchThrough) { if (m_doPunchThrough) {
Barcode::PhysicsProcessCode process = 201;
// call punch-through simulation // call punch-through simulation
const ISF::ISFParticleContainer* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp); const ISF::ISFParticleVector* isfpVec = m_punchThroughTool->computePunchThroughParticles(isfp);
// add punch-through particles to the ISF particle broker // add punch-through particles to the ISF particle broker
if (isfpVec) { if (isfpVec) {
//Record truth incident for created punch through particles
ISF::ISFTruthIncident truth( const_cast<ISF::ISFParticle&>(isfp),
*isfpVec,
process,
isfp.nextGeoID(), // inherits from the parent
ISF::fKillsPrimary);
m_truthRecordSvc->registerTruthIncident( truth, true );
for (ISF::ISFParticle *particle : *isfpVec) { for (ISF::ISFParticle *particle : *isfpVec) {
m_particleBroker->push( particle, &isfp); m_particleBroker->push( particle, &isfp);
} }
} }
} }
......
...@@ -86,6 +86,8 @@ namespace ISF { ...@@ -86,6 +86,8 @@ namespace ISF {
bool m_doPunchThrough; bool m_doPunchThrough;
ToolHandle< IPunchThroughTool > m_punchThroughTool; ToolHandle< IPunchThroughTool > m_punchThroughTool;
ServiceHandle<ISF::IParticleBroker> m_particleBroker; ServiceHandle<ISF::IParticleBroker> m_particleBroker;
ServiceHandle<ISF::ITruthSvc> m_truthRecordSvc; //!< Truth Svc for truth tree
}; };
......
...@@ -346,12 +346,12 @@ StatusCode ISF::PunchThroughTool::finalize() ...@@ -346,12 +346,12 @@ StatusCode ISF::PunchThroughTool::finalize()
* ==> see headerfile * ==> see headerfile
*=======================================================================*/ *=======================================================================*/
const ISF::ISFParticleContainer* ISF::PunchThroughTool::computePunchThroughParticles(const ISF::ISFParticle &isfp) const const ISF::ISFParticleVector* ISF::PunchThroughTool::computePunchThroughParticles(const ISF::ISFParticle &isfp) const
{ {
ATH_MSG_DEBUG( "[ punchthrough ] starting punch-through simulation"); ATH_MSG_DEBUG( "[ punchthrough ] starting punch-through simulation");
// reset the output particle collection // reset the output particle collection
m_isfpCont = new ISF::ISFParticleContainer(); m_isfpCont = new ISF::ISFParticleVector();
// reset the parent GenEvent // reset the parent GenEvent
m_parentGenEvt = 0; m_parentGenEvt = 0;
...@@ -508,7 +508,7 @@ const ISF::ISFParticleContainer* ISF::PunchThroughTool::computePunchThroughParti ...@@ -508,7 +508,7 @@ const ISF::ISFParticleContainer* ISF::PunchThroughTool::computePunchThroughParti
int ISF::PunchThroughTool::getAllParticles(int pdg, int numParticles) const int ISF::PunchThroughTool::getAllParticles(int pdg, int numParticles) const
{ {
// first check if the ISF particle vector already exists // first check if the ISF particle vector already exists
if (!m_isfpCont) m_isfpCont = new ISFParticleContainer(); if (!m_isfpCont) m_isfpCont = new ISFParticleVector();
// get the current particle // get the current particle
PunchThroughParticle *p = m_particles[pdg]; PunchThroughParticle *p = m_particles[pdg];
...@@ -1006,6 +1006,7 @@ ISF::ISFParticle* ISF::PunchThroughTool::createExitPs( int pdg, ...@@ -1006,6 +1006,7 @@ ISF::ISFParticle* ISF::PunchThroughTool::createExitPs( int pdg,
ISF::ISFParticle* finalPar = new ISF::ISFParticle (pos, mom, mass, charge, pdg, pTime, *m_initPs, m_secBC); ISF::ISFParticle* finalPar = new ISF::ISFParticle (pos, mom, mass, charge, pdg, pTime, *m_initPs, m_secBC);
finalPar->setNextGeoID( AtlasDetDescr::fAtlasMS); finalPar->setNextGeoID( AtlasDetDescr::fAtlasMS);
// return the punch-through particle // return the punch-through particle
return finalPar; return finalPar;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "BarcodeEvent/PhysicsProcessCode.h" #include "BarcodeEvent/PhysicsProcessCode.h"
#include "GeoPrimitives/GeoPrimitives.h" #include "GeoPrimitives/GeoPrimitives.h"
#include "ISF_Event/ISFParticleVector.h"
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Forward declarations * Forward declarations
*-------------------------------------------------------------------------*/ *-------------------------------------------------------------------------*/
...@@ -63,7 +64,7 @@ namespace ISF { ...@@ -63,7 +64,7 @@ namespace ISF {
/** AlgTool finalize method */ /** AlgTool finalize method */
virtual StatusCode finalize (); virtual StatusCode finalize ();
/** interface function: fill a vector with the punch-through particles */ /** interface function: fill a vector with the punch-through particles */
const ISF::ISFParticleContainer* computePunchThroughParticles(const ISF::ISFParticle &isfp) const; const ISF::ISFParticleVector* computePunchThroughParticles(const ISF::ISFParticle &isfp) const;
private: private:
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
...@@ -123,7 +124,7 @@ namespace ISF { ...@@ -123,7 +124,7 @@ namespace ISF {
double m_z2{0.}; double m_z2{0.};
/** the returned vector of ISFParticles */ /** the returned vector of ISFParticles */
mutable ISF::ISFParticleContainer *m_isfpCont{nullptr}; mutable ISF::ISFParticleVector *m_isfpCont{nullptr};
/** parent event */ /** parent event */
mutable HepMC::GenEvent* m_parentGenEvt{nullptr}; //!< all newly created particles/vertices will have this common parent mutable HepMC::GenEvent* m_parentGenEvt{nullptr}; //!< all newly created particles/vertices will have this common parent
......
Markdown is supported
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