ATLAS Offline Software
EventShapeCopier.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // EventShapeCopier.cxx
6 
8 
13 #include "AthContainers/Accessor.h"
15 
16 //**********************************************************************
17 
19 : asg::AsgTool(name),
20  m_inputEventShape("LCTopoEventShape"), m_outputEventShape(""), m_eventDensityName("") {
21  declareProperty("InputEventShape", m_inputEventShape );
22  declareProperty("OutputEventShape", m_outputEventShape );
23  declareProperty("EventDensityName", m_eventDensityName );
24 
25 }
26 
27 //**********************************************************************
28 
30 
31 //**********************************************************************
32 
34 
35  // DataHandles
36  ATH_CHECK( m_inputEventShape.initialize() );
37  ATH_CHECK( m_outputEventShape.initialize() );
39  ATH_CHECK( m_outputEventShapeIn.initialize() );
40 
41  return StatusCode::SUCCESS;
42 }
43 
44 //**********************************************************************
45 
47 
48  ATH_MSG_DEBUG("Begin fillEventShape()");
49 
50  // check if not already existing
51  auto handle_inOut = SG::makeHandle (m_outputEventShapeIn);
52  if ( handle_inOut.isValid() ) {
53  ATH_MSG_WARNING( "EventShape with key "<< m_outputEventShapeIn.key() << " already exists. Not overwriting it." );
54  return StatusCode::SUCCESS;
55  }
56 
58  std::unique_ptr<xAOD::EventShape> evs_ptr(evs);
59 
61  std::unique_ptr<xAOD::EventShapeAuxInfo> evsaux_ptr( evsaux);
62  evs->setStore( evsaux );
63 
65 
66  auto h_out = makeHandle(m_outputEventShape);
67  if ( ! h_out.record(std::move(evs_ptr), std::move(evsaux_ptr)) ) {
68  ATH_MSG_WARNING("Unable to write new Jet collection and aux store to event store: " << m_outputEventShape.key());
69  } else {
70  ATH_MSG_DEBUG("Created new EventShape container: " << m_outputEventShape.key());
71  }
72 
73  return StatusCode::SUCCESS;
74 }
75 
76 //**********************************************************************
78  const xAOD::EventShape * inputES;
79 
81  if ( handle_in.isValid() ) {
82  inputES = handle_in.cptr();
83  } else {
84  ATH_MSG_WARNING("Unable to read: " << m_inputEventShape.key());
85  return StatusCode::FAILURE;
86  }
87 
88  SG::ConstAccessor<float> InputDensityAcc ( m_eventDensityName ) ;
89  SG::ConstAccessor<float> InputDensitySigmaAcc ( m_eventDensityName+"Sigma" ) ;
90  SG::ConstAccessor<float> InputDensityAreaAcc ( m_eventDensityName+"Area" ) ;
91  static const SG::Accessor<float> DensityAcc ( "Density" ) ;
92  static const SG::Accessor<float> DensitySigmaAcc ( "DensitySigma" ) ;
93  static const SG::Accessor<float> DensityAreaAcc ( "DensityArea" ) ;
94  DensityAcc(*evs) = InputDensityAcc(*inputES);
95  DensitySigmaAcc(*evs) = InputDensitySigmaAcc(*inputES);
96  DensityAreaAcc(*evs) = InputDensityAreaAcc(*inputES);
97 
98  return StatusCode::SUCCESS;
99 }
100 
101 //**********************************************************************
102 
103 #ifdef XAOD_ANALYSIS
105  setProperty("InputEventShape", "LCTopoEventShape").ignore();
106  setProperty("OutputEventShape", "Kt4LCTopoEventShape").ignore();
107  setProperty("EventDensityName", "DensityForJetsR4").ignore();
108 
109  fillEventShape().ignore();
110 
111  setProperty("InputEventShape", "LCTopoEventShape").ignore();
112  setProperty("OutputEventShape", "Kt6LCTopoEventShape").ignore();
113  setProperty("EventDensityName", "DensityForJetsR6").ignore();
114 
115  fillEventShape().ignore();
116 }
117 #else
118 // In Athena, do nothing. Use an Athena alg as defined in python/EventDensityConfig.py
120 #endif
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::EventShapeAuxInfo_v1
Auxiliary information about the event shapes.
Definition: EventShapeAuxInfo_v1.h:22
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::Accessor< float >
EventShape.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:258
asg
Definition: DataHandleTestTool.h:28
SG::ConstAccessor< float >
EventShapeCopier::m_outputEventShapeIn
SG::ReadHandleKey< xAOD::EventShape > m_outputEventShapeIn
Definition: EventShapeCopier.h:62
EventShapeCopier::m_eventDensityName
std::string m_eventDensityName
Definition: EventShapeCopier.h:66
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
EventShapeCopier::renameEventDensities
void renameEventDensities()
This function is only a convenience function for use in Standalone Analysis it avoids the need of con...
Definition: EventShapeCopier.cxx:119
SG::AuxElement::setStore
void setStore(const SG::IConstAuxStore *store)
Set the store associated with this object.
Definition: AuxElement.cxx:221
EventShapeCopier::initialize
StatusCode initialize()
Initialization.
Definition: EventShapeCopier.cxx:33
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EventShapeCopier::fillEventShape
StatusCode fillEventShape() const
Action.
Definition: EventShapeCopier.cxx:46
EventShapeCopier.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::EventShape_v1
Data class for event shapes.
Definition: EventShape_v1.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
ReadHandle.h
Handle class for reading from StoreGate.
EventShapeCopier::EventShapeCopier
EventShapeCopier(const std::string &name)
Constructor with parameters:
Definition: EventShapeCopier.cxx:18
Accessor.h
Helper class to provide type-safe access to aux data.
EventShapeCopier::m_inputEventShape
SG::ReadHandleKey< xAOD::EventShape > m_inputEventShape
Definition: EventShapeCopier.h:63
EventShapeCopier::~EventShapeCopier
~EventShapeCopier()
Destructor:
Definition: EventShapeCopier.cxx:29
EventShapeAuxInfo.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::EventShapeAuxInfo
EventShapeAuxInfo_v1 EventShapeAuxInfo
Definition of the latest event shape auxiliary info version.
Definition: EventShapeAuxInfo.h:16
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
xAOD::EventShape
EventShape_v1 EventShape
Definition of the current event format version.
Definition: EventShape.h:16
EventShapeCopier::m_outputEventShape
SG::WriteHandleKey< xAOD::EventShape > m_outputEventShape
Definition: EventShapeCopier.h:64