ATLAS Offline Software
Functions | Variables
Resplot.cxx File Reference
#include <iostream>
#include <sstream>
#include <cmath>
#include "Directory.h"
#include "tagname.h"
#include "Resplot.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TMath.h"
#include "generate.h"
#include "rmsFrac.h"

Go to the source code of this file.

Functions

void binwidth (TH1D *h)
 
void ZeroErrors (TH1D *h)
 
void unZeroErrors (TH1D *h)
 
double getWeights (TH1D *h)
 
double getWeights (TH2D *h)
 
void GetStats (TH1D *h, std::vector< double > &stats)
 
std::string number (const double &x)
 
double NCounter (TH1D *h)
 
double FindMean (TH1D *s, double frac=0.95)
 
int findmax (TH1D *s)
 
Double_t langaufun (Double_t *x_par, Double_t *par)
 

Variables

int nexperiments_ = 0
 
int nexperiments_max = 40
 
int nexperiments_min = 20
 

Detailed Description


Author
M.Sutton
Date
Mon Jun 21 18:35:22 BST 2004

Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration

Definition in file Resplot.cxx.

Function Documentation

◆ binwidth()

void binwidth ( TH1D h)

Definition at line 50 of file Resplot.cxx.

50  {
51 
52  for (int i=1 ; i<=h->GetNbinsX() ; i++ ) {
53  double d = h->GetBinLowEdge(i+1) - h->GetBinLowEdge(i);
54 
55  h->SetBinContent(i, h->GetBinContent(i)/d );
56  h->SetBinError(i, h->GetBinError(i)/d );
57  }
58 
59 }

◆ findmax()

int findmax ( TH1D s)

find maximum bin

Definition at line 1396 of file Resplot.cxx.

1396  {
1397  int imax = 1;
1398  for ( int i=2 ; i<=s->GetNbinsX() ; i++ ) {
1400  if ( s->GetBinContent(i)>s->GetBinContent(imax) ) imax = i;
1401  }
1402  return imax;
1403 }

◆ FindMean()

double FindMean ( TH1D s,
double  frac = 0.95 
)

Definition at line 1309 of file Resplot.cxx.

1309  {
1310 
1311  // double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1312  double entries = generate::GetEntries(s,0,s->GetNbinsX()+1);
1313 
1314  // std::cout << s->GetName() << "\tentries: " << entries << std::endl;
1315 
1316  if ( entries==0 ) return 0;
1317 
1318  // s->GetXaxis()->SetRangeUser(-100, 100);
1319  // s->GetXaxis()->UnZoom();
1320  s->GetXaxis()->SetRange(1,s->GetNbinsX());
1321 
1322  double mean = s->GetMean();
1323  double meane = s->GetMeanError();
1324 
1325  int upperbin = 0;
1326  int lowerbin = 0;
1327 
1328 
1329  for ( int it=0 ; it<20 ; it++ ) {
1330 
1331  // std::cout << it << "\tmean " << mean << " +- " << meane << std::endl;
1332 
1333  int imax = s->GetXaxis()->FindBin(mean);
1334 
1335  double sumn = s->GetBinContent(imax);
1336 
1337  // double uppersum = 0;
1338  // double lowersum = 0;
1339 
1340  upperbin = imax;
1341  lowerbin = imax;
1342 
1343 
1344  int i=1;
1345  while ( true ) {
1346 
1347  const int upperbin_i = imax+i;
1348  const int lowerbin_i = imax-i;
1349 
1350  if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1351 
1352  double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1353 
1354  if ( tsum>entries*frac ) {
1355  // uppersum = tsum/entries;
1356  break;
1357  }
1358 
1359  // lowersum = tsum/entries;
1360 
1361  sumn = tsum;
1362 
1363  upperbin = upperbin_i;
1364  lowerbin = lowerbin_i;
1365 
1366  i++;
1367  }
1368 
1369  s->GetXaxis()->SetRange(lowerbin, upperbin);
1370 
1371  double m = s->GetMean();
1372  double me = s->GetMeanError();
1373 
1374  if ( it>0 ) {
1375  if ( mean==m ||
1376  std::fabs(mean-m)<me*1e-5 ||
1377  std::fabs(mean-m)<meane*1e-5 ) {
1378  mean = m;
1379  meane = me;
1380  break;
1381  }
1382  }
1383 
1384  mean = m;
1385  meane = me;
1386 
1387  }
1388 
1389  // std::cout << "mean " << mean << " +- " << meane << "\tentries: " << generate::GetEntries(s) << "\tlower " << lowerbin << " - " << upperbin << std::endl;
1390 
1391 
1392  return mean;
1393 }

◆ GetStats()

void GetStats ( TH1D h,
std::vector< double > &  stats 
)

Definition at line 113 of file Resplot.cxx.

113  {
114 
115  stats.clear();
116  stats.resize(4);
117 
118  TAxis& fXaxis = *h->GetXaxis();
119 
120  double s = 0;
121  double sx = 0;
122  double sx2 = 0;
123  double sx4 = 0;
124 
125 
126  // if ( fXaxis.TestBit(TAxis::kAxisRange) ) {
127  // for (bin=0;bin<4;bin++) stats[bin] = 0;
128 
129  Int_t firstBinX = fXaxis.GetFirst();
130  Int_t lastBinX = fXaxis.GetLast();
131  // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
132  // if (fgStatOverflows && !fXaxis.TestBit(TAxis::kAxisRange)) {
133  // if (firstBinX == 1) firstBinX = 0;
134  // if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
135  // }
136  for (int binx = firstBinX; binx <= lastBinX; binx++) {
137  double x = fXaxis.GetBinCenter(binx);
138  double w = TMath::Abs(h->GetBinContent(binx));
139  // err = TMath::Abs(GetBinError(binx));
140  s += w;
141  // stats[1] += err*err;
142  sx += w*x;
143  sx2 += w*x*x;
144  sx4 += w*x*x*x*x;
145  }
146 
147 
148  double mu = sx/s;
149 
150  double v = sx2/s-mu*mu;
151 
152  double rms = std::sqrt(v);
153  double rmserror = std::sqrt(0.25*(sx4/v-v*s))/s;
154  // double rmserror1 = std::sqrt(0.4*(sx4/s-v*v)/s); << is this the correct one? it seems about 2* too large
155 
156  stats[0] = mu;
157  stats[1] = std::sqrt(v/s);
158 
159  stats[2] = rms;
160  stats[3] = rmserror;
161 
162  // double duff = std::sqrt(0.5*v/s);
163 
164 #if 0
165  std::cout << "GetStats() "
166  // << "\tmean " << stats[0] << " +- " << stats[1]
167  << "\trms " << stats[2] << " +- " << stats[3] << "\t(" << rmserror1 << ")" << "\t root " << duff << std::endl;
168 #endif
169 
170 }

◆ getWeights() [1/2]

double getWeights ( TH1D h)

Definition at line 79 of file Resplot.cxx.

79  {
80  double sum = 0;
81  double sume2 = 0;
82  for ( int i=0 ; i<h->GetNbinsX()+1 ; i++ ) {
83  sum += h->GetBinContent(i);
84  sume2 += h->GetBinError(i)*h->GetBinError(i);
85  }
86  if ( sume2!=0 ) return sum*sum/sume2;
87  return 0;
88 }

◆ getWeights() [2/2]

double getWeights ( TH2D h)

Definition at line 91 of file Resplot.cxx.

91  {
92 
93  double sum = 0;
94  double sume2 = 0;
95 
96  for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
97  for ( int j=1 ; j<=h->GetNbinsY() ; j++ ) {
98  sum += h->GetBinContent(i,j);
99  sume2 += h->GetBinError(i,j)*h->GetBinError(i,j);
100  }
101  }
102 
103  if ( sume2!=0 ) return sum*sum/sume2;
104 
105  return 0;
106 }

◆ langaufun()

Double_t langaufun ( Double_t *  x_par,
Double_t *  par 
)

Definition at line 2018 of file Resplot.cxx.

2018  {
2019 
2020  //Fit parameters:
2021  //par[0]=Total area (integral -inf to inf, normalization constant)
2022  //par[1]=Most Probable (MP, location) parameter of Landau density
2023  //par[2]=Width (scale) parameter of Landau density
2024  //par[3]=Width (sigma) of convoluted Gaussian function
2025  //
2026  //In the Landau distribution (represented by the CERNLIB approximation),
2027  //the maximum is located at x=-0.22278298 with the location parameter=0.
2028  //This shift is corrected within this function, so that the actual
2029  //maximum is identical to the MP parameter.
2030 
2031  // Numeric constants
2032  Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
2033  Double_t mpshift = -0.22278298; // Landau maximum location
2034 
2035  // Control constants
2036  Double_t np = 500; // number of convolution steps
2037  Double_t sc = 5; // convolution extends to +-sc Gaussian sigmas
2038 
2039  double& x = x_par[0];
2040 
2041  // Variables
2042  Double_t xx;
2043  Double_t mpc;
2044  Double_t fland;
2045  Double_t sum = 0.0;
2046  Double_t xlow,xupp;
2047  Double_t step;
2048  Double_t i;
2049 
2050  // if ( par[2]<0.1*par[3] ) return 0;
2051 
2052  // correct the most probable bin position as described above
2053  mpc = par[1] - mpshift*par[2];
2054 
2055  // Range of convolution integral
2056 
2057  // if ( par[3]<par[2] ) np = np*par[2]/par[3];
2058 
2059  xlow = x - sc * par[3];
2060  xupp = x + sc * par[3];
2061 
2062  step = (xupp-xlow) / np;
2063 
2064  // Convolution integral of Landau and Gaussian by sum
2065  for(i=1.0; i<=np/2; i++) {
2066  xx = xlow + (i-0.5)*step;
2067  fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2068  sum += fland * TMath::Gaus(x,xx,par[3]);
2069 
2070  xx = xupp - (i-0.5)*step;
2071  fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2072  sum += fland * TMath::Gaus(x,xx,par[3]);
2073  }
2074 
2075  return (par[0] * step * sum * invsq2pi / par[3]);
2076 }

◆ NCounter()

double NCounter ( TH1D h)

Definition at line 380 of file Resplot.cxx.

380  {
381  double N=0;
382  for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) N += h->GetBinContent(i);
383  return N;
384 }

◆ number()

std::string number ( const double &  x)

Definition at line 373 of file Resplot.cxx.

373  {
374  std::ostringstream s;
375  s << x;
376  return s.str();
377 }

◆ unZeroErrors()

void unZeroErrors ( TH1D h)

Definition at line 73 of file Resplot.cxx.

73  {
74  for (int i=1 ; i<=h->GetNbinsX() ; i++ ) if (h->GetBinContent(i)==0) h->SetBinError(i,0);
75 }

◆ ZeroErrors()

void ZeroErrors ( TH1D h)

Definition at line 67 of file Resplot.cxx.

67  {
68  for (int i=1 ; i<=h->GetNbinsX() ; i++ ) if (h->GetBinContent(i)==0) h->SetBinError(i,1);
69 }

Variable Documentation

◆ nexperiments_

int nexperiments_ = 0

Definition at line 1681 of file Resplot.cxx.

◆ nexperiments_max

int nexperiments_max = 40

Definition at line 1682 of file Resplot.cxx.

◆ nexperiments_min

int nexperiments_min = 20

Definition at line 1683 of file Resplot.cxx.

python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:254
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
hist_file_dump.d
d
Definition: hist_file_dump.py:137
python.compressB64.sx
string sx
Definition: compressB64.py:96
skel.it
it
Definition: skel.GENtoEVGEN.py:423
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
PlotPulseshapeFromCool.np
np
Definition: PlotPulseshapeFromCool.py:64
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
x
#define x
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:92
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:256
imax
int imax(int i, int j)
Definition: TileLaserTimingTool.cxx:33
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
python.PyAthena.v
v
Definition: PyAthena.py:157
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
fitman.sx2
sx2
Definition: fitman.py:537
h
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
entries
double entries
Definition: listroot.cxx:49
LArCellBinning.step
step
Definition: LArCellBinning.py:158
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53