ATLAS Offline Software
Loading...
Searching...
No Matches
T2CaloEgammaReFastAlgo.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/*
6 NAME: T2CaloEgammaReFastAlgo.cxx
7 PACKAGE: Trigger/TrigAlgorithms/TrigT2CaloEgamma
8
9 AUTHOR: Denis Oliveira Damazio
10 Carlos Chavez Barajas
11
12*/
13
14#include "GaudiKernel/StatusCode.h"
15
16#include "AthLinks/ElementLink.h"
19#include "CxxUtils/phihelper.h"
23
24class ISvcLocator;
25
26T2CaloEgammaReFastAlgo::T2CaloEgammaReFastAlgo(const std::string& name, ISvcLocator* pSvcLocator) :
27 AthReentrantAlgorithm(name, pSvcLocator)
28{}
29
31{
32 m_emAlgTools.retrieve().ignore();
33 ATH_CHECK(m_clusterContainerKey.initialize());
34 ATH_CHECK(m_roiCollectionKey.initialize());
35 ATH_CHECK( m_bcidAvgKey.initialize() );
36 if (! m_monTool.empty() ) ATH_CHECK( m_monTool.retrieve() );
38
39 return StatusCode::SUCCESS;
40}
41
42StatusCode T2CaloEgammaReFastAlgo::execute(const EventContext& context) const
43{
44
45 auto timer = Monitored::Timer("TIME_exec");
46 auto clET = Monitored::Scalar("TrigEMCluster_eT",-999.0);
47 auto clHET = Monitored::Scalar("TrigEMCluster_had1",-999.0);
48 auto clEta = Monitored::Scalar("TrigEMCluster_eta",-999.0);
49 auto clPhi = Monitored::Scalar("TrigEMCluster_phi",-999.0);
50 auto clReta = Monitored::Scalar("TrigEMCluster_rEta",-999.0);
51 auto clETrings = Monitored::Scalar("TrigEMCluster_et_rings",-999.0);
52 auto res_et = Monitored::Scalar("Resolution_et",-999.0);
53 auto monitoring = Monitored::Group( m_monTool, timer, clET, clHET, clEta, clPhi, clReta,clETrings,res_et);
54
55
57 ATH_CHECK( trigEmClusterCollection.record(std::make_unique<xAOD::TrigEMClusterContainer>(),
58 std::make_unique<xAOD::TrigEMClusterAuxContainer>()) );
59
60
61 auto roisHandle = SG::makeHandle(m_roiCollectionKey, context);
62 if (!roisHandle.isValid()) {
63 ATH_MSG_DEBUG("no RoI");
64 return StatusCode::SUCCESS;
65 }
66
67
68 trigEmClusterCollection->reserve(roisHandle->size());
69
70 ATH_MSG_DEBUG("RoI descriptor size is " << roisHandle->size() );
71
72 for (const TrigRoiDescriptor* roiDescriptor : *roisHandle) {
73 float etaL1, phiL1;
74 double etamin, etamax, phimin, phimax;
75
76 ATH_MSG_DEBUG( "RoI eta = " << roiDescriptor->eta() << " RoI phi = " << roiDescriptor->phi());
77
78 if ((m_l1eta < -9.9) && (m_l1phi < -9.9)) {
79
80 etamin = std::max(-2.5, roiDescriptor->eta() - m_etaWidth);
81 etamax = std::min( 2.5, roiDescriptor->eta() + m_etaWidth);
82
83 phimin = CxxUtils::wrapToPi(roiDescriptor->phi() - m_phiWidth);
84 phimax = CxxUtils::wrapToPi(roiDescriptor->phi() + m_phiWidth);
85
86 etaL1 = roiDescriptor->eta();
87 phiL1 = roiDescriptor->phi();
88 }
89 else {
90 etamin = std::max(-2.5, m_l1eta - m_etaWidth);
91 etamax = std::min( 2.5, static_cast<double>(m_l1eta) + m_etaWidth);
92
94 phimax = CxxUtils::wrapToPi(static_cast<double>(m_l1phi) + m_phiWidth);
95
96 etaL1 = m_l1eta;
97 phiL1 = m_l1phi;
98 }
99
100 TrigRoiDescriptor newroi(roiDescriptor->eta(), etamin, etamax,
101 roiDescriptor->phi(), phimin, phimax);
102
103
104 ATH_MSG_DEBUG(" etamin = " << etamin << " etamax = " << etamax <<
105 " phimin = " << phimin << " phimax = " << phimax);
106
107 xAOD::TrigEMCluster* ptrigEmCluster = new xAOD::TrigEMCluster();
108 trigEmClusterCollection->push_back(ptrigEmCluster);
109 ptrigEmCluster->setEnergy(0.0);
110 ptrigEmCluster->setEt(0.0);
111 ptrigEmCluster->setRawEnergy(0.0);
112 ptrigEmCluster->setRawEt(0.0);
113 ptrigEmCluster->setE277(0);
114 ptrigEmCluster->setEmaxs1(0);
115 ptrigEmCluster->setE2tsts1(0);
116 ptrigEmCluster->setEhad1(-999);
117 ptrigEmCluster->setWeta2(-999);
118 ptrigEmCluster->setFracs1(-999);
119 ptrigEmCluster->setE233(-999);
120 ptrigEmCluster->setE237(-999);
121 ptrigEmCluster->setWstot(-999);
122 ptrigEmCluster->setEta1(-999);
123 ptrigEmCluster->setNCells(0);
124 ptrigEmCluster->setRawEta(-999);
125 ptrigEmCluster->setRawPhi(-999);
126
127 // It is a good idea to clear the energies
128 for (int i = 0; i < CaloSampling::CaloSample::MINIFCAL0; i++) {
129 ptrigEmCluster->setEnergy((CaloSampling::CaloSample)i, 0.);
130 ptrigEmCluster->setRawEnergy((CaloSampling::CaloSample)i, 0.);
131 }
132 // Initial cluster position is the LVL1 position
133 ptrigEmCluster->setEta(etaL1);
134 ptrigEmCluster->setPhi(phiL1);
135
136 // Add RoI word to TrigEMCluster
137 // Dangerous !!!! we need to define a *new* roiDescriptor if we want to
138 // change the size, so we should be careful about *which* roi descriptor
139 // we save, and *which* "roiWord" (if any) we store if we need to use it
140 // again
141 ptrigEmCluster->setRoIword(roiDescriptor->roiWord());
142 const CaloDetDescrElement* caloDDE = nullptr;
143
144 uint32_t error = 0;
145 for (const auto& tool : m_emAlgTools) {
146 ATH_CHECK( tool->execute(*ptrigEmCluster, newroi, caloDDE, context) );
147 }
148 // // support to new monitoring
149 // Cluster quality is a collection of possible errors
150 // No error quality=0
151 ptrigEmCluster->setClusterQuality(error);
152 if ((error & 0xC0000000) || ptrigEmCluster->phi() < -M_PI || ptrigEmCluster->phi() > +M_PI ||
153 std::abs(ptrigEmCluster->eta()) > 10.0) {
154 // Clustering failed. Transmit ahead L1
155 ptrigEmCluster->setEta(etaL1);
156 ptrigEmCluster->setPhi(phiL1);
157 ptrigEmCluster->setEnergy(0.0);
158 ptrigEmCluster->setEt(0.0);
159 }
160
161
162 if ( caloDDE != nullptr ){
163 if ( caloDDE->is_lar_em_barrel() ){
164 for( ToolHandleArray<IEgammaCalibration>::const_iterator
165 ical=m_calibsBarrel.begin();
166 ical != m_calibsBarrel.end(); ++ical )
167 (*ical)->makeCorrection(ptrigEmCluster,caloDDE);
168 }else{
169 for( ToolHandleArray<IEgammaCalibration>::const_iterator
170 ical=m_calibsEndcap.begin();
171 ical != m_calibsEndcap.end(); ++ical )
172 (*ical)->makeCorrection(ptrigEmCluster,caloDDE);
173 }
174 }
175
176 float et_calib = -999.0;
177 float et_uncalib = ptrigEmCluster->et();
178 if ( m_doCalibWithRings ){
179 if (m_calibWRingsTool->checkRings(context)){
180 et_calib = m_calibWRingsTool->makeCalibWRings(context);
181 ptrigEmCluster->setEt(et_calib);
182 }
183 }
184
185
186 float calZ0 = 0;
187
188 // Print out Cluster produced
189 if (msgLvl(MSG::DEBUG)) {
190 ATH_MSG_DEBUG(" Values of Cluster produced: ");
191 ATH_MSG_DEBUG(" REGTEST: emEnergy = " << ptrigEmCluster->energy());
192 ATH_MSG_DEBUG(" REGTEST: hadEnergy = " << ptrigEmCluster->ehad1());
193 ATH_MSG_DEBUG(" REGTEST: e237= " << ptrigEmCluster->e237());
194 ATH_MSG_DEBUG(" REGTEST: e277= " << ptrigEmCluster->e277());
195 ATH_MSG_DEBUG(" REGTEST: clusterWidth = " << ptrigEmCluster->weta2());
196 ATH_MSG_DEBUG(" REGTEST: frac73 = " << ptrigEmCluster->fracs1());
197 ATH_MSG_DEBUG(" REGTEST: e233 = " << ptrigEmCluster->e233());
198 ATH_MSG_DEBUG(" REGTEST: wstot = " << ptrigEmCluster->wstot());
199 ATH_MSG_DEBUG(" REGTEST: eta = " << ptrigEmCluster->eta());
200 ATH_MSG_DEBUG(" REGTEST: phi = " << ptrigEmCluster->phi());
201 ATH_MSG_DEBUG(" REGTEST: Eta1 = " << ptrigEmCluster->eta1());
202 ATH_MSG_DEBUG(" REGTEST: calZ0 = " << calZ0);
203 ATH_MSG_DEBUG(" REGTEST: quality = " << ptrigEmCluster->clusterQuality());
204 ATH_MSG_DEBUG(std::hex << " REGTEST: roiWord = 0x" << ptrigEmCluster->RoIword()
205 << std::dec);
206 }
207 // my monitoring
208 clET = et_uncalib*1e-3;
209 clHET = ptrigEmCluster->ehad1()*1e-3;
210 clEta = ptrigEmCluster->eta();
211 clPhi = ptrigEmCluster->phi();
212 clETrings = et_calib*1e-3;
213
214 if (et_uncalib != 0.) {
215 res_et = (et_calib - et_uncalib)/et_uncalib;
216 }
217
218 if ( ptrigEmCluster->e277() > 0.01 ) clReta = ptrigEmCluster->e237()/ptrigEmCluster->e277();
219
220 } // end of roiCollection iterator
221
222 return StatusCode::SUCCESS;
223}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
Header file to be included by clients of the Monitored infrastructure.
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
This class groups all DetDescr information related to a CaloCell.
bool is_lar_em_barrel() const
cell belongs to EM barrel
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
A monitored timer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Gaudi::Property< double > m_phiWidth
ToolHandleArray< IReAlgToolCalo > m_emAlgTools
virtual StatusCode execute(const EventContext &context) const override
Gaudi::Property< double > m_etaWidth
T2CaloEgammaReFastAlgo(const std::string &name, ISvcLocator *pSvcLocator)
ToolHandle< TrigFastCalibWithRings > m_calibWRingsTool
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
SG::WriteHandleKey< xAOD::TrigEMClusterContainer > m_clusterContainerKey
ToolHandleArray< IEgammaCalibration > m_calibsBarrel
virtual StatusCode initialize() override
ToolHandle< GenericMonitoringTool > m_monTool
ToolHandleArray< IEgammaCalibration > m_calibsEndcap
SG::ReadHandleKey< CaloBCIDAverage > m_bcidAvgKey
Gaudi::Property< float > m_l1eta
Gaudi::Property< bool > m_doCalibWithRings
Gaudi::Property< float > m_l1phi
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
unsigned int clusterQuality() const
get quality of cluster built (to be defined)
void setClusterQuality(unsigned int)
set quality of cluster built (to be defined)
void setNCells(int)
set number of cells used from RoI
void setRoIword(long)
set RoI Word
long RoIword() const
get RoI Word
void setRawPhi(float)
set Raw Phi (no calibration)
void setRawEnergy(float)
set Raw Energy (no calibration)
void setRawEta(float)
set Raw Eta (no calibration)
void setRawEt(float)
set Raw Et (no calibration)
void setPhi(float)
set Phi (calibrated)
float wstot() const
get width in first layer
void setEta(float)
set Eta (calibrated)
void setEt(float)
set Et (calibrated)
void setEhad1(float)
set hadronic Energy (first hadronic layer)
float et() const
get Et (calibrated)
float eta() const
get Eta (calibrated)
void setWeta2(float)
set cluster width (based on a 3x5 cluster - 2nd layer)
void setEnergy(float energy)
set Energy (calibrated)
void setE2tsts1(float)
set second maximum energy in sampling 1 (strip layer)
float phi() const
get Phi (calibrated)
float e237() const
get Energy in a 3x7 cluster (no calibration) around hottest cell
float e233() const
get Energy in a 3x3 cluster (no calibration) around hottest cell
void setE237(float)
set Energy in a 3x7 cluster (no calibration) around hottest cell
void setE277(float)
set Energy in a 7x7 cluster (no calibration) around hottest cell
void setEmaxs1(float)
set maximum energy in sampling 1 (strip layer)
float eta1() const
get Eta sampling 1 (strip layer)
void setFracs1(float)
set Energy in a 7 strips (around hottest strip) minus energy in 3 strips divided by energy in 3 strip...
float e277() const
get Energy in a 7x7 cluster (no calibration) around hottest cell
float ehad1() const
get hadronic Energy (first hadronic layer)
float weta2() const
get cluster width (based on a 3x5 cluster - 2nd layer)
void setWstot(float)
set width in first layer
float energy() const
get Energy (calibrated)
float fracs1() const
get Energy in a 7 strips (around hottest strip) minus energy in 3 strips divided by energy in 3 strip...
void setE233(float)
set Energy in a 3x3 cluster (no calibration) around hottest cell
void setEta1(float)
set Eta sampling 1 (strip layer)
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition phihelper.h:24
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
TrigEMCluster_v1 TrigEMCluster
Define the latest version of the trigger EM cluster class.
Helper for azimuthal angle calculations.