Пример #1
0
void plot1d(TCanvas* c, char* name){
    TH1F *h;
    c->Divide(1,3);
    c->cd(1)->SetLogy();
    readfile(OPT,11);
    h = (TH1F*)mTFile->Get(Form("%s",name));   h->Draw(); h->SetLineWidth(2); h->SetMinimum(1.0);
    h = (TH1F*)mTFile->Get(Form("%sAG",name)); h->Draw("same"); h->SetLineColor(2);h->SetLineWidth(2);
    t=new TText(0.2, 0.25,"pp collisions"); t->SetNDC(); t->Draw();
    t=new TText(0.2, 0.20,"pp abort-gap");  t->SetNDC(); t->Draw(); t->SetTextColor(2);
    c->cd(2)->SetLogy();
    readfile(OPT,13);
    h = (TH1F*)mTFile->Get(Form("%s",name));   h->Draw(); h->SetLineWidth(2); h->SetMinimum(1.0);
    h = (TH1F*)mTFile->Get(Form("%sAG",name)); h->Draw("same"); h->SetLineColor(2);h->SetLineWidth(2);
    t=new TText(0.2, 0.25,"pAl collisions"); t->SetNDC(); t->Draw();
    t=new TText(0.2, 0.20,"pAl abort-gap");  t->SetNDC(); t->Draw(); t->SetTextColor(2);
    c->cd(3)->SetLogy();
    readfile(OPT,12);
    h = (TH1F*)mTFile->Get(Form("%s",name));  h->Draw(); h->SetLineWidth(2);h->SetMinimum(1.0);
    h = (TH1F*)mTFile->Get(Form("%sAG",name)); h->Draw("same"); h->SetLineColor(2); h->SetLineWidth(2);
    readfile(OPT,15);
    h = (TH1F*)mTFile->Get(Form("%s",name));   h->Draw("same"); h->SetLineColor(4); h->SetLineWidth(2);
    h = (TH1F*)mTFile->Get(Form("%sAG",name)); h->Draw("same"); h->SetLineColor(6); h->SetLineWidth(2);
    t=new TText(0.2,  0.25,"pAu2 collisions"); t->SetNDC(); t->Draw();
    t=new TText(0.2,  0.20,"pAu2 abort-gap");  t->SetNDC(); t->Draw(); t->SetTextColor(2);
    t=new TText(0.35, 0.25,"pAu1 collisions"); t->SetNDC(); t->Draw(); t->SetTextColor(4);
    t=new TText(0.35, 0.20,"pAu1 abort-gap");  t->SetNDC(); t->Draw(); t->SetTextColor(6);
    c->SaveAs(Form("plot/%s.png",name));
}
Пример #2
0
void produceHisto()
{ 
  TH1F * hmostimp =new TH1F("number most important",
			"Mean value number of over threshold digits produced by \
most important  particle",
                        20,0.,23.);
  gStyle->SetOptStat(0); 
  hmostimp->Fill(1.,33.51);
  hmostimp->Fill(5.,34.32);
  hmostimp->Fill(10.,35.78);
  hmostimp->Fill(15.,36.85);
  hmostimp->Fill(20.,37.61);
  hmostimp->Write();
  hmostimp->SetMinimum(32.);
  delete hmostimp;
  
  TH1F * hall =new TH1F("number all3",
			"Mean value Number of over threshold digits produced by \
alll three stored particles",
                        20,0.,23.);
  gStyle->SetOptStat(0); 
  hall->Fill(1.,77.05);
  hall->Fill(5.,76.905);
  hall->Fill(10.,71.9);
  hall->Fill(15.,69.7);
  hall->Fill(20.,65.15);
  hall->Write();
  hall->SetMinimum(32.);    
}
Пример #3
0
void EflowCASTOR()
{

  NCanvas(1,2,"data");

  TH1F * HDat;
  TH1F * HZ2;

  //  TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root");
  TFile *fzee = new TFile("ZDiffOutputfile.root");
  // TFile *fzee = new TFile("ZDiffOutputfile.root");
  HDat  =  (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_DATA");
  HZ2  =  (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_Z2PY6");
  data->cd(1);
  NHSetMarker(HDat,2,20,0.8);
  HDat->SetMinimum(10);
  HDat->Draw();
  NStat(HDat,0);
  NSetTitle(HDat,"CASTOR Modules", "Entries");

  HDat->SetTitle("CASTOR Module Energy 2010");
  HZ2->Draw("SAME HIST");
  NHSetMarker(HDat,2,20,0.4);
  TLegend *legend = new TLegend(0.6,0.7,0.9,0.8);
  legend->SetTextFont(72);
  legend->SetTextSize(0.06);
  legend->SetBorderSize(0);


  legend->AddEntry(HDat,"Data2010","p");
  legend->AddEntry(HZ2,"Z2","l");
  legend->Draw();


  TH1F * Hra = (TH1F * ) HDat->Clone();
  //  Hra->GetXaxis->SetRange(0,12);
  NStat(Hra,0);
  NHSetMarker(Hra,4,20,0.8);
  Hra->SetMinimum(1);
  Hra->Divide(HZ2);
  NLogAxis(0,0);
  data->cd(2);
  Hra->Draw();
  Hra->SetTitle("Ratio DATA/MC");
  Hra->Fit("pol0");
  NSetTitle(Hra,"CASTOR Modules", "Ratio");
  NLogAxis(0,1);

}
Пример #4
0
TH1F* CreateEffHisto(TH1F* hGen, TH1F* hRec)
{
// create an efficiency histogram

  Int_t nBins = hGen->GetNbinsX();
  TH1F* hEff = (TH1F*) hGen->Clone("hEff");
  hEff->SetTitle("");
  hEff->SetStats(kFALSE);
  hEff->SetMinimum(0.);
  hEff->SetMaximum(110.);
  hEff->GetYaxis()->SetTitle("#epsilon [%]");

  for (Int_t iBin = 0; iBin <= nBins; iBin++) {
    Double_t nGen = hGen->GetBinContent(iBin);
    Double_t nRec = hRec->GetBinContent(iBin);
    if (nGen > 0) {
      Double_t eff = nRec/nGen;
      hEff->SetBinContent(iBin, 100. * eff);
      Double_t error = sqrt(eff*(1.-eff) / nGen);
      if (error == 0) error = 0.0001;
      hEff->SetBinError(iBin, 100. * error);
    } else {
      hEff->SetBinContent(iBin, -100.);
      hEff->SetBinError(iBin, 0);
    }
  }

  return hEff;
}
Пример #5
0
void DrawInsituCorr_vs_Eta(Str jetAlgo) {
  Nbins=sizeof(Ebins)/sizeof(double);
  myJES = new JetCalibrationTool(jetAlgo,_jesFile);

  TH1F *h = new TH1F("","",100,-4.8,4.8);
  h->SetXTitle("Jet #eta_{det}");
  h->SetYTitle("Residual correction for data only");
  h->SetMaximum(1.1); h->SetMinimum(0.85);

  h->Draw();
  TLine *l = new TLine(); 
  l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(4);
  l->DrawLine(-4.65,1,4.65,1);
  
  for (int i=0;i<Nbins;++i) {
    Graph *g = GetInsituGraph(Ebins[i]);
    FormatGraph(g,i); g->Draw("PL");
    double x=0.52, y=0.3-0.05*i;
    if (i>2) { x=0.74; y=0.3-0.05*(i-3); }
    DrawLabel(Form("p_{T} = %.0f GeV",Ebins[i]),x,y,i);
  }

  l->SetLineWidth(2);
  l->SetLineColor(kGray+2);
  l->SetLineStyle(1);

  tex->SetNDC(); tex->SetTextAlign(12);
  //tex->DrawLatex(0.18,0.975,myJES->AbsoluteJES_Description());
  tex->DrawLatex(0.18,0.9,GetJetDesc(jetAlgo));
}
Пример #6
0
void DrawInsituCorr_vs_Pt(Str jetAlgo) {
  myJES = new JetCalibrationTool(jetAlgo,_jesFile);
  TH1F *h = new TH1F("","",100,15,2500);
  h->SetXTitle("Jet p_{T}");
  h->SetYTitle("Residual correction for data only");
  h->SetMaximum(1.1); h->SetMinimum(0.85);
  h->Draw();
  TLine *l = new TLine(); 
  l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(4);
  l->DrawLine(16,1,2400,1);
  for (int i=0;i<6;++i) {
    double eta=4.0*i/5;
    Graph *g = GetInsituGraphVsPt(eta);
    FormatGraph(g,i); g->Draw("PL");
    double x=0.52, y=0.3-0.05*i;
    if (i>2) { x=0.74; y=0.3-0.05*(i-3); }
    DrawLabel(Form("#eta = %.1f",eta),x,y,i);
  }

  l->SetLineWidth(2);
  l->SetLineColor(kGray+2);
  l->SetLineStyle(1);

  tex->SetNDC(); tex->SetTextAlign(12);
  //tex->DrawLatex(0.18,0.975,myJES->AbsoluteJES_Description());
  tex->DrawLatex(0.18,0.9,GetJetDesc(jetAlgo));
}
Пример #7
0
void DrawJMS_vs_Eta(Str jetAlgo) {
  double massEbins[] = {50, 100, 250, 500, 750, 1500};
  double massNbins = sizeof(massEbins)/sizeof(double);
  myJES = new JetCalibrationTool(jetAlgo,_jesFile);
  TH1F *h = new TH1F("","",100,-4.8,4.8);
  h->SetXTitle("Jet #eta_{det}"); h->SetYTitle("Jet mass response");
  h->SetMaximum(1.4); h->SetMinimum(0.6);
  h->Draw();
  
  TLine *l = new TLine(); 
  l->SetLineWidth(2); l->SetLineColor(kGray+2); l->SetLineStyle(4);
  l->DrawLine(-4.65,1,4.65,1);

  for (int i=0;i<massNbins;++i) {
    Graph *g = GetJMSGraph(massEbins[i]);
    FormatGraph(g,i);
    g->Draw("PL");
    double x=0.52, y=0.3-0.05*i;
    if (i>2) { x=0.74; y=0.3-0.05*(i-3); }
    DrawLabel(Form("E = %.0f GeV",massEbins[i]),x,y,i);
  }
  
  tex->SetNDC(); tex->SetTextAlign(12);
  tex->DrawLatex(0.18,0.975,myJES->AbsoluteJES_Description());
  tex->DrawLatex(0.18,0.9,jetAlgo);
}
Пример #8
0
void readX(){

  TFile *_file0 = TFile::Open("withbdt.root");
  TTree* tree = gFile->Get("SelTree;1");

  TH1F* histo = new TH1F("m", "m", nbin, minMass, maxMass); histo->Sumw2();
  TH1F* bhisto = new TH1F("bm", "bm", nbin, minMass, maxMass); bhisto->Sumw2();
 

  float tzPsi; 
  tree->SetBranchAddress("tzPsi",&tzPsi);
  
  float m;
  tree->SetBranchAddress("mass",&m);
  float bdt;
  tree->SetBranchAddress("bdt",&bdt);

 
  int nevent = tree->GetEntries(); 
  int n = 0;

  for ( int i = 0; i < nevent; ++i){
    tree->GetEntry(i);
    histo->Fill(m);
    //cout << tzPsi << endl;
    if (bdt> -0.6&& tzPsi > 0.3) bhisto->Fill(m);
  }

  histo->SetMinimum(0); 
 histo->Draw();
 //bhisto->Divide(histo); 
 bhisto->Draw("HISTOSAME");
 }   
Пример #9
0
void seism() {

   TStopwatch sw; sw.Start();
   //set time offset
   TDatime dtime;
   gStyle->SetTimeOffset(dtime.Convert());

   TCanvas *c1 = new TCanvas("c1","Time on axis",10,10,1000,500);
   c1->SetFillColor(42);
   c1->SetFrameFillColor(33);
   c1->SetGrid();

   Float_t bintime = 1; //one bin = 1 second. change it to set the time scale
   TH1F *ht = new TH1F("ht","The ROOT seism",10,0,10*bintime);
   Float_t signal = 1000;
   ht->SetMaximum( signal);
   ht->SetMinimum(-signal);
   ht->SetStats(0);
   ht->SetLineColor(2);
   ht->GetXaxis()->SetTimeDisplay(1);
   ht->GetYaxis()->SetNdivisions(520);
   ht->Draw();

   for (Int_t i=1;i<2300;i++) {
      //======= Build a signal : noisy damped sine ======
      Float_t noise  = gRandom->Gaus(0,120);
      if (i > 700) noise += signal*sin((i-700.)*6.28/30)*exp((700.-i)/300.);
      ht->SetBinContent(i,noise);
      c1->Modified();
      c1->Update();
      gSystem->ProcessEvents(); //canvas can be edited during the loop
   }
   printf("Real Time = %8.3fs, Cpu Time = %8.3fs\n",sw.RealTime(),sw.CpuTime());
}
Пример #10
0
void PlotMinEtFromSim(Bool_t isPhos = kFALSE){
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  Float_t min = 0;
  float max = 1;
  TString filename, detname;
  if(isPhos){
    min = 0.655;
    max = 0.785;
    detname = "PHOS";
    filename = "rootFiles/LHC11a10a_bis/Et.ESD.simPbPb.PHOS.LHC11a10a_bis.Run139465.root";
  }
  else{
    min = 0.58;
    max = 0.725;
    filename = "rootFiles/LHC11a10a_bis/Et.ESD.simPbPb.EMCal.LHC11a10a_bis.Run139465.root";
    detname = "EMCal";
  }
  
  TFile *f = TFile::Open(filename, "READ");
  TList *l = dynamic_cast<TList*>(f->Get("out1"));
  TH1F *fHistSimulatedGammaEnergyAboveThreshold = l->FindObject("fHistSimulatedGammaEnergyAboveThreshold");
  TH1F *fHistSimulatedGammaEnergy = l->FindObject("fHistSimulatedGammaEnergy");
  SetStyles(fHistSimulatedGammaEnergyAboveThreshold,20,TColor::kRed);
  fHistSimulatedGammaEnergyAboveThreshold->Divide(fHistSimulatedGammaEnergy);

    TCanvas *c1 = new TCanvas("c1","Simulation",600,400);
    c1->SetTopMargin(0.02);
    c1->SetRightMargin(0.03);
    c1->SetLeftMargin(0.11745);
    c1->SetBottomMargin(0.11745);
    c1->SetBorderSize(0);
    c1->SetFillColor(0);
    c1->SetFillColor(0);
    c1->SetBorderMode(0);
    c1->SetFrameFillColor(0);
    c1->SetFrameBorderMode(0);
    fHistSimulatedGammaEnergyAboveThreshold->SetMaximum(max +0.1);
    fHistSimulatedGammaEnergyAboveThreshold->SetMinimum(min-0.1);
    fHistSimulatedGammaEnergyAboveThreshold->GetXaxis()->SetTitle("Centrality bin");
    fHistSimulatedGammaEnergyAboveThreshold->GetYaxis()->SetTitle("f_{minEt}");
    fHistSimulatedGammaEnergyAboveThreshold->GetYaxis()->SetLabelSize(0.06);
    fHistSimulatedGammaEnergyAboveThreshold->GetXaxis()->SetLabelSize(0.06);
    fHistSimulatedGammaEnergyAboveThreshold->GetYaxis()->SetTitleSize(0.06);
    fHistSimulatedGammaEnergyAboveThreshold->GetXaxis()->SetTitleSize(0.06);
    fHistSimulatedGammaEnergyAboveThreshold->Draw();
    TLine *lineMin = new TLine(-0.5,min,19.5,min);
    lineMin->Draw();
    TLine *lineMax = new TLine(-0.5,max,19.5,max);
    lineMax->Draw();
    lineMin->SetLineColor(TColor::kBlue);
    lineMax->SetLineColor(TColor::kBlue);
    lineMin->SetLineStyle(2);
    lineMax->SetLineStyle(2);

    TString outfile = "/tmp/MinEtFromSim"+detname+".png";
    c1->SaveAs(outfile.Data());
}
Пример #11
0
void draw_ratio(std::vector<TH1F*> h,
	  TString name, TString xTitle,
	  double xmin, double xmax,
	  TString legHeader = "", bool legRIGHT = true, bool legTOP = true,
	  bool logX = false, bool stat = false, int rebin = -1, int orbin = -1,
	  TString option = "", int nclus = 99) {  //double ymin_ratio, double ymax_ratio,
  TCanvas* can = new TCanvas(name+"_ratio",name+"_ratio",900,450);
  can->cd();

  double legxmin = (legRIGHT ? 0.55 : 0.18);
  double legxmax = legxmin+0.25;
  double legymin = (legTOP ? 0.70 : 0.15);
  double legymax = legymin+0.15;
  TLegend* leg = new TLegend(legxmin,legymin,legxmax,legymax);
  if (legHeader!="") leg->SetHeader(legHeader);
  leg->SetTextSize(0.04);
  leg->SetFillColor(0);
  leg->SetLineColor(0);

  TString options = (option=="" ? "pe" : option);

  if (rebin>0) h[h.size()-1]->Rebin(rebin); //to rebin benchmark before divide
  for (size_t i=0; i<h.size(); i++) {
    //if(h[i]->GetNbinsX() != orbin) cout << "WARNING: orbin for " << h[i]->GetName() << " are " << h[i]->GetNbinsX() << endl; //debug - shift of h[][] wrt clu[][]
    if (rebin>0 && i<(h.size()-1)) h[i]->Rebin(rebin);
    TH1F* ratio = (TH1F*)h[i]->Clone("ratio_"+name);
    ratio->Sumw2();
    ratio->Divide(h[h.size()-1]); //benchmark is at the end.

    if (logX) gPad->SetLogx();
    ratio->SetMarkerStyle(20+i);
    ratio->SetMarkerSize(1.0); //1.2
    ratio->GetXaxis()->SetRangeUser(xmin,xmax);
    ratio->SetMinimum(-0.1);
    ratio->SetMaximum(4);
    if (i==0){    //just for the first one
     ratio->GetXaxis()->SetLabelSize(0.05);
     ratio->GetXaxis()->SetTitle(xTitle);
     ratio->GetXaxis()->SetTitleOffset(1);
     ratio->GetXaxis()->SetTitleSize(0.06);
     ratio->GetYaxis()->SetTitle("ratio");
     ratio->GetYaxis()->SetTitleSize(0.06);
     ratio->GetYaxis()->SetTitleOffset(0.7);
     ratio->GetYaxis()->SetLabelSize(0.05);
    }
    string nam = "";
    nam = translate(clu[nclus][0].c_str());
    if(i==(h.size()-1)) leg->AddEntry(h[i],nam.c_str(),"l"); //to print only benchmark (first in the list)
    if (i==1) options = options + (stat ? "sames" : "same"); //once is enought
    ratio->Draw(options);
  }
  leg->Draw("same");
  drawPrivate(0.04);
  can->Update();
  can->SaveAs(Outfolder+name+"_ratio.png");
}
Пример #12
0
void CheckEHF()
{

 
  TH1F * HDat;
  TH1F * HDatnoPUAft;
  TH1F * HDatnoPUBef;

  //  TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root");
  TFile *fzee = new TFile("ZDiffOutputfile_Data2011_noPU.root");
  // TFile *fzee = new TFile("ZDiffOutputfile.root");
  HDat  =  (TH1F*)fzee->Get("NVTX1_minEHFZoom_DATA10");
  HDatnoPUAft  =  (TH1F*)fzee->Get("NVTX1noPUAft_minEHFZoom_DATA10");
  HDatnoPUBef  =  (TH1F*)fzee->Get("NVTX1noPUBef_minEHFZoom_DATA10");

  HDat->Scale(1./HDat->GetEntries());
  HDatnoPUAft->Add(HDatnoPUBef);
  HDatnoPUAft->Scale(1./HDatnoPUAft->GetEntries());
  HDatnoPUBef->Scale(1./HDatnoPUBef->GetEntries());
  HDatnoPUAft->SetMinimum(0.);
  NHSetMarker(HDatnoPUAft,2,20,0.8);
  NHSetLine(HDatnoPUAft,2,1,1.);
  HDatnoPUAft->Draw("E1");
  HDatnoPUAft->SetTitle("2011 Z->ee Data, minHF Energy");
  NSetTitle(HDatnoPUAft,"HF Energy [GeV]", "Fraction");


  NHSetMarker(HDatnoPUBef,6,20,0.8);
  NHSetLine(HDatnoPUBef,6,1,1.);
  // HDatnoPUBef->Draw("SAMEP");

  NHSetMarker(HDat,4,20,0.8);
  NHSetLine(HDat,1,1,1.);
  HDat->Draw("SAMEP");

  TLegend *legend = new TLegend(0.6,0.1,0.75,0.4);
  legend->SetTextFont(72);
  legend->SetTextSize(0.04);
  legend->SetBorderSize(0);

  legend->AddEntry(HDatnoPUBef,"No PU before or after","p");
  //  legend->AddEntry(HDatnoPUBef,"No PU before","p");
  // legend->AddEntry(HDatnoPUAft,"No PU after","p");
  legend->AddEntry(HDat,"PU before && after","p");
  legend->Draw();






  //  NHSetLine(HDatnoPUBef,3,2,1.);
  // HDatnoPUBef->Draw("SAME HIST");

}
Пример #13
0
//------------------------------------//
// Main
//------------------------------------//
void AnaEField()
{

  // Make Canvas 
  TCanvas* can = makeCanvas("can");
  can->SetLogy();
  can->SetGridx();
  can->SetGridy();

  // Define the function here with parameters:
  // [0] = L
  // [1] = freq
  // [2] = k
  // [3] = n
  // [4] = sqrt(2pi) * mu * mu0
  TString func = "[4]*[0]*[1]*sin(x/57.2957)*exp(-pow([2]*[0],2)*pow(cos(x/57.2957)-1/[3],2)/2)";
  //TString func = "[4]*[1]*sin(x/57.2957)*exp(-pow([2]*[0],2)*pow(cos(x/57.2957)-1/[3],2)/2)";
  //TString func = "[4]*[0]*[1]*exp(-pow([2]*[0],2)*pow(cos(x/57.2957)-1/[3],2)/2)";

  // Now fix some of the variables:
  double freq = 1e9; //600e6; // Hz
  double c    = 3e8;   // m/s
  double n    = 1.3; //1.78;
  double k    = 2*TMath::Pi() * n * freq/c; // 1/m
  double Const= sqrt(2*TMath::Pi()) * 4 * TMath::Pi() * 1e-7 * 1;

  // Make a dummy histogram
  TH1F* h = makeHist("h",100,0,90,"Angle [deg]", "Field Strength",kBlack,0);
  h->Fill(1e10);
  h->SetMinimum(10);
  h->SetMaximum(3000);
  h->Draw();

  // Make two instances of the function
  TF1* f0 = new TF1("f0",func.Data(),0,90);
  setParam(f0,1.2,freq,k,n,Const,kBlack);

  TF1* f1 = new TF1("f1",func.Data(),0,90);
  setParam(f1,0.1,freq,k,n,Const,kBlue);
 
  // Draw
  f0->Draw("same");
  f1->Draw("same");
  
  // Add Legend
  TLegend* leg = makeLegend(0.15,0.3,0.7,0.9);
  leg->SetHeader("f = 600 MHz");
  leg->AddEntry(f0,"L = 1.2m","l");
  leg->AddEntry(f1,"L = 0.1m","l");
  leg->Draw("same");
  
  //can->SaveAs("../plots/quickAnalytic_600MHz.png");

}
Пример #14
0
void FillGoodRun(int ihar){
    float pi = acos(-1.0);
    TString str;
    TFile *fin;
    int nrun = GetTotalRun();
    if(nrun<0) exit(1);
     for(int icent=0;icent<ncent;icent++){
 //     for(int ihar=0;ihar<nhar;ihar++){
 //         if(ihar!=1) continue;
       for(int isub=0;isub<nsub;isub++){
            str = choosesub(isub);
            if(str=="ABORT") continue;
            for(int irun=0;irun<nrun;irun++){
      //std::cout<<icent<<" "<<ihar<<" "<<isub<<" "<<irun<<std::endl;
        //fin = TFile::Open(Form("/phenix/plhf/xuq/taxi/%s%s/%d/data/%s.root",dataset.Data(),pro.Data(),taxi,GetRun(irun).Data()));
         fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/62GeV/output/%s",GetRun(irun).Data()));
        TH1F* hpsi = new TH1F("psi","psi",100,-pi,pi);
        for(int ibbcz=0;ibbcz<nbbcz;ibbcz++){
          TH1F* hpsitemp = (TH1F*)fin->Get(Form("psiFla_0_0_%d_%d_%d_%d",icent,ibbcz,ihar,isub));
          hpsi->Add(hpsitemp);
        }
        TF1 *fun = new TF1("fun","pol0",-pi,pi);
      if(hpsi->GetEntries()>1000){
	//hpsi->SetMarkerStyle(20);
	//hpsi->SetMarkerSize(0.6);
	//hpsi->SetMarkerColor(4);
	hpsi->SetMinimum(10);
	hpsi->Fit("fun","QR0");
	//float par=fun->GetParameter(0);
	//hpsi->SetMaximum(1.5*par);
	//hpsi->Draw();
	GoodRunFit[icent][ihar][isub][irun] = fun->GetChisquare()/fun->GetNDF();
        fin->Close();
      }
      else{
        GoodRunFit[icent][ihar][isub][irun] = -9999;
        fin->Close();
     }
     // GoodRunFit[icent][ihar][isub][irun] = 1.;
    }
       }
   //   }
     }
}
Пример #15
0
CheckEnabledChannels(const Char_t *runlist)
{

  ifstream is(runlist);
  Char_t buf[4096];
  Int_t run[1024];
  Int_t nrun = 0;
  while(!is.eof()) {
    is.getline(buf, 4096);
    if (is.eof()) break;
    run[nrun] = atoi(buf);
    printf("added run number %d\n", run[nrun]);
    nrun++;
  }
  printf("%d runs added\n", nrun);
  is.close();

  TH1F *hActive = new TH1F("hActive", "active channels;run;fraction", nrun, 0, nrun);
  TH1F *hReadout = new TH1F("hReadout", "good readout;run;fraction", nrun, 0, nrun);
  for (Int_t irun = 0; irun < nrun; irun++) {
    hr = CheckEnabledChannels(run[irun], kTRUE);
    ha = CheckEnabledChannels(run[irun], kFALSE);
    hReadout->SetBinContent(irun + 1, hr->Integral());
    hActive->SetBinContent(irun + 1, ha->Integral());
    hReadout->GetXaxis()->SetBinLabel(irun + 1, Form("%d", run[irun]));
    delete hr; delete ha;
  }
  
  hReadout->SetMarkerStyle(20);
  hReadout->SetMarkerColor(4);
  hActive->SetMarkerStyle(25);
  hActive->SetMarkerColor(2);
  hReadout->Sumw2();
  hActive->Sumw2();
  hReadout->Divide(hReadout, hActive, 1., 1., "B");
  hActive->Scale(1. / 152928.);
  hReadout->SetMinimum(0.);
  hReadout->SetMaximum(1.);
  hReadout->Draw("E");
  hActive->Draw("E, same");
  TLegend *l = gPad->BuildLegend();
  l->SetFillStyle(0);

}
Пример #16
0
void FillGoodRun(int icent,int ihar){
    float pi = acos(-1.0);
    TString str;
    TFile *fin;
    int nrun = GetTotalRun();
    if(nrun<0) exit(1);
       for(int isub=0;isub<nsub;isub++){
            str = choosesub(isub);
            if(str=="ABORT") continue;
            for(int irun=0;irun<nrun;irun++){
      std::cout<<icent<<" "<<ihar<<" "<<isub<<" "<<irun<<std::endl;
         fin = TFile::Open(Form("/store/user/qixu/flow/Run16dAu/62GeV/%s",GetRun(irun).Data()));
        TH1F* hpsi = new TH1F("psi","psi",100,-pi,pi);
        for(int ibbcz=0;ibbcz<nbbcz;ibbcz++){
          TH1F* hpsitemp = (TH1F*)fin->Get(Form("psiFla_%d_%d_%d_%d",icent,ibbcz,ihar,isub));
          hpsi->Add(hpsitemp);
        }
        TF1 *fun = new TF1("fun","pol0",-pi,pi);
      if(hpsi->GetEntries()>1000){
	//hpsi->SetMarkerStyle(20);
	//hpsi->SetMarkerSize(0.6);
	//hpsi->SetMarkerColor(4);
	hpsi->SetMinimum(10);
	hpsi->Fit("fun","QR0");
	//float par=fun->GetParameter(0);
	//hpsi->SetMaximum(1.5*par);
	//hpsi->Draw();
	GoodRunFit[icent][ihar][isub][irun] = fun->GetChisquare()/fun->GetNDF();
        fin->Close();
      }
      else{
        GoodRunFit[icent][ihar][isub][irun] = -9999;
        fin->Close();
     }
     // GoodRunFit[icent][ihar][isub][irun] = 1.;
    }
       }
}
Пример #17
0
void drawEmptyHisto ( float Xmin, float Xmax, TString xTitle, float Ymin, float Ymax, TString yTitle, TString name )
{
    printf ( "Setting empty histo: X: %.2f-%.2f\tY: %.2f-%.2f\n",Xmin,Xmax,Ymin,Ymax );
    printf("Total luminosity to be plotted: %.3f\n",Xmax);
    printf("Luminosity scale used: %.2f\n",lumiScale);

    Xmax*=1.02;	  // Increasing max lumi to have free space
    gStyle->SetOptStat ( 0 );
    //    TGaxis::SetMaxDigits ( 4 );

    TH1F *histo = new TH1F ( name, xTitle, 1, Xmin, Xmax );
    TAxis *xAx = histo->GetXaxis();
    TAxis *yAx = histo->GetYaxis();
    xAx->SetTitle ( xTitle );
    //    xAx->SetTitleOffset ( 1.1 );
    //    xAx->SetNdivisions ( 510 );
    yAx->SetTitle ( yTitle );
    //    yAx->SetTitleOffset ( 1.15 );
    //    yAx->SetNdivisions ( 510 );
    histo->SetMinimum ( Ymin );
    histo->SetMaximum ( Ymax );
    histo->Draw ( "AXIS" );
}
Пример #18
0
float GoodRun(int icent, int ihar, int isub, int irun){
    float pi = acos(-1);
    TF1 *fun = new TF1("fun","pol0",-pi,pi);
    TString str;
    TFile *fin;

     ofstream fout;
        if(isub==1){
         str = "FVTX1S";
        }
        else if(isub==2){
         str = "FVTX2S";
        }
        else return -9999;
         fin = TFile::Open(Form("Run15pAu200MinBias/output_fvtxwithcntEP_%d.root",GetRun(irun)));
        TH1F* hpsi = new TH1F("psi","psi",100,-pi,pi);
        for(int ibbcz=0;ibbcz<nbbcz;ibbcz++){
          hpsitemp = (TH1F*)fin->Get(Form("psi_%d_%d_%d_%d",icent,ibbcz,ihar,isub));
          hpsi->Add(hpsitemp);
        }
      if(hpsi->GetEntries()>10000){
	hpsi->SetMarkerStyle(20);
	hpsi->SetMarkerSize(0.6);
	hpsi->SetMarkerColor(4);
	hpsi->SetMinimum(10);
	hpsi->Fit("fun","QR0");
	float par=fun->GetParameter(0);
	hpsi->SetMaximum(1.5*par);
	//hpsi->Draw();
        fin->Close();
	return fun->GetChisquare()/fun->GetNDF();
      }
      else{
        fin->Close();
        return -9999;
      }
    }
Пример #19
0
/*#include <TSystem.h>                      // interface to OS
#include <TStyle.h>                       // class to handle ROOT plotting styles#include <TFile.h>                        // file handle class
#include <TTree.h>                        // class to access ntuples
#include <TBenchmark.h>                   // class to track macro running statistics
#include <TH1D.h>                         // histogram class
#include <vector>                         // STL vector class
#include <iostream>                       // standard I/O
#include <iomanip>                        // functions to format standard I/O
#include <fstream>                        // functions for file I/O
#include <string>                         // C++ string class
#include <sstream>                        // class for parsing strings
#include <TRandom3.h>
#include <TGaxis.h>
#include "Math/LorentzVector.h"           // 4-vector class

#include "../Utils/MyTools.hh"            // various helper functions
#include "../Utils/CPlot.hh"              // helper class for plots
#include "../Utils/MitStyleRemix.hh"      // style settings for drawing
#include "../Utils/WModels.hh"            // definitions of PDFs for fitting
#include "../Utils/RecoilCorrector.hh"    // class to handle recoil corrections for MET
*/
void W_MET_Ratio()
{
  TCanvas *c = new TCanvas("c","c",800,800);
  c->Divide(1,2,0,0);
  c->cd(1)->SetPad(0,0.3,1.0,1.0);
  c->cd(1)->SetTopMargin(0.1);
  c->cd(1)->SetBottomMargin(0.01);
  c->cd(1)->SetLeftMargin(0.15);
  c->cd(1)->SetRightMargin(0.07);  
  c->cd(1)->SetTickx(1);
  c->cd(1)->SetTicky(1);  
  c->cd(2)->SetPad(0,0,1.0,0.3);
  c->cd(2)->SetTopMargin(0.05);
  c->cd(2)->SetBottomMargin(0.45);
  c->cd(2)->SetLeftMargin(0.15);
  c->cd(2)->SetRightMargin(0.07);
  c->cd(2)->SetTickx(1);
  c->cd(2)->SetTicky(1);
  c->cd(2)->SetGridy();

  TLegend * lgc = new TLegend(0.59, 0.67, 0.89, 0.89);
  lgc->SetTextSize(0.03);
  lgc->SetBorderSize(0);
  lgc->SetFillColor(0);

//  TFile *file = new TFile("../ElectronHighPU/Ele_RD_HighPU_A_Analysis.root");
  TFile *file = new TFile("./ElectronHighPU_N/Ele_WToENu_S10_Analysis.root");
 
///////////////Original Plot////////////////////////
  c->cd(1);
  lgc->AddEntry(h1_W_Neut_pt1,"UnCorrected");
  h1_W_Neut_pt1->SetYTitle("Events");
  h1_W_Neut_pt1->SetFillColor(kWhite);
  h1_W_Neut_pt1->SetMarkerColor(kBlack);
  h1_W_Neut_pt1->SetMarkerStyle(1);
  h1_W_Neut_pt1->SetLineWidth(2);
  h1_W_Neut_pt1->Draw();
  lgc->AddEntry(h1_W_Neut_pt_Corr,"Corrected");
  h1_W_Neut_pt_Corr->SetLineColor(kRed);
  h1_W_Neut_pt_Corr->SetFillColor(kWhite);
  h1_W_Neut_pt_Corr->SetMarkerColor(kRed);
  h1_W_Neut_pt_Corr->SetMarkerStyle(1);
  h1_W_Neut_pt_Corr->SetLineWidth(2);
  h1_W_Neut_pt_Corr->Draw("same");
  lgc->Draw();
///////////////////////////////////////////////////////
  
  c->cd(2);

  TH1F * h1_Ori = (TH1F*)file->Get("h1_W_Neut_pt1");
  TH1F * h1_Corr = (TH1F*)file->Get("h1_W_Neut_pt_Corr");

  int Nbins = h1_Ori->GetNbinsX();
  TH1F * ratio = new TH1F("ratio","", Nbins, h1_Ori->GetXaxis()->GetXmin(), h1_Ori->GetXaxis()->GetXmax());
  ratio->Divide(h1_Ori, h1_Corr);
  ratio->SetXTitle("N_vtx");
  ratio->SetMaximum(2);
  ratio->SetMinimum(0);
  ratio->SetNdivisions(10,"X");
  ratio->SetNdivisions(4,"Y");
  ratio->SetLabelSize(0.09,"XY");
  ratio->SetTitleSize(0.12,"X"); 
  ratio->SetMarkerStyle(20);
  ratio->SetMarkerSize(0.7);
  ratio->SetMarkerColor(kBlue);
  ratio->Draw("P");

//  c->SaveAs("W_MET_Ratio_RD.png");
  c->SaveAs("W_MET_Ratio_MC.png");
}
Пример #20
0
int fitCorr_E(){
 
  TFile *f = new TFile("./histCorrections_E.root","read");  

  TH1F *hEB = (TH1F*)f->Get("h_CBE_EB");
  TH1F *hEE = (TH1F*)f->Get("h_CBE_EE");
  
  gROOT->SetStyle("Plain");
  
  TCanvas *c = new TCanvas("c","c",1200,600);
  c->Divide(2,1);
//   c->cd(1);
//   hEB->SetMinimum(0.97);
//   hEB->Draw();
//   TF1 * fEB = new TF1("fEB","([0]+x*[3])*(1-[2]*exp(x/[1]))",0,250);
//   fEB->SetParameters(1,-1,1,1);
//   hEB->Fit("fEB","","same",10,80);  
//   hEB->Fit("fEB","","same",10,200);  

  // Write out the correction for the EB
  ofstream outfile;  
  TString filename = "./corrections_E.C";
  outfile.open(filename);

//   outfile << " Double_t applyScCorrectionsE_EB(Double_t E){      " << endl;    
//   outfile << "   				 	  " << endl;
//   outfile << "   if (E > 200) E =200;   		  " << endl;  
//   outfile << "   if (             E <    5 ) return         1.;  " << endl;
//   outfile << "   if (  5 <= E && E <   10 ) return         " << hEB->GetBinContent(0*1+1) << ";  " << endl;
//   outfile << "   if ( 10 <= E && E <= 200 ) return         (" << fEB->GetParameter(0) << " + E*" << fEB->GetParameter(3) << ")*(1-"<< fEB->GetParameter(2) 
// 	  <<"*exp(E/"<< fEB->GetParameter(1)<<  "));" << endl;
//   outfile << " 						  " << endl;
//   outfile << " }                                           " << endl;
//   outfile << "                					        " << endl;
//   outfile << " Double_t F_applyScCorrectionsE_EB(Double_t *xx, Double_t *pp){  " << endl;        
//   outfile << "   Double_t x = xx[0] ;                     " << endl;
//   outfile << "   return applyScCorrectionsE_EB(x);    		  " << endl;
//   outfile << " }		                          " << endl;
//   outfile << "  		                          " << endl;
  
  c->cd(2);
  hEE->SetMaximum(1.02);
  hEE->SetMinimum(0.92);
  hEE->Draw();
  
  TF1 * fEE = new TF1("fEE","pol1",0,5000);
  fEE->SetParameters(1,1);
  hEE->Fit("fEE","","same",10,80);  
  hEE->Fit("fEE","","same",10,200);  
  hEE->Fit("fEE","","same",10,850);  
  
  Double_t upperLimit =  (1- fEE->GetParameter(0) ) /  fEE->GetParameter(1);
  
  outfile << "Double_t applyScCorrectionsE_EE(Double_t E){      " << endl;    
  outfile << "  				 	  " << endl;
  outfile << " Double_t par0 = 850;               " << endl; 
  outfile << " Double_t par1 = " << fEE->GetParameter(0) << " ;	  " << endl;
  outfile << " Double_t par2 = " << fEE->GetParameter(1) << " ;     " << endl;
  outfile << "  				 	  " << endl;
  outfile << "  if (E  > par0 ) E = par0 ;   		  " << endl;  
  outfile << "  if (            E <   0     ) return      1.;  " << endl;
  outfile << "  if (  0 <= E && E <=  par0  ) return      par1 + E*par2; " << endl;
  outfile << "						   " << endl;
  outfile << "}                                           " << endl;
  outfile << "               					        " << endl;
  outfile << "Double_t F_applyScCorrectionsE_EE(Double_t *xx, Double_t *pp){  " << endl;        
  outfile << "  Double_t x = xx[0] ;                     " << endl;
  outfile << "  return applyScCorrectionsE_EE(x);    		  " << endl;
  outfile << "}		                          " << endl;
  outfile.close();
  
  return 0;
}
Пример #21
0
void  peakOverlay(bool allpk=0, int ipeak=3) {

  double normalization = allpk?0.5:1.0;  // rapidity normalization -- note normalization values are set by hand at the moment 

  gROOT->LoadMacro("setTDRStyle_modified.C");
  setTDRStyle();

  if(allpk)
    assert(!ipeak);
  else
    assert(ipeak);
    
  const int ngr = allpk?3:2;
  
  TString path("mode");
  if(allpk) path+="0";
  else    path+="1";
  path+="/";
  

  TString title[ngr];
  if(allpk) {
    title[0] = "#Upsilon(1S)"; title[1] = "#Upsilon(2S)"; title[2] = "#Upsilon(3S)";
  } else {
    title[0] = "    |y|<1"; title[1]="1<|y|<2";
  }
  
  TString nfile[ngr];
  for(int i=0; i<ngr; i++)
    if(allpk)
      nfile[i] = TString::Format("%sxsection_%ds_y0.root",path.Data(),i+1);
    else 
      nfile[i] = TString::Format("%sxsection_%ds_y%d.root",path.Data(),ipeak,i);

  TFile* file[ngr];
  for(int i=0; i<ngr; i++)
    file[i] = TFile::Open(nfile[i],"read");
  
  TGraphAsymmErrors* gr[ngr], *grsta[ngr], *grsys[ngr];
  enum unc {all,sys,sta,cen};

  TFile* file[ngr];
  for(int i=0; i<ngr; i++) {
    file [i] = TFile::Open(nfile[i],"read");  
    gr   [i] = (TGraphAsymmErrors*)((TMultiGraph*)file[i]->Get("mg1"))->GetListOfGraphs()->At(all);//all
    grsys[i] = (TGraphAsymmErrors*)((TMultiGraph*)file[i]->Get("mg1"))->GetListOfGraphs()->At(sys);//all but lumi
    grsta[i] = (TGraphAsymmErrors*)((TMultiGraph*)file[i]->Get("mg1"))->GetListOfGraphs()->At(sta);//sta
  }
  
  for(int i=0; i<ngr; i++) {
    normalize(gr   [i],normalization);
    normalize(grsta[i],normalization);
    normalize(grsys[i],normalization);
  }

  TPaveText *tp = new TPaveText(0.5,0.8,0.8,0.9,"brNDC");
  tp->SetBorderSize(0);
  tp->AddText("CMS,  #sqrt{s} = 7 TeV");
  if(allpk)
    tp->AddText("L = 3 pb^{-1},  |y|<2");
  else {
    tp->AddText("L = 3 pb^{-1}");
  }

  TPaveText *tpp = new TPaveText(0.75,0.5,0.86,0.6,"brNDC");
  tpp->SetBorderSize(0);
  tpp->AddText(TString::Format("#Upsilon(%dS)",ipeak)); 

  
  TLegend *leg;
  if(allpk)
    leg = new TLegend(0.7,0.6,0.9,0.75);	
  else
    leg = new TLegend(0.7,0.65,0.9,0.75);
	
  int marker[]={21,24,22};
  for(int i=0; i<ngr; i++) {
    //these are needed, unless we re-run xsecresults with newstyle
    gr[i]->SetMarkerSize (1.4);
    if(i==2)
      gr[i]->SetMarkerSize (1.7);
    gr[i]->SetMarkerColor(13);
    //gr[i]->SetMarkerColor(2+2*i);
    //gr[i]->SetLineColor  (2+2*i);
    gr[i]->SetMarkerStyle(marker[i]);
    //gr[i]->SetMarkerStyle(27-3*i);
    leg->AddEntry(gr[i],title[i],"lpe");
  }

  if(!allpk) {
    //gr[0]->SetMarkerSize (1.4);
    //  gr[1]->SetMarkerSize (1.4);
  //gr[1]->SetFillColor(0.);
  }
  TCanvas a;
  TH1F *hh = gPad->DrawFrame(0.001,0,30,1);

  for(int i=0; i<ngr; i++) {
    grsta[i]->SetLineColor  (38);
    grsta[i]->SetMarkerColor(38);
    grsta[i]->SetFillColor  (38);
    grsta[i]->SetMarkerStyle(21);
    grsta[i]->SetMarkerSize(0.8);

    grsys[i]->SetLineColor  (kRed);
    grsys[i]->SetMarkerColor(kRed);
    grsys[i]->SetMarkerStyle(25);	
    grsys[i]->SetMarkerSize(0.8);	
    grsys[i]->SetFillStyle(0);    	
    grsys[i]->SetLineWidth(2);
  }

  for(int i=0; i<ngr; i++) {
    gr   [i]->Draw("e0");
    grsys[i]->Draw("[]");
    gr   [i]->Draw("pxy");
    //grsta[i]->Draw("e2"); //disabled, to simplify plot
  }

  double dummyx[1] = {0.}, dummyy[1] = {0.};
  dummy = new TGraph(1, dummyx, dummyy);

  TLegend *uleg = new TLegend(0.15,0.2,0.45,0.3);	
  //uleg->AddEntry(gr[0],"total uncertainty","p");
  //uleg->AddEntry(grsta[0],"stat. unc.","p");
  uleg->AddEntry(grsys[0],"total unc. except","p");
  //uleg->AddEntry(dummy,"global lumi unc. (11%)","e0");
  uleg->AddEntry(dummy,"luminosity (11%)","e0");
  uleg->Draw();

  leg->Draw();
  tp->Draw();
  if(!allpk)
    tpp->Draw();

  hh->GetYaxis()->SetTitleOffset(1.08); //needed
  hh->GetYaxis()->SetLabelSize(0.0475); //0.05
  //hh->GetXaxis()->SetLabelSize(0.045); //for consistency with y
  hh->GetYaxis()->SetTitleSize(0.055); //needed to fit...

  //TString ytitle = 
  TString ytitle;
  if(allpk)
    if(absrap)
      ytitle = TString::Format("d^{2}#sigma/dp_{T}d|y| #times #Beta(#mu#mu) (nb/(GeV/c))");
    else
      ytitle = TString::Format("d^{2}#sigma/dp_{T}dy #times #Beta(#mu#mu) (nb/(GeV/c))");
  else
    if(absrap)
      ytitle = TString::Format("d^{2}#sigma/dp_{T}d|y| #times #Beta(#mu#mu) (nb/(GeV/c))");
    else
      ytitle = TString::Format("d^{2}#sigma/dp_{T}dy #times #Beta(#mu#mu) (nb/(GeV/c))");

  hh->GetYaxis()->SetTitle(ytitle);
  hh->GetXaxis()->SetTitle("p_{T}^{#Upsilon} (GeV/c)");
  if(absrap)
    hh->SetMinimum(0.0005);
  else
    hh->SetMinimum(0.0002);
  hh->SetMaximum(1.0001);
  hh->GetXaxis()->SetRangeUser(0,30);
  
  gPad->SetLogy();
  
  TString pname;
  if(allpk)
    pname = TString::Format("xsec_overlay");
  else
    pname = TString::Format("xsec_%ds_2ybin",ipeak);

  a.SaveAs(path+pname + ".pdf");
  a.SaveAs(path+pname + ".gif");
  
  for(int i=0; i<ngr; i++)
    file[i]->Close();

  return;
}
Пример #22
0
void 
HTT_MT_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="muTau_$CATEGORY")
{
  // defining the common canvas, axes pad styles
  SetStyle(); gStyle->SetLineStyleString(11,"20 10");

  // determine category tag
  const char* category_extra = "";
  if(std::string(directory) == std::string("muTau_0jet_low"  )){ category_extra = "0 jet, low p_{T}";  }
  if(std::string(directory) == std::string("muTau_0jet_high" )){ category_extra = "0 jet, high p_{T}"; }
  if(std::string(directory) == std::string("muTau_boost_low" )){ category_extra = "1 jet, low p_{T}";  }
  if(std::string(directory) == std::string("muTau_boost_high")){ category_extra = "1 jet, high p_{T}"; }
  if(std::string(directory) == std::string("muTau_vbf"       )){ category_extra = "2 jet (VBF)";       }
  if(std::string(directory) == std::string("muTau_nobtag"    )){ category_extra = "No B-Tag";          }
  if(std::string(directory) == std::string("muTau_btag"      )){ category_extra = "B-Tag";             }

  const char* dataset;
  if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV";}
  if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV";}
#ifdef MSSM
  if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 12.1 fb^{-1} at 8 TeV";}
#endif
 
  // open example histogram file
  TFile* input = new TFile(inputfile);
  TH1F* Fakes  = refill((TH1F*)input->Get(TString::Format("%s/QCD"   , directory)), "QCD"); InitHist(Fakes, "", "", kMagenta-10, 1001);
  TH1F* EWK1   = refill((TH1F*)input->Get(TString::Format("%s/W"     , directory)), "W"  ); InitHist(EWK1 , "", "", kRed    + 2, 1001);
#ifdef EXTRA_SAMPLES
  TH1F* EWK2   = refill((TH1F*)input->Get(TString::Format("%s/ZJ"    , directory)), "ZJ" ); InitHist(EWK2 , "", "", kRed    + 2, 1001);
  TH1F* EWK3   = refill((TH1F*)input->Get(TString::Format("%s/ZL"    , directory)), "ZL" ); InitHist(EWK3 , "", "", kRed    + 2, 1001);
#else
  TH1F* EWK2   = refill((TH1F*)input->Get(TString::Format("%s/ZLL"   , directory)), "ZLL"); InitHist(EWK2 , "", "", kRed    + 2, 1001);
#endif
  TH1F* EWK    = refill((TH1F*)input->Get(TString::Format("%s/VV"    , directory)), "VV" ); InitHist(EWK  , "", "", kRed    + 2, 1001);
  TH1F* ttbar  = refill((TH1F*)input->Get(TString::Format("%s/TT"    , directory)), "TT" ); InitHist(ttbar, "", "", kBlue   - 8, 1001);
  TH1F* Ztt    = refill((TH1F*)input->Get(TString::Format("%s/ZTT"   , directory)), "ZTT"); InitHist(Ztt  , "", "", kOrange - 4, 1001);
#ifdef MSSM
  float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=20, A + H for the time being
  if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = ( 9157.9*0.119 + 10180.7*0.120)/1000.;
                                                             bbHScale = (23314.3*0.119 + 21999.3*0.120)/1000.; }
  if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (11815.3*0.119 + 13124.9*0.120)/1000.;
                                                             bbHScale = (31087.9*0.119 + 29317.8*0.120)/1000.; }
 //  float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=10, A + H for the time being
//   if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = (2111.4*0.11 + 4022.9*0.11)/1000.;
//                                                               bbHScale = (6211.6*0.11 + 5147.0*0.11)/1000.; }
//   if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (2729.9*0.11 + 5193.2*0.11)/1000.;
//                                                               bbHScale = (8282.7*0.11 + 6867.8*0.11)/1000.; }
  TH1F* ggH    = refill((TH1F*)input->Get(TString::Format("%s/ggH160", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(ggHScale);
  TH1F* bbH    = refill((TH1F*)input->Get(TString::Format("%s/bbH160", directory)), "bbH"); InitSignal(bbH); bbH ->Scale(bbHScale);
#else
#ifndef DROP_SIGNAL
  TH1F* ggH    = refill((TH1F*)input->Get(TString::Format("%s/ggH125", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(SIGNAL_SCALE);
  TH1F* qqH    = refill((TH1F*)input->Get(TString::Format("%s/qqH125", directory)), "qqH"); InitSignal(qqH); qqH ->Scale(SIGNAL_SCALE);
  TH1F* VH     = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH  ->Scale(SIGNAL_SCALE);
#endif
#endif
  TH1F* data   = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true);
  InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data);

  TH1F* ref=(TH1F*)Fakes->Clone("ref");
  ref->Add(EWK1 );
  ref->Add(EWK2 );
#ifdef EXTRA_SAMPLES
  ref->Add(EWK3 );
#endif
  ref->Add(EWK  );
  ref->Add(ttbar);
  ref->Add(Ztt  );

  double unscaled[7];
  unscaled[0] = Fakes->Integral();
  unscaled[1] = EWK  ->Integral();
  unscaled[1]+= EWK1 ->Integral();
  unscaled[1]+= EWK2 ->Integral();
#ifdef EXTRA_SAMPLES
  unscaled[1]+= EWK3 ->Integral();
#endif
  unscaled[2] = ttbar->Integral();
  unscaled[3] = Ztt  ->Integral();
#ifdef MSSM
  unscaled[4] = ggH  ->Integral();
  unscaled[5] = bbH  ->Integral();
  unscaled[6] = 0;
#else
#ifndef DROP_SIGNAL
  unscaled[4] = ggH  ->Integral();
  unscaled[5] = qqH  ->Integral();
  unscaled[6] = VH   ->Integral();
#endif
#endif

  if(scaled){
    rescale(Fakes, 7); 
    rescale(EWK1 , 3); 
    rescale(EWK2 , 4); 
#ifdef EXTRA_SAMPLES
    rescale(EWK3 , 5);
#endif 
    rescale(EWK  , 6); 
    rescale(ttbar, 2); 
    rescale(Ztt  , 1);
#ifdef MSSM
    rescale(ggH  , 8); 
    rescale(bbH  , 9);  
#else
#ifndef DROP_SIGNAL
    rescale(ggH  , 8); 
    rescale(qqH  , 9);  
    rescale(VH   ,10);  
#endif
#endif
  }

  TH1F* scales[7];
  scales[0] = new TH1F("scales-Fakes", "", 7, 0, 7);
  scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.);
  scales[1] = new TH1F("scales-EWK"  , "", 7, 0, 7);
  scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK  ->Integral()
					       +EWK1 ->Integral()
					       +EWK2 ->Integral()
#ifdef EXTRA_SAMPLES
					       +EWK3 ->Integral()
#endif
						)/unscaled[1]-1.) : 0.);
  scales[2] = new TH1F("scales-ttbar", "", 7, 0, 7);
  scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.);
  scales[3] = new TH1F("scales-Ztt"  , "", 7, 0, 7);
  scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt  ->Integral()/unscaled[3]-1.) : 0.);
#ifdef MSSM
  scales[4] = new TH1F("scales-ggH"  , "", 7, 0, 7);
  scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH  ->Integral()/unscaled[4]-1.) : 0.);
  scales[5] = new TH1F("scales-bbH"  , "", 7, 0, 7);
  scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH  ->Integral()/unscaled[5]-1.) : 0.);
  scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7);
  scales[6]->SetBinContent(7, 0.);
#else
#ifndef DROP_SIGNAL
  scales[4] = new TH1F("scales-ggH"  , "", 7, 0, 7);
  scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH  ->Integral()/unscaled[4]-1.) : 0.);
  scales[5] = new TH1F("scales-qqH"  , "", 7, 0, 7);
  scales[5]->SetBinContent(6, unscaled[5]>0 ? (qqH  ->Integral()/unscaled[5]-1.) : 0.);
  scales[6] = new TH1F("scales-VH"   , "", 7, 0, 7);
  scales[6]->SetBinContent(7, unscaled[6]>0 ? (VH   ->Integral()/unscaled[6]-1.) : 0.);
#endif
#endif

  EWK1 ->Add(Fakes);
  EWK2 ->Add(EWK1 );
#ifdef EXTRA_SAMPLES
  EWK3 ->Add(EWK2 );
  EWK  ->Add(EWK3 );
#else
  EWK  ->Add(EWK2 );
#endif
  ttbar->Add(EWK  );
  Ztt  ->Add(ttbar);
  if(log){
#ifdef MSSM
    ggH  ->Add(bbH);
#else
#ifndef DROP_SIGNAL
    qqH  ->Add(VH );
    ggH  ->Add(qqH);
#endif
#endif
  }
  else{
#ifdef MSSM    
    bbH  ->Add(Ztt);
    ggH  ->Add(bbH);
#else
#ifndef DROP_SIGNAL
    VH   ->Add(Ztt);
    qqH  ->Add(VH );
    ggH  ->Add(qqH);
#endif
#endif
  }

  /*
    Mass plot before and after fit
  */
  TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600);

  canv->cd();
  if(log){ canv->SetLogy(1); }
#if defined MSSM
  if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); };
#else
  data->GetXaxis()->SetRange(0, data->FindBin(350));
#endif
  data->SetNdivisions(505);
  data->SetMinimum(min);
  data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log)));
  data->Draw("e");

  TH1F* errorBand = (TH1F*)Ztt ->Clone();
  errorBand  ->SetMarkerSize(0);
  errorBand  ->SetFillColor(1);
  errorBand  ->SetFillStyle(3013);
  errorBand  ->SetLineWidth(1);
  for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){
    if(errorBand->GetBinContent(idx)>0){
      std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl;
      break;
    }
  }
  if(log){
    Ztt  ->Draw("histsame");
    ttbar->Draw("histsame");
    EWK  ->Draw("histsame");
    Fakes->Draw("histsame");
    $DRAW_ERROR
#ifndef DROP_SIGNAL
    ggH  ->Draw("histsame");
#endif
  }
  else{
#ifndef DROP_SIGNAL
    ggH  ->Draw("histsame");
#endif
    Ztt  ->Draw("histsame");
    ttbar->Draw("histsame");
    EWK  ->Draw("histsame");
    Fakes->Draw("histsame");
    $DRAW_ERROR
  }
  data->Draw("esame");
  canv->RedrawAxis();

  //CMSPrelim(dataset, "#tau_{#mu}#tau_{h}", 0.17, 0.835);
  CMSPrelim(dataset, "", 0.16, 0.835);  
  TPaveText* chan     = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC");
  chan->SetBorderSize(   0 );
  chan->SetFillStyle(    0 );
  chan->SetTextAlign(   12 );
  chan->SetTextSize ( 0.05 );
  chan->SetTextColor(    1 );
  chan->SetTextFont (   62 );
  chan->AddText("#mu#tau_{h}");
  chan->Draw();

  TPaveText* cat      = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC");
  cat->SetBorderSize(   0 );
  cat->SetFillStyle(    0 );
  cat->SetTextAlign(   12 );
  cat->SetTextSize ( 0.05 );
  cat->SetTextColor(    1 );
  cat->SetTextFont (   62 );
  cat->AddText(category_extra);
  cat->Draw();

#ifdef MSSM
  TPaveText* massA      = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC");
  massA->SetBorderSize(   0 );
  massA->SetFillStyle(    0 );
  massA->SetTextAlign(   12 );
  massA->SetTextSize ( 0.03 );
  massA->SetTextColor(    1 );
  massA->SetTextFont (   62 );
  massA->AddText("m_{A}=160GeV");
  massA->Draw();

  TPaveText* tanb      = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC");
  tanb->SetBorderSize(   0 );
  tanb->SetFillStyle(    0 );
  tanb->SetTextAlign(   12 );
  tanb->SetTextSize ( 0.03 );
  tanb->SetTextColor(    1 );
  tanb->SetTextFont (   62 );
  tanb->AddText("tan#beta=20");
  tanb->Draw();

  TPaveText* scen      = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC");
  scen->SetBorderSize(   0 );
  scen->SetFillStyle(    0 );
  scen->SetTextAlign(   12 );
  scen->SetTextSize ( 0.03 );
  scen->SetTextColor(    1 );
  scen->SetTextFont (   62 );
  scen->AddText("mhmax");
  scen->Draw();
#endif

#ifdef MSSM
  TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90);
  SetLegendStyle(leg);
  leg->AddEntry(ggH  , "#phi#rightarrow#tau#tau" , "L" );
#else
  TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90);
  SetLegendStyle(leg);
#ifndef DROP_SIGNAL
  if(SIGNAL_SCALE!=1){
    leg->AddEntry(ggH  , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" );
  }
  else{
    leg->AddEntry(ggH  , "H(125 GeV)#rightarrow#tau#tau" , "L" );
  }
#endif
#endif
  leg->AddEntry(data , "observed"                       , "LP");
  leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"           , "F" );
  leg->AddEntry(ttbar, "t#bar{t}"                       , "F" );
  leg->AddEntry(EWK  , "electroweak"                    , "F" );
  leg->AddEntry(Fakes, "QCD"                            , "F" );
  $ERROR_LEGEND
  leg->Draw();

//#ifdef MSSM
//  TPaveText* mssm  = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC");
//  mssm->SetBorderSize(   0 );
//  mssm->SetFillStyle(    0 );
//  mssm->SetTextAlign(   12 );
//  mssm->SetTextSize ( 0.03 );
//  mssm->SetTextColor(    1 );
//  mssm->SetTextFont (   62 );
//  mssm->AddText("(m_{A}=120, tan#beta=10)");
//  mssm->Draw();
//#else
//  TPaveText* mssm  = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC");
//  mssm->SetBorderSize(   0 );
//  mssm->SetFillStyle(    0 );
//  mssm->SetTextAlign(   12 );
//  mssm->SetTextSize ( 0.03 );
//  mssm->SetTextColor(    1 );
//  mssm->SetTextFont (   62 );
//  mssm->AddText("m_{H}=125");
//  mssm->Draw();
//#endif

  /*
    Ratio Data over MC
  */
  TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400);
  canv0->SetGridx();
  canv0->SetGridy();
  canv0->cd();

  TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear();
  TH1F* rat1 = (TH1F*)data->Clone("rat"); 
  rat1->Divide(Ztt);
  for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){
    if(rat1->GetBinContent(ibin+1)>0){
      // catch cases of 0 bins, which would lead to 0-alpha*0-1
      rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.);
    }
    zero->SetBinContent(ibin+1, 0.);
  }
  rat1->SetLineColor(kBlack);
  rat1->SetFillColor(kGray );
  rat1->SetMaximum(+0.5);
  rat1->SetMinimum(-0.5);
  rat1->GetYaxis()->CenterTitle();
  rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}");
  rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}");
  rat1->Draw();
  zero->SetLineColor(kBlack);
  zero->Draw("same");
  canv0->RedrawAxis();

  /*
    Ratio After fit over Prefit
  */
  TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400);
  canv1->SetGridx();
  canv1->SetGridy();
  canv1->cd();

  TH1F* rat2 = (TH1F*) Ztt->Clone("rat2");
  rat2->Divide(ref);
  for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){
    if(rat2->GetBinContent(ibin+1)>0){
      // catch cases of 0 bins, which would lead to 0-alpha*0-1
      rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.);
    }
  }
  rat2->SetLineColor(kRed+ 3);
  rat2->SetFillColor(kRed-10);
  rat2->SetMaximum(+0.3);
  rat2->SetMinimum(-0.3);
  rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}");
  rat2->GetYaxis()->CenterTitle();
  rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}");
  rat2->Draw();
  zero->SetLineColor(kBlack);
  zero->Draw("same");
  canv1->RedrawAxis();

  /*
    Relative shift per sample
  */
  TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400);
  canv2->SetGridx();
  canv2->SetGridy();
  canv2->cd();

  InitHist  (scales[0], "", "", kMagenta-10, 1001);
  InitHist  (scales[1], "", "", kRed    + 2, 1001);
  InitHist  (scales[2], "", "", kBlue   - 8, 1001);
  InitHist  (scales[3], "", "", kOrange - 4, 1001);
#ifndef DROP_SIGNAL
  InitSignal(scales[4]);
  InitSignal(scales[5]);
  InitSignal(scales[6]);
#endif
  scales[0]->Draw();
  scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}");
  scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}"  );
  scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}");
  scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}"  );
#ifdef MSSM
  scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}"  );
  scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}"  );
  scales[0]->GetXaxis()->SetBinLabel(7, "NONE"      );
#else
  scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}"  );
  scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}"  );
  scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}"   );
#endif
  scales[0]->SetMaximum(+1.0);
  scales[0]->SetMinimum(-1.0);
  scales[0]->GetYaxis()->CenterTitle();
  scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}");
  scales[1]->Draw("same");
  scales[2]->Draw("same");
  scales[3]->Draw("same");
#ifndef DROP_SIGNAL
  scales[4]->Draw("same");
  scales[5]->Draw("same");
  scales[6]->Draw("same");
#endif
  zero->Draw("same");
  canv2->RedrawAxis();

  /*
    prepare output
  */
  bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos;
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.png"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update");
  output->cd();
  data ->Write("data_obs");
  Fakes->Write("Fakes"   );
  EWK  ->Write("EWK"     );
  ttbar->Write("ttbar"   );
  Ztt  ->Write("Ztt"     );
#ifdef MSSM
  ggH  ->Write("ggH"     );
  bbH  ->Write("bbH"     );
#else
#ifndef DROP_SIGNAL
  ggH  ->Write("ggH"     );
  qqH  ->Write("qqH"     );
  VH   ->Write("VH"      );
#endif
#endif
  if(errorBand){
    errorBand->Write("errorBand");
  }
  output->Close();
}
void InclusiveJets_2010_mcdataRatio(){

//general root settings
gROOT->SetStyle("Plain");
gStyle->SetOptStat(0); //get rid of statistics box

// to set the errors of the histograms to sqrt(sum of squares of weights)
TH1::SetDefaultSumw2() ;

//Ranges for plots
Float_t xmin=17.5 , ymin = 0.00001, xmax = 1684.0, ymax = 10000000000000000.;

//for the linecolor and linestyle
Int_t icol[8]={8,kViolet,7,4,12,46,6,7};
Int_t isty[8]={1,1,1,1,1,1,1,1};
Int_t imark[5] = {21,22,25,26,3};

//get the root files
TFile *f[3];
f[0] = new TFile("out_aida_40times900kevents_errorcut50/Z2MPIHADONbornkt5ktsupp250_errorcut.root");
f[1] = new TFile("out_aida_40times900kevents_errorcut50/Z2MPIHADOFFbornkt5ktsupp250_errorcut.root");
f[2] = new TFile("out_aida_40times900kevents_errorcut50/NOTUNEbornkt5ktsupp250_errorcut.root");

//get the Tgraph and convert into histo
TH1F _histotmp[6][3];
Int_t n = 3; //number of files
Int_t nh = 6; // number of histograms = number of y bins

for(const int ifile = 0; ifile < n; ifile++){

  _histotmp[0][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d01_x01_y01;1")); // |y| <0.5
  _histotmp[1][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d02_x01_y01;2")); // 0.5 < |y| < 1.0
  _histotmp[2][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d03_x01_y01;2")); // 1.0 < |y| < 1.5
  _histotmp[3][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d04_x01_y01;2")); // 1.5 < |y| < 2.0
  _histotmp[4][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d05_x01_y01;1")); // 2.0 < |y| < 2.5
  _histotmp[5][ifile] = Gr2Hi((TGraph*) f[ifile]->Get("d06_x01_y01;1")); // 2.5 < |y| < 3.0

  for(const int ihisto = 0; ihisto < nh; ihisto++){
    _histotmp[ihisto][ifile].SetName("");
  }
}

//change the histo so that I can plot it and do the ratio
 TH1F *_histo[6][3];

for(const int ifile = 0; ifile < n; ifile++){
  for(const int ihisto = 0; ihisto < nh; ihisto++){

    TH1F *_histo[ihisto][ifile]= (TH1F*)_histotmp[ihisto][ifile].Clone("");
/*
  _histo[ihisto][ifile]->Divide((TH1*)_histo[ihisto][1]);  //histo 0 / hsito 1
  TH1F *_ratio1[ihisto]= (TH1F*)_ratiotmp1[ihisto]->Clone("");
  _ratiotmp2[ihisto]->Divide((TH1*)_histo[ihisto][2]);  //histo 0 / hsito 2
  TH1F *_ratio2[ihisto]= (TH1F*)_ratiotmp2[ihisto]->Clone("");
*/
    _histo[ihisto][ifile]->SetLineWidth(2);
    _histo[ihisto][ifile]->SetLineColor(icol[ihisto]);
    _histo[ihisto][ifile]->SetMarkerStyle(2);
    _histo[ihisto][ifile]->SetMarkerColor(icol[ihisto]);

  }

//scale the histos that it fits in one histogram
_histo[0][ifile]->Scale(10000);
_histo[1][ifile]->Scale(1000);
_histo[2][ifile]->Scale(100);
_histo[3][ifile]->Scale(10);
_histo[4][ifile]->Scale(1);
}

//get the data 2010
//data =  new TFile("out_aida/CMS_2011_S9086218.root");

//TH1F _histodata1 = Gr2Hi((TGraph*)data->Get("d01_x01_y01;1")); // |y| <0.5
//TH1F _histodata2 = Gr2Hi((TGraph*)data->Get("d02_x01_y01;1")); // 0.5 < |y| < 1.0
//TH1F _histodata3 = Gr2Hi((TGraph*)data->Get("d03_x01_y01;1")); // 1.0 < |y| < 1.5
//TH1F _histodata4 = Gr2Hi((TGraph*)data->Get("d04_x01_y01;1")); // 1.5 < |y| < 2.0
//TH1F _histodata5 = Gr2Hi((TGraph*)data->Get("d05_x01_y01;1")); // 2.0 < |y| < 2.5
//TH1F _histodata6 = Gr2Hi((TGraph*)data->Get("d06_x01_y01;1")); // 2.5 < |y| < 3.0


   Double_t xAxis1[35] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 592, 638, 686, 737, 846, 1684}; 

   TH1F *d01_x01_y01_histo = new TH1F("d01_x01_y01_histo","d01_x01_y01_histo",34, xAxis1);
   d01_x01_y01_histo->SetBinContent(1,1.97e+11);
   d01_x01_y01_histo->SetBinContent(2,1.02e+11);
   d01_x01_y01_histo->SetBinContent(3,5.14e+10);
   d01_x01_y01_histo->SetBinContent(4,2.66e+10);
   d01_x01_y01_histo->SetBinContent(5,1.38e+10);
   d01_x01_y01_histo->SetBinContent(6,6.53e+09);
   d01_x01_y01_histo->SetBinContent(7,3.35e+09);
   d01_x01_y01_histo->SetBinContent(8,1.8e+09);
   d01_x01_y01_histo->SetBinContent(9,9.2e+08);
   d01_x01_y01_histo->SetBinContent(10,4.66e+08);
   d01_x01_y01_histo->SetBinContent(11,2.37e+08);
   d01_x01_y01_histo->SetBinContent(12,1.18e+08);
   d01_x01_y01_histo->SetBinContent(13,5.43e+07);
   d01_x01_y01_histo->SetBinContent(14,2.39e+07);
   d01_x01_y01_histo->SetBinContent(15,1.08e+07);
   d01_x01_y01_histo->SetBinContent(16,5240000);
   d01_x01_y01_histo->SetBinContent(17,2610000);
   d01_x01_y01_histo->SetBinContent(18,1360000);
   d01_x01_y01_histo->SetBinContent(19,716000);
   d01_x01_y01_histo->SetBinContent(20,381000);
   d01_x01_y01_histo->SetBinContent(21,207000);
   d01_x01_y01_histo->SetBinContent(22,117000);
   d01_x01_y01_histo->SetBinContent(23,66800);
   d01_x01_y01_histo->SetBinContent(24,37900);
   d01_x01_y01_histo->SetBinContent(25,22000);
   d01_x01_y01_histo->SetBinContent(26,12900);
   d01_x01_y01_histo->SetBinContent(27,7540);
   d01_x01_y01_histo->SetBinContent(28,4410);
   d01_x01_y01_histo->SetBinContent(29,2770);
   d01_x01_y01_histo->SetBinContent(30,1450);
   d01_x01_y01_histo->SetBinContent(31,846);

   d01_x01_y01_histo->SetBinContent(32,499);
   d01_x01_y01_histo->SetBinContent(33,205);

   d01_x01_y01_histo->SetBinContent(34,20.2);

   d01_x01_y01_histo->SetBinError(1,2.547782e+10);
   d01_x01_y01_histo->SetBinError(2,1.24325e+10);
   d01_x01_y01_histo->SetBinError(3,6.016764e+09);
   d01_x01_y01_histo->SetBinError(4,3.005329e+09);
   d01_x01_y01_histo->SetBinError(5,1.530463e+09);
   d01_x01_y01_histo->SetBinError(6,7.056178e+08);
   d01_x01_y01_histo->SetBinError(7,3.617535e+08);
   d01_x01_y01_histo->SetBinError(8,1.96072e+08);
   d01_x01_y01_histo->SetBinError(9,9.919588e+07);
   d01_x01_y01_histo->SetBinError(10,5.102008e+07);
   d01_x01_y01_histo->SetBinError(11,2.639067e+07);
   d01_x01_y01_histo->SetBinError(12,1.335539e+07);
   d01_x01_y01_histo->SetBinError(13,6258885);
   d01_x01_y01_histo->SetBinError(14,2836105);
   d01_x01_y01_histo->SetBinError(15,1319900);
   d01_x01_y01_histo->SetBinError(16,663920.6);
   d01_x01_y01_histo->SetBinError(17,342646.4);
   d01_x01_y01_histo->SetBinError(18,184642.2);
   d01_x01_y01_histo->SetBinError(19,100845.5);
   d01_x01_y01_histo->SetBinError(20,55764.14);
   d01_x01_y01_histo->SetBinError(21,31565.29);
   d01_x01_y01_histo->SetBinError(22,18614.95);
   d01_x01_y01_histo->SetBinError(23,11075.51);
   d01_x01_y01_histo->SetBinError(24,6579.499);
   d01_x01_y01_histo->SetBinError(25,4015.708);
   d01_x01_y01_histo->SetBinError(26,2479.083);
   d01_x01_y01_histo->SetBinError(27,1527.99);
   d01_x01_y01_histo->SetBinError(28,943.6936);
   d01_x01_y01_histo->SetBinError(29,627.92);
   d01_x01_y01_histo->SetBinError(30,350.3168);
   d01_x01_y01_histo->SetBinError(31,219.1467);
   d01_x01_y01_histo->SetBinError(32,139.7467);
   d01_x01_y01_histo->SetBinError(33,62.02427);
   d01_x01_y01_histo->SetBinError(34,7.233998);
   d01_x01_y01_histo->SetEntries(34);
   d01_x01_y01_histo->SetStats(0);

   //d01_x01_y01_histo->Scale(10000);
   d01_x01_y01_histo->SetLineWidth(2);
   d01_x01_y01_histo->SetMarkerStyle(21);
   d01_x01_y01_histo->SetMarkerSize(0.7);
   d01_x01_y01_histo->SetFillColor(kGray);

   Double_t xAxis2[34] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 592, 638, 686, 790, 1684}; 

   TH1F *d02_x01_y01_histo = new TH1F("d02_x01_y01_histo","d02_x01_y01_histo",33, xAxis2);
   d02_x01_y01_histo->SetBinContent(1,1.89e+10);
   d02_x01_y01_histo->SetBinContent(2,9.74e+09);
   d02_x01_y01_histo->SetBinContent(3,4.99e+09);
   d02_x01_y01_histo->SetBinContent(4,2.49e+09);
   d02_x01_y01_histo->SetBinContent(5,1.31e+09);
   d02_x01_y01_histo->SetBinContent(6,6.28e+08);
   d02_x01_y01_histo->SetBinContent(7,3.23e+08);
   d02_x01_y01_histo->SetBinContent(8,1.71e+08);
   d02_x01_y01_histo->SetBinContent(9,8.84e+07);
   d02_x01_y01_histo->SetBinContent(10,4.42e+07);
   d02_x01_y01_histo->SetBinContent(11,2.22e+07);
   d02_x01_y01_histo->SetBinContent(12,1.13e+07);
   d02_x01_y01_histo->SetBinContent(13,5130000);
   d02_x01_y01_histo->SetBinContent(14,2230000);
   d02_x01_y01_histo->SetBinContent(15,1010000);
   d02_x01_y01_histo->SetBinContent(16,482000);
   d02_x01_y01_histo->SetBinContent(17,238000);
   d02_x01_y01_histo->SetBinContent(18,122000);
   d02_x01_y01_histo->SetBinContent(19,64200);
   d02_x01_y01_histo->SetBinContent(20,34100);
   d02_x01_y01_histo->SetBinContent(21,18700);
   d02_x01_y01_histo->SetBinContent(22,10100);
   d02_x01_y01_histo->SetBinContent(23,5720);
   d02_x01_y01_histo->SetBinContent(24,3420);
   d02_x01_y01_histo->SetBinContent(25,1890);
   d02_x01_y01_histo->SetBinContent(26,1130);
   d02_x01_y01_histo->SetBinContent(27,590);
   d02_x01_y01_histo->SetBinContent(28,376);
   d02_x01_y01_histo->SetBinContent(29,196);
   d02_x01_y01_histo->SetBinContent(30,130);

   d02_x01_y01_histo->SetBinContent(31,62.4);
   d02_x01_y01_histo->SetBinContent(32,30.1);
   d02_x01_y01_histo->SetBinContent(33,2.14);

   d02_x01_y01_histo->SetBinError(1,2.47211e+09);
   d02_x01_y01_histo->SetBinError(2,1.196891e+09);
   d02_x01_y01_histo->SetBinError(3,5.890842e+08);
   d02_x01_y01_histo->SetBinError(4,2.837945e+08);
   d02_x01_y01_histo->SetBinError(5,1.465766e+08);
   d02_x01_y01_histo->SetBinError(6,6.848512e+07);
   d02_x01_y01_histo->SetBinError(7,3.536592e+07);
   d02_x01_y01_histo->SetBinError(8,1.879562e+07);
   d02_x01_y01_histo->SetBinError(9,9619569);
   d02_x01_y01_histo->SetBinError(10,4860292);
   d02_x01_y01_histo->SetBinError(11,2483524);
   d02_x01_y01_histo->SetBinError(12,1278948);
   d02_x01_y01_histo->SetBinError(13,596427.3);
   d02_x01_y01_histo->SetBinError(14,266851);
   d02_x01_y01_histo->SetBinError(15,124973);
   d02_x01_y01_histo->SetBinError(16,61551.8);
   d02_x01_y01_histo->SetBinError(17,31482.64);
   d02_x01_y01_histo->SetBinError(18,16749.58);
   d02_x01_y01_histo->SetBinError(19,9172.852);
   d02_x01_y01_histo->SetBinError(20,5077.065);
   d02_x01_y01_histo->SetBinError(21,2898.771);
   d02_x01_y01_histo->SetBinError(22,1633.017);
   d02_x01_y01_histo->SetBinError(23,965.8504);
   d02_x01_y01_histo->SetBinError(24,606.0352);
   d02_x01_y01_histo->SetBinError(25,351.8168);
   d02_x01_y01_histo->SetBinError(26,221.2594);
   d02_x01_y01_histo->SetBinError(27,122.0002);
   d02_x01_y01_histo->SetBinError(28,82.34314);
   d02_x01_y01_histo->SetBinError(29,45.69701);
   d02_x01_y01_histo->SetBinError(30,32.27314);
   d02_x01_y01_histo->SetBinError(31,16.82748);
   d02_x01_y01_histo->SetBinError(32,8.687436);
   d02_x01_y01_histo->SetBinError(33,0.745178);
   d02_x01_y01_histo->SetEntries(33);
   d02_x01_y01_histo->SetStats(0);

   d02_x01_y01_histo->SetLineStyle(0);
   d02_x01_y01_histo->SetLineWidth(2);
   d02_x01_y01_histo->SetMarkerStyle(22);
   d02_x01_y01_histo->SetMarkerSize(0.7);
   d02_x01_y01_histo->SetFillColor(kGray);


   Double_t xAxis3[33] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 592, 638, 686, 1410}; 

   TH1F *d03_x01_y01_histo = new TH1F("d03_x01_y01_histo","d03_x01_y01_histo",32, xAxis3);
   d03_x01_y01_histo->SetBinContent(1,1.84e+09);
   d03_x01_y01_histo->SetBinContent(2,9.24e+08);
   d03_x01_y01_histo->SetBinContent(3,4.64e+08);
   d03_x01_y01_histo->SetBinContent(4,2.34e+08);
   d03_x01_y01_histo->SetBinContent(5,1.19e+08);
   d03_x01_y01_histo->SetBinContent(6,5.88e+07);
   d03_x01_y01_histo->SetBinContent(7,2.92e+07);
   d03_x01_y01_histo->SetBinContent(8,1.57e+07);
   d03_x01_y01_histo->SetBinContent(9,8090000);
   d03_x01_y01_histo->SetBinContent(10,4090000);
   d03_x01_y01_histo->SetBinContent(11,2050000);
   d03_x01_y01_histo->SetBinContent(12,994000);
   d03_x01_y01_histo->SetBinContent(13,452000);
   d03_x01_y01_histo->SetBinContent(14,192000);
   d03_x01_y01_histo->SetBinContent(15,86200);
   d03_x01_y01_histo->SetBinContent(16,40500);
   d03_x01_y01_histo->SetBinContent(17,20100);
   d03_x01_y01_histo->SetBinContent(18,10000);
   d03_x01_y01_histo->SetBinContent(19,5210);
   d03_x01_y01_histo->SetBinContent(20,2720);
   d03_x01_y01_histo->SetBinContent(21,1470);
   d03_x01_y01_histo->SetBinContent(22,803);
   d03_x01_y01_histo->SetBinContent(23,435);
   d03_x01_y01_histo->SetBinContent(24,252);
   d03_x01_y01_histo->SetBinContent(25,138);
   d03_x01_y01_histo->SetBinContent(26,75.7);
   d03_x01_y01_histo->SetBinContent(27,43.1);
   d03_x01_y01_histo->SetBinContent(28,23.5);
   d03_x01_y01_histo->SetBinContent(29,13.1);

   d03_x01_y01_histo->SetBinContent(30,6.96);
   d03_x01_y01_histo->SetBinContent(31,3.31);
   d03_x01_y01_histo->SetBinContent(32,0.263);

   d03_x01_y01_histo->SetBinError(1,3.267438e+08);
   d03_x01_y01_histo->SetBinError(2,1.460402e+08);
   d03_x01_y01_histo->SetBinError(3,6.756898e+07);
   d03_x01_y01_histo->SetBinError(4,3.169167e+07);
   d03_x01_y01_histo->SetBinError(5,1.534246e+07);
   d03_x01_y01_histo->SetBinError(6,7206299);
   d03_x01_y01_histo->SetBinError(7,3487964);
   d03_x01_y01_histo->SetBinError(8,1852766);
   d03_x01_y01_histo->SetBinError(9,937690);
   d03_x01_y01_histo->SetBinError(10,474695.6);
   d03_x01_y01_histo->SetBinError(11,239744.8);
   d03_x01_y01_histo->SetBinError(12,117028.5);
   d03_x01_y01_histo->SetBinError(13,54375.43);
   d03_x01_y01_histo->SetBinError(14,23751.81);
   d03_x01_y01_histo->SetBinError(15,11010.17);
   d03_x01_y01_histo->SetBinError(16,5355.962);
   d03_x01_y01_histo->SetBinError(17,2760.221);
   d03_x01_y01_histo->SetBinError(18,1428.408);
   d03_x01_y01_histo->SetBinError(19,775.8965);
   d03_x01_y01_histo->SetBinError(20,422.7916);
   d03_x01_y01_histo->SetBinError(21,238.9779);
   d03_x01_y01_histo->SetBinError(22,137.1344);
   d03_x01_y01_histo->SetBinError(23,78.10703);
   d03_x01_y01_histo->SetBinError(24,47.62767);
   d03_x01_y01_histo->SetBinError(25,27.54976);
   d03_x01_y01_histo->SetBinError(26,16.01829);
   d03_x01_y01_histo->SetBinError(27,9.722084);
   d03_x01_y01_histo->SetBinError(28,5.653863);
   d03_x01_y01_histo->SetBinError(29,3.37332);
   d03_x01_y01_histo->SetBinError(30,1.948179);
   d03_x01_y01_histo->SetBinError(31,1.026618);
   d03_x01_y01_histo->SetBinError(32,0.09205037);
   d03_x01_y01_histo->SetEntries(32);
   d03_x01_y01_histo->SetStats(0);

   d03_x01_y01_histo->SetLineStyle(0);
   d03_x01_y01_histo->SetLineWidth(2);
   d03_x01_y01_histo->SetMarkerStyle(25);
   d03_x01_y01_histo->SetMarkerSize(0.7);
   d03_x01_y01_histo->SetFillColor(kGray);

   Double_t xAxis4[30] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 468, 507, 548, 1032}; 

   TH1F *d04_x01_y01_histo = new TH1F("d04_x01_y01_histo","d04_x01_y01_histo",29, xAxis4);
   d04_x01_y01_histo->SetBinContent(1,1.44e+08);
   d04_x01_y01_histo->SetBinContent(2,7.35e+07);
   d04_x01_y01_histo->SetBinContent(3,3.8e+07);
   d04_x01_y01_histo->SetBinContent(4,1.89e+07);
   d04_x01_y01_histo->SetBinContent(5,9700000);
   d04_x01_y01_histo->SetBinContent(6,4670000);
   d04_x01_y01_histo->SetBinContent(7,2280000);
   d04_x01_y01_histo->SetBinContent(8,1220000);
   d04_x01_y01_histo->SetBinContent(9,629000);
   d04_x01_y01_histo->SetBinContent(10,305000);
   d04_x01_y01_histo->SetBinContent(11,151000);
   d04_x01_y01_histo->SetBinContent(12,73400);
   d04_x01_y01_histo->SetBinContent(13,32900);
   d04_x01_y01_histo->SetBinContent(14,13900);
   d04_x01_y01_histo->SetBinContent(15,6160);
   d04_x01_y01_histo->SetBinContent(16,2860);
   d04_x01_y01_histo->SetBinContent(17,1400);
   d04_x01_y01_histo->SetBinContent(18,711);
   d04_x01_y01_histo->SetBinContent(19,356);
   d04_x01_y01_histo->SetBinContent(20,186);
   d04_x01_y01_histo->SetBinContent(21,94.5);
   d04_x01_y01_histo->SetBinContent(22,50.9);
   d04_x01_y01_histo->SetBinContent(23,25.6);
   d04_x01_y01_histo->SetBinContent(24,13.3);
   d04_x01_y01_histo->SetBinContent(25,7);
   d04_x01_y01_histo->SetBinContent(26,3.45);
   d04_x01_y01_histo->SetBinContent(27,1.73);

   d04_x01_y01_histo->SetBinContent(28,0.796);
   d04_x01_y01_histo->SetBinContent(29,0.066);

   d04_x01_y01_histo->SetBinError(1,3.637846e+07);
   d04_x01_y01_histo->SetBinError(2,1.67099e+07);
   d04_x01_y01_histo->SetBinError(3,7851714);
   d04_x01_y01_histo->SetBinError(4,3568673);
   d04_x01_y01_histo->SetBinError(5,1703586);
   d04_x01_y01_histo->SetBinError(6,750723.4);
   d04_x01_y01_histo->SetBinError(7,343490.2);
   d04_x01_y01_histo->SetBinError(8,173448.2);
   d04_x01_y01_histo->SetBinError(9,84294.21);
   d04_x01_y01_histo->SetBinError(10,39082.27);
   d04_x01_y01_histo->SetBinError(11,18979.5);
   d04_x01_y01_histo->SetBinError(12,9119.636);
   d04_x01_y01_histo->SetBinError(13,4140.893);
   d04_x01_y01_histo->SetBinError(14,1810.098);
   d04_x01_y01_histo->SetBinError(15,830.3785);
   d04_x01_y01_histo->SetBinError(16,399.9657);
   d04_x01_y01_histo->SetBinError(17,204.9602);
   d04_x01_y01_histo->SetBinError(18,109.8075);
   d04_x01_y01_histo->SetBinError(19,59.1287);
   d04_x01_y01_histo->SetBinError(20,33.42105);
   d04_x01_y01_histo->SetBinError(21,18.47046);
   d04_x01_y01_histo->SetBinError(22,10.88183);
   d04_x01_y01_histo->SetBinError(23,6.000047);
   d04_x01_y01_histo->SetBinError(24,3.41489);
   d04_x01_y01_histo->SetBinError(25,1.994767);
   d04_x01_y01_histo->SetBinError(26,1.086542);
   d04_x01_y01_histo->SetBinError(27,0.610451);
   d04_x01_y01_histo->SetBinError(28,0.3130872);
   d04_x01_y01_histo->SetBinError(29,0.03211142);
   d04_x01_y01_histo->SetEntries(29);
   d04_x01_y01_histo->SetStats(0);

   d04_x01_y01_histo->SetLineStyle(0);
   d04_x01_y01_histo->SetLineWidth(2);
   d04_x01_y01_histo->SetMarkerStyle(26);
   d04_x01_y01_histo->SetMarkerSize(0.7);
   d04_x01_y01_histo->SetFillColor(kGray);

   Double_t xAxis5[27] = {18, 21, 24, 28, 32, 37, 43, 49, 56, 64, 74, 84, 97, 114, 133, 153, 174, 196, 220, 245, 272, 300, 330, 362, 395, 430, 737};

   TH1F *d05_x01_y01_histo = new TH1F("d05_x01_y01_histo","d05_x01_y01_histo",26, xAxis5);
   d05_x01_y01_histo->SetBinContent(1,1.05e+07);
   d05_x01_y01_histo->SetBinContent(2,5520000);
   d05_x01_y01_histo->SetBinContent(3,2720000);
   d05_x01_y01_histo->SetBinContent(4,1440000);
   d05_x01_y01_histo->SetBinContent(5,738000);
   d05_x01_y01_histo->SetBinContent(6,348000);
   d05_x01_y01_histo->SetBinContent(7,168000);
   d05_x01_y01_histo->SetBinContent(8,89800);
   d05_x01_y01_histo->SetBinContent(9,43800);
   d05_x01_y01_histo->SetBinContent(10,21800);
   d05_x01_y01_histo->SetBinContent(11,10300);
   d05_x01_y01_histo->SetBinContent(12,5030);
   d05_x01_y01_histo->SetBinContent(13,2180);
   d05_x01_y01_histo->SetBinContent(14,896);
   d05_x01_y01_histo->SetBinContent(15,384);
   d05_x01_y01_histo->SetBinContent(16,170);
   d05_x01_y01_histo->SetBinContent(17,78.5);
   d05_x01_y01_histo->SetBinContent(18,35.8);
   d05_x01_y01_histo->SetBinContent(19,16.5);
   d05_x01_y01_histo->SetBinContent(20,7.25);
   d05_x01_y01_histo->SetBinContent(21,3.27);
   d05_x01_y01_histo->SetBinContent(22,1.38);
   d05_x01_y01_histo->SetBinContent(23,0.579);
   d05_x01_y01_histo->SetBinContent(24,0.22);

   d05_x01_y01_histo->SetBinContent(25,0.0808);
   d05_x01_y01_histo->SetBinContent(26,0.00548);

   d05_x01_y01_histo->SetBinError(1,1978672);
   d05_x01_y01_histo->SetBinError(2,935188);
   d05_x01_y01_histo->SetBinError(3,421635.1);
   d05_x01_y01_histo->SetBinError(4,206618.7);
   d05_x01_y01_histo->SetBinError(5,100557.7);
   d05_x01_y01_histo->SetBinError(6,44514.08);
   d05_x01_y01_histo->SetBinError(7,20942.13);
   d05_x01_y01_histo->SetBinError(8,11048.87);
   d05_x01_y01_histo->SetBinError(9,5260.105);
   d05_x01_y01_histo->SetBinError(10,2634.555);
   d05_x01_y01_histo->SetBinError(11,1278.591);
   d05_x01_y01_histo->SetBinError(12,627.8137);
   d05_x01_y01_histo->SetBinError(13,282.1732);
   d05_x01_y01_histo->SetBinError(14,121.6466);
   d05_x01_y01_histo->SetBinError(15,55.24865);
   d05_x01_y01_histo->SetBinError(16,25.82574);
   d05_x01_y01_histo->SetBinError(17,12.76174);
   d05_x01_y01_histo->SetBinError(18,6.253124);
   d05_x01_y01_histo->SetBinError(19,3.142438);
   d05_x01_y01_histo->SetBinError(20,1.508923);
   d05_x01_y01_histo->SetBinError(21,0.7510828);
   d05_x01_y01_histo->SetBinError(22,0.3514478);
   d05_x01_y01_histo->SetBinError(23,0.1646418);
   d05_x01_y01_histo->SetBinError(24,0.071108);
   d05_x01_y01_histo->SetBinError(25,0.02988224);
   d05_x01_y01_histo->SetBinError(26,0.002567773);
   d05_x01_y01_histo->SetEntries(26);
   d05_x01_y01_histo->SetStats(0);

   d05_x01_y01_histo->SetLineStyle(0);
   d05_x01_y01_histo->SetLineWidth(2);
   d05_x01_y01_histo->SetMarkerStyle(3);
   d05_x01_y01_histo->SetMarkerSize(0.7);
   d05_x01_y01_histo->SetFillColor(kGray);

// MC / Data
TH1F *_ratio[6][3];

for(const int ifile = 0; ifile < n; ifile++){
  for(const int ihisto = 0; ihisto < nh; ihisto++){

    TH1F *_ratio[ihisto][ifile]= (TH1F*)_histo[ihisto][ifile]->Clone("");

    _ratio[ihisto][ifile]->SetLineWidth(1);
    _ratio[ihisto][ifile]->SetLineColor(icol[ihisto]);
    _ratio[ihisto][ifile]->SetMarkerStyle(imark[ihisto]);
    _ratio[ihisto][ifile]->SetMarkerSize(0.5);
    _ratio[ihisto][ifile]->SetMarkerColor(icol[ihisto]);
 }

  _ratio[0][ifile]->Divide((TH1*)d01_x01_y01_histo);  
  _ratio[1][ifile]->Divide((TH1*)d02_x01_y01_histo);  
  _ratio[2][ifile]->Divide((TH1*)d03_x01_y01_histo);  
  _ratio[3][ifile]->Divide((TH1*)d04_x01_y01_histo);  
  _ratio[4][ifile]->Divide((TH1*)d05_x01_y01_histo);  

//  TH1F *_ratio[ihisto]= (TH1F*)_ratiotmp1[ihisto]->Clone("");
 // _ratiotmp2[ihisto]->Divide((TH1*)_histo[ihisto][2]);  //histo 0 / hsito 2
//  TH1F *_ratio2[ihisto]= (TH1F*)_ratiotmp2[ihisto]->Clone("");

}



//create a canvas to draw TGraph and TH1F

TCanvas *c1 = new TCanvas("c1", "c1",369,0,680,750);

    //pads (inclusive jet cross section, MC / data )
   Pad_inclJet = new TPad("Pad_inclJet","xs",0.01,0.51,1.0,1.0);
   Pad_inclJet->Draw();
   Pad_MCdata1 = new TPad("Pad_MCdata1","ratio",0.01,0.40,1.0,0.50);
   Pad_MCdata1->Draw();
   Pad_MCdata2 = new TPad("Pad_MCdata2","ratio",0.01,0.30,1.0,0.40);
   Pad_MCdata2->Draw();
   Pad_MCdata3 = new TPad("Pad_MCdata3","ratio",0.01,0.20,1.0,0.30);
   Pad_MCdata3->Draw();
   Pad_MCdata4 = new TPad("Pad_MCdata4","ratio",0.01,0.10,1.0,0.20);
   Pad_MCdata4->Draw();
   Pad_MCdata5 = new TPad("Pad_MCdata5","ratio",0.01,0.0,1.0,0.10);
   Pad_MCdata5->Draw();

// first pad style
   Pad_inclJet->cd();
   gStyle->SetOptStat(0);
   gPad->SetFillColor(0);
   gPad->SetBorderMode(0);
   gPad->SetBorderSize(2);
   gPad->SetLogy();
   gPad->SetLeftMargin(0.14);
   gPad->SetRightMargin(0.03);
   gPad->SetTopMargin(0.03);
   gPad->SetFrameBorderMode(0);
   gPad->SetFrameBorderMode(0);

//empty histo for border and style

   TH1F *shape = new TH1F("","",1, xmin, xmax);
   shape->SetMinimum(ymin);
   shape->SetMaximum(ymax); 
   shape->GetXaxis()->SetTitle("Jet p_{T} (GeV/c)");
   shape->GetXaxis()->SetLabelSize(0.03);
   shape->GetXaxis()->SetTitleSize(0.03);
   shape->GetXaxis()->SetNdivisions(508);
   shape->GetXaxis()->SetTitleOffset(1.3);
   shape->GetYaxis()->SetTitle("#frac{d^{2}#sigma}{dp_{T}d|y|} (pb/GeV)");
   shape->GetYaxis()->SetLabelSize(0.03);
   shape->GetYaxis()->SetTitleSize(0.03);
   shape->GetYaxis()->SetTitleOffset(1.6);
   shape->Draw("e");

  //data
  d01_x01_y01_histo->Draw("E2same");
  d02_x01_y01_histo->Draw("E2same");
  d03_x01_y01_histo->Draw("E2same");
  d04_x01_y01_histo->Draw("E2same");
  d05_x01_y01_histo->Draw("E2same");

	_histo[0][0]->Draw("E1same");
	_histo[1][0]->Draw("E1same");
	_histo[2][0]->Draw("E1same");
	_histo[3][0]->Draw("E1same");
	_histo[4][0]->Draw("E1same");


  gPad->SetLogy();
  gPad->SetLogx();

   TLine *line = new TLine(xmin,1,xmax,1);
   line->SetLineStyle(2);
   line->Draw();

   TPaveText *pt = new TPaveText(0.17,0.79,0.37,0.95,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.03);
   text = pt->AddText("CMS 2010");
   text = pt->AddText("#sqrt{s} = 7 TeV");
   text = pt->AddText("anti-k_{T} R = 0.5");
   pt->Draw();

TLegend *leg = new TLegend(0.68,0.77,0.83,0.928);
   leg->SetBorderSize(1);
   leg->SetTextSize(0.025);
   leg->SetLineColor(0);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(1001);

   leg->AddEntry((TH1F*)_histo[0][0],"POWHEG & Pythia6 Z2","pfl");
   leg->AddEntry((TH1F*)  d01_x01_y01_histo, "|y| <0.5 (x 10^{4})","pfl");
   leg->AddEntry((TH1F*)  d02_x01_y01_histo, "0.5 < |y| < 1.0 (x 10^{3})","pfl");
   leg->AddEntry((TH1F*)  d03_x01_y01_histo, "1.0 < |y| < 1.5 (x 10^{2})","pfl");
   leg->AddEntry((TH1F*)  d04_x01_y01_histo, "1.5 < |y| < 2.0 (x 10^{1})","pfl");
   leg->AddEntry((TH1F*)  d05_x01_y01_histo, "2.0 < |y| < 2.5 (x 10^{0})","pfl");

   leg->Draw();

//second pad MC / Data

   Pad_MCdata1->cd();

   gPad->SetFillColor(0);
   gPad->SetBorderMode(0);
   gPad->SetBorderSize(2);
   gPad->SetLeftMargin(0.14);
   gPad->SetRightMargin(0.03);
   gPad->SetTopMargin(0.0);
   gPad->SetFrameBorderMode(0);
   gPad->SetFrameBorderMode(0);

  gPad->SetLogx();

   //AK Empty histo for style and borders
   TH1F *shape_MCdata = new TH1F("","",1, xmin, xmax);
   shape_MCdata->SetMinimum(0.5);
   shape_MCdata->SetMaximum(2.0);
   shape_MCdata->GetXaxis()->SetTitle("Jet p_{T} (GeV/c)");
   shape_MCdata->GetXaxis()->SetLabelSize(0.0);
   shape_MCdata->GetXaxis()->SetTitleSize(0.0);
   shape_MCdata->GetXaxis()->SetTitleOffset(0.6);
   shape_MCdata->GetYaxis()->SetTitle("MC/Data");
   shape_MCdata->GetYaxis()->SetLabelSize(0.15);
   shape_MCdata->GetYaxis()->SetTitleSize(0.15);
   shape_MCdata->GetYaxis()->SetTitleOffset(0.2);
   shape_MCdata->GetYaxis()->SetNdivisions(108, kTRUE);   
   shape_MCdata->Draw("e");   

// horizontal line at y = 1
   TLine *line = new TLine(xmin,1,xmax,1);
   line->SetLineStyle(2);
   line->Draw();

   TPaveText *pt = new TPaveText(0.89,0.7,0.94,0.8,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.2);
   text = pt->AddText("|y| <0.5");
   pt->Draw();

	_ratio[0][0]->Draw("EhistSame");

   Pad_MCdata2->cd();

   gPad->SetFillColor(0);
   gPad->SetBorderMode(0);
   gPad->SetBorderSize(2);
   gPad->SetLeftMargin(0.14);
   gPad->SetRightMargin(0.03);
   gPad->SetTopMargin(0.0);
   gPad->SetFrameBorderMode(0);
   gPad->SetFrameBorderMode(0);

  gPad->SetLogx();

   shape_MCdata->Draw("e");   



// horizontal line at y = 1
   TLine *line = new TLine(xmin,1,xmax,1);
   line->SetLineStyle(2);
   line->Draw();

   TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.2);
   text = pt->AddText("0.5 < |y| < 1.0");
   pt->Draw();

	_ratio[1][0]->Draw("EhistSame");

   Pad_MCdata3->cd();

   gPad->SetFillColor(0);
   gPad->SetBorderMode(0);
   gPad->SetBorderSize(2);
   gPad->SetLeftMargin(0.14);
   gPad->SetRightMargin(0.03);
   gPad->SetTopMargin(0.0);
   gPad->SetFrameBorderMode(0);
   gPad->SetFrameBorderMode(0);

  gPad->SetLogx();

   shape_MCdata->Draw("e");   
// horizontal line at y = 1
   TLine *line = new TLine(xmin,1,xmax,1);
   line->SetLineStyle(2);
   line->Draw();

   TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.2);
   text = pt->AddText("1.0 < |y| < 1.5");
   pt->Draw();
	_ratio[2][0]->Draw("EhistSame");

   Pad_MCdata4->cd();

   gPad->SetFillColor(0);
   gPad->SetBorderMode(0);
   gPad->SetBorderSize(2);
   gPad->SetLeftMargin(0.14);
   gPad->SetRightMargin(0.03);
   gPad->SetTopMargin(0.0);
   gPad->SetFrameBorderMode(0);
   gPad->SetFrameBorderMode(0);

  gPad->SetLogx();

   shape_MCdata->Draw("e");   
// horizontal line at y = 1
   TLine *line = new TLine(xmin,1,xmax,1);
   line->SetLineStyle(2);
   line->Draw();

   TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.2);
   text = pt->AddText("1.5 < |y| < 2.0");
   pt->Draw();
	_ratio[3][0]->Draw("EhistSame");

   Pad_MCdata5->cd();

   gPad->SetFillColor(0);
   gPad->SetBorderMode(0);
   gPad->SetBorderSize(2);
   gPad->SetLeftMargin(0.14);
   gPad->SetRightMargin(0.03);
   gPad->SetTopMargin(0.0);
   gPad->SetFrameBorderMode(0);
   gPad->SetFrameBorderMode(0);

  gPad->SetLogx();

   shape_MCdata->Draw("e");   
// horizontal line at y = 1
   TLine *line = new TLine(xmin,1,xmax,1);
   line->SetLineStyle(2);
   line->Draw();

   TPaveText *pt = new TPaveText(0.84,0.7,0.89,0.8,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.2);
   text = pt->AddText("2.0 < |y| < 2.5");
   pt->Draw();
	_ratio[4][0]->Draw("EhistSame");

//write in png file
mysubpad1 =(TPad*)c1->GetPad(0);
mysubpad1->Print("pics/InclusiveJets_10_mcdataRatio.png");

} 
Пример #24
0
void long_Ay_nu_05() {
  gROOT->SetStyle("HALLA");
  TCanvas *cn = new TCanvas("cn","cn",540,360);
  cn->Draw();
  cn->UseCurrentStyle();
  TH1F *frm = new TH1F("frm","",100,0.,10.);
  frm->GetXaxis()->SetTitle("#nu (GeV)");
  frm->GetYaxis()->SetTitle("Ay for Q2=0.456 (GeV/c)2");
  frm->SetMinimum(0);
//  frm->SetMinimum(0);
//  frm->SetMaximum(1.0);
  frm->SetMaximum(0.35);
  frm->UseCurrentStyle();
  frm->Draw();
  frm->SetAxisRange(0.120,0.350,"X");
//  frm->SetAxisRange(0.5,1.1,"X");

//  TF1* galster = new TF1("galster","x/(4.*0.938*.938)*1.91/(1.+x/.71)^2/(1.+5.6*x/(4.*.938*.938))",0.,4.);
//  galster->SetLineColor(6);
//  galster->SetLineStyle(3);
//  galster->SetLineWidth(2);


  TF1 *genf = new TF1("genf",genff,1.,10.,1);
  genf->SetLineColor(2);
  genf->SetLineStyle(2);
  genf->SetParameter(0,1.);
  // match to Madey point just below 1.5
  // genf->SetParameter(0,.0411/genf->Eval(1.45));
  genf->SetParameter(0,-0.558645);

//  TF1 *bbba05 = new TF1("BBBA05",gen_bbba05,0.,10.,0);
//  bbba05->SetLineColor(7);
//  bbba05->SetLineStyle(3);

  
  TMultiGraph* mgrDta = new TMultiGraph("Data","G_{E}^{n}");
  TLegend *legDta = new TLegend(.54,.6,.875,.90,"","brNDC");

  TMultiGraph* wgr = mgrDta;
  TLegend *wlg = legDta;

   // the data
  legDta->SetBorderSize(0); // turn off border
  legDta->SetFillStyle(0);
  
  datafile_t *f = datafiles;
  TGraph* gr=0;
  while ( f && f->filename ) {
    gr=OneGraph(f);
    if (gr) {
      if (f->lnpt) {
	mgrDta->Add(gr,f->lnpt);
	legDta->AddEntry(gr,f->label,f->lnpt);
      }
      else if (gr->GetMarkerStyle()>=20) {
	mgrDta->Add(gr,"p");
	legDta->AddEntry(gr,f->label,"p");
      }	
      else {
	mgrDta->Add(gr,"l");
	legDta->AddEntry(gr,f->label,"l");
      }
    }
    f++;
  }
    

  mgrDta->Draw("p");
//  legDta->Draw();
  TF1 *theFit = new TF1("theFit","pol0");
  gr->Fit(theFit);
  theFit->Draw("same");  
  TMultiGraph* mgrThry = new TMultiGraph("Theory","G_{E}^{n}");
  TLegend *legThry = new TLegend(.54,.3,.875,.6,"","brNDC");

  wgr = mgrThry;
  wlg = legThry;

  // the theory
  wlg->SetBorderSize(0); // turn off border
  wlg->SetFillStyle(0);
  
  f = theoryfiles1;
  gr=0;
  while ( f && f->filename ) {
    gr=OneGraph(f);
    if (gr) {
      TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr);
      if (egr && egr->GetN()>1 && egr->GetEYhigh() && egr->GetEYhigh()[1]>0) {
	gr = toerror_band(egr);
	gr->SetFillStyle(3000+f->style);
      }
      if (f->lnpt) {
	wgr->Add(gr,f->lnpt);
	wlg->AddEntry(gr,f->label,f->lnpt);
      }
      else if (gr->GetMarkerStyle()>=20) {
	wgr->Add(gr,"p");
	wlg->AddEntry(gr,f->label,"p");
      }	
      else {
	wgr->Add(gr,"l");
	wlg->AddEntry(gr,f->label,"l");
      }
    }
    f++;
  }

//  genf->Draw("same");
  mgrThry->Draw("c");
//  galster->Draw("same");
//  bbba05->Draw("same");
//  legThry->AddEntry(genf,"F_{2}/F_{1} #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l");
//  legThry->AddEntry(galster,"Galster fit","l");
//  legThry->AddEntry(bbba05,"BBBA05","l");
//  legThry->Draw();
//  legDta->Draw();
  
  // draw a line at 1
  cn->Modified();

  cn->Update();
  cn->SaveAs(Form("%s.eps",psfile));
  cn->SaveAs(Form("%s.root",psfile));
  gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile));

  return;  // LEAVING HERE

  // now an overlay, hopefully matching dimensions

  // remove everything but the graph
  cn->Update();
  TList *clist = cn->GetListOfPrimitives();
  TFrame* frame = cn->GetFrame();
  for (int i=0; i<clist->GetSize(); ) {
    if (clist->At(i) != frame) {
      clist->RemoveAt(i);
    } else i++;
  }
  // draw markers in the corners
  TMarker *mkr = new TMarker(frame->GetX1(),frame->GetY1(),2);
  mkr->Draw();
  mkr = new TMarker(frame->GetX2(),frame->GetY1(),2);
  mkr->Draw();
  mkr = new TMarker(frame->GetX1(),frame->GetY2(),2);
  mkr->Draw();
  mkr = new TMarker(frame->GetX2(),frame->GetY2(),2);
  mkr->Draw();
  frame->SetLineColor(10);
  cn->Update();

  datafile_t miller = { "figure_input/Miller/lattice.GEn.rtf","Miller",
			"[0]","[1]","[1]-[3]","[2]-[1]",0,0,1,3,"F" };

  gr = OneGraph(&miller);
  TGraphAsymmErrors* egr = dynamic_cast<TGraphAsymmErrors*>(gr);
  if (egr && egr->GetEYhigh() && egr->GetEYhigh()[egr->GetN()/2]>0) {
    gr = toerror_band(egr);
    gr->SetLineStyle(1);
    gr->SetFillColor(gr->GetLineColor());
    gr->SetFillStyle(3000+miller.style);
  }
  
  gr->Draw("F");

  cn->Update();
  cn->SaveAs("gen_Miller_Overlay.eps");
  cn->SaveAs("gen_Miller_Overlay.root");
  
}
//___________________________________________________________________________
Double_t* Ifit(int shift, Double_t& dataResult, Double_t& dataErr, std::string dataFile, 
	       TH1D* hsig, TH1D* hbkg, TH1D* hEGdata, Double_t* FitPar,
	       int ptbin=30, char EBEE[10]="EB", int fit_data=2)
{
  
  printf(" *** calling Ifit for %s , ptbin %d *** \n\n", EBEE,ptbin);

  cout << "The number of bins are: " << endl;
  cout << "hdata nbins = " << hEGdata->GetNbinsX() << endl;
  cout << "hsig nbins = " << hsig->GetNbinsX() << endl;
  cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl;
  

  TCanvas *c1 = new TCanvas("HF1", "Histos1", 0, 0, 600, 600);
  gStyle->SetOptFit(0);

  if(fit_data != 3) dataColl.clear();
  sigColl.clear();
  bkgColl.clear();

  totalColl.clear();
  ctauColl.clear();
  Para.clear();
  Para_err.clear();

  info.clear();
  info_err.clear();

  float ptmax=0.;  
  if(ptbin== 21) ptmax= 23;
  if(ptbin== 23) ptmax= 26;
  if(ptbin== 26) ptmax= 30;
  if(ptbin== 30) ptmax= 35;
  if(ptbin== 35) ptmax= 40;
  if(ptbin== 40) ptmax= 45;
  if(ptbin== 45) ptmax= 50;
  if(ptbin== 50) ptmax= 60;
  if(ptbin== 60) ptmax= 85;
  if(ptbin== 85) ptmax= 120;
  if(ptbin== 120) ptmax= 300;
  if(ptbin== 300) ptmax= 500;



  Double_t* fitted = new Double_t[6];
  fitted[0] = 0.;    fitted[1] = 0.;    fitted[2] = 0.;    fitted[3] = 0.;
  fitted[4] = 0.;    fitted[5] = 0.;

  char hname[30];


  hsig->SetLineColor(1);
  hbkg->SetLineColor(1);
  hsig->SetNdivisions(505,"XY");
  hbkg->SetNdivisions(505,"XY");
  hsig->SetTitle("");
  hbkg->SetTitle("");
  hsig->SetXTitle("combined ISO (GeV)");
  hbkg->SetXTitle("combined ISO (GeV)");

  TH1F *hsum = (TH1F*)hsig->Clone();  
  hsum->Add(hbkg,1);
  float ntemplate = 1.;
  if (hsum->Integral()>1.) ntemplate = hsum->Integral();
  float sigfrac = hsig->Integral()/ntemplate*0.8;

  TH1F *hsum_norm = (TH1F*)hsum->Clone();  
  hsum_norm->Scale(1./hsum->Integral());

  TH1F *hdata = new TH1F();
  int ndata=0;
  if ( fit_data==1 ) {
    hdata = (TH1F*)hEGdata->Clone();
    ndata = (int)hdata->Integral();    
    for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
      for(int ipoint=0; ipoint<hdata->GetBinContent(ibin); ipoint++) {
	dataColl.push_back(hdata->GetBinCenter(ibin));
      }
    }
    ndata = dataColl.size();
  }else if (fit_data==2 ){
      hdata = (TH1F*)hEGdata->Clone();
    hdata -> Reset();
    dataColl.clear();
    FILE *infile =  fopen(dataFile.data(),"r");  
    float xdata, xdata1, xdata2; // combined isolation, pt, eta

    int flag = 1;
    while (flag!=-1){
      flag =fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2);
      if( xdata1 >= ptbin && xdata1 < ptmax && xdata<20.) {
	if((strcmp(EBEE,"EB")==0 && TMath::Abs(xdata2)<1.45) ||
	   (strcmp(EBEE,"EE")==0 && TMath::Abs(xdata2)<2.5 && TMath::Abs(xdata2)>1.7) ) {
 	  dataColl.push_back(xdata);
	  hdata->Fill(xdata);
 	}
      } 
    }// keep reading files as long as text exists
    ndata = dataColl.size();

    printf("test print data 2 %2.3f \n", dataColl[2]);    
//     cout << "ndata in dataColl = " << ndata << endl;
    if ( ndata == 0 ) {
      printf(" no data to fit \n");
      return fitted;
    }
  }

  if(ndata==0) {
    printf(" ---  no events in the fit \n");
    return fitted;
  }
    
  //test fit the template and get PDFs
  TCanvas *c10 = new TCanvas("c10","c10",1000,500);
  c10->Divide(2,1);
  c10->cd(1);

  double par[20] = {hsig->GetMaximum(), 1., 0.6, 0.3,
		    hbkg->GetMaximum(), -.45, -0.05, 0.03, 1., 1., 1., 1.};

  if(strcmp(EBEE,"EE")==0) { par[2]=-0.1, par[3]=0.2; par[6]=-0.15; par[7]=0.02; };
  int fit_status;

  TF1 *f1 = new TF1("f1", exp_conv, -1., 20., 11);
  TF1 *fmcsigfit = new TF1("fmcsigfit", exp_conv, -1., 20., 11);
  fmcsigfit->SetLineColor(4);
  fmcsigfit->SetLineWidth(2);

  f1->SetNpx(10000);
  f1->SetParameters(par);
  f1->SetLineWidth(2);
  c10->cd(1);
  fit_status = hsig->Fit(f1,"","",-1., 5.);

  hsig->Draw();
  f1->Draw("same");
  if ( fit_status > 0 ) {
     printf("fit signal template failed. QUIT \n");
     return fitted;
  }
  if(para_index>0 && para_index<4){
    double tmppar = f1->GetParameter(para_index);
    f1->SetParameter(para_index, tmppar+para_sigma*f1->GetParError(para_index));
  }

  TF1 *fmcsig = (TF1*)f1->Clone();
  TF1 *fmcsigcorr = (TF1*)f1->Clone();
  fmcsig->SetNpx(10000);
  fmcsigcorr->SetNpx(10000);
  fmcsigfit->SetNpx(10000);
  
  TCanvas *c101 = new TCanvas("c101","c101",1000,500);
  c101->Divide(2,1);
  c101->cd(1);

  fmcsig->SetLineColor(1);
//   fmcsig->Draw();
//   f1->Draw("same");
  TH1F *htmp1 = (TH1F*)fmcsig->GetHistogram();
//   TH1F *htmp2 = (TH1F*)fmcsigcorr->GetHistogram();
  
  TH2F *htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25);

  htmp2->SetNdivisions(505,"XY");
  htmp2->SetXTitle("Iso");
  htmp2->SetYTitle("A.U.");
  htmp2->SetLineColor(1);

//   htmp2->Draw();
//   htmp1->Draw("same");
//   htmp2->Add(htmp1,-1);
//   htmp2->Divide(htmp1);
  htmp2->GetXaxis()->SetRangeUser(-1., 10.);
  htmp2->SetMinimum(-1.);
  //htmp2->SetMaximum(1.5);
  htmp2->Draw();
  fmcsig->Draw("same");
//   fmcsigcorr->Draw("same");
  
  TLegend *tleg1 = new TLegend(0.5, 0.7, 0.93, 0.92);
  tleg1->SetHeader("");
  tleg1->SetFillColor(0);
  tleg1->SetShadowColor(0);
  tleg1->SetBorderSize(0);
  tleg1->AddEntry(fmcsig,"Zee data","l");
  //tleg1->AddEntry(fmcsigcorr,"corrected shape","l");
  tleg1->AddEntry(fmcsigfit,"shape from data","l");
  tleg1->Draw();

  //return fitted;
       
  SigPDFnorm = f1->Integral(-1.,20.);
  printf("status %d, sig area %3.3f \n", fit_status,f1->Integral(-1., 20.));


  f1->SetParameter(2,f1->GetParameter(2)+0.2);
  f1->SetParameter(3,f1->GetParameter(3)+0.1);

  Para.push_back(f1->GetParameter(0));
  Para.push_back(f1->GetParameter(1));
  Para.push_back(f1->GetParameter(2));
  Para.push_back(f1->GetParameter(3));

  Para_err.push_back(f1->GetParError(0));
  Para_err.push_back(f1->GetParError(1));
  Para_err.push_back(f1->GetParError(2));
  Para_err.push_back(f1->GetParError(3));

  c10->cd(2);
  TF1 *fbkgfit = new TF1("fbkgfit", expinv_power, -1., 20., 11);  

  TF1 *f3 = new TF1("f3", expinv_power, -1., 20., 11);
  fbkgfit->SetNpx(10000);  
  fbkgfit->SetLineColor(4);
  fbkgfit->SetLineWidth(2);

  f3->SetNpx(10000);
  f3->SetLineWidth(2);
  f3->SetParameters(f1->GetParameters());
    
  f3->SetParLimits(5,-5.,0.);
  f3->SetParLimits(6,-0.5,0.);
  f3->SetParLimits(7,0.001,0.2);
  f3->SetParLimits(8,0.5,5.);
  if ( strcmp(EBEE,"EB")==0 ){  
//     f3->FixParameter(8,1.);
//     f3->FixParameter(6,-0.1);
    f3->SetParLimits(8,1.,1.5);
  }

  float bkg_bend_power = 1.;
  if ( ptbin==21 ) bkg_bend_power = 4.5;
  if ( ptbin==23 ) bkg_bend_power = 4.;
  if ( ptbin==26 ) bkg_bend_power = 3.5;
  if ( ptbin==30 ) bkg_bend_power = 2.6;
  if ( ptbin==35 ) bkg_bend_power = 2.2;
  if ( ptbin==40 ) bkg_bend_power = 2.;
  if ( ptbin==45 ) bkg_bend_power = 2.;
  if ( ptbin==50 ) bkg_bend_power = 1.8;
  if ( ptbin==60 ) bkg_bend_power = 1.5;
  if ( ptbin==85 ) bkg_bend_power = 1.;
  if ( ptbin==120 ) bkg_bend_power = 1.;


  if ( strcmp(EBEE,"EE")==0 ){  
    f3->SetParameter(8,bkg_bend_power);
    f3->SetParLimits(8,bkg_bend_power-1., bkg_bend_power+1.);
  }

  f3->FixParameter(0,f3->GetParameter(0));
  f3->FixParameter(1,f3->GetParameter(1));
  f3->FixParameter(2,f3->GetParameter(2));
  f3->FixParameter(3,f3->GetParameter(3));

  hbkg->SetMaximum(hbkg->GetMaximum()*3.);
  fit_status = hbkg->Fit(f3,"b","",-1., 20.);
  hbkg->Draw();
  if ( fit_status > 0 ) {
    printf("fit background template failed. QUIT \n");    
    return fitted;
  }else {
    f3->Draw("same");
  }

  TF1 *fmcbkg = (TF1*)f3->Clone();
  fmcbkg->SetLineColor(1);
  c101->cd(2);

  htmp1 = (TH1F*)fmcbkg->GetHistogram();
  htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25);

  htmp2->SetNdivisions(505,"XY");
  htmp2->SetXTitle("Iso");
  htmp2->SetYTitle("A.U.");
  htmp2->SetLineColor(1);

  htmp2->GetXaxis()->SetRangeUser(-1., 20.);
  htmp2->SetMinimum(-1.);
  htmp2->SetMaximum(1.5);
  htmp2->Draw();
  fmcbkg->Draw("same");

  TLegend *tleg2 = new TLegend(0.25, 0.2, 0.6, 0.42);
  tleg2->SetHeader("");
  tleg2->SetFillColor(0);
  tleg2->SetShadowColor(0);
  tleg2->SetBorderSize(0);
  if ( strcmp(EBEE,"EB")==0 ){  
    tleg2->AddEntry(fmcbkg,"MC shape","l");
  }else {
    tleg2->AddEntry(fmcbkg,"Data SB shape","l");
  }
  tleg2->AddEntry(fbkgfit,"shape from data","l");
  tleg2->Draw();
  
  if(para_index>4){
    double tmppar = f3->GetParameter(para_index);
    f3->SetParameter(para_index, tmppar+para_sigma*f3->GetParError(para_index));
  }

//   f3->SetParameter(5,-0.5);
//   f3->SetParameter(6,-0.05);
//   f3->SetParameter(7,0.02);
//   f3->SetParameter(8,1.);

  Para.push_back(f3->GetParameter(4));
  Para.push_back(f3->GetParameter(5));
  Para.push_back(f3->GetParameter(6));
  Para.push_back(f3->GetParameter(7)); 
  Para.push_back(f3->GetParameter(8)); 

  Para_err.push_back(f3->GetParError(4));
  Para_err.push_back(f3->GetParError(5));
  Para_err.push_back(f3->GetParError(6));
  Para_err.push_back(f3->GetParError(7));
  Para_err.push_back(f3->GetParError(8));

  BkgPDFnorm = f3->Integral(-1., 20.);
  printf("status %d, bkg area %3.3f \n", fit_status,f3->Integral(-1., 20.)/hdata->GetBinWidth(2));

  //test PDFs
  TCanvas *c11 = new TCanvas("c11","c11",1000,500);
  c11->Divide(2,1);
  c11->cd(1);
  TF1 *f11 = new TF1("f11",exp_conv_norm, -1., 20., 11);
  f11->SetNpx(10000);
  f11->SetParameters(f3->GetParameters());
  f11->Draw();
  printf(" SIG PDF area %2.3f \n", f11->Integral(-1., 20.));

  c11->cd(2);
  TF1 *f12 = new TF1("f12",expinv_power_norm, -1., 20., 11);
  f12->SetNpx(10000);
  f12->SetParameters(f3->GetParameters());
  f12->Draw();
  printf(" BKG PDF area %2.3f \n", f12->Integral(-1., 20.));

  //c1->cd();

  printf(" --------- before the fit ------------- \n");
  printf("Nsig %2.3f, Nbg %2.3f, Ntemplate %3.3f \n", hsig->Integral(), hbkg->Integral(), ntemplate);
  printf("Purity %2.3f, init size %4.3f,  fit sample size %4d\n", hsig->Integral()/hsum->Integral(), hsum->Integral(), ndata);
  printf(" -------------------------------------- \n");



  printf( " -----  Got %d, %d, %d events for fit ----- \n ", dataColl.size(),
	  sigColl.size(), bkgColl.size() );  

  //--------------------------------------------------
  //init parameters for fit
  Double_t vstart[11] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.};
  vstart[0] = sigfrac*ndata;
  vstart[1] = (1-sigfrac)*ndata;
  for (int ii=0; ii<9; ii++) {    
    vstart[ii+2] = Para[ii]; //8 shape parameters
  }
  TMinuit *gMinuit = new TMinuit(NPAR);  
  gMinuit->Command("SET STR 1");
  gMinuit->SetFCN(fcn);
  Double_t arglist[11];
  Int_t ierflg = 0;
  
  arglist[0] = 1;
  gMinuit->mnexcm("SET ERR", arglist ,1,ierflg);
  arglist[0] = 1;
  gMinuit->mnexcm("SET PRINT", arglist ,1,ierflg);

  Double_t step[] = { 1.,1.,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,};

  for ( int ii=0; ii<9; ii++){
    printf(" para %d, %.5f, err %.5f \n", ii, Para[ii], Para_err[ii]);
  }

  float sigma = 3.;
  gMinuit->mnparm(0,  "Signal yield"  , vstart[0],  step[0], 0., ndata*2.  , ierflg);
  gMinuit->mnparm(1,  "background yield"  , vstart[1],  step[1], 0., ndata*2. , ierflg);

//   gMinuit->mnparm(2,  "constant"     , Para[0],  0.00,  Para[0], Para[0] , ierflg);
//   gMinuit->mnparm(3,  "exp tail"     , Para[1],  0.01,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg);
//   gMinuit->mnparm(4,  "exg mean"     , Para[2],  0.01,  Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg);
//   gMinuit->mnparm(5,  "exg width"    , Para[3],  0.01,  Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg);
//   gMinuit->mnparm(6,  "constant"     , Para[4],  0.00,  Para[4]                  , Para[4]                  , ierflg);
//   gMinuit->mnparm(7,  "bg exp turnon", Para[5],  0.01,  Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg);
//   gMinuit->mnparm(8,  "bg x offset  ", Para[6],  0.01,  Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg);
//   gMinuit->mnparm(9,  "bg bend slope", Para[7],  0.01,  0.001                    , 0.1                      , ierflg);
// //   gMinuit->mnparm(10, "bg bend power", Para[8],  0.01,  Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg);
//   gMinuit->mnparm(10, "bg bend power", Para[8],  0.01,  0.5                       , 5.                       , ierflg);

//   gMinuit->mnparm(2,  "constant"     , Para[0], TMath::Abs(Para[0]*0.0) ,  Para[0], Para[0], ierflg);
//   gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.01) ,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); 
// //   gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.1) ,  0.8    , 1.3    , ierflg);
//   gMinuit->mnparm(4,  "exg mean"     , Para[2], TMath::Abs(Para[2]*0.1) ,  0.5    , 1.0    , ierflg);
//   gMinuit->mnparm(5,  "exg width"    , Para[3], TMath::Abs(Para[3]*0.1) ,  0.25   , 0.5    , ierflg);
//   gMinuit->mnparm(6,  "constant"     , Para[4], TMath::Abs(Para[4]*0.0) ,  Para[4], Para[4], ierflg);
//   gMinuit->mnparm(7,  "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.1) ,  -0.7   , -0.3   , ierflg);
//   gMinuit->mnparm(8,  "bg x offset  ", Para[6], TMath::Abs(Para[6]*0.0) ,  -0.15  , -0.05  , ierflg);
//   gMinuit->mnparm(9,  "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) ,  0.01   , 0.05   , ierflg);
//   gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) ,  0.5    , 1.5    , ierflg);

  gMinuit->mnparm(2,  "constant"     , Para[0],  0.00,  Para[0], Para[0] , ierflg);
  gMinuit->mnparm(3,  "exp tail"     , Para[1],  0.00,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg);
  gMinuit->mnparm(4,  "exg mean"     , Para[2],  0.00,  Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg);
  gMinuit->mnparm(5,  "exg width"    , Para[3],  0.00,  Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg);
  gMinuit->mnparm(6,  "constant"     , Para[4],  0.00,  Para[4]                  , Para[4]                  , ierflg);
  gMinuit->mnparm(7,  "bg exp turnon", Para[5],  0.00,  Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg);
  gMinuit->mnparm(8,  "bg x offset  ", Para[6],  0.00,  Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg);
  gMinuit->mnparm(9,  "bg bend slope", Para[7],  0.00,  0.001                    , 0.1                      , ierflg);
  gMinuit->mnparm(10, "bg bend power", Para[8],  0.00,  Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg);
  
  printf(" --------------------------------------------------------- \n");
  printf(" Now ready for minimization step \n --------------------------------------------------------- \n");
  
  arglist[0] = 500; // number of iteration
  gMinuit->mnexcm("MIGRAD", arglist,1,ierflg);
  //can do scan
//   arglist[0] = 0;
//   gMinuit->mnexcm("SCAN", arglist,1,ierflg);

  printf (" -------------------------------------------- \n");
  printf("Finished.  ierr = %d \n", ierflg);

  double para[NPAR+1],errpara[NPAR+1];

  double tmp_errpara[NPAR+1];

  for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j]=0.1; }
  for(int j=2; j<=NPAR-1;j++) { 
    if(Para_err[j-2]!=0.) tmp_errpara[j]=TMath::Abs(Para_err[j-2]); 
  }
  
  int ni=6;       if ( strcmp(EBEE,"EE")==0 ) { ni=6; }//if(ptbin==21) ni=0;}
  
  if ( ierflg == 0 ) {
    for(int i=0; i<ni; i++) {
      float istep[10] = {0.,0.,0.,0.,0.,0.,0.};
      if (i<(ni-1)) {
	istep[i] = 0.001;
      }else {
	for (int j=0; j<ni-1; j++) {istep[j] = 0.001;}
      }

      for(int j=0; j<=NPAR-1;j++) {
	gMinuit->GetParameter(j, para[j], errpara[j]);
	if (errpara[j] != 0. ) {
	  tmp_errpara[j] = TMath::Abs(errpara[j]);
	}
      }

      if ( strcmp(EBEE,"EB")==0 ) {

	sigma = 10.;

 	if ( i==(ni-1) ) { sigma=5.;istep[1]=istep[4]=0.; }
	if ( ptbin==21 && i==1 ){ sigma=3.; }
 	if ( ptbin==21 && i==(ni-1) ){ sigma=20.; }
	if ( ptbin==23 && i==0 ){ para[7]=-0.5; }
	if ( ptbin==23 && i==1 ){ istep[1]=0.; istep[3]=0.01; }
 	if ( ptbin==23 && i==3 ){ istep[1]=0.01; istep[3]=0.0; }
	if ( ptbin==23 && i==(ni-1) ){ sigma=20.; }
 	if ( ptbin==26 && i==1 ){ sigma=5.; }	
	if ( ptbin==26 && i==(ni-1) ){ sigma=20.; }
	if ( ptbin==30 && i==(ni-1) ){ sigma=3.; }
 	if ( ptbin==35 && i==(ni-1) ) { sigma=10.; }
 	if ( ptbin==40 && i==(ni-1) ) { sigma=5.; istep[4]=0.01; }
 	if ( ptbin==45 && i==(ni-1) ) { sigma=10.; }
	if ( ptbin==60 && i==0 ) { para[3]=1.; para[4]=0.6; para[5]=0.32; para[7]=-0.45; para[9]=0.025; para[10] = 1.;}
 	if ( ptbin==60 && i==(ni-1) ) { sigma=5.; istep[4]=0.01;}
	if ( ptbin>=85 && i==(ni-1) ){ sigma=3.; }
	if ( ptbin==300 ) { istep[2]=istep[3]=istep[4]=0.; }// para[7] = -5.11907e-02; istep[1]=0.; }
	float tmp8=0.;
	
// 	if( i!= (ni-1) ) {
	  gMinuit->mnparm(0,  "Signal yield"  ,   para[0],  1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg);
	  gMinuit->mnparm(1,  "background yield", para[1],  1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg);
	  gMinuit->mnparm(2,  "constant"     , para[2],  0., para[2]-100.*tmp_errpara[2], para[2]+100.*tmp_errpara[2], ierflg);
	  gMinuit->mnparm(6,  "constant"     , para[6],  0., para[6]-100.*tmp_errpara[6], para[6]+100.*tmp_errpara[6], ierflg);
	  gMinuit->mnparm(3,  "exp tail"     , para[3],  istep[4],  para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg);
	  gMinuit->mnparm(4,  "exg mean"     , para[4],  istep[3],  para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg);
	  gMinuit->mnparm(5,  "exg width"    , para[5],  istep[2],  para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg);
	  gMinuit->mnparm(7,  "bg exp turnon", para[7],  istep[1],  para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg);
	  gMinuit->mnparm(8,  "bg x offset  ", para[8],  tmp8    ,  para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg);
	  gMinuit->mnparm(9,  "bg bend slope", para[9],  istep[0],  para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg);      
	  float sigma10=5.;
	  if ( para[10]-sigma10*tmp_errpara[10] < 1. )// && i!=(ni-1))
	    gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], 1.,  para[10]+sigma10*tmp_errpara[10], ierflg);      
	  else
	    gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], para[10]-sigma10*tmp_errpara[10],  para[10]+sigma10*tmp_errpara[10], ierflg);      
// 	}else {
// 	  gMinuit->mnparm(2,  "constant"     , Para[0], TMath::Abs(Para[0]*0.0) ,  Para[0], Para[0], ierflg);
// 	  //gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.01) ,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); 
// 	  gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.0) ,  0.8    , 1.3    , ierflg);
// 	  gMinuit->mnparm(4,  "exg mean"     , Para[2], TMath::Abs(Para[2]*0.1) ,  0.5    , 1.0    , ierflg);
// 	  gMinuit->mnparm(5,  "exg width"    , Para[3], TMath::Abs(Para[3]*0.1) ,  0.25   , 0.5    , ierflg);
// 	  gMinuit->mnparm(6,  "constant"     , Para[4], TMath::Abs(Para[4]*0.0) ,  Para[4], Para[4], ierflg);
// 	  gMinuit->mnparm(7,  "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.0) ,  -0.7   , -0.3   , ierflg);
// 	  gMinuit->mnparm(8,  "bg x offset  ", Para[6], TMath::Abs(Para[6]*0.0) ,  -0.15  , -0.05  , ierflg);
// 	  gMinuit->mnparm(9,  "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) ,  0.01   , 0.05   , ierflg);
// 	  gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) ,  0.5    , 1.5    , ierflg);
// 	}


	if( ptbin >=300 ) { 
	  gMinuit->mnparm(3,  "exp tail"  , 1.257281,  0.0,  para[1]-3.*tmp_errpara[1], para[1]+3.*tmp_errpara[1], ierflg);
	  gMinuit->mnparm(4,  "exg mean"  , 0.856906,  0.0,  para[2]-3.*tmp_errpara[2], para[2]+3.*tmp_errpara[2], ierflg);
	  gMinuit->mnparm(5,  "exg width" , 0.320847,  0.0,  para[3]-3.*tmp_errpara[3], para[3]+3.*tmp_errpara[3], ierflg);
	}      

    }else{	

	sigma=10.;
	if ( i==0 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 0.3; }
 	if ( i==(ni-1) ) { sigma=3.;istep[1]=istep[4]=0.; } //test of not changing signal template
     	if ( i==(ni-1) ) { istep[4]=0.;}

   	if ( ptbin==21 && i==(ni-1) ) { sigma=20.;}
  	if ( ptbin==23 && i==0 ) { sigma=5.;}
  	if ( ptbin==23 && i==(ni-1) ) { sigma=10.;}
	if ( ptbin<30 && ptbin>21 && i==1 ){ istep[1]=0.; istep[3]=0.01; }
 	if ( ptbin<30 && ptbin>21 && i==3 ){ istep[1]=0.01; istep[3]=0.0; }
	if ( ptbin==26 && i==1 ) { para[7] = -0.8; }
	if ( ptbin==26 && i==(ni-1) ) { sigma=10.; }
  	if ( ptbin==30 && i==(ni-1) ) { sigma=10.; }
 	if ( ptbin==35) {para[7] = -0.75;}
 	if ( ptbin==40 && i==0) {para[7] = -0.65; para[10] = 2.;}
	if ( ptbin==45 && i==(ni-1) ) {sigma=5.;}
	if ( ptbin==85 && i==(ni-1) ) {sigma=10.; istep[4]=0.01;}
	if (ptbin >= 85 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 1.; }

	if ( ptbin==120 ) { para[7] = -0.615255; istep[1]=0.;}

	
//     	if ( ptbin==120 && i==0 ) { 
// 	  para[3] = 1.446454; para[4]=-0.016373; para[5]=0.163238;
// 	  istep[2]=istep[3]=istep[4]=0.; sigma=5.; tmp_errpara[10]=0.2;
// 	}
//     	if ( ptbin==120 && i==(ni-1) ) { istep[2]=istep[3]=istep[4]=0.; sigma=5.;}

	gMinuit->mnparm(0,  "Signal yield"  ,   para[0],  1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg);
	gMinuit->mnparm(1,  "background yield", para[1],  1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg);
	gMinuit->mnparm(2,  "constant"     , para[2],  0.,  para[2], para[2] , ierflg);
	gMinuit->mnparm(6,  "constant"     , para[6],  0.,  para[6], para[6], ierflg);	
	gMinuit->mnparm(3,  "exp tail"     , para[3],  istep[4],  para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg);
	gMinuit->mnparm(4,  "exg mean"     , para[4],  istep[3],  para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg);
	gMinuit->mnparm(5,  "exg width"    , para[5],  istep[2],  para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg);
	gMinuit->mnparm(7,  "bg exp turnon", para[7],  istep[1],  para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg);
	gMinuit->mnparm(8,  "bg x offset  ", para[8],  0.00,      para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg);
	gMinuit->mnparm(9,  "bg bend slope", para[9],  istep[0],  para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg);	
  
	float minerr=1.;
	//if ( tmp_errpara[10] > 0.5) tmp_errpara[10] = 0.5;
	float sigma10=5.;
	if ( para[10]-sigma10*tmp_errpara[10] < 1. ) 
	  gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], minerr,  para[10]+sigma10*tmp_errpara[10], ierflg);
	else 
	  gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], para[10]-sigma10*tmp_errpara[10],  para[10]+sigma10*tmp_errpara[10], ierflg);

      }
      printf(" ************ \n");
      printf("  do %d th fit  \n", i);
      if(i==5 && dataFile.find("toy")    != std::string::npos)
	{
	  cout << "dataResult = " << dataResult << "\t dataErr = " << dataErr << endl;
	  // fixed turn on at +- 1 sigma
	  gMinuit->mnparm(7,  "bg exp turnon", dataResult-(float)shift*dataErr,  0.00,  para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg);

	}
      else if(dataFile.find("toy")    == std::string::npos)
	{
	  dataResult = para[7];
	  dataErr    = tmp_errpara[7];
	}
      arglist[0] = 500; // number of iteration
      gMinuit->mnexcm("MIGRAD", arglist ,1,ierflg);      
      if ( ierflg != 0 ) {
  	printf("fit failed at %d iteration \n", i);
  	c1->cd();	c1->Draw();  	hdata->Draw("phe");
  	return fitted;
      }
    }
  }
 
  Double_t amin,edm,errdef; 
  if ( ierflg == 0 ) {
    for(int j=0; j<=NPAR-1;j++) {
      gMinuit->GetParameter(j, para[j],errpara[j]);
      info.push_back(para[j]);
      info_err.push_back(errpara[j]);
      printf("Parameter  %d = %f +- %f\n",j,para[j],errpara[j]);	
    }
    para[NPAR] = dataColl.size();
    printf(" fitted yield %2.3f \n", (para[0]+para[1])/ndata );
    
    info.push_back(sigColl.size());
    
    for(int j=0; j<=NPAR-1;j++) {
      tmp_errpara[j] = errpara[j];
      if( tmp_errpara[j] == 0. ) tmp_errpara[j] = par[j]*.1;      
    }
    //do minos if fit sucessed.

  }
  if (ierflg != 0 )  {
    printf(" *********** Fit failed! ************\n");
    gMinuit->GetParameter(0, para[0],errpara[0]);
    gMinuit->GetParameter(1, para[1],errpara[1]);
    para[0]=0.; errpara[0]=0.;

    c1->cd();
    c1->Draw();  
    //gPad->SetLogy();
    hdata->SetNdivisions(505,"XY");
    hdata->SetXTitle("comb. ISO (GeV)");
    hdata->SetYTitle("Entries");
    hdata->SetTitle("");
    hdata->SetMarkerStyle(8);
    hdata->SetMinimum(0.);
    if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.);
    else hdata->SetMaximum(hdata->GetMaximum()*1.25);
    if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.25);
   
    hdata->Draw("phe");  

    return fitted;    
  }

  
  // Print results
//   Double_t amin,edm,errdef;
  Int_t nvpar,nparx,icstat;
  gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat);
  gMinuit->mnprin(1,amin);  
  gMinuit->mnmatu(1);
  printf(" ========= happy ending !? =========================== \n");
  
  printf("FCN =  %3.3f \n", amin);

  //use new PDF form
  double tmppar[12];
  for(int ii=0; ii<9; ii++){
    tmppar[ii] = para[ii+2];
    fmcsigfit->SetParameter(ii,tmppar[ii]);
    fbkgfit->SetParameter(ii,tmppar[ii]);
  }

  c101->cd(1);
  
  //fmcsigfit->SetParameters(tmppar);
  //fmcsigfit->SetParameter(2,0.1);
  //fmcsigfit->SetLineStyle(2);

  fmcsigfit->Draw("same");
  c101->cd(2);

  fbkgfit->SetParameter(4,fbkgfit->GetParameter(4)*fmcbkg->Integral(-1., 20.)/fbkgfit->Integral(-1., 20.));
  fbkgfit->Draw("same");

  char fname[100];
  sprintf(fname,"plots/template_Ifit%s_%d.pdf",EBEE,ptbin);
  c101->SaveAs(fname);


  f11->SetParameters(tmppar);
  SigPDFnorm = f11->Integral(-1., 20.);
  f12->SetParameters(tmppar);
  BkgPDFnorm = f12->Integral(-1., 20.);


  // plot
  c1->cd();
  c1->Draw();  
  //gPad->SetLogy();
   hdata->SetNdivisions(505,"XY");
   hdata->SetXTitle("comb. ISO (GeV)");
   hdata->SetYTitle("Entries");
   hdata->SetTitle("");
   hdata->SetMarkerStyle(8);
   hdata->SetMinimum(0.);
   if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.);
   else hdata->SetMaximum(hdata->GetMaximum()*1.5);
   if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.2);

   hdata->Draw("p e ");

  f11->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2));
//   f11->SetFillColor(5);
  f11->SetLineColor(4);
  //f11->SetFillColor(603);
  f11->SetLineWidth(2);
//   f11->SetFillStyle(3001);
  f11->Draw("same");

  f12->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2));
//   f12->SetFillColor(8);
  f12->SetLineColor(2);
  //f12->SetFillColor(603);
  f12->SetLineWidth(2);
//   f12->SetFillStyle(3013);
  f12->Draw("same");

  TF1 *f13 = new TF1("f13",sum_norm, -1., 20 ,11);
  f13->SetNpx(10000);
  f13->SetParameters(f12->GetParameters());
  f13->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2));
  f13->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2));  
  f13->SetLineWidth(2);
  f13->SetLineColor(1);
  f13->Draw("same");
  f11->Draw("same");
  hdata->Draw("pe same");

//   cout << "The number of bins are: " << endl;
//   cout << "hdata nbins = " << hdata->GetNbinsX() << endl;
//   cout << "hsig nbins = " << hsig->GetNbinsX() << endl;
//   cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl;

  // get chi2/NDF
  double chi2ForThisBin=0;
  int nbinForThisBin=0;
  chi2Nbins(f13, hdata, chi2ForThisBin, nbinForThisBin);
  for(int epar=0; epar < 11; epar++)
    {
//       cout << "f11 parameter " << epar << " = " << 
// 	f11->GetParameter(epar) << endl;
      FitPar[epar] = f11->GetParameter(epar);
    }

  for(int epar=0; epar < 11; epar++)
    {
//       cout << "f12 parameter " << epar << " = " << 
// 	f12->GetParameter(epar) << endl;
      FitPar[epar+11] = f12->GetParameter(epar);
    }

  for(int epar=0; epar < 11; epar++)
    {
//       cout << "f13 parameter " << epar << " = " << 
// 	f13->GetParameter(epar) << endl;
      FitPar[epar+22] = f13->GetParameter(epar);

    }

//   cout << "hdata integral = " << hdata->Integral() << endl;
//   cout << endl;

//   printf("fit area %3.2f; sig area %3.2f; bg area %3.2f\n", f13->Integral(-1., 20.)/hdata->GetBinWidth(2),  f11->Integral(-1., 20.)/hdata->GetBinWidth(2),f12->Integral(-1., 20.)/hdata->GetBinWidth(2));

//   for(int i=0; i<12; i++){
//     printf(" fit para %d = %4.3f \n", i, f13->GetParameter(i));
//   }

   TLegend *tleg = new TLegend(0.5, 0.7, 0.93, 0.92);
   char text[50];
   sprintf(text,"%s Pt %d ~ %.0f GeV",EBEE, ptbin, ptmax);
   tleg->SetHeader(text);
   tleg->SetFillColor(0);
   tleg->SetShadowColor(0);
   tleg->SetBorderSize(0);
   sprintf(text,"#chi^{2}/NDF = %.1f/%d",chi2ForThisBin,nbinForThisBin);
   tleg->AddEntry(hdata,text,"");
   sprintf(text,"Data %.1f events",hdata->Integral());
   tleg->AddEntry(hdata,text,"pl");
   sprintf(text,"Fitted %.1f events",para[0]+para[1]);//f13->Integral(-1., 20.)/hdata->GetBinWidth(2));
   tleg->AddEntry(f13,text,"l");
   sprintf(text,"SIG %.1f #pm %.1f events",para[0], errpara[0]);
   tleg->AddEntry(f11,text,"f");
   sprintf(text,"BKG %.1f #pm %.1f events",para[1], errpara[1]);
   tleg->AddEntry(f12,text,"f");
   tleg->Draw();


   gPad->RedrawAxis();

   printf("%s, ptbin %d, Data %.1f events \n",EBEE, ptbin, hdata->Integral());
   printf("Fitted %.1f (in 5GeV) %.1f events \n",para[0]+para[1],f13->Integral(-1.,5.));
   printf("SIG %.1f #pm %.1f events \n",para[0], errpara[0]);
   printf("SIG (in 5GeV) %.1f #pm %.1f events \n",f11->Integral(-1.,5.)/hdata->GetBinWidth(2), f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2));
   printf("BKG %.1f #pm %.1f events \n",para[1], errpara[1]);
   printf("BKG (in 5GeV) %.1f #pm %.1f events \n",f12->Integral(-1.,5.)/hdata->GetBinWidth(2), f12->Integral(-1.,5.)*errpara[1]/para[1]/hdata->GetBinWidth(2));
   
   float purity = f11->Integral(-1.,5.)/hdata->GetBinWidth(2)/(f11->Integral(-1.,5.)/hdata->GetBinWidth(2)+f12->Integral(-1.,5.)/hdata->GetBinWidth(2));
   float purity_err = purity*errpara[0]/para[0];
   printf("Purity (in 5GeV) %.3f #pm %.3f  \n", purity, purity_err);


//   hsig->Scale(para[0]/hsig->Integral());
//   hbkg->Scale(para[1]/hbkg->Integral());
//   hbkg->Add(hsig);

//   hsig->SetLineColor(1);
//   hsig->SetFillColor(5);
//   hsig->SetFillStyle(3001);

//   hbkg->SetLineWidth(2);


//   hsig->Draw("same");
//   hbkg->Draw("same");


  sprintf(fname,"plots/unbinned_free_Ifit%s_%d.pdf",EBEE,ptbin);
  if (para_index>0) sprintf(fname,"plots/unbinned_Ifit%s_%d_para%d_sigma%1.0f.pdf",EBEE,ptbin,para_index,para_sigma);
  if(Opt_SavePDF == 1) {
    c1->SaveAs(fname);


  } else {

   c1->Close();
   c10->Close();
   c101->Close();
   c11->Close();

  }

  printf("----- fit results with signal projection   ----------- \n");

  fitted[0] = para[0];
  fitted[1] = errpara[0];
  fitted[2] = para[1];
  fitted[3] = errpara[1];
  fitted[4] = f11->Integral(-1.,5.)/hdata->GetBinWidth(2);
  fitted[5] = f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2);

  return fitted;
}
void 
HTT_TT_X(bool scaled=true, bool log=false, float min=0., float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="$CATEGORY")
{
  // define common canvas, axes pad styles
  SetStyle(); gStyle->SetLineStyleString(11,"20 10");

  // determine category tag
  const char* category_extra = "";
  if(std::string(directory) == std::string("emu_0jet_low"  )){ category_extra = "0 jet, low p_{T}";  }
  if(std::string(directory) == std::string("emu_0jet_high" )){ category_extra = "0 jet, high p_{T}"; }
  if(std::string(directory) == std::string("emu_boost_low" )){ category_extra = "1 jet, low p_{T}";  }
  if(std::string(directory) == std::string("emu_boost_high")){ category_extra = "1 jet, high p_{T}"; }
  if(std::string(directory) == std::string("emu_vbf"       )){ category_extra = "2 jet (VBF)";       }
  if(std::string(directory) == std::string("emu_nobtag"    )){ category_extra = "No B-Tag";          }
  if(std::string(directory) == std::string("emu_btag"      )){ category_extra = "B-Tag";             }

  const char* dataset;
  if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary,  ZH#rightarrow#lltau#tau, 4.9 fb^{-1} at 7 TeV";}
  if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary,  ZH#rightarrowll#tau#tau, 19.4 fb^{-1} at 8 TeV";}
#ifdef MSSM
  if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV";}
#endif
  
  TFile* input = new TFile(inputfile);
  TH1F* ZZ  = refill((TH1F*)input->Get(TString::Format("%s/ZZ"   , directory)), "ZZ"); InitHist(ZZ, "", "", kMagenta-10, 1001);
  TH1F* GGToZZ2L2L  = refill((TH1F*)input->Get(TString::Format("%s/GGToZZ2L2L"   , directory)), "GGToZZ2L2L"); InitHist(GGToZZ2L2L, "", "", kMagenta-10, 1001);
  TH1F* Zjets    = refill((TH1F*)input->Get(TString::Format("%s/Zjets"     , directory)), "Zjets"  ); InitHist(Zjets  , "", "", kRed    + 2, 1001);
#ifndef DROP_SIGNAL
  TH1F* ZH_htt    = refill((TH1F*)input->Get(TString::Format("%s/ZH_htt"  , directory)+"125"), "ZH_htt"  ); InitSignal(ZH_htt); ZH_htt->Scale(SIGNAL_SCALE);
  TH1F* ZH_hww    = refill((TH1F*)input->Get(TString::Format("%s/ZH_hww"  , directory)+"125"), "ZH_hww"  ); InitSignal(ZH_hww); ZH_hww->Scale(SIGNAL_SCALE);
#endif
  TH1F* data   = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true);
  InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data);

  TH1F* ref=(TH1F*)ZZ->Clone("ref");
  ref->Add(GGToZZ2L2L);
  ref->Add(Zjets  );

  double unscaled[5];
  unscaled[0] = ZZ->Integral();
  unscaled[1] = GGToZZ2L2L->Integral();
  unscaled[2] = Zjets  ->Integral();
#ifndef DROP_SIGNAL
  unscaled[3] = ZH_htt  ->Integral();
  unscaled[4] = ZH_hww  ->Integral();
#endif

  if(scaled){
    rescale(ZZ, 1);
    rescale(GGToZZ2L2L, 2);
    rescale(Zjets,   3);
#ifndef DROP_SIGNAL
    rescale(ZH_htt,   4);
    rescale(ZH_hww,   5);
#endif
  }

  TH1F* scales[5];
  scales[0] = new TH1F("scales-ZZ", "", 5, 0, 5);
  scales[0]->SetBinContent(1, unscaled[0]>0 ? (ZZ->Integral()/unscaled[0]-1.) : 0.);
  scales[1] = new TH1F("scales-GGToZZ2L2L", "", 5, 0, 5);
  scales[1]->SetBinContent(2, unscaled[1]>0 ? (GGToZZ2L2L->Integral()/unscaled[1]-1.) : 0.);
  scales[2] = new TH1F("scales-Zjets"  , "", 5, 0, 5);
  scales[2]->SetBinContent(3, unscaled[2]>0 ? (Zjets  ->Integral()/unscaled[2]-1.) : 0.);
#ifndef DROP_SIGNAL
  scales[3] = new TH1F("scales-ZH_htt"  , "", 5, 0, 5);
  scales[3]->SetBinContent(4, unscaled[3]>0 ? (ZH_htt  ->Integral()/unscaled[3]-1.) : 0.);
  scales[4] = new TH1F("scales-ZH_hww"  , "", 5, 0, 5);
  scales[4]->SetBinContent(5, unscaled[4]>0 ? (ZH_hww  ->Integral()/unscaled[4]-1.) : 0.);
#endif

  GGToZZ2L2L->Add(Zjets);
  ZZ  ->Add(GGToZZ2L2L);
  if(log){
#ifndef DROP_SIGNAL
    ZH_htt  ->Add(ZH_hww );
#endif
  }
  else{
#ifndef DROP_SIGNAL
    ZH_htt   ->Add(ZH_hww);
#endif
  }

  /*
    mass plot before and after fit
  */
  TCanvas* canv = MakeCanvas("canv", "histograms", 600, 600);
  canv->cd();
  if(log){ canv->SetLogy(1); }
#if defined MSSM
  if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); };
#else
  data->GetXaxis()->SetRange(0, data->FindBin(350));
#endif

  data->SetNdivisions(505);
  data->SetMinimum(min);
  float maxZZ=ZZ->GetBinContent(ZZ->GetMaximumBin()); float maxdata=data->GetBinContent(data->GetMaximumBin());
  if (maxdata>maxZZ)
     data->SetMaximum(1.8*maxdata);
  else
     data->SetMaximum(1.8*maxZZ);
  data->Draw("e");

//  TH1F* errorBand = (TH1F*)ZZ ->Clone();
  TH1F* errorBand = (TH1F*)Zjets ->Clone();
  errorBand  ->SetMarkerSize(0);
  errorBand  ->SetFillColor(1);
  errorBand  ->SetFillStyle(3013);
  errorBand  ->SetLineWidth(1);
  errorBand  ->Scale(0.15);
  for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){
    if(errorBand->GetBinContent(idx)>0){
      std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl;
      break;
    }
  }
  //if(log){
    ZZ  ->Draw("histsame");
    Zjets->Draw("histsame");
    $DRAW_ERROR
#ifndef DROP_SIGNAL
    ZH_htt  ->Draw("histsame");
#endif
  //}
  //else{
//#ifndef DROP_SIGNAL
//    ggH  ->Draw("histsame");
//#endif
//    Ztt  ->Draw("histsame");
//    ttbar->Draw("histsame");
//    EWK  ->Draw("histsame");
//    Fakes->Draw("histsame");
//    $DRAW_ERROR
//  }
  data->Draw("esame");
  canv->RedrawAxis();

//  //CMSPrelim(dataset, "#tau_{e}#tau_{#mu}", 0.17, 0.835);  
  CMSPrelim(dataset, "", 0.16, 0.835);  
  TPaveText* chan     = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC");
  chan->SetBorderSize(   0 );
  chan->SetFillStyle(    0 );
  chan->SetTextAlign(   12 );
  chan->SetTextSize ( 0.05 );
  chan->SetTextColor(    1 );
  chan->SetTextFont (   62 );
  if (directory=="eett_zh") 
    chan->AddText("#tau#tau");
  else
    chan->AddText("#mu#mu#tau#tau");
  chan->Draw();
//
//  TPaveText* cat      = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC");
//  cat->SetBorderSize(   0 );
//  cat->SetFillStyle(    0 );
//  cat->SetTextAlign(   12 );
//  cat->SetTextSize ( 0.05 );
//  cat->SetTextColor(    1 );
//  cat->SetTextFont (   62 );
//  cat->AddText(category_extra);
//  cat->Draw();
//
//#ifdef MSSM
//  TPaveText* massA      = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC");
//  massA->SetBorderSize(   0 );
//  massA->SetFillStyle(    0 );
//  massA->SetTextAlign(   12 );
//  massA->SetTextSize ( 0.03 );
//  massA->SetTextColor(    1 );
//  massA->SetTextFont (   62 );
//  massA->AddText("m_{A}=$MAGeV");
//  massA->Draw();
//
//  TPaveText* tanb      = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC");
//  tanb->SetBorderSize(   0 );
//  tanb->SetFillStyle(    0 );
//  tanb->SetTextAlign(   12 );
//  tanb->SetTextSize ( 0.03 );
//  tanb->SetTextColor(    1 );
//  tanb->SetTextFont (   62 );
//  tanb->AddText("tan#beta=$TANB");
//  tanb->Draw();
// 
//  TPaveText* scen      = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC");
//  scen->SetBorderSize(   0 );
//  scen->SetFillStyle(    0 );
//  scen->SetTextAlign(   12 );
//  scen->SetTextSize ( 0.03 );
//  scen->SetTextColor(    1 );
//  scen->SetTextFont (   62 );
//  scen->AddText("mhmax");
//  scen->Draw();
//#endif
//
//#ifdef MSSM  
//  TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90);
//  SetLegendStyle(leg);
//  leg->AddEntry(ggH  , "#phi#rightarrow#tau#tau" , "L" );
//#else
  TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90);
  SetLegendStyle(leg);
//#ifndef DROP_SIGNAL
//  if(SIGNAL_SCALE!=1){
    leg->AddEntry(ZH_htt  , TString::Format("%.0f#timesZH(125 GeV)#rightarrowll#tau#tau", SIGNAL_SCALE) , "L" );
//  }
//  else{
//    leg->AddEntry(ggH  , "H(125 GeV)#rightarrow#tau#tau" , "L" );
//  }
//#endif
//#endif
  leg->AddEntry(data , "observed"                       , "LP");
  leg->AddEntry(ZZ  , "ZZ"           , "F" );
  leg->AddEntry(Zjets, "Reducible"                       , "F" );
//  leg->AddEntry(EWK  , "electroweak"                    , "F" );
//  leg->AddEntry(Fakes, "QCD"                            , "F" );
  $ERROR_LEGEND
  leg->Draw();
//
////#ifdef MSSM
////  TPaveText* mssm  = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC");
////  mssm->SetBorderSize(   0 );
////  mssm->SetFillStyle(    0 );
////  mssm->SetTextAlign(   12 );
////  mssm->SetTextSize ( 0.03 );
////  mssm->SetTextColor(    1 );
////  mssm->SetTextFont (   62 );
////  mssm->AddText("(m_{A}=250, tan#beta=5)");
////  mssm->Draw();
////#else
////  TPaveText* mssm  = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC");
////  mssm->SetBorderSize(   0 );
////  mssm->SetFillStyle(    0 );
////  mssm->SetTextAlign(   12 );
////  mssm->SetTextSize ( 0.03 );
////  mssm->SetTextColor(    1 );
////  mssm->SetTextFont (   62 );
////  mssm->AddText("m_{H}=125");
////  mssm->Draw();
////#endif
//
//  /*
//    Ratio Data over MC
//  */
//  TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400);
//  canv0->SetGridx();
//  canv0->SetGridy();
//  canv0->cd();
//
//  TH1F* zero = (TH1F*)ref ->Clone("zero"); zero->Clear();
//  TH1F* rat1 = (TH1F*)data->Clone("rat"); 
//  rat1->Divide(Ztt);
//  for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){
//    if(rat1->GetBinContent(ibin+1)>0){
//      // catch cases of 0 bins, which would lead to 0-alpha*0-1
//      rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.);
//    }
//    zero->SetBinContent(ibin+1, 0.);
//  }
//  rat1->SetLineColor(kBlack);
//  rat1->SetFillColor(kGray );
//  rat1->SetMaximum(+0.5);
//  rat1->SetMinimum(-0.5);
//  rat1->GetYaxis()->CenterTitle();
//  rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}");
//  rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}");
//  rat1->Draw();
//  zero->SetLineColor(kBlack);
//  zero->Draw("same");
//  canv0->RedrawAxis();
//
//  /*
//    Ratio After fit over Prefit
//  */
//  TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400);
//  canv1->SetGridx();
//  canv1->SetGridy();
//  canv1->cd();
//
//  TH1F* rat2 = (TH1F*) Ztt->Clone("rat2");
//  rat2->Divide(ref);
//  for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){
//    if(rat2->GetBinContent(ibin+1)>0){
//      // catch cases of 0 bins, which would lead to 0-alpha*0-1
//      rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.);
//    }
//  }
//  rat2->SetLineColor(kRed+ 3);
//  rat2->SetFillColor(kRed-10);
//  rat2->SetMaximum(+0.3);
//  rat2->SetMinimum(-0.3);
//  rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}");
//  rat2->GetYaxis()->CenterTitle();
//  rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}");
//  rat2->GetXaxis()->SetRange(0, 28);
//  rat2->Draw();
//  zero->SetLineColor(kBlack);
//  zero->Draw("same");
//  canv1->RedrawAxis();
//
//  /*
//    Relative shift per sample
//  */
//  TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400);
//  canv2->SetGridx();
//  canv2->SetGridy();
//  canv2->cd();
//
//  InitHist  (scales[0], "", "", kMagenta-10, 1001);
//  InitHist  (scales[1], "", "", kRed    + 2, 1001);
//  InitHist  (scales[2], "", "", kBlue   - 8, 1001);
//  InitHist  (scales[3], "", "", kOrange - 4, 1001);
//#ifndef DROP_SIGNAL
//  InitSignal(scales[4]);
//  InitSignal(scales[5]);
//  InitSignal(scales[6]);
//#endif
//  scales[0]->Draw();
//  scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}");
//  scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}"  );
//  scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}");
//  scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}"  );
//#ifdef MSSM
//  scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}"  );
//  scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}"  );
//  scales[0]->GetXaxis()->SetBinLabel(7, "#bf{NONE}" );
//#else
//  scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}"  );
//  scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}"  );
//  scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}"   );
//#endif
//  scales[0]->SetMaximum(+1.0);
//  scales[0]->SetMinimum(-1.0);
//  scales[0]->GetYaxis()->CenterTitle();
//  scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}");
//  scales[1]->Draw("same");
//  scales[2]->Draw("same");
//  scales[3]->Draw("same");
//#ifndef DROP_SIGNAL
//  scales[4]->Draw("same");
//  scales[5]->Draw("same");
//  scales[6]->Draw("same");
//#endif
//  zero->Draw("same");
//  canv2->RedrawAxis();
//
//  /*
//    prepare output
//  */
  bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos;
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.png"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
//  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
//  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
//  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
//  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
//  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
//  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
//  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
//  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
//  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update");
  output->cd(); 
  data ->Write("data_obs");
  ZZ->Write("ZZ"   );
  Zjets  ->Write("Zjets"     );
  ZH_htt->Write("ZH_htt"   );
  ZH_hww  ->Write("ZH_hww"     );
//#ifdef MSSM
//  ggH  ->Write("ggH"     );
//  bbH  ->Write("bbH"     );
//#else
//#ifndef DROP_SIGNAL
//  ggH  ->Write("ggH"     );
//  qqH  ->Write("qqH"     );
//  VH   ->Write("VH"      );
//#endif
//#endif
  if(errorBand){
    errorBand->Write("errorBand");
  }
  output->Close();
}
Пример #27
0
void 
postfit_use(const char* inputfile, const char* analysis = "SM", const char* dataset = "2011+2012", const char* extra="", const char* extra2="", float min=0.1, float max=-1., bool log=true)
{
  // defining the common canvas, axes pad styles
  SetStyle(); gStyle->SetLineStyleString(11,"20 10");
  // switch for MSSM/SM
  bool MSSM = std::string(analysis) == std::string("MSSM");
  // determine label
  if (std::string(dataset) == std::string("2011"     )){ dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV"; }
  if (std::string(dataset) == std::string("2012"     )){ dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 19.8 fb^{-1} at 8 TeV"; }
  if (std::string(dataset) == std::string("2011+2012")){ dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV, 19.8 fb^{-1} at 8 TeV"; }
  // determine category tag
  const char* category_extra = "";
  if(std::string(extra2) == std::string("0jet_low"  )){ category_extra = "0 jet, low p_{T}";  }
  if(std::string(extra2) == std::string("0jet_high" )){ category_extra = "0 jet, high p_{T}"; }
  if(std::string(extra2) == std::string("0jet"      )){ category_extra = "0 jet";             }
  if(std::string(extra2) == std::string("1jet_low"  )){ category_extra = "1 jet, low p_{T}";  }
  if(std::string(extra2) == std::string("1jet_high" )){ category_extra = "1 jet, high p_{T}"; }
  if(std::string(extra2) == std::string("1jet"      )){ category_extra = "1 jet";             }
  if(std::string(extra2) == std::string("vbf"       )){ category_extra = "2 jet (VBF)";       }
  if(std::string(extra2) == std::string("nobtag"    )){ category_extra = "No B-Tag";          }
  if(std::string(extra2) == std::string("btag"      )){ category_extra = "B-Tag";             }

  TFile* input = new TFile(inputfile);
  TH1F* Fakes  = refill((TH1F*)input->Get("Fakes"   ), "Fakes/QCD"); 
  TH1F* EWK    = refill((TH1F*)input->Get("EWK"     ), "EWK"      ); 
  TH1F* ttbar  = refill((TH1F*)input->Get("ttbar"   ), "ttbar"    ); 
  TH1F* Ztt    = refill((TH1F*)input->Get("Ztt"     ), "Ztt"      ); 
  TH1F* Zmm    = refill((TH1F*)input->Get("Zmm"     ), "Zmm"      ); 
  TH1F* Zee    = refill((TH1F*)input->Get("Zee"     ), "Zee"      ); 
  TH1F* ggH    = refill((TH1F*)input->Get("ggH"     ), "ggH"      ); 
  TH1F* data   = (TH1F*)input->Get("data_obs"); 
  // determine channel for etau Z->ee (EWK) will be shown separated from the rest (EWK1)
  TH1F* EWK1   = 0;
  if(std::string(extra) == std::string("e#tau_{h}")){
    EWK1 = refill((TH1F*)input->Get("EWK1"),  "EWK1");
  }
  TH1F* ggH_hww = 0;
  if(std::string(extra) == std::string("e#mu") and HWWBG){
    ggH_hww= refill((TH1F*)input->Get("ggH_hww" ), "ggH_hww"  ); 
  }
  TH1F* errorBand = (TH1F*)input->Get("errorBand");

  /* 
    mass plot before and after fit
  */
  TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600);
  if(log) canv->SetLogy(1);
  // reduce the axis range if necessary for linea plots and SM
  if(MSSM && !log){ data->GetXaxis()->SetRange(0, data->FindBin(345)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(UPPER_EDGE)); };
  if(!MSSM){ data->GetXaxis()->SetRange(0, data->FindBin(345)); }
  data->SetNdivisions(505);
  data->SetMinimum(min);
  if(std::string(extra) == std::string("#mu#mu")){
    data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Zmm, log)));
    data->Draw("e");
    if(log){
      Zmm  ->Draw("same");
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      Fakes->Draw("same");
      EWK  ->Draw("same");
      if(ggH) ggH  ->Draw("histsame");
    }
  }
  else if(std::string(extra) == std::string("ee")){
    data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Zee, log)));
    data->Draw("e");
    if(log){
      Zee  ->Draw("same");
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      Fakes->Draw("same");
      EWK  ->Draw("same");
      if(ggH) ggH  ->Draw("histsame");
    }
  }
  else if(std::string(extra) == std::string("e#tau_{h}")){
    data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log)));
    data->Draw("e");
    if(log){
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      EWK  ->Draw("same");
      EWK1 ->Draw("same");
      Fakes->Draw("same");
      if(ggH) ggH  ->Draw("histsame");
    }
    else{
      if(ggH) ggH  ->Draw("histsame");
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      EWK  ->Draw("same");
      EWK1 ->Draw("same");
      Fakes->Draw("same");
    } 
  }
  else if(std::string(extra) == std::string("e#mu") && HWWBG){
    data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(ggH_hww, log)));
    data->Draw("e");
    if(log){
      ggH_hww -> Draw("same");
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      EWK  ->Draw("same");
      Fakes->Draw("same");
      if(ggH) ggH  ->Draw("histsame");
    }
    else{
      if(ggH) ggH  ->Draw("histsame");
      ggH_hww -> Draw("same");
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      EWK  ->Draw("same");
      Fakes->Draw("same");
    } 
  }
  else{
    data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log)));
    data->Draw("e");
    if(log){
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      EWK  ->Draw("same");
      Fakes->Draw("same");
      if(ggH) ggH  ->Draw("histsame");
    }
    else{
      if(ggH) ggH  ->Draw("histsame");
      Ztt  ->Draw("same");
      ttbar->Draw("same");
      EWK  ->Draw("same");
      Fakes->Draw("same");
    } 
  }
  if(errorBand){
    errorBand->Draw("e2same");
  }
  data->Draw("esame");
  canv->RedrawAxis();




  //CMSPrelim(dataset, extra, 0.17, 0.835);
  CMSPrelim(dataset, "", 0.18, 0.835);  
  TPaveText* chan     = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC");
  chan->SetBorderSize(   0 );
  chan->SetFillStyle(    0 );
  chan->SetTextAlign(   12 );
  chan->SetTextSize ( 0.05 );
  chan->SetTextColor(    1 );
  chan->SetTextFont (   62 );
  chan->AddText(extra);
  chan->Draw();

  TPaveText* cat      = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC");
  cat->SetBorderSize(   0 );
  cat->SetFillStyle(    0 );
  cat->SetTextAlign(   12 );
  cat->SetTextSize ( 0.05 );
  cat->SetTextColor(    1 );
  cat->SetTextFont (   62 );
  cat->AddText(category_extra);
  cat->Draw();

  if(MSSM){
    float lower_bound = EWK1 ? 0.45 : 0.50;
    TPaveText* massA      = new TPaveText(0.55, lower_bound+0.061, 0.95, lower_bound+0.161, "NDC");
    massA->SetBorderSize(   0 );
    massA->SetFillStyle(    0 );
    massA->SetTextAlign(   12 );
    massA->SetTextSize ( 0.03 );
    massA->SetTextColor(    1 );
    massA->SetTextFont (   62 );
    massA->AddText("m^{h}_{max} (m_{A}=$MA GeV, tan#beta=$TANB)");
    massA->Draw();
  }    
  float lower_bound = EWK1 ? 0.60 : 0.65;
  TLegend* leg = new TLegend(MSSM ? 0.55 : 0.50, lower_bound, 0.93, 0.90);
  SetLegendStyle(leg);
  if(MSSM){
    leg->AddEntry(ggH  , "#phi#rightarrow#tau#tau", "L" );
  }
  else{
    if(ggH){
      if(SIGNAL_SCALE!=1){
	leg->AddEntry(ggH  , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" );
      }
      else{
	leg->AddEntry(ggH  , "H(125 GeV)#rightarrow#tau#tau" , "L" );
      }
    }
  }
  leg->AddEntry(data , "observed"                       , "LP");
  
  if(std::string(extra) == std::string("#mu#mu")){
    leg->AddEntry(Zmm  , "Z#rightarrow#mu#mu"    , "F" );
    leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"           , "F" );
    leg->AddEntry(ttbar, "t#bar{t}"                       , "F" );
    leg->AddEntry(Fakes, "QCD"                 , "F" );
    leg->AddEntry(EWK  , "electroweak"                  , "F" );
  }
  else if(std::string(extra) == std::string("ee")){
    leg->AddEntry(Zee  , "Z#rightarrowee"        , "F" );
    leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"           , "F" );
    leg->AddEntry(ttbar, "t#bar{t}"                       , "F" );
    leg->AddEntry(Fakes, "QCD"                 , "F" );
    leg->AddEntry(EWK  , "electroweak"                  , "F" );
  }
  else if(std::string(extra) == std::string("e#tau_{h}")){
    leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"           , "F" );
    leg->AddEntry(EWK  , "Z#rightarrow ee"              , "F" );
    leg->AddEntry(EWK1 , "electroweak"                  , "F" );
    leg->AddEntry(ttbar, "t#bar{t}"                       , "F" );
    leg->AddEntry(Fakes, "QCD"                 , "F" );
  }
  else if(std::string(extra) == std::string("e#mu") && HWWBG){
    leg->AddEntry(ggH_hww  , "H(125 GeV)#rightarrowWW" , "F" );
    leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"           , "F" );
    leg->AddEntry(ttbar, "t#bar{t}"                       , "F" );
    leg->AddEntry(EWK  , "electroweak"                  , "F" );
    leg->AddEntry(Fakes, "QCD"                 , "F" );
  }
  else{
    leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"           , "F" );
    leg->AddEntry(ttbar, "t#bar{t}"                       , "F" );
    leg->AddEntry(EWK  , "electroweak"                  , "F" );
    leg->AddEntry(Fakes, "QCD"                 , "F" );
  }
  if(errorBand){
    leg->AddEntry(errorBand, "bkg. uncertainty" , "F" );
  }
  leg->Draw();

  /*
    prepare output
  */
  std::string newName = std::string(inputfile).substr(0, std::string(inputfile).find(".root"));
  canv->Print(TString::Format("%s.png", newName.c_str())); 
  canv->Print(TString::Format("%s.pdf", newName.c_str())); 
  canv->Print(TString::Format("%s.eps", newName.c_str())); 

  /*
    Ratio Data over MC
  */
  TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400);
  canv0->SetGridx();
  canv0->SetGridy();
  canv0->cd(); 
  TH1F* model;
  if(CONSERVATIVE_CHI2){
    if(std::string(extra) == std::string("#mu#mu")){
      model = (TH1F*)Zmm ->Clone("model");
    }
    else if(std::string(extra) == std::string("ee")){
      model = (TH1F*)Zee ->Clone("model");
    }
    else if(std::string(extra) == std::string("e#mu") && HWWBG){
      model = (TH1F*)ggH_hww ->Clone("model");
    }
    else{  
      model = (TH1F*)Ztt ->Clone("model");
    }
  }
  else{
    model = (TH1F*)errorBand->Clone("model");
  }
  TH1F* test1 = (TH1F*)data->Clone("test1"); 
  for(int ibin=0; ibin<test1->GetNbinsX(); ++ibin){
    //the small value in case of 0 entries in the model is added to prevent the chis2 test from failing
    model->SetBinContent(ibin+1, model->GetBinContent(ibin+1)>0 ? model->GetBinContent(ibin+1)*model->GetBinWidth(ibin+1) : 0.01);
    model->SetBinError  (ibin+1, CONSERVATIVE_CHI2 ? 0. : model->GetBinError  (ibin+1)*model->GetBinWidth(ibin+1));
    test1->SetBinContent(ibin+1, test1->GetBinContent(ibin+1)*test1->GetBinWidth(ibin+1));
    test1->SetBinError  (ibin+1, test1->GetBinError  (ibin+1)*test1->GetBinWidth(ibin+1));
  }
  double chi2prob = test1->Chi2Test      (model,"PUW");        std::cout << "chi2prob:" << chi2prob << std::endl;
  double chi2ndof = test1->Chi2Test      (model,"CHI2/NDFUW"); std::cout << "chi2ndf :" << chi2ndof << std::endl;
  double ksprob   = test1->KolmogorovTest(model);              std::cout << "ksprob  :" << ksprob   << std::endl;
  double ksprobpe = test1->KolmogorovTest(model,"DX");         std::cout << "ksprobpe:" << ksprobpe << std::endl;  

  std::vector<double> edges;
  TH1F* zero = (TH1F*)Ztt->Clone("zero"); zero->Clear();
  TH1F* rat1 = (TH1F*)data->Clone("rat"); 
  for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){
    rat1->SetBinContent(ibin+1, errorBand->GetBinContent(ibin+1)>0 ? data->GetBinContent(ibin+1)/errorBand->GetBinContent(ibin+1) : 0);
    rat1->SetBinError  (ibin+1, errorBand->GetBinContent(ibin+1)>0 ? data->GetBinError  (ibin+1)/errorBand->GetBinContent(ibin+1) : 0);
    zero->SetBinContent(ibin+1, 0.);
    zero->SetBinError  (ibin+1, errorBand->GetBinContent(ibin+1)>0 ? errorBand ->GetBinError  (ibin+1)/errorBand->GetBinContent(ibin+1) : 0);
  }
  for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){
    if(rat1->GetBinContent(ibin+1)>0){
      edges.push_back(TMath::Abs(rat1->GetBinContent(ibin+1)-1.)+TMath::Abs(rat1->GetBinError(ibin+1)));
      // catch cases of 0 bins, which would lead to 0-alpha*0-1
      rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.);
    }
    zero->SetBinContent(ibin+1, 0.);
  }
  float range = 0.1;
  std::sort(edges.begin(), edges.end());
  if (edges[edges.size()-2]>0.1) { range = 0.2; }
  if (edges[edges.size()-2]>0.2) { range = 0.5; }
  if (edges[edges.size()-2]>0.5) { range = 1.0; }
  if (edges[edges.size()-2]>1.0) { range = 1.5; }
  if (edges[edges.size()-2]>1.5) { range = 2.0; }
  rat1->SetLineColor(kBlack);
  rat1->SetFillColor(kGray );
  rat1->SetMaximum(+range);
  rat1->SetMinimum(-range);
  rat1->GetYaxis()->CenterTitle();
  rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}");
  if((std::string(extra) == std::string("#mu#mu") || std::string(extra) == std::string("ee")) && !MSSM){
    rat1->GetXaxis()->SetTitle("#bf{D}");
  }
  else{
    rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}");
  }
  rat1->Draw();
  zero->SetFillStyle(  3013);
  zero->SetFillColor(kBlack);
  zero->SetLineColor(kBlack);
  zero->SetMarkerSize(0.1);
  zero->Draw("e2histsame");
  canv0->RedrawAxis();

  TPaveText* stat1 = new TPaveText(0.20, 0.76+0.061, 0.32, 0.76+0.161, "NDC");
  stat1->SetBorderSize(   0 );
  stat1->SetFillStyle(    0 );
  stat1->SetTextAlign(   12 );
  stat1->SetTextSize ( 0.05 );
  stat1->SetTextColor(    1 );
  stat1->SetTextFont (   62 );
  stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f,  P(#chi^{2})=%.3f", chi2ndof, chi2prob));
  //stat1->AddText(TString::Format("#chi^{2}/ndf=%.3f,  P(#chi^{2})=%.3f,  P(KS)=%.3f", chi2ndof, chi2prob, ksprob));
  stat1->Draw();

  /*
    prepare output
  */
  newName = std::string(inputfile).substr(0, std::string(inputfile).find(".root")) + "_datamc";
  canv0->Print(TString::Format("%s.png", newName.c_str())); 
  canv0->Print(TString::Format("%s.pdf", newName.c_str())); 
  canv0->Print(TString::Format("%s.eps", newName.c_str())); 
}
//------------------------------------------------------------------------------
// Draw projections and residuals
//------------------------------------------------------------------------------
void DrawWithRatio(TCanvas *canvas, char *cTitle,
                  TH1F *hNum, TH1F *hDen)
{
 
 // sanity check
 if (hNum->GetNbinsX() != hDen->GetNbinsX()){
   std::cout<< " *** Error: binning not consistent between data"
            << " and MC -> Exit!\n";
   return;
 }

 
 hNum->Sumw2();
 hDen->Sumw2();

 
 TH1F *hPull = (TH1F*)hNum ->Clone("hPull");
 hPull->Sumw2();
 hPull->Divide(hDen);
 
 //----------------------------------------------------------------------------
 // Create the pads
 //----------------------------------------------------------------------------
 TPad* pad1;
 TPad* pad2;
 
 pad1 = new TPad("pad1","This is pad1",0.02,0.30,0.98,0.98,0);
 pad2 = new TPad("pad2","This is pad2",0.02,0.01,0.98,0.29,0);
 
 pad1->SetLogx();
 pad2->SetLogx();
 pad1->SetBottomMargin(0.01);
 pad2->SetBottomMargin(0.33);
 pad2->SetTopMargin   (0.10);
 
 pad1->Draw(); // Projections pad
 pad2->Draw(); // Residuals   pad
        
        _leg2 = new TLegend(.68,.77,.98,.93);
        _leg2->AddEntry(hDen,"Gen ","l");
        _leg2->AddEntry(hNum,"Unfolded Reco","p");
 pad1->cd();
 hDen->Draw("histo");
 hNum->Draw("pe same");
 _leg2->Draw(); 
 PrintItLog(pad1,cTitle);

//   TLegend* leg = SetLegend(0.73, 0.7, 0.92, 0.89);
//   leg -> AddEntry(hDen," no mass cut","f");
//   leg -> AddEntry(hNum," 60 < M^{#mu #mu} < 120","p");
//   leg ->Draw("same");
 //----------------------------------------------------------------------------
 // Residuals pad
 //----------------------------------------------------------------------------
 pad2->cd();
 
 TAxis *xPull = NULL;
 TAxis *yPull = NULL;
 char xAxisName[200];
 sprintf(xAxisName,"%s",hDen->GetXaxis()->GetTitle());
 axis1F(hPull,xPull,yPull,xAxisName,"ratio");
 
 if (hPull->GetMaximum() > 100) {
   hPull->SetMinimum(-100);
   hPull->SetMaximum( 100);
 }
 
 hPull->GetXaxis()->SetLabelOffset(0.005);
 hPull->GetXaxis()->SetLabelSize  (0.11);
 hPull->GetXaxis()->CenterTitle(1);
 hPull->GetXaxis()->SetTitleOffset(1.10);
 hPull->GetXaxis()->SetTitleSize  (0.12);
 hPull->GetXaxis()->SetNdivisions(7);

 hPull->GetYaxis()->SetLabelSize  (0.09);
 hPull->GetYaxis()->CenterTitle(1);
 hPull->GetYaxis()->SetTitleOffset(0.5);
 hPull->GetYaxis()->SetTitleSize  (0.12);

 hPull->SetMaximum(1.5);
 hPull->SetMinimum(0.5);
 hPull->Draw("pe");

 pad2->Update();
 pad2->GetFrame()->DrawClone();

}
Пример #29
0
bool PlotManager::saveFakeRate(const string& histName, const string& histTitle,
                               const string& numeHistName, const string& denoHistName)
{
  if ( ! isSetup_ ) return false;
  
  TH1F* numeHist = (TH1F*)(theSrcFile_->Get(numeHistName.c_str()));
  TH1F* denoHist = (TH1F*)(theSrcFile_->Get(denoHistName.c_str()));
  
  // Check validity of objects
  if ( numeHist == 0 || denoHist == 0 ) {
    cerr << "Cannot get object : " << histName << endl;
    return false;
  }

  if ( ! numeHist->IsA()->InheritsFrom("TH1") || 
       ! denoHist->IsA()->InheritsFrom("TH1") ||
       numeHist->IsA()->InheritsFrom("TH2") ||
       denoHist->IsA()->InheritsFrom("TH2") ) {
    return false;
  }
  
  // Check bin size
  if ( numeHist->GetNbinsX() != denoHist->GetNbinsX() ) {
    cerr << "Bin size of two histograms are not same" << endl;
    return false;
  }
  
  // Push to base directory
  string pwd(gDirectory->GetPath());
  
  string newHistPath = dirname(histName);
  string newHistName = basename(histName);

  if ( newHistPath.empty() ) {
    theOutFile_->cd();
  }
  else if ( theOutFile_->cd(newHistPath.c_str()) == kFALSE ) {
    cout << "Cannot find directory, do mkdirs" << endl;
    mkdirs(theOutFile_, newHistPath)->cd();
  }

  // Create new histogram
  TH1F* fakeHist = dynamic_cast<TH1F*>(numeHist->Clone());
  
  // effHist->Divide(denoHist);
  // Set the error to binomial statistics
  int nBinsX = fakeHist->GetNbinsX();
  for(int bin = 1; bin <= nBinsX; bin++) {
    float nNume = numeHist->GetBinContent(bin);
    float nDeno = denoHist->GetBinContent(bin);
    float fakeRate = nDeno==0 ? 0 : 1.0 - nNume/nDeno;
    float err = 0;
    if ( nDeno != 0 && fakeRate <= 1 ) {
      err = sqrt(fakeRate*(1-fakeRate)/nDeno);
    }
    fakeHist->SetBinContent(bin, fakeRate);
    fakeHist->SetBinError(bin, err);
  }

  // Cosmetics
  fakeHist->SetName(newHistName.c_str());
  fakeHist->SetTitle(histTitle.c_str());
  fakeHist->SetMinimum(0.8);
  fakeHist->SetMaximum(1.0);
  fakeHist->GetXaxis()->SetTitle(numeHist->GetXaxis()->GetTitle());
  fakeHist->GetYaxis()->SetTitle("Efficiency");

  // Save histogram
  fakeHist->Write();

  // Pop directory
  gDirectory->cd(pwd.c_str());
                           
  return true;
}
Пример #30
0
void plotv2(){
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetStripDecimals(0);

  float pt[24];
  float ept[24];

  float v2pAu[24], ev2pAu[24];

  float v2mpcs[24], ev2mpcs[24];
  float v3mpcs[24], ev3mpcs[24];

  float v2bbcs[24], ev2bbcs[24];
  float v3bbcs[24], ev3bbcs[24];

  float v2fvtxs[24], ev2fvtxs[24];
  float v3fvtxs[24], ev3fvtxs[24];

  ifstream fin2mpcs("run15pAu_mpcs_hadron_v2_0_5.txt");
  ifstream fin2bbcs("run15pAu_bbcs_hadron_v2_0_5.txt");
  ifstream fin2fvtxs("run15pAu_fvtx0s_hadron_v2_0_5.txt");
  ifstream fin2fvtxs_RES("../../final05/vn/run15pAu_fvtx0s_hadron_v2_0_5.txt");
  
  ifstream fin2pAu("v2_pt_pAu_00_05_sys.dat");
  /*
  ifstream fin3mpcs("run15pAu_mpcs_hadron_v3_0_5.txt");
  ifstream fin3bbcs("run15pAu_bbcs_hadron_v3_0_5.txt");
  ifstream fin3fvtxs("../../final06/vn/run15pAu_fvtx0s_hadron_v2_0_5.txt");
  */

  float tmp;
  for(int i=0; i<13; i++){
    ept[i]=0;
    fin2pAu>>pt[i]>>v2pAu[i]>>ev2pAu[i]>>tmp;
  }
  TGraphErrors *grpAu2 = new TGraphErrors(13, pt, v2pAu, ept, ev2pAu);

  for(int i=0; i<14; i++){
    ept[i]=0;
    fin2mpcs>>pt[i]>>v2mpcs[i]>>ev2mpcs[i];
    //fin3mpcs>>pt[i]>>v3mpcs[i]>>ev3mpcs[i];

    fin2bbcs>>pt[i]>>v2bbcs[i]>>ev2bbcs[i];
    //fin3bbcs>>pt[i]>>v3bbcs[i]>>ev3bbcs[i];

    fin2fvtxs>>pt[i]>>v2fvtxs[i]>>ev2fvtxs[i];
    //fin3fvtxs>>pt[i]>>v3fvtxs[i]>>ev3fvtxs[i];
  }
  fin2bbcs.close();
  fin2mpcs.close();
  fin2fvtxs.close();

  //fin3bbcs.close();
  //fin3mpcs.close();
  //fin3fvtxs.close();


  TGraphErrors *grmpcs2 = new TGraphErrors(14, pt, v2mpcs, ept, ev2mpcs);
  TGraphErrors *grbbcs2 = new TGraphErrors(14, pt, v2bbcs, ept, ev2bbcs);
  TGraphErrors *grfvtxs2 = new TGraphErrors(14, pt, v2fvtxs, ept, ev2fvtxs);

  TGraphErrors *grmpcs3 = new TGraphErrors(14, pt, v3mpcs, ept, ev3mpcs);
  TGraphErrors *grbbcs3 = new TGraphErrors(14, pt, v3bbcs, ept, ev3bbcs);
  TGraphErrors *grfvtxs3 = new TGraphErrors(14, pt, v3fvtxs, ept, ev3fvtxs);

  c1=new TCanvas("c1","c1");
  c1->SetFillColor(10);
  c1->cd();

  TH1F *h = new TH1F("h", "h", 50, 0, 5.0);
  h->SetMinimum(0.002);
  h->SetMaximum(0.312);
  h->SetMarkerStyle(20);
  h->SetMarkerSize(1.2);
  h->Draw();

  h->GetYaxis()->SetTitleOffset(0.9);
  h->GetYaxis()->SetTitleSize(0.05);
  h->GetYaxis()->SetTitle("v_{2}");

  h->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  h->GetXaxis()->SetTitleSize(0.04);
  h->GetYaxis()->CenterTitle(kTRUE);
  h->GetXaxis()->CenterTitle(kTRUE);

  grmpcs2->SetMarkerStyle(20);
  grmpcs2->SetMarkerSize(1.2);
  grmpcs2->SetMarkerColor(2);
  //grmpcs2->Draw("P");

  grbbcs2->SetMarkerStyle(24);
  grbbcs2->SetMarkerSize(1.2);
  grbbcs2->SetMarkerColor(4);
  grbbcs2->Draw("P");

  grfvtxs2->SetMarkerStyle(21);
  grfvtxs2->SetMarkerSize(1.2);
  grfvtxs2->SetMarkerColor(6);
  grfvtxs2->Draw("P");

  grpAu2->SetMarkerStyle(21);
  grpAu2->SetMarkerSize(1.2);
  grpAu2->SetMarkerColor(4);
  //grpAu2->Draw("P");

  grmpcs3->SetMarkerStyle(22);
  grmpcs3->SetMarkerSize(1.2);
  grmpcs3->SetMarkerColor(6);
  //grmpcs3->Draw("P");

  grbbcs3->SetMarkerStyle(23);
  grbbcs3->SetMarkerSize(1.2);
  grbbcs3->SetMarkerColor(9);
  //grbbcs3->Draw("P");

  grfvtxs3->SetMarkerStyle(25);
  grfvtxs3->SetMarkerSize(1.2);
  grfvtxs3->SetMarkerColor(4);
  //fvtxs3->Draw("P");

  TLegend *leg1 = new TLegend(0.20,0.60,0.60,0.88);
  leg1->SetFillColor(10);
  leg1->SetLineStyle(4000);
  leg1->SetLineColor(10);
  leg1->SetLineWidth(0.);
  leg1->SetTextSize(0.05);
  leg1->SetBorderSize(0);
  leg1->AddEntry(grmpcs2,"0~5%","");
  //leg1->AddEntry(grmpcs2,"v_{2}(pAu, MPCs)","P");
  leg1->AddEntry(grbbcs2,"v_{2}(pAu, BBCs)","P");
  leg1->AddEntry(grfvtxs2,"v_{2}(pAu, FVTXs)","P");
 
  //leg1->AddEntry(grpAu2,"v_{2}(pAu,MPCs)","P");
  //leg1->AddEntry(grmpcs3,"v_{3}(#Psi_{3}^{MPCs}, -4.0<#eta<-4.0)","P");
  //leg1->AddEntry(grbbcs3,"v_{3}(#Psi_{3}^{BBCs}, -4.0<#eta<-4.0)","P");
  //leg1->AddEntry(grfvtxs3,"v_{3}(#Psi_{2}^{FVTXs}, -3.0<#eta<-1.0)","P");
  leg1->Draw();
c1->Print("v2_pAu.pdf");
}