Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:01

0001 /** 
0002  * A collection of simple ROOT macros
0003  *
0004  * N. Amapane 2002-2004
0005  */
0006 
0007 #include <sstream>
0008 #include <iomanip>
0009 
0010 #if !defined(__CINT__) || defined(__MAKECINT__)
0011 #include "TProfile.h"
0012 #include "TLegend.h"
0013 #include "TROOT.h"
0014 #include "TVirtualPad.h"
0015 #include "TLine.h"
0016 #include "TCanvas.h"
0017 #include "TPostScript.h"
0018 #include "TH1.h"
0019 #include "TH2.h"
0020 #include "TF1.h"
0021 #include "TAxis.h"
0022 #include "TMath.h"
0023 #include "TROOT.h"
0024 #include "TStyle.h"
0025 
0026 #include <iostream>
0027 
0028 using namespace std;
0029 
0030 #endif
0031 
0032 
0033 
0034 TString getPitchString(TH1 *histo, int prec = 5);
0035 
0036 
0037 TLegend * getLegend(float x1=0.48, float y1=0.81, float x2=0.98, float y2=0.995);
0038 void setStyle(TH1 *histo);
0039 void setStyle(TH2 *histo);
0040 
0041 
0042 void setStyle(TH1 *histo) {
0043   histo->GetXaxis()->SetTitleFont(gStyle->GetTitleFont());
0044   histo->GetXaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0045   histo->GetXaxis()->SetLabelFont(gStyle->GetLabelFont());
0046   histo->GetXaxis()->SetLabelSize(gStyle->GetLabelSize());
0047 
0048   histo->GetYaxis()->SetTitleFont(gStyle->GetTitleFont());
0049   histo->GetYaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0050   histo->GetYaxis()->SetLabelFont(gStyle->GetLabelFont());
0051   histo->GetYaxis()->SetLabelSize(gStyle->GetLabelSize());
0052 }
0053 
0054 void setStyle(TH2 *histo) {
0055   histo->GetXaxis()->SetTitleFont(gStyle->GetTitleFont());
0056   histo->GetXaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0057   histo->GetXaxis()->SetLabelFont(gStyle->GetLabelFont());
0058   histo->GetXaxis()->SetLabelSize(gStyle->GetLabelSize());
0059 
0060   histo->GetYaxis()->SetTitleFont(gStyle->GetTitleFont());
0061   histo->GetYaxis()->SetTitleSize(gStyle->GetTitleFontSize());
0062   histo->GetYaxis()->SetLabelFont(gStyle->GetLabelFont());
0063   histo->GetYaxis()->SetLabelSize(gStyle->GetLabelSize());
0064 }
0065 
0066 
0067 bool addProfile=false;
0068 bool addSlice=true;
0069 bool addMedian  = false;
0070 TString opt2Dplot = "col";
0071 
0072 // Plot a TH2 + add profiles on top of it
0073 // minY, maxY: Y range for plotting and for computing profile if addProfile==true.
0074 //             Note that the simple profile is very sensitive to the Y range used!
0075 TH1F* plotAndProfileX (TH2* theh, int rebinX, int rebinY, int rebinProfile, float minY, float maxY, float minX=0, float maxX=0) {
0076   TH2* h2=(TH2*)theh->Clone();
0077   
0078   //  setStyle(h2);
0079   if (h2==0) {
0080     cout << "plotAndProfileX: null histo ptr" << endl;
0081     return 0;
0082   }
0083   
0084   gPad->SetGrid(1,1);
0085   gStyle->SetGridColor(15);
0086   h2->Rebin2D(rebinX,rebinY);
0087   //  h2->GetYaxis()->SetRangeUser(minY,maxY);
0088 
0089   TLine * l = new TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
0090   if (maxX>minX) {
0091     h2->GetXaxis()->SetRangeUser(minX,maxX);  
0092     l->SetX1(minX);
0093     l->SetX2(maxX);
0094   }
0095 
0096   h2->SetMarkerStyle(1);
0097   h2->Draw(opt2Dplot);
0098   l->SetLineColor(3);
0099   l->SetLineWidth(2);
0100   l->Draw();
0101   if (addProfile) {
0102     TAxis* yaxis = h2->GetYaxis();
0103     //Add option "s" to draw RMS as error instead than RMS/sqrt(N)
0104     TProfile* prof = h2->ProfileX("_pfx", 
0105                   TMath::Max(1,yaxis->FindBin(minY)), 
0106                   TMath::Min(yaxis->GetNbins(),yaxis->FindBin(maxY)));
0107 //     cout << yaxis->FindBin(minY) << " " << yaxis->FindBin(maxY) << endl;
0108 //     cout << yaxis->GetNbins();
0109     //TProfile* prof = h2->ProfileX("_pfx");
0110     prof->SetMarkerColor(2);
0111     prof->SetMarkerStyle(20);
0112     prof->SetMarkerSize(0.4);
0113     prof->SetLineColor(2);
0114     prof->Rebin(rebinProfile);
0115     prof->Draw("same");
0116   }
0117 
0118   TH1F* ht=0;
0119 
0120   if (addSlice) {
0121     TObjArray aSlices;
0122     //    TF1 fff("a", "gaus", -0.1, 0.1);   
0123     h2->FitSlicesY(0, 0, -1, 0, "QNR", &aSlices); // add "G2" to merge 2 consecutive bins
0124 
0125     TH1F*  ht = (TH1F*) aSlices[1]->Clone();    
0126     // Remove bins with failed fits, based on fit errors
0127     float thr = (maxY-minY)/4.;
0128     for (int bin=1; bin<=ht->GetNbinsX();++bin){
0129       if (ht->GetBinError(bin)>thr) {
0130     ht->SetBinContent(bin,0);
0131     ht->SetBinError(bin,0);
0132       }
0133     }
0134     ht->SetMarkerColor(4);
0135     ht->Draw("same");    
0136   }
0137 
0138   if (addMedian) {
0139     double xq[1] = {0.5};
0140     double median[1];
0141 
0142     TAxis* axis =  h2->GetXaxis();
0143     TH1F* medprof = new TH1F(h2->GetName()+TString("medians"),"medians", axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
0144     float bw =  h2->GetYaxis()->GetBinLowEdge(2)-h2->GetYaxis()->GetBinLowEdge(1);
0145     
0146 
0147     TString projname = h2->GetName()+TString("_pmedian");
0148     for (int bin=1; bin<=h2->GetNbinsX(); ++bin){
0149       TH1D * proj = h2->ProjectionY(projname, bin, bin);
0150       double integral = proj->Integral();
0151       if (integral==0) continue;
0152       // Take overflow and underflow into account
0153       int nbins = proj->GetNbinsX();
0154       proj->SetBinContent(1, proj->GetBinContent(0)+proj->GetBinContent(1));
0155       proj->SetBinContent(0,0);
0156       proj->SetBinContent(nbins, proj->GetBinContent(nbins)+proj->GetBinContent(nbins+1));
0157       proj->SetBinContent(nbins+1,0);
0158       proj->GetQuantiles(1,median,xq);
0159       medprof->SetBinContent(bin,median[0]);
0160       // Approximated uncertainty on median, probably underestimated.
0161       medprof->SetBinError(bin,bw*sqrt(integral/2.)/2./TMath::Max(1.,proj->GetBinContent(proj->FindBin(median[0]))));
0162     }
0163     medprof->SetMarkerColor(2);
0164     medprof->SetMarkerStyle(20);
0165     medprof->SetMarkerSize(0.4);
0166     medprof->Draw("Esame");
0167   }
0168 
0169   h2->GetYaxis()->SetRangeUser(minY,maxY);
0170 
0171   return ht;
0172 }
0173 
0174 
0175 // void plotAndProfileX (TH2* h2, float min, float max, bool profile=false) {
0176 //   setStyle(h2);
0177 //   gPad->SetGrid(1,1);
0178 //   gStyle->SetGridColor(15);
0179 //   h2->GetYaxis()->SetRangeUser(min,max);
0180 //   h2->Draw();
0181 //   if (profile) {
0182 //     TProfile* prof = h2->ProfileX();
0183 //     prof->SetMarkerColor(2);
0184 //     prof->SetLineColor(2);
0185 //     prof->Draw("same");
0186 //   }
0187 //   TLine * l = new TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
0188 //   l->SetLineColor(3);
0189 //   l->Draw();
0190 // }
0191 
0192 
0193 // Draw a 2-D plot within the specified Y range and superimpose its X profile,
0194 // setting as sigmas that of the fit (and not the error of the mean)
0195 void plotAndProfileXSpread (TH2* h2, float min, float max, bool profile=false, float ymin=-5., float ymax=5.) {
0196   setStyle(h2);
0197   gPad->SetGrid(1,1);
0198   gStyle->SetGridColor(15);
0199   gStyle->SetOptStat(0);
0200   // h2->RebinX(3);
0201   // h2->RebinY(2);
0202   // h2->SetXTitle("distance from anode (cm)");
0203   // h2->SetYTitle("(d_{reco}-d_{sim})/#sigma_{reco}");
0204   h2->SetMarkerColor(2);
0205   h2->SetLineColor(2);
0206   h2->GetYaxis()->SetTitleOffset(1.4);
0207   h2->GetXaxis()->SetRangeUser(min,max);
0208   h2->GetYaxis()->SetRangeUser(ymin,ymax);
0209   h2->DrawCopy("box");
0210   if (profile) {
0211     TProfile* prof = h2->ProfileX("profile",-1,-1,"s");
0212     prof->SetMarkerStyle(20);
0213     prof->SetMarkerSize(1.2);
0214     prof->SetMarkerColor(1);
0215     prof->SetLineColor(1);
0216     prof->SetLineWidth(2);
0217     prof->DrawCopy("same e1");
0218     delete prof;
0219   }
0220   TLine * l = new TLine(h2->GetXaxis()->GetXmin(),0,h2->GetXaxis()->GetXmax(),0);
0221   l->SetLineColor(3);
0222   l->Draw();
0223 }
0224 
0225 
0226 
0227 // Fit the gaussian core of an histogram with in  the range mean+-nsigmas.
0228 TF1* drawGFit(TH1 * h1, float nsigmas, float min, float max){
0229 
0230   gPad->SetGrid(1,1);
0231   gStyle->SetGridColor(15);
0232   h1->GetXaxis()->SetRangeUser(min,max);
0233   float minfit = h1->GetMean() - h1->GetRMS();
0234   float maxfit = h1->GetMean() + h1->GetRMS();
0235  
0236   TLine * l = new TLine(0,0,0,h1->GetMaximum()*1.05);
0237   
0238   l->SetLineColor(3);
0239   l->SetLineWidth(2);
0240   
0241   static int i = 0;
0242   TString nameF1 = TString("g") + (Long_t)i;
0243   i++;
0244   TF1* g1 = new TF1(nameF1,"gaus",minfit,maxfit);
0245 
0246   g1->SetLineColor(2);
0247   g1->SetLineWidth(2);
0248   h1->Fit(g1,"RQ");
0249   
0250   minfit = g1->GetParameter("Mean") - nsigmas*g1->GetParameter("Sigma");
0251   maxfit = g1->GetParameter("Mean") + nsigmas*g1->GetParameter("Sigma");
0252   g1->SetRange(minfit,maxfit);
0253 
0254   h1->Fit(g1,"RQ");
0255   TF1* fh=h1->GetFunction(nameF1);
0256   if (fh) fh->FixParameter(0,g1->GetParameter(0)); // so that it is not shown in legend
0257 
0258   gPad->Draw(); 
0259   l->Draw();
0260   h1->Draw("same"); //redraw on top of the line
0261   return g1;
0262 }
0263 
0264 
0265 /*
0266  * Create a new TCanvas setting its properties
0267  *
0268  * 2003 NCA 
0269  */
0270 // Specify name, title, x/y divisions, form or x,y sizes.
0271 // If no name is specified, a new name is generated automatically
0272 TCanvas * newCanvas(TString name="", TString title="",
0273                      Int_t xdiv=0, Int_t ydiv=0, Int_t form = 1, Int_t w=-1){
0274   static char i = '1';
0275   if (name == "") {
0276     name = TString("Canvas ") + i;
0277     i++;
0278   }
0279   if (title == "") title = name;
0280   TCanvas * c = 0;
0281   if (w<0) {
0282     c = new TCanvas(name,title, form);
0283   } else {
0284     c = new TCanvas(name,title,form,w);
0285   }
0286   if (xdiv*ydiv!=0) c->Divide(xdiv,ydiv);
0287   c->cd(1);
0288   return c;
0289 }
0290 // Create a new canvas with an automatic generated name and the specified 
0291 // divisions and form
0292 TCanvas * newCanvas(Int_t xdiv, Int_t ydiv, Int_t form = 1) {
0293   return newCanvas("","",xdiv,ydiv,form);
0294 }
0295 // Create a new canvas with an automatic generated name and the specified 
0296 // form
0297 TCanvas * newCanvas(Int_t form = 1)
0298 {
0299   return newCanvas(0,0,form);
0300 }
0301 // ...without specifying the title...
0302 TCanvas * newCanvas(TString name, Int_t xdiv, Int_t ydiv, Int_t form,
0303                     Int_t w) {
0304   return newCanvas(name, name,xdiv,ydiv,form,w);
0305 }
0306 // ...without specifying title and divisions.
0307 TCanvas * newCanvas(TString name, Int_t form, Int_t w=-1)
0308 {
0309   return newCanvas(name, name, 0,0,form,w);
0310 }
0311 /*
0312  * Print all open canvases to PS or EPS files.
0313  *
0314  * 2003 NCA 
0315  */
0316 // Print all canvases in a single PS file
0317 void printCanvasesPS(TString name){
0318   TPostScript * ps = new TPostScript(name,112);
0319   TIter iter(gROOT->GetListOfCanvases());
0320   TCanvas *c;
0321   while( (c = (TCanvas *)iter()) )
0322     {
0323       c->cd();
0324       cout << "Printing " << c->GetName() << endl;
0325       ps->NewPage();
0326       c->Draw();
0327     }
0328   cout << " File " << name << " was created" << endl;
0329   ps->Close();
0330 }
0331 // Print all canvases in separate EPS files
0332 void printCanvasesEps(){
0333   TIter iter(gROOT->GetListOfCanvases());
0334   TCanvas *c;
0335   while( (c = (TCanvas *)iter()) ) {
0336     c->Print(0,".eps");
0337   }
0338 }
0339 // Print all canvases in separate EPS files (another way)
0340 void printCanvasesEps2() {
0341   gROOT->GetListOfCanvases()->Print(".eps");
0342 }
0343 
0344 // Print all canvases in separate files
0345 void printCanvases(TString type="png", TString path="."){
0346   TIter iter(gROOT->GetListOfCanvases());
0347   TCanvas *c;
0348   while( (c = (TCanvas *)iter()) ) {
0349     TString name =  c->GetTitle();
0350     c->Print(path+"/"+name+"."+type,type);
0351   }
0352 }
0353 
0354 /*
0355  * Define different TStyles; use them with:
0356  * getStyle->cd();
0357  *
0358  * 2003 NCA
0359  */
0360 TStyle * getStyle(TString name="myStyle")
0361 {
0362   TStyle *theStyle;
0363 
0364   gROOT->ForceStyle();
0365 
0366   if ( name == "myStyle" ) {
0367     theStyle = new TStyle("myStyle", "myStyle");
0368     //    theStyle->SetOptStat(0);
0369     theStyle->SetPadBorderMode(0);
0370     theStyle->SetCanvasBorderMode(0);
0371     theStyle->SetPadColor(0);
0372     theStyle->SetCanvasColor(0);
0373     theStyle->SetMarkerStyle(8);
0374     theStyle->SetMarkerSize(0.7);
0375     theStyle->SetStatH(0.3);
0376     theStyle->SetStatW(0.15);
0377     //   theStyle->SetTextFont(132);
0378     //   theStyle->SetTitleFont(132);
0379     theStyle->SetTitleBorderSize(1);
0380     theStyle->SetPalette(1);
0381 
0382   } else if( name == "tdr" ) {
0383     theStyle = new TStyle("tdrStyle","Style for P-TDR");
0384 
0385     // For the canvas:
0386     theStyle->SetCanvasBorderMode(0);
0387     theStyle->SetCanvasColor(kWhite);
0388 //      theStyle->SetCanvasDefH(600); //Height of canvas
0389 //      theStyle->SetCanvasDefW(800); //Width of canvas
0390     theStyle->SetCanvasDefH(750); //Height of canvas
0391     theStyle->SetCanvasDefW(1000); //Width of canvas
0392 
0393     theStyle->SetCanvasDefX(0);   //POsition on screen
0394     theStyle->SetCanvasDefY(0);
0395 
0396     // For the Pad:
0397     theStyle->SetPadBorderMode(0);
0398     // theStyle->SetPadBorderSize(Width_t size = 1);
0399     theStyle->SetPadColor(kWhite);
0400     theStyle->SetPadGridX(true);
0401     theStyle->SetPadGridY(true);
0402     theStyle->SetGridColor(0);
0403     theStyle->SetGridStyle(3);
0404     theStyle->SetGridWidth(1);
0405 
0406     // For the frame:
0407     theStyle->SetFrameBorderMode(0);
0408     theStyle->SetFrameBorderSize(1);
0409     theStyle->SetFrameFillColor(0);
0410     theStyle->SetFrameFillStyle(0);
0411     theStyle->SetFrameLineColor(1);
0412     theStyle->SetFrameLineStyle(1);
0413     theStyle->SetFrameLineWidth(1);
0414 
0415     // For the histo:
0416     // theStyle->SetHistFillColor(1);
0417     // theStyle->SetHistFillStyle(0);
0418     theStyle->SetHistLineColor(kBlue);
0419     theStyle->SetMarkerColor(kBlue);
0420     //    theStyle->SetHistLineStyle(0);
0421     //    theStyle->SetHistLineWidth(1);
0422     // theStyle->SetLegoInnerR(Float_t rad = 0.5);
0423     // theStyle->SetNumberContours(Int_t number = 20);
0424 
0425 
0426      theStyle->SetEndErrorSize(2);
0427 //     theStyle->SetErrorMarker(20);
0428 //     theStyle->SetErrorX(0.);
0429 
0430     theStyle->SetMarkerStyle(20);
0431     theStyle->SetMarkerSize(0.5);
0432 
0433 
0434     //For the fit/function:
0435     theStyle->SetOptFit(1);
0436     theStyle->SetFitFormat("5.4g");
0437     theStyle->SetFuncColor(2);
0438     theStyle->SetFuncStyle(1);
0439     theStyle->SetFuncWidth(1);
0440 
0441     //For the date:
0442     theStyle->SetOptDate(0);
0443     // theStyle->SetDateX(Float_t x = 0.01);
0444     // theStyle->SetDateY(Float_t y = 0.01);
0445 
0446     // For the statistics box:
0447     theStyle->SetOptFile(0);
0448 //     theStyle->SetOptStat(0); // To display the mean and RMS:   SetOptStat("mr");
0449 
0450     theStyle->SetOptStat("e");
0451     theStyle->SetStatColor(kWhite);
0452     //    theStyle->SetStatFont(42);
0453     //    theStyle->SetStatFontSize(0.05);
0454     theStyle->SetStatTextColor(1);
0455     theStyle->SetStatFormat("6.4g");
0456     theStyle->SetStatBorderSize(1);
0457 //     theStyle->SetStatH(0.02);
0458 //     theStyle->SetStatW(0.2);
0459     // theStyle->SetStatStyle(Style_t style = 1001);
0460     theStyle->SetStatX(0.94);
0461     theStyle->SetStatY(0.96);
0462 
0463     // Margins:
0464 //      theStyle->SetPadTopMargin(0.1);
0465       theStyle->SetPadBottomMargin(0.11);
0466 //      theStyle->SetPadLeftMargin(0.1);
0467 //      theStyle->SetPadRightMargin(0.05);
0468     theStyle->SetPadLeftMargin(0.15);
0469 
0470     // For the Global title:
0471     
0472     //    theStyle->SetOptTitle(0); // Uncomment to remove title
0473 //     theStyle->SetTitleFont(42);
0474 //     theStyle->SetTitleColor(1);
0475 //     theStyle->SetTitleTextColor(1);
0476     theStyle->SetTitleFillColor(0);
0477 //     theStyle->SetTitleFontSize(0.05);
0478     // theStyle->SetTitleH(0); // Set the height of the title box
0479     // theStyle->SetTitleW(0); // Set the width of the title box
0480     // theStyle->SetTitleX(0); // Set the position of the title box
0481     theStyle->SetTitleY(0.96); // Set the position of the title box
0482     theStyle->SetTitleStyle(0);
0483     theStyle->SetTitleBorderSize(0);
0484 
0485 
0486     // For the axis titles:
0487 
0488 //     theStyle->SetTitleColor(1, "XYZ");
0489 //     theStyle->SetTitleFont(42, "XYZ");
0490     //    theStyle->SetTitleSize(0.05, "XYZ");
0491     // theStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
0492     // theStyle->SetTitleYSize(Float_t size = 0.02);
0493 //     theStyle->SetTitleXOffset(0.9);
0494 //     theStyle->SetTitleYOffset(1.25);
0495     // theStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
0496 
0497     // For the axis labels:
0498 
0499 //     theStyle->SetLabelColor(1, "XYZ");
0500 //     theStyle->SetLabelFont(42, "XYZ");
0501 //     theStyle->SetLabelOffset(0.007, "XYZ");
0502 //     theStyle->SetLabelSize(0.045, "XYZ");
0503 
0504     // For the axis:
0505 
0506     theStyle->SetAxisColor(1, "XYZ");
0507     theStyle->SetStripDecimals(kTRUE);
0508     theStyle->SetTickLength(0.03, "XYZ");
0509     theStyle->SetNdivisions(510, "XYZ");
0510     theStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
0511     theStyle->SetPadTickY(1);
0512 
0513     // Change for log plots:
0514     theStyle->SetOptLogx(0);
0515     theStyle->SetOptLogy(0);
0516     theStyle->SetOptLogz(0);
0517 
0518     // Postscript options:
0519     theStyle->SetPaperSize(20.,20.);
0520     // theStyle->SetLineScalePS(Float_t scale = 3);
0521     // theStyle->SetLineStyleString(Int_t i, const char* text);
0522     // theStyle->SetHeaderPS(const char* header);
0523     // theStyle->SetTitlePS(const char* pstitle);
0524 
0525     // theStyle->SetBarOffset(Float_t baroff = 0.5);
0526     // theStyle->SetBarWidth(Float_t barwidth = 0.5);
0527     // theStyle->SetPaintTextFormat(const char* format = "g");
0528     // theStyle->SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
0529     // theStyle->SetTimeOffset(Double_t toffset);
0530     // theStyle->SetHistMinimumZero(kTRUE);
0531     theStyle->SetTextSize(0.045);
0532     //    theStyle->SetTextFont(42);
0533     
0534     //   style->SetOptFit(101);
0535     //   style->SetOptStat(1111111);
0536 
0537   } else {
0538     // Avoid modifying the default style!
0539     theStyle = gStyle;
0540   }
0541   return theStyle;
0542 }
0543 
0544 
0545 void
0546 setPalette()
0547 {
0548   const Int_t NRGBs = 5;
0549   const Int_t NCont = 255;
0550  
0551 //   { // Fine rainbow
0552 //     Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0553 //     Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
0554 //     Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
0555 //     Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
0556 //   }
0557  
0558 //   { // blues
0559 //     Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0560 //     Double_t red[NRGBs]   = { 1.00, 0.84, 0.61, 0.34, 0.00 };
0561 //     Double_t green[NRGBs] = { 1.00, 0.84, 0.61, 0.34, 0.00 };
0562 //     Double_t blue[NRGBs]  = { 1.00, 1.00, 1.00, 1.00, 1.00 };
0563 //   }
0564 
0565 
0566 //   { // Gray (white->black)
0567 //     Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0568 //     Double_t red[NRGBs]   = { 1.00, 0.84, 0.61, 0.34, 0.00 };
0569 //     Double_t green[NRGBs] = { 1.00, 0.84, 0.61, 0.34, 0.00 };
0570 //     Double_t blue[NRGBs]  = { 1.00, 0.84, 0.61, 0.34, 0.00 };
0571 //   }
0572 
0573 
0574   { // Gray (white->gray)
0575     //  similar to gStyle->SetPalette(5);
0576     float max = 0.3;
0577     float step=(1-max)/(NRGBs-1);
0578     Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
0579     Double_t red[NRGBs]   = { 1.00, 1-step, 1-2*step, 1-3*step, 1-4*step };
0580     Double_t green[NRGBs] = { 1.00, 1-step, 1-2*step, 1-3*step, 1-4*step };
0581     Double_t blue[NRGBs]  = { 1.00, 1-step, 1-2*step, 1-3*step, 1-4*step };
0582     TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
0583   }
0584 
0585 
0586  gStyle->SetNumberContours(NCont);
0587 }
0588 
0589 
0590 // Overlay efficiency plots for S1, S2, S3
0591 void plotEff(TH1* h1, TH1* h2=0, TH1* h3=0) {
0592   float minY=0.6;
0593   float maxY=1.05;
0594   h1->GetYaxis()->SetRangeUser(minY,maxY);
0595   h1->GetXaxis()->SetRangeUser(0.,2.1);
0596   h1->SetMarkerStyle(20);
0597   h1->SetMarkerSize(0.5);
0598   h1->SetStats(0);
0599   h1->Draw();
0600   
0601   if (h2) {
0602     h2->SetLineColor(kRed);
0603     h2->SetMarkerColor(kRed);
0604     h2->SetMarkerStyle(20);
0605     h2->SetMarkerSize(0.5);
0606     h2->SetStats(0);
0607     h2->Draw("same");
0608   }
0609   
0610   if (h3) {
0611     h3->SetLineColor(kBlack);
0612     h3->SetMarkerColor(kBlack);
0613     h3->SetMarkerStyle(20);
0614     h3->SetMarkerSize(0.5);
0615     h3->SetStats(0);
0616     h3->Draw("same");
0617   }
0618 }
0619 
0620 TH1F* getEffPlot(TH1* hnum, TH1* hden, int rebin=1) {
0621   hnum->Rebin(rebin);
0622   hden->Rebin(rebin);
0623   TH1F* h = (TH1F*)hnum->Clone();
0624   h->Sumw2();
0625   h->Divide(hnum,hden,1.,1.,"B");
0626   h->SetStats(0);
0627   return h;
0628 }