ATLAS Offline Software
Loading...
Searching...
No Matches
CaloSwEtaoff_v2.cxx
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4*/
11
12
13#include "CaloSwEtaoff_v2.h"
17#include <cmath>
18#include <cassert>
19
20
23
24
46 CaloCluster* cluster,
47 const CaloDetDescrElement* elt,
48 float eta,
49 float adj_eta,
50 float /*phi*/,
51 float /*adj_phi*/,
52 CaloSampling::CaloSample samp) const
53{
54 const CxxUtils::Array<3> correction = m_correction (myctx);
55 const CxxUtils::Array<1> interp_barriers = m_interp_barriers (myctx);
56 const CxxUtils::Array<1> energies = m_energies (myctx);
57 const int degree = m_degree (myctx);
58 const int energy_degree = m_energy_degree (myctx);
59
60 // Find u, the normalized displacement of the cluster within the cell.
61 // In the range -1...1, with 0 at the center.
62 float u = (eta - elt->eta()) / elt->deta() * 2;
63 if (elt->eta_raw() < 0)
64 u = -u;
65
66 // u can sometimes be outside of the prescribed range, due to DD bugs.
67 if (u > 1)
68 u = 1;
69 else if (u < -1)
70 u = -1;
71
72 // For each energy, interpolate in eta.
73 // We can't use the common energy_interpolation code here,
74 // because we're interpolating the fit parameters, not the overall
75 // correction. This should probably be done differently in the
76 // next version.
77 unsigned int n_energies = energies.size();
78 unsigned int shape[] = {n_energies, 4};
79 CaloRec::WritableArrayData<2> partab (shape);
80 if (n_energies == 0) {
81 ATH_MSG_ERROR("Empty energies vector");
82 return;
83 }
84
85 // If we're outside the range of the table, we'll just be using the
86 // value at the end (no extrapolation). We only need to calculate
87 // that one point in that case.
88 int beg = 0;
89 int end = n_energies;
90 float energy = cluster->e();
91 if (energy <= energies[0])
92 end = 1;
93 else if (energy >= energies[n_energies-1])
94 beg = n_energies-1;
95
96 for (int i=beg; i<end; i++) {
97 partab[i][0] = energies[i];
98 for (int j=0; j < 3; j++)
99 partab[i][j+1] = interpolate (correction[i],
100 std::abs (adj_eta),
101 degree,
102 j+1,
103 interp_barriers);
104 }
105
106 // Now interpolate in energy.
107 // But if we're outside of the range of the table, just use the value
108 // at the end (don't extrapolate).
109 float par[3];
110 for (int i=0; i < 3; i++) {
111 if (end-beg > 1)
112 par[i] = interpolate (partab, energy, energy_degree, i+1);
113 else
114 par[i] = partab[beg][i+1];
115 }
116
117 // Calculate the fit function.
118 // Don't allow b to go all the way to zero; we get a division
119 // by zero there.
120 double b = std::max ((double)par[1], 1e-5);
121 double atanb = std::atan(b);
122 double sq = std::sqrt (b/atanb - 1);
123 double den = (sq/b*atanb - std::atan(sq));
124 float offs = par[0]* ((- std::atan (b*u) + u*atanb) / den +
125 par[2]*(1-std::abs(u)));
126
127 // Apply the offset correction to the cluster.
128 if (eta < 0)
129 offs = -offs;
130 cluster->setEta (samp, eta + offs);
131}
Scalar eta() const
pseudorapidity method
#define ATH_MSG_ERROR(x)
Definition of CaloDetDescrManager.
CaloPhiRange class declaration.
EM calorimeter eta offset (S-shape) corrections.
#define sq(x)
Principal data class for CaloCell clusters.
virtual double e() const
Retrieve energy independent of signal state.
virtual void setEta(double eta)
Set eta.
This class groups all DetDescr information related to a CaloCell.
Constant< CxxUtils::Array< 1 > > m_interp_barriers
Calibration constant: allow breaking up the interpolation into independent regions.
Constant< CxxUtils::Array< 3 > > m_correction
Calibration constant: tabulated arrays of function parameters.
Constant< int > m_degree
Calibration constant: degree of the polynomial interpolation.
Constant< int > m_energy_degree
Calibration constant: degree of the polynomial interpolation in energy.
Constant< CxxUtils::Array< 1 > > m_energies
Calibration constant: table of energies at which the correction was tabulated.
virtual void makeTheCorrection(const Context &myctx, xAOD::CaloCluster *cluster, const CaloDetDescrElement *elt, float eta, float adj_eta, float phi, float adj_phi, CaloSampling::CaloSample samp) const override
Virtual function for the correction-specific code.
Read-only multidimensional array.
unsigned int size(unsigned int dim=0) const
Return the size of the array along one dimension.
Polynomial interpolation in a table.
float interpolate(const CaloRec::Array< 2 > &a, float x, unsigned int degree, unsigned int ycol=1, const CaloRec::Array< 1 > &regions=CaloRec::Array< 1 >(), int n_points=-1, bool fixZero=false)
Polynomial interpolation in a table.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.