Example #1
0
void twoscales()
{
   TCanvas *c1 = new TCanvas("c1","hists with different scales",600,400);

   //create/fill draw h1
   gStyle->SetOptStat(kFALSE);
   TH1F *h1 = new TH1F("h1","my histogram",100,-3,3);
   Int_t i;
   for (i=0;i<10000;i++) h1->Fill(gRandom->Gaus(0,1));
   h1->Draw();
   c1->Update();

   //create hint1 filled with the bins integral of h1
   TH1F *hint1 = new TH1F("hint1","h1 bins integral",100,-3,3);
   Float_t sum = 0;
   for (i=1;i<=100;i++) {
      sum += h1->GetBinContent(i);
      hint1->SetBinContent(i,sum);
   }

   //scale hint1 to the pad coordinates
   Float_t rightmax = 1.1*hint1->GetMaximum();
   Float_t scale = gPad->GetUymax()/rightmax;
   hint1->SetLineColor(kRed);
   hint1->Scale(scale);
   hint1->Draw("same");

   //draw an axis on the right side
   TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
         gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"+L");
   axis->SetLineColor(kRed);
   axis->SetLabelColor(kRed);
   axis->Draw();
}
Example #2
0
File: xyplot.C Project: Y--/root
void xyplot()
{
   TCanvas *c = new TCanvas("c","XY plot",200,10,700,500);

   // Remove the frame
   c->SetFillColor(kWhite);
   c->SetFrameLineColor(kWhite);
   c->SetFrameBorderMode(0);

   // Define and draw a curve the frame
   const Int_t n = 4;
   Double_t x[n] = {-1, -3, -9, 3};
   Double_t y[n] = {-1000,  900,  300, 300};
   gr = new TGraph(n,x,y);
   gr->SetTitle("XY plot");
   gr->SetMinimum(-1080);
   gr->SetMaximum(1080);
   gr->SetLineColor(kRed);
   gr->Draw("AC*");

   // Remove the frame's axis
   gr->GetHistogram()->GetYaxis()->SetTickLength(0);
   gr->GetHistogram()->GetXaxis()->SetTickLength(0);
   gr->GetHistogram()->GetYaxis()->SetLabelSize(0);
   gr->GetHistogram()->GetXaxis()->SetLabelSize(0);
   gr->GetHistogram()->GetXaxis()->SetAxisColor(0);
   gr->GetHistogram()->GetYaxis()->SetAxisColor(0);

   gPad->Update();

   // Draw orthogonal axis system centered at (0,0).
   // Draw the Y axis. Note the 4th label is erased with SetLabelAttributes
   TGaxis *yaxis = new TGaxis(0, gPad->GetUymin(),
                              0, gPad->GetUymax(),
                              gPad->GetUymin(),gPad->GetUymax(),6,"+LN");
   yaxis->ChangeLabel(4,-1,0.);
   yaxis->Draw();

   // Draw the Y-axis title.
   TLatex *ytitle = new TLatex(-0.5,gPad->GetUymax(),"Y axis");
   ytitle->Draw();
   ytitle->SetTextSize(0.03);
   ytitle->SetTextAngle(90.);
   ytitle->SetTextAlign(31);

   // Draw the X axis
   TGaxis *xaxis = new TGaxis(gPad->GetUxmin(), 0,
                              gPad->GetUxmax(), 0,
                              gPad->GetUxmin(),gPad->GetUxmax(),510,"+L");
   xaxis->Draw();

   // Draw the X axis title.
   TLatex *xtitle = new TLatex(gPad->GetUxmax(),-200.,"X axis");
   xtitle->Draw();
   xtitle->SetTextAlign(31);
   xtitle->SetTextSize(0.03);
}
Example #3
0
ReverseXAxis (TGraphAsymmErrors *g, double  size)
{
// Remove the current axis
   g->GetXaxis()->SetLabelOffset(999);
   g->GetXaxis()->SetTickLength(0);

//  Redraw the new axis 
   gPad->Update();

	g->GetYaxis()->SetTitle("Event Selection Efficiency");
   TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
                                gPad->GetUymin(),
                                gPad->GetUxmin(),
                                gPad->GetUymin(),
                                g->GetXaxis()->GetXmin(),
                                g->GetXaxis()->GetXmax(),
                                510,"-");
   newaxis->SetLabelOffset(-0.04);
   newaxis->SetTitle("Centrality");
   newaxis->SetTitleFont(42);
   newaxis->SetTitleSize(size);
   newaxis->SetLabelSize(size);
   newaxis->CenterTitle();
   newaxis->SetLabelFont(42);
   newaxis->Draw();


}
Example #4
0
// Example of a canvas showing two histograms with different scales.
// The second histogram is drawn in a transparent pad
void transpad() {
   TCanvas *c1 = new TCanvas("c1","transparent pad",200,10,700,500);
   TPad *pad1 = new TPad("pad1","",0,0,1,1);
   TPad *pad2 = new TPad("pad2","",0,0,1,1);
   pad2->SetFillStyle(4000); //will be transparent
   pad1->Draw();
   pad1->cd();

   TH1F *h1 = new TH1F("h1","h1",100,-3,3);
   TH1F *h2 = new TH1F("h2","h2",100,-3,3);
   TRandom r;
   for (Int_t i=0;i<100000;i++) {
      Double_t x1 = r.Gaus(-1,0.5);
      Double_t x2 = r.Gaus(1,1.5);
      if (i <1000) h1->Fill(x1);
      h2->Fill(x2);
   }
   h1->Draw();
   pad1->Update(); //this will force the generation of the "stats" box
   TPaveStats *ps1 = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats");
   ps1->SetX1NDC(0.4); ps1->SetX2NDC(0.6);
   pad1->Modified();
   c1->cd();
   
   //compute the pad range with suitable margins
   Double_t ymin = 0;
   Double_t ymax = 2000;
   Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
   Double_t xmin = -3;
   Double_t xmax = 3;
   Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
   pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
   pad2->Draw();
   pad2->cd();
   h2->SetLineColor(kRed);
   h2->Draw("sames");
   pad2->Update();
   TPaveStats *ps2 = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats");
   ps2->SetX1NDC(0.65); ps2->SetX2NDC(0.85);
   ps2->SetTextColor(kRed);
   
   // draw axis on the right side of the pad
   TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
   axis->SetLabelColor(kRed);
   axis->Draw();
}
Example #5
0
void ReverseXAxis (TH1 *h)
{
   h->GetXaxis()->SetLabelOffset(999);
   h->GetXaxis()->SetTickLength(0);

   gPad->Update();
   TGaxis *newaxis = new TGaxis(gPad->GetUxmax(),
                                gPad->GetUymin(),
                                gPad->GetUxmin(),
                                gPad->GetUymin(),
                                h->GetXaxis()->GetXmin(),
                                h->GetXaxis()->GetXmax(),
                                510,"-");
   newaxis->SetLabelOffset(-0.03);
   newaxis->SetTitle("X[cm]");
   newaxis->CenterTitle(1);
   newaxis->Draw();
}
Example #6
0
void drawLabels(){
  TLatex l;
  l.SetTextSize(0.04);
  l.DrawLatex(500,50,"-z");
  l.DrawLatex(500,1430,"+z");
  l.DrawLatex(900,330,"TIB L1");
  l.DrawLatex(900,1000,"TIB L2");
  l.DrawLatex(1300,330,"TIB L3");
  l.DrawLatex(1300,1000,"TIB L4");
  l.DrawLatex(1700,330,"TOB L1");
  l.DrawLatex(1700,1000,"TOB L2");
  l.DrawLatex(2100,330,"TOB L3");
  l.DrawLatex(2100,1000,"TOB L4");
  l.DrawLatex(2500,330,"TOB L5");
  l.DrawLatex(2500,1000,"TOB L6");
  TArrow arx(2900,1190,2900,1350,0.01,"|>");
  l.DrawLatex(2915,1350,"x");
  TArrow ary(2900,1190,2790,1190,0.01,"|>");
  l.DrawLatex(2790,1210,"y");
  TArrow arz(2790,373,2790,672,0.01,"|>");
  l.DrawLatex(2820,667,"z");
  TArrow arphi(2790,511,2447,511,0.01,"|>");
  l.DrawLatex(2433,520,"#Phi");
  arx.SetLineWidth(3);
  ary.SetLineWidth(3);
  arz.SetLineWidth(3);
  arphi.SetLineWidth(3);
  arx.Draw();
  ary.Draw();
  arz.Draw();
  arphi.Draw();

  //FIXME : when tkmaps with taxis in color palette, introduce this
  TGaxis* axis = new TGaxis(3060,hmin,3060,hmax,0,100,510,"+L");
  axis->SetLabelSize(0.02);
  axis->Draw();

  canvas->Update();
}
Example #7
0
//==========================================
//==========================================
void plotPair(TH1F *h1,TH1F *h0 ) {
  h1->Draw();

  // edit fonts/sizes
  TAxis *ax =h1->GetYaxis(); 
  float ss=ax->GetTitleSize();
  //printf("ss=%f\n",ss);
  ax->SetTitleSize(2*ss);
  ax->SetTitleOffset(0.5);
  ax =h1->GetXaxis(); 
 ax->SetTitleSize(1.5*ss);
 ax->SetLabelSize(1.5*ss);
 ax->SetTitleOffset(0.7);
 

  // edit fonts/sizes DONE



  gPad->Update();
  //scale hint1 to the pad coordinates
  Float_t rightmax = 1.1*h0->GetMaximum();
  Float_t scale = gPad->GetUymax()/rightmax;
  h0->Scale(scale);
  h0->Draw("same");
   
  //draw an axis on the right side
  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
	      gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"-R");
  int col=h0->GetLineColor();
  axis->SetLineColor(col);
  
  axis->SetTextColor(col);
  axis->SetLabelColor(col);
  axis ->SetTitle("LCP yield");
 axis->SetTitleSize(2*ss);
 axis->SetTitleOffset(.5);

  axis->Draw();
  
  
  TPaveStats *st =( TPaveStats *)gPad->GetPrimitive("stats");
  st->SetX1NDC(0.35);
  st->SetX2NDC(0.5);
  st->SetY1NDC(0.7);
  st->SetY2NDC(1.);
}
Example #8
0
  void draw_sigvsback(std::string const & cname,
		      std::string const & dr,
		      std::string const & binning,
		      std::string const & we_sig,
		      std::string const & sig_label,
		      std::string const & we_back,		     
		      std::string const & back_label,		     
		      std::string const & op = "",
		      std::string const & title = "",
		      std::string const & xtitle = "",
		      std::string const & ytitle = "",
		      bool const significance = false,
		      bool const efficiency = false,
		      bool const forwards = false) {
    
    TString hname_sig = "h_sig";
    TString draw_str_sig = "";
    draw_str_sig += dr;
    draw_str_sig += ">>";
    draw_str_sig += hname_sig;
    draw_str_sig += binning;
    
    TString hname_back = "h_back";
    TString draw_str_back = "";
    draw_str_back += dr;
    draw_str_back += ">>";
    draw_str_back += hname_back;
    draw_str_back += binning;
    
    TCanvas * canvas = new TCanvas("temp");
    if(tree2)
      tree2->Draw(draw_str_sig.Data(),
		  we_sig.c_str(),
		  op.c_str());
    else
      tree->Draw(draw_str_sig.Data(),
		 we_sig.c_str(),
		 op.c_str());
    delete canvas;
    
    canvas = new TCanvas("temp");
    tree->Draw(draw_str_back.Data(),
	       we_back.c_str(),
	       op.c_str());
    delete canvas;
    
    TH1F * hist_sig = (TH1F*)gDirectory->Get(hname_sig.Data());
    TH1F * hist_back = (TH1F*)gDirectory->Get(hname_back.Data()); 
    if(hist_sig->GetEntries() == 0) 
      std::cout << "draw_sigvsback: No signal for selection: \"" << we_sig << "\"\n";
    if(hist_back->GetEntries() == 0) 
      std::cout << "draw_sigvsback: No background for selection: \"" << we_back << "\"\n";    
    
    hist_back->SetStats(0);
    hist_back->SetTitle(title.c_str());
    hist_back->GetXaxis()->SetTitle(xtitle.c_str());
    hist_back->GetXaxis()->CenterTitle(); 
    hist_back->GetYaxis()->SetTitle(ytitle.c_str());
    hist_back->GetYaxis()->CenterTitle();
    hist_sig->SetLineColor(kRed);
    hist_back->SetLineColor(kBlue);

    TLegend * legend = new TLegend(0.6, 0.9, 0.9, 0.6);
    /*
    legend->SetHeader(("Total: "+to_string_with_precision(hist_sig->Integral()+hist_back->Integral())+" events").c_str());
    ((TLegendEntry*)legend->GetListOfPrimitives()->First())->SetTextAlign(22);
    
    legend->AddEntry(hist_sig, (sig_label+": "+to_string_with_precision(hist_sig->Integral())+" events").c_str());
    legend->AddEntry(hist_back, (back_label+": "+to_string_with_precision(hist_back->Integral())+" events").c_str());
    */

    legend->AddEntry(hist_sig, (sig_label).c_str());
    legend->AddEntry(hist_back, (back_label).c_str());

    canvas = new TCanvas(cname.c_str());   
    TPad * pad_base = new TPad();
    pad_base->Draw();
    pad_base->SetFillColor(0);
    double ymin_base = hist_sig->GetYaxis()->GetXmin();
    double ymax_base = hist_sig->GetYaxis()->GetXmax();
    double dy_base = (ymax_base-ymin_base)/0.8;
    double xmin_base = hist_sig->GetXaxis()->GetXmin();
    double xmax_base = hist_sig->GetXaxis()->GetXmax();
    double dx_base = (xmax_base-xmin_base)/0.8;
    pad_base->Range(xmin_base-0.1*dx_base,ymin_base-0.1*dy_base,xmax_base+0.1*dx_base,ymax_base+0.1*dy_base);
    pad_base->cd();
    hist_back->Draw();
    hist_sig->Draw("same");
    if(!significance && !efficiency) legend->Draw();

    //////    
    hist_sig->Scale(run_pot / signal_pot);
    hist_back->Scale(run_pot / background_pot);
    //////

    TGraph * graph_sig = nullptr;
    TPad * pad_sig = nullptr;
    if(significance) {
      graph_sig = getgraphsig(hist_sig, hist_back, forwards);
      canvas->cd();
      pad_sig = new TPad();
      pad_sig->SetFillStyle(4000);
      double ymin = graph_sig->GetYaxis()->GetXmin();
      double ymax = graph_sig->GetYaxis()->GetXmax();
      double dy = (ymax-ymin)/0.8;
      double xmax = 0;
      double ytemp = 0;
      graph_sig->GetPoint(graph_sig->GetN()-1, xmax, ytemp);
      pad_sig->Range(xmin_base-0.1*dx_base,ymin-0.1*dy,xmax_base+0.1*dx_base,ymax+0.1*dy);
      pad_sig->Draw();
      pad_sig->cd();
      graph_sig->Draw("samep");
      TGaxis * axis = new TGaxis(xmax_base,ymin,xmax_base,ymax,ymin,ymax, 510, "+L");
      axis->SetLabelColor(graph_sig->GetMarkerColor());
      axis->SetLabelSize(0.03);
      axis->Draw();
      legend->AddEntry(graph_sig, "Significance");
      if(!efficiency) legend->Draw();
    }

    TGraph * graph_eff = nullptr;
    TPad * pad_eff = nullptr;
    if(efficiency) {
      graph_eff = getgrapheff(hist_sig, forwards);
      canvas->cd();
      pad_eff = new TPad();
      pad_eff->SetFillStyle(4000);
      double ymin = graph_eff->GetYaxis()->GetXmin();
      double ymax = graph_eff->GetYaxis()->GetXmax();
      double dy = (ymax-ymin)/0.8;
      double xmax = 0;
      double ytemp = 0;
      graph_eff->GetPoint(graph_eff->GetN()-1, xmax, ytemp);
      pad_eff->Range(xmin_base-0.1*dx_base,ymin-0.1*dy,xmax_base+0.1*dx_base,ymax+0.1*dy);
      pad_eff->Draw();
      pad_eff->cd();
      graph_eff->Draw("samep");
      double axis_offset = 0;
      if(significance) axis_offset = 1./14*xmax;
      TGaxis * axis = new TGaxis(xmax_base+axis_offset,ymin,xmax_base+axis_offset,ymax,ymin,ymax, 510, "+L");   
      axis->SetLabelColor(graph_eff->GetMarkerColor());
      axis->SetLabelSize(0.03);
      axis->Draw();
      legend->AddEntry(graph_eff, "Efficiency");
      legend->Draw();
    }

    hist_sig->Scale(signal_pot / run_pot);
    hist_sig->Scale(1. / hist_sig->Integral());
    hist_back->Scale(background_pot / run_pot);
    hist_back->Scale(1. / hist_back->Integral()); 

    double const ymin_hist = 0;
    double ymax_hist = hist_sig->GetMaximum();
    if(hist_back->GetMaximum() > ymax_hist) ymax_hist = hist_back->GetMaximum();
    hist_back->GetYaxis()->SetRangeUser(ymin_hist, 1.1*ymax_hist);

    canvas->Write();
    delete canvas;
    delete hist_sig;
    delete hist_back;
    delete legend;
    if(graph_sig) delete graph_sig;
    if(graph_eff) delete graph_eff;

  }
Example #9
0
 void drawmat_DBD(char* FILEN) {

   //char* title = "Material budget for ILD_O1_v05" ;


   double M_PI = 3.14159265358979312e+00 ;
   //   180./pi = 57.295779 ;
   
   //ntuple variables
   double itheta, nrvxd, nrsit, nrtpc, nrtpc_i, nrset, nrecal ;

   
   // stuff for histograms
   const int nhist = 7;
   TString htitle[nhist];
   int idx = 0 ;
   htitle[idx++] = "ECAL layer 1";
   htitle[idx++] = "SET";
   htitle[idx++] = "outside TPC";
   htitle[idx++] = "TPC";
   htitle[idx++] = "SIT + FTD";
   htitle[idx++] = "VXT";
   htitle[idx++] = "dummy";
   TString hname[nhist];
   idx = 0 ;
   hname[idx++] = "ecal";
   hname[idx++] = "set";
   hname[idx++] = "tpc_o";
   hname[idx++] = "tpc_i";
   hname[idx++] = "sit";
   hname[idx++] = "vtx";
   hname[idx++] = "dummy";

   int nbin = 90 ; // 720

   float xmin = -90;
   float xmax = -0;
   int color[nhist] = { 14, 8, 38, 2, 1, 9};
   TString option[nhist];
      
  TLegend *leg = new TLegend (0.2, 0.7, 0.45, 0.9);
  leg->SetFillStyle(0);
  
   // stuff for histograms
   TH1F* hmat[nhist];
   for (int ihist = 0; ihist < nhist; ihist++) {
     hmat[ihist] = new TH1F(hname[ihist],"",nbin,xmin,xmax);
     //// ensure proper errors
     // hmat[ihist]->Sumw2();
     hmat[ihist]->SetLineColor(color[ihist]);
     hmat[ihist]->SetLineWidth(3);
     hmat[ihist]->SetTitle(";#theta / degrees;X_{0}");
   }
   
   
  // read tree
  TFile* file = new TFile ( FILEN ) ;
  TTree* tree = (TTree *) file->Get("ntuple");
  if (!tree) {
    cout << "ERROR: Couldn't open tree ntuple on file: "<< FILEN << endl;
    return 1; 
  }
  
  tree->SetBranchAddress("itheta",  &itheta);
  tree->SetBranchAddress("nrecal",   &nrecal);
  tree->SetBranchAddress("nrset",   &nrset);
  tree->SetBranchAddress("nrtpc",   &nrtpc);
  tree->SetBranchAddress("nrtpc_i", &nrtpc_i);
  tree->SetBranchAddress("nrsit",   &nrsit);
  tree->SetBranchAddress("nrvxd",   &nrvxd);
  int entries = tree->GetEntries();
    cout << "tree has " << entries << " entries" << endl;
  
  // event loop
  for (int ievt = 0; ievt < entries; ++ievt) {

     tree->GetEntry(ievt);
     if (itheta < 4.45) continue;


     hmat[0]->Fill(-itheta,nrecal);
     hmat[1]->Fill(-itheta,nrset);
     hmat[2]->Fill(-itheta,nrtpc);
     if( itheta > 8. ) 
     hmat[3]->Fill(-itheta,nrtpc_i);

     hmat[4]->Fill(-itheta,nrsit);
     hmat[5]->Fill(-itheta,nrvxd);
     hmat[6]->Fill(-itheta,1);
  }
  
//   for (int ibin = 0; ibin < nbin+1; ++ibin) {
//     cout << "Bin " << ibin << " has " << hmat[4]->GetBinContent(ibin) << " entries" << endl;
//   }

  c1 = new TCanvas("c1","c1",600,600);
  

  bool first = true ;

#define _include_Ecal 0

#if _include_Ecal 
  for (int ihist = 0; ihist < nhist-1; ihist++) {
#else
  for (int ihist = 1; ihist < nhist-1; ihist++) {
#endif

    // average double counts 
    hmat[ihist]->Divide( hmat[nhist-1] );

    if( first ) { 

      hmat[ihist]->Draw( ""  );

      // --------- change axis labels from minus to plus --------
      c1->Update() ;
      TF1 *f1 = new TF1("f1","-x",0,90);
      hmat[ihist]->GetXaxis()->SetLabelOffset(99);
      Double_t x_min = c1->GetUxmin();
      Double_t x_max = c1->GetUxmax();
      Double_t y_min = c1->GetUymin();
      //std::cout << "x_min " << x_min << " x_max " << x_max << " y_min " << y_min << std::endl ;
      TGaxis *axis = new TGaxis( x_min, y_min, x_max, y_min, "f1", 5);    
      axis->SetLabelSize( 0.06 );
      axis->SetLabelFont( 42 ); 
      axis->Draw(); 
      // -----end: change axis labels from minus to plus --------

      first = false ;


    } else {
      hmat[ihist]->Draw( "same"  );
    }

    leg->AddEntry(hmat[ihist],htitle[ihist],"L");

  }
  leg->Draw();
  

  std::string pdfFile( std::string( FILEN ) + std::string( ".pdf" ) ) ;
  c1->Print( pdfFile.c_str() ) ;
  
}
void composeTrackAnalysisbyAssociator(string FileListName, int FileNumber) {

    if(debug) cout << FileListName << endl;
    string theFileName;
    ifstream composeFileList;
    composeFileList.open(FileListName.c_str());

    string OutputPlotNamepreFix = FileListName + "_";
    string OutputPlotNameFix = ".png";

    unsigned int EventNumber;
    unsigned int trackingParticleMatch;
    double recTrackPurity;
    double recTrackrefMomentum;
    double recTrackrefPhi;
    double recTrackrefEta;
    double recTrackinnerMomentum;
    double recTrackinnerPhi;
    double recTrackinnerEta;
    unsigned int recTrackinnerValid;
    double recTrackouterMomentum;
    double recTrackouterPhi;
    double recTrackouterEta;
    unsigned int recTrackouterValid;
    double simTrackinnerMomentum;
    double simTrackinnerPhi;
    double simTrackinnerEta;
    unsigned int simTrackinnerMatch;
    double simTrackouterMomentum;
    double simTrackouterPhi;
    double simTrackouterEta;
    unsigned int simTrackouterMatch;
    double recTrackinnerMomentumofTSOS;
    double recTrackinnerPhiofTSOS;
    double recTrackinnerEtaofTSOS;
    unsigned int recTrackinnerValidofTSOS;
    double recTrackouterMomentumofTSOS;
    double recTrackouterPhiofTSOS;
    double recTrackouterEtaofTSOS;
    unsigned int recTrackouterValidofTSOS;
    double recTrackimpactMomentumofTSOS;
    double recTrackimpactPhiofTSOS;
    double recTrackimpactEtaofTSOS;
    unsigned int recTrackimpactValidofTSOS;
    int recTrackCharge;
    double simTrackMomentumPt;
    double simTrackPhi;
    double simTrackEta;
    int simTrackCharge;

    TObjArray* myEfficiencyHist = new TObjArray();
    TObjArray* myParticleHist = new TObjArray();
    TObjArray* mySTAHist = new TObjArray();
    TObjArray* myChargeCheckHist = new TObjArray();
    TObjArray* myDeltaPtHist = new TObjArray();
    TObjArray* myDeltaPhiHist = new TObjArray();
    TObjArray* myDeltaEtaHist = new TObjArray();
    vector<string> TypeName;
    TypeName.clear();

    for(int Index = 0; Index < FileNumber; Index++) {
        getline(composeFileList, theFileName);
        TypeName.push_back(theFileName);
        string fullFileName = "data/"+ theFileName + ".root";
        if(debug) cout << theFileName << endl;
        TFile* RootFile = TFile::Open(fullFileName.c_str());

        TTree* T1 = (TTree*)RootFile->Get("ExTree");
        T1->SetBranchAddress("EventNumber", &EventNumber);
        T1->SetBranchAddress("trackingParticleMatch", &trackingParticleMatch);
        T1->SetBranchAddress("recTrackPurity", &recTrackPurity);
        T1->SetBranchAddress("recTrackrefMomentum", &recTrackrefMomentum);
        T1->SetBranchAddress("recTrackrefPhi", &recTrackrefPhi);
        T1->SetBranchAddress("recTrackrefEta", &recTrackrefEta);
        T1->SetBranchAddress("recTrackinnerMomentum", &recTrackinnerMomentum);
        T1->SetBranchAddress("recTrackinnerPhi", &recTrackinnerPhi);
        T1->SetBranchAddress("recTrackinnerEta", &recTrackinnerEta);
        T1->SetBranchAddress("recTrackinnerValid", &recTrackinnerValid);
        T1->SetBranchAddress("recTrackouterMomentum", &recTrackouterMomentum);
        T1->SetBranchAddress("recTrackouterPhi", &recTrackouterPhi);
        T1->SetBranchAddress("recTrackouterEta", &recTrackouterEta);
        T1->SetBranchAddress("recTrackouterValid", &recTrackouterValid);
        T1->SetBranchAddress("simTrackinnerMomentum", &simTrackinnerMomentum);
        T1->SetBranchAddress("simTrackinnerPhi", &simTrackinnerPhi);
        T1->SetBranchAddress("simTrackinnerEta", &simTrackinnerEta);
        T1->SetBranchAddress("simTrackinnerMatch", &simTrackinnerMatch);
        T1->SetBranchAddress("simTrackouterMomentum", &simTrackouterMomentum);
        T1->SetBranchAddress("simTrackouterPhi", &simTrackouterPhi);
        T1->SetBranchAddress("simTrackouterEta", &simTrackouterEta);
        T1->SetBranchAddress("simTrackouterMatch", &simTrackouterMatch);
        T1->SetBranchAddress("recTrackinnerMomentumofTSOS", &recTrackinnerMomentumofTSOS);
        T1->SetBranchAddress("recTrackinnerPhiofTSOS", &recTrackinnerPhiofTSOS);
        T1->SetBranchAddress("recTrackinnerEtaofTSOS", &recTrackinnerEtaofTSOS);
        T1->SetBranchAddress("recTrackinnerValidofTSOS", &recTrackinnerValidofTSOS);
        T1->SetBranchAddress("recTrackouterMomentumofTSOS", &recTrackouterMomentumofTSOS);
        T1->SetBranchAddress("recTrackouterPhiofTSOS", &recTrackouterPhiofTSOS);
        T1->SetBranchAddress("recTrackouterEtaofTSOS", &recTrackouterEtaofTSOS);
        T1->SetBranchAddress("recTrackouterValidofTSOS", &recTrackouterValidofTSOS);
        T1->SetBranchAddress("recTrackimpactMomentumofTSOS", &recTrackimpactMomentumofTSOS);
        T1->SetBranchAddress("recTrackimpactPhiofTSOS", &recTrackimpactPhiofTSOS);
        T1->SetBranchAddress("recTrackimpactEtaofTSOS", &recTrackimpactEtaofTSOS);
        T1->SetBranchAddress("recTrackimpactValidofTSOS", &recTrackimpactValidofTSOS);
        T1->SetBranchAddress("recTrackCharge", &recTrackCharge);
        T1->SetBranchAddress("simTrackMomentumPt", &simTrackMomentumPt);
        T1->SetBranchAddress("simTrackPhi", &simTrackPhi);
        T1->SetBranchAddress("simTrackEta", &simTrackEta);
        T1->SetBranchAddress("simTrackCharge", &simTrackCharge);

        string TempHistName;
        TempHistName = theFileName + "_Efficiency2simPt";
        TH1D* Efficiency2simPtHist = new TH1D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale);
        TempHistName = theFileName + "_Particle2simPt";
        TH1D* Particle2simPtHist = new TH1D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale);
        TempHistName = theFileName + "_STA2simPt";
        TH1D* STA2simPtHist = new TH1D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale);
        TempHistName = theFileName + "_InverseChargeRato2simPt";
        TH1D* InverseChargeRato2simPtHist = new TH1D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale);
        TempHistName = theFileName + "_DeltaPt2simPt";
        TH1D* DeltaPt2simPtHist = new TH1D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale);
        TempHistName = theFileName + "_DeltaPhi2simPt";
        TH1D* DeltaPhi2simPtHist = new TH1D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale);
        TempHistName = theFileName + "_DeltaEta2simPt";
        TH1D* DeltaEta2simPtHist = new TH1D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale);
        TempHistName = theFileName + "_MaxPurity2simPt";
        TH2D* MaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 6, 0., 1.2);
        TempHistName = theFileName + "_Multiplicity2simPt";
        TH2D* Multiplicity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 10, 0., 10.);
        TempHistName = theFileName + "_ChargeCheck2simPt";
        TH2D* ChargeCheck2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 5, -2.5, 2.5);
        TempHistName = theFileName + "_simTrackMomentumPtmaxPurity2simPt";
        TH2D* simTrackMomentumPtmaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, (int)5*PtScale, 0, PtScale);
        TempHistName = theFileName + "_simTrackPhimaxPurity2simPt";
        TH2D* simTrackPhimaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 314, -PI, PI);
        TempHistName = theFileName + "_simTrackEtamaxPurity2simPt";
        TH2D* simTrackEtamaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 400, -2.0, 2.0);
        TempHistName = theFileName + "_recTrackimpactMomentumofTSOSmaxPurity2simPt";
        TH2D* recTrackimpactMomentumofTSOSmaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, (int)5*PtScale, 0, PtScale);
        TempHistName = theFileName + "_recTrackimpactPhiofTSOSmaxPurity2simPt";
        TH2D* recTrackimpactPhiofTSOSmaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 314, -PI, PI);
        TempHistName = theFileName + "_recTrackimpactEtaofTSOSmaxPurity2simPt";
        TH2D* recTrackimpactEtaofTSOSmaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 600, -3.0, 3.0);
        TempHistName = theFileName + "_recTrackimpactValidofTSOSmaxPurity2simPt";
        TH2D* recTrackimpactValidofTSOSmaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(), (int)(PtScale/2), 0, PtScale, 2, 0., 2.);
        TempHistName = theFileName + "_DeltaPtmaxPurity2simPt";
        TH2D* DeltaPtmaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(),  (int)(PtScale/2), 0, PtScale, (int)5*PtScale, -1.*PtScale, PtScale);
        TempHistName = theFileName + "_DeltaPhimaxPurity2simPt";
        TH2D* DeltaPhimaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(),  (int)(PtScale/2), 0, PtScale, 314, -PI, PI);
        TempHistName = theFileName + "_DeltaEtamaxPurity2simPt";
        TH2D* DeltaEtamaxPurity2simPtHist = new TH2D(TempHistName.c_str(), TempHistName.c_str(),  (int)(PtScale/2), 0, PtScale, 400, -2.0, 2.0);

        unsigned int trackingParticleMatch_temp;
        unsigned int efficiency_temp;
        double recTrackPurity_temp;
        double recTrackrefMomentum_temp;
        double recTrackrefPhi_temp;
        double recTrackrefEta_temp;
        double recTrackinnerMomentum_temp;
        double recTrackinnerPhi_temp;
        double recTrackinnerEta_temp;
        unsigned int recTrackinnerValid_temp;
        double recTrackouterMomentum_temp;
        double recTrackouterPhi_temp;
        double recTrackouterEta_temp;
        unsigned int recTrackouterValid_temp;
        double simTrackinnerMomentum_temp;
        double simTrackinnerPhi_temp;
        double simTrackinnerEta_temp;
        unsigned int simTrackinnerMatch_temp;
        double simTrackouterMomentum_temp;
        double simTrackouterPhi_temp;
        double simTrackouterEta_temp;
        unsigned int simTrackouterMatch_temp;
        double recTrackinnerMomentumofTSOS_temp;
        double recTrackinnerPhiofTSOS_temp;
        double recTrackinnerEtaofTSOS_temp;
        unsigned int recTrackinnerValidofTSOS_temp;
        double recTrackouterMomentumofTSOS_temp;
        double recTrackouterPhiofTSOS_temp;
        double recTrackouterEtaofTSOS_temp;
        unsigned int recTrackouterValidofTSOS_temp;
        double recTrackimpactMomentumofTSOS_temp;
        double recTrackimpactPhiofTSOS_temp;
        double recTrackimpactEtaofTSOS_temp;
        unsigned int recTrackimpactValidofTSOS_temp;
        int recTrackCharge_temp;
        double simTrackMomentumPt_temp;
        double simTrackPhi_temp;
        double simTrackEta_temp;
        int simTrackCharge_temp;

        int Nentries = T1->GetEntries(); 
        for(int i = 0; i < Nentries; i++) { 
            T1->GetEntry(i);
            if(trackingParticleMatch == 0) {
                MaxPurity2simPtHist->Fill(simTrackMomentumPt, 0);
                Multiplicity2simPtHist->Fill(simTrackMomentumPt, 0);
                int tempParticleBinNumber = Particle2simPtHist->FindBin(simTrackMomentumPt);
                double tempParticleBinValue = Particle2simPtHist->GetBinContent(tempParticleBinNumber);
                tempParticleBinValue += 1.;
                Particle2simPtHist->SetBinContent(tempParticleBinNumber, tempParticleBinValue);
            }
            else {
                efficiency_temp = 1;
                trackingParticleMatch_temp = trackingParticleMatch;
                recTrackPurity_temp = recTrackPurity;
                recTrackrefMomentum_temp = recTrackrefMomentum;
                recTrackrefPhi_temp = recTrackrefPhi;
                recTrackrefEta_temp = recTrackrefEta;
                recTrackinnerMomentum_temp = recTrackinnerMomentum;
                recTrackinnerPhi_temp = recTrackinnerPhi;
                recTrackinnerEta_temp = recTrackinnerEta;
                recTrackinnerValid_temp = recTrackinnerValid;
                recTrackouterMomentum_temp = recTrackouterMomentum;
                recTrackouterPhi_temp = recTrackouterPhi;
                recTrackouterEta_temp = recTrackouterEta;
                recTrackouterValid_temp = recTrackouterValid;
                simTrackinnerMomentum_temp = simTrackinnerMomentum;
                simTrackinnerPhi_temp = simTrackinnerPhi;
                simTrackinnerEta_temp = simTrackinnerEta;
                simTrackinnerMatch_temp = simTrackinnerMatch;
                simTrackouterMomentum_temp = simTrackouterMomentum;
                simTrackouterPhi_temp = simTrackouterPhi;
                simTrackouterEta_temp = simTrackouterEta;
                simTrackouterMatch_temp = simTrackouterMatch;
                recTrackinnerMomentumofTSOS_temp = recTrackinnerMomentumofTSOS;
                recTrackinnerPhiofTSOS_temp = recTrackinnerPhiofTSOS;
                recTrackinnerEtaofTSOS_temp = recTrackinnerEtaofTSOS;
                recTrackinnerValidofTSOS_temp = recTrackinnerValidofTSOS;
                recTrackouterMomentumofTSOS_temp = recTrackouterMomentumofTSOS;
                recTrackouterPhiofTSOS_temp = recTrackouterPhiofTSOS;
                recTrackouterEtaofTSOS_temp = recTrackouterEtaofTSOS;
                recTrackouterValidofTSOS_temp = recTrackouterValidofTSOS;
                recTrackimpactMomentumofTSOS_temp = recTrackimpactMomentumofTSOS;
                recTrackimpactPhiofTSOS_temp = recTrackimpactPhiofTSOS;
                recTrackimpactEtaofTSOS_temp = recTrackimpactEtaofTSOS;
                recTrackimpactValidofTSOS_temp = recTrackimpactValidofTSOS;
                recTrackCharge_temp = recTrackCharge;
                simTrackMomentumPt_temp = simTrackMomentumPt;
                simTrackPhi_temp = simTrackPhi;
                simTrackEta_temp = simTrackEta;
                simTrackCharge_temp = simTrackCharge;

                bool nextStep = true;
                while(nextStep) {
                    i++;
                    T1->GetEntry(i);
                    if(trackingParticleMatch <= trackingParticleMatch_temp)
                        nextStep = false;
                    else
                        trackingParticleMatch_temp = trackingParticleMatch;
                    if(nextStep == true && recTrackPurity_temp < recTrackPurity) {
                        if(debug) cout << "step another match, trackingParticleMatch_temp: " << trackingParticleMatch_temp << endl;
                        //trackingParticleMatch_temp = trackingParticleMatch;
                        recTrackPurity_temp = recTrackPurity;
                        recTrackrefMomentum_temp = recTrackrefMomentum;
                        recTrackrefPhi_temp = recTrackrefPhi;
                        recTrackrefEta_temp = recTrackrefEta;
                        recTrackinnerMomentum_temp = recTrackinnerMomentum;
                        recTrackinnerPhi_temp = recTrackinnerPhi;
                        recTrackinnerEta_temp = recTrackinnerEta;
                        recTrackinnerValid_temp = recTrackinnerValid;
                        recTrackouterMomentum_temp = recTrackouterMomentum;
                        recTrackouterPhi_temp = recTrackouterPhi;
                        recTrackouterEta_temp = recTrackouterEta;
                        recTrackouterValid_temp = recTrackouterValid;
                        simTrackinnerMomentum_temp = simTrackinnerMomentum;
                        simTrackinnerPhi_temp = simTrackinnerPhi;
                        simTrackinnerEta_temp = simTrackinnerEta;
                        simTrackinnerMatch_temp = simTrackinnerMatch;
                        simTrackouterMomentum_temp = simTrackouterMomentum;
                        simTrackouterPhi_temp = simTrackouterPhi;
                        simTrackouterEta_temp = simTrackouterEta;
                        simTrackouterMatch_temp = simTrackouterMatch;
                        recTrackinnerMomentumofTSOS_temp = recTrackinnerMomentumofTSOS;
                        recTrackinnerPhiofTSOS_temp = recTrackinnerPhiofTSOS;
                        recTrackinnerEtaofTSOS_temp = recTrackinnerEtaofTSOS;
                        recTrackinnerValidofTSOS_temp = recTrackinnerValidofTSOS;
                        recTrackouterMomentumofTSOS_temp = recTrackouterMomentumofTSOS;
                        recTrackouterPhiofTSOS_temp = recTrackouterPhiofTSOS;
                        recTrackouterEtaofTSOS_temp = recTrackouterEtaofTSOS;
                        recTrackouterValidofTSOS_temp = recTrackouterValidofTSOS;
                        recTrackimpactMomentumofTSOS_temp = recTrackimpactMomentumofTSOS;
                        recTrackimpactPhiofTSOS_temp = recTrackimpactPhiofTSOS;
                        recTrackimpactEtaofTSOS_temp = recTrackimpactEtaofTSOS;
                        recTrackimpactValidofTSOS_temp = recTrackimpactValidofTSOS;
                        recTrackCharge_temp = recTrackCharge;
                        simTrackMomentumPt_temp = simTrackMomentumPt;
                        simTrackPhi_temp = simTrackPhi;
                        simTrackEta_temp = simTrackEta;
                        simTrackCharge_temp = simTrackCharge;
                    }
                }
                i--;
                //if(debug) cout << "Filling Multiplicity " << trackingParticleMatch_temp << endl;
                MaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, recTrackPurity_temp);
                Multiplicity2simPtHist->Fill(simTrackMomentumPt_temp, trackingParticleMatch_temp);
                ChargeCheck2simPtHist->Fill(simTrackMomentumPt_temp, simTrackCharge_temp*recTrackCharge_temp);
                simTrackMomentumPtmaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, simTrackMomentumPt_temp);
                simTrackPhimaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, simTrackPhi_temp);
                simTrackEtamaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, simTrackEta_temp);
                recTrackimpactMomentumofTSOSmaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, recTrackimpactMomentumofTSOS_temp);
                recTrackimpactPhiofTSOSmaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, recTrackimpactPhiofTSOS_temp);
                recTrackimpactEtaofTSOSmaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, recTrackimpactEtaofTSOS_temp);
                recTrackimpactValidofTSOSmaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, recTrackimpactValidofTSOS_temp);
                DeltaPtmaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, (recTrackimpactMomentumofTSOS_temp-simTrackMomentumPt_temp)/simTrackMomentumPt_temp);
                DeltaPhimaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, recTrackimpactPhiofTSOS_temp-simTrackPhi_temp);
                DeltaEtamaxPurity2simPtHist->Fill(simTrackMomentumPt_temp, recTrackimpactEtaofTSOS_temp-simTrackEta_temp);


                int tempParticleBinNumber = STA2simPtHist->FindBin(simTrackMomentumPt_temp);
                double tempParticleBinValue = Particle2simPtHist->GetBinContent(tempParticleBinNumber);
                tempParticleBinValue += 1.;
                Particle2simPtHist->SetBinContent(tempParticleBinNumber, tempParticleBinValue);
                double tempSTABinValue = STA2simPtHist->GetBinContent(tempParticleBinNumber);
                tempSTABinValue += 1.;                        
                STA2simPtHist->SetBinContent(tempParticleBinNumber, tempSTABinValue);
            }
        }

        
        for(int PtIndex = 1; PtIndex <= (int)(PtScale/2); PtIndex++) {
            double ParticleBinValue = Particle2simPtHist->GetBinContent(PtIndex);
            double STABinValue = STA2simPtHist->GetBinContent(PtIndex);
            if(ParticleBinValue == 0.)
                ParticleBinValue += 1.;
            double EfficiencyBinValue = STABinValue / ParticleBinValue * 100.;
            double EfficiencyBinError = sqrt(EfficiencyBinValue * (100. - EfficiencyBinValue) / ParticleBinValue);
            cout << ParticleBinValue << ", " << STABinValue << ", " << EfficiencyBinValue << endl;
            Efficiency2simPtHist->SetBinContent(PtIndex, EfficiencyBinValue);
            Efficiency2simPtHist->SetBinError(PtIndex, EfficiencyBinError);

            TH1D* ChargeCheckHist = ChargeCheck2simPtHist->ProjectionY("ChargeCheck", PtIndex, PtIndex, "o");
            double ReverseChargeBinValue = ChargeCheckHist->GetBinContent(2);
            double CoverseChargeBinValue = ChargeCheckHist->GetBinContent(4);
            double TotalChargeBinValue = ReverseChargeBinValue + CoverseChargeBinValue;
            if(TotalChargeBinValue == 0.);
                TotalChargeBinValue += 1.;
            double ReverseChargeRato = ReverseChargeBinValue / TotalChargeBinValue;
            InverseChargeRato2simPtHist->SetBinContent(PtIndex, ReverseChargeRato);

            TH1D* DeltaPtHist = DeltaPtmaxPurity2simPtHist->ProjectionY("DeltaPt", PtIndex, PtIndex, "o");
            double DeltaPtMean = DeltaPtHist->GetMean();
            double DeltaPtRMS = DeltaPtHist->GetRMS();
            DeltaPt2simPtHist->SetBinContent(PtIndex, DeltaPtMean);
            DeltaPt2simPtHist->SetBinError(PtIndex, DeltaPtRMS);

            TH1D* DeltaPhiHist = DeltaPhimaxPurity2simPtHist->ProjectionY("DeltaPhi", PtIndex, PtIndex, "o");
            double DeltaPhiMean = DeltaPhiHist->GetMean();
            double DeltaPhiRMS = DeltaPhiHist->GetRMS();
            DeltaPhi2simPtHist->SetBinContent(PtIndex, DeltaPhiMean);
            DeltaPhi2simPtHist->SetBinError(PtIndex, DeltaPhiRMS);

            TH1D* DeltaEtaHist = DeltaEtamaxPurity2simPtHist->ProjectionY("DeltaEta", PtIndex, PtIndex, "o");
            double DeltaEtaMean = DeltaEtaHist->GetMean();
            double DeltaEtaRMS = DeltaEtaHist->GetRMS();
            DeltaEta2simPtHist->SetBinContent(PtIndex, DeltaEtaMean);
            DeltaEta2simPtHist->SetBinError(PtIndex, DeltaEtaRMS);
        }
        myEfficiencyHist->AddLast(Efficiency2simPtHist);
        myParticleHist->AddLast(Particle2simPtHist);
        mySTAHist->AddLast(STA2simPtHist);
        myChargeCheckHist->AddLast(InverseChargeRato2simPtHist);
        myDeltaPtHist->AddLast(DeltaPt2simPtHist);
    }
    double minX = 0;
    double minY = 0;
    double maxX = 110;
    double maxY = 40;

    TCanvas* myCanvas = new TCanvas("Canvas", "Canvas", 800, 600);
    myCanvas->cd();
    TPad* myPad = new TPad("Pad", "Pad", 0, 0, 1, 1);
    myPad->Draw();
    myPad->cd();

    ((TH1D*)(myParticleHist->At(0)))->SetStats(0);
    ((TH1D*)(myParticleHist->At(0)))->GetXaxis()->SetTitle("simPt/Gev");
    ((TH1D*)(myParticleHist->At(0)))->GetXaxis()->CenterTitle(1);
    ((TH1D*)(myParticleHist->At(0)))->Draw();
    for(int Index = 0; Index < FileNumber; Index++) {
	((TH1D*)(mySTAHist->At(Index)))->SetStats(0);
        ((TH1D*)(mySTAHist->At(Index)))->SetLineColor(kRed+Index);
        ((TH1D*)(mySTAHist->At(Index)))->Draw("same");
    }
    TLegend *STALeg = new TLegend(0.6,0.1,0.9,0.3);
    STALeg->SetBorderSize(1);
    TString LegKey = "ParticleTrack";
    STALeg->AddEntry(myParticleHist->At(0), LegKey, "lpf");
    for(int Index = 0; Index < FileNumber; Index++) {
        LegKey = TypeName[Index];
        STALeg->AddEntry(mySTAHist->At(Index), LegKey, "lpf");
    }
    STALeg->Draw();
    string SaveName = OutputPlotNamepreFix + "_STA2simPt" + OutputPlotNameFix;
    myCanvas->SaveAs(SaveName.c_str());

    myPad->Clear();
    myPad->Update();
    double YScale = myPad->GetUymax() / 110.;
    ((TH1D*)(myEfficiencyHist->At(0)))->GetXaxis()->SetTitle("simPt/Gev");
    ((TH1D*)(myEfficiencyHist->At(0)))->GetXaxis()->CenterTitle(1);
    ((TH1D*)(myEfficiencyHist->At(0)))->SetStats(0);
    ((TH1D*)(myEfficiencyHist->At(0)))->Scale(YScale);
    ((TH1D*)(myEfficiencyHist->At(0)))->SetLineColor(kRed);
    ((TH1D*)(myEfficiencyHist->At(0)))->Draw("same,ah");
    for(int Index = 1; Index < FileNumber; Index++) {
	((TH1D*)(myEfficiencyHist->At(Index)))->SetStats(0);
        ((TH1D*)(myEfficiencyHist->At(Index)))->Scale(YScale);
        ((TH1D*)(myEfficiencyHist->At(Index)))->SetLineColor(kRed+Index);
        ((TH1D*)(myEfficiencyHist->At(Index)))->Draw("same,ah");
    }
    myPad->Update();
    if(debug) cout << "Y: " << myPad->GetUymax() << endl;
    double YAxisMinValue=((TH1D*)(myEfficiencyHist->At(0)))->GetYaxis()->GetXmin();
    double YAxisMaxValue=((TH1D*)(myEfficiencyHist->At(0)))->GetYaxis()->GetXmax();
    int YAxisNBins=((TH1D*)(myEfficiencyHist->At(0)))->GetYaxis()->GetNbins();
    TGaxis* YAxis = new TGaxis(myPad->GetUxmin(), myPad->GetUymin(), myPad->GetUxmin(), myPad->GetUymax(), 0, 110, 510, "-R");
    YAxis->SetLineColor(kGreen);
    YAxis->SetLabelColor(kGreen);
    YAxis->SetTitle("Efficiency of STA for simPts");
    YAxis->CenterTitle(1);
    YAxis->Draw();
    double XAxisMinValue=((TH1D*)(myEfficiencyHist->At(0)))->GetXaxis()->GetXmin();
    double XAxisMaxValue=((TH1D*)(myEfficiencyHist->At(0)))->GetXaxis()->GetXmax();
    int XAxisNBins=((TH1D*)(myEfficiencyHist->At(0)))->GetXaxis()->GetNbins();
    TGaxis* XAxis = new TGaxis(myPad->GetUxmin(), myPad->GetUymin(), myPad->GetUxmax(), myPad->GetUymin(), XAxisMinValue, XAxisMaxValue, 510, "+L");
    XAxis->SetTitle("simPt/Gev");
    XAxis->CenterTitle(1);
    XAxis->Draw();
    TLegend *EffLeg = new TLegend(0.1,0.9,0.4,1.0);
    EffLeg->SetBorderSize(1);
    for(int Index = 0; Index < FileNumber; Index++) {
        TString LegKey = TypeName[Index];
        EffLeg->AddEntry(myEfficiencyHist->At(Index), LegKey, "lpf");
    }
    EffLeg->Draw();
    string SaveName = OutputPlotNamepreFix + "_Eff2simPt" + OutputPlotNameFix;
    myCanvas->SaveAs(SaveName.c_str());

    ((TH1D*)(myDeltaPtHist->At(0)))->SetStats(0);
    ((TH1D*)(myDeltaPtHist->At(0)))->GetXaxis()->SetTitle("simPt/Gev");
    ((TH1D*)(myDeltaPtHist->At(0)))->GetXaxis()->CenterTitle(1);
    ((TH1D*)(myDeltaPtHist->At(0)))->GetYaxis()->SetTitle("deltPt/simPt");
    ((TH1D*)(myDeltaPtHist->At(0)))->GetYaxis()->CenterTitle(1);
    ((TH1D*)(myDeltaPtHist->At(0)))->SetLineColor(kRed);
    ((TH1D*)(myDeltaPtHist->At(0)))->Draw("");
    for(int Index = 1; Index < FileNumber; Index++) {
	    ((TH1D*)(myDeltaPtHist->At(Index)))->SetStats(0);
	    //((TH1D*)(myDeltaPtHist->At(Index)))->GetXaxis()->SetTitle("simPt/Gev");
	    //((TH1D*)(myDeltaPtHist->At(Index)))->GetXaxis()->CenterTitle(1);
	    //((TH1D*)(myDeltaPtHist->At(Index)))->GetYaxis()->SetTitle("deltPt/simPt");
	    //((TH1D*)(myDeltaPtHist->At(Index)))->GetYaxis()->CenterTitle(1);
        ((TH1D*)(myDeltaPtHist->At(Index)))->SetLineColor(kRed+Index);
        ((TH1D*)(myDeltaPtHist->At(Index)))->Draw("same");
        //SaveName = OutputPlotNamepreFix + TypeName[Index] + "DeltaPt" + OutputPlotNameFix;
        //myCanvas->SaveAs(SaveName.c_str());
    }
    TLegend *PtLeg = new TLegend(0.6,0.8,0.9,0.9);
    PtLeg->SetBorderSize(1);
    for(int Index = 0; Index < FileNumber; Index++) {
        TString LegKey = TypeName[Index];
        PtLeg->AddEntry(myDeltaPtHist->At(Index), LegKey, "lpf");
    }
    PtLeg->Draw();
    SaveName = OutputPlotNamepreFix + "_DeltaPt" + OutputPlotNameFix;
    myCanvas->SaveAs(SaveName.c_str());
}
Example #11
0
void PlotPotential2D( const TString &sim, Int_t time, Int_t zoom=2, Int_t Nbins=2, const TString &options="") {

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

    PlasmaGlob::Initialize();

    // Palettes!
    gROOT->Macro("PlasmaPalettes.C");

    // Init Units table
    PUnits::UnitsTable::Get();

    // Load PData
    PData *pData = PData::Get(sim.Data());
    pData->LoadFileNames(time);
    if(!pData->IsInit()) return;

    TString opt = options;

    // More makeup
    gStyle->SetPadGridY(0);
    if(opt.Contains("gridx")) {
        gStyle->SetPadGridX(1);
    }
    if(opt.Contains("gridy")) {
        gStyle->SetPadGridY(1);
    }


    // Some plasma constants
    Double_t n0 = pData->GetPlasmaDensity();
    Double_t omegap = pData->GetPlasmaFrequency();
    Double_t timedepth = 1.;
    if(omegap!=0.0) timedepth = 1/omegap;
    Double_t kp = pData->GetPlasmaK();
    Double_t skindepth = 1.;
    if(kp!=0.0) skindepth = 1/kp;
    Double_t E0 = pData->GetPlasmaE0();

    // Some beam properties:
    Double_t Ebeam = pData->GetBeamEnergy();
    Double_t gamma = pData->GetBeamGamma();
    Double_t vbeam = pData->GetBeamVelocity();

    cout << Form(" - Bunch gamma      = %8.4f", gamma ) << endl;
    cout << Form(" - Bunch velocity   = %8.4f c", vbeam ) << endl;

    // Other parameters
    Float_t trapPotential = 1.0 - (1.0/gamma);
    cout << Form(" - Trap. potential  = %8.4f mc2/e",trapPotential) << endl;
    cout << endl;

    // 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;
    // z start of the neutral in normalized units.
    Float_t zStartNeutral = pData->GetNeutralStart()*kp;
    // z end of the neutral in normalized units.
    Float_t zEndNeutral = pData->GetNeutralEnd()*kp;

    if(opt.Contains("center")) {
        Time -= zStartPlasma;
        if(opt.Contains("comov"))      // Centers on the head of the beam.
            Time += zStartBeam;
    }
    Float_t shiftz = pData->Shift(opt);
    //  cout << "Shift = " << shiftz << endl;


    // Calculate the "axis range" in number of bins. If Nbins==0 a RMS width is taken.
    Double_t rms0 = pData->GetBeamRmsY() * kp;
    if(pData->IsCyl())  rms0  = pData->GetBeamRmsR() * kp;

    Int_t FirstyBin = 0;
    Int_t LastyBin = 0;
    if(Nbins==0) {
        if(rms0>0.0)
            Nbins =  TMath::Nint(rms0 / pData->GetDX(1));
        else
            Nbins = 1;
    }

    // Slice width limits.
    if(!pData->IsCyl()) {
        FirstyBin = pData->GetNX(1)/2 + 1 - Nbins;
        LastyBin =  pData->GetNX(1)/2 + Nbins;
    } else {
        FirstyBin = 1;
        LastyBin  = Nbins;
    }
    // ----------------------------------------------------------------------------------


    // Get charge density histos
    Int_t Nspecies = pData->NSpecies();
    TH2F **hDen2D = new TH2F*[Nspecies];
    // Get charge density on-axis
    TH1F **hDen1D = new TH1F*[Nspecies];
    // And electric current (integrated)
    TH1F **hCur1D = new TH1F*[Nspecies];
    for(Int_t i=0; i<Nspecies; i++) {

        hDen2D[i] = NULL;

        if(!pData->GetChargeFileName(i))
            continue;

        cout << Form(" Getting charge density of specie: ") << i << endl;


        char hName[24];
        sprintf(hName,"hDen2D_%i",i);
        hDen2D[i] = (TH2F*) gROOT->FindObject(hName);
        if(hDen2D[i]) delete hDen2D[i];

        if(!pData->Is3D())
            hDen2D[i] = pData->GetCharge(i,opt);
        else
            hDen2D[i] = pData->GetCharge2DSliceZY(i,-1,Nbins,opt+"avg");

        hDen2D[i]->SetName(hName);
        hDen2D[i]->GetXaxis()->CenterTitle();
        hDen2D[i]->GetYaxis()->CenterTitle();
        hDen2D[i]->GetZaxis()->CenterTitle();

        if(opt.Contains("comov"))
            hDen2D[i]->GetXaxis()->SetTitle("k_{p} #zeta");
        else
            hDen2D[i]->GetXaxis()->SetTitle("k_{p} z");

        if(pData->IsCyl())
            hDen2D[i]->GetYaxis()->SetTitle("k_{p} r");
        else
            hDen2D[i]->GetYaxis()->SetTitle("k_{p} y");

        hDen2D[i]->GetZaxis()->SetTitle("n [n_{0}]");


        hDen1D[i] = NULL;
        hCur1D[i] = NULL;

        if(!pData->GetEfieldFileName(i))
            continue;

        sprintf(hName,"hDen1D_%i",i);
        hDen1D[i] = (TH1F*) gROOT->FindObject(hName);
        if(hDen1D[i]) delete hDen1D[i];

        // 1D histograms
        if(pData->Is3D()) {
            hDen1D[i] = pData->GetH1SliceZ3D(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,-1,Nbins,opt+"avg");
        } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).
            hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",1,Nbins,opt+"avg");
        } else { // 2D cartesian
            hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,opt+"avg");
        }
        hDen1D[i]->SetName(hName);

        // if(hDen1D[i]) delete hDen1D[i];
        // hDen1D[i] = (TH1F*) hE2D[i]->ProjectionX(hName,FirstyBin,LastyBin);
        // hDen1D[i]->Scale(1.0/(LastyBin-FirstyBin+1));

        if(opt.Contains("comov"))
            hDen1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
        else
            hDen1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");

        if(i==0)
            hDen1D[i]->GetYaxis()->SetTitle("n/n_{0}");
        else if(i==1)
            hDen1D[i]->GetYaxis()->SetTitle("n_{b}/n_{0}");
        else
            hDen1D[i]->GetYaxis()->SetTitle("n_{i}/n_{0}");

        // Get the current:
        if(i==0) continue;

        sprintf(hName,"hCur1D_%i",i);
        hCur1D[i] = (TH1F*) gROOT->FindObject(hName);
        if(hCur1D[i]) delete hCur1D[i];

        if(opt.Contains("curr")) {
            // To get the current is needed to read in a wider transverse range which includes all the charge.
            Int_t NbinsT = 100;
            if(pData->Is3D()) {
                hCur1D[i] = pData->GetH1SliceZ3D(pData->GetChargeFileName(i)->c_str(),"charge",-1,NbinsT,-1,NbinsT,opt+"int");
            } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).
                hCur1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",1,NbinsT,opt+"int");
            } else { // 2D cartesian
                hCur1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",-1,NbinsT,opt+"int");
            }
            hCur1D[i]->SetName(hName);

            if(opt.Contains("comov")) {
                hCur1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
                hCur1D[i]->GetYaxis()->SetTitle("dn/d#zeta [(n_{0}/k_{p}^{3}) (#omega_{p}/c)]");
            } else {
                hCur1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
                hCur1D[i]->GetYaxis()->SetTitle("dn/dz [(n_{0}/k_{p}^{3}) (#omega_{p}/c)]");
            }

            Int_t NB = hCur1D[i]->GetNbinsX();
            Float_t dx = (hCur1D[i]->GetBinLowEdge(1)-hCur1D[i]->GetBinLowEdge(NB+1))/NB;

            // hCur1D[i]->Scale(dx);
            Float_t Charge = hCur1D[i]->Integral() * dx;

            cout << Form(" Integrated charge of specie %3i = %8.4f n0 * kp^-3",i,Charge) << endl;
        }
    }


    // Get electric fields 2D
    const Int_t Nfields = 3;
    TH2F **hE2D = new TH2F*[Nfields];
    TH1F **hE1D = new TH1F*[Nfields];
    TH2F *hV2D = NULL;
    TH1F *hV1D = NULL;
    for(Int_t i=0; i<Nfields; i++) {
        hE2D[i] = NULL;
        hE1D[i] = NULL;

        if(!pData->GetEfieldFileName(i))
            continue;

        cout << Form(" Getting electric field number ") << i+1 << endl;

        char hName[24];
        sprintf(hName,"hE2D_%i",i);
        hE2D[i] = (TH2F*) gROOT->FindObject(hName);
        if(hE2D[i]) delete hE2D[i];

        if(!pData->Is3D())
            hE2D[i] = pData->GetEField(i,opt);
        else
            hE2D[i] = pData->GetEField2DSliceZY(i,-1,Nbins,opt+"avg");

        hE2D[i]->SetName(hName);
        hE2D[i]->GetXaxis()->CenterTitle();
        hE2D[i]->GetYaxis()->CenterTitle();
        hE2D[i]->GetZaxis()->CenterTitle();
        if(opt.Contains("comov"))
            hE2D[i]->GetXaxis()->SetTitle("k_{p} #zeta");
        else
            hE2D[i]->GetXaxis()->SetTitle("k_{p} z");

        if(pData->IsCyl())
            hE2D[i]->GetYaxis()->SetTitle("k_{p} r");
        else
            hE2D[i]->GetYaxis()->SetTitle("k_{p} y");

        if(i==0)
            hE2D[i]->GetZaxis()->SetTitle("E_{z}/E_{0}");
        else if(i==1)
            hE2D[i]->GetZaxis()->SetTitle("E_{y}/E_{0}");
        else if(i==2)
            hE2D[i]->GetZaxis()->SetTitle("E_{x}/E_{0}");

        sprintf(hName,"hE1D_%i",i);
        hE1D[i] = (TH1F*) gROOT->FindObject(hName);
        if(hE1D[i]) delete hE1D[i];

        // 1D histograms
        char nam[3];
        sprintf(nam,"e%i",i+1);
        if(pData->Is3D()) {

            if(i==0)
                hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins,opt+"avg");
            else
                hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins,opt+"avg");

        } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).

            hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opt+"avg");

        } else { // 2D cartesian

            if(i==0)
                hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opt+"avg");
            else
                hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opt+"avg");
        }

        hE1D[i]->SetName(hName);
        if(opt.Contains("comov"))
            hE1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
        else
            hE1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");

        if(i==0)
            hE1D[i]->GetYaxis()->SetTitle("E_{z} [E_{0}]");
        else if(i==1)
            hE1D[i]->GetYaxis()->SetTitle("E_{y} [E_{0}]");
        else if(i==2)
            hE1D[i]->GetYaxis()->SetTitle("E_{x} [E_{0}]");

        // Alternative
        // if(hE1D[i]) delete hE1D[i];
        // hE1D[i] = (TH1F*) hE2D[i]->ProjectionX(hName,FirstyBin,LastyBin);
        // hE1D[i]->Scale(1.0/(LastyBin-FirstyBin+1));

        if(i==0) {
            Int_t   NbinsX = hE2D[i]->GetNbinsX();
            Int_t   NbinsY = hE2D[i]->GetNbinsY();

            Float_t dx = pData->GetDX(0);

            sprintf(hName,"hV2D");
            hV2D = (TH2F*) hE2D[i]->Clone(hName);
            hV2D->Reset();

            sprintf(hName,"hV1D");
            hV1D = (TH1F*) hE1D[i]->Clone(hName);
            hV1D->Reset();

            for(Int_t j=NbinsY; j>0; j--) {
                Double_t integral = 0.0;
                for(Int_t k=NbinsX; k>0; k--) {
                    integral += hE2D[i]->GetBinContent(k,j) * dx;
                    hV2D->SetBinContent(k,j,integral);
                }
            }

            Double_t integral = 0.0;
            for(Int_t k=NbinsX; k>0; k--) {
                integral += hE1D[i]->GetBinContent(k) * dx;
                hV1D->SetBinContent(k,integral);
            }

        }

    }

    // Now, combine the electric field components into the total |E|
    // and calculate ionization probability for He:
    // Outter Helium electron
    Double_t Eion0 = 24.59 * PUnits::eV;
    Double_t Z     = 1;

    TH2F *hETotal2D = (TH2F*) hE2D[0]->Clone("hETotal2D");
    hETotal2D->Reset();
    TH2F *hIonProb2D = (TH2F*) hE2D[0]->Clone("hIonProb2D");
    hIonProb2D->Reset();
    TH1F *hETotal1D = (TH1F*) hE1D[0]->Clone("hETotal1D");
    hETotal1D->Reset();
    TH1F *hIonProb1D = (TH1F*) hE1D[0]->Clone("hIonProb1D");
    hIonProb1D->Reset();
    {
        Int_t NbinsX = hE2D[0]->GetNbinsX();
        Int_t NbinsY = hE2D[0]->GetNbinsY();
        for(Int_t j=0; j<NbinsX; j++) {
            for(Int_t k=0; k<NbinsY; k++) {
                Double_t E1 = hE2D[0]->GetBinContent(j,k);
                Double_t E2 = hE2D[1]->GetBinContent(j,k);
                Double_t E3 = hE2D[2]->GetBinContent(j,k);
                Double_t E  = TMath::Sqrt(E1*E1+E2*E2+E3*E3);

                hETotal2D->SetBinContent(j,k,E);

                E *= E0;

                // Double_t IonProb = (PFunc::ADK(E,Eion0,Z,l,m)/PUnits::atomictime)*PUnits::femtosecond;
                Double_t IonProb = PFunc::ADK_ENG(E,Eion0,Z) * PUnits::femtosecond;
                // if(IonProb>1) IonProb = 1.0;
                // cout << "Ion prob = " << IonProb << endl;
                hIonProb2D->SetBinContent(j,k,IonProb);
            }
            Double_t E1 = hE1D[0]->GetBinContent(j);
            Double_t E2 = hE1D[1]->GetBinContent(j);
            Double_t E3 = hE1D[2]->GetBinContent(j);
            Double_t E  = TMath::Sqrt(E1*E1+E2*E2+E3*E3);

            hETotal1D->SetBinContent(j,E);

            E *= E0;

            // Double_t IonProb = (PFunc::ADK(E,Eion0,Z,l,m)/PUnits::atomictime)*PUnits::femtosecond;
            Double_t IonProb = PFunc::ADK_ENG(E,Eion0,Z) * PUnits::femtosecond;
            // cout << "Ion prob = " << IonProb << endl;

            hIonProb1D->SetBinContent(j,IonProb);


        }
    }
    hETotal2D->GetZaxis()->SetTitle("E [E_{0}]");
    hIonProb2D->GetZaxis()->SetTitle("W_{ADK} [fs^{-1}]");
    hETotal1D->GetYaxis()->SetTitle("E [E_{0}]");
    hIonProb1D->GetYaxis()->SetTitle("W_{ADK} [fs^{-1}]");



    // Tunning the Histograms
    // ---------------------

    // Chaning to user units:
    // --------------------------

    if(opt.Contains("units") && n0) {

        for(Int_t i=0; i<Nspecies; i++) {

            if(!hDen2D[i]) continue;

            Int_t NbinsX = hDen2D[i]->GetNbinsX();
            Float_t xMin = skindepth * hDen2D[i]->GetXaxis()->GetXmin() / PUnits::um;
            Float_t xMax = skindepth * hDen2D[i]->GetXaxis()->GetXmax() / PUnits::um;
            Int_t NbinsY = hDen2D[i]->GetNbinsY();
            Float_t ymin = skindepth * hDen2D[i]->GetYaxis()->GetXmin() / PUnits::um;
            Float_t ymax = skindepth * hDen2D[i]->GetYaxis()->GetXmax() / PUnits::um;
            hDen2D[i]->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
            // for(Int_t j=0;j<hDen2D[i]->GetNbinsX();j++) {
            // 	for(Int_t k=0;k<hDen2D[i]->GetNbinsY();k++) {
            // 	  hDen2D[i]->SetBinContent(j,k, hDen2D[i]->GetBinContent(j,k) * n0 / (1e17/PUnits::cm3) );
            // 	}
            // }

            if(pData->IsCyl())
                hDen2D[i]->GetYaxis()->SetTitle("r [#mum]");
            else
                hDen2D[i]->GetYaxis()->SetTitle("y [#mum]");

            if(opt.Contains("comov"))
                hDen2D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
            else
                hDen2D[i]->GetXaxis()->SetTitle("z [#mum]");

            // if(i==0)
            // 	hDen2D[i]->GetZaxis()->SetTitle("n_{e} [10^{17}/cm^{3}]");
            // else if(i==1)
            // 	hDen2D[i]->GetZaxis()->SetTitle("n_{b} [10^{17}/cm^{3}]");
            // else
            // 	hDen2D[i]->GetZaxis()->SetTitle("n_{i} [10^{17}/cm^{3}]");

            hDen1D[i]->SetBins(NbinsX,xMin,xMax);
            // for(Int_t j=0;j<hDen1D[i]->GetNbinsX();j++) {
            // 	hDen1D[i]->SetBinContent(j, hDen1D[i]->GetBinContent(j) * n0 / (1e17/PUnits::cm3) );
            // }


            if(opt.Contains("comov"))
                hDen1D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
            else
                hDen1D[i]->GetXaxis()->SetTitle("z [#mum]");

            if(hCur1D[i]) {

                hCur1D[i]->SetBins(NbinsX,xMin,xMax);
                Double_t binSize = (xMax - xMin)/NbinsX;  // bin size in um.

                Double_t dV = skindepth * skindepth * skindepth;
                Double_t lightspeed =  PConst::c_light / (PUnits::um/PUnits::femtosecond);

                hCur1D[i]->Scale(TMath::Abs(n0 * dV * (PConst::ElectronCharge/PUnits::picocoulomb) * (kp * PConst::c_light * PUnits::femtosecond)));

                hCur1D[i]->GetYaxis()->SetTitle("I[kA]");
                hCur1D[i]->GetYaxis()->SetTitle("");
                if(opt.Contains("comov"))
                    hCur1D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
                else
                    hCur1D[i]->GetXaxis()->SetTitle("z [#mum]");


                Float_t Charge = hCur1D[i]->Integral() * (binSize / lightspeed);
                cout << Form(" Integrated charge of specie %3i = %8f pC",i,Charge) << endl;
            }
        }


        for(Int_t i=0; i<Nfields; i++) {
            Int_t NbinsX = hE2D[i]->GetNbinsX();
            Float_t xMin = skindepth * hE2D[i]->GetXaxis()->GetXmin() / PUnits::um;
            Float_t xMax = skindepth * hE2D[i]->GetXaxis()->GetXmax() / PUnits::um;
            Int_t NbinsY = hE2D[i]->GetNbinsY();
            Float_t ymin = skindepth * hE2D[i]->GetYaxis()->GetXmin() / PUnits::um;
            Float_t ymax = skindepth * hE2D[i]->GetYaxis()->GetXmax() / PUnits::um;
            hE2D[i]->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
            hE1D[i]->SetBins(NbinsX,xMin,xMax);

            for(Int_t j=0; j<hE2D[i]->GetNbinsX(); j++) {
                for(Int_t k=0; k<hE2D[i]->GetNbinsY(); k++) {
                    hE2D[i]->SetBinContent(j,k, hE2D[i]->GetBinContent(j,k) * ( E0 / (PUnits::GV/PUnits::m) ) );
                }
                hE1D[i]->SetBinContent(j, hE1D[i]->GetBinContent(j) * ( E0 / (PUnits::GV/PUnits::m) ) );
            }

            if(pData->IsCyl())
                hE2D[i]->GetYaxis()->SetTitle("r [#mum]");
            else
                hE2D[i]->GetYaxis()->SetTitle("y [#mum]");

            if(opt.Contains("comov"))
                hE2D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
            else
                hE2D[i]->GetXaxis()->SetTitle("z [#mum]");

            if(i==0)
                hE2D[i]->GetZaxis()->SetTitle("E_{z} [GV/m]");
            else if(i==1)
                hE2D[i]->GetZaxis()->SetTitle("E_{y} [GV/m]");
            else if(i==2)
                hE2D[i]->GetZaxis()->SetTitle("E_{x} [GV/m]");


            if(opt.Contains("comov"))
                hE1D[i]->GetXaxis()->SetTitle("#zeta [mm]");
            else
                hE1D[i]->GetXaxis()->SetTitle("z [mm]");

            if(i==0)
                hE1D[i]->GetYaxis()->SetTitle("E_{z} [GV/m]");
            else if(i==1)
                hE1D[i]->GetYaxis()->SetTitle("E_{y} [GV/m]");
            else if(i==2)
                hE1D[i]->GetYaxis()->SetTitle("E_{x} [GV/m]");


            if(i==0) {
                hV2D->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
                hETotal2D->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
                hIonProb2D->SetBins(NbinsX,xMin,xMax,NbinsY,ymin,ymax);
                hV1D->SetBins(NbinsX,xMin,xMax);
                hETotal1D->SetBins(NbinsX,xMin,xMax);
                hIonProb1D->SetBins(NbinsX,xMin,xMax);
                for(Int_t j=0; j<NbinsX; j++) {
                    for(Int_t k=0; k<NbinsY; k++) {
                        hV2D->SetBinContent(j,k, hV2D->GetBinContent(j,k) * E0 * skindepth / (PUnits::MV));
                        hETotal2D->SetBinContent(j,k, hETotal2D->GetBinContent(j,k) * ( E0 / (PUnits::GV/PUnits::m) ) );
                    }
                    hV1D->SetBinContent(j, hV1D->GetBinContent(j) * ( E0 * skindepth / (PUnits::MV) ) );
                    hETotal1D->SetBinContent(j, hETotal1D->GetBinContent(j) * ( E0 / (PUnits::GV/PUnits::m) ) );
                }

                if(pData->IsCyl()) {
                    hV2D->GetYaxis()->SetTitle("r [#mum]");
                    hETotal2D->GetYaxis()->SetTitle("r [#mum]");
                } else {
                    hV2D->GetYaxis()->SetTitle("y [#mum]");
                    hETotal2D->GetYaxis()->SetTitle("y [#mum]");

                }

                if(opt.Contains("comov")) {
                    hV2D->GetXaxis()->SetTitle("#zeta [#mum]");
                    hV1D->GetXaxis()->SetTitle("#zeta [#mum]");
                    hETotal2D->GetXaxis()->SetTitle("#zeta [#mum]");
                    hETotal1D->GetXaxis()->SetTitle("#zeta [#mum]");
                } else {
                    hV2D->GetXaxis()->SetTitle("z [#mum]");
                    hV2D->GetXaxis()->SetTitle("z [#mum]");
                    hETotal2D->GetXaxis()->SetTitle("z [#mum]");
                    hETotal1D->GetXaxis()->SetTitle("z [#mum]");
                }

                hV2D->GetZaxis()->SetTitle("#Psi-#Psi_{t} [MV]");
                hV1D->GetYaxis()->SetTitle("#Psi-#Psi_{t} [MV]");
                hETotal2D->GetZaxis()->SetTitle("E [GV/m]");
                hETotal1D->GetYaxis()->SetTitle("E [GV/m]");
            }
        }
    }


    // --------------------------------------------------- Vertical Zoom ------------

    Float_t yRange    = (hDen2D[0]->GetYaxis()->GetXmax() - hDen2D[0]->GetYaxis()->GetXmin())/zoom;
    Float_t midPoint = (hDen2D[0]->GetYaxis()->GetXmax() + hDen2D[0]->GetYaxis()->GetXmin())/2.;
    Float_t yMin = midPoint-yRange/2;
    Float_t yMax = midPoint+yRange/2;
    if(pData->IsCyl()) {
        yMin = pData->GetXMin(1);
        yMax = yRange;
    }

    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen2D[i]) continue;
        hDen2D[i]->GetYaxis()->SetRangeUser(yMin,yMax);
    }

    for(Int_t i=0; i<Nfields; i++) {
        if(!hE2D[i]) continue;
        hE2D[i]->GetYaxis()->SetRangeUser(yMin,yMax);
    }

    hETotal2D->GetYaxis()->SetRangeUser(yMin,yMax);

    Float_t xMin = hDen2D[0]->GetXaxis()->GetXmin();
    Float_t xMax = hDen2D[0]->GetXaxis()->GetXmax();
    Float_t xRange = xMax - xMin;

    // ------------- z Zoom --------------------------------- Plasma palette -----------
    // Set the range of the plasma charge density histogram for maximum constrast
    // using a dynamic palette wich adjust the nominal value to a certain color.


    Float_t density = 1;
    Float_t Base  = density;

    Float_t *Max = new Float_t[Nspecies];
    Float_t *Min = new Float_t[Nspecies];

    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen2D[i]) continue;

        Max[i] = hDen2D[i]->GetMaximum();
        Min[i] = 1.01E-1 * Base;
        if(i==1) Min[i] = 1.01E-1 * Base;
        if(i==2) Min[i] = 1.01E-4 * Base;
        hDen2D[i]->GetZaxis()->SetRangeUser(Min[i],Max[i]);
    }

    // Dynamic plasma palette
    const Int_t plasmaDNRGBs = 3;
    const Int_t plasmaDNCont = 64;
    Float_t basePos = 0.5;
    if(Max[0]!=Min[0]) {
        if(opt.Contains("logz")) {
            Float_t a = 1.0/(TMath::Log10(Max[0])-TMath::Log10(Min[0]));
            Float_t b = TMath::Log10(Min[0]);
            basePos = a*(TMath::Log10(Base) - b);

        } else {
            basePos = (1.0/(Max[0]-Min[0]))*(Base - Min[0]);
        }
    }

    Double_t plasmaDStops[plasmaDNRGBs] = { 0.00, basePos, 1.00 };
    Double_t plasmaDRed[plasmaDNRGBs]   = { 0.99, 0.90, 0.00 };
    Double_t plasmaDGreen[plasmaDNRGBs] = { 0.99, 0.90, 0.00 };
    Double_t plasmaDBlue[plasmaDNRGBs]  = { 0.99, 0.90, 0.00 };

    PPalette * plasmaPalette = (PPalette*) gROOT->FindObject("plasma");
    plasmaPalette->CreateGradientColorTable(plasmaDNRGBs, plasmaDStops,
                                            plasmaDRed, plasmaDGreen, plasmaDBlue, plasmaDNCont);
    // Change the range of z axis for the fields to be symmetric.
    Float_t *Emax = new Float_t[Nfields];
    Float_t *Emin = new Float_t[Nfields];
    for(Int_t i=0; i<Nfields; i++) {
        Emax[i] = hE2D[i]->GetMaximum();
        Emin[i] = hE2D[i]->GetMinimum();
        if(Emax[i] > TMath::Abs(Emin[i]))
            Emin[i] = -Emax[i];
        else
            Emax[i] = -Emin[i];
        hE2D[i]->GetZaxis()->SetRangeUser(Emin[i],Emax[i]);
    }


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

    Float_t Vmin = hV1D->GetMinimum();
    {   // Shift potential
        Int_t   NbinsX = hV2D->GetNbinsX();
        Int_t   NbinsY = hV2D->GetNbinsY();
        for(Int_t j=0; j<NbinsX; j++) {
            for(Int_t k=0; k<NbinsY; k++) {
                hV2D->SetBinContent(j,k, hV2D->GetBinContent(j,k) - Vmin -trapPotential);
            }
            hV1D->SetBinContent(j, hV1D->GetBinContent(j) - Vmin -trapPotential);
        }
    }

    Vmin = hV1D->GetMinimum();
    Float_t Vmax = hV1D->GetMaximum();

    // Dynamic potential palette
    const Int_t potPNRGBs = 5;
    const Int_t potPNCont = 64;
    Float_t zeroPos = -Vmin/(Vmax-Vmin);

    Double_t potPStops[potPNRGBs] = { 0.00, zeroPos-3.0/potPNCont,zeroPos, zeroPos+3.0/potPNCont, 1.00 };
    Double_t potPRed[potPNRGBs]   = { 0.518, 0.965, 0.90, 0.498, 0.106 };
    Double_t potPGreen[potPNRGBs] = { 0.078, 0.925, 0.90, 0.718, 0.078 };
    Double_t potPBlue[potPNRGBs]  = { 0.106, 0.353, 0.90, 0.780, 0.518 };

    PPalette * potentialPalette = (PPalette*) gROOT->FindObject("rbow2inv");
    potentialPalette->CreateGradientColorTable(potPNRGBs, potPStops,
            potPRed, potPGreen, potPBlue, potPNCont);

    // Extract contours
    TCanvas* c = new TCanvas("c","Contour List",0,0,600,600);
    c->cd();

    // Potential
    TH2F *hV2Dc = (TH2F*) hV2D->Clone("hV2Dc");
    const Int_t Ncontours = 25;
    Double_t contours[Ncontours];
    for(Int_t i=0; i<Ncontours; i++) {
        contours[i] = i*(trapPotential/5.0) - trapPotential;
    }
    hV2Dc->SetContour(Ncontours, contours);
    hV2Dc->Draw("cont list");

    c->Update();
    TObjArray *contsV2D = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
    TClonesArray graphsV2D("TGraph",Ncontours);
    {
        Int_t ncontours = contsV2D->GetSize();
        TList* clist = NULL;
        Int_t nGraphs = 0;
        TGraph *gr = NULL;
        for(Int_t i = 0; i < ncontours; i++) {
            if(i==0) continue;

            clist = (TList*) contsV2D->At(i);

            for(Int_t j = 0 ; j < clist->GetSize(); j++) {
                gr = (TGraph*) clist->At(j);
                if(!gr) continue;

                gr->SetLineWidth(1);
                gr->SetLineColor(kGray+1);

                if( !((i)%5) ) {
                    gr->SetLineWidth(2);
                    gr->SetLineColor(kGray+2);
                }
                new(graphsV2D[nGraphs]) TGraph(*gr) ;
                nGraphs++;
            }
        }
    }

    // Ion probability
    hIonProb2D->GetZaxis()->SetRangeUser(0.00501,80);

    TH2F *hIonProb2Dc = (TH2F*) hIonProb2D->Clone("hIonProb2Dc");
    const Int_t NcontI = 4;
    Double_t contI[NcontI] = {0.01,0.1,1.0,10.0};
    hIonProb2Dc->SetContour(NcontI, contI);
    hIonProb2Dc->Draw("cont list");

    c->Update();
    TObjArray *contsI2D = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
    TClonesArray graphsI2D("TGraph",NcontI);
    {
        Int_t ncontours = contsI2D->GetSize();
        TList* clist = NULL;
        Int_t nGraphs = 0;
        TGraph *gr = NULL;
        for(Int_t i = 0; i < ncontours; i++) {
            clist = (TList*) contsI2D->At(i);

            for(Int_t j = 0 ; j < clist->GetSize(); j++) {
                gr = (TGraph*) clist->At(j);
                if(!gr) continue;

                if( !(i%2) ) {
                    gr->SetLineWidth(1);
                    gr->SetLineStyle(2);
                    gr->SetLineColor(kOrange-3);
                } else {
                    gr->SetLineWidth(1);
                    gr->SetLineStyle(1);
                    gr->SetLineColor(kOrange-3);
                }

                new(graphsI2D[nGraphs]) TGraph(*gr) ;
                nGraphs++;
            }
        }
    }




    // "Axis range" in Osiris units:
    Double_t ylow  = hDen2D[0]->GetYaxis()->GetBinLowEdge(FirstyBin);
    Double_t yup = hDen2D[0]->GetYaxis()->GetBinUpEdge(LastyBin);
    Double_t xmin = hDen2D[0]->GetXaxis()->GetXmin();
    Double_t xmax = hDen2D[0]->GetXaxis()->GetXmax();

    TLine *lineYzero = new TLine(xmin,0.0,xmax,0.0);
    lineYzero->SetLineColor(kGray+2);
    lineYzero->SetLineStyle(2);

    TLine *lineYup = new TLine(xmin,yup,xmax,yup);
    lineYup->SetLineColor(kGray+1);
    lineYup->SetLineStyle(2);

    TLine *lineYdown = new TLine(xmin,ylow,xmax,ylow);
    lineYdown->SetLineColor(kGray+1);
    lineYdown->SetLineStyle(2);

    zStartPlasma -= shiftz;
    zStartNeutral -= shiftz;
    zEndNeutral -= shiftz;

    if(opt.Contains("units")) {
        zStartPlasma *= skindepth / PUnits::um;
        zStartNeutral *= skindepth / PUnits::um;
        zEndNeutral *= skindepth / PUnits::um;
    }

    //  cout << "Start plasma = " << zStartPlasma << endl;
    TLine *lineStartPlasma = new TLine(zStartPlasma,yMin,zStartPlasma,yMax);
    lineStartPlasma->SetLineColor(kGray+2);
    lineStartPlasma->SetLineStyle(2);
    lineStartPlasma->SetLineWidth(3);

    //  cout << "Start plasma = " << zStartNeutral << endl;
    TLine *lineStartNeutral = new TLine(zStartNeutral,yMin,zStartNeutral,yMax);
    lineStartNeutral->SetLineColor(kGray+1);
    lineStartNeutral->SetLineStyle(2);
    lineStartNeutral->SetLineWidth(3);

    //  cout << "End plasma = " << zEndNeutral << endl;
    TLine *lineEndNeutral = new TLine(zEndNeutral,yMin,zEndNeutral,yMax);
    lineEndNeutral->SetLineColor(kGray+1);
    lineEndNeutral->SetLineStyle(2);
    lineEndNeutral->SetLineWidth(3);


    // Plotting
    // -----------------------------------------------

    // Canvas setup
    TCanvas *C = new TCanvas("C","2D Charge density and Electric field",750,666);

    // Palettes setup
    TExec *exPlasma = new TExec("exPlasma","plasmaPalette->cd();");
    TExec *exElec   = new TExec("exElec","redelectronPalette->cd();");
    TExec *exHot    = new TExec("exHot","hotPalette->cd();");
    TExec *exField  = new TExec("exField","rbow2Palette->cd();");
    TExec *exFieldT = new TExec("exFieldT","redPalette->cd();");
    TExec *exIonP   = new TExec("exIonP","redPalette->cd();");
    TExec *exPot    = new TExec("exPot","rbow2invPalette->cd();");

    // Actual Plotting!
    // ------------------------------------------------------------

    // Output file
    TString fOutName = Form("./%s/Plots/Potential2D/Potential2D",pData->GetPath().c_str());
    fOutName += Form("-%s_%i",pData->GetName(),time);

    // Setup Pad layout:
    Float_t lMargin = 0.15;
    Float_t rMargin = 0.18;
    Float_t bMargin = 0.15;
    Float_t tMargin = 0.04;
    Float_t factor = 1.0;
    PlasmaGlob::CanvasAsymPartition(C,2,lMargin,rMargin,bMargin,tMargin,factor);

    TPad *pad[2];
    TString sLabels[] = {"(a)","(b)"};
    // Text objects
    TPaveText **textLabel = new TPaveText*[2];

    C->cd(0);
    char pname[16];
    sprintf(pname,"pad_%i",1);
    pad[0] = (TPad*) gROOT->FindObject(pname);
    pad[0]->Draw();
    pad[0]->cd(); // <---------------------------------------------- Top Plot ---------
    if(opt.Contains("logz")) {
        pad[0]->SetLogz(1);
    } else {
        pad[0]->SetLogz(0);
    }
    pad[0]->SetFrameLineWidth(3);
    pad[0]->SetTickx(1);

    // Re-range:
    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen2D[i]) continue;
        hDen2D[i]->GetYaxis()->SetRangeUser(yMin -(factor-1)*yRange, yMax);
    }


    TH2F *hFrame = (TH2F*) gROOT->FindObject("hFrame1");
    if(hFrame) delete hFrame;
    hFrame = (TH2F*) hDen2D[0]->Clone("hFrame1");
    hFrame->Reset();

    hFrame->SetLabelFont(42,"xyz");
    hFrame->SetTitleFont(42,"xyz");

    hFrame->GetYaxis()->SetNdivisions(505);
    hFrame->GetYaxis()->SetLabelSize(0.085);
    hFrame->GetYaxis()->SetTitleSize(0.09);
    hFrame->GetYaxis()->SetTitleOffset(0.7);
    hFrame->GetYaxis()->SetTickLength(0.02);

    hFrame->GetXaxis()->SetLabelOffset(999.);
    hFrame->GetXaxis()->SetTitleOffset(999.);
    hFrame->GetXaxis()->SetTickLength(0.04);

    // Frame asymmetry:
    hFrame->Draw("col");

    // hDen2D[0]->GetZaxis()->SetNdivisions(505);

    // Injected electrons if any
    if(Nspecies>=3) {
        if(hDen2D[2]) {
            exHot->Draw();
            hDen2D[2]->Draw("colz same");
        }
    }

    // Plasma
    hDen2D[0]->GetZaxis()->SetTitleFont(42);
    exPlasma->Draw();
    hDen2D[0]->Draw("colz same");

    // Beam driver.
    if(hDen2D[1]) {
        //    hDen2D[1]->GetZaxis()->SetNdivisions(505);
        exElec->Draw();
        hDen2D[1]->Draw("colz same");
    }

    {
        TGraph *gr = (TGraph*) graphsV2D.At(4);
        gr->Draw("C");
    }

    {
        TGraph *gr = (TGraph*) graphsI2D.At(1);
        gr->Draw("C");
    }


    if(opt.Contains("1dline")) {
        lineYzero->Draw();
        lineYdown->Draw();
        lineYup->Draw();
    }

    if(opt.Contains("sline")) {
        if(zStartPlasma>xmin && zStartPlasma<xmax)
            lineStartPlasma->Draw();
        if(zStartNeutral>xmin && zStartNeutral<xmax)
            lineStartNeutral->Draw();
        if(zEndNeutral>xmin && zEndNeutral<xmax)
            lineEndNeutral->Draw();
    }

    // lineYdown->Draw();
    // lineYup->Draw();

    // Palettes re-arrangement
    pad[0]->Update();
    Float_t y1 = pad[0]->GetBottomMargin();
    Float_t y2 = 1 - pad[0]->GetTopMargin();
    Float_t x1 = pad[0]->GetLeftMargin();
    Float_t x2 = 1 - pad[0]->GetRightMargin();

    TPaletteAxis *palette = NULL;
    if(Nspecies>=3) {
        if(hDen2D[2]) {
            palette = (TPaletteAxis*)hDen2D[2]->GetListOfFunctions()->FindObject("palette");
        }
    }
    if(palette) {
        palette->SetY2NDC(y2 - 0.00);
        palette->SetY1NDC(0.66*(y1+y2) + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        //  palette->SetTitleFont(42);
        //  palette->SetTitleOffset(0.85);
        palette->SetTitleOffset(999.9);
        palette->SetTitleSize(0.075);
        palette->SetLabelFont(42);
        palette->SetLabelSize(0.075);
        palette->SetLabelOffset(0.001);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }

    palette = (TPaletteAxis*)hDen2D[0]->GetListOfFunctions()->FindObject("palette");
    if(palette) {
        palette->SetY2NDC(0.66*(y1+y2) - 0.00);
        palette->SetY1NDC(0.33*(y1+y2) + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        // palette->SetTitleFont(42);
        palette->SetTitleOffset(0.80);
        palette->SetTitleSize(0.075);
        palette->SetLabelFont(42);
        palette->SetLabelSize(0.075);
        palette->SetLabelOffset(0.001);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }

    palette = (TPaletteAxis*)hDen2D[1]->GetListOfFunctions()->FindObject("palette");
    if(palette) {
        palette->SetY2NDC(0.33*(y1+y2) - 0.00);
        palette->SetY1NDC(y1 + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        //palette->SetTitleFont(42);
        //palette->SetTitleOffset(0.85);
        palette->SetTitleOffset(999.9);
        palette->SetTitleSize(0.075);
        palette->SetLabelFont(42);
        palette->SetLabelSize(0.075);
        palette->SetLabelOffset(0.001);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }


    // 1D charge density plots:
    Float_t yaxismin  =  pad[0]->GetUymin();
    Float_t yaxismax  =  pad[0]->GetUymin() + 0.33*(pad[0]->GetUymax() - pad[0]->GetUymin()) - 0.00;
    Float_t denmin = Min[1];
    Float_t denmax = Max[1];
    if(opt.Contains("logz")) {
        denmin = TMath::Log10(denmin);
        denmax = TMath::Log10(denmax);
    }

    Float_t curmin = 0.0;
    Float_t curmax = 0.0;
    if(opt.Contains("curr")) {
        curmin = 0.0;
        curmax = hCur1D[1]->GetMaximum();

        cout << Form(" Maximum driver  current = %6.2f kA ", curmax) << endl ;
        if(Nspecies>=3)
            if(hCur1D[2])
                cout << Form(" Maximum witness current = %6.2f kA ", hCur1D[2]->GetMaximum()) << endl ;

        // Round for better plotting
        curmax = 0.1*TMath::Nint(curmax*10);
    }

    for(Int_t i=0; i<Nspecies; i++) {
        if(!hDen1D[i]) continue;

        Float_t slope = (yaxismax - yaxismin)/(denmax - denmin);

        for(Int_t j=0; j<hDen1D[i]->GetNbinsX(); j++) {
            Float_t content = hDen1D[i]->GetBinContent(j+1);
            if(opt.Contains("logz")) content = TMath::Log10(content);

            if(content<denmin)
                hDen1D[i]->SetBinContent(j+1,yaxismin);
            else
                hDen1D[i]->SetBinContent(j+1,(content - denmin) * slope + yaxismin);


        }

        if(hCur1D[i]) {
            slope = (yaxismax - yaxismin)/(curmax - curmin);

            for(Int_t j=0; j<hCur1D[i]->GetNbinsX(); j++) {
                Float_t content = hCur1D[i]->GetBinContent(j+1);

                if(content<curmin)
                    hCur1D[i]->SetBinContent(j+1,yaxismin);
                else
                    hCur1D[i]->SetBinContent(j+1,(content - curmin) * slope + yaxismin);
            }

        }

    }

    // Plasma on-axis density:
    // hDen1D[0]->SetLineWidth(2);
    // hDen1D[0]->SetLineColor(kGray+1);
    // // // PlasmaGlob::SetH1Style(hDen1D[0],1);
    // hDen1D[0]->Draw("same C");


    if(opt.Contains("curr")) {
        hCur1D[1]->SetLineWidth(2);
        hCur1D[1]->SetLineColor(PlasmaGlob::elecLine);
        hCur1D[1]->Draw("same C");
    } else {
        hDen1D[1]->SetLineWidth(2);
        hDen1D[1]->SetLineColor(PlasmaGlob::elecLine);
        //    hDen1D[1]->Draw("same C");
    }

    if(Nspecies>=3) {
        if(hDen1D[2]) {
            if(opt.Contains("curr")) {
                hCur1D[2]->SetLineWidth(2);
                hCur1D[2]->SetLineColor(kOrange+8);
                hCur1D[2]->Draw("same C");
            } else {
                hDen1D[2]->SetLineWidth(2);
                hDen1D[2]->SetLineColor(kOrange+8);
                //   hDen1D[2]->Draw("same C");
            }
        }
    }

    // Current axis
    TGaxis *axis = NULL;
    if(opt.Contains("curr")) {
        axis = new TGaxis(xMax-xRange/6.0,yMin - (factor-1)*yRange,
                          xMax-xRange/6.0,yaxismax,
                          0.001,curmax,503,"+LS");

        axis->SetLineWidth(1);
        axis->SetLineColor(kGray+3);//PlasmaGlob::elecLine);
        axis->SetLabelColor(kGray+3);//PlasmaGlob::elecLine);
        axis->SetLabelSize(0.06);
        axis->SetLabelOffset(0.01);
        axis->SetLabelFont(42);
        axis->SetTitleColor(kGray+3);//PlasmaGlob::elecLine);
        axis->SetTitleSize(0.06);
        axis->SetTitleOffset(0.6);
        axis->SetTitleFont(42);
        axis->SetTickSize(0.03);
        axis->SetTitle("I [kA]");
        axis->CenterTitle();
        axis->SetNdivisions(505);

        axis->Draw();
    }


    TPaveText *textTime = new TPaveText(xMax - 0.3*xRange, yMax-0.15*yRange, xMax-0.1, yMax-0.05*yRange);
    //x2-0.17,y2-0.12,x2-0.02,y2-0.02,"NDC");
    PlasmaGlob::SetPaveTextStyle(textTime,32);
    char ctext[128];
    if(opt.Contains("units") && n0)
        sprintf(ctext,"z = %5.1f #mum", Time * skindepth / PUnits::um);
    else
        sprintf(ctext,"t = %5.1f #omega_{p}^{-1}",Time);
    textTime->SetTextFont(42);
    textTime->AddText(ctext);

    textTime->Draw();
    // textDen->Draw();
    // if(opt.Contains("units"))
    //   textWav->Draw();

    textLabel[0] = new TPaveText(xMin + 0.02*xRange, yMax-0.2*yRange, xMin+0.30*xRange, yMax-0.05*yRange);
    PlasmaGlob::SetPaveTextStyle(textLabel[0],12);
    textLabel[0]->SetTextFont(42);
    textLabel[0]->AddText(sLabels[0]);
    textLabel[0]->Draw();


    pad[0]->RedrawAxis();

    C->cd(0);
    sprintf(pname,"pad_%i",0);
    pad[1] = (TPad*) gROOT->FindObject(pname);
    pad[1]->Draw();
    pad[1]->cd(); // <--------------------------------------------------------- Bottom Plot
    pad[1]->SetFrameLineWidth(3);
    pad[1]->SetTickx(1);

    hFrame = (TH2F*) gROOT->FindObject("hFrame2");
    if(hFrame) delete hFrame;
    hFrame = (TH2F*) hDen2D[0]->Clone("hFrame2");
    hFrame->Reset();

    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[1]->GetAbsHNDC();


    hFrame->GetYaxis()->SetLabelSize(yFactor*0.085);
    hFrame->GetYaxis()->SetTitleSize(yFactor*0.09);
    hFrame->GetYaxis()->SetTitleOffset(0.7/yFactor);
    hFrame->GetYaxis()->SetTickLength(0.02/yFactor);

    hFrame->GetXaxis()->SetTitleSize(0.10);
    hFrame->GetXaxis()->SetLabelSize(0.08);
    hFrame->GetXaxis()->SetLabelOffset(0.02);
    hFrame->GetXaxis()->SetTitleOffset(1.0);
    hFrame->GetXaxis()->SetTickLength(0.04*yFactor);

    hFrame->SetLabelFont(42,"xyz");
    hFrame->SetTitleFont(42,"xyz");

    hFrame->Draw("col");

    //  hE2D[0]->GetZaxis()->SetNdivisions(505);
    hV2D->GetZaxis()->SetTitleFont(42);
    hV2D->GetZaxis()->SetTickLength(0.02/yFactor);


    exPot->Draw();

    hV2D->Draw("col z same");

    for(Int_t i=0; i<graphsV2D.GetEntriesFast(); i++) {
        TGraph *gr = (TGraph*) graphsV2D.At(i);
        if(!gr) continue;
        gr->Draw("C");
    }

    for(Int_t i=0; i<graphsI2D.GetEntriesFast(); i++) {
        //if(i!=2) continue;
        TGraph *gr = (TGraph*) graphsI2D.At(i);
        if(!gr) continue;
        gr->Draw("C");
    }


    if(opt.Contains("1dline")) {
        lineYzero->Draw();
        lineYdown->Draw();
        lineYup->Draw();
    }

    if(opt.Contains("sline")) {
        if(zStartPlasma>xmin && zStartPlasma<xmax)
            lineStartPlasma->Draw();
        if(zStartNeutral>xmin && zStartNeutral<xmax)
            lineStartNeutral->Draw();
        if(zEndNeutral>xmin && zEndNeutral<xmax)
            lineEndNeutral->Draw();
    }


    pad[1]->Update();

    y1 = pad[1]->GetBottomMargin();
    y2 = 1 - pad[1]->GetTopMargin();
    x1 = pad[1]->GetLeftMargin();
    x2 = 1 - pad[1]->GetRightMargin();

    palette = (TPaletteAxis*)hV2D->GetListOfFunctions()->FindObject("palette");
    if(palette) {
        palette->SetY2NDC(y2 - 0.00);
        palette->SetY1NDC(y1 + 0.00);
        palette->SetX1NDC(x2 + 0.005);
        palette->SetX2NDC(x2 + 0.03);
        // palette->SetTitleFont(42);
        palette->SetTitleSize(yFactor*0.075);
        palette->SetTitleOffset(0.80/yFactor);
        palette->SetLabelSize(yFactor*0.075);
        palette->SetLabelFont(42);
        palette->SetLabelOffset(0.01/yFactor);
        palette->SetBorderSize(2);
        palette->SetLineColor(1);
    }



    pad[1]->RedrawAxis();

    textLabel[1] = new TPaveText(xMin + 0.02*xRange, yMax-0.2*yRange, xMin+0.30*xRange, yMax-0.05*yRange);
    PlasmaGlob::SetPaveTextStyle(textLabel[1],12);
    textLabel[1]->SetTextFont(42);
    textLabel[1]->AddText(sLabels[1]);
    textLabel[1]->Draw();

    C->cd();

    // Print to a file
    PlasmaGlob::imgconv(C,fOutName,opt);
    // ---------------------------------------------------------

    PlasmaGlob::DestroyCanvases();
}
Example #12
0
void ZinvEstimate(){//main programme
     //Set Canvas Style
     TStyle *gStyle = new TStyle("gStyle","Style for P-TDR");
     SetStyle st;
     st.SetPars(gStyle);
     //finished setting canvas style
     DataMC plot;
     //Important
     //In kevins v3 production due to a bug puWeight is divided to all standard MC weights ...this should be removed 
     //from the code if you are using it for version otherthan V3
     TString InputFilePathV4="/eos/uscms/store/user/pedrok/SUSY2015/Analysis/Skims/Run2ProductionV4/";

     TString InputFilePathV3="/eos/uscms/store/user/pedrok/SUSY2015/Analysis/Skims/Run2ProductionV3/";

     TString InputFilePathV2="/eos/uscms/store/user/pedrok/SUSY2015/Analysis/Skims/Run2ProductionV2/";

     


     TChain* tZinv = new TChain("tree");
     tZinv->Add(InputFilePathV4+"tree_signal/tree_ZJetsToNuNu_HT*.root");
     ReadTree Zinv(tZinv);


     //reading the GJets MC
     TChain* tGJets = new TChain("tree");
     tGJets->Add(InputFilePathV4+"tree_GJet_CleanVars/tree_GJets_HT-*.root");
     ReadTree GJets(tGJets);





     //reading QCD MC
     TChain* tQCD = new TChain("tree");
     tQCD->Add(InputFilePathV4+"tree_GJet_CleanVars/tree_QCD_HT*.root");
     ReadTree QCD(tQCD);

     //reading Single photon Data
     TChain* tData = new TChain("tree");
     tData->Add(InputFilePathV4+"tree_GJet_CleanVars/tree_SinglePhoton_*.root");
     ReadTree Data(tData);

     double Lumi=1280.23;


     int nBinsHT=13;
     int nBinsMHT=7;
     int nBinsPt=8;
     int nBinsNJ=6;
     int nBinsS=25;
     double HTbins[14]={500.,600.,700,800,900,1000.,1100,1200.,1300,1400,1500,1700,2000,3000};
     double MHTbins[8]={200.,300,400,500.,600,750.,1000,1500.};
     double Ptbins[9]={100,200.,300,400,500.,600,750.,1000,1500.};
     double NJetsbins[7]={4,5,6,7,8,9,12};

    /////////Three MHT Bins
    double MHTbin1Min=200;
    double MHTbin1Max=350;
    double MHTbin2Min=350;
    double MHTbin2Max=500;
    double MHTbin3Min=500;
    double MHTbin3Max=1500;



    ///////////Three MHT Bins

     

     int nBinAN=18;
     double nBinANmax=18.5;

     /////////////////////////////////////////////////////////////////////////////All user input changes above 
     TH1F *hHT_Zinv=new TH1F("hHT_Zinv","hHT_Zinv",nBinsHT,HTbins);
     TH1F *hMHT_Zinv=new TH1F("hMHT_Zinv","hMHT_Zinv",nBinsMHT,MHTbins);
     TH1F *hNJets_Zinv=new TH1F("hNJets_Zinv","hNJets_Zinv",nBinsNJ,NJetsbins);
     


     TH1F *hHT_GJets=new TH1F("hHT_GJets","hHT_GJets",nBinsHT,HTbins);
     TH1F *hMHT_GJets=new TH1F("hMHT_GJets","hMHT_GJets",nBinsMHT,MHTbins);
     TH1F *hNJets_GJets=new TH1F("hNJets_GJets","hNJets_GJets",nBinsNJ,NJetsbins);

     TH1F *hSieta_GJetsEB=new TH1F("hSieta_GJetsEB","hSieta_GJetsEB",nBinsS,0.006,0.0107);
     TH1F *hSieta_GJetsEC=new TH1F("hSieta_GJetsEC","hSieta_GJetsEC",nBinsS,0.01,0.0272);


     TH1F *hSieta_GJetsEBLow=new TH1F("hSieta_GJetsEBLow","hSieta_GJetsEBLow",nBinsS,0.006,0.0107);
     TH1F *hSieta_GJetsECLow=new TH1F("hSieta_GJetsECLow","hSieta_GJetsECLow",nBinsS,0.01,0.0272);

     TH1F *hSieta_GJetsEBMed=new TH1F("hSieta_GJetsEBMed","hSieta_GJetsEBMed",nBinsS,0.006,0.0107);
     TH1F *hSieta_GJetsECMed=new TH1F("hSieta_GJetsECMed","hSieta_GJetsECMed",nBinsS,0.01,0.0272);

     TH1F *hSieta_GJetsEBHigh=new TH1F("hSieta_GJetsEBHigh","hSieta_GJetsEBHigh",nBinsS,0.006,0.0107);
     TH1F *hSieta_GJetsECHigh=new TH1F("hSieta_GJetsECHigh","hSieta_GJetsECHigh",nBinsS,0.01,0.0272);
  

     TH1F *hPhPt_GJetsEB=new TH1F("hPhPt_GJetsEB","hPhPt_GJetsEB",nBinsPt,Ptbins);
     TH1F *hPhPt_GJetsEC=new TH1F("hPhPt_GJetsEC","hPhPt_GJetsEC",nBinsPt,Ptbins);




     TH1F *hHT_QCD=new TH1F("hHT_QCD","hHT_QCD",nBinsHT,HTbins);
     TH1F *hMHT_QCD=new TH1F("hMHT_QCD","hMHT_QCD",nBinsMHT,MHTbins);
     TH1F *hNJets_QCD=new TH1F("hNJets_QCD","hNJets_QCD",nBinsNJ,NJetsbins);

     TH1F *hSieta_QCDEB=new TH1F("hSieta_QCDEB","hSieta_QCDEB",nBinsS,0.006,0.0107);
     TH1F *hSieta_QCDEC=new TH1F("hSieta_QCDEC","hSieta_QCDEC",nBinsS,0.01,0.0272);     



     TH1F *hSieta_QCDEBLow=new TH1F("hSieta_QCDEBLow","hSieta_QCDEBLow",nBinsS,0.006,0.0107);
     TH1F *hSieta_QCDECLow=new TH1F("hSieta_QCDECLow","hSieta_QCDECLow",nBinsS,0.01,0.0272);

     TH1F *hSieta_QCDEBMed=new TH1F("hSieta_QCDEBMed","hSieta_QCDEBMed",nBinsS,0.006,0.0107);
     TH1F *hSieta_QCDECMed=new TH1F("hSieta_QCDECMed","hSieta_QCDECMed",nBinsS,0.01,0.0272);

     TH1F *hSieta_QCDEBHigh=new TH1F("hSieta_QCDEBHigh","hSieta_QCDEBHigh",nBinsS,0.006,0.0107);
     TH1F *hSieta_QCDECHigh=new TH1F("hSieta_QCDECHigh","hSieta_QCDECHigh",nBinsS,0.01,0.0272);

     TH1F *hPhPt_QCDEB=new TH1F("hPhPt_QCDEB","hPhPt_QCDEB",nBinsPt,Ptbins);
     TH1F *hPhPt_QCDEC=new TH1F("hPhPt_QCDEC","hPhPt_QCDEC",nBinsPt,Ptbins);
    



     TH1F *hHT_Data=new TH1F("hHT_Data","hHT_Data",nBinsHT,HTbins);
     TH1F *hMHT_Data=new TH1F("hMHT_Data","hMHT_Data",nBinsMHT,MHTbins);
     TH1F *hNJets_Data=new TH1F("hNJets_Data","hNJets_Data",nBinsNJ,NJetsbins);

     TH1F *hSieta_DataEB=new TH1F("hSieta_DataEB","hSieta_DataEB",nBinsS,0.006,0.0107);
     TH1F *hSieta_DataEC=new TH1F("hSieta_DataEC","hSieta_DataEC",nBinsS,0.01,0.0272);;


     TH1F *hSieta_DataEBLow=new TH1F("hSieta_DataEBLow","hSieta_DataEBLow",nBinsS,0.006,0.0107);
     TH1F *hSieta_DataECLow=new TH1F("hSieta_DataECLow","hSieta_DataECLow",nBinsS,0.01,0.0272);

     TH1F *hSieta_DataEBMed=new TH1F("hSieta_DataEBMed","hSieta_DataEBMed",nBinsS,0.006,0.0107);
     TH1F *hSieta_DataECMed=new TH1F("hSieta_DataECMed","hSieta_DataECMed",nBinsS,0.01,0.0272);

     TH1F *hSieta_DataEBHigh=new TH1F("hSieta_DataEBHigh","hSieta_DataEBHigh",nBinsS,0.006,0.0107);
     TH1F *hSieta_DataECHigh=new TH1F("hSieta_DataECHigh","hSieta_DataECHigh",nBinsS,0.01,0.0272);
    
     TH1F *hPhPt_DataEB=new TH1F("hPhPt_DataEB","hPhPt_DataEB",nBinsPt,Ptbins);
     TH1F *hPhPt_DataEC=new TH1F("hPhPt_DataEC","hPhPt_DataEC",nBinsPt,Ptbins);
    



     TH1F *h_NZinv18bin=new TH1F("h_NZinv18bin","h_NZinv18bin",nBinAN,0.5,nBinANmax); 
     //
     TH1F *h_NZinv18binC=new TH1F("h_NZinv18binC","h_NZinv18binC",nBinAN,0.5,nBinANmax);   

     //TH1F *EBestimate=new TH1F("EBestimate","EBestimate",18,0.5,18.5);
     //TH1F *ECestimate=new TH1F("ECestimate","ECestimate",18,0.5,18.5);

     TH1F *ZinvEstimate=new TH1F("ZinvEstimate","ZinvEstimate",nBinAN,0.5,nBinANmax);

     TH1F  *h_NGJets18bin=new TH1F("h_NGJets18binC","h_NGJets18binC",nBinAN,0.5,nBinANmax); 

     TH1F *h_NGJets18binEB=new TH1F("h_NGJets18binEB","h_NGJets18binEB",nBinAN,0.5,nBinANmax);
  
     TH1F *h_NGJets18binEC=new TH1F("h_NGJets18binEC","h_NGJets18binEC",nBinAN,0.5,nBinANmax);     


     TH1F *h_NQCD18binEB=new TH1F("h_NQCD18binEB","h_NQCD18binEB",nBinAN,0.5,nBinANmax);
  
     TH1F *h_NQCD18binEC=new TH1F("h_NQCD18binEC","h_NQCD18binEC",nBinAN,0.5,nBinANmax); 



     TH1F *h_Ndata18binEB=new TH1F("h_Ndata18binEB","h_Ndata18binEB",nBinAN,0.5,nBinANmax);
   
     TH1F *h_Ndata18binEC=new TH1F("h_Ndata18binEC","h_Ndata18binEC",nBinAN,0.5,nBinANmax);



     TH1F *h_ZgammaR18bin=new TH1F("h_ZgammaR18bin","h_ZgammmaR18bin",nBinAN,0.5,nBinANmax);

     
     TH1F *h_ZgammaRWSF=new TH1F("h_ZgammaRWSF","h_ZgammmaRWSF",nBinAN,0.5,nBinANmax);

 
        


     int maxEvents_Zinv=tZinv->GetEntries();
     cout<<"maxEventsZinv: "<<maxEvents_Zinv<<endl;

     for(int iEv=0;iEv<maxEvents_Zinv;iEv++){//Looping over Zinv MC///////////////////////////////////////
     tZinv->GetEntry(iEv);
     if(iEv % 1000000==0){cout<<"Event no Zinv : "<<iEv<<endl;}
     
     int binNumber_Zinv = computeBin( Zinv.MHTclean, Zinv.HTclean, Zinv.NJetsclean, k13TeV);

     double weight=0;
     if(binNumber_Zinv >-1  && Zinv.BTagsclean==0){//Filling Yield(N_Obsereved) in Zinv
                     
         

          h_NZinv18bin->Fill(binNumber_Zinv,(Lumi*Zinv.Weight));      
          h_NZinv18binC->Fill(binNumber_Zinv,(Lumi*Zinv.Weight));


       }

     
     }//Lopping over Zinv MC//////////////////////////////////////////////////////////


      cout<<"Zinv Observed MC: "<<h_NZinv18bin->Integral()<<endl;
      cout<<"First bin: "<<h_NZinv18bin->GetBinContent(0)<<endl;

      for(int i=1;i<19;i++){
      cout<<"Zinv Bin Content: "<<h_NZinv18bin->GetBinContent(i)<<endl;
           }


     int maxEvents_GJets=tGJets->GetEntries();
     cout<<"maxEventsGJets: "<<maxEvents_GJets<<endl;
     for(int iEv=0;iEv<maxEvents_GJets;iEv++){//Looping over GJets MC///////////////////////////////////////
     tGJets->GetEntry(iEv);
     if(iEv % 1000000==0){cout<<"Event no GJets : "<<iEv<<endl;}
     
      

     int binNumber_GJets = computeBin( GJets.MHTclean, GJets.HTclean, GJets.NJetsclean, k13TeV);
     int index=GJets.photonIndex();
    

     if(binNumber_GJets >-1 && GJets.BTagsclean==0 && index !=-1 && GJets.photon_nonPrompt->at(index) !=1){//Filling Yield(N_Obsereved) in GJets MC
         
 
         hHT_GJets->Fill(GJets.HTclean,Lumi*GJets.Weight);
         hMHT_GJets->Fill(GJets.MHTclean,Lumi*GJets.Weight);
         hNJets_GJets->Fill(GJets.NJetsclean,Lumi*GJets.Weight);  
         h_NGJets18bin->Fill(binNumber_GJets,Lumi*GJets.Weight);
       


         if(fabs(GJets.bestPhoton->at(0).Eta())< 1.4442){//barrel
         hSieta_GJetsEB->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
         h_NGJets18binEB->Fill(binNumber_GJets,Lumi*GJets.Weight);
         hPhPt_GJetsEB->Fill(GJets.photonCands->at(index).Pt(),Lumi*GJets.Weight);
         ////////////////////////////////////Sieta in MHT bins
         if(GJets.MHTclean >MHTbin1Min && GJets.MHTclean< MHTbin1Max){
         hSieta_GJetsEBLow->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
             }


         if(GJets.MHTclean >MHTbin2Min && GJets.MHTclean< MHTbin2Max){
         hSieta_GJetsEBMed->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
             }


         if(GJets.MHTclean >MHTbin3Min && GJets.MHTclean< MHTbin3Max){
         hSieta_GJetsEBHigh->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
             }
          

         /////////////////////////Sieta in MHT bins




              }//barrel
         if(fabs(GJets.bestPhoton->at(0).Eta())> 1.566 && fabs(GJets.bestPhoton->at(0).Eta())< 2.5){//endcap
         hSieta_GJetsEC->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
         h_NGJets18binEC->Fill(binNumber_GJets,Lumi*GJets.Weight);
         hPhPt_GJetsEC->Fill(GJets.photonCands->at(index).Pt(),Lumi*GJets.Weight);


         ////////////////////////////////////Sieta in MHT bins
         if(GJets.MHTclean >MHTbin1Min && GJets.MHTclean< MHTbin1Max){
         hSieta_GJetsECLow->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
             }


         if(GJets.MHTclean >MHTbin2Min && GJets.MHTclean< MHTbin2Max){
         hSieta_GJetsECMed->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
             }


         if(GJets.MHTclean >MHTbin3Min && GJets.MHTclean< MHTbin3Max){
         hSieta_GJetsECHigh->Fill(GJets.photon_sigmaIetaIeta->at(index),Lumi*GJets.Weight);
             }
          

         /////////////////////////Sieta in MHT bins










             }//endcap





         }//Filling Yield(N_Obsereved) in GJets MC





     }//Looping over GJets MC//////////////////////////////////////////////////////////////////////////


     cout<<"Total GJets Events:  "<<hHT_GJets->Integral();


     int maxEvents_QCD=tQCD->GetEntries();
     cout<<"maxEventsQCD: "<<maxEvents_QCD<<endl;
     for(int iEv=0;iEv<maxEvents_QCD;iEv++){//Looping over QCD MC
     tQCD->GetEntry(iEv);
     if(iEv % 1000000==0){cout<<"Event no QCD : "<<iEv<<endl;}
     int binNumber_QCD = computeBin( QCD.MHTclean, QCD.HTclean, QCD.NJetsclean, k13TeV);
     int index=QCD.photonIndex();
     if(binNumber_QCD >-1 && QCD.BTagsclean==0 && index !=-1 && QCD.photon_nonPrompt->at(index) ==1 ){//Filling Yield(N_Obsereved) in QCD MC
         
         hHT_QCD->Fill(QCD.HTclean,Lumi*QCD.Weight);
         hMHT_QCD->Fill(QCD.MHTclean,Lumi*QCD.Weight);
         hNJets_QCD->Fill(QCD.NJetsclean,Lumi*QCD.Weight);
         


         if(fabs(QCD.bestPhoton->at(0).Eta())< 1.4442){//barrel
         hSieta_QCDEB->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
         h_NQCD18binEB->Fill(binNumber_QCD,Lumi*QCD.Weight);
         hPhPt_QCDEB->Fill(QCD.photonCands->at(index).Pt(),Lumi*QCD.Weight);


         ////////////////////////////////////Sieta in MHT bins
         if(QCD.MHTclean >MHTbin1Min && QCD.MHTclean< MHTbin1Max){
         hSieta_QCDEBLow->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
             }


         if(QCD.MHTclean >MHTbin2Min && QCD.MHTclean< MHTbin2Max){
         hSieta_QCDEBMed->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
             }


         if(QCD.MHTclean >MHTbin3Min && QCD.MHTclean< MHTbin3Max){
         hSieta_QCDEBHigh->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
             }
          

         /////////////////////////Sieta in MHT bins











              }//barrel
         if(fabs(QCD.bestPhoton->at(0).Eta())> 1.566 && abs(QCD.bestPhoton->at(0).Eta()) <2.5 ){//endcap
         hSieta_QCDEC->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
         h_NQCD18binEC->Fill(binNumber_QCD,Lumi*QCD.Weight);
         hPhPt_QCDEC->Fill(QCD.photonCands->at(index).Pt(),Lumi*QCD.Weight);
             }//endcap


         ////////////////////////////////////Sieta in MHT bins
         if(QCD.MHTclean >MHTbin1Min && QCD.MHTclean< MHTbin1Max){
         hSieta_QCDECLow->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
             }


         if(QCD.MHTclean >MHTbin2Min && QCD.MHTclean< MHTbin2Max){
         hSieta_QCDECMed->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
             }


         if(QCD.MHTclean >MHTbin3Min && QCD.MHTclean< MHTbin3Max){
         hSieta_QCDECHigh->Fill(QCD.photon_sigmaIetaIeta->at(index),Lumi*QCD.Weight);
             }
          

         /////////////////////////Sieta in MHT bins





         }//Filling Yield(N_Obsereved) in QCD MC




     }//Looping over QCD MC
 

     

     int maxEvents_Data=tData->GetEntries();
     //cout<<"maxEvents in Single Photon Data: "<<maxEvents_Data<<endl;
     for(int iEv=0;iEv<maxEvents_Data;iEv++){//Data
     tData->GetEntry(iEv);
     if(iEv % 1000000==0){cout<<"Event no Data : "<<iEv<<endl;}
     
      //cout<<"Event no: "<<iEv<<endl;
     int binNumber_Data = computeBin( Data.MHTclean, Data.HTclean, Data.NJetsclean, k13TeV);
     int index=Data.photonIndex();

     if(binNumber_Data >-1 && Data.BTagsclean==0 && index !=-1){//Filling Yield(N_Obsereved) in Data
            bool PassTrigger=false;
          
         for(int itr=0;itr<Data.TriggerNames->size();itr++){
             //cout<<"trigger size: "<<Data.TriggerNames->at(itr)<<endl;
             if(Data.TriggerNames->at(itr)=="HLT_Photon90_CaloIdL_PFHT500_v3" && Data.TriggerPass->at(itr)==1){
                PassTrigger=true;


               }

              }


         

         if(PassTrigger==true){//trigger pass
         
         hHT_Data->Fill(Data.HTclean);
         hMHT_Data->Fill(Data.MHTclean);
         hNJets_Data->Fill(Data.NJetsclean);



         if(fabs(Data.bestPhoton->at(0).Eta())< 1.4442){//barrel
         

         h_Ndata18binEB->Fill(binNumber_Data);
         hSieta_DataEB->Fill(Data.photon_sigmaIetaIeta->at(index));
         hPhPt_DataEB->Fill(Data.photonCands->at(index).Pt());


         ////////////////////////////////////Sieta in MHT bins
         if(Data.MHTclean >MHTbin1Min && Data.MHTclean< MHTbin1Max){
         hSieta_DataEBLow->Fill(Data.photon_sigmaIetaIeta->at(index));
             }


         if(Data.MHTclean >MHTbin2Min && Data.MHTclean< MHTbin2Max){
         hSieta_DataEBMed->Fill(Data.photon_sigmaIetaIeta->at(index));
             }


         if(Data.MHTclean >MHTbin3Min && Data.MHTclean< MHTbin3Max){
         hSieta_DataEBHigh->Fill(Data.photon_sigmaIetaIeta->at(index));
             }
          

         /////////////////////////Sieta in MHT bins










              }//barrel
         if(fabs(Data.bestPhoton->at(0).Eta())> 1.566 && fabs(Data.bestPhoton->at(0).Eta())< 2.5 ){//endcap
         h_Ndata18binEC->Fill(binNumber_Data);
         hSieta_DataEC->Fill(Data.photon_sigmaIetaIeta->at(index));
         hPhPt_DataEC->Fill(Data.photonCands->at(index).Pt());


         ////////////////////////////////////Sieta in MHT bins
         if(Data.MHTclean >MHTbin1Min && Data.MHTclean< MHTbin1Max){
         hSieta_DataECLow->Fill(Data.photon_sigmaIetaIeta->at(index));
             }


         if(Data.MHTclean >MHTbin2Min && Data.MHTclean< MHTbin2Max){
         hSieta_DataECMed->Fill(Data.photon_sigmaIetaIeta->at(index));
             }


         if(Data.MHTclean >MHTbin3Min && Data.MHTclean< MHTbin3Max){
         hSieta_DataECHigh->Fill(Data.photon_sigmaIetaIeta->at(index));
             }
          

         /////////////////////////Sieta in MHT bins










             }//endcap
             

         
         }//trigger pass 

         }//Filling Yield(N_Obsereved) in Data




     

     }//Data 


     //trigger efficiency
     



     ///////////////////////////defining legend
    char Legname1[100];
    TLegend *leg[24];
    for(int k0=0;k0<24;k0++){
    sprintf(Legname1,"leg_1D%i",k0);
    leg[k0]=new TLegend(0.5,0.7,0.80,0.89);
    leg[k0]->SetTextFont(62);
    leg[k0]->SetLineColor(1);
    leg[k0]->SetLineStyle(1);
    leg[k0]->SetLineWidth(3);
    leg[k0]->SetFillColor(0);
    leg[k0]->SetFillStyle(1001);
    leg[k0]->SetShadowColor(0);
    leg[k0]->SetDrawOption(0);
    leg[k0]->SetBorderSize(0);
    leg[k0]->SetTextSize(0.03);
    }


     ///////////////////////////////ZinvMC Yield

     //TCanvas *ZinvMCYield=new TCanvas("ZinvMC","ZinvMC");
     //ZinvMCYield->SetLogy();
     h_NZinv18bin->Sumw2();
     h_NZinv18bin->SetFillColor(1);
     h_NZinv18bin->SetFillStyle(1000);
     h_NZinv18bin->GetXaxis()->SetTitle("bin Number");
     h_NZinv18bin->GetYaxis()->SetTitle("Z/Gamma Ratio");
     //h_NZinv18bin->Draw("hist");

   //////////////////////////////////////////////Calculating Zgamma Ratio start
      TPaveText *tpav1 = new TPaveText(0.1956522,0.6247818,0.729097,0.8970332,"brNDC");

    tpav1->SetBorderSize(0);
    tpav1->SetFillStyle(0);
    tpav1->SetTextAlign(11);
    tpav1->SetTextFont(42);
    tpav1->SetTextSize(0.04);
    tpav1->AddText("HT >500");
    tpav1->AddText("#gamma p_{T} > 100 ");
    tpav1->AddText("NJets >=4");
    tpav1->AddText("MHT>200");
    tpav1->AddText("Btags=0");
    tpav1->AddText("#Delta #Phi_{1,2,3,4}>(0.5,0.5,0.3,0.3)");

    TPaveText *pCMS1 = new TPaveText(0.132107,0.9308003,0.8327759,0.9923583,"brNDC");

    pCMS1->SetBorderSize(0);
    pCMS1->SetFillStyle(0);
    pCMS1->SetTextAlign(11);
    pCMS1->SetTextFont(42);
    pCMS1->SetTextSize(0.04);
    pCMS1->AddText("CMS #it{Preliminary}                      #sqrt{s}= 13 TeV");

    
    
     TCanvas *cZgammaR=new TCanvas("cZGammaR","cZGammaR");
     TH1F *h_ZgR = (TH1F*)h_NZinv18bin->Clone("h_ZgR");

     h_ZgR->Divide(h_NGJets18bin);


     cZgammaR->cd();
     h_ZgR->Draw("E2");
     tpav1->Draw();
     pCMS1->Draw();
    
     cZgammaR->SaveAs("ZgammaRatioWOSF.png");
     cZgammaR->SaveAs("ZgammaRatioWOSF.pdf");
     cZgammaR->SaveAs("ZgammaRatioWOSF.gif");
     
     ///////////////////////////////////Calculating ZGamma ratio end




     
    /////////////////////////////////////////////////////Dealing with Data barrel

   



     TH1F *h_DataSimEB = (TH1F*)h_Ndata18binEB->Clone("h_DataSimEB");
     
     TH1F *h_DataSimEC = (TH1F*)h_Ndata18binEC->Clone("h_DataSimEC");
   

     TH1F *h_DataSimEBforErr = (TH1F*)h_NGJets18binEB->Clone("h_DataSimEBforErr");
     
     TH1F *h_DataSimECforErr = (TH1F*)h_NGJets18binEB->Clone("h_DataSimECforErr");
     
     h_DataSimEBforErr->Scale((1/h_DataSimEBforErr->Integral())*h_Ndata18binEB->Integral());
     h_DataSimECforErr->Scale((1/h_DataSimECforErr->Integral())*h_Ndata18binEC->Integral());
     
     /////////////////////Fill the empty bins with simulated data
        
     for(int i=1;i<(nBinAN+1);i++){//loop over bins

        h_DataSimEB->SetBinError(i,0.);
        h_DataSimEC->SetBinError(i,0.);

        


        }//loop over bins 
        


     

     TH1F *hEBPurity=new TH1F("hEBPurity","hEBPurity",nBinAN,0.5,nBinANmax);
     TH1F *hECPurity=new TH1F("hECPurity","hECPurity",nBinAN,0.5,nBinANmax);
     
     TH1F *hEBfrag=new TH1F("hEBfrag","hEBfrag",nBinAN,0.5,nBinANmax);
     TH1F *hECfrag=new TH1F("hECfrag","hECfrag",nBinAN,0.5,nBinANmax);    
                         //uncorel      //corel
     double ebpErr=sqrt((0.009*0.009)+(0.03*0.03));
     double ecpErr=sqrt((0.016*0.016)+(0.046*0.046));

     double ebpErrCorel=0.03;
     double ebpErrUnCorel=0.009;

     double ecpErrCorel=0.046;
     double ecpErrUnCorel=0.016;


     for(int i=1;i<(nBinAN+1);i++){//set purity stuff
          hEBPurity->SetBinContent(i,0.967);
          hEBPurity->SetBinError(i,ebpErr);
          hECPurity->SetBinContent(i,0.956);
          hECPurity->SetBinError(i,ecpErr);
          
          hEBfrag->SetBinContent(i,0.92);
          hEBfrag->SetBinError(i,0.04);
          hECfrag->SetBinContent(i,0.92);
          hECfrag->SetBinError(i,0.04);


         }//set purity stuff     


    

    const Int_t NumBins= nBinAN;
    double binNumber[nBinAN];
    double YieldEstimated[nBinAN];
    double YieldErrUp_Estimated[nBinAN];
    double YieldErrLow_Estimated[nBinAN];

    double YieldPredMC[nBinAN];
    double YieldErrUp_PredMC[nBinAN];
    double YieldErrLow_PredMC[nBinAN];

    double XErrLow[nBinAN];
    double XErrUp[nBinAN];


    double ZgRwSF[nBinAN];
    double ZgRwSF_sys_ErrUp[nBinAN];
    double ZgRwSF_sys_ErrLow[nBinAN];
    double ZgRwSF_stat_Err[nBinAN];



    for(int ibin=1;ibin<(nBinAN+1);ibin++){//loop over bin error calculation


       double SF=0.98;
       double SFup=1.03;
       double SFlow=0.93;
       double ZgRcentral=h_ZgR->GetBinContent(ibin)/0.98;
       double ZgRup=h_ZgR->GetBinContent(ibin)/1.03;
       double ZgRlow=h_ZgR->GetBinContent(ibin)/0.93;

       double ZgRcorelErrup=fabs(ZgRcentral-ZgRlow);
       double ZgRcorelErrlow=fabs(ZgRcentral-ZgRup);

       double ZgRsymErr=0.5*(sqrt((ZgRcorelErrup*ZgRcorelErrup)+(ZgRcorelErrlow*ZgRcorelErrlow)));
       double ZgRcorel_Rel_Errup=ZgRcorelErrup/ZgRcentral;
       double ZgRcorel_Rel_Errlow=ZgRcorelErrlow/ZgRcentral;

       

       //double ZgRcorelErr=sqrt((ZgRcorelErrup*ZgRcorelErrup)+(ZgRcorelErrlow*ZgRcorelErrlow));

       double ZgRuncorelErr=h_ZgR->GetBinError(ibin)/SF;

       double ZgRuncorel_Rel_Err=ZgRuncorelErr/ZgRcentral;
   
       double ZgRsymErrStat=h_ZgR->GetBinError(ibin)/SF;//h_ZgR->GetBinError(ibin);
       
       double ZgRallSymErr=sqrt((ZgRsymErr*ZgRsymErr)+(ZgRsymErrStat*ZgRsymErrStat));

       

       
       //important lines to be changed
       double ZgR=ZgRcentral;
       
       double ZgRerr=ZgRallSymErr;
   
       double ZgRerrUp=sqrt((ZgRcorelErrup*ZgRcorelErrup)+(ZgRuncorelErr*ZgRuncorelErr));
       double ZgRerrLow=sqrt((ZgRcorelErrlow*ZgRcorelErrlow)+(ZgRuncorelErr*ZgRuncorelErr));
     

       ////////////////////////////////////barrel starts
       int EBobs=h_DataSimEB->GetBinContent(ibin);
       double EBobsErr=h_DataSimEB->GetBinError(ibin);     

       double pEB=hEBPurity->GetBinContent(ibin);
       double pEBerr=hEBPurity->GetBinError(ibin);
       double pEB_Rel_err=pEBerr/pEB;


       int ECobs=h_DataSimEC->GetBinContent(ibin);
       double ECobsErr=h_DataSimEC->GetBinError(ibin);

       double pEC=hECPurity->GetBinContent(ibin);
       double pECerr=hECPurity->GetBinError(ibin);       
       double pEC_Rel_err=pECerr/pEC;

       double f=0.92;
       double ferr=0.04;
       double f_Rel_err=ferr/f;

       double YieldTotal=ZgR*(EBobs*pEB+ECobs*pEC)*f;
       double YieldTotalErr=0;
       double YieldTotal_Rel_Err=0;

       double YieldTotalErrUp=0;
       double YieldTotal_Rel_ErrUp=0;

       double YieldTotalErrLow=0;
       double YieldTotal_Rel_ErrLow=0;


       int Nobserved=EBobs+ECobs;

       
       double totalPurity=0;
       double totalPurityErr=0;
       double totalPurity_Rel_Err=0;
       
       double ZinvMCYield=h_NZinv18binC->GetBinContent(ibin);
       double ZinvMCYieldErr=h_NZinv18binC->GetBinError(ibin);
       double ZinvMCYield_Rel_Err=ZinvMCYieldErr/ZinvMCYield;


       if(Nobserved !=0){
          totalPurity=((EBobs*pEB+ECobs*pEC)*f)/Nobserved;
          double totalPurityErr1=(EBobs*pEBerr+ECobs*pECerr)/Nobserved;
          double totalPurityErr2=ferr;
          totalPurityErr=sqrt((totalPurityErr1*totalPurityErr1)+(totalPurityErr2*totalPurityErr2));
          totalPurity_Rel_Err=totalPurityErr/totalPurity;


          YieldTotalErr=Nobserved*(sqrt((ZgR*ZgR*totalPurityErr*totalPurityErr)+(totalPurity*totalPurity*ZgRerr*ZgRerr)));

          YieldTotal_Rel_Err=YieldTotalErr/YieldTotal; 


          YieldTotalErrUp=Nobserved*(sqrt((ZgR*ZgR*totalPurityErr*totalPurityErr)+(totalPurity*totalPurity*ZgRerrUp*ZgRerrUp)));

          YieldTotal_Rel_ErrUp=YieldTotalErrUp/YieldTotal;
          

          YieldTotalErrLow=Nobserved*(sqrt((ZgR*ZgR*totalPurityErr*totalPurityErr)+(totalPurity*totalPurity*ZgRerrLow*ZgRerrLow)));

          YieldTotal_Rel_ErrLow=YieldTotalErrLow/YieldTotal;



           }
        if(Nobserved ==0){

          double NobservedNew=h_DataSimEBforErr->GetBinContent(ibin)+h_DataSimECforErr->GetBinContent(ibin);
          double EBobsNew=h_DataSimEBforErr->GetBinContent(ibin);
          double ECobsNew=h_DataSimECforErr->GetBinContent(ibin);
          totalPurity=((EBobsNew*pEB+ECobsNew*pEC)*f)/NobservedNew;
          
          double totalPurityErr1=(EBobsNew*pEBerr+ECobsNew*pECerr)/NobservedNew;
          double totalPurityErr2=ferr;
          totalPurityErr=sqrt((totalPurityErr1*totalPurityErr1)+(totalPurityErr2*totalPurityErr2));
          totalPurity_Rel_Err=totalPurityErr/totalPurity;

          YieldTotalErr=NobservedNew*(sqrt((ZgR*ZgR*totalPurityErr*totalPurityErr)+(totalPurity*totalPurity*ZgRerr*ZgRerr)));

          double YieldTotalNew=ZgR*(EBobsNew*pEB+ECobsNew*pEC)*f;

          YieldTotal_Rel_Err=YieldTotalErr/YieldTotalNew;


          YieldTotalErrUp=NobservedNew*(sqrt((ZgR*ZgR*totalPurityErr*totalPurityErr)+(totalPurity*totalPurity*ZgRerrUp*ZgRerrUp)));

          YieldTotal_Rel_ErrUp=YieldTotalErrUp/YieldTotalNew;
          

          YieldTotalErrLow=NobservedNew*(sqrt((ZgR*ZgR*totalPurityErr*totalPurityErr)+(totalPurity*totalPurity*ZgRerrLow*ZgRerrLow)));

          YieldTotal_Rel_ErrLow=YieldTotalErrLow/YieldTotalNew;







           }


        

          double YieldErrWithStat=0;
          double YieldErrWithStatUp=0;
          double YieldErrWithStatLow=0;
          double NobsErr=sqrt(Nobserved);
          YieldErrWithStat=sqrt((ZgR*totalPurity*NobsErr)*(ZgR*totalPurity*NobsErr) + (Nobserved*totalPurity*ZgRerr)*(Nobserved*totalPurity*ZgRerr) + (Nobserved*ZgR*totalPurityErr)*(Nobserved*ZgR*totalPurityErr));
         
          YieldErrWithStatUp=sqrt((ZgR*totalPurity*NobsErr)*(ZgR*totalPurity*NobsErr) + (Nobserved*totalPurity*ZgRerrUp)*(Nobserved*totalPurity*ZgRerrUp) + (Nobserved*ZgR*totalPurityErr)*(Nobserved*ZgR*totalPurityErr));
         

          YieldErrWithStatLow=sqrt((ZgR*totalPurity*NobsErr)*(ZgR*totalPurity*NobsErr) + (Nobserved*totalPurity*ZgRerrLow)*(Nobserved*totalPurity*ZgRerrLow) + (Nobserved*ZgR*totalPurityErr)*(Nobserved*ZgR*totalPurityErr));
      
      
     ZgRwSF[ibin-1]=ZgR;
     ZgRwSF_sys_ErrUp[ibin-1]=ZgRcorelErrup;
     ZgRwSF_sys_ErrLow[ibin-1]=ZgRcorelErrlow;
     ZgRwSF_stat_Err[ibin-1]=ZgRuncorelErr;




      
      
      binNumber[ibin-1]=ibin;
      YieldEstimated[ibin-1]=YieldTotal;
      YieldErrUp_Estimated[ibin-1]=YieldErrWithStatUp;
      YieldErrLow_Estimated[ibin-1]=YieldErrWithStatLow;
  
      YieldPredMC[ibin-1]=ZinvMCYield;
      YieldErrUp_PredMC[ibin-1]=ZinvMCYieldErr;
      YieldErrLow_PredMC[ibin-1]=ZinvMCYieldErr;
      XErrLow[ibin-1]=0.5;
      XErrUp[ibin-1]=0.5;    






printf(" %i :%i |%i| %4.3f(%4.3f) |%i| %4.3f(%4.3f) |%4.3f(%4.3f,+%4.3f-%4.3f)| %4.3f(%4.3f) |%4.3f(%4.3f)| %4.3f(+%4.3f-%4.3f) |%4.3f(%4.3f)",ibin,Nobserved, EBobs,pEB,pEB_Rel_err,ECobs,pEC,pEC_Rel_err, ZgR,ZgRuncorel_Rel_Err,ZgRcorel_Rel_Errup,ZgRcorel_Rel_Errlow,f,f_Rel_err,totalPurity,totalPurity_Rel_Err,YieldTotal,YieldTotal_Rel_ErrUp,YieldTotal_Rel_ErrLow,ZinvMCYield,ZinvMCYield_Rel_Err);
//printf("%4.3f",ZinvMCYield);

      //printf("bin %i :%i | %4.3f(%4.3f) | %4.3f(%4.3f)  | %4.2f(%4.3f) ",ibin,Nobserved,ZgR,ZgRerr,totalPurity,totalPurityErr,YieldTotal,YieldTotalErr);

   //printf("bin %i :%i | %4.3f(%4.3f,+%4.3f-%4.3f) | %4.3f(%4.3f)  | %4.2f(+%4.3f-%4.3f) ",ibin,Nobserved,ZgR,ZgRuncorel_Rel_Err,ZgRcorel_Rel_Errup,ZgRcorel_Rel_Errlow,totalPurity,totalPurity_Rel_Err,YieldTotal,YieldTotal_Rel_ErrUp,YieldTotal_Rel_ErrLow);

     cout<<endl;
     

      
      double Percent=(int)round(100*(YieldTotalErr/YieldTotal));

      
      double maxErrorYield=max(YieldErrWithStatUp,YieldErrWithStatLow);
      ZinvEstimate->SetBinContent(ibin,YieldTotal);
      ZinvEstimate->SetBinError(ibin,maxErrorYield);

       /////////////////endcap ends

        

       }//loop over bin error calculation



      ////////////////////////Pred vs Estimated



     TPaveText *tpa = new TPaveText(0.5056522,0.6247818,0.829097,0.8970332,"brNDC");

      tpa->SetBorderSize(0);
      tpa->SetFillStyle(0);
      tpa->SetTextAlign(11);
      tpa->SetTextFont(42);
      tpa->SetTextSize(0.04);
      tpa->AddText("HT >500");
      tpa->AddText("N_{jets} >=4");
      tpa->AddText("MHT>200");
      tpa->AddText("Btags=0");
      tpa->AddText("#Delta #Phi_{1,2,3,4}>(0.5,0.5,0.3,0.3)");



      TPaveText *pCMS = new TPaveText(0.132107,0.9308003,0.8327759,0.9923583,"brNDC");

      pCMS->SetBorderSize(0);
      pCMS->SetFillStyle(0);
      pCMS->SetTextAlign(11);
      pCMS->SetTextFont(42);
      pCMS->SetTextSize(0.04);
      pCMS->AddText("CMS #it{Preliminary}       1.3 fb^{-1} #sqrt{s}= 13 TeV");

      


       TLegend *legP = new TLegend(0.2173913,0.2478185,0.5167224,0.4363002,NULL,"brNDC");
      legP->SetBorderSize(0);
      legP->SetTextFont(62);
      legP->SetTextSize(0.03);
      legP->SetLineColor(1);
      legP->SetLineStyle(1);
      legP->SetLineWidth(3);
      legP->SetFillColor(0);
      legP->SetFillStyle(1001);

      cout<<"Est: "<<ZinvEstimate->Integral()<<endl;
      cout<<"Pred: "<<h_NZinv18binC->Integral()<<endl;

     
     //////////////////////////////////ZGammaRatio

     c_ZgRwSF = new TCanvas("c_ZgRwSF","c_ZgRwSF");
     c_ZgRwSF->cd();
     
     

     gr_ZgRwSFsys = new TGraphAsymmErrors(NumBins,binNumber,ZgRwSF,XErrLow,XErrUp,ZgRwSF_sys_ErrLow,ZgRwSF_sys_ErrUp);
     gr_ZgRwSFsys->SetTitle("ZgammaRatio");
     gr_ZgRwSFsys->SetMarkerColor(4);
     gr_ZgRwSFsys->SetLineColor(4);
     gr_ZgRwSFsys->SetMarkerStyle(21);

     gr_ZgRwSFstat = new TGraphAsymmErrors(NumBins,binNumber,ZgRwSF,XErrLow,XErrUp,ZgRwSF_stat_Err,ZgRwSF_stat_Err);
     gr_ZgRwSFstat->SetTitle("ZgammaRatio");
     gr_ZgRwSFstat->SetMarkerColor(2);
     gr_ZgRwSFstat->SetLineColor(2);
     gr_ZgRwSFstat->SetMarkerStyle(21);

     TLegend *legPZgR = new TLegend(0.2173913,0.7478185,0.5167224,0.8563002,NULL,"brNDC");
      legPZgR->SetBorderSize(0);
      legPZgR->SetTextFont(62);
      legPZgR->SetTextSize(0.03);
      legPZgR->SetLineColor(1);
      legPZgR->SetLineStyle(1);
      legPZgR->SetLineWidth(3);
      legPZgR->SetFillColor(0);
      legPZgR->SetFillStyle(1001);

      legPZgR->AddEntry(gr_ZgRwSFsys,"Sys Error","l");
      legPZgR->AddEntry(gr_ZgRwSFstat,"Stat Error","l");

     TMultiGraph *mgZgR=new TMultiGraph();
     mgZgR->SetTitle(" ;ith Bin ; Z/#gamma Ratio ");
     
     mgZgR->Add(gr_ZgRwSFstat);
     mgZgR->Add(gr_ZgRwSFsys);

     mgZgR->Draw("AP");
     tpa->Draw();
     pCMS->Draw();
     legPZgR->Draw();

     c_ZgRwSF->SaveAs("ZGammaRatioWSF.png");
     c_ZgRwSF->SaveAs("ZGammaRatioWSF.pdf");
     c_ZgRwSF->SaveAs("ZGammaRatioWSF.gif");



     ///////////////////////////////ZGammaRatio







     cPredVsEstimated = new TCanvas("estvspred","estvspred");
     
       TPad *pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0);
       pad1->SetBottomMargin(0); // Upperand lower plot are joined
       pad1->Draw();             // Draw the upper pad: pad1
       gPad->Update();
       pad1->cd();               // pad1 becomes the current pad
       gPad->DrawFrame(0.5, 0.01, 18.5, 2000, "PredVsEst;ith Bin;Events");
       gPad->SetLogy();
     
     gr_estimated = new TGraphAsymmErrors(NumBins,binNumber,YieldEstimated,XErrLow,XErrUp,YieldErrLow_Estimated,YieldErrUp_Estimated);
     gr_estimated->SetTitle("Estimated");
     gr_estimated->SetMarkerColor(4);
     gr_estimated->SetLineColor(4);
     gr_estimated->SetMarkerStyle(21);
     

     gr_mcPred = new TGraphAsymmErrors(NumBins,binNumber,YieldPredMC,XErrLow,XErrUp,YieldErrLow_PredMC,YieldErrUp_PredMC);
     gr_mcPred->SetTitle("MC predicted");
     gr_mcPred->SetMarkerColor(2);
     gr_mcPred->SetLineColor(2);
     gr_mcPred->SetMarkerStyle(8);


      legP->AddEntry(gr_mcPred,"Zinv MC Pred ","P");
      
      legP->AddEntry(gr_estimated,"Estimated(from #gamma +Jets)","P");

    


     char TMgname1[100];
     TMultiGraph *TMg_1D[2];
     for(int k0=0;k0<2;k0++){
     sprintf(TMgname1,"TMg_1D%i",k0);
     TMg_1D[k0]=new TMultiGraph();
      }
     for(int j0=0;j0<2;j0++){
     TMg_1D[j0]->SetMinimum(0.01);
     TMg_1D[j0]->SetMaximum(2000);
      }
      
    TMg_1D[0]->SetTitle(" ;ith Bin ; Events ");

    TMg_1D[0]->Add(gr_mcPred);
    TMg_1D[0]->Add(gr_estimated);


    
    TMg_1D[0]->Draw("AP");
    TMg_1D[0]->GetXaxis()->SetLimits(0.5,18.5); 
   
    tpa->Draw();
    pCMS->Draw();
    legP->Draw();


   TGaxis *axis = new TGaxis( -5, 20, -5, 220, 20,220,510,"");
       axis->SetLabelFont(43); // Absolute font size in pixel (precision 3)
       axis->SetLabelSize(15);
       axis->Draw();



  cPredVsEstimated->cd();

      TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3);
      pad2->SetTopMargin(0);
      pad2->SetBottomMargin(0.2);
      pad2->SetGridy(); // vertical grid
      pad2->Draw();
      pad2->cd();       // pad2 becomes the current pad


   TH1F *h3 = (TH1F*)h_NZinv18binC->Clone("h3");
   h3->SetLineColor(kBlack);
   h3->SetMinimum(-1);  // Define Y ..
   h3->SetMaximum(3); // .. range
   h3->Sumw2();
   h3->SetStats(0);      // No statistics on lower plot
   h3->Divide(ZinvEstimate);
   h3->SetMarkerStyle(21);
   h3->SetMarkerColor(1);
   h3->Draw("ep");       // Draw the r
   h3->GetXaxis()->SetTitle("ith Bin"); // Remove the ratio title

   // Y axis ratio plot settings
   h3->GetYaxis()->SetTitle("Pred/Est");
   h3->GetYaxis()->SetNdivisions(505);

   h3->GetYaxis()->SetTitleSize(20);
   h3->GetYaxis()->SetTitleFont(43);
   h3->GetYaxis()->SetTitleOffset(1.55);
   h3->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3)
   h3->GetYaxis()->SetLabelSize(15);

   // X axis ratio plot settings
   h3->GetXaxis()->SetTitleSize(20);
   h3->GetXaxis()->SetTitleFont(43);
   h3->GetXaxis()->SetTitleOffset(3.);
   h3->GetXaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3)
   h3->GetXaxis()->SetLabelSize(15);


     cPredVsEstimated->SaveAs("PredVsEstimated.png");
     cPredVsEstimated->SaveAs("PredVsEstimated.gif");
     cPredVsEstimated->SaveAs("ZPredVsEstimated.pdf");



   

     
      
      
      






    /////////////////////////////Fill the empty bins with simulated data
     


       TCanvas *c[20];
   int a;

  double promptfrac=hSieta_GJetsEB->Integral()/(hSieta_GJetsEB->Integral()+hSieta_QCDEB->Integral());

  cout<<"prompt fraction: "<<promptfrac<<endl;

  
  
   plot.plotHist(hHT_Data,hHT_GJets,hHT_QCD,c[0],"","Data","MC","HT");
   
   plot.plotHist(hMHT_Data,hMHT_GJets,hMHT_QCD,c[1],"","Data","MC","MHT");
   
   plot.plotHist(hNJets_Data,hNJets_GJets,hNJets_QCD,c[2],"","Data","MC","Njets");
   
   plot.plotHist(hSieta_DataEB,hSieta_GJetsEB,hSieta_QCDEB,c[3],"EB","Data","MC","SigmaIetaIeta_EB");
   
   plot.plotHist(hSieta_DataEBLow,hSieta_GJetsEBLow,hSieta_QCDEBLow,c[4],"Low-MHT-EB","Data","MC","SigmaIetaIeta_EB");
   
   plot.plotHist(hSieta_DataEBMed,hSieta_GJetsEBMed,hSieta_QCDEBMed,c[5],"Med-MHT-EB","Data","MC","SigmaIetaIeta_EB");
   
   plot.plotHist(hSieta_DataEBHigh,hSieta_GJetsEBHigh,hSieta_QCDEBHigh,c[6],"High-MHT-EB","Data","MC","SigmaIetaIeta_EB");
   

   plot.plotHist(hSieta_DataEC,hSieta_GJetsEC,hSieta_QCDEC,c[7],"EE","Data","MC","SigmaIetaIeta_EE");
   
   plot.plotHist(hSieta_DataECLow,hSieta_GJetsECLow,hSieta_QCDECLow,c[8],"Low-MHT-EE","Data","MC","SigmaIetaIeta_EE");
   
   plot.plotHist(hSieta_DataECMed,hSieta_GJetsECMed,hSieta_QCDECMed,c[9],"Med-MHT-EE","Data","MC","SigmaIetaIeta_EE");
   
   plot.plotHist(hSieta_DataECHigh,hSieta_GJetsECHigh,hSieta_QCDECHigh,c[10],"High-MHT-EE","Data","MC","SigmaIetaIeta_EE");   


   
   
   plot.plotHist(hPhPt_DataEB,hPhPt_GJetsEB,hPhPt_QCDEB,c[11],"EB","Data","MC","PhotonPt_EB");

   

   plot.plotHist(hPhPt_DataEC,hPhPt_GJetsEC,hPhPt_QCDEC,c[12],"EE","Data","MC","PhotonPt_EE");

   

   plot.plotHist(h_Ndata18binEB,h_NGJets18binEB,h_NQCD18binEB,c[13],"EB","Data","MC","ith-Bin-EB");
   
   plot.plotHist(h_Ndata18binEC,h_NGJets18binEC,h_NQCD18binEC,c[14],"EE","Data","MC","ith-Bin-EE");

   

  
  

     
   







}//main programme
Example #13
0
void PlotDensity1D( const TString &sim, Int_t time, Int_t Nbins=1, const TString &options="") {
  
#ifdef __CINT__  
  gSystem->Load("libplasma.so");
#endif

  PlasmaGlob::Initialize();
  
  // Init Units table
  PUnits::UnitsTable::Get();

  // Load PData
  PData *pData = PData::Get(sim.Data());
  pData->LoadFileNames(time);
  if(!pData->IsInit()) return; 

  TString opt = options;
 
  gStyle->SetPadRightMargin(0.20); // Margin right axis 
  if(opt.Contains("grid")) {
    gStyle->SetPadGridX(1);
    gStyle->SetPadGridY(1);
  }

  Bool_t CYL = kFALSE;
  if(sim.Contains("cyl")) { CYL = kTRUE; opt += "cyl"; } 
  
  Bool_t ThreeD = kFALSE;
  if(sim.Contains("3D")) ThreeD = kTRUE; 

  Bool_t INT = kTRUE; // Integrate instead of averaging.
  
  // Some plasma constants
  Float_t n0 = pData->GetPlasmaDensity(); 
  Float_t kp = pData->GetPlasmaK();       
  Float_t skindepth = (1/kp);               
  Float_t E0 = pData->GetPlasmaE0();

  // Some beam properties:
  Double_t Ebeam = pData->GetBeamEnergy();
  Double_t gamma = pData->GetBeamGamma();
  Double_t vbeam = pData->GetBeamVelocity();
  Double_t kbeta = PFunc::BeamBetatronWavenumber(gamma,n0);
  Double_t rms0  = pData->GetBeamRmsY() * kp;
  if(CYL)  rms0  = pData->GetBeamRmsR() * kp;
  
  cout << Form(" - Bunch gamma      = %8.4f", gamma ) << endl;
  cout << Form(" - Bunch velocity   = %8.4f c", vbeam ) << endl;
  cout << Form(" - Bunch betatron k = %8.4f mm-1", kbeta * PUnits::mm) << endl;
  cout << Form(" - Bunch RMS_0      = %8.4f um", rms0 * skindepth / PUnits::um) << endl;
  cout << endl;

  // 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;
  
  if(opt.Contains("center")) {
    Time -= zStartPlasma;
    if(opt.Contains("comov"))      // Centers on the head of the beam.
      Time += zStartBeam;
  }
  
  // Get charge density histos
  Int_t Nspecies = pData->NSpecies();
  TH1F **hDen1D = new TH1F*[Nspecies];
  TH2F *hDen2D = NULL;
  for(Int_t i=0;i<Nspecies;i++) {
    hDen1D[i] = NULL;
    
    if(!pData->GetChargeFileName(i)) 
      continue;
    
    if(i==0) {
      if(ThreeD)
	hDen2D = pData->GetCharge2DSliceZY(i,-1,Nbins);
      else
	hDen2D = pData->GetCharge(i,opt);
      
      char hName[24];
      sprintf(hName,"hDen_%i",i);
      hDen2D->SetName(hName);
      hDen2D->GetXaxis()->CenterTitle();
      hDen2D->GetYaxis()->CenterTitle();
      hDen2D->GetZaxis()->CenterTitle();
      hDen2D->GetXaxis()->SetTitle("z [c/#omega_{p}]");
      hDen2D->GetYaxis()->SetTitle("y [c/#omega_{p}]");
      if(i==0)
	hDen2D->GetZaxis()->SetTitle("#LTn_{e}#GT [n_{0}]");
      else
	hDen2D->GetZaxis()->SetTitle("#LTn_{b}#GT [n_{0}]");
    }
    
    if(Nbins==0) {
      Nbins = TMath::Nint(rms0 / hDen2D->GetYaxis()->GetBinWidth(1)) ;
      // cout << Form(" Rms0 = %6.2f  Dx = %6.2f  Nbins = %4i .", 
      // 	   rms0, hDen2D[i]->GetYaxis()->GetBinWidth(1), Nbins) << endl;
    }
    
    // 1D histograms
    TString opth1 = opt;
    opth1 += "avg";
    if(CYL) opth1 += "cyl";
    
    if(ThreeD) {
      hDen1D[i] = pData->GetH1SliceZ3D(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,-1,Nbins);
    } else if(CYL) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).
      hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",1,Nbins,opth1.Data());
    } else {         // 2D cartesian
      hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,opth1.Data());
    }
    
    char hName[24];
    sprintf(hName,"hDen_%i",i);
    hDen1D[i]->SetName(hName);
    hDen1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
    hDen1D[i]->GetYaxis()->SetTitle("#LTn_{e}#GT [n_{0}]");
    
  }
  
  // Get electric fields
  const Int_t Nfields = 2;
  TH1F **hE1D = new TH1F*[Nfields];
  for(Int_t i=0;i<Nfields;i++) {
    hE1D[i] = NULL;
    
    if(!pData->GetEfieldFileName(i)) 
      continue;

    // 1D histograms
    TString opth1 = opt;
    opth1 += "avg";
    if(CYL) opth1 += "cyl";
    
    char nam[3]; sprintf(nam,"e%i",i+1);
    if(ThreeD) {
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins);
      else  
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins);
    } else if(CYL) { // Cylindrical: The firt bin with r>0 is actually the number 1 (not the 0).
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data());
      else
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data());
    } else {         // 2D cartesian
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opth1.Data());
      else 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opth1.Data());
    }
    
    
    char hName[24];
    sprintf(hName,"hE_%i",i);
    hE1D[i]->SetName(hName);
    hE1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
    hE1D[i]->GetYaxis()->SetTitle("E [E_{e}]");
  }
  
  // Y range:
  Int_t NbinsY  = (Int_t) hDen2D->GetNbinsY();
  Int_t midyBin = NbinsY/2;
  if(!CYL && (Nbins >  midyBin) ) Nbins = midyBin;
  if(CYL  && (Nbins >= NbinsY ) ) Nbins = NbinsY-1;
  
  Int_t FirstyBin = midyBin + 1 - Nbins;
  Int_t LastyBin  = midyBin + Nbins;
  if(CYL) {
    FirstyBin = 1; 
    LastyBin  = Nbins;
  }
  
  if(LastyBin>=NbinsY) LastyBin = NbinsY - 1;
  Float_t ymin = hDen2D->GetYaxis()->GetBinLowEdge(FirstyBin);
  Float_t ymax = hDen2D->GetYaxis()->GetBinLowEdge(LastyBin+1);

  cout << Form(" Nbins = %i. Firstbin = %i Lastbin = %i  ->  ymin = %7.2f , ymax = %7.2f",Nbins,FirstyBin,LastyBin,ymin,ymax) << endl;
  // ----

  // Tunning the Histograms
  // ---------------------

  // Chaning to user units: 

  // cout << Form(" n0 = %10e ", n0 * PUnits::cm3) << endl;
  
  if(opt.Contains("units") && n0) {
    
    Int_t NbinsX = hDen2D->GetNbinsX();
    Float_t xMin = skindepth * hDen2D->GetXaxis()->GetXmin() / PUnits::mm;
    Float_t xMax = skindepth * hDen2D->GetXaxis()->GetXmax() / PUnits::mm;
    Int_t NbinsY = hDen2D->GetNbinsY();
    Float_t yMin = skindepth * hDen2D->GetYaxis()->GetXmin() / PUnits::mm;
    Float_t yMax = skindepth * hDen2D->GetYaxis()->GetXmax() / PUnits::mm;
    hDen2D->SetBins(NbinsX,xMin,xMax,NbinsY,yMin,yMax);
    for(Int_t j=0;j<hDen2D->GetNbinsX();j++) {
      for(Int_t k=0;k<hDen2D->GetNbinsY();k++) {
	hDen2D->SetBinContent(j,k, hDen2D->GetBinContent(j,k) * n0 / (1e15/PUnits::cm3) );
      }
    }
    
    hDen2D->GetYaxis()->SetTitle("y [mm]");      
    if(opt.Contains("comov"))
      hDen2D->GetXaxis()->SetTitle("#zeta [mm]");
    else
      hDen2D->GetXaxis()->SetTitle("z [mm]");
    
    hDen2D->GetZaxis()->SetTitle("#LTn_{b}#GT [10^{15}/cm^{3}]"); 
  
    
    for(Int_t i=0;i<Nspecies;i++) {
    
      Int_t NbinsX = hDen1D[i]->GetNbinsX();
      Float_t xMin = skindepth * hDen1D[i]->GetXaxis()->GetXmin() / PUnits::mm;
      Float_t xMax = skindepth * hDen1D[i]->GetXaxis()->GetXmax() / PUnits::mm;
      hDen1D[i]->SetBins(NbinsX,xMin,xMax);
      for(Int_t j=0;j<hDen1D[i]->GetNbinsX();j++) {
	Float_t bincontent = (hDen1D[i]->GetBinContent(j) * n0 / (1e15/PUnits::cm3));
	hDen1D[i]->SetBinContent(j,bincontent);
      }
      
      hDen1D[i]->GetYaxis()->SetTitle("#LTn_{e}#GT [10^{15}/cm^{3}]");
      
      if(opt.Contains("comov"))
	hDen1D[i]->GetXaxis()->SetTitle("#zeta [mm]");
      else
	hDen1D[i]->GetXaxis()->SetTitle("z [mm]");
    
    }


    for(Int_t i=0;i<Nfields;i++) {
      Int_t NbinsX = hE1D[i]->GetNbinsX();
      Float_t xMin = skindepth * hE1D[i]->GetXaxis()->GetXmin() / PUnits::mm;
      Float_t xMax = skindepth * hE1D[i]->GetXaxis()->GetXmax() / PUnits::mm;
      hE1D[i]->SetBins(NbinsX,xMin,xMax);
      
      for(Int_t j=0;j<hE1D[i]->GetNbinsX();j++) {
	hE1D[i]->SetBinContent(j, hE1D[i]->GetBinContent(j) * ( E0 / (PUnits::GV/PUnits::m) ) );
      }
      
      hE1D[i]->GetYaxis()->SetTitle("E [GV/m]");
      
      if(opt.Contains("comov"))
	hE1D[i]->GetXaxis()->SetTitle("#zeta [mm]");
      else
	hE1D[i]->GetXaxis()->SetTitle("z [mm]");
    }
  }
  
  // Set the range of the histogram for maximum constrast
  Float_t density = 1;
  if(opt.Contains("units") && n0)
    density = 1e-15 * 1e-6 * n0;
  
  Float_t Max  = 1.1*hDen1D[0]->GetMaximum();
  Float_t Min  = 0;
  // Float_t Base = density;
  // Float_t Min  = 2.* Base - Max;
  // if(Max >= 2. * Base) {
  //   Max = 2. * Base;
  //   Min = 2. * Base  - Max;
  // } else if(Max<1.0 * Base) {
  //   Max = 1.1 * Base;
  //   Min = 0.;
  // }
 
  hDen1D[0]->GetYaxis()->SetRangeUser(0.,Max);  
  
  // Plotting
  // -----------------------------------------------

  // Canvas setup
  TCanvas *C = new TCanvas("C","Charge density and Electric field on axis",850,500);

  TPaveText *textTime = new TPaveText(0.63,0.87,0.78,0.92,"NDC");
  PlasmaGlob::SetPaveTextStyle(textTime); 
  textTime->SetTextColor(kGray+2);
  char ctext[128];

  if(opt.Contains("units") && n0) 
    sprintf(ctext,"Z = %5.1f mm", 1e3 * skindepth * Time);
  else
    sprintf(ctext,"T = %5.1f 1/#omega_{p}",Time);
  textTime->AddText(ctext);

  
  TPaveText *textRange = new TPaveText(0.13,0.87,0.38,0.92,"NDC");
  PlasmaGlob::SetPaveTextStyle(textRange,12); 
  textRange->SetTextColor(kGray+2);
  if(opt.Contains("units") && n0)
    sprintf(ctext,"%5.3f < y < %5.3f mm",ymin,ymax);
  else
    sprintf(ctext,"%5.3f < y < %5.3f c/#omega_{p}",ymin,ymax);
  textRange->AddText(ctext);

  // Actual Plotting!
  // ------------------------------------------------------------

  // Output file
  TString fOutName = Form("./%s/Plots/Density1D/Density1D",sim.Data());
  fOutName += Form("-%s_%i",sim.Data(),time);

  // Colors
  Int_t plasmaC = kGray+1;
  Int_t beamC   = kAzure-5;
  Int_t fieldC  = kOrange+10;
  Int_t fieldCb = kGray+1;

  C->cd(0);
  gPad->SetFrameLineWidth(2);  

  hDen1D[0]->SetLineColor(plasmaC);
  hDen1D[0]->SetLineWidth(1);
  hDen1D[0]->Draw("C");
  hDen1D[0]->GetYaxis()->CenterTitle();
  hDen1D[0]->GetXaxis()->CenterTitle();
  
  C->Update();

  TLine *line0 = new TLine(hDen1D[0]->GetXaxis()->GetXmin(),
			  (gPad->GetUymin()+gPad->GetUymax())/2.,
			  hDen1D[0]->GetXaxis()->GetXmax(),
			  (gPad->GetUymin()+gPad->GetUymax())/2.);
  line0->SetLineColor(kGray+1);
  line0->SetLineStyle(2);
  line0->Draw();

  Float_t rightmax = 2.5 * hDen1D[1]->GetMaximum();
  Float_t slope = (gPad->GetUymax() - gPad->GetUymin())/rightmax;

  for(Int_t i=0;i<hDen1D[1]->GetNbinsX();i++) {
    hDen1D[1]->SetBinContent(i+1,hDen1D[1]->GetBinContent(i+1)*slope + Min);
  }

  hDen1D[1]->SetLineWidth(2);
  hDen1D[1]->SetLineColor(beamC);
  hDen1D[1]->Draw("same C");
  // hTest->Draw("same");
 
  //draw an axis on the right side
  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(),
			    gPad->GetUymax(),0,rightmax,505,"+L");
  
  axis->SetLineWidth(1);
  axis->SetLineColor(beamC);
  axis->SetLabelColor(beamC);
  if(opt.Contains("units") && n0) 
    axis->SetTitle("#LTn_{b}#GT [10^{15}/cm^{3}]");
  else
    axis->SetTitle("#LTn_{b}#GT [n_{0}]");
  axis->CenterTitle();
  axis->SetTitleColor(beamC);
  axis->SetTitleOffset(1.2);
  
  axis->Draw();

  // Longitudinal Electric field
  Float_t factor = 1.5;
  Float_t rightmin = factor * hE1D[0]->GetMinimum();
  rightmax = factor * hE1D[0]->GetMaximum();
  if(hE1D[1]) {
    if(hE1D[1]->GetMaximum() > hE1D[0]->GetMaximum())
      rightmax = factor * hE1D[1]->GetMaximum();
  }
  
  if(rightmax > TMath::Abs(rightmin)) rightmin = -rightmax;
  else rightmax = - rightmin;
  slope = (gPad->GetUymax() - gPad->GetUymin())/(rightmax-rightmin);
  
  for(Int_t i=0;i<hE1D[0]->GetNbinsX();i++) {
    hE1D[0]->SetBinContent(i+1,(hE1D[0]->GetBinContent(i+1)-rightmin)*slope + Min);
  }
  
  hE1D[0]->SetLineStyle(1);
  hE1D[0]->SetLineWidth(2);
  hE1D[0]->SetLineColor(fieldC);
  hE1D[0]->Draw("same C");

  // Transverse field
  for(Int_t i=0;i<hE1D[1]->GetNbinsX();i++) {
    hE1D[1]->SetBinContent(i+1,(hE1D[1]->GetBinContent(i+1)-rightmin)*slope + Min);
  }
  
  hE1D[1]->SetLineStyle(2);
  hE1D[1]->SetLineWidth(1);
  hE1D[1]->SetLineColor(fieldC);
  hE1D[1]->Draw("same C");

  //draw an axis on the right side
  Float_t rightmargin = 0.08;
  Float_t ux = gPad->PixeltoX(gPad->UtoPixel(1-rightmargin));
  TGaxis *axisE = new TGaxis(ux,gPad->GetUymin(),ux,
			     gPad->GetUymax(),rightmin,rightmax,505,"+L");
  
  axisE->SetLineWidth(1);
  axisE->SetLineColor(fieldC);
  axisE->SetLabelColor(fieldC);
  axisE->SetTitleColor(fieldC);
  if(opt.Contains("units") && n0) 
    axisE->SetTitle("E [GV/m]");
  else
    axisE->SetTitle("E [E_{0}]");
  axisE->CenterTitle();
  axisE->SetTitleOffset(0.8);

  axisE->Draw();
  
  textTime->Draw();

  textRange->Draw();

  C->cd();

  // Print to a file
  PlasmaGlob::imgconv(C,fOutName,opt);
  // ---------------------------------------------------------
}
Example #14
0
 void drawintlen_DBD(char* FILEN) {

   //char* title = "Material budget for ILD_O1_v05" ;


   double M_PI = 3.14159265358979312e+00 ;
   //   180./pi = 57.295779 ;
   
   //ntuple variables
   //   float theta, nrvxd, nrsit, nrtpc, nrset, thedeg;
   //   float theta, nlyoke,nlcoil,nlhcal,nlecal,nlset
   Float_t thedeg,theta,eta,nlset,nlecal,nlhcal,nlcoil,nlyoke ; 

   // stuff for histograms
   const int nhist = 5;
   TString htitle[nhist];
   htitle[0] = "Ecal (Lcal)";
   htitle[1] = "Hcal (LHcal/bcal)";
   htitle[2] = "Coil";
   htitle[3] = "";
   htitle[4] = "dummy";
   TString hname[nhist];
   hname[0] = "ECAL";
   hname[1] = "HCAL";
   hname[2] = "SIT";
   hname[3] = "VTX";
   hname[4] = "dummy";

   int nbin = 180;
   float xmin = -90;
   float xmax = -0;
   //   int color[nhist] = {9,8,2,38,1};
   int color[nhist] = {8,2,38,1,9};
   TString option[nhist];

   option[0] = "same";
   option[1] = "same";
   option[2] = "";
   option[3] = "";
   option[4] = "";
      
   //  TLegend *leg = new TLegend (0.25, 0.6, 0.5, 0.85);
  TLegend *leg = new TLegend (0.25, 0.3, 0.6, 0.55);
  leg->SetFillStyle(0);
  
  // stuff for histograms
  TH1F* hmat[nhist];

  for (int ihist = 0; ihist < nhist; ihist++) {

    hmat[ihist] = new TH1F(hname[ihist],"",nbin,xmin,xmax);
    //// ensure proper errors
    // hmat[ihist]->Sumw2();
    hmat[ihist]->SetLineColor(color[ihist]);
    hmat[ihist]->SetLineWidth(3);
    hmat[ihist]->SetTitle(";#theta / degrees;Interaction Lengths");
  }
  
  
  // read tree
  TFile* file = new TFile ( FILEN ) ;
  TTree* tree = (TTree *) file->Get("ntuple");
  if (!tree) {
    cout << "ERROR: Couldn't open tree ntuple on file: "<< FILEN << endl;
    return 1; 
  }
  
  tree->SetBranchAddress("theta", &theta);
  tree->SetBranchAddress("thedeg",&thedeg);
  tree->SetBranchAddress("nlset", &nlset);
  tree->SetBranchAddress("nlecal", &nlecal);
  tree->SetBranchAddress("nlhcal", &nlhcal);
  tree->SetBranchAddress("nlcoil", &nlcoil);
  tree->SetBranchAddress("nlyoke", &nlyoke);
  int entries = tree->GetEntries();
    cout << "tree has " << entries << " entries" << endl;
  
  // event loop
  for (int ievt = 0; ievt < entries; ++ievt) {
     tree->GetEntry(ievt);

     //,     if (thedeg < 4.41) continue;  // ???

     hmat[0]->Fill(-thedeg,nlecal);
     hmat[1]->Fill(-thedeg,nlhcal);
     hmat[2]->Fill(-thedeg,nlcoil);
     hmat[3]->Fill(-thedeg,nlyoke);
     hmat[4]->Fill(-thedeg,1);
  }
  
  //   for (int ibin = 0; ibin < nbin+1; ++ibin) {
  //     cout << "Bin " << ibin << " has " << hmat[4]->GetBinContent(ibin) << " entries" << endl;
//   }
  
  c1 = new TCanvas("c1","c1",600,600);
  
  
  hmat[2]->GetYaxis()->SetRangeUser(0.,14.) ;

  //  for (int ihist = 0; ihist < nhist-2; ihist++) {
  for (int ihist = nhist-3 ; ihist >=0 ; --ihist) {
    // average double counts 
    hmat[ihist]->Divide( hmat[4] ) ;
    // draw 

    hmat[ihist]->Draw(option[ihist]);


    if( ihist ==  nhist-3 ){
      c1->Update() ;
      TF1 *f1 = new TF1("f1","-x",0,90);
      hmat[ihist]->GetXaxis()->SetLabelOffset(99);
      Double_t x_min = c1->GetUxmin();
      Double_t x_max = c1->GetUxmax();
      Double_t y_min = c1->GetUymin();
      //std::cout << "x_min " << x_min << " x_max " << x_max << " y_min " << y_min << std::endl ;
      TGaxis *axis = new TGaxis( x_min, y_min, x_max, y_min, "f1", 5);    
      axis->SetLabelSize( 0.06 );
      axis->SetLabelFont( 42 ); 
      axis->Draw(); 
    }

    leg->AddEntry(hmat[ihist],htitle[ihist],"L");
  }
  leg->Draw();
  

  std::string pdfFile( std::string( FILEN ) + std::string( ".pdf" ) ) ;
  c1->Print( pdfFile.c_str() ) ;
  
}
Example #15
0
void plot_figure(TString fn,TPad *thePad,bool saxis=false,float ymin=1.0e-10,float ymax=1.0e-02,bool with_d=false) {
//cout<<"wit"<<with_d<<endl;

gStyle->SetOptFit();
gStyle->SetPadTickY(1);
//gStyle->SetLogY();

gStyle->SetLineStyleString(11,"40 20");
float xmin=0,xmax=4;

thePad->cd();
thePad->SetLogy();
//thePad->SetGrid();

/*****************************************************
 Colors
*****************************************************/
int HRMcol=kRed+2;
int RNAcol=kMagenta;
int QGScol=kGreen+1;

Double_t x,y;
/*****************************************************
 Format the pad
*****************************************************/

thePad->SetTopMargin(0.15);
TH1F *hr = thePad->DrawFrame(xmin,ymin,xmax,ymax);
hr->SetXTitle("Q^{2} (GeV^{2})");
hr->SetYTitle("B");
hr->GetYaxis()->SetTitleOffset(1.5);
hr->GetYaxis()->SetTitleSize(.06);
hr->GetYaxis()->SetTitleFont(42);
hr->GetYaxis()->CenterTitle();
hr->GetXaxis()->SetTitleSize(.06);
hr->GetXaxis()->SetTitleFont(42);
/*****************************************************
  Draw legend
*****************************************************/

TLegend *dummylegend=new TLegend();
TLegend *legend=new TLegend(0.66,0.64,0.93,0.84);
legend->SetMargin(0.2);
legend->SetTextFont(72);
legend->SetTextSize(0.035);
legend->SetFillStyle(0);
legend->SetBorderSize(0);
legend->Draw();

TLegend *thlegend=new TLegend(0.33,0.64,0.66,0.84);
thlegend->SetMargin(0.2);
thlegend->SetTextFont(72);
thlegend->SetTextSize(0.035);
thlegend->SetFillStyle(0);
thlegend->SetBorderSize(0);
thlegend->Draw();

thePad->SetLeftMargin(0.19);
/*****************************************************
  Draw top axis
*****************************************************/
float titlex1=0.47, titley1=0.85,titlex2=0.56,titley2=0.95;

if (saxis) {
  titley1=0.72;titley2=0.82;
  TGaxis *axispp = new TGaxis(thePad->GetUxmin(),thePad->GetUymax(),
		 thePad->GetUxmax(),
		 thePad->GetUymax(),
		 xmin/0.1973**2,
		 xmax/0.1973**2,510,"-R");
  axispp->SetTitle("Q^{2} (fm^{-2})");
  axispp->SetLabelFont(42);
  axispp->SetLabelSize(0.04);
  axispp->SetTitleFont(42);
  axispp->SetTitleSize(.055);
  axispp->Draw();
}
/*****************************************************
    Make Title
*****************************************************/
//TPaveLabel *label = new TPaveLabel(titlex1,titley1,titlex2,titley2,"^{3}He(#gamma,pp)n","NDC");
//label->SetTextSize(0.7);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
//TPaveLabel *label = new TPaveLabel(titlex1,titley1-0.06,titlex2,titley2-0.06,"90#circc.m.","NDC");
//label->SetTextSize(0.5);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
/*--------------------------------------------------------------------------------------
    Constants?
---------------------------------------------------------------------------------------*/
  Double_t xmd = 1.875613;
  Double_t xmdsq = xmd*xmd;
  Double_t q0sq = 1.15;
  Double_t degr = 0.01745329252;
  Double_t xhbarc = 0.1973;

/*--------------------------------------------------------------------------------------
    Plot IMII modelfor B
 ---------------------------------------------------------------------------------------*/
  const Int_t npt = 95;
  //Double_t x, y;
  Double_t qfm[npt];
  Double_t qsqpt[npt] = {  0.0000,  0.0004,  0.0039,  0.0389,  0.0584,  0.0779,  0.0973,  0.1168,  0.1363,  0.1558, 
			   0.1752,  0.1947,  0.2531,  0.3115,  0.3894,  0.4673,  0.5451,  0.6230,  0.7009,  0.7788, 
			   0.8566,  0.9345,  1.0124,  1.0903,  1.1681,  1.2460,  1.3239,  1.4018,  1.4796,  1.5575, 
			   1.5965,  1.6354,  1.6743,  1.7133,  1.7522,  1.8106,  1.8301,  1.8690,  1.9080,  1.9469, 
			   1.9858,  2.0248,  2.0637,  2.1026,  2.1416,  2.1805,  2.2195,  2.2584,  2.2973,  2.3363, 
			   2.3752,  2.4142,  2.4531,  2.4920,  2.5310,  2.5699,  2.6088,  2.6478,  2.6867,  2.7257, 
			   2.8035,  2.8814,  2.9593,  3.0372,  3.1150,  3.3097,  3.5044,  3.6991,  3.8938,  4.0885, 
			   4.2832,  4.4779,  4.6726,  4.8672,  5.0619,  5.2566,  5.4513,  5.6460,  5.8407,  6.0354, 
			   6.2301,  6.4248,  6.6195,  6.7168,  6.8141,  6.9115,  7.0088,  7.1062,  7.2035,  7.3009, 
			   7.3982,  7.4956,  7.5929,  7.6902,  7.7876};
  Double_t atheory[npt]   = { 1.0710E-05,  1.0574E-04,  9.3420E-04,  3.5050E-03,  3.4115E-03, 
			      3.0845E-03,  2.6987E-03,  2.3221E-03,  1.9803E-03,  1.6807E-03, 
			      1.4229E-03,  1.2034E-03,  7.2925E-04,  4.4651E-04,  2.3739E-04, 
			      1.2959E-04,  7.2494E-05,  4.1431E-05,  2.4107E-05,  1.4229E-05, 
			      8.4877E-06,  5.0970E-06,  3.0687E-06,  1.8439E-06,  1.0999E-06, 
			      6.4724E-07,  3.7264E-07,  2.0753E-07,  1.0994E-07,  5.3905E-08, 
			      3.6143E-08,  2.3248E-08,  1.4106E-08,  7.8561E-09,  3.8096E-09, 
			      7.1157E-10,  2.6517E-10,  7.6047E-12,  3.8643E-10,  1.1987E-09, 
			      2.2880E-09,  3.5354E-09,  4.8498E-09,  6.1665E-09,  7.4371E-09, 
			      8.6270E-09,  9.7149E-09,  1.0688E-08,  1.1537E-08,  1.2263E-08, 
			      1.2867E-08,  1.3352E-08,  1.3726E-08,  1.3996E-08,  1.4171E-08, 
			      1.4259E-08,  1.4270E-08,  1.4209E-08,  1.4089E-08,  1.3914E-08, 
			      1.3434E-08,  1.2822E-08,  1.2120E-08,  1.1364E-08,  1.0584E-08, 
			      8.6526E-09,  6.8980E-09,  5.4000E-09,  4.1725E-09,  3.1908E-09, 
			      2.4208E-09,  1.8250E-09,  1.3673E-09,  1.0200E-09,  7.5739E-10, 
			      5.5948E-10,  4.1182E-10,  3.0194E-10,  2.2009E-10,  1.5958E-10, 
			      1.1516E-10,  8.2658E-11,  5.8806E-11,  4.9418E-11,  4.1436E-11, 
			      3.4661E-11,  2.8921E-11,  2.4066E-11,  1.9968E-11,  1.6516E-11, 
			      1.3608E-11,  1.1156E-11,  9.0935E-12,  7.3668E-12,  5.9294E-12};
//TGraph* gQGS=new TGraph("log170_89.dat","%lg %lg");
  gQGS = new TGraph(npt,qsqpt,atheory);
  gQGS->SetLineColor(kMagenta);
  gQGS->SetMarkerStyle(20);
  gQGS->SetMarkerSize(1.3);
  gQGS->SetLineStyle(11);
  gQGS->SetLineWidth(2);
  //TPaveLabel * Label = new TPaveLabel(0.74,0.24,0.84,0.30,"IMII","NDC");
  //Label->SetTextSize(0.6);
  //Label->SetLineColor(kWhite);
  //Label->SetFillColor(kWhite);
  //Label->SetTextColor(kMagenta);
  //Label->SetBorderSize(0);
  //Label->Draw();
gQGS->Draw("l");
thlegend->AddEntry(gQGS,"IMII","L");
/*--------------------------------------------------------------------------------------
    Plot IMII+ME modelfor B
 ---------------------------------------------------------------------------------------*/
  Double_t atheoryme[npt] =   { 1.0806E-05,  1.0669E-04,  9.4299E-04,  3.5533E-03,  3.4668E-03, 
				3.1422E-03,  2.7561E-03,  2.3777E-03,  2.0331E-03,  1.7302E-03, 
				1.4689E-03,  1.2459E-03,  7.6183E-04,  4.7094E-04,  2.5382E-04, 
				1.4061E-04,  7.9917E-05,  4.6454E-05,  2.7523E-05,  1.6562E-05, 
				1.0086E-05,  6.1936E-06,  3.8206E-06,  2.3582E-06,  1.4498E-06, 
				8.8327E-07,  5.2973E-07,  3.1019E-07,  1.7528E-07,  9.3887E-08, 
				6.6801E-08,  4.6325E-08,  3.1059E-08,  1.9921E-08,  1.1991E-08, 
				4.6073E-09,  3.0706E-09,  1.0502E-09,  1.3882E-10,  4.4654E-11, 
				5.3635E-10,  1.4329E-09,  2.5922E-09,  3.9043E-09,  5.2841E-09, 
				6.6632E-09,  8.0019E-09,  9.2634E-09,  1.0425E-08,  1.1476E-08, 
				1.2409E-08,  1.3215E-08,  1.3893E-08,  1.4448E-08,  1.4882E-08, 
				1.5208E-08,  1.5432E-08,  1.5567E-08,  1.5619E-08,  1.5596E-08, 
				1.5350E-08,  1.4883E-08,  1.4254E-08,  1.3528E-08,  1.2744E-08, 
				1.0662E-08,  8.6328E-09,  6.8749E-09,  5.3894E-09,  4.1719E-09, 
				3.2238E-09,  2.4857E-09,  1.9002E-09,  1.4523E-09,  1.1197E-09, 
				8.7045E-10,  6.7932E-10,  5.3066E-10,  4.1792E-10,  3.3449E-10, 
				2.7250E-10,  2.2493E-10,  1.8672E-10,  1.7020E-10,  1.5532E-10, 
				1.4219E-10,  1.3070E-10,  1.2068E-10,  1.1198E-10,  1.0447E-10, 
				9.8023E-11,  9.2442E-11,  8.7575E-11,  8.3244E-11,  7.9331E-11};
TGraph* gRNA=new TGraph(npt,qsqpt,atheoryme);
gRNA->SetLineColor(kRed);
gRNA->SetMarkerStyle(1);
gRNA->SetMarkerSize(1.3);
gRNA->SetLineStyle(11);
gRNA->SetLineWidth(3);

//TPaveLabel * Label = new TPaveLabel(0.72,0.34,0.89,0.40,"IM+E II","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(kRed);
//Label->SetBorderSize(0);
//Label->Draw();
gRNA->Draw("l");
thlegend->AddEntry(gRNA,"IM+E II","L");
/*--------------------------------------------------------------------------------------
    Dan Phillips no rpg(f/g=0)
 ---------------------------------------------------------------------------------------*/
 const Int_t nph = 66;
 Double_t qph[nph] = {      0.0,    0.2,    0.5,    0.8,    1.0,    1.5,    2.0,    2.5,    3.0,    4.0, 
			    5.0,    6.0,    7.0,    8.0,    9.0,   10.0,   11.0,   12.0,   13.0,   14.0, 
			   15.0,   16.0,   17.0,   18.0,   19.0,   20.0,   21.0,   22.0,   23.0,   24.0, 
			   25.0,   26.0,   27.0,   28.0,   29.0,   30.0,   31.0,   32.0,   33.0,   34.0, 
			   35.0,   36.0,   37.0,   38.0,   39.0,   40.0,   41.0,   42.0,   43.0,   44.0, 
			   45.0,   47.5,   50.0,   52.5,   55.0,   57.5,   60.0,   62.5,   65.0,   70.0, 
			   75.0,   80.0,   85.0,   90.0,   95.0,  100.0};
 for (Int_t i=0;i<nph;i++) {qph[i] = qph[i]*xhbarc**2;}
 Double_t tphrpg0[nph] = { 1.0947E-04,  1.9851E-03,  2.9335E-03,  3.3468E-03,  3.4916E-03, 
			   3.4072E-03,  3.1031E-03,  2.7207E-03,  2.3330E-03,  1.6663E-03, 
			   1.1822E-03,  8.4372E-04,  6.0546E-04,  4.3536E-04,  3.1518E-04, 
			   2.3030E-04,  1.6981E-04,  1.2638E-04,  9.4826E-05,  7.1682E-05, 
			   5.4533E-05,  4.1635E-05,  3.1895E-05,  2.4516E-05,  1.8919E-05, 
			   1.4661E-05,  1.1401E-05,  8.8907E-06,  6.9517E-06,  5.4487E-06, 
			   4.2756E-06,  3.3572E-06,  2.6366E-06,  2.0698E-06,  1.6242E-06, 
			   1.2738E-06,  9.9798E-07,  7.9339E-07,  6.2007E-07,  4.8291E-07, 
			   3.7446E-07,  2.8884E-07,  2.2138E-07,  1.6846E-07,  1.2710E-07, 
			   9.4863E-08,  6.9878E-08,  5.0644E-08,  3.5914E-08,  2.4760E-08, 
			   1.6446E-08,  7.0652E-09,  1.2173E-09,  7.6159E-12,  9.6591E-10, 
			   2.6954E-09,  4.5038E-09,  6.0939E-09,  7.3450E-09,  6.3859E-09, 
			   6.7640E-09,  6.3279E-09,  5.5286E-09,  4.5850E-09,  3.6182E-09, 
			   2.7204E-09};

TGraph* gph=new TGraph(nph,qph,tphrpg0);
gph->SetLineColor(9);
gph->SetMarkerStyle(1);
gph->SetMarkerSize(1.3);
gph->SetLineStyle(1);
gph->SetLineWidth(3);

//TPaveLabel * Label = new TPaveLabel(0.545,0.16,0.755,0.22,"#rho#pi#gamma f/g=0","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(9);
//Label->SetBorderSize(0);
//Label->Draw();
gph->Draw("l");
thlegend->AddEntry(gph,"#rho#pi#gamma f/g=0","L");

 Double_t tphrpg3[nph] = {1.0907E-04,  1.9766E-03,  2.9192E-03,  3.3286E-03,  3.4707E-03, 
			  3.3824E-03,  3.0769E-03,  2.6944E-03,  2.3073E-03,  1.6423E-03, 
			  1.1612E-03,  8.2554E-04,  5.8989E-04,  4.2211E-04,  3.0392E-04, 
			  2.2073E-04,  1.6165E-04,  1.1941E-04,  8.8865E-05,  6.6570E-05, 
			  5.0141E-05,  3.7859E-05,  2.8647E-05,  2.1720E-05,  1.6508E-05, 
			  1.2580E-05,  9.6042E-06,  7.3376E-06,  5.6085E-06,  4.2865E-06, 
			  3.2703E-06,  2.4882E-06,  1.8860E-06,  1.4224E-06,  1.0665E-06, 
			  7.9418E-07,  5.8638E-07,  4.3319E-07,  3.1260E-07,  2.2158E-07, 
			  1.5352E-07,  1.0325E-07,  6.6740E-08,  4.0856E-08,  2.3101E-08, 
			  1.1490E-08,  4.5140E-09,  9.8979E-10,  3.1737E-13,  8.5748E-10, 
			  3.0274E-09,  9.8315E-09,  1.9608E-08,  2.8845E-08,  3.6378E-08, 
			  4.1832E-08,  4.5388E-08,  4.7378E-08,  4.8091E-08,  4.4323E-08, 
			  4.0773E-08,  3.5870E-08,  3.0742E-08,  2.5819E-08,  2.1278E-08, 
			  1.7241E-08};

 //TGraph* gph3=new TGraph(nph,qph,tphrpg3);
//gph3->SetLineColor(39);
//gph3->SetMarkerStyle(1);
//gph3->SetMarkerSize(1.3);
//gph3->SetLineStyle(2);
//gph3->SetLineWidth(2);

//TPaveLabel * Label = new TPaveLabel(0.60,0.49,0.82,0.55,"Propagator f/g=3","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(39);
//Label->SetBorderSize(0);
//Label->Draw();
//gph3->Draw("l");

 Double_t tphrpg6[nph] = {1.0866E-04,  1.9679E-03,  2.9046E-03,  3.3099E-03,  3.4491E-03, 
			  3.3569E-03,  3.0500E-03,  2.6674E-03,  2.2810E-03,  1.6177E-03, 
			  1.1396E-03,  8.0697E-04,  5.7402E-04,  4.0863E-04,  2.9249E-04, 
			  2.1104E-04,  1.5343E-04,  1.1242E-04,  8.2908E-05,  6.1486E-05, 
			  4.5796E-05,  3.4145E-05,  2.5473E-05,  1.9008E-05,  1.4190E-05, 
			  1.0598E-05,  7.9092E-06,  5.8892E-06,  4.3719E-06,  3.2319E-06, 
			  2.3729E-06,  1.7267E-06,  1.2421E-06,  8.8052E-07,  6.1299E-07, 
			  4.1706E-07,  2.7536E-07,  1.7461E-07,  1.0443E-07,  5.7152E-08, 
			  2.7017E-08,  9.6080E-09,  1.5284E-09,  1.7233E-10,  3.5226E-09, 
			  1.0061E-08,  1.8644E-08,  2.8417E-08,  3.8799E-08,  4.9346E-08, 
			  5.9730E-08,  8.3215E-08,  1.0290E-07,  1.1730E-07,  1.2653E-07, 
			  1.3121E-07,  1.3238E-07,  1.3099E-07,  1.2769E-07,  1.1937E-07, 
			  1.0601E-07,  9.1747E-08,  7.8220E-08,  6.5922E-08,  5.4966E-08, 
			  4.5409E-08};

TGraph* gph6=new TGraph(nph,qph,tphrpg6);
gph6->SetLineColor(49);
gph6->SetMarkerStyle(1);
gph6->SetMarkerSize(1.3);
gph6->SetLineStyle(1);
gph6->SetLineWidth(2);

//TPaveLabel * Label = new TPaveLabel(0.23,0.16,0.45,0.22,"#rho#pi#gamma f/g=6.1","NDC");
//Label->SetTextSize(0.6);
//Label->SetLineColor(kWhite);
//Label->SetFillColor(kWhite);
//Label->SetTextColor(49);
//Label->SetBorderSize(0);
//Label->Draw();
gph6->Draw("l");
thlegend->AddEntry(gph6,"#rho#pi#gamma f/g=6.1","L");

/*  sanity checks
plots11dsdtSet(100,0.040,0.020,0.05,0.000,0.140,kBlack,legend,"E03-101 140 MeV Bins Pn< 100 Mev/c 80 mr X 40 mr");
*/

/*  PRL */
//plotSet(kBlue,legend,"T_{20}");
//plotSet(kBlue,legend,"");
plotSet(kBlue,legend,"");
//plots11dsdtSet(kBlue,legend,"");

/*****************************************************
 Add the rest of the legend enteries
*****************************************************/

//if(!with_d){
//legend->AddEntry(gQGS,"QGS","l");
//legend->AddEntry(gRNA,"RNA","l");
//legend->AddEntry(gHRM,"HRM","F");
//};
gStyle->SetPaperSize(20,26);  //default
//TPaveLabel *label = new TPaveLabel(0.5,0.4,0.85,0.5,"Preliminary","NDC");
//label->SetTextColor(kBlue);
//label->Draw();
//cout<<with_d<<endl;
c->SaveAs(fn+".pdf");
c->SaveAs(fn+".eps");
c->SaveAs(fn+".png");
}
Example #16
0
ExtraAxis anotherScale (const TH1* refHist, double scale, int color, const char* title, double offset) {
  ExtraAxis result;
  double x0 = refHist->GetXaxis()->GetXmin();
  double x1 = refHist->GetXaxis()->GetXmax();
  double y0 = refHist->GetMinimum();
  double y1 = refHist->GetMaximum();
  // double y0 = refHist->GetYaxis()->GetXmin();
  // double y1 = refHist->GetYaxis()->GetXmax();
  double xoffset = exp (log(x0) - (log(x1) - log(x0))*offset);

  TGaxis* axis = new TGaxis(xoffset, y0, xoffset, y1, y0*scale,y1*scale,510,"-GS");
  axis->ImportAxisAttributes (refHist->GetXaxis());
  axis->SetTitle(title);
  axis->SetTextColor (color);
  axis->SetLineColor (color);
  axis->SetLineWidth (1);
  axis->SetTextColor (color);
  axis->SetLabelColor (color);
  axis->SetLabelOffset (0.);
  axis->SetTitleOffset (0.65);
  axis->SetTickSize(0.015);	
  result.Add (axis);

  TLine* line = new TLine (xoffset, y0, xoffset, y1);
  line->SetLineColor (color);
  line->SetLineWidth (2);
  result.Add (line);

  line = new TLine (x0, y0, xoffset, y0);
  line->SetLineColor (kGray);
  line->SetLineWidth (2);
  result.Add (line);
  
  line = new TLine (x0, y1, xoffset, y1);
  line->SetLineColor (kGray);
  line->SetLineWidth (2);
  result.Add (line);

  return result;
}
Example #17
0
int rate(std::string fileName)
{
  setGlobalStyle();
  
  //###############################
  //## run274200 ##
  unsigned int HT250Calo  = 9; //index of DST_HT250_CaloScouting_v   old:1 ref:9
  unsigned int HT410PF = 7; //index of DST_HT410_PFScouting_v   old:3 ref:7
  unsigned int MJJ200Calo = 12; //index of DST_DiCaloWideJetMass200_CaloScouting_v
  
  unsigned int HTT200 = 0; //index if L1_HTT200
  unsigned int HTT240 = 1; //index if L1_HTT240
  unsigned int HTT270 = 2; //index if L1_HTT270
  unsigned int HTT280 = 3; //index if L1_HTT280
  unsigned int DoubleJetC100 = 7; //index if L1_DoubleJetC100
  unsigned int DoubleJetC112 = 8; //index if L1_DoubleJetC112
  unsigned int DoubleIsoTau28er = 11; //index if L1_DoubleJetC112

  float instLumi = 0.71; //E34
  float targetLumi = 1; //E34
  float lumiScaleFactor = targetLumi/instLumi;

  float PDRate = 21986976; //unprescaled rate of ParkingZeroBias accordingly to:  nEv/(nLS*23.3)*hltPresc*l1Presc   [*nPDs?] = 2343149/(824*23,3)*12*15013

  unsigned int L1MjjThr = 150;
  //###############################

  TChain* tt = new TChain("MyAnalysis/HLTree");
  tt->Add(fileName.c_str());

  //set branches
  TBranch* b_lumi;
  
  TBranch* b_caloMjj;
  TBranch* b_PFMjj;
  TBranch* b_caloWMjj;
  TBranch* b_PFWMjj;
  TBranch* b_l1Mjj;

  TBranch* b_hltAccept;
  TBranch* b_l1Accept;
  TBranch* b_l1Names;

  TBranch* b_caloJet1Pt;
  TBranch* b_caloJet2Pt;
  TBranch* b_caloJet1Eta;
  TBranch* b_caloJet2Eta;
  TBranch* b_caloJet1Phi;
  TBranch* b_caloJet2Phi;
  TBranch* b_caloDeltaEta;
  TBranch* b_caloWJet1Pt;
  TBranch* b_caloWJet2Pt;
  TBranch* b_caloWJet1Eta;
  TBranch* b_caloWJet2Eta;
  TBranch* b_caloWJet1Phi;
  TBranch* b_caloWJet2Phi;
  TBranch* b_caloWDeltaEta;

  TBranch* b_PFJet1Pt;
  TBranch* b_PFJet2Pt;
  TBranch* b_PFJet1Eta;
  TBranch* b_PFJet2Eta;
  TBranch* b_PFJet1Phi;
  TBranch* b_PFJet2Phi;
  TBranch* b_PFDeltaEta;
  TBranch* b_PFWJet1Pt;
  TBranch* b_PFWJet2Pt;
  TBranch* b_PFWJet1Eta;
  TBranch* b_PFWJet2Eta;
  TBranch* b_PFWJet1Phi;
  TBranch* b_PFWJet2Phi;
  TBranch* b_PFWDeltaEta;

  TBranch* b_l1Jet1Pt;
  TBranch* b_l1Jet2Pt;
  TBranch* b_l1Jet1Eta;
  TBranch* b_l1Jet2Eta;
  TBranch* b_l1Jet1Phi;
  TBranch* b_l1Jet2Phi;
  TBranch* b_l1DeltaEta;

  TBranch* b_l1JetPt;
  TBranch* b_l1JetEta;
  TBranch* b_l1JetPhi;

  int lumi = 0;
  float caloMjj = 0;
  float PFMjj = 0;
  float caloWMjj = 0;
  float PFWMjj = 0;
  float l1Mjj = 0;

  float caloJet1Pt_ = 0;
  float caloJet2Pt_ = 0;
  float caloJet1Eta_ = -999;
  float caloJet2Eta_ = -999;
  float caloJet1Phi_ = -999;
  float caloJet2Phi_ = -999;
  float caloDeltaEta_ = -999;
  float caloWJet1Pt_ = 0;
  float caloWJet2Pt_ = 0;
  float caloWJet1Eta_ = -999;
  float caloWJet2Eta_ = -999;
  float caloWJet1Phi_ = -999;
  float caloWJet2Phi_ = -999;
  float caloWDeltaEta_ = -999;

  float PFJet1Pt_ = 0;
  float PFJet2Pt_ = 0;
  float PFJet1Eta_ = -999;
  float PFJet2Eta_ = -999;
  float PFJet1Phi_ = -999;
  float PFJet2Phi_ = -999;
  float PFDeltaEta_ = -999;
  float PFWJet1Pt_ = 0;
  float PFWJet2Pt_ = 0;
  float PFWJet1Eta_ = -999;
  float PFWJet2Eta_ = -999;
  float PFWJet1Phi_ = -999;
  float PFWJet2Phi_ = -999;
  float PFWDeltaEta_ = -999;

  float l1Jet1Pt_ = 0;
  float l1Jet2Pt_ = 0;
  float l1Jet1Eta_ = -999;
  float l1Jet2Eta_ = -999;
  float l1Jet1Phi_ = -999;
  float l1Jet2Phi_ = -999;
  float l1DeltaEta_ = -999;

  std::vector<float>* l1JetPt_ = 0;
  std::vector<float>* l1JetEta_ = 0;
  std::vector<float>* l1JetPhi_ = 0;
  
  std::vector<int>* hltAccept = 0;
  std::vector<int>* l1Accept = 0;
  std::vector<string>* l1Names = 0;

  tt->SetBranchAddress("lumi", &lumi, &b_lumi);

  tt->SetBranchAddress("caloMjj", &caloMjj, &b_caloMjj);
  tt->SetBranchAddress("PFMjj", &PFMjj, &b_PFMjj);
  tt->SetBranchAddress("caloWMjj", &caloWMjj, &b_caloWMjj);
  tt->SetBranchAddress("PFWMjj", &PFWMjj, &b_PFWMjj);
  tt->SetBranchAddress("l1Mjj", &l1Mjj, &b_l1Mjj);

  tt->SetBranchAddress("caloJet1Pt", &caloJet1Pt_, &b_caloJet1Pt);
  tt->SetBranchAddress("caloJet2Pt", &caloJet2Pt_, &b_caloJet2Pt);
  tt->SetBranchAddress("caloJet1Eta", &caloJet1Eta_, &b_caloJet1Eta);
  tt->SetBranchAddress("caloJet2Eta", &caloJet2Eta_, &b_caloJet2Eta);
  tt->SetBranchAddress("caloJet1Phi", &caloJet1Phi_, &b_caloJet1Phi);
  tt->SetBranchAddress("caloJet2Phi", &caloJet2Phi_, &b_caloJet2Phi);
  tt->SetBranchAddress("caloDeltaEta", &caloDeltaEta_, &b_caloDeltaEta);
  tt->SetBranchAddress("caloWJet1Pt", &caloWJet1Pt_, &b_caloWJet1Pt);
  tt->SetBranchAddress("caloWJet2Pt", &caloWJet2Pt_, &b_caloWJet2Pt);
  tt->SetBranchAddress("caloWJet1Eta", &caloWJet1Eta_, &b_caloWJet1Eta);
  tt->SetBranchAddress("caloWJet2Eta", &caloWJet2Eta_, &b_caloWJet2Eta);
  tt->SetBranchAddress("caloWJet1Phi", &caloWJet1Phi_, &b_caloWJet1Phi);
  tt->SetBranchAddress("caloWJet2Phi", &caloWJet2Phi_, &b_caloWJet2Phi);
  tt->SetBranchAddress("caloWDeltaEta", &caloWDeltaEta_, &b_caloWDeltaEta);

  tt->SetBranchAddress("PFJet1Pt", &PFJet1Pt_, &b_PFJet1Pt);
  tt->SetBranchAddress("PFJet2Pt", &PFJet2Pt_, &b_PFJet2Pt);
  tt->SetBranchAddress("PFJet1Eta", &PFJet1Eta_, &b_PFJet1Eta);
  tt->SetBranchAddress("PFJet2Eta", &PFJet2Eta_, &b_PFJet2Eta);
  tt->SetBranchAddress("PFJet1Phi", &PFJet1Phi_, &b_PFJet1Phi);
  tt->SetBranchAddress("PFJet2Phi", &PFJet2Phi_, &b_PFJet2Phi);
  tt->SetBranchAddress("PFDeltaEta", &PFDeltaEta_, &b_PFDeltaEta);
  tt->SetBranchAddress("PFWJet1Pt", &PFWJet1Pt_, &b_PFWJet1Pt);
  tt->SetBranchAddress("PFWJet2Pt", &PFWJet2Pt_, &b_PFWJet2Pt);
  tt->SetBranchAddress("PFWJet1Eta", &PFWJet1Eta_, &b_PFWJet1Eta);
  tt->SetBranchAddress("PFWJet2Eta", &PFWJet2Eta_, &b_PFWJet2Eta);
  tt->SetBranchAddress("PFWJet1Phi", &PFWJet1Phi_, &b_PFWJet1Phi);
  tt->SetBranchAddress("PFWJet2Phi", &PFWJet2Phi_, &b_PFWJet2Phi);
  tt->SetBranchAddress("PFWDeltaEta", &PFWDeltaEta_, &b_PFWDeltaEta);

  tt->SetBranchAddress("l1Jet1Pt", &l1Jet1Pt_, &b_l1Jet1Pt);
  tt->SetBranchAddress("l1Jet2Pt", &l1Jet2Pt_, &b_l1Jet2Pt);
  tt->SetBranchAddress("l1Jet1Eta", &l1Jet1Eta_, &b_l1Jet1Eta);
  tt->SetBranchAddress("l1Jet2Eta", &l1Jet2Eta_, &b_l1Jet2Eta);
  tt->SetBranchAddress("l1Jet1Phi", &l1Jet1Phi_, &b_l1Jet1Phi);
  tt->SetBranchAddress("l1Jet2Phi", &l1Jet2Phi_, &b_l1Jet2Phi);
  tt->SetBranchAddress("l1DeltaEta", &l1DeltaEta_, &b_l1DeltaEta);

  tt->SetBranchAddress("l1JetPt", &l1JetPt_, &b_l1JetPt);
  tt->SetBranchAddress("l1JetEta", &l1JetEta_, &b_l1JetEta);
  tt->SetBranchAddress("l1JetPhi", &l1JetPhi_, &b_l1JetPhi);

  tt->SetBranchAddress("hltAccept", &hltAccept, &b_hltAccept);
  tt->SetBranchAddress("l1Accept", &l1Accept, &b_l1Accept);
  tt->SetBranchAddress("l1Names", &l1Names, &b_l1Names);

  int nentries = tt->GetEntries();
  std::cout << "Number of entries: " << nentries << std::endl;
  
  //book graphs and plots
  float min = 0.;
  float max = 1000.;
  int nBins = 20;

  TF1* f1 = new TF1("f1","[0]*TMath::Erf((x-[1])/[2])-[0]*TMath::Erf((-x-[1])/[2])",min,max);
  f1->SetParameters(0.5,350,40);  
  f1->FixParameter(0,0.5);
  f1->SetLineWidth(2.);
  f1->SetLineColor(kRed);

  TF1* f2 = (TF1*)f1->Clone("f2");
  f2->SetParameters(0.5,150,10);
  f2->SetLineColor(kBlack);

  //##############################################
  //##############################################

  //book graphs and plots
  TGraphErrors* totL1RateVsCut = new TGraphErrors();
  totL1RateVsCut->SetMinimum(0);
  TGraphErrors* pureL1RateVsCut = new TGraphErrors();

  TGraphErrors* totHltRateVsCut = new TGraphErrors();
  totHltRateVsCut->SetMinimum(0);
  TGraphErrors* pureHltRateVsCut = new TGraphErrors();

  //loops
  int bin = 0;
  for (int cut = 200; cut < 350; cut=cut+10)
    {
      std::cout << "analyzing point at " << cut << " GeV" << std::endl;

      int mjjHltPassed = 0;
      int excl_mjjHltPassed = 0;

      int mjjL1Passed = 0;
      int excl_mjjL1Passed = 0;

      int HTT240Passed = 0;

      for (Long64_t jentry=0; jentry<nentries;++jentry) 
	{
	  tt->GetEntry(jentry);

	  //### Sanity checks ###
	  if (l1Accept->at(HTT240) == 1)
	    ++HTT240Passed;
	  
	  //### L1 ###
	  bool l1Pass = (l1Mjj>cut &&
			 l1Jet1Pt_ > 15. &&
			 l1Jet2Pt_ > 15. &&
			 fabs(l1Jet1Eta_) < 5.0 &&
			 fabs(l1Jet2Eta_) < 5.0 &&
			 l1DeltaEta_ < 2.0
			 );

	  bool L1RefPass = (l1Mjj>L1MjjThr &&
			    l1Jet1Pt_ > 15. &&
			    l1Jet2Pt_ > 15. &&
			    fabs(l1Jet1Eta_) < 5.0 &&
			    fabs(l1Jet2Eta_) < 5.0 &&
			    l1DeltaEta_ < 2.0
			    );


	  // if(l1Pass && l1Accept->at(HTT240) == 0 && caloWMjj < 100 && caloWMjj>0)
	  //   {
	  //     std::cout << std::endl;
	  //     std::cout << std::fixed << std::setprecision(2)
	  // 		<< "l1Mjj-caloWMjj = " << l1Mjj-caloWMjj << " l1Mjj = " << l1Mjj << " caloWMjj = " << caloWMjj << std::endl;
	  //     std::cout << "  caloWJet1Pt_    = " << caloWJet1Pt_     << " caloWJet1Eta_     = " << caloWJet1Eta_     << " caloWJet1Phi_     = " << caloWJet1Phi_ << std::endl;
	  //     std::cout << "  l1Jet1Pt        = " << l1Jet1Pt_        << " l1Jet1Eta         = " << l1Jet1Eta_        << " l1Jet1Phi         = " << l1Jet1Phi_ << std::endl;
	  //     std::cout << std::endl;
	  //     std::cout << "  caloWJet2Pt_     = " << caloWJet2Pt_     << " caloWJet2Eta_     = " << caloWJet2Eta_     << " caloWJet2Phi_     = " << caloWJet2Phi_ << std::endl;
	  //     std::cout << "  l1Jet2Pt         = " << l1Jet2Pt_        << " l1Jet2Eta         = " << l1Jet2Eta_        << " l1Jet2Phi         = " << l1Jet2Phi_ << std::endl;
	  //     std::cout << "==========================================================" << std::endl;
	  //   }
	  

		      
	  if (l1Pass)
	    ++mjjL1Passed;
	  if (l1Pass && l1Accept->at(HTT240) == 0)
	    ++excl_mjjL1Passed;


	  //### HLT ###
	  //Hypothesis of HLT rates with L1Mjj seed at L1MjjThr
	  if (caloWMjj > cut && L1RefPass)
	    ++mjjHltPassed;
	  if (caloWMjj > cut && L1RefPass && hltAccept->at(HT250Calo) == 0)
	    ++excl_mjjHltPassed;


	}
      float HTT240rate = (float)HTT240Passed/(float)nentries*PDRate;
      //std::cout << "HTT240rate = " << HTT240rate << std::endl;
      
      float sigmaNentries = sqrt((float)nentries);

      float sigmaMjjHltPassed = sqrt((float)mjjHltPassed);
      float excl_sigmaMjjHltPassed = sqrt((float)excl_mjjHltPassed);

      float sigmaMjjL1Passed = sqrt((float)mjjL1Passed);
      float excl_sigmaMjjL1Passed = sqrt((float)excl_mjjL1Passed);

      float mjjHltRate = (float)mjjHltPassed/(float)nentries*PDRate;
      float mjjHltRateE = PDRate*sqrt(pow((sigmaMjjHltPassed/nentries),2)+pow((sigmaNentries*mjjHltPassed/nentries/nentries),2));
      float excl_mjjHltRate = (float)excl_mjjHltPassed/(float)nentries*PDRate;
      float excl_mjjHltRateE = PDRate*sqrt(pow((excl_sigmaMjjHltPassed/nentries),2)+pow((sigmaNentries*excl_mjjHltPassed/nentries/nentries),2));

      float mjjL1Rate = (float)mjjL1Passed/(float)nentries*PDRate;
      float mjjL1RateE = PDRate*sqrt(pow((sigmaMjjL1Passed/nentries),2)+pow((sigmaNentries*mjjL1Passed/nentries/nentries),2));
      float excl_mjjL1Rate = (float)excl_mjjL1Passed/(float)nentries*PDRate;
      float excl_mjjL1RateE = PDRate*sqrt(pow((excl_sigmaMjjL1Passed/nentries),2)+pow((sigmaNentries*excl_mjjL1Passed/nentries/nentries),2));

      totHltRateVsCut->SetPoint(bin,cut,mjjHltRate);
      totHltRateVsCut->SetPointError(bin,0.,mjjHltRateE);
      pureHltRateVsCut->SetPoint(bin,cut,excl_mjjHltRate);
      pureHltRateVsCut->SetPointError(bin,0.,excl_mjjHltRateE);

      totL1RateVsCut->SetPoint(bin,cut,mjjL1Rate);
      totL1RateVsCut->SetPointError(bin,0.,mjjL1RateE);
      pureL1RateVsCut->SetPoint(bin,cut,excl_mjjL1Rate);
      pureL1RateVsCut->SetPointError(bin,0.,excl_mjjL1RateE);

      ++bin;
    }

  //plotting and styling
  TLegend* legHlt = new TLegend(0.62, 0.78, 0.83, 0.89);
  legHlt->AddEntry(totHltRateVsCut,"hlt total rate","P");
  legHlt->AddEntry(pureHltRateVsCut,"hlt pure rate wrt HT250","P");

  TLegend* legL1 = new TLegend(0.62, 0.78, 0.83, 0.89);
  legL1->AddEntry(totL1RateVsCut,"l1 total rate","P");
  legL1->AddEntry(pureL1RateVsCut,"l1 pure rate wrt HTT240","P");

  totHltRateVsCut->GetXaxis()->SetTitle("Mjj cut threshold [GeV]");
  totHltRateVsCut->GetYaxis()->SetTitle("Rate @7E33 [Hz]");
  totHltRateVsCut->SetMarkerColor(kRed);
  pureHltRateVsCut->SetMarkerColor(kOrange+1);

  totL1RateVsCut->GetXaxis()->SetTitle("Mjj cut threshold [GeV]");
  totL1RateVsCut->GetYaxis()->SetTitle("Rate @7E33 [Hz]");
  totL1RateVsCut->SetMarkerColor(kBlue);
  totL1RateVsCut->SetMarkerColor(kAzure);

  TCanvas* c4 = new TCanvas();
  c4->cd();
  totHltRateVsCut->Draw("AP");
  pureHltRateVsCut->Draw("P,sames");
  legHlt->Draw("sames");
  c4->Update();
  TGaxis *axisHlt = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
    			    (totHltRateVsCut->GetYaxis()->GetBinLowEdge(1))*lumiScaleFactor,
			    (totHltRateVsCut->GetYaxis()->GetBinLowEdge(totHltRateVsCut->GetYaxis()->GetNbins())+totHltRateVsCut->GetYaxis()->GetBinWidth(1))*lumiScaleFactor,510,"+L");

  c4->SetTicky(0);
  axisHlt->SetLineColor(kRed);
  axisHlt->SetLabelColor(kRed);
  axisHlt->SetTextColor(kRed);
  axisHlt->SetTitleOffset(1.3);
  axisHlt->SetLabelSize(0.03);
  axisHlt->SetTitle("Rate @1E34 [Hz]");
  axisHlt->Draw();
  c4->Print("rates/hltRate.pdf","pdf");


  TCanvas* c5 = new TCanvas();
  c5->cd();
  totL1RateVsCut->Draw("AP");
  pureL1RateVsCut->Draw("P,sames");
  legL1->Draw("sames");
  c5->Update();
  TGaxis *axisL1 = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
			      (totL1RateVsCut->GetYaxis()->GetBinLowEdge(1))*lumiScaleFactor,
			      (totL1RateVsCut->GetYaxis()->GetBinLowEdge(totL1RateVsCut->GetYaxis()->GetNbins())+totL1RateVsCut->GetYaxis()->GetBinWidth(1))*lumiScaleFactor,510,"+L");

  c5->SetTicky(0);
  axisL1->SetLineColor(kRed);
  axisL1->SetLabelColor(kRed);
  axisL1->SetTextColor(kRed);
  axisL1->SetTitleOffset(1.3);
  axisL1->SetLabelSize(0.03);
  axisL1->SetTitle("Rate @1E34 [Hz]");
  axisL1->Draw();
  c5->Print("rates/l1Rate.pdf","pdf");

  return 0;
}
Example #18
0
void  drawPlots(canvasSet_t& cs,bool savePlots2file)
{
  wCanvas_t *wc0 = cs.canvases[0];
  unsigned npads = wc0->npadsx*wc0->npadsy;
  unsigned npadsall = cs.ncanvases*npads;

  if (!npads) {
    if (gl_verbose) cout << "Nothing to draw, guess I'm done." << endl;
    return; // no pads to draw on.

  } else if (!wc0->pads.size()) {

    /********************************************************
     * CHECK MULTIPAD OPTION, ASSIGN HISTOS TO PADS/CANVASES
     ********************************************************/

    if (wc0->multipads.size()) {
      npadsall = assignHistos2Multipad(cs);
    } else {
      cerr << "npads>0, but no pad specs supplied, exiting." << endl;
      return; // no pads to draw on.
    }
  } else if (cs.ncanvases>1) {
    npadsall = assignPads2Canvases(cs);
  } else {
    npadsall = std::min(npadsall,(unsigned)wc0->pads.size());
  }

  wc0->c1->cd();

  if (gl_verbose)
    cout << "Drawing on " << npadsall << " pad(s)" << endl;

  wLegend_t *wleg = NULL;

  /***************************************************
   * LOOP OVER PADS...
   ***************************************************/

  //vector<vector<string> >::const_iterator it;
  for (unsigned ipad = 0; ipad< npadsall; ipad++) {

    if (gl_verbose) cout << "Drawing pad# " << ipad+1 << endl;

    unsigned ipadc =  ipad % npads;
    unsigned cnum  = (ipad / npads) + 1;

    wCanvas_t *wc = cs.canvases[cnum-1];

    if (!ipadc) {
      if (cnum-1) { // first canvas already created
	wc->c1 = new TCanvas(wc->title.c_str(),wc->title.c_str(),
			     wc->padxdim*wc->npadsx,
			     wc->padydim*wc->npadsy);
	float left = wc->leftmargin;
	float bot  = wc->bottommargin;
	float rhgt = 1-wc->rightmargin;
	float top  = 1-wc->topmargin;
	wc->motherpad = new TPad("mother","",left,bot,rhgt,top);
	wc->c1->SetFillColor(wc->fillcolor);
	wc->motherpad->SetFillColor(wc->fillcolor);
	wc->motherpad->Draw();
	wc->motherpad->cd();
	wc->motherpad->Divide(wc->npadsx,wc->npadsy); // , wc->padxmargin,wc->padymargin);
      }

      /***************************************************
       * CHECK FOR LATEX OBJECTS ON THE CANVAS
       ***************************************************/
      
      wc->c1->cd();
      for (unsigned j=0; j<wc->latex_ids.size(); j++) {
	string& lid = wc->latex_ids[j];
	map<string,TLatex *>::const_iterator it = glmap_id2latex.find(lid);
	if (it == glmap_id2latex.end()) {
	  cerr << "ERROR: latex id " << lid << " never defined in layout" << endl;
	  exit (-1);
	}
	TLatex *ltx = it->second;
	ltx->Draw();
	wc->c1->Update();
      }
    }

    wPad_t *& wp = wc->pads[ipadc];
    wp->vp = wc->motherpad->cd(ipadc+1);

    if (!wp->histo_ids.size() &&
	!wp->stack_ids.size() &&
	!wp->graph_ids.size() &&
	!wp->macro_ids.size()) {
      cerr << "ERROR: pad #" << ipadc+1 << " has no ids defined for it";
      cerr << ", continuing to the next" << endl;
      continue;
    }


#if 0
    /***************************************************
     * Draw the frame first:
     * (Fix up frame since it can't be auto-scaled:)
     ***************************************************/
    string& hid0 = wp->histo_ids[0];
    map<string,wTH1 *>::const_iterator it = glmap_id2histo.find(hid0);
    if (it == glmap_id2histo.end()) {
      cerr << "ERROR: id0 " << hid0 << " never defined in layout" << endl;
      return;
    }
    wTH1 *myHisto = it->second;
    TH1  *h = myHisto->histo();

    if (wp->hframe->histo()->GetXaxis()->GetXmin() <=
	wp->hframe->histo()->GetXaxis()->GetXmax())
      wp->hframe->histo()->GetXaxis()->SetRangeUser(h->GetXaxis()->GetXmin(),
						    h->GetXaxis()->GetXmax());
    if (wp->hframe->histo()->GetYaxis()->GetXmin() <= 
	wp->hframe->histo()->GetYaxis()->GetXmax())
      wp->hframe->histo()->GetYaxis()->SetRangeUser(h->GetYaxis()->GetXmin(),
						    h->GetYaxis()->GetXmax());

    wp->hframe->SetStats(0);
    //wp->hframe->Draw("AXIS");
#endif

    /***************************************************
     * Check for external macros to run on the pad
     ***************************************************/
    for (size_t i=0; i<wp->macro_ids.size(); i++) {
      map<string,string>::const_iterator it = glmap_objpath2id.find(wp->macro_ids[i]);
      if (it != glmap_objpath2id.end()) {
	string path = it->second;
	int error;
	gROOT->Macro(path.c_str(), &error, kTRUE); // update current pad
	if (error) {
	  static const char *errorstr[] = {
	    "kNoError","kRecoverable","kDangerous","kFatal","kProcessing" };
	  cerr << "ERROR: error returned from macro: " << errorstr[error] << endl;
	}
      } else {
	cerr << "ERROR: macro id " << wp->macro_ids[i];
	cerr << " never defined in layout" << endl;
      }
    }
    /***************************************************
     * Check for existence of a legend, create it
     ***************************************************/
    bool drawlegend = false;

    if (wp->legid.size()) {
      map<string,wLegend_t *>::const_iterator it=glmap_id2legend.find(wp->legid);
      if (it != glmap_id2legend.end()) {
	drawlegend = true;
	wleg = it->second;
      } else {
	cerr << "ERROR: legend id " << wp->legid;
	cerr << " never defined in layout" << endl;
      }
    } else {
      // Maybe gPad already *has* a legend from macros...
      TPave *testing = (TPave *)gPad->GetPrimitive("TPave");
      if (testing &&
	  !strcmp(testing->IsA()->GetName(),"TLegend")) {
	TLegend *pullTheOtherOne = (TLegend *)testing;
	if (gl_verbose) cout << "Found legend from macro" << endl;
	wleg = new wLegend_t();
	wleg->leg = pullTheOtherOne;
	drawlegend = true;
      }
    }

    /***************************************************
     * LOOP OVER STACKS DEFINED FOR PAD...
     ***************************************************/

    if (wp->stack_ids.size()) {
      wStack_t *ws=NULL;
      for (unsigned j = 0; j < wp->stack_ids.size(); j++) {
	string& sid = wp->stack_ids[j];
	map<string,wStack_t *>::const_iterator it = glmap_id2stack.find(sid);
	if (it == glmap_id2stack.end()) {
	  cerr << "ERROR: stack id " << sid << " never defined in layout" << endl;
	  exit (-1);
	}

	bool firstInPad = !j;

	ws = it->second;
	if (!ws) { cerr<< "find returned NULL stack pointer for " << sid << endl; continue; }

	// Add the histos in the stack to any legend that exists

	//
	if (drawlegend) {
	  for (size_t i=0; i<ws->v_histos.size(); i++) {
	    wTH1 *wh = ws->v_histos[i];
	    wh->ApplySavedStyle();
	    if(wh->GetLegendEntry().size())
	      wh->Add2Legend(wleg->leg);
	  }
	}

	string drawopt("");
	if (ws->sum->GetDrawOption().size()) {
	  drawopt = ws->sum->GetDrawOption();
	  cout << "drawopt stored with histo = " << drawopt << endl;
	}

	drawInPad(wp, ws, firstInPad, drawopt);

	wp->vp->Update();
      }
    } // stack loop

    /***************************************************
     * LOOP OVER HISTOS DEFINED FOR PAD...
     ***************************************************/

    for (unsigned j = 0; j < wp->histo_ids.size(); j++) {
      string& hid = wp->histo_ids[j];
      map<string,wTH1 *>::const_iterator it = glmap_id2histo.find(hid);
      if (it == glmap_id2histo.end()) {
	cerr << "ERROR: histo id " << hid << " never defined in layout" << endl;
	exit (-1);
      }

      wTH1 *myHisto = it->second;
      
      if (myHisto) {
	bool firstInPad = !j && !wp->stack_ids.size();
	if (gl_verbose) {
	  cout << "Drawing " << hid << " => ";
	  cout << myHisto->histo()->GetName() << endl;
	  cout << "firstInPad = " << firstInPad << endl;
	}
	drawInPad(wp,*myHisto,firstInPad);

	myHisto->DrawFits("same");
	if (drawlegend && myHisto->GetLegendEntry().size()) {
	  if (wleg->drawoption.size()) myHisto->SetDrawOption(wleg->drawoption);
	  myHisto->Add2Legend(wleg->leg);
	}
	if (myHisto->statsAreOn()) {
	  myHisto->DrawStats();
	  wp->vp->Update();
	}

	myHisto->ApplySavedStyle();
	wp->vp->Update();
      }
    } // histos loop

    /***************************************************
     * LOOP OVER HISTOS DEFINED FOR ALTERNATE Y-AXIS
     ***************************************************/

    Float_t rightmax=0.0,rightmin=0.0;
    Float_t scale=0.0;
    for (unsigned j = 0; j < wp->altyh_ids.size(); j++) {
      string& hid = wp->altyh_ids[j];
      map<string,wTH1 *>::const_iterator it = glmap_id2histo.find(hid);
      if (it == glmap_id2histo.end()) {
	cerr << "ERROR: histo id " << hid << " never defined in layout" << endl;
	exit (-1);
      }

      wTH1 *myHisto = it->second;
      TH1 *h = myHisto->histo();

      if (!j) {
	//scale second set of histos to the pad coordinates
	rightmin = h->GetMinimum();
	rightmax = 1.1*h->GetMaximum();
	scale    = gPad->GetUymax()/rightmax;
      }
      TH1 *scaled=(TH1 *)h->Clone(Form("%s_%d",h->GetName(),ipad));

      scaled->Scale(scale);
      scaled->Draw("same");
   
      //draw an axis on the right side
      TGaxis *axis = new TGaxis(gPad->GetUxmax(), gPad->GetUymin(),
				gPad->GetUxmax(), gPad->GetUymax(),
				rightmin,rightmax,505,"+L");
      axis->Draw();
      gPad->Update();
      if (drawlegend && myHisto->GetLegendEntry().size()) {
	if (wleg->drawoption.size()) myHisto->SetDrawOption(wleg->drawoption);
	myHisto->Add2Legend(wleg->leg);
      }
    }

    /***************************************************
     * LOOP OVER GRAPHS DEFINED FOR PAD...
     ***************************************************/
#if 0
    TMultiGraph *mg;
    if (graph_ids.size())
      mg = new TMultiGraph();
#endif
    for( unsigned j = 0; j < wp->graph_ids.size(); j++ ) {
      string& gid = wp->graph_ids[j];
      
      wGraph_t *wg   = findGraph(gid);

      bool firstInPad = !j && !wp->histo_ids.size() && !wp->macro_ids.size();
      if( firstInPad && wg->gr && wg->gr->IsA()==TGraph::Class() )
	wg->drawopt += string("A"); // no histos drawn, need to draw the frame ourselves.

      if( wg && wg->gr ) {
	// "pre-draw" in order to define the plot elements
	wg->gr->Draw(wg->drawopt.c_str());

	if (firstInPad) {
	  // Now we can set the axis attributes and range:
	  wg->gr->GetXaxis()->ImportAttributes(wg->xax);
	  wg->gr->GetYaxis()->ImportAttributes(wg->yax);

	  cout << wg->xax->GetXmin() << " " << wg->xax->GetXmax() << endl;
	  if( wg->xax->GetXmax()>wg->xax->GetXmin() )
	    wg->gr->GetXaxis()->SetLimits(wg->xax->GetXmin(),wg->xax->GetXmax());
	  if( wg->yax->GetXmax()>wg->yax->GetXmin() )
	    wg->gr->GetYaxis()->SetRangeUser(wg->yax->GetXmin(),wg->yax->GetXmax());
	}
	// draw for good
	drawInPad<TGraph>(wp,wg->gr,wg->drawopt.c_str(),firstInPad);

	wp->vp->Update();
	if( wg->fitfn ) 
	  wg->gr->Fit(wg->fitfn);
	if( drawlegend && wg->leglabel.size() )
	  wleg->leg->AddEntry(wg->gr,wg->leglabel.c_str(),wg->legdrawopt.c_str());
      }
      if( wg && wg->gr2d ) {
	drawInPad<TGraph2D>(wp,wg->gr2d,wg->drawopt.c_str(),firstInPad);

	if (firstInPad) {
	  // Now we can set the axis attributes and range:
	  wg->gr2d->GetXaxis()->ImportAttributes(wg->xax);
	  wg->gr2d->GetYaxis()->ImportAttributes(wg->yax);

	  cout << wg->xax->GetXmin() << " " << wg->xax->GetXmax() << endl;
	  if( wg->xax->GetXmax()>wg->xax->GetXmin() )
	    wg->gr2d->GetXaxis()->SetLimits(wg->xax->GetXmin(),wg->xax->GetXmax());
	  if( wg->yax->GetXmax()>wg->yax->GetXmin() )
	    wg->gr2d->GetYaxis()->SetRangeUser(wg->yax->GetXmin(),wg->yax->GetXmax());
	}

	if (wg->contours) {
	  //cout << "setting contours "; wg->contours->Print();
	  wg->gr2d->GetHistogram()->SetContour(wg->contours->GetNoElements(),
					       wg->contours->GetMatrixArray());
	  wg->gr2d->SetLineStyle   (wg->lstyle);
	  wg->gr2d->SetLineColor   (wg->lcolor);
	  wg->gr2d->SetLineWidth   (wg->lwidth);
	}
	wp->vp->Modified();
	wp->vp->Update();
	if( drawlegend && wg->leglabel.size() )
	  wleg->leg->AddEntry(wg->gr2d,wg->leglabel.c_str(),wg->legdrawopt.c_str());
      }
    } // graph loop

    /***************************************************
     * LOOP OVER LINES DEFINED FOR PAD...
     ***************************************************/

    for( unsigned j = 0; j < wp->line_ids.size(); j++ ) {
      string drawopt("L");
      string& lid = wp->line_ids[j];
      map<string,TLine *>::const_iterator it2 = glmap_id2line.find(lid);
      if (it2 == glmap_id2line.end()) {
	cerr << "ERROR: line id " << lid << " never defined in layout" << endl;
	exit (-1);
      }

      TLine *line = it2->second;

      if (!j && !wp->histo_ids.size() && !wp->macro_ids.size())
	drawopt += string("A"); // no histos drawn, need to draw the frame ourselves.

      if (line) {
	drawInPad<TLine>(wp,line,drawopt.c_str());
	//if (drawlegend)
	//wleg->leg->AddEntry(line,lid.c_str(),"L");
      }
    }

    /***************************************************
     * LOOP OVER BOXES DEFINED FOR PAD...
     ***************************************************/

    for (unsigned j = 0; j < wp->box_ids.size(); j++) {
      string drawopt("L");
      string& bid = wp->box_ids[j];
      map<string,TBox *>::const_iterator it2 = glmap_id2box.find(bid);
      if (it2 == glmap_id2box.end()) {
	cerr << "ERROR: box id " << bid << " never defined in layout" << endl;
	exit (-1);
      }

      TBox *box = it2->second;

      if (box) {
	drawInPad<TBox>(wp,box,drawopt.c_str());
      }
    }

    /***************************************************
     * Draw the legend
     ***************************************************/

    if (drawlegend) {
      wleg->leg->Draw("same");
      wp->vp->Update();
    }

    /***************************************************
     * Draw each latex/label object
     ***************************************************/
    
    for (unsigned j=0; j<wp->latex_ids.size(); j++) {
      string& lid = wp->latex_ids[j];
      map<string,TLatex *>::const_iterator it2 = glmap_id2latex.find(lid);
      if (it2 == glmap_id2latex.end()) {
	cerr << "ERROR: latex id " << lid << " never defined in layout" << endl;
	exit (-1);
      }
      if (gl_verbose) cout << "Drawing latex object " << lid << endl;
      TLatex *ltx = it2->second;
      ltx->Draw();
      wp->vp->Update();
    }

    for (unsigned j = 0; j < wp->label_ids.size(); j++) {
      string& lid = wp->label_ids[j];
      map<string,wLabel_t *>::const_iterator it2 = glmap_id2label.find(lid);
      if (it2 == glmap_id2label.end()) {
	cerr << "ERROR: label id " << lid << " never defined in layout" << endl;
	exit (-1);
      }
      if (gl_verbose) cout << "Drawing label object " << lid << endl;
      wLabel_t *wlab = it2->second;
      drawStandardText(wlab->text, wlab->x1ndc, wlab->y1ndc,-1,-1,wlab->textsize);

      wp->vp->Update();
    }
    wc->c1->Update();

  } // pad loop

  //prdFixOverlay();

  if (savePlots2file) {
    wc0 = cs.canvases[0];
    if (!wc0->savenamefmts.size())  // define a default
      wc0->savenamefmts.push_back("%F_%C.png");
    for (size_t i=0; i<cs.canvases.size(); i++) {
      wCanvas_t *wc = cs.canvases[i];
      wc->c1->cd();
      for (size_t j=0; j<wc0->savenamefmts.size(); j++)
	saveCanvas2File(wc,wc0->savenamefmts[j]);
    }
  }
}                                                           // drawPlots
void GE11sEfficiencyScan(int RunNumber, string RunName, string path)
{
   
   ifstream InGE11_IV_GIF, InGE11_IV, InGE11_V;

   //string path = "/home/ramkrishna/TEMP/LogFiles_TB/LogFiles306To407";	    

   string gif	= path+"/Efficiency_LC1_"+std::to_string(RunNumber)+".log";
   string IV	= path+"/Efficiency_LC2_"+std::to_string(RunNumber)+".log";
   string V	= path+"/Efficiency_LC3_"+std::to_string(RunNumber)+".log";

   cout<<"gif = "<<gif<<endl;
   InGE11_IV_GIF.open(gif);
   InGE11_IV.open(IV);
   InGE11_V.open(V);

   string rootFile = "Efficiency_Run"+std::to_string(RunNumber)+".root";
   const char *CharrootFile = rootFile.c_str();
   TFile *f = new TFile(CharrootFile,"RECREATE");
   //TTree *tree = new TTree("Run306", "Detector info for Run 306");
   TNtuple *GE11_IV_GIF = new TNtuple("GE11_IV_GIF","data from text file LC1","MeanPosOfSector:Efficiency:EfficiencyError:Nevents");
   TNtuple *GE11_IV = new TNtuple("GE11_IV","data from text file LC2","MeanPosOfSector:Efficiency:EfficiencyError:Nevents");
   TNtuple *GE11_V = new TNtuple("GE11_V","data from text file LC3","MeanPosOfSector:Efficiency:EfficiencyError:Nevents");

   Int_t nlines = 0;

   vector<double> GIF_MeanPosOfSector, GIF_Efficiency, GIF_EfficiencyError;
   vector<unsigned int> GIF_Nevents;
   unsigned int temp_Nevents;
   double temp_MeanPosOfSector, temp_Efficiency, temp_EfficiencyError;

   vector<double> IV_MeanPosOfSector, IV_Efficiency, IV_EfficiencyError;
   vector<unsigned int> IV_Nevents;

   vector<double> V_MeanPosOfSector, V_Efficiency, V_EfficiencyError;
   vector<unsigned int> V_Nevents;

   string NameOfDet, xRange;

   while (1) 
   {
     InGE11_IV_GIF >> NameOfDet >> xRange >> temp_MeanPosOfSector >> temp_Efficiency >> temp_EfficiencyError >> temp_Nevents;
	if (!InGE11_IV_GIF.good()) break;

     GIF_MeanPosOfSector.push_back(temp_MeanPosOfSector+(nlines*5));
     GIF_Efficiency.push_back(temp_Efficiency);
     GIF_EfficiencyError.push_back(temp_EfficiencyError);
     GIF_Nevents.push_back(temp_Nevents);
    	GE11_IV_GIF->Fill(temp_MeanPosOfSector+(nlines*5),temp_Efficiency,temp_EfficiencyError,temp_Nevents);
	nlines++;
	if (nlines > 20) 
	{
	    cout<<"Check the input text file for run number "<< RunNumber << endl;
	    exit(EXIT_SUCCESS);
	}
   }

   InGE11_IV_GIF.close();
   nlines=0;
   while (1) 
   {
     InGE11_IV >> NameOfDet >> xRange >> temp_MeanPosOfSector >> temp_Efficiency >> temp_EfficiencyError >> temp_Nevents;
	if (!InGE11_IV.good()) break;

     IV_MeanPosOfSector.push_back(temp_MeanPosOfSector+(nlines*5));
     IV_Efficiency.push_back(temp_Efficiency);
     IV_EfficiencyError.push_back(temp_EfficiencyError);
     IV_Nevents.push_back(temp_Nevents);
    	GE11_IV->Fill(temp_MeanPosOfSector+(nlines*5),temp_Efficiency,temp_EfficiencyError,temp_Nevents);
	nlines++;
   }

   InGE11_IV.close();
   nlines=0;
   while (1) 
   {
     InGE11_V >> NameOfDet >> xRange >> temp_MeanPosOfSector >> temp_Efficiency >> temp_EfficiencyError >> temp_Nevents;
	if (!InGE11_V.good()) break;

     V_MeanPosOfSector.push_back(temp_MeanPosOfSector+(nlines*5));
     V_Efficiency.push_back(temp_Efficiency);
     V_EfficiencyError.push_back(temp_EfficiencyError);
     V_Nevents.push_back(temp_Nevents);
    	GE11_V->Fill(temp_MeanPosOfSector+(nlines*5),temp_Efficiency,temp_EfficiencyError,temp_Nevents);
	nlines++;
   }

   InGE11_V.close();
   string CanvasName = "RunNumber"+std::to_string(RunNumber);
   const char * CharCanvasName = CanvasName.c_str();
   TCanvas* c1 = new TCanvas(CharCanvasName,"Efficiency Scan Plot",200,10,700,500);
   TPad *pad = new TPad("pad","",0,0,1,1);
   //pad->SetFillColor(42);
   pad->SetGrid();
   pad->Draw();
   pad->cd();

      // draw a frame to define the range
   TH1F *hr = pad->DrawFrame(0,-0.5,100,1.1);
   hr->SetXTitle("Detector Position (mm)");
   hr->SetYTitle("Efficiency");
   //pad->GetFrame()->SetFillColor(21);
   pad->GetFrame()->SetBorderSize(12);

      // create first graph
   TGraphErrors *gr_GIF = new TGraphErrors(V_Efficiency.size());
   TGraphErrors *gr_IV = new TGraphErrors(V_Efficiency.size());
   TGraphErrors *gr_V = new TGraphErrors(V_Efficiency.size());
   for(unsigned int i=0;i<V_Efficiency.size();i++)
   {
       gr_GIF->SetPoint(i, GIF_MeanPosOfSector[i], GIF_Efficiency[i]);
       gr_GIF->SetPointError(i,0, GIF_EfficiencyError[i]);
       
       gr_IV->SetPoint(i, IV_MeanPosOfSector[i], IV_Efficiency[i]);
       gr_IV->SetPointError(i,0, IV_EfficiencyError[i]);

       gr_V->SetPoint(i, V_MeanPosOfSector[i], V_Efficiency[i]);
       gr_V->SetPointError(i,0, V_EfficiencyError[i]);
   }
   gr_GIF->SetMarkerColor(kBlue);
   gr_GIF->SetLineColor(kBlue);
   gr_GIF->SetMarkerStyle(21);
   gr_GIF->GetXaxis()->SetTitle("dist (mm)");
   gr_GIF->GetYaxis()->SetTitle("Efficiency");
   gr_GIF->GetYaxis()->SetRangeUser(0,1.2);
   gr_GIF->SetTitle("Efficiency Scan");
   gr_GIF->Draw("ACP");
   gr_IV->SetMarkerColor(kGreen-6);
   gr_IV->SetLineColor(kGreen);
   gr_IV->SetMarkerStyle(21);
   gr_IV->Draw("sameCP");
   gr_V->SetMarkerColor(kBlack);
   gr_V->SetLineColor(kBlack);
   gr_V->SetMarkerStyle(21);
   gr_V->Draw("sameCP");

   //create a transparent pad drawn on top of the main pad
   c1->cd();
   TPad *overlay = new TPad("overlay","",0,0,1,1);
   overlay->SetFillStyle(4000);
   overlay->SetFillColor(0);
   overlay->SetFrameFillStyle(4000);
   overlay->Draw();
   overlay->cd();
   // create second graph
   //TGraphErrors* gr_GIF_Num = new TGraphErrors("data_noerror.dat","%lg %lg");
   TGraphErrors *gr_GIF_Num = new TGraphErrors(GIF_Nevents.size());
   TGraphErrors *gr_IV_Num = new TGraphErrors(IV_Nevents.size());
   TGraphErrors *gr_V_Num = new TGraphErrors(V_Nevents.size());

   for(unsigned int i=0;i<V_MeanPosOfSector.size();i++)
   {
       gr_GIF_Num->SetPoint(i,GIF_MeanPosOfSector[i],GIF_Nevents[i]);
       gr_IV_Num->SetPoint(i,IV_MeanPosOfSector[i],IV_Nevents[i]);
       gr_V_Num->SetPoint(i,V_MeanPosOfSector[i],V_Nevents[i]);

   }
   gr_GIF_Num->SetMarkerColor(kBlue);
   gr_GIF_Num->SetLineColor(kBlue);
   gr_GIF_Num->SetLineStyle(2);
   gr_GIF_Num->SetLineWidth(3);
   gr_GIF_Num->SetMarkerStyle(22);
   gr_GIF_Num->SetName("gr_GIF_Num");

   gr_IV_Num->SetMarkerColor(kGreen-6);
   gr_IV_Num->SetLineColor(kGreen);
   gr_IV_Num->SetMarkerStyle(22);
   gr_IV_Num->SetLineStyle(2);
   gr_IV_Num->SetLineWidth(3);
   gr_IV_Num->SetName("gr_IV_Num");

   gr_V_Num->SetMarkerColor(kBlack);
   gr_V_Num->SetLineColor(kBlack);
   gr_V_Num->SetMarkerStyle(22);
   gr_V_Num->SetLineStyle(2);
   gr_V_Num->SetLineWidth(3);
   gr_V_Num->SetName("gr_V_Num");

   Double_t xmin = pad->GetUxmin();
   Double_t ymin = 0;
   Double_t xmax = pad->GetUxmax();
   Double_t ymax = 1550;
   TH1F *hframe = overlay->DrawFrame(xmin,ymin,xmax,ymax);
   hframe->GetXaxis()->SetLabelOffset(99);
   hframe->GetYaxis()->SetLabelOffset(99);
   hframe->Draw("Y+");
   
   gr_GIF_Num->Draw("CPY+");
   gr_IV_Num->Draw("CPY+");
   gr_V_Num->Draw("CPY+");

   //Draw the Legend 
   TLegend *leg = new TLegend(0.10,0.732,0.40,0.90);
   leg->AddEntry(gr_GIF,"GE11_IV_GIF eff","LPE");
   leg->AddEntry(gr_IV,"GE11_IV eff","LPE");
   leg->AddEntry(gr_V,"GE11_V eff","LPE");
   leg->AddEntry(gr_GIF_Num,"No of events_GE11_IV_GIF","LPE");
   leg->AddEntry(gr_IV_Num,"No of events_GE11_IV","LPE");
   leg->AddEntry(gr_V_Num,"No of events_GE11_V","LPE");

   leg->Draw("same");

   const char *runnum = RunName.c_str();
   
   TLatex *t2a = new TLatex(0.00,0.94, runnum  );
   t2a->SetNDC();
   t2a->SetTextFont(42);
   t2a->SetTextSize(0.033);
   t2a->SetTextAlign(13);
   t2a->Draw("same");
   
   
   //Draw an axis on the right side
   TGaxis *axis = new TGaxis(xmax,ymin,xmax, ymax,ymin,ymax,510,"+L");
   axis->SetLineColor(kRed);
   axis->SetLabelColor(kRed);
   axis->SetTitle("Approx. No. of Events");

   axis->Draw();

   string OutputFileName = "GE11_Efficiency_Scan_"+std::to_string(RunNumber)+".pdf";
   const char *CharOutputFileName = OutputFileName.c_str();
   c1->SaveAs(CharOutputFileName);

   c1->Write();
   //tree->Write();
   //tree->Write("", TObject::kOverwrite);
   f->Write();

}
//*************************************************************
void arrangeCanvas(TCanvas *canv,TH1F* meanplots[100],TH1F* widthplots[100],Int_t nFiles, TString LegLabels[10], bool onlyBias){
//*************************************************************

  TPaveText *ali = new TPaveText(0.18,0.87,0.50,0.93,"NDC");  
  ali->SetFillColor(10);
  ali->SetTextColor(1);
  ali->SetTextFont(42);
  ali->SetMargin(0.);
  ali->SetLineColor(10);
  ali->SetShadowColor(10);
  // pt->SetTextAlign(11);
  TText *alitext = ali->AddText("Alignment: PCL"); //"Preliminary 2015 - 0T collision data");
  alitext->SetTextSize(0.04);

  TLegend *lego = new TLegend(0.18,0.80,0.78,0.92);
  lego-> SetNColumns(2);
  //TLegend *lego = new TLegend(0.18,0.77,0.50,0.86);
  lego->SetFillColor(10);
  lego->SetTextSize(0.04);
  lego->SetTextFont(42);
  lego->SetFillColor(10);
  lego->SetLineColor(10);
  lego->SetShadowColor(10);

  TPaveText *pt  = NULL;
  TPaveText *pt2 = NULL;
  TPaveText *pt3 = NULL;

  if(!onlyBias){ 
    pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC");
  } else {
    pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC");
  }

  pt->SetFillColor(10);
  pt->SetTextColor(1);
  pt->SetTextFont(61);
  // pt->SetTextAlign(11);
  TText *text1 = pt->AddText("CMS"); //"Preliminary 2015 - 0T collision data");
  text1->SetTextSize(0.05);
 
  float extraOverCmsTextSize  = 0.76;

  if(!onlyBias){ 
    pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC");
  } else {
    pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC");
  }

  pt2->SetFillColor(10);
  pt2->SetTextColor(1);
  pt2->SetTextFont(52);
  pt2->SetTextAlign(22);
  TText *text2 = pt2->AddText("work in progress");
  text2->SetTextSize(0.05*extraOverCmsTextSize);

  if(!onlyBias){ 
    pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC");
  } else {
    pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC");
  }

  pt3->SetFillColor(10);
  pt3->SetTextColor(1);
  pt3->SetTextFont(42);
  // pt2->SetTextAlign(11);
  TText *text3 = pt3->AddText("3.8T collision data 2015");
  text3->SetTextSize(0.05*extraOverCmsTextSize);

  canv->SetFillColor(10);  
  if(!onlyBias) {
    canv->Divide(2,1);
    
    canv->cd(1)->SetBottomMargin(0.12);
    canv->cd(1)->SetLeftMargin(0.17);
    canv->cd(1)->SetRightMargin(0.02);
    canv->cd(1)->SetTopMargin(0.06);  
    
    canv->cd(2)->SetBottomMargin(0.12);
    canv->cd(2)->SetLeftMargin(0.17);
    canv->cd(2)->SetRightMargin(0.02);
    canv->cd(2)->SetTopMargin(0.06);  
  
    canv->cd(1);
  } else {
    
    canv->cd()->SetBottomMargin(0.14);
    canv->cd()->SetLeftMargin(0.17);
    canv->cd()->SetRightMargin(0.02);
    canv->cd()->SetTopMargin(0.06);  
    canv->cd();

  }

  Double_t absmin(999.);
  Double_t absmax(-999.);

  for(Int_t i=0; i<nFiles; i++){
    if(meanplots[i]->GetMaximum()>absmax) absmax = meanplots[i]->GetMaximum();
    if(meanplots[i]->GetMinimum()<absmin) absmin = meanplots[i]->GetMinimum();
  }

  Double_t safeDelta=(absmax-absmin)/2.;
  Double_t theExtreme=std::max(absmax,TMath::Abs(absmin));

  for(Int_t i=0; i<nFiles; i++){

    TString myTitle = meanplots[i]->GetName();
    float axmin = -999;
    float axmax = 999.;
    int ndiv = 510;
    if(myTitle.Contains("eta")){
      axmin = -2.5;
      axmax = 2.5;
      ndiv = 505;
    } else if (myTitle.Contains("phi")){
      axmin = -TMath::Pi();
      axmax = TMath::Pi();
      ndiv = 510;
    } else  {
      std::cout<<"unrecongnized variable";
    }

    meanplots[i]->GetXaxis()->SetLabelOffset(999);
    meanplots[i]->GetXaxis()->SetTickLength(0);
    
    // Redraw the new axis 
    gPad->Update();
    TGaxis *newaxis =  new TGaxis(gPad->GetUxmin(),gPad->GetUymin(),
				  gPad->GetUxmax(),gPad->GetUymin(),
				  axmin,
				  axmax,
				  //meanplots[i]->GetXaxis()->GetXmin(),
				  //meanplots[i]->GetXaxis()->GetXmax(),
				  ndiv,"SDH");
    
    
    TGaxis *newaxisup =  new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),
				    gPad->GetUxmax(),gPad->GetUymax(),
				    axmin,
				    axmax,
				    //meanplots[i]->GetXaxis()->GetXmin(),                                                                                                     
				    //meanplots[i]->GetXaxis()->GetXmax(),                                                                                                     
				    ndiv,"-SDH");
    
    newaxis->SetLabelOffset(0.02);
    newaxis->SetLabelFont(42);
    newaxis->SetLabelSize(.05);
    newaxis->Draw();

    newaxisup->SetLabelOffset(-0.02);
    newaxisup->SetLabelFont(42);
    newaxisup->SetLabelSize(0);
    newaxisup->Draw();
    
    if(i==0){
      //meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta/2.,absmax+safeDelta);
      std::cout<<"name is: "<< meanplots[i]->GetName() << " absmin:" <<absmin<<" absmax: "<<absmax<<" safeDelta: "<<safeDelta<<std::endl;
      TString theTitle = meanplots[i]->GetName();
      if( theTitle.Contains("Norm")){
	meanplots[i]->GetYaxis()->SetRangeUser(std::min(-0.48,absmin-safeDelta),std::max(0.48,absmax+safeDelta));
      } else {
	if(!onlyBias){
	  meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta,absmax+safeDelta);
	} else {
	  meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme-(TMath::Abs(absmin)/10.),theExtreme+(TMath::Abs(absmax/10.)));
	}
	//meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme,theExtreme);
      } 
      meanplots[i]->Draw("e1");

      if(onlyBias){
	Int_t nbins =  meanplots[i]->GetNbinsX();
	Double_t lowedge  = meanplots[i]->GetBinLowEdge(1);
	Double_t highedge = meanplots[i]->GetBinLowEdge(nbins+1);
	
	TH1F* hzero = DrawZero(meanplots[i],nbins,lowedge,highedge);
	hzero->Draw("PLsame");
      }

    }
    else meanplots[i]->Draw("e1sames");
    lego->AddEntry(meanplots[i],LegLabels[i]); 
  }  
  

  //ali->Draw();
  lego->Draw();
  pt->Draw("same");
  pt2->Draw("same");
  pt3->Draw("same");


  if(!onlyBias){

    canv->cd(2);
    Double_t absmax2(-999.);
    
    for(Int_t i=0; i<nFiles; i++){
      if(widthplots[i]->GetMaximum()>absmax2) absmax2 = widthplots[i]->GetMaximum();
    }
    
    Double_t safeDelta2=absmax2/3.;
    
    for(Int_t i=0; i<nFiles; i++){

      TString myTitle = widthplots[i]->GetName();
      float axmin = -999;
      float axmax = 999.;
      int ndiv = 510;
      if(myTitle.Contains("eta")){
	axmin = -2.5;
	axmax = 2.5;
	ndiv = 505;
      } else if (myTitle.Contains("phi")){
	axmin = -TMath::Pi();
	axmax = TMath::Pi();
	ndiv = 510;
      } else  {
	std::cout<<"unrecongnized variable";
      }
      
      widthplots[i]->GetXaxis()->SetLabelOffset(999);
      widthplots[i]->GetXaxis()->SetTickLength(0);
      
      // Redraw the new axis 
      gPad->Update();
      TGaxis *newaxis2 = new TGaxis(gPad->GetUxmin(),gPad->GetUymin(),
				    gPad->GetUxmax(),gPad->GetUymin(),
				    axmin,
				    axmax,
				    //widthplots[i]->GetXaxis()->GetXmin(),
				    //widthplots[i]->GetXaxis()->GetXmax(),
				    ndiv,"SDH");
      
      newaxis2->SetLabelOffset(0.02);
      newaxis2->SetLabelFont(42);
      newaxis2->SetLabelSize(.05);
      newaxis2->Draw();

      TGaxis *newaxis2up = new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),
				      gPad->GetUxmax(),gPad->GetUymax(),
				      axmin,
				      axmax,
				      //widthplots[i]->GetXaxis()->GetXmin(),
				      //widthplots[i]->GetXaxis()->GetXmax(),
				      ndiv,"-SDH");
      
      newaxis2up->SetLabelOffset(-0.02);
      newaxis2up->SetLabelFont(42);
      newaxis2up->SetLabelSize(0.);
      newaxis2up->Draw();

      if(i==0) widthplots[i]->Draw("e1");
      else widthplots[i]->Draw("e1sames");
      widthplots[i]->SetMinimum(0.5);
      widthplots[i]->SetMaximum(absmax2+safeDelta2);
    }
    
    lego->Draw();
    pt->Draw("same");
    pt2->Draw("same");
    pt3->Draw("same");

  }
}
Example #21
0
///
/// Make a plot out of a 1D histogram holding a 1-CL curve.
/// The strategy is to always convert the 1-CL histogram (hCL) into
/// a TGraph. This way we can add known points (solutions, points
/// at end of scan range) and also have a filled area without line
/// smoothing. This is not possible with histograms due to a Root bug.
///
/// The function draws the TGraphs, and returns a pointer to the
/// TGraph object that can be used in the TLegend.
///
/// Markers are plotted if the method name of the scanner is "Plugin" or "BergerBoos" or "DatasetsPlugin".
/// One can plot a line instead of points even for the Plugin method by
/// using setPluginMarkers().
///
/// For the angle variables, a new axis is painted that is in Deg.
///
/// \param s The scanner to plot.
/// \param first
/// \param last
/// \param filled
///
TGraph* OneMinusClPlot::scan1dPlot(MethodAbsScan* s, bool first, bool last, bool filled, int CLsType)
{
	if ( arg->debug ){
		cout << "OneMinusClPlot::scan1dPlot() : plotting ";
		cout << s->getName() << " (" << s->getMethodName() << ")" << endl;
	}
	if ( m_mainCanvas==0 ){
		m_mainCanvas = newNoWarnTCanvas(name+getUniqueRootName(), title, 800, 600);
	}
	m_mainCanvas->cd();
	bool plotPoints = ( s->getMethodName()=="Plugin" || s->getMethodName()=="BergerBoos" || s->getMethodName()=="DatasetsPlugin" ) && plotPluginMarkers;
	TH1F *hCL = (TH1F*)s->getHCL()->Clone(getUniqueRootName());
	if (CLsType==1) hCL = (TH1F*)s->getHCLs()->Clone(getUniqueRootName());
  else if (CLsType==2) hCL = (TH1F*)s->getHCLsFreq()->Clone(getUniqueRootName());
	// fix inf and nan entries
	for ( int i=1; i<=s->getHCL()->GetNbinsX(); i++ ){
		if ( s->getHCL()->GetBinContent(i)!=s->getHCL()->GetBinContent(i)
				|| std::isinf(s->getHCL()->GetBinContent(i)) ) s->getHCL()->SetBinContent(i, 0.0);
	}

	// remove errors the hard way, else root ALWAYS plots them
	if ( !plotPoints ) hCL = histHardCopy(hCL, true, true);

	// disable any statistics box
	hCL->SetStats(0);

	// Convert the histogram into a TGraph so we can add the solution.
	// Also, the lf2 drawing option is broken in latest root versions.
	TGraph *g;
	if ( plotPoints ) g = new TGraphErrors(hCL->GetNbinsX());
	else              g = new TGraph(hCL->GetNbinsX());
	g->SetName(getUniqueRootName());
	for ( int i=0; i<hCL->GetNbinsX(); i++ ){
		g->SetPoint(i, hCL->GetBinCenter(i+1), hCL->GetBinContent(i+1));
		if ( plotPoints ) ((TGraphErrors*)g)->SetPointError(i, 0.0, hCL->GetBinError(i+1));
	}

	// add solution
	if ( ! s->getSolutions().empty() ){
		TGraphTools t;
		TGraph *gNew = t.addPointToGraphAtFirstMatchingX(g, s->getScanVar1Solution(0), 1.0);
		delete g;
		g = gNew;
	}

	// // set last point to the same p-value as first point by hand
	// // some angle plots sometimes don't manage to do it by themselves...
	// if ( arg->isQuickhack(XX) )
	// {
	//   Double_t pointx0, pointy0, err0;
	//   Double_t pointx1, pointy1, err1;
	//   g->GetPoint(0, pointx0, pointy0);
	//   g->GetPoint(g->GetN()-1, pointx1, pointy1);
	//   g->SetPoint(g->GetN()-1, pointx1, pointy0);
	//   if ( plotPoints ) err0 = ((TGraphErrors*)g)->GetErrorY(0);
	//   if ( plotPoints ) ((TGraphErrors*)g)->SetPointError(g->GetN()-1, 0.0, err0);
	// }

	// add end points of scan range
	if ( !plotPoints )
	{
		Double_t pointx0, pointy0;
		TGraph *gNew = new TGraph(g->GetN()+4);
		gNew->SetName(getUniqueRootName());
		for ( int i=0; i<g->GetN(); i++)
		{
			g->GetPoint(i, pointx0, pointy0);
			gNew->SetPoint(i+2, pointx0, pointy0);
		}

		// add origin
		gNew->SetPoint(0, hCL->GetXaxis()->GetXmin(), 0);

		// add a point at first y height but at x=origin.
		g->GetPoint(0, pointx0, pointy0);
		gNew->SetPoint(1, hCL->GetXaxis()->GetXmin(), pointy0);

		// add a point at last y height but at x=xmax.
		g->GetPoint(g->GetN()-1, pointx0, pointy0);
		gNew->SetPoint(gNew->GetN()-2, hCL->GetXaxis()->GetXmax(), pointy0);

		// add a point at xmax, 0
		gNew->SetPoint(gNew->GetN()-1, hCL->GetXaxis()->GetXmax(), 0);
		g = gNew;
	}

	int color = s->getLineColor();
	if(CLsType>0 && s->getMethodName().Contains("Plugin") && !arg->plotpluginonly) {
    if (CLsType==1) color = kBlue-7;
    else if (CLsType==2) color = kBlue+2;
  }
	else if(CLsType>0) {
    if (CLsType==1) color = s->getLineColor() - 5;
    if (CLsType==2) color = s->getLineColor() - 4;
  }
	g->SetLineColor(color);

	if ( filled ){
		g->SetLineWidth(2);
    double alpha = arg->isQuickhack(12) ? 0.4 : 1.;
    if ( arg->isQuickhack(24) ) alpha = 0.;
		g->SetFillColorAlpha(color,alpha);
		g->SetLineStyle(1);
    g->SetFillStyle( s->getFillStyle() );
	}
	else{
		g->SetLineWidth(2);
		g->SetLineStyle(s->getLineStyle());
    if ( last && arg->isQuickhack(25) ) g->SetLineWidth(3);
	}

	if ( plotPoints ){
		g->SetLineWidth(1);
		g->SetMarkerColor(color);
		g->SetMarkerStyle(8);
		g->SetMarkerSize(0.6);
		if(CLsType==1) {
			g->SetMarkerStyle(33);
			g->SetMarkerSize(1);
		}
		if(CLsType==2) {
			g->SetMarkerStyle(21);
		}
	}

	// build a histogram which holds the axes
	float min = arg->scanrangeMin == arg->scanrangeMax ? hCL->GetXaxis()->GetXmin() : arg->scanrangeMin;
	float max = arg->scanrangeMin == arg->scanrangeMax ? hCL->GetXaxis()->GetXmax() : arg->scanrangeMax;
	TH1F *haxes = new TH1F("haxes"+getUniqueRootName(), "", 100, min, max);
	haxes->SetStats(0);
	haxes->GetXaxis()->SetTitle(s->getScanVar1()->GetTitle());
	haxes->GetYaxis()->SetTitle("1-CL");
	haxes->GetXaxis()->SetLabelFont(font);
	haxes->GetYaxis()->SetLabelFont(font);
	haxes->GetXaxis()->SetTitleFont(font);
	haxes->GetYaxis()->SetTitleFont(font);
	haxes->GetXaxis()->SetTitleOffset(0.9);
	haxes->GetYaxis()->SetTitleOffset(0.85);
	haxes->GetXaxis()->SetLabelSize(labelsize);
	haxes->GetYaxis()->SetLabelSize(labelsize);
	haxes->GetXaxis()->SetTitleSize(titlesize);
	haxes->GetYaxis()->SetTitleSize(titlesize);
	int xndiv = arg->ndiv==-1 ? 407 : abs(arg->ndiv);
	bool optimizeNdiv = arg->ndiv<0 ? true : false;
	haxes->GetXaxis()->SetNdivisions(xndiv, optimizeNdiv);
	haxes->GetYaxis()->SetNdivisions(407, true);

  // plot y range
  float plotYMax;
  float plotYMin;
  if ( plotLegend && !arg->isQuickhack(22) ) {
    if ( arg->plotlog ) { plotYMin = 1.e-3; plotYMax = 10.; }
    else                { plotYMin = 0.0  ; plotYMax = 1.3; }
  }
  else {
    if ( arg->plotlog ) { plotYMin = 1.e-3; plotYMax = 1.0; }
    else                { plotYMin = 0.0  ; plotYMax = 1.0; }
  }
  // change if passed as option
	plotYMin = arg->plotymin > 0. ? arg->plotymin : plotYMin;
  plotYMax = arg->plotymax > 0. ? arg->plotymax : plotYMax;

  haxes->GetYaxis()->SetRangeUser( plotYMin, plotYMax );
	haxes->Draw("axissame");
	g->SetHistogram(haxes);

	TString drawOption = "";
	if ( plotPoints )   drawOption += " pe";
	else if ( filled )  drawOption += " F";
	else                drawOption += " L";
	if ( first )        drawOption += " A";
	g->Draw(drawOption);
  //if ( drawOption.Contains("F") ) ((TGraph*)g->Clone())->Draw("L");

	gPad->Update();
	float ymin = gPad->GetUymin();
	float ymax = gPad->GetUymax();
	float xmin = gPad->GetUxmin();
	float xmax = gPad->GetUxmax();

	// for the angles, draw a new axis in units of degrees
	if ( isAngle(s->getScanVar1()) ){
		haxes->GetXaxis()->SetTitle(s->getScanVar1()->GetTitle() + TString(" [#circ]"));
		haxes->GetXaxis()->SetNdivisions(0);  // disable old axis
		if ( last ){
			// new top axis
			TString chopt = "-U"; // - = downward ticks, U = unlabeled, http://root.cern.ch/root/html534/TGaxis.html
			if ( !optimizeNdiv ) chopt += "N"; // n = no bin optimization
			TGaxis *axist = new TGaxis(xmin, 1, xmax, 1, RadToDeg(xmin), RadToDeg(xmax), xndiv, chopt);
			axist->SetName("axist");
			axist->Draw();

			// new bottom axis
			float axisbMin = RadToDeg(xmin);
			float axisbMax = RadToDeg(xmax);
			if ( arg->isQuickhack(3) ){ ///< see documentation of --qh option in OptParser.cpp
				axisbMin += 180.;
				axisbMax += 180.;
			}
			chopt = ""; // - = downward ticks, U = unlabeled, http://root.cern.ch/root/html534/TGaxis.html
			if ( !optimizeNdiv ) chopt += "N"; // n = no bin optimization
			TGaxis *axisb = new TGaxis(xmin, ymin, xmax, ymin, axisbMin, axisbMax, xndiv, chopt);
			axisb->SetName("axisb");
			axisb->SetLabelFont(font);
			axisb->SetLabelSize(labelsize);
			axisb->Draw();
		}
	}
	else
	{
		if ( last ){
			// add top axis
			TString chopt = "-U"; // - = downward ticks, U = unlabeled, http://root.cern.ch/root/html534/TGaxis.html
			if ( !optimizeNdiv ) chopt += "N"; // n = no bin optimization
			TGaxis *axist = new TGaxis(xmin, 1.0, xmax, 1.0, xmin, xmax, xndiv, chopt);
			axist->SetName("axist");
			axist->SetLineWidth(1);
			axist->Draw();
		}
	}

	if ( last )
	{
		// add right axis
		TGaxis *axisr = 0;
		if ( arg->plotlog ){
			float f3min = 1e-3;
			float f3max = (plotLegend && !arg->isQuickhack(22)) ? 10. : 1.;
			TF1 *f3 = new TF1("f3","log10(x)",f3min,f3max);
			axisr = new TGaxis(xmax, f3min, xmax, f3max, "f3", 510, "G+");
		}
		else{
			axisr = new TGaxis(xmax, ymin, xmax, ymax, 0, (plotLegend && !arg->isQuickhack(22)) ? 1.3 : 1.0, 407, "+");
		}
		axisr->SetLabelSize(0);
		axisr->SetLineWidth(1);
		axisr->SetName("axisr");
		axisr->SetLabelColor(kWhite);
		axisr->SetTitleColor(kWhite);
		axisr->Draw();

		// redraw right axis as well because the 1-CL graph can cover the old one
		haxes->Draw("axissame");
	}

	return g;
}
Example #22
0
void plot_figure(TString fn,TPad *thePad,bool saxis=false,float ymin=-2.0,float ymax=1.0,bool with_d=false) {
//cout<<"wit"<<with_d<<endl;

gStyle->SetOptFit();
gStyle->SetPadTickY(1);

gStyle->SetLineStyleString(11,"40 20");
float xmin=0,xmax=2;

thePad->cd();
//thePad->SetGrid();

/*****************************************************
 Colors
*****************************************************/
int HRMcol=kRed+2;
int RNAcol=kMagenta;
int QGScol=kGreen+1;

float kb2b=1000;
Double_t x,y;
/*****************************************************
 Format the pad
*****************************************************/

thePad->SetTopMargin(0.15);
TH1F *hr = thePad->DrawFrame(xmin,ymin,xmax,ymax);
hr->SetXTitle("Q (GeV)");
hr->SetYTitle("t_{20}");
/*hr->GetYaxis()->SetTitleOffset(1.5);
hr->GetYaxis()->SetTitleSize(.06);
hr->GetYaxis()->SetTitleFont(42);
hr->GetYaxis()->CenterTitle();
hr->GetXaxis()->SetTitleSize(.06);
hr->GetXaxis()->SetTitleFont(42);
*//*****************************************************
  Draw legend
*****************************************************/

TLegend *dummylegend=new TLegend();
TLegend *legend=new TLegend(0.59,0.17,0.94,0.55);
legend->SetMargin(0.2);
legend->SetTextFont(72);
legend->SetTextSize(0.035);
legend->SetFillStyle(0);
legend->SetBorderSize(0);
legend->Draw();

TLegend *thlegend=new TLegend(0.23,0.64,0.57,0.84);
thlegend->SetMargin(0.2);
thlegend->SetTextFont(72);
thlegend->SetTextSize(0.035);
thlegend->SetFillStyle(0);
thlegend->SetBorderSize(0);
thlegend->Draw();

thePad->SetLeftMargin(0.19);
/*****************************************************
  Draw top axis
*****************************************************/
float titlex1=0.47, titley1=0.85,titlex2=0.56,titley2=0.95;

if (saxis) {
  titley1=0.72;titley2=0.82;
  TGaxis *axispp = new TGaxis(thePad->GetUxmin(),thePad->GetUymax()*1,
		 thePad->GetUxmax(),
		 thePad->GetUymax()*1,
		 xmin*0.1973,
		 xmax*0.1973,510,"-R");
  axispp->SetTitle("Q (GeV)");
  axispp->SetLabelFont(42);
  axispp->SetLabelSize(0.04);
  axispp->SetTitleFont(42);
  axispp->SetTitleSize(.055);
  axispp->Draw();
}
/*****************************************************
    Make Title
*****************************************************/
//TPaveLabel *label = new TPaveLabel(titlex1,titley1,titlex2,titley2,"^{3}He(#gamma,pp)n","NDC");
//label->SetTextSize(0.7);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
//TPaveLabel *label = new TPaveLabel(titlex1,titley1-0.06,titlex2,titley2-0.06,"90#circc.m.","NDC");
//label->SetTextSize(0.5);
//label->SetFillStyle(0);
//label->SetTextFont(42);
//label->SetBorderSize(0);
//label->Draw();
/*--------------------------------------------------------------------------------------
    Constants?
---------------------------------------------------------------------------------------*/
  Double_t xmd = 1.875613;
  Double_t xmdsq = xmd*xmd;
  Double_t q0sq = 1.15;
  Double_t degr = 0.01745329252;
  Double_t xhbarc = 0.1973;

/*--------------------------------------------------------------------------------------
    Plot IMII modelfor t20
 ---------------------------------------------------------------------------------------*/
  const Int_t npt = 94;
  //Double_t x, y;
  Double_t qfm[npt];
  Double_t qsqpt[npt] = {0.0003893797, 0.003893797, 0.03893797, 0.05840695, 0.07787593, 0.09734491, 0.1168139, 0.1362829, 
		       0.1557519, 0.1752208, 0.1946898, 0.2530968, 0.3115037, 0.3893797, 0.4672556, 0.5451315, 
		       0.6230075, 0.7008834, 0.7787593, 0.8566352, 0.9345112, 1.012387, 1.090263, 1.168139, 1.246015, 
		       1.323891, 1.401767, 1.479643, 1.557519, 1.596457, 1.635395, 1.674333, 1.71327, 1.752208, 
		       1.810615, 1.830084, 1.869022, 1.90796, 1.946898, 1.985836, 2.024774, 2.063712, 2.10265, 
		       2.141588, 2.180526, 2.219464, 2.258402, 2.29734, 2.336278, 2.375216, 2.414154, 2.453092, 
		       2.49203, 2.530968, 2.569906, 2.608844, 2.647782, 2.68672, 2.725658, 2.803534, 2.881409, 
		       2.959285, 3.037161, 3.115037, 3.309727, 3.504417, 3.699107, 3.893797, 4.088486, 4.283176, 
		       4.477866, 4.672556, 4.867246, 5.061936, 5.256625, 5.451315, 5.646005, 5.840695, 6.035385, 
		       6.230075, 6.424764, 6.619454, 6.716799, 6.814144, 6.911489, 7.008834, 7.106179, 7.203524, 
		       7.300869, 7.398214, 7.495558, 7.592903, 7.690248, 7.787593};
  Double_t t20theory[npt] = {-0.001309568, -0.0131055, -0.1318868, -0.1984704, -0.2654408, -0.3327329, -0.4002368, -0.4677915,
			 -0.5351828, -0.6021447, -0.668362, -0.8587877, -1.027779, -1.198694, -1.286326, -1.282388,
			 -1.197382, -1.054978, -0.8820486, -0.7009335, -0.5265257, -0.3668914, -0.2252485, -0.1019077,
			 0.004321276, 0.09524616, 0.1728195, 0.238883, 0.2950801, 0.3199333, 0.3428342, 0.3639258,
			 0.3833423, 0.4012027, 0.4253075, 0.432676, 0.4464807, 0.4591073, 0.4706305, 0.4811208, 
			 0.4906344, 0.4992296, 0.506956, 0.5138575, 0.5199757, 0.5253475, 0.5300049, 0.5339787, 
			 0.5372949, 0.539977, 0.5420477, 0.5435232, 0.5444235, 0.5447623, 0.5445543, 0.5438103, 
			 0.5425456, 0.540766, 0.5384844, 0.5324458, 0.5245013, 0.514713, 0.5031468, 0.4898722, 
			 0.4497016, 0.4006593, 0.3444063, 0.2827923, 0.2178549, 0.1514989, 0.08547981, 0.02124835, 
			 -0.04018853, -0.09806195, -0.1520174, -0.2019219, -0.2477681, -0.2898, -0.3282607, -0.3633281,
			 -0.3951718, -0.4241511, -0.4375907, -0.4502916, -0.4622216, -0.473322, -0.4835232, -0.4927239, 
			 -0.500801, -0.5076282, -0.513053, -0.516797, -0.5184837, -0.5176145};
  //FILE *fp = fopen("im2.dat","r");
  for (Int_t i=0;i<npt;i++) {
  //  Int_t ncols = fscanf(fp,"%f, %f",&x, &y);
  //  qsqpt[i] = x;
  //  t20theory[i] = y;
    qfm[i] = qsqpt[i]**(0.5)/xhbarc;
    //  printf(" line %d read: %f %f \n",i,qsqpt[i],t20theory[i]);
  }
  //fclose(fp);
//TGraph* gQGS=new TGraph("log170_89.dat","%lg %lg");
  gQGS = new TGraph(npt,qsqpt,t20theory);
  gQGS->SetLineColor(kMagenta);
  gQGS->SetMarkerStyle(20);
  gQGS->SetMarkerSize(1.3);
  gQGS->SetLineStyle(11);
  gQGS->SetLineWidth(2);
gQGS->Draw("l");
thlegend->AddEntry(gQGS,"IMII","L");
/*--------------------------------------------------------------------------------------
    Plot IMII+ME modelfor t20
 ---------------------------------------------------------------------------------------*/
  Double_t t20theoryme[npt] = {-0.001325945, -0.01328168, -0.1349228, -0.2041014, -0.2743705, -0.3456319, -0.4177289, -0.4904376,
			       -0.5634585, -0.6364107, -0.7088243, -0.9168859, -1.095754, -1.251422, -1.277469, -1.170903,
			       -0.9677308, -0.7200701, -0.4713423, -0.2466468, -0.05555869, 0.101535, 0.2283672, 0.3298602,
			       0.4107891, 0.4752683, 0.5266488, 0.567598, 0.6002075, 0.6139116, 0.6261154, 0.6369641,
			       0.6465931, 0.6551208, 0.6660647, 0.6692667, 0.6750632, 0.6801088, 0.6844693, 0.6882072,
			       0.6913724, 0.694014, 0.6961743, 0.6978924, 0.6992062, 0.7001432, 0.7007343, 0.701005,
			       0.7009771, 0.7006715, 0.7001097, 0.6993112, 0.6982906, 0.6970643, 0.6956426, 0.6940377,
			       0.6922587, 0.6903158, 0.6882191, 0.6836015, 0.6784688, 0.6728624, 0.6668122, 0.6603509,
			       0.6425963, 0.622676, 0.6008623, 0.5773537, 0.5521636, 0.5259722, 0.4991099, 0.4706432,
			       0.4410795, 0.4127616, 0.3872456, 0.3640124, 0.3422358, 0.3246932, 0.3143134, 0.3116054,
			       0.3142227, 0.3184956, 0.3200235, 0.3212056, 0.3227668, 0.3250734, 0.3281051, 0.3321319,
			       0.3372873, 0.3437867, 0.351448, 0.3600231, 0.3689893, 0.3779735};
TGraph* gRNA=new TGraph(npt,qsqpt,t20theoryme);
gRNA->SetLineColor(kRed);
gRNA->SetMarkerStyle(1);
gRNA->SetMarkerSize(1.3);
gRNA->SetLineStyle(11);
gRNA->SetLineWidth(3);
gRNA->Draw("l");
thlegend->AddEntry(gRNA,"IM+E II","L");
/*--------------------------------------------------------------------------------------
    Dan Phillips no rpg(f/g=0)
 ---------------------------------------------------------------------------------------*/
 const Int_t nph = 66;
 Double_t qph[nph] = { 0.01, 0.25,  0.5,  0.75,   1.0,    1.5,    2.0,    2.5,    3.0,    4.0,
		        5.0,  6.0,  7.0,   8.0,   9.0,   10.0,   11.0,   12.0,   13.0,   14.0,
		       15.0, 16.0, 17.0,  18.0,  19.0,   20.0,   21.0,   22.0,   23.0,   24.0,
		       25.0, 26.0, 27.0,  28.0,  29.0,   30.0,   31.0,   32.0,   33.0,   34.0,
		       35.0, 36.0, 37.0,  38.0,  39.0,   40.0,   41.0,   42.0,   43.0,   44.0,
		       45.0, 47.5, 50.0,  52.5,  55.0,   57.5,   60.0,   62.5,   65.0,   70.0,
		       75.0, 80.0, 85.0,  90.0,  95.0,  100.0};
 for (Int_t i=0;i<nph;i++) {qph[i] = qph[i]*xhbarc**2;}
 Double_t tphrpg0[nph] = {-0.00139028, -0.0347797, -0.0705278, -0.106823, -0.143214, -0.215941, -0.28903, -0.36176, -0.437352, -0.594782,
			  -0.753442, -0.905365, -1.04209, -1.14824, -1.2301, -1.27076, -1.26585, -1.21681, -1.13043, -1.01648,
			  -0.885684, -0.7701, -0.630809, -0.495011, -0.366781, -0.248492, -0.141153, -0.0449377, 0.0407569, 0.116675,
			  0.183835, 0.230211, 0.284553, 0.332797, 0.375647, 0.41358, 0.447136, 0.476061, 0.502346, 0.525668,
			  0.546396, 0.561598, 0.57851, 0.593626, 0.607141, 0.619222, 0.630017, 0.638943, 0.647659, 0.655433,
			  0.662379, 0.675447, 0.686163, 0.693653, 0.698255, 0.70103, 0.701985, 0.701414, 0.699577, 0.696913,
			  0.68897, 0.68092, 0.673572, 0.668027, 0.665207, 0.664439};

TGraph* gph=new TGraph(nph,qph,tphrpg0);
gph->SetLineColor(9);
gph->SetMarkerStyle(1);
gph->SetMarkerSize(1.3);
gph->SetLineStyle(1);
gph->SetLineWidth(3);
gph->Draw("l");
thlegend->AddEntry(gph,"#rho#pi#gamma f/g=0","L");

 Double_t tphrpg3[nph] = {-0.00139212, -0.0348353, -0.0706589, -0.10705, -0.143559, -0.216597, -0.290087, -0.363321, -0.439532, -0.598654,
			  -0.759312, -0.913351, -1.0519, -1.15918, -1.24066, -1.27901, -1.2698, -1.21493, -1.12197, -1.00156,
			  -0.865071, -0.744981, -0.60214, -0.464095, -0.334789, -0.216384, -0.109662, -0.0145868, 0.069612, 0.143819,
			  0.20915, 0.254731, 0.307099, 0.353368, 0.394259, 0.43028, 0.461982, 0.489554, 0.51413, 0.535803,
			  0.554941, 0.568991, 0.584356, 0.59797, 0.610026, 0.620686, 0.630093, 0.63772, 0.645084, 0.651525,
			  0.657156, 0.666024, 0.673624, 0.678127, 0.679481, 0.67949, 0.677837, 0.674823, 0.670722, 0.662356,
			  0.650039, 0.638996, 0.628928, 0.620671, 0.614933, 0.610454};

 //TGraph* gph3=new TGraph(nph,qph,tphrpg3);
 //gph3->SetLineColor(39);
 //gph3->SetMarkerStyle(1);
 //gph3->SetMarkerSize(1.3);
 //gph3->SetLineStyle(2);
 //gph3->SetLineWidth(2);

 //TPaveLabel * Label = new TPaveLabel(0.20,0.66,0.48,0.71,"Propagator f/g=3","NDC");
 //Label->SetTextSize(0.6);
 //Label->SetLineColor(kWhite);
 //Label->SetFillColor(kWhite);
//Label->SetTextColor(39);
//Label->SetBorderSize(0);
//Label->Draw();
//gph3->Draw("l");

 Double_t tphrpg6[nph] = {-0.00139403, -0.0348929, -0.0707944, -0.107286, -0.143917, -0.217276, -0.29118, -0.364936, -0.441787, -0.602659,
			  -0.765378, -0.921581, -1.06195, -1.17027, -1.25116, -1.28686, -1.27292, -1.21183, -1.11202, -0.985056,
			  -0.84299, -0.718589, -0.572616, -0.432822, -0.302967, -0.184961, -0.0793357, 0.0141671, 0.0964853, 0.168642,
			  0.231842, 0.276257, 0.326398, 0.370465, 0.409197, 0.443123, 0.472809, 0.498773, 0.52149, 0.541377,
			  0.558796, 0.571442, 0.58515, 0.597161, 0.607665, 0.616818, 0.624764, 0.630973, 0.636932, 0.642002,
			  0.646291, 0.650319, 0.654857, 0.656509, 0.654827, 0.652371, 0.648479, 0.643459, 0.637587, 0.622962,
			  0.607813, 0.595048, 0.583592, 0.574033, 0.566854, 0.560502};

 TGraph* gph6=new TGraph(nph,qph,tphrpg6);
 gph6->SetLineColor(49);
 gph6->SetMarkerStyle(1);
 gph6->SetMarkerSize(1.3);
 gph6->SetLineStyle(1);
 gph6->SetLineWidth(2);
gph6->Draw("l");
thlegend->AddEntry(gph6,"#rho#pi#gamma f/g=6.1","L");

/*--------------------------------------------------------------------------------------
    put line at -root(2)
---------------------------------------------------------------------------------------*/
Int_t n = 2;
float xfm[2] = {0., 9.};
float yt20[2] = {0., 0.}; 
TGraph* g0=new TGraph(n,xfm,yt20);
g0->SetLineColor(1);
g0->SetMarkerStyle(1);
g0->SetMarkerSize(1.3);
g0->SetLineStyle(1);
g0->SetLineWidth(1);
g0->Draw("l");
yt20[0] = -1.*2**(0.5);
yt20[1] = yt20[0];
xfm[1] = 1.;
TGraph* g1=new TGraph(n,xfm,yt20);
g1->SetLineColor(1);
g1->SetMarkerStyle(1);
g1->SetMarkerSize(1.3);
g1->SetLineStyle(3);
g1->SetLineWidth(1);
g1->Draw("l");

/*  sanity checks
plots11dsdtSet(100,0.040,0.020,0.05,0.000,0.140,kBlack,legend,"E03-101 140 MeV Bins Pn< 100 Mev/c 80 mr X 40 mr");
*/

/*  PRL */
//plotSet(kBlue,legend,"T_{20}");
//plotSet(kBlue,legend,"");
plotSet(kBlue,legend,"");
//plots11dsdtSet(kBlue,legend,"");


/*****************************************************
 Add the rest of the legend enteries
*****************************************************/

//if(!with_d){
//legend->AddEntry(gQGS,"QGS","l");
//legend->AddEntry(gRNA,"RNA","l");
//legend->AddEntry(gHRM,"HRM","F");
//};
gStyle->SetPaperSize(20,26);  //default
//TPaveLabel *label = new TPaveLabel(0.5,0.4,0.85,0.5,"Preliminary","NDC");
//label->SetTextColor(kBlue);
//label->Draw();
//cout<<with_d<<endl;
c->SaveAs(fn+".pdf");
c->SaveAs(fn+".eps");
c->SaveAs(fn+".png");
}
Example #23
0
int ntuAnalyzer(std::string fileName)
{
  setGlobalStyle();
  
  //###############################
  //## run274200 ##
  unsigned int HT250Calo  = 9; //index of DST_HT250_CaloScouting_v   old:1 ref:9
  float HT250Calo_rate = 1928;

  unsigned int HT410PF = 7; //index of DST_HT410_PFScouting_v   old:3 ref:7
  float HT410PF_rate = 294;

  unsigned int MJJ200Calo = 12; //index of DST_DiCaloWideJetMass200_CaloScouting_v
  
  unsigned int HTT200 = 0; //index if L1_HTT200
  unsigned int HTT240 = 1; //index if L1_HTT240
  unsigned int HTT270 = 2; //index if L1_HTT270
  unsigned int HTT280 = 3; //index if L1_HTT280
  unsigned int DoubleJetC100 = 7; //index if L1_DoubleJetC100
  unsigned int DoubleJetC112 = 8; //index if L1_DoubleJetC112
  unsigned int DoubleIsoTau28er = 11; //index if L1_DoubleJetC112

  float instLumi = 0.4; //E34
  float targetLumi = 1; //E34
  float lumiScaleFactor = targetLumi/instLumi;

  float PDRate = 59300; //unprescaled rate of HLTPhysics accordingly to: https://cmswbm2.web.cern.ch/cmswbm2/cmsdb/servlet/DatasetSummary?RUN=274200 and prescale of 9000
  

  unsigned int L1scenario = HTT240;
  //###############################

  TChain* tt = new TChain("MyAnalysis/HLTree");
  tt->Add(fileName.c_str());

  //set branches
  TBranch* b_lumi;
  
  TBranch* b_caloMjj;
  TBranch* b_PFMjj;

  TBranch* b_hltAccept;
  TBranch* b_l1Accept;
  TBranch* b_l1Names;

  TBranch* b_caloJet1Pt;
  TBranch* b_caloJet2Pt;
  TBranch* b_caloJet1Eta;
  TBranch* b_caloJet2Eta;
  TBranch* b_caloDeltaEta;

  TBranch* b_PFJet1Pt;
  TBranch* b_PFJet2Pt;
  TBranch* b_PFJet1Eta;
  TBranch* b_PFJet2Eta;
  TBranch* b_PFDeltaEta;

  int lumi = 0;
  float caloMjj = 0;
  float PFMjj = 0;

  float caloJet1Pt_ = 0;
  float caloJet2Pt_ = 0;
  float caloJet1Eta_ = -999;
  float caloJet2Eta_ = -999;
  float caloDeltaEta_ = -999;

  float PFJet1Pt_ = 0;
  float PFJet2Pt_ = 0;
  float PFJet1Eta_ = -999;
  float PFJet2Eta_ = -999;
  float PFDeltaEta_ = -999;

  
  std::vector<int>* hltAccept = 0;
  std::vector<int>* l1Accept = 0;
  std::vector<string>* l1Names = 0;

  tt->SetBranchAddress("lumi", &lumi, &b_lumi);

  tt->SetBranchAddress("caloMjj", &caloMjj, &b_caloMjj);
  tt->SetBranchAddress("PFMjj", &PFMjj, &b_PFMjj);

  tt->SetBranchAddress("caloJet1Pt", &caloJet1Pt_, &b_caloJet1Pt);
  tt->SetBranchAddress("caloJet2Pt", &caloJet2Pt_, &b_caloJet2Pt);
  tt->SetBranchAddress("caloJet1Eta", &caloJet1Eta_, &b_caloJet1Eta);
  tt->SetBranchAddress("caloJet2Eta", &caloJet2Eta_, &b_caloJet2Eta);
  tt->SetBranchAddress("caloDeltaEta", &caloDeltaEta_, &b_caloDeltaEta);

  tt->SetBranchAddress("PFJet1Pt", &PFJet1Pt_, &b_PFJet1Pt);
  tt->SetBranchAddress("PFJet2Pt", &PFJet2Pt_, &b_PFJet2Pt);
  tt->SetBranchAddress("PFJet1Eta", &PFJet1Eta_, &b_PFJet1Eta);
  tt->SetBranchAddress("PFJet2Eta", &PFJet2Eta_, &b_PFJet2Eta);
  tt->SetBranchAddress("PFDeltaEta", &PFDeltaEta_, &b_PFDeltaEta);

  tt->SetBranchAddress("hltAccept", &hltAccept, &b_hltAccept);
  tt->SetBranchAddress("l1Accept", &l1Accept, &b_l1Accept);
  tt->SetBranchAddress("l1Names", &l1Names, &b_l1Names);

  int nentries = tt->GetEntries();
  std::cout << "Number of entries: " << nentries << std::endl;

  //book graphs and plots
  float min = 0.;
  float max = 1000.;
  int nBins = 20;

  TF1* f1 = new TF1("f1","[0]*TMath::Erf((x-[1])/[2])-[0]*TMath::Erf((-x-[1])/[2])",min,max);
  f1->SetParameters(0.5,350,40);  
  f1->FixParameter(0,0.5);
  f1->SetLineWidth(2.);
  f1->SetLineColor(kRed);

  TF1* f2 = (TF1*)f1->Clone("f2");
  f2->SetParameters(0.5,150,10);
  f2->SetLineColor(kBlack);

  TH1F* caloMjjSpectrum = new TH1F("caloMjjSpectrum","caloMjjSpectrum",nBins,min,max);
  TH1F* PFMjjSpectrum = new TH1F("PFMjjSpectrum","PFMjjSpectrum",nBins,min,max);
  
  TEfficiency* mjj450_eff = new TEfficiency("mjj450_eff","mjj450_eff",nBins,min,max);
  mjj450_eff->SetMarkerColor(kRed);
  mjj450_eff->SetLineColor(kRed);
  mjj450_eff->SetLineWidth(2);
  mjj450_eff->SetTitle("turnOn;Mjj [GeV]");
  TEfficiency* mjj200_eff = new TEfficiency("mjj200_eff","mjj200_eff",nBins,min,max);
  mjj200_eff->SetLineWidth(2);
  mjj200_eff->SetTitle("turnOn;Mjj [GeV]");
  TEfficiency* pf410_eff = new TEfficiency("pf410_eff","pf410_eff",nBins,min,max);
  pf410_eff->SetMarkerColor(kOrange+1);
  pf410_eff->SetLineColor(kOrange+1);
  TEfficiency* calo250_eff = new TEfficiency("calo250_eff","calo250_eff",nBins,min,max);
  calo250_eff->SetMarkerColor(kBlue);
  calo250_eff->SetLineColor(kBlue);
  TEfficiency* HTT240_eff = new TEfficiency("HTT240_eff","HTT240_eff",nBins,min,max);
  HTT240_eff->SetMarkerColor(kGreen+2);
  HTT240_eff->SetLineColor(kGreen+2);

  TH1F* l1 = new TH1F("l1","l1",14,0.,14.);
  TH1F* l2 = new TH1F("l2","l2",14,0.,14.);
  
  //loop
  for (Long64_t jentry=0; jentry<nentries;++jentry)
    {
      tt->GetEntry(jentry);

      //remove low rate lumis.
      //see: https://cmswbm2.web.cern.ch/cmswbm2/cmsdb/servlet/ChartHLTTriggerRates?RUNID=274200&PATHID=2043408&LSLENGTH=23.31040958&TRIGGER_PATH=DST_HT250_CaloScouting_v2
      //if(lumi > 539 && lumi < 553) continue;

      //l1 and hlt rates
      for(unsigned int ii=0; ii<l1Names->size(); ++ii)
	if (l1Accept->at(ii)==1)
	  l1->Fill(ii);
      
      
      //analysis cuts needed to compare to the analysis
      //calo analysis
      if (caloJet1Pt_ > 60. &&
	  caloJet2Pt_ > 30. &&
	  fabs(caloJet1Eta_) < 2.5 &&
	  fabs(caloJet2Eta_) < 2.5 &&
	  caloDeltaEta_ < 1.3)
	{
	  caloMjjSpectrum->Fill(caloMjj);
	  mjj200_eff->Fill((caloMjj>200 && l1Accept->at(L1scenario)==1) || hltAccept->at(HT250Calo)==1, caloMjj);
	  calo250_eff->Fill((hltAccept->at(HT250Calo)==1 && l1Accept->at(L1scenario)==1), caloMjj);

	  //references
	  HTT240_eff->Fill(l1Accept->at(HTT240)==1, caloMjj);
	  //l1 and hlt rates
	  for(unsigned int ii=0; ii<l1Names->size(); ++ii)
	    if (l1Accept->at(ii)==1)
	      l2->Fill(ii);
	}

      //PF analysis
      if (PFJet1Pt_ > 60. &&
	  PFJet2Pt_ > 30. &&
	  fabs(PFJet1Eta_) < 2.5 &&
	  fabs(PFJet2Eta_) < 2.5 &&
	  PFDeltaEta_ < 1.3)
	{
	  PFMjjSpectrum->Fill(PFMjj);
	  mjj450_eff->Fill((caloMjj>450 && l1Accept->at(L1scenario)==1) || hltAccept->at(HT410PF)==1, PFMjj);
	  pf410_eff->Fill((hltAccept->at(HT410PF)==1 && l1Accept->at(L1scenario)==1), PFMjj);
	}
    }

  mjj450_eff->Fit(f1,"r");
  mjj200_eff->Fit(f2,"r");


  caloMjjSpectrum->Scale(1./caloMjjSpectrum->GetBinContent(caloMjjSpectrum->GetMaximumBin()));
  PFMjjSpectrum->Scale(1./PFMjjSpectrum->GetBinContent(PFMjjSpectrum->GetMaximumBin()));

			      
  
  TLegend* leg0 = new TLegend(0.62, 0.78, 0.83, 0.89);
  leg0->AddEntry(mjj200_eff,"MJJ200Calo || HT250Calo","L");
  leg0->AddEntry(calo250_eff,"HT250_Calo","P");
  leg0->AddEntry(HTT240_eff,"HTT240","P");

  TLegend* leg1 = new TLegend(0.62, 0.78, 0.83, 0.89);
  leg1->AddEntry(mjj450_eff,"MJJ450PF || HT410PF","L");
  leg1->AddEntry(pf410_eff,"HT410_PF","P");

  TCanvas* c1 = new TCanvas();
  mjj200_eff->Draw();
  calo250_eff->Draw("sames");
  HTT240_eff->Draw("sames");
  caloMjjSpectrum->Draw("L,sames");
  leg0->Draw("sames");

  TCanvas* c2 = new TCanvas();
  mjj450_eff->Draw();
  pf410_eff->Draw("sames");
  PFMjjSpectrum->Draw("L,sames");
  leg1->Draw("sames");

  TCanvas* c3 = new TCanvas();
  //l1->Scale(PDRate/nentries);

  for(unsigned int ii=0; ii<l1Names->size(); ++ii)
    l1->GetXaxis()->SetBinLabel(ii+1,l1Names->at(ii).c_str());
  //l1->GetYaxis()->SetTitle("L1 Rate @4E33 [Hz]");
  l1->SetMaximum(l1->GetMaximum()+200);
  l2->SetLineColor(kRed);
  
  l1->Draw();
  l2->Draw("same");
  c3->Update();

  // TGaxis *l1axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
  // 			      l1->GetMinimum()*lumiScaleFactor,
  // 			      l1->GetMaximum()*lumiScaleFactor,510,"+L");

  // c2->SetTicky(0);
  // l1axis->SetLineColor(kRed);
  // l1axis->SetLabelColor(kRed);
  // l1axis->SetTextColor(kRed);
  // l1axis->SetTitleOffset(1.3);
  // l1axis->SetLabelSize(0.03);
  // l1axis->SetTitle("L1 Rate @1E34 [Hz]");
  // l1axis->Draw();
  
  
  //return 0;

  //##############################################
  //##############################################

  //book graphs and plots
  TGraphErrors* totRateVsCut = new TGraphErrors();
  totRateVsCut->SetMinimum(0);
  TGraphErrors* pureRateVsCut450 = new TGraphErrors();
  TGraphErrors* pureRateVsCut280 = new TGraphErrors();

  //loops
  int bin = 0;
  for (int cut = 350; cut < 500; cut=cut+10)
    {
      int mjjPassed = 0;
      int HT250Calo_Passed = 0;
      int excl410_passed = 0;
      int excl250_passed = 0;
      for (Long64_t jentry=0; jentry<nentries;++jentry) 
	{
	  tt->GetEntry(jentry);

	  if (hltAccept->at(HT250Calo) == 1)
	    ++HT250Calo_Passed;

	  //if (caloMjj > cut && !hltAccept->at(HT410PF))
	  if (caloMjj > cut && l1Accept->at(L1scenario) == 1 && hltAccept->at(HT410PF)==0)
	    ++excl410_passed;
	  if (caloMjj > cut && l1Accept->at(L1scenario)==1 && hltAccept->at(HT250Calo)==0)
	    ++excl250_passed;
	  if (caloMjj > cut && l1Accept->at(L1scenario)==1)
	    ++mjjPassed;

	  // if (hltAccept->at(HT250Calo) == 0 && mjj > cut)
	  //   std::cout << "ref trigger doesn't completely cover cut at " << cut << std::endl;
	}
      // float mjjTotalRate = (float)mjjPassed/(float)HT250Calo_Passed*HT250Calo_rate;
      // float mjjPureRate = (float)exclPassed/(float)HT250Calo_Passed*HT250Calo_rate;

      float sigmaMjjPassed = sqrt((float)mjjPassed);
      float sigmaNentries = sqrt((float)nentries);
      float sigmaExcl410_passed = sqrt((float)excl410_passed);
      float sigmaExcl250_passed = sqrt((float)excl250_passed);

      float mjjTotalRate = (float)mjjPassed/(float)nentries*PDRate;
      float mjjTotalRateE = PDRate*sqrt(pow((sigmaMjjPassed/nentries),2)+pow((sigmaNentries*mjjPassed/nentries/nentries),2));

      float mjj450_PureRate = (float)excl410_passed/(float)nentries*PDRate;
      float mjj450_PureRateE = PDRate*sqrt(pow((sigmaExcl410_passed/nentries),2)+pow((sigmaNentries*excl410_passed/nentries/nentries),2));
      
      float mjj280_PureRate = (float)excl250_passed/(float)nentries*PDRate;
      float mjj280_PureRateE = PDRate*sqrt(pow((sigmaExcl250_passed/nentries),2)+pow((sigmaNentries*excl250_passed/nentries/nentries),2));

      totRateVsCut->SetPoint(bin,cut,mjjTotalRate);
      totRateVsCut->SetPointError(bin,0.,mjjTotalRateE);

      pureRateVsCut450->SetPoint(bin,cut,mjj450_PureRate);
      pureRateVsCut450->SetPointError(bin,0.,mjj450_PureRateE);

      pureRateVsCut280->SetPoint(bin,cut,mjj280_PureRate);
      pureRateVsCut280->SetPointError(bin,0.,mjj280_PureRateE);

      ++bin;
    }

  //plotting and styling
  TLegend* leg = new TLegend(0.62, 0.78, 0.83, 0.89);
  leg->AddEntry(totRateVsCut,"total rate","P");
  leg->AddEntry(pureRateVsCut450,"pure rate wrt HT410PF","P");
  leg->AddEntry(pureRateVsCut280,"pure rate wrt HT250Calo","P");

  totRateVsCut->SetTitle("Rate Ref");

  totRateVsCut->GetXaxis()->SetTitle("Mjj cut threshold [GeV]");
  totRateVsCut->GetYaxis()->SetTitle("Rate @4E33 [Hz]");
  pureRateVsCut450->SetMarkerColor(kRed);
  pureRateVsCut450->SetLineColor(kRed);
  pureRateVsCut280->SetMarkerColor(kOrange+1);
  pureRateVsCut280->SetLineColor(kOrange+1);

  TCanvas* c4 = new TCanvas();
  c4->cd();
  totRateVsCut->Draw("AP");
  pureRateVsCut450->Draw("P,sames");
  pureRateVsCut280->Draw("P,sames");
  leg->Draw("sames");
  c4->Update();

  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(), gPad->GetUymax(),
    			    (totRateVsCut->GetYaxis()->GetBinLowEdge(1))*lumiScaleFactor,
			    (totRateVsCut->GetYaxis()->GetBinLowEdge(totRateVsCut->GetYaxis()->GetNbins())+totRateVsCut->GetYaxis()->GetBinWidth(1))*lumiScaleFactor,510,"+L");

  c4->SetTicky(0);
  axis->SetLineColor(kRed);
  axis->SetLabelColor(kRed);
  axis->SetTextColor(kRed);
  axis->SetTitleOffset(1.3);
  axis->SetLabelSize(0.03);
  axis->SetTitle("Rate @1E34 [Hz]");
  axis->Draw();


  return 0;
}
Example #24
0
/*
void makeEff(TString fin){

  c1 = new TCanvas("c1","",1360,768);
  f= TFile::Open(fin.Data());
  TH1F * th1 = (TH1F*)f->FindObjectAny("HMass");
  int width [nWidth]={30,35,50,45,50};
  int bmin[nBmin]={91,93,95,97,99,101,103,105,107,109};
  double eff[nWidth][nBmin];
  for(int i=0;i<nWidth;i++){
    for(int j=0;j<nBmin;j++){
      eff[i][j]=getEff(th1,bmin[j],bmin[j]+width[i]);
      cout<<"range={"<<bmin[j]<<","<<bmin[j]+width[i]<<"} and efficiency="<<eff[i][j]<<endl;
    }
  }
}
*/
void makeEffPRN0922() {
    c1 = new TCanvas("c1","",1360,768);
    c2 = new TCanvas("c2","",1360,768);
    c1->cd();
    string output="FATjetATLASmassL2L3Corr";
    int twikiSign[13][nWidth][nBmin];
    int twikiSignNum[13][nWidth][nBmin];
    double twikiSignValue[13][nWidth][nBmin];
    double twikiSignNumValue[13][nWidth][nBmin];
    double twikiEffValue[13][nWidth][nBmin];
    double tgraphMass[13]= {600,800,1000,1200,1400,1600,1800,2000,2500,3000,3500,4000,4500};
    double tgraphMassError[13]= {0};
    double tgraphSigEff[13]= {0};
    double tgraphSigEffError[13]= {0};
    double tgraphBkgEff[13]= {0};
    double tgraphBkgEffError[13]= {0};
    double tgraphSgnEff[13]= {0};
    double tgraphSgnEffError[13]= {0};
    double tgraphSigEff145[13]= {0};
    double tgraphSigEffError145[13]= {0};
    double tgraphBkgEff145[13]= {0};
    double tgraphBkgNum145[13]= {0};
    double tgraphBkgNum[13]= {0};
    double tgraphBkgEffError145[13]= {0};
    double tgraphSgnEff145[13]= {0};
    double tgraphSgnEffError145[13]= {0};
    //double twikiEffNumValue[13][nWidth][nBmin];
    //double twikiWidth[13][nWidth][nBmin];
    //double twikiBmin[13][nWidth][nBmin];
    //string  masspoint[4]={"1000","2000","3000","4500"};
    string  masspoint[13]= {"600","800","1000","1200","1400","1600","1800","2000","2500","3000","3500","4000","4500"};
    int width [nWidth]= {20,25,30,35,40,45,50,55,60};
    int bmin[nBmin]= {90,95,100,105,110};
    for (int massP=0; massP<13; massP++) {
        TString fin =Form("root_files/signal-%s.root",masspoint[massP].data()),
                fin2 = Form("root_files/DY-%s.root",masspoint[massP].data());
        // fin2=Form("root_files/DYHTall-%s.root",masspoint[massP].data());
        f= TFile::Open(fin.Data());
        f2= TFile::Open(fin2.Data());
        TH1F * th1 = (TH1F*)f->FindObjectAny("FATjetPRmassL2L3Corr");
        TH1F * th2 = (TH1F*)f2->FindObjectAny("FATjetPRmassL2L3Corr");

        //TString fin3 = Form("root_files/BulkGravitonZlepZqq-%s.root",masspoint[massP].data());
        //f3= TFile::Open(fin3.Data());
        //TH1F * th3 = (TH1F*)f3->FindObjectAny("HMass");
        //cout<<"before"<<th2->GetEntries()<<endl;
        th2->Sumw2();
        //th2->Add(th3);
        //cout<<"after"<<th2->GetEntries()<<endl;
        double eff[nWidth][nBmin],eff2[nWidth][nBmin],err[nWidth][nBmin],err2[nWidth][nBmin],err2Num[nWidth][nBmin];
        double sign[nWidth][nBmin],signCP[nWidth][nBmin],signErr[nWidth][nBmin];
        double signNum[nWidth][nBmin],signNumCP[nWidth][nBmin],signNumErr[nWidth][nBmin];
        for(int i=0; i<nWidth; i++) {
            for(int j=0; j<nBmin; j++) {
                eff[i][j]=getEff(th1,bmin[j],bmin[j]+width[i]);
                eff2[i][j]=getEff(th2,bmin[j],bmin[j]+width[i]);
                //if(eff2[i][j]==0)cout<<massP<<","<<eff2[i][j]<<endl;
                err[i][j]=getErr(th1,bmin[j],bmin[j]+width[i]);
                err2[i][j]=getErr(th2,bmin[j],bmin[j]+width[i]);
                err2Num[i][j]=getErr2(th2,bmin[j],bmin[j]+width[i]);
                //if(massP==0)cout<<"method1="<<err2[i][j]<<",method2="<<err2Num[i][j]/th2->Integral()<<endl;
                sign[i][j]=getSign(eff[i][j],eff2[i][j]);
                signNum[i][j]=getSign(eff[i][j],eff2[i][j]*th2->Integral());
                signCP[i][j]=sign[i][j];
                signNumCP[i][j]=signNum[i][j];
                signErr[i][j]=(1/(1+sqrt(eff2[i][j])))*sqrt(err[i][j]*err[i][j]+ (eff[i][j]*eff[i][j]*err2[i][j]*err2[i][j])/(4*eff2[i][j]*(1+sqrt(eff2[i][j]))*(1+sqrt(eff2[i][j]))));
                //signNumErr[i][j]=(1/(1+sqrt(eff2[i][j]*th2->Integral())))*sqrt(err[i][j]*err[i][j]+ (eff[i][j]*eff[i][j]*err2[i][j]*err2[i][j]*th2->Integral())/(4*eff2[i][j]*(1+sqrt(eff2[i][j]*th2->Integral()))*(1+sqrt(eff2[i][j]*th2->Integral()))));
                signNumErr[i][j]=(1/(1+sqrt(eff2[i][j]*th2->Integral())))*sqrt(err[i][j]*err[i][j]+ (eff[i][j]*eff[i][j]*err2Num[i][j]*err2Num[i][j])/(4*eff2[i][j]*th2->Integral()*(1+sqrt(eff2[i][j]*th2->Integral()))*(1+sqrt(eff2[i][j]*th2->Integral()))));
                if(eff2[i][j]<1e-7) {
                    signErr[i][j]=err[i][j]/(1+sqrt(eff2[i][j]));
                    signNumErr[i][j]=err[i][j]/(1+sqrt(eff2[i][j]*th2->Integral()));
                }
                if(massP==2 &&i==3 && j==3) {
                    tgraphBkgNum145[massP]=eff2[i][j]*th2->Integral();
                    tgraphSigEff145[massP]=eff[i][j];
                    tgraphSigEffError145[massP]=err[i][j];
                    tgraphBkgEff145[massP]=eff2[i][j];
                    tgraphBkgEffError145[massP]=err2[i][j];
                    tgraphSgnEff145[massP]=signNum[i][j];
                    tgraphSgnEffError145[massP]=signNumErr[i][j];
                }
                else if (massP==7 &&i==2 && j==2) {
                    tgraphBkgNum145[massP]=eff2[i][j]*th2->Integral();
                    tgraphSigEff145[massP]=eff[i][j];
                    tgraphSigEffError145[massP]=err[i][j];
                    tgraphBkgEff145[massP]=eff2[i][j];
                    tgraphBkgEffError145[massP]=err2[i][j];
                    tgraphSgnEff145[massP]=signNum[i][j];
                    tgraphSgnEffError145[massP]=signNumErr[i][j];
                }
                else if (massP==9 &&i==2 && j==2) {
                    tgraphBkgNum145[massP]=eff2[i][j]*th2->Integral();
                    tgraphSigEff145[massP]=eff[i][j];
                    tgraphSigEffError145[massP]=err[i][j];
                    tgraphBkgEff145[massP]=eff2[i][j];
                    tgraphBkgEffError145[massP]=err2[i][j];
                    tgraphSgnEff145[massP]=signNum[i][j];
                    tgraphSgnEffError145[massP]=signNumErr[i][j];

                }
                else if (massP==11 &&i==4 && j==1) {

                    tgraphBkgNum145[massP]=eff2[i][j]*th2->Integral();
                    tgraphSigEff145[massP]=eff[i][j];
                    tgraphSigEffError145[massP]=err[i][j];
                    tgraphBkgEff145[massP]=eff2[i][j];
                    tgraphBkgEffError145[massP]=err2[i][j];
                    tgraphSgnEff145[massP]=signNum[i][j];
                    tgraphSgnEffError145[massP]=signNumErr[i][j];
                }

                else {}

                if(i==4 && j==3) {

                    //cout<<width[i]<<","<<bmin[j];



                }

                //cout<<"range={"<<bmin[j]<<","<<bmin[j]+width[i]<<"} and efficiency="<<eff[i][j]<<endl;
                //cout<<"range=["<<bmin[j]<<","<<bmin[j]+width[i]<<"] and significant="<<sign[i][j]<<endl;
                //if(massP==0)cout<<eff[i][j]<<","<<eff2[i][j]<<endl;
            }
        }

        vector<int> signI,signJ;
        for(int ij=0; ij<nWidth*nBmin; ij++) {
            double tempSign=0;
            int tempI=0,tempJ=0;
            for(int i=0; i<nWidth; i++) {
                for(int j=0; j<nBmin; j++) {
                    if(signCP[i][j]>tempSign) {
                        //cout<<"i="<<i<<",j="<<j<<",signcp="<<signCP[i][j]<<",temp="<<tempSign<<endl;
                        tempSign=signCP[i][j];
                        tempI=i;
                        tempJ=j;
                    }
                }
            }

            //cout<<signCP[tempI][tempJ]<<endl;
            signCP[tempI][tempJ]=0;
            if(width[tempI]+bmin[tempJ]>150) {

                continue;
            }
            //if(massP==0)cout<<"tempI"<<tempI<<",tempJ"<<tempJ<<endl;
            signI.push_back(tempI);
            signJ.push_back(tempJ);
        }

        vector<int> signINum,signJNum;
        for(int ij=0; ij<nWidth*nBmin; ij++) {
            double tempSign=0;
            int tempI=0,tempJ=0;
            for(int i=0; i<nWidth; i++) {
                for(int j=0; j<nBmin; j++) {
                    if(signNumCP[i][j]>tempSign) {
                        //cout<<"i="<<i<<",j="<<j<<",signcp="<<signCP[i][j]<<",temp="<<tempSign<<endl;
                        tempSign=signNumCP[i][j];
                        tempI=i;
                        tempJ=j;
                    }
                }
            }

            //cout<<signCP[tempI][tempJ]<<endl;
            signNumCP[tempI][tempJ]=0;
            if(width[tempI]+bmin[tempJ]>150) {
                //cout<<"!";
                continue;
            }
            signINum.push_back(tempI);
            signJNum.push_back(tempJ);
        }

        int numberBin=15;
        int numberBinFull=35;
        TH1F * th1Sign=new TH1F("Sign","Sign",numberBin,0,numberBin);
        TH1F * th1Eff=new TH1F("th1Eff","th1Eff",numberBin,0,numberBin);
        TH1F * th1Eff2=new TH1F("th1Eff2","th1Eff2",numberBin,0,numberBin);
        TH1F * th1SignFull=new TH1F("SignFull","SignFull",numberBinFull,0,numberBinFull);
        TH1F * th1EffFull=new TH1F("th1EffFull","th1EffFull",numberBinFull,0,numberBinFull);
        TH1F * th1Eff2Full=new TH1F("th1Eff2Full","th1Eff2Full",numberBinFull,0,numberBinFull);
        for(int i=0; i<numberBin; i++) {
            th1Sign->SetBinContent(i+1,sign[signI[i]][signJ[i]]);
            th1Sign->SetBinError(i+1,signErr[signI[i]][signJ[i]]);
            th1Eff->SetBinContent(i+1,eff[signI[i]][signJ[i]]);
            th1Eff2->SetBinContent(i+1,eff2[signI[i]][signJ[i]]);
            th1Eff->SetBinError(i+1,err[signI[i]][signJ[i]]);
            th1Eff2->SetBinError(i+1,err2[signI[i]][signJ[i]]);
            th1Sign->GetXaxis()->SetBinLabel(i+1,Form("%d-%d",bmin[signJ[i]],bmin[signJ[i]]+width[signI[i]]));
            //cout<<"range=["<<bmin[signJ[i]]<<","<<bmin[signJ[i]]+width[signI[i]]<<"] and significant="<<sign[signI[i]][signJ[i]]<<endl;
        }

        //cout<<"signI.size="<<signI.size()<<endl;
        for(unsigned int i=0; i<signI.size(); i++) {
            twikiSign[massP][signI[i]][signJ[i]]=i+1;

            th1SignFull->SetBinContent(i+1,sign[signI[i]][signJ[i]]);
            th1SignFull->SetBinError(i+1,signErr[signI[i]][signJ[i]]);
            th1EffFull->SetBinContent(i+1,eff[signI[i]][signJ[i]]);
            th1Eff2Full->SetBinContent(i+1,eff2[signI[i]][signJ[i]]);
            th1EffFull->SetBinError(i+1,err[signI[i]][signJ[i]]);
            th1Eff2Full->SetBinError(i+1,err2[signI[i]][signJ[i]]);
            //th1SignFull->GetXaxis()->SetBinLabel(i+1,Form("%d-%d",bmin[signJ[i]],bmin[signJ[i]]+width[signI[i]]));
            th1SignFull->GetXaxis()->SetBinLabel(i+1,"");
            twikiSignValue[massP][signI[i]][signJ[i]]=sign[signI[i]][signJ[i]];
            twikiEffValue[massP][signI[i]][signJ[i]]=eff[signI[i]][signJ[i]];
            //cout<<"range=["<<bmin[signJ[i]]<<","<<bmin[signJ[i]]+width[signI[i]]<<"] and significant="<<sign[signI[i]][signJ[i]]<<endl;
        }
        gStyle->SetOptStat(0000000000);


        th1Sign->SetTitle(Form("largest 15 Sign.(eff),%sGev",masspoint[massP].data()));
        th1Sign->SetMinimum(0);
        th1Sign->SetMaximum(1);
        th1Sign->SetLineColor(4);
        th1Sign->Draw();
        th1Eff->SetLineColor(2);
        th1Eff2->SetLineColor(3);
        th1Eff->Draw("same");
        th1Eff2->Draw("same");
        TLegend* leg ;
        leg=new TLegend(x1NDC,y1NDC,x2NDC,y2NDC);
        setLeg(leg);
        leg->AddEntry(th1Sign,"significance");
        leg->AddEntry(th1Eff,"signal efficiency");
        leg->AddEntry(th1Eff2,"Bkg. efficiency");
        leg->Draw("same");

        if(massP==0)c1->Print(Form("pdfPR/%s.pdf(",output.data()));
        //else if(massP==12)c1->Print("pdf/signv2.pdf)");
        else c1->Print(Form("pdfPR/%s.pdf",output.data()));

        th1SignFull->SetTitle(Form("all windows(eff),%sGev",masspoint[massP].data()));
        th1SignFull->SetMinimum(0);
        th1SignFull->SetMaximum(1);
        th1SignFull->SetLineColor(4);
        th1SignFull->Draw("Hist");
        th1EffFull->SetLineColor(2);
        th1Eff2Full->SetLineColor(3);
        th1EffFull->Draw("same");
        th1Eff2Full->Draw("same");
        leg->Draw("same");

        c1->Print(Form("pdfPR/%s.pdf",output.data()));

        for(int i=0; i<numberBin; i++) {
            if(i==0) {
                tgraphSigEff[massP]=eff[signINum[i]][signJNum[i]];
                tgraphSigEffError[massP]=err[signINum[i]][signJNum[i]];
                tgraphBkgEff[massP]=eff2[signINum[i]][signJNum[i]];
                tgraphBkgEffError[massP]=err2[signINum[i]][signJNum[i]];
                tgraphSgnEff[massP]=signNum[signINum[i]][signJNum[i]];
                tgraphSgnEffError[massP]=signNumErr[signINum[i]][signJNum[i]];
                tgraphBkgNum[massP]=eff2[signINum[i]][signJNum[i]]*th2->Integral();


            }
            th1Sign->SetBinContent(i+1,signNum[signINum[i]][signJNum[i]]);
            th1Sign->SetBinError(i+1,signNumErr[signINum[i]][signJNum[i]]);
            th1Eff->SetBinContent(i+1,eff[signINum[i]][signJNum[i]]);
            th1Eff2->SetBinContent(i+1,eff2[signINum[i]][signJNum[i]]);
            th1Eff->SetBinError(i+1,err[signINum[i]][signJNum[i]]);
            th1Eff2->SetBinError(i+1,err2[signINum[i]][signJNum[i]]);
            th1Eff->GetXaxis()->SetBinLabel(i+1,Form("%d-%d",bmin[signJNum[i]],bmin[signJNum[i]]+width[signINum[i]]));
            //cout<<"range=["<<bmin[signJ[i]]<<","<<bmin[signJ[i]]+width[signI[i]]<<"] and significant="<<sign[signI[i]][signJ[i]]<<endl;
        }


        for(unsigned int i=0; i<signINum.size(); i++) {
            twikiSignNum[massP][signINum[i]][signJNum[i]]=i+1;

            th1SignFull->SetBinContent(i+1,signNum[signINum[i]][signJNum[i]]);
            th1SignFull->SetBinError(i+1,signNumErr[signINum[i]][signJNum[i]]);
            th1EffFull->SetBinContent(i+1,eff[signINum[i]][signJNum[i]]);
            th1Eff2Full->SetBinContent(i+1,eff2[signINum[i]][signJNum[i]]);
            th1EffFull->SetBinError(i+1,err[signINum[i]][signJNum[i]]);
            th1Eff2Full->SetBinError(i+1,err2[signINum[i]][signJNum[i]]);
            //th1SignFull->GetXaxis()->SetBinLabel(i+1,Form("%d-%d",bmin[signJ[i]],bmin[signJ[i]]+width[signI[i]]));
            th1SignFull->GetXaxis()->SetBinLabel(i+1,"");
            th1EffFull->GetXaxis()->SetBinLabel(i+1,"");
            th1Eff2Full->GetXaxis()->SetBinLabel(i+1,"");
            twikiSignNumValue[massP][signINum[i]][signJNum[i]]=signNum[signINum[i]][signJNum[i]];
            th1EffFull->GetXaxis()->SetBinLabel(i+1,Form("%d-%d",bmin[signJNum[i]],bmin[signJNum[i]]+width[signINum[i]]));
            //twikiEffNumValue[massP][signINum[i]][signJNum[i]]=effNum[signINum[i]][signJNum[i]];
            //cout<<"range=["<<bmin[signJ[i]]<<","<<bmin[signJ[i]]+width[signI[i]]<<"] and significant="<<sign[signI[i]][signJ[i]]<<endl;
        }



        th1Eff->SetMinimum(0);
        th1Eff->SetMaximum(1);
        th1EffFull->SetMinimum(0);
        th1EffFull->SetMaximum(1);
        th1Eff->SetYTitle("efficiency");
        th1EffFull->SetYTitle("efficiency");
        th1Eff->SetTitle(Form("largest 15 Sign.(Num),%sGev",masspoint[massP].data()));
        th1Eff->Draw();
        th1Eff2->Draw("same");

        Float_t rightmax = 2*th1Sign->GetBinContent(1);
        //cout<<rightmax<<endl;
        Float_t scale = gPad->GetUymax()/rightmax;
        //hint1->SetLineColor(kRed);
        th1Sign->Scale(scale);
        //hint1->Draw("same");
        //draw an axis on the right side
        c1->Update();
        th1Sign->Draw("same");
        //leg->Clear();
        //leg->AddEntry(th1Eff,"signal efficiency");
        //leg->AddEntry(th1Eff2,"Bkg. efficiency");
        //leg->SetY1(0.8335);
        leg->Draw("same");

        TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
                                  gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"+L");
        axis->SetTitle("significance");
        axis->SetTitleColor(4);
        axis->SetLineColor(4);
        axis->SetLabelColor(4);
        axis->Draw();

        c1->Print(Form("pdfPR/%s.pdf",output.data()));




        th1EffFull->SetTitle(Form("all windows(Num),%sGev",masspoint[massP].data()));
        th1EffFull->Draw();
        th1Eff2Full->Draw("same");
        c1->Update();
        rightmax = 1.1*th1SignFull->GetBinContent(1);
        scale = gPad->GetUymax()/rightmax;
        th1SignFull->Scale(scale);

        th1SignFull->Draw("Hist,same");
        leg->Draw("same");

        TGaxis *axis2 = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
                                   gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"+L");
        axis2->SetTitle("significance");
        axis2->SetTitleColor(4);
        axis2->SetLineColor(4);
        axis2->SetLabelColor(4);
        axis2->Draw();



        if(massP==12)c1->Print(Form("pdfPR/%s.pdf)",output.data()));
        else c1->Print(Form("pdfPR/%s.pdf",output.data()));

    }


    TLegend* leg ;
    leg=new TLegend(0.1441452,0.742447,0.300645,0.883966);
    setLeg(leg);
    c2->cd();
    TGraphErrors* tg1= new TGraphErrors(13,tgraphMass,tgraphSigEff,tgraphMassError,tgraphSigEffError);
    TGraphErrors* tg2= new TGraphErrors(13,tgraphMass,tgraphBkgEff,tgraphMassError,tgraphBkgEffError);
    TGraphErrors* tg3= new TGraphErrors(13,tgraphMass,tgraphSgnEff,tgraphMassError,tgraphSgnEffError);

    for(int i=0; i<13; i++) {
        //cout<<tgraphSigEff[i]<<","<<tgraphSigEff145[i];
        cout<<"i="<<i<<","<<tgraphSigEff[i]<<","<<tgraphBkgNum[i]<<","<<tgraphSgnEff[i]<<endl;
        cout<<"i="<<i<<","<<tgraphSigEff145[i]<<","<<tgraphBkgNum145[i]<<","<<tgraphSgnEff145[i]<<endl;
        tgraphSigEff[i]=tgraphSigEff[i]/tgraphSigEff145[i];
        //cout<<tgraphSigEff[i]<<endl;
        tgraphSigEffError[i]=sqrt((tgraphSigEffError[i]/tgraphSigEff[i])*(tgraphSigEffError[i]/tgraphSigEff[i])+(tgraphSigEffError145[i]/tgraphSigEff145[i])*(tgraphSigEffError145[i]/tgraphSigEff145[i]));
        tgraphSigEffError[i]*=tgraphSigEff[i];
        tgraphBkgEff[i]=tgraphBkgEff[i]/tgraphBkgEff145[i];
        tgraphBkgEffError[i]=sqrt((tgraphBkgEffError[i]/tgraphBkgEff[i])*(tgraphBkgEffError[i]/tgraphBkgEff[i])+(tgraphBkgEffError145[i]/tgraphBkgEff145[i])*(tgraphBkgEffError145[i]/tgraphBkgEff145[i]));
        tgraphBkgEffError[i]*=tgraphBkgEff[i];
        tgraphSgnEff[i]=tgraphSgnEff[i]/tgraphSgnEff145[i];
        tgraphSgnEffError[i]=sqrt((tgraphSgnEffError[i]/tgraphSgnEff[i])*(tgraphSgnEffError[i]/tgraphSgnEff[i])+(tgraphSgnEffError145[i]/tgraphSgnEff145[i])*(tgraphSgnEffError145[i]/tgraphSgnEff145[i]));
        tgraphSgnEffError[i]*=tgraphSgnEff[i];

    }

    TGraphErrors* tg4= new TGraphErrors(13,tgraphMass,tgraphSigEff,tgraphMassError,tgraphSigEffError);
    TGraphErrors* tg5= new TGraphErrors(13,tgraphMass,tgraphBkgEff,tgraphMassError,tgraphBkgEffError);
    TGraphErrors* tg6= new TGraphErrors(13,tgraphMass,tgraphSgnEff,tgraphMassError,tgraphSgnEffError);


    tg1->SetMaximum(1);
    tg1->SetMinimum(0);
    tg1->SetTitle("");
    tg1->GetXaxis()->SetTitle("Mass of Z' [GeV]");
    tg1->Draw("APL*");
    tg2->SetLineColor(2);
    tg3->SetLineColor(3);
    tg1->SetMarkerStyle(20);
    tg2->SetMarkerStyle(21);
    tg3->SetMarkerStyle(22);
    leg->Clear();
    tg1->SetFillColor(kWhite);
    tg2->SetFillColor(kWhite);
    tg3->SetFillColor(kWhite);
    gStyle->SetFillColor(kWhite) ;
    leg->AddEntry(tg1,"signal eff.");
    leg->AddEntry(tg2,"bkg. eff.");
    leg->AddEntry(tg3,"significance");
    tg2->Draw("PL,same");
    tg3->Draw("PL,same");
    leg->Draw("same");
    c2->Print("png/1.png");


    tg4->GetXaxis()->SetTitle("Mass of Z' [GeV]");
    tg4->SetTitle("most significant window/105-145");
    tg4->SetMaximum(2.2);
    tg4->SetMinimum(0.3);
    tg4->SetMarkerStyle(20);
    tg5->SetMarkerStyle(21);
    tg6->SetMarkerStyle(22);
    tg4->Draw("APL");
    tg5->SetLineColor(2);
    tg6->SetLineColor(3);

    leg->Clear();
    tg4->SetFillColor(kWhite);
    tg5->SetFillColor(kWhite);
    tg6->SetFillColor(kWhite);
    gStyle->SetFillColor(kWhite) ;
    leg->AddEntry(tg4,"signal eff. ratio");
    leg->AddEntry(tg5,"bkg. eff. ratio");
    leg->AddEntry(tg6,"significance ratio");
    tg5->Draw("PL,same");
    tg6->Draw("PL,same");
    leg->Draw("same");
    c2->Print("png/2.png");






    ofstream myfile;
    myfile.open ("txt/twikiOPPRN.txt");
    myfile<<"|*windowRange*|";
    for (int massP=0; massP<4; massP++)myfile<<"*"<<masspoint[massP].data()<<"Num*|";
    //myfile<<"*";
    for (int massP=0; massP<4; massP++)myfile<<"*"<<masspoint[massP].data()<<"Eff*|";
    myfile<<"*avg.rank(eff)*|*avg.rank(Num)*|*avg.rank(total)*|"<<endl;
    for(int j=0; j<nBmin; j++) {
        for(int i=0; i<nWidth; i++) {
            if(width[i]+bmin[j]>150)continue;
            myfile<<"|"<<bmin[j]<<"to"<<bmin[j]+width[i]<<"|";
            double temp1=0,temp2=0;
            for (int massP=0; massP<4; massP++) {
                myfile<<twikiSignNum[massP][i][j]<<"("<<twikiSignNumValue[massP][i][j]<<")|";
                temp1+=twikiSign[massP][i][j];
                temp2+=twikiSignNum[massP][i][j];
            }
            for (int massP=0; massP<4; massP++) {
                myfile<<twikiSign[massP][i][j]<<"("<<twikiSignValue[massP][i][j]<<")|";
            }
            myfile<<temp1/4<<"|"<<temp2/4<<"|"<<(temp1+temp2)/8<<"|"<<endl;
            //<<"to"<<bmin[i]+width[j]<<"|"<<endl;
            //cout<<j<<","<<i<<endl;
        }
    }
    myfile<<endl;



    myfile<<"|*rank(signalEff)*|";
    for (int massP=0; massP<4; massP++)myfile<<"*"<<masspoint[massP].data()<<"Eff*|";
    myfile<<endl;
    vector<int> signINum,signJNum;
//for(int ij=0;ij<nWidth*nBmin;ij++){
    for(int ij=0; ij<15; ij++) {
        myfile<<"|"<<ij+1<<"|";
        for (int massP=0; massP<4; massP++) {
            double tempSign=1000;
            int tempI=0,tempJ=0;
            //for(int i=0;i<nWidth;i++)for(int j=0;j<nBmin;j++)if(width[tempI]+bmin[tempJ]>150)twikiSign[massP][tempI][tempJ]=10000;

            for(int i=0; i<nWidth; i++) {
                for(int j=0; j<nBmin; j++) {
                    if(twikiSign[massP][i][j]<tempSign) {
                        if(width[i]+bmin[j]>150)continue;
                        //cout<<"i="<<i<<",j="<<j<<",signcp="<<signCP[i][j]<<",temp="<<tempSign<<endl;
                        tempSign=twikiSign[massP][i][j];
                        tempI=i;
                        tempJ=j;
                        //cout<<tempI<<","<<tempJ<<","<<tempSign<<endl;
                    }
                }
            }
            //signINum.push_back(tempI);
            //signJNum.push_back(tempJ);
            //cout<<signCP[tempI][tempJ]<<endl;
            //cout<<"twikiSign[massP][tempI][tempJ]="<<twikiSign[massP][tempI][tempJ]<<"|"<<bmin[tempJ]<<"to"<<bmin[tempJ]+width[tempI]<<"|"<<endl;
            twikiSign[massP][tempI][tempJ]=10000;
            //if(width[tempI]+bmin[tempJ]>150)continue;
            myfile<<bmin[tempJ]<<"to"<<bmin[tempJ]+width[tempI]<<"("<<setprecision(3)<<twikiEffValue[massP][tempI][tempJ]<<")|";
            //cout<<twikiSign[massP][tempI][tempJ];

        }
        myfile<<endl;
    }
    myfile<<endl;

    myfile<<"|*rank(signalEff)*|";
    for (int massP=0; massP<4; massP++)myfile<<"*"<<masspoint[massP].data()<<"Num*|";
    myfile<<endl;
    //vector<int> signINum,signJNum;
//for(int ij=0;ij<nWidth*nBmin;ij++){
    for(int ij=0; ij<15; ij++) {
        myfile<<"|"<<ij+1<<"|";
        for (int massP=0; massP<4; massP++) {
            double tempSign=10000;
            int tempI=0,tempJ=0;
            //for(int i=0;i<nWidth;i++)for(int j=0;j<nBmin;j++)if(width[tempI]+bmin[tempJ]>150)twikiSignNum[massP][tempI][tempJ]=10000;

            for(int i=0; i<nWidth; i++) {
                for(int j=0; j<nBmin; j++) {
                    if(twikiSignNum[massP][i][j]<tempSign) {
                        if(width[i]+bmin[j]>150)continue;
                        //cout<<"i="<<i<<",j="<<j<<",signcp="<<signCP[i][j]<<",temp="<<tempSign<<endl;
                        tempSign=twikiSignNum[massP][i][j];
                        tempI=i;
                        tempJ=j;
                        //cout<<tempI<<","<<tempJ<<","<<tempSign<<endl;
                    }
                }
            }
            //signINum.push_back(tempI);
            //signJNum.push_back(tempJ);
            //cout<<signCP[tempI][tempJ]<<endl;
            twikiSignNum[massP][tempI][tempJ]=10000;
            //if(width[tempI]+bmin[tempJ]>150)continue;
            myfile<<bmin[tempJ]<<"to"<<bmin[tempJ]+width[tempI]<<"("<<setprecision(3)<<twikiEffValue[massP][tempI][tempJ]<<")|";
            //cout<<twikiSign[massP][tempI][tempJ];

        }
        myfile<<endl;
    }
    myfile<<endl;
}
Example #25
0
void PlotField1D( const TString &sim, Int_t time, Int_t Nbins=1, const TString &options="") { 
  
#ifdef __CINT__  
  gSystem->Load("libplasma.so");
#endif

  PlasmaGlob::Initialize();
    
  TString opt = options;

  gStyle->SetPadLeftMargin(0.10);  // Margin left axis  
  gStyle->SetPadRightMargin(0.12); // Margin right axis 
  if(opt.Contains("grid")) {
    gStyle->SetPadGridX(1);
    gStyle->SetPadGridY(1);
  }

  // Load PData
  PData *pData = PData::Get(sim.Data());
  pData->LoadFileNames(time);
  if(!pData->IsInit()) return;

  Bool_t CYL = kFALSE;
  if(sim.Contains("cyl")) { CYL = kTRUE; opt += "cyl"; } 
    
  Bool_t ThreeD = kFALSE;
  if(sim.Contains("3D")) ThreeD = kTRUE; 

  // Some plasma constants
  Double_t n0 = pData->GetPlasmaDensity();
  Double_t kp = pData->GetPlasmaK();
  Double_t skindepth = 1/kp;
  Double_t E0 = pData->GetPlasmaE0();

  // Some beam properties:
  Float_t Ebeam = pData->GetBeamEnergy() * PUnits::MeV;
  Float_t gamma = Ebeam / PConst::ElectronMassE;
  Float_t vbeam = TMath::Sqrt(1 - 1/(gamma*gamma));
  // cout << Form(" - Bunch gamma      = %8.4f", gamma ) << endl;
  // cout << Form(" - Bunch velocity   = %8.4f c", vbeam ) << endl;

  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;
  Time -= zStartPlasma - zStartBeam;

  // 1D histograms
  TString opth1 = opt;
  opth1 += "avg";
  // Get electric fields
  const Int_t Nfields = 1;
  TH1F **hE1D = new TH1F*[Nfields];
  for(Int_t i=0;i<Nfields;i++) {
    hE1D[i] = NULL;
    if(!pData->GetEfieldFileName(i))
      continue;
    
    char nam[3]; sprintf(nam,"e%i",i+1);
    if(ThreeD) {
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins,opth1.Data());
      else  
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins,opth1.Data());
    } else if(CYL) { // Cylindrical: The firt bin with r>0 is actually the number 1 (not the 0).
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data());
      else
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opth1.Data());
    } else { // 2D cartesian
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opth1.Data());
      else 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opth1.Data());
    }
    
    char hName[24];
    sprintf(hName,"hE_%i",i);
    hE1D[i]->SetName(hName);
    if(opt.Contains("comov"))
      hE1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
    else
      hE1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
   
    if(i==0)
      hE1D[i]->GetYaxis()->SetTitle("E_{z} [E_{0}]");
    else if(i==1)
      hE1D[i]->GetYaxis()->SetTitle("E_{y} [E_{0}}]");
    else if(i==2)
      hE1D[i]->GetYaxis()->SetTitle("E_{x} [E_{0}}]");
    
    
  }  
  
  // Chaning to user units: 
  if(opt.Contains("units") && n0) {
    for(Int_t i=0;i<Nfields;i++) {
      Int_t NbinsX = hE1D[i]->GetNbinsX();
      Float_t xMin = (skindepth/PUnits::mm) * hE1D[i]->GetXaxis()->GetXmin();
      Float_t xMax = (skindepth/PUnits::mm) * hE1D[i]->GetXaxis()->GetXmax();
      
      hE1D[i]->SetBins(NbinsX,xMin,xMax);
      
      for(Int_t j=0;j<NbinsX;j++) {
	hE1D[i]->SetBinContent(j, hE1D[i]->GetBinContent(j) * ( E0 / (PUnits::GV/PUnits::m) ) );
      }
      
      if(opt.Contains("comov"))
	hE1D[i]->GetXaxis()->SetTitle("#zeta [mm]");
      else
	hE1D[i]->GetXaxis()->SetTitle("z [mm]");
      
      if(i==0)
	hE1D[i]->GetYaxis()->SetTitle("E_{z} [GV/m]");
      else if(i==1)
	hE1D[i]->GetYaxis()->SetTitle("E_{y} [GV/m]");
      else if(i==2)
	hE1D[i]->GetYaxis()->SetTitle("E_{x} [GV/m]");
    }
  }
  
  // Calculate wave positions:
  // ----------------------------------------------------------------
  
  // Retrieve the previous time TGraph if any;
  // Open TGraph
  TString filename = Form("./%s/Plots/Field1D/Field1D-%s.root",sim.Data(),sim.Data());
  TFile * ifile = (TFile*) gROOT->GetListOfFiles()->FindObject(filename);
  // if doesn't exist the directory should be created
  if (!ifile) {
    TString f = filename;
    TString dir2 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) );
    TString dir1 = f.Remove( f.Last( '/' ), f.Length() - f.Last( '/' ) );
    gSystem->mkdir( dir1 );
    gSystem->mkdir( dir2 );
    ifile = new TFile(filename,"UPDATE");
  }  
  
  
  
  Float_t *EMaxPos = new Float_t[Nfields];
  Float_t *EMaxValue = new Float_t[Nfields];
  
  // Get the Graph with the x1 positions of the maximum E_1
  TGraph **graph = new TGraph*[Nfields];
  char gName[24];
  for(Int_t i=0;i<Nfields;i++) {
    if(!hE1D[i]) continue;
    
    EMaxPos[i] = EMaxValue[i] = -999;
    
    // Initial time search window:
    Float_t xCenter = (hE1D[i]->GetXaxis()->GetXmin()+hE1D[i]->GetXaxis()->GetXmax())/2.; 
    Float_t xs1min = 0.5*(hE1D[i]->GetXaxis()->GetXmin()+xCenter);
    Float_t xs1max = xCenter;

    // For focusing fields i==1,2 we use a narrower window based on the previosly found 
    // minimum for the accelerating fields i==0.
    if(i>0) {
      xCenter = EMaxPos[0];
      if(opt.Contains("units") && n0) {
	xs1min = xCenter - (0.25*TMath::Pi() * 1e3 * skindepth);
	xs1max = xCenter + (0.25*TMath::Pi() * 1e3 * skindepth);
      } else {
	xs1min = xCenter - 0.25*TMath::Pi();
	xs1max = xCenter + 0.25*TMath::Pi();
      }
    }

    sprintf(gName,"gEMaxPos_%i",i);
    graph[i] =  (TGraph*) ifile->Get(gName);
    if(graph[i]) {
      Double_t *y = graph[i]->GetY();
      
      // Setup the searching windows to +/- pi/2 respect the last found minimum.
      if(opt.Contains("units") && n0) {
	xs1min = y[graph[i]->GetN()-1] - (0.5*TMath::Pi() * 1e3 * skindepth);
	xs1max = y[graph[i]->GetN()-1] + (0.5*TMath::Pi() * 1e3 * skindepth);
      } else {
	xs1min = y[graph[i]->GetN()-1] - 0.5*TMath::Pi();
	xs1max = y[graph[i]->GetN()-1] + 0.5*TMath::Pi();
      }
      
      delete graph[i];
    }
    
    TH1F *htemp = (TH1F*) hE1D[i]->Clone("htemp");
    htemp->GetXaxis()->SetRangeUser(xs1min,xs1max);
    
    //htemp->Smooth(1,"R");
    Int_t binMax = htemp->GetMinimumBin();
    EMaxPos[i] = (Float_t) htemp->GetBinCenter(binMax);
    EMaxValue[i] = (Float_t) htemp->GetBinContent(binMax);
    delete htemp;
    
  }
  
  
  // Tunning the Histograms
  // ---------------------
  
  
  // Plotting
  // -----------------------------------------------
  
  // Output file
  TString fOutName = Form("./%s/Plots/Field1D/Field1D",sim.Data());
  fOutName += Form("-%s_%i",sim.Data(),time);
  
  // Canvas setup
  TCanvas *C = new TCanvas("C","Electric wakefield on axis",850,1000);
  C->Divide(1,2);

  // Draw objects
  TPaveText *textTime = new TPaveText(0.70,0.87,0.85,0.92,"NDC");
  PlasmaGlob::SetPaveTextStyle(textTime); 
  char ctext[128];
  if(opt.Contains("units") && n0) 
    sprintf(ctext,"Z = %5.1f mm", 1e3 * skindepth * Time);
  else
    sprintf(ctext,"T = %5.1f 1/#omega_{p}",Time);
  textTime->AddText(ctext);
  
  // Colors
  Int_t fieldC  = PlasmaGlob::fieldLine;
  Int_t phaseC  = kGray+1;
 
  // Actual Plotting!
  // ------------------------------------------------------------

  // More makeup
  C->cd(1);
  gPad->SetGridy(0);
  gPad->SetGridx(0);
  gPad->SetFrameLineWidth(2);  

  hE1D[0]->SetLineWidth(1);
  hE1D[0]->GetYaxis()->CenterTitle();
  hE1D[0]->GetXaxis()->CenterTitle();
  hE1D[0]->SetLineStyle(1);
  hE1D[0]->SetLineWidth(3);
  hE1D[0]->SetLineColor(fieldC);
  hE1D[0]->SetMarkerStyle(20);

  if(Nfields>1) {
    hE1D[1]->GetYaxis()->CenterTitle();
    hE1D[1]->GetXaxis()->CenterTitle();
    hE1D[1]->SetLineStyle(1);
    hE1D[1]->SetLineWidth(1);  
    hE1D[1]->SetLineColor(fieldC);
    hE1D[1]->SetMarkerStyle(24);
  }

  Float_t factor = 1.5;
  Float_t minimum = factor * hE1D[0]->GetMinimum();
  Float_t maximum = factor * hE1D[0]->GetMaximum();
    
  if(Nfields>1) {
    if(hE1D[1]->GetMaximum() > hE1D[0]->GetMaximum()) {
      maximum = factor * hE1D[1]->GetMaximum();
    } 
    
    if(hE1D[1]->GetMinimum() < hE1D[0]->GetMinimum()) {
    minimum = factor * hE1D[1]->GetMinimum();
    } 
  }
  
  if( maximum >= TMath::Abs(minimum)) minimum = -maximum;
  else maximum = - minimum;
  
  hE1D[0]->GetYaxis()->SetRangeUser(minimum,maximum);
  hE1D[0]->Draw("C");
  
  if(Nfields>1)
    hE1D[1]->Draw("C same");
  
  C->Update();
  
  TLine *line0 = new TLine(hE1D[0]->GetXaxis()->GetXmin(),
			   (gPad->GetUymin()+gPad->GetUymax())/2.,
			   hE1D[0]->GetXaxis()->GetXmax(),
			   (gPad->GetUymin()+gPad->GetUymax())/2.);
  line0->SetLineColor(kGray+1);
  line0->SetLineStyle(2);
  line0->Draw();
  
  TMarker *markEMax0 = new TMarker(EMaxPos[0],EMaxValue[0], 24);
  markEMax0->SetMarkerColor(fieldC);
  markEMax0->SetMarkerSize(1.6);
  markEMax0->Draw();

  if(Nfields>1) {
    TMarker *markEMax1 = new TMarker(EMaxPos[1],EMaxValue[1], 24);
    markEMax1->SetMarkerColor(fieldC);
    markEMax1->SetMarkerSize(1.4);
    markEMax1->Draw();
  }
  
  textTime->Draw();

  // ----
  
  // Define the TGraphs
  Int_t nPoints = 0;  
  TGraph **gEMaxPos = new TGraph*[Nfields];
  TGraph **gEMaxValue = new TGraph*[Nfields];
  for(Int_t i=0;i<Nfields;i++) {
    if(!hE1D[i]) continue;

    sprintf(gName,"gEMaxPos_%i",i);
    gEMaxPos[i] = (TGraph*) ifile->Get(gName);
    if(gEMaxPos[i]==NULL) {
      gEMaxPos[i] = new TGraph();
      gEMaxPos[i]->SetName(gName);
    } else {
      nPoints = gEMaxPos[i]->GetN(); 
    }  
    gEMaxPos[i]->Set(nPoints+1);
    if(opt.Contains("units") && n0) 
      gEMaxPos[i]->SetPoint(nPoints, 1e3 * skindepth * Time,EMaxPos[i]);
    else
      gEMaxPos[i]->SetPoint(nPoints,Time,EMaxPos[i]);
    
    if(opt.Contains("units") && n0) {
      gEMaxPos[i]->GetYaxis()->SetTitle("#zeta_{min} [mm]");
      gEMaxPos[i]->GetXaxis()->SetTitle("Z [mm]");
    } else {
      gEMaxPos[i]->GetYaxis()->SetTitle("#zeta_{min} [c/#omega_{p}]");
      gEMaxPos[i]->GetXaxis()->SetTitle("T [c/#omega_{p}]");
    }

    gEMaxPos[i]->Write(gEMaxPos[i]->GetName(),TObject::kOverwrite);

    sprintf(gName,"gEMaxValue_%i",i);
    gEMaxValue[i] = (TGraph*) ifile->Get(gName);
    if(gEMaxValue[i]==NULL) {
      gEMaxValue[i] = new TGraph();  
      gEMaxValue[i]->SetName(gName);
    } else {
      nPoints = gEMaxValue[i]->GetN(); 
    }  
    gEMaxValue[i]->Set(nPoints+1);
    if(opt.Contains("units") && n0) 
      gEMaxValue[i]->SetPoint(nPoints, 1e3 * skindepth * Time,EMaxValue[i]);
    else
      gEMaxValue[i]->SetPoint(nPoints,Time,EMaxValue[i]);
    
    if(opt.Contains("units") && n0) {
      gEMaxValue[i]->GetYaxis()->SetTitle("E_{min} [GV/m]");
      gEMaxValue[i]->GetXaxis()->SetTitle("Z [mm]");
    } else {
      gEMaxValue[i]->GetYaxis()->SetTitle("E_{min} [E_{0}]");
      gEMaxValue[i]->GetXaxis()->SetTitle("T [c/#omega_{p}]");
    }
    
    gEMaxValue[i]->Write(gEMaxValue[i]->GetName(),TObject::kOverwrite);    
  }


  C->cd(2);
  gPad->SetGridy(1);
  gPad->SetGridx(0);
  gPad->SetFrameLineWidth(2);  

  Float_t minPhase = 99.;
  Float_t maxPhase = -99.;
  Float_t minField = 99.;
  Float_t maxField = -99.;

  Double_t *yEMaxPos[Nfields];
  Double_t *yEMaxValue[Nfields];

  for(Int_t i=0;i<Nfields;i++) {
    yEMaxPos[i]   = gEMaxPos[i]->GetY();
    yEMaxValue[i] = gEMaxValue[i]->GetY();
    
    for(Int_t j=0;j<gEMaxPos[0]->GetN();j++) {
      if(yEMaxPos[i][j]>maxPhase)
	maxPhase = yEMaxPos[i][j];
      if(yEMaxPos[i][j]<minPhase)
	minPhase = yEMaxPos[i][j];
 
      if(yEMaxValue[i][j]>maxField)
	maxField = yEMaxValue[i][j];
      if(yEMaxValue[i][j]<minField)
	minField = yEMaxValue[i][j];
    }
  }

  Float_t margin = (maxPhase - minPhase)/10;
  gEMaxPos[0]->GetYaxis()->SetRangeUser(minPhase-margin,maxPhase+margin);
  gEMaxPos[0]->GetYaxis()->CenterTitle();
  gEMaxPos[0]->GetXaxis()->CenterTitle();
  gEMaxPos[0]->SetLineColor(phaseC);
  gEMaxPos[0]->SetMarkerColor(phaseC);
  gEMaxPos[0]->SetLineWidth(3);
  gEMaxPos[0]->SetMarkerStyle(20);
  gEMaxPos[0]->SetMarkerSize(1.4);
  gEMaxPos[0]->Draw("APC");

  if(Nfields>1) {
    gEMaxPos[1]->SetLineStyle(1);
    gEMaxPos[1]->SetLineColor(phaseC);
    gEMaxPos[1]->SetMarkerColor(phaseC);
    gEMaxPos[1]->SetLineWidth(1);
    gEMaxPos[1]->SetMarkerStyle(24);
    gEMaxPos[1]->SetMarkerSize(1.4);
    gEMaxPos[1]->Draw("PC");
  }

  // Emax value
  // New axis first:
  C->Update();  // Needed for the axis!

  margin = (maxField - minField)/10;
  if (margin==0) margin = 1; 
  Float_t rightmin = minField-margin;
  Float_t rightmax = maxField+margin;
  Float_t slope = (gPad->GetUymax() - gPad->GetUymin())/(rightmax-rightmin);
  TGaxis *axisEmax = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(),
				gPad->GetUymax(),rightmin,rightmax,505,"+L");
  axisEmax->SetLineWidth(1);
  axisEmax->SetLineColor(fieldC);
  axisEmax->SetLabelColor(fieldC);
  axisEmax->SetTitleColor(fieldC);
  if(opt.Contains("units") && n0) 
    axisEmax->SetTitle("E_{min} [GV/m]");
  else
    axisEmax->SetTitle("E_{min} [E_{0}]");
  axisEmax->CenterTitle();
  axisEmax->SetTitleSize(0.05);
  axisEmax->SetTitleOffset(1.2);
  axisEmax->SetLabelSize(0.05);
  axisEmax->SetLabelOffset(0.006);
  
  axisEmax->Draw();
  
  // Adjust the TGraph
  Double_t *x = gEMaxValue[0]->GetX();
  Double_t *y = gEMaxValue[0]->GetY();
  for(Int_t i=0;i<gEMaxValue[0]->GetN();i++) {
    gEMaxValue[0]->SetPoint(i,x[i],(y[i]-rightmin)*slope + gPad->GetUymin());
  }  
  gEMaxValue[0]->SetLineColor(fieldC);
  gEMaxValue[0]->SetMarkerColor(fieldC);
  gEMaxValue[0]->SetLineWidth(3);
  gEMaxValue[0]->SetMarkerStyle(20);
  gEMaxValue[0]->SetMarkerSize(1.4);
  gEMaxValue[0]->Draw("PC");

   if(Nfields>1) {
    x = gEMaxValue[1]->GetX();
    y = gEMaxValue[1]->GetY();
    for(Int_t i=0;i<gEMaxValue[1]->GetN();i++) {
      gEMaxValue[1]->SetPoint(i,x[i],(y[i]-rightmin)*slope + gPad->GetUymin());
    }  
    gEMaxValue[1]->SetLineColor(fieldC);
    gEMaxValue[1]->SetMarkerColor(fieldC);
    gEMaxValue[1]->SetLineWidth(1);
    gEMaxValue[1]->SetMarkerStyle(24);
    gEMaxValue[1]->SetMarkerSize(1.4);
    gEMaxValue[1]->Draw("PC");
  }

  // Emax value
  // New axis first:
  C->Update();  // Needed for the axis!

  C->cd();

  ifile->Close();
  
  // Print to a file
  PlasmaGlob::imgconv(C,fOutName,opt);
  // ---------------------------------------------------------
  
  }