ATLAS Offline Software
Functions
MuonPTResolution.h File Reference
#include "TF1.h"
#include "TH1F.h"
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
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 14 of file MuonPTResolution.cxx.

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

◆ getMuonPTResolution() [1/2]

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

Definition at line 39 of file MuonPTResolution.cxx.

45 {
46  double empty = 0.;
47  getMuonPTResolution(hist, 3, PTResMean, ErrMean, PTSigma, ErrSigma, TailContent,empty,empty);
48 }

◆ 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 52 of file MuonPTResolution.cxx.

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