Commit e8c3ec31 authored by Zach Marshall's avatar Zach Marshall
Browse files

Adding Keep children strategy and changing defaults

Adding the KeepChildrenTruthStrategy from !30161 to master. There were a
few interface changes to the truth strategy base class that had to be
added. Adding a few extra helper functions in the python setup (on top
of what was made available in !30161).

Finally, tweaking the defaults for the LLP truth setups to use these
strategies, since I think that's what we really want for MC15 and later.
parent daf05c8d
......@@ -222,7 +222,9 @@ def getMC15aPlusTruthService(name="ISF_MC15aPlusTruthService", **kwargs):
def getMC15aPlusLLPTruthService(name="ISF_MC15aPlusLLPTruthService", **kwargs):
kwargs.setdefault('TruthStrategies', ['ISF_MCTruthStrategyGroupID_MC15',
kwargs.setdefault('TruthStrategies', ['ISF_KeepLLPDecayChildrenStrategy',
'ISF_KeepLLPHadronicInteractionChildrenStrategy',
'ISF_MCTruthStrategyGroupID_MC15',
'ISF_MCTruthStrategyGroupIDHadInt_MC15',
'ISF_MCTruthStrategyGroupCaloMuBrem', #FIXME this should be ISF_MCTruthStrategyGroupCaloMuBrem_MC15!!
'ISF_MCTruthStrategyGroupCaloDecay_MC15',
......
......@@ -210,3 +210,29 @@ def getLLPTruthStrategy(name="ISF_LLPTruthStrategy", **kwargs):
kwargs.setdefault('PassProcessCategory', 9 ) # ==
kwargs.setdefault('Regions', [1,2,3,4])
return CfgMgr.ISF__LLPTruthStrategy(name, **kwargs);
def getKeepLLPDecayChildrenStrategy(name="ISF_KeepLLPDecayChildrenStrategy", **kwargs):
# ProcessCategory==9 corresponds to the 'fUserDefined' G4ProcessType:
# http://www-geant4.kek.jp/lxr/source//processes/management/include/G4ProcessType.hh
kwargs.setdefault('PassProcessCategory' , 9 ) # ==
kwargs.setdefault('VertexTypeRangeLow' , 200) # All kinds of decay processes
kwargs.setdefault('VertexTypeRangeHigh' , 299) # ...
kwargs.setdefault('BSMParent' , True)
return CfgMgr.ISF__KeepChildrenTruthStrategy(name, **kwargs);
def getKeepLLPHadronicInteractionChildrenStrategy(name="ISF_KeepLLPHadronicInteractionChildrenStrategy", **kwargs):
kwargs.setdefault('VertexTypes' , [ 111, 121, 131, 141, 151, 161, 210 ])
kwargs.setdefault('BSMParent' , True)
return CfgMgr.ISF__KeepChildrenTruthStrategy(name, **kwargs);
def getKeepAllDecayChildrenStrategy(name="ISF_KeepAllDecayChildrenStrategy", **kwargs):
# ProcessCategory==9 corresponds to the 'fUserDefined' G4ProcessType:
# http://www-geant4.kek.jp/lxr/source//processes/management/include/G4ProcessType.hh
kwargs.setdefault('PassProcessCategory' , 9 ) # ==
kwargs.setdefault('VertexTypeRangeLow' , 200) # All kinds of decay processes
kwargs.setdefault('VertexTypeRangeHigh' , 299) # ...
return CfgMgr.ISF__KeepChildrenTruthStrategy(name, **kwargs);
def getKeepHadronicInteractionChildrenStrategy(name="ISF_KeepHadronicInteractionChildrenStrategy", **kwargs):
kwargs.setdefault('VertexTypes' , [ 111, 121, 131, 141, 151, 161, 210 ])
return CfgMgr.ISF__KeepChildrenTruthStrategy(name, **kwargs);
......@@ -23,3 +23,8 @@ addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getTruthStrategyGroupCaloDecay",
addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getTruthStrategyGroupCaloDecay_MC15", "ISF_MCTruthStrategyGroupCaloDecay_MC15")
addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getValidationTruthStrategy", "ISF_ValidationTruthStrategy")
addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getLLPTruthStrategy", "ISF_LLPTruthStrategy")
# Truth Strategy Modifiers
addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getKeepLLPDecayChildrenStrategy", "ISF_KeepLLPDecayChildrenStrategy")
addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getKeepLLPHadronicInteractionChildrenStrategy", "ISF_KeepLLPHadronicInteractionChildrenStrategy")
addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getKeepAllDecayChildrenStrategy", "ISF_KeepAllDecayChildrenStrategy")
addTool("ISF_HepMC_Tools.ISF_HepMC_ToolsConfig.getKeepHadronicInteractionChildrenStrategy", "ISF_KeepHadronicInteractionChildrenStrategy")
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// KeepChildrenTruthStrategy.cxx, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
// class header include
#include "KeepChildrenTruthStrategy.h"
// ISF includes
#include "ISF_Event/ITruthIncident.h"
#include "ISF_Event/ISFParticle.h"
// For BSM helper
#include "TruthUtils/PIDHelpers.h"
/** Constructor **/
ISF::KeepChildrenTruthStrategy::KeepChildrenTruthStrategy(const std::string& t, const std::string& n, const IInterface* p)
: base_class(t,n,p)
, m_vertexTypesVector(0)
, m_vertexTypes()
, m_doVertexRangeCheck(false)
, m_vertexTypeRangeLow(0)
, m_vertexTypeRangeHigh(0)
, m_vertexTypeRangeLength(0)
, m_passProcessCategory(0)
, m_bsmParent(false)
, m_parentPdgCodesVector(0)
, m_parentPdgCodes()
{
// if set to true, kinetic cuts are passed even if only child particles pass them
// (used for special cases such as de-excitation)
declareProperty("VertexTypes" , m_vertexTypesVector );
declareProperty("VertexTypeRangeLow" , m_vertexTypeRangeLow );
declareProperty("VertexTypeRangeHigh" , m_vertexTypeRangeHigh );
declareProperty("PassProcessCategory", m_passProcessCategory=9);
declareProperty("ParentPDGCodes" , m_parentPdgCodesVector );
declareProperty("BSMParent" , m_bsmParent );
}
/** Destructor **/
ISF::KeepChildrenTruthStrategy::~KeepChildrenTruthStrategy()
{
}
// Athena algtool's Hooks
StatusCode ISF::KeepChildrenTruthStrategy::initialize()
{
ATH_MSG_VERBOSE("Initializing ...");
// VertexTypeRanges:
//
// check whether user input makes sense:
if ( m_vertexTypeRangeHigh < m_vertexTypeRangeLow) {
ATH_MSG_ERROR("The given parameter VertexTypeRangeLow is bigger than VertexTypeRangeHigh. ABORT");
return StatusCode::FAILURE;
}
// the length of the given vertex type range
m_vertexTypeRangeLength = unsigned(m_vertexTypeRangeHigh - m_vertexTypeRangeLow) + 1;
// if neither lower now upper range limit given, disable range check
m_doVertexRangeCheck = m_vertexTypeRangeLow && m_vertexTypeRangeHigh;
// fill PDG code std::set used for optimized search
m_parentPdgCodes.insert( m_parentPdgCodesVector.begin(), m_parentPdgCodesVector.end());
// fill vertex type std::set used for optimized search
m_vertexTypes.insert( m_vertexTypesVector.begin(), m_vertexTypesVector.end());
return StatusCode::SUCCESS;
}
bool ISF::KeepChildrenTruthStrategy::pass( ITruthIncident& ti) const {
// check whether parent PDG code matches with any of the given ones
// Could require BSM parents and hit BSM, or give a list and be on the list
// Or require neither and apply to everything
if ( !( (m_bsmParent && MC::PID::isBSM(abs(ti.parentPdgCode()))) || // BSM parent and parent is BSM
(m_parentPdgCodes.size() && m_parentPdgCodes.find(ti.parentPdgCode())==m_parentPdgCodes.end()) || // Explicit list and parent in the list
(!m_bsmParent && !m_parentPdgCodes.size()) ) ){ // Neither BSM parent nor explicit list -- allow all
return false;
}
// vertex type check
// ----
int vxtype = ti.physicsProcessCode();
int processCategory = ti.physicsProcessCategory(); // == G4ProcessType
if ((processCategory!=m_passProcessCategory && m_passProcessCategory!=0) && // Not in the category we were after
(m_doVertexRangeCheck || m_vertexTypes.size()) ){ // Should do the category check
// (part 1) vxtype in given range?: this is a small performance trick (only one comparison operator to check if within range)
// -> exactly equivalent to: m_doVertexRangeCheck && (m_vertexTypeLow<=vxtype) && (vxtype<=m_vertexTypeRangeHigh)
bool vtxTypeRangePassed = m_doVertexRangeCheck && ( unsigned(vxtype-m_vertexTypeRangeLow) < m_vertexTypeRangeLength );
// (part 2) if not in range or range check disabled, check whether vxtype
// std::set contains the given vertex type
if ( (!vtxTypeRangePassed) && (m_vertexTypes.find(vxtype)==m_vertexTypes.end()) ) {
// vxtype not registered -> not passed
return false;
}
}
// all cuts passed. Save all children.
for (unsigned short i=0;i<ti.numberOfChildren();++i){
ti.setChildPassedFilters(i);
}
// This strategy does not cause the *saving* of a vertex -- it only changes the strategy for the children
return false;
}
bool ISF::KeepChildrenTruthStrategy::appliesToRegion(unsigned short) const
{
// This applies to all regions, since it is only a modifier
return true;
}
\ No newline at end of file
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// KeepChildrenTruthStrategy.h, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#ifndef ISF_TOOLS_KEEPCHILDRENTRUTHSTRATEGY_H
#define ISF_TOOLS_KEEPCHILDRENTRUTHSTRATEGY_H 1
// stl includes
#include <set>
#include <vector>
// Athena includes
#include "AthenaBaseComps/AthAlgTool.h"
// ISF includes
#include "ISF_HepMC_Interfaces/ITruthStrategy.h"
namespace ISF {
typedef std::vector<int> VertexTypesVector;
typedef std::set<int> VertexTypesSet;
typedef std::vector<int> PDGCodesVector;
typedef std::set<int> PDGCodesSet;
/** @class KeepChildrenTruthStrategy
A modifier for the purposes of truth strategies defining cases
in which we should keep all the children of an interaction.
@author Zach.Marshall -at- cern.ch
*/
class KeepChildrenTruthStrategy final : public extends<AthAlgTool, ITruthStrategy> {
public:
/** Constructor with parameters */
KeepChildrenTruthStrategy( const std::string& t, const std::string& n, const IInterface* p );
/** Destructor */
~KeepChildrenTruthStrategy();
// Athena algtool's Hooks
StatusCode initialize() override;
/** true if the ITruthStrategy implementation applies to the given ITruthIncident */
bool pass( ITruthIncident& incident) const override;
/** true if the strategy applies to this region */
virtual bool appliesToRegion(unsigned short) const override;
private:
/** vertex type (physics code) checks */
VertexTypesVector m_vertexTypesVector; //!< Python property
VertexTypesSet m_vertexTypes; //!< optimized for search
bool m_doVertexRangeCheck;
int m_vertexTypeRangeLow;
int m_vertexTypeRangeHigh;
unsigned m_vertexTypeRangeLength;
int m_passProcessCategory;
bool m_bsmParent; //!< Apply to BSM parents
/** PDG code checks */
PDGCodesVector m_parentPdgCodesVector; //!< Python property
PDGCodesSet m_parentPdgCodes; //!< optimized for search
};
}
#endif //> !ISF_TOOLS_KEEPCHILDRENTRUTHSTRATEGY_H
\ No newline at end of file
......@@ -8,6 +8,7 @@
#include "../GenParticleSimWhiteList.h"
#include "../LLPTruthStrategy.h"
#include "../ValidationTruthStrategy.h"
#include "../KeepChildrenTruthStrategy.h"
DECLARE_COMPONENT( ISF::CylinderVolumeTruthStrategy )
DECLARE_COMPONENT( ISF::GenericTruthStrategy )
......@@ -19,3 +20,4 @@ DECLARE_COMPONENT( ISF::GenParticlePositionFilter )
DECLARE_COMPONENT( ISF::GenParticleSimWhiteList )
DECLARE_COMPONENT( ISF::LLPTruthStrategy )
DECLARE_COMPONENT( ISF::ValidationTruthStrategy )
DECLARE_COMPONENT( ISF::KeepChildrenTruthStrategy )
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