Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CaloClusterDetails.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XAODCALOEVENT_CALOCLUSTERDETAILS_H
6 #define XAODCALOEVENT_CALOCLUSTERDETAILS_H
7 
8 #include <CaloGeoHelpers/CaloSampling.h>
9 #include <bit>
10 #include <cstdint>
11 #include <span>
12 
13 namespace xAOD
14 {
15  namespace CaloClusterDetails
16  {
37 
38 
40 
41 
47  constexpr float defaultErrorValue = -999;
48 
49 
51  [[nodiscard]] inline bool hasSampling(const CaloSample s, const std::uint32_t samplingPattern) {
52  return (samplingPattern & (0x1U<<(std::uint32_t)s));
53  }
54 
55 
56  [[nodiscard]] inline unsigned sampVarIdx(const CaloSample s, const std::uint32_t samplingPattern) {
57  //std::cout << "Pattern=" << std::hex << pattern << std::dec << ", Sampling=" << s << std::endl;
58  if ((samplingPattern & (0x1U << s)) == 0) {
59  return CaloSampling::Unknown;
60  }
61  if (s == 0) {
62  return 0;
63  } // shifting a 32-bit int by 32 bits is undefined behavior!
64  return std::popcount(samplingPattern << (32 - s));
65  // Explanation: Need to get the number of bit (=samples) before the sampling in question
66  // Shift to the left, so bits after the sampling in question fall off the 32bit integer
67  // Then use popcount to count the numbers of 1 in the rest
68  }
69 
70 
71  [[nodiscard]] inline float getSamplVar(const CaloSample sampling, const std::uint32_t samplingPattern, const std::span<const float> vec, const float errorvalue=defaultErrorValue) {
72  const unsigned idx=sampVarIdx(sampling, samplingPattern);
73  if (idx<vec.size() ) {
74  return vec[idx];
75  }
76 
77  //std::cout <<Sampling " << sampling << ", Pattern=" << std::hex <<m_samplingPattern << std::dec << ", index=" << idx << " size=" << vec.size() << std::endl;
78  return errorvalue;
79  }
80 
81 
86  [[nodiscard]] inline float energyBE(const unsigned sample, const std::uint32_t samplingPattern, const std::span<const float> e_sampl) {
87  if (sample>3) return defaultErrorValue;
90  double energy=0;
91  if (hasSampling(barrelSample, samplingPattern)) {
92  energy+=getSamplVar(barrelSample,samplingPattern,e_sampl); //Check for errorcode? Should not happen...
93  }
94  if (hasSampling(endcapSample, samplingPattern)) {
95  energy+=getSamplVar(endcapSample,samplingPattern,e_sampl);
96  }
97  return energy;
98  }
99 
100 
101 
106  [[nodiscard]] inline float etaBE(const unsigned sample, const std::uint32_t samplingPattern, const std::span<const float> e_sampl, const std::span<const float> eta_sampl) {
107  if (sample>3) {return defaultErrorValue;}
110  const bool haveBarrel=hasSampling(barrelSample, samplingPattern);
111  const bool haveEndcap=hasSampling(endcapSample, samplingPattern);
112  if (haveBarrel && haveEndcap) {
113  //cluster spans barren and endcap
114  float eBarrel=getSamplVar(barrelSample,samplingPattern,e_sampl); //Check for errorcode? Should not happen...
115  float eEndcap=getSamplVar(endcapSample,samplingPattern,e_sampl);
116 
117  float etaBarrel=getSamplVar(barrelSample,samplingPattern,eta_sampl);
118  float etaEndcap=getSamplVar(endcapSample,samplingPattern,eta_sampl);
119  float eSum=eBarrel + eEndcap;
120  if (eSum > 100 /*MeV*/) {
121  //E-weighted average ...
122  if ((eBarrel > 0 && eEndcap > 0) || (eBarrel < 0 && eEndcap < 0))
123  return (eBarrel * etaBarrel + eEndcap * etaEndcap) / eSum;
124  else if (eBarrel > 0)
125  return etaBarrel;
126  else
127  return etaEndcap;
128  }//else eSum==0 case, should never happen
129  return (0.5 * (etaBarrel + etaEndcap));
130  }
131  if (haveBarrel) {
132  return getSamplVar(barrelSample,samplingPattern,eta_sampl);
133  }
134  if (haveEndcap) {
135  return getSamplVar(endcapSample,samplingPattern,eta_sampl);
136  }
137 
138  //Should never reach this point ...
139  return defaultErrorValue;
140  }
141  }
142 }
143 
144 #endif
xAOD::CaloClusterDetails::hasSampling
bool hasSampling(const CaloSample s, const std::uint32_t samplingPattern)
Checks if certain smapling contributes to cluster.
Definition: CaloClusterDetails.h:51
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
xAOD::CaloClusterDetails::etaBE
float etaBE(const unsigned sample, const std::uint32_t samplingPattern, const std::span< const float > e_sampl, const std::span< const float > eta_sampl)
Get the eta in one layer of the EM Calo.
Definition: CaloClusterDetails.h:106
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
xAOD::CaloClusterDetails::CaloSample
CaloSampling::CaloSample CaloSample
Definition: CaloClusterDetails.h:39
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
xAOD::CaloClusterDetails::energyBE
float energyBE(const unsigned sample, const std::uint32_t samplingPattern, const std::span< const float > e_sampl)
Get the energy in one layer of the EM Calo.
Definition: CaloClusterDetails.h:86
xAOD::CaloClusterDetails::sampVarIdx
unsigned sampVarIdx(const CaloSample s, const std::uint32_t samplingPattern)
Definition: CaloClusterDetails.h:56
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
xAOD::CaloClusterDetails::getSamplVar
float getSamplVar(const CaloSample sampling, const std::uint32_t samplingPattern, const std::span< const float > vec, const float errorvalue=defaultErrorValue)
Definition: CaloClusterDetails.h:71
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
xAOD::CaloClusterDetails::defaultErrorValue
constexpr float defaultErrorValue
the default error code to return in case of error
Definition: CaloClusterDetails.h:47