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