Commit 7bcd7e03 authored by scott snyder's avatar scott snyder Committed by scott snyder
Browse files

DerivationFrameworkMCTruth: Update GenericTruthThinning for MT thinning.

    
Convert GenericTruthThinning to use MT-compatible thinning.
Update uses of it (pass stream name rather than thinning service).
parent 04858a4c
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
......@@ -10,34 +10,42 @@
#define DERIVATIONFRAMEWORK_GENERICTRUTHTHINNING_H
#include <string>
#include <atomic>
#include "AthenaBaseComps/AthAlgTool.h"
#include "DerivationFrameworkInterfaces/IThinningTool.h"
#include "DerivationFrameworkMCTruth/DecayGraphHelper.h"
#include "xAODTruth/TruthVertexContainer.h"
#include "xAODTruth/TruthEventContainer.h"
#include "StoreGate/ThinningHandleKey.h"
#include "GaudiKernel/ToolHandle.h"
namespace ExpressionParsing {
class ExpressionParser;
}
class IThinningSvc;
namespace DerivationFramework {
class GenericTruthThinning : public AthAlgTool, public IThinningTool {
class GenericTruthThinning : public extends<AthAlgTool, IThinningTool> {
public:
GenericTruthThinning(const std::string& t, const std::string& n, const IInterface* p);
~GenericTruthThinning();
StatusCode initialize();
StatusCode finalize();
virtual StatusCode doThinning() const;
virtual ~GenericTruthThinning();
virtual StatusCode initialize() override;
virtual StatusCode finalize() override;
virtual StatusCode doThinning() const override;
private:
ServiceHandle<IThinningSvc> m_thinningSvc;
//ExpressionParsing::ExpressionParser *m_vertParser;
ExpressionParsing::ExpressionParser *m_partParser;
mutable unsigned int m_ntotvtx, m_ntotpart, m_npassvtx, m_npasspart;
std::string m_particlesKey, m_verticesKey, m_eventsKey;
mutable std::atomic<unsigned int> m_ntotvtx, m_ntotpart, m_npassvtx, m_npasspart;
StringProperty m_streamName
{ this, "StreamName", "", "Name of the stream being thinned" };
SG::ThinningHandleKey<xAOD::TruthParticleContainer> m_particlesKey
{ this, "ParticlesKey", "TruthParticles", "" };
SG::ThinningHandleKey<xAOD::TruthVertexContainer> m_verticesKey
{ this, "VerticesKey", "TruthVertices", "" };
std::string m_eventsKey;
std::string m_partString;
//std::string m_vtxString;
bool m_preserveDescendants;
......
......@@ -7,6 +7,25 @@ from DerivationFrameworkCore.DerivationFrameworkMaster import *
from DerivationFrameworkMCTruth.MCTruthCommon import *
from DerivationFrameworkTau.TauTruthCommon import *
augmentationTools = []
#==============================================================================
# Set up stream
#==============================================================================
streamName = derivationFlags.WriteDAOD_TRUTH1Stream.StreamName
fileName = buildFileName( derivationFlags.WriteDAOD_TRUTH1Stream )
TRUTH1Stream = MSMgr.NewPoolRootStream( streamName, fileName )
# Thinning
from AthenaServices.Configurables import ThinningSvc, createThinningSvc
augStream = MSMgr.GetStream( streamName )
evtStream = augStream.GetEventStream()
svcMgr += createThinningSvc( svcName="TRUTH1ThinningSvc", outStreams=[evtStream] )
# Only events that pass the filters listed are written out
# AcceptAlgs = logical OR of filters
# RequireAlgs = logical AND of filters
TRUTH1Stream.AcceptAlgs(['TRUTH1Kernel'])
#====================================================================
# JET/MET
#====================================================================
......@@ -142,7 +161,7 @@ ToolSvc += TRUTH1TruthThinning
#==============================================================================
from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
TRUTH1PhotonThinning = DerivationFramework__GenericTruthThinning(name = "TRUTH1PhotonThinning",
ThinningService = "TRUTH1ThinningSvc",
StreamName = streamName,
ParticlesKey = "TruthPhotons",
ParticleSelectionString = "(TruthPhotons.classifierParticleOrigin != 42) || (TruthPhotons.pt > 20.0*GeV)")
ToolSvc += TRUTH1PhotonThinning
......@@ -170,23 +189,6 @@ DerivationFrameworkJob += CfgMgr.DerivationFramework__DerivationKernel("TRUTH1Ke
AugmentationTools = augmentationTools,
ThinningTools = [TRUTH1TruthThinning,TRUTH1PhotonThinning])
#==============================================================================
# Set up stream
#==============================================================================
streamName = derivationFlags.WriteDAOD_TRUTH1Stream.StreamName
fileName = buildFileName( derivationFlags.WriteDAOD_TRUTH1Stream )
TRUTH1Stream = MSMgr.NewPoolRootStream( streamName, fileName )
# Thinning
from AthenaServices.Configurables import ThinningSvc, createThinningSvc
augStream = MSMgr.GetStream( streamName )
evtStream = augStream.GetEventStream()
svcMgr += createThinningSvc( svcName="TRUTH1ThinningSvc", outStreams=[evtStream] )
# Only events that pass the filters listed are written out
# AcceptAlgs = logical OR of filters
# RequireAlgs = logical AND of filters
TRUTH1Stream.AcceptAlgs(['TRUTH1Kernel'])
#==============================================================================
# Set up slimming content list here
#==============================================================================
......
......@@ -8,6 +8,23 @@ from RecExConfig.ObjKeyStore import objKeyStore
from xAODTruthCnv.xAODTruthCnvConf import xAODMaker__xAODTruthCnvAlg
from DerivationFrameworkMCTruth.TruthDerivationTools import *
#==============================================================================
# Set up stream
#==============================================================================
streamName = derivationFlags.WriteDAOD_TRUTH5Stream.StreamName
fileName = buildFileName( derivationFlags.WriteDAOD_TRUTH5Stream )
TRUTH5Stream = MSMgr.NewPoolRootStream( streamName, fileName )
# Thinning
from AthenaServices.Configurables import ThinningSvc, createThinningSvc
augStream = MSMgr.GetStream( streamName )
evtStream = augStream.GetEventStream()
svcMgr += createThinningSvc( svcName="TRUTH5ThinningSvc", outStreams=[evtStream] )
# Only events that pass the filters listed are written out
# AcceptAlgs = logical OR of filters
# RequireAlgs = logical AND of filters
TRUTH5Stream.AcceptAlgs(['TRUTH5Kernel'])
#====================================================================
# GEN_AOD and xAOD truth making
#====================================================================
......@@ -89,7 +106,7 @@ ToolSvc += TRUTH5TruthThinning
#==============================================================================
from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
TRUTH5PhotonThinning = DerivationFramework__GenericTruthThinning(name = "TRUTH5PhotonThinning",
ThinningService = "TRUTH5ThinningSvc",
StreamName = streamName,
ParticlesKey = "TruthPhotons",
ParticleSelectionString = "(TruthPhotons.classifierParticleOrigin != 42) || (TruthPhotons.pt > 20.0*GeV)")
ToolSvc += TRUTH5PhotonThinning
......@@ -107,23 +124,6 @@ DerivationFrameworkJob += CfgMgr.DerivationFramework__DerivationKernel("TRUTH5Ke
DFCommonTruthPhotonIsolationTool1, DFCommonTruthPhotonIsolationTool2],
ThinningTools = [TRUTH5TruthThinning,TRUTH5PhotonThinning])
#==============================================================================
# Set up stream
#==============================================================================
streamName = derivationFlags.WriteDAOD_TRUTH5Stream.StreamName
fileName = buildFileName( derivationFlags.WriteDAOD_TRUTH5Stream )
TRUTH5Stream = MSMgr.NewPoolRootStream( streamName, fileName )
# Thinning
from AthenaServices.Configurables import ThinningSvc, createThinningSvc
augStream = MSMgr.GetStream( streamName )
evtStream = augStream.GetEventStream()
svcMgr += createThinningSvc( svcName="TRUTH5ThinningSvc", outStreams=[evtStream] )
# Only events that pass the filters listed are written out
# AcceptAlgs = logical OR of filters
# RequireAlgs = logical AND of filters
TRUTH5Stream.AcceptAlgs(['TRUTH5Kernel'])
#==============================================================================
# Set up slimming content list here
#==============================================================================
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
/////////////////////////////////////////////////////////////////
......@@ -9,7 +9,6 @@
// Removes all truth particles/vertices which do not pass a user-defined cut
#include "DerivationFrameworkMCTruth/GenericTruthThinning.h"
#include "AthenaKernel/IThinningSvc.h"
#include "ExpressionEvaluation/ExpressionParser.h"
#include "ExpressionEvaluation/SGxAODProxyLoader.h"
#include "ExpressionEvaluation/SGNTUPProxyLoader.h"
......@@ -17,6 +16,8 @@
#include "xAODTruth/TruthParticleContainer.h"
#include "xAODTruth/TruthVertexContainer.h"
#include "xAODTruth/TruthEventContainer.h"
#include "StoreGate/ThinningHandle.h"
#include "GaudiKernel/ThreadLocalContext.h"
#include <vector>
#include <string>
......@@ -24,15 +25,11 @@
DerivationFramework::GenericTruthThinning::GenericTruthThinning(const std::string& t,
const std::string& n,
const IInterface* p ) :
AthAlgTool(t,n,p),
m_thinningSvc("ThinningSvc",n),
base_class(t,n,p),
m_ntotvtx(0),
m_ntotpart(0),
m_npassvtx(0),
m_npasspart(0),
m_particlesKey("TruthParticles"),
m_verticesKey("TruthVertices"),
m_eventsKey("TruthEvents"),
m_partString(""),
//m_vtxString(""),
m_preserveDescendants(false),
......@@ -41,9 +38,6 @@ m_preserveAncestors(false),
m_tauHandling(true),
m_geantOffset(200000)
{
declareInterface<DerivationFramework::IThinningTool>(this);
declareProperty("ThinningService", m_thinningSvc);
declareProperty("ParticlesKey", m_particlesKey);
declareProperty("VerticesKey", m_verticesKey);
declareProperty("EventsKey", m_eventsKey);
declareProperty("ParticleSelectionString", m_partString);
......@@ -63,10 +57,9 @@ DerivationFramework::GenericTruthThinning::~GenericTruthThinning() {
StatusCode DerivationFramework::GenericTruthThinning::initialize()
{
ATH_MSG_VERBOSE("initialize() ...");
if (m_particlesKey=="" || m_verticesKey=="") {
ATH_MSG_FATAL("No truth vertex/particle collection provided for thinning.");
return StatusCode::FAILURE;
} else {ATH_MSG_INFO("Using " << m_particlesKey << " and "<< m_verticesKey << " as the source collections for truth thinning");}
ATH_CHECK( m_particlesKey.initialize (m_streamName) );
ATH_CHECK( m_verticesKey.initialize (m_streamName) );
ATH_MSG_INFO("Using " << m_particlesKey.key() << " and "<< m_verticesKey.key() << " as the source collections for truth thinning");
if (m_partString==""/* && m_vtxString==""*/) {
ATH_MSG_FATAL("No selection string provided either for vertices or particles!");
......@@ -113,18 +106,14 @@ StatusCode DerivationFramework::GenericTruthThinning::finalize()
// The thinning itself
StatusCode DerivationFramework::GenericTruthThinning::doThinning() const
{
const EventContext& ctx = Gaudi::Hive::currentContext();
// Retrieve truth collections
const xAOD::TruthParticleContainer* importedTruthParticles;
if (evtStore()->retrieve(importedTruthParticles,m_particlesKey).isFailure()) {
ATH_MSG_ERROR("No TruthParticle collection with name " << m_particlesKey << " found in StoreGate!");
return StatusCode::FAILURE;
}
const xAOD::TruthVertexContainer* importedTruthVertices;
if (evtStore()->retrieve(importedTruthVertices,m_verticesKey).isFailure()) {
ATH_MSG_ERROR("No TruthVertex collection with name " << m_verticesKey << " found in StoreGate!");
return StatusCode::FAILURE;
}
SG::ThinningHandle<xAOD::TruthParticleContainer> importedTruthParticles
(m_particlesKey, ctx);
SG::ThinningHandle<xAOD::TruthVertexContainer> importedTruthVertices
(m_verticesKey, ctx);
const xAOD::TruthEventContainer* importedTruthEvents;
if (evtStore()->retrieve(importedTruthEvents,m_eventsKey).isFailure()) {
ATH_MSG_ERROR("No TruthEventContainer with name " << m_eventsKey << " found in StoreGate!");
......@@ -232,22 +221,12 @@ StatusCode DerivationFramework::GenericTruthThinning::doThinning() const
//}
// Count the masks
for (unsigned int i=0; i<nParticles; ++i) {
if (partMask[i]) ++m_npasspart;
}
for (unsigned int i=0; i<nVertices; ++i) {
if (vertMask[i]) ++m_npassvtx;
}
m_npasspart += std::count (partMask.begin(), partMask.end(), true);
m_npassvtx += std::count (vertMask.begin(), vertMask.end(), true);
// Execute the thinning service based on the mask. Finish.
if (m_thinningSvc->filter(*importedTruthParticles, partMask, IThinningSvc::Operator::Or).isFailure()) {
ATH_MSG_FATAL("Application of thinning service failed! ");
return StatusCode::FAILURE;
}
if (m_thinningSvc->filter(*importedTruthVertices, vertMask, IThinningSvc::Operator::Or).isFailure()) {
ATH_MSG_FATAL("Application of thinning service failed! ");
return StatusCode::FAILURE;
}
importedTruthParticles.keep (partMask);
importedTruthVertices.keep (vertMask);
return StatusCode::SUCCESS;
}
......
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