Exemplo n.º 1
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));
  }  
Exemplo n.º 2
0
/** 
 * 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"));
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
void vs_PlotQCDcomp() {

  Bool_t saveC  = false;
  Bool_t diJets = true;
  Bool_t isMC   = false;

  TString vsSave;
  vsSave = "_T07w";

  TString jSave;
  if(diJets) jSave = "2j";
  else       jSave = "3j";

  TString sample;
  if(diJets) sample = "select_1ph_2jets";
  else       sample = "select_1ph_3jets";

  TString FOtag;
  if(isMC) FOtag = "_FO_CorrMC";
  //  else     FOtag = "_FO_Corr";
  else     FOtag = "_FO";

  TString sysu = "SYSTUP_";
  TString sysd = "SYSTDOWN_";

  TString outDir;
  outDir = "Plots_PhotonSusyAnalysis/QCDweights/";


  //  string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_QCD_PhotonJet_T07w_PAT/mergedHistos.root";
  //  string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_Data_V05w_PAT/mergedHistos.root";
  string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/PhotonHadReReco_22Jan2013_V05_PAT/mergedHistos.root";
  
  
  setMyTDRStyle();
  gROOT->SetStyle("mytdrStyle");
  
  //  gStyle->SetHistMinimumZero();
  //  gStyle->SetPaintTextFormat("4.2f");

  gStyle->SetHistLineWidth(2);
  gStyle->UseCurrentStyle();

  //  gStyle->SetPadTopMargin(1.0);
  //  gStyle->SetPadLeftMargin(3.2);
  //  gStyle->SetPadRightMargin(4.5);
  //  gStyle->SetPadBottomMargin(3.2);

  gROOT->ForceStyle(1);


  static const Int_t nHt  =  7;
  static const Int_t nPt  = 13;
  static const Int_t nMet = 16;
  static const Int_t nJet = 15;

  Double_t binPt[nPt+1]   = {0.,75.,90.,120.,160.,210.,260.,320.,400.,500.,650.,800.,1000.,1500.};
  Double_t binHt[nHt+1]   = {0.,400.,450.,550.,700.,900.,1200.,1500.};
  Double_t binMet[nMet+1] = {0.,10.,20.,30.,40.,50.,60.,70.,80.,90.,100.,120.,160.,200.,270.,350.,500.};
  Double_t binJet[nJet+1] = {0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15};


  TLatex *as = new TLatex();
  as->SetNDC(true);
  as->SetTextColor(12);
  as->SetTextFont(43);
  as->SetTextSize(19);

  TLegend *legend = new TLegend(0.60, 0.70, 0.75, 0.85, "");
  legend->SetFillColor(10);
  legend->SetFillStyle(1001);
  legend->SetTextSize(0.04);
  legend->SetBorderSize(0);
  legend->SetShadowColor(0);

  std::string outLumi  = "CMS Work in Progress - QCD MC #sqrt{s} = 8 TeV - #geq 1 #gamma, #geq 2 j";

  TFile* f1 = TFile::Open( inputFile1.c_str() );

  //photon Pt
  TCanvas * cPt = new TCanvas("cPt","cPt");

  TH1F* hpt   = (TH1F*) f1->Get( sample+"/PreselCut_photonPt" );
  TH1F* hptFO = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_photonPt" );

  TH1F *hptR = (TH1F*) hpt->Rebin(nPt,hpt->GetTitle(),binPt);
  if (hptR->GetSumw2N() == 0)
    hptR->Sumw2();

  TH1F *hptFOR = (TH1F*) hptFO->Rebin(nPt,hptFO->GetTitle(),binPt);
  if (hptFOR->GetSumw2N() == 0)
    hptFOR->Sumw2();

  TH1F* hptSU = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysu+"photonPt" );
  TH1F* hptSD = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysd+"photonPt" );

  TH1F *hptSUR = (TH1F*) hptSU->Rebin(nPt,hptSU->GetTitle(),binPt);
  if (hptSUR->GetSumw2N() == 0)
    hptSUR->Sumw2();

  TH1F *hptSDR = (TH1F*) hptSD->Rebin(nPt,hptSD->GetTitle(),binPt);
  if (hptSDR->GetSumw2N() == 0)
    hptSDR->Sumw2();

  if ( hptFOR != 0 ) {
    for (int b = 0; b < hptFOR->GetNbinsX(); b++) {

      Double_t mainHistoContent   = hptFOR->GetBinContent(b);
      Double_t systUpHistoContent = hptSUR->GetBinContent(b);
      Double_t systDnHistoContent = hptSDR->GetBinContent(b);
      Double_t systDiffUp = fabs( (double) systUpHistoContent - mainHistoContent );
      Double_t systDiffDn = fabs( (double) mainHistoContent - systDnHistoContent );

      // use average error for histogram
      Double_t systDiff = ( systDiffUp + systDiffDn ) / 2.;
      
      Double_t statErr   = hptFOR->GetBinError(b);
      Double_t combError = sqrt( systDiff * systDiff + statErr * statErr );
      hptFOR->SetBinError(b, combError);
    } //for
  }//if
    
  cPt->SetLogy(1);
  gPad->Update();
  cPt->Update();

  //  hptR->Scale(1,"width");
  //  hptR->SetMinimum(0.02);
  //  hptR->SetMaximum(1000); 
  hptR->GetXaxis()->SetTitle("1^{st} photon p_{T} [GeV]");
  hptR->GetYaxis()->SetTitle("Number of Events / GeV");

  if(isMC) hptR->SetMarkerSize(0);
  if(isMC) hptR->Draw("histE");
  else     hptR->Draw("E X0");


  hptFOR->SetMarkerSize(0);
  hptFOR->SetLineColor(2);
  hptFOR->SetFillColor(2);
  hptFOR->SetFillStyle(3004);
  hptFOR->Draw("same hist ][ E2");

  legend->Clear();
  if(isMC) legend->SetHeader("#gamma/QCD (Sim)");
  else     legend->SetHeader("#gamma/QCD (Data)");
  if(isMC) legend->AddEntry(hptR, "#gamma", "l");
  else     legend->AddEntry(hptR, "#gamma", "p");
  legend->AddEntry(hptFOR, "Pred (from #gamma_{jet})", "f");
  legend->Draw();

  as->DrawLatex(0.17, 0.93, outLumi.c_str() );
  cPt->Update();
  cPt->SetBottomMargin(0.2 + 0.8 * cPt->GetBottomMargin() - 0.2 * cPt->GetTopMargin());

  TPad *ratioPt = new TPad("BottomPad", "", 0, 0, 1, 1);
  ratioPt->SetTopMargin(0.8 - 0.8 * ratioPt->GetBottomMargin() + 0.2 * ratioPt->GetTopMargin());
  ratioPt->SetFillStyle(0);
  ratioPt->SetFrameFillColor(10);
  ratioPt->SetFrameBorderMode(0);
  ratioPt->Draw();

  ratioPt->cd();
  ratioPt->SetLogy(0);

  TH1F *hptRat = (TH1F*) divideHistosForRatio(hptR,hptFOR);
  hptRat->SetMinimum(0.);
  hptRat->SetMaximum(10.);
  hptRat->GetXaxis()->SetNdivisions(505);
  if(isMC) hptRat->GetYaxis()->SetTitle("Sim/Pred");
  else     hptRat->GetYaxis()->SetTitle("Data/Pred");
  hptRat->GetYaxis()->SetTitleSize(0.04);
  hptRat->GetYaxis()->SetLabelSize(0.03);
  hptRat->GetYaxis()->SetTitleOffset(1.3);
  hptRat->GetYaxis()->SetNdivisions(505);
  hptRat->SetMarkerStyle(20);
  hptRat->SetMarkerSize(1);
  hptRat->SetMarkerColor(1);
  hptRat->SetLineColor(1);
  hptRat->Draw("E X0");

  TH1F *hptFRat = (TH1F*) getSystErrForRatio(hptFOR);
  hptFRat->SetLineColor(2);
  hptFRat->SetFillColor(2);
  hptFRat->SetFillStyle(3004);
  hptFRat->Draw("same hist ][ E2");


  TLine * line = new TLine( hptRat->GetXaxis()->GetXmin(), 1., hptRat->GetXaxis()->GetXmax(), 1. );
  line->SetLineColor(1);
  line->SetLineWidth(0.5);
  line->SetLineStyle(1);
  line->Draw("same");

  hptR->GetXaxis()->SetLabelSize(0);
  hptR->GetXaxis()->SetTitle("");
  cPt->RedrawAxis();
  gPad->Update();
  cPt->Update();


  return;
}
Exemplo n.º 5
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;

}