Ejemplo n.º 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 );
}
void showGraph(double canvasSizeX, double canvasSizeY,
	       TGraph* graph, 
	       bool useLogScaleX, double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset,
	       bool useLogScaleY, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset,
	       const std::string& outputFileName)
{
  TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2); 
  canvas->SetTopMargin(0.05);
  canvas->SetLeftMargin(0.19);
  canvas->SetBottomMargin(0.19);
  canvas->SetRightMargin(0.05);
  canvas->SetLogx(useLogScaleX);
  canvas->SetLogy(useLogScaleY);

  TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 10, xMin, xMax);
  dummyHistogram->SetTitle("");
  dummyHistogram->SetStats(false);
  dummyHistogram->SetMinimum(yMin);
  dummyHistogram->SetMaximum(yMax);
  dummyHistogram->Draw("axis");

  TAxis* xAxis = dummyHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.data());
  xAxis->SetTitleOffset(xAxisOffset);
  xAxis->SetTitleSize(0.065);
  xAxis->SetLabelSize(0.055);
  xAxis->SetLabelOffset(0.01);
  xAxis->SetTickLength(0.055);
  xAxis->SetNdivisions(505);

  TAxis* yAxis = dummyHistogram->GetYaxis();
  yAxis->SetTitle(yAxisTitle.data());
  yAxis->SetTitleOffset(yAxisOffset);
  yAxis->SetTitleSize(0.070);
  yAxis->SetLabelSize(0.055);
  yAxis->SetLabelOffset(0.01);
  yAxis->SetTickLength(0.055);
  yAxis->SetNdivisions(505);

  graph->SetMarkerColor(1);
  graph->SetLineColor(1);
  graph->Draw("p");

  canvas->Update();
  size_t idx = outputFileName.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName, 0, idx);
  if ( useLogScaleY ) outputFileName_plot.append("_log");
  else outputFileName_plot.append("_linear");
  if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
  canvas->Print(std::string(outputFileName_plot).append(".png").data());
  //canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
  //canvas->Print(std::string(outputFileName_plot).append(".root").data());
  
  delete dummyHistogram;
  delete canvas;  
}
Ejemplo n.º 3
0
void DrawHijing2GeV()
{
  TCanvas *c1 = new TCanvas();
TFile *fin = TFile::Open("Gamma_Neutron_Hijing_Energy_Graphs.root");
gROOT->cd();
TH1 *h1lim = new TH1F("h1lim","",1,0,0.1);
TH1 *hjbkg = (TH1 *) fin->Get("hjbkg")->Clone();
TGraph *anti_neutron2GeV = (TGraph *) fin->Get("anti_neutron2GeV")->Clone();
TGraph *neutron2GeV = (TGraph *) fin->Get("neutron2GeV")->Clone();
h1lim->SetStats(0);
h1lim->SetMaximum(0.3);
h1lim->SetTitle("2 GeV Hadronic Showers with HIJING background");
h1lim->GetYaxis()->SetTitle("Deposited Energey [GeV]");
h1lim->GetYaxis()->SetTitleOffset(1.2);
h1lim->GetXaxis()->SetTitle("cone size (#sqrt{#Delta#Phi^{2}+#Delta#Theta^{2}})");
h1lim->GetXaxis()->SetTitleOffset(1.2);
h1lim->Draw();
hjbkg->SetStats(0);
hjbkg->SetLineColor(6);
hjbkg->SetMaximum(5.5);
hjbkg->SetLineWidth(2);
hjbkg->Draw("same");
anti_neutron2GeV->SetLineColor(4);
anti_neutron2GeV->SetLineWidth(2);
anti_neutron2GeV->Draw("same");
neutron2GeV->SetLineColor(2);
neutron2GeV->SetLineWidth(2);
neutron2GeV->Draw("same");
TLine *tl = new TLine();
tl->SetLineStyle(2);
tl->DrawLine(0.024,0,0.024,0.3);
TLegend *legrda = new TLegend(0.67,0.34,0.87,0.54,NULL,"brNDC");
  legrda->SetLineColor(1);
  legrda->SetLineStyle(1);
  legrda->SetLineWidth(1);
  legrda->SetFillColor(10);
  legrda->SetFillStyle(1001);
  legrda->SetBorderSize(0);
//  legrda->SetTextSize(labelsize);
  legrda->AddEntry(hjbkg,"HIJING bkg"); 
  legrda->AddEntry(anti_neutron2GeV,"2 GeV Anti Neutron","l"); 
  legrda->AddEntry(neutron2GeV,"2 GeV Neutron", "l"); 
  legrda->AddEntry(tl,"EMCal tower size","l"); 
  legrda->Draw();
 
fin->Close();
c1->Print("Hijing2GeV.png");
}
Ejemplo n.º 4
0
TH1 *computeEffVsCut(TH1 *discrShape, double total)
{
	TH1 *h = discrShape->Clone(Form("%s_effVsCut", discrShape->GetName()));
	h->Sumw2();
	h->SetMaximum(1.5);
	h->SetMinimum(1e-3);

	unsigned int n = h->GetNbinsX();
	for(unsigned int bin = 1; bin <= n; bin++) {
		double efficiency = h->Integral(bin, n + 1) / total;
		double error = sqrt(efficiency * (1 - efficiency) / total);
		h->SetBinContent(bin, efficiency);
		h->SetBinError(bin, error);
	}

	return h;
}
Ejemplo n.º 5
0
TCanvas* DrawNP(int np, TObjArray* harr, TCanvas* cnv)
{
  if (!harr) harr = &histoArr;
  if (!cnv) cnv = new TCanvas(Form("cnv%d",np),Form("cnv%d",np),900,700);
  cnv->Clear();
  cnv->Divide(2,1);
  cnv->cd(1);
  //
  TH1* dxodd = (TH1*)harr->At(np*10+kDTXodd);
  TH1* dxevn = (TH1*)harr->At(np*10+kDTXeven);
  TH1* dxoddS =(TH1*)harr->At(np*10+kDTXoddSPL);
  TH1* dxevnS =(TH1*)harr->At(np*10+kDTXevenSPL);
  double max = TMath::Max(dxodd->GetMaximum(),dxevn->GetMaximum());
  dxodd->SetMaximum(1.1*max);
  dxodd->GetXaxis()->SetTitle("#DeltaX, #mum");
  dxodd->SetTitle(Form("#DeltaX for clSize=%d",np));
  dxodd->Fit("gaus","","");
  dxevn->Fit("gaus","","sames");
  //
  dxoddS->Draw("sames");
  dxevnS->Draw("sames");
  //
  gPad->Modified();
  gPad->Update();
  SetStPadPos(dxodd,0.75,0.97,0.8,1., -1,dxodd->GetLineColor());
  SetStPadPos(dxevn,0.75,0.97,0.6,0.8, -1,dxevn->GetLineColor());
  SetStPadPos(dxoddS,0.75,0.97,0.4,0.6, -1,dxoddS->GetLineColor());
  SetStPadPos(dxevnS,0.75,0.97,0.2,0.4, -1,dxevnS->GetLineColor());
  //
  cnv->cd(2);
  TH1* dz  = (TH1*)harr->At(np*10+kDTZ);
  dz->SetTitle(Form("#DeltaZ for clSize=%d",np));
  dz->GetXaxis()->SetTitle("#DeltaZ, #mum");
  dz->Fit("gaus");
  TH1* dzS = (TH1*)harr->At(np*10+kDTZSPL);
  dz->Draw("sames");
  gPad->Modified();
  gPad->Update();
  SetStPadPos(dz,0.75,0.97,0.8,1., -1, dz->GetLineColor());
  SetStPadPos(dzS,0.75,0.97,0.5,0.7, -1, dzS->GetLineColor());
  gPad->Modified();
  gPad->Update();
  //
  cnv->cd();
  return cnv;
}
Ejemplo n.º 6
0
void
TestShaping(int max=4)
{
  TArrayI adcs(10);
  TGraph* orig = new TGraph(adcs.fN);
  orig->SetName("Original");
  orig->SetTitle("Original");
  orig->SetMarkerStyle(25);
  orig->SetMarkerColor(1);
  orig->SetMarkerSize(2);
  orig->SetLineColor(1);
  for (Int_t i = 0; i < adcs.fN; i++) { 
    adcs.fArray[i] = Int_t(gRandom->Uniform(0, 1023));
    orig->SetPoint(i, i, adcs.fArray[i]);
  }

  TCanvas* c = new TCanvas("c", "c");
  c->SetFillColor(0);
  c->SetTopMargin(.02);
  c->SetRightMargin(.02);
  
  TH1* h = new TH1F("frame","frame", adcs.fN+1, -2, adcs.fN);
  h->SetMinimum(0);
  h->SetMaximum(1300);
  h->SetStats(0);
  h->Draw("");
  orig->Draw("pl same");

  TLegend* l = new TLegend(adcs.fN*3./4, 1023, adcs.fN, 1300, "", "");
  l->SetFillColor(0);
  l->SetBorderSize(1);
  l->AddEntry(orig, orig->GetTitle(), "lp");
  
  for (int i = 1; i <= max; i++) {
    TGraph* g = makeGraph(adcs, i);
    g->Draw("pl same");
    l->AddEntry(g, g->GetTitle(), "lp");
  }
  l->Draw();
  
  c->Modified();
  c->Update();
  c->cd();
}
Ejemplo n.º 7
0
TH1 *computeEffVsBEff(TH1 *effVsCut, TH1 *effVsCutB)
{
	TH1 *h = new TH1F(Form("%s_effVsBEff", effVsCut->GetName()), "effVsBEff",
	                  100, 0, 1);
	h->SetMaximum(1.5);
	h->SetMinimum(1e-3);

	unsigned int n = effVsCut->GetNbinsX();
	for(unsigned int bin = 1; bin <= n; bin++) {
		double eff = effVsCut->GetBinContent(bin);
		double error = effVsCut->GetBinError(bin);
		double effB = effVsCutB->GetBinContent(bin);

		h->SetBinContent(h->FindBin(effB), eff);
		h->SetBinError(h->FindBin(effB), error);
 		// FIXME: The error in effB is not propagated
	}

	return h;
}
TH1* getMonitorElement(TFile* inputFile, const TString& dqmDirectory, const char* dqmSubDirectory, const TString& meName)
{
  TString meName_full = TString("DQMData").Append("/");
  if ( dqmDirectory != "") meName_full.Append(dqmDirectory).Append("/");
  meName_full.Append(dqmSubDirectory).Append("/").Append(meName);
  std::cout << "meName_full = " << meName_full << std::endl;
  
  TH1* me = (TH1*)inputFile->Get(meName_full);
  std::cout << "me = " << me <<  std::endl;
  
  //if ( !me->GetSumw2() ) me->Sumw2();
  me->Sumw2();

  me->Rebin(2);

  me->Scale(1./me->Integral());

  me->SetMaximum(1.);
  me->SetStats(false);

  return me;
}
void boostcontrolplots( TDirectory *boostdir ) {

   const Int_t nPlots = 4;

   Int_t width  = 900;
   Int_t height = 600;
   char cn[100];
   const TString titName = boostdir->GetName();
   sprintf( cn, "cv_%s", titName.Data() );
   TCanvas *c = new TCanvas( cn,  Form( "%s Control Plots", titName.Data() ),
                             width, height ); 
   c->Divide(2,2);


   const TString titName = boostdir->GetName();

   TString hname[nPlots]={"Booster_BoostWeight","Booster_MethodWeight","Booster_ErrFraction","Booster_OrigErrFraction"};

   for (Int_t i=0; i<nPlots; i++){
      Int_t color = 4; 
      TPad * cPad = (TPad*)c->cd(i+1);
      TH1 *h = (TH1*) boostdir->Get(hname[i]);
      TString plotname = h->GetName();
      h->SetMaximum(h->GetMaximum()*1.3);
      h->SetMinimum( 0 );
      h->SetMarkerColor(color);
      h->SetMarkerSize( 0.7 );
      h->SetMarkerStyle( 24 );
      h->SetLineWidth(1);
      h->SetLineColor(color);
      h->Draw();
      c->Update();
   }

   // write to file
   TString fname = Form( "plots/%s_ControlPlots", titName.Data() );
   TMVAGlob::imgconv( c, fname );
   
}
Ejemplo n.º 10
0
void drawTimeDifference (TDirectory* directory, TH1* refHisto, const char* fname=0)
{
  TGraphErrors* graphX = (TGraphErrors*)directory->Get("x");
  if ( graphX==0 )  return;
  TH1I* hFirst = (TH1I*)directory->Get("firstTime");
  TH1I* hLast = (TH1I*)directory->Get("lastTime");
  if ( hFirst==0 || hLast==0 )  return;

  std::string fullName("cDeltaT");
  if ( fname )  fullName += fname;
  else  fullName += directory->GetName();
  TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str());
  TH1* h = refHisto->Clone("DeltaT");
  h->Reset();
  h->SetTitle("DeltaT");

  TGraph* graph = new TGraph();
  graph->SetName("gDeltaT");

  double xg,yg;
  for ( unsigned int i=1; i<=hFirst->GetNbinsX(); ++i ) {
    std::time_t t1 = hFirst->GetAt(i);
    std::time_t t2 = hLast->GetAt(i);
    TTimeStamp ts1(hFirst->GetAt(i));
    std::cout << "Fit started at " << ts1.AsString() << std::endl;
    graphX->GetPoint(i-1,xg,yg);
    graph->SetPoint(i-1,xg,difftime(t2,t1));
  }

  double xmin,xmax,ymin,ymax;
  graph->ComputeRange(xmin,ymin,xmax,ymax);
  h->SetMinimum(0.);
  h->SetMaximum((ymax+ymin)/2.+2.*(ymax-ymin)/2.);
  h->Draw();
  graph->SetMarkerStyle(20);
//   graph->SetMarkerColor(2);
//   graph->SetLineColor(2);
  graph->Draw("P");
}
Ejemplo n.º 11
0
void axesStyle(TH1& hist, const char* titleX, const char* titleY, float yMin, float yMax, float yTitleSize, float yTitleOffset) 
{
  hist.SetTitle("");
  hist.GetXaxis()->SetTitle(titleX);
  hist.GetXaxis()->CenterTitle();
  hist.GetXaxis()->SetTitleSize  ( 0.06);
  hist.GetXaxis()->SetTitleColor (    1);
  hist.GetXaxis()->SetTitleOffset(  1.0);
  hist.GetXaxis()->SetTitleFont  (   62);
  hist.GetXaxis()->SetLabelSize  ( 0.05);
  hist.GetXaxis()->SetLabelFont  (   62);
  hist.GetXaxis()->SetNdivisions (  505);
  hist.GetYaxis()->SetTitle(titleY);
  hist.GetYaxis()->SetTitleSize  ( yTitleSize );
  hist.GetYaxis()->SetTitleColor (    1);
  hist.GetYaxis()->SetTitleOffset(yTitleOffset);
  hist.GetYaxis()->SetTitleFont  (   62);
  hist.GetYaxis()->SetLabelSize  ( 0.04);
  hist.GetYaxis()->SetLabelFont  (   62);
  hist.GetYaxis()->CenterTitle   ( true);
  if(yMin!=-123) hist.SetMinimum(yMin);
  if(yMax!=-123) hist.SetMaximum(yMax);
}
Ejemplo n.º 12
0
void drawEventDifference (TDirectory* directory, TH1* refHisto, const char* fname=0)
{
  TGraphErrors* graphX = (TGraphErrors*)directory->Get("x");
  if ( graphX==0 )  return;
  TH1I* hFirst = (TH1I*)directory->Get("firstEvent");
  TH1I* hLast = (TH1I*)directory->Get("lastEvent");
  if ( hFirst==0 || hLast==0 )  return;

  std::string fullName("cDeltaE");
  if ( fname )  fullName += fname;
  else  fullName += directory->GetName();
  TCanvas* c = new TCanvas(fullName.c_str(),fullName.c_str());
  TH1* h = refHisto->Clone("DeltaE");
  h->Reset();
  h->SetTitle("DeltaE");

  TGraph* graph = new TGraph();
  graph->SetName("gDeltaE");

  double xg,yg;
  for ( unsigned int i=1; i<=hFirst->GetNbinsX(); ++i ) {
    int e1 = hFirst->GetAt(i);
    int e2 = hLast->GetAt(i);
    graphX->GetPoint(i-1,xg,yg);
    graph->SetPoint(i-1,xg,e2-e1);
  }

  double xmin,xmax,ymin,ymax;
  graph->ComputeRange(xmin,ymin,xmax,ymax);
  h->SetMinimum(0.);
  h->SetMaximum((ymax+ymin)/2.+2.*(ymax-ymin)/2.);
  h->Draw();
  graph->SetMarkerStyle(20);
//   graph->SetMarkerColor(2);
//   graph->SetLineColor(2);
  graph->Draw("P");
}
Ejemplo n.º 13
0
void makeStack(TString myVar, TString myCut, TString myName, TString myAxisNameX, TString myAxisNameY, 
               vector<const Sample*>& listOfSignals, vector<const Sample*>& listOfSamples, vector<const Sample*> listOfDatasets, 
               TString inFileName,
               bool isBlind, bool isLog, bool drawSignal, bool drawLegend,
               int nBins, float xLow, float xHigh,
               float* xlowVec)
{
  // prepare the input file
  TFile* infile = new TFile(inFileName, "READ"); 
  infile -> cd();
  
  // prepare the stack
  THStack *hs = new THStack("hs","");
  // prepare the histos pointers
  TH1F*   hist[20];
  // prepare the tree pointers
  TTree*  tree[20];
  // prepare the legend
  TLegend* leg = new TLegend(.7485,.7225,.9597,.9604);
  leg->SetFillColor(0);
  // prepare the colors
  Int_t col[20] = {46,2,12,5,3,4,9,7,47,49,49,50,51,52,53,54,55,56,57,58};
  // prepare the cut
  if (isBlind) myCut += "*(phoMetDeltaPhi < 2.9)";        
  // prepare the Y axis lable
  if (xlowVec != 0) myAxisNameY = "Events/" + myAxisNameY;
  else {
    float binWidth = (xHigh-xLow)/nBins;
    TString tempString;
    tempString.Form("%.2f ",binWidth); 
    myAxisNameY = "Events/" + tempString + myAxisNameY;
  }
  // prepare the legend strings
  vector<TString> theLegends;
  
  // loop through the datasets and produce the plots
  TH1F* hdata;
  TH1F* hsignal;
  //prepare data and signal histos
  if (xlowVec != 0) hdata   = new TH1F("hdata","",nBins,xlowVec);
  else hdata = new TH1F("hdata","",nBins,xLow,xHigh);
  if (xlowVec != 0) hsignal = new TH1F("hsignal","",nBins,xlowVec);
  else hsignal = new TH1F("hsignal","",nBins,xLow,xHigh);

  TTree*  treedata[20];
  for (UInt_t iDatas=0; iDatas < listOfDatasets.size(); iDatas++) {
    //get the tree
    treedata[iDatas] = (TTree*) infile -> Get(listOfDatasets.at(iDatas)->Name()->Data());

    //fill the histogram
    if ( iDatas == 0 ) treedata[iDatas] -> Draw(myVar + " >> hdata","evt_weight*kf_weight*pu_weight" + myCut);
    else treedata[iDatas] -> Draw(myVar + " >>+ hdata","evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( isBlind && iDatas == 0 ) leg -> AddEntry(hdata, "DATA (19.8 fb^{-1})", "pl");    
    
  }//end loop on datasets
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinError  (iBin,hdata->GetBinError(iBin)/hdata->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinContent(iBin,hdata->GetBinContent(iBin)/hdata->GetBinWidth(iBin));
  }

  TTree*  treesignal[20];
  for (UInt_t iSignal=0; iSignal < listOfSignals.size(); iSignal++) {
    //get the tree
    treesignal[iSignal] = (TTree*) infile -> Get(listOfSignals.at(iSignal)->Name()->Data());

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSignals.at(iSignal)->Scale()));
    if ( iSignal == 0 ) treesignal[iSignal] -> Draw(myVar + " >> hsignal",thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    else treesignal[iSignal] -> Draw(myVar + " >>+ hsignal",thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( drawSignal && iSignal == 0 ) leg -> AddEntry(hsignal, "Signal", "l");    
    
  }//end loop on signals
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinError  (iBin,hsignal->GetBinError(iBin)/hsignal->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinContent(iBin,hsignal->GetBinContent(iBin)/hsignal->GetBinWidth(iBin));
  }
  hsignal -> SetLineColor(49);
  hsignal -> SetLineWidth(4.0);
       
  int theHistCounter = 0;
  // loop through the samples and produce the plots
  for (UInt_t iSample=0; iSample < listOfSamples.size(); iSample++) {

    //determine if the histo is first of the series
    bool isFirstOfSerie = (*listOfSamples.at(iSample)->Legend()).CompareTo(" ");
    bool isLastOfSerie = false;
    if (iSample == listOfSamples.size() - 1) isLastOfSerie = true;
    if (iSample < listOfSamples.size() - 1 && (*listOfSamples.at(iSample+1)->Legend()).CompareTo(" ") != 0) isLastOfSerie = true;
    
    //get the tree
    tree[iSample] = (TTree*) infile -> Get(listOfSamples.at(iSample)->Name()->Data());
    //if sample first of the list create a new histogram
    if (isFirstOfSerie) {
       TString thisHistName = "h_" + *(listOfSamples.at(iSample)->Name());
       //variable bin histo
       if (xlowVec != 0) hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xlowVec);
       //fixed bin histo
       else hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xLow,xHigh);
       hist[theHistCounter] -> Sumw2();
       hist[theHistCounter] -> SetFillColor(col[theHistCounter]);
       hist[theHistCounter] -> SetFillStyle(1001);
       theLegends.push_back(*listOfSamples.at(iSample)->Legend());
    }

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSamples.at(iSample)->Scale()));
    if (isFirstOfSerie) tree[iSample] -> Draw(myVar + " >> " + TString(hist[theHistCounter] -> GetName()),thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    else tree[iSample] -> Draw(myVar + " >>+ " + TString(hist[theHistCounter] -> GetName()),thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    
    //add the histogram to the stack if the last of the series:
    //either last sample or ~ sample followed by non ~ sample
    if (isLastOfSerie) {
       if (xlowVec != 0) {
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinError  (iBin,hist[theHistCounter]->GetBinError(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinContent(iBin,hist[theHistCounter]->GetBinContent(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
       }
       hs -> Add(hist[theHistCounter]);
       theHistCounter++;
    }
    
  }//end loop on samples

  //Fix the legend
  for (int iHisto = theHistCounter-1; iHisto >= 0; iHisto--) {
    leg -> AddEntry(hist[iHisto], theLegends[iHisto], "f");   
  }
  
  //get the maximum to properly set the frame
  float theMax = hdata -> GetBinContent(hdata -> GetMaximumBin()) + hdata -> GetBinError(hdata -> GetMaximumBin());
  TH1* theMCSum = (TH1*) hs->GetStack()->Last();
  float theMaxMC = theMCSum->GetBinContent(theMCSum->GetMaximumBin()) + theMCSum->GetBinError(theMCSum->GetMaximumBin());
  if (theMaxMC > theMax) theMax = theMaxMC;
  
  //prepare the ratio band and plot
  TH1* theMCRatioBand = makeRatioBand(theMCSum);
  TH1* theRatioPlot = makeRatioPlot(hdata,theMCSum);
    
  TCanvas* can = new TCanvas();
  can -> SetLogy(isLog);
  
  TPad *pad1 = new TPad("pad1","top pad",0,0.30,1,1);
  pad1->SetBottomMargin(0.02);
  pad1->SetLeftMargin(0.13);
  pad1->Draw();
  TPad *pad2 = new TPad("pad2","bottom pad",0,0.0,1,0.30);
  pad2->SetTopMargin(0.02);
  pad2->SetLeftMargin(0.13);
  pad2->SetBottomMargin(0.4);
  pad2->SetGridy();
  pad2->Draw();
  
  pad1->cd();
  hs->Draw("hist");
  hdata->Draw("same,pe");
  if (drawSignal) hsignal->Draw("same,hist");
  if (drawLegend) leg->Draw("same");
  //hs->GetXaxis()->SetTitle(myAxisNameX);
  hs->GetYaxis()->SetTitle(myAxisNameY);
  hs->GetXaxis()->SetLabelSize(0.04);
  hs->GetYaxis()->SetLabelSize(0.04);
  hs->GetXaxis()->SetLabelOffset(0.025);
  hs->GetYaxis()->SetLabelOffset(0.035);
  //hs->GetXaxis()->SetTitleOffset(1.1);
  hs->GetYaxis()->SetTitleOffset(1.1);
  hs->SetMaximum(theMax);
  if (isLog) hs->SetMinimum(0.01);
  
  pad2->cd();
  theMCRatioBand->GetXaxis()->SetTitle(myAxisNameX);
  theMCRatioBand->GetXaxis()->SetTitleSize(0.16);
  theMCRatioBand->GetXaxis()->SetTitleOffset(1.1);
  theMCRatioBand->GetXaxis()->SetLabelSize(0.12);
  theMCRatioBand->GetXaxis()->SetLabelOffset(0.07);
  theMCRatioBand->GetYaxis()->SetTitle("Data/MC");
  theMCRatioBand->GetYaxis()->SetTitleSize(0.10);
  theMCRatioBand->GetYaxis()->SetTitleOffset(0.6);
  theMCRatioBand->GetYaxis()->SetLabelSize(0.06);
  theMCRatioBand->GetYaxis()->SetLabelOffset(0.03);
  theMCRatioBand->SetFillStyle(3001);
  theMCRatioBand->SetFillColor(kBlue);
  theMCRatioBand->SetLineWidth(1);
  theMCRatioBand->SetLineColor(kBlack);
  theMCRatioBand->SetMarkerSize(0.1);
  theMCRatioBand->SetMaximum(4.);
  theMCRatioBand->SetMinimum(0.);
  theMCRatioBand->Draw("E2");
  TLine *line = new TLine(xLow,1,xHigh,1);
  line->SetLineColor(kBlack);
  line->Draw("same");
  theRatioPlot->Draw("same,pe");
  
  can->cd();
  can->Modified();
  can -> SaveAs(myName + ".pdf","pdf");
  
  //cleanup the memory allocation
  delete theMCSum;
  delete hs;
  delete leg;
  delete hdata;
  delete pad1;
  delete pad2;
  delete can;
  delete theMCRatioBand;
  delete theRatioPlot;
  infile -> Close();
  delete infile;
  
  return;
}
Ejemplo n.º 14
0
void cmsRAA(int version = 6)
{
  double mymarkersize = 1.;
  bool bDo2PadZoo = true;
  
  //----------------------------------------- charged hadrons
  double ptBins_h[27]={0};
  double ptError_h[27]={0};
  
  double raa_h[27];
  double raaStat_h[27];
  double raaSyst_h[27];

  double ptSystXlow_h[27];
  double ptSystXhigh_h[27];

  // reading numbers
  ifstream inData_h; 
  TString inFile("raa_h05.dat");
  inData_h.open(inFile);
  if(inData_h.fail()) {
    cerr << "unable to open file raa_h05.dat for reading" << endl;
    exit(1);
  }
  Int_t j=0;
  Double_t xx_low, xx_high,raa,raa_syst, raa_stat;
  while(!inData_h.eof())
  { 
    inData_h >> xx_low >> xx_high >> raa >> raa_syst >> raa_stat;
    ptBins_h[j]   = xx_low+ (xx_high-xx_low)/2;
    raa_h[j]      = raa;
    raaStat_h[j]  = raa_syst;
    raaSyst_h[j]  = raa_stat;
    
    ptSystXlow_h[j] = (xx_high-xx_low)/2;
    ptSystXhigh_h[j]= (xx_high-xx_low)/2;
    // cout<<"pT"<<ptBins_h[j]<<"\t raa= "<<raa_h[j]<<"\t syst= "<<raaStat_h[j]<<"\t stat ="<<raaSyst_h[j]<<"\t x_low= "<<ptSystXlow_h[j]<<"\t high= "<<ptSystXhigh_h[j]<<endl;
    j++;
  }     
  inData_h.close();
  // done reading numebrs
  
  TGraphErrors *pgRaa_h          = new TGraphErrors(27, ptBins_h, raa_h, ptError_h, raaStat_h);
  TGraphAsymmErrors *pgRaaSyst_h = new TGraphAsymmErrors(27, ptBins_h, raa_h, ptSystXlow_h,ptSystXhigh_h,raaSyst_h,raaSyst_h);
  pgRaa_h->SetName("pgRaa_h");
  pgRaa_h->SetMarkerStyle(kFullCircle);
  pgRaa_h->SetMarkerSize(1.);
  
  //systm error
  pgRaaSyst_h->SetName("pgRaaSyst_h");
  pgRaaSyst_h->SetFillColor(TColor::GetColor("#33ccff"));

  //----------------------------------------- jet RAA
  double ptBins_jet[]   = {105,115,125,135,145,155,165,175,190,220,270}; 
  double ptError_jet[]  = {0.0, 0.0, 0.0, 0.0, 0.0,0,0,0,0,0,0};
  
  double raa_jet[]      = {0.47,   0.47,   0.46,  0.44,   0.43,  0.47,  0.52,  0.51,  0.44,  0.42,  0.58}; 
  double raaStat_jet[]  = {0.0076, 0.0098, 0.013, 0.016,  0.021, 0.028, 0.038, 0.045, 0.035, 0.039, 0.098};
  double raaSyst_jet[]  = {0.07, 0.07, 0.08, 0.09, 0.08, 0.08, 0.08, 0.08, 0.07, 0.07, 0.10 };

  double ptSystXlow_jet[]      = {5, 5, 5, 5, 5,5,5,5,10,20,30};
  double ptSystXhigh_jet[]     = {5, 5, 5, 5, 5,5,5,5,10,20,30};
  
  TGraphErrors *pgRaa_jet          = new TGraphErrors(11, ptBins_jet, raa_jet, ptError_jet, raaStat_jet);
  TGraphAsymmErrors *pgRaaSyst_jet = new TGraphAsymmErrors(11, ptBins_jet, raa_jet, ptSystXlow_jet,ptSystXhigh_jet,raaSyst_jet,raaSyst_jet);
  pgRaa_jet->SetName("pgRaa_jet");
  pgRaa_jet->SetMarkerStyle(22);
  pgRaa_jet->SetMarkerSize(1.);
  
  //systm error
  pgRaaSyst_jet->SetName("pgRaaSyst_jet");
  pgRaaSyst_jet->SetFillColor(TColor::GetColor("#00FF60"));

  //----------------------------------------- b-jet RAA
  double ptBins_bjet[5]   = {85,100,120,150,210}; 
  double ptError_bjet[5]  = {0,0,0,0,0};
  
  double raa_bjet[5]      = {0.3927,0.3277,0.4598,0.4034,0.4214}; 
  double raaStat_bjet[5]  = {0.0179,0.0178,0.0374,0.0625,0.1589};
  double raaSyst_bjet[5]  = {0.0917,0.0923,0.1272,0.1529,0.2771};

  double ptSystXlow_bjet[5]      = {5,10,10,20,40};
  double ptSystXhigh_bjet[5]     = {5,10,10,20,40};
  
  TGraphErrors *pgRaa_bjet          = new TGraphErrors(5, ptBins_bjet, raa_bjet, ptError_bjet, raaStat_bjet);
  TGraphAsymmErrors *pgRaaSyst_bjet = new TGraphAsymmErrors(5, ptBins_bjet, raa_bjet, ptSystXlow_bjet,ptSystXhigh_bjet,raaSyst_bjet,raaSyst_bjet);
  pgRaa_bjet->SetName("pgRaa_bjet");
  pgRaa_bjet->SetMarkerStyle(21);
  pgRaa_bjet->SetMarkerColor(kRed);
  pgRaa_bjet->SetMarkerSize(1.);
  
  //systm error
  pgRaaSyst_bjet->SetName("pgRaaSyst_bjet");
  pgRaaSyst_bjet->SetFillColor(TColor::GetColor("#FFBF00"));


  //----------------------------------------- photon
  double ptBins_photon[]   = {22.26, 27.30, 34.35, 44.45, 61.72}; 
  double ptError_photon[]  = {0.0, 0.0, 0.0, 0.0, 0.0};
  
  double raa_photon[]      = {1.03, 0.84, 1.37, 0.98, 0.99}; 
  double raaStat_photon[]  = {0.12 ,0.14, 0.22, 0.24, 0.31 };
  double raaSyst_photon[]  = {0.29, 0.27,  0.25, 0.22, 0.21};

  double ptSystXlow_photon[]      = {2.5, 2.5, 5, 5, 15};
  double ptSystXhigh_photon[]     = {2.5, 2.5, 5, 5, 15};
  
  TGraphErrors *pgRaa_photon          = new TGraphErrors(5, ptBins_photon, raa_photon, ptError_photon, raaStat_photon);
  TGraphAsymmErrors *pgRaaSyst_photon = new TGraphAsymmErrors(5, ptBins_photon, raa_photon, ptSystXlow_photon,ptSystXhigh_photon,raaSyst_photon,raaSyst_photon);
  pgRaa_photon->SetName("pgRaa_photon");
  pgRaa_photon->SetMarkerStyle(23);
  pgRaa_photon->SetMarkerSize(1.);
  //systm error
  pgRaaSyst_photon->SetName("pgRaaSyst_photon");
  pgRaaSyst_photon->SetFillColor(TColor::GetColor("#ffff00"));
  
  //----------------------------------------- Z 
  double ptBins_z[]   = {91.19};
  //double ptBins_z[7]   = {2.5,7.5,15,25,35,45,75};
  double ptError_z[]  = {0.0};
  //double ptError_z[7]  = {0.0};
  
  double raa_z[]      = {1.06}; 
  double raaStat_z[]  = {0.05};
  double raaSyst_z[]  = {0.08};
  double ptSystXlow_z[]      = {4};
  double ptSystXhigh_z[]     = {4};
  //double raa_z[7]        = {0.88,1.20,1.00,1.35,1.11,1.35,0.78}; 
  //double raaStat_z[7]    = {0.09,0.13,0.11,0.22,0.27,0.42,0.20};
  //double raaSyst_z[7]    = {0.06,0.08,0.07,0.09,0.08,0.09,0.05};
  //double ptSystXlow_z[7] = {2.5,2.5,5,5,5,5,25};
  //double ptSystXhigh_z[7] = {2.5,2.5,5,5,5,5,25};

  TGraphErrors *pgRaa_z          = new TGraphErrors(1, ptBins_z, raa_z, ptError_z, raaStat_z);
  TGraphAsymmErrors *pgRaaSyst_z = new TGraphAsymmErrors(1, ptBins_z, raa_z, ptSystXlow_z,ptSystXhigh_z,raaSyst_z,raaSyst_z);
  pgRaa_z->SetName("pgRaa_z");   pgRaa_z->SetMarkerStyle(kFullCircle);
  pgRaa_z->SetMarkerSize(1.);
  pgRaa_z->SetMarkerStyle(22);  

  //systm error
  pgRaaSyst_z->SetName("pgRaaSyst_z");
  pgRaaSyst_z->SetFillColor(TColor::GetColor("#ff8888"));


  // ----------------------------------------- W raa
  double ptBins_w[]   = {80.38}; 
  double ptError_w[]  = {0.0};
  
  double raa_w[]      = {1.04}; 
  double raaStat_w[]  = {0.07};
  double raaSyst_w[]  = {0.12};
  double ptSystXlow_w[]      = {4};
  double ptSystXhigh_w[]     = {4};

  TGraphErrors *pgRaa_w          = new TGraphErrors(1, ptBins_w, raa_w, ptError_w, raaStat_w);
  TGraphAsymmErrors *pgRaaSyst_w = new TGraphAsymmErrors(1, ptBins_w, raa_w, ptSystXlow_w,ptSystXhigh_w,raaSyst_w,raaSyst_w);
  pgRaa_w->SetName("pgRaa_w");
  pgRaa_w->SetMarkerStyle(kFullCircle);
  pgRaa_w->SetMarkerSize(1.);
  pgRaa_w->SetMarkerStyle(21);
  
  //systm error
  pgRaaSyst_w->SetName("pgRaaSyst_w");
  pgRaaSyst_w->SetFillColor(TColor::GetColor("#ff88ff"));


  // ----------------------------------------- 2012 non-prompt Jpsi
  double ptBins_npjpsi[]   = {7.31,8.97,11.32,16.52}; 
  double ptError_npjpsi[]  = {0.0,0.0,0.0,0.0};
  
  double raa_npjpsi[]      = {0.52,0.43,0.43,0.34};  
  double raaStat_npjpsi[]  = {0.12,0.08,0.09,0.07};
  double raaSyst_npjpsi[]  = {0.06,0.05,0.05,0.04};

  double ptSystXlow_npjpsi[]      = {0.81, 0.97, 1.32, 3.52};
  double ptSystXhigh_npjpsi[]     = {0.69, 1.03, 1.68, 13.48};

  TGraphErrors *pgRaa_npjpsi          = new TGraphErrors(4, ptBins_npjpsi, raa_npjpsi, ptError_npjpsi, raaStat_npjpsi);
  TGraphAsymmErrors *pgRaaSyst_npjpsi = new TGraphAsymmErrors(4, ptBins_npjpsi, raa_npjpsi, ptSystXlow_npjpsi,ptSystXhigh_npjpsi,raaSyst_npjpsi,raaSyst_npjpsi);
  pgRaa_npjpsi->SetName("pgRaa_npjpsi");
  pgRaa_npjpsi->SetMarkerStyle(29);
  pgRaa_npjpsi->SetMarkerSize(1.2);
  pgRaa_npjpsi->SetMarkerColor(kRed);
  
  //systm error
  pgRaaSyst_npjpsi->SetName("pgRaaSyst_npjpsi");
  // pgRaaSyst_npjpsi->SetFillColor(TColor::GetColor("#ee7711"));
  pgRaaSyst_npjpsi->SetFillColor(TColor::GetColor("#ba8a98"));
  
  
  //---------------------------------------------------------
  // lumi uncert.
  TBox *box = new TBox(0.9,0.9568966,2,1.043103);
  box->SetFillColor(kGray+1);
  box->SetFillStyle(1001);
  

  TBox *box_lin = new TBox(0.9,0.9568966,10,1.043103);
  box_lin->SetFillColor(kGray+1);
  box_lin->SetFillStyle(1001);
  
  //------------------------ single pannel:
  
  TCanvas *pc = new TCanvas("pc","pc");
  TH1 *phAxis = new TH1D("phAxis",";p_{T} (m_{T}) [GeV];R_{AA}",1,0.9,300);
  phAxis->GetYaxis()->CenterTitle(true);
  phAxis->SetMinimum(0.);
  phAxis->SetMaximum(2.5);
  gPad->SetLogx();
  phAxis->Draw("");
  
  // drawing order:
  // A)  stat boxes:
  pgRaaSyst_photon->Draw("2");
  pgRaaSyst_npjpsi->Draw("2");
  pgRaaSyst_h->Draw("2");
  pgRaaSyst_z->Draw("2");
  pgRaaSyst_w->Draw("2");
  pgRaaSyst_bjet->Draw("2");
  pgRaaSyst_jet->Draw("2");
  //nominal+stat
  // photon
  pgRaa_photon->Draw("P z");
  pgRaa_z->Draw("P z");
  pgRaa_w->Draw("P z");
  pgRaa_h->Draw("P z");
  pgRaa_npjpsi->Draw("P z");
  pgRaa_bjet->Draw("P z");
  pgRaa_jet->Draw("P z");

  TLine *line = new TLine(0.9,1,300,1);
  line->SetLineStyle(7);
  line->Draw();
  //box->Draw();
  // // legends and writings:

  TLegend *leg = new TLegend(0.05,0.87,0.39,0.95,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextFont(62);
  leg->SetTextSize(0.029);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(19);
  leg->SetFillStyle(0);
  //  TLegendEntry *entry=leg->AddEntry("hEtSIEIECorrected","CMS PRELIMINARY","");
  //    entry->SetLineWidth(1);
  //    entry=leg->AddEntry("hEtSIEIECorrected","PbPb #sqrt{s_{NN}} = 2.76 TeV","");
  //    entry=leg->AddEntry("hEtSIEIECorrected","","");
  //    entry=leg->AddEntry("hEtSIEIECorrected","#int L dt = 7-150 #mub^{-1}","");

  TLegendEntry *entry=leg->AddEntry("hEtSIEIECorrected","CMS  *PRELIMINARY  PbPb #sqrt{s_{NN}} = 2.76 TeV  #int L dt = 7-150 #mub^{-1}","");
  entry->SetLineWidth(1);
  
  

  // TAA
  // TAA only
  TLegend *leg_taa = new TLegend(0.15,0.5,0.5,0.55,NULL,"brNDC");
  leg_taa->SetBorderSize(0);
  leg_taa->SetTextFont(62);
  leg_taa->SetTextSize(0.028);
  leg_taa->SetLineColor(1);
  leg_taa->SetLineStyle(1);
  leg_taa->SetLineWidth(1);
  leg_taa->SetFillColor(19);
  leg_taa->SetFillStyle(0);
  TLegendEntry *entry_taa= leg_taa->AddEntry("general","T_{AA} uncertainty","f");
  entry_taa->SetFillColor(kGray+1);
  entry_taa->SetFillStyle(1001);
  entry_taa->SetLineColor(0);
  entry_taa->SetLineWidth(1);
  entry_taa->SetMarkerStyle(21);
  entry_taa->SetMarkerSize(1);

  // EWQ legend
  TLegend *leg_ewq = new TLegend(0.14,0.79,0.6,0.89,NULL,"brNDC");
  leg_ewq->SetBorderSize(0);
  leg_ewq->SetTextFont(62);
  leg_ewq->SetTextSize(0.028);
  leg_ewq->SetLineColor(1);
  leg_ewq->SetLineStyle(1);
  leg_ewq->SetLineWidth(1);
  leg_ewq->SetFillColor(19);
  leg_ewq->SetFillStyle(0);
  TLegendEntry *entry_ewq=leg_ewq->AddEntry("raaz","*Z  (0-100%) |y| < 2","lpf");
  entry_ewq->SetFillColor(TColor::GetColor("#ff8888"));
  entry_ewq->SetFillStyle(1001);
  entry_ewq->SetLineColor(1);
  entry_ewq->SetLineWidth(1);
  entry_ewq->SetMarkerStyle(22);
  entry_ewq->SetMarkerSize(1.);
  
  entry_ewq=leg_ewq->AddEntry("raaw","W  (0-100%) p_{T}^{#mu} > 25 GeV/c^{^{ }}, |#eta^{#mu}| < 2.1","lpf");
  entry_ewq->SetFillColor(TColor::GetColor("#ff88ff"));
  entry_ewq->SetFillStyle(1001);
  entry_ewq->SetLineColor(1);
  entry_ewq->SetLineWidth(1);
  entry_ewq->SetMarkerStyle(21);
  entry_ewq->SetMarkerSize(1.);
  
  entry_ewq=leg_ewq->AddEntry("raaphoton","Isolated photon  (0-10%)  |#eta| < 1.44","lpf");
  entry_ewq->SetFillColor(TColor::GetColor("#ffff00"));
  entry_ewq->SetFillStyle(1001);
  entry_ewq->SetLineColor(1);
  entry_ewq->SetLineWidth(1);
  entry_ewq->SetMarkerStyle(23);
  entry_ewq->SetMarkerSize(1);
  

  // b and h
  TLegend *leg_q = new TLegend(0.14,0.72,0.6,0.79,NULL,"brNDC");
  leg_q->SetBorderSize(0);
  leg_q->SetTextFont(62);
  leg_q->SetTextSize(0.028);
  leg_q->SetLineColor(1);
  leg_q->SetLineStyle(1);
  leg_q->SetLineWidth(1);
  leg_q->SetFillColor(19);
  leg_q->SetFillStyle(0);


  TLegendEntry *entry_q=leg_q->AddEntry("raah","Charged particles  (0-5%)  |#eta| < 1","lpf");
  entry_q->SetFillColor(TColor::GetColor("#33ccff"));
  entry_q->SetFillStyle(1001);
  entry_q->SetLineColor(1);
  entry_q->SetLineStyle(1);
  entry_q->SetLineWidth(1);
  entry_q->SetMarkerStyle(kFullCircle);
  entry_q->SetMarkerSize(1);

  entry_q=leg_q->AddEntry("raab","*B #rightarrow J/#psi  (0-100%)  |#eta| < 2.4","lpf");
  entry_q->SetFillColor(TColor::GetColor("#ba8a98"));
  entry_q->SetFillStyle(1001);
  entry_q->SetLineColor(1);
  entry_q->SetLineStyle(1);
  entry_q->SetLineWidth(1);
  entry_q->SetMarkerStyle(29);
  entry_q->SetMarkerColor(kRed);
  entry_q->SetMarkerSize(1.2);
  //entry_q=leg_q->AddEntry("raabjpsi", "(via secondary J/#psi)","");
  
  // jet legend
  TLegend *leg_jet = new TLegend(0.14,0.65,0.6,0.72,NULL,"brNDC");
  leg_jet->SetBorderSize(0);
  leg_jet->SetTextFont(62);
  leg_jet->SetTextSize(0.028);
  leg_jet->SetLineColor(1);
  leg_jet->SetLineStyle(1);
  leg_jet->SetLineWidth(1);
  leg_jet->SetFillColor(19);
  leg_jet->SetFillStyle(0);

  TLegendEntry *entry_jet=leg_jet->AddEntry("raaq","*q/g-jet  (0-5%)  |#eta| < 2","lpf");
  entry_jet->SetFillColor(TColor::GetColor("#00FF60"));
  entry_jet->SetFillStyle(1001);
  entry_jet->SetLineColor(1);
  entry_jet->SetLineStyle(1);
  entry_jet->SetLineWidth(1);
  entry_jet->SetMarkerStyle(22);
  entry_jet->SetMarkerSize(1);

  entry_jet=leg_jet->AddEntry("raaheavy","*b-jet  (0-10%)  |#eta| < 2","lpf");
  entry_jet->SetFillColor(TColor::GetColor("#FFBF00"));
  entry_jet->SetFillStyle(1001);
  entry_jet->SetLineColor(1);
  entry_jet->SetLineStyle(1);
  entry_jet->SetLineWidth(1);
  entry_jet->SetMarkerStyle(21);
  entry_jet->SetMarkerColor(kRed);
  entry_jet->SetMarkerSize(1);
  
  leg->Draw();
  //leg_taa->Draw();
  leg_ewq->Draw();
  leg_q->Draw();
  leg_jet->Draw();
  gPad->RedrawAxis();
  
  // save the work
  // pc->SaveAs("raaZoo_cms_log.pdf");
  // pc->SaveAs("raaZoo_cms_log.png");




  //--------------------------------------------------------------------------------
  //-------------------------- 2TPad
  //double sizeincrease = 1.2;
  
  TH1 *phAxis_single = new TH1D("phAxis_single",";p_{T} (m_{T}) [GeV];R_{AA}",1,0,105);
  phAxis_single->GetYaxis()->CenterTitle(true);
  //phAxis_single->GetXaxis()->CenterTitle(true);

  //double defaxissize = phAxis_single->GetYaxis()->GetTitleSize();
  //double defaxislabel = phAxis_single->GetYaxis()->GetLabelSize();

  //phAxis_single->GetYaxis()->SetTitleSize(defaxissize*sizeincrease);
  //phAxis_single->GetXaxis()->SetTitleSize(defaxissize*sizeincrease);
  //phAxis_single->GetYaxis()->SetLabelSize(defaxislabel*sizeincrease);
  //phAxis_single->GetXaxis()->SetLabelSize(defaxislabel*sizeincrease);
  
  //phAxis_single->GetYaxis()->SetNdivisions(310);
  //phAxis_single->GetXaxis()->SetNdivisions(310);
  //phAxis_single->GetYaxis()->SetTitleOffset(0.85);
  //phAxis_single->GetXaxis()->SetTitleOffset(0.85);
  
  phAxis_single->SetMinimum(0.);
  phAxis_single->SetMaximum(2.5);
  TH1 *phAxis_jet = new TH1D("phAxis_jet",";p_{T} [GeV];",1,75,300);
  //phAxis_jet->GetYaxis()->CenterTitle(true);
  //phAxis_jet->GetXaxis()->CenterTitle(true);
  //phAxis_jet->GetYaxis()->SetTitleSize(defaxissize*sizeincrease);
  //phAxis_jet->GetXaxis()->SetTitleSize(defaxissize*sizeincrease);
  //phAxis_jet->GetYaxis()->SetLabelSize(defaxislabel*sizeincrease);
  phAxis_jet->GetYaxis()->SetLabelColor(0);
  //phAxis_jet->GetXaxis()->SetLabelSize(defaxislabel*sizeincrease);
  //phAxis_jet->GetYaxis()->SetNdivisions(310);
  //phAxis_jet->GetXaxis()->SetNdivisions(310);
  //phAxis_jet->GetYaxis()->SetTitleOffset(0.85);
  //phAxis_jet->GetXaxis()->SetTitleOffset(0.85);
  
  phAxis_jet->SetMinimum(0.);
  phAxis_jet->SetMaximum(2.5);

  // redefine legends:
  // TAA only
  /*TLegend *leg2_taa = new TLegend(0.15,0.85,0.5,0.9,NULL,"brNDC");
  leg2_taa->SetBorderSize(0);
  leg2_taa->SetTextFont(62);
  leg2_taa->SetTextSize(0.028);
  leg2_taa->SetLineColor(1);
  leg2_taa->SetLineStyle(1);
  leg2_taa->SetLineWidth(1);
  leg2_taa->SetFillColor(19);
  leg2_taa->SetFillStyle(0);
  TLegendEntry *entry2_taa= leg2_taa->AddEntry("general","T_{AA} uncertainty (0-5%)","f");
  entry2_taa->SetFillColor(kGray+1);
  entry2_taa->SetFillStyle(1001);
  entry2_taa->SetLineColor(0);
  entry2_taa->SetLineWidth(1);
  entry2_taa->SetMarkerStyle(21);
  entry2_taa->SetMarkerSize(1);*/

  TLegend *leg2 = new TLegend(0.04,0.81,0.34,0.93,NULL,"brNDC");
  leg2->SetBorderSize(0);
  leg2->SetTextFont(62);
  leg2->SetTextSize(0.03);
  //leg2->SetLineColor(1);
  //leg2->SetLineStyle(1);
  //leg2->SetLineWidth(1);
  //leg2->SetFillColor(19);
  leg2->SetFillStyle(0);
  TLegendEntry *entry2=leg2->AddEntry("general","CMS  *PRELIMINARY  PbPb #sqrt{s_{NN}} = 2.76 TeV","");
  entry2=leg2->AddEntry("general","#int L dt = 7-150 #mub^{-1}","");
  
  // jet leg2end
  TLegend *leg2_jet = new TLegend(0.08,0.73,0.64,0.81,NULL,"brNDC");
  leg2_jet->SetBorderSize(0);
  leg2_jet->SetTextFont(62);
  leg2_jet->SetTextSize(0.028);
  leg2_jet->SetLineColor(1);
  leg2_jet->SetLineStyle(1);
  leg2_jet->SetLineWidth(1);
  leg2_jet->SetFillColor(19);
  leg2_jet->SetFillStyle(0);

  TLegendEntry *entry2_jet=leg2_jet->AddEntry("raaq","*q/g-jet  (0-5%)  |#eta| < 2","lpf");
  entry2_jet->SetFillColor(TColor::GetColor("#00FF60"));
  entry2_jet->SetFillStyle(1001);
  entry2_jet->SetLineColor(1);
  entry2_jet->SetLineStyle(1);
  entry2_jet->SetLineWidth(1);
  entry2_jet->SetMarkerStyle(22);
  entry2_jet->SetMarkerSize(mymarkersize);

  if(version > 5)
  {
    entry2_jet=leg2_jet->AddEntry("raaheavy","*b-jet  (0-10%)  |#eta| < 2","lpf");
    entry2_jet->SetFillColor(TColor::GetColor("#FFBF00"));
    entry2_jet->SetFillStyle(1001);
    entry2_jet->SetLineColor(1);
    entry2_jet->SetLineStyle(1);
    entry2_jet->SetLineWidth(1);
    entry2_jet->SetMarkerStyle(21);
    entry2_jet->SetMarkerColor(kRed);
    entry2_jet->SetMarkerSize(mymarkersize);
  }
  else  entry2_jet=leg2_jet->AddEntry("raaheavy","","");
  

  // EWQ legend
  TLegend *leg2_ewq = new TLegend(0.14,0.81,0.7,0.93,NULL,"brNDC");
  leg2_ewq->SetBorderSize(0);
  leg2_ewq->SetTextFont(62);
  leg2_ewq->SetTextSize(0.028);
  leg2_ewq->SetLineColor(1);
  leg2_ewq->SetLineStyle(1);
  leg2_ewq->SetLineWidth(1);
  leg2_ewq->SetFillColor(19);
  leg2_ewq->SetFillStyle(0);
  TLegendEntry *entry2_ewq;
  if(version > 1)
  {
    entry2_ewq=leg2_ewq->AddEntry("raaz","*Z  (0-100%) |y| < 2","lpf");
    entry2_ewq->SetFillColor(TColor::GetColor("#ff8888"));
    entry2_ewq->SetFillStyle(1001);
    entry2_ewq->SetLineColor(1);
    entry2_ewq->SetLineWidth(1);
    entry2_ewq->SetMarkerStyle(22);
    entry2_ewq->SetMarkerSize(mymarkersize);
  }
  else entry2_ewq=leg2_ewq->AddEntry("raaz","",""); 
  
  if(version > 2)
  {  
    entry2_ewq=leg2_ewq->AddEntry("raaw","W  (0-100%) p_{T}^{#mu} > 25 GeV/c^{^{ }}, |#eta^{#mu}| < 2.1","lpf");
    entry2_ewq->SetFillColor(TColor::GetColor("#ff88ff"));
    entry2_ewq->SetFillStyle(1001);
    entry2_ewq->SetLineColor(1);
    entry2_ewq->SetLineWidth(1);
    entry2_ewq->SetMarkerStyle(21);
    entry2_ewq->SetMarkerSize(mymarkersize);
  } 
  else  entry2_ewq=leg2_ewq->AddEntry("raaw","","");
  
  if(version > 0)
  {
    entry2_ewq=leg2_ewq->AddEntry("raaphoton","Isolated photon  (0-10%)  |#eta| < 1.44","lpf");
    entry2_ewq->SetFillColor(TColor::GetColor("#ffff00"));
    entry2_ewq->SetFillStyle(1001);
    entry2_ewq->SetLineColor(1);
    entry2_ewq->SetLineWidth(1);
    entry2_ewq->SetMarkerStyle(23);
    entry2_ewq->SetMarkerSize(mymarkersize);
  }
  else  entry2_ewq=leg2_ewq->AddEntry("raaphoton","","");
    
  // B and h
  TLegend *leg2_q = new TLegend(0.14,0.74,0.7,0.81,NULL,"brNDC");
  leg2_q->SetBorderSize(0);
  leg2_q->SetTextFont(62);
  leg2_q->SetTextSize(0.028);
  leg2_q->SetLineColor(1);
  leg2_q->SetLineStyle(1);
  leg2_q->SetLineWidth(1);
  leg2_q->SetFillColor(19);
  leg2_q->SetFillStyle(0);
  TLegendEntry *entry2_q;
  if(version > 3)
  {
    entry2_q=leg2_q->AddEntry("raah","Charged particles  (0-5%)  |#eta| < 1","lpf");
    entry2_q->SetFillColor(TColor::GetColor("#33ccff"));
    entry2_q->SetFillStyle(1001);
    entry2_q->SetLineColor(1);
    entry2_q->SetLineStyle(1);
    entry2_q->SetLineWidth(1);
    entry2_q->SetMarkerStyle(kFullCircle);
    entry2_q->SetMarkerSize(mymarkersize);
  }
  else  entry2_q=leg2_q->AddEntry("raah","","");
  
  if(version > 5)
  {
    entry2_q=leg2_q->AddEntry("raab","*B #rightarrow J/#psi  (0-100%)  |y| < 2.4","lpf");
    // entry2_q->SetFillColor(TColor::GetColor("#ee7711"));
    entry2_q->SetFillColor(TColor::GetColor("#ba8a98"));
    entry2_q->SetFillStyle(1001);
    entry2_q->SetLineColor(1);
    entry2_q->SetLineStyle(1);
    entry2_q->SetLineWidth(1);
    entry2_q->SetMarkerStyle(29);
    entry2_q->SetMarkerColor(kRed);
    entry2_q->SetMarkerSize(mymarkersize);
    //entry2_q=leg2_q->AddEntry("raabjpsi", "(via secondary J/#psi)","");
  }
  else
  {
    entry2_q=leg2_q->AddEntry("raab","","");
    entry2_q=leg2_q->AddEntry("raab","","");
  }
  
  if(bDo2PadZoo)
  {
    TCanvas *pc2 = new TCanvas("pc2","pc2",1200,600);
    TPad *p_0 = new TPad("p_0","p_0",0,0,0.50,1);
    p_0->Draw();
    p_0->cd();
    p_0->SetRightMargin(0.03);
    
    phAxis_single->Draw("");
    //box_lin->Draw();
    
    pgRaa_photon->SetMarkerSize(mymarkersize);
    pgRaa_z->SetMarkerSize(mymarkersize);
    pgRaa_h->SetMarkerSize(mymarkersize);
    pgRaa_w->SetMarkerSize(mymarkersize);
    pgRaa_npjpsi->SetMarkerSize(mymarkersize);
    pgRaa_bjet->SetMarkerSize(mymarkersize);
    pgRaa_jet->SetMarkerSize(mymarkersize);
    
    if(version > 0) pgRaaSyst_photon->Draw("2");
    if(version > 1) pgRaaSyst_z->Draw("2");
    if(version > 3) pgRaaSyst_h->Draw("2");
    if(version > 2) pgRaaSyst_w->Draw("2");
    if(version > 5) pgRaaSyst_npjpsi->Draw("2");
    
    if(version > 0) pgRaa_photon->Draw("P z");
    if(version > 1) pgRaa_z->Draw("P z");
    if(version > 3) pgRaa_h->Draw("P z");
    if(version > 2) pgRaa_w->Draw("P z");
    if(version > 5) pgRaa_npjpsi->Draw("P z");
    
    TLine *line_single = new TLine(0,1,105,1);
    line_single->SetLineStyle(7);
    line_single->Draw();
    
    // legends 
    //leg2_taa->Draw();
    leg2_q->Draw();
    leg2_ewq->Draw();
    TLine * midborder = new TLine(99.9,0,99.9,2);
    midborder->SetLineStyle(1);
    
    //if(version < 5) midborder->Draw();
    
    pc2->cd();
    // midborder->Draw();
    if(version > 4)
    {
      // jet pad
      TPad *p_1 = new TPad("p_1","p_1",0.50,0,1,1);
      p_1->Draw();
      p_1->cd();
      p_1->SetLeftMargin(0.06);
      p_1->SetTickx(1);
      p_1->SetTicky(1);
      
      if(version > 4) phAxis_jet->Draw("");
      
      if(version > 5) pgRaaSyst_bjet->Draw("2");
      if(version > 4) pgRaaSyst_jet->Draw("2");
      
      if(version > 5) pgRaa_bjet->Draw("P z");
      if(version > 4) pgRaa_jet->Draw("P z");
      
      
      TLine *line_jet = new TLine(75,1,300,1);
      line_jet->SetLineStyle(7);
      line_jet->Draw();
      
      leg2->Draw();
      leg2_jet->Draw();
    }
    
    p_0->cd();
    gPad->RedrawAxis();
    
    //! adds the latex "100" joining the two pads
    //pc2->cd();
    //TPad * blankpad = new TPad("b", "b",0.48,0.07,0.52,0.11);
    //blankpad->SetBorderMode(0);
    //blankpad->Draw();
    //blankpad->cd();
    //TLatex * test = new TLatex( 0.102843, 0.122822, Form("100"));
    //test->SetTextSize(test->GetTextSize()*26.0*sizeincrease);
    //test->Draw("same");
    //blankpad->Update();
    
    // pc2->SaveAs(Form("raaZoo_cms_2pads_%d.pdf",version));
    //pc2->SaveAs(Form("raaZoo_cms_2pads_%d.png",version));

  }
}
void makePlot(const std::string& inputFilePath, const std::string& canvasName, const std::string& sample, int massPoint, const std::string& channel, double k, 
	      const std::string& inputFileName, const std::string& outputFilePath, const std::string& outputFileName)
{
  std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileName.data());
  TFile* inputFile = new TFile(inputFileName_full.data());
  if ( !inputFile ) {
    std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl;
    assert(0);
  }

  inputFile->ls();

  TCanvas* canvas = dynamic_cast<TCanvas*>(inputFile->Get(canvasName.data()));
  if ( !canvas ) {
    std::cerr << "Failed to load canvas = " << canvasName << " !!" << std::endl;
    assert(0);
  }

  int idxPad = -1;
  if ( massPoint ==  90 ) idxPad = 1;
  if ( massPoint == 125 ) idxPad = 2;
  if ( massPoint == 200 ) idxPad = 3;
  if ( massPoint == 300 ) idxPad = 4;
  if ( massPoint == 500 ) idxPad = 5;
  if ( massPoint == 800 ) idxPad = 6;  
  if ( !(idxPad >= 1 && idxPad <= 6) ) {
    std::cerr << "Invalid sample = " << sample << " !!" << std::endl;
    assert(0);
  }
  TVirtualPad* pad = canvas->GetPad(idxPad);
  std::cout << "pad = " << pad << ": ClassName = " << pad->ClassName() << std::endl;

  TCanvas* canvas_new = new TCanvas("canvas_new", "canvas_new", 900, 800);
  canvas_new->SetFillColor(10);
  canvas_new->SetBorderSize(2);
  canvas_new->SetTopMargin(0.065);
  canvas_new->SetLeftMargin(0.17);
  canvas_new->SetBottomMargin(0.165);
  canvas_new->SetRightMargin(0.015);
  canvas_new->SetLogx(true);
  canvas_new->SetLogy(true);
  canvas_new->Draw();
  canvas_new->cd();

  //TList* pad_primitives = canvas->GetListOfPrimitives();
  TList* pad_primitives = pad->GetListOfPrimitives();

  TH1* histogramCA            = 0;
  TH1* histogramSVfit         = 0;
  TH1* histogramSVfitMEMkEq0  = 0;
  TH1* histogramSVfitMEMkNeq0 = 0;

  TIter pad_nextObj(pad_primitives);
  while ( TObject* obj = pad_nextObj() ) {
    std::string objName = "";
    if ( dynamic_cast<TNamed*>(obj) ) objName = (dynamic_cast<TNamed*>(obj))->GetName();    
    std::cout << "obj = " << obj << ": name = " << objName << ", type = " << obj->ClassName() << std::endl;

    TH1* tmpHistogram = dynamic_cast<TH1*>(obj);
    if ( tmpHistogram ) {
      std::cout << "tmpHistogram:" 
		<< " fillColor = " << tmpHistogram->GetFillColor() << ", fillStyle = " << tmpHistogram->GetFillStyle() << ","
		<< " lineColor = " << tmpHistogram->GetLineColor() << ", lineStyle = " << tmpHistogram->GetLineStyle() << ", lineWidth = " << tmpHistogram->GetLineWidth() << ","
		<< " markerColor = " << tmpHistogram->GetMarkerColor() << ", markerStyle = " << tmpHistogram->GetMarkerStyle() << ", markerSize = " << tmpHistogram->GetMarkerSize() << ","
		<< " integral = " << tmpHistogram->Integral() << std::endl;
      std::cout << "(mean = " << tmpHistogram->GetMean() << ", rms = " << tmpHistogram->GetRMS() << ": rms/mean = " << (tmpHistogram->GetRMS()/tmpHistogram->GetMean()) << ")" << std::endl;
      if ( tmpHistogram->GetLineColor() == 416 ) histogramCA            = tmpHistogram;
      if ( tmpHistogram->GetLineColor() == 600 ) histogramSVfit         = tmpHistogram;
      if ( tmpHistogram->GetLineColor() == 616 ) histogramSVfitMEMkEq0  = tmpHistogram;
      if ( tmpHistogram->GetLineColor() == 632 ) histogramSVfitMEMkNeq0 = tmpHistogram;
    }
  }

  if ( !(histogramCA && histogramSVfit && histogramSVfitMEMkEq0 && histogramSVfitMEMkNeq0) ) {
    std::cerr << "Failed to load histograms !!" << std::endl;
    assert(0);
  }

  //gStyle->SetLineStyleString(2,"40 10 10 10 10 10 10 10");
  //gStyle->SetLineStyleString(3,"25 15");
  //gStyle->SetLineStyleString(4,"60 25");

  //int colors[4] = { kBlack, kGreen - 6, kBlue - 7, kMagenta - 7  };
  int colors[4] = { 28, kGreen - 6, kBlue - 7, kBlack };
  //int lineStyles[4] = { 2, 3, 4, 1 };
  int lineStyles[4] = { 7, 1, 1, 1 };
  //int lineWidths[4] = { 3, 3, 4, 3 };
  int lineWidths[4] = { 3, 3, 1, 1 };
  int markerStyles[4] = { 20, 25, 21, 24 };
  int markerSizes[4] = { 2, 2, 2, 2 };

  histogramCA->SetFillColor(0);
  histogramCA->SetFillStyle(0);
  histogramCA->SetLineColor(colors[0]);
  histogramCA->SetLineStyle(lineStyles[0]);
  histogramCA->SetLineWidth(lineWidths[0]);
  histogramCA->SetMarkerColor(colors[0]);
  histogramCA->SetMarkerStyle(markerStyles[0]);
  histogramCA->SetMarkerSize(markerSizes[0]);

  histogramSVfit->SetFillColor(0);
  histogramSVfit->SetFillStyle(0);
  histogramSVfit->SetLineColor(colors[1]);
  histogramSVfit->SetLineStyle(lineStyles[1]);
  histogramSVfit->SetLineWidth(lineWidths[1]);
  histogramSVfit->SetMarkerColor(colors[1]);
  histogramSVfit->SetMarkerStyle(markerStyles[1]);
  histogramSVfit->SetMarkerSize(markerSizes[1]);

  histogramSVfitMEMkEq0->SetFillColor(0);
  histogramSVfitMEMkEq0->SetFillStyle(0);
  histogramSVfitMEMkEq0->SetLineColor(colors[2]);
  histogramSVfitMEMkEq0->SetLineStyle(lineStyles[2]);
  histogramSVfitMEMkEq0->SetLineWidth(lineWidths[2]);
  histogramSVfitMEMkEq0->SetMarkerColor(colors[2]);
  histogramSVfitMEMkEq0->SetMarkerStyle(markerStyles[2]);
  histogramSVfitMEMkEq0->SetMarkerSize(markerSizes[2]);
  // CV: fix pathological bins at high mass for which dN/dm increases
  int numBins = histogramSVfitMEMkEq0->GetNbinsX();
  for ( int idxBin = 1; idxBin <= numBins; ++idxBin ) {
    double binCenter = histogramSVfitMEMkEq0->GetBinCenter(idxBin);
    if ( (channel == "#tau_{h}#tau_{h}" && massPoint == 500 && binCenter > 1500.) ||
	 (channel == "#tau_{h}#tau_{h}" && massPoint == 800 && binCenter > 2000.) ||
	 (channel == "#mu#tau_{h}"      && massPoint == 500 && binCenter > 1500.) ||
	 (channel == "#mu#tau_{h}"      && massPoint == 800 && binCenter > 2500.) ) {
      histogramSVfitMEMkEq0->SetBinContent(idxBin, 0.);
    }
  }

  histogramSVfitMEMkNeq0->SetFillColor(0);
  histogramSVfitMEMkNeq0->SetFillStyle(0);
  histogramSVfitMEMkNeq0->SetLineColor(colors[3]);
  histogramSVfitMEMkNeq0->SetLineStyle(lineStyles[3]);
  histogramSVfitMEMkNeq0->SetLineWidth(lineWidths[3]);
  histogramSVfitMEMkNeq0->SetMarkerColor(colors[3]);
  histogramSVfitMEMkNeq0->SetMarkerStyle(markerStyles[3]);
  histogramSVfitMEMkNeq0->SetMarkerSize(markerSizes[3]);

  TAxis* xAxis = histogramCA->GetXaxis();
  xAxis->SetTitle("m_{#tau#tau} [GeV]");
  xAxis->SetTitleOffset(1.15);
  xAxis->SetTitleSize(0.070);
  xAxis->SetTitleFont(42);
  xAxis->SetLabelOffset(0.010);
  xAxis->SetLabelSize(0.055);
  xAxis->SetLabelFont(42);
  xAxis->SetTickLength(0.040);
  xAxis->SetNdivisions(510);

  //double xMin = 20.;
  //double xMax = xAxis->GetXmax();
  //xAxis->SetRangeUser(xMin, xMax);

  TAxis* yAxis = histogramCA->GetYaxis();
  yAxis->SetTitle("dN/dm_{#tau#tau} [1/GeV]");
  yAxis->SetTitleOffset(1.20);
  yAxis->SetTitleSize(0.070);
  yAxis->SetTitleFont(42);
  yAxis->SetLabelOffset(0.010);
  yAxis->SetLabelSize(0.055);
  yAxis->SetLabelFont(42);
  yAxis->SetTickLength(0.040);  
  yAxis->SetNdivisions(505);

  double massPoint_double = 0.;
  if ( massPoint == 90 ) massPoint_double = 91.2;
  else massPoint_double = massPoint;
  double dLog = (TMath::Log(5.*massPoint_double) - TMath::Log(50.))/25.; // xMin = 50, xMax = 5*massPoint, numBins = 25
  double binWidth = TMath::Exp(TMath::Log(massPoint_double) + 0.5*dLog) - TMath::Exp(TMath::Log(massPoint_double) - 0.5*dLog);
  double sf_binWidth = 1./binWidth;
  std::cout << "massPoint = " << massPoint << ": sf_binWidth = " << sf_binWidth << std::endl;

  histogramCA->SetTitle("");
  histogramCA->SetStats(false);
  histogramCA->SetMaximum(sf_binWidth*0.79);
  histogramCA->SetMinimum(sf_binWidth*1.1e-4);
  histogramCA->Draw("hist");
  histogramSVfit->Draw("histsame");
  //histogramSVfitMEMkEq0->Draw("histsame");
  histogramSVfitMEMkEq0->Draw("epsame");
  //histogramSVfitMEMkNeq0->Draw("histsame");
  histogramSVfitMEMkNeq0->Draw("epsame");
  histogramCA->Draw("axissame");

  //TPaveText* label_sample = new TPaveText(0.21, 0.86, 0.46, 0.94, "NDC");
  TPaveText* label_sample = new TPaveText(0.1700, 0.9475, 0.4600, 1.0375, "NDC");
  label_sample->SetFillStyle(0);
  label_sample->SetBorderSize(0);
  label_sample->AddText(sample.data());
  label_sample->SetTextFont(42);
  label_sample->SetTextSize(0.055);
  label_sample->SetTextColor(1);
  label_sample->SetTextAlign(13);
  label_sample->Draw();

  //TLegend* legend_new = new TLegend(0.225, 0.52, 0.41, 0.82, NULL, "brNDC");
  TLegend* legend_new = new TLegend(0.30, 0.30, 0.80, 0.80, NULL, "brNDC");
  legend_new->SetFillColor(10);
  legend_new->SetFillStyle(0);
  legend_new->SetBorderSize(0);
  legend_new->SetTextFont(42);
  legend_new->SetTextSize(0.055);
  legend_new->SetTextColor(1);
  legend_new->SetMargin(0.20);
  legend_new->AddEntry(histogramCA, "CA", "l");
  legend_new->AddEntry(histogramSVfit, "SVfit", "l");
  //legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "l");
  legend_new->AddEntry(histogramSVfitMEMkEq0, "SVfitMEM (k=0)", "p");
  //legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM(k=%1.0f)", k), "l");
  legend_new->AddEntry(histogramSVfitMEMkNeq0, Form("SVfitMEM (k=%1.0f)", k), "p");
  //legend_new->Draw();

  double label_channel_y0;
  if      ( channel == "e#mu"             ) label_channel_y0 = 0.9275;
  else if ( channel == "#mu#tau_{h}"      ) label_channel_y0 = 0.9400;
  else if ( channel == "#tau_{h}#tau_{h}" ) label_channel_y0 = 0.9350;
  else {
    std::cerr << "Invalid channel = " << channel << " !!" << std::endl;
    assert(0);
  }
  TPaveText* label_channel = new TPaveText(0.895, label_channel_y0, 0.975, label_channel_y0 + 0.055, "NDC");
  label_channel->SetFillStyle(0);
  label_channel->SetBorderSize(0);
  label_channel->AddText(channel.data());
  label_channel->SetTextFont(62);
  label_channel->SetTextSize(0.055);
  label_channel->SetTextColor(1);
  label_channel->SetTextAlign(31);
  label_channel->Draw();

  canvas_new->Update();

  std::string outputFileName_full = Form("%s%s", outputFilePath.data(), outputFileName.data());
  size_t idx = outputFileName_full.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName_full, 0, idx);
  canvas_new->Print(std::string(outputFileName_plot).append(".pdf").data());
  canvas_new->Print(std::string(outputFileName_plot).append(".root").data());

  std::string channel_string;
  if      ( channel == "e#mu"             ) channel_string = "emu";
  else if ( channel == "#mu#tau_{h}"      ) channel_string = "muhad";
  else if ( channel == "#tau_{h}#tau_{h}" ) channel_string = "hadhad";
  else {
    std::cerr << "Invalid channel = " << channel << " !!" << std::endl;
    assert(0);
  }
  std::string outputFileName_legend = Form("makeSVfitMEM_PerformancePlots_legend_%s.pdf", channel_string.data());
  makePlot_legend(legend_new, outputFilePath, outputFileName_legend);

  delete label_sample;
  delete legend_new;
  delete label_channel;
  delete canvas_new;

  delete inputFile;
}
Ejemplo n.º 16
0
void patBJetVertex_efficiencies()
{
	// define proper canvas style
	setNiceStyle();
	gStyle->SetOptStat(0);

	// open file
	TFile* file = new TFile("analyzePatBJetVertex.root");

	unsigned int j = 0;
	for(const char **algo = algos; *algo; algo++, j++) {
		TLegend *legend[3] = { 0, 0, 0 };

		// draw canvas with efficiencies
		TCanvas *canv;
		canv = new TCanvas(*algo, Form("%s efficiencies", algoNames[j]), 800, 300);
		canv->Divide(3, 1);

		TH1 *total = (TH1*)file->Get(Form("%s/flavours", directory));
		TH1 *effVsCutB = 0;
		unsigned int i = 0;
		for(const char **flavour = flavours; *flavour; flavour++, i++) {
			TH1 *h = (TH1*)file->Get(Form("%s/%s_%s", directory, *algo, *flavour));
			TH1 *discrShape = (TH1*)h->Clone(Form("%s_discrShape", h->GetName()));
			discrShape->Scale(1.0 / discrShape->Integral());
			discrShape->SetMaximum(discrShape->GetMaximum() * 5);
			TH1 *effVsCut = computeEffVsCut(h, total->GetBinContent(4 - i));
			TH1 *effVsBEff = 0;

			if (flavour == flavours)	// b-jets
				effVsCutB = effVsCut;
			else
				effVsBEff = computeEffVsBEff(effVsCut, effVsCutB);

			discrShape->SetTitle("discriminator shape");
			effVsCut->SetTitle("efficiency versus discriminator cut");
			if (effVsBEff)
				effVsBEff->SetTitle("mistag versus b efficiency");

			setHistStyle(discrShape);
			setHistStyle(effVsCut);
			setHistStyle(effVsBEff);

			canv->cd(1);
			gPad->SetLogy(1);
			gPad->SetGridy(1);
			discrShape->SetLineColor(i + 1);
			discrShape->SetMarkerColor(i + 1);
			discrShape->Draw(i > 0 ? "same" : "");
			if (!legend[0])
				legend[0] = new TLegend(0.5, 0.7, 0.78, 0.88);
			legend[0]->AddEntry(discrShape, *flavour);

			canv->cd(2);
			gPad->SetLogy(1);
			gPad->SetGridy(1);
			effVsCut->SetLineColor(i + 1);
			effVsCut->SetMarkerColor(i + 1);
			effVsCut->Draw(i > 0 ? "same" : "");
			if (!legend[1])
				legend[1] = new TLegend(0.3, 0.4, 0.58, 0.58);
			legend[1]->AddEntry(effVsCut, *flavour);

			if (!effVsBEff)
				continue;
			canv->cd(3);
			gPad->SetLogy(1);
			gPad->SetGridx(1);
			gPad->SetGridy(1);
			effVsBEff->SetLineColor(i + 1);
			effVsBEff->SetMarkerColor(i + 1);
			effVsBEff->Draw(i > 1 ? "same" : "");
			if (!legend[2])
				legend[2] = new TLegend(0.12, 0.7, 0.40, 0.88);
			legend[2]->AddEntry(effVsBEff, *flavour);
		}

		canv->cd(1);
		legend[0]->Draw();

		canv->cd(2);
		legend[1]->Draw();

		canv->cd(3);
		legend[2]->Draw();
	}
}
Ejemplo n.º 17
0
void LEPStyle::draw()
{
  if( _canv==0 )
    {
      setCanvas();
      setHist();
      _canv->Draw();
      if( _ymin==0 ) _ymin = 0.2;
      //  _ymax = _n*1.5; 
      if( _ymax==0 ) _ymax = _n+_upDy;
      _hist->SetMinimum( _ymin  );
      _hist->SetMaximum( _ymax );
      
      _hist->Draw();

      if( _cmsPrelim ) cmsPrelim( _intLumi );
    }

  //  size_t n_ = _entry.size();
  _n = _entry.size();
  
  if( _extraBand )
    {
      drawExtraBand();
    }
 
  if( _band )
    {
      Double_t xx_[5] = { _bxmin, _bxmax, _bxmax, _bxmin, _bxmin };
      float eps1_ = _eps1*(_ymax-_ymin);
      float eps2_ = _eps2*(_ymax-_ymin);
      Double_t yy_[5] = { _ymin+eps1_, _ymin+eps1_, _ymax-eps2_, _ymax-eps2_, _ymin+eps1_ };
      TPolyLine* pl_ = new TPolyLine( 5, xx_, yy_ );
      pl_->SetFillStyle(_bandFillStyle);
      pl_->SetFillColor(_bandFillColor);
      pl_->SetLineWidth(3);
      pl_->SetLineColor( kOrange );
      pl_->DrawClone("FSame");
      TLine* l_ = new TLine( _bx0, _ymin+eps1_, _bx0, _ymax-eps2_  );
      l_->SetLineWidth(4);
      l_->SetLineColor( kOrange );
      l_->DrawClone();


      if( _hasLegend )
	{

	  cout << "HELLO!!!!" << endl;
	  //      _y0 = 4.0;
	  if( _y0==0 ) _y0 = _n+2*_upDy/3.;
	  if( _dy==0 ) _dy = 0.06;
	  _x0 = _xmax - 0.05*(_xmax-_xmin);
	  
	  TLatex leg1_;
	  leg1_.SetTextSize(_scale*0.05);      
	  leg1_.SetTextAlign(31); 
	  leg1_.DrawLatex( _x0, _y0+_dy, _legend );
	  
	  
	  TLatex leg2_;
	  leg2_.SetTextSize(_scale*0.05);      
	  leg2_.SetTextAlign(23); 
	  leg2_.DrawLatex( _bx0, _y0-_dy, _theory );

	}

//       TLegend* legend=new TLegend(_x0,_y0, _x0+_dx, _y0+_dy );
//       legend->SetLineColor(0);
//       legend->SetFillColor(0);
      
//       //      legend->AddEntry(pl_,_legend,"lf");
//       legend->AddEntry(pl_,_legend,"");

//       legend->Draw("same");
      

    }

  for( size_t ii=0; ii<_entry.size(); ii++ )
    {
      if( _entry[ii]==("SPACE") ) continue;
      Float_t  xval_[1];
      Float_t  yval_[1];
      Float_t    ey_[1];
      Float_t estatup_[1];
      Float_t ecombup_[1];
      Float_t etotup_[1];
      Float_t estatlo_[1];
      Float_t ecomblo_[1];
      Float_t etotlo_[1];

      float yy_ = _n-(Float_t)ii;
      xval_[0] = _val[ii];
      yval_[0] = yy_;
      ey_[0] = 0;

      estatup_[0] = _statup[ii];
      ecombup_[0] = sqrt( pow( _statup[ii],2 ) + pow( _systup[ii],2 ) );
      etotup_[0] = ecombup_[0] + _lumi[ii];

      estatlo_[0] = _statlo[ii];
      ecomblo_[0] = sqrt( pow( _statlo[ii],2 ) + pow( _systlo[ii],2 ) );      
      etotlo_[0] = ecomblo_[0] + _lumi[ii];

      TGraphAsymmErrors* gtot_  = new TGraphAsymmErrors( 1, xval_, yval_, etotlo_, etotup_, ey_, ey_ );
      gtot_->SetLineColor( kGreen );
      TGraphAsymmErrors* gcomb_ = new TGraphAsymmErrors( 1, xval_, yval_, ecomblo_, ecombup_, ey_, ey_ );
      gcomb_->SetLineColor( kRed );
      TGraphAsymmErrors* gstat_ = new TGraphAsymmErrors( 1, xval_, yval_, estatlo_, estatup_, ey_, ey_ );
      gstat_->SetLineColor( kBlack );
      gstat_->SetLineWidth( 2 );
      gstat_->SetMarkerStyle( _marker[ii] );
      gstat_->SetMarkerSize( _size[ii] );
      gstat_->SetMarkerColor( _color[ii] );

      gcomb_->SetLineWidth( 2 );

      gtot_->SetLineWidth( 2 );

      if( _lumi[ii]>0 )
	gtot_->Draw();

      gcomb_->DrawClone();
      gstat_->DrawClone("P");



      if( !_writeText ) continue;

      //   align = 10*HorizontalAlign + VerticalAlign
      // For Horizontal alignment the following convention applies:
      //   1=left adjusted, 2=centered, 3=right adjusted
      // For Vertical alignment the following convention applies:
      //   1=bottom adjusted, 2=centered, 3=top adjusted
      float xtxt_ = _xmin + 0.05*(_xmax-_xmin);
      TLatex ltx1_;

      ltx1_.SetTextSize(_scale*_size1);      
      ltx1_.SetTextAlign(_align1);
      if( _specifyPlacement )
	ltx1_.DrawLatex( _xx1, yy_+_e1, _entry[ii] );
      else
	ltx1_.DrawLatex( xtxt_, yy_+E_+e_, _entry[ii] );

      TLatex ltx2_;

      char line_[512];

      TString str_;
      TString pmstr_(" #pm ");
      TString format_("%-4.");
      format_ += _ndigit[ii];
      format_ += "f";
      TString valstr_;
      TString statstr_;
      TString syststr_;
      TString lumistr_;

      sprintf( line_, format_.Data(), _val[ii] );
      // sprintf( line_,  "%-4.3f", _val[ii] );
      valstr_ = line_;

      if( fabs( _statup[ii]-_statlo[ii] )<0.01 )
	{
	  sprintf( line_, format_.Data(), _statlo[ii] );
	}
      else
	{
	  sprintf( line_, "#scale[0.7]{#splitline{+%-4.3f}{-%-4.3f}}_{ stat.}", _statup[ii], _statlo[ii] );
	}

      statstr_ = line_;
      str_ = valstr_ + pmstr_ + statstr_;
      str_ += "_{ ";
      str_ += _firstError;
      str_ += "}";

      if( _systup[ii]>0 )
	{
	  if( fabs( _systup[ii]-_systlo[ii] )<0.01 )
	    {
	      sprintf( line_, format_.Data(), _systlo[ii] );
	    }
	  else 
	    {
	      sprintf( line_, "#scale[0.7]{#splitline{+%-4.3f}{- %-4.3f}}_", _systup[ii], _systlo[ii] );
	    }
	  syststr_ = line_;
	  str_ += pmstr_;
	  str_ += syststr_;
	  str_ += "_{ ";
	  str_ += _secondError;
	  str_ += "}";
	}
  
      if( _lumi[ii]>0 )
	{
	  sprintf( line_, format_.Data(), _lumi[ii] );
	  lumistr_ = line_;
	  lumistr_ += "_{lumi.}";
	  str_ += pmstr_ + lumistr_;
	}

      //      TString str_(line_);
      
      str_ += _unit;
      cout << str_ << endl;
 
      ltx2_.SetTextSize(_scale*_size2);      
      ltx2_.SetTextAlign(_align2);
      if( _specifyPlacement )
	ltx2_.DrawLatex( _xx2, yy_+_e2, str_ );
      else
	ltx2_.DrawLatex( xtxt_+0.02*(_xmax-_xmin), yy_+E_-e_, str_ );
    }


  _hist->Draw("Same");

  _canv->RedrawAxis();
}
void showGraph(TGraph* graph, 
	       const std::string& xAxisTitle,
	       Float_t* genX, 
	       double yMin, double yMax, const std::string& yAxisTitle,
	       const std::string& outputFileName)
{
  TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2);

  canvas->SetTopMargin(0.10);
  canvas->SetLeftMargin(0.16);
  canvas->SetRightMargin(0.14);
  canvas->SetBottomMargin(0.12);

  int numPoints = graph->GetN();
  double xMin, xMax, yDummy;
  graph->GetPoint(0, xMin, yDummy);
  graph->GetPoint(numPoints - 1, xMax, yDummy);

  TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", numPoints/100, xMin, xMax);
  dummyHistogram->SetStats(false);
  dummyHistogram->SetMinimum(yMin);
  dummyHistogram->SetMaximum(yMax);

  TAxis* xAxis = dummyHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.data());
  xAxis->SetTitleOffset(1.15);

  TAxis* yAxis = dummyHistogram->GetYaxis();
  yAxis->SetTitle(yAxisTitle.data());
  yAxis->SetTitleOffset(1.15);

  dummyHistogram->Draw("axis");

  TGraph* genMarker = 0;
  if ( genX ) {
    genMarker = new TGraph(2);
    genMarker->SetPoint(0, xMin, *genX);
    genMarker->SetPoint(1, xMax, *genX);
    genMarker->SetLineColor(8);
    genMarker->SetLineWidth(1);
    genMarker->SetMarkerColor(8);
    genMarker->SetMarkerStyle(20);
    genMarker->SetMarkerSize(1);
    genMarker->Draw("L");
  }

  graph->SetLineColor(1);
  graph->SetLineWidth(2);
  graph->SetMarkerColor(1);
  graph->SetMarkerStyle(20);
  graph->SetMarkerSize(1);
  graph->Draw("L");

  canvas->Update();
  size_t idx = outputFileName.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName, 0, idx);
  if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
  canvas->Print(std::string(outputFileName_plot).append(".png").data());
  canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
  canvas->Print(std::string(outputFileName_plot).append(".root").data());

  delete dummyHistogram;
  delete genMarker;
  delete canvas;  
}
Ejemplo n.º 19
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"));
}
void showGraphs(double canvasSizeX, double canvasSizeY,
		TGraph* graph1, const std::string& legendEntry1,
		TGraph* graph2, const std::string& legendEntry2,
		TGraph* graph3, const std::string& legendEntry3,
		TGraph* graph4, const std::string& legendEntry4,
		TGraph* graph5, const std::string& legendEntry5,
		TGraph* graph6, const std::string& legendEntry6,
		int colors[], int markerStyles[], 
		double legendTextSize, double legendPosX, double legendPosY, double legendSizeX, double legendSizeY, 
		std::vector<std::string>& labelTextLines, double labelTextSize,
		double labelPosX, double labelPosY, double labelSizeX, double labelSizeY,
		double xMin, double xMax, const std::string& xAxisTitle, double xAxisOffset,
		double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset,
		const std::string& outputFileName)
{
  TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2);
  
  canvas->SetLeftMargin(0.14);
  canvas->SetBottomMargin(0.12);

  TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", 100, xMin, xMax);
  dummyHistogram->SetTitle("");
  dummyHistogram->SetStats(false);
  dummyHistogram->SetMinimum(yMin);
  dummyHistogram->SetMaximum(yMax);

  TAxis* xAxis = dummyHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.data());
  xAxis->SetTitleSize(0.045);
  xAxis->SetTitleOffset(xAxisOffset);

  TAxis* yAxis = dummyHistogram->GetYaxis();
  yAxis->SetTitle(yAxisTitle.data());
  yAxis->SetTitleSize(0.045);
  yAxis->SetTitleOffset(yAxisOffset);

  dummyHistogram->Draw("axis");

  graph1->SetLineColor(colors[0]);
  graph1->SetLineWidth(2);
  graph1->SetMarkerColor(colors[0]);
  graph1->SetMarkerStyle(markerStyles[0]);
  graph1->SetMarkerSize(2);
  graph1->Draw("p");

  if ( graph2 ) {
    graph2->SetLineColor(colors[1]);
    graph2->SetLineWidth(2);
    graph2->SetMarkerColor(colors[1]);
    graph2->SetMarkerStyle(markerStyles[1]);
    graph2->SetMarkerSize(2);
    graph2->Draw("p");
  }
  
  if ( graph3 ) {
    graph3->SetLineColor(colors[2]);
    graph3->SetLineWidth(2);
    graph3->SetMarkerColor(colors[2]);
    graph3->SetMarkerStyle(markerStyles[2]);
    graph3->SetMarkerSize(2);
    graph3->Draw("p");
  }

  if ( graph4 ) {
    graph4->SetLineColor(colors[3]);
    graph4->SetLineWidth(2);
    graph4->SetMarkerColor(colors[3]);
    graph4->SetMarkerStyle(markerStyles[3]);
    graph4->SetMarkerSize(2);
    graph4->Draw("p");
  }

  if ( graph5 ) {
    graph5->SetLineColor(colors[4]);
    graph5->SetLineWidth(2);
    graph5->SetMarkerColor(colors[4]);
    graph5->SetMarkerStyle(markerStyles[4]);
    graph5->SetMarkerSize(2);
    graph5->Draw("p");
  }

  if ( graph6 ) {
    graph6->SetLineColor(colors[5]);
    graph6->SetLineWidth(2);
    graph6->SetMarkerColor(colors[5]);
    graph6->SetMarkerStyle(markerStyles[5]);
    graph6->SetMarkerSize(2);
    graph6->Draw("p");
  }
  
  TLegend* legend = new TLegend(legendPosX, legendPosY, legendPosX + legendSizeX, legendPosY + legendSizeY, "", "brNDC"); 
  legend->SetBorderSize(0);
  legend->SetFillColor(0);
  legend->SetTextSize(legendTextSize);
  legend->AddEntry(graph1, legendEntry1.data(), "p");
  if ( graph2 ) legend->AddEntry(graph2, legendEntry2.data(), "p");
  if ( graph3 ) legend->AddEntry(graph3, legendEntry3.data(), "p");
  if ( graph4 ) legend->AddEntry(graph4, legendEntry4.data(), "p");
  if ( graph5 ) legend->AddEntry(graph5, legendEntry5.data(), "p");
  if ( graph6 ) legend->AddEntry(graph6, legendEntry6.data(), "p");
  legend->Draw();

  TPaveText* label = 0;
  if ( labelTextLines.size() > 0 ) {
    label = new TPaveText(labelPosX, labelPosY, labelPosX + labelSizeX, labelPosY + labelSizeY, "brNDC");
    for ( std::vector<std::string>::const_iterator labelTextLine = labelTextLines.begin();
	  labelTextLine != labelTextLines.end(); ++labelTextLine ) {
      label->AddText(labelTextLine->data());
    }
    label->SetFillColor(10);
    label->SetBorderSize(0);
    label->SetTextColor(1);
    label->SetTextAlign(12);
    label->SetTextSize(labelTextSize);
    label->Draw();
  }

  canvas->Update();
  std::string outputFileName_plot = "plots/";
  size_t idx = outputFileName.find_last_of('.');
  outputFileName_plot.append(std::string(outputFileName, 0, idx));
  if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
  canvas->Print(std::string(outputFileName_plot).append(".png").data());
  canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
  
  delete dummyHistogram;
  delete label;
  delete legend;
  delete canvas;  
}
Ejemplo n.º 21
0
// input: - Input file (result from TMVA),
//        - normal/decorrelated/PCA
//        - use of TMVA plotting TStyle
void variables( TString fin = "TMVA.root", TString dirName = "InputVariables_Id", TString title = "TMVA Input Variables",
                Bool_t isRegression = kFALSE, Bool_t useTMVAStyle = kTRUE )
{
   TString outfname = dirName;
   outfname.ToLower(); outfname.ReplaceAll( "input", ""  );

   // set style and remove existing canvas'
   TMVAGlob::Initialize( useTMVAStyle );

   // obtain shorter histogram title 
   TString htitle = title; 
   htitle.ReplaceAll("variables ","variable");
   htitle.ReplaceAll("and target(s)","");
   htitle.ReplaceAll("(training sample)","");

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

   TDirectory* dir = (TDirectory*)file->Get( dirName );
   if (dir==0) {
      cout << "No information about " << title << " available in directory " << dirName << " of file " << fin << endl;
      return;
   }
   dir->cd();

   // how many plots are in the directory?
   Int_t noPlots = TMVAGlob::GetNumberOfInputVariables( dir ) +
      TMVAGlob::GetNumberOfTargets( dir );

   // define Canvas layout here!
   // default setting
   Int_t xPad;  // no of plots in x
   Int_t yPad;  // no of plots in y
   Int_t width; // size of canvas
   Int_t height;
   switch (noPlots) {
   case 1:
      xPad = 1; yPad = 1; width = 550; height = 0.90*width; break;
   case 2:
      xPad = 2; yPad = 1; width = 600; height = 0.50*width; break;
   case 3:
      xPad = 3; yPad = 1; width = 900; height = 0.4*width; break;
   case 4:
      xPad = 2; yPad = 2; width = 600; height = width; break;
   default:
//       xPad = 3; yPad = 2; width = 800; height = 0.55*width; break;
     xPad = 1; yPad = 1; width = 550; height = 0.90*width; break;
   }

   Int_t noPadPerCanv = xPad * yPad ;

   // counter variables
   Int_t countCanvas = 0;
   Int_t countPad    = 0;

   // loop over all objects in directory
   TCanvas* canv = 0;
   TKey*    key  = 0;
   Bool_t   createNewFig = kFALSE;
   TIter next(dir->GetListOfKeys());
   while ((key = (TKey*)next())) {
      if (key->GetCycle() != 1) continue;

      if (!TString(key->GetName()).Contains("__Signal") && 
          !(isRegression && TString(key->GetName()).Contains("__Regression"))) continue;

      // make sure, that we only look at histograms
      TClass *cl = gROOT->GetClass(key->GetClassName());
      if (!cl->InheritsFrom("TH1")) continue;
      TH1 *sig = (TH1*)key->ReadObj();
      TString hname(sig->GetName());

      //normalize to 1
      NormalizeHist(sig);      

      // create new canvas
      if (countPad%noPadPerCanv==0) {
         ++countCanvas;
         canv = new TCanvas( Form("canvas%d", countCanvas), title,
                             countCanvas*50+50, countCanvas*20, width, height );
         canv->Divide(xPad,yPad);
         canv->SetFillColor(kWhite);
         canv->Draw();
      }

      TPad* cPad = (TPad*)canv->cd(countPad++%noPadPerCanv+1);
      cPad->SetFillColor(kWhite);

      // find the corredponding backgrouns histo
      TString bgname = hname;
      bgname.ReplaceAll("__Signal","__Background");
      TH1 *bgd = (TH1*)dir->Get(bgname);
      if (bgd == NULL) {
         cout << "ERROR!!! couldn't find background histo for" << hname << endl;
         exit;
      }
      //normalize to 1
      NormalizeHist(bgd);


      // this is set but not stored during plot creation in MVA_Factory
      TMVAGlob::SetSignalAndBackgroundStyle( sig, (isRegression ? 0 : bgd) );            

      sig->SetTitle( TString( htitle ) + ": " + sig->GetTitle() );
      TMVAGlob::SetFrameStyle( sig, 1.2 );

      // normalise both signal and background
//       if (!isRegression) TMVAGlob::NormalizeHists( sig, bgd );
//       else {
//          // change histogram title for target
//          TString nme = sig->GetName();
//          if (nme.Contains( "_target" )) {
//             TString tit = sig->GetTitle();
//             sig->SetTitle( tit.ReplaceAll("Input variable", "Regression target" ) );
//          }
//       }
      sig->SetTitle( "" );            
      

      // finally plot and overlay
      Float_t sc = 1.1;
      if (countPad == 1) sc = 1.3;
      sig->SetMaximum( TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*sc );
      sig->Draw( "hist" );
      cPad->SetLeftMargin( 0.17 );

      sig->GetYaxis()->SetTitleOffset( 1.50 );
      if (!isRegression) {
         bgd->Draw("histsame");
         TString ytit = TString("(1/N) ") + sig->GetYaxis()->GetTitle();
         ytit = TString("Fraction of Events");
         sig->GetYaxis()->SetTitle( ytit ); // histograms are normalised
      }

      if (countPad == 1) sig->GetXaxis()->SetTitle("Leading Lepton p_{T} [GeV/c]");
      if (countPad == 2) sig->GetXaxis()->SetTitle("Trailing Lepton p_{T} [GeV/c]");
      if (countPad == 3) sig->GetXaxis()->SetTitle("#Delta#phi(l,l)");
      if (countPad == 4) sig->GetXaxis()->SetTitle("#Delta R(l,l)");
      if (countPad == 5) sig->GetXaxis()->SetTitle("Dilepton Mass [GeV/c^{2}]");
      if (countPad == 6) sig->GetXaxis()->SetTitle("Dilepton Flavor Final State");
      if (countPad == 7) sig->GetXaxis()->SetTitle("M_{T} (Higgs) [GeV/c^{2}]");
      if (countPad == 8) sig->GetXaxis()->SetTitle("#Delta#phi(Dilepton System, MET)");
      if (countPad == 9) sig->GetXaxis()->SetTitle("#Delta#phi(Dilepton System, Jet)");


      // Draw legend
//       if (countPad == 1 && !isRegression) {
         TLegend *legend= new TLegend( cPad->GetLeftMargin(), 
                                       1-cPad->GetTopMargin()-.15, 
                                       cPad->GetLeftMargin()+.4, 
                                       1-cPad->GetTopMargin() );

         if(countPad == 1 || countPad == 2 ||countPad == 3 ||countPad == 4 ||countPad == 5 ||countPad == 7  ) {
           legend= new TLegend( 0.50, 
                                1-cPad->GetTopMargin()-.15, 
                                0.90, 
                                1-cPad->GetTopMargin() );
         }

         legend->SetFillStyle(0);
         legend->AddEntry(sig,"Signal","F");
         legend->AddEntry(bgd,"Background","F");
         legend->SetBorderSize(0);
         legend->SetMargin( 0.3 );
         legend->SetTextSize( 0.03 );
         legend->Draw("same");
//       } 

      // redraw axes
      sig->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 = "";
      if (isRegression) {
         uoflow = Form( "U/O-flow: %.1f%% / %.1f%%", 
                        sig->GetBinContent(0)*dxu*100, sig->GetBinContent(nbin+1)*dxo*100 );
      }
      else {
         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.98, 0.14, uoflow );
      t->SetNDC();
      t->SetTextSize( 0.040 );
      t->SetTextAngle( 90 );
//       t->AppendPad();    

      // save canvas to file
      if (countPad%noPadPerCanv==0) {
         TString fname = Form( "plots/%s_c%i", outfname.Data(), countCanvas );
         TMVAGlob::plot_logo();
         TMVAGlob::imgconv( canv, fname );
         createNewFig = kFALSE;
      }
      else {
         createNewFig = kTRUE;
      }
   }
   
   if (createNewFig) {
      TString fname = Form( "plots/%s_c%i", outfname.Data(), countCanvas );
      TMVAGlob::plot_logo();
      TMVAGlob::imgconv( canv, fname );
      createNewFig = kFALSE;
   }

   return;
}
Ejemplo n.º 22
0
// ---------------------------------------------------------------------------------------------
// returns scaling (change in normalization, in log 10) or -666 if failed
// optional parameter accepts the desired unit prefix (in log 10)
int adjustUnits( TH1& h1, int forceNewPrefix = -666)
{
  if( h1.GetDimension() != 1) {cerr<<"ERROR! 'adjustUnits' works only for 1D histograms!"<<endl; return -666;}
  bool forced = forceNewPrefix != -666;
  TString ss( h1.GetYaxis()->GetTitle() );
  ss.ReplaceAll ("_{T}", "_%@#"); // otherwise it messes up the reg. exp.
  // all backslashes are doubled, to get by the compiler string parsing, leaving \[ for TRegexp --> literal [s & ]s
  int iOpenBracket = ss.Index (TRegexp ("\\[[^\\]]*\\][^\\[\\]]*$"));// That is, the start of the last square brackets
  int iCloseBracket = ss.Last(']'); // no need for quotes with char
  if( iOpenBracket < 0 || iCloseBracket <= iOpenBracket ) {
    // can't find units
    return -666;
  }
  Double_t oldMax = h1.GetMaximum();
  h1.SetMaximum(); // unsets
  Double_t max = h1.GetMaximum();
  Double_t max10 = TMath::Log10( max );
  if( -3 < max10 && max10 < 3 && ! forced ) return 0; // no rescaling needed
  
  // parse input units
  TString inputUnits = ss( 1+iOpenBracket, -1 + iCloseBracket - iOpenBracket);
  int curPrefix = 0, prefixLength = 0;
  if( inputUnits.BeginsWith( "m" ) ) {curPrefix = -3; prefixLength = 1;}
  if( inputUnits.BeginsWith( "#mu" ) ) {curPrefix = -6; prefixLength = 3;}
  if( inputUnits.BeginsWith( "n" ) ) {curPrefix = -9; prefixLength = 1;}
  if( inputUnits.BeginsWith( "p" ) ) {curPrefix = -12; prefixLength = 1;}
  if( inputUnits.BeginsWith( "f" ) ) {curPrefix = -15; prefixLength = 1;}
  if( inputUnits.BeginsWith( "k" ) ) {curPrefix = 3; prefixLength = 1;}
  // add more as needed....
  TString baseUnit( inputUnits( prefixLength, inputUnits.Length() - prefixLength ) );

  // find target units
  int iNewPrefix = 3 * TMath::Floor( 0.5 + (curPrefix + max10)/3. );
  if( forced ) iNewPrefix = forceNewPrefix;

  // prepare new units and scaling
  TString sNewPrefix;
  int scale10 = 1;
  if( iNewPrefix > 3 ) {cerr<<"adjustUnits - NYI for >kilo"<<endl;}
  if( iNewPrefix >= 3 ) {sNewPrefix = "k"; scale10 = curPrefix - 3;}

  if( -15 < iNewPrefix && iNewPrefix < 3 ) scale10 = curPrefix- iNewPrefix;
  if( iNewPrefix == 0   ) sNewPrefix = "";
  if( iNewPrefix == -3  ) sNewPrefix = "m";
  if( iNewPrefix == -6  ) sNewPrefix = "#mu";
  if( iNewPrefix == -9  ) sNewPrefix = "n";
  if( iNewPrefix == -12 ) sNewPrefix = "p";

  if( iNewPrefix < -15 ) {cerr<<"adjustUnits - NYI for <femto"<<endl;}
  if( iNewPrefix <= -15 ) {sNewPrefix = "f"; scale10 = curPrefix + 15;}
  
  // sanity checks
  if( forced && forceNewPrefix != 0 && sNewPrefix == "" ) {
    cerr<<"adjustUnits - illegal new prefix forced!"<<endl;
    return -666;
  }
  if( scale10 == 0 && ! forced ) {cerr<<"Bug in adjustUnits? scale10 == 0 .... "<<endl; return -666;}

  // good to go - changing the histogram
  Double_t scale = TMath::Power( 10, scale10 );
  h1.Scale( scale );
  h1.SetMaximum( oldMax * scale );
  h1.GetYaxis()->SetTitle( ss( 0, iOpenBracket + 1 ) + sNewPrefix + baseUnit 
			   + ss( iCloseBracket, ss.Length() - iCloseBracket ) );
  return scale10;
}
Ejemplo n.º 23
0
CompareSpectra(Int_t part, Int_t charge, Int_t cent = -1, Int_t ratio = kFALSE, Int_t fitfunc = -1, Bool_t cutSpectra = kTRUE) 
{

  gROOT->LoadMacro("HistoUtils.C");

  gStyle->SetOptStat(0);
  gStyle->SetOptFit();

  LoadLibraries();
  AliBWFunc bwf;
  bwf.SetVarType(AliBWFunc::kdNdpt);
  TF1 *fFitFunc = NULL;

  switch (fitfunc) {
  case 0:
    gROOT->LoadMacro("SpectraAnalysis.C");
    fFitFunc = STAR_BlastWave("fBW", AliPID::ParticleMass(part), 0.9, 0.1, 1.);
    fBW->SetParLimits(3, 0.5, 1.5);
    //    fBW->FixParameter(3, 1.);
    break;
  case 1:
    fFitFunc = bwf.GetLevi(AliPID::ParticleMass(part), AliPID::ParticleMass(part), 5., 1000.);
    break;
  case 2:
    fFitFunc = bwf.GetBoltzmann(AliPID::ParticleMass(part), AliPID::ParticleMass(part), 100.);
    break;
  case 3:
    fFitFunc = bwf.GetMTExp(AliPID::ParticleMass(part),AliPID::ParticleMass(part) , 100.);
    break;
  case 4:
    fFitFunc = bwf.GetPTExp(AliPID::ParticleMass(part), 100.);
    break;
  case 5:
    fFitFunc = bwf.GetBGBW(AliPID::ParticleMass(part), 0.5, 0.1, 1.e6);
    break;
  case 6:
    fFitFunc = new TF1("fpol9", "pol9", 0., 5.0);
    break;
  }
  if (fFitFunc) fFitFunc->SetLineWidth(2);

  TFile *itssafile = TFile::Open(ratio ? itssaratiofilename : itssafilename);
  //  TFile *itstpcfile = TFile::Open(itstpcfilename);
  if (part / 3 == charge / 3)
    Char_t *tpctofratiofilename = tpctofratiofilenameA;
  else
    Char_t *tpctofratiofilename = tpctofratiofilenameB;
  TFile *tpctoffile = TFile::Open(ratio ? tpctofratiofilename : tpctoffilename);
  TFile *toffile = TFile::Open(ratio ? tofratiofilename : toffilename);
  //  TFile *hydrofile = TFile::Open(hydrofilename);

  TCanvas *cCanvas = new TCanvas("cCanvas");
  if (cent == -1) cCanvas->Divide(5, 2);
  TCanvas *cCanvasCombined = new TCanvas("cCanvasCombined");
  TCanvas *cCanvasRatio = new TCanvas("cCanvasRatio");
  if (cent == -1) cCanvasRatio->Divide(5, 2);
  TCanvas *cCanvasRatioComb = new TCanvas("cCanvasRatioComb");
  if (cent == -1) cCanvasRatioComb->Divide(5, 2);
  TCanvas *cCanvasRatioFit = new TCanvas("cCanvasRatioFit");
  if (cent == -1) cCanvasRatioFit->Divide(5, 2);
  TPad *curpad = NULL;
  TH1D *hITSsa, *hITSTPC, *hTPCTOF, *hTOF;
  TGraph *hHydro;
  TGraphErrors *gCombined[10];
  TProfile *pCombined[10];
  TH1D *hCombined[10];
  TH1D *hRatio_ITSsa_ITSTPC[10];
  TH1D *hRatio_ITSsa_TPCTOF[10];
  TH1D *hRatio_ITSTPC_TPCTOF[10];
  TH1D *hRatio_ITSTPC_TOF[10];
  TH1D *hRatio_TPCTOF_TOF[10];
  TH1D *hRatio_ITSsa_TOF[10];
  for (Int_t icent = 0; icent < 10; icent++) {
    if (cent != -1 && icent != cent) continue;
    gCombined[icent] = new TGraphErrors();
    pCombined[icent] = new TProfile(Form("pCombined_cent%d", icent), "", NptBins, ptBin);
    hCombined[icent] = new TH1D(Form("hCombined_cent%d", icent), "", NptBins, ptBin);
    TObjArray spectraArray;
    hITSsa = ratio ? GetITSsaRatio(itssafile, part, charge, icent, cutSpectra): GetITSsaSpectrum(itssafile, part, charge, icent, cutSpectra);
    //    hITSTPC = GetITSTPCSpectrum(itstpcfile, part, charge, icent, cutSpectra);
    hTPCTOF = ratio ? GetTPCTOFRatio(tpctoffile, part, charge, icent, cutSpectra) : GetTPCTOFSpectrum(tpctoffile, part, charge, icent, cutSpectra);
    hTOF = ratio ? GetTOFRatio(toffile, part, charge, icent, cutSpectra) : GetTOFSpectrum(toffile, part, charge, icent, cutSpectra);
    //    hHydro = GetHydroSpectrum(hydrofile, part, charge, icent);
    if (cent == -1)
      curpad = (TPad *)cCanvas->cd(icent + 1);
    else
      curpad = (TPad *)cCanvas->cd();
    if (!ratio)
      TH1D *hArea = new TH1D(Form("hArea_%d", icent), Form("%s (%s);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{t}};", partChargeName[part][charge], centName[icent]), 100, 0., 5.);
    else
      TH1D *hArea = new TH1D(Form("hArea_%d", icent), Form("%s (%s);p_{T} (GeV/c);#frac{d^{2}N}{dy dp_{t}};", "generic ratio", centName[icent]), 100, 0., 5.);
    hArea->Draw();
    Double_t minimum = 0.001;
    Double_t maximum = 1000.;
    if (hITSsa) {
      AddPointsToGraph(hITSsa, gCombined[icent]);
      AddPointsToProfile(hITSsa, pCombined[icent]);
      spectraArray.Add(hITSsa);
      hITSsa->DrawCopy("same");
      if (hITSsa->GetMaximum() > maximum) maximum = hITSsa->GetMaximum();
      if (hITSsa->GetMinimum() < minimum) minimum = hITSsa->GetMinimum();
    }
    if (hITSTPC) {
      AddPointsToGraph(hITSTPC, gCombined[icent]);
      AddPointsToProfile(hITSTPC, pCombined[icent]);
      spectraArray.Add(hITSTPC);
      hITSTPC->DrawCopy("same");
      if (hITSTPC->GetMaximum() > maximum) maximum = hITSTPC->GetMaximum();
      if (hITSTPC->GetMinimum() < minimum) minimum = hITSTPC->GetMinimum();
    }
    if (hTPCTOF) {
      AddPointsToGraph(hTPCTOF, gCombined[icent]);
      AddPointsToProfile(hTPCTOF, pCombined[icent]);
      spectraArray.Add(hTPCTOF);
      hTPCTOF->DrawCopy("same");
      if (hTPCTOF->GetMaximum() > maximum) maximum = hTPCTOF->GetMaximum();
      if (hTPCTOF->GetMinimum() < minimum) minimum = hTPCTOF->GetMinimum();
    }
    if (hTOF) {
      AddPointsToGraph(hTOF, gCombined[icent]);
      AddPointsToProfile(hTOF, pCombined[icent]);
      spectraArray.Add(hTOF);
      hTOF->DrawCopy("same");
      if (hTOF->GetMaximum() > maximum) maximum = hTOF->GetMaximum();
      if (hTOF->GetMinimum() < minimum) minimum = hTOF->GetMinimum();
    }
    if (hHydro) {
      ;//hHydro->Draw("c,same");
    }
    TLegend *legend = curpad->BuildLegend();
    legend->SetFillStyle(0);
    legend->SetFillColor(0);
    legend->DeleteEntry();

    hArea->SetMaximum(maximum * 1.1);
    hArea->SetMinimum(0.01);
    //    gPad->SetLogy();

    /*** RATIOS ***/

    /* switch canvas */
    if (cent == -1)
      curpad = (TPad *)cCanvasRatio->cd(icent + 1);
    else
      curpad = (TPad *)cCanvasRatio->cd();

   
    /* area histo */
    if (!ratio)
      TH1D *hAreaRatio = new TH1D(Form("hAreaRatio_%d", icent), Form("%s (%s);p_{T} (GeV/c);ratio;", partChargeName[part][charge], centName[icent]), 100, 0., 5.);
    else
      TH1D *hAreaRatio = new TH1D(Form("hAreaRatio_%d", icent), Form("%s (%s);p_{T} (GeV/c);ratio;", "generic ratio", centName[icent]), 100, 0., 5.);

    hAreaRatio->SetMaximum(1.5);
    hAreaRatio->SetMinimum(0.5);
    hAreaRatio->Draw();

    /* do ratios */
    if (hITSsa && hITSTPC) {
      hRatio_ITSsa_ITSTPC[icent] = new TH1D(*hITSsa);
      hRatio_ITSsa_ITSTPC[icent]->Divide(hITSTPC);
      hRatio_ITSsa_ITSTPC[icent]->SetNameTitle(Form("hRatio_ITSsa_ITSTPC_cent%d", icent), "ITSsa / ITSTPC");
      hRatio_ITSsa_ITSTPC[icent]->Draw("same");
    }
    if (hITSsa && hTPCTOF) {
      hRatio_ITSsa_TPCTOF[icent] = new TH1D(*hITSsa);
      hRatio_ITSsa_TPCTOF[icent]->Divide(hTPCTOF);
      hRatio_ITSsa_TPCTOF[icent]->SetNameTitle(Form("hRatio_ITSsa_TPCTOF_cent%d", icent), "ITSsa / TPCTOF");
      hRatio_ITSsa_TPCTOF[icent]->SetMarkerStyle(23);
      hRatio_ITSsa_TPCTOF[icent]->SetMarkerColor(4);
      hRatio_ITSsa_TPCTOF[icent]->Draw("same");
    }
    if (hITSTPC && hTPCTOF) {
      hRatio_ITSTPC_TPCTOF[icent] = new TH1D(*hITSTPC);
      hRatio_ITSTPC_TPCTOF[icent]->Divide(hTPCTOF);
      hRatio_ITSTPC_TPCTOF[icent]->SetNameTitle(Form("hRatio_ITSTPC_TPCTOF_cent%d", icent), "ITSTPC / TPCTOF");
      hRatio_ITSTPC_TPCTOF[icent]->Draw("same");
    }
    if (hTPCTOF && hTOF) {
      hRatio_TPCTOF_TOF[icent] = new TH1D(*hTPCTOF);
      hRatio_TPCTOF_TOF[icent]->Divide(hTOF);
      hRatio_TPCTOF_TOF[icent]->SetNameTitle(Form("hRatio_TPCTOF_TOF_cent%d", icent), "TPCTOF / TOF");
      hRatio_TPCTOF_TOF[icent]->Draw("same");
    }
    if (hITSsa && hTOF) {
      hRatio_ITSsa_TOF[icent] = new TH1D(*hITSsa);
      hRatio_ITSsa_TOF[icent]->Divide(hTOF);
      hRatio_ITSsa_TOF[icent]->SetNameTitle(Form("hRatio_ITSsa_TOF_cent%d", icent), "ITSsa / TOF");
      //      hRatio_ITSsa_TOF[icent]->SetMarkerStyle(25);
      //      hRatio_ITSsa_TOF[icent]->SetMarkerColor(2);
      hRatio_ITSsa_TOF[icent]->Draw("same");
    }

    /* legend */
    TLegend *legendRatio = curpad->BuildLegend();
    legendRatio->SetFillStyle(0);
    legendRatio->SetFillColor(0);
    legendRatio->DeleteEntry();

    CombineSpectra(hCombined[icent], &spectraArray);
    hCombined[icent]->SetFillStyle(0);
    hCombined[icent]->SetFillColor(kOrange + 1);
    hCombined[icent]->SetMarkerColor(kOrange+1);
    hCombined[icent]->SetMarkerStyle(24);
    hCombined[icent]->SetLineColor(kOrange+1);
    hCombined[icent]->SetLineWidth(2);
    hCombined[icent]->SetMarkerSize(0);
    
    //    hCombined[icent]->DrawCopy("same,E2");
    //    pCombined[icent]->DrawCopy("same");

    if (cent == -1)
      cCanvas->cd(icent + 1);
    else
      cCanvas->cd();
    //    hCombined[icent]->Draw("same, E2");

    cCanvasCombined->cd();
    if (cent == -1 && icent != 0)
      hCombined[icent]->Draw("E2,same");
    else
      hCombined[icent]->Draw("E2");

    //    cCanvasCombined->DrawClonePad();
    if (hITSsa) {
      hITSsa->DrawCopy("same");
    }
    if (hITSTPC) {
      hITSTPC->DrawCopy("same");
    }
    if (hTPCTOF) {
      hTPCTOF->DrawCopy("same");
    }
    if (hTOF) {
      hTOF->DrawCopy("same");
    }
    if (hHydro) {
      ;//hHydro->Draw("c,same");
    }

    if (cent == -1)
      cCanvasRatioComb->cd(icent + 1);
    else
      cCanvasRatioComb->cd();
    //    hCombined[icent]->Draw("same, E2");

    TH1 *hhr = HistoUtils_smartratio(hCombined[icent], hCombined[icent]);
    hhr->SetMaximum(1.25);
    hhr->SetMinimum(0.75);
    hhr->SetFillStyle(3001);
    hhr->SetTitle("combined error;p_{T} (GeV/c);ratio wrt. combined");
    hhr->Draw("e2");
    if (hITSsa) {
      hhr = HistoUtils_smartratio(hITSsa, hCombined[icent]);
      hhr->SetLineColor(1);
      hhr->SetLineWidth(2);
      hhr->Draw("e2,same");
    }
    if (hITSTPC) {
      hhr = HistoUtils_smartratio(hITSTPC, hCombined[icent]);
      hhr->SetLineColor(1);
      hhr->SetLineWidth(2);
      hhr->Draw("e2,same");
    }
    if (hTPCTOF) {
      hhr = HistoUtils_smartratio(hTPCTOF, hCombined[icent]);
      hhr->SetLineColor(8);
      hhr->SetLineWidth(2);
      hhr->Draw("e2,same");
    }
    if (hTOF) {
      hhr = HistoUtils_smartratio(hTOF, hCombined[icent]);
      hhr->SetLineColor(4);
      hhr->SetLineWidth(2);
      hhr->Draw("e2,same");
    }
    if (hHydro) {
      ;//hHydro->Draw("c,same");
    }


    if (!fFitFunc)
      continue;
    
    //    gCombined[icent]->Draw("p*");
    //    gCombined[icent]->Fit(fFitFunc, "0q", "", 0.5, 1.0);
    //    gCombined[icent]->Fit(fFitFunc, "0q", "", 0.2, 1.5);
    hCombined[icent]->Fit(fFitFunc, "0q", "", 0., 5.);
    fFitFunc->DrawCopy("same");
    printf("cent = %d, dNdy = %f +- %f\n", icent, fFitFunc->GetParameter(0), fFitFunc->GetParError(0));

    if (cent == -1)
      cCanvas->cd(icent + 1);
    else
      cCanvas->cd();
    fFitFunc->DrawCopy("same");

    if (cent == -1)
      cCanvasRatioFit->cd(icent + 1);
    else
      cCanvasRatioFit->cd();
    if (!ratio)
      TH1D *hAreaRatioFit = new TH1D(Form("hAreaRatioFit_%d", icent), Form("%s (%s);p_{T} (GeV/c);ratio wrt. fit;", partChargeName[part][charge], centName[icent]), 100, 0., 5.);
    else
      TH1D *hAreaRatioFit = new TH1D(Form("hAreaRatioFit_%d", icent), Form("%s (%s);p_{T} (GeV/c);ratio wrt. fit;", "generic ratio", centName[icent]), 100, 0., 5.);
    hAreaRatioFit->SetMaximum(1.5);
    hAreaRatioFit->SetMinimum(0.5);
    hAreaRatioFit->Draw();
    legend->Draw("same");

    if (hITSsa) {
      hITSsa->Divide(fFitFunc);
      hITSsa->DrawCopy("same");
    }
    if (hITSTPC) {
      hITSTPC->Divide(fFitFunc);
      hITSTPC->DrawCopy("same");
    }
    if (hTPCTOF) {
      hTPCTOF->Divide(fFitFunc);
      hTPCTOF->DrawCopy("same");
    }
    if (hTOF) {
      hTOF->Divide(fFitFunc);
      hTOF->DrawCopy("same");
    }

  }

}
Ejemplo n.º 24
0
TCanvas* example_plot( int iPeriod, int iPos )
{ 
  //  if( iPos==0 ) relPosX = 0.12;

  int W = 800;
  int H = 600;

  // 
  // Simple example of macro: plot with CMS name and lumi text
  //  (this script does not pretend to work in all configurations)
  // iPeriod = 1*(0/1 7 TeV) + 2*(0/1 8 TeV)  + 4*(0/1 13 TeV) 
  // For instance: 
  //               iPeriod = 3 means: 7 TeV + 8 TeV
  //               iPeriod = 7 means: 7 TeV + 8 TeV + 13 TeV 
  // Initiated by: Gautier Hamel de Monchenault (Saclay)
  // Updated by:   Dinko Ferencek (Rutgers)
  //
  int H_ref = 600; 
  int W_ref = 800; 

  // references for T, B, L, R
  float T = 0.08*H_ref;
  float B = 0.12*H_ref; 
  float L = 0.12*W_ref;
  float R = 0.04*W_ref;

  TString canvName = "FigExample_";
  canvName += W;
  canvName += "-";
  canvName += H;
  canvName += "_";  
  canvName += iPeriod;
  if( writeExtraText ) canvName += "-prelim";
  if( iPos%10==0 ) canvName += "-out";
  else if( iPos%10==1 ) canvName += "-left";
  else if( iPos%10==2 )  canvName += "-center";
  else if( iPos%10==3 )  canvName += "-right";

  TCanvas* canv = new TCanvas(canvName,canvName,50,50,W,H);
  canv->SetFillColor(0);
  canv->SetBorderMode(0);
  canv->SetFrameFillStyle(0);
  canv->SetFrameBorderMode(0);
  canv->SetLeftMargin( L/W );
  canv->SetRightMargin( R/W );
  canv->SetTopMargin( T/H );
  canv->SetBottomMargin( B/H );
  canv->SetTickx(0);
  canv->SetTicky(0);

  TH1* h = new TH1F("h","h",40,70,110);
  h->GetXaxis()->SetNdivisions(6,5,0);
  h->GetXaxis()->SetTitle("m_{e^{+}e^{-}} (GeV)");  
  h->GetYaxis()->SetNdivisions(6,5,0);
  h->GetYaxis()->SetTitleOffset(1);
  h->GetYaxis()->SetTitle("Events / 0.5 GeV");  

  h->SetMaximum( 260 );
  if( iPos==1 ) h->SetMaximum( 300 );
  h->Draw();

  int histLineColor = kOrange+7;
  int histFillColor = kOrange-2;
  float markerSize  = 1.0;

  {
    TLatex latex;
				
    int n_ = 2;

    float x1_l = 0.92;
    float y1_l = 0.60;

    float dx_l = 0.30;
    float dy_l = 0.18;
    float x0_l = x1_l-dx_l;
    float y0_l = y1_l-dy_l;

    TPad* legend = new TPad("legend_0","legend_0",x0_l,y0_l,x1_l, y1_l );
    //    legend->SetFillColor( kGray );
    legend->Draw();
    legend->cd();
		
    float ar_l = dy_l/dx_l;
		
    float x_l[1];
    float ex_l[1];
    float y_l[1];
    float ey_l[1];
		
    //    float gap_ = 0.09/ar_l;
    float gap_ = 1./(n_+1);
		
    float bwx_ = 0.12;
    float bwy_ = gap_/1.5;
		
    x_l[0] = 1.2*bwx_;
    //    y_l[0] = 1-(1-0.10)/ar_l;
    y_l[0] = 1-gap_;
    ex_l[0] = 0;
    ey_l[0] = 0.04/ar_l;
		
    TGraph* gr_l = new TGraphErrors(1, x_l, y_l, ex_l, ey_l );
		
    gStyle->SetEndErrorSize(0);
    gr_l->SetMarkerSize(0.9);
    gr_l->Draw("0P");
		
    latex.SetTextFont(42);
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);    
    latex.SetTextSize(0.25);    
    latex.SetTextAlign(12); 
		
    TLine line_;
    TBox  box_;
    float xx_ = x_l[0];
    float yy_ = y_l[0];
    latex.DrawLatex(xx_+1.*bwx_,yy_,"Data");
		
    yy_ -= gap_;
    box_.SetLineStyle( kSolid );
    box_.SetLineWidth( 1 );
    //		box_.SetLineColor( kBlack );
    box_.SetLineColor( histLineColor );
    box_.SetFillColor( histFillColor );
    box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 );
    box_.SetFillStyle(0);
    box_.DrawBox( xx_-bwx_/2, yy_-bwy_/2, xx_+bwx_/2, yy_+bwy_/2 );
    latex.DrawLatex(xx_+1.*bwx_,yy_,"Z #rightarrow e^{+}e^{-} (MC)");

    canv->cd();
  }

  {
    // Observed data
    TFile file_("histo.root","READ");

    TH1F *data = static_cast<TH1F*>(file_.Get("data")->Clone());
    data->SetDirectory(0);
    data->SetMarkerStyle(20);
    data->SetMarkerSize(markerSize);

    TH1F *MC   = static_cast<TH1F*>(file_.Get("MC")->Clone());
    MC->SetDirectory(0);
    MC->SetLineColor(histLineColor);
    MC->SetFillColor(histFillColor);

    MC->Draw("histsame");
    data->Draw("esamex0");

    file_.Close();
  }

  // writing the lumi information and the CMS "logo"
  CMS_lumi( canv, iPeriod, iPos );

  canv->Update();
  canv->RedrawAxis();
  canv->GetFrame()->Draw();

  canv->Print(canvName+".pdf",".pdf");
  canv->Print(canvName+".png",".png");

  return canv;
}
Ejemplo n.º 25
0
//________________________________________________________
void GFHistManager::DrawReally(Int_t layer)
{
  if(layer < 0 || layer > fDepth-1) {
    this->Warning("DrawReally","Layer %d does not exist, possible are 0 to %d.", 
		  layer, fDepth-1);
    return;
  }

  this->MakeCanvases(layer);

  TIter canIter(static_cast<TObjArray*>(fCanArrays->At(layer)));
  TIter histIter(static_cast<TObjArray*>(fHistArrays->At(layer)));

  Int_t histNo = 0; // becomes number of histograms in layer
  while(TCanvas* can = static_cast<TCanvas*>(canIter.Next())){
    Int_t nPads = this->NumberOfSubPadsOf(can);
    if (fNoX[layer] * fNoY[layer] != nPads && 
	!(nPads == 0 && fNoX[layer] * fNoY[layer] == 1)) {
      this->Warning("Update", "inconsistent number of pads %d, expect %d*%d",
		    nPads, fNoX[layer], fNoY[layer]);
    }
    for(Int_t i = 0; i <= nPads; ++i){
      if (i == 0 && nPads != 0) i = 1;
      can->cd(i);
      if(GFHistArray* histsOfPad = static_cast<GFHistArray*>(histIter.Next())){
	TIter hists(histsOfPad);
	TH1* firstHist = static_cast<TH1*>(hists.Next());
	firstHist->Draw();
	this->DrawFuncs(firstHist);
	while(TH1* h = static_cast<TH1*>(hists.Next())){
	  h->Draw(Form("SAME%s%s", (fSameWithStats ? "S" : ""), h->GetOption()));
	  this->DrawFuncs(h);
	}
	if(histsOfPad->GetEntriesFast() > 1){
	  const Double_t max = this->MaxOfHists(histsOfPad);
	  if(//firstHist->GetMaximumStored() != -1111. &&  ????
	     max > firstHist->GetMaximumStored()){
	    firstHist->SetMaximum((fLogY[layer] ? 1.1 : 1.05) * max);
	  }
	  const Double_t min = this->MinOfHists(histsOfPad);
	  if(!(gStyle->GetHistMinimumZero() && min > 0.)) {
	    firstHist->SetMinimum(min * 1.05);
	  }
	}
	if(fLogY[layer] 
	   && (firstHist->GetMinimum() > 0. 
	      || (firstHist->GetMinimum() == 0. 
		  && firstHist->GetMinimumStored() == -1111.)))gPad->SetLogy();
	// draw other objects:
	this->DrawObjects(layer, histNo);
	// make hist style differ
	if(fDrawDiffStyle) GFHistManager::MakeDifferentStyle(histsOfPad);
	// draw legends on top of all
	if(fLegendArrays && layer <= fLegendArrays->GetLast() && fLegendArrays->At(layer)){
	  this->DrawLegend(layer, histNo);
	}
	gPad->Modified();
	this->ColourFuncs(histsOfPad);
	if (fSameWithStats) {
	  gPad->Update(); // not nice to need this here, makes use over network impossible...
	  this->ColourStatsBoxes(histsOfPad);
	}
	histNo++;
      }
    } // loop over pads
  } // loop over canvases
}
void plotVariable(string variable = "Elec_Fbrem",
		  const TString& category = "TauNoGammas",
		  const TString& xAxisTitle = "Fbrem",
		  const TString& yAxisTitle = "a.u.",
		  float xMin = -0.2, 
		  float xMax = 1,
		  int nBins = 100, 
		  int numPVMin = 0, 
		  int numPVMax = 50,
		  float PtMin = 10, 
		  float PtMax = 60,
		  const TString& Region = "Endcap"
		   )
{
   string discriminator = "";
//   string discriminator = "-AntiEMed";

  float AbsEtaMin = 0; 
  float AbsEtaMax = 3.0;
  if(Region == "Barrel"){
    AbsEtaMin = 0; 
    AbsEtaMax = 1.479;
  }
  if(Region == "Endcap"){
    AbsEtaMin = 1.479; 
    AbsEtaMax = 3.0;
  }
  TCanvas *c1 = new TCanvas("c1","",5,30,650,600);
  c1->SetGrid(0,0);
  c1->SetFillStyle(4000);
  c1->SetFillColor(10);
  c1->SetTicky();
  c1->SetObjectStat(0);

  gStyle->SetOptStat(0);
  gStyle->SetTitleFillColor(0);
  gStyle->SetCanvasBorderMode(0);
  gStyle->SetCanvasColor(0);
  gStyle->SetPadBorderMode(0);
  gStyle->SetPadColor(0);
  gStyle->SetTitleFillColor(0);
  gStyle->SetTitleBorderSize(0);
  gStyle->SetTitleH(0.07);
  gStyle->SetTitleFontSize(0.1);
  gStyle->SetTitleStyle(0);
  gStyle->SetTitleOffset(1.3,"y");

  TLegend* leg = new TLegend(0.6,0.75,0.8,0.88,NULL,"brNDC");
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetFillColor(10);
  leg->SetTextSize(0.03);
  //leg->SetHeader("#splitline{CMS Preliminary}{ #sqrt{s}=7 TeV}");

//   std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/AntiEMVA_Fall11DYJetsToLL-iter4.root";
//   std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/Trees_ForV4/AntiEMVA_AntiEMVATrees-DYJetsToLL-madgraph-PUS6.root";
  std::string inputFileName = "/data_CMS/cms/ivo/AntiEMVA/Trees/Trees_ForV4/AntiEMVA_V4.root";
  TFile* inputFile = new TFile (inputFileName.data(),"READ");
  if(inputFile->IsZombie()){
    cout << "No such file!" << endl;
    return;
  }
  TTree* inputTree = (TTree*)inputFile->Get("AntiEMVAAnalyzer2/tree");
//   TTree* inputTree = (TTree*)inputFile->Get("AntiEMVAAnalyzer/tree");
  std::vector<TH1*> histograms;

  std::vector<std::string> matchings ; 
  matchings.push_back("GenHadMatch");
  matchings.push_back("GenEleMatch");

  for ( std::vector<std::string>::const_iterator matching = matchings.begin();
	matching  != matchings.end(); ++matching ) {


    TCut PUSelection(Form("NumPV>%i && NumPV<%i",numPVMin,numPVMax));
    TCut ElecPtSelection (Form("Elec_Pt>%0f && Elec_Pt<%0f",PtMin,PtMax));
    TCut TauPtSelection (Form("Tau_Pt>%0f && Tau_Pt<%0f",PtMin,PtMax));
    TCut ElecAbsEtaSelection (Form("Elec_AbsEta>%0f && Elec_AbsEta<%0f",AbsEtaMin,AbsEtaMax));
    TCut TauAbsEtaSelection = "";
    if(Region == "Barrel"){
      TauAbsEtaSelection = "Tau_Eta>-1.479 && Tau_Eta<1.479";
    }
    if(Region == "Endcap"){
      TauAbsEtaSelection = "(Tau_Eta>1.479 && Tau_Eta<3.0) || (Tau_Eta>-3.0 && Tau_Eta<-1.479)";
    }
    //   TCut TauAbsEtaSelection (Form("Tau_AbsEta>%0f && Tau_AbsEta<%0f",AbsEtaMin,AbsEtaMax));
    TCut ElecMatchSelection (Form("Elec_%s == 1",matching->data()));
    //   TCut ElecMatchSelection (Form("Elec_PFTauMatch && Elec_%s",matching->data()));
    TCut TauMatchSelection (Form("Tau_%s",matching->data()));
    TCut CategorySelection = "";
    if(discriminator == ""){
      if (category == "NoEleMatch") CategorySelection = "Tau_GsfEleMatch<0.5"; 
      if (category == "woG") CategorySelection = "Tau_NumGammaCands<0.5"; 
      if (category == "wGwoGSF") CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf<0.5";
      if (category == "wGwGSFwoPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput<-0.1";
      if (category == "wGwGSFwPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput>-0.1";
    }

    if(discriminator == "-AntiEMed"){
      if (category == "NoEleMatch") CategorySelection = "Tau_GsfEleMatch<0.5"; 
      if (category == "woG") CategorySelection = "Tau_NumGammaCands<0.5"; 
      if (category == "wGwoGSF") CategorySelection = "Tau_NumGammaCands>0.5 && (Tau_HasGsf<0.5 || (Tau_HasGsf>0.5 && Elec_PFMvaOutput>-0.1))";
      if (category == "wGwGSFwoPFMVA")CategorySelection = "Tau_NumGammaCands>0.5 && Tau_HasGsf>0.5 && Elec_PFMvaOutput<-0.1";
    }

  TCut ElecSelection = CategorySelection && PUSelection && ElecPtSelection && ElecAbsEtaSelection && ElecMatchSelection ;
  TCut TauSelection = CategorySelection && PUSelection && TauPtSelection && TauAbsEtaSelection && TauMatchSelection ;
  TCut Selection;
  if (variable.find("Elec")!=std::string::npos)Selection = ElecSelection;
  if (variable.find("Tau")!=std::string::npos)Selection = TauSelection;
  

  TH1F* hVariable   = new TH1F( "hVariable" ,"" , nBins ,xMin, xMax);
  hVariable->SetXTitle(Form("%s",variable.data()));

  if (matching->find("EleMatch")!=std::string::npos){
//     hVariable->SetFillColor(kRed);
//     hVariable->SetFillStyle(3345);
    hVariable->SetLineColor(kRed);
    hVariable->SetLineWidth(2);
  }
  if (matching->find("HadMatch")!=std::string::npos){
//     hVariable->SetFillColor(kBlue);
//     hVariable->SetFillStyle(3354);
    hVariable->SetLineColor(kBlue);
    hVariable->SetLineWidth(2);
  }  
  inputTree->Draw(Form("%s>>hVariable",variable.data()));

  cout<<"Variable plotted : "<<variable<<endl;
  cout<<"Matching applied : "<<matching->data()<<endl;
  cout<<"  Total number of Candidates : "<<hVariable->GetEntries()<<endl;
  inputTree->Draw(Form("%s>>hVariable",variable.data()),Selection);
  cout<<"  Number of Cantidates after selection: "<<hVariable->GetEntries()<<endl;
  hVariable->Scale(1./hVariable->Integral());
  leg->AddEntry(hVariable,Form("%s",matching->data()));

  histograms.push_back(hVariable);
  c1->Clear();
  }
//   double yMin = +1.e+6;
//   double yMax = -1.e+6;
  TH1* refHistogram = histograms.front();
  refHistogram->SetStats(false);
  refHistogram->SetTitle("");
//   refHistogram->SetMinimum(yMin);
//   refHistogram->SetMaximum(yMax);


  if (xAxisTitle == "HoHplusE" ) {
    refHistogram->SetMaximum(1.0);
    refHistogram->SetMinimum(0.01);
    c1->SetLogy();
  }

  if(xAxisTitle == "E_{#gamma}/(P_{in}-P_{out})" ){
    refHistogram->SetMaximum(0.03);
    refHistogram->SetMinimum(0.0);
  }

  if(xAxisTitle == "HadrMva(#tau)" ){
    refHistogram->SetMaximum(0.25);
    refHistogram->SetMinimum(0.0);
  }

  TAxis* xAxis = refHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.Data());
  xAxis->SetTitleOffset(1.15);
  //if(variable.find("AbsEta")!=std::string::npos)xAxis->SetLimits(AbsEtaMin, AbsEtaMax);
  TAxis* yAxis = refHistogram->GetYaxis();
  yAxis->SetTitle(yAxisTitle.Data());
  yAxis->SetTitleOffset(1.30);

  int numHistograms = histograms.size();
  float YMax = 0;
  for ( int iHistogram = 0; iHistogram < numHistograms; ++iHistogram ) {
    TH1* histogram = histograms[iHistogram];
    if(histogram->GetMaximum()>YMax) YMax = histogram->GetMaximum();
  }
  for ( int iHistogram = 0; iHistogram < numHistograms; ++iHistogram ) {
    TH1* histogram = histograms[iHistogram];
    yAxis->SetRangeUser(0.,YMax+0.10*YMax);
    std::string drawOption = "hist";
    if ( iHistogram > 0 ) drawOption.append("same");
    histogram->Draw(drawOption.data());
    leg->Draw();

  }//loop matchings
  string outputName = Form("plots/plotVariablesAntiEMVA/%s/plotVariablesAntiEMVA_v4_%s_%s_%s",category.Data(),category.Data(),variable.data(),Region.Data());
  c1->Print(std::string(outputName).append(".png").data());
  c1->Print(std::string(outputName).append(".pdf").data());

}
void showEfficiency(const TString& title, double canvasSizeX, double canvasSizeY,
		    const TH1* histogram1_numerator, const TH1* histogram1_denominator, const std::string& legendEntry1,
		    const TH1* histogram2_numerator, const TH1* histogram2_denominator, const std::string& legendEntry2,
		    const TH1* histogram3_numerator, const TH1* histogram3_denominator, const std::string& legendEntry3,
		    const TH1* histogram4_numerator, const TH1* histogram4_denominator, const std::string& legendEntry4,
		    const TH1* histogram5_numerator, const TH1* histogram5_denominator, const std::string& legendEntry5,
		    const TH1* histogram6_numerator, const TH1* histogram6_denominator, const std::string& legendEntry6,
		    const std::string& xAxisTitle, double xAxisOffset,
                    bool useLogScale, double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset,
		    double legendX0, double legendY0, 
		    const std::string& outputFileName)
{
  TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2);
  canvas->SetLeftMargin(0.12);
  canvas->SetBottomMargin(0.12);
  canvas->SetLogy(useLogScale);
  canvas->SetGridx();
  canvas->SetGridy();

  TH1* dummyHistogram = new TH1D("dummyHistogram_top", "dummyHistogram_top", 10, histogram1_numerator->GetXaxis()->GetXmin(), histogram1_numerator->GetXaxis()->GetXmax());
  dummyHistogram->SetTitle("");
  dummyHistogram->SetStats(false);
  dummyHistogram->SetMaximum(yMax);
  dummyHistogram->SetMinimum(yMin);
  
  TAxis* xAxis = dummyHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.data());
  xAxis->SetTitleOffset(xAxisOffset);
  
  TAxis* yAxis = dummyHistogram->GetYaxis();
  yAxis->SetTitle(yAxisTitle.data());
  yAxis->SetTitleOffset(yAxisOffset);

  dummyHistogram->Draw();

  int colors[6] = { 1, 2, 3, 4, 6, 7 };
  int markerStyles[6] = { 22, 32, 20, 24, 21, 25 };

  int numGraphs = 1;
  if ( histogram2_numerator && histogram2_denominator ) ++numGraphs;
  if ( histogram3_numerator && histogram3_denominator ) ++numGraphs;
  if ( histogram4_numerator && histogram4_denominator ) ++numGraphs;
  if ( histogram5_numerator && histogram5_denominator ) ++numGraphs;
  if ( histogram6_numerator && histogram6_denominator ) ++numGraphs;

  TLegend* legend = new TLegend(legendX0, legendY0, legendX0 + 0.18, legendY0 + 0.05*numGraphs, "", "brNDC"); 
  legend->SetBorderSize(0);
  legend->SetFillColor(0);
  
  TGraphAsymmErrors* graph1 = getEfficiency(histogram1_numerator, histogram1_denominator);
  graph1->SetLineColor(colors[0]);
  graph1->SetMarkerColor(colors[0]);
  graph1->SetMarkerStyle(markerStyles[0]);
  graph1->Draw("p");
  legend->AddEntry(graph1, legendEntry1.data(), "p");    

  TGraphAsymmErrors* graph2 = 0;
  if ( histogram2_numerator && histogram2_denominator ) {
    graph2 = getEfficiency(histogram2_numerator, histogram2_denominator);
    graph2->SetLineColor(colors[1]);
    graph2->SetMarkerColor(colors[1]);
    graph2->SetMarkerStyle(markerStyles[1]);
    graph2->Draw("p");
    legend->AddEntry(graph2, legendEntry2.data(), "p");
  }

  TGraphAsymmErrors* graph3 = 0;
  if ( histogram3_numerator && histogram3_denominator ) {
    graph3 = getEfficiency(histogram3_numerator, histogram3_denominator);
    graph3->SetLineColor(colors[2]);
    graph3->SetMarkerColor(colors[2]);
    graph3->SetMarkerStyle(markerStyles[2]);
    graph3->Draw("p");
    legend->AddEntry(graph3, legendEntry3.data(), "p");
  }
  
  TGraphAsymmErrors* graph4 = 0;
  if ( histogram4_numerator && histogram4_denominator ) {
    graph4 = getEfficiency(histogram4_numerator, histogram4_denominator);
    graph4->SetLineColor(colors[3]);
    graph4->SetMarkerColor(colors[3]);
    graph4->SetMarkerStyle(markerStyles[3]);
    graph4->Draw("p");
    legend->AddEntry(graph4, legendEntry4.data(), "p");
  }

  TGraphAsymmErrors* graph5 = 0;
  if ( histogram5_numerator && histogram5_denominator ) {
    graph5 = getEfficiency(histogram5_numerator, histogram5_denominator);
    graph5->SetLineColor(colors[4]);
    graph5->SetMarkerColor(colors[4]);
    graph5->SetMarkerStyle(markerStyles[4]);
    graph5->Draw("p");
    legend->AddEntry(graph5, legendEntry5.data(), "p");
  }
  
  TGraphAsymmErrors* graph6 = 0;
  if ( histogram6_numerator && histogram6_denominator ) {
    graph6 = getEfficiency(histogram6_numerator, histogram6_denominator);
    graph6->SetLineColor(colors[5]);
    graph6->SetMarkerColor(colors[5]);
    graph6->SetMarkerStyle(markerStyles[5]);
    graph6->Draw("p");
    legend->AddEntry(graph6, legendEntry6.data(), "p");
  }

  legend->Draw();

  TPaveText* label = 0;
  if ( title.Length() > 0 ) {
    label = new TPaveText(0.175, 0.925, 0.48, 0.98, "NDC");
    label->AddText(title.Data());
    label->SetTextAlign(13);
    label->SetTextSize(0.045);
    label->SetFillStyle(0);
    label->SetBorderSize(0);
    label->Draw();
  }

  canvas->Update();
  size_t idx = outputFileName.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName, 0, idx);
  if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
  canvas->Print(std::string(outputFileName_plot).append(".png").data());
  canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
  
  delete legend;
  delete label;
  delete dummyHistogram;
  delete canvas;
}
void makePlot(TCanvas* canvas, const std::string& outputFileName, TTree* testTree, const std::string& varName, 
	      unsigned numBinsX, double xMin, double xMax)
{
  std::cout << "creating histogramTauIdPassed..." << std::endl;
  TString histogramTauIdPassedName = TString("histogramTauIdPassed").Append("_").Append(varName.data());
  TH1* histogramTauIdPassed = fillHistogram(testTree, varName, "type==1", "",
					    histogramTauIdPassedName.Data(), numBinsX, xMin, xMax);
  std::cout << "--> histogramTauIdPassed = " << histogramTauIdPassed << ":" 
	    << " integral = " << histogramTauIdPassed->Integral() << std::endl;

  std::cout << "creating histogramTauIdFailed..." << std::endl;
  TString histogramTauIdFailedName = TString("histogramTauIdFailed").Append("_").Append(varName.data());
  TH1* histogramTauIdFailed = fillHistogram(testTree, varName, "type==0", "",
					    histogramTauIdFailedName.Data(), numBinsX, xMin, xMax);
  std::cout << "--> histogramTauIdFailed = " << histogramTauIdFailed 
	    << " integral = " << histogramTauIdFailed->Integral() << std::endl;

  std::cout << "creating histogramTauIdDenominator..." << std::endl;
  TString histogramTauIdDenominatorName = TString("histogramTauIdDenominator").Append("_").Append(varName.data());
  TH1* histogramTauIdDenominator = new TH1F(histogramTauIdDenominatorName.Data(), 
					    histogramTauIdDenominatorName.Data(), numBinsX, xMin, xMax);
  histogramTauIdDenominator->Add(histogramTauIdPassed);
  histogramTauIdDenominator->Add(histogramTauIdFailed);
  std::cout << "--> histogramTauIdDenominator = " << histogramTauIdDenominator 
	    << " integral = " << histogramTauIdDenominator->Integral() << std::endl;

  std::cout << "creating histogramFakeRate..." << std::endl;
  TString histogramFakeRateName = TString("histogramFakeRate").Append("_").Append(varName.data());
  TH1* histogramFakeRate = new TH1F(histogramFakeRateName.Data(), 
				    histogramFakeRateName.Data(), numBinsX, xMin, xMax);
  histogramFakeRate->Add(histogramTauIdPassed);
  histogramFakeRate->Divide(histogramTauIdDenominator);
  std::cout << "--> histogramFakeRate = " << histogramFakeRate 
	    << " integral = " << histogramFakeRate->Integral() << std::endl;

  std::cout << "creating histogramFakeRateWeighted..." << std::endl;
  TString histogramFakeRateWeightedName = TString("histogramFakeRateWeighted").Append("_").Append(varName.data());
  TH1* histogramFakeRateWeighted = fillHistogram(testTree, varName, "", "MVA_KNN", 
						 histogramFakeRateWeightedName.Data(), numBinsX, xMin, xMax);
  histogramFakeRateWeighted->Divide(histogramTauIdDenominator);
  std::cout << "--> histogramFakeRateWeighted = " << histogramFakeRateWeighted 
	    << " entries = " << histogramFakeRateWeighted->GetEntries() << ","
	    << " integral = " << histogramFakeRateWeighted->Integral() << std::endl;
  // Scale the weighted fake rate histogram

  histogramFakeRate->SetTitle(varName.data());
  histogramFakeRate->SetStats(false);
  histogramFakeRate->SetMinimum(1.e-4);
  histogramFakeRate->SetMaximum(1.e+1);
  histogramFakeRate->SetLineColor(2);
  histogramFakeRate->SetLineWidth(2);
  histogramFakeRate->SetMarkerStyle(20);
  histogramFakeRate->SetMarkerColor(2);
  histogramFakeRate->SetMarkerSize(1);
  histogramFakeRate->Draw("e1p");

  histogramFakeRateWeighted->SetLineColor(4);
  histogramFakeRateWeighted->SetLineWidth(2);
  histogramFakeRateWeighted->SetMarkerStyle(24);
  histogramFakeRateWeighted->SetMarkerColor(4);
  histogramFakeRateWeighted->SetMarkerSize(1);
  histogramFakeRateWeighted->Draw("e1psame");

  TLegend legend(0.11, 0.73, 0.31, 0.89);
  legend.SetBorderSize(0);
  legend.SetFillColor(0);
  legend.AddEntry(histogramFakeRate, "Tau id. discr.", "p");
  legend.AddEntry(histogramFakeRateWeighted, "Fake-Rate weight", "p");
  legend.Draw();

  canvas->Update();
  canvas->Print(outputFileName.data());
}
Ejemplo n.º 29
0
void patBJetTracks_efficiencies()
{
	// define proper canvas style
	setNiceStyle();
	gStyle->SetOptStat(0);

	// open file
	TFile* file = new TFile("analyzePatBJetTracks.root");

	TLegend *legend[3] = { 0, 0, 0 };

	// draw canvas with efficiencies

	TCanvas *canv;
	canv = new TCanvas("canv0", "hand-crafted track counting efficiencies", 800, 300);
	canv->Divide(3, 1);

	TH1 *total = (TH1*)file->Get(Form("%s/flavours", directory));
	TH1 *effVsCutB = 0;
	unsigned int i = 0;
	for(const char **flavour = flavours; *flavour; flavour++, i++) {
		TH1 *h = (TH1*)file->Get(Form("%s/trackIPSig_%s", directory, *flavour));
		TH1 *discrShape = (TH1*)h->Clone(Form("%s_discrShape", h->GetName()));
		discrShape->Scale(1.0 / discrShape->Integral());
		discrShape->SetMaximum(discrShape->GetMaximum() * 5);
		TH1 *effVsCut = computeEffVsCut(h, total->GetBinContent(4 - i));
		TH1 *effVsBEff = 0;

		if (flavour == flavours)	// b-jets
			effVsCutB = effVsCut;
		else
			effVsBEff = computeEffVsBEff(effVsCut, effVsCutB);

		discrShape->SetTitle("discriminator shape");
		effVsCut->SetTitle("efficiency versus discriminator cut");
		if (effVsBEff)
			effVsBEff->SetTitle("mistag versus b efficiency");

		setHistStyle(discrShape);
		setHistStyle(effVsCut);
		setHistStyle(effVsBEff);

		canv->cd(1);
		gPad->SetLogy(1);
		gPad->SetGridy(1);
		discrShape->SetLineColor(i + 1);
		discrShape->SetMarkerColor(i + 1);
		discrShape->Draw(i > 0 ? "same" : "");
		if (!legend[0])
			legend[0] = new TLegend(0.5, 0.7, 0.78, 0.88);
		legend[0]->AddEntry(discrShape, *flavour);

		canv->cd(2);
		gPad->SetLogy(1);
		gPad->SetGridy(1);
		effVsCut->SetLineColor(i + 1);
		effVsCut->SetMarkerColor(i + 1);
		effVsCut->Draw(i > 0 ? "same" : "");
		if (!legend[1])
			legend[1] = new TLegend(0.12, 0.12, 0.40, 0.30);
		legend[1]->AddEntry(effVsCut, *flavour);

		if (!effVsBEff)
			continue;
		canv->cd(3);
		gPad->SetLogy(1);
		gPad->SetGridx(1);
		gPad->SetGridy(1);
		effVsBEff->SetLineColor(i + 1);
		effVsBEff->SetMarkerColor(i + 1);
		effVsBEff->Draw(i > 1 ? "same" : "");
		if (!legend[2])
			legend[2] = new TLegend(0.12, 0.7, 0.40, 0.88);
		legend[2]->AddEntry(effVsBEff, *flavour);
	}

	canv->cd(1);
	legend[0]->Draw();

	canv->cd(2);
	legend[1]->Draw();

	canv->cd(3);
	legend[2]->Draw();

	////////////////////////////////////////////

	// canvas to compare negative tagger with light flavour mistag

	TCanvas *canv;
	canv = new TCanvas("canv1", "comparing light flavour mistag with negative tagger", 530, 300);
	canv->Divide(2, 1);

	TH1 *h1 = (TH1*)file->Get(Form("%s/trackIPSig_udsg", directory));
	TH1 *h2 = (TH1*)file->Get(Form("%s/negativeIPSig_all", directory));
	h2 = invertHisto(h2);	// invert x-axis

	TH1 *discrShape1 = (TH1*)h1->Clone("discrShape1");
	TH1 *discrShape2 = (TH1*)h2->Clone("discrShape2");

	discrShape1->Scale(1.0 / discrShape1->Integral());
	discrShape1->SetMaximum(discrShape1->GetMaximum() * 5);
	discrShape2->Scale(1.0 / discrShape2->Integral());

	TH1 *effVsCut1 = computeEffVsCut(h1, total->GetBinContent(2));
	TH1 *effVsCut2 = computeEffVsCut(h2, total->GetBinContent(1));

	discrShape1->SetTitle("discriminator shape");
	effVsCut1->SetTitle("efficiency versus discriminator cut");

	setHistStyle(discrShape1);
	setHistStyle(discrShape2);
	setHistStyle(effVsCut1);
	setHistStyle(effVsCut2);

	canv->cd(1);
	gPad->SetLogy(1);
	gPad->SetGridy(1);
	discrShape1->SetLineColor(1);
	discrShape1->SetMarkerColor(1);
	discrShape2->SetLineColor(2);
	discrShape2->SetMarkerColor(2);

	discrShape1->Draw();
	discrShape2->Draw("same");

	TLegend *l = new TLegend(0.5, 0.7, 0.78, 0.88);
	l->AddEntry(discrShape1, "udsg");
	l->AddEntry(discrShape2, "inv. neg");
	l->Draw();

	canv->cd(2);
	gPad->SetLogy(1);
	gPad->SetGridy(1);
	effVsCut1->SetLineColor(1);
	effVsCut1->SetMarkerColor(1);
	effVsCut2->SetLineColor(2);
	effVsCut2->SetMarkerColor(2);

	effVsCut1->Draw();
	effVsCut2->Draw("same");

	l = new TLegend(0.5, 0.7, 0.78, 0.88);
	l->AddEntry(effVsCut1, "udsg");
	l->AddEntry(effVsCut2, "inv. neg");
	l->Draw();
}
void showGraphs(const TString& title, double canvasSizeX, double canvasSizeY,
		TGraph* graph1, const std::string& legendEntry1,
		TGraph* graph2, const std::string& legendEntry2,
		TGraph* graph3, const std::string& legendEntry3,
		TGraph* graph4, const std::string& legendEntry4,
		TGraph* graph5, const std::string& legendEntry5,
		TGraph* graph6, const std::string& legendEntry6,
		double xMin, double xMax, unsigned numBinsX, const std::string& xAxisTitle, double xAxisOffset,
		double yMin, double yMax, const std::string& yAxisTitle, double yAxisOffset,
		double legendX0, double legendY0, 
		const std::string& outputFileName)
{
  TCanvas* canvas = new TCanvas("canvas", "canvas", canvasSizeX, canvasSizeY);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2);
  canvas->SetLeftMargin(0.12);
  canvas->SetBottomMargin(0.12);

  int colors[6] = { 1, 2, 3, 4, 6, 7 };
  int markerStyles[6] = { 22, 32, 20, 24, 21, 25 };

  TLegend* legend = new TLegend(legendX0, legendY0, legendX0 + 0.44, legendY0 + 0.20, "", "brNDC"); 
  legend->SetBorderSize(0);
  legend->SetFillColor(0);

  TH1* dummyHistogram = new TH1D("dummyHistogram", "dummyHistogram", numBinsX, xMin, xMax);
  dummyHistogram->SetTitle("");
  dummyHistogram->SetStats(false);
  dummyHistogram->SetMinimum(yMin);
  dummyHistogram->SetMaximum(yMax);

  TAxis* xAxis = dummyHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.data());
  xAxis->SetTitleOffset(xAxisOffset);

  TAxis* yAxis = dummyHistogram->GetYaxis();
  yAxis->SetTitle(yAxisTitle.data());
  yAxis->SetTitleOffset(yAxisOffset);

  dummyHistogram->Draw("axis");

  graph1->SetLineColor(colors[0]);
  graph1->SetLineWidth(2);
  graph1->Draw("L");
  legend->AddEntry(graph1, legendEntry1.data(), "l");

  if ( graph2 ) {
    graph2->SetLineColor(colors[1]);
    graph2->SetLineWidth(2);
    graph2->Draw("L");
    legend->AddEntry(graph2, legendEntry2.data(), "l");
  }
  
  if ( graph3 ) {
    graph3->SetLineColor(colors[2]);
    graph3->SetLineWidth(2);
    graph3->Draw("L");
    legend->AddEntry(graph3, legendEntry3.data(), "l");
  }

  if ( graph4 ) {
    graph4->SetLineColor(colors[3]);
    graph4->SetLineWidth(2);
    graph4->Draw("L");
    legend->AddEntry(graph4, legendEntry4.data(), "l");
  }

  if ( graph5 ) {
    graph5->SetLineColor(colors[4]);
    graph5->SetLineWidth(2);
    graph5->Draw("L");
    legend->AddEntry(graph5, legendEntry5.data(), "l");
  }

  if ( graph6 ) {
    graph6->SetLineColor(colors[5]);
    graph6->SetLineWidth(2);
    graph6->Draw("L");
    legend->AddEntry(graph6, legendEntry6.data(), "l");
  }
  
  legend->Draw();
    
  TPaveText* label = 0;
  if ( title.Length() > 0 ) {
    label = new TPaveText(0.175, 0.925, 0.48, 0.98, "NDC");
    label->AddText(title.Data());
    label->SetTextAlign(13);
    label->SetTextSize(0.045);
    label->SetFillStyle(0);
    label->SetBorderSize(0);
    label->Draw();
  }

  canvas->Update();
  size_t idx = outputFileName.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName, 0, idx);
  if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
  canvas->Print(std::string(outputFileName_plot).append(".png").data());
  canvas->Print(std::string(outputFileName_plot).append(".pdf").data());
  
  delete legend;
  delete label;
  delete dummyHistogram;
  delete canvas;  
}