#ifndef __FuncDef__ #define __FuncDef__ #include "TStyle.h" #include "TCanvas.h" #include "TH1F.h" #include "TLegend.h" #include "TPad.h" #include "TTree.h" #include "TFile.h" #include "THStack.h" #include "TLine.h" #include "TArrow.h" #include "TMarker.h" #include "TStyle.h" #include "TROOT.h" #include #include #include #include #include "TPaveText.h" #include "TProfile.h" #include "TF1.h" #include "TGraph.h" #include "TGraphErrors.h" #include "interface/TdrStyle.h" using namespace std; TPaveText * MakeTPave(Float_t xmin,Float_t ymin,Float_t xmax,Float_t ymax,string text) { TPaveText *leg1 = new TPaveText(xmin,ymin,xmax,ymax,"NDC"); leg1->AddText(text.c_str()); leg1->SetFillColor(10); leg1->SetBorderSize(0); leg1->SetTextFont(42); leg1->SetTextSize(0.03791469); return leg1; } TLegend * 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) { TLegend *leg = new TLegend(x1,y1,x2,y2,NULL,"NDC"); leg->SetFillColor(FilledColor); leg->SetBorderSize(BorderSize); leg->SetTextSize(TextSize); leg->SetTextFont(42); return leg; } TH1F * 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) { string temp = histo; string nom = histo.erase(0,histo.find(">>")+2); TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX); //Analyze->Draw(temp.c_str(),"(JetPTResol.NonSmearePT >0 && JetPTResol.NonSmearePT < 20)"); Analyze->Draw(temp.c_str()); h->SetLineColor(Lcolor); h->SetFillColor(Fcolor); h->SetLineStyle(Lstyle); h->SetLineWidth(width); if(Log)gPad->SetLogy(); if(h->Integral()!=0)h->Scale(1./h->Integral()); return h; } void GaussValues(TTree * Analyze,string histo,double &rms, double &mean, string min,string max) { string temp = histo; string mintemp = min; string maxtemp = max; string nom = histo.erase(0,histo.find(">>")+2); TH1F *h = new TH1F(nom.c_str(),"",100,0,3); string all = min + " && " + max; Analyze->Draw(temp.c_str(),all.c_str()); h->SetMarkerSize(0.6); //double MeanFix = h->GetMean(); double RangMin = (h->GetMean()-1.5*h->GetRMS()); double RangMax = (h->GetMean()+1.5*h->GetRMS()); TF1 *Gauss = new TF1("Gauss","gaus",RangMin,RangMax); // Gauss->FixParameter(1,MeanFix); h->Fit("Gauss","QR"); h->Fit("Gauss","QRI"); h->Fit("Gauss","QRI"); Double_t* params = Gauss->GetParameters(); rms=params[2]; //mean= MeanFix; mean=params[1]; h->Draw("P"); h->GetXaxis()->SetTitle("E_{T}^{rec}/E_{T}^{MC} [GeV]"); Gauss->Delete(); } void GaussValuesAsymmetry(TTree * Analyze,string histo, double &mean, string min,string max,string cut="1==1") { string temp = histo; string mintemp = min; string maxtemp = max; string nom = histo.erase(0,histo.find(">>")+2); TH1F *h = new TH1F(nom.c_str(),nom.c_str(),50,-3,3); //string all = min + " && " + max + " && abs(JetPTResol.Eta) < 0.5"; string all = min + " && " + max + " && " + cut; Analyze->Draw(temp.c_str(),all.c_str()); h->SetMarkerSize(0.6); // mean = h->GetMean(); TF1 *Gauss = new TF1("Gauss","gaus",-0.4,0.4); //Gauss->FixParameter(1,MeanFix); h->Fit("Gauss","QR"); h->Fit("Gauss","QRI"); h->Fit("Gauss","QRI"); Double_t* params = Gauss->GetParameters(); mean=params[1]; h->Draw("P"); h->GetXaxis()->SetTitle("E_{T}^{rec}/E_{T}^{MC} [GeV]"); Gauss->Delete(); // double RangMin = (h->GetMean()-2*h->GetRMS()); // double RangMax = (h->GetMean()+2*h->GetRMS()); } void GaussValuesAsymmetry2(TTree * Analyze,string histo, double &mean, string min,string max,string cut="1==1") { string temp = histo; string mintemp = min; string maxtemp = max; string nom = histo.erase(0,histo.find(">>")+2); TH1F *h = new TH1F(nom.c_str(),nom.c_str(),50,-3,3); string all = min + " && " + max + " && " + cut; Analyze->Draw(temp.c_str(),all.c_str()); h->SetMarkerSize(0.6); mean = h->GetMean(); } void GaussValuesElec(TTree * Analyze,string histo,double &rms, double &mean, string min,string max) { string temp = histo; string mintemp = min; string maxtemp = max; string nom = histo.erase(0,histo.find(">>")+2); TH1F *h = new TH1F(nom.c_str(),"",20,-1,3); string all = min + " && " + max; Analyze->Draw(temp.c_str(),all.c_str()); h->SetMarkerSize(0.6); double MeanFix = h->GetMean(); TF1 *Gauss = new TF1("Gauss","gaus",-0.5,1.5); Gauss->FixParameter(1,MeanFix); h->Fit("Gauss","QR"); h->Fit("Gauss","QRI"); h->Fit("Gauss","QRI"); Double_t* params = Gauss->GetParameters(); rms=params[2]; //mean= MeanFix; mean=params[1]; h->Draw("P"); h->GetXaxis()->SetTitle("E_{T}^{rec}/E_{T}^{MC} [GeV]"); Gauss->Delete(); } void GaussValuesETmis(TTree * Analyze,string histo,double &rms, string min,string max) { string temp = histo; string mintemp = min; string maxtemp = max; string nom = histo.erase(0,histo.find(">>")+2); TH1F *h = new TH1F(nom.c_str(),"",50,-50,50); string all = min + " && " + max; Analyze->Draw(temp.c_str(),all.c_str()); h->SetMarkerSize(0.6); double RangMin = (h->GetMean()-2.5*h->GetRMS()); double RangMax = (h->GetMean()+2.5*h->GetRMS()); //TF1 *Gauss = new TF1("Gauss","gaus"); TF1 *Gauss = new TF1("Gauss","gaus",RangMin,RangMax); //TF1 *Gauss = new TF1("Gauss","gaus"); h->Fit("Gauss","QR"); h->Fit("Gauss","QRI"); h->Fit("Gauss","QRI"); Double_t* params = Gauss->GetParameters(); rms=params[2]; //rms=h->GetRMS(); //mean=params[1]; h->Draw("P"); h->GetXaxis()->SetTitle("E_{T}^{rec}-E_{T}^{MC} [GeV]"); } TH1F * 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) { string temp = histo; string nom = histo.erase(0,histo.find(">>")+2); TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX); Analyze->Draw(temp.c_str()); h->SetLineColor(Lcolor); h->SetFillColor(Fcolor); h->SetLineStyle(Lstyle); h->SetLineWidth(width); if(Log)gPad->SetLogy(); if(h->Integral()!=0)h->Scale(1*Scale); return h; } TH1F * MakeNormTH1FSum(Int_t numBin,Float_t minX,Float_t maxX,TTree * analyze1,TTree * analyze2,TTree * analyze3, string * histo,float * weight, Int_t Lcolor, Int_t Fcolor, Int_t Lstyle,Int_t width=2,bool Log=false) { TTree *analyse[3]={analyze1,analyze2,analyze3}; TH1F *hq = new TH1F("hq","pt_lept ",numBin,minX,maxX); for(unsigned int i=0; i<3; i++) { string temp = histo[i]; string nom = histo[i].erase(0,histo[i].find(">>")+2); TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX); analyse[i]->Draw(temp.c_str()); h->Scale(weight[i]); hq->Add(h); } hq->SetLineColor(Lcolor); hq->SetFillColor(Fcolor); hq->SetLineStyle(Lstyle); hq->SetLineWidth(width); if(Log)gPad->SetLogy(); if(hq->Integral()!=0)hq->Scale(1./hq->Integral()); return hq; } TH1F * HiggsMakeNormTH1FSum(Int_t numBin,Float_t minX,Float_t maxX,TTree * analyze1,TTree * analyze2,TTree * analyze3, string * histo,float * weight, Int_t Lcolor, Int_t Fcolor, Int_t Lstyle,Int_t width=2,bool Log=false) { TTree *analyse[3]={analyze1,analyze2,analyze3}; TH1F *hq = new TH1F("hq","pt_lept ",numBin,minX,maxX); for(unsigned int i=0; i<3; i++) { string temp = histo[i]; string nom = histo[i].erase(0,histo[i].find(">>")+2); TH1F *h = new TH1F(nom.c_str(),"pt_lept ",numBin,minX,maxX); analyse[i]->Draw(temp.c_str()); h->Scale(weight[i]); hq->Add(h); } hq->SetLineColor(Lcolor); hq->SetFillColor(Fcolor); hq->SetLineStyle(Lstyle); hq->SetLineWidth(width); if(Log)gPad->SetLogy(); if(hq->Integral()!=0)hq->Scale(1./hq->Integral()); return hq; } #endif