ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
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
46
47
48void 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
64StatusCode HIUEModulatorTool::getShape(const xAOD::HIEventShape* & shape) const
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
90float 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
114StatusCode HIUEModulatorTool::checkQVectorSize(const xAOD::HIEventShape* shape, unsigned int n) const
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
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual StatusCode getShape(const xAOD::HIEventShape *&shape) const override
virtual void setHarmonics(const std::vector< unsigned int > &v) override
static float modulate(const std::vector< unsigned int > &nh_vector, const xAOD::HIEventShape *shape, float phi)
SG::ReadHandleKey< xAOD::HIEventShapeContainer > m_shape_key
Gaudi::Property< bool > m_do_v2
HIUEModulatorTool(const std::string &myname)
virtual StatusCode setEventShapeForModulation(const xAOD::HIEventShape *shape) override
StatusCode checkQVectorSize(const xAOD::HIEventShape *shape, unsigned int n) const
const xAOD::HIEventShape * m_shape
virtual float getModulation(float phi, const xAOD::HIEventShape *shape=nullptr) const override
StatusCode checkCompatibility() const
std::vector< unsigned int > m_nh_vector
Gaudi::Property< bool > m_do_v4
Gaudi::Property< bool > m_do_v3
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
const std::vector< float > & etSin() const
sine (x) part of the harmonic modulation strength
const std::vector< float > & etCos() const
cosine (y) part of the harmonic modulation strength Following convention is used: index 0 is first ha...
float et() const
Transverse energy reconstructed on the slice.
HIEventShapeContainer_v2 HIEventShapeContainer
Define the latest version of the container.
HIEventShape_v2 HIEventShape
Definition of the latest event info version.
Helper to simultaneously calculate sin and cos of the same angle.
Helper to simultaneously calculate sin and cos of the same angle.
Definition sincos.h:39
Extra patterns decribing particle interation process.