ATLAS Offline Software
Loading...
Searching...
No Matches
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
7#include "boost/multi_array.hpp"
8#include "TMath.h"
9#include <cmath>
10
11CaloNoise::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;
27 m_caloCellId->calo_cell_hash_range(CaloCell_ID::TILE, h1,h2);
29}
30
31void CaloNoise::setTileBlob(const CaloCondBlobFlt* flt, const float lumi) {
32 m_tileBlob=flt;
33 m_lumi=lumi;
34}
35
39
40
41
42float 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
77float 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}
static Double_t a
#define x
#define z
Helper base class for offline cell identifiers.
Class for storing a number of floats (Flt) and functions on those.
static unsigned int getDbCaloGain(int caloGain)
Returns the non-negative gainId to be used with the COOL DB.
Thrown if object version in BLOB does not agree with class version.
float calcSig(const IdentifierHash tilehash, const int gain, const float energy) const
Definition CaloNoise.cxx:42
const CaloCondBlobFlt * m_tileBlob
Definition CaloNoise.h:102
boost::multi_array< float, 2 > m_tileNoise
Definition CaloNoise.h:97
const CaloCell_Base_ID * m_caloCellId
Definition CaloNoise.h:93
boost::multi_array< float, 2 > m_larNoise
Definition CaloNoise.h:96
unsigned m_tileHashOffset
Definition CaloNoise.h:98
float m_lumi
Definition CaloNoise.h:103
float getTileEffSigma(const IdentifierHash subHash, const int gain, const float e) const
Definition CaloNoise.cxx:77
NOISETYPE m_noiseType
Definition CaloNoise.h:104
CaloNoise()=delete
void setTileBlob(const CaloCondBlobFlt *flt, const float lumi)
Definition CaloNoise.cxx:31
NOISETYPE
Conditions Data Object holding the calorimeter noise per cell and per gain.
Definition CaloNoise.h:21
This is a "hash" representation of an Identifier.
Tell the compiler to optimize assuming that FP may trap.
#define CXXUTILS_TRAPPING_FP
Definition trapping_fp.h:24