Commit 9a07f9fb authored by Atlas-Software Librarian's avatar Atlas-Software Librarian Committed by Graeme Stewart
Browse files

'CMakeLists.txt' (DerivationFrameworkMCTruth-00-01-56)

	* Modifications to HF classification from M. Casolino
	* Tagging as DerivationFrameworkMCTruth-00-01-56

2015-11-05 James Catmore <james.catmore@cern.ch>

	* Fixing bug in TruthCollectionMaker - unchecked access to
	outgoing/incoming particles
	* Tagging as DerivationFrameworkMCTruth-00-01-55

2015-10-10 James Catmore <james.catmore@cern.ch>

	* Adding heavy flavour from ttbar common augmentation
	* Tagging as DerivationFrameworkMCTruth-00-01-54

2015-10-07 Benjamin Nachman <bnachman@cern.ch>

	* Added G4 protection for TRUTH1/3
	* Tagging as DerivationFrameworkMCTruth-00-01-53

...
(Long ChangeLog diff - truncated)
parent b9996155
################################################################################
# Package: DerivationFrameworkMCTruth
################################################################################
# Declare the package name:
atlas_subdir( DerivationFrameworkMCTruth )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
Event/xAOD/xAODEventInfo
Event/xAOD/xAODTruth
GaudiKernel
PhysicsAnalysis/DerivationFramework/DerivationFrameworkInterfaces
PRIVATE
Control/AthenaKernel
Control/DataModel
Control/StoreGate
Event/EventInfo
Event/xAOD/xAODBase
Event/xAOD/xAODJet
Generators/GeneratorObjects
PhysicsAnalysis/CommonTools/ExpressionEvaluation
PhysicsAnalysis/MCTruthClassifier )
# External dependencies:
find_package( FastJet )
find_package( HepMC )
find_package( HepPDT )
find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread )
# Component(s) in the package:
atlas_add_library( DerivationFrameworkMCTruthLib
src/*.cxx
PUBLIC_HEADERS DerivationFrameworkMCTruth
INCLUDE_DIRS ${HEPPDT_INCLUDE_DIRS} ${FASTJET_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS}
PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${HEPPDT_LIBRARIES} ${FASTJET_LIBRARIES} ${HEPMC_LIBRARIES} AthenaBaseComps xAODEventInfo xAODTruth GaudiKernel StoreGateLib SGtests ExpressionEvaluationLib MCTruthClassifierLib
PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaKernel DataModel EventInfo xAODBase xAODJet GeneratorObjects )
atlas_add_component( DerivationFrameworkMCTruth
src/components/*.cxx
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${HEPPDT_INCLUDE_DIRS} ${FASTJET_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} ${HEPPDT_LIBRARIES} ${FASTJET_LIBRARIES} ${HEPMC_LIBRARIES} AthenaBaseComps xAODEventInfo xAODTruth GaudiKernel AthenaKernel DataModel StoreGateLib SGtests EventInfo xAODBase xAODJet GeneratorObjects ExpressionEvaluationLib MCTruthClassifierLib DerivationFrameworkMCTruthLib )
# Install files from the package:
atlas_install_python_modules( python/*.py )
atlas_install_joboptions( share/*.py )
......@@ -22,6 +22,14 @@
namespace DerivationFramework {
struct DecayGraphHelper {
// Geant4 barcode offset
int g4BarcodeOffset;
DecayGraphHelper(int init_g4BarcodeOffset) {
g4BarcodeOffset = init_g4BarcodeOffset;
}
DecayGraphHelper(void) {
g4BarcodeOffset = 200000;
}
// descendants: starting from particle (simple listing version)
void descendants(const xAOD::TruthParticle* pHead,
std::vector<int> &particleList,
......@@ -71,7 +79,7 @@ namespace DerivationFramework {
else {return;}
// If user doesn't want Geant, check and reject
if (!includeGeant && pHead->barcode()>200000) return;
if (!includeGeant && pHead->barcode()>g4BarcodeOffset) return;
// Save the decay vertex
int vtxIndex = decayVtx->index();
......@@ -137,7 +145,7 @@ namespace DerivationFramework {
if (!skipPdgCheck && find(pdgId.begin(), pdgId.end(), abs(particle->pdgId())) == pdgId.end()) continue;
//ensure particles are not from GEANT
if (particle->barcode() >= 2e5) continue;
if (particle->barcode() >= g4BarcodeOffset) continue;
//check if we have a neutral particle (threeCharge returns int)
if (chargedOnly && HepPID::threeCharge(particle->pdgId()) == 0) continue;
......
......@@ -44,6 +44,7 @@ namespace DerivationFramework {
bool m_preserveGeneratorDescendants;
bool m_preserveAncestors;
bool m_tauHandling;
int m_geantOffset;
};
}
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/*
* @author Mirko Casolino
* @date June 2015
* @brief tool to compute oring of hadron to flag ttbar+HF
*/
#ifndef DerivationFrameworkMCTruth_HadronOriginClassifier_H
#define DerivationFrameworkMCTruth_HadronOriginClassifier_H
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include "AthenaBaseComps/AthAlgTool.h"
#include "xAODTruth/TruthEventContainer.h"
#include "xAODEventInfo/EventInfo.h"
namespace DerivationFramework{
static const InterfaceID IID_HadronOriginClassifier("HadronOriginClassifier", 1, 0);
class HadronOriginClassifier: public AthAlgTool {
public:
HadronOriginClassifier(const std::string& t, const std::string& n, const IInterface* p);
virtual ~HadronOriginClassifier();
virtual StatusCode initialize();
virtual StatusCode finalize();
static const InterfaceID& interfaceID() { return IID_HadronOriginClassifier; }
typedef enum {extrajet=0,
c_MPI =-1, b_MPI =1,
c_FSR =-2, b_FSR =2,
c_from_W =-3, b_from_W =3,
c_from_top=-4, b_from_top =4,
c_from_H =-5, b_from_H =5} HF_id;
std::map<const xAOD::TruthParticle*, HF_id> GetOriginMap();
private:
void initMaps();
void fillHadronMap(const xAOD::TruthParticle* mainhad, const xAOD::TruthParticle* ihad, bool decayed=false);
void findPartonsToRemove(bool isNotDecayed);
void buildPartonsHadronsMaps();
int hadronType(int pdgid) const;
bool isBHadron(const xAOD::TruthParticle* part) const;
bool isCHadron(const xAOD::TruthParticle* part) const;
bool passHadronSelection(const xAOD::TruthParticle* part) const;
bool isQuarkFromHadron(const xAOD::TruthParticle* part) const;
bool isCHadronFromB(const xAOD::TruthParticle* part) const;
/// init_part needed to detect looping graphs (sherpa) and to switch on using barcode to resolve it without affecting pythia8
/// up to know only seen at parton level
bool isLooping(const xAOD::TruthParticle* part, std::set<const xAOD::TruthParticle*> init_part = std::set<const xAOD::TruthParticle*>()) const;
const xAOD::TruthParticle* findInitial(const xAOD::TruthParticle* part, bool looping) const;
bool isFromTop(const xAOD::TruthParticle* part, bool looping) const;
bool isDirectlyFromTop(const xAOD::TruthParticle* part, bool looping) const;
bool isDirectlyFromWTop(const xAOD::TruthParticle* part, bool looping) const;
bool isDirectlyFromGluonQuark(const xAOD::TruthParticle* part, bool looping) const;
bool isFromGluonQuark(const xAOD::TruthParticle* part, bool looping) const;
bool isDirectlyFSRPythia(const xAOD::TruthParticle* part, bool looping) const;
bool isDirectlyFromQuarkTop(const xAOD::TruthParticle* part, bool looping) const;
bool isFromQuarkTop(const xAOD::TruthParticle* part, bool looping) const;
bool isDirectlyFSR(const xAOD::TruthParticle* part, bool looping) const;
bool isFromWTop(const xAOD::TruthParticle* part, bool looping) const;
bool isDirectlyMPI(const xAOD::TruthParticle* part, bool looping) const;
inline bool IsHerwigPP(){return m_isHerwigPP;};
const xAOD::TruthParticle* partonToHadron(const xAOD::TruthParticle* parton);
std::set<const xAOD::TruthParticle*> usedHadron;
std::map<const xAOD::TruthParticle*,int> mainHadronMap; //maps main hadrons with flavor
std::map<const xAOD::TruthParticle*, HF_id> partonsOrigin; //parton, category
std::map<const xAOD::TruthParticle*, const xAOD::TruthParticle*> hadronsPartons; //hadron, category
std::map<const xAOD::TruthParticle*, HF_id> hadronsOrigin; //hadron, category
std::string m_mcName;
double m_HadronPtMinCut;
double m_HadronEtaMaxCut;
int m_DSID;
bool m_isHerwigPP;
};
} //namespace
#endif //DerivationFrameworkMCTruth_HadronOriginClassifier_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/*
* @file DerivationFrameworkTop/TopHeavyFlavorFilterAugmentation.h
* @date Apr. 2015
* @brief tool to add a variable to the TruthParticles corresponding to the HF hadrons origin flag
*/
#ifndef DerivationFrameworkMCTruth_HadronOriginDecorator_H
#define DerivationFrameworkMCTruth_HadronOriginDecorator_H
#include <string>
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/ToolHandle.h"
#include "DerivationFrameworkInterfaces/IAugmentationTool.h"
namespace DerivationFramework {
class HadronOriginClassifier;
class HadronOriginDecorator : public AthAlgTool, public IAugmentationTool {
public:
HadronOriginDecorator(const std::string& t, const std::string& n, const IInterface* p);
~HadronOriginDecorator();
StatusCode initialize();
StatusCode finalize();
virtual StatusCode addBranches() const;
private:
std::string m_TruthEventName;
ToolHandle<DerivationFramework::HadronOriginClassifier> m_Tool;
}; /// class
} /// namespace
#endif
......@@ -39,6 +39,7 @@ namespace DerivationFramework {
bool isLeptonFromTau(const xAOD::TruthParticle*) const;
bool isFromTau(const xAOD::TruthParticle*) const;
bool isBSM(const xAOD::TruthParticle*) const;
bool isttHFHadron(const xAOD::TruthParticle*) const;
bool isBoson(const xAOD::TruthParticle*) const;
bool isFsrFromLepton(const xAOD::TruthParticle*) const;
......@@ -102,6 +103,9 @@ namespace DerivationFramework {
/// Parameter: Write particles with status code 3
bool m_writeStatus3;
/// Parameter: Write particles for tt+HF classification
bool m_writettHFHadrons;
/// Parameter: First N particles to write
int m_writeFirstN;
......@@ -110,7 +114,7 @@ namespace DerivationFramework {
bool m_preserveDescendants;
bool m_preserveGeneratorDescendants;
bool m_preserveAncestors;
/// for keeping trace of barcodes in order to detect loops
mutable std::unordered_set<int> m_barcode_trace;
......@@ -118,7 +122,10 @@ namespace DerivationFramework {
mutable unsigned int m_totpart;
mutable unsigned int m_removedpart;
mutable int m_particleCountSoFar;
/// Parameter: simulation barcode offset
int m_geantOffset;
// handle to the thinning service
ServiceHandle<IThinningSvc> m_thinningSvc;
};
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// TruthClassificationDecorator.h, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#ifndef DERIVATIONFRAMEWORK_TRUTHCLASSIFICATIONDECORATOR_H
#define DERIVATIONFRAMEWORK_TRUTHCLASSIFICATIONDECORATOR_H
#include <string>
#include "AthenaBaseComps/AthAlgTool.h"
#include "DerivationFrameworkInterfaces/IAugmentationTool.h"
#include "GaudiKernel/ToolHandle.h"
class IMCTruthClassifier;
namespace DerivationFramework {
class TruthClassificationDecorator : public AthAlgTool, public IAugmentationTool {
public:
TruthClassificationDecorator(const std::string& t, const std::string& n, const IInterface* p);
~TruthClassificationDecorator();
StatusCode initialize();
StatusCode finalize();
virtual StatusCode addBranches() const;
private:
mutable unsigned int m_ntotpart;
std::string m_particlesKey;
ToolHandle<IMCTruthClassifier> m_classifier;
};
}
#endif // DERIVATIONFRAMEWORK_TRUTHCLASSIFICATIONDECORATOR_H
......@@ -18,7 +18,6 @@
namespace ExpressionParsing {
class ExpressionParser;
}
class IMCTruthClassifier;
namespace DerivationFramework {
......@@ -38,8 +37,7 @@ namespace DerivationFramework {
//std::string m_verticesKey;
std::string m_collectionName;
std::string m_partString;
ToolHandle<IMCTruthClassifier> m_classifier;
bool m_runClassifier;
bool do_compress, do_sherpa;
};
}
......
......@@ -12,25 +12,25 @@ use HepPDT * LCG_Interfaces
# added by Frank Paige
use AtlasHepMC AtlasHepMC-* External
use AtlasFastJet AtlasFastJet-* External
use xAODEventInfo xAODEventInfo-* Event/xAOD
private
use GeneratorObjects GeneratorObjects-* Generators
use AthenaKernel AthenaKernel-* Control
use EventKernel EventKernel-* Event
#use EventKernel EventKernel-* Event
use StoreGate StoreGate-* Control
use DataModel DataModel-* Control
use ExpressionEvaluation ExpressionEvaluation-* PhysicsAnalysis/CommonTools
use MCTruthClassifier MCTruthClassifier-* PhysicsAnalysis
# added by Frank Paige
use McParticleEvent McParticleEvent-* PhysicsAnalysis/TruthParticleID
use McParticleKernel McParticleKernel-* PhysicsAnalysis/TruthParticleID
use McParticleUtils McParticleUtils-* PhysicsAnalysis/TruthParticleID
use TruthHelper TruthHelper-* Generators/GenAnalysisTools
#use McParticleEvent McParticleEvent-* PhysicsAnalysis/TruthParticleID
#use McParticleKernel McParticleKernel-* PhysicsAnalysis/TruthParticleID
#use McParticleUtils McParticleUtils-* PhysicsAnalysis/TruthParticleID
#use TruthHelper TruthHelper-* Generators/GenAnalysisTools
use AtlasROOT AtlasROOT-* External
use xAODJet xAODJet-* Event/xAOD
use xAODBase xAODBase-* Event/xAOD
use xAODEventInfo xAODEventInfo-* Event/xAOD
use EventInfo EventInfo-* Event
#################################################################
......
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
#############################################
# Heavy flavour from tt tools
#############################################
from DerivationFrameworkCore.DerivationFrameworkMaster import *
DSIDList=[
410000,
410001,
410002,
410003,
410004,
410007,
410008,
301528,
301529,
301530,
301531,
301532,
303722,
303723,
303724,
303725,
303726,
407009,
407010,
407011,
407012,
410120,
426090,
426091,
426092,
426093,
426094,
426095,
426096,
426097,
429007,
]
import PyUtils.AthFile as af
from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
f = af.fopen(athenaCommonFlags.PoolAODInput()[0])
if len(f.mc_channel_number) > 0:
if(int(f.mc_channel_number[0]) in DSIDList):
from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__HadronOriginClassifier
DFCommonhadronorigintool = DerivationFramework__HadronOriginClassifier(name="DFCommonHadronOriginClassifier",DSID=int(f.mc_channel_number[0]))
ToolSvc += DFCommonhadronorigintool
from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__HadronOriginDecorator
DFCommonhadronorigindecorator = DerivationFramework__HadronOriginDecorator(name = "DFCommonHadronOriginDecorator")
DFCommonhadronorigindecorator.ToolName = DFCommonhadronorigintool
ToolSvc += DFCommonhadronorigindecorator
DerivationFrameworkJob += CfgMgr.DerivationFramework__CommonAugmentation("HFHadronsCommonKernel",
AugmentationTools = [DFCommonhadronorigindecorator]
)
......@@ -4,35 +4,30 @@
from DerivationFrameworkCore.DerivationFrameworkMaster import *
from RecExConfig.ObjKeyStore import objKeyStore
from xAODTruthCnv.xAODTruthCnvConf import xAODMaker__xAODTruthCnvAlg
from DerivationFrameworkMCTruth.TruthDerivationTools import *
dfInputIsEVNT = False # Flag to distinguish EVNT from AOD input
# Build truth collection if input is HepMC. Must be scheduled first to allow slimming.
# Input file is EVNT
if objKeyStore.isInInput( "McEventCollection", "GEN_EVENT" ):
DerivationFrameworkJob += xAODMaker__xAODTruthCnvAlg("GEN_EVNT2xAOD",AODContainerName="GEN_EVENT")
DerivationFrameworkJob.insert(0,xAODMaker__xAODTruthCnvAlg("GEN_EVNT2xAOD",AODContainerName="GEN_EVENT"))
dfInputIsEVNT = True
# Input file is HITS
elif objKeyStore.isInInput( "McEventCollection", "TruthEvent"):
DerivationFrameworkJob += xAODMaker__xAODTruthCnvAlg("GEN_EVNT2xAOD",AODContainerName="TruthEvent")
DerivationFrameworkJob.insert(0,xAODMaker__xAODTruthCnvAlg("GEN_EVNT2xAOD",AODContainerName="TruthEvent"))
dfInputIsEVNT = True
# Input file must be xAOD
if (dfInputIsEVNT==False):
# xAOD input so we need to schedule the special truth building tools and add them to a common augmentation
from DerivationFrameworkMCTruth.TruthObjectTools import *
from DerivationFrameworkMCTruth.TruthDecoratorTools import *
#==============================================================================
# Thinning the photon truth collection : no photons from pi0 (origin=42)
#==============================================================================
from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__GenericTruthThinning
TRUTH1PhotonThinning = DerivationFramework__GenericTruthThinning(name = "TRUTH1PhotonThinning",
ThinningService = "TRUTH1ThinningSvc",
ParticlesKey = "TruthPhotons",
ParticleSelectionString = "(TruthPhotons.particleOrigin != 42) || (TruthPhotons.pt > 20.0*GeV)")
ToolSvc += TRUTH1PhotonThinning
augmentationToolsList = [ DFCommonTruthClassificationTool,
DFCommonTruthMuonTool,DFCommonTruthElectronTool,
DFCommonTruthPhotonToolSim,
#DFCommonTruthTauTool,
DFCommonTruthElectronDressingTool, DFCommonTruthMuonDressingTool,
DFCommonTruthElectronIsolationTool1, DFCommonTruthElectronIsolationTool2,
DFCommonTruthMuonIsolationTool1, DFCommonTruthMuonIsolationTool2,
DFCommonTruthPhotonIsolationTool1, DFCommonTruthPhotonIsolationTool2]
from DerivationFrameworkCore.DerivationFrameworkCoreConf import DerivationFramework__CommonAugmentation
DerivationFrameworkJob += CfgMgr.DerivationFramework__CommonAugmentation("MCTruthCommonKernel",
AugmentationTools = [ TRUTH1MuonTool,TRUTH1ElectronTool,TRUTH1PhotonTool,TRUTH1TauTool,
TRUTH1ElectronDressingTool, TRUTH1MuonDressingTool,
TRUTH1ElectronIsolationTool1, TRUTH1ElectronIsolationTool2,
TRUTH1MuonIsolationTool1, TRUTH1MuonIsolationTool2,
TRUTH1PhotonIsolationTool1, TRUTH1PhotonIsolationTool2]
AugmentationTools = augmentationToolsList
)
......@@ -2,28 +2,81 @@
from AthenaCommon.AppMgr import ToolSvc
#add the custom tools for new truth collections
from DerivationFrameworkMCTruth.TruthObjectTools import *
# Set up the MCTruthClassifier
from DerivationFrameworkCore.DerivationFrameworkMaster import *
from MCTruthClassifier.MCTruthClassifierConf import MCTruthClassifier
DFCommonTruthClassifier = MCTruthClassifier(name = "DFCommonTruthClassifier",
ParticleCaloExtensionTool="")
ToolSvc += DFCommonTruthClassifier
#==============================================================================
# Schedule the tools for adding new truth collection
#==============================================================================
from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__TruthCollectionMaker
#from DerivationFrameworkMCTruth.DerivationFrameworkMCTruthConf import DerivationFramework__TruthCollectionMakerTau
DFCommonTruthMuonTool = DerivationFramework__TruthCollectionMaker(name = "DFCommonTruthMuonTool",
NewCollectionName = "TruthMuons",
ParticleSelectionString = "(abs(TruthParticles.pdgId) == 13) && (TruthParticles.status == 1) && TruthParticles.barcode < "+str(DerivationFrameworkSimBarcodeOffset))
ToolSvc += DFCommonTruthMuonTool
DFCommonTruthElectronTool = DerivationFramework__TruthCollectionMaker(name = "DFCommonTruthElectronTool",
NewCollectionName = "TruthElectrons",
ParticleSelectionString = "(abs(TruthParticles.pdgId) == 11) && (TruthParticles.status == 1) && TruthParticles.barcode < "+str(DerivationFrameworkSimBarcodeOffset))
ToolSvc += DFCommonTruthElectronTool
DFCommonTruthPhotonTool = DerivationFramework__TruthCollectionMaker(name = "DFCommonTruthPhotonTool",
NewCollectionName = "TruthPhotons",
ParticleSelectionString = "(abs(TruthParticles.pdgId) == 22) && (TruthParticles.status == 1) && TruthParticles.barcode < "+str(DerivationFrameworkSimBarcodeOffset))
ToolSvc += DFCommonTruthPhotonTool
# this tool is needed for making TruthPhotons from sim samples, where extra cuts are needed
DFCommonTruthPhotonToolSim = DerivationFramework__TruthCollectionMaker(name = "DFCommonTruthPhotonToolSim",
NewCollectionName = "TruthPhotons",
ParticleSelectionString = "(abs(TruthParticles.pdgId) == 22) && (TruthParticles.status == 1) && ((TruthParticles.classifierParticleOrigin != 42) || (TruthParticles.pt > 20.0*GeV)) && ( TruthParticles.barcode < "+str(DerivationFrameworkSimBarcodeOffset)+")")
ToolSvc += DFCommonTruthPhotonToolSim