ATLAS Offline Software
BichselData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
5  #include "BichselData.h"
6  #include <cmath> //for pow
7  #include <algorithm> //for std::clamp
8 
9 
10 
11 double
13  if (not logBetaGammaVector.empty()){
14  return logBetaGammaVector.back();
15  } else {
16  return std::numeric_limits<double>::quiet_NaN();
17  }
18 }
19 
20 
21 void
22 BichselData::addNewLogBetaGamma(double logBetaGamma){
23 
24  if (not empty()) {
26  }
27  logBetaGammaVector.push_back(logBetaGamma);
28  //insert empty arrays
29  logCollisionEnergyVectorOfVector.emplace_back();
31 }
32 
33 void
34 BichselData::addEntry(double logBetaGamma, double logCollisionEnergy, double logIntegratedCrossSection){
35  if (empty() or (lastBetaGammaValue() != logBetaGamma)) { // a new BetaGamma
36  addNewLogBetaGamma(logBetaGamma);
37  }
38  logCollisionEnergyVectorOfVector.back().push_back(logCollisionEnergy);
39  logIntegratedCrossSectionsVectorOfVector.back().push_back(logIntegratedCrossSection);
40 }
41 
44 }
45 
46 
47  //=======================================
48 // B E T A G A M M A I N D E X
49 //=======================================
50 std::pair<int, int>
51 BichselData::getBetaGammaIndices(double BetaGammaLog10) const {
52  std::pair<int, int> indices_BetaGammaLog10;
53  if (empty()) return {-1,-1};
54  if (BetaGammaLog10 > logBetaGammaVector.back()) { // last one is used because when beta-gamma is very large,
55  // energy deposition behavior is very similar
56  indices_BetaGammaLog10.first = logBetaGammaVector.size() - 1;
57  indices_BetaGammaLog10.second = logBetaGammaVector.size() - 1;
58  } else {
59  indices_BetaGammaLog10 =PixelDigitization::fastSearch(logBetaGammaVector, BetaGammaLog10);
60  }
61 
62  return indices_BetaGammaLog10;
63 }
64 
65 
66 
67 
68 //==========================================
69 // G E T C O L L I S I O N E N E R G Y
70 //==========================================
71 //Interpolate collision energy
72 double
73 BichselData::interpolateCollisionEnergy(std::pair<int, int> indices_BetaGammaLog10, double IntXLog10) const {
74  if ((indices_BetaGammaLog10.first == -1) && (indices_BetaGammaLog10.second == -1)) return -1.;
75  if (empty()) return -1.;
76 
77 
78  // BetaGammaLog10_2 then
79  std::pair<int, int> indices_IntXLog10_x2 =
80  PixelDigitization::fastSearch(logIntegratedCrossSectionsVectorOfVector[indices_BetaGammaLog10.second], IntXLog10);
81  if (indices_IntXLog10_x2.first < 0) {
82  return -1;
83  }
84  if (indices_IntXLog10_x2.second < 0) {
85  return -1;
86  }
87 
88  double y21 = logIntegratedCrossSectionsVectorOfVector.at(indices_BetaGammaLog10.second).at(indices_IntXLog10_x2.first);
89  double y22 = logIntegratedCrossSectionsVectorOfVector.at(indices_BetaGammaLog10.second).at(indices_IntXLog10_x2.second);
90  const auto diff = y22 - y21;
91  if (diff<1e-300){
92  //these are the same value
93  return -1;
94  }
95  double Est_x2 =
96  ((y22 - IntXLog10) *
97  logCollisionEnergyVectorOfVector[indices_BetaGammaLog10.second][indices_IntXLog10_x2.first] +
98  (IntXLog10 - y21) *
99  logCollisionEnergyVectorOfVector[indices_BetaGammaLog10.second][indices_IntXLog10_x2.second]) / diff;
100  double Est = std::clamp(Est_x2,-300.,300.);
101  return std::pow(10., Est);
102 }
103 
104 //===========================================
105 // Overloaded C O L L I S I O N E N E R G Y
106 //===========================================
107 double
108 BichselData::interpolateCollisionEnergy(double BetaGammaLog10, double IntXLog10) const {
109  std::pair<int, int> indices_BetaGammaLog10 = getBetaGammaIndices(BetaGammaLog10);
110  return interpolateCollisionEnergy(indices_BetaGammaLog10, IntXLog10);
111 }
112 
113 //==========================================
114 // G E T U P P E R B O U N D BETA GAMMA
115 //==========================================
116 double
117 BichselData::interpolateCrossSection(std::pair<int, int> indices_BetaGammaLog10, double BetaGammaLog10) const {
118  if (empty()) return -1;
119  if (indices_BetaGammaLog10.first < 0) {
120  return -1;
121  }
122  if (indices_BetaGammaLog10.second < 0) {
123  return -1;
124  }
125  if (indices_BetaGammaLog10.second == indices_BetaGammaLog10.first){ //either an exact value or the last one in the table
126  return std::pow(10., logHighestCrossSectionsVector.at(indices_BetaGammaLog10.first));
127  }
128  double BetaGammaLog10_1 = logBetaGammaVector.at(indices_BetaGammaLog10.first);
129  double BetaGammaLog10_2 = logBetaGammaVector.at(indices_BetaGammaLog10.second);
130 
131  // obtain estimation
132  double Est_1 = logHighestCrossSectionsVector.at(indices_BetaGammaLog10.first);
133  double Est_2 = logHighestCrossSectionsVector.at(indices_BetaGammaLog10.second);
134 
135  // final estimation
136  const auto diff=BetaGammaLog10_2 - BetaGammaLog10_1;
137  if (diff<1e-300){
138  return -1;
139  }
140  double Est = ((BetaGammaLog10_2 - BetaGammaLog10) * Est_1 + (BetaGammaLog10 - BetaGammaLog10_1) * Est_2) /diff;
141  Est = std::clamp(Est,-300.,300.);
142  return std::pow(10., Est);
143 
144 
145 }
146 //==========================================
147 // overloaded G E T U P P E R B O U N D
148 //==========================================
149 double
150 BichselData::interpolateCrossSection(double BetaGammaLog10) const {
151  std::pair<int, int> indices_BetaGammaLog10 = getBetaGammaIndices(BetaGammaLog10);
152  return interpolateCrossSection(indices_BetaGammaLog10, BetaGammaLog10);
153 }
154 
155 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
BichselData::interpolateCrossSection
double interpolateCrossSection(std::pair< int, int > indices_BetaGammaLog10, double BetaGammaLog10) const
Definition: BichselData.cxx:117
BichselData::getBetaGammaIndices
std::pair< int, int > getBetaGammaIndices(double BetaGammaLog10) const
Definition: BichselData.cxx:51
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
BichselData::addEntry
void addEntry(double logBetaGamma, double logCollisionEnergy, double logIntegratedCrossSection)
Definition: BichselData.cxx:34
BichselData::logBetaGammaVector
std::vector< double > logBetaGammaVector
Definition: BichselData.h:16
BichselData::updateAfterLastEntry
void updateAfterLastEntry()
Definition: BichselData.cxx:42
BichselData.h
BichselData::interpolateCollisionEnergy
double interpolateCollisionEnergy(std::pair< int, int > indices_BetaGammaLog10, double IntXLog10) const
Definition: BichselData.cxx:73
BichselData::logHighestCrossSectionsVector
std::vector< double > logHighestCrossSectionsVector
Definition: BichselData.h:19
BichselData::addNewLogBetaGamma
void addNewLogBetaGamma(double logBetaGamma)
Definition: BichselData.cxx:22
BichselData::logCollisionEnergyVectorOfVector
std::vector< std::vector< double > > logCollisionEnergyVectorOfVector
Definition: BichselData.h:17
BichselData::empty
bool empty() const
Definition: BichselData.h:22
PixelDigitization::fastSearch
std::pair< int, int > fastSearch(const std::vector< double > &vec, double item)
Definition: PixelDigitizationUtilities.cxx:73
BichselData::lastBetaGammaValue
double lastBetaGammaValue() const
Definition: BichselData.cxx:12
PixelDigitizationUtilities.h
BichselData::logIntegratedCrossSectionsVectorOfVector
std::vector< std::vector< double > > logIntegratedCrossSectionsVectorOfVector
Definition: BichselData.h:18
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15