ATLAS Offline Software
Loading...
Searching...
No Matches
WeightsAgregator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ReweightUtils includes
7
9
10
11WeightsAgregator::WeightsAgregator( const std::string& name )
12 : WeightToolBase( name ),
13 m_eventInfoName("EventInfo"),
14 m_toolArray() {
15 declareProperty("Ingredients", m_toolArray, "List of helpers to offload some tasks to" );
16 declareProperty("EventInfoName", m_eventInfoName, "Name of the xAOD::EventInfo object");
17}
18
19
21 ATH_MSG_DEBUG ("Initializing " << name() << "...");
23
24 // Retrieve the needed weight tools
25 ATH_CHECK(m_toolArray.retrieve());
26
27 return StatusCode::SUCCESS;
28}
29
30
31
32// returns: the value that was calculated from the xAOD::IParticle composite built event
34{
35 ATH_MSG_DEBUG ("Evaluating " << name() << "...");
36
37 double weight=1.0;
38 for ( const auto& wToolHandle : m_toolArray ){
39 const IWeightTool* wtool = &(*wToolHandle);
40 ATH_MSG_DEBUG (" In WeightsAgregator::evaluate(), having tool to deal with called " << wtool->name());
41 if( const IObservableTool* obstool = dynamic_cast< const IObservableTool* >( wtool ) )
42 weight *= obstool->evaluate(part);
43 }
44
45 ATH_MSG_DEBUG ("Got weight in WeightsAgregator::evaluate() = " << weight << ".");
46 return weight;
47}
48
49
51 //Retrieveing eventInfo
52 const xAOD::EventInfo* evtInfo;
53 StatusCode sc = evtStore()->retrieve( evtInfo, m_eventInfoName );
54 if(sc.isFailure() || !evtInfo) {
55 ATH_MSG_ERROR (" EventInfo could not be retrieved !!");
56 return 0.;
57 }
58
59 // don't do anything for data
61 ATH_MSG_DEBUG (" Returning weight=1. for data.");
62 return 1.;
63 }
64
65 float weight=1.;
66 ToolHandleArray< IWeightTool >::const_iterator itPriv = m_toolArray.begin(), itPrivEnd = m_toolArray.end();
67 for ( ; itPriv != itPrivEnd; ++itPriv ) {
68 /*if (!(*itPriv))
69 ATH_MSG_ERROR("tool " << (*itPriv).typeAndName() << " failed it's task ... stop!");*/
70 weight *= (*itPriv)->getWeight();
71 }
72
73 //Decorate EventInfo with weight for later use
74 this->addDecoration(evtInfo, weight);
75
76
77 ATH_MSG_DEBUG (" " << name() << " returning weight= " << weight << ".");
78 return weight;
79}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
Interface for tools that want to calculate a quantity from an xAOD::IParticle.
Interface for tools that want to calculate a weight from different event information.
Definition IWeightTool.h:21
WeightToolBase(const std::string &name)
Create a proper constructor for Athena.
bool addDecoration(const xAOD::EventInfo *evtInfo, float weight) const
virtual StatusCode initialize() override
Usual initialize method of the framework.
virtual double evaluate(const xAOD::IParticle *part) const override
returns: the value that was calculated from the xAOD::IParticle (composite built event object for ins...
virtual StatusCode initialize() override
Usual initialize method of the framework.
virtual double getWeight() const override
returns: the value that was calculated from the usual Athena storegate
ToolHandleArray< IWeightTool > m_toolArray
Array of ingredient weight tools.
WeightsAgregator(const std::string &name)
Create a proper constructor for Athena.
std::string m_eventInfoName
Name of the xAOD::EventInfo object.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
Class providing the definition of the 4-vector interface.
EventInfo_v1 EventInfo
Definition of the latest event info version.