예제 #1
2
void annconvergencetest( TDirectory *lhdir )
{
   TCanvas* c = new TCanvas( "MLPConvergenceTest", "MLP Convergence Test", 150, 0, 600, 580*0.8 ); 
  
   TH1* estimatorHistTrain = (TH1*)lhdir->Get( "estimatorHistTrain" );
   TH1* estimatorHistTest  = (TH1*)lhdir->Get( "estimatorHistTest"  );

   Double_t m1  = estimatorHistTrain->GetMaximum();
   Double_t m2  = estimatorHistTest ->GetMaximum();
   Double_t max = TMath::Max( m1, m2 );
   m1  = estimatorHistTrain->GetMinimum();
   m2  = estimatorHistTest ->GetMinimum();
   Double_t min = TMath::Min( m1, m2 );
   estimatorHistTrain->SetMaximum( max + 0.1*(max - min) );
   estimatorHistTrain->SetMinimum( min - 0.1*(max - min) );
   estimatorHistTrain->SetLineColor( 2 );
   estimatorHistTrain->SetLineWidth( 2 );
   estimatorHistTrain->SetTitle( TString("MLP Convergence Test") );
  
   estimatorHistTest->SetLineColor( 4 );
   estimatorHistTest->SetLineWidth( 2 );

   estimatorHistTrain->GetXaxis()->SetTitle( "Epochs" );
   estimatorHistTrain->GetYaxis()->SetTitle( "Estimator" );
   estimatorHistTrain->GetXaxis()->SetTitleOffset( 1.20 );
   estimatorHistTrain->GetYaxis()->SetTitleOffset( 1.65 );

   estimatorHistTrain->Draw();
   estimatorHistTest ->Draw("same");

   // need a legend
   TLegend *legend= new TLegend( 1 - c->GetRightMargin() - 0.45, 1-c->GetTopMargin() - 0.20, 
                                 1 - c->GetRightMargin() - 0.05, 1-c->GetTopMargin() - 0.05 );

   legend->AddEntry(estimatorHistTrain,"Training Sample","l");
   legend->AddEntry(estimatorHistTest,"Test sample","l");
   legend->Draw("same");
   legend->SetMargin( 0.3 );

   c->cd();
   TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-(
   c->Update();

   TString fname = "plots/annconvergencetest";
   TMVAGlob::imgconv( c, fname );
}
예제 #2
0
  //____________________________________________________________________
  void Run(const char* newName,        const char* oldName,
	   const char* newTitle="New", const char* oldTitle="Old")
  {
    TFile* newFile = TFile::Open(newName,"READ");
    TFile* oldFile = TFile::Open(oldName,"READ");
    if (!newFile || !oldFile) return;

    TH1* newCent = GetH1(newFile, "realCent");
    TH1* oldCent = GetH1(oldFile, "realCent");
    if (!newCent || !oldCent) return;

    TString  t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
    TCanvas* c     = new TCanvas("c", t, 1200, 800);
    c->SetTopMargin(0.01);
    c->SetRightMargin(0.20);
    fLegend = new TLegend(1-c->GetRightMargin(),
			  c->GetBottomMargin(),
			  1, 1-c->GetTopMargin(),
			  t);
    fLegend->SetFillStyle(0);
    fLegend->SetBorderSize(0);
    THStack* stack = new THStack("ratios","");
			       
    fMin = +1e6;
    fMax = -1e6;
    TH1* one = 0;
    for (Int_t i = newCent->GetNbinsX(); i--;) {
      Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
      Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
      Info("", "c1=%f c2=%f", c1, c2);
      TH1*     r  = One(newFile, oldFile, c1, c2);    
      if (!r) continue;
      if (!one) {
	one = static_cast<TH1*>(r->Clone("one"));
	one->SetDirectory(0);
	one->Reset();
	for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
	  one->SetBinContent(j,1);
	  one->SetBinError  (j,0);
	}
      }
      // r->Add(one, i-1);
      // r->Scale(TMath::Power(10,i));
      stack->Add(r);
    }
    stack->Draw("nostack");
    stack->SetMinimum(0.95*fMin);
    stack->SetMaximum(1.05*fMax);
    stack->GetHistogram()->SetXTitle("#eta");
    stack->GetHistogram()->SetYTitle("#it{R}");
    fLegend->Draw();
    c->Modified();
    c->Update();
    c->cd();
    c->SaveAs(Form("%sover%s.png", newTitle, oldTitle));
  }  
예제 #3
0
파일: Extract.C 프로젝트: ktf/AliPhysics
/** 
 * Extract ALICE PbPb @ 5.02TeV over |eta|<2
 * 
 * @param filename  Input file name 
 * @param outname   Output file name 
 * @param reweigh   Whether it is reweighed 
 */
void
Extract(const char* filename="dndneta.pbpb502.20151124.root",
	const char* outname="TRACKLETS_5023_PbPb.input",
	Bool_t      reweigh=false)
{
  if (filename == 0) return;
  TFile* file = TFile::Open(filename, "READ");
  TObjArray* arr = static_cast<TObjArray*>(file->Get("TObjArray"));
  // Now count number of bins
  Int_t nBins = 0;
  TIter next(arr);
  TObject* obj = 0;
  while ((obj = next())) {
    if (TString(obj->GetName()).Contains("DataCorrSignal")) 
      nBins++;
  }
  Info("ExtractdNdeta", "Defining %d centrality bins", nBins);
  TArrayD c(nBins+1);
  if (nBins == 5) {
    c[0] = 0; c[1] = 10; c[2] = 20; c[3] = 40; c[4] = 60; c[5] = 80;
  }
  else if (nBins >= 9) {
    c[0] =  0; c[1] =  5; c[2] = 10; c[3] = 20; c[4] = 30; c[5] = 40;
    c[6] = 50; c[7] = 60; c[8] = 70; c[9] = 80;
    if (nBins >= 10) c[10] =  90;
    if (nBins >= 11) c[11] = 100;
  }
  
  THStack* all = new THStack("all","all");
  std::ofstream out(outname);
  std::ostream& o = out; // std::cout;
  // std::ostream& o = std::cout;
  
  o << "*author: SHAHOYAN : 2015\n"
    << "*title: Full centrality dependence of the charged "
    << "particle pseudo-rapidity density over the widest "
    << "possible pseudo-rapidity range in Pb-Pb collisions "
    << "at 5.02 TeV\n"
    << "*detector: TRACKLETS\n"
    << "*experiment: CERN-LHC-TRACKLETS\n"
    << "*comment: CERN-LHC: We present the charged particle pseudo-rapidity "
    << "density of charged particles in Pb-Pb collisions at sqrt(s)/nucleon "
    "= 5.02 over the widest possible pseudo-rapidity and centrality range "
    << "possible.\n"  << std::endl;
  
  for (Int_t i = 0; i < nBins; i++) {
    TString hName = Form("bin%d_DataCorrSignal_PbPb",i);
    TH1* h = static_cast<TH1*>(arr->FindObject(hName));
    if (!h) {
      hName.ReplaceAll("PbPb", "PBPB");
      h = static_cast<TH1*>(arr->FindObject(hName));
      if (!h) {
	Warning("", "Histogram (%s) missing for bin %d", hName.Data(), i);
	arr->Print();
	continue;
      }
    }
    
    Color_t      col = PbPbColor(c[i], c[i+1]);
    h->SetLineColor(col);
    h->SetMarkerColor(col);
    h->SetFillColor(col);
    all->Add(h);
    Info("","Making GSE for %0d%% to %3d%% (%d)",
	 Int_t(c[i]), Int_t(c[i+1]), col);
    
    MakeGSE(o, h, c[i], c[i+1], reweigh);
  }
  // all->Draw("nostack");
  o << "*E" << std::endl;
  out.close();

  TCanvas*        can = new TCanvas("c","C", 1600, 800);
  can->SetRightMargin(0.2);
  can->SetTopMargin(0.01);

  TLegend*        cl = new TLegend(1-can->GetRightMargin(),
				   can->GetBottomMargin(),.99,
				   1-can->GetTopMargin());
  cl->SetFillStyle(0);
  cl->SetBorderSize(0);
  
  gROOT->LoadMacro("$HOME/GraphSysErr/GraphSysErr.C+");
  TList* ll = GraphSysErr::Import(outname);
  // ll->ls();

  TIter next(ll);
  TObject* obj = 0;
  Bool_t first = true;
  TH1* frame = 0;
  Double_t min=100000, max=0;
  Int_t i = 0;
  while ((obj = next())) {
    if (c[i+1] > 80) break;
    GraphSysErr* g = static_cast<GraphSysErr*>(obj);
    Color_t      col = PbPbColor(c[i], c[i+1]);
    TLegendEntry* e =  cl->AddEntry("", Form("%4.1f-%4.1f%%", c[i], c[i+1]),
				    "F");
    e->SetFillColor(col);
    e->SetFillStyle(1001);
    g->SetLineColor(col);
    g->SetMarkerColor(col);
    g->SetFillColor(col);
    // g->Print("qual");
    g->SetDataOption(GraphSysErr::kNoTick);
    g->SetSumOption(GraphSysErr::kBox);
    g->SetSumLineColor(col);
    g->SetSumFillColor(col);
    g->SetCommonSumOption(GraphSysErr::kBox);
    g->SetCommonSumLineColor(col);
    g->SetCommonSumFillColor(col);
    g->SetName(Form("tracklets%03dd%02d_%03dd%02d",
		    Int_t(c[i]),   Int_t(c[i]*100) % 100,
		    Int_t(c[i+1]), Int_t(c[i+1]*100) % 100));
    g->SetTitle(Form("%4.1f - %4.1f%%", c[i], c[i+1]));
    if (first) g->Draw("combine stat quad axis xbase=2.5");
    else       g->Draw("combine stat quad xbase=2.5");
    if (!frame)
      frame = g->GetMulti()->GetHistogram();
    first = false;
    Double_t mn, mx;
    g->GetMinMax("combine stat quad", mn, mx);
    FindLeastLargest(g, c[i], c[i+1]);
    min = TMath::Min(min, mn);
    max = TMath::Max(max, mx);
    i++;
  }
  frame->SetMinimum(min*.9);
  frame->SetMaximum(max*1.1);
  cl->Draw();

  TFile* outFile = TFile::Open(Form("PbPb5023midRapidity%s.root",
				    reweigh ? "Reweighed" : "Normal"),
			       "RECREATE");
  ll->Write("container",TObject::kSingleKey);
  outFile->Write();
  
  can->SaveAs(Form("PbPb5023midRapidity%s.png",
		   reweigh ? "Reweighed" : "Normal"));
}
예제 #4
0
파일: mvas.C 프로젝트: aocampor/UGentSUSY
// input: - Input file (result from TMVA)
//        - use of TMVA plotting TStyle
void mvas( TString fin = "TMVA.root", HistType htype = MVAType, Bool_t useTMVAStyle = kTRUE )
{
   // set style and remove existing canvas'
   TMVAGlob::Initialize( useTMVAStyle );

   // switches
   const Bool_t Save_Images     = kTRUE;

   // checks if file with name "fin" is already open, and if not opens one
   TFile* file = TMVAGlob::OpenFile( fin );  

   // define Canvas layout here!
   Int_t xPad = 1; // no of plots in x
   Int_t yPad = 1; // no of plots in y
   Int_t noPad = xPad * yPad ; 
   const Int_t width = 600;   // size of canvas

   // this defines how many canvases we need
   TCanvas *c = 0;

   // counter variables
   Int_t countCanvas = 0;

   // search for the right histograms in full list of keys
   TIter next(file->GetListOfKeys());
   TKey *key(0);   
   while ((key = (TKey*)next())) {

      if (!TString(key->GetName()).BeginsWith("Method_")) continue;
      if( ! gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory") ) continue;

      TString methodName;
      TMVAGlob::GetMethodName(methodName,key);

      TDirectory* mDir = (TDirectory*)key->ReadObj();

      TIter keyIt(mDir->GetListOfKeys());
      TKey *titkey;
      while ((titkey = (TKey*)keyIt())) {
         if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue;

         TDirectory *titDir = (TDirectory *)titkey->ReadObj();
         TString methodTitle;
         TMVAGlob::GetMethodTitle(methodTitle,titDir);

         cout << "--- Found directory for method: " << methodName << "::" << methodTitle << flush;
         TString hname = "MVA_" + methodTitle;
         if      (htype == ProbaType  ) hname += "_Proba";
         else if (htype == RarityType ) hname += "_Rarity";
         TH1* sig = dynamic_cast<TH1*>(titDir->Get( hname + "_S" ));
         TH1* bgd = dynamic_cast<TH1*>(titDir->Get( hname + "_B" ));

         if (sig==0 || bgd==0) {
            if     (htype == MVAType)     
               cout << "mva distribution not available (this is normal for Cut classifier)" << endl;
            else if(htype == ProbaType)   
               cout << "probability distribution not available (this is normal for Cut classifier)" << endl;
            else if(htype == RarityType)  
               cout << "rarity distribution not available (this is normal for Cut classifier)" << endl;
            else if(htype == CompareType) 
               cout << "overtraining check not available (this is normal for Cut classifier)" << endl;
            else cout << endl;
         } 
         else {
            cout << endl;
            // chop off useless stuff
            sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) );
            if      (htype == ProbaType) 
               sig->SetTitle( Form("TMVA probability for classifier: %s", methodTitle.Data()) );
            else if (htype == RarityType) 
               sig->SetTitle( Form("TMVA Rarity for classifier: %s", methodTitle.Data()) );
            else if (htype == CompareType) 
               sig->SetTitle( Form("TMVA overtraining check for classifier: %s", methodTitle.Data()) );
         
            // create new canvas
            TString ctitle = ((htype == MVAType) ? 
                              Form("TMVA response %s",methodTitle.Data()) : 
                              (htype == ProbaType) ? 
                              Form("TMVA probability %s",methodTitle.Data()) :
                              (htype == CompareType) ? 
                              Form("TMVA comparison %s",methodTitle.Data()) :
                              Form("TMVA Rarity %s",methodTitle.Data()));
         
            TString cname = ((htype == MVAType) ? 
                             Form("output_%s",methodTitle.Data()) : 
                             (htype == ProbaType) ? 
                             Form("probability_%s",methodTitle.Data()) :
                             (htype == CompareType) ? 
                             Form("comparison_%s",methodTitle.Data()) :
                             Form("rarity_%s",methodTitle.Data()));

            c = new TCanvas( Form("canvas%d", countCanvas+1), ctitle, 
                             countCanvas*50+200, countCanvas*20, width, (Int_t)width*0.78 ); 
    
            // set the histogram style
            TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
   
            // normalise both signal and background
            TMVAGlob::NormalizeHists( sig, bgd );
   
            // frame limits (choose judicuous x range)
            Float_t nrms = 4;
            cout << "--- Mean and RMS (S): " << sig->GetMean() << ", " << sig->GetRMS() << endl;
            cout << "--- Mean and RMS (B): " << bgd->GetMean() << ", " << bgd->GetRMS() << endl;
            Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), 
                                                  bgd->GetMean() - nrms*bgd->GetRMS() ),
                                       sig->GetXaxis()->GetXmin() );
            Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), 
                                                  bgd->GetMean() + nrms*bgd->GetRMS() ),
                                       sig->GetXaxis()->GetXmax() );
            Float_t ymin = 0;
            Float_t maxMult = (htype == CompareType) ? 1.3 : 1.2;
            Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult;
   
            // build a frame
            Int_t nb = 500;
            TString hFrameName(TString("frame") + methodTitle);
            TObject *o = gROOT->FindObject(hFrameName);
            if(o) delete o;
            TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), 
                                    nb, xmin, xmax, nb, ymin, ymax );
            frame->GetXaxis()->SetTitle( methodTitle + ((htype == MVAType || htype == CompareType) ? " response" : "") );
            if      (htype == ProbaType  ) frame->GetXaxis()->SetTitle( "Signal probability" );
            else if (htype == RarityType ) frame->GetXaxis()->SetTitle( "Signal rarity" );
            frame->GetYaxis()->SetTitle("Normalized");
            TMVAGlob::SetFrameStyle( frame );
   
            // eventually: draw the frame
            frame->Draw();  
    
            c->GetPad(0)->SetLeftMargin( 0.105 );
            frame->GetYaxis()->SetTitleOffset( 1.2 );

            // Draw legend               
            TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, 
                                          c->GetLeftMargin() + (htype == CompareType ? 0.40 : 0.3), 1 - c->GetTopMargin() );
            legend->SetFillStyle( 1 );
            legend->AddEntry(sig,TString("Signal")     + ((htype == CompareType) ? " (test sample)" : ""), "F");
            legend->AddEntry(bgd,TString("Background") + ((htype == CompareType) ? " (test sample)" : ""), "F");
            legend->SetBorderSize(1);
            legend->SetMargin( (htype == CompareType ? 0.2 : 0.3) );
            legend->Draw("same");

            // overlay signal and background histograms
            sig->Draw("samehist");
            bgd->Draw("samehist");
   
            if (htype == CompareType) {
               // if overtraining check, load additional histograms
               TH1* sigOv = 0;
               TH1* bgdOv = 0;

               TString ovname = hname += "_Train";
               sigOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_S" ));
               bgdOv = dynamic_cast<TH1*>(titDir->Get( ovname + "_B" ));
      
               if (sigOv == 0 || bgdOv == 0) {
                  cout << "+++ Problem in \"mvas.C\": overtraining check histograms do not exist" << endl;
               }
               else {
                  cout << "--- Found comparison histograms for overtraining check" << endl;

                  TLegend *legend2= new TLegend( 1 - c->GetRightMargin() - 0.42, 1 - c->GetTopMargin() - 0.12,
                                                 1 - c->GetRightMargin(), 1 - c->GetTopMargin() );
                  legend2->SetFillStyle( 1 );
                  legend2->SetBorderSize(1);
                  legend2->AddEntry(sigOv,"Signal (training sample)","P");
                  legend2->AddEntry(bgdOv,"Background (training sample)","P");
                  legend2->SetMargin( 0.1 );
                  legend2->Draw("same");
               }
               Int_t col = sig->GetLineColor();
               sigOv->SetMarkerColor( col );
               sigOv->SetMarkerSize( 0.7 );
               sigOv->SetMarkerStyle( 20 );
               sigOv->SetLineWidth( 1 );
               sigOv->SetLineColor( col );
               sigOv->Draw("e1same");
      
               col = bgd->GetLineColor();
               bgdOv->SetMarkerColor( col );
               bgdOv->SetMarkerSize( 0.7 );
               bgdOv->SetMarkerStyle( 20 );
               bgdOv->SetLineWidth( 1 );
               bgdOv->SetLineColor( col );
               bgdOv->Draw("e1same");

               ymax = TMath::Max( ymax, TMath::Max( sigOv->GetMaximum(), bgdOv->GetMaximum() )*maxMult );
               frame->GetYaxis()->SetLimits( 0, ymax );
      
               // for better visibility, plot thinner lines
               sig->SetLineWidth( 1 );
               bgd->SetLineWidth( 1 );

               // perform K-S test
               cout << "--- Perform Kolmogorov-Smirnov tests" << endl;
               Double_t kolS = sig->KolmogorovTest( sigOv );
               Double_t kolB = bgd->KolmogorovTest( bgdOv );
               cout << "--- Goodness of signal (background) consistency: " << kolS << " (" << kolB << ")" << endl;

               TString probatext = Form( "Kolmogorov-Smirnov test: signal (background) probability = %5.3g (%5.3g)", kolS, kolB );
               TText* tt = new TText( 0.12, 0.74, probatext );
               tt->SetNDC(); tt->SetTextSize( 0.032 ); tt->AppendPad(); 
            }

            // redraw axes
            frame->Draw("sameaxis");

            // text for overflows
            Int_t    nbin = sig->GetNbinsX();
            Double_t dxu  = sig->GetBinWidth(0);
            Double_t dxo  = sig->GetBinWidth(nbin+1);
            TString uoflow = Form( "U/O-flow (S,B): (%.1f, %.1f)%% / (%.1f, %.1f)%%", 
                                   sig->GetBinContent(0)*dxu*100, bgd->GetBinContent(0)*dxu*100,
                                   sig->GetBinContent(nbin+1)*dxo*100, bgd->GetBinContent(nbin+1)*dxo*100 );
            TText* t = new TText( 0.975, 0.115, uoflow );
            t->SetNDC();
            t->SetTextSize( 0.030 );
            t->SetTextAngle( 90 );
            t->AppendPad();    
   
            // update canvas
            c->Update();

            // save canvas to file

            TMVAGlob::plot_logo(1.058);
            if (Save_Images) {
               if      (htype == MVAType)     TMVAGlob::imgconv( c, Form("plots/mva_%s",     methodTitle.Data()) );
               else if (htype == ProbaType)   TMVAGlob::imgconv( c, Form("plots/proba_%s",   methodTitle.Data()) ); 
               else if (htype == CompareType) TMVAGlob::imgconv( c, Form("plots/overtrain_%s", methodTitle.Data()) ); 
               else                           TMVAGlob::imgconv( c, Form("plots/rarity_%s",  methodTitle.Data()) ); 
            }
            countCanvas++;
         }
      }
   }
}
예제 #5
0
//------------------------------------------------------------------------------
// DrawIt
//------------------------------------------------------------------------------
void DrawIt(TString filename,
	    TString hname,
	    TString cname,
	    TString title)
{
  TFile* inputfile = TFile::Open("../AuxiliaryFilesWZXS8TeV/" + filename + ".root");

  TH2F* h = (TH2F*)inputfile->Get(hname)->Clone(cname);

  h->SetDirectory(0);

  inputfile->Close();

  TString name = h->GetName();

  TCanvas* canvas = new TCanvas(name, name, 600, 600);

  if (name.Contains("PR")) canvas->SetLogx();
  if (name.Contains("SF")) canvas->SetLogx();

  canvas->SetLeftMargin (0.9 * canvas->GetLeftMargin());
  canvas->SetRightMargin(3.5 * canvas->GetRightMargin());
  canvas->SetTopMargin  (1.2 * canvas->GetTopMargin());

  TH2FAxisFonts(h, "x", "p_{T} [GeV]");
  TH2FAxisFonts(h, "y", "#eta");

  h->Draw("colz");

  h->SetTitle("");

  DrawTLatex(42, 0.940, 0.976, _bigLabelSize, 33, title);

  if (!title.Contains("trigger")) {

    Double_t hmin = h->GetMinimum();
    Double_t hmax = h->GetMaximum();

    for (Int_t i=1; i<=h->GetNbinsX(); i++) {
      for (Int_t j=1; j<=h->GetNbinsY(); j++) {

	Double_t value = h->GetBinContent(i,j);

	Double_t ypos = h->GetYaxis()->GetBinCenter(j);
	Double_t xpos = h->GetXaxis()->GetBinCenter(i);
      
	if (gPad->GetLogx()) xpos = h->GetXaxis()->GetBinCenterLog(i);

	TLatex* latex = new TLatex(xpos, ypos, Form("%.2f", value));

	latex->SetTextAlign(   22);
	latex->SetTextFont (   42);
	latex->SetTextSize (0.027);

	if (value < hmin + 0.3*(hmax - hmin)) latex->SetTextColor(kWhite);
	
	latex->Draw();
      }
    }
  }


  // Set the palette font
  //----------------------------------------------------------------------------
  canvas->Update();

  TPaletteAxis* palette = (TPaletteAxis*)h->GetListOfFunctions()->FindObject("palette");

  palette->SetLabelFont(42);


  // Save the plot
  //----------------------------------------------------------------------------
  canvas->Update();
  
  canvas->Modified();

  canvas->GetFrame()->DrawClone();

  canvas->SaveAs("pdf/scale_factors/" + name + ".pdf");
  canvas->SaveAs("png/scale_factors/" + name + ".png");
}
예제 #6
0
파일: DrawKs.C 프로젝트: ktf/AliPhysics
TCanvas* DrawKs(const char* filename)
{

  TFile* file = TFile::Open(filename, "READ");
  if (!file) {
    Warning("DrawKs", "File %s couldn't be opened", filename);
    return 0;
  }

  TH1* cent = static_cast<TH1*>(file->Get("cent"));
  if (!cent) {
    Warning("DrawKs", "Failed to find cent in %s", file->GetName());
    return 0;
  }

  TString t(filename);
  t.ReplaceAll("results/", "");
  t.ReplaceAll("combine_","");
  t.ReplaceAll("_0x3.root", "");
  TString nm(filename);
  nm.ReplaceAll(".root", "");
  nm.ReplaceAll("results/", "plots/");
  nm.ReplaceAll("combine", "ks");
  if (t.Contains("none")) 
    t.ReplaceAll("none", "No weights");
  else
    t.Append(" weights");
  
  Int_t cW = 1200;
  Int_t cH =  800;
  TCanvas* c = new TCanvas(nm,t,cW, cH);
  c->SetTopMargin(0.07);
  c->SetRightMargin(0.20);
  c->SetTicks();
  
  TLegend* l = new TLegend(1-c->GetRightMargin(),
			   c->GetBottomMargin(), 
			   .99,
			   1-c->GetTopMargin());
  l->SetFillStyle(0);
  l->SetBorderSize(0);
  
  THStack* s = new THStack("ks", "");
  Int_t nCent = cent->GetXaxis()->GetNbins();
  for (Int_t i = 1; i <= nCent; i++) {
    Double_t c1 = cent->GetXaxis()->GetBinLowEdge(i);
    Double_t c2 = cent->GetXaxis()->GetBinUpEdge(i);

    TH1*     h  = GetCentK(file, c1, c2, nCent-i+1-2, l);
    if (!h) continue;

    s->Add(h);
  }
  s->Draw("nostack");
  TH1* f = s->GetHistogram();
  if (f) {
    f->SetXTitle("#eta");
    f->SetYTitle("#it{k}(#eta)");
  }
  
  TLatex* tit = new TLatex(0.55, 0.99, t);
  tit->SetTextFont(42);
  tit->SetTextAlign(23);
  tit->SetTextSize(0.03);
  tit->SetNDC();
  tit->Draw();
  l->SetBorderSize(0);
  l->Draw();

  c->Modified();
  c->Update();
  c->cd();

  return c;
}
예제 #7
0
void plotLimit(int signal = 0){
//signal: 0 = ZPN, 1 = ZPW, 2 = ZPXW, 3 = RSG  

setTDRStyle();

//gROOT->SetStyle("Plain");
gStyle->SetOptStat(0000000000); //this clears all the boxes and crap
gStyle->SetLegendBorderSize(1);

TGraph * limit_obs = new TGraph(3);
TGraph * limit_exp = new TGraph(3);
TGraphAsymmErrors * band_exp1 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2 = new TGraphAsymmErrors();

TGraph * limit_obs_2 = new TGraph(3);
TGraph * limit_exp_2 = new TGraph(3);
TGraphAsymmErrors * band_exp1_2 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_2 = new TGraphAsymmErrors();
TGraph * limit_obs_3 = new TGraph(3);
TGraph * limit_exp_3 = new TGraph(3);
TGraphAsymmErrors * band_exp1_3 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_3 = new TGraphAsymmErrors();
TGraph * limit_obs_4 = new TGraph(3);
TGraph * limit_exp_4 = new TGraph(3);
TGraphAsymmErrors * band_exp1_4 = new TGraphAsymmErrors();
TGraphAsymmErrors * band_exp2_4 = new TGraphAsymmErrors();
TGraph *theory = new TGraph(3);
TGraph *theory2 = new TGraph(3);
TGraph *theory3 = new TGraph(3);
TGraph *theory4 = new TGraph(3);

   theory->SetPoint(0,  0.01, 4.24671);

   theory->SetPoint(1,  0.1, 42.24246);

   theory->SetPoint(2,  0.3, 122.17487);
   theory2->SetPoint(0,  0.01, 0.17980);
   theory2->SetPoint(1,  0.1, 2.00723);
   theory2->SetPoint(2,  0.3, 6.99950);
   theory3->SetPoint(0, 0.01, 0.01659*0.1);
   theory3->SetPoint(1,  0.1, 0.23030*0.1);
   theory3->SetPoint(2,  0.3, 1.03387*0.1);
   theory4->SetPoint(0, 0.01, 0.00203*0.01);
   theory4->SetPoint(1, 0.1, 0.04254*0.01);
   theory4->SetPoint(2, 0.3, 0.25352*0.01); 

 string filename = "Limits/comb_width_1TeV.txt";
 if (signal == 1) filename= "Limits/comb_width_2TeV.txt";
 if (signal == 2) filename= "Limits/comb_width_3TeV.txt";
 if (signal == 3) filename= "Limits/comb_width_4TeV.txt";

ifstream infile(filename);

double mass, exp, obs, up1, up2, dn1, dn2;
int point = 0;

while (!infile.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 1.0;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs->SetPoint(point, mass, obs*sf);
  limit_exp->SetPoint(point, mass, exp*sf);
  band_exp1->SetPoint(point, mass, exp*sf);
  band_exp2->SetPoint(point, mass, exp*sf);
  
  band_exp1->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile2 ("Limits/comb_width_2TeV.txt");
point = 0;
while (!infile2.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile2 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 1.0;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_2->SetPoint(point, mass, obs*sf);
  limit_exp_2->SetPoint(point, mass, exp*sf);
  band_exp1_2->SetPoint(point, mass, exp*sf);
  band_exp2_2->SetPoint(point, mass, exp*sf);
  
  band_exp1_2->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_2->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_2->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_2->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile3 ("Limits/comb_width_3TeV.txt");
point = 0;

while (!infile3.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile3 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 0.1;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_3->SetPoint(point, mass, obs*sf);
  limit_exp_3->SetPoint(point, mass, exp*sf);
  band_exp1_3->SetPoint(point, mass, exp*sf);
  band_exp2_3->SetPoint(point, mass, exp*sf);

  band_exp1_3->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_3->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_3->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_3->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}

ifstream infile4 ("Limits/comb_width_4TeV.txt");
point = 0;

while (!infile4.eof()){

  //infile >> mass >> exp >>  dn2 >> up2 >> dn1 >> up1;
  //obs = exp;	

  infile4 >> mass >> obs >> exp >>  dn2 >> up2 >> dn1 >> up1;

 
  double sf = 0.01;
  cout.precision(3);
  //cout << mass << " & " << obs << " & " << exp << " & " << "["<<dn1<<", "<<up1<<"] & ["<<dn2<<", "<<up2<<"] \\" << endl;
  cout << mass << " & \\textbf{" << obs*sf << "} & " << dn2*sf << " & " << dn1*sf << " & \\textbf{" << exp*sf << "} & " << up1*sf << " & " << up2*sf <<  " \\\\" << endl;


  //if (mass == 2500) sf = 0.01;
  //if (mass == 3000) sf = 0.001;
  //if (mass == 3500) sf = 0.0001;
  //if (mass == 4000) sf = 0.0001;


  limit_obs_4->SetPoint(point, mass, obs*sf);
  limit_exp_4->SetPoint(point, mass, exp*sf);
  band_exp1_4->SetPoint(point, mass, exp*sf);
  band_exp2_4->SetPoint(point, mass, exp*sf);
  band_exp1_4->SetPointEYhigh(point, up1*sf - exp*sf);
  band_exp1_4->SetPointEYlow(point, exp*sf - dn1*sf);
  band_exp2_4->SetPointEYhigh(point, up2*sf - exp*sf);
  band_exp2_4->SetPointEYlow(point, exp*sf - dn2*sf);
  point++;

}





double max = 200000.0; //band_exp2->GetHistogram()->GetMaximum()*50;

  TCanvas *canvas = new TCanvas("limit set ZPN","limit set ZPN", 500,500);

  limit_exp->SetMinimum(0.00001);
  limit_exp->GetXaxis()->SetLabelSize(0.05);
  limit_exp->GetYaxis()->SetLabelSize(0.05);
  limit_exp->Draw("AL");
  if (signal == 0){
    limit_exp->GetXaxis()->SetTitle("#Gamma_{Z'} / M_{Z'}");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 1){
    limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 2){
    limit_exp->GetXaxis()->SetTitle("M_{Z'} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{Z'} #times B(Z'#rightarrowt#bar{t}) [pb]");
  }
  else if (signal == 3){
    limit_exp->GetXaxis()->SetTitle("M_{g_{KK}} [GeV]");
    limit_exp->GetYaxis()->SetTitle("95% CL Limit on #sigma_{g_{KK}} #times B(g_{KK}#rightarrowt#bar{t}) [pb]");
  }
  //limit_exp->GetYaxis()->SetTitleOffset(1.2);
  limit_exp->GetYaxis()->SetRangeUser(0.00001,2000);


  band_exp2->SetFillColor(5);
  band_exp2->SetLineColor(0);
  //band_exp2->SetFillStyle(4000);
  band_exp2->Draw("3same");

  band_exp1->SetFillColor(3);
  band_exp1->SetLineColor(0);
  //band_exp1->SetFillStyle(4000);
  band_exp1->Draw("3same");

  limit_obs->Draw("Lsame");
  limit_obs->SetLineWidth(2);
  limit_obs->SetMarkerSize(1.0);
  limit_obs->SetMarkerStyle(20);
   
  limit_exp->Draw("Lsame");
  limit_exp->SetLineStyle(2);
  limit_exp->SetLineWidth(2);
  limit_exp->SetMarkerSize(1.0);
  limit_exp->SetMaximum(max);
  limit_exp->SetMinimum(0.000001);
  limit_exp->SetMarkerStyle(20);
  

  band_exp2_2->SetFillColor(5);
  band_exp2_2->SetLineColor(0);
  band_exp1_2->SetFillColor(3);
  band_exp1_2->SetLineColor(0);
  band_exp2_3->SetFillColor(5);
  band_exp2_3->SetLineColor(0);
  band_exp1_3->SetFillColor(3);
  band_exp1_3->SetLineColor(0);
  band_exp2_4->SetFillColor(5);
  band_exp2_4->SetLineColor(0);
  band_exp1_4->SetFillColor(3);
  band_exp1_4->SetLineColor(0);
  band_exp2_2->Draw("3same");
  band_exp1_2->Draw("3same");
  limit_obs_2->Draw("Lsame");
  limit_obs_2->SetLineWidth(2);
  limit_obs_2->SetMarkerSize(1.0);
  limit_obs_2->SetMarkerStyle(20);
  band_exp2_3->Draw("3same");
  band_exp1_3->Draw("3same");
  limit_obs_3->Draw("Lsame");
  limit_obs_3->SetLineWidth(2);
  limit_obs_3->SetMarkerSize(1.0);
  limit_obs_3->SetMarkerStyle(20);
  band_exp2_4->Draw("3same");
  band_exp1_4->Draw("3same");
  limit_obs_4->Draw("Lsame");
  limit_obs_4->SetLineWidth(2);
  limit_obs_4->SetMarkerSize(1.0);
  limit_obs_4->SetMarkerStyle(20);

  limit_exp_2->Draw("L same");
  limit_exp_2->SetLineStyle(2);
  limit_exp_2->SetLineWidth(2);
  limit_exp_2->SetMarkerSize(1.0);
  limit_exp_3->Draw("L same");
  limit_exp_3->SetLineStyle(2);
  limit_exp_3->SetLineWidth(2);
  limit_exp_3->SetMarkerSize(1.0);
  limit_exp_4->Draw("L same");
  limit_exp_4->SetLineStyle(2);
  limit_exp_4->SetLineWidth(2);
  limit_exp_4->SetMarkerSize(1.0);








    canvas->RedrawAxis();

  double x1 = 595; 
  double y1 = 1.0;
  double x2 = 905;
  double y2 = 1.0;
  TLine * line = new TLine(x1, y1, x2, y2);
  theory->SetLineColor(2);
  theory->SetLineWidth(2);
  theory->Draw("same");
	theory2->SetLineColor(kBlue);
	theory2->SetLineWidth(2);
	theory2->Draw("same");
	theory3->SetLineColor(kMagenta);
	theory3->SetLineWidth(2);
	theory3->Draw("same");
	theory4->SetLineColor(kCyan);
	theory4->SetLineWidth(2);
	theory4->Draw("same");

  CMS_lumi(canvas, 4, 10);

  float t = canvas->GetTopMargin();
  float r = canvas->GetRightMargin();

  //Legend
  TLegend *l = new TLegend(0.51,0.63,0.99-r,0.99-t);
  l->AddEntry(limit_obs,"Observed", "L");
  l->AddEntry(limit_exp,"Expected", "L");
  l->AddEntry(band_exp1,"#pm1 #sigma Exp.", "F");
  l->AddEntry(band_exp2,"#pm2 #sigma Exp.", "F");
    l->AddEntry(theory, "Z' 1 TeV (NLO)", "L");
    l->AddEntry(theory2, "Z' 2 TeV (NLO)", "L");
    l->AddEntry(theory3, "Z' 3 TeV (NLO x 0.1)", "L");
    l->AddEntry(theory4, "Z' 4 TeV (NLO x 0.01)", "L");
  l->SetFillColor(0);
  l->SetLineColor(0);
  l->SetTextSize(0.04);
  l->SetTextFont(42);
  l->Draw();

  //TLatex * label = new TLatex();
  //label->SetNDC();
  //label->DrawLatex(0.2,0.86,"CMS Preliminary, 19.7 fb^{-1}");
  //label->DrawLatex(0.2,0.80,"#sqrt{s} = 8 TeV");
  //label->DrawLatex(0.6,0.80, Form("BR(b'#rightarrow %s) = 1", channel.Data()));
  //label->DrawLatex(0.55,0.80, "BR(b'#rightarrow tW) = 0.5");
  //label->DrawLatex(0.55,0.74, "BR(b'#rightarrow bH) = 0.25");
  //label->DrawLatex(0.55,0.68, "BR(b'#rightarrow bZ) = 0.25");
  //label->DrawLatex(0.2,0.74, lepton.Data());

  canvas->SetLogy(1);
  canvas->SetLogx(1);
  canvas->SetTickx(1);
  canvas->SetTicky(1);


  if (signal == 0){
    canvas->Print("Limits/comb_ZPN_limit.pdf");
    canvas->Print("Limits/comb_ZPN_limit.root");
  }
  else if (signal == 1){
    canvas->Print("Limits/comb_ZPW_limit.pdf");
    canvas->Print("Limits/comb_ZPW_limit.root");
  }
  else if (signal == 2){
    canvas->Print("Limits/comb_ZPXW_limit.pdf");
    canvas->Print("Limits/comb_ZPXW_limit.root");
  }
  else if (signal == 3){
    canvas->Print("Limits/comb_RSG_limit.pdf");
    canvas->Print("Limits/comb_RSG_limit.root");
  }
}
예제 #8
0
파일: drawXS.C 프로젝트: piedraj/usercode
//------------------------------------------------------------------------------
//
// drawXS
//
//------------------------------------------------------------------------------
void drawXS(UInt_t theCharge = WInclusive)
{
  gStyle->SetEndErrorSize(5);


  // 7 TeV inclusive
  //----------------------------------------------------------------------------
  xs_value[WInclusive][EEE] = 23.00;
  xs_value[WInclusive][EEM] = 19.67;
  xs_value[WInclusive][MME] = 19.81;
  xs_value[WInclusive][MMM] = 21.02;
  xs_value[WInclusive][all] = 20.76;
  
  xs_stat[WInclusive][EEE] = 3.10;
  xs_stat[WInclusive][EEM] = 2.73;
  xs_stat[WInclusive][MME] = 2.60;
  xs_stat[WInclusive][MMM] = 2.30;
  xs_stat[WInclusive][all] = 1.32;
  
  xs_syst[WInclusive][EEE] = 1.39;
  xs_syst[WInclusive][EEM] = 1.50;
  xs_syst[WInclusive][MME] = 1.55;
  xs_syst[WInclusive][MMM] = 1.47;
  xs_syst[WInclusive][all] = 1.13;
  
  xs_lumi[WInclusive][EEE] = 0.51;
  xs_lumi[WInclusive][EEM] = 0.43;
  xs_lumi[WInclusive][MME] = 0.44;
  xs_lumi[WInclusive][MMM] = 0.46;
  xs_lumi[WInclusive][all] = 0.46;
  
  
  // 7 TeV W+
  //----------------------------------------------------------------------------
  xs_value[WPlus][EEE] = 13.39;
  xs_value[WPlus][EEM] = 13.18;
  xs_value[WPlus][MME] = 14.14;
  xs_value[WPlus][MMM] = 11.43;
  xs_value[WPlus][all] = 12.73;
  
  xs_stat[WPlus][EEE] = 2.39;
  xs_stat[WPlus][EEM] = 2.24;
  xs_stat[WPlus][MME] = 2.19;
  xs_stat[WPlus][MMM] = 1.71;
  xs_stat[WPlus][all] = 1.04;
  
  xs_syst[WPlus][EEE] = 0.75;
  xs_syst[WPlus][EEM] = 0.64;
  xs_syst[WPlus][MME] = 0.74;
  xs_syst[WPlus][MMM] = 0.53;
  xs_syst[WPlus][all] = 0.59;
  
  xs_lumi[WPlus][EEE] = 0.29;
  xs_lumi[WPlus][EEM] = 0.29;
  xs_lumi[WPlus][MME] = 0.31;
  xs_lumi[WPlus][MMM] = 0.25;
  xs_lumi[WPlus][all] = 0.28;
  
  
  // 7 TeV W-
  //----------------------------------------------------------------------------
  xs_value[WMinus][EEE] = 9.49;
  xs_value[WMinus][EEM] = 6.51;
  xs_value[WMinus][MME] = 5.73;
  xs_value[WMinus][MMM] = 9.48;
  xs_value[WMinus][all] = 7.46;
  
  xs_stat[WMinus][EEE] = 1.95;
  xs_stat[WMinus][EEM] = 1.58;
  xs_stat[WMinus][MME] = 1.40;
  xs_stat[WMinus][MMM] = 1.52;
  xs_stat[WMinus][all] = 0.79;
  
  xs_syst[WMinus][EEE] = 0.60;
  xs_syst[WMinus][EEM] = 0.37;
  xs_syst[WMinus][MME] = 0.37;
  xs_syst[WMinus][MMM] = 0.50;
  xs_syst[WMinus][all] = 0.40;
  
  xs_lumi[WMinus][EEE] = 0.21;
  xs_lumi[WMinus][EEM] = 0.14;
  xs_lumi[WMinus][MME] = 0.13;
  xs_lumi[WMinus][MMM] = 0.21;
  xs_lumi[WMinus][all] = 0.16;


  // Do the work
  //----------------------------------------------------------------------------
  TGraphErrors* gStat = new TGraphErrors(nChannel);
  TGraphErrors* gSyst = new TGraphErrors(nChannel);
  TGraphErrors* gLumi = new TGraphErrors(nChannel);

  for (UInt_t i=0; i<nChannel; i++)
    {
      Double_t errorSquared = (xs_stat[theCharge][i] * xs_stat[theCharge][i]);

      gStat->SetPointError(i, sqrt(errorSquared) / xs_nlo[theCharge], 0.0);
      
      errorSquared += (xs_syst[theCharge][i] * xs_syst[theCharge][i]);

      gSyst->SetPointError(i, sqrt(errorSquared) / xs_nlo[theCharge], 0.0);

      errorSquared += (xs_lumi[theCharge][i] * xs_lumi[theCharge][i]);

      gLumi->SetPointError(i, sqrt(errorSquared) / xs_nlo[theCharge], 0.0);

      gStat->SetPoint(i, xs_value[theCharge][i] / xs_nlo[theCharge], nChannel-i-1);
      gSyst->SetPoint(i, xs_value[theCharge][i] / xs_nlo[theCharge], nChannel-i-1);
      gLumi->SetPoint(i, xs_value[theCharge][i] / xs_nlo[theCharge], nChannel-i-1);
    }


  // Cosmetics
  //----------------------------------------------------------------------------
  gStat->SetLineWidth  (2);
  gStat->SetMarkerSize (1.3);
  gStat->SetMarkerStyle(kFullCircle);

  gSyst->SetLineColor  (kRed);
  gSyst->SetLineWidth  (2);
  gSyst->SetMarkerSize (1.3);
  gSyst->SetMarkerStyle(kFullCircle);

  gLumi->SetLineColor  (kBlue);
  gLumi->SetLineWidth  (2);
  gLumi->SetMarkerSize (1.3);
  gLumi->SetMarkerStyle(kFullCircle);


  // Draw
  //----------------------------------------------------------------------------
  TString suffix = "7TeV_" + sCharge[theCharge];

  TCanvas* canvas = new TCanvas("ratioNLO_" + suffix, "ratioNLO_" + suffix);

  canvas->SetLeftMargin(canvas->GetRightMargin());

  Double_t xmin    =  0.0;
  Double_t xmax    =  2.0;
  Double_t ylegend =  1.2;
  Double_t ymin    = -0.6;
  Double_t ymax    = nChannel + ymin + ylegend;
  
  TH2F* h2 = new TH2F("h2_" + suffix, "", 100, xmin, xmax, 100, ymin, ymax);

  h2->Draw();
  
  
  // NLO WZ cross-section
  //----------------------------------------------------------------------------
  TBox* nlo = new TBox(1. - xs_nlo_left [theCharge] / xs_nlo[theCharge], ymin,
		       1. + xs_nlo_right[theCharge] / xs_nlo[theCharge], ymax - ylegend);

  nlo->SetLineColor(0);
  nlo->SetFillColor(kGray);
  nlo->SetFillStyle(1001);

  nlo->Draw("e2,same");

  TLine* line = new TLine(1., ymin, 1., ymax - ylegend);

  line->SetLineColor(kGray+1);
  line->SetLineWidth(2);

  line->Draw("same");


  // Cross sections
  //----------------------------------------------------------------------------
  gLumi->Draw("p,same");
  gSyst->Draw("p,same");
  gStat->Draw("p,same");


  // Labels
  //----------------------------------------------------------------------------
  for (UInt_t i=0; i<nChannel; i++) {

    Double_t x = gStat->GetX()[i];
    Double_t y = gStat->GetY()[i];

    Double_t gStatError = gStat->GetErrorX(i);
    Double_t gSystError = gSyst->GetErrorX(i);
    Double_t gLumiError = gLumi->GetErrorX(i);

    DrawTLatex(42, xmin+0.06, y+0.15, 0.035, 12,
	       Form("%s %.2f #pm %.2f",
		    lChannel[i].Data(), x, gLumiError), 0);

    gLumiError = sqrt(gLumiError*gLumiError - gSystError*gSystError);
    gSystError = sqrt(gSystError*gSystError - gStatError*gStatError);

    DrawTLatex(42, xmin+0.06, y-0.15, 0.025, 12,
	       Form("%.2f #pm %.2f #pm %.2f #pm %.2f",
		    x, gStatError, gSystError, gLumiError), 0);
  }

  DrawTLatex(42, 0.050, 0.975, _bigLabelSize, 13, "CMS Preliminary");

  DrawTLatex(42, 0.940, 0.983, _bigLabelSize, 33, 
	     Form("#sqrt{s} = 7 TeV, L = %.1f fb^{-1}", luminosity/1e3));

  TString swz = "";

  if      (theCharge == WPlus)  swz = "W^{+}Z";
  else if (theCharge == WMinus) swz = "W^{-}Z";
  else                          swz = "W^{#pm}Z";
  
  h2->GetXaxis()->CenterTitle();
  h2->GetXaxis()->SetTitleOffset(1.4);
  h2->GetXaxis()->SetTitle(Form("#sigma_{%s}^{exp} / #sigma_{%s}^{theory}",
				   swz.Data(),
				   swz.Data()));

  h2->GetYaxis()->SetTitle("");


  // Remove y-axis labels
  //----------------------------------------------------------------------------
  TAxis* yaxis = h2->GetYaxis();
  
  for (Int_t j=1; j<yaxis->GetNbins(); j++) yaxis->SetBinLabel(j, "");


  // Additional legend
  //----------------------------------------------------------------------------
  DrawLegend(0.645, 0.840, gStat, " stat.",  "lp");
  DrawLegend(0.645, 0.795, nlo,   " theory", "f");
  DrawLegend(0.800, 0.840, gSyst, " syst.",  "l");
  DrawLegend(0.800, 0.795, gLumi, " lumi.",  "l");


  // Save
  //----------------------------------------------------------------------------
  canvas->Update();
  canvas->GetFrame()->DrawClone();
  canvas->RedrawAxis();

  canvas->SaveAs(Form("pdf/ratioNLO_%s.pdf", suffix.Data()));
  canvas->SaveAs(Form("png/ratioNLO_%s.png", suffix.Data()));
}
예제 #9
0
TCanvas* makeNiceCanvasByPixMargins(Int_t pixelPerBinX, Int_t pixelPerBinY, Int_t nbinx, Int_t nbiny, Int_t top, Int_t bottom, Int_t left, Int_t right) {
  
  Int_t rubaX = 4; //determinato sperimentalmente                                                                          
  Int_t rubaY = 28; //determinato sperimentalmente                                                                                                        

  TString name = generateRandomName();

  Int_t plotBaseDimX = pixelPerBinX*nbinx;
  Int_t plotBaseDimY = pixelPerBinY*nbiny;
  Int_t XX = (Int_t)(plotBaseDimX+left+right);
  Int_t YY = (Int_t)(plotBaseDimY+top+bottom);
  TCanvas* can = new TCanvas(name,name,XX+rubaX,YY+rubaY);
  can->SetTopMargin((1.*top)/(1.*YY));
  can->SetBottomMargin((1.*bottom)/(1.*YY));
  can->SetRightMargin(right/(1.*XX));
  can->SetLeftMargin(left/(1.*XX));
  can->SetBorderMode(0);
  std::cout << "Nice canvas " << XX << " * " << YY << " Margin: t " << can->GetTopMargin() << " b " << can->GetBottomMargin() << " l " << can->GetLeftMargin() << " r " << can->GetRightMargin() << std::endl;

  return can;

}
예제 #10
0
void DrawMLPoutputMovie( TFile* file, const TString& methodType, const TString& methodTitle )
{
   gROOT->SetBatch( 1 );

   // define Canvas layout here!
   const Int_t width = 600;   // size of canvas

   // this defines how many canvases we need
   TCanvas* c = 0;

   Float_t nrms = 4;
   Float_t xmin = -1.2;
   Float_t xmax = 1.2;
   Float_t ymin = 0;
   Float_t ymax = 0;
   Float_t maxMult = 6.0;
   Int_t   countCanvas = 0;
   Bool_t  first = kTRUE;
            
   TString     dirname  = methodType + "/" + methodTitle + "/" + "EpochMonitoring";
   TDirectory *epochDir = (TDirectory*)file->Get( dirname );
   if (!epochDir) {
      cout << "Big troubles: could not find directory \"" << dirname << "\"" << endl;
      exit(1);
   }

   // now read all evolution histograms
   TIter keyItTit(epochDir->GetListOfKeys());
   TKey *titkeyTit;
   while ((titkeyTit = (TKey*)keyItTit())) {
      
      if (!gROOT->GetClass(titkeyTit->GetClassName())->InheritsFrom("TH1F")) continue;
      TString name = titkeyTit->GetName();
      
      if (!name.BeginsWith("convergencetest___")) continue;
      if (!name.Contains("_train_"))              continue; // only for training so far
      if (name.EndsWith( "_B"))                   continue;
      
      // must be signal histogram
      if (!name.EndsWith( "_S")) {
         cout << "Big troubles with histogram: " << name << " -> should end with _S" << endl;
         exit(1);
      }
      
      // create canvas
      countCanvas++;
      TString ctitle = Form("TMVA response %s",methodTitle.Data());
      c = new TCanvas( Form("canvas%d", countCanvas), ctitle, 0, 0, width, (Int_t)width*0.78 ); 
      
      TH1F* sig = (TH1F*)titkeyTit->ReadObj();
      sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) );
      
      TString dataType = (name.Contains("_train_") ? "(training sample)" : "(test sample)");
      
      // find background
      TString nbn = sig->GetName(); nbn[nbn.Length()-1] = 'B';            
      TH1F* bgd = dynamic_cast<TH1F*>(epochDir->Get( nbn ));
      if (bgd == 0) {
         cout << "Big troubles with histogram: " << bgd << " -> cannot find!" << endl;
         exit(1);
      }
      
      cout << "sig = " << sig->GetName() << endl;
      cout << "bgd = " << bgd->GetName() << endl;
      
      // set the histogram style
      TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
      
      // normalise both signal and background
      TMVAGlob::NormalizeHists( sig, bgd );
      
      // set only first time, then same for all plots
      if (first) {
         if (xmin == 0 && xmax == 0) {
            xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), 
                                          bgd->GetMean() - nrms*bgd->GetRMS() ),
                               sig->GetXaxis()->GetXmin() );
            xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), 
                                          bgd->GetMean() + nrms*bgd->GetRMS() ),
                               sig->GetXaxis()->GetXmax() );
         }
         ymin = 0;
         ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult;
         first = kFALSE;
      }
      
      // build a frame
      Int_t nb = 100;
      TString hFrameName(TString("frame") + methodTitle);
      TObject *o = gROOT->FindObject(hFrameName);
      if(o) delete o;
      TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), 
                              nb, xmin, xmax, nb, ymin, ymax );
      frame->GetXaxis()->SetTitle( methodTitle + " response" );
      frame->GetYaxis()->SetTitle("(1/N) dN^{ }/^{ }dx");
      TMVAGlob::SetFrameStyle( frame );
      
      // find epoch number (4th token)
      TObjArray* tokens = name.Tokenize("_");
      TString es = ((TObjString*)tokens->At(4))->GetString();
      if (!es.IsFloat()) {
         cout << "Big troubles in epoch parsing: \"" << es << "\" is not float" << endl;
         exit(1);
      }
      Int_t epoch = es.Atoi();
      
      // eventually: draw the frame
      frame->Draw();  
      
      c->GetPad(0)->SetLeftMargin( 0.105 );
      frame->GetYaxis()->SetTitleOffset( 1.2 );
      
      // Draw legend               
      TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, 
                                    c->GetLeftMargin() + 0.5, 1 - c->GetTopMargin() );
      legend->SetFillStyle( 1 );
      legend->AddEntry(sig,TString("Signal ")     + dataType, "F");
      legend->AddEntry(bgd,TString("Background ") + dataType, "F");
      legend->SetBorderSize(1);
      legend->SetMargin( 0.15 );
      legend->Draw("same");
      
      TText* t = new TText();            
      t->SetTextSize( 0.04 );
      t->SetTextColor( 1 );
      t->SetTextAlign( 31 );
      t->DrawTextNDC( 1 - c->GetRightMargin(), 1 - c->GetTopMargin() + 0.015, Form( "Epoch: %i", epoch) );
      
      // overlay signal and background histograms
      sig->Draw("samehist");
      bgd->Draw("samehist");
      
      // save to file
      TString dirname  = "movieplots";
      TString foutname = dirname + "/" + name;
      foutname.Resize( foutname.Length()-2 );
      foutname.ReplaceAll("convergencetest___","");
      foutname += ".gif";
      
      cout << "storing file: " << foutname << endl;
      
      c->Update();
      c->Print(foutname);            
   }
}