ATLAS Offline Software
CaloNoise.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "CxxUtils/trapping_fp.h"
7 #include "boost/multi_array.hpp"
8 #include "TMath.h"
9 #include <cmath>
10 
11 CaloNoise::CaloNoise(const size_t nLArCells,
12  const size_t nLArGains,
13  const size_t nTileCells,
14  const size_t nTileGains,
15  const CaloCell_Base_ID* caloCellId,
16  const NOISETYPE noisetype)
17  : m_caloCellId(caloCellId)
18  , m_noiseType(noisetype)
19 {
20 
21  boost::multi_array_types::extent_gen lar_extent_gen;
22  m_larNoise.resize(lar_extent_gen[nLArGains][nLArCells]);
23  boost::multi_array_types::extent_gen tile_extent_gen;
24  m_tileNoise.resize(tile_extent_gen[nTileGains][nTileCells]);
25 
26  IdentifierHash h1,h2;
29 }
30 
31 void CaloNoise::setTileBlob(const CaloCondBlobFlt* flt, const float lumi) {
33  m_lumi=lumi;
34 }
35 
37  if ( m_tileBlob) delete m_tileBlob;
38 }
39 
40 
41 
42 float CaloNoise::calcSig(const IdentifierHash subHash, const int dbGain, const float e) const {
43 
44  const double sigma1 = m_tileBlob->getData(subHash,dbGain,2);
45  const double sigma2 = m_tileBlob->getData(subHash,dbGain,3);
46  const double ratio = m_tileBlob->getData(subHash,dbGain,4);
47 
48 
49  if((sigma1 == 0. && sigma2 == 0.) || e == 0.) return 0.;
50  if(sigma1 == 0.) return e/sigma2;
51  if((ratio == 0.) || sigma2 == 0.) return e/sigma1;
52  const double x1 = e/sigma1;
53  const double x2 = e/sigma2;
54 
55  constexpr std::array<float,2> valid_range{0.9,7.5};
56  const float wide_gauss_sigma = std::min(std::abs(x1),std::abs(x2));
57  if(wide_gauss_sigma > valid_range[1]) return wide_gauss_sigma;
58 
59  const float narrow_gauss_sigma= std::max(std::abs(x1),std::abs(x2));
60  if(narrow_gauss_sigma < valid_range[0]) return narrow_gauss_sigma;
61 
62 
63  const double y1= TMath::Erf(M_SQRT1_2*x1);
64  const double y2= TMath::Erf(M_SQRT1_2*x2);
65 
66  const double z = ( y1*sigma1 + ratio*y2*sigma2 )/( sigma1 + ratio*sigma2);
67 
68  //return the C.L. probability (with sign!)
69  // return z;
70 
71  // if instead you want to return the sigma-equivalent C.L.
72  // (with sign!) use the following line
73  return M_SQRT2*TMath::ErfInverse(z);
74 }
75 
76 
77 float CaloNoise::getTileEffSigma(const IdentifierHash subHash, const int gain, const float e) const {
78  // Tell clang to optimize assuming that FP exceptions can trap.
79  // Otherwise, it can vectorize the division, which can lead to
80  // spurious division-by-zero traps from unused vector lanes.
82 
83  const unsigned int dbGain = CaloCondUtils::getDbCaloGain(gain);
84  if (!m_tileBlob) {
85  //No data (pilup-noise only): return cached noise
86  return m_tileNoise[dbGain][subHash];
87  }
88 
89  const float sigma=calcSig(subHash,dbGain,e);
90  const float a= (sigma != 0.) ? std::abs(e/sigma) : 0.0;
91 
93  return a;
94  }
95 
96  //Case: Total Noise
97  const float b= m_tileBlob->getData(subHash,dbGain,1);
98  const int objver = m_tileBlob->getObjVersion();
99  float x=0;
100  if(objver==1){
101  //=== Total noise parameterized as
102  //=== Sigma**2 = a**2 + b**2 * Lumi
103  x = std::sqrt( a*a + b*b*m_lumi );
104  }
105  else if (objver==2) {
106  //== parameterization for pedestal = a + b*Lumi
107  x = a+b*m_lumi;
108  }
109  else{
110  throw CaloCond::VersionConflict("CaloNoise::get2dEffSigma ",objver);
111  }
112  return x;
113 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
CXXUTILS_TRAPPING_FP
#define CXXUTILS_TRAPPING_FP
Definition: trapping_fp.h:24
CaloCondBlobDat::getData
T getData(const unsigned int channel, const unsigned int adc, const unsigned int idx) const
Returns a single T belonging to a channel/gain.
Definition: CaloCondBlobDat.h:134
CaloNoise::NOISETYPE
NOISETYPE
Conditions Data Object holding the calorimeter noise per cell and per gain.
Definition: CaloNoise.h:21
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
CaloNoise::~CaloNoise
~CaloNoise()
Definition: CaloNoise.cxx:36
CaloCondBlobFlt
Class for storing a number of floats (Flt) and functions on those.
Definition: CaloCondBlobFlt.h:29
CaloNoise::setTileBlob
void setTileBlob(const CaloCondBlobFlt *flt, const float lumi)
Definition: CaloNoise.cxx:31
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
CaloNoise::calcSig
float calcSig(const IdentifierHash tilehash, const int gain, const float energy) const
Definition: CaloNoise.cxx:42
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
CaloNoise::ELEC
@ ELEC
Definition: CaloNoise.h:21
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
CaloNoise::m_larNoise
boost::multi_array< float, 2 > m_larNoise
Definition: CaloNoise.h:96
x
#define x
CaloNoise::m_tileNoise
boost::multi_array< float, 2 > m_tileNoise
Definition: CaloNoise.h:97
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
CaloNoise::m_noiseType
NOISETYPE m_noiseType
Definition: CaloNoise.h:104
z
#define z
CaloCondBlobBase::getObjVersion
uint16_t getObjVersion() const
Returns the BLOB object version.
Definition: CaloCondBlobBase.h:203
CaloCell_Base_ID::calo_cell_hash_range
void calo_cell_hash_range(const Identifier id, IdentifierHash &caloCellMin, IdentifierHash &caloCellMax) const
to loop on 'global' cell hashes of one sub-calorimeter alone
CaloNoise::m_caloCellId
const CaloCell_Base_ID * m_caloCellId
Definition: CaloNoise.h:93
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
CaloCond::VersionConflict
Thrown if object version in BLOB does not agree with class version.
Definition: Calorimeter/CaloCondBlobObjs/CaloCondBlobObjs/Exception.h:64
CaloNoise::m_lumi
float m_lumi
Definition: CaloNoise.h:103
CaloCondBlobAlgs_fillNoiseFromASCII.flt
flt
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:97
trapping_fp.h
Tell the compiler to optimize assuming that FP may trap.
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CaloNoise.h
CaloNoise::getTileEffSigma
float getTileEffSigma(const IdentifierHash subHash, const int gain, const float e) const
Definition: CaloNoise.cxx:77
CaloCondUtils::getDbCaloGain
static unsigned int getDbCaloGain(int caloGain)
Returns the non-negative gainId to be used with the COOL DB.
Definition: CaloCondUtils.cxx:86
lumiFormat.lumi
lumi
Definition: lumiFormat.py:106
a
TList * a
Definition: liststreamerinfos.cxx:10
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
CaloNoise::m_tileHashOffset
unsigned m_tileHashOffset
Definition: CaloNoise.h:98
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CaloCell_Base_ID
Helper base class for offline cell identifiers.
Definition: CaloCell_Base_ID.h:41
CaloNoise::m_tileBlob
const CaloCondBlobFlt * m_tileBlob
Definition: CaloNoise.h:102
CaloNoise::CaloNoise
CaloNoise()=delete