Fork me on GitHub

source: svn/trunk/interface/FuncDef.h@ 150

Last change on this file since 150 was 91, checked in by severine ovyn, 16 years ago

for resol plots

File size: 5.4 KB
Line 
1#ifndef __FuncDef__
2#define __FuncDef__
3
4#include "TStyle.h"
5#include "TCanvas.h"
6#include "TH1F.h"
7#include "TLegend.h"
8#include "TPad.h"
9#include "TTree.h"
10#include "TFile.h"
11#include "THStack.h"
12#include "TLine.h"
13#include "TArrow.h"
14#include "TMarker.h"
15#include "TStyle.h"
16#include "TROOT.h"
17
18#include <iomanip>
19#include <vector>
20#include <iostream>
21#include <string>
22#include "TPaveText.h"
23#include "TProfile.h"
24#include "TF1.h"
25#include "TGraph.h"
26#include "TGraphErrors.h"
27
28#include "interface/TdrStyle.h"
29
30using namespace std;
31
32TPaveText * MakeTPave(Float_t xmin,Float_t ymin,Float_t xmax,Float_t ymax,string text)
33{
34
35 TPaveText *leg1 = new TPaveText(xmin,ymin,xmax,ymax,"NDC");
36 leg1->AddText(text.c_str());
37 leg1->SetFillColor(10);
38 leg1->SetBorderSize(0);
39 leg1->SetTextFont(42);
40 leg1->SetTextSize(0.03791469);
41 return leg1;
42
43
44}
45
46
47TLegend * MakeLegend(Int_t FilledColor,Int_t BorderSize,Float_t TextSize,Double_t x1 = 0.60, Double_t y1 = 0.71, Double_t x2= 0.92, Double_t y2 = 0.92)
48{
49 TLegend *leg = new TLegend(x1,y1,x2,y2,NULL,"NDC");
50 leg->SetFillColor(FilledColor);
51 leg->SetBorderSize(BorderSize);
52 leg->SetTextSize(TextSize);
53 leg->SetTextFont(42);
54
55 return leg;
56}
57
58TH1F * MakeNormTH1F(Int_t numBin,Float_t minX,Float_t maxX, TTree * Analyze,string histo, Int_t Lcolor, Int_t Fcolor, Int_t Lstyle,Int_t width=2,bool Log=false)
59{
60 string temp = histo;
61 string nom = histo.erase(0,histo.find(">>")+2);
62 TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX);
63 //Analyze->Draw(temp.c_str(),"(JetPTResol.NonSmearePT >0 && JetPTResol.NonSmearePT < 20)");
64 Analyze->Draw(temp.c_str());
65 h->SetLineColor(Lcolor);
66 h->SetFillColor(Fcolor);
67 h->SetLineStyle(Lstyle);
68 h->SetLineWidth(width);
69 if(Log)gPad->SetLogy();
70 if(h->Integral()!=0)h->Scale(1./h->Integral());
71 return h;
72}
73
74void GaussValues(TTree * Analyze,string histo,double &rms, double &mean, string min,string max)
75{
76 string temp = histo;
77 string mintemp = min;
78 string maxtemp = max;
79
80 string nom = histo.erase(0,histo.find(">>")+2);
81 TH1F *h = new TH1F(nom.c_str(),"",50,-1,3);
82
83 string all = min + " && " + max;
84 Analyze->Draw(temp.c_str(),all.c_str());
85 h->SetMarkerSize(0.6);
86 double MeanFix = h->GetMean();
87 TF1 *Gauss = new TF1("Gauss","gaus",-1,3);
88 Gauss->FixParameter(1,MeanFix);
89 h->Fit("Gauss","QR");
90 h->Fit("Gauss","QRI");
91 h->Fit("Gauss","QRI");
92 Double_t* params = Gauss->GetParameters();
93 rms=params[2];
94 mean=params[1];
95 h->Draw("P");
96 h->GetXaxis()->SetTitle("E_{T}^{rec}/E_{T}^{MC} [GeV]");
97Gauss->Delete();
98
99}
100
101void GaussValuesETmis(TTree * Analyze,string histo,double &rms, string min,string max)
102{
103 string temp = histo;
104 string mintemp = min;
105 string maxtemp = max;
106
107 string nom = histo.erase(0,histo.find(">>")+2);
108 TH1F *h = new TH1F(nom.c_str(),"",20,-100,100);
109
110 string all = min + " && " + max;
111 Analyze->Draw(temp.c_str(),all.c_str());
112 h->SetMarkerSize(0.6);
113 double RangMin = h->GetMean()-h->GetRMS();
114 double RangMax = h->GetMean()+h->GetRMS();
115 TF1 *Gauss = new TF1("Gauss","gaus",RangMin,RangMax);
116 //TF1 *Gauss = new TF1("Gauss","gaus");
117 h->Fit("Gauss","QR");
118 h->Fit("Gauss","QRI");
119 h->Fit("Gauss","QRI");
120 Double_t* params = Gauss->GetParameters();
121 rms=params[2];
122 //rms=h->GetRMS();
123 //mean=params[1];
124 h->Draw("P");
125 h->GetXaxis()->SetTitle("E_{T}^{rec}-E_{T}^{MC} [GeV]");
126}
127
128
129TH1F * HiggsMakeNormTH1F(Float_t Scale, Int_t numBin,Float_t minX,Float_t maxX, TTree * Analyze,string histo, Int_t Lcolor, Int_t Fcolor, Int_t Lstyle,Int_t width=2,bool Log=false)
130{
131 string temp = histo;
132 string nom = histo.erase(0,histo.find(">>")+2);
133 TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX);
134 Analyze->Draw(temp.c_str());
135 h->SetLineColor(Lcolor);
136 h->SetFillColor(Fcolor);
137 h->SetLineStyle(Lstyle);
138 h->SetLineWidth(width);
139 if(Log)gPad->SetLogy();
140 if(h->Integral()!=0)h->Scale(1*Scale);
141 return h;
142}
143
144
145TH1F * MakeNormTH1FSum(Int_t numBin,Float_t minX,Float_t maxX,TTree * analyze1,TTree * analyze2,TTree * analyze3,
146string * histo,float * weight, Int_t Lcolor, Int_t Fcolor, Int_t Lstyle,Int_t width=2,bool Log=false)
147{
148
149 TTree *analyse[3]={analyze1,analyze2,analyze3};
150 TH1F *hq = new TH1F("hq","pt_lept ",numBin,minX,maxX);
151
152 for(unsigned int i=0; i<3; i++)
153 {
154 string temp = histo[i];
155 string nom = histo[i].erase(0,histo[i].find(">>")+2);
156 TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX);
157 analyse[i]->Draw(temp.c_str());
158 h->Scale(weight[i]);
159 hq->Add(h);
160 }
161
162 hq->SetLineColor(Lcolor);
163 hq->SetFillColor(Fcolor);
164 hq->SetLineStyle(Lstyle);
165 hq->SetLineWidth(width);
166 if(Log)gPad->SetLogy();
167 if(hq->Integral()!=0)hq->Scale(1./hq->Integral());
168
169 return hq;
170}
171
172TH1F * HiggsMakeNormTH1FSum(Int_t numBin,Float_t minX,Float_t maxX,TTree * analyze1,TTree * analyze2,TTree * analyze3,
173string * histo,float * weight, Int_t Lcolor, Int_t Fcolor, Int_t Lstyle,Int_t width=2,bool Log=false)
174{
175
176 TTree *analyse[3]={analyze1,analyze2,analyze3};
177 TH1F *hq = new TH1F("hq","pt_lept ",numBin,minX,maxX);
178
179 for(unsigned int i=0; i<3; i++)
180 {
181 string temp = histo[i];
182 string nom = histo[i].erase(0,histo[i].find(">>")+2);
183 TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX);
184 analyse[i]->Draw(temp.c_str());
185 h->Scale(weight[i]);
186 hq->Add(h);
187 }
188
189 hq->SetLineColor(Lcolor);
190 hq->SetFillColor(Fcolor);
191 hq->SetLineStyle(Lstyle);
192 hq->SetLineWidth(width);
193 if(Log)gPad->SetLogy();
194 if(hq->Integral()!=0)hq->Scale(1./hq->Integral());
195
196 return hq;
197}
198
199
200#endif
Note: See TracBrowser for help on using the repository browser.