ATLAS Offline Software
CopyEventWeight.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XAOD_ANALYSIS
6 
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 
18 {
21  return StatusCode::SUCCESS;
22 }
23 
25  // Check that the collection isn't empty
27  const size_t nEvents = events_const()->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()->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()->weights()[iw]);
45  eventType->set_mc_event_weight(event_const()->weights()[iw], iw, nw);
46  weights.push_back(event_const()->weights()[iw]);
47  }
48 
50  mcWeights(0) = 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
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CopyEventWeight::m_mcWeightsKey
SG::WriteDecorHandleKey< xAOD::EventInfo > m_mcWeightsKey
Definition: CopyEventWeight.h:39
GenBase::events_const
const McEventCollection * events_const() const
Access the current event's McEventCollection (const)
Definition: GenBase.h:96
EventType
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition: EventType.h:92
EventType.h
This class provides general information about an event. It extends EventInfo with a list of sub-evts ...
CopyEventWeight::execute
virtual StatusCode execute() override
Definition: CopyEventWeight.cxx:24
CopyEventWeight::CopyEventWeight
CopyEventWeight(const std::string &name, ISvcLocator *svcLoc)
Constructor.
Definition: CopyEventWeight.cxx:12
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CopyEventWeight.h
GenBase
Base class for common behaviour of MC truth algorithms.
Definition: GenBase.h:47
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
CopyEventWeight::initialize
virtual StatusCode initialize() override
Copy the weight vector for each event.
Definition: CopyEventWeight.cxx:17
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
nEvents
int nEvents
Definition: fbtTestBasics.cxx:79
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:43
weights
Definition: herwig7_interface.h:44
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
SG::WriteDecorHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
GenBase::initialize
virtual StatusCode initialize() override
Definition: GenBase.cxx:17
GenBase::event_const
const HepMC::GenEvent * event_const() const
Access the current signal event (const)
Definition: GenBase.h:83
EventInfo::event_type
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
Definition: EventInfo/EventInfo/EventInfo.h:234