PageRenderTime 64ms CodeModel.GetById 15ms app.highlight 41ms RepoModel.GetById 2ms app.codeStats 0ms

/ElectroWeakAnalysis/WMuNu/bin/WMuNuValidatorMacro.cpp

https://github.com/aivanov-cern/cmssw
C++ | 214 lines | 167 code | 39 blank | 8 comment | 29 complexity | 53dc17c517e6987ef677be949204a8ad MD5 | raw file
  1#include "TROOT.h"
  2#include "TSystem.h"
  3#include "TStyle.h"
  4#include "TRint.h"
  5#include "TFile.h"
  6#include "TCanvas.h"
  7#include "TPaveLabel.h"
  8#include "TPad.h"
  9#include "TH1D.h"
 10#include "TLegend.h"
 11
 12int printUsage(){
 13    printf("Usage: WMuNuValidatorMacro [-lbh] 'root_file_to_validate' 'reference_root_file' 'directory_name'\n\n");
 14
 15    printf("\tOptions:\t -l ==> linear scale for Y axes (default is log-scale)\n");
 16    printf("\t        \t -b ==> run in batch (no graphics)\n");
 17    printf("\t        \t -n ==> normalize reference to data (default = false)\n");
 18    printf("\t        \t -h ==> print this message\n\n");
 19
 20
 21    printf("\tInput files:\t Created via '*Validator.py' configuration files in:\n");
 22    printf("\t            \t   $CMSSW_BASE/src/ElectroWeakAnalysis/WMuNu/test/\n\n");
 23
 24    printf("\tOutput: \t Canvases: './WMuNuValidation_$CMSSW_VERSION_*.root'\n");
 25    printf("\t        \t Gifs:     './WMuNuValidation_$CMSSW_VERSION_*.gif'\n\n");
 26
 27    return 1;
 28}
 29
 30int main(int argc, char** argv){
 31
 32  TString chfile;
 33  TString chfileref;
 34  TString DirectoryLast;
 35
 36
 37  int ntrueargs = 0;
 38  bool logyFlag = true;
 39  bool normalize = false;
 40
 41  for (int i=1; i<argc; ++i) {
 42      if (argv[i][0] == '-') {
 43            if (argv[i][1]=='l') logyFlag = false;
 44            else if (argv[i][1]=='b') gROOT->SetBatch();
 45            else if (argv[i][1]=='h') return printUsage();
 46            else if (argv[i][1]=='n') normalize=true;
 47
 48      } else {
 49            ntrueargs += 1;
 50            if (ntrueargs==1) chfile = argv[i];
 51            else if (ntrueargs==2) chfileref = argv[i];
 52            else if (ntrueargs==3) DirectoryLast = argv[i];
 53
 54      }
 55  }
 56
 57  if (ntrueargs!=3) return printUsage();
 58
 59  TRint* app = new TRint("CMS Root Application", 0, 0);
 60
 61  TString cmssw_version = gSystem->Getenv("CMSSW_VERSION");
 62  TString chsample = "WMuNu";
 63  TString chtitle = chsample + " validation for " + cmssw_version;
 64
 65  //TCanvas* c1 = new TCanvas("c1",chtitle.Data());
 66  TCanvas* c1 = new TCanvas("c1",chtitle.Data(),0,0,1024,768);
 67
 68  TPaveLabel* paveTitle = new TPaveLabel(0.1,0.93,0.9,0.99, chtitle.Data());
 69  paveTitle->Draw();
 70
 71  gStyle->SetOptLogy(logyFlag);
 72  gStyle->SetPadGridX(true);
 73  gStyle->SetPadGridY(true);
 74  gStyle->SetOptStat(1111111);
 75  gStyle->SetFillColor(0);
 76
 77  TPad* pad[4];
 78  pad[0] = new TPad("pad_tl","The top-left pad",0.01,0.48,0.49,0.92); 
 79  pad[1] = new TPad("pad_tr","The top-right pad",0.51,0.48,0.99,0.92); 
 80  pad[2] = new TPad("pad_bl","The bottom-left pad",0.01,0.01,0.49,0.46); 
 81  pad[3] = new TPad("pad_br","The bottom-right pad",0.51,0.01,0.99,0.46); 
 82  for (unsigned int i=0; i<4; ++i) pad[i]->Draw();
 83                                                                                
 84  TLegend* leg = new TLegend(0.5,0.9,0.7,1.0);
 85
 86  TFile* input_file = new TFile(chfile.Data(),"READONLY");
 87  TFile* input_fileref = new TFile(chfileref.Data(),"READONLY");
 88  bool first_plots_done = false;
 89
 90  TString directory = DirectoryLast + "/BeforeCuts";
 91
 92  TDirectory* dir_before = input_file->GetDirectory(directory);
 93  TDirectory* dirref_before = input_fileref->GetDirectory(directory);
 94  TList* list_before = dir_before->GetListOfKeys();
 95  list_before->Print();
 96
 97  unsigned int list_before_size = list_before->GetSize();
 98  TString auxTitle = chtitle + ": BEFORE CUTS";
 99  for (unsigned int i=0; i<list_before_size; i+=4) {
100      if (first_plots_done==true) c1->DrawClone();
101      paveTitle->SetLabel(auxTitle.Data());
102      for (unsigned int j=0; j<4; ++j) {
103            pad[j]->cd(); 
104            pad[j]->Clear(); 
105            if ((i+j)>=list_before_size) continue;
106
107            TH1D* h1 = (TH1D*)dir_before->Get(list_before->At(i+j)->GetName()); 
108//            h1->SetLineColor(kBlue);
109//            h1->SetMarkerColor(kBlue);
110            h1->SetMarkerStyle(21);
111            h1->SetLineStyle(1);
112            h1->SetLineWidth(3);
113            h1->SetTitleSize(0.05,"X");
114            h1->SetTitleSize(0.05,"Y");
115            h1->SetXTitle(h1->GetTitle()); 
116            h1->SetYTitle("");
117            h1->SetTitle(""); 
118            h1->SetTitleOffset(0.85,"X");
119
120            TH1D* hr = (TH1D*)dirref_before->Get(list_before->At(i+j)->GetName()); 
121            hr->SetLineColor(kRed);
122//            hr->SetLineStyle(2);
123            hr->SetLineWidth(3);
124            hr->SetTitleSize(0.05,"X");
125            hr->SetTitleSize(0.05,"Y");
126            hr->SetXTitle(h1->GetTitle());
127            hr->SetYTitle("");
128            hr->SetTitle("");
129            hr->SetTitleOffset(0.85,"X");
130
131            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
132            else{hr->Draw("hist");}
133            h1->Draw("same,p");
134
135            leg->Clear();
136            leg->AddEntry(h1,"Skim","L");
137            leg->AddEntry(hr,"Reference","L");
138            leg->Draw();
139      }
140      first_plots_done = true;
141      c1->Modified();
142      c1->Update();
143      char chplot[80];
144      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
145      c1->SaveAs(chplot);
146      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
147      c1->SaveAs(chplot);
148  }
149
150  TString directory2 = DirectoryLast + "/LastCut";
151
152  TDirectory* dir_lastcut = input_file->GetDirectory(directory2);
153  TDirectory* dirref_lastcut = input_fileref->GetDirectory(directory2);
154  TList* list_lastcut = dir_lastcut->GetListOfKeys();
155  list_lastcut->Print();
156
157  unsigned int list_lastcut_size = list_lastcut->GetSize();
158  auxTitle = chtitle + ": AFTER N-1 CUTS";
159  for (unsigned int i=0; i<list_lastcut_size; i+=4) {
160      if (first_plots_done==true) c1->DrawClone();
161      paveTitle->SetLabel(auxTitle.Data());
162      for (unsigned int j=0; j<4; ++j) {
163            pad[j]->cd(); 
164            pad[j]->Clear(); 
165            if ((i+j)>=list_lastcut_size) continue;
166
167            TH1D* h1 = (TH1D*)dir_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
168//            h1->SetLineColor(kBlue);
169//            h1->SetMarkerColor(kBlue);
170            h1->SetMarkerStyle(21);
171            h1->SetLineWidth(3);
172            h1->SetTitleSize(0.05,"X");
173            h1->SetTitleSize(0.05,"Y");
174            h1->SetXTitle(h1->GetTitle()); 
175            h1->SetYTitle("");
176            h1->SetTitle(""); 
177            h1->SetTitleOffset(0.85,"X");
178
179            TH1D* hr = (TH1D*)dirref_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
180            hr->SetLineColor(kRed);
181//            hr->SetLineStyle(2);
182            hr->SetLineWidth(3);
183            hr->SetTitleSize(0.05,"X");
184            hr->SetTitleSize(0.05,"Y");
185            hr->SetXTitle(h1->GetTitle());
186            hr->SetYTitle("");
187            hr->SetTitle("");
188            hr->SetTitleOffset(0.85,"X");
189
190//            h1->Draw();
191            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
192            else{hr->Draw("hist");}
193            h1->Draw("same,p");
194
195
196            leg->Clear();
197            leg->AddEntry(h1,"Skim" ,"L");
198            leg->AddEntry(hr,"Reference","L");
199            leg->Draw();
200      }
201      first_plots_done = true;
202      c1->Modified();
203      c1->Update();
204      char chplot[80];
205      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
206      c1->SaveAs(chplot);
207      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
208      c1->SaveAs(chplot);
209  }
210
211  if (!gROOT->IsBatch()) app->Run();
212
213  return 0;
214}