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 {
virtual ~ITruthSvc() { }
/** 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 */
virtual StatusCode initializeTruthCollection() = 0;
......
......@@ -155,10 +155,11 @@ StatusCode ISF::TruthSvc::releaseEvent() {
/** 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
ti.setPassWholeVertices(m_passWholeVertex);
ti.setPassWholeVertices(passWholeVertex);
// the GeoID
AtlasDetDescr::AtlasRegion geoID = ti.geoID();
......@@ -201,7 +202,7 @@ void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti) const {
ATH_MSG_VERBOSE("At least one TruthStrategy passed.");
// at least one truth strategy returned true
// -> record incident
recordIncidentToMCTruth( ti);
recordIncidentToMCTruth(ti, passWholeVertex);
} else {
// none of the truth strategies returned true
......@@ -231,7 +232,7 @@ void ISF::TruthSvc::registerTruthIncident( ISF::ITruthIncident& ti) const {
}
/** 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
ATH_MSG_INFO("Starting recordIncidentToMCTruth(...)");
#endif
......@@ -335,7 +336,7 @@ void ISF::TruthSvc::recordIncidentToMCTruth( ISF::ITruthIncident& ti) const {
std::vector<HepMC::GenParticle*> matchedChildParticles;
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) {
HepMC::GenParticle *p = nullptr;
......
......@@ -76,7 +76,7 @@ namespace ISF {
StatusCode finalize() override final;
/** 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 */
StatusCode initializeTruthCollection() override final;
......@@ -86,7 +86,7 @@ namespace ISF {
private:
/** 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 */
HepMC::GenVertex *createGenVertexFromTruthIncident( ITruthIncident& truthincident,
bool replaceExistingGenVertex=false) const;
......
......@@ -355,7 +355,7 @@ namespace ISFTesting {
.Times(1)
.WillOnce(::testing::Return(nullptr));
recordIncidentToMCTruth(ti);
recordIncidentToMCTruth(ti,false);
HepMC::GenVertex* generated = anEvent->barcode_to_vertex(-2); //Find a nicer way to get this.
ASSERT_EQ( vtxPosition, generated->position() );
ASSERT_EQ( 1021, generated->id() );
......
......@@ -10,7 +10,7 @@
// ISF includes
#include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ISFParticleContainer.h"
#include "ISF_Event/ISFParticleVector.h"
namespace Trk{
class Track;
......@@ -37,7 +37,7 @@ namespace ISF {
DeclareInterfaceID(IPunchThroughTool, 1, 0);
/** 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
......
......@@ -280,14 +280,12 @@ StatusCode ISF::NativeFastCaloSimSvc::simulate(const ISF::ISFParticle& isfp)
if (m_doPunchThrough) {
// 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
if (isfpVec) {
ISF::ISFParticleContainer::const_iterator partIt = isfpVec->begin();
ISF::ISFParticleContainer::const_iterator partItEnd = isfpVec->end();
for ( ; partIt!=partItEnd; ++partIt) {
m_particleBroker->push( *partIt, &isfp);
for (ISF::ISFParticle *particle : *isfpVec) {
m_particleBroker->push( particle, &isfp);
}
}
}
......@@ -350,4 +348,3 @@ StatusCode ISF::NativeFastCaloSimSvc::processOneParticle( const ISF::ISFParticle
// ATH_MSG_VERBOSE ( m_screenOutputPrefix << "kill the particle in the end");
return sc;
}
......@@ -114,6 +114,7 @@ def getFastCaloSimSvcV2(name="ISF_FastCaloSimSvcV2", **kwargs):
kwargs.setdefault("RandomStream" , ISF_FastCaloSimFlags.RandomStreamName())
kwargs.setdefault("RandomSvc" , simFlags.RandomSvc.get_Value() )
kwargs.setdefault("ParticleTruthSvc" , simFlags.TruthStrategy.TruthServiceName() )
return CfgMgr.ISF__FastCaloSimSvcV2(name, **kwargs )
......
......@@ -15,7 +15,7 @@
// ISF includes
#include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ISFParticleContainer.h"
#include "ISF_Event/ISFParticleVector.h"
// HepMC include needed for FastCaloSim
#include "HepMC/GenParticle.h"
......@@ -283,12 +283,12 @@ StatusCode ISF::FastCaloSimSvc::simulate(const ISF::ISFParticle& isfp)
if (m_doPunchThrough) {
// 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
if (isfpVec) {
ISF::ISFParticleContainer::const_iterator partIt = isfpVec->begin();
ISF::ISFParticleContainer::const_iterator partItEnd = isfpVec->end();
ISF::ISFParticleVector::const_iterator partIt = isfpVec->begin();
ISF::ISFParticleVector::const_iterator partItEnd = isfpVec->end();
for ( ; partIt!=partItEnd; ++partIt) {
m_particleBroker->push( *partIt, &isfp);
}
......
......@@ -15,7 +15,7 @@
// ISF includes
#include "ISF_Event/ISFParticle.h"
#include "ISF_Event/ISFParticleContainer.h"
#include "ISF_Event/ISFParticleVector.h"
// HepMC include needed for FastCaloSim
#include "HepMC/GenParticle.h"
......@@ -512,13 +512,13 @@ StatusCode ISF::FastCaloSimSvcPU::simulate(const ISF::ISFParticle& isfp)
if (m_doPunchThrough)
{
// 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
if (isfpVec)
{
ISF::ISFParticleContainer::const_iterator partIt = isfpVec->begin();
ISF::ISFParticleContainer::const_iterator partItEnd = isfpVec->end();
ISF::ISFParticleVector::const_iterator partIt = isfpVec->begin();
ISF::ISFParticleVector::const_iterator partItEnd = isfpVec->end();
for ( ; partIt!=partItEnd; ++partIt)
{
m_particleBroker->push( *partIt, &isfp);
......
......@@ -28,6 +28,8 @@
#include "StoreGate/StoreGateSvc.h"
#include "StoreGate/StoreGate.h"
#include "ISF_Interfaces/IParticleBroker.h"
#include "ISF_Interfaces/ITruthSvc.h"
#include "ISF_Event/ISFTruthIncident.h"
#include "CaloEvent/CaloCellContainer.h"
......@@ -52,6 +54,7 @@ ISF::FastCaloSimSvcV2::FastCaloSimSvcV2(const std::string& name, ISvcLocator* sv
, m_doPunchThrough(false)
, m_punchThroughTool("")
, m_particleBroker ("ISF_ParticleBroker",name)
, m_truthRecordSvc("ISF_TruthRecordSvc", name)
{
declareProperty("ParamSvc" , m_paramSvc);
......@@ -64,6 +67,8 @@ ISF::FastCaloSimSvcV2::FastCaloSimSvcV2(const std::string& name, ISvcLocator* sv
declareProperty("RandomStream" , m_randomEngineName );
declareProperty("FastCaloSimCaloExtrapolation" , m_FastCaloSimCaloExtrapolation );
declareProperty("ParticleBroker" , m_particleBroker, "ISF ParticleBroker Svc" );
declareProperty("ParticleTruthSvc" , m_truthRecordSvc, "ISF Particle Truth Svc" );
}
/** framework methods */
......@@ -79,6 +84,11 @@ StatusCode ISF::FastCaloSimSvcV2::initialize()
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() )
{
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)
Amg::Vector3D particle_direction(isfp.momentum().x(),isfp.momentum().y(),isfp.momentum().z());
if (m_doPunchThrough) {
Barcode::PhysicsProcessCode process = 201;
// 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
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) {
m_particleBroker->push( particle, &isfp);
}
}
}
......
......@@ -86,6 +86,8 @@ namespace ISF {
bool m_doPunchThrough;
ToolHandle< IPunchThroughTool > m_punchThroughTool;
ServiceHandle<ISF::IParticleBroker> m_particleBroker;
ServiceHandle<ISF::ITruthSvc> m_truthRecordSvc; //!< Truth Svc for truth tree
};
......
......@@ -346,12 +346,12 @@ StatusCode ISF::PunchThroughTool::finalize()
* ==> 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");
// reset the output particle collection
m_isfpCont = new ISF::ISFParticleContainer();
m_isfpCont = new ISF::ISFParticleVector();
// reset the parent GenEvent
m_parentGenEvt = 0;
......@@ -508,7 +508,7 @@ const ISF::ISFParticleContainer* ISF::PunchThroughTool::computePunchThroughParti
int ISF::PunchThroughTool::getAllParticles(int pdg, int numParticles) const
{
// 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
PunchThroughParticle *p = m_particles[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);
finalPar->setNextGeoID( AtlasDetDescr::fAtlasMS);
// return the punch-through particle
return finalPar;
}
......
......@@ -15,6 +15,7 @@
#include "BarcodeEvent/PhysicsProcessCode.h"
#include "GeoPrimitives/GeoPrimitives.h"
#include "ISF_Event/ISFParticleVector.h"
/*-------------------------------------------------------------------------
* Forward declarations
*-------------------------------------------------------------------------*/
......@@ -63,7 +64,7 @@ namespace ISF {
/** AlgTool finalize method */
virtual StatusCode finalize ();
/** 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:
/*---------------------------------------------------------------------
......@@ -123,7 +124,7 @@ namespace ISF {
double m_z2{0.};
/** the returned vector of ISFParticles */
mutable ISF::ISFParticleContainer *m_isfpCont{nullptr};
mutable ISF::ISFParticleVector *m_isfpCont{nullptr};
/** parent event */
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