ATLAS Offline Software
Loading...
Searching...
No Matches
LArCellEmMiscalib.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6/********************************************************************
7
8NAME: LArCellEmMiscalib
9PACKAGE: offline/LArCalorimeter/LArRecUtils
10
11AUTHORS: G.Unal
12CREATED: 25 October 2006
13
14PURPOSE: applies miscalibration in EM calorimeter
15
16********************************************************************/
17#include "LArCellEmMiscalib.h"
23
24#include "CLHEP/Units/SystemOfUnits.h"
25#include <CLHEP/Random/Randomize.h>
26
28
29using CLHEP::RandGauss;
30
31
33// CONSTRUCTOR:
35
37 const std::string& type,
38 const std::string& name,
39 const IInterface* parent)
40 : CaloCellCorrection(type, name, parent),
41 m_larem_id(nullptr),
42 m_seed(1234),
43 m_sigmaPerRegion(0.005),
44 m_sigmaPerCell(0.007),
45 m_undo(false),
46 m_ncellem(0)
47{
48 declareInterface<CaloCellCorrection>(this);
49 declareProperty("Seed", m_seed, "seed : should always be the same");
50 declareProperty("SigmaPerRegion", m_sigmaPerRegion,"smearing per region");
51 declareProperty("SigmaPerCell", m_sigmaPerCell, "smearing per cell ");
52 declareProperty("UndoMisCalib",m_undo,"Apply opposite sign to undo miscalibration");
53}
54
55
57// INITIALIZE:
58// The initialize method will create all the required algorithm objects
60
62{
63 ATH_MSG_INFO( " in LArCellEmMiscalib::initialize()" );
64 ATH_CHECK(m_caloMgrKey.initialize());
65 ATH_CHECK(m_rngSvc.retrieve());
66 return StatusCode::SUCCESS;
67}
68
69void LArCellEmMiscalib::initOnce (const EventContext& ctx) {
70 StatusCode sc;
71 sc=detStore()->retrieve( m_caloIdMgr );
72 sc.ignore();
74 m_calodetdescrmgr = *caloMgrHandle;
75
76 ATHRNG::RNGWrapper* wrapper = m_rngSvc->getEngine (this);
77 wrapper->setSeed (ctx.slot(), m_seed);
78 CLHEP::HepRandomEngine* engine = wrapper->getEngine (ctx);
79
80
81 // computes the smearing per region
82 this->smearingPerRegion (engine);
83
84
85 m_larem_id = m_caloIdMgr->getEM_ID();
86
87 m_ncellem=m_larem_id->channel_hash_max();
88 m_calib.resize(m_ncellem,1.);
89
90 ATH_MSG_DEBUG(" Number of EM cells " << m_ncellem);
91
92 for (unsigned int i=0;i<m_ncellem;i++){
93 IdentifierHash idHash = i;
94 Identifier id = m_larem_id->channel_id(idHash);
95 int barrel_ec = m_larem_id->barrel_ec(id);
96 const CaloDetDescrElement* calodde = m_calodetdescrmgr->get_element(id);
97 double eta = fabs(calodde->eta_raw());
98 double phi = calodde->phi_raw();
99 int iregion= LArCellEmMiscalib::region(barrel_ec,eta,phi);
100 if (iregion>=0) {
101 ATH_MSG_VERBOSE("barrel_ec,eta,phi,region " << barrel_ec << " " << eta << " " << phi << " "
102 << iregion << " " << m_spread1[iregion]);
103 double spread2=m_sigmaPerCell*RandGauss::shoot(engine,0.,1.);
104 m_calib[idHash] = m_spread1[iregion] + spread2;
105 if (m_undo ) {
106 if (m_calib[idHash] >0.) m_calib[idHash]=1./m_calib[idHash];
107 else m_calib[idHash]=1.;
108 }
109 ATH_MSG_VERBOSE(" m_calib " << m_calib[idHash]);
110 }
111 else {
112 ATH_MSG_WARNING( " Cannot find region for cell " << eta << " " << phi );
113 m_calib[idHash]=1.;
114 }
115 }
116
117
118
119}
120
121
122void LArCellEmMiscalib::smearingPerRegion (CLHEP::HepRandomEngine* engine)
123{
124 m_spread1.resize(544,1);
125 for (int i=0;i<544;i++) {
126 m_spread1[i]=1.+m_sigmaPerRegion*RandGauss::shoot(engine,0.,1.);
127 }
128
129 if (msgLvl(MSG::DEBUG)) {
130 for (int i=0;i<544;i++) {
131 int iregion=i;
132 int ieta,iphi,barrelec,ii;
133 if (iregion<128) {
134 barrelec=-1;
135 ii=iregion;
136 }
137 else if (iregion<256) {
138 barrelec=1;
139 ii=iregion-128;
140 }
141 else if (iregion<(256+112)) {
142 barrelec=-2;
143 ii=iregion-256;
144 }
145 else if (iregion<(256+224)) {
146 barrelec=2;
147 ii=iregion-(256+112);
148 }
149 else if (iregion<(256+224+32)) {
150 barrelec=-3;
151 ii=iregion-(256+224);
152 }
153 else {
154 barrelec=3;
155 ii=iregion-(256+224+32);
156 }
157 iphi=ii%16;
158 ieta=ii/16;
159 ATH_MSG_DEBUG( "iregion,barrelec,ieta,iphi,spread " << iregion << " "
160 << barrelec << " " << ieta << " " << iphi << " " << m_spread1[i] );
161 }
162 }//end if msg_lvl(DEBUG)
163
164}
165
167
168int LArCellEmMiscalib::region(int barrelec, double eta, double phi)
169{
170 int iregion=-1;
171 if (phi<0.) phi=phi+2*M_PI;
172 int iphi=(int)(phi*(16./(2*M_PI)));
173 if (iphi>15) iphi=15;
174 if (abs(barrelec)==1) {
175 int ieta=(int)(eta*(1./0.2));
176 if (ieta>7) ieta=7;
177 iregion=16*ieta+iphi;
178 if (barrelec==1) iregion=iregion+128;
179 }
180 if (abs(barrelec)==2) {
181 int ieta;
182 if (eta<1.5) ieta=0;
183 else if(eta<1.6) ieta=1;
184 else if(eta<1.8) ieta=2;
185 else if(eta<2.0) ieta=3;
186 else if(eta<2.1) ieta=4;
187 else if(eta<2.3) ieta=5;
188 else ieta=6;
189 iregion=16*ieta+iphi;
190 if (barrelec==-2) iregion=iregion+256;
191 if (barrelec==2) iregion=iregion+256+112;
192 }
193 if (abs(barrelec)==3) {
194 //int ieta;
195 //if (eta<2.8) ieta=0;
196 //else ieta=1;
197 if (barrelec==-3) iregion=iregion+256+224;
198 if (barrelec==3) iregion=iregion+256+224+32;
199 }
200 return iregion;
201
202}
203
205// PROCESS:
206//
208
209
211 const EventContext& ctx) const
212{
213 LArCellEmMiscalib* thisNC ATLAS_THREAD_SAFE = const_cast<LArCellEmMiscalib*>(this);
214 std::call_once(m_initOnce, &LArCellEmMiscalib::initOnce,thisNC, ctx);
215 float energy = theCell->energy();
216
217 float weight=1;
218
219
220 const CaloDetDescrElement * theDDE = theCell->caloDDE();
221 // Identifier id = theCell->ID();
222
223 //if (m_larem_id->is_lar_em(id)) {
224
225 if (theDDE->getSubCalo()==CaloCell_ID::LAREM) {
226 // IdentifierHash idHash = m_larem_id->channel_hash(id);
227 IdentifierHash idHash = theDDE->calo_hash();
228 if (idHash < m_ncellem) {
229 weight = m_calib[idHash];
230 }
231 else
232 {
233 ATH_MSG_WARNING( "Inconsistent hash value found " << idHash
234 << " >= " << m_ncellem );
235 }
236// if (m_larem_id->phi(id)==0)
237// std::cout << "Barrel_ec,sampl.region,eta,wt " << m_larem_id->barrel_ec(id) <<
238// " " << m_larem_id->sampling(id) << " " << m_larem_id->region(id) << " " <<
239// m_larem_id->eta(id) << " " << weight << std::endl;
240
241 setenergy(theCell,energy*weight);
242
243
244 }
245}
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
static Double_t sc
#define ATLAS_THREAD_SAFE
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
static void setenergy(CaloCell *lar_cell, float energy)
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
double energy() const
get energy (data member)
Definition CaloCell.h:327
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
This class groups all DetDescr information related to a CaloCell.
This is a "hash" representation of an Identifier.
std::vector< float > m_spread1
std::once_flag m_initOnce
LArCellEmMiscalib(const std::string &type, const std::string &name, const IInterface *parent)
static int region(int barrelec, double eta, double phi)
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
const CaloDetDescrManager * m_calodetdescrmgr
void initOnce(const EventContext &ctx)
virtual void MakeCorrection(CaloCell *theCell, const EventContext &ctx) const override
virtual StatusCode initialize() override
Constructor.
std::vector< float > m_calib
const LArEM_ID * m_larem_id
void smearingPerRegion(CLHEP::HepRandomEngine *engine)
ServiceHandle< IAthRNGSvc > m_rngSvc
const CaloIdManager * m_caloIdMgr