Example #1
0
void SimplePlot2D(){

  //string filename = "data/scan_CH1-64_unmasked.root";
  //string filename = "data/scan_CH1-50_masked.root";
  string filename = "test.root";
  string varXname = "VMM #";
  string varYname = "CH #";
  
  // delay count stuff
  int CH = 21;
  double delays[5];
  double count_tot[5];
  double count_right[5];
  for(int i = 0; i < 5; i++){
    delays[i] = double(i)*5.;
    count_tot[i] = 0.;
    count_right[i] = 0.;
  }
  
      

  ///////////////////////////////////////////////////////
  
  TChain* tree = new TChain("MMFE8","MMFE8");

  tree->AddFile(filename.c_str());

  MMFE8Base* base = new MMFE8Base(tree);

  int N = tree->GetEntries();

  TH2D* hist = new TH2D("hist","hist", 8, 0.5, 8.5, 64, 0.5,64.5);
  TH2D* histN = (TH2D*) hist->Clone("norm");
  TH2D* histchch = new TH2D("histchch","histchch", 64, 0.5, 64.5, 64, 0.5,64.5);
  TH2D* histDelay = new TH2D("histN","histN", 31, 9.5, 40.5, 5,-0.5, 4.5);	
  TH2D* histDelayD = new TH2D("histD","histD", 31, 9.5, 40.5, 5,-0.5, 4.5);

  for(int i = 0; i < N; i++){
    base->GetEntry(i);
    
    if(base->CHpulse == CH){
      //count_tot[base->Delay] += 1.;
      count_tot[(base->TPDAC-80)/20] += 1.;
      if(base->CHpulse == base->CHword)
	//count_right[base->Delay] += base->TDO;
      	count_right[(base->TPDAC-80)/20] += base->PDO;
    }

    //histDelayD->Fill(base->CHpulse,base->Delay);
    histDelayD->Fill(base->CHpulse,(base->TPDAC-80)/20);
    if(base->CHpulse == base->CHword)
      //histDelay->Fill(base->CHpulse,base->Delay,base->TDO);
      histDelay->Fill(base->CHpulse,(base->TPDAC-80)/20,base->PDO);

    if((base->CHpulse != base->CHword || true) &&
       base->VMM == 6)
      histchch->Fill(base->CHpulse,base->CHword);

    if(base->CHpulse != base->CHword)
      continue;

    hist->Fill(base->VMM,base->CHpulse,base->PDO);
    histN->Fill(base->VMM,base->CHpulse);
  
  }

  for(int x = 0; x < 8; x++){
    for(int y = 0; y < 64; y++){
      double v = hist->GetBinContent(x+1,y+1);
      double N = histN->GetBinContent(x+1,y+1);
      hist->SetBinContent(x+1,y+1,v/max(int(N),1));
    }
  }
  
  TLatex l;
  //l.NDC();

  TCanvas* can = new TCanvas("can","can",600,500);
  can->SetTopMargin(0.05);
  can->SetLeftMargin(0.12);
  can->SetRightMargin(0.15);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  can->Draw();
  can->SetGridx();
  can->SetGridy();
  
  can->cd();

  hist->Draw("COLZ");
  
  hist->GetXaxis()->SetTitle(varXname.c_str());
  hist->GetXaxis()->CenterTitle();
  hist->GetYaxis()->SetTitle(varYname.c_str());
  hist->GetYaxis()->CenterTitle();
  hist->GetYaxis()->SetTitleOffset(1.4);
  hist->GetYaxis()->CenterTitle();
  //hist->GetYaxis()->SetRangeUser(0.,hist->GetMaximum()*1.1) ;

  TCanvas* canN = new TCanvas("canN","canN",600,500);
  canN->SetTopMargin(0.05);
  canN->SetLeftMargin(0.12);
  canN->SetRightMargin(0.15);

  canN->Draw();
  canN->SetGridx();
  canN->SetGridy();
  
  canN->cd();

  histN->Draw("COLZ");
  
  histN->GetXaxis()->SetTitle(varXname.c_str());
  histN->GetXaxis()->CenterTitle();
  histN->GetYaxis()->SetTitle(varYname.c_str());
  histN->GetYaxis()->CenterTitle();
  histN->GetYaxis()->SetTitleOffset(1.4);
  histN->GetYaxis()->CenterTitle();
			     
  TCanvas* canchch = new TCanvas("canchch","canchch",600,500);
  canchch->SetTopMargin(0.05);
  canchch->SetLeftMargin(0.12);
  canchch->SetRightMargin(0.15);

  canchch->Draw();
  canchch->SetGridx();
  canchch->SetGridy();
  
  canchch->cd();
  histchch->Draw("COLZ");
  
  histchch->GetXaxis()->SetTitle("CH pulsed");
  histchch->GetXaxis()->CenterTitle();
  histchch->GetYaxis()->SetTitle("CH data");
  histchch->GetYaxis()->CenterTitle();
  histchch->GetYaxis()->SetTitleOffset(1.4);
  histchch->GetYaxis()->CenterTitle();
  histchch->GetZaxis()->SetTitle("Number of data events");
  histchch->GetZaxis()->SetTitleOffset(1.4);
  histchch->GetZaxis()->CenterTitle();
 
  l.DrawLatex(.54,65.2,"VMM 2");

  TCanvas* can_delay = new TCanvas("can_delay","can_delay",600,500);
  can_delay->Draw();
  can_delay->cd();

  for(int i = 0; i < 5; i++)
    count_tot[i] = count_right[i]/count_tot[i];
  TGraph* gr = new TGraph(5,delays,count_tot);
  gr->SetMarkerSize(4);
  gr->SetMarkerStyle(5);
  gr->Draw("AP");

  histDelay->Divide(histDelayD);

  TCanvas* canDelay = new TCanvas("canDelay","canDelay",600,500);
  canDelay->SetTopMargin(0.05);
  canDelay->SetLeftMargin(0.12);
  canDelay->SetRightMargin(0.15);

  canDelay->Draw();
  canDelay->SetGridx();
  canDelay->SetGridy();
  
  canDelay->cd();
  histDelay->Draw("COLZ");
  
  histDelay->GetXaxis()->SetTitle("CH pulsed");
  histDelay->GetXaxis()->CenterTitle();
  histDelay->GetYaxis()->SetTitle("Delay Count");
  histDelay->GetYaxis()->CenterTitle();
  histDelay->GetYaxis()->SetTitleOffset(1.4);
  histDelay->GetYaxis()->CenterTitle();
  histDelay->GetZaxis()->SetTitle("Fraction zeroes");
  histDelay->GetZaxis()->SetTitleOffset(1.4);
  histDelay->GetZaxis()->CenterTitle();
}
Example #2
0
void ConfidenceIntervals()
{
//Illustrates TVirtualFitter::GetConfidenceIntervals
//This method computes confidence intervals for the fitted function
//Author: Anna Kreshuk
   
   TCanvas *myc = new TCanvas("myc", 
      "Confidence intervals on the fitted function",1200, 500);
   myc->Divide(3,1);

/////1. A graph
   //Create and fill a graph
   Int_t ngr = 100;
   TGraph *gr = new TGraph(ngr);
   gr->SetName("GraphNoError");
   Double_t x, y;
   Int_t i;
   for (i=0; i<ngr; i++){
      x = gRandom->Uniform(-1, 1);
      y = -1 + 2*x + gRandom->Gaus(0, 1);
      gr->SetPoint(i, x, y);
   }
   //Create the fitting function
   TF1 *fpol = new TF1("fpol", "pol1", -1, 1);
   fpol->SetLineWidth(2);
   gr->Fit(fpol, "Q");

   //Create a TGraphErrors to hold the confidence intervals
   TGraphErrors *grint = new TGraphErrors(ngr);
   grint->SetTitle("Fitted line with .95 conf. band");
   for (i=0; i<ngr; i++)
      grint->SetPoint(i, gr->GetX()[i], 0);
   //Compute the confidence intervals at the x points of the created graph
   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint);
   //Now the "grint" graph contains function values as its y-coordinates
   //and confidence intervals as the errors on these coordinates
   //Draw the graph, the function and the confidence intervals
   myc->cd(1);
   grint->SetLineColor(kRed);
   grint->Draw("ap");
   gr->SetMarkerStyle(5);
   gr->SetMarkerSize(0.7);
   gr->Draw("psame");

/////2. A histogram
   myc->cd(2);
   //Create, fill and fit a histogram
   Int_t nh=5000;
   TH1D *h = new TH1D("h", 
      "Fitted gaussian with .95 conf.band", 100, -3, 3);
   h->FillRandom("gaus", nh);
   TF1 *f = new TF1("fgaus", "gaus", -3, 3);
   f->SetLineWidth(2);
   h->Fit(f, "Q");
   h->Draw();
   
   //Create a histogram to hold the confidence intervals
   TH1D *hint = new TH1D("hint", 
      "Fitted gaussian with .95 conf.band", 100, -3, 3);
   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(hint);
   //Now the "hint" histogram has the fitted function values as the 
   //bin contents and the confidence intervals as bin errors
   hint->SetStats(kFALSE);
   hint->SetFillColor(2);
   hint->Draw("e3 same");

/////3. A 2d graph
   //Create and fill the graph
   Int_t ngr2 = 100;
   Double_t z, rnd, e=0.3;
   TGraph2D *gr2 = new TGraph2D(ngr2);
   gr2->SetName("Graph2DNoError");
   TF2  *f2 = new TF2("f2",
      "1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+250",-6,6,-6,6);
   f2->SetParameters(1,1);
   for (i=0; i<ngr2; i++){
      f2->GetRandom2(x,y);
      // Generate a random number in [-e,e]
      rnd = 2*gRandom->Rndm()*e-e; 
      z = f2->Eval(x,y)*(1+rnd);
      gr2->SetPoint(i,x,y,z);
   }
   //Create a graph with errors to store the intervals
   TGraph2DErrors *grint2 = new TGraph2DErrors(ngr2);
   for (i=0; i<ngr2; i++)
      grint2->SetPoint(i, gr2->GetX()[i], gr2->GetY()[i], 0);

   //Fit the graph
   f2->SetParameters(0.5,1.5);
   gr2->Fit(f2, "Q");
   //Compute the confidence intervals
   (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint2);   
   //Now the "grint2" graph contains function values as z-coordinates
   //and confidence intervals as their errors
   //draw
   myc->cd(3);
   f2->SetNpx(30);
   f2->SetNpy(30);
   f2->SetFillColor(kBlue);
   f2->Draw("surf4");
   grint2->SetNpx(20);
   grint2->SetNpy(20);
   grint2->SetMarkerStyle(24);
   grint2->SetMarkerSize(0.7);
   grint2->SetMarkerColor(kRed);
   grint2->SetLineColor(kRed);
   grint2->Draw("E0 same");
   grint2->SetTitle("Fitted 2d function with .95 error bars");

   myc->cd();

}
Example #3
0
void errftest()
{
  
  gSystem->Load("libRooFitCore.so");
  gSystem->Load("libRooFitModels.so");
  
  // Define some free parameters to use 
  Double_t t = 2;
  Double_t t0 = 1.51;
  Double_t dm = 0.51; 
  Double_t s = 0.5;
  Double_t tag = 1;
  
  //Define the timers
  Double_t timer1R[20]=0;
  Double_t timer1C[20]=0;
  Double_t timer2R[20]=0;
  Double_t timer2C[20]=0;
  Double_t xi[20]=0;
  
  //Declare everything so we don't have to redeclare in loop
  Double_t tcompare,aa,bb,cc,evilterm1,evilterm2,wzreneg1,wzreneg2,func1,func2;
  Complex_t wz1;
  RooComplex wz2;
  
  //loop over t
  for (Int_t ij = 0.; ij<20; ij++){
    
    // do the test!!!
    //complexmath calculation
    TStopwatch *time1 = new TStopwatch();
    time1.Start();
    
    for(Int_t n = 0.; n<50; n++){
      
      t = -4 + 0.36*n;
      
      aa = (t/(TMath::Sqrt(2.)*s)) - (s/(TMath::Sqrt(2.)*t0));  
      bb = (s*s/(2.*t0*t0)) - t/t0;
      cc = s*dm/(TMath::Sqrt(2.));
      
      if(t >= tcompare){
	evilterm1=TMath::Exp(-(cc*cc))*2*TMath::Cos(2*aa*cc);
	evilterm2=TMath::Exp(-(cc*cc))*2*TMath::Cos(2*aa*cc);   
      }else if(t<= -tcompare){    
	evilterm1=0;
	evilterm2=0;    
      }else{
	
	wz1 = cxerf(cc,-aa);
	wzreneg1 = re(wz1);    
	evilterm1=TMath::Exp(-(aa*aa))*wzreneg1;
	func1 = 1./(2.*t0)*TMath::Exp(bb)*( 1 + TMath::Erf(aa) - tag*evilterm1 );
      }
    }
    
    time1.Stop();
    timer1R[ij] = time1.RealTime();
    timer1C[ij] = time1.CpuTime();
    
    //roomath calculation
    TStopwatch *time2 = new TStopwatch();
    time2.Start();
    
    for(Int_t n = 0.; n<50; n++){
      
      t = -4 + 0.36*n;
      
      aa = (t/(TMath::Sqrt(2.)*s)) - (s/(TMath::Sqrt(2.)*t0));  
      bb = (s*s/(2.*t0*t0)) - t/t0;
      cc = s*dm/(TMath::Sqrt(2.));
      
      if(t >= tcompare){
	evilterm1=TMath::Exp(-(cc*cc))*2*TMath::Cos(2*aa*cc);
	evilterm2=TMath::Exp(-(cc*cc))*2*TMath::Cos(2*aa*cc);   
      }else if(t<= -tcompare){    
	evilterm1=0;
	evilterm2=0;    
      }else{
	
	wz2 = RooMath::ComplexErrFunc(cc,-aa);
	wzreneg2 = wz2.re();    
	evilterm2=TMath::Exp(-(aa*aa))*wzreneg2;
	func2 = 1./(2.*t0)*TMath::Exp(bb)*( 1 + TMath::Erf(aa) - tag*evilterm2 );
      }
    }
    time2.Stop();
    timer2R[ij] = time2.RealTime();
    timer2C[ij] = time2.CpuTime();  
    xi[ij]=ij;
  }

  gROOT->SetStyle("Plain");

  TCanvas *realtime = new TCanvas("realtime", "realtime_compare", 500,500);
  realtime->SetGrid();

  TGraph *complextestRT = new TGraph(20,xi,timer1R);
  complextestRT->SetName("complextest-RT");
  complextestRT->SetTitle("Complexmath Test: Real Time");
  complextestRT->SetMarkerStyle(30);
  complextestRT->SetMarkerSize(2);
  complextestRT->Draw("ALP");
  
  TGraph *roofittestRT = new TGraph(20,xi,timer2R);
  roofittestRT->SetName("roofittest-RT");
  roofittestRT->SetMarkerStyle(29);
  roofittestRT->SetMarkerSize(1);
  roofittestRT->SetMarkerColor(4);
  roofittestRT->Draw("LP");
  
  TCanvas *cputime = new TCanvas("cputime", "cputime_compare", 500,500);
  cputime->SetGrid(); 

  TGraph *complextestCT = new TGraph(20,xi,timer1C);
  complextestCT->SetName("complextest-CT");
  complextestCT->SetTitle("Complexmath Test: CPU Time");
  complextestCT->SetMarkerStyle(30);
  complextestCT->SetMarkerSize(2);
  complextestCT->Draw("ALP");
  
  TGraph *roofittestCT = new TGraph(20,xi,timer2C);
  roofittestCT->SetName("roofittest-CT");
  roofittestCT->SetMarkerStyle(29);
  roofittestCT->SetMarkerSize(1);
  roofittestCT->SetMarkerColor(4);
  roofittestCT->Draw("LP");
  
}
Example #4
0
void quantiles() {
   // demo for quantiles
   // Author; Rene Brun
   const Int_t nq = 100;
   const Int_t nshots = 10;
   Double_t xq[nq];  // position where to compute the quantiles in [0,1]
   Double_t yq[nq];  // array to contain the quantiles
   for (Int_t i=0;i<nq;i++) xq[i] = Float_t(i+1)/nq;

   TGraph *gr70 = new TGraph(nshots);
   TGraph *gr90 = new TGraph(nshots);
   TGraph *gr98 = new TGraph(nshots);
   TH1F *h = new TH1F("h","demo quantiles",50,-3,3);
   
   for (Int_t shot=0;shot<nshots;shot++) {
      h->FillRandom("gaus",50);
      h->GetQuantiles(nq,yq,xq);
      gr70->SetPoint(shot,shot+1,yq[70]);
      gr90->SetPoint(shot,shot+1,yq[90]);
      gr98->SetPoint(shot,shot+1,yq[98]);
   }
   
   //show the original histogram in the top pad
   TCanvas *c1 = new TCanvas("c1","demo quantiles",10,10,600,900);
   c1->SetFillColor(41);
   c1->Divide(1,3);
   c1->cd(1);
   h->SetFillColor(38);
   h->Draw();
   
   // show the final quantiles in the middle pad
   c1->cd(2);
   gPad->SetFrameFillColor(33);
   gPad->SetGrid();
   TGraph *gr = new TGraph(nq,xq,yq);
   gr->SetTitle("final quantiles");
   gr->SetMarkerStyle(21);
   gr->SetMarkerColor(kRed);
   gr->SetMarkerSize(0.3);
   gr->Draw("ap");
   
   // show the evolution of some  quantiles in the bottom pad
   c1->cd(3);
   gPad->SetFrameFillColor(17);
   gPad->DrawFrame(0,0,nshots+1,3.2);
   gPad->SetGrid();
   gr98->SetMarkerStyle(22);
   gr98->SetMarkerColor(kRed);
   gr98->Draw("lp");
   gr90->SetMarkerStyle(21);
   gr90->SetMarkerColor(kBlue);
   gr90->Draw("lp");
   gr70->SetMarkerStyle(20);
   gr70->SetMarkerColor(kMagenta);
   gr70->Draw("lp");
   // add a legend
   TLegend *legend = new TLegend(0.85,0.74,0.95,0.95);
   legend->SetTextFont(72);
   legend->SetTextSize(0.05);
   legend->AddEntry(gr98," q98","lp");
   legend->AddEntry(gr90," q90","lp");
   legend->AddEntry(gr70," q70","lp");
   legend->Draw();
}
void fit(){
  //int NumberOfLines();
  string input_name;
  cout << "Archivo de datos sin extension \n";
  cin >>  input_name;



  //const char *input_name = "para_grafica";
  string name = input_name+".txt";
  cout << name;
  ifstream file(name.c_str());

if (!file) {
  cout << "Archivo no encontado \n";
}
else{
  int N_Lines = NumberOfLines(file);
  printf("Number of lines: %i \n", N_Lines);

  int j = 0;
  float t, P;

  //int LinesCont = NumberOfLines(archivo);

   TVectorD X(N_Lines+1);
   TVectorD Y(N_Lines+1);

  while (!file.eof()){
    file >> t >> P;
    //printf("%i, %f, %f \n", j, t, P);
    //getchar();

    X(j) = t;
    Y(j) = P;

    ++j;

  }
  TCanvas *Grafico = new TCanvas("Grafico", "Grafico de P contra t", 200, 10, 700, 500);
  TGraph *gr = new TGraph(X,Y);

  TF1 *f = new TF1 ("fit", FitFunction, 20, 3000, 2);
  f -> SetParameters(700, 0.5);
  f -> SetParNames("PresionControl", "VelocidadEfectiva");
  f ->SetLineStyle(1);
  f ->SetLineColor(kBlue);
  gr -> Fit("fit", "R");

  gr->SetMarkerColor(kPink - 9);

  gr->SetMarkerStyle(23);
  gr->SetMarkerSize(0.5);
  gr->SetTitle("P(t) Muestra I");
  gr->GetXaxis()->SetTitle("Tiempo (s)");
  gr->GetYaxis()->SetTitle("Presion (Torr)");
  gr->GetYaxis()->SetRange(-100, 800);
  gr->Draw("AP");

  leg = new TLegend(0.63,0.70,0.87,0.88);
  leg->SetHeader("Muestra");
  leg->AddEntry("f","P=P_{0} e^{-S t/V}", "l");
  leg->AddEntry("gr","P(t)","lep");
  leg->AddEntry((TObject*)0, Form("S = %f", f->GetParameter(1)), "");
  leg->AddEntry((TObject*)0, Form("#sigma_{S} = %f", f->GetParError(1)), "");
  leg->Draw();

  //Grafico.SetLogy();
  Grafico->SetGrid();
  Grafico->Update();
  string save_file = input_name+".png";
  Grafico->Print(save_file.c_str());
  //printf("%i", cont);
}


  cout << "Funciona" << endl;
  Hola();

}
Example #6
0
void AnalysisSparse(Bool_t save_output = kFALSE)
{
  gStyle->SetGridColor(kGray);
  //  TString tmpstr(fname);
  //  if (tmpstr.Contains("data")) {
  //    Printf("!!! Real Data !!!");
  //    mc = kFALSE;
  //  }
  TString gtitle = Form("Monte Carlo, %s", graph_name.Data());
  grapht = graph_name.Data();
  Double_t grx[999], gry[999], gry2[999], gry3[999], gry4[999],
    gry_eff[999], gry_fix[999], grxE[999];
  Double_t gry22[999], gry22E[999], grx22E[999];
  Double_t gry_true[999], gry_true_eff[999], gry_true_effE[999];
  TH1::AddDirectory(kFALSE);
  TFile::SetCacheFileDir(gSystem->HomeDirectory());
  TFile *f = TFile::Open(fname.Data(), "CACHEREAD");
  if (!f) return;
  TList *l; f->GetObject(lname.Data(), l);
  if (!l) return;
  Int_t bf[999], bl[999];
  Int_t nn = FindExactRange(((THnSparse *)(l->FindObject(s1name.Data())))->
                            Projection(1), del_step, bf, bl);
  //  Int_t nn = FindRange5(bf, bl);
  Bool_t binhaluska = kFALSE;
  if (binAnders) {
    nn = 8;
    bf[0] = 6;bf[1] =  9;bf[2] = 11;bf[3] = 16;bf[4] = 21;bf[5] = 26;
    bl[0] = 8;bl[1] = 10;bl[2] = 15;bl[3] = 20;bl[4] = 25;bl[5] = 30;

    bf[6] = 31;bf[7] = 41;
    bl[6] = 40;bl[7] = 50;
  }
  Printf("number of intervals = %d =>", nn);

  Int_t count = 0;
  Double_t ptmean = 0, value = 0;
  Int_t fitStatus = -1;
  gStyle->SetOptStat(0);
  TCanvas *c = new TCanvas("c", "Signal & Background");
  c->Divide(5, 5); c->Modified(); c->Draw();
  TCanvas *c2 = (TCanvas *)c->DrawClone("c2");
  c2->SetTitle("Phi mesons (raw)"); c2->Modified(); c2->Draw();
  TCanvas *c3, *c4;
  if (mc) {
    c3 = (TCanvas *)c->DrawClone("c3");
    c3->SetTitle("Phi mesons (gen)"); c3->Modified(); c3->Draw();
    c4 = (TCanvas *)c->DrawClone("c4");
    c4->SetTitle("Phi mesons (true)"); c4->Modified(); c4->Draw();
  }

  for (Int_t i = 0; i < nn; i++) {
    c->cd(count + 1)->SetGrid();
    h1 = (TH1D *)PullHisto(l, s1name.Data(), bf[i], bl[i], ptmean);
    h1->SetLineColor(kRed);
    h1->GetXaxis()->SetTitle("inv. mass, GeV/c^2");
    h1->Draw("hist");

    h3_p = (TH1D *)PullHisto(l, s3name_p.Data(), bf[i], bl[i], ptmean);
    h3_m = (TH1D *)PullHisto(l, s3name_m.Data(), bf[i], bl[i], ptmean);
    // !!!!!!!!!!!!!!!!!!!!!!!!
    if (count==0) h3_p = h1;
    // !!!!!!!!!!!!!!!!!!!!!!!!
    else {
      h3_p->Add(h3_m);
      //      h3_p->Add((TH1D *)PullHisto(l, smix.Data(), bf[i], bl[i], ptmean));
      //      h3_p->Add((TH1D *)PullHisto(l, smixpp.Data(), bf[i], bl[i], ptmean));
      //      h3_p->Add((TH1D *)PullHisto(l, smixmm.Data(), bf[i], bl[i], ptmean));
      Norm(h1, h3_p, norm[0], norm[1]);
    }
    h3_p->SetLineColor(kBlue);
    h3_p->Draw("hist, same");

    if (mc) {
      c3->cd(count + 1)->SetGrid();
      Printf("%s", s1namegen.Data());
      hg = (TH1D *)PullHisto(l, s1namegen.Data(), bf[i], bl[i], ptmean);
      hg->SetLineColor(kMagenta);
      hg->GetXaxis()->SetTitle("inv. mass, GeV/c^2");
      hg->Draw("hist");
      c4->cd(count + 1)->SetGrid();
      ht = (TH1D *)PullHisto(l, s1nametrue.Data(), bf[i], bl[i], ptmean);
      ht->SetLineColor(kMagenta-5);
      ht->GetXaxis()->SetTitle("inv. mass, GeV/c^2");
      ht->Draw("hist");
    }
    c2->cd(count + 1)->SetGrid();
    TH1 *hh = (TH1 *)h1->Clone("hh");
    hh->SetLineColor(kRed+1);
    hh->Add(h3_p, -1);
    /// !!!!!!!!!!!!!!!!!!!!!!
    //////////    if ((ilist == 3) && (count < 2)) hh->Reset();
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    hh->Draw("hist");

    // !!!!!!!!!!!!!!!!!!
    ff->SetParameters(0.1, 1.02, 0.004, -25000., 0., 0., 0.);
    ff->SetLineColor(hh->GetLineColor());
    ff->SetLineWidth(1);
    //    ff->SetLineStyle(kDashed);
    // where fit
    Double_t fmin = 1.02-2*0.004;
    Double_t fmax = 1.02+2*0.004;
    //    Double_t fmin = 0.995;
    //    Double_t fmax = 1.185;
    // !!!!!!!!!!!!!!!!!!
    Bool_t hisfun = kFALSE; // kFALSE = integral from function
    Double_t   hisfun_k = 1.0/hh->GetBinWidth(10);
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if (binhaluska)
      if (i > 9) hisfun_k = 0.5/hh->GetBinWidth(10);
    Printf("======= %f", hisfun_k);
    // !!!!!!!!!!!!!!!!!!
    // wehere integral (his or fun)
    Double_t fmini = 1.02-2*0.004;
    Double_t fmaxi = 1.02+2*0.004;
    hh->Fit(ff, "Q", "", fmin, fmax);
    hh->Fit(ff, "Q", "", fmin, fmax);
    fitStatus = hh->Fit(ff, "Q", "", fmin, fmax);
    TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax);
    pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4),
                       ff->GetParameter(5), ff->GetParameter(6));
    pp3->SetLineWidth(1);
    pp3->SetLineColor(h3_p->GetLineColor());
    pp3->Draw("same");
    // ff->SetRange(fmin, fmax);
    // ff->DrawCopy("same");

    value              = hh->Integral(hh->FindBin(fmini), hh->FindBin(fmaxi));
    if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k -
                   pp3->Integral(fmini, fmaxi)*hisfun_k;
    if (value < 0) value = 0;

    if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) {
      printf(" SKIP Data");
      value = 0;
    }
    grx[count] = ptmean;
    if (binhaluska) {
      if (count < 10) grxE[count] = 0.25; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      else            grxE[count] = 0.50; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    }
    else
      //      grxE[count] = (1.30-1.10)/2.0; // !!!!!!!!!!!!!!!!!!!!!!!!!!
      grxE[count] = 0.05;
    gry[count] = value;

    Double_t tmp1 = h1->Integral(h1->FindBin(fmini), h1->FindBin(fmaxi));
    Double_t tmp2 = h3_p->Integral(h3_p->FindBin(fmini), h3_p->FindBin(fmaxi));
    Double_t tmp_sg = tmp1 - tmp2;
    Double_t tmp_bg = tmp2;

    // if ((tmp_sg <= -tmp_bg) || (tmp_bg < 33.0)) {
    //   gry3[count] = 0.0;
    //   gry4[count] = 0.0;
    // }
    // else {
    gry3[count] = tmp_sg/tmp_bg;
    gry4[count] = tmp_sg/TMath::Sqrt(tmp_sg + tmp_bg);
    // }

    //    Printf("%4.2f, %10f, %10f, %10f", ptmean, tmp1, tmp2, gry3[count]);


    if (mc) {
      c3->cd(count + 1);
      // !!!!!!!!!!!!!!!!
      ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.);
      hg->Fit(ff, "Q", "", fmin, fmax);
      hg->Fit(ff, "Q", "", fmin, fmax);
      fitStatus = hg->Fit(ff, "Q", "", fmin, fmax);
      /*      TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax);
              pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4),
              ff->GetParameter(5), ff->GetParameter(6));
              pp3->SetLineWidth(1);
              pp3->SetLineColor(h3_p->GetLineColor());
              pp3->Draw("same");
      */

      value              = hg->Integral(hg->FindBin(fmini), hg->FindBin(fmaxi));
      if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k;
      //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k;
      if (value <= 0) value = -1;

      if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) {
        printf(" SKIP MC");
        value = -1;
      }
      gry2[count]    = value;
      Double_t superfactor = CalculateFactor(l, 0.1);
      if (useCF) {
        gry22E[i] = TMath::Sqrt(gry2[i])*superfactor;
        //        gry22E[i] = 0.0001;
        gry22[i]  = gry2[i]*superfactor;
        grx22E[i] = 0.05;
      }
      gry_eff[count] = gry[count]/gry2[count];

      c4->cd(count + 1);
      // !!!!!!!!!!!!!!!!
      ff->SetParameters(1, 1.02, 0.004, 0., 0., 0., 0.);
      ht->Fit(ff, "Q", "", fmin, fmax);
      ht->Fit(ff, "Q", "", fmin, fmax);
      fitStatus = ht->Fit(ff, "Q", "", fmin, fmax);
      /*      TF1 *pp3 = new TF1("pp3", "[0]+x*[1]+x*x*[2]+x*x*x*[3]", fmin, fmax);
              pp3->SetParameters(ff->GetParameter(3), ff->GetParameter(4),
              ff->GetParameter(5), ff->GetParameter(6));
              pp3->SetLineWidth(1);
              pp3->SetLineColor(h3_p->GetLineColor());
              pp3->Draw("same");
      */

      value              = ht->Integral(ht->FindBin(fmini), ht->FindBin(fmaxi));
      if (!hisfun) value = ff->Integral(fmini, fmaxi)*hisfun_k;
      //!!!!!!!!!!!!!!!!!!!pp3->Integral(fmini, fmaxi)*hisfun_k;
      if (value <= 0) value = -1;

      if ((fitStatus != 0) || (ff->GetParameter(2) > 0.1)) {
        printf(" SKIP true");
        value = -1;
      }
      gry_true[count]     = value;
      gry_true_eff[count] = gry_true[count]/gry2[count];
      // Propagation of uncertainty (A/B)
      Double_t AAA  = gry_true[count];
      Double_t AAAE = TMath::Sqrt(AAA);
      Double_t BBB  = gry2[count];
      Double_t BBBE = TMath::Sqrt(BBB);
      Double_t EEE  = TMath::Sqrt((AAAE/AAA)*(AAAE/AAA)+(BBBE/BBB)*(BBBE/BBB));
      EEE = EEE*gry_true_eff[count];
      gry_true_effE[count] = EEE;
    }

    Printf("=> %6.4f", ptmean);
    count++;
  }

  new TCanvas();
  TGraph *gr = new TGraph(count, grx, gry);
  gr->SetMarkerStyle(8);
  gr->SetMarkerColor(hh->GetLineColor());
  gr->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr->SetTitle(Form("raw phi, %s", gtitle.Data()));
  gr->Draw("AP");

  cc3 = new TCanvas();
  TGraph *gr3 = new TGraph(count, grx, gry3);
  gr3->SetMarkerStyle(22);
  gr3->SetMarkerColor(kBlue+1);
  gr3->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr3->SetTitle(Form("SIG / BKG, %s", gtitle.Data()));
  gr3->SetMinimum(0);
  gr3->Draw("AP");

  cc4 = new TCanvas();
  TGraph *gr4 = new TGraph(count, grx, gry4);
  gr4->SetMarkerStyle(23);
  gr4->SetMarkerColor(kBlue-1);
  gr4->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr4->SetTitle(Form("Significance, %s", gtitle.Data()));
  gr4->SetMinimum(0);
  gr4->Draw("AP");

  ccc = new TCanvas("ccc","ccc",0,0,900,300);
  ccc->Divide(2, 1, 0.001, 0.001);
  ccc->cd(1); gr3->Draw("AP");
  ccc->cd(2); gr4->Draw("AP");

  TString blabla = "mc";
  if (!mc) blabla = "data";
  // gr3->SaveAs(Form("SB_%s_%s.C", blabla.Data(), grapht.Data()));
  // gr4->SaveAs(Form("Sig_%s_%s.C", blabla.Data(), grapht.Data()));
  // ccc->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data()));
  // c->SaveAs(Form("%s_%s_0.eps", blabla.Data(), grapht.Data()));
  // c2->SaveAs(Form("%s_%s_1.eps", blabla.Data(), grapht.Data()));

  //  cc3->SaveAs(Form("%s_%s_2.eps", blabla.Data(), grapht.Data()));
  //  gr3->SaveAs(Form("sig_bck_%s_%s.C", blabla.Data(), grapht.Data()));

  if (mc) {
    new TCanvas();
    TGraph *gr2 = new TGraph(count, grx, gry2);
    gr2->SetMarkerStyle(8);
    gr2->SetMarkerColor(hg->GetLineColor());
    gr2->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr2->SetTitle(Form("gen phi, %s", gtitle.Data()));
    gr2->Draw("AP");

    new TCanvas();
    TGraphErrors *gr22 = new TGraphErrors(count, grx, gry22, grx22E, gry22E);
    gr22->SetMarkerStyle(8);
    gr22->SetMarkerColor(kCyan);
    gr22->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr22->SetTitle(Form("gen phi, %s", gtitle.Data()));
    gr22->Draw("AP");


    c = new TCanvas();
    c->SetGrid();
    TGraph *gr_e = new TGraph(count, grx, gry_eff);
    gr_e->SetMarkerStyle(22);
    gr_e->SetMarkerColor(kBlack);
    gr_e->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr_e->SetTitle(Form("efficiency (raw), %s", grapht.Data()));
    gr_e->Draw("AP");
    Printf("Save as '\033[1meffi_raw_%s\033[0m' file", grapht.Data());
    for (Int_t i = 0; i < gr_e->GetN(); i++)
      Printf("%f %f", gr_e->GetX()[i], gr_e->GetY()[i]);

    cvb = new TCanvas();
    cvb->cd();
    TGraph *gr_true = new TGraph(count, grx, gry_true);
    gr_true->SetMarkerStyle(8);
    gr_true->SetMarkerColor(ht->GetLineColor());
    gr_true->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr_true->SetTitle(Form("true phi, %s", gtitle.Data()));
    gr_true->Draw("AP");
    c = new TCanvas();
    c->cd();
    c->SetGrid();
    TGraphErrors *gr_true_eff = new TGraphErrors(count, grx, gry_true_eff,
                                                 grxE, gry_true_effE);
    gr_true_eff->SetMarkerStyle(20);
    //    gr_true_eff->SetMarkerSize(0.75);
    gr_true_eff->SetMarkerColor(kBlack);
    gr_true_eff->GetXaxis()->SetTitle("p_{t}, GeV/c");
    gr_true_eff->SetTitle(Form("efficiency (true), %s", grapht.Data()));
    gr_true_eff->Draw("AEP");
    m_gr->Add(gr_true_eff);
    Printf("Save as '\033[1meffi_true_%s\033[0m' file", grapht.Data());
    TString tout;
    Double_t oux, ouy, ouxe, ouye;
    for (Int_t i = 0; i < gr_true_eff->GetN(); i++) {
      oux = gr_true_eff->GetX()[i];
      ouy = gr_true_eff->GetY()[i];
      ouy = MinusCheck(ouy);
      ouxe = gr_true_eff->GetErrorX(i);
      ouye = gr_true_eff->GetErrorY(i);
      ouye = NanCheck(ouye);
      Printf("%f %f %f %f", gr_true_eff->GetX()[i], gr_true_eff->GetY()[i],
             gr_true_eff->GetErrorX(i), gr_true_eff->GetErrorY(i));
      if (!save_output) continue;
      gSystem->mkdir(dir_prefix.Data());
      tout = Form("%f %f %f %f", oux, ouy, ouxe, ouye);
      if (i == 0)
        tout = Form("Printf(\"%s\"); > %s/effi_%s", tout.Data(),
                    dir_prefix.Data(), grapht.Data());
      else
        tout = Form("Printf(\"%s\"); >> %s/effi_%s", tout.Data(),
                    dir_prefix.Data(), grapht.Data());
      //      Printf(":::::: %s", tout.Data());
      gROOT->ProcessLine(tout.Data());
    }
    // ------------------
    c = new TCanvas("cfinal", "mc_effi", 1200, 450);
    c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw();
    c->cd(1);
    gr_true->SetMinimum(0);
    gr_true->SetTitle(Form("phi (true & raw), %s", gtitle.Data()));
    gr_true->SetMarkerColor(kGreen+1);
    gr_true->Draw("AP");
    gr->SetMarkerColor(kRed+1);
    gr->Draw("P");
    c->cd(2)->SetGrid();
    gr_true_eff->SetMinimum(0);
    gr_true_eff->SetTitle(Form("efficiency, %s", grapht.Data()));
    gr_true_eff->SetMarkerColor(kGreen+1);
    gr_true_eff->Draw("AP");
    gr_e->SetMarkerColor(kRed+1);
    gr_e->Draw("P");
    //    c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data()));
    return;
  }

  //  TGraph *geff = new TGraph(Form("effi_raw_%s", grapht.Data()));
  //  TGraph *geff = new TGraph(Form("effi_true_%s", grapht.Data()));
  //  TGraph *geff = new TGraph("effi_true_Phi2010_qualityonly");
  TGraph *geff = new TGraph("effi_true_PhiNsigma_qualityonly");
  if (geff->IsZombie()) return;
  geff->SetMarkerStyle(22);
  geff->SetMarkerColor(kBlack);
  geff->GetXaxis()->SetTitle("p_{t}, GeV/c");
  geff->SetTitle(Form("efficiency, %s", grapht.Data()));
  c = new TCanvas();
  c->SetGrid();
  geff->Draw("AP");
  Double_t tpcsigma = 9999.9;
  if (ilist == 1) tpcsigma = 1.0;
  if (ilist == 2) tpcsigma = 1.5;
  if (ilist == 3) tpcsigma = 2.0;
  if (ilist == 4) tpcsigma = 2.5;
  if (ilist == 5) tpcsigma = 3.0;
  Double_t sss = TMath::Erf(tpcsigma/TMath::Sqrt(2.0));
  if (noSigma) sss = 1.0;
  Printf("sigma = %10f", sss);

  // for (Int_t i = 0; i < count; i++)
  //   geff->GetY()[i] = (sss*sss)/(geff->GetY()[i]);
  // geff->SetMaximum(1.0);
  // geff->Draw("AP");

  for (Int_t i = 0; i < count; i++) {
    Double_t deno = geff->Eval(grx[i])*sss*sss;
    if (deno < 0.00001) deno = 1;
    gry_fix[i] = gry[i]/deno;
  }
  new TCanvas;
  TGraph *gr_fix = new TGraph(count, grx, gry_fix);
  gr_fix->SetMarkerStyle(21);
  gr_fix->SetMarkerColor(hh->GetLineColor());
  gr_fix->GetXaxis()->SetTitle("p_{t}, GeV/c");
  gr_fix->SetTitle(Form("corrected phi * #sigma^{2}, %s", gtitle.Data()));
  if (noSigma)
    gr_fix->SetTitle(Form("corrected phi (no #sigma), %s", gtitle.Data()));
  gr_fix->Draw("AP");

  //---------------------
  c = new TCanvas("cfinald", "data_correct", 1200, 450);
  c->Divide(2, 1, 0.001, 0.001); c->Modified(); c->Draw();
  c->cd(1);
  gr->SetMinimum(0);
  gr->SetMarkerColor(kBlack);
  gr->Draw("AP");
  c->cd(2);
  gr_fix->SetMinimum(0);
  gr_fix->SetMarkerColor(kGreen+3);
  gr_fix->Draw("AP");
  TString bla9 = Form("qualityonly_PID2_%s", grapht.Data());
  if (noSigma) bla9 = Form("%s_noSig.C", bla9.Data());
  else         bla9 = Form("%s.C", bla9.Data());
  //  gr_fix->SaveAs(bla9.Data());
  //  TPad *cp = new TPad("cpf", "", 0.45,0.45,0.99,0.92);
  TPad *cp = new TPad("cpf", "", 0.60,0.55,0.99,0.93);
  cp->SetLogy(); cp->Draw(); cp->cd();
  TGraph *cloneg = ((TGraph *)gr_fix->Clone());
  cloneg->SetTitle(); cloneg->SetMarkerSize(0.8);
  cloneg->Draw("AP");
  //  c->SaveAs(Form("%s_%s.eps", blabla.Data(), grapht.Data()));
  f->Close();
}
Example #7
0
TCanvas* plotting36GT( bool logScale=false ) 
{

  std::cout << "plotting mu + track " << std::endl;
  TGaxis::SetMaxDigits(3);

  // channels, ordered as in the legend
  vector<TString> channels;  
  vector<TString> hnames; 
  vector<TString> type;

  map<TString,int> fillColor_;
  map<TString,int> lineColor_;
  int lineWidth1(2);
  int lineWidth2(1);

  bool salamanderStyle=true;
  if( salamanderStyle )
    {
      fillColor_["Signal"] = kOrange-2;
      lineColor_["Signal"] = kOrange+3;
      
      fillColor_["EWK"] = kOrange+7;
      lineColor_["EWK"] = kOrange+3;
      
      fillColor_["QCD"] = kViolet-5;
      lineColor_["QCD"] = kViolet+3;
      
      fillColor_["ttbar"] = kRed+2;
      lineColor_["ttbar"] = kRed+4;
      
      fillColor_["gamma+jet"] = kMagenta+4;
      lineColor_["gamma+jet"] = kViolet+3;
    }
  else
    {
      lineWidth1 = 2;
      lineWidth2 = 2;

      fillColor_["Signal"] = kPink+6;
      lineColor_["Signal"] = kMagenta+3;
      
      fillColor_["EWK"] = kAzure+8;
      lineColor_["EWK"] = kAzure+4;
      
      fillColor_["QCD"] = kYellow-7;
      lineColor_["QCD"] = kYellow+4;
      
      fillColor_["ttbar"] = kGreen;
      lineColor_["ttbar"] = kGreen+2;
      
      fillColor_["gamma+jet"] = kOrange;
      lineColor_["gamma+jet"] = kOrange+2;
    }

  // root file, where the data is
  TString fname("root/");

  // histogram limits, in linear and logarithmic
  int nbin_(100);
  float xmin_(0.), xmax_(0.); 
  float ymin_(0.), ymax_(0.); 
  float yminl_(0.), ymaxl_(0.); 

  // titles and axis, marker size
  TString xtitle;
  TString ytitle;
  int ndivx(510);
  int ndivy(510);
  float markerSize(0.);
  float titleOffset(1.);

  float r0_ = 1.;
  float dr_ = 0.3;
  if( use_chi )
    {
      r0_ = 0.;
      dr_ = 7.5;
      //dr_ = 3.0;
    }

  // canvas name
  TString cname("");
  TString ctitle;

  // legend position and scale;
  float xl_  = 0.;
  float yl_  = 0.; 	   
  float scalel_ = 0.0;

  {
    if( logScale )
      //      fname += "Zmumu_40-200_36pb";
      fname += "Zmutrk_36pb";
    else
      fname += "Zmutrk_36pb";

    if( logScale )
      {
	lineWidth1 = 1;
	lineWidth2 = 1;
      }
    
    channels.push_back("Zmumu"); 
    hnames.push_back("   Z #rightarrow #mu^{+}#mu^{-}"); 
    type.push_back("Signal"); 
    
    bool revert(false);
    if( logScale )
      {
 	if( revert )
 	  {
 	    channels.push_back("EWK");          
 	    hnames.push_back("   EWK");                
	    type.push_back("EWK"); 
	    
 	    channels.push_back("tt");              
 	    hnames.push_back("   t#bar{t}");         
	    type.push_back("ttbar"); 

	     	    channels.push_back("QCD");              
	     	    hnames.push_back("   QCD");              
	    	    type.push_back("QCD"); 
 	  }
 	else
 	  {
 	    channels.push_back("EWK");          
 	    hnames.push_back("   EWK");                
	    type.push_back("EWK"); 
	    
 	    channels.push_back("tt");              
 	    hnames.push_back("   t#bar{t}");         
	    type.push_back("ttbar"); 
	    
	    channels.push_back("QCD");              
	     	    hnames.push_back("   QCD");              
	    	    type.push_back("QCD"); 	  
	      
 	  }
       }
    
    if( !logScale )
      {
	// lin scale
	xmin_ = 60;
	xmax_ = 120;
	ymin_ = 0.01;
	ymax_ = 2100;

  }
    else
      {	
	// log scale
	xmin_ = 40;
	xmax_ = 200;
	yminl_ = 0.08;
	ymaxl_ = 3000;

      }

    xtitle = "M(#mu^{+}#mu^{-})    [GeV]";
    ytitle = "number of events /";    


    ndivx = 504;
    if( logScale )
      {
	ytitle += "4 GeV";
	ndivy = 510;
      }
    else
      {
	ytitle += " GeV";
	ndivy = 506;
      }
    
    if( logScale )
      {
	markerSize = 0.48;
      }
    else
      {	
	markerSize = 0.75;
      }
    
    cname += "Zmutrk";
    ctitle = "Z to trk";
    
    if( logScale )
      {
	xl_ = 0.60;
	yl_ = 0.50;
	scalel_ = 0.065;
      }
    else
      {
	xl_ = 0.22;
	yl_ = 0.50;
	scalel_ = 0.072;
      }
  }

  if( logScale ) cname += "MuTrk_log";
  else           cname += "MuTrkNotInThePAPER_lin";

  //Open the root file containing histograms and graphs
  fname += ".root";
  TFile* f_ = TFile::Open(fname,"READ");

  TCanvas* c_ = new TCanvas(cname,ctitle,300,300,479,510);
  c_->SetLeftMargin(  87./479 );
  c_->SetRightMargin( 42./479 );
  c_->SetTopMargin(  30./510 );
  c_->SetBottomMargin( 80./510 ); 
  c_->SetFillColor(0);
  c_->SetTickx(1);
  c_->SetTicky(1);
  c_->SetFrameFillStyle(0);
  c_->SetFrameLineWidth(2);
  c_->SetFrameBorderMode(0);
  Double_t scale = 4;
  Double_t wbin = 42*scale;
  Double_t left  = 8*scale;
  Double_t right = 5*scale;
  Double_t h1 = 135*scale;
  Double_t h2 = 45*scale;
  Double_t top1 = 15*scale;
  Double_t bot1 = 3*scale;
  Double_t top2 = 3*scale;
  //  Double_t bot1 = 0*scale;
  //  Double_t top2 = 0*scale;
  Double_t bot2 = 80*scale;
  Double_t W = left + wbin + right;
  Double_t H = h1 + h2;
  Double_t s[2] = {1, h1/h2 };

  TPad* pad[2];
  pad[0] = new TPad( "top", "top", 
		     0, h2/H, 1, 1,
		     kWhite,0,0);
  pad[0]->SetLeftMargin(  left/W );
  pad[0]->SetRightMargin( right/W );
  pad[0]->SetTopMargin(  top1/H );
  pad[0]->SetBottomMargin( bot1/H );

  pad[1] = new TPad( "bottom", "bottom", 
		     0, 0, 1, h2/H,
		     kWhite,0,0);
  pad[1]->SetLeftMargin(  left/W );
  pad[1]->SetRightMargin( right/W );
  pad[1]->SetTopMargin(  top2/H );
  pad[1]->SetBottomMargin( bot2/H );
  pad[1]->SetGridy();

  for( int ii=0; ii<2; ii++ )
    {
      pad[ii]->SetFillColor(0);
      pad[ii]->SetTickx(1);
      pad[ii]->SetTicky(1);
      pad[ii]->SetFrameFillStyle(0);
      pad[ii]->SetFrameLineWidth(2);
      pad[ii]->SetFrameBorderMode(0);
      pad[ii]->SetFrameFillStyle(0);
      pad[ii]->SetFrameLineWidth(2);
      pad[ii]->SetFrameBorderMode(0);
    }

  // a dummy histogram with the correct x axis
  // Warning: setTDRstyle() must be called before
  TH1F* h_= new TH1F( "bidon", "bidon", nbin_, xmin_, xmax_ );
  TAxis* ax_ = h_->GetXaxis();
  TAxis* ay_ = h_->GetYaxis();

  ax_->SetTitle(xtitle);
  ax_->CenterTitle();
  ax_->SetTitleOffset(1.0);
  ax_->SetNdivisions(ndivx);

  ay_->SetTitle(ytitle);
  ay_->CenterTitle();
  ay_->SetNdivisions(ndivy);
  ay_->SetTitleOffset(titleOffset);
  ay_->SetLabelOffset(0.015);

  // fetch histograms and dress them
  vector<TH1F*> histos;

  size_t nChan=channels.size();   
  for( size_t ii=0;ii<nChan;ii++)
    {
      TH1F* tmp = (TH1F*)f_->Get(channels[ii]);      
      tmp->SetFillColor( fillColor_[type[ii]] );
      tmp->SetLineColor( lineColor_[type[ii]] );
      tmp->SetLineWidth( lineWidth2 );
      histos.push_back(tmp);
    }

  //
  // stack histograms
  //
  TH1* h_stack = (TH1*) histos[nChan-1]->Clone();
  h_stack -> Reset();

  TString stackName_ = TString("Mll");
  vector<TH1*> listOfStackedHists;
  for( size_t ii=0; ii<nChan; ii++ )
    {
      TH1* hh_ = (TH1*) histos[nChan-ii-1]->Clone();

      stackName_ += "_";
      stackName_ += hh_->GetName();	  	  

      TAxis* xaxis = h_stack->GetXaxis();
      for( int iBin=1; iBin<=xaxis->GetNbins(); iBin++ )
	{
	  hh_ -> AddBinContent( iBin, h_stack->GetBinContent( iBin ) );
	}        

      hh_->SetName( stackName_ );
      delete h_stack;
      h_stack = hh_;
      listOfStackedHists.push_back( (TH1*)hh_->Clone() );
    }
  delete h_stack;
  
  TH1* totalHisto = listOfStackedHists[nChan-1];

  // colors the stacked histogram
  totalHisto->SetLineColor( lineColor_["Signal"] );
  totalHisto->SetLineWidth( lineWidth1 );
  
  // The data points are presented as a TGraph 
  // - error bars indicate the Poisson confidence interval at 68%
  // - bins with zero entry are removed
  TH1* hdata = (TH1*) f_->Get("hdata");
  // hdata->Sumw2();
  //hdata->Rebin(2);
  RooHist* roohist;
  TGraphAsymmErrors* dataGraph;

  roohist = new RooHist((*hdata));

  int Nn0=0;
  vector<double> vY;
  vector<double> vX;
  vector<double > veY;
  vector<double > veX;
  vector<double> tmp(0,2);

  for(int ip=0;ip<roohist->GetN();ip++) 
    {
      double Y,X;
      roohist->GetPoint(ip,X,Y);
      
      if(Y!=0) 
	{
	  Nn0++;
	  
	  vY.push_back(Y);
	  vX.push_back(X);
	  veX.push_back( roohist->GetErrorXlow(ip) );
	  veX.push_back( roohist->GetErrorXhigh(ip) );
	  veY.push_back( roohist->GetErrorYlow(ip) );
	  veY.push_back( roohist->GetErrorYhigh(ip) );
	}
    }
  dataGraph=new TGraphAsymmErrors(Nn0);
  for(int ip=0;ip<Nn0;ip++) 
    {
      dataGraph->SetPoint(ip,vX[ip],vY[ip]);      
      dataGraph->SetPointError(ip,veX[ip*2],veX[ip*2+1],veY[ip*2],veY[ip*2+1]);
    }
  dataGraph->SetName("data");

  dataGraph->SetMarkerStyle(kFullCircle);
  dataGraph->SetMarkerColor(kBlack);
  dataGraph->SetMarkerSize(markerSize);

  TGraph* dummyGraph = (TGraph*) dataGraph->Clone("dummyGraph");
  dummyGraph->SetLineColor(0);
  dummyGraph->SetMarkerSize(1.5*markerSize);

  // Remove the horizontal bars (at Michael's request)
  double x_(0), y_(0);
  for( int ii=0; ii<dataGraph->GetN(); ii++ )
    {
      dataGraph->SetPointEXlow(ii,0);
      dataGraph->SetPointEXhigh(ii,0);
      dataGraph->GetPoint(ii,x_,y_ );
      if( y_==0 )
	{
	  dataGraph->RemovePoint( ii );
	  ii--;
	}	  
    }

  // get the ratio data/fit
  TGraphAsymmErrors* ratioGraph = (TGraphAsymmErrors*) dataGraph->Clone("ratio");
  TH1* hfit = totalHisto;
  for( int ii=0; ii<dataGraph->GetN(); ii++ )
    {
      dataGraph->GetPoint(ii,x_,y_ );
      ratioGraph->SetPointEYlow(ii,0);
      ratioGraph->SetPointEYhigh(ii,0);
      ratioGraph->SetPoint(ii,x_,0 );
      double eyl_ = dataGraph->GetErrorYlow(ii);
      double eyh_ = dataGraph->GetErrorYhigh(ii);
      int jj = hfit->FindBin(x_);
      float fit_ = hfit->GetBinContent( jj );
      if( fit_>0 )
	{
	  if( use_chi )
	    {
	      ratioGraph->SetPointEYlow(ii,eyl_/sqrt(fit_));
	      ratioGraph->SetPointEYhigh(ii,eyh_/sqrt(fit_));
	      ratioGraph->SetPoint(ii,x_,(y_-fit_)/sqrt(fit_) );
	    }
	  else
	    {
	      ratioGraph->SetPointEYlow(ii,eyl_/fit_);
	      ratioGraph->SetPointEYhigh(ii,eyh_/fit_);
	      ratioGraph->SetPoint(ii,x_,y_/fit_ );
	    }
	}
      //      cout << ii << " ratio=" << ratioGraph->GetY()[ii] 
      //       	   << "+" << ratioGraph->GetEYhigh()[ii] 
      //	   << "-" << ratioGraph->GetEYlow()[ii] << endl;
    }

  TH1* hratio_ = (TH1*) h_->Clone("hratio");
  ax_->SetLabelOffset(99);
  ax_->SetTitleOffset(99);

  //
  // now plotting
  //  
  c_->Draw();
  c_->cd();

  TPad* p_ = pad[0];
  p_->Draw();
  p_->cd();

  if( logScale )
    {
      p_->SetLogy(true);
    }
  else
    {
      p_->SetLogy(false);
    }

  if( !logScale )
    {
      h_->GetYaxis()->SetRangeUser(ymin_+0.001*(ymax_-ymin_),ymax_);
    }
  else
    {
      h_->GetYaxis()->SetRangeUser(yminl_,ymaxl_);
    }

  h_->Draw();

  float dxl_ = scalel_*3.5;
  float dyl_ = scalel_*1.8;
  if( logScale )
    {
      dxl_ = scalel_*4;
      dyl_ = scalel_*3.4;
    }
  TLegend* legend=new TLegend(xl_,yl_,xl_+dxl_,yl_+dyl_);
  legend->SetLineColor(0);
  legend->SetFillColor(0);
  legend->SetTextFont(42);
  legend->SetTextSize(0.048);
  
  legend->AddEntry(dummyGraph,"   data","pl");      
  if( logScale )
    {
      legend->AddEntry(dummyGraph,"       ","0");
    }
  for(size_t ii=0;ii<nChan;ii++) 
    {
      legend->AddEntry(histos[ii],hnames[ii],"f");
    }
  legend->Draw("same");

  totalHisto->Draw("same");

  for( size_t ii=0; ii<nChan; ii++ )
    {
      //  listOfStackedHists[nChan-ii-1]->Sumw2();   
      listOfStackedHists[nChan-ii-1]->Rebin(1.);
      listOfStackedHists[nChan-ii-1]->Scale(1.);
      listOfStackedHists[nChan-ii-1]->Draw("Same");
    }

  // draw the data points
  dataGraph->Draw("PE");

  // redraw axis
  p_->RedrawAxis();

  //lumi pad, cms prelim pad etc..
  {
    int txtFont = 42;  // bold is 62
    float txtSize1 = 0.055;
    float txtX1 = 0.91;
    float txtY1 = 0.935;

    float txtSize2 = 0.05;
    float txtX2 = 0.85;
    float txtY2 = 0.83;
    
    // TEST FOR THE NAME ZMT, ZMMNONISO, ZMS
    float txtSize3 = 0.055;
    float txtX3 = 0.25;
    float txtY3 = 0.935;

    TLatex latex;
    latex.SetNDC();
    latex.SetTextFont(txtFont);
    
    latex.SetTextSize(txtSize1);    
    latex.SetTextAlign(31); // align right
    latex.DrawLatex(txtX1,txtY1,"CMS");

    latex.SetTextAlign(31); // align right
    latex.SetTextSize(txtSize2);
    latex.DrawLatex(txtX2,txtY2,"36 pb^{-1}  at  #sqrt{s} = 7 TeV");

    latex.SetTextAlign(21); // align left???
    latex.SetTextSize(txtSize3);
    latex.DrawLatex(txtX3,txtY3,"global muon plus track");
  }

  c_->cd();
  
  p_ = pad[1];

  p_->Draw();

  p_->cd();

  TAxis* xratio_ = hratio_->GetXaxis();
  TAxis* yratio_ = hratio_->GetYaxis();

  yratio_->SetRangeUser(r0_-0.9999*dr_,r0_+0.9999*dr_);
  yratio_->SetLabelSize( s[1]*yratio_->GetLabelSize() );
  yratio_->SetTitleSize( s[1]*yratio_->GetTitleSize() );
  yratio_->SetLabelOffset( yratio_->GetLabelOffset() );
  yratio_->SetTitleOffset( yratio_->GetTitleOffset()/s[1] );
  if( use_chi )
    {
      yratio_->SetTitle("#chi");
      yratio_->SetNdivisions(4);
    }
  else
    {
      yratio_->SetTitle("data/fit");
      yratio_->SetNdivisions(3);
    }

  xratio_->SetLabelSize( s[1]*xratio_->GetLabelSize() );
  xratio_->SetTitleSize( s[1]*xratio_->GetTitleSize() );
  xratio_->SetTitleOffset( 1.0 );
  xratio_->CenterTitle();
  xratio_->SetLabelOffset( xratio_->GetLabelOffset()*s[1] );
  xratio_->SetTickLength( xratio_->GetTickLength()*s[1] );

  hratio_->Draw();
  ratioGraph->SetMarkerSize( ratioGraph->GetMarkerSize()*1. );
  ratioGraph->SetLineColor( kBlack );

  ratioGraph->SetMarkerColor( kGray+2 );
  ratioGraph->SetMarkerStyle( kFullCircle );
  ratioGraph->DrawClone("PE");
  ratioGraph->SetMarkerColor( kBlack );
  ratioGraph->SetMarkerStyle( kOpenCircle );
  ratioGraph->DrawClone("PE");

  p_->RedrawAxis();

  c_->cd();

  return c_;
}
Example #8
0
void PlotBlowoutScalings(Int_t time, const TString &options="") {

#ifdef __CINT__  
  gSystem->Load("libptools.so");
#endif

  PGlobals::Initialize();

  TString opt = options;

  const Int_t Nsim = 11;
  char sName[Nsim][36] = {"rake-v1.0kA.G.SR2.MC01.3D", 
			  "rake-v2.5kA.G.SR2.MC01.3D",
			  "rake-v04kA.G.SR2.MC01.3D",
			  "rake-v06kA.G.SR2.MC01.3D",
			  "rake-v08kA.G.SR2.MC01.3D",
			  "rake-v10kA.G.SR2.MC01.3D",
			  "rake-v15kA.G.SR2.MC01.3D",
			  "rake-v20kA.G.MC01.3D",
  			  "rake-v30kA.G.SR2.MC01.3D",
  			  "rake-v45kA.G.SR2.MC01.3D",
  			  "rake-v60kA.G.SR2.MC01.3D"};

  // Load first simulation data (for instance)
  PData *pData = PData::Get(sName[0]);
  pData->LoadFileNames(time);
  if(!pData->IsInit()) return;

  // Some plasma constants
  Double_t n0 = pData->GetPlasmaDensity();
  Double_t kp = pData->GetPlasmaK();
  Double_t skindepth = 1.;
  if(kp!=0.0) skindepth = 1/kp;
  Double_t E0 = pData->GetPlasmaE0();
  Double_t  lightspeed =  PConst::c_light;

  // Some beam properties:
  Float_t gamma = pData->GetBeamGamma();

  // Trapping potential
  Float_t trapPotential = 1.0 - (1.0/gamma);

  // Time in OU
  Float_t Time = pData->GetRealTime();
  // z start of the plasma in normalized units.
  Float_t zStartPlasma = pData->GetPlasmaStart()*kp;
  // z start of the beam in normalized units.
  Float_t zStartBeam = pData->GetBeamStart()*kp;
  
  // Compulsory options
  opt += "comovcenter";

  // Centering time and z position:
  Double_t shiftz = pData->Shift(opt);
  if(opt.Contains("center")) {
    Time -= zStartPlasma;
    if(opt.Contains("comov"))      // Centers on the head of the beam.
      Time += zStartBeam;
  } 

  TFile *sFile[Nsim];
  TString *sPath[Nsim];
  Int_t color[Nsim];

  // histos and graphs
  TH2F *hEz2D[Nsim];
  TH2F *hDen2D[Nsim];
  TH1F *hCur1D[Nsim];
  TH1F *hEz1D[Nsim];
  TH1F *hV1D[Nsim];
  TH1F *hFocus1D[Nsim];
  TH1F *hDenx1D[Nsim];

  // Arrays with the quantities
  Float_t Current[Nsim];
  Float_t Zeta0[Nsim];
  Float_t RadiusX[Nsim];
  Float_t RadiusZ[Nsim];
  Float_t RadiusPsi[Nsim];
  Float_t EzMax[Nsim]; 
  Float_t EzMaxUse[Nsim];
  Float_t EzLimit[Nsim];
  Float_t EzMaxFocus[Nsim];
  Float_t EzSlope[Nsim];
  Float_t EzSlopeMaxFocus[Nsim];
  Float_t EzMaxBeam[Nsim];  
  Float_t DeltaPsi[Nsim];
  Float_t DeltaPsiFocus[Nsim];
  Float_t TransRatio[Nsim];
  Float_t TransRatioFocus[Nsim];


  // Theory
  Float_t EzMaxLU[Nsim];  
  Float_t EzMaxLO[Nsim];  
  Float_t EzMaxUseBO[Nsim];  
  Float_t EzMaxBeamLO[Nsim];  
  Float_t EzSlopeLO[Nsim];
  Float_t RadiusLO[Nsim];
  Float_t RadiusLU[Nsim];
  Float_t RadiusPsiBO[Nsim];
  Float_t PsiMaxLO[Nsim];
  Float_t DeltaPsiLO[Nsim];
  Float_t DeltaPsiLU[Nsim];

  // Maximums and minimums for plotting
  Float_t maxCur = -999.;
  Float_t minCur = 999.;
  Float_t maxRadius = -999.;
  Float_t minRadius = 999.;
  Float_t maxEz = -999.;
  Float_t minEz = 999.;
  Float_t maxEzSlope = -999.;
  Float_t minEzSlope = 999.;
  Float_t maxPsi = -999.;
  Float_t minPsi = 999.;
  Float_t maxTR = -999.;
  Float_t minTR = 999.;


  for(Int_t i=0;i<Nsim;i++) {
    
    TString filename = Form("./%s/Plots/Snapshots/Snapshot-%s_%i.root",sName[i],sName[i],time);
    sFile[i] = new TFile(filename,"READ");
    
    // Load histos and graphs
    hEz2D[i]  = (TH2F*) sFile[i]->Get("hE2D_0"); 
    hDen2D[i] = (TH2F*) sFile[i]->Get("hDen2D_0"); 
    hEz1D[i]  = (TH1F*) sFile[i]->Get("hE1D_0"); 
    hCur1D[i] = (TH1F*) sFile[i]->Get("hCur1D_1"); 
    hV1D[i]   = (TH1F*) sFile[i]->Get("hV1D"); 
    hFocus1D[i]   = (TH1F*) sFile[i]->Get("hFocus1D"); 

    hDen2D[i]->ResetStats();
    hEz1D[i]->ResetStats();
    hCur1D[i]->ResetStats();
    hV1D[i]->ResetStats();
    
    cout << Form("\n Analyzing simulation %s : \n",sName[i]) << endl;
   
    // Driver RMS
    Double_t rmslength = hCur1D[i]->GetRMS();
  
    // Find the first point on-axis where Ez changes from positive to negative:
    Int_t MAXCROSS = 2;
    Float_t *EzCross = new Float_t[MAXCROSS];
    Float_t *EzExtr = new Float_t[MAXCROSS];
    memset(EzCross,0,sizeof(Float_t)*MAXCROSS);
    memset(EzExtr,0,sizeof(Float_t)*MAXCROSS);
  
    Int_t auxNcross = PGlobals::HCrossings(hEz1D[i],EzCross,EzExtr,MAXCROSS,0.0,2*rmslength);
  
    // for(Int_t j=0;j<auxNcross;j++) {
    //   if(opt.Contains("units"))
    // 	cout << Form(" %i Ez crossing found at zeta = %.2f um -> Ez maximum = %.2f GV/m",j,EzCross[j],EzExtr[j]) << endl;
    //   else
    // 	cout << Form(" %i Ez crossing found at zeta = %.2f kp^-1 -> Ez maximum = %.2f E0",j,EzCross[j],EzExtr[j]) << endl;      
    // }

    Zeta0[i] = EzCross[0];

    Int_t bin0 = hEz1D[i]->FindBin(Zeta0[i]);
    hDenx1D[i] = (TH1F*) hDen2D[i]->ProjectionY("_py",bin0);

    RadiusX[i] = fabs(hDenx1D[i]->GetBinCenter(hDenx1D[i]->GetMaximumBin()));
    RadiusZ[i] = fabs(hV1D[i]->GetBinCenter(hV1D[i]->GetMinimumBin()) - Zeta0[i]);

    DeltaPsi[i] =  hV1D[i]->GetBinContent(hV1D[i]->GetMaximumBin()) -  hV1D[i]->GetBinContent(hV1D[i]->GetMinimumBin());
    

    Float_t zshift = 0.5; 
    if(opt.Contains("units")) 
      zshift *= PUnits::um * kp;
    
    Int_t bin1 = hEz1D[i]->FindBin(Zeta0[i]-zshift);
    Int_t bin2 = hEz1D[i]->FindBin(Zeta0[i]+zshift);
    EzSlope[i] = (hEz1D[i]->GetBinContent(bin1)-hEz1D[i]->GetBinContent(bin2))/
	(hEz1D[i]->GetBinCenter(bin1)-hEz1D[i]->GetBinCenter(bin2));

    EzMaxUse[i]  = EzSlope[i] * RadiusZ[i];
    EzMaxBeam[i] = EzExtr[0];
    EzMax[i] = fabs(EzExtr[1]);

    Current[i] = hCur1D[i]->GetMaximum();
    if(opt.Contains("units")) {
      Current[i] *= PUnits::kA / PConst::I0;
      rmslength *= PUnits::um * kp;
    }
    RadiusLO[i] = PFunc::RadiusBO(Current[i],rmslength);
    RadiusLU[i] = 2.0 * TMath::Sqrt(Current[i]);
    EzMaxLU[i] = PFunc::EzMaxLu(Current[i]);
    EzMaxBeamLO[i] = PFunc::EzMaxBeamLo(Current[i]);
    EzMaxLO[i] = RadiusLO[i]/2.0;
    Float_t RadiusLO2 = RadiusLO[i]*RadiusLO[i];
    Float_t RadiusLU2 = RadiusLU[i]*RadiusLU[i];
    // EzSlopeLO[i] = RadiusLO2 * (RadiusLO2 + 8.0) / (2.0 * (RadiusLO2 + 4.0) * (RadiusLO2 + 4.0));
    EzSlopeLO[i] = RadiusLU2 * (RadiusLU2 + 8.0) / (2.0 * (RadiusLU2 + 4.0) * (RadiusLU2 + 4.0));
    PsiMaxLO[i] = RadiusLO[i]*RadiusLO[i]/4.0;
    DeltaPsiLO[i] = RadiusLO[i]*RadiusLO[i]/4.0;
    DeltaPsiLU[i] = RadiusLU[i]*RadiusLU[i]/4.0;
    RadiusPsiBO[i] = TMath::Sqrt(2*(DeltaPsiLO[i]-1)); 
    EzMaxUseBO[i]  = RadiusPsiBO[i]/2.0;
    if(opt.Contains("units")) {
      Current[i] /= PUnits::kA / PConst::I0;
      rmslength /= PUnits::um * kp;
      RadiusLO[i] *= skindepth / PUnits::um;
      RadiusLU[i] *= skindepth / PUnits::um;
      RadiusPsiBO[i] *= skindepth / PUnits::um;
      EzMaxLU[i]  *= E0 / (PUnits::GV/PUnits::m);
      EzMaxBeamLO[i] *= E0 / (PUnits::GV/PUnits::m);
      EzMaxUseBO[i] *= E0 / (PUnits::GV/PUnits::m);
      EzSlope[i] *= (E0 / (PUnits::GV/PUnits::m)) * skindepth / PUnits::um;
      cout << Form(" Beam max. current = %.2f kA   RMS = %.2f um",Current[i],rmslength) << endl;
      cout << Form(" Radius of the bubble (Lotov): R = %.2f um",RadiusLO[i]) << endl;
      cout << Form(" Radius of the bubble (Lu)   : R = %.2f um",RadiusLU[i]) << endl;
      cout << Form(" Ez max beam (Lo) = %.2f GV/m",EzMaxBeamLO[i]) << endl;
      cout << Form(" Ez max (Lu) = %.2f GV/m",-EzMaxLU[i]) << endl;
      cout << Form(" Ez slope at crossing = %.2f (GV/m)/um ",EzSlope[i]) << endl;
    } else {
      cout << Form(" Beam max. current = %.2f I0   RMS = %.2f kp^-1",Current[i],rmslength) << endl;
      cout << Form(" Radius of the bubble (Lotov): R = %.2f kp^-1",RadiusLO[i]) << endl;
      cout << Form(" Radius of the bubble (Lu)   : R = %.2f kp^-1",RadiusLU[i]) << endl;
      cout << Form(" Ez max beam (Lo) = %.2f E0",EzMaxBeamLO[i]) << endl;
      cout << Form(" Ez max (Lu) = %.2f E0",-EzMaxLU[i]) << endl;
      cout << Form(" Ez slope at crossing = %.2f ",EzSlope[i]) << endl;
    }

    if(opt.Contains("kA")) {
      Current[i] /= PUnits::kA / PConst::I0;
    }

    // Find the first Focusing crossing after the maximum 
    MAXCROSS = 1;
    Float_t *FocusCross = new Float_t[MAXCROSS];
    Float_t *FocusExtr = new Float_t[MAXCROSS];
    memset(FocusCross,0,sizeof(Float_t)*MAXCROSS);
    memset(FocusExtr,0,sizeof(Float_t)*MAXCROSS);
    auxNcross = PGlobals::HCrossings(hFocus1D[i],FocusCross,FocusExtr,MAXCROSS,0.0,Zeta0[i]);

    if(opt.Contains("units") && n0) {
      trapPotential *=  ( E0 * skindepth / (PUnits::MV) ); 
    }  

    Int_t binFcross = hFocus1D[i]->FindBin(FocusCross[0]);
    Float_t potValueFin = hV1D[i]->GetBinContent(binFcross);
    EzMaxFocus[i] = fabs(hEz1D[i]->GetBinContent(binFcross));


    TransRatio[i] = EzMax[i]/EzMaxBeam[i];
    TransRatioFocus[i] = EzMaxFocus[i]/EzMaxBeam[i];
   
    cout << Form(" Max. R       = %.2f ",TransRatio[i]) << endl;
    cout << Form(" Max. R focus = %.2f ",TransRatioFocus[i]) << endl;


    Int_t binPotValueIni = -99;
    Float_t potValueIni = -99;
    for(Int_t j=binFcross;j<hV1D[i]->GetNbinsX();j++) {
      if(hV1D[i]->GetBinContent(j)>=potValueFin+trapPotential) {
	binPotValueIni = j;
	potValueIni = hV1D[i]->GetBinContent(j);
	//break;
      }
    }

    // Ez slope at max focusing Ez
    zshift = 0.1;
    bin1 = hEz1D[i]->FindBin(FocusCross[0]-zshift);
    bin2 = hEz1D[i]->FindBin(FocusCross[0]+zshift);
    EzSlopeMaxFocus[i] = (hEz1D[i]->GetBinContent(bin1)-hEz1D[i]->GetBinContent(bin2))/
	(hEz1D[i]->GetBinCenter(bin1)-hEz1D[i]->GetBinCenter(bin2));
    cout << Form(" Ez slope at max focus = %.2f ",EzSlopeMaxFocus[i]) << endl;


    // Difference between psi maximum and psi final focus
    DeltaPsiFocus[i] = hV1D[i]->GetBinContent(hV1D[i]->GetMaximumBin()) - potValueFin;

    // Find the first Psi crossing after the maximum 
    MAXCROSS = 1;
    Float_t *PsiCross = new Float_t[MAXCROSS];
    Float_t *PsiExtr = new Float_t[MAXCROSS];
    memset(PsiCross,0,sizeof(Float_t)*MAXCROSS);
    memset(PsiExtr,0,sizeof(Float_t)*MAXCROSS);
    auxNcross = PGlobals::HCrossings(hV1D[i],PsiCross,PsiExtr,MAXCROSS,potValueIni,Zeta0[i]);

    Int_t binVcross = -1;
    EzLimit[i] = 0.0;
    RadiusPsi[i] = 0.0;
    if(auxNcross>0) {
      binVcross = hEz1D[i]->FindBin(PsiCross[0]);
      EzLimit[i] = fabs(hEz1D[i]->GetBinContent(binVcross));
      RadiusPsi[i] = fabs(PsiCross[0]- Zeta0[i]);
    }
        
    cout << Form(" Trapping zone radius = %.2f ",RadiusPsi[i]) << endl;

    if(RadiusX[i]>maxRadius) maxRadius = RadiusX[i];
    if(RadiusZ[i]>maxRadius) maxRadius = RadiusZ[i];
    if(RadiusLO[i]>maxRadius) maxRadius = RadiusLO[i];
    if(RadiusLU[i]>maxRadius) maxRadius = RadiusLU[i];

    if(RadiusX[i]<minRadius) minRadius = RadiusX[i];
    if(RadiusZ[i]<minRadius) minRadius = RadiusZ[i];
    if(RadiusLO[i]<minRadius) minRadius = RadiusLO[i];
    if(RadiusLU[i]<minRadius) minRadius = RadiusLU[i];

    if(EzMax[i]>maxEz) maxEz = EzMax[i];
    if(EzMaxUse[i]>maxEz) maxEz = EzMaxUse[i];
    if(EzLimit[i]>maxEz) maxEz = EzLimit[i];
    if(EzMaxFocus[i]>maxEz) maxEz = EzMaxFocus[i];
    if(EzMaxBeam[i]>maxEz) maxEz = EzMaxBeam[i];
    if(EzMaxLO[i]>maxEz) maxEz = EzMaxLO[i];
    if(EzMaxLU[i]>maxEz) maxEz = EzMaxLU[i];
    if(EzMaxBeamLO[i]>maxEz) maxEz = EzMaxBeamLO[i];

    if(EzMax[i]<minEz) minEz = EzMax[i];
    if(EzMaxUse[i]<minEz) minEz = EzMaxUse[i];
    if(EzLimit[i]<minEz) minEz = EzLimit[i];
    if(EzMaxFocus[i]<minEz) minEz = EzMaxFocus[i];
    if(EzMaxBeam[i]<minEz) minEz = EzMaxBeam[i];
    if(EzMaxLO[i]<minEz) minEz = EzMaxLO[i];
    if(EzMaxLU[i]<minEz) minEz = EzMaxLU[i];
    if(EzMaxBeamLO[i]<minEz) minEz = EzMaxBeamLO[i];
    
    if(EzSlope[i]>maxEzSlope) maxEzSlope = EzSlope[i]; 
    if(EzSlope[i]<minEzSlope) minEzSlope = EzSlope[i]; 
    // if(EzSlopeMaxFocus[i]>maxEzSlope) maxEzSlope = EzSlopeMaxFocus[i]; 
    // if(EzSlopeMaxFocus[i]<minEzSlope) minEzSlope = EzSlopeMaxFocus[i]; 

    if(DeltaPsi[i]>maxPsi) maxPsi = DeltaPsi[i];
    if(DeltaPsiFocus[i]>maxPsi) maxPsi = DeltaPsiFocus[i];
    if(DeltaPsiLO[i]>maxPsi) maxPsi = DeltaPsiLO[i];
    if(DeltaPsiLU[i]>maxPsi) maxPsi = DeltaPsiLU[i];
    if(DeltaPsi[i]<minPsi) minPsi = DeltaPsi[i];
    if(DeltaPsiFocus[i]<minPsi) minPsi = DeltaPsiFocus[i];
    if(DeltaPsiLO[i]<minPsi) minPsi = DeltaPsiLO[i];
    if(DeltaPsiLU[i]<minPsi) minPsi = DeltaPsiLU[i];
    
    if(TransRatio[i]<minTR) minTR = TransRatio[i];
    if(TransRatio[i]>maxTR) maxTR = TransRatio[i];
    if(TransRatioFocus[i]<minTR) minTR = TransRatioFocus[i];
    if(TransRatioFocus[i]>maxTR) maxTR = TransRatioFocus[i];

    if(Current[i]<minCur) minCur = Current[i];
    if(Current[i]>maxCur) maxCur = Current[i];

  }

  Float_t xMin = minCur - (maxCur-minCur)*0.1;
  Float_t xMax = maxCur + (maxCur-minCur)*0.1;


  // Graphs for the max. current dependence
  TGraph *gRadiusX  = new TGraph(Nsim,Current,RadiusX);
  TGraph *gRadiusZ  = new TGraph(Nsim,Current,RadiusZ);
  TGraph *gRadiusPsi  = new TGraph(Nsim,Current,RadiusPsi);
  TGraph *gRadiusLO  = new TGraph(Nsim,Current,RadiusLO);
  TGraph *gRadiusLU  = new TGraph(Nsim,Current,RadiusLU);
  TGraph *gRadiusPsiBO  = new TGraph(Nsim,Current,RadiusPsiBO);

  TGraph *gEzMax    = new TGraph(Nsim,Current,EzMax);
  TGraph *gEzMaxUse = new TGraph(Nsim,Current,EzMaxUse);
  TGraph *gEzMaxBeam = new TGraph(Nsim,Current,EzMaxBeam);
  TGraph *gEzLimit = new TGraph(Nsim,Current,EzLimit);
  TGraph *gEzMaxFocus = new TGraph(Nsim,Current,EzMaxFocus);
  TGraph *gEzMaxLU   = new TGraph(Nsim,Current,EzMaxLU);
  TGraph *gEzMaxLO  = new TGraph(Nsim,Current,EzMaxLO);
  TGraph *gEzMaxUseBO  = new TGraph(Nsim,Current,EzMaxUseBO);
  TGraph *gEzMaxBeamLO = new TGraph(Nsim,Current,EzMaxBeamLO);
 
  TGraph *gDeltaPsi = new TGraph(Nsim,Current,DeltaPsi);
  TGraph *gDeltaPsiFocus = new TGraph(Nsim,Current,DeltaPsiFocus);
  TGraph *gDeltaPsiLO = new TGraph(Nsim,Current,DeltaPsiLO);
  TGraph *gDeltaPsiLU = new TGraph(Nsim,Current,DeltaPsiLU);

  TGraph *gEzSlope = new TGraph(Nsim,Current,EzSlope);
  TGraph *gEzSlopeMaxFocus = new TGraph(Nsim,Current,EzSlopeMaxFocus);
  TGraph *gEzSlopeLO = new TGraph(Nsim,Current,EzSlopeLO);

  TGraph *gTransRatio = new TGraph(Nsim,Current,TransRatio);
  TGraph *gTransRatioFocus = new TGraph(Nsim,Current,TransRatioFocus);

  // Int_t color1 = kMagenta-8;
  // Int_t color2 = kMagenta-2;
  // Int_t color3 = kMagenta-4;
  // Int_t color4 = kAzure+1;
  // Int_t color5 = kGray+2;
  // Int_t markersty = 20;
  // Float_t markersiz = 1.0;
  // Int_t linewit = 2;

  Int_t color1 = kGray+3;
  Int_t color2 = kGray+2;
  Int_t color3 = kAzure+1;
  Int_t color4 = kRed;
  Int_t color5 = kGray+1;
  Int_t markersty = 20;
  Float_t markersiz = 1.0;
  Int_t linewit = 1;

  gRadiusX->SetLineColor(color1);
  gRadiusX->SetLineWidth(linewit);
  gRadiusX->SetMarkerColor(color1);
  gRadiusX->SetMarkerStyle(markersty);
  gRadiusX->SetMarkerSize(markersiz);

  gRadiusLU->SetLineColor(color1);
  gRadiusLU->SetLineWidth(1);
  gRadiusLU->SetLineStyle(4);
  gRadiusLU->SetMarkerColor(color1);
  gRadiusLU->SetMarkerStyle(markersty);
  gRadiusLU->SetMarkerSize(0.0);

  gRadiusZ->SetLineColor(color2);
  gRadiusZ->SetLineWidth(linewit);
  gRadiusZ->SetMarkerColor(color2);
  gRadiusZ->SetMarkerStyle(markersty);
  gRadiusZ->SetMarkerSize(markersiz);

  gRadiusLO->SetLineColor(color2);
  gRadiusLO->SetLineWidth(1);
  gRadiusLO->SetLineStyle(3);
  gRadiusLO->SetMarkerColor(color2);
  gRadiusLO->SetMarkerStyle(markersty);
  gRadiusLO->SetMarkerSize(0.0);

  gRadiusPsi->SetLineColor(color3);
  gRadiusPsi->SetLineWidth(linewit);
  gRadiusPsi->SetMarkerColor(color3);
  gRadiusPsi->SetMarkerStyle(markersty);
  gRadiusPsi->SetMarkerSize(markersiz);

  gEzMax->SetLineColor(color2);
  gEzMax->SetLineWidth(linewit);
  gEzMax->SetMarkerColor(color2);
  gEzMax->SetMarkerStyle(markersty);
  gEzMax->SetMarkerSize(markersiz);

  gEzMaxUse->SetLineColor(color2);
  gEzMaxUse->SetLineWidth(linewit);
  gEzMaxUse->SetMarkerColor(color2);
  gEzMaxUse->SetMarkerStyle(markersty);
  gEzMaxUse->SetMarkerSize(markersiz);

  gEzLimit->SetLineColor(color3);
  gEzLimit->SetLineWidth(linewit);
  gEzLimit->SetMarkerColor(color3);
  gEzLimit->SetMarkerStyle(markersty);
  gEzLimit->SetMarkerSize(markersiz);

  gEzMaxFocus->SetLineColor(color1);
  gEzMaxFocus->SetLineWidth(linewit);
  gEzMaxFocus->SetMarkerColor(color1);
  gEzMaxFocus->SetMarkerStyle(markersty);
  gEzMaxFocus->SetMarkerSize(markersiz);

  gEzSlope->SetLineColor(color2);
  gEzSlope->SetLineWidth(linewit);
  gEzSlope->SetMarkerColor(color2);
  gEzSlope->SetMarkerStyle(markersty);
  gEzSlope->SetMarkerSize(markersiz);

  gEzSlopeMaxFocus->SetLineColor(color1);
  gEzSlopeMaxFocus->SetLineWidth(linewit);
  gEzSlopeMaxFocus->SetMarkerColor(color1);
  gEzSlopeMaxFocus->SetMarkerStyle(markersty);
  gEzSlopeMaxFocus->SetMarkerSize(markersiz);

  gEzSlopeLO->SetLineColor(color2);
  gEzSlopeLO->SetLineWidth(1);
  gEzSlopeLO->SetLineStyle(3);
  gEzSlopeLO->SetMarkerColor(color2);
  gEzSlopeLO->SetMarkerStyle(markersty);
  gEzSlopeLO->SetMarkerSize(0);


  gDeltaPsi->SetLineColor(color2);
  gDeltaPsi->SetLineWidth(linewit);
  gDeltaPsi->SetMarkerColor(color2);
  gDeltaPsi->SetMarkerStyle(markersty);
  gDeltaPsi->SetMarkerSize(markersiz);

  gDeltaPsiFocus->SetLineColor(color1);
  gDeltaPsiFocus->SetLineWidth(linewit);
  gDeltaPsiFocus->SetMarkerColor(color1);
  gDeltaPsiFocus->SetMarkerStyle(markersty);
  gDeltaPsiFocus->SetMarkerSize(markersiz);

  gEzMaxBeam->SetLineColor(color4);
  gEzMaxBeam->SetLineWidth(linewit);
  gEzMaxBeam->SetMarkerColor(color4);
  gEzMaxBeam->SetMarkerStyle(markersty);
  gEzMaxBeam->SetMarkerSize(markersiz);

  gRadiusPsiBO->SetLineColor(color3);
  gRadiusPsiBO->SetLineWidth(1);
  gRadiusPsiBO->SetLineStyle(3);
  gRadiusPsiBO->SetMarkerColor(color3);
  gRadiusPsiBO->SetMarkerStyle(markersty);
  gRadiusPsiBO->SetMarkerSize(0.0);

  gEzMaxLU->SetLineColor(color5);
  gEzMaxLU->SetLineWidth(1);
  gEzMaxLU->SetLineStyle(4);
  gEzMaxLU->SetMarkerColor(color5);
  gEzMaxLU->SetMarkerStyle(markersty);
  gEzMaxLU->SetMarkerSize(0.0);

  gEzMaxLO->SetLineColor(color2);
  gEzMaxLO->SetLineWidth(1);
  gEzMaxLO->SetLineStyle(3);
  gEzMaxLO->SetMarkerColor(color2);
  gEzMaxLO->SetMarkerStyle(markersty);
  gEzMaxLO->SetMarkerSize(0.0);

  gEzMaxUseBO->SetLineColor(color3);
  gEzMaxUseBO->SetLineWidth(1);
  gEzMaxUseBO->SetLineStyle(3);
  gEzMaxUseBO->SetMarkerColor(color3);
  gEzMaxUseBO->SetMarkerStyle(markersty);
  gEzMaxUseBO->SetMarkerSize(0.0);

  gEzMaxBeamLO->SetLineColor(color4);
  gEzMaxBeamLO->SetLineWidth(1);
  gEzMaxBeamLO->SetLineStyle(3);
  gEzMaxBeamLO->SetMarkerColor(color4);
  gEzMaxBeamLO->SetMarkerStyle(markersty);
  gEzMaxBeamLO->SetMarkerSize(0.0);

  gDeltaPsiLO->SetLineColor(color2);
  gDeltaPsiLO->SetLineWidth(1);
  gDeltaPsiLO->SetLineStyle(3);
  gDeltaPsiLO->SetMarkerColor(color2);
  gDeltaPsiLO->SetMarkerStyle(markersty);
  gDeltaPsiLO->SetMarkerSize(0.0);

  gDeltaPsiLU->SetLineColor(color2);
  gDeltaPsiLU->SetLineWidth(1);
  gDeltaPsiLU->SetLineStyle(4);
  gDeltaPsiLU->SetMarkerColor(color2);
  gDeltaPsiLU->SetMarkerStyle(markersty);
  gDeltaPsiLU->SetMarkerSize(0.0);


  gTransRatio->SetLineColor(color2);
  gTransRatio->SetLineWidth(linewit);
  gTransRatio->SetMarkerColor(color2);
  gTransRatio->SetMarkerStyle(markersty);
  gTransRatio->SetMarkerSize(markersiz);

  gTransRatioFocus->SetLineColor(color1);
  gTransRatioFocus->SetLineWidth(linewit);
  gTransRatioFocus->SetMarkerColor(color1);
  gTransRatioFocus->SetMarkerStyle(markersty);
  gTransRatioFocus->SetMarkerSize(markersiz);


  // Canvas setup
  // Create the canvas and the pads before the Frame loop
  // Resolution:
  Int_t sizex = 800;
  Int_t sizey = 1000;
  char cName[32];

  sprintf(cName,"C");     
  TCanvas *C = (TCanvas*) gROOT->FindObject(cName);
  if(C==NULL) C = new TCanvas("C","",sizex,sizey);
  C->cd();

  C->Clear();

  // Setup Pad layout: 
  const Int_t Npads = 5;
 
  // Text objects
  // TPaveText **textLabel = new TPaveText*[Npads];

  TPad **pad = new TPad*[Npads];
  TH1F *hFrame[Npads];
  TGaxis *axis[Npads];
  TLegend *Leg[Npads];

  // Setup Pad layout:
  Double_t lMargin = 0.14;
  Double_t rMargin = 0.05;
  Double_t bMargin = 0.10;
  Double_t tMargin = 0.04;
  Float_t mMargin = 0.01;
  PGlobals::CanvasPartition(C,Npads,lMargin,rMargin,bMargin,tMargin,mMargin);
  //PGlobals::CanvasAsymPartition(C,Npads,lMargin,rMargin,bMargin,tMargin,1.,mMargin);
  
  // Define the frames for plotting
  Int_t fonttype = 43;
  Int_t fontsize = 24;
  Int_t tfontsize = 28;
  Float_t txoffset = 3.8;
  Float_t lxoffset = 0.02;
  Float_t tyoffset = 2.0;
  Float_t lyoffset = 0.01;
  Float_t tylength = 0.02;
  Float_t txlength = 0.04;
  for(Int_t i=0;i<Npads;i++) {
    char name[16];
    sprintf(name,"pad_%i",i);
    pad[i] = (TPad*) gROOT->FindObject(name);
    pad[i]->SetFrameLineWidth(2);  
    // pad[i]->SetTickx(1);
    // pad[i]->SetTicky(1);
    
    sprintf(name,"hFrame_%i",i);  
    hFrame[i] = (TH1F*) gROOT->FindObject(name);
    if(hFrame[i]) delete hFrame[i];

    hFrame[i] = new TH1F(name,"",100,xMin,xMax);
    hFrame[i]->Reset();
    
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[i]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[i]->GetAbsHNDC();
    
    // Format for y axis
    hFrame[i]->GetYaxis()->SetTitleFont(fonttype);
    hFrame[i]->GetYaxis()->SetTitleSize(tfontsize);
    hFrame[i]->GetYaxis()->SetTitleOffset(tyoffset);
    hFrame[i]->GetYaxis()->SetLabelFont(fonttype);
    hFrame[i]->GetYaxis()->SetLabelSize(fontsize);
    hFrame[i]->GetYaxis()->SetLabelOffset(lyoffset);
    hFrame[i]->GetYaxis()->SetTickLength(xFactor*tylength/yFactor);
    hFrame[i]->GetYaxis()->CenterTitle();
    
    // Format for x axis
    hFrame[i]->GetXaxis()->SetTitleFont(fonttype);
    hFrame[i]->GetXaxis()->SetTitleSize(tfontsize+2);
    hFrame[i]->GetXaxis()->SetTitleOffset(txoffset);
    hFrame[i]->GetXaxis()->SetLabelFont(fonttype);
    hFrame[i]->GetXaxis()->SetLabelSize(fontsize+2);
    hFrame[i]->GetXaxis()->SetLabelOffset(lxoffset);
    hFrame[i]->GetXaxis()->CenterTitle();
    hFrame[i]->GetXaxis()->SetTickLength(yFactor*txlength/xFactor);      
  }


  C->cd(0);

  pad[0]->Draw();
  pad[0]->cd();

  //  gPad->SetLogx(1);
  Float_t yMin = minTR - (maxTR-minTR)*0.2;
  Float_t yMax = maxTR + (maxTR-minTR)*0.2;
  if(yMin<0.0) yMin = 0.001;
  hFrame[0]->GetYaxis()->SetRangeUser(yMin,yMax);  
  
  hFrame[0]->GetXaxis()->SetTitle("#Lambda_{b}");
  if(opt.Contains("kA"))
    hFrame[0]->GetXaxis()->SetTitle("I_{b}^{ 0} [kA]");

  hFrame[0]->GetYaxis()->SetTitle("R");
  hFrame[0]->Draw("AXIS");

  // if(opt.Contains("theo")) {
  //   gDeltaPsiLO->Draw("PL");
  //   gDeltaPsiLU->Draw("PL");
  // }

  gTransRatio->Draw("PL");
  gTransRatioFocus->Draw("PL");

  Int_t fontsizeleg = 20;
  if(opt.Contains("leg")) { 
    Leg[0]=new TLegend(1 - gPad->GetRightMargin() - 0.26, gPad->GetBottomMargin() + 0.40,
		       1 - gPad->GetRightMargin() - 0.02, gPad->GetBottomMargin() + 0.55); 
    PGlobals::SetPaveStyle(Leg[0]);
    Leg[0]->SetTextAlign(13);
    Leg[0]->SetTextColor(kGray+3);
    Leg[0]->SetTextFont(43);
    Leg[0]->SetTextSizePixels(fontsizeleg);
    Leg[0]->SetLineColor(1);
    Leg[0]->SetBorderSize(0);
    Leg[0]->SetFillColor(0);
    Leg[0]->SetFillStyle(1001);
    Leg[0]->SetFillStyle(0); // Hollow

    Leg[0]->AddEntry(gTransRatio,"Max R","LP");
    Leg[0]->AddEntry(gTransRatioFocus,"Max R in focus","LP");

    Leg[0]->Draw();
  }    

  
  C->cd(0);
  pad[1]->Draw();
  pad[1]->cd();

  //  gPad->SetLogx(1);
  yMin = minPsi - (maxPsi-minPsi)*0.2;
  yMax = maxPsi + (maxPsi-minPsi)*0.2;
  //if(yMin<0.0) yMin = 0.001;
  hFrame[1]->GetYaxis()->SetRangeUser(yMin,yMax);  
  
  hFrame[1]->GetXaxis()->SetTitle("#Lambda_{b}");
  if(opt.Contains("kA"))
    hFrame[1]->GetXaxis()->SetTitle("I_{b} [kA]");

  hFrame[1]->GetYaxis()->SetTitle("#Delta#psi");
  hFrame[1]->Draw("AXIS");

  TLine *line1 = new TLine(xMin,1.0,xMax,1.0);
  line1->SetLineColor(kGray+2);
  line1->SetLineStyle(2);
  line1->Draw();

  if(opt.Contains("theo")) {
    gDeltaPsiLO->Draw("PL");
    gDeltaPsiLU->Draw("PL");
  }
  gDeltaPsi->Draw("PL");
  gDeltaPsiFocus->Draw("PL");

  if(opt.Contains("leg")) { 
    Leg[1]=new TLegend(gPad->GetLeftMargin() + 0.03, 1 - gPad->GetTopMargin() - 0.32,
		       gPad->GetLeftMargin() + 0.24, 1 - gPad->GetTopMargin() - 0.08); 
    PGlobals::SetPaveStyle(Leg[1]);
    Leg[1]->SetTextAlign(13);
    Leg[1]->SetTextColor(kGray+3);
    Leg[1]->SetTextFont(43);
    Leg[1]->SetTextSizePixels(fontsizeleg);
    Leg[1]->SetLineColor(1);
    Leg[1]->SetBorderSize(0);
    Leg[1]->SetFillColor(0);
    Leg[1]->SetFillStyle(1001);
    Leg[1]->SetFillStyle(0); // Hollow

    Leg[1]->AddEntry(gDeltaPsi,"Max #Delta#psi","LP");
    Leg[1]->AddEntry(gDeltaPsiFocus,"Max #Delta#psi in focus","LP");
    // Leg[1]->AddEntry(gDeltaPsiLO,"Max #Psi Lotov","L");
    // Leg[1]->AddEntry(gDeltaPsiLU,"Max #Psi Lu","L");

    Leg[1]->Draw();
  }    

  C->cd(0);
  pad[2]->Draw();
  pad[2]->cd();

  // gPad->SetLogx(1);
  yMin = minEz - (maxEz-minEz)*0.2;
  yMax = maxEz + (maxEz-minEz)*0.2;
  if(yMin<=0.0) yMin = -0.999;
  hFrame[2]->GetYaxis()->SetRangeUser(yMin,yMax);  
  hFrame[2]->GetYaxis()->SetTitle("|E_{z}/E_{0}|");
  hFrame[2]->Draw("AXIS");

  TLine *line0 = new TLine(xMin,0.0,xMax,0.0);
  line0->SetLineColor(kGray+2);
  line0->SetLineStyle(2);
  line0->Draw();

  if(opt.Contains("theo")) {
    gEzMaxLO->Draw("PL");
    //gEzMaxUseBO->Draw("PL");
    gEzMaxBeamLO->Draw("PL");
    //   gEzMaxLU->Draw("PL");
  }

  gEzMax->Draw("PL");
  // gEzMaxUse->Draw("PL");
  gEzMaxBeam->Draw("PL");
  gEzLimit->Draw("PL");
  gEzMaxFocus->Draw("PL");

  if(opt.Contains("leg")) { 
    Leg[2]=new TLegend(gPad->GetLeftMargin() + 0.03, 1 - gPad->GetTopMargin() - 0.4, gPad->GetLeftMargin() + 0.24, 1 - gPad->GetTopMargin() - 0.04); 
    PGlobals::SetPaveStyle(Leg[2]);
    Leg[2]->SetTextAlign(13);
    Leg[2]->SetTextColor(kGray+3);
    Leg[2]->SetTextFont(43);
    Leg[2]->SetTextSizePixels(fontsizeleg-2);
    Leg[2]->SetLineColor(1);
    Leg[2]->SetBorderSize(0);
    Leg[2]->SetFillColor(0);
    Leg[2]->SetFillStyle(1001);
    Leg[2]->SetFillStyle(0); // Hollow

    Leg[2]->AddEntry(gEzMax,"Min E_{z}","LP");
    Leg[2]->AddEntry(gEzMaxFocus,"Min E_{z} in focus","LP");
    Leg[2]->AddEntry(gEzLimit,"Min E_{z} trapping","LP");
    Leg[2]->AddEntry(gEzMaxBeam,"Max E_{z} beam","LP");

    Leg[2]->Draw();
  }

  C->cd(0);
  pad[3]->Draw();
  pad[3]->cd();

  // gPad->SetLogx(1);
  yMin = minEzSlope - (maxEzSlope-minEzSlope)*0.25;
  yMax = maxEzSlope + (maxEzSlope-minEzSlope)*0.25;
  if(yMin<=0.0) yMin = -0.999;
  //  hFrame[3]->GetYaxis()->SetRangeUser(yMin,yMax);
  hFrame[3]->GetYaxis()->SetRangeUser(-0.0499,0.5499);
  hFrame[3]->GetYaxis()->SetNdivisions(510);
  hFrame[3]->GetYaxis()->SetTitle("#partial_{#zeta}E_{z}^{0}/k_{p}E_{0}");
  hFrame[3]->Draw("AXIS");

  TLine *line05 = new TLine(xMin,0.5,xMax,0.5);
  line05->SetLineColor(kGray+2);
  line05->SetLineStyle(2);
  line05->Draw();

  line0->Draw();
  
  if(opt.Contains("theo")) {
    //   gEzSlopeLO->Draw("PL");
  }

  gEzSlope->Draw("PL");
  // gEzSlopeMaxFocus->Draw("PL");

  if(opt.Contains("leg")) { 
    Leg[3]=new TLegend(1 - gPad->GetRightMargin() - 0.26, gPad->GetBottomMargin() + 0.14,1- gPad->GetRightMargin() - 0.02, gPad->GetBottomMargin() + 0.24); 
    PGlobals::SetPaveStyle(Leg[3]);
    Leg[3]->SetTextAlign(12);
    Leg[3]->SetTextColor(kGray+3);
    Leg[3]->SetTextFont(43);
    Leg[3]->SetTextSizePixels(fontsizeleg);
    Leg[3]->SetLineColor(1);
    Leg[3]->SetBorderSize(0);
    Leg[3]->SetFillColor(0);
    Leg[3]->SetFillStyle(1001);
    Leg[3]->SetFillStyle(0); // Hollow

    Leg[3]->AddEntry(gEzSlope,"E_{z} slope at #zeta_{m}","LP");
 
    Leg[3]->Draw();
  }

  C->cd(0);

  pad[4]->Draw();
  pad[4]->cd();

  //  gPad->SetLogx(1);

  yMin = minRadius - (maxRadius-minRadius)*0.2;
  yMax = maxRadius + (maxRadius-minRadius)*0.2;
  if(yMin<=0.0) yMin = -0.999;
  hFrame[4]->GetYaxis()->SetRangeUser(yMin,yMax);  
  hFrame[4]->GetYaxis()->SetTitle("k_{p} x");
  hFrame[4]->Draw("AXIS");
  
  line0->Draw();

  if(opt.Contains("theo")) {
    gRadiusLO->Draw("PL");
    gRadiusLU->Draw("PL");
    //    gRadiusPsiBO->Draw("PL");
  }

  gRadiusPsi->Draw("PL");
  gRadiusX->Draw("PL");
  gRadiusZ->Draw("PL");

  if(opt.Contains("leg")) { 
    Leg[4]=new TLegend(1 - gPad->GetRightMargin() - 0.15, gPad->GetBottomMargin() + 0.15,
		       1 - gPad->GetRightMargin() + 0.09, gPad->GetBottomMargin() + 0.45); 
    PGlobals::SetPaveStyle(Leg[4]);
    Leg[4]->SetTextAlign(12);
    Leg[4]->SetTextColor(kGray+3);
    Leg[4]->SetTextFont(43);
    Leg[4]->SetTextSizePixels(fontsizeleg);
    Leg[4]->SetLineColor(1);
    Leg[4]->SetBorderSize(0);
    Leg[4]->SetFillColor(0);
    Leg[4]->SetFillStyle(1001);
    Leg[4]->SetFillStyle(0); // Hollow

    // Leg[4]->AddEntry(gRadiusZ,"Longitudinal radius","LP");
    // Leg[4]->AddEntry(gRadiusX,"Transverse radius","LP");
    // Leg[4]->AddEntry(gRadiusPsi,"Trapping radius","LP");
    Leg[4]->AddEntry(gRadiusZ,"l_{m}","LP");
    Leg[4]->AddEntry(gRadiusX,"r_{m}","LP");
    Leg[4]->AddEntry(gRadiusPsi,"l_{t}","LP");
 
    Leg[4]->Draw();
  }
  C->cd();
  
  // Output file
  TString fOutName = Form("./Blowout/Blowout-Scalings");
  fOutName += Form("_%i",time);
  
  PGlobals::imgconv(C,fOutName,opt);
  // ---------------------------------------------------------
  
  
}
Example #9
0
void PlotHARPHisto( std::string beam, std::string target, std::string energy,
                    std::string secondary,
		    std::string region,
		    int ibin )
{
   
   // ReadHARPData( beam, target, energy, secondary, region );
   
   double ymin = 10000.; // something big... don't know if I can use FLT_MAX
   double ymax = -1. ;
   
   for ( int i=0; i<NPoints[ibin]; i++ )
   {
      if ( (Y[ibin][i]+EY[ibin][i]) > ymax ) ymax = Y[ibin][i]+EY[ibin][i];
      if ( (Y[ibin][i]-EY[ibin][i]) < ymin && (Y[ibin][i]-EY[ibin][i]) > 0. ) ymin = (Y[ibin][i]-EY[ibin][i]);
   }
   
   TH1F* hi[NModels];
   std::string YTitle;

   for ( int m=0; m<NModels; m++ )
   {

      std::string histofile = "";
      
      // histofile = "./harp-histo/";
      histofile = "./harp-histo-no-res-decays/";
      // histofile = "../t23-bld/harp-histo/";
      
      // std::string histofile = "./harp-histo/" + beam + target + energy + "GeV" + ModelName[m] + ".root"; 
      histofile += ( beam + target + energy + "GeV" + ModelName[m] + ".root" ); 
      
      // std::cout << " histofile = " << histofile << std::endl;
      
      TFile* f = new TFile( histofile.c_str() );
      
      char buf[5];
      sprintf( buf, "%i", ibin );      
      std::string histoname = secondary + "_" + region + "_";
      histoname.append( buf );
      
      hi[m] = (TH1F*)f->Get( histoname.c_str() );
      
      hi[m]->SetStats(0);
      hi[m]->SetLineColor(ColorModel[m]);
      hi[m]->SetLineWidth(2);
      
      int nx = hi[m]->GetNbinsX();
      for (int k=1; k <= nx; k++) 
      {
	double yy = hi[m]->GetBinContent(k);
	if ( yy > ymax ) ymax = yy;
	if ( yy < ymin && yy > 0. ) ymin = yy;
      }
      if ( m == 0 ) 
      {
         hi[m]->Draw();
	 hi[m]->GetXaxis()->SetTitle("momentum (GeV/c)");
	 //hi[m]->GetYaxis()->SetTitle( YTitle.c_str() );
	 // hi[m]->GetYaxis()->SetTitle("#frac{d^{2}#sigma}{dpd#Theta} [mb/(GeV/c/rad)]");
	 hi[m]->GetYaxis()->SetTitle("d^{2}#sigma / dpd#Theta [mb/(GeV/c/rad)]");
	 hi[m]->GetYaxis()->SetTitleOffset(1.5);
      }
      else hi[m]->Draw("same"); 
            
   }
   
   TLegend* leg = new TLegend(0.6, 0.70, 0.9, 0.9);
   
   for ( int m=0; m<NModels; m++ )
   {
      hi[m]->GetYaxis()->SetRangeUser(ymin,ymax*1.1); // hi[m]->SetTitle("");
      leg->AddEntry( hi[m], ModelName[m].c_str(), "L" );
   }
      
   float* X = new float[NPoints[ibin]];
   for ( int i=0; i<NPoints[ibin]; i++ )
   {
      X[i] = 0.5 * (XMin[ibin][i]+XMax[ibin][i]);
      //std::cout << "X[" << i << "] = " << X[i] << std::endl;
      //std::cout << "Y[" << i << "] = " << Y[0][i] << std::endl;
   }
   
   TGraph* gr = new TGraphErrors( NPoints[ibin], X, Y[ibin], 0, EY[ibin] );
   gr->SetMarkerColor(kBlue);
   gr->SetMarkerStyle(22);
   gr->SetMarkerSize(1.5);
    
   gr->Draw("p");
      
   leg->AddEntry( gr, "exp.data", "p");

   leg->Draw();
   leg->SetFillColor(kWhite);   


   return;

}