ATLAS Offline Software
Loading...
Searching...
No Matches
MuonPTResolution.h File Reference
#include <string>
Include dependency graph for MuonPTResolution.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double getContentInRange (TH1F *hist, double centralX, double halfWidth)
void getMuonPTResolution (TH1F *hist, double &PTResMean, double &ErrMean, double &PTSigma, double &ErrSigma, double &TailFraction)
void getMuonPTResolution (TH1F *hist, int n_max_runs, double &PTResMean, double &ErrMean, double &PTSigma, double &ErrSigma, double &TailFraction, double PercentageOfEntriesInWidth, double &HalfWidth)

Function Documentation

◆ getContentInRange()

double getContentInRange ( TH1F * hist,
double centralX,
double halfWidth )

Definition at line 12 of file MuonPTResolution.cxx.

13{
14 double ContentInRange=0;
15 for (int i=0; i<=hist->GetNbinsX(); i++)
16 {
17 if ( ( (hist->GetBinCenter(i) + hist->GetBinWidth(i)/2.) < centralX+halfWidth) &&
18 ( (hist->GetBinCenter(i) - hist->GetBinWidth(i)/2.) > centralX-halfWidth ))
19 {
20 ContentInRange=ContentInRange+ hist->GetBinContent(i); // If Bin is completly in range, add the full bin
21 }
22 }
23 int borderbin=hist->FindBin(centralX-halfWidth);
24
25 double ContentInLeftBorderBin = hist->GetBinContent(borderbin)*
26 ((hist->GetBinCenter(borderbin) + hist->GetBinWidth(borderbin)/2.) -(centralX-halfWidth))/hist->GetBinWidth(borderbin);
27
28 borderbin=hist->FindBin(centralX+halfWidth);
29 double ContentInRightBorderBin = hist->GetBinContent(borderbin)*((centralX+halfWidth) - (hist->GetBinCenter(borderbin) -
30 hist->GetBinWidth(borderbin)/2.))/hist->GetBinWidth(borderbin);
31
32 return ContentInRange+ContentInRightBorderBin+ContentInLeftBorderBin;
33}

◆ getMuonPTResolution() [1/2]

void getMuonPTResolution ( TH1F * hist,
double & PTResMean,
double & ErrMean,
double & PTSigma,
double & ErrSigma,
double & TailFraction )

Definition at line 37 of file MuonPTResolution.cxx.

43{
44 double empty = 0.;
45 getMuonPTResolution(hist, 3, PTResMean, ErrMean, PTSigma, ErrSigma, TailContent,empty,empty);
46}
void getMuonPTResolution(TH1F *hist, double &PTResMean, double &ErrMean, double &PTSigma, double &ErrSigma, double &TailContent)
static const Attributes_t empty

◆ getMuonPTResolution() [2/2]

void getMuonPTResolution ( TH1F * hist,
int n_max_runs,
double & PTResMean,
double & ErrMean,
double & PTSigma,
double & ErrSigma,
double & TailFraction,
double PercentageOfEntriesInWidth,
double & HalfWidth )

Definition at line 50 of file MuonPTResolution.cxx.

59{
60 PTResMean = -1.0;
61 ErrMean = -1.0;
62 PTSigma = -1.0;
63 ErrSigma = -1.0;
64 TailFraction = -1.0;
65 HalfWidth = -1.0;
66
67 if (n_max_runs<=0) return;
68 Double_t par[8];
69 Double_t mean=0.0, sigma=0.0;
70 Double_t old_sigma=0.0;
71 PTResMean = 0.0;
72
73 TF1 gaussian("g1","gaus");
74 gaussian.SetRange(-300,300);
75
76
77 for (int i=1; i<=n_max_runs ;i++)
78 {
79 hist->Fit(&gaussian,"R");
80 gaussian.GetParameters(&par[0]);
81 mean = par[1];
82 sigma = std::abs(par[2]);
83 gaussian.SetRange(mean-sigma*2.,mean+sigma*2.);
84
85 // Check if converged, if yes then quit
86 if (std::abs(1.0-old_sigma/sigma)<0.0001) break;
87 old_sigma=sigma;
88 }
89
90
91 PTResMean = mean;
92 PTSigma = std::abs(sigma);
93 ErrMean = (gaussian.GetParError(1));
94 ErrSigma = std::abs((gaussian.GetParError(2)));
95 int i=0;
96 double TailContent=0;
97
98 while ( (hist->GetBinCenter(i)-hist->GetBinWidth(i)/2.) < mean-sigma*2. )
99 {
100 TailContent=TailContent+hist->GetBinContent(i);
101 i++;
102 }
103 i=hist->GetNbinsX();
104
105 while ( (hist->GetBinCenter(i)+hist->GetBinWidth(i)/2.) > mean+sigma*2. )
106 {
107 TailContent=TailContent+hist->GetBinContent(i);
108 i--;
109 }
110
111 TailFraction = ((double)(TailContent))/((double)hist->GetEntries());
112
113 if (PercentageOfEntriesInWidth>1) PercentageOfEntriesInWidth=PercentageOfEntriesInWidth/100;
114
115 double NumberOfEntriesInWidth = PercentageOfEntriesInWidth * 1.0 * hist->GetEntries();
116 HalfWidth=0.;
117 double StepLength=0.1;
118
119 while (StepLength>sigma/1000.)
120 {
121 while ( getContentInRange(hist,mean,HalfWidth) < NumberOfEntriesInWidth )
122 {
123 HalfWidth=HalfWidth+StepLength;
124 }
125 HalfWidth=HalfWidth-StepLength;
126
128 }
129}
double getContentInRange(TH1F *hist, double centralX, double halfWidth)
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="")