ATLAS Offline Software
HIUEModulatorTool.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 #include "HIUEModulatorTool.h"
6 #include "CxxUtils/sincos.h"
8 
9 #include "StoreGate/ReadHandle.h"
10 #include "StoreGate/WriteHandle.h"
11 
12 HIUEModulatorTool::HIUEModulatorTool(const std::string& n) : asg::AsgTool(n),
13  m_shape(nullptr)
14 {
15 #ifndef XAOD_STANDALONE
16  //should not need this due to ASG_TOOL_CLASS macro since
17  //athena only calls 3 arg constructor which explicitly declares athena interface?
18  declareInterface<IHIUEModulatorTool>(this);
19 #endif
20 }
21 
23 {
24  //First we initialize keys - after initialization they are frozen
25 
26  ATH_CHECK( m_shape_key.initialize( !m_shape_key.key().empty() ) );
27 
28  m_nh_vector.reserve(3);
29  if(m_do_v2) m_nh_vector.push_back(2);
30  if(m_do_v3) m_nh_vector.push_back(3);
31  if(m_do_v4) m_nh_vector.push_back(4);
32  if( m_nh_vector.size()!=0 && m_shape_key.key().empty() )
33  ATH_MSG_WARNING("Requested modulation, but provided no name for HIEventShapeContainer, no modulation will be applied");
34 
35  ATH_MSG_DEBUG("Equipping " << m_do_v2 << "\t" << m_do_v3 << "\t" << m_do_v4);
36 
37  return StatusCode::SUCCESS;
38 }
39 
40 
42 {
43  m_shape=shape;
44  return checkCompatibility();
45 }
46 
47 
48 void HIUEModulatorTool::setHarmonics(const std::vector<unsigned int>& v)
49 {
50  m_nh_vector.assign(v.begin(),v.end());
51 }
52 
54  const xAOD::HIEventShape* shape /*=nullptr*/) const
55 {
56  if (!shape)
57  shape = m_shape;
58  if (!shape)
59  if (getShape (shape).isFailure() || !shape)
60  return 1;
61  return modulate(m_nh_vector,shape,phi);
62 }
63 
65 {
66  shape = 0;
67  if( m_shape_key.key().empty() )
68  {
69  ATH_MSG_DEBUG("ShapeKey empty, no modulation, returning shape =" << shape);
70  return StatusCode::SUCCESS;
71  }
72 
74  if (!read_handle_evtShape.isValid()) {
75  ATH_MSG_FATAL( "Could not find HI event shape!" );
76  return(StatusCode::FAILURE);
77  }
78 
79  const xAOD::HIEventShapeContainer* mod_shape = read_handle_evtShape.get();
80 
81  if(mod_shape->size()==0)
82  {
83  ATH_MSG_ERROR("Modulation container empty : " << m_shape_key);
84  return StatusCode::FAILURE;
85  }
86  shape = mod_shape->at(0);
87  return StatusCode::SUCCESS;
88 }
89 
90 float HIUEModulatorTool::modulate(const std::vector<unsigned int>& nh_vector, const xAOD::HIEventShape* shape, float phi)
91 {
92  float modulation=0;
93  float et=shape->et();
94  if(et > 0.)
95  {
96  for(unsigned int i : nh_vector)
97  {
98 
99  unsigned int ih=i-1;
100  float nphi=i;
101 
102  nphi*=phi;
103  float qx=shape->etCos().at(ih);
104  float qy=shape->etSin().at(ih);
105  CxxUtils::sincos sc(nphi);
106  modulation+=2.*sc.apply(qy,qx);
107  }
108  modulation/=et;
109  }
110 
111  return modulation+1;
112 }
113 
115 {
116  return ( shape->etCos().size() >= n ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
117 }
118 
120 {
121  for(unsigned int i : m_nh_vector)
122  {
123  if(checkQVectorSize(m_shape,i).isFailure())
124  {
125  ATH_MSG_ERROR("HIEventShapeContainer " << m_shape_key << " does not have requested harmonic " << i );
126  return StatusCode::FAILURE;
127  }
128  }
129  return StatusCode::SUCCESS;
130 }
131 
HIUEModulatorTool::getShape
virtual StatusCode getShape(const xAOD::HIEventShape *&shape) const override
Definition: HIUEModulatorTool.cxx:64
xAOD::HIEventShape_v2::et
float et() const
Transverse energy reconstructed.
HIUEModulatorTool.h
HIUEModulatorTool::setEventShapeForModulation
virtual StatusCode setEventShapeForModulation(const xAOD::HIEventShape *shape) override
Definition: HIUEModulatorTool.cxx:41
et
Extra patterns decribing particle interation process.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
HIUEModulatorTool::HIUEModulatorTool
HIUEModulatorTool(const std::string &myname)
Definition: HIUEModulatorTool.cxx:12
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
asg
Definition: DataHandleTestTool.h:28
sincos.h
Helper to simultaneously calculate sin and cos of the same angle.
xAOD::HIEventShape_v2::etSin
const std::vector< float > & etSin() const
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
HIUEModulatorTool::m_do_v3
Gaudi::Property< bool > m_do_v3
Definition: HIUEModulatorTool.h:47
HIUEModulatorTool::m_nh_vector
std::vector< unsigned int > m_nh_vector
Definition: HIUEModulatorTool.h:42
xAOD::HIEventShape_v2
Interface class for the HI reconstruction EDM.
Definition: HIEventShape_v2.h:31
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::HIEventShape_v2::etCos
const std::vector< float > & etCos() const
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HIUEModulatorTool::getModulation
virtual float getModulation(float phi, const xAOD::HIEventShape *shape=nullptr) const override
Definition: HIUEModulatorTool.cxx:53
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HIEventShapeContainer.h
HIUEModulatorTool::checkCompatibility
StatusCode checkCompatibility() const
Definition: HIUEModulatorTool.cxx:119
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HIUEModulatorTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: HIUEModulatorTool.cxx:22
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HIUEModulatorTool::setHarmonics
virtual void setHarmonics(const std::vector< unsigned int > &v) override
Definition: HIUEModulatorTool.cxx:48
HIUEModulatorTool::checkQVectorSize
StatusCode checkQVectorSize(const xAOD::HIEventShape *shape, unsigned int n) const
Definition: HIUEModulatorTool.cxx:114
python.PyAthena.v
v
Definition: PyAthena.py:157
HIUEModulatorTool::m_do_v2
Gaudi::Property< bool > m_do_v2
Definition: HIUEModulatorTool.h:45
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CxxUtils::sincos
Helper to simultaneously calculate sin and cos of the same angle.
Definition: sincos.h:76
HIUEModulatorTool::m_do_v4
Gaudi::Property< bool > m_do_v4
Definition: HIUEModulatorTool.h:49
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
ReadHandle.h
Handle class for reading from StoreGate.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
HIUEModulatorTool::m_shape_key
SG::ReadHandleKey< xAOD::HIEventShapeContainer > m_shape_key
Definition: HIUEModulatorTool.h:39
HIUEModulatorTool::modulate
static float modulate(const std::vector< unsigned int > &nh_vector, const xAOD::HIEventShape *shape, float phi)
Definition: HIUEModulatorTool.cxx:90
HIUEModulatorTool::m_shape
const xAOD::HIEventShape * m_shape
Definition: HIUEModulatorTool.h:41