ATLAS Offline Software
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 
8 NAME: LArCellEmMiscalib
9 PACKAGE: offline/LArCalorimeter/LArRecUtils
10 
11 AUTHORS: G.Unal
12 CREATED: 25 October 2006
13 
14 PURPOSE: 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 
29 using CLHEP::RandGauss;
30 
31 
33 // CONSTRUCTOR:
35 
37  const std::string& type,
38  const std::string& name,
39  const IInterface* 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()" );
65  ATH_CHECK(m_rngSvc.retrieve());
66  return StatusCode::SUCCESS;
67 }
68 
69 void 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 
86 
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);
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 }
121 
122 void 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 
168 int 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 }
LArCellEmMiscalib::m_calodetdescrmgr
const CaloDetDescrManager * m_calodetdescrmgr
Definition: LArCellEmMiscalib.h:60
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
LArEM_ID.h
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
LArCellEmMiscalib::LArCellEmMiscalib
LArCellEmMiscalib(const std::string &type, const std::string &name, const IInterface *parent)
Definition: LArCellEmMiscalib.cxx:36
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloIDHelper::channel_hash_max
size_type channel_hash_max() const
One more than the largest channel (cell) hash code.
LArCellEmMiscalib::initialize
virtual StatusCode initialize() override
Constructor.
Definition: LArCellEmMiscalib.cxx:61
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArCellEmMiscalib::m_rngSvc
ServiceHandle< IAthRNGSvc > m_rngSvc
Definition: LArCellEmMiscalib.h:63
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloIdManager::getEM_ID
const LArEM_ID * getEM_ID(void) const
Definition: CaloIdManager.cxx:80
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
CaloCellCorrection
Definition: CaloCellCorrection.h:51
LArCellEmMiscalib::m_sigmaPerRegion
double m_sigmaPerRegion
Definition: LArCellEmMiscalib.h:66
M_PI
#define M_PI
Definition: ActiveFraction.h:11
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
LArCellEmMiscalib::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArCellEmMiscalib.h:76
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
LArEM_Base_ID::channel_id
Identifier channel_id(const ExpandedIdentifier &exp_id) const
Build a cell identifier from an expanded identifier.
LArCellEmMiscalib::initOnce
void initOnce(const EventContext &ctx)
Definition: LArCellEmMiscalib.cxx:69
LArCellEmMiscalib::m_larem_id
const LArEM_ID * m_larem_id
Definition: LArCellEmMiscalib.h:58
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CaloDetDescrElement::eta_raw
float eta_raw() const
cell eta_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:350
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloCell::energy
double energy() const
get energy (data member)
Definition: CaloCell.h:311
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
CaloDetDescrElement::getSubCalo
CaloCell_ID::SUBCALO getSubCalo() const
cell subcalo
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:433
CaloDetDescrElement::calo_hash
IdentifierHash calo_hash() const
cell calo hash
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:412
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArCellEmMiscalib.h
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
LArCellEmMiscalib::m_calib
std::vector< float > m_calib
Definition: LArCellEmMiscalib.h:72
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
LArCellEmMiscalib::m_ncellem
unsigned int m_ncellem
Definition: LArCellEmMiscalib.h:70
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArCellEmMiscalib::m_caloIdMgr
const CaloIdManager * m_caloIdMgr
Definition: LArCellEmMiscalib.h:59
LArCellEmMiscalib::smearingPerRegion
void smearingPerRegion(CLHEP::HepRandomEngine *engine)
Definition: LArCellEmMiscalib.cxx:122
LArCellEmMiscalib::region
static int region(int barrelec, double eta, double phi)
Definition: LArCellEmMiscalib.cxx:168
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
LArEM_Base_ID::barrel_ec
int barrel_ec(const Identifier id) const
return barrel_ec according to :
LArCellEmMiscalib::m_undo
bool m_undo
Definition: LArCellEmMiscalib.h:68
LArCellEmMiscalib::m_spread1
std::vector< float > m_spread1
Definition: LArCellEmMiscalib.h:71
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCellContainer.h
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
LArCellEmMiscalib::m_sigmaPerCell
double m_sigmaPerCell
Definition: LArCellEmMiscalib.h:67
LArCellEmMiscalib::m_initOnce
std::once_flag m_initOnce
Definition: LArCellEmMiscalib.h:74
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloCellCorrection::setenergy
static void setenergy(CaloCell *lar_cell, float energy)
Definition: CaloCellCorrection.cxx:89
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
CaloIdManager.h
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
IdentifierHash
Definition: IdentifierHash.h:38
CaloCell_Base_ID::LAREM
@ LAREM
Definition: CaloCell_Base_ID.h:46
LArCellEmMiscalib
Apply miscalibration in EM calorimeter at cell level.
Definition: LArCellEmMiscalib.h:37
LArCellEmMiscalib::MakeCorrection
virtual void MakeCorrection(CaloCell *theCell, const EventContext &ctx) const override
Definition: LArCellEmMiscalib.cxx:210
LArCellEmMiscalib::m_seed
int m_seed
Definition: LArCellEmMiscalib.h:65
CaloDetDescrElement::phi_raw
float phi_raw() const
cell phi_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:352