Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:59

0001 #include <iostream>
0002 #include <string.h>
0003 #include <iomanip>
0004 #include<fstream>
0005 #include <math.h>
0006 
0007 #include "TFile.h"
0008 #include "TH1F.h"
0009 #include "TH2F.h"
0010 
0011 
0012 void drawall(char* f1, char* f2 ,string pathName,char* label1, char* label2, char* var , string outname){
0013  
0014   gStyle->SetOptTitle(1);
0015   
0016   TFile* file1 = TFile::Open(f1);
0017   TFile* file2 = TFile::Open(f2);
0018 
0019   TH1F* hf1=0, *hf2=0;
0020 
0021   TH1F* num1=0, *denom1=0;
0022 
0023   char* name1=0, *name2=0;
0024 
0025   const int npaths = 1;
0026   string paths[npaths]={"DQMData/ElectronOf"+pathName+"DQM"};
0027   string Histo_paths[npaths];
0028   for(int i=0;i<npaths;i++){Histo_paths[i]=paths[i]+"/total eff";cout<<Histo_paths[i]<<endl;}
0029 
0030   string fname= outname+"(";
0031   TCanvas* c1= new TCanvas("c1","c1");
0032   c1->SetFillColor(0);
0033   c1->Divide(2,2);
0034 
0035   string out_file=pathName+"Plots.root";
0036   TFile* f=new TFile(out_file.c_str(),"RECREATE");
0037   
0038   for(int path=0; path< npaths ; path++){
0039     
0040     hf1 = (TH1F*)file1->Get(Histo_paths[path].c_str());
0041     hf2 = (TH1F*)file2->Get(Histo_paths[path].c_str());
0042     
0043     int plotnr = 0;
0044     TGraphAsymmErrors* graph1;TGraphAsymmErrors* graph2;
0045     
0046     for(int filter=1; filter < hf1->GetNbinsX() -2 ; filter++){
0047       name1 = hf1->GetXaxis()->GetBinLabel(filter);
0048       name2 = hf1->GetXaxis()->GetBinLabel(filter+1);
0049       
0050       string numname = paths[path] + "/"+ name2 + var;
0051       string denomname = paths[path] + "/"+ name1 + var;
0052       string title = paths[path]+name2+var+"Efficiency";
0053       
0054       num1   =  new TH1F( *(TH1F*)file1->Get(numname.c_str()) );
0055       denom1 =  new TH1F( *(TH1F*)file1->Get(denomname.c_str()) );
0056       num2   =  new TH1F( *(TH1F*)file2->Get(numname.c_str()) ); 
0057       denom2 =  new TH1F( *(TH1F*)file2->Get(denomname.c_str() ));
0058       
0059       graph1=new TGraphAsymmErrors;
0060       graph1->SetName((title+"1").c_str());
0061       graph1->BayesDivide(num1,denom1);
0062       graph1->SetLineColor(2);
0063       graph1->GetXaxis()->SetTitle(var);
0064       graph1->GetYaxis()->SetTitle("Efficiency");
0065       
0066       graph2=new TGraphAsymmErrors;
0067       graph2->SetName((title+"2").c_str());
0068       graph2->BayesDivide(num2,denom2);
0069       graph2->SetLineColor(4);
0070       graph2->SetMarkerStyle(24);
0071       graph2->GetXaxis()->SetTitle(var);
0072       graph2->GetYaxis()->SetTitle("Efficiency");
0073 
0074       TLegend *legend = new TLegend(0.4,0.2,0.55,0.4,"");
0075       l1 = legend->AddEntry(graph1,label1,"lp");
0076       l1 = legend->AddEntry(graph2,label2,"lp");
0077       
0078       TPaveText* pave=new TPaveText();
0079       pave->AddText(name2);
0080       
0081       if(plotnr%4==0){
0082     c1->Clear("D");
0083       }
0084       c1->cd(plotnr%4 + 1);
0085 
0086       graph1->Draw("AP");
0087       graph2->Draw("Psame");
0088       legend->Draw();      
0089       pave->Draw();
0090 
0091       plotnr++;
0092    
0093       if(plotnr%4==0){
0094     cout<<fname<<endl;
0095     c1->Print(fname.c_str());
0096       }   
0097       std::cout <<"::"<<filter<<"::"<<numname << "::"<<num1->GetEntries()<<std::endl;  
0098       std::cout <<"::"<<filter<<"::"<<denomname << "::"<<denom1->GetEntries()<<std::endl;  
0099       graph1->Write();graph2->Write();
0100     }
0101     
0102     if(plotnr%4!=0){
0103       c1->Print(fname.c_str());
0104     }
0105   }
0106   c1->Clear();
0107   fname=outname+")";
0108   c1->Print(fname.c_str());
0109 
0110 
0111 }
0112