ATLAS Offline Software
Reconstruction/PanTau/PanTauAlgs/Root/HelperFunctions.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "Math/SpecFuncMathMore.h"
8 #include "TMath.h"
9 #include "TLorentzVector.h"
10 #include "TVector3.h"
11 #include <vector>
12 #include <sstream>
13 #include <cmath>
14 
16  std::stringstream tmpStream;
17  tmpStream << x;
18  return tmpStream.str();
19 }
20 
21 
22 int PanTau::HelperFunctions::getBinIndex(const std::vector<double>& binEdges, double value) const {
23  int resBin = -1;
24  for(unsigned int i=0; i<binEdges.size()-1; i++) {
25  double lowerEdge = binEdges[i];
26  double upperEdge = binEdges[i+1];
27  if(lowerEdge <= value && value < upperEdge) resBin = i;
28  }
29  if(resBin == -1) {
30  ATH_MSG_WARNING("Could not find matching bin for value " << value << " in these bin edges:");
31  for(unsigned int i=0; i<binEdges.size(); i++) ATH_MSG_WARNING("\tbin edge " << i << ": " << binEdges[i]);
32  }
33  return resBin;
34 }
35 
36 
37 double PanTau::HelperFunctions::stddev(double sumOfSquares, double sumOfValues, int numConsts) const {
38  // calculate standard deviations according to:
39  // sigma^2 = (sum_i x_i^2) / N - ((sum_i x_i)/N)^2 (biased maximum-likelihood estimate)
40  // directly set sigma^2 to 0 in case of N=1, otherwise numerical effects may yield very small negative sigma^2
41  if(numConsts == 1) return 0;
42  double a = sumOfSquares / (static_cast<double>(numConsts));
43  double b = sumOfValues / (static_cast<double>(numConsts));
44  double stdDev = a - b*b;
45  if(stdDev < 0.) stdDev = 0;
46  return std::sqrt(stdDev);
47 }
48 
HelperFunctions.h
athena.value
value
Definition: athena.py:124
x
#define x
TauConstituent.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
PanTau::HelperFunctions::getBinIndex
virtual int getBinIndex(const std::vector< double > &binEdges, double value) const
Definition: Reconstruction/PanTau/PanTauAlgs/Root/HelperFunctions.cxx:22
PanTau::HelperFunctions::convertNumberToString
virtual std::string convertNumberToString(double x) const
Definition: Reconstruction/PanTau/PanTauAlgs/Root/HelperFunctions.cxx:15
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
a
TList * a
Definition: liststreamerinfos.cxx:10
PanTau::HelperFunctions::stddev
virtual double stddev(double sumOfSquares, double sumOfValues, int numConsts) const
Definition: Reconstruction/PanTau/PanTauAlgs/Root/HelperFunctions.cxx:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32