1 #include "RooGaussian.h"
2 #include "RooChebychev.h"
3 #include "RooVoigtian.h"
4 #include "RooExponential.h"
5 #include "RooRealVar.h"
6 #include "RooFormulaVar.h"
7 #include "RooDataHist.h"
9 #include "RooGlobalFunc.h"
10 #include "RooCategory.h"
11 #include "RooSimultaneous.h"
12 #include "RooChi2Var.h"
17 #include "TProfile2D.h"
44 mass(
"mass",
"mass",0.,100.,
"GeV"),
45 mean(
"mean",
"mean",0.,100.,
"GeV"),
46 sigma(
"sigma",
"sigma",0.,100.,
"GeV"),
47 efficiency(
"efficiency",
"efficiency",0.5,0.0,1.0),
67 void setup(
double expectedMean_,
double massLow,
double massHigh,
double expectedSigma_){
70 mass.setRange(massLow,massHigh);
71 mean.setRange(massLow,massHigh);
73 virtual void fit(TH1*
num, TH1* den) = 0;
78 using namespace RooFit;
79 RooPlot* frame =
mass.frame(Name(name), Title(
"Failing and Passing Probe Distributions"));
80 data->plotOn(frame,Cut(
"category==category::pass"),LineColor(kGreen),MarkerColor(kGreen));
81 data->plotOn(frame,Cut(
"category==category::fail"),LineColor(kRed),MarkerColor(kRed));
84 simPdf.paramOn(frame,Layout(0.58,0.99,0.99));
85 data->statOn(frame,Layout(0.70,0.99,0.5));
90 TString
calculateEfficiency(TH3 *pass, TH3 *
all,
int massDimension, TProfile2D* &eff, TProfile2D* &effChi2, TString plotName=
""){
92 TAxis *par1Axis, *par2Axis, *massAxis;
93 int par1C, par2C, massC;
95 massAxis = all->GetXaxis();
97 par1Axis = all->GetYaxis();
98 par1C = all->GetXaxis()->GetNbins()+2;
99 par2Axis = all->GetZaxis();
100 par2C = (all->GetXaxis()->GetNbins()+2)*(all->GetYaxis()->GetNbins()+2);
101 }
else if(massDimension==2){
102 par1Axis = all->GetXaxis();
104 massAxis = all->GetYaxis();
105 massC = all->GetXaxis()->GetNbins()+2;
106 par2Axis = all->GetZaxis();
107 par2C = (all->GetXaxis()->GetNbins()+2)*(all->GetYaxis()->GetNbins()+2);
108 }
else if(massDimension==3){
109 par1Axis = all->GetXaxis();
111 par2Axis = all->GetYaxis();
112 par2C = all->GetXaxis()->GetNbins()+2;
113 massAxis = all->GetZaxis();
114 massC = (all->GetXaxis()->GetNbins()+2)*(all->GetYaxis()->GetNbins()+2);
116 return "massDimension > 3 !, skipping...";
120 if(!par1Axis || !par2Axis)
return "No par1Axis or par2Axis!";
121 if( par1Axis->GetXbins()->GetSize()==0 && par2Axis->GetXbins()->GetSize()==0 ){
122 eff =
new TProfile2D(
"efficiency",
"efficiency",par1Axis->GetNbins(),par1Axis->GetXmin(),par1Axis->GetXmax(),par2Axis->GetNbins(),par2Axis->GetXmin(),par2Axis->GetXmax());
123 }
else if( par1Axis->GetXbins()->GetSize()==0 ){
124 eff =
new TProfile2D(
"efficiency",
"efficiency",par1Axis->GetNbins(),par1Axis->GetXmin(),par1Axis->GetXmax(),par2Axis->GetNbins(),par2Axis->GetXbins()->GetArray());
125 }
else if( par2Axis->GetXbins()->GetSize()==0 ){
126 eff =
new TProfile2D(
"efficiency",
"efficiency",par1Axis->GetNbins(),par1Axis->GetXbins()->GetArray(),par2Axis->GetNbins(),par2Axis->GetXmin(),par2Axis->GetXmax());
128 eff =
new TProfile2D(
"efficiency",
"efficiency",par1Axis->GetNbins(),par1Axis->GetXbins()->GetArray(),par2Axis->GetNbins(),par2Axis->GetXbins()->GetArray());
131 eff->SetXTitle( par1Axis->GetTitle() );
132 eff->SetYTitle( par2Axis->GetTitle() );
133 eff->SetStats(kFALSE);
134 effChi2 = (TProfile2D*)eff->Clone(
"efficiencyChi2");
135 eff->SetZTitle(
"Efficiency");
136 eff->SetOption(
"colztexte");
137 eff->GetZaxis()->SetRangeUser(-0.001,1.001);
138 effChi2->SetZTitle(
"Chi^2/NDF");
139 effChi2->SetOption(
"colztext");
142 TH1D* all1D = (massAxis->GetXbins()->GetSize()==0) ?
143 new TH1D(
"all1D",
"all1D",massAxis->GetNbins(),massAxis->GetXmin(),massAxis->GetXmax()):
144 new TH1D(
"all1D",
"all1D",massAxis->GetNbins(),massAxis->GetXbins()->GetArray());
145 TH1D* pass1D = (TH1D *)all1D->Clone(
"pass1D");
148 for(
int par1=1; par1<=par1Axis->GetNbins(); par1++){
149 for(
int par2=1; par2<=par2Axis->GetNbins(); par2++){
151 int index = par1*par1C + par2*par2C +
mass*massC;
152 all1D->SetBinContent(
mass,all->GetBinContent(index));
153 pass1D->SetBinContent(
mass,pass->GetBinContent(index));
155 fit( pass1D, all1D );
156 int index = par1 + par2*(par1Axis->GetNbins()+2);
158 eff->SetBinEntries( index, 1 );
160 effChi2->SetBinContent( index,
getChi2() );
161 effChi2->SetBinEntries( index, 1 );
163 savePlot( TString::Format(
"%s_%d_%d",plotName.Data(),par1,par2) );
172 TString
calculateEfficiency(TH2 *pass, TH2 *
all,
int massDimension, TProfile* &eff, TProfile* &effChi2, TString plotName=
""){
174 TAxis *par1Axis, *massAxis;
176 if(massDimension==1){
177 massAxis = all->GetXaxis();
179 par1Axis = all->GetYaxis();
180 par1C = all->GetXaxis()->GetNbins()+2;
181 }
else if(massDimension==2){
182 par1Axis = all->GetXaxis();
184 massAxis = all->GetYaxis();
185 massC = all->GetXaxis()->GetNbins()+2;
187 return "massDimension > 2 !, skipping...";
191 if(!par1Axis)
return "No par1Axis!";
192 eff = (par1Axis->GetXbins()->GetSize()==0)?
193 new TProfile(
"efficiency",
"efficiency",par1Axis->GetNbins(),par1Axis->GetXmin(),par1Axis->GetXmax()):
194 new TProfile(
"efficiency",
"efficiency",par1Axis->GetNbins(),par1Axis->GetXbins()->GetArray());
196 eff->SetXTitle( par1Axis->GetTitle() );
197 eff->SetLineColor(2);
198 eff->SetLineWidth(2);
199 eff->SetMarkerStyle(20);
200 eff->SetMarkerSize(0.8);
201 eff->SetStats(kFALSE);
202 effChi2 = (TProfile*)eff->Clone(
"efficiencyChi2");
203 eff->SetYTitle(
"Efficiency");
204 eff->SetOption(
"PE");
205 eff->GetYaxis()->SetRangeUser(-0.001,1.001);
206 effChi2->SetYTitle(
"Chi^2/NDF");
207 effChi2->SetOption(
"HIST");
210 TH1D * all1D = (massAxis->GetXbins()->GetSize()==0) ?
211 new TH1D(
"all1D",
"all1D",massAxis->GetNbins(),massAxis->GetXmin(),massAxis->GetXmax()):
212 new TH1D(
"all1D",
"all1D",massAxis->GetNbins(),massAxis->GetXbins()->GetArray());
213 TH1D * pass1D = (TH1D *)all1D->Clone(
"pass1D");
216 for(
int par1=1; par1<=par1Axis->GetNbins(); par1++){
219 all1D->SetBinContent(
mass,all->GetBinContent(index));
220 pass1D->SetBinContent(
mass,pass->GetBinContent(index));
222 fit( pass1D, all1D );
225 eff->SetBinEntries( index, 1 );
227 effChi2->SetBinContent( index,
getChi2() );
228 effChi2->SetBinEntries( index, 1 );
230 savePlot( TString::Format(
"%s_%d",plotName.Data(),par1) );
253 slopeFail(
"slopeFail",
"slopeFail",0.,-1.,1.),
254 linearFail(
"linearFail",
"linearFail",
mass,slopeFail),
255 slopePass(
"slopePass",
"slopePass",0.,-1.,1.),
256 linearPass(
"linearPass",
"linearPass",
mass,slopePass),
260 simPdf.addPdf(pdfFail,
"fail");
261 simPdf.addPdf(pdfPass,
"pass");
265 using namespace RooFit;
269 data =
new RooDataHist(
"data",
"data",
mass, Index(
category), Import(
"fail",*
fail), Import(
"pass",*pass) );
270 if(pass->Integral()+
fail->Integral() < 5){
278 efficiency.setVal(pass->Integral()/(pass->Integral()+
fail->Integral()));
282 slopeFail.setVal(0.);
283 slopePass.setVal(0.);
287 simPdf.fitTo( *
data,
Verbose(kFALSE), PrintLevel(-1), Warnings(kFALSE), PrintEvalErrors(-1) );
289 RooDataHist dataFail(
"fail",
"fail",
mass,
fail );
290 RooDataHist dataPass(
"pass",
"pass",
mass, pass );
291 chi2 = ( RooChi2Var(
"chi2Fail",
"chi2Fail",pdfFail,dataFail,DataError(RooAbsData::Poisson)).getVal()
292 +RooChi2Var(
"chi2Pass",
"chi2Pass",pdfPass,dataPass,DataError(RooAbsData::Poisson)).getVal() )/(2*pass->GetNbinsX()-8);
314 width(
"width",
"width",2.5,
"GeV"),
316 slopeFail(
"slopeFail",
"slopeFail",0.,-1.,0.),
317 exponentialFail(
"linearFail",
"linearFail",
mass,slopeFail),
318 slopePass(
"slopePass",
"slopePass",0.,-1.,0.),
319 exponentialPass(
"linearPass",
"linearPass",
mass,slopePass),
323 width.setConstant(kTRUE);
324 simPdf.addPdf(pdfFail,
"fail");
325 simPdf.addPdf(pdfPass,
"pass");
328 void setup(
double expectedMean_,
double massLow,
double massHigh,
double expectedSigma_,
double width_){
331 mass.setRange(massLow,massHigh);
332 mean.setRange(massLow,massHigh);
333 width.setVal(width_);
336 using namespace RooFit;
340 data =
new RooDataHist(
"data",
"data",
mass, Index(
category), Import(
"fail",*
fail), Import(
"pass",*pass) );
341 if(pass->Integral()+
fail->Integral() < 5){
349 efficiency.setVal(pass->Integral()/(pass->Integral()+
fail->Integral()));
353 slopeFail.setVal(0.);
354 slopePass.setVal(0.);
358 simPdf.fitTo( *
data,
Verbose(kFALSE), PrintLevel(-1), Warnings(kFALSE), PrintEvalErrors(-1) );
360 RooDataHist dataFail(
"fail",
"fail",
mass,
fail );
361 RooDataHist dataPass(
"pass",
"pass",
mass, pass );
362 chi2 = ( RooChi2Var(
"chi2Fail",
"chi2Fail",pdfFail,dataFail,DataError(RooAbsData::Poisson)).getVal()
363 +RooChi2Var(
"chi2Pass",
"chi2Pass",pdfPass,dataPass,DataError(RooAbsData::Poisson)).getVal() )/(2*all->GetNbinsX()-8);
RooRealVar nBackgroundFail
static PFTauRenderPlugin instance
void fit(TH1 *pass, TH1 *all)
void setup(double expectedMean_, double massLow, double massHigh, double expectedSigma_)
void savePlot(const TString &name)
void setup(double expectedMean_, double massLow, double massHigh, double expectedSigma_, double width_)
RooFormulaVar nSignalFail
TString calculateEfficiency(TH3 *pass, TH3 *all, int massDimension, TProfile2D *&eff, TProfile2D *&effChi2, TString plotName="")
RooExponential exponentialFail
~GaussianPlusLinearFitter()
GaussianPlusLinearFitter(bool verbose=false)
virtual ~AbstractFitter()
VoigtianPlusExponentialFitter(bool verbose=false)
double getEfficiencyError()
AbstractFitter(bool verbose_=false)
~VoigtianPlusExponentialFitter()
RooExponential exponentialPass
RooFormulaVar nSignalPass
virtual void fit(TH1 *num, TH1 *den)=0
RooRealVar nBackgroundPass
TString calculateEfficiency(TH2 *pass, TH2 *all, int massDimension, TProfile *&eff, TProfile *&effChi2, TString plotName="")
void fit(TH1 *pass, TH1 *all)