ATLAS Offline Software
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"
17 #include "T2CaloEgammaReFastAlgo.h"
19 #include "CxxUtils/phihelper.h"
23 
24 class ISvcLocator;
25 
26 T2CaloEgammaReFastAlgo::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());
36  if (! m_monTool.empty() ) ATH_CHECK( m_monTool.retrieve() );
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 StatusCode 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 }
xAOD::TrigCaloCluster_v1::setRawPhi
void setRawPhi(float)
set Raw Phi (no calibration)
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
T2CaloEgammaReFastAlgo::m_l1eta
Gaudi::Property< float > m_l1eta
Definition: T2CaloEgammaReFastAlgo.h:62
T2CaloEgammaReFastAlgo::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: T2CaloEgammaReFastAlgo.h:90
xAOD::TrigEMCluster_v1::setEta
void setEta(float)
set Eta (calibrated)
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
xAOD::TrigEMCluster_v1::eta
float eta() const
get Eta (calibrated)
xAOD::TrigEMCluster_v1::e233
float e233() const
get Energy in a 3x3 cluster (no calibration) around hottest cell
xAOD::TrigEMCluster_v1::setE237
void setE237(float)
set Energy in a 3x7 cluster (no calibration) around hottest cell
xAOD::TrigEMCluster_v1::setEnergy
void setEnergy(float energy)
set Energy (calibrated)
xAOD::TrigEMCluster_v1::weta2
float weta2() const
get cluster width (based on a 3x5 cluster - 2nd layer)
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
xAOD::TrigCaloCluster_v1::setRawEt
void setRawEt(float)
set Raw Et (no calibration)
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CxxUtils::wrapToPi
T wrapToPi(T phi)
Wrap angle in radians to [-pi, pi].
Definition: phihelper.h:24
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
xAOD::TrigEMCluster_v1::setE233
void setE233(float)
set Energy in a 3x3 cluster (no calibration) around hottest cell
xAOD::TrigEMCluster_v1::setEhad1
void setEhad1(float)
set hadronic Energy (first hadronic layer)
M_PI
#define M_PI
Definition: ActiveFraction.h:11
T2CaloEgammaReFastAlgo::m_calibsEndcap
ToolHandleArray< IEgammaCalibration > m_calibsEndcap
Definition: T2CaloEgammaReFastAlgo.h:72
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
xAOD::TrigCaloCluster_v1::setRawEta
void setRawEta(float)
set Raw Eta (no calibration)
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
T2CaloEgammaReFastAlgo::T2CaloEgammaReFastAlgo
T2CaloEgammaReFastAlgo(const std::string &name, ISvcLocator *pSvcLocator)
Definition: T2CaloEgammaReFastAlgo.cxx:26
xAOD::TrigEMCluster_v1::setE277
void setE277(float)
set Energy in a 7x7 cluster (no calibration) around hottest cell
xAOD::TrigCaloCluster_v1::clusterQuality
unsigned int clusterQuality() const
get quality of cluster built (to be defined)
xAOD::TrigEMCluster_v1::setPhi
void setPhi(float)
set Phi (calibrated)
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
xAOD::TrigEMCluster_v1::e237
float e237() const
get Energy in a 3x7 cluster (no calibration) around hottest cell
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
xAOD::TrigEMCluster_v1::phi
float phi() const
get Phi (calibrated)
T2CaloEgammaReFastAlgo::m_clusterContainerKey
SG::WriteHandleKey< xAOD::TrigEMClusterContainer > m_clusterContainerKey
Definition: T2CaloEgammaReFastAlgo.h:88
xAOD::TrigEMCluster_v1::setEmaxs1
void setEmaxs1(float)
set maximum energy in sampling 1 (strip layer)
T2CaloEgammaReFastAlgo::initialize
virtual StatusCode initialize() override
Definition: T2CaloEgammaReFastAlgo.cxx:30
TrigEMClusterAuxContainer.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
T2CaloEgammaReFastAlgo::m_calibsBarrel
ToolHandleArray< IEgammaCalibration > m_calibsBarrel
Definition: T2CaloEgammaReFastAlgo.h:70
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
T2CaloEgammaReFastAlgo::m_bcidAvgKey
SG::ReadHandleKey< CaloBCIDAverage > m_bcidAvgKey
Definition: T2CaloEgammaReFastAlgo.h:82
xAOD::TrigEMCluster
TrigEMCluster_v1 TrigEMCluster
Define the latest version of the trigger EM cluster class.
Definition: Event/xAOD/xAODTrigCalo/xAODTrigCalo/TrigEMCluster.h:17
IReAlgToolCalo.h
T2CaloEgammaReFastAlgo::m_emAlgTools
ToolHandleArray< IReAlgToolCalo > m_emAlgTools
Definition: T2CaloEgammaReFastAlgo.h:80
xAOD::TrigEMCluster_v1::setE2tsts1
void setE2tsts1(float)
set second maximum energy in sampling 1 (strip layer)
T2CaloEgammaReFastAlgo::m_etaWidth
Gaudi::Property< double > m_etaWidth
Definition: T2CaloEgammaReFastAlgo.h:64
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TrigEMCluster_v1::setWeta2
void setWeta2(float)
set cluster width (based on a 3x5 cluster - 2nd layer)
xAOD::TrigCaloCluster_v1::RoIword
long RoIword() const
get RoI Word
xAOD::TrigEMCluster_v1::setFracs1
void setFracs1(float)
set Energy in a 7 strips (around hottest strip) minus energy in 3 strips divided by energy in 3 strip...
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
xAOD::TrigEMCluster_v1::setEta1
void setEta1(float)
set Eta sampling 1 (strip layer)
xAOD::TrigEMCluster_v1::wstot
float wstot() const
get width in first layer
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
xAOD::TrigEMCluster_v1::fracs1
float fracs1() const
get Energy in a 7 strips (around hottest strip) minus energy in 3 strips divided by energy in 3 strip...
xAOD::TrigCaloCluster_v1::setRoIword
void setRoIword(long)
set RoI Word
T2CaloEgammaReFastAlgo::m_phiWidth
Gaudi::Property< double > m_phiWidth
Definition: T2CaloEgammaReFastAlgo.h:65
T2CaloEgammaReFastAlgo.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
xAOD::TrigEMCluster_v1::e277
float e277() const
get Energy in a 7x7 cluster (no calibration) around hottest cell
phihelper.h
Helper for azimuthal angle calculations.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::TrigCaloCluster_v1::setNCells
void setNCells(int)
set number of cells used from RoI
T2CaloEgammaReFastAlgo::m_roiCollectionKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_roiCollectionKey
Definition: T2CaloEgammaReFastAlgo.h:85
xAOD::TrigEMCluster_v1::ehad1
float ehad1() const
get hadronic Energy (first hadronic layer)
TrigEMClusterContainer.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloDetDescrElement::is_lar_em_barrel
bool is_lar_em_barrel() const
cell belongs to EM barrel
Definition: CaloDetDescrElement.cxx:98
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
T2CaloEgammaReFastAlgo::m_calibWRingsTool
ToolHandle< TrigFastCalibWithRings > m_calibWRingsTool
Definition: T2CaloEgammaReFastAlgo.h:91
xAOD::TrigEMCluster_v1::eta1
float eta1() const
get Eta sampling 1 (strip layer)
DEBUG
#define DEBUG
Definition: page_access.h:11
xAOD::TrigCaloCluster_v1::setRawEnergy
void setRawEnergy(float)
set Raw Energy (no calibration)
xAOD::TrigEMCluster_v1::setEt
void setEt(float)
set Et (calibrated)
xAOD::TrigEMCluster_v1::et
float et() const
get Et (calibrated)
xAOD::TrigEMCluster_v1::setWstot
void setWstot(float)
set width in first layer
xAOD::TrigCaloCluster_v1::setClusterQuality
void setClusterQuality(unsigned int)
set quality of cluster built (to be defined)
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
T2CaloEgammaReFastAlgo::m_doCalibWithRings
Gaudi::Property< bool > m_doCalibWithRings
Definition: T2CaloEgammaReFastAlgo.h:55
xAOD::TrigEMCluster_v1
Description of a trigger EM cluster.
Definition: TrigEMCluster_v1.h:28
T2CaloEgammaReFastAlgo::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: T2CaloEgammaReFastAlgo.cxx:42
LArCellBinning.etamin
etamin
Definition: LArCellBinning.py:137
error
Definition: IImpactPoint3dEstimator.h:70
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
xAOD::TrigEMCluster_v1::energy
float energy() const
get Energy (calibrated)
T2CaloEgammaReFastAlgo::m_l1phi
Gaudi::Property< float > m_l1phi
Definition: T2CaloEgammaReFastAlgo.h:63