ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
EvgenProdTools
src
CopyEventWeight.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef XAOD_ANALYSIS
6
7
#include "
EvgenProdTools/CopyEventWeight.h
"
8
#include "
StoreGate/WriteDecorHandle.h
"
9
#include "EventInfo/EventInfo.h"
10
#include "
EventInfo/EventType.h
"
11
12
CopyEventWeight::CopyEventWeight
(
const
std::string& name, ISvcLocator* svcLoc)
13
:
GenBase
(name, svcLoc)
14
{
15
}
16
17
StatusCode
CopyEventWeight::initialize
()
18
{
19
ATH_CHECK
(
GenBase::initialize
());
20
ATH_CHECK
(
m_mcWeightsKey
.initialize());
21
return
StatusCode::SUCCESS;
22
}
23
24
StatusCode
CopyEventWeight::execute
(
const
EventContext& ctx) {
25
// Check that the collection isn't empty
27
const
size_t
nEvents
=
events_const
(ctx)->
size
();
28
if
(
nEvents
== 0) {
29
ATH_MSG_WARNING
(
"McEventCollection is empty"
);
30
return
StatusCode::SUCCESS;
31
}
32
33
// Get the event info/type object to be filled
34
const
EventInfo
* pInputEvt(
nullptr
);
35
CHECK
(
evtStore
()->retrieve(pInputEvt));
36
assert(pInputEvt);
37
EventType
* eventType =
const_cast<
EventType
*
>
(pInputEvt->
event_type
());
38
39
// Copy weights into EventInfo
40
const
size_t
nw =
event_const
(ctx)->weights().size();
41
if
(nw == 0)
ATH_MSG_WARNING
(
"EVENT WEIGHT ARRAY EMPTY"
);
42
std::vector<float>
weights
;
43
for
(
size_t
iw = 0; iw < nw; ++iw) {
44
ATH_MSG_DEBUG
(
"COPYING EVENT WEIGHT "
<< iw <<
"/"
<< nw <<
": "
<<
event_const
(ctx)->
weights
()[iw]);
45
eventType->
set_mc_event_weight
(
event_const
(ctx)->
weights
()[iw], iw, nw);
46
weights
.push_back(
event_const
(ctx)->
weights
()[iw]);
47
}
48
49
SG::WriteDecorHandle<xAOD::EventInfo,std::vector<float>
> mcWeights(
m_mcWeightsKey
, ctx);
50
mcWeights(0) = std::move(
weights
);
51
52
// Post-hoc debug printouts
53
ATH_MSG_DEBUG
(
"Copied HepMC signal event weight(s) to EventInfo"
);
54
if
(
nEvents
> 1)
ATH_MSG_DEBUG
(
"Ignored event weights of "
<<
nEvents
-1 <<
"bkg events"
);
55
56
return
StatusCode::SUCCESS;
57
}
58
59
#endif
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CopyEventWeight.h
EventType.h
This class provides general information about an event.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
CopyEventWeight::m_mcWeightsKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_mcWeightsKey
Definition
CopyEventWeight.h:39
CopyEventWeight::initialize
virtual StatusCode initialize() override
Copy the weight vector for each event.
Definition
CopyEventWeight.cxx:17
CopyEventWeight::CopyEventWeight
CopyEventWeight(const std::string &name, ISvcLocator *svcLoc)
Constructor.
Definition
CopyEventWeight.cxx:12
CopyEventWeight::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
CopyEventWeight.cxx:24
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
EventInfo::event_type
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
Definition
EventInfo/EventInfo/EventInfo.h:234
EventType
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition
EventType.h:92
EventType::set_mc_event_weight
void set_mc_event_weight(float weight, unsigned int iweight=0, unsigned int nWeightsMax=0)
Add in MC weight. For more than 1 weight, add with iweight > 0.
Definition
EventType.cxx:207
GenBase::initialize
virtual StatusCode initialize() override
Definition
GenBase.cxx:17
GenBase::event_const
const HepMC::GenEvent * event_const(const EventContext &ctx) const
Access the current signal event (const).
Definition
GenBase.h:79
GenBase::GenBase
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
GenBase.cxx:11
GenBase::events_const
const McEventCollection * events_const(const EventContext &ctx) const
Access the current event's McEventCollection (const).
Definition
GenBase.h:93
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
nEvents
const int nEvents
Definition
fbtTestBasics.cxx:78
EventInfo
Definition
EventInfo.py:1
weights
Definition
herwig7_interface.h:38
Generated on
for ATLAS Offline Software by
1.17.0