1 |
#ifndef FITINFO_H
|
2 |
#define FITINFO_H
|
3 |
|
4 |
#include "samples.hpp"
|
5 |
#include "controlRegions.h"
|
6 |
#include "../plugins/customize.h"
|
7 |
#include "../plugins/setTDRStyle.C"
|
8 |
#include <iostream>
|
9 |
#include <TCanvas.h>
|
10 |
#include <TLine.h>
|
11 |
#include <TRegexp.h>
|
12 |
#include <TLegend.h>
|
13 |
#include <THStack.h>
|
14 |
#include <TROOT.h>
|
15 |
#include "TLatex.h"
|
16 |
#include "TPaveText.h"
|
17 |
#include "TGraphErrors.h"
|
18 |
#include "TAxis.h"
|
19 |
#include <TH1.h>
|
20 |
#include <TFractionFitter.h>
|
21 |
#include <TFile.h>
|
22 |
|
23 |
#include "TObjArray.h"
|
24 |
#include "RooAbsReal.h"
|
25 |
#include "RooRealVar.h"
|
26 |
#include "RooArgList.h"
|
27 |
#include "RooFitResult.h"
|
28 |
#include "RooDataHist.h"
|
29 |
#include "RooDataSet.h"
|
30 |
#include "RooHistPdf.h"
|
31 |
#include "RooAddPdf.h"
|
32 |
#include "RooPlot.h"
|
33 |
#include "RooSimultaneous.h"
|
34 |
#include "RooCategory.h"
|
35 |
|
36 |
|
37 |
|
38 |
class fitInfo{
|
39 |
|
40 |
private:
|
41 |
|
42 |
std::string s_prefix;
|
43 |
std::string s_sysprefix;
|
44 |
std::string s_suffix;
|
45 |
std::string s_region;
|
46 |
std::string s_var;
|
47 |
std::string s_channel;
|
48 |
|
49 |
double minVar;
|
50 |
double maxVar;
|
51 |
double initial;
|
52 |
|
53 |
TH1F * hd;
|
54 |
|
55 |
public:
|
56 |
|
57 |
fitInfo():cr(new controlRegion), cr_signal( new controlRegion){
|
58 |
cr->init();
|
59 |
cr_signal->init();
|
60 |
s_regionString = s_prefix+s_region+"ControlRegionHZee/"+s_var+s_prefix+s_region+"ControlRegionHZee$";
|
61 |
s_regionForSyst = s_sysprefix+s_region+"ControlRegionHZee/"+s_var+s_sysprefix+s_region+"ControlRegionHZee"+s_suffix;
|
62 |
if(s_sysprefix != "")
|
63 |
s_signalRegion=s_sysprefix+"RegionHZee/SimpleJet1_phi"+s_sysprefix+"RegionHZee$";
|
64 |
else
|
65 |
s_signalRegion="BDTRegionHZee/SimpleJet1_phiBDTRegionHZee$";
|
66 |
};
|
67 |
fitInfo(std::string & region, std::string & var, std::string & prefix, std::string & sysprefix , std::string & suffix, std::string & channel, double min_, double max_ )
|
68 |
:s_region(region), s_var(var), s_prefix(prefix), s_sysprefix(sysprefix), s_suffix(suffix), minVar(min_), maxVar(max_), s_channel(channel),cr(new controlRegion), cr_signal( new controlRegion) {
|
69 |
cr->init();
|
70 |
cr_signal->init();
|
71 |
s_regionString = s_prefix+s_region+"Region"+s_channel+"/"+s_var+s_prefix+s_region+"Region"+s_channel+"$";
|
72 |
s_regionForSyst = s_sysprefix+s_region+"Region"+s_channel+"/"+s_var+s_sysprefix+s_region+"Region"+s_channel+s_suffix;
|
73 |
if(s_sysprefix != "")
|
74 |
s_signalRegion=s_sysprefix+"Region"+s_channel+"/SimpleJet1_phi"+s_sysprefix+"Region"+s_channel+"$";
|
75 |
else
|
76 |
s_signalRegion="BDTRegionHZee/SimpleJet1_phiBDTRegionHZee$";
|
77 |
};
|
78 |
fitInfo(std::string & region, std::string & var, std::string & prefix, std::string & sysprefix , std::string & suffix, double min_, double max_ )
|
79 |
:s_region(region), s_var(var), s_prefix(prefix), s_sysprefix(sysprefix), s_suffix(suffix), minVar(min_), maxVar(max_),cr(new controlRegion), cr_signal( new controlRegion) {
|
80 |
cr->init();
|
81 |
cr_signal->init();
|
82 |
s_channel = "HZee";
|
83 |
s_regionString = s_prefix+s_region+"ControlRegion"+s_channel+"/"+s_var+s_prefix+s_region+"ControlRegion"+s_channel+"$";
|
84 |
s_regionForSyst = s_sysprefix+s_region+"ControlRegion"+s_channel+"/"+s_var+s_sysprefix+s_region+"ControlRegion"+s_channel+s_suffix;
|
85 |
if(s_sysprefix != "")
|
86 |
s_signalRegion=s_sysprefix+"Region"+s_channel+"/SimpleJet1_phi"+s_sysprefix+"Region"+s_channel+"$";
|
87 |
else
|
88 |
s_signalRegion="BDTRegionHZee/SimpleJet1_phiBDTRegionHZee$";
|
89 |
};
|
90 |
fitInfo(std::string & regionString , double min_, double max_ )
|
91 |
:s_regionString(regionString), minVar(min_), maxVar(max_),cr(new controlRegion), cr_signal( new controlRegion) {
|
92 |
cr->init();
|
93 |
cr_signal->init();
|
94 |
s_regionForSyst = "";
|
95 |
s_signalRegion = "";
|
96 |
};
|
97 |
~fitInfo() {};
|
98 |
|
99 |
std::string regionName(){return s_region;}
|
100 |
std::string regionString(){return s_regionString;}
|
101 |
|
102 |
void setSignalRegion( std::string & signalString ){ s_signalRegion = signalString; std::cout << s_signalRegion << std::endl; }
|
103 |
|
104 |
std::string s_regionString;
|
105 |
std::string s_regionForSyst;
|
106 |
std::string s_signalRegion;
|
107 |
controlRegion *cr;
|
108 |
controlRegion *cr_signal;
|
109 |
|
110 |
void fillHistoToFit( TH1F & data ){
|
111 |
hd = new TH1F( data );
|
112 |
}
|
113 |
|
114 |
RooRealVar *var;
|
115 |
std::vector<RooRealVar*> tr_vars;
|
116 |
std::vector<RooFormulaVar*> fit_vars;
|
117 |
std::vector<RooDataHist*> templates;
|
118 |
std::vector<RooHistPdf*> pdfs;
|
119 |
RooArgList *pdfList;
|
120 |
RooArgList *varList;
|
121 |
RooAddPdf *model;
|
122 |
RooDataHist * h_data;
|
123 |
|
124 |
void create_variable( std::vector<std::string> &templateNames, std::vector<std::string> &fixedTemplateNames, std::vector<RooRealVar*>& f_vars, double min = -1e10, double max = 1e10, bool SF = false ){
|
125 |
|
126 |
std::cout << "Creating variables" << std::endl;
|
127 |
|
128 |
SF = true;
|
129 |
min = minVar;
|
130 |
max = maxVar;
|
131 |
pdfList = new RooArgList;
|
132 |
varList = new RooArgList;
|
133 |
var = new RooRealVar(("var"+s_region+s_var).c_str(),("var"+s_region+s_var).c_str(), min, max);
|
134 |
h_data = new RooDataHist(("data"+s_region).c_str(),("data"+s_region).c_str(), *var, hd );
|
135 |
|
136 |
std::cout << "creating varibles for fixed template..." << std::endl;
|
137 |
for(int i=0; i<fixedTemplateNames.size(); ++i){
|
138 |
std::cout << fixedTemplateNames.at(i) << " count = " << cr->count(fixedTemplateNames.at(i)) << ", signal count = " << cr_signal->count(fixedTemplateNames.at(i)) << std::endl;
|
139 |
templates.push_back( new RooDataHist((s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(),(s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(), RooArgList(*var), cr->histo(fixedTemplateNames.at(i) )));
|
140 |
if(!SF) tr_vars.push_back( new RooRealVar(("tr_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(),("tr_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(), cr->count(fixedTemplateNames.at(i))/cr_signal->count(fixedTemplateNames.at(i))) );
|
141 |
else tr_vars.push_back( new RooRealVar(("tr_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(),("tr_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(), cr->count(fixedTemplateNames.at(i)) ) );
|
142 |
fit_vars.push_back( new RooFormulaVar(("fit_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(),("fit_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(),"@0*@1", RooArgList(*f_vars.at(i),*tr_vars.at(i) ) ) );
|
143 |
pdfs.push_back( new RooHistPdf( ("pdf_"+fixedTemplateNames.at(i)+"_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(),("pdf_"+fixedTemplateNames.at(i)+"_"+s_region+"_cr_"+fixedTemplateNames.at(i)).c_str(), RooArgList(*var), *templates.at(i) ) );
|
144 |
|
145 |
pdfList->addOwned(*pdfs.at(i));
|
146 |
varList->addOwned(*fit_vars.at(i));
|
147 |
}
|
148 |
std::cout << "creating varibles for variable template..." << std::endl;
|
149 |
for(int i=0; i<templateNames.size(); ++i){
|
150 |
int j = i+fixedTemplateNames.size();
|
151 |
std::cout << templateNames.at(i) << " count = " << cr->count(templateNames.at(i)) << ", signal count = " << cr_signal->count(templateNames.at(i)) << std::endl;
|
152 |
templates.push_back( new RooDataHist((s_region+"_cr_"+templateNames.at(i)).c_str(),(s_region+"_cr_"+templateNames.at(i)).c_str(), RooArgList(*var), cr->histo(templateNames.at(i))));
|
153 |
if(!SF) tr_vars.push_back( new RooRealVar(("tr_"+s_region+"_cr_"+templateNames.at(i)).c_str(),("tr_"+s_region+"_cr_"+templateNames.at(i)).c_str(), cr->count(templateNames.at(i))/cr_signal->count(templateNames.at(i))) );
|
154 |
else tr_vars.push_back( new RooRealVar(("tr_"+s_region+"_cr_"+templateNames.at(i)).c_str(),("tr_"+s_region+"_cr_"+templateNames.at(i)).c_str(), cr->count(templateNames.at(i)) ) );
|
155 |
fit_vars.push_back( new RooFormulaVar(("fit_"+s_region+"_cr_"+templateNames.at(i)).c_str(),("fit_"+s_region+"_cr_"+templateNames.at(i)).c_str(),"@0*@1", RooArgList(*f_vars.at(j),*tr_vars.at(j) ) ) );
|
156 |
pdfs.push_back( new RooHistPdf( ("pdf_"+templateNames.at(i)+"_"+s_region+"_cr_"+templateNames.at(i)).c_str(),("pdf_"+templateNames.at(i)+"_"+s_region+"_cr_"+templateNames.at(i)).c_str(), RooArgList(*var), *templates.at(j) ) );
|
157 |
|
158 |
pdfList->addOwned(*pdfs.at(j));
|
159 |
varList->addOwned(*fit_vars.at(j));
|
160 |
}
|
161 |
|
162 |
pdfList->Print();
|
163 |
varList->Print();
|
164 |
model = new RooAddPdf( ("model_"+s_region+s_var+s_suffix).c_str(),("model_"+s_region+s_var+s_suffix).c_str(), *pdfList, *varList, kFALSE );
|
165 |
}
|
166 |
|
167 |
|
168 |
};
|
169 |
|
170 |
#endif
|