Commit 1b81ab54 authored by John Derek Chapman's avatar John Derek Chapman Committed by Rachid Mazini
Browse files

Initial implementation of method to decorate Truth Particle and Truth Jet containers

Part of work for ATLASSIM-3837
Compiles - need to do run-time tests
parent 12c3d61c
......@@ -29,6 +29,10 @@ def getHITSFile(runArgs):
raise SystemExit("No HITS file in runArgs!!")
def HitsFilePeeker(runArgs, skeletonLog):
peekInfo = dict()
peekInfo["AntiKt4TruthJetsPresent"] = False
peekInfo["AntiKt6TruthJetsPresent"] = False
peekInfo["PileUpTruthParticlesPresent"] = False
import PyUtils.AthFile as af
try:
f = af.fopen(getHITSFile(runArgs))
......@@ -70,7 +74,15 @@ def HitsFilePeeker(runArgs, skeletonLog):
metadatadict['SimulatedDetectors'] = hitColls2SimulatedDetectors(f.infos['eventdata_items'])
else :
metadatadict['SimulatedDetectors'] = ['pixel','SCT','TRT','BCM','Lucid','LAr','Tile','MDT','CSC','TGC','RPC','Truth']
# Check for Truth Containers
if 'eventdata_items' in f.infos.keys():
for entry in f.infos['eventdata_items']:
if 'AntiKt4TruthJets' == entry[1]:
peekInfo["AntiKt4TruthJetsPresent"] = True
if 'AntiKt6TruthJets' == entry[1]:
peekInfo["AntiKt6TruthJetsPresent"] = True
if 'TruthPileupParticles' == entry[1]:
peekInfo["PileUpTruthParticlesPresent"] = True
import re
from AthenaCommon.GlobalFlags import globalflags
globalflags.DataSource="geant4"
......@@ -135,4 +147,4 @@ def HitsFilePeeker(runArgs, skeletonLog):
DetFlags.writeRDOPool.all_setOff()
DetFlags.writeRIOPool.all_setOff()
return
return peekInfo
......@@ -36,7 +36,7 @@ if not hasattr(runArgs,"inputHITSFile"):
raise RuntimeError("No inputHITSFile provided.")
from SimuJobTransforms.HitsFilePeeker import HitsFilePeeker
HitsFilePeeker(runArgs, filterHitLog)
peekInfo = HitsFilePeeker(runArgs, filterHitLog)
#==============================================================
# Job Configuration parameters:
......@@ -236,7 +236,10 @@ if hasattr(runArgs,'TruthReductionScheme'):
pass
from McEventCollectionFilter.McEventCollectionFilterConf import McEventCollectionFilter
McEventCollectionFilter = McEventCollectionFilter("McEventCollectionFilter")
McEventCollectionFilter = McEventCollectionFilter("McEventCollectionFilter",
DecorateAntiKt4TruthJets = peekInfo["AntiKt4TruthJetsPresent"],
DecorateAntiKt6TruthJets = peekInfo["AntiKt6TruthJetsPresent"],
DecorateTruthParticles = peekInfo["PileUpTruthParticlesPresent"])
if runArgs.TruthReductionScheme != 'SingleGenParticle':
filterHitLog.warning( 'Unknown TruthReductionScheme (' + runArgs.TruthReductionScheme + '). Currently just a dummy value, but please check.' )
## here configure the level of Truth reduction required
......
......@@ -9,6 +9,8 @@ atlas_subdir( McEventCollectionFilter )
atlas_depends_on_subdirs( PRIVATE
Control/AthenaBaseComps
DetectorDescription/GeoPrimitives
Event/xAOD/xAODJet
Event/xAOD/xAODTruth
GaudiKernel
Generators/GeneratorObjects
InnerDetector/InDetSimEvent
......@@ -26,7 +28,7 @@ atlas_add_library( McEventCollectionFilterLib
PRIVATE_INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${HEPMC_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS}
PRIVATE_DEFINITIONS ${CLHEP_DEFINITIONS}
LINK_LIBRARIES StoreGateLib SGtests
PRIVATE_LINK_LIBRARIES ${CLHEP_LIBRARIES} ${HEPMC_LIBRARIES} ${EIGEN_LIBRARIES} AthenaBaseComps GeoPrimitives GaudiKernel GeneratorObjects InDetSimEvent MuonSimEvent )
PRIVATE_LINK_LIBRARIES ${CLHEP_LIBRARIES} ${HEPMC_LIBRARIES} ${EIGEN_LIBRARIES} AthenaBaseComps GeoPrimitives GaudiKernel GeneratorObjects InDetSimEvent MuonSimEvent xAODJet xAODTruth)
atlas_add_component( McEventCollectionFilter
src/components/*.cxx
......
......@@ -10,6 +10,10 @@
#include "HepMC/GenEvent.h"
#include "HepMC/GenVertex.h"
#include "GeneratorObjects/McEventCollection.h"
#include "xAODJet/JetContainer.h"
#include "xAODJet/JetAuxContainer.h"
#include "xAODTruth/TruthParticleContainer.h"
#include "xAODTruth/TruthParticleAuxContainer.h"
//
#include "InDetSimEvent/SiHitCollection.h"
#include "InDetSimEvent/SiHit.h"
......@@ -31,12 +35,14 @@
McEventCollectionFilter::McEventCollectionFilter(const std::string& name, ISvcLocator* pSvcLocator):
AthAlgorithm(name, pSvcLocator)
{
declareProperty("IsKeepTRTElect" , m_IsKeepTRTElect = false); //
declareProperty("McEventCollection" , m_mcEventCollection = "TruthEvent");
declareProperty("PileupPartPDGID" , m_PileupPartPDGID = 999); //Geantino
declareProperty("UseTRTHits" , m_UseTRTHits = true); //
m_RefBarcode=0;
declareProperty("IsKeepTRTElect" , m_IsKeepTRTElect);
declareProperty("McEventCollection" , m_mcEventCollection);
declareProperty("PileupPartPDGID" , m_PileupPartPDGID);
declareProperty("UseTRTHits" , m_UseTRTHits);
declareProperty("DecoratePileUpTruth" , m_decoratePileUpTruth);
declareProperty("DecorateTruthParticles", m_decorateTruthParticles);
declareProperty("DecorateAntiKt4TruthJets", m_decorateAntiKt4TruthJets);
declareProperty("DecorateAntiKt6TruthJets", m_decorateAntiKt6TruthJets);
}
......@@ -64,6 +70,11 @@ StatusCode McEventCollectionFilter::execute(){
ATH_CHECK( FindTRTElectronHits() );
}
// decorate Pile Up Truth Containers
if (m_decoratePileUpTruth) {
ATH_CHECK( decoratePileUpTruth() );
}
//.......Reduce McEventCollection
ATH_CHECK( ReduceMCEventCollection() );
......@@ -190,7 +201,7 @@ StatusCode McEventCollectionFilter::ReduceMCEventCollection(){
//.....add new vetex with geantino
evt->add_vertex(genVertex);
m_RefBarcode=genPart->barcode();
m_RefPVtxZ = static_cast<float>(genVertex->position().z());
pMcEvtCollNew->push_back(evt);
......@@ -204,6 +215,44 @@ StatusCode McEventCollectionFilter::ReduceMCEventCollection(){
}
//--------------------------------------------------------
StatusCode McEventCollectionFilter::decoratePileUpTruth() {
//--------------------------------------------------------
// decorate pile-up truth objects with primary vertex Z coordinate
//--------------------------------------------------------
if (m_decorateTruthParticles) {
const xAOD::TruthParticleContainer* tpc = nullptr;
ATH_CHECK( evtStore()->retrieve( tpc, "TruthPileupParticles" ) );
for( const xAOD::TruthParticle* tp : *tpc ) {
static const SG::AuxElement::Decorator< float > dec_z( "PVz" );
dec_z( *tp ) = m_RefPVtxZ;
}
}
if (m_decorateAntiKt4TruthJets) {
const xAOD::JetContainer* jc4 = nullptr;
ATH_CHECK( evtStore()->retrieve( jc4, "AntiKt4TruthJets" ) );
for( const xAOD::Jet* truthJet : *jc4 ) {
static const SG::AuxElement::Decorator< float > dec_z( "PVz" );
dec_z( *truthJet ) = m_RefPVtxZ;
}
}
if (m_decorateAntiKt6TruthJets) {
const xAOD::JetContainer* jc6 = nullptr;
ATH_CHECK( evtStore()->retrieve( jc6, "AntiKt6TruthJets" ) );
for( const xAOD::Jet* truthJet : *jc6 ) {
static const SG::AuxElement::Decorator< float > dec_z( "PVz" );
dec_z( *truthJet ) = m_RefPVtxZ;
}
}
return StatusCode::SUCCESS;
}
//--------------------------------------------------------
StatusCode McEventCollectionFilter::SiHistsTruthRelink(){
//--------------------------------------------------------
//.......to relink all Si hits to the new particle
......@@ -268,17 +317,17 @@ StatusCode McEventCollectionFilter::TRTHistsTruthRelink(){
//--------------------------------------------------------
//
//.......retrive TRTUncompressedHitCollection collection
m_HitName = "TRTUncompressedHits";
const std::string hitName = "TRTUncompressedHits";
const DataHandle<TRTUncompressedHitCollection> pTRTHitColl;
if(evtStore()->contains<TRTUncompressedHitCollection>(m_HitName)) {
ATH_CHECK( evtStore()->retrieve(pTRTHitColl, m_HitName) );
if(evtStore()->contains<TRTUncompressedHitCollection>(hitName)) {
ATH_CHECK( evtStore()->retrieve(pTRTHitColl, hitName) );
} else {
ATH_MSG_ERROR( "Could not find collection containing " << m_HitName );
ATH_MSG_ERROR( "Could not find collection containing " << hitName );
return StatusCode::FAILURE;
}
ATH_MSG_DEBUG( "Found collection containing " << m_HitName );
ATH_MSG_DEBUG( "Found collection containing " << hitName );
TRTUncompressedHitCollection* pTRTHitC= const_cast<TRTUncompressedHitCollection*> (&*pTRTHitColl);
......@@ -314,7 +363,7 @@ StatusCode McEventCollectionFilter::TRTHistsTruthRelink(){
ATH_CHECK( evtStore()->remove(pTRTHitC) );
//.......write new TRTUncompressedHitCollection
ATH_CHECK( evtStore()->record(pTRTHitCollNew,m_HitName) );
ATH_CHECK( evtStore()->record(pTRTHitCollNew,hitName) );
return StatusCode::SUCCESS;
......@@ -325,13 +374,13 @@ StatusCode McEventCollectionFilter::MDTHistsTruthRelink(){
//.......to relink all MDT hits to the new particle
//--------------------------------------------------------
m_HitName="MDT_Hits";
const std::string hitName ="MDT_Hits";
const DataHandle<MDTSimHitCollection> pMDTHitColl;
if(evtStore()->contains<MDTSimHitCollection>(m_HitName)) {
ATH_CHECK( evtStore()->retrieve(pMDTHitColl, m_HitName) );
if(evtStore()->contains<MDTSimHitCollection>(hitName)) {
ATH_CHECK( evtStore()->retrieve(pMDTHitColl, hitName) );
} else {
ATH_MSG_ERROR( "Could not find MDTSimHitCollection containing " << m_HitName );
ATH_MSG_ERROR( "Could not find MDTSimHitCollection containing " << hitName );
return StatusCode::FAILURE;
}
......@@ -366,7 +415,7 @@ StatusCode McEventCollectionFilter::MDTHistsTruthRelink(){
ATH_CHECK( evtStore()->remove(pMDTHitC) );
//.......write new MDTSimHitCollection
ATH_CHECK( evtStore()->record(pMDTHitCollNew,m_HitName) );
ATH_CHECK( evtStore()->record(pMDTHitCollNew,hitName) );
return StatusCode::SUCCESS;
......@@ -377,13 +426,13 @@ StatusCode McEventCollectionFilter::CSCHistsTruthRelink(){
//.......to relink all CSC hits to the new particle
//--------------------------------------------------------
m_HitName="CSC_Hits";
const std::string hitName ="CSC_Hits";
const DataHandle<CSCSimHitCollection> pCSCHitColl;
if(evtStore()->contains<CSCSimHitCollection>(m_HitName)) {
ATH_CHECK( evtStore()->retrieve(pCSCHitColl, m_HitName) );
if(evtStore()->contains<CSCSimHitCollection>(hitName)) {
ATH_CHECK( evtStore()->retrieve(pCSCHitColl, hitName) );
} else {
ATH_MSG_ERROR( "Could not find CSCSimHitCollection containing " << m_HitName );
ATH_MSG_ERROR( "Could not find CSCSimHitCollection containing " << hitName );
return StatusCode::FAILURE;
}
......@@ -415,7 +464,7 @@ StatusCode McEventCollectionFilter::CSCHistsTruthRelink(){
ATH_CHECK( evtStore()->remove(pCSCHitC) );
//.......write new CSCSimHitCollection
ATH_CHECK( evtStore()->record(pCSCHitCollNew,m_HitName) );
ATH_CHECK( evtStore()->record(pCSCHitCollNew,hitName) );
return StatusCode::SUCCESS;
}
......@@ -426,13 +475,13 @@ StatusCode McEventCollectionFilter::RPCHistsTruthRelink(){
//.......to relink all RPC hits to the new particle
//--------------------------------------------------------
m_HitName="RPC_Hits";
const std::string hitName ="RPC_Hits";
const DataHandle<RPCSimHitCollection> pRPCHitColl;
if(evtStore()->contains<RPCSimHitCollection>(m_HitName)) {
ATH_CHECK( evtStore()->retrieve(pRPCHitColl, m_HitName) );
if(evtStore()->contains<RPCSimHitCollection>(hitName)) {
ATH_CHECK( evtStore()->retrieve(pRPCHitColl, hitName) );
} else {
ATH_MSG_ERROR( "Could not find RPCSimHitCollection containing " << m_HitName );
ATH_MSG_ERROR( "Could not find RPCSimHitCollection containing " << hitName );
return StatusCode::FAILURE;
}
......@@ -465,7 +514,7 @@ StatusCode McEventCollectionFilter::RPCHistsTruthRelink(){
ATH_CHECK( evtStore()->remove(pRPCHitC) );
//.......write new RPCSimHitCollection
ATH_CHECK( evtStore()->record(pRPCHitCollNew,m_HitName) );
ATH_CHECK( evtStore()->record(pRPCHitCollNew,hitName) );
return StatusCode::SUCCESS;
}
......@@ -475,13 +524,13 @@ StatusCode McEventCollectionFilter::TGCHistsTruthRelink(){
//--------------------------------------------------------
//.......to relink all TGC hits to the new particle
//--------------------------------------------------------
m_HitName="TGC_Hits";
const std::string hitName ="TGC_Hits";
const DataHandle<TGCSimHitCollection> pTGCHitColl;
if(evtStore()->contains<TGCSimHitCollection>(m_HitName)) {
ATH_CHECK( evtStore()->retrieve(pTGCHitColl, m_HitName) );
if(evtStore()->contains<TGCSimHitCollection>(hitName)) {
ATH_CHECK( evtStore()->retrieve(pTGCHitColl, hitName) );
} else {
ATH_MSG_ERROR( "Could not find TGCSimHitCollection containing " << m_HitName );
ATH_MSG_ERROR( "Could not find TGCSimHitCollection containing " << hitName );
return StatusCode::FAILURE;
}
......@@ -513,7 +562,7 @@ StatusCode McEventCollectionFilter::TGCHistsTruthRelink(){
ATH_CHECK( evtStore()->remove(pTGCHitC) );
//.......write new TGCSimHitCollection
ATH_CHECK( evtStore()->record(pTGCHitCollNew,m_HitName) );
ATH_CHECK( evtStore()->record(pTGCHitCollNew,hitName) );
return StatusCode::SUCCESS;
}
......@@ -522,17 +571,17 @@ StatusCode McEventCollectionFilter::TGCHistsTruthRelink(){
StatusCode McEventCollectionFilter::FindTRTElectronHits(){
//--------------------------------------------------------
//.......retrive TRTUncompressedHitCollection collection
m_HitName = "TRTUncompressedHits";
const std::string hitName = "TRTUncompressedHits";
const DataHandle<TRTUncompressedHitCollection> pTRTHitColl;
if(evtStore()->contains<TRTUncompressedHitCollection>(m_HitName)) {
ATH_CHECK( evtStore()->retrieve(pTRTHitColl, m_HitName) );
if(evtStore()->contains<TRTUncompressedHitCollection>(hitName)) {
ATH_CHECK( evtStore()->retrieve(pTRTHitColl, hitName) );
} else {
ATH_MSG_ERROR( "Could not find collection containing " << m_HitName );
ATH_MSG_ERROR( "Could not find collection containing " << hitName );
return StatusCode::FAILURE;
}
ATH_MSG_DEBUG( "Found collection containing " << m_HitName );
ATH_MSG_DEBUG( "Found collection containing " << hitName );
m_elecBarcode.clear();
......
......@@ -5,7 +5,7 @@
#ifndef MCEVENTCOLLECTIONFILTER_H
#define MCEVENTCOLLECTIONFILTER_H
// Base class include
// Base class include
#include "AthenaBaseComps/AthAlgorithm.h"
// std library includes
......@@ -21,10 +21,11 @@ public:
virtual StatusCode initialize();
virtual StatusCode execute();
virtual StatusCode finalize();
private:
StatusCode ReduceMCEventCollection();
StatusCode decoratePileUpTruth();
StatusCode FindTRTElectronHits();
StatusCode SiHistsTruthRelink();
StatusCode TRTHistsTruthRelink();
......@@ -33,16 +34,20 @@ public:
StatusCode RPCHistsTruthRelink();
StatusCode TGCHistsTruthRelink();
bool m_IsKeepTRTElect;
std::string m_mcEventCollection;
int m_PileupPartPDGID;
bool m_UseTRTHits;
bool m_IsKeepTRTElect{false};
std::string m_mcEventCollection{"TruthEvent"};
int m_PileupPartPDGID{999}; //Geantino
bool m_UseTRTHits{true};
bool m_decoratePileUpTruth{true};
bool m_decorateTruthParticles{true};
bool m_decorateAntiKt4TruthJets{true};
bool m_decorateAntiKt6TruthJets{true};
//---------------------
std::string m_HitName;
int m_RefBarcode;
int m_RefBarcode{0};
float m_RefPVtxZ{0.0};
std::vector<int> m_elecBarcode;
};
};
#endif
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