ATLAS Offline Software
SumOfWeightsAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ReweightUtils includes
6 #include "SumOfWeightsAlg.h"
8 
9 #include "TString.h"
10 #include <string>
11 
12 using std::string;
13 
14 //**********************************************************************
15 
16 SumOfWeightsAlg::SumOfWeightsAlg(const std::string& name, ISvcLocator* pSvcLocator ) :
17  ::AthFilterAlgorithm( name, pSvcLocator ), m_eventsProcessed(0), m_cutIDs() {
18  declareProperty( "WeightTools", m_weightTools);
19 }
20 
21 //**********************************************************************
22 
24 
25 //**********************************************************************
26 
28  // ^ due to registerTopFilter
29  StatusCode sc;
30  ATH_MSG_DEBUG("Initializing " << name() << "...");
31  ATH_MSG_DEBUG("Retrieving tools...");
32  sc = m_weightTools.retrieve();
33  if ( ! sc.isSuccess() ) {
34  ATH_MSG_ERROR("Tool retrieval failed.");
35  return sc;
36  }
37  ATH_MSG_DEBUG("Tool retrieval completed.");
38  unsigned int ntool = m_weightTools.size();
39  ATH_MSG_DEBUG(" Tool count: " << ntool);
40  for (size_t itool = 0; itool < ntool; ++itool ) {
41  ATH_MSG_DEBUG(" " << m_weightTools[itool]->name());
42  if(msgLvl(MSG::DEBUG)) m_weightTools[itool]->print();
43  // Get the tool's message property:
44  const WeightToolBase* tool = dynamic_cast< const WeightToolBase* >( m_weightTools[ itool ].operator->() );
45  if( ! tool ) {
46  ATH_MSG_ERROR( "The received tool is not an WeightToolBase?!?" );
47  return StatusCode::FAILURE;
48  }
49  //strip the 'ToolSvc.' off the weight name
50  std::string toolName = m_weightTools[itool]->name();
51  if(toolName.starts_with ("ToolSvc.")) toolName.replace(0,8,"");
52  CutIdentifier cID = cutFlowSvc()->registerTopFilter( toolName,
53  toolName, // description (can be improved FIXME)
54  xAOD::CutBookkeeper::CutLogic::ALLEVENTSPROCESSED,
55  "AllStreams",
56  true);
57  m_cutIDs.push_back(cID);
58  }
59 
60  return StatusCode::SUCCESS;
61 }
62 
63 //**********************************************************************
64 
66  ATH_MSG_DEBUG ("Executing " << name() << ", will loop over WeightTools...");
67  setFilterPassed(true);
68 
69  for (std::size_t i = 0; i < m_cutIDs.size(); ++i) {
70  float weight = m_weightTools[i]->getWeight();
71  ATH_MSG_DEBUG(" got weight = " << weight << " for " << m_weightTools[i]->name());
72  const CutIdentifier cutID = m_cutIDs[i];
73  cutFlowSvc()->addEvent(cutID, weight);
74  }
75 
76  m_eventsProcessed += 1;
77  return StatusCode::SUCCESS;
78 }
79 
80 
81 //**********************************************************************
83  ATH_MSG_INFO ("Finalizing " << name() << "...");
84  return StatusCode::SUCCESS;
85 }
86 
87 
WeightToolBase.h
AthFilterAlgorithm::setFilterPassed
virtual void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
Definition: AthFilterAlgorithm.cxx:99
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
initialize
void initialize()
Definition: run_EoverP.cxx:894
SumOfWeightsAlg.h
AthFilterAlgorithm::cutID
CutIdentifier cutID()
return the CutIdentifier corresponding to the top-level cut of this filter algorithm
Definition: AthFilterAlgorithm.h:116
SumOfWeightsAlg::m_eventsProcessed
unsigned long m_eventsProcessed
number of events processed
Definition: SumOfWeightsAlg.h:54
SumOfWeightsAlg::m_weightTools
ToolHandleArray< IWeightTool > m_weightTools
Athena configured tools.
Definition: SumOfWeightsAlg.h:51
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
AthFilterAlgorithm
Definition: AthFilterAlgorithm.h:26
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SumOfWeightsAlg::~SumOfWeightsAlg
~SumOfWeightsAlg()
Destructor:
Definition: SumOfWeightsAlg.cxx:23
SumOfWeightsAlg::m_cutIDs
std::vector< CutIdentifier > m_cutIDs
cut IDs
Definition: SumOfWeightsAlg.h:57
CutIdentifier
uint32_t CutIdentifier
InstanceIdentifier is a unique identifer used for every AthFilterAlgorithm instance.
Definition: ICutFlowSvc.h:22
SumOfWeightsAlg::finalize
StatusCode finalize()
Definition: SumOfWeightsAlg.cxx:82
SumOfWeightsAlg::execute
StatusCode execute()
Definition: SumOfWeightsAlg.cxx:65
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
AthFilterAlgorithm::cutFlowSvc
ServiceHandle< ICutFlowSvc > & cutFlowSvc()
return a handle to an ICutFlowSvc instance
Definition: AthFilterAlgorithm.h:108
DEBUG
#define DEBUG
Definition: page_access.h:11
WeightToolBase
Definition: WeightToolBase.h:29
SumOfWeightsAlg::SumOfWeightsAlg
SumOfWeightsAlg()
Default constructor:
ATLAS_NOT_THREAD_SAFE
StatusCode SumOfWeightsAlg::initialize ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: SumOfWeightsAlg.cxx:27