ATLAS Offline Software
Loading...
Searching...
No Matches
Resplot.cxx File Reference
#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-2026 CERN for the benefit of the ATLAS collaboration

Definition in file Resplot.cxx.

Function Documentation

◆ binwidth()

void binwidth ( TH1D * h)

Definition at line 49 of file Resplot.cxx.

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

◆ findmax()

int findmax ( TH1D * s)

find maximum bin

Definition at line 1375 of file Resplot.cxx.

1375 {
1376 int imax = 1;
1377 for ( int i=2 ; i<=s->GetNbinsX() ; i++ ) {
1379 if ( s->GetBinContent(i)>s->GetBinContent(imax) ) imax = i;
1380 }
1381 return imax;
1382}
int imax(int i, int j)

◆ FindMean()

double FindMean ( TH1D * s,
double frac = 0.95 )

Definition at line 1288 of file Resplot.cxx.

1288 {
1289
1290 // double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1291 double entries = generate::GetEntries(s,0,s->GetNbinsX()+1);
1292
1293 // std::cout << s->GetName() << "\tentries: " << entries << std::endl;
1294
1295 if ( entries==0 ) return 0;
1296
1297 // s->GetXaxis()->SetRangeUser(-100, 100);
1298 // s->GetXaxis()->UnZoom();
1299 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1300
1301 double mean = s->GetMean();
1302 double meane = s->GetMeanError();
1303
1304 int upperbin = 0;
1305 int lowerbin = 0;
1306
1307
1308 for ( int it=0 ; it<20 ; it++ ) {
1309
1310 // std::cout << it << "\tmean " << mean << " +- " << meane << std::endl;
1311
1312 int imax = s->GetXaxis()->FindBin(mean);
1313
1314 double sumn = s->GetBinContent(imax);
1315
1316 // double uppersum = 0;
1317 // double lowersum = 0;
1318
1319 upperbin = imax;
1320 lowerbin = imax;
1321
1322
1323 int i=1;
1324 while ( true ) {
1325
1326 const int upperbin_i = imax+i;
1327 const int lowerbin_i = imax-i;
1328
1329 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1330
1331 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1332
1333 if ( tsum>entries*frac ) {
1334 // uppersum = tsum/entries;
1335 break;
1336 }
1337
1338 // lowersum = tsum/entries;
1339
1340 sumn = tsum;
1341
1342 upperbin = upperbin_i;
1343 lowerbin = lowerbin_i;
1344
1345 i++;
1346 }
1347
1348 s->GetXaxis()->SetRange(lowerbin, upperbin);
1349
1350 double m = s->GetMean();
1351 double me = s->GetMeanError();
1352
1353 if ( it>0 ) {
1354 if ( mean==m ||
1355 std::fabs(mean-m)<me*1e-5 ||
1356 std::fabs(mean-m)<meane*1e-5 ) {
1357 mean = m;
1358 meane = me;
1359 break;
1360 }
1361 }
1362
1363 mean = m;
1364 meane = me;
1365
1366 }
1367
1368 // std::cout << "mean " << mean << " +- " << meane << "\tentries: " << generate::GetEntries(s) << "\tlower " << lowerbin << " - " << upperbin << std::endl;
1369
1370
1371 return mean;
1372}
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="")
double entries
Definition listroot.cxx:49
double GetEntries(TH1D *h, int ilow, int ihi)
Definition rmsFrac.cxx:20

◆ GetStats()

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

Definition at line 112 of file Resplot.cxx.

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

◆ getWeights() [1/2]

double getWeights ( TH1D * h)

Definition at line 78 of file Resplot.cxx.

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

◆ getWeights() [2/2]

double getWeights ( TH2D * h)

Definition at line 90 of file Resplot.cxx.

90 {
91
92 double sum = 0;
93 double sume2 = 0;
94
95 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
96 for ( int j=1 ; j<=h->GetNbinsY() ; j++ ) {
97 sum += h->GetBinContent(i,j);
98 sume2 += h->GetBinError(i,j)*h->GetBinError(i,j);
99 }
100 }
101
102 if ( sume2!=0 ) return sum*sum/sume2;
103
104 return 0;
105}
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ langaufun()

Double_t langaufun ( Double_t * x_par,
Double_t * par )

Definition at line 1997 of file Resplot.cxx.

1997 {
1998
1999 //Fit parameters:
2000 //par[0]=Total area (integral -inf to inf, normalization constant)
2001 //par[1]=Most Probable (MP, location) parameter of Landau density
2002 //par[2]=Width (scale) parameter of Landau density
2003 //par[3]=Width (sigma) of convoluted Gaussian function
2004 //
2005 //In the Landau distribution (represented by the CERNLIB approximation),
2006 //the maximum is located at x=-0.22278298 with the location parameter=0.
2007 //This shift is corrected within this function, so that the actual
2008 //maximum is identical to the MP parameter.
2009
2010 // Numeric constants
2011 Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
2012 Double_t mpshift = -0.22278298; // Landau maximum location
2013
2014 // Control constants
2015 Double_t np = 500; // number of convolution steps
2016 Double_t sc = 5; // convolution extends to +-sc Gaussian sigmas
2017
2018 double& x = x_par[0];
2019
2020 // Variables
2021 Double_t xx;
2022 Double_t mpc;
2023 Double_t fland;
2024 Double_t sum = 0.0;
2025 Double_t xlow,xupp;
2026 Double_t step;
2027 Double_t i;
2028
2029 // if ( par[2]<0.1*par[3] ) return 0;
2030
2031 // correct the most probable bin position as described above
2032 mpc = par[1] - mpshift*par[2];
2033
2034 // Range of convolution integral
2035
2036 // if ( par[3]<par[2] ) np = np*par[2]/par[3];
2037
2038 xlow = x - sc * par[3];
2039 xupp = x + sc * par[3];
2040
2041 step = (xupp-xlow) / np;
2042
2043 // Convolution integral of Landau and Gaussian by sum
2044 for(i=1.0; i<=np/2; i++) {
2045 xx = xlow + (i-0.5)*step;
2046 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2047 sum += fland * TMath::Gaus(x,xx,par[3]);
2048
2049 xx = xupp - (i-0.5)*step;
2050 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
2051 sum += fland * TMath::Gaus(x,xx,par[3]);
2052 }
2053
2054 return (par[0] * step * sum * invsq2pi / par[3]);
2055}
static Double_t sc

◆ NCounter()

double NCounter ( TH1D * h)

Definition at line 381 of file Resplot.cxx.

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

◆ number()

std::string number ( const double & x)

Definition at line 374 of file Resplot.cxx.

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

◆ unZeroErrors()

void unZeroErrors ( TH1D * h)

Definition at line 72 of file Resplot.cxx.

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

◆ ZeroErrors()

void ZeroErrors ( TH1D * h)

Definition at line 66 of file Resplot.cxx.

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

Variable Documentation

◆ nexperiments_

int nexperiments_ = 0

Definition at line 1660 of file Resplot.cxx.

◆ nexperiments_max

int nexperiments_max = 40

Definition at line 1661 of file Resplot.cxx.

◆ nexperiments_min

int nexperiments_min = 20

Definition at line 1662 of file Resplot.cxx.