ATLAS Offline Software
TruthParticleFilterBaseTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TruthParticleFilterBaseTool.cxx
7 // Implementation file for class TruthParticleFilterBaseTool
8 // Author: S.Binet<binet@cern.ch>
10 
11 
12 // McParticleKernel includes
15 
16 // McParticleTools includes
18 
22 
26  const std::string& name,
27  const IInterface* parent ) :
29 {
30  //
31  // Property declaration
32  //
33 
34  declareProperty( "McVtxFilterTool",
35  m_mcVtxFilterTool = McVtxFilterTool_t( "McVtxFilterTool",
36  this ),
37  "Pointer to the McVtxFilterTool to be able to select additional "
38  "vertices on some decay pattern(s) criterion(s)" );
39 
40  declareProperty( "TruthIsolationTool",
41  m_isolationTool = IsolTool_t( "TruthIsolationTool" ),
42  "Pointer to the TruthIsolationTool to be able to compute "
43  "transverse energy isolations for various isolation cones cuts. "
44  "See McParticleEvent/TruthParticleParameters.h for cone cuts." );
45 
46 
47  declareProperty( "DoEtIsolations",
48  m_doEtIsolation = false,
49  "Switch to compute or not the Et-isolations for TruthParticle "
50  "(and their underlying @c HepMC::GenParticle).\n"
51  "Default is to not compute these Et-isolations (and save CPU)." );
52 
53  declareInterface<ITruthParticleFilterTool>(this);
54 }
55 
59 {
60  ATH_MSG_DEBUG("Calling destructor");
61 }
62 
66 {
67  ATH_MSG_INFO("Initializing " << name() << "...");
68 
70  if ( !m_mcVtxFilterTool.retrieve().isSuccess() ) {
71  ATH_MSG_ERROR("Creation of algTool IMcVtxFilterTool FAILED !");
72  return StatusCode::FAILURE;
73  }
74 
76  if( m_doEtIsolation.value()) {
77  ATH_CHECK(m_isolationTool.retrieve());
78  }
79  else {
80  m_isolationTool.disable();
81  }
82 
83  //initialize DataHandleKeys
86 
88  (" DoEtIsolations: [" << std::boolalpha << m_doEtIsolation.value()
89  << "]" << endmsg
90  << " McEvents: [" << m_mcEventsReadHandleKey.key() << "]" << endmsg
91  << " McEventsOutput: [" << m_mcEventsOutputWriteHandleKey.key() << "]");
92 
93  // Give the concrete (derived) tool a chance to initialize itself
94  if ( initializeTool().isFailure() ) {
95  ATH_MSG_ERROR("Could not initialize concrete tool !");
96  return StatusCode::FAILURE;
97  }
98 
99  ATH_MSG_INFO("Options of the McVtxFilterTool:");
100  m_mcVtxFilterTool->displayOptions();
101 
102  return StatusCode::SUCCESS;
103 }
104 
106 {
107  ATH_MSG_INFO("Finalizing " << name() << "...");
108 
109  m_mcVtxFilterTool->stats();
110 
111  // Give the concrete (derived) tool a chance to finalize itself
112  if ( finalizeTool().isFailure() ) {
113  ATH_MSG_ERROR("Could not finalize concrete tool !");
114  return StatusCode::FAILURE;
115  }
116 
117  return StatusCode::SUCCESS;
118 }
119 
121 {
122  ATH_MSG_DEBUG("Executing " << name() << "...");
123 
124  //Setup Handle to read input container
126 
127  if (!mcEventsReadHandle.isValid()){
128  ATH_MSG_ERROR("Invalid ReadHandle to McEventColleciton with key: " << m_mcEventsReadHandleKey.key());
129  return StatusCode::FAILURE;
130  }
131 
132  //Setup WriteHandle, and then record new McEventCollection.
134  ATH_CHECK(mcEventsOutputWriteHandle.record(std::make_unique<McEventCollection>()));
135 
136  if (!mcEventsOutputWriteHandle.isValid()){
137  ATH_MSG_ERROR("Invalid WriteHamdle for McEventCollection with key ["
138  <<m_mcEventsOutputWriteHandleKey.key() << "] !!");
139  return StatusCode::FAILURE;
140  }
141 
142  // Compute isolation for gamma/lepton.
143  if ( m_doEtIsolation.value() ) {
144  ATH_MSG_VERBOSE("Computing Et isolations...");
145  if ( m_isolationTool->buildEtIsolations(m_mcEventsReadHandleKey.key()).isFailure() ) {
146  ATH_MSG_ERROR("Could not compute Et isolations !!");
147  return StatusCode::FAILURE;
148  }
149  } //> end do Et-isolation
150 
151  if ( this->buildMcAod( mcEventsReadHandle.ptr(), mcEventsOutputWriteHandle.ptr() ).isFailure() ) {
152  ATH_MSG_ERROR("Could not buildMcAod(in,out) !!");
153  return StatusCode::FAILURE;
154  }
155 
156  // We have slimmed the mcEventsOutputWriteHandle.
157  // To not bias the map of isolation energies for this GenEvent, we alias
158  // it to its original one
159  if ( m_doEtIsolation.value() &&
162  ).isSuccess() ) {
163  ATH_MSG_WARNING("Could not create an alias in the map of "\
164  "isolation energies !");
165  }
166 
167  return StatusCode::SUCCESS;
168 }
169 
TruthParticleFilterBaseTool::m_doEtIsolation
BooleanProperty m_doEtIsolation
Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle...
Definition: TruthParticleFilterBaseTool.h:94
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle< McEventCollection >
TruthParticleFilterBaseTool.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ITruthParticleFilterTool::buildMcAod
virtual StatusCode buildMcAod(const McEventCollection *in, McEventCollection *filtered)=0
This method will check the validity of the input McEventCollection and build a filtered one from the ...
TruthParticleFilterBaseTool::finalizeTool
virtual StatusCode finalizeTool()
Definition: TruthParticleFilterBaseTool.h:124
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
TruthParticleFilterBaseTool::execute
StatusCode execute()
Definition: TruthParticleFilterBaseTool.cxx:120
TruthParticleFilterBaseTool::initializeTool
virtual StatusCode initializeTool()
I/O operators.
Definition: TruthParticleFilterBaseTool.h:117
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TruthParticleFilterBaseTool::m_mcEventsReadHandleKey
SG::ReadHandleKey< McEventCollection > m_mcEventsReadHandleKey
ReadHandleKey for the input McEventCollection one wants to filter.
Definition: TruthParticleFilterBaseTool.h:100
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TruthParticleFilterBaseTool::m_mcVtxFilterTool
McVtxFilterTool_t m_mcVtxFilterTool
Pointer to the McVtxFilterTool to be able to select additional vertices on some decay pattern criteri...
Definition: TruthParticleFilterBaseTool.h:78
TruthParticleFilterBaseTool::m_isolationTool
IsolTool_t m_isolationTool
Pointer to the TruthIsolationTool to be able to compute transverse energy isolations for various isol...
Definition: TruthParticleFilterBaseTool.h:85
TruthParticleFilterBaseTool::finalize
StatusCode finalize()
Definition: TruthParticleFilterBaseTool.cxx:105
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TruthParticleFilterBaseTool::IsolTool_t
ToolHandle< ITruthIsolationTool > IsolTool_t
Definition: TruthParticleFilterBaseTool.h:80
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
TruthParticleFilterBaseTool::McVtxFilterTool_t
ToolHandle< IMcVtxFilterTool > McVtxFilterTool_t
Definition: TruthParticleFilterBaseTool.h:74
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TruthParticleFilterBaseTool::TruthParticleFilterBaseTool
TruthParticleFilterBaseTool()
Default constructor:
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TruthParticleFilterBaseTool::~TruthParticleFilterBaseTool
virtual ~TruthParticleFilterBaseTool()
Destructor:
Definition: TruthParticleFilterBaseTool.cxx:58
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TruthParticleFilterBaseTool::initialize
StatusCode initialize()
Athena Algorithm's Hooks.
Definition: TruthParticleFilterBaseTool.cxx:65
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
SG::WriteHandle< McEventCollection >
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IMcVtxFilterTool.h
AthAlgTool
Definition: AthAlgTool.h:26
TruthParticleFilterBaseTool::m_mcEventsOutputWriteHandleKey
SG::WriteHandleKey< McEventCollection > m_mcEventsOutputWriteHandleKey
Location of the output McEventCollection which has been filtered.
Definition: TruthParticleFilterBaseTool.h:104
ITruthIsolationTool.h