Пример #1
0
//_____________________________________________________________________________
void ProofEventProc::Terminate()
{
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.

   // Check ranges
   CheckRanges();

   if (gROOT->IsBatch()) return;
   
   TCanvas* canvas = new TCanvas("event","event",800,10,700,780);
   canvas->Divide(2,2);
   TPad *pad1 = (TPad *) canvas->GetPad(1);
   TPad *pad2 = (TPad *) canvas->GetPad(2);
   TPad *pad3 = (TPad *) canvas->GetPad(3);
   TPad *pad4 = (TPad *) canvas->GetPad(4);

   // The number of tracks
   pad1->cd();
   pad1->SetLogy();
   TH1F *hi = dynamic_cast<TH1F*>(fOutput->FindObject("pz_dist"));
   if (hi) {
      hi->SetFillColor(30);
      hi->SetLineColor(9);
      hi->SetLineWidth(2);
      hi->DrawCopy();
   } else { Warning("Terminate", "no pz dist found"); }

   // The Pt distribution
   pad2->cd();
   pad2->SetLogy();
   TH1F *hf = dynamic_cast<TH1F*>(fOutput->FindObject("pt_dist"));
   if (hf) {
      hf->SetFillColor(30);
      hf->SetLineColor(9);
      hf->SetLineWidth(2);
      hf->DrawCopy();
   } else { Warning("Terminate", "no pt dist found"); }

   // The Px,Py distribution, color surface
   TH2F *h2f = dynamic_cast<TH2F*>(fOutput->FindObject("px_py"));
   if (h2f) {
      // Color surface
      pad3->cd();
      h2f->DrawCopy("SURF1 ");
      // Lego
      pad4->cd();
      h2f->DrawCopy("CONT2COL");
   } else {
      Warning("Terminate", "no px py found");
   }

   // Final update
   canvas->cd();
   canvas->Update();
}
void testIlcGlauberQuenching() {

  IlcFastGlauber g;
  g.Init(2);
  g.SetCentralityClass(0.00,0.10); // centrality (fraction of geometrical cross section)

  IlcQuenchingWeights afq;
  afq.InitMult();
  afq.SetQTransport(1.);
  afq.SetECMethod(0);
  afq.SetLengthMax(8.);
  afq.SampleEnergyLoss();

  TCanvas *c = new TCanvas("cELD","Energy Loss Distribution",0,0,800,500);
  c->Divide(2,1);

  for(Int_t itype=1;itype<=2;itype++){
    c->cd(itype);
    gPad->SetLogy();
    Char_t name[100];
    Char_t hname[100];
    if(itype==1){
      sprintf(name,"Energy Loss Distribution - Quarks;E_{loss} (GeV);#"); 
      sprintf(hname,"hQuarks"); 
    } else {
      sprintf(name,"Energy Loss Distribution - Gluons;E_{loss} (GeV);#"); 
      sprintf(hname,"hGluons"); 
    }

    TH1F *h = new TH1F(hname,name,100,0,200);

    for(Int_t i=0;i<10000;i++){
      if(i % 100 == 0) cout << "." << flush;
      Double_t ell;
      g.GetLength(ell);
      Double_t loss=afq.GetELossRandom(itype,ell);
      h->Fill(loss);
    }

    h->SetStats(kTRUE);
    if(itype==1){
      h->SetLineColor(1);
      h->DrawCopy();
    }
    else {
      h->SetLineColor(2);
      h->DrawCopy();
    }
    delete h;
  }

  c->Update();
}
// second example using ell distribution
void testFastIlcGlauberQuenching(Char_t *fname) {

  TFile f(fname);
  TH1F *hEll=(TH1F*)f.Get("hEll");
  if(!hEll) return;

  IlcQuenchingWeights afq;
  afq.InitMult();
  afq.SetQTransport(1.);
  afq.SetECMethod(0);
  afq.SetLengthMax(5.);
  afq.SampleEnergyLoss();

  TCanvas *c = new TCanvas("cELD","Energy Loss Distribution",0,0,800,500);
  c->Divide(2,1);

  for(Int_t itype=1;itype<=2;itype++){
    c->cd(itype);
    gPad->SetLogy();
    Char_t name[200];
    if(itype==1)
      sprintf(name,"Energy Loss Distribution - Quarks;E_{loss} (GeV);#"); 
    else 
      sprintf(name,"Energy Loss Distribution - Gluons;E_{loss} (GeV);#"); 
    Char_t hname[200];
    if(itype==1)
      sprintf(hname,"hQuarks"); 
    else 
      sprintf(hname,"hGluons"); 

    TH1F *h = afq.ComputeELossHisto(itype,1.,hEll);

    h->SetStats(kTRUE);
    if(itype==1){
      h->SetLineColor(1);
      h->DrawCopy();
    }
    else {
      h->SetLineColor(2);
      h->DrawCopy();
    }
    delete h;
  }

  c->Update();
}
Пример #4
0
//================================================
void toyMC_Cent()
{
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(1);
  gStyle->SetStatY(0.9);                
  gStyle->SetStatX(0.9);  
  gStyle->SetStatW(0.2);                
  gStyle->SetStatH(0.2);

  myRandom = new TRandom3();
  TDatime *clock = new TDatime();
  myRandom->SetSeed(clock->GetTime());


  // Get true refMult vs Ncoll distribution
  TH2F *hRefMultVsNcoll = 0x0;

  // Get different efficiency curve vs. refMult
  const int nEff = 2;
  const int nMult = 2;
  TF1 *funcEff[nEff];
  funcEff[0] = new TF1("funcEff_0", "pol1",0,1000);
  funcEff[0]->SetParameters(0.9, -2e-4);
  funcEff[1] = new TF1("funcEff_1", "pol0",0,1000);
  funcEff[1]->SetParameter(0,0.6);
  TCanvas *c = new TCanvas("cEff","cEff",800,600);
  TH1F *hplot = new TH1F("hplot",";Mult;",100,0,1000);
  hplot->SetYTitle("Efficiency");
  hplot->DrawCopy();
  for(int i=0; i<2; i++)
    {
      funcEff[i]->SetLineColor(i+1);
      funcEff[i]->SetLineWidth(1.5);
      funcEff[i]->Draw("sames");
    }
  TPaveText *title = GetTitleText("TPC tracking efficiency");
  title->Draw();
  TLegend *leg = new TLegend(0.4,0.2,0.7,0.4);
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->SetTextSize(0.04);
  leg->AddEntry(funcEff[0], "Efficiency 1", "L");
  leg->AddEntry(funcEff[1], "Efficiency 2", "L");
  leg->Draw();

  // Get ngTrack distribution to mimic efficiency distribution
  
  TH1F *hMcMult[nMult];
  
}
Пример #5
0
void plot1D( TH2F* hul ){

  cout << "PLOT1D" << endl;
  TFile* f = TFile::Open("stop_xsec.root");
  TH1F* hxsec = (TH1F*) f->Get("h_stop_xsec");

  TH1F* hulproj = (TH1F*) hul->ProjectionX("hulproj",1,1);

  TCanvas* cproj = new TCanvas();
  gPad->SetLogy();

  hulproj->Draw("hist");

  hxsec->SetLineColor(2);
  hxsec->DrawCopy("samehistl");

  hxsec->SetLineColor(4);
  hxsec->Scale(1.15);
  hxsec->DrawCopy("samehistl");

  hxsec->Scale(0.85/1.15);
  hxsec->DrawCopy("samehistl");

}
void display(){
  
  gROOT->ProcessLine(".x lhcbStyle.C");
  gStyle->SetPalette(1);
	
  string filename = "../analysed/SET9THL914.root";
	TFile* file = new TFile(filename.c_str(),"OPEN");

	int nBinsX=32; int nBinsY=32;
	int nPixelsX=64; int nPixelsY=64;
	
  std::cout<<"Making global intercept tot map"<<std::endl;
  // Global intercept map (not per pixel)
	TH2F* hToTMap = new TH2F("hToTMap","hToTMap",nBinsX,0,nPixelsX,nBinsY,0,nPixelsY);
	for(int x=0;x<nBinsX;x++){
		for(int y=0;y<nBinsY;y++){
			int id = x + y*nBinsX;
			// Get the ToT distribution for this location
			string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixMap"+makestring(id);
			TH1F* totMapHisto = 0;
			totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
			if(totMapHisto == 0) continue;
			if(totMapHisto->GetEntries() < 20) continue;
	
			// Fit the tot distribution and enter the value in the ToT map
			totMapHisto->Fit("gaus","0q");
			TF1* fit = totMapHisto->GetFunction("gaus");
			hToTMap->Fill(x*floor(nPixelsX/nBinsX),y*floor(nPixelsY/nBinsY),fit->GetParameter(1));
			
			delete fit; delete totMapHisto;
		}
	}
	// Plot the map of ToT
	TCanvas* canv = new TCanvas();
	hToTMap->GetXaxis()->SetTitle("Column");
	hToTMap->GetYaxis()->SetTitle("Row");
  hToTMap->GetZaxis()->SetTitle("Mean charge (ToT)");
	hToTMap->SetMaximum(9);
	hToTMap->SetMinimum(5);
	hToTMap->DrawCopy("colz");

  
  std::cout<<"Making per pixel tot map"<<std::endl;
  // Per pixel map
  TH2F* hToTMapPerPixel = new TH2F("hToTMapPerPixel","hToTMapPerPixel",nPixelsX,0,nPixelsX,nPixelsY,0,nPixelsY);
  for(int x=0;x<nPixelsX;x++){
    for(int y=0;y<nPixelsY;y++){
      int id = x + y*nPixelsX;
      // Get the ToT distribution for this location
      string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixPixel"+makestring(id);
      TH1F* totMapHisto = 0;
      totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
      if(totMapHisto == 0) continue;
      if(totMapHisto->GetEntries() < 10) continue;
      
      // Fit the tot distribution and enter the value in the ToT map
      totMapHisto->Fit("gaus","0q");
      TF1* fit = totMapHisto->GetFunction("gaus");
      hToTMapPerPixel->Fill(x,y,fit->GetParameter(1));
      
      delete fit; delete totMapHisto;
    }
  }
  // Plot the map of ToT
  TCanvas* canv2 = new TCanvas();
  hToTMapPerPixel->GetXaxis()->SetTitle("Column");
  hToTMapPerPixel->GetYaxis()->SetTitle("Row");
  hToTMapPerPixel->GetZaxis()->SetTitle("Mean charge (ToT)");
  hToTMapPerPixel->SetMaximum(10);
  hToTMapPerPixel->SetMinimum(0);
  hToTMapPerPixel->DrawCopy("colz");

  std::cout<<"Making pixel response tot maps"<<std::endl;
  // Pixel response maps
  int responseBins=100;
  double responseWidth=0.05;
  TH2F* hToTMapPixelResponseX = new TH2F("hToTMapPixelResponseX","hToTMapPixelResponseX",responseBins+1,-responseWidth,responseWidth,15,0,15);
  for(double rID=0;rID<responseBins;rID++){
    // Get the ToT distribution for this location
    string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseX"+makestringD(rID);
    TH1F* totMapHisto = 0;
    totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
    if(totMapHisto == 0) continue;
    if(totMapHisto->GetEntries() < 1) continue;
 		// loop over all tot bins
    for(int i=0;i<45;i++){
      hToTMapPixelResponseX->Fill(2.*responseWidth*(rID/100.)-responseWidth,i,totMapHisto->GetBinContent(totMapHisto->FindBin(i)));
    }
    delete totMapHisto;
  }
  // Plot the map of ToT
  TCanvas* canv3 = new TCanvas();
  hToTMapPixelResponseX->GetXaxis()->SetTitle("Track distance x (mm)");
  hToTMapPixelResponseX->GetYaxis()->SetTitle("ToT");
  hToTMapPixelResponseX->DrawCopy("colz");

  TH1F* hToTProfilePixelResponseY = new TH1F("hToTProfilePixelResponseY","hToTProfilePixelResponseY",responseBins+1,-responseWidth,responseWidth);
  TH2F* hToTMapPixelResponseY = new TH2F("hToTMapPixelResponseY","hToTMapPixelResponseY",responseBins+1,-responseWidth,responseWidth,16,0,16);
  for(double rID=0;rID<responseBins;rID++){
    // Get the ToT distribution for this location
    string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseY"+makestringD(rID);
    TH1F* totMapHisto = 0;
    totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
    if(totMapHisto == 0) continue;
    if(totMapHisto->GetEntries() < 1) continue;
    // loop over all tot bins
    for(int i=0;i<45;i++){
      hToTMapPixelResponseY->Fill(2.*responseWidth*(rID/100.)-responseWidth,i,totMapHisto->GetBinContent(totMapHisto->FindBin(i)));
    }
    hToTProfilePixelResponseY->Fill(2.*responseWidth*(rID/100.)-responseWidth+0.001,totMapHisto->GetXaxis()->GetBinCenter(totMapHisto->GetMaximumBin()));
    delete totMapHisto;
  }
  // Plot the map of ToT
  TCanvas* canv4 = new TCanvas();
  hToTMapPixelResponseY->GetXaxis()->SetTitle("Track distance y (mm)");
  hToTMapPixelResponseY->GetYaxis()->SetTitle("ToT");
  hToTMapPixelResponseY->GetZaxis()->SetTitle("Number of events");
  hToTMapPixelResponseY->DrawCopy("colz");
//  drawline(-0.03,1,7);
//  drawline(0.03,1,7);
	
  TCanvas* canv6 = new TCanvas();
  hToTProfilePixelResponseY->GetXaxis()->SetTitle("Track distance y (mm)");
  hToTProfilePixelResponseY->GetYaxis()->SetTitle("Most probable ToT");
  hToTProfilePixelResponseY->DrawCopy("");



  
  TCanvas* canv5 = new TCanvas();
  TH1F* sidebandLow = (TH1F*)gDirectory->Get("/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseY20");
  TH1F* sidebandHigh = (TH1F*)gDirectory->Get("/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseY80");
  sidebandHigh->GetXaxis()->SetTitle("ToT (single pixel)");
  sidebandHigh->GetXaxis()->SetRangeUser(0,20);
  sidebandHigh->DrawCopy("");
  sidebandLow->SetLineColor(2);
  sidebandLow->DrawCopy("same");

}
Пример #7
0
void plotvn(){
    gStyle->SetOptStat(kFALSE);
    int icent = 0;
    int n = 3;
    int color[6] = {1,2,4,7,8,5};
    int style[12] = {20,21,24,25,26,27,29,30,31,32,33,34};
    TGraphErrors *gr[nsub][3][2];
    TGraphErrors *grraw[nsub][3][2];
    TString CNTEP, dire;
    for(int isub=0;isub<nsub;isub++){
    for(int idire=0;idire<3;idire++){
    for(int iCNTEP=0;iCNTEP<1;iCNTEP++){
        if(iCNTEP==0) CNTEP = "NoUseCNTEP";
        if(iCNTEP==1) CNTEP = "UseCNTEP";
        if(idire==0) dire = "";
        if(idire==1) dire = "_east";
        if(idire==2) dire = "_west";
        TString str = choosesub(isub);
        if(str=="ABORT") continue;
        gr[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%d_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        grraw[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%draw_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        SetStyle(*gr[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
        SetStyle(*grraw[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
    }
    }
    }
TH1F* h = new TH1F("h","",50,0,5);
h->GetXaxis()->SetRangeUser(0,3.2);
/*
TCanvas *c1 = new TCanvas("c1","c1",800,450);
iCNTEP = 0;
idire = 0;
c1->Divide(2);
c1->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
h->GetXaxis()->SetRangeUser(0,3.2);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
for(int ilay = 0;ilay<4;ilay++){
leg->AddEntry(gr[ilay+8][idire][iCNTEP],Form("FVTX layer %d",ilay));
gr[ilay+8][idire][iCNTEP]->Draw("Psame");
}
gr[6][0][1]->Draw("Psame");
leg->AddEntry(gr[6][idire][iCNTEP],Form("FVTX -3.0<#eta<-1.0"));
leg->Draw("Psame");

c1->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
for(int ilay = 0;ilay<4;ilay++){
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[ilay+8][idire][iCNTEP],gr[6][idire][iCNTEP]);
SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[ilay+8]);
grr->Draw("Psame");
}
*/
TCanvas *c2 = new TCanvas("c2","c2",450,450);
iCNTEP = 0;
idire = 0;
//c2->Divide(2);
c2->cd(1);
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
isub=5;
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
isub=6;
h->SetMinimum(-0.05);
h->SetMaximum(0.2);
}
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(*h,"p_{T} (GeV/c)",Form("v_{%d}",n),"");
c2->SetLeftMargin(0.12);
h->GetXaxis()->CenterTitle();
h->GetYaxis()->CenterTitle();
h->GetYaxis()->SetTitleSize(0.06);
h->DrawCopy();
TLatex t;
t.SetNDC();
t.DrawLatex(0.6,0.82,"d+Au 62GeV");
TLegend *leg = new TLegend(0.2,0.7,0.5,0.88);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
SetStyle(*gr[4][idire][iCNTEP], 1.2, 2,style[6]);
SetStyle(*gr[isub][idire][iCNTEP], 1.2, 4,style[6]);
gr[4][idire][iCNTEP]->Draw("Psame");
gr[isub][idire][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[4][idire][iCNTEP],Form("BBCs"),"P");
leg->AddEntry(gr[isub][idire][iCNTEP],Form("FVTXs 1+2+3L -3.0<#eta<-1.0"),"P");
leg->Draw("Psame");
/*
c2->cd(2);
if(n==2){
h->SetMinimum(0.8);
h->SetMaximum(1.2);
}
if(n==3){
h->SetMinimum(0);
h->SetMaximum(2);
}
SetTitle(h,"","p_{T}","v_{2} ratio BBCs/FVTXs");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[4][idire][iCNTEP],gr[5][idire][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]);
grr->Draw("Psame");
*/
c2->Print(Form("v%d.png",n));
/*
TCanvas *c3 = new TCanvas("c3","c3",800,450);
idire = 0;
isub=5;
c3->Divide(2);
c3->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][idire][1]->Draw("Psame");
gr[isub][idire][0]->Draw("Psame");
leg->AddEntry(gr[isub][idire][1],Form("FVTXs -3.0<#eta<-1.0"));
leg->AddEntry(gr[isub][idire][1],Form("Using Psi EP"),"P");
leg->AddEntry(gr[isub][idire][0],Form("Using phi EP"),"P");
leg->Draw("Psame");

c3->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs using phi EP/using Psi EP");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][idire][0],gr[isub][idire][1]);
SetStyle(*grr,1.2,color[idire+3*0],style[isub]);
grr->Draw("Psame");
*/
TCanvas *c4 = new TCanvas("c4","c4",800,450);
isub=5;
iCNTEP = 0;
c4->Divide(2);
c4->cd(1);
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
h->SetMinimum(-0.05);
h->SetMaximum(0.1);
}
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.88);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs -3.0<#eta<-1.0"),"P");
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c4->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c4->Print(Form("v%dEWFVTX.png",n));

TCanvas *c5 = new TCanvas("c5","c5",800,450);
isub=4;
iCNTEP = 0;
c5->Divide(2);
c5->cd(1);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
h->SetMinimum(-0.05);
h->SetMaximum(0.1);
}
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetTextSize(0.05);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("Using BBC event plane"),"");
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c5->cd(2);
h->SetMinimum(0);
h->SetMaximum(2.);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c5->Print(Form("v%dEWBBC.png",n));

TCanvas *c6 = new TCanvas("c6","c6",800,450);
iCNTEP = 0;
c6->Divide(2);
c6->cd(1);
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
h->SetMinimum(-0.05);
h->SetMaximum(0.1);
}
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.5,0.75,0.8,0.85);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[0][0][iCNTEP]->Draw("Psame");
gr[1][0][iCNTEP]->Draw("Psame");
gr[2][0][iCNTEP]->Draw("Psame");
gr[3][0][iCNTEP]->Draw("Psame");
SetStyle(*gr[0][0][iCNTEP],1.2,color[0],style[0]);
SetStyle(*gr[0][1][iCNTEP],1.2,color[1],style[1]);
SetStyle(*gr[0][2][iCNTEP],1.2,color[2],style[2]);
SetStyle(*gr[0][3][iCNTEP],1.2,color[3],style[3]);
leg->AddEntry(gr[0][0][iCNTEP],Form("FVTX 1LS"),"P");
leg->AddEntry(gr[1][0][iCNTEP],Form("FVTX 2LS"),"P");
leg->AddEntry(gr[2][0][iCNTEP],Form("FVTX 3LS"),"P");
leg->AddEntry(gr[3][0][iCNTEP],Form("FVTX 4LS"),"P");
leg->Draw("same");

c6->cd(2);
if(n==2){
h->SetMinimum(0);
h->SetMaximum(2);
}
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[0][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[0]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[1][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[1]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[2][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[3][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[3]);
grr->Draw("Psame");
c6->Print(Form("v%dLayers.png",n));
}
Пример #8
0
void CountTrackableMCs(TH1F *hAllMC, Bool_t onlyPrims,Bool_t onlyPion) {
  
  gSystem->Load("libITSUpgradeBase");
  gSystem->Load("libITSUpgradeSim");

 // open run loader and load gAlice, kinematics and header
  AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
  if (!runLoader) {
    Error("Check kine", "getting run loader from file %s failed",
          "galice.root");
    return;
  }
  runLoader->LoadHeader();
  runLoader->LoadKinematics();
  runLoader->LoadTrackRefs();

  AliLoader *dl = runLoader->GetDetectorLoader("ITS");

  //Trackf
  TTree *trackRefTree = 0x0; 
  TClonesArray *trackRef = new TClonesArray("AliTrackReference",1000);

  //  TH1F *hRef = new TH1F("","",100,0,100);
  TH1F *hR = new TH1F("","",100,0,100);
  if (hAllMC==0) hAllMC = new TH1F("","",100,0.1,2);
  Float_t ptmin = hAllMC->GetBinCenter(1)-hAllMC->GetBinWidth(1)/2;
  Float_t ptmax = hAllMC->GetBinCenter(hAllMC->GetNbinsX())+hAllMC->GetBinWidth(hAllMC->GetNbinsX())/2;
  //  Int_t nAllMC = 0;

  // Detector geometry
  TArrayD rmin(0);   TArrayD rmax(0); 
  GetDetectorRadii(&rmin,&rmax);
  TArrayI nLaySigs(rmin.GetSize());

  printf("Counting trackable MC tracks ...\n");
  
  for(Int_t iEv =0; iEv<runLoader->GetNumberOfEvents(); iEv++){
    Int_t nTrackableTracks = 0;
    runLoader->GetEvent(iEv);
    AliStack* stack = runLoader->Stack();  
    printf("+++ event %i (of %d) +++++++++++++++++++++++  # total MCtracks: %d \n",iEv,runLoader->GetNumberOfEvents()-1,stack->GetNtrack());

    trackRefTree=runLoader->TreeTR();
    TBranch *br = trackRefTree->GetBranch("TrackReferences");
    if(!br) {
      printf("no TR branch available , exiting \n");
      return;
    }
    br->SetAddress(&trackRef);

    // init the trackRef tree 
    trackRefTree=runLoader->TreeTR();
    trackRefTree->SetBranchAddress("TrackReferences",&trackRef);
 
    // Count trackable MC tracks
    for (Int_t iMC=0; iMC<stack->GetNtrack(); iMC++) {

      TParticle* particle = stack->Particle(iMC); 
      if (TMath::Abs(particle->Eta())>etaCut) continue;
      if (onlyPrims && !stack->IsPhysicalPrimary(iMC)) continue;
      if (onlyPion && TMath::Abs(particle->GetPdgCode())!=211) continue;


      Bool_t isTrackable = 0;
      nLaySigs.Reset(0);
 
      trackRefTree->GetEntry(stack->TreeKEntry(iMC));
      Int_t nref=trackRef->GetEntriesFast();
      for(Int_t iref =0; iref<nref; iref++){
	AliTrackReference *trR = (AliTrackReference*)trackRef->At(iref);
	if(!trR) continue;
	if(trR->DetectorId()!=AliTrackReference::kITS) continue;
	Float_t radPos = trR->R();
	hR->Fill(radPos);
	for (Int_t il=0; il<rmin.GetSize();il++) {
	  if (radPos>=rmin.At(il)-0.1 && radPos<=rmax.At(il)+0.1) {
	    //	    cout<<"  in Layer "<<il<<" "<<radPos;
	    nLaySigs.AddAt(1.,il);
	    //	    cout<<" "<<nLaySigs.At(il)<<endl;
	  }
	}
      }

      if (nLaySigs.GetSum()>=3) {
	isTrackable =1;
	//	cout<<nLaySigs.GetSum()<<endl;
      }
      
      if (isTrackable) {
	Double_t ptMC = particle->Pt();
	//	Double_t etaMC = particle->Eta();
	//	if (ptMC>ptmin&&ptMC<ptmax) {nTrackableTracks++;hAllMC->Fill(ptMC);}
	if (ptMC>ptmin) {nTrackableTracks++;hAllMC->Fill(ptMC);}

      }

      
    } // entries tracks MC
    printf(" -> trackable MC tracks: %d (%d)\n",nTrackableTracks,hAllMC->GetEntries());
  }//entries Events
  

  hR->DrawCopy();
  hAllMC->DrawCopy();
  runLoader->UnloadHeader();
  runLoader->UnloadKinematics();
  delete runLoader;

}
Пример #9
0
void plotMerged(Bool_t onlyPlot=0) {

  gStyle->SetPalette(1);
 
  TFile f("histoSum.root","UPDATE");

  TH1F* hAllMC = f.Get("allMC");
  TH1F* hAllFound= f.Get("allFound");
  TH1F* hImperfect= f.Get("imperfect");
  TH1F* hPerfect= f.Get("perfect");
  TH1F* hNoMCTrack= f.Get("noMCtrack");
  
  
  // have to be recalculated
  TH1F* hPurity = f.Get("purity");
  TH1F* hEff= f.Get("efficiency");
  TH1F* hFake= f.Get("fake");
  TH1F* hAnna= f.Get("annaEff");

  TH2D* h2Ddca= f.Get("dca2D");
  TGraphErrors *d0= f.Get("dca");

  TH2D* h2Dpt= f.Get("dPt2D");
  TGraphErrors *gPt= f.Get("dPt");


  if (!onlyPlot) {
    /*    // Get Errors right
    hAllMC->Sumw2();   
    hAllFound->Sumw2();
    hPerfect->Sumw2(); 
    hImperfect->Sumw2(); 
    h2Dpt->Sumw2();
    h2Ddca->Sumw2();
    */

    // Efficiencies - and normalize to 100%
    
    TF1 f1("f1","100+x*0",0.,1.e3);
    
    hPurity->Divide(hPerfect,hAllFound,1,1,"b"); 
    hPurity->Multiply(&f1);
    hPurity->SetMarkerColor(kGreen);
    hPurity->SetMarkerStyle(21);
    hPurity->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)");
    hPurity->SetStats(0);
    
    hPurity->GetYaxis()->SetRangeUser(0,100);
    hPurity->SetTitle("Efficiency & Purity");
    
    hEff->Divide(hPerfect,hAllMC,1,1,"b");
    hEff->Multiply(&f1);
    hEff->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)");
    hEff->SetMarkerColor(kBlue);
    hEff->SetMarkerStyle(21);
    hEff->SetStats(0);
    
    hFake->Divide(hImperfect,hAllMC,1,1,"b");
    hFake->Multiply(&f1);
    hFake->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)");
    hFake->SetMarkerColor(kRed);
    hFake->SetMarkerStyle(21);
    hFake->SetStats(0);
    
    hAnna->Divide(hAllFound,hAllMC,1,1,"b");
    hAnna->Multiply(&f1);
    hAnna->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)");
    hAnna->SetMarkerColor(kBlack);
    hAnna->SetMarkerStyle(21);
    hAnna->SetStats(0);
    
    
    // Impact parameter resolution ---------------
    TCanvas *c3 = new TCanvas("c3","impact");//,200,10,900,900);
    c3->Divide(2,1); c3->cd(1);
    h2Ddca->DrawCopy("colz");
    h2Ddca->FitSlicesY() ;
    TH2D *dcaM = (TH2D*)gDirectory->Get("dca2D_1"); dcaM->Draw("same");
    TH2D *dcaRMS = (TH2D*)gDirectory->Get("dca2D_2"); //dcaRMS->Draw();
    TGraphErrors *d0 = new TGraphErrors(); 
    for (Int_t ibin =1; ibin<=dcaRMS->GetXaxis()->GetNbins(); ibin++) {
      d0->SetPoint(     ibin-1,dcaRMS->GetBinCenter(ibin),dcaRMS->GetBinContent(ibin)*1e4); // microns
      d0->SetPointError(ibin-1,0,dcaRMS->GetBinError(ibin)*1e4); // microns
    }
    d0->SetMarkerStyle(21);
    d0->SetMaximum(200);  d0->SetMinimum(0);
    d0->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)");
    d0->GetYaxis()->SetTitle("R-#phi Pointing Resolution (#mum)");
    d0->SetName("dca");  d0->SetTitle("DCAvsPt");
    //  c3->cd(1);  h2Ddca->Draw("surf2");
    c3->cd(2);  d0->Draw("APE");
    
    // PT RESOLUTION ------------
    TCanvas *c4 = new TCanvas("c4","pt resolution");//,200,10,900,900);  
    c4->Divide(2,1); c4->cd(1);
    h2Dpt->DrawCopy("colz");
    h2Dpt->FitSlicesY() ;
    TH2D *dPtM = (TH2D*)gDirectory->Get("dPt2D_1"); dPtM->Draw("same");
    TH2D *dPtRMS = (TH2D*)gDirectory->Get("dPt2D_2"); // dPtRMS->Draw("");
    TGraphErrors *gPt = new TGraphErrors(); 
    for (Int_t ibin =1; ibin<=dPtRMS->GetXaxis()->GetNbins(); ibin++) {
      gPt->SetPoint(     ibin-1,dPtRMS->GetBinCenter(ibin),dPtRMS->GetBinContent(ibin)); 
      gPt->SetPointError(ibin-1,0,dPtRMS->GetBinError(ibin)); 
    }
    gPt->SetMarkerStyle(21);
    gPt->SetMaximum(20);  gPt->SetMinimum(0);
    gPt->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)");
    gPt->GetYaxis()->SetTitle("relative momentum resolution (%)");
    gPt->SetName("dPt");  gPt->SetTitle("DPTvsPt");
    //  c4->cd(1);  h2Dpt->Draw("surf2");
    c4->cd(2);  gPt->Draw("APE");


    // overwrite with normalized graphs
    hPurity->Write();
    hEff->Write();
    hFake->Write();
    hAnna->Write();
    h2Ddca->Write();
    d0->Write();
    h2Dpt->Write();
    gPt->Write();
   
  }
  
  // Plots

  TCanvas *c2 = new TCanvas("c2","Eff&Purity");//,200,10,900,900);
  TVirtualPad *pad =   c2->cd();
  pad->SetGridx();   pad->SetGridy();
  //  pad->SetLogx();

  TLegend *leg = new TLegend(0.1,0.8,0.6,0.9);leg->SetFillColor(0);
  leg->AddEntry(hPurity,"Purity (\"Perfect tracks\" within \"Found Tracks\")","PE");
  leg->AddEntry(hEff,"Efficiency (\"Perfect tracks\" within \"MC findable Tracks\")","PE");
  leg->AddEntry(hFake,"Fake (\"Inperfect tracks\" within \"MC findable Tracks\")","PE");
  leg->AddEntry(hAnna,"AnnaLisa - Efficiency (\"Found tracks\" within \"MC findable Tracks\")","PE");
 

  hPurity->DrawCopy("E");
  hEff->DrawCopy("Same E");
  hFake->DrawCopy("Same E");
  hAnna->DrawCopy("Same E");
  leg->Draw();

  c2->SaveAs("EffPlot.png");

  f.Close();



}
Пример #10
0
void AnalyzeData(char *DataFile = "drs4_peds_5buffers.dat", Int_t nevt,
		Int_t startEv = 1, char *PedFile, Int_t DrawExtraGraphs = 0) {


	// Redefine DOMINO Depth in ADC counts
	const Float_t DominoDepthADC = pow(2, DOMINO_DEPTH);

	// open file

	FILE *fdata = OpenDataFile(DataFile);
	struct channel_struct *p;
	struct channel_struct *dep;

	// create histograms
	// create list of histograms for channels and distribution

	TList *DistChList = new TList();
	TH1F *distch; // histo with distribution of cell-charge, for each channel

	TList *DistChSubList = new TList();
	TH1F *distchsub; // histo with distribution of cell-charge, pedestals subtracted, for each channel

	TList *DistCh0SubList = new TList();
	TH1F *distch0sub; // histo with distribution of cell-charge, pedestals subtracted,
	// channel 0 subtracted for each channel

	TList *grPedList = new TList();
	TGraphErrors *grPed; // for each channel, pedestal value and RMS for each cell is plotted

	TList *hCellList = new TList();
	TH1F *hCell; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos)
	TList *hCellSubList = new TList();
	TH1F *hCellSub; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos), pedestal subtracted

	TList *hRMSList = new TList();
	TH1F *hRMSdist; // histo with RMS distribution (statistical RMS of distribution)
	TList *hRMSFitList = new TList();
	TH1F *hRMSFitdist; // histo with RMS distribution (RMS of Gaussian fit)

	TList *grDataList = new TList();
	TGraphErrors *grData; // charge-cell and RMS for each cell is plotted

	TList *grDataSubList = new TList();
	TGraphErrors *grDataSub; // pedestal subtracted charge-cell and RMS for each cell is plotted


	for (int h = 0; h < DOMINO_NCH; h++) {
		//
		TString title = "Data Dist channel";
		title += h;
		distch = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC);
		DistChList->Add(distch);
		//
		TString title = "Data Dist Ped Sub channel";
		title += h;
		distchsub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2);
		DistChSubList->Add(distchsub);
		//
		TString title = "Data Dist Ped Ch0 Sub channel";
		title += h;
		distch0sub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2);
		DistCh0SubList->Add(distch0sub);
		//
		TString title = "Pedestal ch";
		title += h;
		grPed = new TGraphErrors(DOMINO_NCELL);
		grPed->SetTitle(title);
		grPedList->Add(grPed);
		//
		TString title = "Data ch";
		title += h;
		grData = new TGraphErrors(DOMINO_NCELL);
		grData->SetTitle(title);
		grDataList->Add(grData);
		//
		// Mean data and RMS for each channel and cell
		TString title = "Data PedSubtracted ch";
		title += h;
		grDataSub = new TGraphErrors(DOMINO_NCELL);
		grDataSub->SetTitle(title);
		grDataSubList->Add(grDataSub);
		//
		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			// data distribution histos
			TString title = "Data ch";
			title += h;
			title += " cell";
			title += ch;
			hCell = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC);
			hCellList->Add(hCell);
			// data (ped subtracted) distribution histos
			TString title = "Data PedSub ch";
			title += h;
			title += " cell ";
			title += ch;
			hCellSub = new TH1F(title, title, 2 * DominoDepthADC, -1
					* DominoDepthADC, DominoDepthADC);
			hCellSubList->Add(hCellSub);
		}
		// Data-RMS distribution histos
		TString title = "RMSDist channel";
		title += h;
		hRMSdist = new TH1F(title, title, 100, 0, 20.);
		hRMSList->Add(hRMSdist);
		// Data-RMS (calculated through a fit) distribution histos
		TString title = "RMSFitDist channel";
		title += h;
		hRMSFitdist = new TH1F(title, title, 100, 0, 20.);
		hRMSFitList->Add(hRMSFitdist);
	}
	//--------------
	//
	// calculate or read pedestals from file
	grPedList = OpenPedestals(PedFile);

	//    return;
	//
	// ====== Read data file and subtract the pedestals
	//
	// Count number of events in data file
	int nevtDataMax = 0;
	while (!feof(fdata)) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		nevtDataMax++;
	}
	printf("nevtDataMax: %d\n", nevtDataMax);

	if (nevt > (nevtDataMax - startEv) || nevt == 0)
		nevt = nevtDataMax - startEv;
	cout << endl << "==>> Processing " << nevt << " events from file "
			<< DataFile << endl;

	rewind(fdata);

	Int_t ievt = 1;
	// go to first event (startEv)
	while (ievt < startEv) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			break;
		ievt++;
	}
	// filling
	ievt = 1;
	Int_t flagEnd = 0;
	Double_t chtmp;
	Double_t PedVal, itmp, Ch0Val;
	// loop on events
	cout << endl << " --- read DATA file:" << fdata << endl;
	while (ievt <= nevt && !flagEnd) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			flagEnd = 1;
		if (ievt % (nevt / 10 + 1) == 0)
			cout << "*" << endl;
		p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data
		dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data

		TGraphErrors *grCh0 = new TGraphErrors(DOMINO_NCELL);

		// loop on channels
		for (int h = 0; h < DOMINO_NCH; h++) {
			// loop on cells
			distch = (TH1F *) DistChList->At(h);
			distchsub = (TH1F *) DistChSubList->At(h);
			grPed = (TGraphErrors *) grPedList->At(h);
			distch0sub = (TH1F *) DistCh0SubList->At(h);
			if(h==0) {
				for(i = 0; i < DOMINO_NCELL;i++) {
					grPed->GetPoint(i, itmp, PedVal);
					chtmp = (Double_t)(p->data[i]);
					chtmp = chtmp - PedVal;
					grCh0->SetPoint(i,itmp, chtmp);
				}
			}
			for (int i = 0; i < DOMINO_NCELL; i++) {
				// Read pedestal value for this cell
				grPed->GetPoint(i, itmp, PedVal);
				grCh0->GetPoint(i, itmp, Ch0Val);
				//                cout << itmp << ", " << PedVal << endl;
				// Read calibration correction for this cell
				//                CalFact =

				//charge distribution for each cell, pedestal subtracted
				chtmp = (Double_t)(p->data[i]); // data value
				//                cout  << "tcell, tcell, depth: " << chtmp << ","  << p->data[i] << "," << deptmp << endl;
				distch->Fill(chtmp);
				// Check data value: must be within DOMINO Depth
				//                if(chtmp > DominoDepthADC)
				//                    cout << " === WARNING!!! Channel " << h << " Cell " << i << " has value " << chtmp << endl;
				//                cout << "Charge: " << p->data[i] << endl;
				((TH1 *) hCellList->At(h * DOMINO_NCELL + i))->Fill(chtmp);
				// Now the pedestal is subtracted
				chtmp = chtmp - PedVal;
				distchsub->Fill(chtmp);
				((TH1 *) hCellSubList->At(h * DOMINO_NCELL + i))->Fill(chtmp);
				chtmp = chtmp - Ch0Val;
				distch0sub->Fill(chtmp);
			}
			p++; // next channel
		}
		ievt++; // next event
	}
	cout << endl;

	// now mean and RMS for each cell are computed and save in histos and graphs
	cout << " --- filling data histos and grphs " << endl;
	TF1 *fgauss = new TF1("fgauss", Gauss, -10., 10., 3);
	fgauss->SetParLimits(0, 0.1, 10000.);
	fgauss->SetParLimits(1, 0., 4096.);
	fgauss->SetParLimits(2, 0.1, 20.);
	Float_t mean, rms, meansub, rmssub;
	for (int h = 0; h < DOMINO_NCH; h++) {
		//        for (int h=5; h<6; h++){
		cout << " Channel:" << h << endl;
		hRMSdist = (TH1F *) hRMSList->At(h);
		hRMSFitdist = (TH1F *) hRMSFitList->At(h);
		grData = (TGraphErrors *) grDataList->At(h);
		grDataSub = (TGraphErrors *) grDataSubList->At(h);
		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			// data distribution histos
			//            cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<<hCell->GetMean()<< "," << hCell->GetRMS()<<endl;
			hCell = (TH1F *) hCellList->At(h * DOMINO_NCELL + ch);
			mean = hCell->GetMean();
			rms = hCell->GetRMS();
			hCellSub = (TH1F *) hCellSubList->At(h * DOMINO_NCELL + ch);
			meansub = hCellSub->GetMean();
			rmssub = hCellSub->GetRMS();
			fgauss->SetParameter(0, (Double_t) nevt / 4.);
			fgauss->SetParameter(1, mean);
			fgauss->SetParameter(2, rms);
			//            hCell->Fit("fgauss","QN0");
			grData->SetPoint(ch, ch, mean);
			grData->SetPointError(ch, 0, rms);
			grDataSub->SetPoint(ch, ch, meansub);
			//            grDataSub->SetPointError(ch,0.5,rmssub);
			grDataSub->SetPointError(ch, 0.5, 2.1);
			hRMSdist->Fill(rms);
			hRMSFitdist->Fill(fgauss->GetParameter(2));
			//           cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<< mean << "," << rms<<endl;
		}
	}

	Double_t x, y, chtmp, x1, x2, y1, y2;

	/*TList *grCellCalibList = OpenCalibFile("CalibrationData1000events.root");

	TGraphErrors *grCellCalib;
	TGraphErrors *grDataSubCalib = new TGraphErrors(DOMINO_NCELL);
	grDataSubCalib->SetTitle("Data after calibration correction");
	grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel);


	for(ch = 0; ch < DOMINO_NCELL; ch++) {
		grCellCalib = ((TGraphErrors *) grCellCalibList->At(ch));
		grCellCalib->Fit("pol3", "Q");
		TF1 *pol3fit = ((TF1 *) grCellCalib->GetFunction("pol3"));
		grDataSub->GetPoint(ch, x, y);
		chtmp = y - (Double_t)(pol3fit->Eval(y/3.25));
		grDataSubCalib->SetPoint(ch, x, chtmp);
	}

	TCanvas *cGrTest = new TCanvas("grTest", "test per vedere i dati", 1000,1000);

	grDataSubCalib->Draw("APEL");*/


	TString Title = "Charge Distribution per channel";
	gStyle->SetOptFit(111);
	TCanvas *cdistch = new TCanvas("cdistch", Title, 1000, 1000);
	cdistch->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistch->cd(i + 1);
		TH1 *dhist = (TH1 *) DistChList->At(i);
		dhist->DrawCopy();
		dhist->SetLineWidth(1);
		dhist->Fit("gaus", "Q");
		dhist->GetFunction("gaus")->SetLineColor(4);
		dhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TString Title = "Charge Distribution Pedestals Subtracted per channel";
	TCanvas *cdistchsub = new TCanvas("cdistchsub", Title, 1000, 1000);
	cdistchsub->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistchsub->cd(i + 1);
		TH1 *dsubhist = (TH1 *) DistChSubList->At(i);
		dsubhist->DrawCopy();
		dsubhist->SetLineWidth(1);
		dsubhist->Fit("gaus", "Q");
		dsubhist->GetFunction("gaus")->SetLineColor(4);
		dsubhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TString Title = "Charge Distribution Pedestals and Ch0 Subtracted per channel";
	TCanvas *cdistch0sub = new TCanvas("cdistch0sub", Title, 1000, 1000);
	cdistch0sub->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistch0sub->cd(i + 1);
		TH1 *dch0subhist = (TH1 *) DistCh0SubList->At(i);
		dch0subhist->DrawCopy();
		dch0subhist->SetLineWidth(1);
		dch0subhist->Fit("gaus", "Q");
		dch0subhist->GetFunction("gaus")->SetLineColor(4);
		dch0subhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TCanvas *cDataSubTest = new TCanvas("cDataSubTest", "Data after pedestal subtraction", 1000, 1000);
	cDataSubTest->Divide(1,8);
	for (h = 0; h< DOMINO_NCH; h++) {
		grDataSub = (TGraphErrors *) grDataSubList->At(h);
		cDataSubTest->cd(h+1);
		grDataSub->GetYaxis()->SetLabelSize(0.06);
		grDataSub->GetXaxis()->SetLabelSize(0.06);
		grDataSub->Draw("APE");
	}

	TCanvas *cDataSubTestCh5 = new TCanvas("cDataSubTestCh5", "Data after pedestal subtraction Ch5", 1200, 800);
	grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel);
	grDataSub->GetYaxis()->SetLabelSize(0.06);
	grDataSub->GetYaxis()->SetTitle("ADC Counts");
	grDataSub->GetXaxis()->SetTitle("Cell");
	grDataSub->GetXaxis()->SetLabelSize(0.06);
	TLine *refval = new TLine(0,350,1024,350);
	refval->SetLineWidth(3);
	refval->SetLineStyle(2);
	refval->SetLineColor(2);
	TLine *i1 = new TLine(121,-50,121,800);
	i1->SetLineStyle(2);
	TLine *i2 = new TLine(291,-50,291,800);
	i2->SetLineStyle(2);
	TLine *i3 = new TLine(461,-50,461,800);
	i3->SetLineStyle(2);
	TLine *i4 = new TLine(632,-50,632,800);
	i4->SetLineStyle(2);
	TLine *i5 = new TLine(803,-50,803,800);
	i5->SetLineStyle(2);
	TLine *i6 = new TLine(975,-50,975,800);
	i6->SetLineStyle(2);
	TLine *ireal1 = new TLine(121+20,600,121+20,800);
	ireal1->SetLineWidth(3);
	ireal1->SetLineColor(4);
	TLine *ireal2 = new TLine(291-20,600,291-20,800);
	ireal2->SetLineWidth(3);
	ireal2->SetLineColor(4);
	TLine *ireal3 = new TLine(461+20,600,461+20,800);
	ireal3->SetLineWidth(3);
	ireal3->SetLineColor(4);
	TLine *ireal4 = new TLine(632-20,600,632-20,800);
	ireal4->SetLineWidth(3);
	ireal4->SetLineColor(4);
	TLine *ireal5 = new TLine(803+20,600,803+20,800);
	ireal5->SetLineWidth(3);
	ireal5->SetLineColor(4);
	TLine *ireal6 = new TLine(975-20,600,975-20,800);
	ireal6->SetLineWidth(3);
	ireal6->SetLineColor(4);
	grDataSub->Draw("APE");
	refval->Draw("SAME");
	i1->Draw("SAME");
	i2->Draw("SAME");
	i3->Draw("SAME");
	i4->Draw("SAME");
	i5->Draw("SAME");
	i6->Draw("SAME");
	ireal1->Draw("SAME");
	ireal2->Draw("SAME");
	ireal3->Draw("SAME");
	ireal4->Draw("SAME");
	ireal5->Draw("SAME");
	ireal6->Draw("SAME");


	TCanvas *cDataTest = new TCanvas("cDataTest", "Raw Data", 1000,1000);
	cDataTest->Divide(1,8);
	for(h = 0; h < DOMINO_NCH; h++) {
		cDataTest->cd(h+1);
		grData = (TGraphErrors *) grDataList->At(h);
		grData->SetMarkerStyle(20);
		grData->SetMarkerSize(0.5);
		grData->Draw("APE");

	}

	// save root file with graph containing channel 5 data after pedestals subtraction.
	/*
	cout << "test" << endl;

	TString OutFile = DataSubFile;
	TFile *f = new TFile(OutFile,"RECREATE");
	int h = anaChannel;
	TString key="DataSubGraph";
	key += h;
	((TGraphErrors*)grDataSubList->At(h))->Write(key);
	f->Close();
	cout << " ---- Write data on file " << endl;
	 */

	// =======================================================//
	// =====================Matteo's Code=====================//
	// =======================================================//
	/*
	Int_t cht, incCht, decCht, xflag, nPeriods, iMax, iMin;
	Double_t xdiff, incDiff, decDiff, incDiffTemp, decDiffTemp, incXDiff, decXDiff;
	Double_t fitMax, fitMin, fitPeriod, chisquare;
	Double_t DominoXval[DOMINO_NCELL];
	Double_t DominoYval[DOMINO_NCELL];
	Double_t FitXval[DOMINO_NCELL];
	Double_t FitYval[DOMINO_NCELL];


        // opens grDataSub.root

        TString FileName = DataSubFile;
        TGraphErrors *grDataSub;
        int h = anaChannel;
        TFile *f = new TFile(FileName);
        TString key = "DataSubGraph";
        key += h;
        grDataSub = (TGraphErrors *) f->Get(key);
        f->Close();


	// Create a new graph with channel 5 data
	TGraphErrors *grDataSubAnaCh;
	int h = anaChannel;
	grDataSubAnaCh = (TGraphErrors *) grDataSubList->At(h);

	TGraphErrors *grDataSubFix = grDataSubAnaCh->Clone();
	TGraphErrors *grRes = new TGraphErrors(DOMINO_NCELL);
	TList *grResPeriodList = new TList();



	Double_t xtemp, ytemp, DominoMax, DominoMin;

	for (int ch = 0; ch < DOMINO_NCELL; ch++){
		// get domino-output point and save in array
		grDataSubAnaCh->GetPoint(ch, DominoXval[ch], DominoYval[ch]);
	}

	// find the domino point with max y-value
	iMax = 0;
	for(int ch = 0; ch < DOMINO_NCELL; ch++) {
		if(DominoYval[ch] > DominoYval[iMax]) {
			DominoMax = DominoYval[ch];
			iMax = ch;
		}
	}

	cout << "DominoMax e': " << DominoMax << endl;

	// find the domino point with min y-value
	iMin = 0;
	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		if(DominoYval[ch] < DominoYval[iMin]) {
			DominoMin = DominoYval[ch];
			iMin = ch;
		}
	}

	cout << "DominoMin e': " << DominoMin << endl;

	// remove points from the graph that will be used for fit
	for (int ch = 0; ch < DOMINO_NCELL; ch++){
		grDataSubFix->GetPoint(ch, xtemp, ytemp);
		if(ytemp > 0.8*DominoMax || ytemp < 0.2*DominoMin)
			grDataSubFix->RemovePoint(ch);
	}


	TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4);
	fsin->SetParameters(600., DOMINO_NCELL / 4., 150., 150.);
	fsin->SetParNames("amplitude", "Period", "Phase", "DC-Offset");
	grDataSubFix->Fit("fsin");
	TF1 *fsinFit = grDataSubFix->GetFunction("fsin");
	fsinFit->SetParNames("amplitude", "Period", "Phase", "DC-Offset");
	chisquare = grDataSub->Chisquare(fsinFit);
	cout << "il chi quadro della funzione di fit e' : " << chisquare << endl;

	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		// get Fit-value and save in array
		FitXval[ch] = DominoXval[ch];
		FitYval[ch] = fsinFit->Eval(FitXval[ch]);
	}

	fitPeriod = fsinFit->GetParameter("Period");
	cout << "il periodo della funzione e': " << fitPeriod << endl;

	nPeriods = (Int_t) (DOMINO_NCELL/fitPeriod);
	cout << "il numero di periodi della funzione e': " << nPeriods << endl;

	fitMax = fsinFit->GetMaximum();
	cout << "il massimo della funzione e': " << fitMax << endl;

	fitMin = fsinFit->GetMinimum();
	cout << "il minimo della funzione e': " << fitMin << endl;




	// computes the y difference between the ch-domino point and the i-fit point
	// and stops when the difference changes sign
	//
	// first and last points are not included in the cicle
	//
	// if the fit point y-value is bigger or smaller than the fit function max*0.8 or min*0.2
	// the point is removed

	for (int ch = 1; ch < DOMINO_NCELL - 1; ch++) {

		if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) {
			grRes->RemovePoint(ch);
			continue;
		}

		incDiff = DominoYval[ch] - FitYval[ch];
		incDiffTemp = DominoYval[ch] - FitYval[ch + 1];

		decDiff = DominoYval[ch] - FitYval[ch];
		decDiffTemp = DominoYval[ch] - FitYval[ch - 1];

		if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) {
			for (int i = ch; i < DOMINO_NCELL; i++, incDiff = incDiffTemp) {
				incDiffTemp = DominoYval[ch] - FitYval[i];

				if (sign(incDiff) != sign(incDiffTemp)) {
					if(abs(incDiffTemp) < abs(incDiff))
						incCht = i;
					else
						incCht = i - 1;
					break;
				}
			}
			xflag = 1;
		}
		else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) {
			for (int j = ch; j >= 0 ; j--, decDiff = decDiffTemp) {
				decDiffTemp = DominoYval[ch] - FitYval[j];

				if (sign(decDiff) != sign(decDiffTemp)) {
					if(abs(decDiffTemp) < abs(decDiff))
						decCht = j;
					else
						decCht = j + 1;
					break;
				}
			}
			xflag = -1;
		}

		if(xflag == 1)
			xdiff = FitXval[incCht] - DominoXval[ch];
		else
			xdiff = FitXval[decCht] - DominoXval[ch];

		grRes->SetPoint(ch, (Double_t) ch, xdiff);
	}

	cout << "Draw Time Residuals" << endl;
	TString Title = "Time Residuals";
	TCanvas *timeres = new TCanvas("timeres", Title, 1200, 780);
	grRes->SetMarkerStyle(20);
	grRes->SetMarkerSize(0.3);
	grRes->GetYaxis()->SetLabelSize(0.12);
	grRes->GetXaxis()->SetLabelSize(0.12);
	grRes->Draw("APE");


	// The previous graph is now split in N graphs, where N is the number of fit periods

	// this will be needed to set the function phase
	//
    //    iMax = 0;
	//
    //    for(ch = 0; ch < fitPeriod - 1; ch++) {
    //            if(FitYval[ch] > FitYval[iMax]) iMax = ch;
    //    }

	cout << "il primo massimo ha l'indice : " << iMax << endl;

	for (i = 0; i < nPeriods; i++) {
		TGraphErrors *grResPeriod = new TGraphErrors((Int_t) fitPeriod);
		grResPeriodList->Add(grResPeriod);

		for(ch = i*fitPeriod + 1; ch < fitPeriod + (i*fitPeriod); ch++) {

			if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) {
				grResPeriod->RemovePoint(ch);
				continue;
			}

			incDiff = DominoYval[ch] - FitYval[ch];
			incDiffTemp = DominoYval[ch] - FitYval[ch + 1];

			decDiff = DominoYval[ch] - FitYval[ch];
			decDiffTemp = DominoYval[ch] - FitYval[ch - 1];

			if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) {
				for (int k = ch; k < k*fitPeriod + fitPeriod; k++, incDiff = incDiffTemp) {
					incDiffTemp = DominoYval[ch] - FitYval[k];

					if (sign(incDiff) != sign(incDiffTemp)) {
						if(abs(incDiffTemp) < abs(incDiff))
							incCht = k;
						else
							incCht = k - 1;
						break;
					}
				}
				xflag = 1;
			}
			else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) {
				for (int j = ch; j > i*fitPeriod; j--, decDiff = decDiffTemp) {
					decDiffTemp = DominoYval[ch] - FitYval[j];

					if (sign(decDiff) != sign(decDiffTemp)) {
						if(abs(decDiffTemp) < abs(decDiff))
							decCht = j;
						else
							decCht = j + 1;
						break;
					}
				}
				xflag = -1;
			}

			if(xflag == 1)
				xdiff = FitXval[incCht] - DominoXval[ch];
			else
				xdiff = FitXval[decCht] - DominoXval[ch];

			grResPeriod->SetPoint(ch - i*fitPeriod, (Double_t) (ch - i*fitPeriod), xdiff);
		}
	}

	TCanvas *timeresperiod = new TCanvas("timeresperiod", "Time Residuals Period", 1200, 780);
	for(i = 0; i < nPeriods; i++) {
		grResPeriod = ((TGraphErrors *) grResPeriodList->At(i));
		grResPeriod->SetMarkerStyle(20);
		grResPeriod->SetMarkerSize(0.3);
		grResPeriod->GetYaxis()->SetLabelSize(0.12);
		grResPeriod->GetXaxis()->SetLabelSize(0.12);
		grResPeriod->Draw("APEsame");
	}

	cout << "Draw Data - Pedestals Subtracted" << endl;
	TString Title = "Average Charge - Pedestal subtracted";
	TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780);
	grDataSubAnaCh->SetMarkerStyle(20);
	grDataSubAnaCh->SetMarkerSize(0.3);
	grDataSubAnaCh->GetYaxis()->SetLabelSize(0.12);
	grDataSubAnaCh->GetXaxis()->SetLabelSize(0.12);
	grDataSubAnaCh->Draw("APE");
	fsinFit->Draw("same");
	 */
	// draw extra graphs
	if (DrawExtraGraphs == 1) {
		cout << " ----- DRAW Results ------" << endl;
		//================ DRAW Results ==================

		TCanvas *c = new TCanvas("ctmp", "test", 800, 800);
		c->Divide(3, 3);
		for (int pad = 1; pad < 10; pad++) {
			c->cd(pad);
			((TH1 *) hCellList->At(pad * 512 + 219))->DrawCopy();
			hCellSub = (TH1F *) hCellSubList->At(pad * 512 + 219);
			hCellSub->SetLineColor(2);
			hCellSub->DrawCopy("same");
		}

		cout << "Draw RMS distributions" << endl;
		TString Title = "RMS distributions per channel";
		TCanvas *c4 = new TCanvas("c4", Title, 700, 700);
		c4->Divide(3, 3);
		for (int i = 0; i < DOMINO_NCH; i++) {
			c4->cd(i + 2);
			hRMSdist = (TH1F *) hRMSList->At(i);
			hRMSFitdist = (TH1F *) hRMSFitList->At(i);
			hRMSFitdist->SetLineColor(2);
			hRMSFitdist->DrawCopy();
			hRMSdist->DrawCopy("same");
		}


		TList *grDataCh0SubList = new TList();
		TGraphErrors *grDataCh0Sub;
		for(h = 0; h< DOMINO_NCELL; h++) {
			grDataCh0Sub = new TGraphErrors(DOMINO_NCELL);
			grDataCh0SubList->Add(grDataCh0Sub);
		}

		TGraphErrors *grDataSubCh0 = (TGraphErrors *) grDataSubList->At(6);
		for(h = 0; h < DOMINO_NCH; h++) {
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSubCh0->GetPoint(ch, x1, y1);
				grDataSub->GetPoint(ch, x2, y2);
				grDataCh0Sub->SetPoint(ch, x1 , y2 - y1);
			}
		}

		TCanvas *cDataCH0Sub = new TCanvas("cDataCH0Sub","cDataCH0Sub", 1000,1000);
		cDataCH0Sub->Divide(1,8);
		for(h = 0; h < DOMINO_NCH; h++) {
			cDataCH0Sub->cd(h+1);
			grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h);
			grDataCh0Sub->GetYaxis()->SetLabelSize(0.12);
			grDataCh0Sub->GetXaxis()->SetLabelSize(0.12);
			grDataCh0Sub->Draw("APEL");
		}



		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Average Charge - Pedestal subtracted";
		TCanvas *csubdata = new TCanvas("csubdata", Title, 1000, 1000);
		csubdata->Divide(3,3);

		for(h = 0; h < DOMINO_NCH; h++) {
			csubdata->cd(h+1);
			TString title = "DataSub channel ";
			title += h;
			TH1F *hCellDataSub = new TH1F(title, title, 100, -20, 20);
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSub->GetPoint(ch, x, y);
				hCellDataSub->Fill(y);
			}
			hCellDataSub->Fit("gaus", "Q");
			hCellDataSub->GetXaxis()->SetTitle("ADC Counts");
			hCellDataSub->GetFunction("gaus")->SetLineColor(4);
			hCellDataSub->DrawCopy();
		}

		cout << "breakpoint" << endl;
		TCanvas *csubdata2 = new TCanvas("csubdata2", "DataSub for every channel", 1000, 1000);
		TString title = "DataSub every channel ";
		TH1F *hCellChDataSubTot = new TH1F(title, title, 100, -20, 20);
		for(h = 0; h < DOMINO_NCH; h++) {
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSub->GetPoint(ch, x, y);
				hCellChDataSubTot->Fill(y);
			}
			hCellChDataSubTot->Fit("gaus", "Q");
			hCellChDataSubTot->GetXaxis()->SetTitle("ADC Counts");
			hCellChDataSubTot->GetFunction("gaus")->SetLineColor(4);
			hCellChDataSubTot->Draw();
		}

		cout << "Draw Pedestals" << endl;
		TString Title = "Pedestals";
		TCanvas *c2 = new TCanvas("c2", Title, 1050, 780);
		c2->SetBorderMode(0);
		c2->SetBorderSize(0.);
		c2->Divide(1, 8);
		//    gStyle->SetCanvasBorderMode(0.);
		//    gStyle->SetCanvasBorderSize(0.);
		Double_t x, y;
		for (int h = 0; h < DOMINO_NCH; h++) {
			c2->cd(h + 1);
			grPed = ((TGraphErrors *) grPedList->At(h));
			grPed->SetMarkerStyle(20);
			grPed->SetMarkerSize(0.5);
			grPed->GetYaxis()->SetLabelSize(0.12);
			grPed->GetXaxis()->SetLabelSize(0.12);
			//        cout <<  " err:" << grPed->GetErrorY(102) << " " ;
			//        cout << x << "--" << y << endl;
			grPed->Draw("APE");
		}

		cout << "Draw Data - Average charge" << endl;
		TString Title = "Average_Charge";
		TCanvas *cdata = new TCanvas("cdata", Title, 1050, 780);
		cdata->Divide(1, 8);
		Double_t x, y;
		for (int h = 0; h < DOMINO_NCH; h++) {
			cdata->cd(h + 1);
			grData = ((TGraphErrors *) grDataList->At(h));
			grData->SetMarkerStyle(20);
			grData->SetMarkerSize(0.3);
			grData->GetYaxis()->SetLabelSize(0.12);
			grData->GetXaxis()->SetLabelSize(0.12);
			grData->GetPoint(10, x, y);
			//        cout << x << "-" << y << endl;
			grData->Draw("APE");
		}

		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Average Charge - Pedestal subtracted";
		TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780);
		csubdata->Divide(1, 8);
		TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4);
		TH1D *resDist = new TH1D("resDist", "Residuals Signal", 100, -100., 100.);

		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Residuals";
		TCanvas *residuals = new TCanvas("residuals", Title, 1200, 780);
		resDist->DrawCopy();

	}

	fclose(fdata);

	hCellList->Delete();
	hCellSubList->Delete();
	hRMSList->Delete();
	hRMSFitList->Delete();
}
void fig1LumiCombinePASplots()
{
  bool SavePlots = kTRUE;
  
//================rebin for the turn on shape plots===================	
  double Jet20PtBin[] = {25,27,30,34,38,42,47,53,60,70,100,150};
  const int Jet20Nbins = sizeof(Jet20PtBin)/sizeof(double)-1;
	
  double Jet40PtBin[] = {25,26,27,28,29,30,31,32,33,34,35,36,37,40,43,47,52,57,62,67,72,77,85,110,130,150}; 
  const int Jet40Nbins = sizeof(Jet40PtBin)/sizeof(double)-1;
  
  double Jet60PtBin[] = {25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,60,63,66,70,74,78,82,86,90,95,100,110,120,135,150};
  const int Jet60Nbins = sizeof(Jet60PtBin)/sizeof(double)-1;

  double Jet80PtBin[] = {25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,77,79,81,83,85,87,90,95,102,110,120,130,140,150}; 
  const int Jet80Nbins = sizeof(Jet80PtBin)/sizeof(double)-1;

  double Jet100PtBinA[65];
  for(int i=0; i<65; i++) Jet100PtBinA[i] = 25+i;//25 to 89
  double Jet100PtBinB[14] = {91,94,97,98,104,110,115,120,125,130,135,140,145,150};

  double Jet100PtBin[79];
  for(int ibin=0; ibin<79; ibin++)
  {
    if(ibin<65) Jet100PtBin[ibin] = Jet100PtBinA[ibin];
    else  Jet100PtBin[ibin] = Jet100PtBinB[ibin-65];
  }

  const int Jet100Nbins = sizeof(Jet100PtBin)/sizeof(double)-1;
//=======================================================================

//========================Rebin For the Spectra=========================
  double Jet20RebinSpectra[] = {26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,78,82,90,100,110,120,130,140}; 
  const int Jet20RebinSpectraNbins = sizeof(Jet20RebinSpectra)/sizeof(double)-1;
  
  double Jet40RebinSpectra[] = {26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,125,130,140,150};
  const int Jet40RebinSpectraNbins = sizeof(Jet40RebinSpectra)/sizeof(double)-1;

//=====================================================================
  char JetTrig[5][256] = {"20","40","60","80","100"};
  	
  TString InputDir = "./input";
  TString PlotsDir = "./plots";
  
  TFile *f = new TFile(Form("%s/DATAPPbakPu3PFJetSpectraCombineTriggerQiaoTreeNoWeightNoJetIDCutFineBin.root",InputDir.Data())); 

  TH1F *hcombine = (TH1F *) f->Get("jetptEtaBin-10_10"); 
  
  TH1F *hjet[5];
  for(int itrig=0; itrig<5; itrig++)
  hjet[itrig] = (TH1F *) f->Get(Form("jet%sEtaBin-10_10",JetTrig[itrig]));

//========histograms for rebinning==========
  TH1F * hcombine_Rebin[5];
  hcombine_Rebin[0] = (TH1F *) hcombine->Rebin(Jet20Nbins,"rebincombine_Jet20",Jet20PtBin); 
  hcombine_Rebin[1] = (TH1F *) hcombine->Rebin(Jet40Nbins,"rebincombine_Jet40",Jet40PtBin);  
  hcombine_Rebin[2] = (TH1F *) hcombine->Rebin(Jet60Nbins,"rebincombine_Jet60",Jet60PtBin);
  hcombine_Rebin[3] = (TH1F *) hcombine->Rebin(Jet80Nbins,"rebincombine_Jet80",Jet80PtBin);
  hcombine_Rebin[4] = (TH1F *) hcombine->Rebin(Jet100Nbins,"rebincombine_Jet100",Jet100PtBin);


  TH1F *hjet_Rebin[5];
  hjet_Rebin[0] = (TH1F *) hjet[0] -> Rebin(Jet20Nbins,Form("RebinJet%s",JetTrig[0]),Jet20PtBin);
  hjet_Rebin[1] = (TH1F *) hjet[1] -> Rebin(Jet40Nbins,Form("RebinJet%s",JetTrig[1]),Jet40PtBin);
  hjet_Rebin[2] = (TH1F *) hjet[2] -> Rebin(Jet60Nbins,Form("RebinJet%s",JetTrig[2]),Jet60PtBin);
  hjet_Rebin[3] = (TH1F *) hjet[3] -> Rebin(Jet80Nbins,Form("RebinJet%s",JetTrig[3]),Jet80PtBin);
  hjet_Rebin[4] = (TH1F *) hjet[4] -> Rebin(Jet100Nbins,Form("RebinJet%s",JetTrig[4]),Jet100PtBin);

  TH1F *hjet_Rebin_Jet20 = (TH1F *) hjet[0] -> Rebin(Jet20RebinSpectraNbins,"Jet20RebinSpectra",Jet20RebinSpectra);
  normalizeByBinWidth(hjet_Rebin_Jet20);

  TH1F *hjet_Rebin_Jet40 = (TH1F *) hjet[1] -> Rebin(Jet40RebinSpectraNbins,"Jet40RebinSpectra",Jet40RebinSpectra);
  normalizeByBinWidth(hjet_Rebin_Jet40);

//================================================================
  
  double StartPoint = 25.;
  double EndPoint = 152.;

  TCanvas *c1 = new TCanvas("c1","c1",50,100,599,599);	
  gStyle->SetOptFit(1);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  c1->Range(-38.59656,-12.02472,644.9871,2.486126);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetTickx(1);
  c1->SetTicky(1);
  c1->SetLeftMargin(0.1552174);
  c1->SetRightMargin(0.02034783);
  c1->SetTopMargin(0.08166969);
  c1->SetBottomMargin(0.1288566);
  c1->SetFrameFillStyle(0);
  c1->SetFrameBorderMode(0);

  c1->cd();
  c1->cd()->SetLogy(); 
 

  TH1F *hDum1 =  new TH1F("hdum1","hdum1",13,StartPoint,EndPoint);
  hDum1->SetMinimum(1.E3);
  hDum1->SetMaximum(1.E8);
  hDum1->GetXaxis()->SetTitle("p_{T} [GeV/c]");
  hDum1->GetXaxis()->SetTitleSize(0.05);
  hDum1->GetXaxis()->SetLabelSize(0.045);
  hDum1->GetXaxis()->SetTitleOffset(1.18);
  hDum1->GetXaxis()->CenterTitle();
  hDum1->GetYaxis()->SetTitle("dN_{jet}/dp_{T} [(GeV/c)^{-1}]");
  hDum1->GetYaxis()->SetTitleSize(0.05);
  hDum1->GetYaxis()->SetLabelSize(0.045);
  hDum1->GetYaxis()->SetTitleOffset(1.45);
  hDum1->GetYaxis()->CenterTitle();
  hDum1->DrawCopy();

  hjet_Rebin_Jet20->GetXaxis()->SetRangeUser(StartPoint+1,EndPoint-2);
  hjet_Rebin_Jet20->SetMarkerStyle(20);
  hjet_Rebin_Jet20->SetMarkerColor(1);
  hjet_Rebin_Jet20->SetMarkerSize(1.0);
  hjet_Rebin_Jet20->SetLineColor(1);
  hjet_Rebin_Jet20->DrawCopy("same");

  hjet_Rebin_Jet40->GetXaxis()->SetRangeUser(StartPoint+1,EndPoint-2);
  hjet_Rebin_Jet40->SetMarkerStyle(20);
  hjet_Rebin_Jet40->SetMarkerColor(2);
  hjet_Rebin_Jet40->SetMarkerSize(1.0);
  hjet_Rebin_Jet40->SetLineColor(2);
  hjet_Rebin_Jet40->DrawCopy("same");

  for(int itrig=2; itrig<5; itrig++)
  {	 	  
    hjet[itrig]->Rebin(2);
    normalizeByBinWidth(hjet[itrig]);
    hjet[itrig]->GetXaxis()->SetRangeUser(StartPoint+1,EndPoint-2);	   
    hjet[itrig]->SetMarkerStyle(20);
    hjet[itrig]->SetMarkerColor(1+itrig);
    hjet[itrig]->SetMarkerSize(1.0);
    hjet[itrig]->SetLineColor(1+itrig);
    hjet[itrig]->DrawCopy("same");
  }
  hcombine->Rebin(2);
  normalizeByBinWidth(hcombine);
  hcombine->GetXaxis()->SetRangeUser(StartPoint+1,EndPoint-2);
  hcombine->SetMarkerStyle(24);
  hcombine->SetMarkerColor(1);
  hcombine->SetMarkerSize(1.5);
  hcombine->SetLineColor(1);
  hcombine->DrawCopy("same");

  TLegend *leg1 = new TLegend(0.5,0.69,0.7,0.88);
  leg1->SetBorderSize(0);
  leg1->SetTextFont(43);
  leg1->SetTextSize(20);
  leg1->AddEntry(hcombine,"Combined","P");
  leg1->AddEntry(hjet_Rebin_Jet20,"Jet20","P");
  leg1->AddEntry(hjet_Rebin_Jet40,"Jet40","P");
  leg1->SetFillColor(kWhite);
  leg1->Draw("same");

  TLegend *leg2 = new TLegend(0.72,0.69,0.86,0.88);
  leg2->SetBorderSize(0);
  leg2->SetTextFont(43);
  leg2->SetTextSize(20);
  for(int i=2; i<5; i++)
  {
    leg2->AddEntry(hjet[i],Form("Jet%s",JetTrig[i]),"P");
  }
  leg2->SetFillColor(kWhite);
  leg2->Draw("same");

  drawText("CMS Preliminary, pPb #sqrt{s_{NN}} = 5.02 TeV",0.28,0.95,20);
  drawCMS(0.68,0.640,35);

  TLatex *tex1 = new TLatex(0.68,0.5,"| #eta_{CM} | < 1.0");
  tex1->SetTextFont(43);
  tex1->SetTextSize(20);
  tex1->SetNDC();
  tex1->Draw("same");

  TLatex *tex2 = new TLatex(0.20,0.18,"Anti-k_{T} Particle Flow Jets: R=0.3");
  tex2->SetTextFont(43);
  tex2->SetTextSize(20);
  tex2->SetNDC();
  tex2->Draw("same");

//====================Relative shape=======================  
  TCanvas *c2 = new TCanvas("c2","c2",400,50,599,599);
  gStyle->SetOptFit(1);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  c2->Range(-38.59656,-12.02472,644.9871,2.486126);
  c2->SetFillColor(0);
  c2->SetBorderMode(0);
  c2->SetBorderSize(2);
  c2->SetTickx(1);
  c2->SetTicky(1);
  c2->SetLeftMargin(0.1552174);
  c2->SetRightMargin(0.02034783);
  c2->SetTopMargin(0.08166969);
  c2->SetBottomMargin(0.1288566);
  c2->SetFrameFillStyle(0);
  c2->SetFrameBorderMode(0);   
  c2->cd();
  	
  TH1F *hDum2 = new TH1F("hdum2","hdum2",13,StartPoint,EndPoint);
  hDum2->SetMinimum(0.);
  hDum2->SetMaximum(1.5);
  hDum2->GetXaxis()->SetTitle("p_{T} [GeV/c]");
  hDum2->GetXaxis()->SetTitleSize(0.05);
  hDum2->GetXaxis()->SetTitleOffset(1.2);
  hDum2->GetXaxis()->SetLabelSize(0.045);
  hDum2->GetXaxis()->CenterTitle();
  hDum2->GetYaxis()->SetTitle("Rel. Shape");
  hDum2->GetYaxis()->SetTitleSize(0.05);
  hDum2->GetYaxis()->SetTitleOffset(1.4);
  hDum2->GetYaxis()->SetLabelSize(0.045);
  hDum2->GetYaxis()->CenterTitle();
  hDum2->DrawCopy();

  TH1F *hRatio[5];
  for(int itrig=0; itrig<5; itrig++)
  {
    hRatio[itrig] = (TH1F *)hjet_Rebin[itrig]->Clone(hjet[itrig]->GetName());
    hRatio[itrig] -> Divide(hcombine_Rebin[itrig]);
    hRatio[itrig] -> SetMarkerSize(1.5);
    hRatio[itrig] -> SetMarkerStyle(20);
    hRatio[itrig] -> SetMarkerColor(1+itrig);
    hRatio[itrig] -> SetLineColor(1+itrig);
    hRatio[itrig] -> GetXaxis()->SetRangeUser(StartPoint+1,EndPoint-2);
    hRatio[itrig] -> DrawCopy("same");
  }

  drawText("CMS Preliminary, pPb #sqrt{s_{NN}} = 5.02 TeV",0.28,0.95,20);   
  drawCMS(0.2383193,0.8743608,35);
  
  TLegend *leg3 = new TLegend(0.6386555,0.2304904,0.7394958,0.39098599);
  leg3->SetBorderSize(0);
  leg3->SetTextFont(43);
  leg3->SetTextSize(20);
  for(int i = 0; i<2; i++) leg3->AddEntry(hRatio[i],Form("Jet%s",JetTrig[i]));
  leg3->SetFillColor(kWhite);
  leg3->Draw("same");

  TLegend *leg4 = new TLegend(0.7831933,0.2204904,0.8823529,0.4098599);
  leg4->SetBorderSize(0);
  leg4->SetTextFont(43);
  leg4->SetTextSize(20);
  for(int i = 2; i<5; i++) leg4->AddEntry(hRatio[i],Form("Jet%s",JetTrig[i]));
  leg4->SetFillColor(kWhite);
  leg4->Draw("same");
  
  TLatex *tex3 = new TLatex(0.2234454,0.7490543,"| #eta_{CM} | < 1.0");
  tex3->SetTextFont(43);
  tex3->SetTextSize(20);
  tex3->SetNDC();
  tex3->Draw("same");

  TLatex *tex4 = new TLatex(0.4552101,0.7775832,"Anti-k_{T} Particle Flow Jets: R=0.3");
  tex4->SetTextFont(43);
  tex4->SetTextSize(20);
  tex4->SetNDC();
  tex4->Draw("same");


  TLine *l = new TLine(StartPoint,1,EndPoint,1);
  l->SetLineStyle(2);
  l->SetLineWidth(2);
  l->SetLineColor(kBlack);
  l->Draw("same");
  
  if(SavePlots) 
  {
    c1->SaveAs("LumiCombineSpectrawithunit.pdf");
    c1->SaveAs("LumiCombineSpectrawithunit.gif");
    c2->SaveAs("RelativeShapewithunit.pdf");
    c2->SaveAs("RelativeShapewithunit.gif");
  }
}
void plotFrac(TList* HistList, TH1F* compT, std::string name, bool fracAll){

  gROOT->SetBatch();
  system("mkdir -p plots/ada/fracs");
  system("mkdir -p plots/grad/fracs");

  std::string bdt;
  TString str = compT->GetName();
  if (str.Contains("ada")) bdt="ada";
  if (str.Contains("grad")) bdt="grad";

  int nHists=HistList->GetEntries();
  TH1F *comp = linearBin(compT);
  TH1F *uandd[nHists];
  
  gROOT->SetStyle("Plain");
  gROOT->ForceStyle();
  gStyle->SetOptStat(0);
  TCanvas *canv = new TCanvas("","",700,700);
  
  canv->Divide(1,2,0.1,0.1);
  canv->cd(1);
  gPad->SetPad(0.01,0.3,0.99,0.99);
  gPad->SetBottomMargin(0.0);
  gPad->SetLeftMargin(0.1);
  comp->SetLineColor(1);
  comp->SetFillColor(kGray);
  comp->Draw("hist");
  comp->SetTitle(("Up, down and interpolated templates for "+bdt+" "+name).c_str());
  comp->GetYaxis()->SetRangeUser(0.0,((TH1F*)HistList->At(0))->GetMaximum()+0.5);
  comp->GetYaxis()->SetTitle("Events / bin");
  comp->GetXaxis()->SetTitle("Category");
  int mass;
  if (name=="syst120") mass=120;
  if (name=="syst135") mass=135;
  TLegend *leg = new TLegend(0.6,0.5,0.88,0.88);
  leg->SetLineColor(0);
  leg->SetFillColor(0);
  if (name=="syst120" || name=="syst135"){
    leg->AddEntry(comp,Form("True %d signal binned at %d",mass,mass),"f");
  }
  
  canv->cd(2);
  gPad->SetPad(0.01,0.01,0.99,0.3);
  gPad->SetTopMargin(0.0);
  gPad->SetBottomMargin(0.2);
  gPad->SetLeftMargin(0.1);
  TF1 *line = new TF1("line","0.0",0.,comp->GetBinLowEdge(comp->GetNbinsX()+1));
  line->SetLineColor(kBlack);
  
  for (int i=0; i<nHists; i++){
    TH1F *temp = linearBin((TH1F*)HistList->At(i));
    temp->SetLineColor((i+1)*2);
    if (!fracAll && i==nHists-1) temp->SetLineColor(kBlack); 
    canv->cd(1);
    temp->DrawCopy("same e");
    uandd[i]= (TH1F*)temp->Clone();
    uandd[i]->Add(comp,-1);
    uandd[i]->Divide(temp);
    uandd[i]->Scale(-100.);
    //uandd[i]->Divide(comp);
    if (name=="syst120" || name=="syst135") {
      if (i==0) leg->AddEntry(uandd[i],Form("True %d signal binned at %d",mass+5,mass),"lep");
      if (i==1) leg->AddEntry(uandd[i],Form("True %d signal binned at %d",mass-5,mass),"lep");
      if (i==nHists-1) leg->AddEntry(uandd[i],Form("Interpolated %d signal",mass),"lep");
    }
    //uandd[i]->Scale(100.0);
    canv->cd(2);
    if (fracAll){
      if (i==0) uandd[i]->Draw("e");
      else {
        uandd[i]->Draw("same e");
        line->Draw("same");
      }
    }
    else {
      if (i==nHists-1) {
        uandd[i]->Draw("e");
        line->Draw("same");
      }
    }
    uandd[i]->SetTitle("");
    uandd[i]->GetYaxis()->SetLabelSize(0.08);
    uandd[i]->GetYaxis()->SetRangeUser(-50.,50.);
    uandd[i]->GetYaxis()->SetTitle("#frac{#Delta_{int}}{int} %");
    uandd[i]->GetYaxis()->SetTitleOffset(0.4);
    uandd[i]->GetYaxis()->SetTitleSize(0.08);
    uandd[i]->GetXaxis()->SetLabelSize(0.08);
    uandd[i]->GetXaxis()->SetTitle("BDT output");
    uandd[i]->GetXaxis()->SetTitleSize(0.08);
    canv->cd(1);
    if (name=="syst120" || name=="syst135") leg->Draw("same");
  }
  

  canv->Print(("plots/"+bdt+"/fracs/"+name+".png").c_str(),"png");
  delete canv;
  
  fracCalls++;
  
}
Пример #13
0
//_____________________________________________________________________________
void ProofSimple::Terminate()
{
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.

   //
   // Create a canvas, with 100 pads
   //
   TCanvas *c1 = (TCanvas *) gDirectory->FindObject("c1");
   if (c1) {
      gDirectory->Remove(c1);
      delete c1;
   }
   c1 = new TCanvas("c1","Proof ProofSimple canvas",200,10,700,700);
   Int_t nside = (Int_t)TMath::Sqrt((Float_t)fNhist);
   nside = (nside*nside < fNhist) ? nside+1 : nside;
   c1->Divide(nside,nside,0,0);

   Bool_t tryfc = kFALSE;
   TH1F *h = 0;
   for (Int_t i=0; i < fNhist; i++) {
      if (!(h = dynamic_cast<TH1F *>(TProof::GetOutput(Form("h%d",i), fOutput)))) {
         // Not found: try TFileCollection
         tryfc = kTRUE;
         break;
      }
      c1->cd(i+1);
      h->DrawCopy();
   }

   // If the histograms are not found they may be in files: is there a file collection?
   if (tryfc && GetHistosFromFC(c1) != 0) {
      Warning("Terminate", "histograms not found");
   } else {
      // Final update
      c1->cd();
      c1->Update();
   }

   // Analyse hlab, if there
   if (fHLab && !gROOT->IsBatch()) {
      // Printout
      Int_t nb = fHLab->GetNbinsX();
      if (nb > 0) {
         Double_t entb = fHLab->GetEntries() / nb;
         if (entb) {
            for (Int_t i = 0; i < nb; i++) {
               TString lab = TString::Format("hl%d", i);
               Int_t ib = fHLab->GetXaxis()->FindBin(lab);
               Info("Terminate","  %s [%d]:\t%f", lab.Data(), ib, fHLab->GetBinContent(ib)/entb); 
            }
         } else
            Warning("Terminate", "no entries in the hlab histogram!");
      }
   }

   // Process the ntuple, if required
   if (fHasNtuple != 1 || !fPlotNtuple) return;

   if (!(fNtp = dynamic_cast<TNtuple *>(TProof::GetOutput("ntuple", fOutput)))) {
      // Get the ntuple from the file
      if ((fProofFile =
            dynamic_cast<TProofOutputFile*>(fOutput->FindObject("SimpleNtuple.root")))) {

         TString outputFile(fProofFile->GetOutputFileName());
         TString outputName(fProofFile->GetName());
         outputName += ".root";
         Printf("outputFile: %s", outputFile.Data());

         // Read the ntuple from the file
         fFile = TFile::Open(outputFile);
         if (fFile) {
            Printf("Managed to open file: %s", outputFile.Data());
            fNtp = (TNtuple *) fFile->Get("ntuple");
         } else {
            Error("Terminate", "could not open file: %s", outputFile.Data());
         }
         if (!fFile) return; 

      } else {
         Error("Terminate", "TProofOutputFile not found");
         return;
      }
   }
   // Plot ntuples
   if (fNtp) PlotNtuple(fNtp, "proof ntuple");
}
Пример #14
0
void plotfigure4(bool nodata = false, bool prelim = false, bool AMPT=true, bool SONIC=true, 
                 bool superSONIC=true, bool IPGLASMA=true, bool BOZEK=true) {

  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  TCanvas *c1 = new TCanvas("c1","c1",10,10,700,700);

  // create template histogram
  TH1F *htemplate = new TH1F("htemplate","htemplate",10,0.0,3.5);
  htemplate->SetMaximum(0.30); //25);
  htemplate->SetXTitle("p_{T} [GeV/c]");
  //  htemplate->SetYTitle("v_{n} Coefficient");
  htemplate->SetYTitle("v_{n}");
  htemplate->GetYaxis()->SetTitleOffset(1.2);
  htemplate->DrawCopy();

  // grab AMPT points (http://arxiv.org/abs/1501.06880)
  TFile *fin_ampt = new TFile("AMPT_3HeAu_central_vn_new.root");
  // copy into new TGraphs for easier manipulcation
  //TGraphErrors *tamptv2 = gv2->Clone();
  //TGraphErrors *tamptv3 = gv3->Clone();

  TGraphErrors *tamptv22 = gv2->Clone();
  TGraphErrors *tamptv32 = gv3->Clone();
  
  TGraph *tamptv2 = new TGraph();
  TGraph *tamptv3 = new TGraph();
  for (int i=0;i<gv2->GetN();i++) {
    double x; double y;
    gv2->GetPoint(i,x,y);
    tamptv2->SetPoint(i,x,y);
  }
  for (int i=0;i<gv3->GetN();i++) {
    double x; double y;
    gv3->GetPoint(i,x,y);
    tamptv3->SetPoint(i,x,y);
  }
  
  

  
  
  tamptv22->SetFillColor(42);
  tamptv32->SetFillColor(42);

  tamptv22->SetLineColor(46);
  tamptv22->SetLineWidth(3);
  tamptv22->SetLineStyle(1);
  if (AMPT) tamptv22->Draw("3,same");
  tamptv32->SetLineColor(46);
  tamptv32->SetLineWidth(3);
  tamptv32->SetLineStyle(1);
  if (AMPT) tamptv32->Draw("3,same");

  tamptv2->SetLineColor(46);
  tamptv2->SetLineWidth(3);
  tamptv2->SetLineStyle(1);
  if (AMPT) tamptv2->Draw("l,same");
  tamptv3->SetLineColor(46);
  tamptv3->SetLineWidth(3);
  tamptv3->SetLineStyle(1);
  if (AMPT) tamptv3->Draw("l,same");
  

  // IPGlasma curves (http://arxiv.org/abs/1407.7557)
  TGraph *tipglasmav2 = new TGraph("ipglasmaflowv2.dat","%lg, %lg");
  tipglasmav2->SetLineColor(6);
  tipglasmav2->SetLineWidth(3);
  tipglasmav2->SetLineStyle(1);
  if (IPGLASMA) tipglasmav2->Draw("l,same");
  TGraph *tipglasmav3 = new TGraph("ipglasmaflowv3.dat","%lg, %lg");
  tipglasmav3->SetLineColor(6);
  tipglasmav3->SetLineWidth(3);
  tipglasmav3->SetLineStyle(1);
  if (IPGLASMA) tipglasmav2->Draw("l,same");
  if (IPGLASMA) tipglasmav3->Draw("l,same"); 

  // Now Paul Romatschke result without and with preflow
  // Refs:  http://arxiv.org/abs/1502.04745

  double sonic_beta2[100][13];
  double sonic_beta3[100][13];
  double supersonic_beta2[100][13];
  double supersonic_beta3[100][13];
  // pt:yield:yields:v1:v1s:v2:v2s:v3:v3s:v4:v4s:v5:v5s 

  ifstream myfile;
  myfile.open("res_he3config-42mb-s63-sigma0.4-scal2.00-beta2-nopf-av_unid_vn.dat");
  int j=0;
  string dummyLine;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> sonic_beta2[j][0] >> sonic_beta2[j][1] >> sonic_beta2[j][2] >>
		   sonic_beta2[j][3] >> sonic_beta2[j][4] >> sonic_beta2[j][5] >>
		   sonic_beta2[j][6] >> sonic_beta2[j][7] >> sonic_beta2[j][8] >>
		   sonic_beta2[j][9] >> sonic_beta2[j][10] >> sonic_beta2[j][11] >>
		   sonic_beta2[j][12];
    cout << "pt = " << sonic_beta2[j][0] << " v2 = " << sonic_beta2[j][5] << endl;
    j++;
  }
  myfile.close();

  myfile.open("res_he3config-42mb-s63-sigma0.4-scal2.00-beta3-nopf-av_unid_vn.dat");
  j=0;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> sonic_beta3[j][0] >> sonic_beta3[j][1] >> sonic_beta3[j][2] >>
		   sonic_beta3[j][3] >> sonic_beta3[j][4] >> sonic_beta3[j][5] >>
		   sonic_beta3[j][6] >> sonic_beta3[j][7] >> sonic_beta3[j][8] >>
		   sonic_beta3[j][9] >> sonic_beta3[j][10] >> sonic_beta3[j][11] >>
		   sonic_beta3[j][12];
    j++;
  }
  myfile.close();

  myfile.open("res_he3config-42mb-s63-sigma0.4-scal2.00-beta2-av_unid_vn.dat");
  j=0;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> supersonic_beta2[j][0] >> supersonic_beta2[j][1] >> supersonic_beta2[j][2] >>
		   supersonic_beta2[j][3] >> supersonic_beta2[j][4] >> supersonic_beta2[j][5] >>
		   supersonic_beta2[j][6] >> supersonic_beta2[j][7] >> supersonic_beta2[j][8] >>
		   supersonic_beta2[j][9] >> supersonic_beta2[j][10] >> supersonic_beta2[j][11] >>
		   supersonic_beta2[j][12];
    j++;
  }
  myfile.close();

  myfile.open("res_he3config-42mb-s63-sigma0.4-scal2.00-av_unid_vn.dat");
  j=0;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> supersonic_beta3[j][0] >> supersonic_beta3[j][1] >> supersonic_beta3[j][2] >>
		   supersonic_beta3[j][3] >> supersonic_beta3[j][4] >> supersonic_beta3[j][5] >>
		   supersonic_beta3[j][6] >> supersonic_beta3[j][7] >> supersonic_beta3[j][8] >>
		   supersonic_beta3[j][9] >> supersonic_beta3[j][10] >> supersonic_beta3[j][11] >>
		   supersonic_beta3[j][12];
    j++;
  }
  myfile.close();

  TGraph *tsonic_beta2_v2 = new TGraph();
  TGraph *tsonic_beta2_v3 = new TGraph();
  TGraph *tsonic_beta3_v2 = new TGraph();
  TGraph *tsonic_beta3_v3 = new TGraph();

  TGraphErrors *tesonic_v2 = new TGraphErrors();
  TGraphErrors *tesonic_v3 = new TGraphErrors();

  TGraph *tsupersonic_beta2_v2 = new TGraph();
  TGraph *tsupersonic_beta2_v3 = new TGraph();
  TGraph *tsupersonic_beta3_v2 = new TGraph();
  TGraph *tsupersonic_beta3_v3 = new TGraph();

  TGraphErrors *tesupersonic_v2 = new TGraphErrors();
  TGraphErrors *tesupersonic_v3 = new TGraphErrors();

  for (int i=0;i<25;i++) {

    tsonic_beta2_v2->SetPoint(i,sonic_beta2[i][0],sonic_beta2[i][5]);
    tsonic_beta3_v2->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][5]);
    tesonic_v2->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][5]);
    tesonic_v2->SetPointError(i,0.0,TMath::Abs(sonic_beta2[i][5]-sonic_beta3[i][5]));

    tsonic_beta2_v3->SetPoint(i,sonic_beta2[i][0],sonic_beta2[i][7]);
    tsonic_beta3_v3->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][7]);
    tesonic_v3->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][7]);
    tesonic_v3->SetPointError(i,0.0,TMath::Abs(sonic_beta2[i][7]-sonic_beta3[i][7]));

    tsupersonic_beta2_v2->SetPoint(i,supersonic_beta2[i][0],supersonic_beta2[i][5]);
    tsupersonic_beta3_v2->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][5]);
    tesupersonic_v2->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][5]);
    tesupersonic_v2->SetPointError(i,0.0,TMath::Abs(supersonic_beta2[i][5]-supersonic_beta3[i][5]));

    tsupersonic_beta2_v3->SetPoint(i,supersonic_beta2[i][0],supersonic_beta2[i][7]);
    tsupersonic_beta3_v3->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][7]);
    tesupersonic_v3->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][7]);
    tesupersonic_v3->SetPointError(i,0.0,TMath::Abs(supersonic_beta2[i][7]-supersonic_beta3[i][7]));

  }


  tesonic_v2->SetFillColor(29);
  tesonic_v2->SetLineWidth(3);
  if (SONIC) tesonic_v2->Draw("3,same");
  tesonic_v3->SetFillColor(29);
  tesonic_v3->SetLineWidth(3);
  if (SONIC) tesonic_v3->Draw("3,same");

  tesupersonic_v2->SetFillColor(8);
  tesupersonic_v2->SetLineWidth(3);
  if (superSONIC) tesupersonic_v2->Draw("3,same");
  tesupersonic_v3->SetFillColor(8);
  tesupersonic_v3->SetLineWidth(3);
  if (superSONIC) tesupersonic_v3->Draw("3,same");

  tsonic_beta3_v2->SetLineColor(1);
  tsonic_beta3_v2->SetLineWidth(3);
  tsonic_beta3_v3->SetLineColor(1);
  tsonic_beta3_v3->SetLineWidth(3);

  tsupersonic_beta3_v2->SetLineColor(1);
  tsupersonic_beta3_v2->SetLineWidth(3);
  tsupersonic_beta3_v3->SetLineColor(1);
  tsupersonic_beta3_v3->SetLineWidth(3);

  tsupersonic_beta3_v2->SetFillColor(8);
  tsonic_beta3_v2->SetFillColor(29);

  

  // Bozek theory
  TGraph *bozekv2 = new TGraph("bozekv2.dat","%lg, %lg");
  bozekv2->SetLineWidth(3);
  bozekv2->SetLineStyle(2);
  //if (BOZEK) bozekv2->Draw("l,same");

  TGraph *bozekv3 = new TGraph("bozekv3.dat","%lg, %lg");
  bozekv3->SetLineWidth(3);
  bozekv3->SetLineStyle(2);
  //if (BOZEK) bozekv3->Draw("l,same");

  //==============================================================
  //plot data added by shengli
  if (!nodata) {

  float ptv2[24];
  float eptv2[24], sptv2[24];
  float v2mpcs[24], ev2mpcs[24], sv2mpcs[24], asv2mpcs1[24];

  float ptv3[24];
  float eptv3[24], sptv3[24];
  float v3mpcs[24], ev3mpcs[24], sv3mpcs[24], asv3mpcs1[24], asv3mpcs2[24];

  int imax = 13;
  if (prelim) imax = 10;

  // final PPG181 data!!!!
  
  if (!prelim) {
    ifstream finv2("He3Au_0_5_v2_asys_new.dat");
    ifstream finv3("He3Au_0_5_v3_asys_new.dat");
  }
  if (prelim) {
    ifstream finv2("He3Au_0_5_v2_prelim.dat");
    ifstream finv3("He3Au_0_5_v3_prelim.dat");
  }

  
  for(int i=0; i<imax; i++){
    eptv2[i]=0;
    sptv2[i]=0.05;
    finv2>>ptv2[i]>>v2mpcs[i]>>ev2mpcs[i]>>sv2mpcs[i]>>asv2mpcs1[i];
    
  }
  finv2.close();
  
  TGraphErrors *grmpcs2 = new TGraphErrors(imax, ptv2, v2mpcs, eptv2, ev2mpcs);
  TGraphErrors *sgrmpcs2 = new TGraphErrors(imax, ptv2, v2mpcs, sptv2, sv2mpcs);
 

  for(int i=0; i<imax; i++){
    eptv3[i]=0;
    sptv3[i]=0.05;
    finv3>>ptv3[i]>>v3mpcs[i]>>ev3mpcs[i]>>sv3mpcs[i]>>asv3mpcs1[i];

  }
  finv3.close();
  
  TGraphErrors *grmpcs3 = new TGraphErrors(imax, ptv3, v3mpcs, eptv3, ev3mpcs);
  TGraphErrors *sgrmpcs3 = new TGraphErrors(imax, ptv3, v3mpcs, sptv3, sv3mpcs);
  

  float pt[13], ept[13], spt[13], v2[13], ev2[13], sv2[13];
  ifstream fppg161("v2_pt_dAu_00_05_sys_new.dat");

  for(int i=0; i<13; i++){
    spt[i]=0.05;
    ept[i]=0.0;
    fppg161>>pt[i]>>v2[i]>>ev2[i]>>sv2[i];
  }
  fppg161.close();

  TGraphErrors *grppg161 = new TGraphErrors(10, pt, v2, ept, ev2);
  TGraphErrors *sgrppg161 = new TGraphErrors(10, pt, v2, spt, sv2);

  // TLegend *leg1 = new TLegend(0.54,0.74,0.74,0.86);
  // leg1->SetFillColor(10);
  // leg1->SetLineStyle(4000);
  // leg1->SetLineColor(10);
  // leg1->SetLineWidth(0.);
  // leg1->SetTextSize(0.05);
  // leg1->SetBorderSize(0);
  // leg1->AddEntry(grmpcs2,"v_{2}","P");
  //  leg1->Draw();

  //TLegend *leg2 = new TLegend(0.11,0.63,0.79,0.89);
  //leg2->SetFillColor(10);
  //leg2->SetLineStyle(4000);
  //leg2->SetLineColor(10);
  //leg2->SetLineWidth(0.);
  //leg2->SetTextSize(0.05);
  //leg2->SetBorderSize(0);
  //leg2->AddEntry(grmpcs3,"v_{3}","P");
  //  leg2->Draw();
  }
Пример #15
0
void scan2() {

    /*  TFile f1("hist.root");
      TFile f2("SysTot.root");

      TH1D *datahist = (TH1D*)f1.Get("datahist");
      TH1D *fithist = (TH1D*)f1.Get("fithist");

      TH1D *totlow = (TH1D*)f2.Get("totlow");
      TH1D *tothigh = (TH1D*)f2.Get("tothigh");
    */

    TF1 *fun1 = new TF1("fun",fun,0,1000,3);

    TFile f("Output.root");
    TH1F *datahist = dynamic_cast<TH1F*> (f.Get("InvMass"));
    TH1F *fithist = dynamic_cast<TH1F*> (f.Get("hist_err"));
    TH1F *tothigh = dynamic_cast<TH1F*> (f.Get("SystPlus"));
    TH1F *totlow = dynamic_cast<TH1F*> (f.Get("SystMinus"));
    new TCanvas();
    datahist->DrawCopy();
    fithist->DrawCopy("same");
    gPad->SetEditable(0);

    /*	if (datahist->IsZombie()) { std::cout << "Err! datahist not found " << std::endl; return; }
    	if (fithist->IsZombie()) { std::cout << "Err! err_hist not found " << std::endl; return; }
    	if (tothigh->IsZombie()) { std::cout << "Err! syst_plus hist not found " << std::endl; return; }
    	if (totlow->IsZombie()) { std::cout << "Err! syst_minus hist not found " << std::endl; return; }
    */

    TH1D *p = new TH1D("p","Probability",100,150,900);

    for (int i = 1; i<=fithist->GetNbinsX(); i++)
    {
        double mass = fithist->GetBinCenter(i);

        if (mass>440 && mass<450)
        {
            double sigma = sqrt(2.0)*sqrt(pow(0.135*sqrt(mass/2.0),2)+
                                          pow(0.02*(mass/2.0),2));
            cout<< " ===================== mass +/- sigma = " << mass<<"+/-"<<sigma<<endl;
            int bin1 = fithist->FindBin(mass-sigma/2);
            int bin2 = fithist->FindBin(mass+sigma/2);
            cout<<mass<<" "<<bin1<<" "<<bin2<<endl;
            double data = 0;
            double bg = 0;
            double err = 0;

            for (int j = bin1; j<=bin2; j++)
            {
                data+=datahist->GetBinContent(j);
                bg+=fithist->GetBinContent(j);
                double err1 = -totlow->GetBinContent(j);
                double err2 = tothigh->GetBinContent(j);
                err+=TMath::Max(err1,err2)*bg; //why multiply by bg???
            }
            cout << "Total Data/Bg+/-err in mass window[" << mass << "] = "<< data <<"/ "<< bg << "+/-" << err <<endl;
            double prob = 0;
            fun1->SetParameter(0,bg);
            fun1->SetParameter(1,err);

            for (int j = int(data+0.001); j<100; j++) {
                fun1->SetParameter(2,j);
                //fun1->Print();
                //cout << "Evaluating Intrgral for j = " << j << " from x0= " << TMath::Max(0.0,bg-10*err) << " to x1 = " << bg+10*err << endl;
                double val = fun1->Integral(TMath::Max(0.0,bg-10*err),bg+10*err);
                //double val = fun1->Integral(TMath::Max(0.0,bg-2*err),bg+2*err);
                /*for (int z=TMath::Max(0.0,bg-2*err); z < bg+2*err; ++z)
                {
                	if (c<4)
                	{
                	std::cout << "func at [" << z << "]=" << 	fun1->Eval(z) << std::endl;
                	}
                }
                */
                prob += val;
            }
            cout<< "Prob for mass[" << mass<<"]="<< prob <<endl;
            p->SetBinContent(p->FindBin(mass),prob);
        }
    }
    /*
    delete gRandom;
    gRandom = (TRandom*) new TRandom3;
    gRandom->SetSeed(3);

    TH1D *minp = new TH1D("minp","Minimum Probability of Each PseudoExpt",100,0,0.2);

    //int nexp = 50000;
    int nexp = 10;

    TH1D *htemp = (TH1D*)datahist->Clone("htemp");

    for (int iexp = 0; iexp<nexp; iexp++){
      //if (iexp%10==0) cout<<iexp<<endl;
      //generate pseudo-experiments
      htemp->Reset();
      for (int i = 1; i<=htemp->GetNbinsX(); i++){
        double mass = htemp->GetBinCenter(i);
        if (mass>150&&mass<650){
    double bg = fithist->GetBinContent(i);
    double err1 = -totlow->GetBinContent(i);
    double err2 = tothigh->GetBinContent(i);
    double err = TMath::Max(err1,err2)*bg;
    double mean = gRandom->Gaus(bg,err);
    if (mean<0) mean = 0;
    htemp->SetBinContent(i,gRandom->Poisson(mean));
        }
      }
      double minprob = 2.;
      for (int i = 1; i<=fithist->GetNbinsX(); i++){
        double mass = fithist->GetBinCenter(i);
        if (mass>150&&mass<650){
    double sigma = sqrt(2.0)*sqrt(pow(0.135*sqrt(mass/2.0),2)+
    			      pow(0.02*(mass/2.0),2));
    //cout<<mass<<" "<<sigma<<endl;
    int bin1 = fithist->FindBin(mass-sigma/2);
    int bin2 = fithist->FindBin(mass+sigma/2);
    //cout<<mass<<" "<<bin1<<" "<<bin2<<endl;
    double data = 0;
    double bg = 0;
    double err = 0;
    for (int j = bin1; j<=bin2; j++){
      data+=htemp->GetBinContent(j);
      bg+=fithist->GetBinContent(j);
      double err1 = -totlow->GetBinContent(j);
      double err2 = tothigh->GetBinContent(j);
      err+=TMath::Max(err1,err2)*bg;
    }
    //cout<<mass<<" "<<data<<" "<<bg<<" "<<err<<endl;
    double prob = 0;
    fun1->SetParameter(0,bg);
    fun1->SetParameter(1,err);
    for (int j = int(data+0.001); j<100; j++){
      fun1->SetParameter(2,j);
      prob += fun1->Integral(TMath::Max(0.0,bg-10*err),bg+10*err);
    }
    if (prob<minprob) minprob=prob;
        }
      }
      minp->Fill(minprob);
    }
    */
    TCanvas *c1 = new TCanvas("c1","c1");
    TH2D *fr = new TH2D("fr","",100,150,900,100,1e-5,2);
    fr->SetStats(0);
    fr->SetXTitle("M(#gamma,lead jet)(GeV)");
    fr->SetYTitle("Prob of fluctuation #geq N_{obs}");
    fr->GetXaxis()->CenterTitle();
    fr->GetYaxis()->CenterTitle();
    fr->DrawCopy();
    p->SetLineWidth(2);
    p->DrawCopy("same");
    double minp=0;
    double mgg=0;
    double minc = 10;
    for (int i = 1; i<=p->GetNbinsX(); i++) {
        double bin = p->GetBinCenter(i);
        double binc = p->GetBinContent(i);
        if (binc<minc) {
            minp = binc;
            mgg = bin;
            minc = binc;
        }
    }
    cout<<mgg<<" "<<minp<<endl;
    gPad->SetLogy();
    double p1s = 0.00458319;
    double m1s = 0.0435982;
    double s3s = 0.000100319;
    TLine *l1 = new TLine(150,p1s,900,p1s);
    TLine *l2 = new TLine(150,m1s,900,m1s);
    TLine *l3 = new TLine(150,s3s,900,s3s);
    l1->SetLineColor(4);
    l2->SetLineColor(4);
    l3->SetLineColor(2);
    l1->SetLineWidth(2);
    l2->SetLineWidth(2);
    l3->SetLineWidth(2);
    l1->Draw();
    l2->Draw();
    l3->Draw();
    TLatex *t1 = new TLatex(250,m1s/4,"Expected Range for Min. Obs. Prob.");
    t1->SetTextColor(4);
    t1->SetTextSize(0.05);
    t1->Draw();
    TLatex *t2 = new TLatex(350,s3s*1.5,"3 #sigma evidence level");
    t2->SetTextColor(2);
    t2->SetTextSize(0.05);
    t2->Draw();

    TLatex *t3 = new TLatex(0.3,0.93,"CDF Run II Preliminary, 2.0 fb^{-1}");
    t3->SetNDC(true);
    t3->SetTextSize(0.06);
    t3->Draw();

//
//  TCanvas *c2 = new TCanvas("c2","c2");
//  minp->DrawCopy();
    //cout<<minp->GetMean()<<endl;
}
Пример #16
0
void DrawDiffJetIDsystematic()
{ 
  bool DoSave = kFALSE;
  double EtaMin[8] = {-2.0,-1.5,-1.0,-0.5,0.5,1.0,1.5,-1.0}; 
  double EtaMax[8] = {-1.5,-1.0,-0.5, 0.5,1.0,1.5,2.0, 1.0};
 
  double EtaMinRev[8];
  double EtaMaxRev[8];

  for(int j=0; j<8; j++){
     EtaMinRev[j] = -EtaMax[j];
     EtaMaxRev[j] = -EtaMin[j];
     }//swap eta convention

  int MarkerColor[8] = {1,2,4,6,7,8,40,46};

//  double ptbins[22] = {32,37,43,49,56,64,74,84,97,114,133,153,174,196,220,245,272,300,330,362,395,430}; 
  
//  TString TxtDir = "/afs/cern.ch/user/h/honi/CMSSW_5_3_8_HI_patch2/src/JetRpA0418/NewJetID/txtfile";
TLatex *T2=new TLatex();
T2->SetTextAlign(12);
T2->SetTextSize(0.02);
T2->SetTextColor(1);
T2->SetTextFont(42);
T2->SetNDC();

  double bincenter[8][21];
  double sys[8][21];

  TH1F *hJetID0[8];
  TH1F *hJetIDUp1[8];
  TH1F *hJetIDUp2[8];
  TH1F *hJetIDUp[8];
  TH1F *hJetIDDown[8];

  TH1F *hMax;
  TH1F *hMin;
  double MaxValueUp[100];
  double MinValueDown[100];
 ofstream fstr[8];
  for(int ieta = 0; ieta<8; ieta++){
	fstr[ieta].open(Form("jetIDsys%s.txt",etabinname[ieta].Data()));
//    JetID[ieta].open(Form("%s/JetIDsystematic%.f_%.f.txt",TxtDir.Data(),10*EtaMin[ieta],10*EtaMax[ieta]));
//    hJetIDUp[ieta]=new TH1F(Form("hJetIDup%.f_%.f",10*EtaMin[ieta],10*EtaMax[ieta]),Form("hJetIDup%.f_%.f",10*EtaMin[ieta],10*EtaMax[ieta]),21,ptbins);
//    hJetIDDown[ieta]=new TH1F(Form("hJetIDdown%.f_%.f",10*EtaMin[ieta],10*EtaMax[ieta]),Form("hJetIDdown%.f_%.f",10*EtaMin[ieta],10*EtaMax[ieta]),21,ptbins);

hJetID0[ieta] = makehisto(ilist0,ieta,cut[ilist0]);
hJetIDUp[ieta] = makehisto(ilist0,ieta,cut[ilist0]);
hJetIDDown[ieta] = makehisto(ilist0,ieta,cut[ilist0]);
hJetIDUp1[ieta] = makehisto(ilist1,ieta,cut[ilist1]);
hJetIDUp2[ieta] = makehisto(ilist2,ieta,cut[ilist2]);
/*
if(ilist==6){
double cutUp=cut[ilist]*0.8;
double cutDown=cut[ilist]*1.2;
}
else{
double cutUp=cut[ilist]*1.02;
double cutDown=cut[ilist]*0.98;
}
*/

hJetIDUp1[ieta]->Divide(hJetID0[ieta]);
hJetIDUp2[ieta]->Divide(hJetID0[ieta]);

    for(int ibin = 1; ibin<=hJetID0[ieta]->GetNbinsX(); ibin++){
       hJetIDUp[ieta]->SetBinContent(ibin,TMath::Max(TMath::Abs(hJetIDUp1[ieta]->GetBinContent(ibin)-1),TMath::Abs(hJetIDUp2[ieta]->GetBinContent(ibin)-1))*100);
       hJetIDDown[ieta]->SetBinContent(ibin,-hJetIDUp[ieta]->GetBinContent(ibin));
		if(ibin>=hJetID0[0]->GetXaxis()->FindBin(45) && ibin<=hJetID0[0]->GetXaxis()->FindBin(500))
	fstr[ieta]<<hJetIDUp[ieta]->GetBinCenter(ibin)<<"\t"<<hJetIDUp[ieta]->GetBinContent(ibin)<<endl;
	if(ieta==4)cout<<hJetIDUp[ieta]->GetBinCenter(ibin)<<"\t"<<hJetIDUp[ieta]->GetBinContent(ibin)<<endl;
       }//end loop for ibin
  }//end loop for ieta
 
  hMax = (TH1F *)hJetIDUp[0]->Clone(hJetIDUp[0]->GetName());
  hMin = (TH1F *)hJetIDDown[0]->Clone(hJetIDDown[0]->GetName());

  for(int ibin=0; ibin<=hJetID0[0]->GetNbinsX(); ibin++){
      MaxValueUp[ibin]=0;
      MinValueDown[ibin]=0;
      for(int ieta=0; ieta<8; ieta++){
         if(MaxValueUp[ibin]<hJetIDUp[ieta]->GetBinContent(ibin)) MaxValueUp[ibin] = hJetIDUp[ieta]->GetBinContent(ibin);
         if(MinValueDown[ibin]>hJetIDDown[ieta]->GetBinContent(ibin)) MinValueDown[ibin] = hJetIDDown[ieta]->GetBinContent(ibin);
       }//find the max value for each bin
      hMax->SetBinContent(ibin,MaxValueUp[ibin]);
      hMin->SetBinContent(ibin,MinValueDown[ibin]);
     } 
    

  TCanvas *c1 = new TCanvas("c1","c1",0,0,650,650);
  makeMultiPanelCanvas(c1,1,1,0.0,0.0,0.12,0.01,0.06);
  gStyle->SetOptStat(0);
  c1->cd();
  TH1F *hDum = new TH1F("hDum","",1000,0,1000);
  hDum->GetXaxis()->SetRangeUser(45,500);
  hDum->SetMaximum(20.0);
  hDum->SetMinimum(-20.0);
  hDum->GetXaxis()->SetTitle("p_{T}[GeV/c]");
  hDum->GetXaxis()->SetTitleSize(0.045);
  hDum->GetXaxis()->SetLabelSize(0.035);
  hDum->GetXaxis()->CenterTitle();
  hDum->GetYaxis()->SetTitle("Relative Sys" );
  hDum->GetYaxis()->SetTitleSize(0.045);
  hDum->GetYaxis()->SetLabelSize(0.035);
  hDum->GetYaxis()->CenterTitle();
  hDum->DrawCopy();
  
  hMax->SetFillStyle(3001);
  hMax->SetFillColor(5);
  hMax->DrawCopy("sameHIST");

  hMin->SetFillStyle(3001);
  hMin->SetFillColor(5);
  hMin->DrawCopy("sameHIST");
  
  TLegend *t1 = new TLegend(0.25,0.72,0.55,0.90);
  t1->SetFillColor(0);
  t1->SetBorderSize(0);
  t1->SetFillStyle(0);
  t1->SetTextFont(63);
  t1->SetTextSize(17);  

  TLegend *t2 = new TLegend(0.55,0.72,0.85,0.90);
  t2->SetFillColor(0);
  t2->SetBorderSize(0);
  t2->SetFillStyle(0);
  t2->SetTextFont(63);
  t2->SetTextSize(17);


  for(int ieta=0; ieta<8; ieta++){
     hJetIDUp[ieta]->SetMarkerSize(1.2);
     hJetIDUp[ieta]->SetLineWidth(2);
     hJetIDUp[ieta]->SetMarkerColor(MarkerColor[ieta]);
     hJetIDUp[ieta]->SetLineColor(MarkerColor[ieta]);
     hJetIDUp[ieta]->DrawCopy("sameHIST");

     hJetIDDown[ieta]->SetMarkerSize(1.2);
     hJetIDDown[ieta]->SetLineWidth(2);
     hJetIDDown[ieta]->SetMarkerColor(MarkerColor[ieta]);
     hJetIDDown[ieta]->SetLineColor(MarkerColor[ieta]);
     hJetIDDown[ieta]->DrawCopy("sameHIST");
    if(ieta<4) t1->AddEntry(hJetIDUp[ieta],Form("%.1f<#eta_{CM}<%.1f",EtaMinRev[ieta],EtaMaxRev[ieta]),"l");
    else  t2->AddEntry(hJetIDUp[ieta],Form("%.1f<#eta_{CM}<%.1f",EtaMinRev[ieta],EtaMaxRev[ieta]),"l");
   }
/*	if(ilist==6)
     T2->DrawLatex(0.2,0.2,Form("%.2f#pm%.2f<%s<1",cut[ilist],TMath::Abs(cutUp-cutDown)/2,hJetID0[0]->GetTitle()));
	else
     T2->DrawLatex(0.2,0.2,Form("0<%s<%.2f#pm%.2f",hJetID0[0]->GetTitle(),cut[ilist],TMath::Abs(cutUp-cutDown)/2));
*/
	
     T2->DrawLatex(0.15,0.15,Form("%.2f<%s<1/0<%s<%.2f",cut[ilist1],hJetIDUp1[0]->GetTitle(),hJetIDUp[0]->GetTitle(),cut[ilist0]));
     T2->DrawLatex(0.15,0.2,Form("0<%s<%.3f/0<%s<%.2f",hJetIDUp2[0]->GetTitle(),cut[ilist2],hJetIDUp[0]->GetTitle(),cut[ilist0]));
     t1->Draw("same");  
     t2->Draw("same");
     gPad->RedrawAxis();

   if(DoSave){
if(isMC)  c1->SaveAs(Form("MC%sAllEtaBinSystematic.pdf",JetIDNameList[ilist].Data()));
else {c1->SaveAs(Form("Data%sAllEtaBinSystematic.pdf",JetIDNameList[ilist].Data()));
 c1->SaveAs(Form("Data%sAllEtaBinSystematic.png",JetIDNameList[ilist].Data()));
}
}
}
void quickPhotonPurity_yj_multiTreeUtil(const TString configFile, const TString inputData, const TString inputMC, const TString outputName, const TString coll="pbpb")
{
  TH1::SetDefaultSumw2();
  CutConfiguration config = CutConfigurationParser::Parse(configFile.Data());
  TTree *configTree = setupConfigurationTreeForWriting(config);
   const char* photreeSt="";
   const char* hitreeSt="";
  if(coll=="pbpb") {
      photreeSt="EventTree";
      hitreeSt="HiTree";
  } else {
      photreeSt="ggHiNtuplizer/EventTree";
      hitreeSt="hiEvtAnalyzer/HiTree";
  } 

  TFile *dataFile = TFile::Open(pbpbDatafname);
  //TFile *dataFile = TFile::Open(inputData);
  TTree *dataTree = (TTree*)dataFile->Get(photreeSt);
  TTree *dataEvtTree = (TTree*)dataFile->Get(hitreeSt);
//  TTree *dataTree = (TTree*)dataFile->Get("ggHiNtuplizer/EventTree");
//  TTree *dataEvtTree = (TTree*)dataFile->Get("hiEvtAnalyzer/HiTree");
  //TTree *dataTree = (TTree*)dataFile->Get("photonSkimTree");

  dataTree->AddFriend(dataEvtTree);
  TFile *mcFile = TFile::Open(pbpbMCfname);
  //TFile *mcFile = TFile::Open(inputMC);
  TTree *mcTree = (TTree*)mcFile->Get("ggHiNtuplizer/EventTree");
  TTree *mcEvtTree = (TTree*)mcFile->Get("hiEvtAnalyzer/HiTree");
  //TTree *mcTree = (TTree*)mcFile->Get("photonSkimTree");
    mcTree->AddFriend(mcEvtTree);
  TFile *outFile = new TFile(outputName,"RECREATE");

  const TCut sidebandIsolation = "((pho_ecalClusterIsoR4 + pho_hcalRechitIsoR4 + pho_trackIsoR4PtCut20)>10) && ((pho_ecalClusterIsoR4 + pho_hcalRechitIsoR4 + pho_trackIsoR4PtCut20)<20) && phoHoverE<0.1";
  const TCut mcIsolation = "(pho_genMatchedIndex!= -1) && mcCalIsoDR04[pho_genMatchedIndex]<5 && abs(mcPID[pho_genMatchedIndex])<=22";
    cout << "JJ" << endl;
  //TCanvas *cPurity[nPTBINS];
  //TCanvas *cPurity = new TCanvas("c1","c1",337*nPTBINS,300*nCENTBINS/**2*/);
  TCanvas *cPurity = new TCanvas("c1","c1",400*nPTBINS,400*nCENTBINS);
  //cPurity->Divide(nPTBINS,2*nCENTBINS,0,0);
  //cPurity->Divide(nPTBINS,nCENTBINS,0,0);
  makeMultiPanelCanvas(cPurity, nPTBINS, nCENTBINS, 0.0, 0.0 , 0.2, 0.15, 0.005);
  cout << "nPTBINS = " << nPTBINS << ", nCENTBINS = " << nCENTBINS << ", nETABINS = " << nETABINS << endl;
  for(Int_t i = 0; i < nPTBINS; ++i) {
    cout << "i : " << i << endl;
    //cPurity[i] = new TCanvas(Form("c1_%d",i),"",1920,1000);
    //cPurity[i]->Divide(nETABINS,2,0,0);
    for(Int_t j = 0; j < nCENTBINS; ++j) {
    cout << "j : " << j << endl;
      for(Int_t k = 0; k< nETABINS; ++k) {
    cout << "k : " << k << endl;
	TString ptCut = Form("(phoEt >= %f) && (phoEt < %f)",
			     PTBINS[i], PTBINS[i+1]);
	TString centCut = Form("((hiBin) >= %i) && ((hiBin) < %i)",
			     CENTBINS[j], CENTBINS[j+1]);
	TString etaCut = Form("(phoEta >= %f) && (phoEta < %f)",
			      ETABINS[k], ETABINS[k+1]);

	//TString pPbflipetaCut = Form("(eta*((run>211257)*-1+(run<211257)) >=%f) && (eta*((run>211257)*-1+(run<211257)) <%f)",
	//			     ETABINS[k], ETABINS[k+1]);

	TCut dataCandidateCut = sampleIsolation && etaCut && ptCut && centCut;
	TCut sidebandCut =  sidebandIsolation && etaCut && ptCut && centCut;
	TCut mcSignalCut = dataCandidateCut && mcIsolation;

	// if(nETABINS != 1)
	// {
	//   dataCandidateCut = sampleIsolation && pPbflipetaCut && ptCut && centCut;
	//   sidebandCut =  sidebandIsolation && pPbflipetaCut && ptCut && centCut;
	//   mcSignalCut =  sampleIsolation && etaCut && ptCut && centCut && mcIsolation;
	// }

	PhotonPurity fitr = getPurity(config, dataTree, mcTree,
				      dataCandidateCut, sidebandCut,
				      mcSignalCut);

	//cPurity[i*nCENTBINS+j] = new TCanvas(Form("cpurity%d",i*nCENTBINS+j),
	// 					 "",500,500);
    cout << "centBin = " << centCut << ", ptBin : " << ptCut << ",,,, canvas # : "<<2*(k+j)*nPTBINS+i+1 << endl;
    cout << "k = " << k << ", j = " << j << ", i = " << i << endl;
    //cPurity->cd(2*(k+j)*nPTBINS+i+1);
	cPurity->cd((k+j)*nPTBINS+i+1);
	//cPurity[i]->cd(k+1);

	TH1F *hSigPdf = fitr.sigPdf;
	TH1F *hBckPdf = fitr.bckPdf;
	TH1D *hData1  = fitr.data;
	hSigPdf->Add(hBckPdf);

	TString name = "mcfit_total_ptbin";
	name += i;

	// outFile->cd();
	// hSigPdf->SetName(name);
	// hSigPdf->Write();


	// TH1D *err = (TH1D*)hSigPdf->Clone("error");
	// TH1D *tempErr[4];
	// err->Reset();
	// for(int s = 0; s < 4; s++)
	// {
	//   if(s == 0)
	//     tempErr[s] = (TH1D*)TFile::Open("photonPurity_sys_loose.root")->Get(name);
	//   else if(s ==1)
	//     tempErr[s] = (TH1D*)TFile::Open("photonPurity_sys_tight.root")->Get(name);
	//   else if(s ==2)
	//     tempErr[s] = (TH1D*)TFile::Open("photonPurity_sys_sigshift.root")->Get(name);
	//   else if(s ==3)
	//     tempErr[s] = (TH1D*)TFile::Open("photonPurity_sys_bkgshift.root")->Get(name);
	//   tempErr[s]->Divide(hSigPdf);
	//   for (Int_t l=1; l<=tempErr[s]->GetNbinsX();l++)
	//   {
	//     tempErr[s]->SetBinContent(l, TMath::Abs(tempErr[s]->GetBinContent(l))-1);
	//   }
	// }
	// for (Int_t l=1; l<=err->GetNbinsX();l++)
	// {
	//   Double_t errVal = TMath::Sqrt(tempErr[0]->GetBinContent(l)*tempErr[0]->GetBinContent(l) +
	// 				tempErr[1]->GetBinContent(l)*tempErr[1]->GetBinContent(l) +
	// 				tempErr[2]->GetBinContent(l)*tempErr[2]->GetBinContent(l) +
	// 				tempErr[3]->GetBinContent(l)*tempErr[3]->GetBinContent(l)
	//     );
	//   err->SetBinContent(l, errVal);
	// }

	// plot stacked histos
	handsomeTH1(hSigPdf);
	mcStyle(hSigPdf);
	sbStyle(hBckPdf);
	cleverRange(hSigPdf,1.5);
	hSigPdf->SetAxisRange(0.001,0.024,"X");
	hSigPdf->SetNdivisions(505);
	hSigPdf->GetYaxis()->SetTitleOffset(1.75);
	hSigPdf->SetYTitle("Entries");
	hSigPdf->SetXTitle("#sigma_{#eta #eta}");

	hSigPdf->DrawCopy("hist");
	//drawSys(hSigPdf, err, kRed, -1, 0.001);
	hBckPdf->DrawCopy("same hist");
	hData1->DrawCopy("same");

	Float_t xpos = 0.44;
	if(2*(k+j)*nPTBINS+i+1 == 1)
	  xpos = 0.54;

	TLegend *t3=new TLegend(xpos, 0.45, 0.92, 0.71);
	t3->AddEntry(hData1,LABEL,"pl");
	t3->AddEntry(hSigPdf,"Signal","lf");
	t3->AddEntry(hBckPdf,"Background","lf");
	t3->SetFillColor(0);
	t3->SetBorderSize(0);
	t3->SetFillStyle(0);
	t3->SetTextFont(43);
	t3->SetTextSize(20);
	//if(i == 0)
	// TH1D *dummyHist = new TH1D("dummyHist","",10,0,10);
	// dummyHist->Fill(1);
	// dummyHist->SetFillColor(kRed);
	// dummyHist->SetLineColor(kRed);
	// dummyHist->SetFillStyle(1001);
	// t3->AddEntry(dummyHist,"MC Sys. Error","f");
	// if(i == 0)
	//   t3->Draw();

	if(i == 3)
	{
	  drawText("CMS Preliminary", xpos, 0.68,1,20);
	  drawText("PbPb #sqrt{s}_{_{NN}}=5.02 TeV", xpos, 0.60,1,20);
	  drawText("#intL = 404 #ub^{-1}", xpos, 0.50,1,20);
	}



	//drawText("|#eta_{#gamma}| < 1.479",0.5680963,0.9);
	//drawText(Form("%f shift",fitr.sigMeanShift),0.57,0.82);
	//drawText("Background Correction",0.57,0.82);
	//drawText("bkg Tighter",0.57,0.82);
	//if(nPTBINS != 1)
	drawText(Form("%.0f GeV < p_{T}^{#gamma} < %.0f GeV",
		      PTBINS[i], PTBINS[i+1]),
		 xpos, 0.90,1,20);
	// if(/*nCENTBINS != 1 && */i ==0)
	drawText(Form("%.0f - %.0f%c",
		      CENTBINS[j]/2., CENTBINS[j+1]/2.,'%'),
		 xpos, 0.82,1,20);
	// if(nETABINS != 1)
	//   drawText(Form("%.3f < #eta_{#gamma} < %.3f",
	// 		ETABINS[k], ETABINS[k+1]),
	// 	   xpos, 0.82,1,20);
	drawText(Form("Purity (#sigma_{#eta#eta} < 0.01) : %.2f", (Float_t)fitr.purity),
		 xpos, 0.76,1,20);
	drawText(Form("#chi^{2}/ndf : %.2f", (Float_t)fitr.chisq),
		 xpos, 0.45,1,20);


	// //plot ratio
	// cPurity->cd((2*(j+k)+1)*nPTBINS+i+1);
	// //cPurity[i]->cd(nETABINS + k+ 1);
	// TH1D* ratio = (TH1D*)hData1->Clone("ratio");
	// ratio->Divide(hData1, hSigPdf, 1, 1);
	// ratio->SetMinimum(0);
	// ratio->SetMaximum(3);
	// ratio->SetXTitle("#sigma_{#eta #eta}");
	// ratio->GetXaxis()->CenterTitle();
	// ratio->SetYTitle("Data/Fit");
	// ratio->GetYaxis()->CenterTitle();
	// ratio->DrawCopy("E");
	// TLine *line = new TLine(0,1,maxSIGMA,1);
	// line->SetLineStyle(2);
	// line->Draw("same");

	// TString savename = Form("purity_pA_barrel_pt%.0f_hf%.0f_plot",
	// 			PTBINS[i], CENTBINS[j]);
	// cPurity[i*nCENTBINS+j]->SaveAs(savename+".C");
	// cPurity[i*nCENTBINS+j]->SaveAs(savename+".pdf");
	// cPurity[i*nCENTBINS+j]->SaveAs(savename+".png");

      }
    }
    //cPurity[i]->SaveAs(Form("pPb_purity_etadep_wshift_ptbin%.0f.png",PTBINS[i]));
    //cPurity[i]->SaveAs(Form("pPb_purity_etadep_noshift_inclusive.png"));
  }
  outFile->cd();
  configTree->Write();
  cPurity->Write();
  outFile->Close();
  //cPurity->SaveAs(SAVENAME+".C");
  //cPurity->SaveAs(SAVENAME+".png");
  //cPurity->SaveAs(SAVENAME+".pdf");
}
Пример #18
0
void plotFinalEnergy()  {

    
    gStyle->SetStatH(0.3);
    gStyle->SetStatY(0.88);
    gStyle->SetStatW(0.3);
    char canTitle[180];
    sprintf(canTitle,"Energy at Terminal Interaction (10000 tries)"); 
    TCanvas *canFinalEnergy = new TCanvas("canFinalEnergy","Final Energy",800,800);
    TPaveLabel *pl = new TPaveLabel(0.1,0.96,0.9,0.99,canTitle,"br NDC");
    pl->SetBorderSize(0);
    pl->SetFillColor(0);
    pl->SetFillStyle(0);
    pl->Draw();
    TPad *subCanFinalEnergy = new TPad("subCanFinalEnergy","",0,0,1,0.95);
    subCanFinalEnergy->Draw();
    subCanFinalEnergy->cd();
    subCanFinalEnergy->Divide(2,4);
    subCanFinalEnergy->Update();
    


//    gStyle->SetOptStat(0);
    char fileName[80];   
    char histTitle[80];

    char theEnergies[4][5]={"1e9","1e10","1e11","1e12"};

    int theColours[2][3]={{50,42,46},{40,30,38}};
    
    for(int isATau=0;isATau<=1;isATau++) {
	for(int i=0;i<4;i++) {		 
	    sprintf(fileName,
		    "newest%sFile%sIce.root",getParticleNameCaps(isATau),theEnergies[i]);
	    sprintf(histTitle,"%s -- %s GeV",getParticleNameCaps(isATau),theEnergies[i]);
	    TFile *fp = new TFile(fileName);
	    TH1F *histEnergy = 
		new TH1F("histEnergy",histTitle,100,7.5,12.5);
	    TH1F *histEnergy2 = 
		new TH1F("histEnergy2","Last Energy",100,7.5,12.5);
	    TH1F *histEnergy3 = 
		new TH1F("histEnergy3","Last Energy",100,7.5,12.5);

	    TTree *theTree = (TTree*) fp->Get("theTree");
	    cout << theTree->GetEntries() << endl;
	    subCanFinalEnergy->cd((2*i)+isATau+1);
	    gPad->SetTopMargin(0.12);
//	gPad->SetBottomMargin(0.2);
	    histEnergy->SetLineWidth(3);
	    histEnergy->SetLineColor(theColours[isATau][0]);
	    histEnergy2->SetLineWidth(3);
	    histEnergy2->SetLineColor(theColours[isATau][1]);
	    histEnergy3->SetLineWidth(3);
	    histEnergy3->SetLineColor(theColours[isATau][2]);
	    theTree->Draw("log10(stepIntEnergy)>>histEnergy","stepIntType>=4");
//	histEnergy->GetXaxis()->SetTitle("IntType (#mus)");
// 	histEnergy->GetXaxis()->SetBinLabel(2,"Bremsstrahlung");
// 	histEnergy->GetXaxis()->SetBinLabel(3,"Pair Production");
// 	histEnergy->GetXaxis()->SetBinLabel(4,"Photonuclear");
// 	histEnergy->GetXaxis()->SetLabelSize(0.09);
// 	histEnergy->GetXaxis()->SetLabelOffset(0.02);
 	    theTree->Draw("log10(stepIntEnergy)>>histEnergy2","stepIntType==4");
 	    theTree->Draw("log10(stepIntEnergy)>>histEnergy3","stepIntType==5");

	    histEnergy->DrawCopy();
	    if(histEnergy2->GetEntries())
		histEnergy2->DrawCopy("same");
	    if(histEnergy3->GetEntries())
		histEnergy3->DrawCopy("same");
	    
	    if(histEnergy->GetEntries())
		gPad->SetLogy();

	    if(i==0) {
		TLegend *leg = new TLegend(0.7,0.2,0.9,0.6);
		leg->SetFillColor(0);
		leg->SetFillStyle(0);
		leg->SetBorderSize(0);
		leg->AddEntry(histEnergy2,"Decay","l");
		leg->AddEntry(histEnergy3,"Weak (CC)","l");
		leg->AddEntry(histEnergy,"Either","l");
		leg->Draw("same");
	    }
	}
    } 
    for(int i=0;i<8;i++) {
//	cout << "Doing title "<< i+1 << endl;
	subCanFinalEnergy->cd(i+1);
	sortOutTitle(0.07);
    }
//    gStyle->SetOptStat(1110);

}
Пример #19
0
void plotfigure4_pAl(bool nodata = true, bool prelim = false, bool AMPT=true, bool SONIC=true, 
                 bool superSONIC=true, bool IPGLASMA=false, bool BOZEK=false) {

  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  TCanvas *c1 = new TCanvas("c1","c1",10,10,700,700);

  // create template histogram
  TH1F *htemplate = new TH1F("htemplate","htemplate",10,0.0,3.5);
  htemplate->SetMaximum(0.30); //25);
  htemplate->SetXTitle("p_{T} [GeV/c]");
  //  htemplate->SetYTitle("v_{n} Coefficient");
  htemplate->SetYTitle("v_{n}");
  htemplate->GetYaxis()->SetTitleOffset(1.2);
  htemplate->DrawCopy();

  // grab AMPT points (http://arxiv.org/abs/1501.06880)
  TFile *fin_ampt = new TFile("AMPT_pAl_central_vn_new.root");
  // copy into new TGraphs for easier manipulcation
  //TGraphErrors *tamptv2 = gv2->Clone();
  //TGraphErrors *tamptv3 = gv3->Clone();

  TGraphErrors *tamptv22 = gv2->Clone();
  TGraphErrors *tamptv32 = gv3->Clone();
  
  TGraph *tamptv2 = new TGraph();
  TGraph *tamptv3 = new TGraph();
  for (int i=0;i<gv2->GetN();i++) {
    double x; double y;
    gv2->GetPoint(i,x,y);
    tamptv2->SetPoint(i,x,y);
  }
  for (int i=0;i<gv3->GetN();i++) {
    double x; double y;
    gv3->GetPoint(i,x,y);
    tamptv3->SetPoint(i,x,y);
  }
  
  

  
  
  tamptv22->SetFillColor(42);
  tamptv32->SetFillColor(42);

  tamptv22->SetLineColor(46);
  tamptv22->SetLineWidth(3);
  tamptv22->SetLineStyle(1);
  if (AMPT) tamptv22->Draw("3,same");
  tamptv32->SetLineColor(46);
  tamptv32->SetLineWidth(3);
  tamptv32->SetLineStyle(1);
  if (AMPT) tamptv32->Draw("3,same");

  tamptv2->SetLineColor(46);
  tamptv2->SetLineWidth(3);
  tamptv2->SetLineStyle(1);
  if (AMPT) tamptv2->Draw("l,same");
  tamptv3->SetLineColor(46);
  tamptv3->SetLineWidth(3);
  tamptv3->SetLineStyle(1);
  if (AMPT) tamptv3->Draw("l,same");
  

  // IPGlasma curves (http://arxiv.org/abs/1407.7557)
  TGraph *tipglasmav2 = new TGraph("ipglasmaflowv2.dat","%lg, %lg");
  tipglasmav2->SetLineColor(6);
  tipglasmav2->SetLineWidth(3);
  tipglasmav2->SetLineStyle(1);
  if (IPGLASMA) tipglasmav2->Draw("l,same");
  TGraph *tipglasmav3 = new TGraph("ipglasmaflowv3.dat","%lg, %lg");
  tipglasmav3->SetLineColor(6);
  tipglasmav3->SetLineWidth(3);
  tipglasmav3->SetLineStyle(1);
  if (IPGLASMA) tipglasmav2->Draw("l,same");
  if (IPGLASMA) tipglasmav3->Draw("l,same"); 

  // Now Paul Romatschke result without and with preflow
  // Refs:  http://arxiv.org/abs/1502.04745

  double sonic_beta2[100][13];
  double sonic_beta3[100][13];
  double supersonic_beta2[100][13];
  double supersonic_beta3[100][13];
  // pt:yield:yields:v1:v1s:v2:v2s:v3:v3s:v4:v4s:v5:v5s 

  ifstream myfile;
  myfile.open("res_pAlconfig-42mb-s63-sigma0.4-beta2-nopf-av_unid_vn.dat");
  int j=0;
  string dummyLine;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> sonic_beta2[j][0] >> sonic_beta2[j][1] >> sonic_beta2[j][2] >>
		   sonic_beta2[j][3] >> sonic_beta2[j][4] >> sonic_beta2[j][5] >>
		   sonic_beta2[j][6] >> sonic_beta2[j][7] >> sonic_beta2[j][8] >>
		   sonic_beta2[j][9] >> sonic_beta2[j][10] >> sonic_beta2[j][11] >>
		   sonic_beta2[j][12];
    //cout << "pt = " << sonic_beta2[j][0] << " v2 = " << sonic_beta2[j][5] << endl;
    j++;
  }
  myfile.close();

  myfile.open("res_pAlconfig-42mb-s63-sigma0.4-beta3-nopf-av_unid_vn.dat");
  j=0;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> sonic_beta3[j][0] >> sonic_beta3[j][1] >> sonic_beta3[j][2] >>
		   sonic_beta3[j][3] >> sonic_beta3[j][4] >> sonic_beta3[j][5] >>
		   sonic_beta3[j][6] >> sonic_beta3[j][7] >> sonic_beta3[j][8] >>
		   sonic_beta3[j][9] >> sonic_beta3[j][10] >> sonic_beta3[j][11] >>
		   sonic_beta3[j][12];
    j++;
  }
  myfile.close();

  myfile.open("res_pAlconfig-42mb-s63-sigma0.4-beta2-av_unid_vn.dat");
  j=0;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> supersonic_beta2[j][0] >> supersonic_beta2[j][1] >> supersonic_beta2[j][2] >>
		   supersonic_beta2[j][3] >> supersonic_beta2[j][4] >> supersonic_beta2[j][5] >>
		   supersonic_beta2[j][6] >> supersonic_beta2[j][7] >> supersonic_beta2[j][8] >>
		   supersonic_beta2[j][9] >> supersonic_beta2[j][10] >> supersonic_beta2[j][11] >>
		   supersonic_beta2[j][12];
    j++;
  }
  myfile.close();

  myfile.open("res_pAlconfig-42mb-s63-sigma0.4-beta3.dat");
  j=0;
  getline(myfile, dummyLine); // skip first comment line
  while (myfile) {
    myfile >> supersonic_beta3[j][0] >> supersonic_beta3[j][1] >> supersonic_beta3[j][2] >>
		   supersonic_beta3[j][3] >> supersonic_beta3[j][4] >> supersonic_beta3[j][5] >>
		   supersonic_beta3[j][6] >> supersonic_beta3[j][7] >> supersonic_beta3[j][8] >>
		   supersonic_beta3[j][9] >> supersonic_beta3[j][10] >> supersonic_beta3[j][11] >>
		   supersonic_beta3[j][12];
    j++;
  }
  myfile.close();

  TGraph *tsonic_beta2_v2 = new TGraph();
  TGraph *tsonic_beta2_v3 = new TGraph();
  TGraph *tsonic_beta3_v2 = new TGraph();
  TGraph *tsonic_beta3_v3 = new TGraph();

  TGraphErrors *tesonic_v2 = new TGraphErrors();
  TGraphErrors *tesonic_v3 = new TGraphErrors();

  TGraph *tsupersonic_beta2_v2 = new TGraph();
  TGraph *tsupersonic_beta2_v3 = new TGraph();
  TGraph *tsupersonic_beta3_v2 = new TGraph();
  TGraph *tsupersonic_beta3_v3 = new TGraph();

  TGraphErrors *tesupersonic_v2 = new TGraphErrors();
  TGraphErrors *tesupersonic_v3 = new TGraphErrors();

  for (int i=0;i<25;i++) {

    tsonic_beta2_v2->SetPoint(i,sonic_beta2[i][0],sonic_beta2[i][5]);
    tsonic_beta3_v2->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][5]);
    tesonic_v2->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][5]);
    tesonic_v2->SetPointError(i,0.0,TMath::Abs(sonic_beta2[i][5]-sonic_beta3[i][5]));

    tsonic_beta2_v3->SetPoint(i,sonic_beta2[i][0],sonic_beta2[i][7]);
    tsonic_beta3_v3->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][7]);
    tesonic_v3->SetPoint(i,sonic_beta3[i][0],sonic_beta3[i][7]);
    tesonic_v3->SetPointError(i,0.0,TMath::Abs(sonic_beta2[i][7]-sonic_beta3[i][7]));

    tsupersonic_beta2_v2->SetPoint(i,supersonic_beta2[i][0],supersonic_beta2[i][5]);
    tsupersonic_beta3_v2->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][5]);
    tesupersonic_v2->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][5]);
    tesupersonic_v2->SetPointError(i,0.0,TMath::Abs(supersonic_beta2[i][5]-supersonic_beta3[i][5]));

    tsupersonic_beta2_v3->SetPoint(i,supersonic_beta2[i][0],supersonic_beta2[i][7]);
    tsupersonic_beta3_v3->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][7]);
    tesupersonic_v3->SetPoint(i,supersonic_beta3[i][0],supersonic_beta3[i][7]);
    tesupersonic_v3->SetPointError(i,0.0,TMath::Abs(supersonic_beta2[i][7]-supersonic_beta3[i][7]));

  }


  tesonic_v2->SetFillColor(29);
  tesonic_v2->SetLineWidth(3);
  if (SONIC) tesonic_v2->Draw("3,same");
  tesonic_v3->SetFillColor(29);
  tesonic_v3->SetLineWidth(3);
  if (SONIC) tesonic_v3->Draw("3,same");

  tesupersonic_v2->SetFillColor(8);
  tesupersonic_v2->SetLineWidth(3);
  if (superSONIC) tesupersonic_v2->Draw("3,same");
  tesupersonic_v3->SetFillColor(8);
  tesupersonic_v3->SetLineWidth(3);
  if (superSONIC) tesupersonic_v3->Draw("3,same");

  tsonic_beta3_v2->SetLineColor(1);
  tsonic_beta3_v2->SetLineWidth(3);
  tsonic_beta3_v3->SetLineColor(1);
  tsonic_beta3_v3->SetLineWidth(3);

  tsupersonic_beta3_v2->SetLineColor(1);
  tsupersonic_beta3_v2->SetLineWidth(3);
  tsupersonic_beta3_v3->SetLineColor(1);
  tsupersonic_beta3_v3->SetLineWidth(3);

  tsupersonic_beta3_v2->SetFillColor(8);
  tsonic_beta3_v2->SetFillColor(29);

  

  // Bozek theory
  TGraph *bozekv2 = new TGraph("bozekv2.dat","%lg, %lg");
  bozekv2->SetLineWidth(3);
  bozekv2->SetLineStyle(2);
  //if (BOZEK) bozekv2->Draw("l,same");

  TGraph *bozekv3 = new TGraph("bozekv3.dat","%lg, %lg");
  bozekv3->SetLineWidth(3);
  bozekv3->SetLineStyle(2);
  //if (BOZEK) bozekv3->Draw("l,same");

  //==============================================================
  //plot data added by shengli
  //if (!nodata) {

  float ptv2[24];
  float eptv2[24], sptv2[24];
  float v2mpcs[24], ev2mpcs[24], sv2mpcs[24], asv2mpcs1[24];

  float ptv3[24];
  float eptv3[24], sptv3[24];
  float v3mpcs[24], ev3mpcs[24], sv3mpcs[24], asv3mpcs1[24], asv3mpcs2[24];

  int imax = 13;
  if (prelim) imax = 10;

  // final PPG181 data!!!!
  
  if (!prelim) {
    ifstream finv2("He3Au_0_5_v2_asys_new.dat");
    ifstream finv3("He3Au_0_5_v3_asys_new.dat");
  }
  if (prelim) {
    ifstream finv2("He3Au_0_5_v2_prelim.dat");
    ifstream finv3("He3Au_0_5_v3_prelim.dat");
  }

  
  for(int i=0; i<imax; i++){
    eptv2[i]=0;
    sptv2[i]=0.05;
    finv2>>ptv2[i]>>v2mpcs[i]>>ev2mpcs[i]>>sv2mpcs[i]>>asv2mpcs1[i];
    
  }
  finv2.close();
  
  TGraphErrors *grmpcs2 = new TGraphErrors(imax, ptv2, v2mpcs, eptv2, ev2mpcs);
  TGraphErrors *sgrmpcs2 = new TGraphErrors(imax, ptv2, v2mpcs, sptv2, sv2mpcs);
 

  for(int i=0; i<imax; i++){
    eptv3[i]=0;
    sptv3[i]=0.05;
    finv3>>ptv3[i]>>v3mpcs[i]>>ev3mpcs[i]>>sv3mpcs[i]>>asv3mpcs1[i];

  }
  finv3.close();
  
  TGraphErrors *grmpcs3 = new TGraphErrors(imax, ptv3, v3mpcs, eptv3, ev3mpcs);
  TGraphErrors *sgrmpcs3 = new TGraphErrors(imax, ptv3, v3mpcs, sptv3, sv3mpcs);
  

  float pt[13], ept[13], spt[13], v2[13], ev2[13], sv2[13];
  ifstream fppg161("v2_pt_dAu_00_05_sys_new.dat");

  for(int i=0; i<13; i++){
    spt[i]=0.05;
    ept[i]=0.0;
    fppg161>>pt[i]>>v2[i]>>ev2[i]>>sv2[i];
  }
  fppg161.close();

  TGraphErrors *grppg161 = new TGraphErrors(10, pt, v2, ept, ev2);
  TGraphErrors *sgrppg161 = new TGraphErrors(10, pt, v2, spt, sv2);

  // TLegend *leg1 = new TLegend(0.54,0.74,0.74,0.86);
  // leg1->SetFillColor(10);
  // leg1->SetLineStyle(4000);
  // leg1->SetLineColor(10);
  // leg1->SetLineWidth(0.);
  // leg1->SetTextSize(0.05);
  // leg1->SetBorderSize(0);
  // leg1->AddEntry(grmpcs2,"v_{2}","P");
  //  leg1->Draw();

  //TLegend *leg2 = new TLegend(0.11,0.63,0.79,0.89);
  //leg2->SetFillColor(10);
  //leg2->SetLineStyle(4000);
  //leg2->SetLineColor(10);
  //leg2->SetLineWidth(0.);
  //leg2->SetTextSize(0.05);
  //leg2->SetBorderSize(0);
  //leg2->AddEntry(grmpcs3,"v_{3}","P");
  //  leg2->Draw();
  //}

  TLatex *tt2 = new TLatex(3.2,0.144,"v_{2}");
  tt2->Draw("same");
  TLatex *tt3 = new TLatex(3.2,0.045,"v_{3}");
  tt3->Draw("same");

  TLegend *tleg = new TLegend(0.11,0.66,0.58,0.88,"p+Al at 200 GeV, 0-5% Central","brNDC");
  //  tleg->SetMargin(0.1);
  //tleg->SetNColumns(2);
  tleg->SetTextSize(0.04);
  tleg->SetBorderSize(0);
  
  if (!nodata && !prelim) tleg->AddEntry((TObject *) 0,"PHENIX data v_{2}, v_{3}","");
  //tleg->AddEntry((TObject *) 0, "", "");
  //  if (!nodata && !prelim) tleg->AddEntry(grmpcs3,"PHENIX data v_{3}","P");

  if (!nodata && prelim) tleg->AddEntry(grmpcs2,"PHENIX data v_{2} (PRELIMINARY)","P");
  if (!nodata && prelim) tleg->AddEntry(grmpcs3,"PHENIX data v_{3} (PRELIMINARY)","P");

  if (SONIC) tleg->AddEntry(tsonic_beta3_v2,"SONIC","l,f");
  //if (superSONIC) tleg->AddEntry(tsupersonic_beta3_v2,"superSONIC","l,f");
  if (BOZEK) tleg->AddEntry(bozekv2,"Glauber+Hydro","l");
  //if (IPGLASMA) tleg->AddEntry(tipglasmav2,"IPGlasma+Hydro","l");
  if (AMPT) tleg->AddEntry(tamptv22,"AMPT","l,f");
  tleg->SetFillColor(0);
  tleg->Draw("same");

  TLegend *leg2 = new TLegend(0.51,0.70,0.89,0.79);
  leg2->SetFillColor(10);
  leg2->SetLineStyle(4000);
  leg2->SetLineColor(10);
  leg2->SetLineWidth(0.);
  leg2->SetTextSize(0.04);
  leg2->SetBorderSize(0);
  leg2->AddEntry(tsupersonic_beta3_v2,"superSONIC","l,f");
  if(IPGLASMA) leg2->AddEntry(tipglasmav2,"IPGlasma+Hydro","l");
  leg2->Draw();

  TGraph *foo = new TGraph();
  foo->SetPoint(0,0.21,0.2705);
  foo->SetMarkerStyle(20);
  foo->SetMarkerColor(2);
  foo->SetMarkerSize(1.4);
  if(!nodata) foo->Draw("p,same");

  TGraph *foo2 = new TGraph();
  foo2->SetPoint(0,0.32,0.2705);
  foo2->SetMarkerStyle(21);
  foo2->SetMarkerColor(4);
  foo2->SetMarkerSize(1.4);
  if(!nodata) foo2->Draw("p,same");
  

  sgrmpcs2->SetMarkerStyle(20);
  sgrmpcs2->SetMarkerSize(1.4);
  sgrmpcs2->SetMarkerColor(2);
  sgrmpcs2->SetFillColor(15);
  //sgrmpcs2->Draw("PE2");

  grmpcs2->SetMarkerStyle(20);
  grmpcs2->SetMarkerSize(1.4);
  grmpcs2->SetMarkerColor(2);
  if(!nodata) grmpcs2->Draw("P");

  if(!nodata)
    {
      for(int i=0; i<13; i++){
	double px1 = ptv2[i]-0.05;
	double py1 = v2mpcs[i]+sv2mpcs[i];
	double px2 = ptv2[i]+0.05;
	double py2 = v2mpcs[i]-asv2mpcs1[i];
	TBox *boxv2 = new TBox(px1,py1,px2,py2);
	boxv2->SetFillColor(4);
	boxv2->SetFillStyle(0);
	boxv2->SetLineColor(2);
	boxv2->SetLineWidth(1);
	boxv2->Draw("lsame");
      }
    }

  sgrmpcs3->SetMarkerStyle(21);
  sgrmpcs3->SetMarkerSize(1.4);
  sgrmpcs3->SetMarkerColor(4);
  sgrmpcs3->SetFillColor(15);
  //sgrmpcs3->Draw("PE2");

  grmpcs3->SetMarkerStyle(21);
  grmpcs3->SetMarkerSize(1.4);
  grmpcs3->SetMarkerColor(4);
  if(!nodata) grmpcs3->Draw("P");
 
  if(!nodata)
    {
      for(int i=0; i<imax; i++){
	double px1 = ptv3[i]-0.05;
	double py1 = v3mpcs[i]+sv3mpcs[i];
	double px2 = ptv3[i]+0.05;
	double py2 = v3mpcs[i]-asv3mpcs1[i];
	TBox *boxv3 = new TBox(px1,py1,px2,py2);
	boxv3->SetFillColor(4);
	boxv3->SetFillStyle(0);
	boxv3->SetLineColor(4);
	boxv3->SetLineWidth(1);
	boxv3->Draw("lsame");
      }
    }
  /*
  for(int i=0; i<10; i++){
    double px1 = pt[i]-0.05;//ept[i];
    double py1 = v2[i]-sv2[i];
    double px2 = pt[i]+0.05;//ept[i];
    double py2 = v2[i]+sv2[i];
    TBox *boxppg161 = new TBox(px1,py1,px2,py2);
    boxppg161->SetFillColor(4);
    boxppg161->SetFillStyle(0);
    boxppg161->SetLineColor(4);
    boxppg161->SetLineWidth(1);
    boxppg161->Draw("lsame");
  }

  grppg161->SetMarkerStyle(20);
  grppg161->SetMarkerSize(1.4);
  grppg161->SetMarkerColor(4);
  grppg161->SetLineColor(2);
  grppg161->Draw("P");
  */
  if (SONIC) tsonic_beta3_v2->Draw("l,same");
  if (SONIC) tsonic_beta3_v3->Draw("l,same");
  if (superSONIC) tsupersonic_beta3_v2->Draw("l,same");
  if (superSONIC) tsupersonic_beta3_v3->Draw("l,same");

  if (IPGLASMA) tipglasmav2->Draw("l,same");
  if (IPGLASMA) tipglasmav3->Draw("l,same"); 

  if (BOZEK) bozekv2->Draw("l,same");
  if (BOZEK) bozekv3->Draw("l,same");

  TLatex *t11=new TLatex(0.1,0.18, "PHENIX");
  t11->SetTextSize(0.05);
  //t11->SetTextColor(2);
  //t11->Draw();
}
Пример #20
0
void plotvn(){
    gStyle->SetOptStat(kFALSE);
    int icent = 0;
    int n = 2;
    int color[nsub] = {1,2,4,5,7,8,2,4};
    int style[12] = {20,21,24,25,26,27,29,30,31,32,33,34};
    TGraphErrors *gr[nsub][3][2];
    TGraphErrors *grraw[nsub][3][2];
    TString CNTEP, dire;
    for(int isub=0;isub<nsub;isub++){
    for(int idire=0;idire<3;idire++){
    for(int iCNTEP=0;iCNTEP<1;iCNTEP++){
        if(iCNTEP==0) CNTEP = "NoUseCNTEP";
        if(iCNTEP==1) CNTEP = "UseCNTEP";
        if(idire==0) dire = "";
        if(idire==1) dire = "_east";
        if(idire==2) dire = "_west";
        TString str = choosesub(isub);
        if(str=="ABORT") continue;
        gr[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%d_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        grraw[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%draw_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        SetStyle(*gr[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
        SetStyle(*grraw[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
    }
    }
    }

    TGraphErrors *gr3 = new TGraphErrors("../../Ridge3sub/v2_cent0.dat");
    TGraphErrors *gr3sub = new TGraphErrors("../../Ridge3sub/v2_cent0_scale1.dat");
TH1F* h = new TH1F("h","",50,0,5);
h->GetXaxis()->SetRangeUser(0,3.2);
/*
TCanvas *c1 = new TCanvas("c1","c1",800,450);
iCNTEP = 0;
idire = 0;
c1->Divide(2);
c1->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
h->GetXaxis()->SetRangeUser(0,3.2);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
for(int ilay = 0;ilay<4;ilay++){
leg->AddEntry(gr[ilay+8][idire][iCNTEP],Form("FVTX layer %d",ilay));
gr[ilay+8][idire][iCNTEP]->Draw("Psame");
}
gr[6][0][1]->Draw("Psame");
leg->AddEntry(gr[6][idire][iCNTEP],Form("FVTX -3.0<#eta<-1.0"));
leg->Draw("Psame");

c1->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
for(int ilay = 0;ilay<4;ilay++){
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[ilay+8][idire][iCNTEP],gr[6][idire][iCNTEP]);
SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[ilay+8]);
grr->Draw("Psame");
}
*/
TCanvas *c2 = new TCanvas("c2","c2",800,450);
iCNTEP = 0;
idire = 0;
c2->Divide(2);
c2->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
SetStyle(*gr[4][idire][iCNTEP], 1.2, 2,style[2]);
SetStyle(*gr[5][idire][iCNTEP], 1.2, 4,style[4]);
SetStyle(*gr3, 1.2, 1,style[1]);
SetStyle(*gr3sub, 1.2, 1,style[3]);
gr[4][idire][iCNTEP]->Draw("Psame");
gr[5][idire][iCNTEP]->Draw("Psame");
gr3->Draw("Psame");
gr3sub->Draw("Psame");
leg->AddEntry(gr[4][idire][iCNTEP],Form("BBCs"));
leg->AddEntry(gr[5][idire][iCNTEP],Form("FVTXs -3.0<#eta<-1.0"));
leg->AddEntry(gr3,Form("3-sub event method"));
leg->AddEntry(gr3sub,Form("3-sub non-flow PP subtracted"));
leg->Draw("Psame");

c2->cd(2);
h->SetMinimum(0.);
h->SetMaximum(2);
SetTitle(h,"","p_{T}","v_{2} ratio BBCs/FVTXs");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[4][idire][iCNTEP],gr[5][idire][iCNTEP]);
SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]);
grr->Draw("Psame");
c2->Print(Form("FVTXvsBBCv%d.png",n));
/*
TCanvas *c3 = new TCanvas("c3","c3",800,450);
idire = 0;
isub=5;
c3->Divide(2);
c3->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(h,"","p_{T}","v_{2}^{raw}");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][idire][1]->Draw("Psame");
gr[isub][idire][0]->Draw("Psame");
leg->AddEntry(gr[isub][idire][1],Form("FVTXs -3.0<#eta<-1.0"));
leg->AddEntry(gr[isub][idire][1],Form("Using Psi EP"),"P");
leg->AddEntry(gr[isub][idire][0],Form("Using phi EP"),"P");
leg->Draw("Psame");

c3->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs using phi EP/using Psi EP");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][idire][0],gr[isub][idire][1]);
SetStyle(*grr,1.2,color[idire+3*0],style[isub]);
grr->Draw("Psame");
*/
TCanvas *c4 = new TCanvas("c4","c4",800,450);
isub=7;
iCNTEP = 0;
c4->Divide(2);
c4->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(*h,"p_{T} (GeV/c)","v_{2}","");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
if(isub==5)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs -3.0<#eta<-1.0"));
else if(isub<4)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer %d -3.0<#eta<-1.0", isub+1));
else if(isub==6)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer 2+4"));
else if(isub==7)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer 1+2+4"));
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c4->cd(2);
h->SetMinimum(0);
h->SetMaximum(2);
SetTitle(*h,"p_{T} (GeV/c)","v_{2} ratio","");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c4->Print(Form("v%dFVTXs%dEW.png",n,isub));

TCanvas *c5 = new TCanvas("c5","c5",800,450);
isub=4;
iCNTEP = 0;
c5->Divide(2);
c5->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(*h,"p_{T}","v_{2}","");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetTextSize(0.05);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("Using BBC event plane"));
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c5->cd(2);
h->SetMinimum(0);
h->SetMaximum(2.);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c5->Print(Form("v%dBBCs%dEW.png",n,isub));

TCanvas *c6 = new TCanvas("c6","c6",800,450);
iCNTEP = 0;
c6->Divide(2);
c6->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(*h,"p_{T}","v_{2}","");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.5,0.65,0.8,0.85);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
SetStyle(*gr[0][0][iCNTEP], 1.2, color[0],style[0]);
SetStyle(*gr[1][0][iCNTEP], 1.2, color[1],style[1]);
SetStyle(*gr[2][0][iCNTEP], 1.2, color[2],style[2]);
SetStyle(*gr[3][0][iCNTEP], 1.2, color[3],style[3]);
SetStyle(*gr[5][0][iCNTEP], 1.2, color[5],style[5]);
gr[0][0][iCNTEP]->Draw("Psame");
gr[1][0][iCNTEP]->Draw("Psame");
gr[2][0][iCNTEP]->Draw("Psame");
gr[3][0][iCNTEP]->Draw("Psame");
gr[5][0][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[0][0][iCNTEP],Form("FVTX 1LS"),"P");
leg->AddEntry(gr[1][0][iCNTEP],Form("FVTX 2LS"),"P");
leg->AddEntry(gr[2][0][iCNTEP],Form("FVTX 3LS"),"P");
leg->AddEntry(gr[3][0][iCNTEP],Form("FVTX 4LS"),"P");
leg->AddEntry(gr[5][0][iCNTEP],Form("FVTX All"),"P");
leg->Draw("same");

c6->cd(2);
h->SetMinimum(0.5);
h->SetMaximum(1.5);
SetTitle(*h,"p_{T}","v_{2} ratio","");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[0][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[0],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[1][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[1],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[2][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[2],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[3][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[3],style[isub]);
grr->Draw("Psame");
c6->Print(Form("FVTXeachlayerv%d.png",n));


TCanvas *c7 = new TCanvas("c7","c7",800,450);
iCNTEP = 0;
c7->Divide(2);
c7->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(*h,"p_{T}","v_{2}","");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.5,0.75,0.8,0.85);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
SetStyle(*gr[5][0][iCNTEP], 1.2, color[5],style[0]);
SetStyle(*gr[6][0][iCNTEP], 1.2, color[6],style[1]);
SetStyle(*gr[7][0][iCNTEP], 1.2, color[7],style[2]);
gr[5][0][iCNTEP]->Draw("Psame");
gr[6][0][iCNTEP]->Draw("Psame");
gr[7][0][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[5][0][iCNTEP],Form("FVTX All"),"P");
leg->AddEntry(gr[6][0][iCNTEP],Form("FVTX 2+4 layer"),"P");
leg->AddEntry(gr[7][0][iCNTEP],Form("FVTX 1+2+4 layer"),"P");
leg->Draw("same");

c7->cd(2);
h->SetMinimum(0.5);
h->SetMaximum(1.5);
SetTitle(*h,"p_{T}","v_{2} ratio","");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[5][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[5],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[6][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[6],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[7][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[7],style[isub]);
grr->Draw("Psame");
c7->Print(Form("FVTXlayerCombv%d.png",n));
}
Пример #21
0
   void ws_constrained_profile3D( const char* wsfile = "rootfiles/ws-data-unblind.root",
                                   const char* new_poi_name = "n_M234_H4_3b",
                                   int npoiPoints = 20,
                                   double poiMinVal = 0.,
                                   double poiMaxVal = 20.,
                                   double constraintWidth = 1.5,
                                   double ymax = 10.,
                                   int verbLevel=0 ) {


     gStyle->SetOptStat(0) ;

     //--- make output directory.

     char command[10000] ;
     sprintf( command, "basename %s", wsfile ) ;
     TString wsfilenopath = gSystem->GetFromPipe( command ) ;
     wsfilenopath.ReplaceAll(".root","") ;
     char outputdirstr[1000] ;
     sprintf( outputdirstr, "outputfiles/scans-%s", wsfilenopath.Data() ) ;
     TString outputdir( outputdirstr ) ;


     printf("\n\n Creating output directory: %s\n\n", outputdir.Data() ) ;
     sprintf(command, "mkdir -p %s", outputdir.Data() ) ;
     gSystem->Exec( command ) ;


     //--- Tell RooFit to shut up about anything less important than an ERROR.
      RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR) ;



       if ( verbLevel > 0 ) { printf("\n\n Verbose level : %d\n\n", verbLevel) ; }


       TFile* wstf = new TFile( wsfile ) ;

       RooWorkspace* ws = dynamic_cast<RooWorkspace*>( wstf->Get("ws") );

       if ( verbLevel > 0 ) { ws->Print() ; }






       RooDataSet* rds = (RooDataSet*) ws->obj( "ra2b_observed_rds" ) ;

       if ( verbLevel > 0 ) {
          printf("\n\n\n  ===== RooDataSet ====================\n\n") ;
          rds->Print() ;
          rds->printMultiline(cout, 1, kTRUE, "") ;
       }





       ModelConfig* modelConfig = (ModelConfig*) ws->obj( "SbModel" ) ;
       RooAbsPdf* likelihood = modelConfig->GetPdf() ;

       RooRealVar* rrv_mu_susy_all0lep = ws->var("mu_susy_all0lep") ;
       if ( rrv_mu_susy_all0lep == 0x0 ) {
          printf("\n\n\n *** can't find mu_susy_all0lep in workspace.  Quitting.\n\n\n") ;
          return ;
       }





       //-- do BG only.
       rrv_mu_susy_all0lep->setVal(0.) ;
       rrv_mu_susy_all0lep->setConstant( kTRUE ) ;










       //-- do a prefit.

       printf("\n\n\n ====== Pre fit with unmodified nll var.\n\n") ;

       RooFitResult* dataFitResultSusyFixed = likelihood->fitTo(*rds, Save(true),Hesse(false),Minos(false),Strategy(1),PrintLevel(verbLevel));
       int dataSusyFixedFitCovQual = dataFitResultSusyFixed->covQual() ;
       if ( dataSusyFixedFitCovQual < 2 ) { printf("\n\n\n *** Failed fit!  Cov qual %d.  Quitting.\n\n", dataSusyFixedFitCovQual ) ; return ; }
       double dataFitSusyFixedNll = dataFitResultSusyFixed->minNll() ;

       if ( verbLevel > 0 ) {
          dataFitResultSusyFixed->Print("v") ;
       }

       printf("\n\n Nll value, from fit result : %.3f\n\n", dataFitSusyFixedNll ) ;

       delete dataFitResultSusyFixed ;






       //-- Construct the new POI parameter.
       RooAbsReal* new_poi_rar(0x0) ;

       new_poi_rar = ws->var( new_poi_name ) ;
       if ( new_poi_rar == 0x0 ) {
          printf("\n\n New POI %s is not a variable.  Trying function.\n\n", new_poi_name ) ;
          new_poi_rar = ws->function( new_poi_name ) ;
          if ( new_poi_rar == 0x0 ) {
             printf("\n\n New POI %s is not a function.  I quit.\n\n", new_poi_name ) ;
             return ;
          }
       } else {
          printf("\n\n     New POI %s is a variable with current value %.1f.\n\n", new_poi_name, new_poi_rar->getVal() ) ;
       }








       if ( npoiPoints <=0 ) {
          printf("\n\n Quitting now.\n\n" ) ;
          return ;
       }


       double startPoiVal = new_poi_rar->getVal() ;



      //--- The RooNLLVar is NOT equivalent to what minuit uses.
  //   RooNLLVar* nll = new RooNLLVar("nll","nll", *likelihood, *rds ) ;
  //   printf("\n\n Nll value, from construction : %.3f\n\n", nll->getVal() ) ;

      //--- output of createNLL IS what minuit uses, so use that.
       RooAbsReal* nll = likelihood -> createNLL( *rds, Verbose(true) ) ;

       RooRealVar* rrv_poiValue = new RooRealVar( "poiValue", "poiValue", 0., -10000., 10000. ) ;
   /// rrv_poiValue->setVal( poiMinVal ) ;
   /// rrv_poiValue->setConstant(kTRUE) ;

       RooRealVar* rrv_constraintWidth = new RooRealVar("constraintWidth","constraintWidth", 0.1, 0.1, 1000. ) ;
       rrv_constraintWidth -> setVal( constraintWidth ) ;
       rrv_constraintWidth -> setConstant(kTRUE) ;




       if ( verbLevel > 0 ) {
          printf("\n\n ======= debug likelihood print\n\n") ;
          likelihood->Print("v") ;
          printf("\n\n ======= debug nll print\n\n") ;
          nll->Print("v") ;
       }






    //----------------------------------------------------------------------------------------------

       RooMinuit* rminuit( 0x0 ) ;


       RooMinuit* rminuit_uc = new RooMinuit( *nll  ) ;

       rminuit_uc->setPrintLevel(verbLevel-1) ;
       rminuit_uc->setNoWarn() ;

       rminuit_uc->migrad() ;
       rminuit_uc->hesse() ;

       RooFitResult* rfr_uc = rminuit_uc->fit("mr") ;

       double floatParInitVal[10000] ;
       char   floatParName[10000][100] ;
       int nFloatParInitVal(0) ;
       RooArgList ral_floats = rfr_uc->floatParsFinal() ;
       TIterator* floatParIter = ral_floats.createIterator() ;
       {
          RooRealVar* par ;
          while ( (par = (RooRealVar*) floatParIter->Next()) ) {
             sprintf( floatParName[nFloatParInitVal], "%s", par->GetName() ) ;
             floatParInitVal[nFloatParInitVal] = par->getVal() ;
             nFloatParInitVal++ ;
          }
       }



     //-------

       printf("\n\n Unbiased best value for new POI %s is : %7.1f\n\n", new_poi_rar->GetName(), new_poi_rar->getVal() ) ;
       double best_poi_val = new_poi_rar->getVal() ;

       char minuit_formula[10000] ;
       sprintf( minuit_formula, "%s+%s*(%s-%s)*(%s-%s)",
         nll->GetName(),
         rrv_constraintWidth->GetName(),
         new_poi_rar->GetName(), rrv_poiValue->GetName(),
         new_poi_rar->GetName(), rrv_poiValue->GetName()
          ) ;

       printf("\n\n Creating new minuit variable with formula: %s\n\n", minuit_formula ) ;
       RooFormulaVar* new_minuit_var = new RooFormulaVar("new_minuit_var", minuit_formula,
           RooArgList( *nll,
                       *rrv_constraintWidth,
                       *new_poi_rar, *rrv_poiValue,
                       *new_poi_rar, *rrv_poiValue
                       ) ) ;

       printf("\n\n Current value is %.2f\n\n",
            new_minuit_var->getVal() ) ;

       rminuit = new RooMinuit( *new_minuit_var ) ;


       RooAbsReal* plot_var = nll ;

       printf("\n\n Current value is %.2f\n\n",
            plot_var->getVal() ) ;




       rminuit->setPrintLevel(verbLevel-1) ;
       if ( verbLevel <=0 ) { rminuit->setNoWarn() ; }

    //----------------------------------------------------------------------------------------------

       //-- If POI range is -1 to -1, automatically determine the range using the set value.

       if ( poiMinVal < 0. && poiMaxVal < 0. ) {

          printf("\n\n Automatic determination of scan range.\n\n") ;

          if ( startPoiVal <= 0. ) {
             printf("\n\n *** POI starting value zero or negative %g.  Quit.\n\n\n", startPoiVal ) ;
             return ;
          }

          poiMinVal = startPoiVal - 3.5 * sqrt(startPoiVal) ;
          poiMaxVal = startPoiVal + 6.0 * sqrt(startPoiVal) ;

          if ( poiMinVal < 0. ) { poiMinVal = 0. ; }

          printf("    Start val = %g.   Scan range:   %g  to  %g\n\n", startPoiVal, poiMinVal, poiMaxVal ) ;


       }



    //----------------------------------------------------------------------------------------------


       double poiVals_scanDown[1000] ;
       double nllVals_scanDown[1000] ;

       //-- Do scan down from best value.

       printf("\n\n +++++ Starting scan down from best value.\n\n") ;

       double minNllVal(1.e9) ;

       for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) {

          ////double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*(npoiPoints-1)) ;
          double poiValue = best_poi_val - poivi*(best_poi_val-poiMinVal)/(1.*(npoiPoints/2-1)) ;

          rrv_poiValue -> setVal( poiValue ) ;
          rrv_poiValue -> setConstant( kTRUE ) ;


       //+++++++++++++++++++++++++++++++++++

          rminuit->migrad() ;
          rminuit->hesse() ;
          RooFitResult* rfr = rminuit->save() ;

       //+++++++++++++++++++++++++++++++++++


          if ( verbLevel > 0 ) { rfr->Print("v") ; }


          float fit_minuit_var_val = rfr->minNll() ;

          printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI :    %.5f   %.5f   %.5f   %.5f\n",
                poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ;
          cout << flush ;



          poiVals_scanDown[poivi] = new_poi_rar->getVal() ;
          nllVals_scanDown[poivi] = plot_var->getVal() ;

          if ( nllVals_scanDown[poivi] < minNllVal ) { minNllVal = nllVals_scanDown[poivi] ; }

          delete rfr ;


       } // poivi


       printf("\n\n +++++ Resetting floats to best fit values.\n\n") ;

       for ( int pi=0; pi<nFloatParInitVal; pi++ ) {
          RooRealVar* par = ws->var( floatParName[pi] ) ;
          par->setVal( floatParInitVal[pi] ) ;
       } // pi.

       printf("\n\n +++++ Starting scan up from best value.\n\n") ;

      //-- Now do scan up.

       double poiVals_scanUp[1000] ;
       double nllVals_scanUp[1000] ;

       for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) {

          double poiValue = best_poi_val + poivi*(poiMaxVal-best_poi_val)/(1.*(npoiPoints/2-1)) ;

          rrv_poiValue -> setVal( poiValue ) ;
          rrv_poiValue -> setConstant( kTRUE ) ;


       //+++++++++++++++++++++++++++++++++++

          rminuit->migrad() ;
          rminuit->hesse() ;
          RooFitResult* rfr = rminuit->save() ;

       //+++++++++++++++++++++++++++++++++++


          if ( verbLevel > 0 ) { rfr->Print("v") ; }


          float fit_minuit_var_val = rfr->minNll() ;

          printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI :    %.5f   %.5f   %.5f   %.5f\n",
                poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ;
          cout << flush ;

          poiVals_scanUp[poivi] = new_poi_rar->getVal() ;
          nllVals_scanUp[poivi] = plot_var->getVal() ;

          if ( nllVals_scanUp[poivi] < minNllVal ) { minNllVal = nllVals_scanUp[poivi] ; }

          delete rfr ;


       } // poivi





       double poiVals[1000] ;
       double nllVals[1000] ;

       int pointCount(0) ;
       for ( int pi=0; pi<npoiPoints/2; pi++ ) {
          poiVals[pi] = poiVals_scanDown[(npoiPoints/2-1)-pi] ;
          nllVals[pi] = nllVals_scanDown[(npoiPoints/2-1)-pi] ;
          pointCount++ ;
       }
       for ( int pi=1; pi<npoiPoints/2; pi++ ) {
          poiVals[pointCount] = poiVals_scanUp[pi] ;
          nllVals[pointCount] = nllVals_scanUp[pi] ;
          pointCount++ ;
       }
       npoiPoints = pointCount ;

       printf("\n\n --- TGraph arrays:\n") ;
       for ( int i=0; i<npoiPoints; i++ ) {
          printf("  %2d : poi = %6.1f, nll = %g\n", i, poiVals[i], nllVals[i] ) ;
       }
       printf("\n\n") ;

       double nllDiffVals[1000] ;

       double poiAtMinlnL(-1.) ;
       double poiAtMinusDelta2(-1.) ;
       double poiAtPlusDelta2(-1.) ;
       for ( int poivi=0; poivi < npoiPoints ; poivi++ ) {
          nllDiffVals[poivi] = 2.*(nllVals[poivi] - minNllVal) ;
          double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*npoiPoints) ;
          if ( nllDiffVals[poivi] < 0.01 ) { poiAtMinlnL = poiValue ; }
          if ( poiAtMinusDelta2 < 0. && nllDiffVals[poivi] < 2.5 ) { poiAtMinusDelta2 = poiValue ; }
          if ( poiAtMinlnL > 0. && poiAtPlusDelta2 < 0. && nllDiffVals[poivi] > 2.0 ) { poiAtPlusDelta2 = poiValue ; }
       } // poivi

       printf("\n\n Estimates for poi at delta ln L = -2, 0, +2:  %g ,   %g ,   %g\n\n", poiAtMinusDelta2, poiAtMinlnL, poiAtPlusDelta2 ) ;




      //--- Main canvas

       TCanvas* cscan = (TCanvas*) gDirectory->FindObject("cscan") ;
       if ( cscan == 0x0 ) {
          printf("\n Creating canvas.\n\n") ;
          cscan = new TCanvas("cscan","Delta nll") ;
       }


       char gname[1000] ;

       TGraph* graph = new TGraph( npoiPoints, poiVals, nllDiffVals ) ;
       sprintf( gname, "scan_%s", new_poi_name ) ;
       graph->SetName( gname ) ;

       double poiBest(-1.) ;
       double poiMinus1stdv(-1.) ;
       double poiPlus1stdv(-1.) ;
       double poiMinus2stdv(-1.) ;
       double poiPlus2stdv(-1.) ;
       double twoDeltalnLMin(1e9) ;

       int nscan(1000) ;
       for ( int xi=0; xi<nscan; xi++ ) {

          double x = poiVals[0] + xi*(poiVals[npoiPoints-1]-poiVals[0])/(nscan-1) ;

          double twoDeltalnL = graph -> Eval( x, 0, "S" ) ;

          if ( poiMinus1stdv < 0. && twoDeltalnL < 1.0 ) { poiMinus1stdv = x ; printf(" set m1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}
          if ( poiMinus2stdv < 0. && twoDeltalnL < 4.0 ) { poiMinus2stdv = x ; printf(" set m2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}
          if ( twoDeltalnL < twoDeltalnLMin ) { poiBest = x ; twoDeltalnLMin = twoDeltalnL ; }
          if ( twoDeltalnLMin < 0.3 && poiPlus1stdv < 0. && twoDeltalnL > 1.0 ) { poiPlus1stdv = x ; printf(" set p1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}
          if ( twoDeltalnLMin < 0.3 && poiPlus2stdv < 0. && twoDeltalnL > 4.0 ) { poiPlus2stdv = x ; printf(" set p2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}

          if ( xi%100 == 0 ) { printf( " %4d : poi=%6.2f,  2DeltalnL = %6.2f\n", xi, x, twoDeltalnL ) ; }

       }
       printf("\n\n POI estimate :  %g  +%g  -%g    [%g,%g],   two sigma errors: +%g  -%g   [%g,%g]\n\n",
               poiBest,
               (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), poiMinus1stdv, poiPlus1stdv,
               (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv), poiMinus2stdv, poiPlus2stdv
               ) ;

       printf(" %s val,pm1sig,pm2sig: %7.2f  %7.2f  %7.2f  %7.2f  %7.2f\n",
          new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv) ) ;

       char htitle[1000] ;
       sprintf(htitle, "%s profile likelihood scan: -2ln(L/Lm)", new_poi_name ) ;
       TH1F* hscan = new TH1F("hscan", htitle, 10, poiMinVal, poiMaxVal ) ;
       hscan->SetMinimum(0.) ;
       hscan->SetMaximum(ymax) ;


       hscan->DrawCopy() ;
       graph->SetLineColor(4) ;
       graph->SetLineWidth(3) ;
       graph->Draw("CP") ;
       gPad->SetGridx(1) ;
       gPad->SetGridy(1) ;
       cscan->Update() ;

       TLine* line = new TLine() ;
       line->SetLineColor(2) ;
       line->DrawLine(poiMinVal, 1., poiPlus1stdv, 1.) ;
       line->DrawLine(poiMinus1stdv,0., poiMinus1stdv, 1.) ;
       line->DrawLine(poiPlus1stdv ,0., poiPlus1stdv , 1.) ;

       TText* text = new TText() ;
       text->SetTextSize(0.04) ;
       char tstring[1000] ;

       sprintf( tstring, "%s = %.1f +%.1f -%.1f", new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv) ) ;
       text -> DrawTextNDC( 0.15, 0.85, tstring ) ;

       sprintf( tstring, "68%% interval [%.1f,  %.1f]", poiMinus1stdv, poiPlus1stdv ) ;
       text -> DrawTextNDC( 0.15, 0.78, tstring ) ;


       char hname[1000] ;
       sprintf( hname, "hscanout_%s", new_poi_name ) ;
       TH1F* hsout = new TH1F( hname,"scan results",4,0.,4.) ;
       double obsVal(-1.) ;
       hsout->SetBinContent(1, obsVal ) ;
       hsout->SetBinContent(2, poiPlus1stdv ) ;
       hsout->SetBinContent(3, poiBest ) ;
       hsout->SetBinContent(4, poiMinus1stdv ) ;
       TAxis* xaxis = hsout->GetXaxis() ;
       xaxis->SetBinLabel(1,"Observed val.") ;
       xaxis->SetBinLabel(2,"Model+1sd") ;
       xaxis->SetBinLabel(3,"Model") ;
       xaxis->SetBinLabel(4,"Model-1sd") ;

       char outrootfile[10000] ;
       sprintf( outrootfile, "%s/scan-ff-%s.root", outputdir.Data(), new_poi_name ) ;

       char outpdffile[10000] ;
       sprintf( outpdffile, "%s/scan-ff-%s.pdf", outputdir.Data(), new_poi_name ) ;

       cscan->Update() ; cscan->Draw() ;

       printf("\n Saving %s\n", outpdffile ) ;
       cscan->SaveAs( outpdffile ) ;



     //--- save in root file

       printf("\n Saving %s\n", outrootfile ) ;
       TFile fout(outrootfile,"recreate") ;
       graph->Write() ;
       hsout->Write() ;
       fout.Close() ;

       delete ws ;
       wstf->Close() ;

   }
Пример #22
0
void plotGlauberCenVars(Float_t eff=1., const Char_t* file="ZNA_ntuple_195483.root")
{
  TFile *f = TFile::Open(file);
  TNtuple* ntuple = dynamic_cast<TNtuple*> (f->Get("gnt"));
   
  TGraphErrors *gNpart=new TGraphErrors(0);
  gNpart->SetName("gNpart"); 
  TGraphErrors *gNcoll=new TGraphErrors(0);
  gNcoll->SetName("gNcoll"); 
  TGraphErrors *gtAA=new TGraphErrors(0);
  gtAA->SetName("gtAA"); 
  
  /*TFile *ffd = TFile::Open("hZNAcalibRUN195483.root");
  TH1F * hd = dynamic_cast<TH1F*> (ffd->Get(("hZNA")));
  hd->Sumw2();*/
  //
  TFile *ff = TFile::Open("ZNA_fit_195483.root");
  TH1F * hd = dynamic_cast<TH1F*> (ff->Get(("hZNA")));
  hd->Sumw2();
  TH1F * hg = dynamic_cast<TH1F*> (ff->Get(("hZNA_GLAU")));
  hd->SetMarkerColor(kBlue+3);
  hd->SetMarkerSize(1.);
  hd->SetLineColor(kBlue+3);
  hd->SetLineWidth(2);
  hd->SetMarkerStyle(20);
  hd->SetLineWidth(2);
//  hg->Scale(1./hd->GetEntries());
//  hd->Scale(1./hd->GetEntries());
  hd->SetMinimum(1.e-01);
  hd->SetXTitle("E_{ZNA} (TeV)");
  hg->SetLineColor(kPink-2);
  hg->SetLineWidth(2);
  
  TH1F* hist = (TH1F*) hg->Clone("hist");

  //---------------------------------------------------
  getCentrality(hist, eff);
  //---------------------------------------------------

  TCanvas* canvas = new TCanvas("canvas","Multiplicity",200,200,600,600);
  canvas->cd();
  canvas->SetLogy();
  hd->Draw("pe");
  //hd->GetXaxis()->SetRangeUser(0.,130.);
  hd->SetMinimum(0.01);
  hg->Draw("SAME");

  float low = 0;
  float high = hist->GetNbinsX();
  for(int i=0; i<binUp->GetSize(); i++){
      low = binUp->At(i);
      hist->GetXaxis()->SetRange(low+1, high);
      hist->SetFillColor((i%2==0)?0:kAzure+6);
      hist->SetLineColor((i%2==0)?0:kAzure+6);
      printf(" bin %d  low %f  high %f\n",i,low,high);
      hist->DrawCopy("h same");
      high=low;
  }
  hd->Draw("esame");
  hg->Draw("SAME");
  canvas->Print("plotGlauber.gif");   
  
  TCanvas* canvas2 = new TCanvas("canvas2","NPart");
  canvas2->cd();
  canvas2->SetLogy();
  TH1F *hist2 = new TH1F("hist2","N_{part}",35,0.,35);
  ntuple->Project("hist2","fNpart");
  //hist2->SetStats(0);
  hist2->SetTitle("");
  hist2->GetXaxis()->SetTitle("NPart");
  hist2->GetXaxis()->SetTitleSize(0.05);
  hist2->GetXaxis()->SetLabelSize(0.04);
  hist2->GetXaxis()->SetTitleOffset(1.2);
  hist2->GetYaxis()->SetTitle("");
  hist2->GetYaxis()->SetTitleOffset(1.3);
  hist2->GetYaxis()->SetTitleSize(0.05);
  hist2->GetYaxis()->SetLabelSize(0.04);
  hist2->DrawCopy();
  
  float lownp=0;
  float highnp=5000;
  TH1F *htemp10[nbins];
  printf("\n ***** N_part \n");
  for(int i=0; i<Multbin->GetSize(); i++){
      lownp = Multbin->At(i);
      char cuts[120];
      char histname[20];
      sprintf(cuts,"Etot>%f && Etot<=%f",lownp,highnp);
      sprintf(histname,"htemp10[%i]",i);
      htemp10[i] = new TH1F(histname,"N_{part}",35,0.,35);
      //printf(" cut: %s\n", cuts);
      ntuple->Project(histname,"fNpart",cuts);
      htemp10[i]->SetLineColor(i+1);
      htemp10[i]->Draw("same");
      cout  << i << " | " << lownp << " | " << highnp << " | " << setprecision(3) << 
      htemp10[i]->GetMean() << " | " << htemp10[i]->GetRMS() << " | " << endl;
      gNpart->SetPoint(i,Float_t(i),htemp10[i]->GetMean());
      gNpart->SetPointError(i,0,htemp10[i]->GetRMS());
      highnp = lownp;
  }
  cout << endl;
  
  TCanvas* canvas3 = new TCanvas("canvas3","NColl");
  canvas3->SetLogy();
  TH1F *hist3 = new TH1F("hist3","N_{coll}",35,0.,35);
  ntuple->Project("hist3","fNcoll");
  //hist3->SetStats(0);
  hist3->SetTitle("");
  hist3->GetXaxis()->SetTitle("NColl");
  hist3->GetXaxis()->SetTitleSize(0.05);
  hist3->GetXaxis()->SetLabelSize(0.04);
  hist3->GetXaxis()->SetTitleOffset(1.2);
  hist3->GetXaxis()->SetTitle("");
  hist3->GetXaxis()->SetTitleOffset(1.3);
  hist3->GetXaxis()->SetTitleSize(0.05);
  hist3->GetXaxis()->SetLabelSize(0.04);
  hist3->DrawCopy();
  
  float lownc = 0;
  float highnc = 5000;
  TH1F *htemp11[nbins];
  printf("\n ***** N_coll \n");
  for(int i=0; i<Multbin->GetSize(); i++){
      lownc = Multbin->At(i);
      char cuts[120];
      char histname[20];
      sprintf(cuts,"Etot>%f && Etot<=%f",lownc,highnc);
      sprintf(histname,"htemp11[%i]",i);
      htemp11[i] = new TH1F(histname,"N_{coll}",35,0.,35.);
      ntuple->Project(histname,"fNcoll",cuts);
      htemp11[i]->SetLineColor(i+1);
      htemp11[i]->Draw("same");
      cout << setprecision(3) << htemp11[i]->GetMean() << " | " << htemp11[i]->GetRMS() << " | " << endl;
      gNcoll->SetPoint(i,Float_t(i),htemp11[i]->GetMean());
      gNcoll->SetPointError(i,0,htemp11[i]->GetRMS());
      highnc = lownc;
  }
  cout << endl;
  
  TCanvas* canvas4 = new TCanvas("canvas4","Impact Parameter");
  canvas4->cd();
  TH1F *hist4 = new TH1F("hist4","b",100,0.,16.);
  ntuple->Project("hist4","fB");
  //hist4->SetStats(0);
  hist4->SetTitle("");
  hist4->GetXaxis()->SetTitle("b");
  hist4->GetXaxis()->SetTitleSize(0.05);
  hist4->GetXaxis()->SetLabelSize(0.04);
  hist4->GetXaxis()->SetTitleOffset(1.2);
  hist4->GetYaxis()->SetTitle("");
  hist4->GetYaxis()->SetTitleOffset(1.3);
  hist4->GetYaxis()->SetTitleSize(0.05);
  hist4->GetYaxis()->SetLabelSize(0.04);
  hist4->DrawCopy();
  
  float lowb = 0;
  float highb = 5000;
  TH1F *htemp12[nbins];
  printf("\n ***** b \n");
  for(int i=0; i<Multbin->GetSize(); i++){
      lowb = Multbin->At(i);
      char cuts[100];
      char histname[25];
      sprintf(cuts,"Etot>%f && Etot<=%f",lowb,highb);
      sprintf(histname,"htemp12[%i]",i);
      htemp12[i] = new TH1F(histname,"b",100,0.,16.);
      //printf(" cut: %s\n", cuts);
      ntuple->Project(histname,"fB",cuts);
      htemp12[i]->SetLineColor(i+1);
      htemp12[i]->DrawCopy("same");
      cout << i << " | " << lowb << " | " << highb << " | " << setprecision(3) << htemp12[i]->GetMean() << " | " << htemp12[i]->GetRMS() << " | " << endl;
      highb = lowb;
  }
  
  TCanvas* canvas5 = new TCanvas("canvas5","Taa");
  canvas5->SetLogy();
  TH1F *hist5 = new TH1F("hist5","T_{AA}",100,0.,0.5);
  ntuple->Project("hist5","fTaa");
  //hist5->SetStats(0);
  hist5->SetTitle("");
  hist5->GetXaxis()->SetTitle("tAA");
  hist5->GetXaxis()->SetTitleSize(0.05);
  hist5->GetXaxis()->SetLabelSize(0.04);
  hist5->GetXaxis()->SetTitleOffset(1.2);
  hist5->GetYaxis()->SetTitle("");
  hist5->GetYaxis()->SetTitleOffset(1.3);
  hist5->GetYaxis()->SetTitleSize(0.05);
  hist5->GetYaxis()->SetLabelSize(0.04);
  hist5->DrawCopy();
  
  float lowtaa = 0;
  float hightaa = 5000;
  TH1F *htemp13[nbins];
  printf("\n ***** T_AA \n");
  for (int i=0; i<Multbin->GetSize(); i++){
      lowtaa = Multbin->At(i);
      char cuts[100];
      char histname[100];
      sprintf(cuts,"Etot>%f && Etot<%f",lowtaa,hightaa);
      //printf(" cut: %s\n", cuts);
      sprintf(histname,"htemp13[%i]",i);
      htemp13[i] = new TH1F(histname,"b",100,0.,0.5);
      ntuple->Project(histname,"fTaa",cuts);
      htemp13[i]->SetLineColor(i+1);
      htemp13[i]->DrawCopy("same");
      cout << setprecision(3) << htemp13[i]->GetMean() << " | " << htemp13[i]->GetRMS() << " | " << endl;  
      gtAA->SetPoint(i,Float_t(i),htemp13[i]->GetMean());
      gtAA->SetPointError(i,0,htemp13[i]->GetRMS());
      hightaa = lowtaa;
  }

  /*TCanvas* canvas6 = new TCanvas("canvas6","Mean Mult");
  canvas6->SetLogy();
  //ntuple->Draw("ntot/Npart/23.867>>hmultperanc");
  ntuple->Draw("Etot/(0.801*Npart+(1-0.801)*Ncoll)/3.9>>hmultperanc");
  TH1F* hmultperanc = (TH1F*)gPad->GetPrimitive("hmultperanc");
  TH1F* hist6 = (TH1F*)hmultperanc->Clone();
  hist6->SetStats(0);
  hist6->SetTitle("");
  hist6->GetXaxis()->SetTitle("Mult/NPart");
  hist6->GetXaxis()->SetTitleSize(0.05);
  hist6->GetXaxis()->SetLabelSize(0.04);
  hist6->GetXaxis()->SetTitleOffset(1.);
  hist6->GetYaxis()->SetTitle("");
  hist6->GetYaxis()->SetTitleOffset(1.);
  hist6->GetYaxis()->SetTitleSize(0.05);
  hist6->GetYaxis()->SetLabelSize(0.04);
  hist6->DrawCopy();
  
  low=0;
  high=50000;
  for (int i=0; i<Multbin->GetSize(); i++)
    {
      low=Multbin->At(i);
      char cuts[100];
      char histtitle1[100];
      char histtitle[100];
      sprintf(cuts,"Etot>%i && Etot<%i",low,high);
      //sprintf(histtitle,"ntot/Npart/23.867>>htemp%i(100)",80+i);
      sprintf(histtitle,"Etot/(0.801*Npart+(1-0.801)*Ncoll)/3.9>>htemp%i(100)",80+i);
      sprintf(histtitle1,"htemp%i",80+i);
      ntuple->Draw(histtitle,cuts,"same");
      TH1F* htemp14 = (TH1F*)gPad->GetPrimitive(histtitle1);
      htemp14 = (TH1F*)gPad->GetPrimitive(histtitle1);
      htemp14->SetFillColor(i+1);
      htemp14->DrawCopy("same");
      //cout  << i << " | " << low << " | " << high << " | " << setprecision(3) << htemp14->GetMean() << " | " << htemp14->GetRMS() << " | " << endl;
      high=low;
      
      h->SetBinContent(i+1,htemp14->GetMean());
      h->SetBinError(i+1,0.01*htemp14->GetRMS());  
    }
  
  TCanvas* c7 = new TCanvas("c7","c7");
  c7->cd();
  h->Draw();
  */
  
  //TFile *outrootfile = new TFile("OutGlauber_Hijing.root","RECREATE");
  TFile *outrootfile = new TFile("test.root","RECREATE");
  outrootfile->cd();
  //h->Write();
  gNpart->Write();
  gNcoll->Write();
  gtAA->Write();
  hd->Write();
  outrootfile->Close();


}
Пример #23
0
Bool_t CheckESD(const char* gAliceFileName = "galice.root", 
		const char* esdFileName = "AliESDs.root")
{
// check the content of the ESD
 
  // check values
  Int_t    checkNGenLow = 1;

  Double_t checkEffLow = 0.5;
  Double_t checkEffSigma = 3;
  Double_t checkFakeHigh = 0.5;
  Double_t checkFakeSigma = 3;

  Double_t checkResPtInvHigh = 5;
  Double_t checkResPtInvSigma = 3;
  Double_t checkResPhiHigh = 10;
  Double_t checkResPhiSigma = 3;
  Double_t checkResThetaHigh = 10;
  Double_t checkResThetaSigma = 3;

  Double_t checkPIDEffLow = 0.5;
  Double_t checkPIDEffSigma = 3;
  Double_t checkResTOFHigh = 500;
  Double_t checkResTOFSigma = 3;

  Double_t checkPHOSNLow = 5;
  Double_t checkPHOSEnergyLow = 0.3;
  Double_t checkPHOSEnergyHigh = 1.0;
  Double_t checkEMCALNLow = 50;
  Double_t checkEMCALEnergyLow = 0.05;
  Double_t checkEMCALEnergyHigh = 1.0;

  Double_t checkMUONNLow = 1;
  Double_t checkMUONPtLow = 0.5;
  Double_t checkMUONPtHigh = 10.;

  Double_t cutPtV0 = 0.3;
  Double_t checkV0EffLow = 0.02;
  Double_t checkV0EffSigma = 3;
  Double_t cutPtCascade = 0.5;
  Double_t checkCascadeEffLow = 0.01;
  Double_t checkCascadeEffSigma = 3;

  // open run loader and load gAlice, kinematics and header
  AliRunLoader* runLoader = AliRunLoader::Open(gAliceFileName);
  if (!runLoader) {
    Error("CheckESD", "getting run loader from file %s failed", 
	    gAliceFileName);
    return kFALSE;
  }
  runLoader->LoadgAlice();
  gAlice = runLoader->GetAliRun();
  if (!gAlice) {
    Error("CheckESD", "no galice object found");
    return kFALSE;
  }
  runLoader->LoadKinematics();
  runLoader->LoadHeader();

  // open the ESD file
  TFile* esdFile = TFile::Open(esdFileName);
  if (!esdFile || !esdFile->IsOpen()) {
    Error("CheckESD", "opening ESD file %s failed", esdFileName);
    return kFALSE;
  }
  AliESDEvent * esd = new AliESDEvent;
  TTree* tree = (TTree*) esdFile->Get("esdTree");
  if (!tree) {
    Error("CheckESD", "no ESD tree found");
    return kFALSE;
  }
  esd->ReadFromTree(tree);

  // efficiency and resolution histograms
  Int_t nBinsPt = 15;
  Float_t minPt = 0.1;
  Float_t maxPt = 3.1;
  TH1F* hGen = CreateHisto("hGen", "generated tracks", 
			   nBinsPt, minPt, maxPt, "p_{t} [GeV/c]", "N");
  TH1F* hRec = CreateHisto("hRec", "reconstructed tracks", 
			   nBinsPt, minPt, maxPt, "p_{t} [GeV/c]", "N");
  Int_t nGen = 0;
  Int_t nRec = 0;
  Int_t nFake = 0;

  TH1F* hResPtInv = CreateHisto("hResPtInv", "", 100, -10, 10, 
           "(p_{t,rec}^{-1}-p_{t,sim}^{-1}) / p_{t,sim}^{-1} [%]", "N");
  TH1F* hResPhi = CreateHisto("hResPhi", "", 100, -20, 20, 
			      "#phi_{rec}-#phi_{sim} [mrad]", "N");
  TH1F* hResTheta = CreateHisto("hResTheta", "", 100, -20, 20, 
				"#theta_{rec}-#theta_{sim} [mrad]", "N");

  // PID
  Int_t partCode[AliPID::kSPECIES] = 
    {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
  const char* partName[AliPID::kSPECIES+1] = 
    {"electron", "muon", "pion", "kaon", "proton", "other"};
  Double_t partFrac[AliPID::kSPECIES] = 
    {0.01, 0.01, 0.85, 0.10, 0.05};
  Int_t identified[AliPID::kSPECIES+1][AliPID::kSPECIES];
  for (Int_t iGen = 0; iGen < AliPID::kSPECIES+1; iGen++) {
    for (Int_t iRec = 0; iRec < AliPID::kSPECIES; iRec++) {
      identified[iGen][iRec] = 0;
    }
  }
  Int_t nIdentified = 0;

  // dE/dx and TOF
  TH2F* hDEdxRight = new TH2F("hDEdxRight", "", 300, 0, 3, 100, 0, 400);
  hDEdxRight->SetStats(kFALSE);
  hDEdxRight->GetXaxis()->SetTitle("p [GeV/c]");
  hDEdxRight->GetYaxis()->SetTitle("dE/dx_{TPC}");
  hDEdxRight->SetMarkerStyle(kFullCircle);
  hDEdxRight->SetMarkerSize(0.4);
  TH2F* hDEdxWrong = new TH2F("hDEdxWrong", "", 300, 0, 3, 100, 0, 400);
  hDEdxWrong->SetStats(kFALSE);
  hDEdxWrong->GetXaxis()->SetTitle("p [GeV/c]");
  hDEdxWrong->GetYaxis()->SetTitle("dE/dx_{TPC}");
  hDEdxWrong->SetMarkerStyle(kFullCircle);
  hDEdxWrong->SetMarkerSize(0.4);
  hDEdxWrong->SetMarkerColor(kRed);
  TH1F* hResTOFRight = CreateHisto("hResTOFRight", "", 100, -1000, 1000, 
				   "t_{TOF}-t_{track} [ps]", "N");
  TH1F* hResTOFWrong = CreateHisto("hResTOFWrong", "", 100, -1000, 1000, 
				   "t_{TOF}-t_{track} [ps]", "N");
  hResTOFWrong->SetLineColor(kRed);

  // calorimeters
  TH1F* hEPHOS = CreateHisto("hEPHOS", "PHOS", 100, 0, 50, "E [GeV]", "N");
  TH1F* hEEMCAL = CreateHisto("hEEMCAL", "EMCAL", 100, 0, 50, "E [GeV]", "N");

  // muons
  TH1F* hPtMUON = CreateHisto("hPtMUON", "MUON", 100, 0, 20, 
			      "p_{t} [GeV/c]", "N");

  // V0s and cascades
  TH1F* hMassK0 = CreateHisto("hMassK0", "K^{0}", 100, 0.4, 0.6, 
			      "M(#pi^{+}#pi^{-}) [GeV/c^{2}]", "N");
  TH1F* hMassLambda = CreateHisto("hMassLambda", "#Lambda", 100, 1.0, 1.2, 
				  "M(p#pi^{-}) [GeV/c^{2}]", "N");
  TH1F* hMassLambdaBar = CreateHisto("hMassLambdaBar", "#bar{#Lambda}", 
				     100, 1.0, 1.2, 
				     "M(#bar{p}#pi^{+}) [GeV/c^{2}]", "N");
  Int_t nGenV0s = 0;
  Int_t nRecV0s = 0;
  TH1F* hMassXi = CreateHisto("hMassXi", "#Xi", 100, 1.2, 1.5, 
			      "M(#Lambda#pi) [GeV/c^{2}]", "N");
  TH1F* hMassOmega = CreateHisto("hMassOmega", "#Omega", 100, 1.5, 1.8, 
				 "M(#LambdaK) [GeV/c^{2}]", "N");
  Int_t nGenCascades = 0;
  Int_t nRecCascades = 0;

  // loop over events
  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
    runLoader->GetEvent(iEvent);

    // select simulated primary particles, V0s and cascades
    AliStack* stack = runLoader->Stack();
    Int_t nParticles = stack->GetNtrack();
    TArrayF vertex(3);
    runLoader->GetHeader()->GenEventHeader()->PrimaryVertex(vertex);
    TObjArray selParticles;
    TObjArray selV0s;
    TObjArray selCascades;
    for (Int_t iParticle = 0; iParticle < nParticles; iParticle++) {
      TParticle* particle = stack->Particle(iParticle);
      if (!particle) continue;
      if (particle->Pt() < 0.001) continue;
      if (TMath::Abs(particle->Eta()) > 0.9) continue;
      TVector3 dVertex(particle->Vx() - vertex[0], 
		       particle->Vy() - vertex[1],
		       particle->Vz() - vertex[2]);
      if (dVertex.Mag() > 0.0001) continue;

      switch (TMath::Abs(particle->GetPdgCode())) {
      case kElectron:
      case kMuonMinus:
      case kPiPlus:
      case kKPlus:
      case kProton: {
	if (particle->Pt() > minPt) {
	  selParticles.Add(particle);
	  nGen++;
	  hGen->Fill(particle->Pt());
	}
	break;
      }
      case kK0Short:
      case kLambda0: {
	if (particle->Pt() > cutPtV0) {
	  nGenV0s++;
	  selV0s.Add(particle);
	}
	break;
      }
      case kXiMinus:
      case kOmegaMinus: {
	if (particle->Pt() > cutPtCascade) {
	  nGenCascades++;
	  selCascades.Add(particle);
	}
	break;
      }
      default: break;
      }
    }

    // get the event summary data
    tree->GetEvent(iEvent);
    if (!esd) {
      Error("CheckESD", "no ESD object found for event %d", iEvent);
      return kFALSE;
    }

    // loop over tracks
    for (Int_t iTrack = 0; iTrack < esd->GetNumberOfTracks(); iTrack++) {
      AliESDtrack* track = esd->GetTrack(iTrack);

      // select tracks of selected particles
      Int_t label = TMath::Abs(track->GetLabel());
      if (label > stack->GetNtrack()) continue;     // background
      TParticle* particle = stack->Particle(label);
      if (!selParticles.Contains(particle)) continue;
      if ((track->GetStatus() & AliESDtrack::kITSrefit) == 0) continue;
      if (track->GetConstrainedChi2() > 1e9) continue;
      selParticles.Remove(particle);   // don't count multiple tracks

      nRec++;
      hRec->Fill(particle->Pt());
      if (track->GetLabel() < 0) nFake++;

      // resolutions
      hResPtInv->Fill(100. * (TMath::Abs(track->GetSigned1Pt()) - 1./particle->Pt()) * 
		      particle->Pt());
      hResPhi->Fill(1000. * (track->Phi() - particle->Phi()));
      hResTheta->Fill(1000. * (track->Theta() - particle->Theta()));

      // PID
      if ((track->GetStatus() & AliESDtrack::kESDpid) == 0) continue;
      Int_t iGen = 5;
      for (Int_t i = 0; i < AliPID::kSPECIES; i++) {
	if (TMath::Abs(particle->GetPdgCode()) == partCode[i]) iGen = i;
      }
      Double_t probability[AliPID::kSPECIES];
      track->GetESDpid(probability);
      Double_t pMax = 0;
      Int_t iRec = 0;
      for (Int_t i = 0; i < AliPID::kSPECIES; i++) {
	probability[i] *= partFrac[i];
	if (probability[i] > pMax) {
	  pMax = probability[i];
	  iRec = i;
	}
      }
      identified[iGen][iRec]++;
      if (iGen == iRec) nIdentified++;

      // dE/dx and TOF
      Double_t time[AliPID::kSPECIES];
      track->GetIntegratedTimes(time);
      if (iGen == iRec) {
	hDEdxRight->Fill(particle->P(), track->GetTPCsignal());
        if ((track->GetStatus() & AliESDtrack::kTOFpid) != 0) {
	  hResTOFRight->Fill(track->GetTOFsignal() - time[iRec]);
	}
      } else {
	hDEdxWrong->Fill(particle->P(), track->GetTPCsignal());
        if ((track->GetStatus() & AliESDtrack::kTOFpid) != 0) {
	  hResTOFWrong->Fill(track->GetTOFsignal() - time[iRec]);
	}
      }
    }

    // loop over muon tracks
    {
    for (Int_t iTrack = 0; iTrack < esd->GetNumberOfMuonTracks(); iTrack++) {
      AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
      Double_t ptInv = TMath::Abs(muonTrack->GetInverseBendingMomentum());
      if (ptInv > 0.001) {
	hPtMUON->Fill(1./ptInv);
      }
    }
    }

    // loop over V0s
    for (Int_t iV0 = 0; iV0 < esd->GetNumberOfV0s(); iV0++) {
      AliESDv0* v0 = esd->GetV0(iV0);
      if (v0->GetOnFlyStatus()) continue;
      v0->ChangeMassHypothesis(kK0Short);
      hMassK0->Fill(v0->GetEffMass());
      v0->ChangeMassHypothesis(kLambda0);
      hMassLambda->Fill(v0->GetEffMass());
      v0->ChangeMassHypothesis(kLambda0Bar);
      hMassLambdaBar->Fill(v0->GetEffMass());

      Int_t negLabel = TMath::Abs(esd->GetTrack(v0->GetNindex())->GetLabel());
      if (negLabel > stack->GetNtrack()) continue;     // background
      Int_t negMother = stack->Particle(negLabel)->GetMother(0);
      if (negMother < 0) continue;
      Int_t posLabel = TMath::Abs(esd->GetTrack(v0->GetPindex())->GetLabel());
      if (posLabel > stack->GetNtrack()) continue;     // background
      Int_t posMother = stack->Particle(posLabel)->GetMother(0);
      if (negMother != posMother) continue;
      TParticle* particle = stack->Particle(negMother);
      if (!selV0s.Contains(particle)) continue;
      selV0s.Remove(particle);
      nRecV0s++;
    }

    // loop over Cascades
    for (Int_t iCascade = 0; iCascade < esd->GetNumberOfCascades(); 
	 iCascade++) {
      AliESDcascade* cascade = esd->GetCascade(iCascade);
      Double_t v0q;
      cascade->ChangeMassHypothesis(v0q,kXiMinus);
      hMassXi->Fill(cascade->GetEffMassXi());
      cascade->ChangeMassHypothesis(v0q,kOmegaMinus);
      hMassOmega->Fill(cascade->GetEffMassXi());

      Int_t negLabel = TMath::Abs(esd->GetTrack(cascade->GetNindex())
				  ->GetLabel());
      if (negLabel > stack->GetNtrack()) continue;     // background
      Int_t negMother = stack->Particle(negLabel)->GetMother(0);
      if (negMother < 0) continue;
      Int_t posLabel = TMath::Abs(esd->GetTrack(cascade->GetPindex())
				  ->GetLabel());
      if (posLabel > stack->GetNtrack()) continue;     // background
      Int_t posMother = stack->Particle(posLabel)->GetMother(0);
      if (negMother != posMother) continue;
      Int_t v0Mother = stack->Particle(negMother)->GetMother(0);
      if (v0Mother < 0) continue;
      Int_t bacLabel = TMath::Abs(esd->GetTrack(cascade->GetBindex())
				  ->GetLabel());
      if (bacLabel > stack->GetNtrack()) continue;     // background
      Int_t bacMother = stack->Particle(bacLabel)->GetMother(0);
      if (v0Mother != bacMother) continue;
      TParticle* particle = stack->Particle(v0Mother);
      if (!selCascades.Contains(particle)) continue;
      selCascades.Remove(particle);
      nRecCascades++;
    }

    // loop over the clusters
    {
      for (Int_t iCluster=0; iCluster<esd->GetNumberOfCaloClusters(); iCluster++) {
	AliESDCaloCluster * clust = esd->GetCaloCluster(iCluster);
	if (clust->IsPHOS()) hEPHOS->Fill(clust->E());
	if (clust->IsEMCAL()) hEEMCAL->Fill(clust->E());
      }
    }

  }

  // perform checks
  if (nGen < checkNGenLow) {
    Warning("CheckESD", "low number of generated particles: %d", Int_t(nGen));
  }

  TH1F* hEff = CreateEffHisto(hGen, hRec);

  Info("CheckESD", "%d out of %d tracks reconstructed including %d "
	 "fake tracks", nRec, nGen, nFake);
  if (nGen > 0) {
    // efficiency
    Double_t eff = nRec*1./nGen;
    Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGen);
    Double_t fake = nFake*1./nGen;
    Double_t fakeError = TMath::Sqrt(fake*(1.-fake) / nGen);
    Info("CheckESD", "eff = (%.1f +- %.1f) %%  fake = (%.1f +- %.1f) %%",
	 100.*eff, 100.*effError, 100.*fake, 100.*fakeError);

    if (eff < checkEffLow - checkEffSigma*effError) {
      Warning("CheckESD", "low efficiency: (%.1f +- %.1f) %%", 
	      100.*eff, 100.*effError);
    }
    if (fake > checkFakeHigh + checkFakeSigma*fakeError) {
      Warning("CheckESD", "high fake: (%.1f +- %.1f) %%", 
	      100.*fake, 100.*fakeError);
    }

    // resolutions
    Double_t res, resError;
    if (FitHisto(hResPtInv, res, resError)) {
      Info("CheckESD", "relative inverse pt resolution = (%.1f +- %.1f) %%",
	   res, resError);
      if (res > checkResPtInvHigh + checkResPtInvSigma*resError) {
	Warning("CheckESD", "bad pt resolution: (%.1f +- %.1f) %%", 
		res, resError);
      }
    }

    if (FitHisto(hResPhi, res, resError)) {
      Info("CheckESD", "phi resolution = (%.1f +- %.1f) mrad", res, resError);
      if (res > checkResPhiHigh + checkResPhiSigma*resError) {
	Warning("CheckESD", "bad phi resolution: (%.1f +- %.1f) mrad", 
		res, resError);
      }
    }

    if (FitHisto(hResTheta, res, resError)) {
      Info("CheckESD", "theta resolution = (%.1f +- %.1f) mrad", 
	   res, resError);
      if (res > checkResThetaHigh + checkResThetaSigma*resError) {
	Warning("CheckESD", "bad theta resolution: (%.1f +- %.1f) mrad", 
		res, resError);
      }
    }

    // PID
    if (nRec > 0) {
      Double_t eff = nIdentified*1./nRec;
      Double_t effError = TMath::Sqrt(eff*(1.-eff) / nRec);
      Info("CheckESD", "PID eff = (%.1f +- %.1f) %%", 
	   100.*eff, 100.*effError);
      if (eff < checkPIDEffLow - checkPIDEffSigma*effError) {
	Warning("CheckESD", "low PID efficiency: (%.1f +- %.1f) %%", 
		100.*eff, 100.*effError);
      }
    }

    printf("%9s:", "gen\\rec");
    for (Int_t iRec = 0; iRec < AliPID::kSPECIES; iRec++) {
      printf("%9s", partName[iRec]);
    }
    printf("\n");
    for (Int_t iGen = 0; iGen < AliPID::kSPECIES+1; iGen++) {
      printf("%9s:", partName[iGen]);
      for (Int_t iRec = 0; iRec < AliPID::kSPECIES; iRec++) {
	printf("%9d", identified[iGen][iRec]);
      }
      printf("\n");
    }

    if (FitHisto(hResTOFRight, res, resError)) {
      Info("CheckESD", "TOF resolution = (%.1f +- %.1f) ps", res, resError);
      if (res > checkResTOFHigh + checkResTOFSigma*resError) {
	Warning("CheckESD", "bad TOF resolution: (%.1f +- %.1f) ps", 
		res, resError);
      }
    }

    // calorimeters
    if (hEPHOS->Integral() < checkPHOSNLow) {
      Warning("CheckESD", "low number of PHOS particles: %d", 
	      Int_t(hEPHOS->Integral()));
    } else {
      Double_t mean = hEPHOS->GetMean();
      if (mean < checkPHOSEnergyLow) {
	Warning("CheckESD", "low mean PHOS energy: %.1f GeV", mean);
      } else if (mean > checkPHOSEnergyHigh) {
	Warning("CheckESD", "high mean PHOS energy: %.1f GeV", mean);
      }
    }

    if (hEEMCAL->Integral() < checkEMCALNLow) {
      Warning("CheckESD", "low number of EMCAL particles: %d", 
	      Int_t(hEEMCAL->Integral()));
    } else {
      Double_t mean = hEEMCAL->GetMean();
      if (mean < checkEMCALEnergyLow) {
	Warning("CheckESD", "low mean EMCAL energy: %.1f GeV", mean);
      } else if (mean > checkEMCALEnergyHigh) {
	Warning("CheckESD", "high mean EMCAL energy: %.1f GeV", mean);
      }
    }

    // muons
    if (hPtMUON->Integral() < checkMUONNLow) {
      Warning("CheckESD", "low number of MUON particles: %d", 
	      Int_t(hPtMUON->Integral()));
    } else {
      Double_t mean = hPtMUON->GetMean();
      if (mean < checkMUONPtLow) {
	Warning("CheckESD", "low mean MUON pt: %.1f GeV/c", mean);
      } else if (mean > checkMUONPtHigh) {
	Warning("CheckESD", "high mean MUON pt: %.1f GeV/c", mean);
      }
    }

    // V0s
    if (nGenV0s > 0) {
      Double_t eff = nRecV0s*1./nGenV0s;
      Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGenV0s);
      if (effError == 0) effError = checkV0EffLow / TMath::Sqrt(1.*nGenV0s);
      Info("CheckESD", "V0 eff = (%.1f +- %.1f) %%", 
	   100.*eff, 100.*effError);
      if (eff < checkV0EffLow - checkV0EffSigma*effError) {
	Warning("CheckESD", "low V0 efficiency: (%.1f +- %.1f) %%", 
		100.*eff, 100.*effError);
      }
    }

    // Cascades
    if (nGenCascades > 0) {
      Double_t eff = nRecCascades*1./nGenCascades;
      Double_t effError = TMath::Sqrt(eff*(1.-eff) / nGenCascades);
      if (effError == 0) effError = checkV0EffLow / 
			   TMath::Sqrt(1.*nGenCascades);
      Info("CheckESD", "Cascade eff = (%.1f +- %.1f) %%", 
	   100.*eff, 100.*effError);
      if (eff < checkCascadeEffLow - checkCascadeEffSigma*effError) {
	Warning("CheckESD", "low Cascade efficiency: (%.1f +- %.1f) %%", 
		100.*eff, 100.*effError);
      }
    }
  }

  // draw the histograms if not in batch mode
  if (!gROOT->IsBatch()) {
    new TCanvas;
    hEff->DrawCopy();
    new TCanvas;
    hResPtInv->DrawCopy("E");
    new TCanvas;
    hResPhi->DrawCopy("E");
    new TCanvas;
    hResTheta->DrawCopy("E");
    new TCanvas;
    hDEdxRight->DrawCopy();
    hDEdxWrong->DrawCopy("SAME");
    new TCanvas;
    hResTOFRight->DrawCopy("E");
    hResTOFWrong->DrawCopy("SAME");
    new TCanvas;
    hEPHOS->DrawCopy("E");
    new TCanvas;
    hEEMCAL->DrawCopy("E");
    new TCanvas;
    hPtMUON->DrawCopy("E");
    new TCanvas;
    hMassK0->DrawCopy("E");
    new TCanvas;
    hMassLambda->DrawCopy("E");
    new TCanvas;
    hMassLambdaBar->DrawCopy("E");
    new TCanvas;
    hMassXi->DrawCopy("E");
    new TCanvas;
    hMassOmega->DrawCopy("E");
  }

  // write the output histograms to a file
  TFile* outputFile = TFile::Open("check.root", "recreate");
  if (!outputFile || !outputFile->IsOpen()) {
    Error("CheckESD", "opening output file check.root failed");
    return kFALSE;
  }
  hEff->Write();
  hResPtInv->Write();
  hResPhi->Write();
  hResTheta->Write();
  hDEdxRight->Write();
  hDEdxWrong->Write();
  hResTOFRight->Write();
  hResTOFWrong->Write();
  hEPHOS->Write();
  hEEMCAL->Write();
  hPtMUON->Write();
  hMassK0->Write();
  hMassLambda->Write();
  hMassLambdaBar->Write();
  hMassXi->Write();
  hMassOmega->Write();
  outputFile->Close();
  delete outputFile;

  // clean up
  delete hGen;
  delete hRec;
  delete hEff;
  delete hResPtInv;
  delete hResPhi;
  delete hResTheta;
  delete hDEdxRight;
  delete hDEdxWrong;
  delete hResTOFRight;
  delete hResTOFWrong;
  delete hEPHOS;
  delete hEEMCAL;
  delete hPtMUON;
  delete hMassK0;
  delete hMassLambda;
  delete hMassLambdaBar;
  delete hMassXi;
  delete hMassOmega;

  delete esd;
  esdFile->Close();
  delete esdFile;

  runLoader->UnloadHeader();
  runLoader->UnloadKinematics();
  delete runLoader;

  // result of check
  Info("CheckESD", "check of ESD was successfull");
  return kTRUE;
}
Пример #24
0
void PlotPubHisto(TObjArray histograms,TEnv *params){
    // This is a modification of the AddHistos macro
    
    // Number of histos to plot:
    Int_t ntot = histograms.GetEntries();
    
    // Check we have what we expect (the order should be: data, qcd, wjets, etc...)
    for(Int_t i = 0; i<ntot; i++){
	if(histograms[i]==0) {
	    cout<<"Error in AddHistos: histogram "<<i<<" is a NULL pointer!"<<endl;
	    return;
	}
	TH1F * hthis = (TH1F*) histograms[i];
	// include the overflow/underflow bins:
	int numbins = hthis->GetNbinsX(); //this is the last bin plotted
	double hicontent = hthis->GetBinContent(numbins);
	double overflow  = hthis->GetBinContent(numbins+1);// this bin contains the overflow
	double locontent = hthis->GetBinContent(1);// this is the first bin plotted
	double underflow = hthis->GetBinContent(0);// this bin contains the underflow
	if (underflow>0 || overflow>0){
	    //printf("%-20s numbins=%4i hicontent=%4.2f over=%4.2f locontent=%4.2f underflow=%4.2f \n",
	    //	 title.Data(),numbins,hicontent,overflow,locontent,underflow);
	}
	hthis->SetBinContent(numbins,hicontent+overflow);
	hthis->SetBinContent(1,locontent+underflow);
    }
    
    // define a few additional line styles:
    gStyle->SetLineStyleString(5,"20 12 4 12");
    gStyle->SetLineStyleString(6,"20 12 4 12 4 12 4 12");
    gStyle->SetLineStyleString(7,"20 20");
    gStyle->SetLineStyleString(8,"20 12 4 12 4 12");
    gStyle->SetLineStyleString(9,"80 25");
    gStyle->SetLineStyleString(10,"50 10 10 10");
    gStyle->SetLineStyleString(17,"30 25");
    gStyle->SetLineStyleString(20,"60 20");
    gStyle->SetLineStyleString(21,"60 20 20 20");
    int lineStyle[20];
    for(int i=0;i<20;i++) {
	lineStyle[i]=i;
    }

    // the first histogram in the list:
    TH1F *h0=((TH1F*) histograms[0])->Clone();
    
    // histogram output filename
    TString oFileName=params->GetValue("Histo.Output.Filename","bogus.eps");
    
    // figure out the number of signals
    Int_t nsig=1;
    if(params->Defined("Histo.Signal.Title.1")) nsig=1;
    if(params->Defined("Histo.Signal.Title.2")) nsig=2;
    if(params->Defined("Histo.Signal.Title.3")) nsig=3;
    
    cout << " I will use nsig = " << nsig << " signal sources" << endl;
    
    // Do the cumulative summing, except for the data
    TObjArray addedhistos; addedhistos.Clear();
    TObjArray signalhistos; signalhistos.Clear();
    TString sampletitles[20];
    Int_t nbkg=0;
    for(Int_t i = 1; i<ntot; i++){// i runs over histograms[i], so data is for i=0
	ostringstream baseSrcName;
	baseSrcName << "Files." << i+1 << ".";// Counting starts at 1: Files.1.Name: Data
	TString bSrcName(baseSrcName.str().c_str());
	// skip some if we want to show them as lines
	TString htitle=params->GetValue(bSrcName+"Title","");
	sampletitles[i-1]=htitle;
	if(params->GetValue("Histo.ShowSignalSeparately",0)==1 &&
	   // skip the last two if the signal title is not defined:
	   ( ( !(params->Defined("Histo.Signal.Title")||params->Defined("Histo.Signal.Title.1")) && i>=ntot-nsig) 
	     // skip the signal if the signal title is defined
	     || params->GetValue("Histo.Signal.Title",".")==htitle
	     || params->GetValue("Histo.Signal.Title.1",".")==htitle
	     || params->GetValue("Histo.Signal.Title.2",".")==htitle
	     || params->GetValue("Histo.Signal.Title.3",".")==htitle
	     ) ) {
	    TH1F * hthis = (TH1F*) histograms[i]->Clone();
	    cout<<" Found signal in location "<<i+1<<" with name "<<htitle.Data()<<endl;
	    signalhistos.Add(hthis);
	} else {
	    TH1F * hthis = (TH1F*) histograms[i]->Clone();
	    addedhistos.Add(hthis); // Fill in the new TObjArray with a copy 
	    //cout << " Adding bkg " << i << " " << htitle.Data() << " " << hthis->Integral() << endl;
	    // add all of the backgrounds
	    if (i>1) {// i=0 is the data, and we must start with the second
		      // background to add the previous
		TH1F * hprevious = (TH1F*) addedhistos[i-2];
		if ( hthis->GetXaxis()->GetNbins() != hprevious->GetXaxis()->GetNbins() ) {
		    // Protection against _whoran histogram. 
		    // We cannot add two histograms with different numbers of bins!
		    cout<<"Error in AddHistos: incompatible number of bins!"<<endl;  
		    return;
		}
		hthis->Add(hprevious); // Do the addition
		addedhistos.RemoveAt(i-1); // And substitute whatever we had 
		addedhistos.AddAt(hthis,i-1);
		nbkg++;
		//cout << "Substituing bkg " << i << " + " << i-1 << " in addedhistos["<< i-1 <<"]" << endl;
	    }	    
	} // end of: if adding histograms
    }
    cout << " nbkg = " << nbkg << endl; 
    
    // Rebin histos if necessary, but first calculate KS:
    TH1F *hbkg = (TH1F*) addedhistos[nbkg];
    double KS = h0->KolmogorovTest(hbkg);
    double chi2ndf = h0->Chi2Test(hbkg, "UWUFOFCHI2/NDF");
    //cout << title.Data() << " KS = " << KS << " chi2/NDF = " << chi2ndf << endl;
    // Rebin? Set nrebin = 0 to NOT do rebinning. 
    // Will rebin only histos whose maximum x axis value exceeds 20. 
    // Anything with less will most probably be already made of integers, so no
    // need to rebin that! 
    Int_t nbinsx = h0->GetXaxis()->GetNbins();
    Int_t nbinsy = 100;
    Int_t nrebin = 5;
    if ( nbinsx > 750 && nbinsx <= 1000) nrebin = 30;
    if ( nbinsx > 400 && nbinsx <= 750 ) nrebin = 25;//20
    if ( nbinsx > 300 && nbinsx <= 400 ) nrebin = 25;//15
    if ( nbinsx > 200 && nbinsx <= 300 ) nrebin = 25;//15
    if ( nbinsx > 150 && nbinsx <= 200 ) nrebin = 10;//10
    if ( nbinsx > 100 && nbinsx <= 150 ) nrebin = 10;//10
    if ( nbinsx > 50 && nbinsx <= 100 )  nrebin = 10;//10
    if ( nbinsx > 20 && nbinsx <= 50 )   nrebin = 2;
    if ( nbinsx <= 20 ) nrebin = 1;  
    
    printf(" Saw nbins =%4i, rebinning by nrebin =%2i to final %3i bins \n",nbinsx,nrebin,int(nbinsx/nrebin));	

    if ( nrebin != 0 ) {
	h0->Rebin(nrebin); // data
	for (Int_t i = 0; i<=nbkg; i++){
	    TH1F * h = (TH1F*) addedhistos[i];
	    h->Rebin(nrebin);
	}
	for (Int_t i = 0; i<nsig; i++){
	    TH1F * h = (TH1F*) signalhistos[i];
	    h->Rebin(nrebin);
	}
    }

    // default text size: 0.045
    // make it bigger for the paper
    float textSize = 0.045;
    if(params->GetValue("Histo.Preliminary","yes")==TString("paper")) textSize=0.07;
    if(params->Defined("Histo.TextSize")) textSize=params->GetValue("Histo.TextSize",0.07);
    
    // Now, check largest dimensions so that we can plot all histograms at once.
    Float_t xmin=9999., xmax=-9999., ymin=9999., ymax=-9999.;
    for(Int_t i = 0; i<=nbkg; i++){
	TH1F * h = (TH1F*) addedhistos[i];
	ostringstream baseSrcName;
	baseSrcName << "Files." << i+1 << ".";
	TString bSrcName(baseSrcName.str().c_str());
	
	TAxis *axis = h->GetXaxis();
	if( axis->GetXmin() < xmin ) xmin = axis->GetXmin();
	if( axis->GetXmax() > xmax ) xmax = axis->GetXmax();
	if( h->GetMinimum() < ymin ) ymin = h->GetMinimum();
	if( h->GetMaximum() > ymax ) ymax = h->GetMaximum();
    }
    ymax = TMath::Nint(ymax*1.25+1); // Make enough room for the big legend
    TString title = h0->GetTitle();
    
    //
    // now check if we should simply use the ranges that was passed to us.
    if(params->Defined("Histo.Xmin")) xmin = params->GetValue("Histo.Xmin",0.);
    if(params->Defined("Histo.Xmax")) xmax = params->GetValue("Histo.Xmax",0.);
    if(params->Defined("Histo.Ymin")) ymin = params->GetValue("Histo.Ymin",0.);
    if(params->Defined("Histo.Ymax")) ymax = params->GetValue("Histo.Ymax",0.);
    
    // Now make the frame:
    TH2F * frame = new TH2F("frame","",nbinsx,xmin,xmax,nbinsy,ymin,ymax);
    cout<<" frame has xmin "<<xmin<<", xmax "<<xmax<<", ymax "<<ymax<<endl;
    
    // get the x- and y-axis titles
    TString ytitle=params->GetValue("Histo.YTitle","");
    if ( params->Defined("Histo.XTitle")) {
	frame->SetXTitle(params->GetValue("Histo.XTitle",""));
    } else {
	frame->SetXTitle(h0->GetTitle());
    }
    frame->SetYTitle(ytitle.Data()); 
    // also set the text size for the X and Y axis titles and numbers
    // do this globally for the style we are using
    float axisLabelSize=textSize;
    frame->GetXaxis()->SetLabelSize(axisLabelSize);
    frame->GetYaxis()->SetLabelSize(axisLabelSize);
    frame->GetXaxis()->SetTitleSize(axisLabelSize);
    frame->GetYaxis()->SetTitleSize(axisLabelSize);
    
    frame->SetStats(false);
    // reduce the axis title offset if the fonts are very large
    if(textSize>0.055) frame->GetXaxis()->SetTitleOffset(1.0);
    // also change the X axis title offset to move it farther away from the numbers
    if(params->Defined("Histo.XTitle.Offset")) {
	float xtitoffset=params->GetValue("Histo.XTitle.Offset",1.0);
	frame->GetXaxis()->SetTitleOffset(xtitoffset);
    }
    
    // also change the y axis title offset to move it farther away from the numbers
    frame->GetYaxis()->SetTitleOffset(1.0);
    // reduce the axis title offset if the fonts are very large
    if(textSize>0.055) frame->GetYaxis()->SetTitleOffset(1.0);
    
    // set the axes divisions
    frame->GetXaxis()->SetNdivisions(505,true);
    if(params->Defined("Histo.XNdivisions")) frame->GetXaxis()->SetNdivisions(params->GetValue("Histo.XNdivisions",505),kTRUE);
    if(params->Defined("Histo.YNdivisions")) frame->GetYaxis()->SetNdivisions(params->GetValue("Histo.YNdivisions",505),kTRUE);
    
    // make sure the X axis title and Y axis title are in black!
    frame->GetXaxis()->SetTitleColor(1);
    frame->GetYaxis()->SetTitleColor(1);

    // Could plot in log scale...
    //gPad->SetLogy();

    // finally: Draw
    frame->Draw();
    
    // Draw the background ones:
    for(Int_t i=nbkg; i>=0; i--){
	TH1F * h = (TH1F*) addedhistos[i];
	h->SetStats(kFALSE);
	
	ostringstream baseSrcName;
	baseSrcName << "Files." << i+2 << ".";// to account for the data which is Files.1
	TString bSrcName(baseSrcName.str().c_str());
	Int_t hcolor=params->GetValue(bSrcName+"Color",1); 	
	h->SetLineColor(1);      
	h->SetFillColor(hcolor);
        if (i==nbkg) printf(" Data Yield = %5.2f ; SumBkg = %5.2f ; Data-SumBkg diff = %5.2f%% \n",
	   		     h0->Integral(),h->Integral(),(h0->Integral()-h->Integral())*100./h0->Integral());
	printf(" plotting bkg i=%2i name=%20.20s file=%2i integral=%5.1f color=%2i\n",
	       i,sampletitles[i].Data(),i+2,h->Integral(),hcolor);
	int fillStyle=params->GetValue(bSrcName+"FillStyle",1001);
	h->SetFillStyle(fillStyle);
	h->DrawCopy("Hist,Same");
    }
    //
    // and draw the signal ones
    // draw them in reverse order so that the last one will be on top.
    //for(Int_t i=ntot-3; i<ntot; i++){
    for(Int_t i=nsig-1; i>=0; i--){
	ostringstream baseSrcName;
	baseSrcName << "Files." << ntot+1-nsig+i << ".";
	TString bSrcName(baseSrcName.str().c_str());
	
	Int_t hcolor=params->GetValue(bSrcName+"Color",1);
	TH1F * h = (TH1F*) signalhistos[i];
       	if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=90"))        h->Add (h, 1.07874865  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=100"))  h->Add (h, 1.62317373  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=110"))  h->Add (h, 2.31347600  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=120"))  h->Add (h, 3.25275183  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=130"))  h->Add (h, 4.54142919  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=140"))  h->Add (h, 6.19195046  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=150"))  h->Add (h, 8.38307290  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=160"))  h->Add (h, 11.31721008 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=170"))  h->Add (h, 14.85376469 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=180"))  h->Add (h, 19.54537459 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=190"))  h->Add (h, 25.44594010 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=200"))  h->Add (h, 32.94784356 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=220"))  h->Add (h, 54.09499080 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=240"))  h->Add (h, 86.85079034 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=260"))  h->Add (h, 136.31406761-1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=280"))  h->Add (h, 210.70375053-1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=300"))  h->Add (h, 319.79533099-1.000);
	
	printf(" plotting sig i=%2i name=%20.20s file=%2i integral=%5.1f color=%2i\n",
	       i,sampletitles[ntot-1-nsig+i].Data(),ntot+1-nsig+i,h->Integral(),hcolor);
	// create a white background around each line (helps readibility):
	TH1F *h1=h->Clone();
	h1->SetStats(kFALSE);
	h1->SetLineWidth(6);
	h1->SetLineColor(0);h1->SetFillColor(0);
	h1->SetLineStyle(1);
	h1->SetFillStyle(0);
	h1->Draw("HIST,SAME");
	// now draw the proper line:
	h->SetStats(kFALSE);
	h->SetLineWidth(6);
	h->SetLineColor(hcolor);h->SetFillColor(0);	
	Int_t hlinestyle = params->GetValue(bSrcName+"LineStyle",1);
	h->SetLineStyle(hlinestyle);
	h->SetFillStyle(0);	
	// finally, draw!
	h->Draw("HIST,SAME");      
    } // end of: drawing signal as separate lines
    
    // Data is special: 
    // change the default size of the little bar at the end of the error bar here
    gStyle->SetEndErrorSize(3);
    // also, maybe don't display the error bars along the X axis:
    //gStyle->SetErrorX(0);  // X error bars not displayed
    gStyle->SetErrorX(0.5);  // X error bars have width of a bin
    // now set the rest
    h0->SetMarkerSize(2);
    // if there are too many points (>80), keep the marker size smaller
    if(h0->GetNbinsX()>=50) h0->SetMarkerSize(1);
    //if(h0->GetNbinsX()>=100) h0->SetMarkerSize(1);
    h0->SetLineWidth(3);
    h0->SetMarkerStyle(8);
    h0->SetMarkerColor(1);
    h0->Draw("E1,SAME");
    
    // Print some comparison:
    //ostringstream basefactor;
    //basefactor << "Files." << nbkg+3 << "." << "Factor";
    //TString timesfactor(basefactor.str().c_str()); 
    //Double_t nprod = params->GetValue(timesfactor,1.000);
    //printf("Data Yield = %5.2f ; SumBkg = %5.2f ; SumBkg+Sig = %5.2f ; Data-SumBkg diff = %5.2f%% \n",
    //        h0->Integral(),hbkg2->Integral,(hbkg2->Integral()+(signalhistos[0]->Integral()/nprod),
    //        (h0->Integral()-hbkg2->Integral)*100./h0->Integral()));

    //
    // Print D0 and lumi:
    //
    TText *t1 = new TText();
    t1->SetTextFont(62);
    t1->SetTextColor(1);   
    t1->SetNDC();
    t1->SetTextAlign(12);
    t1->SetTextSize(textSize);
    TString prelim="D\328 Preliminary";
    if(oFileName.EndsWith(".eps")) {
	prelim="D\349 Preliminary L=3.7 fb^-1#";
    }
    else if(oFileName.EndsWith(".gif")) {
	prelim="D\328 Preliminary L=3.7 fb^-1#";
    }
    t1->DrawTextNDC(0.13,0.965,prelim.Data());

    // a counter of how much text we have added from the top
    int nAddTextLines=0;
    
    // any additional text?
    for(int iText=1;iText<20;iText++) {
	ostringstream baseTextName;
	baseTextName << "Histo.AddText." << iText;
	TString bTextName(baseTextName.str().c_str());
	if(params->Defined(bTextName)) {
	    // we are adding a line of text
	    TLatex *t2 = new TLatex();
	    t2->SetTextFont(62);
	    t2->SetTextColor(13);   
	    t2->SetTextAlign(32);
	    t2->SetNDC();
	    t2->SetTextSize(textSize);
	    TString addText(params->GetValue(bTextName,"."));
	    float x0=0.94;
	    float y0=0.96-(nAddTextLines)*0.05;
	    
	    // check if the user specified an alternative location for the text
	    if(params->Defined(bTextName+".X0")) x0=params->GetValue(bTextName+".X0",0.94);
	    if(params->Defined(bTextName+".Y0")) y0=params->GetValue(bTextName+".Y0",0.8);
	    if(params->Defined(bTextName+".TextSize")) t2->SetTextSize(params->GetValue(bTextName+".TextSize",textSize));
	    
	    // and increment the counter keeping track of how much we added,
	    // but only if the user didn't move the label around.
	    if(!params->Defined(bTextName+".X0")) nAddTextLines++;
	    printf("AddText %4.2f %4.2f %s\n",x0,y0,addText.Data());
	    
	    t2->DrawLatex(x0,y0,addText.Data()); 
	}
    }// end additional text
    
    // now draw the frame axis again so that we can see the tick marks
    frame->Draw("sameaxis");
    
    // Legend:
    TString showLegend(params->GetValue("Histo.ShowLegend","."));
    if( showLegend != "no" ){ 
	float lgdxmin=.65, lgdxmax=.90, lgdymin=.50, lgdymax=.91;
	if(showLegend=="yes" || showLegend=="right") {
	    
	} else if (showLegend=="left"){
	    lgdxmin=.16;
	    lgdxmax=.42;
	}
	TLegend *lgd = new TLegend(lgdxmin,lgdymin,lgdxmax,lgdymax); 
	// This line makes the legend transparent (not grey, ewwww!): 
	lgd->SetBorderSize(0); lgd->SetTextSize(textSize*0.9);// 10% less size 
	lgd->SetTextFont(62); lgd->SetFillColor(0);
	// Plot the legend in reverse order (but data goes first):
	NiceAddEntry(lgd,h0,params->GetValue("Files.1.Title","Data"),"PL");
	for(Int_t i = nbkg; i>=0; i--){
	    TH1F * h = (TH1F*) addedhistos[i];
	    TString lgd_entry= sampletitles[i]; // sampletitles runs from 0 (firstbkg) to ntot-1
	    NiceAddEntry(lgd,h,lgd_entry.Data(),"F");	
	}
	for(Int_t i = nsig-1; i>=0; i--){
	    TH1F * h = (TH1F*) signalhistos[i];
	    TString lgd_entry = sampletitles[i+nbkg+1]; // sampletitles runs from 0 (firstbkg) to ntot-1
	    ostringstream basefactor;
	    basefactor << "Files." << i+nbkg+3 << "." << "Factor";
	    TString timesfactor(basefactor.str().c_str());
	    Double_t nprod = params->GetValue(timesfactor,1.000);
	    if (nprod != 1.0 ) lgd_entry.Form("%s x%2.0f",lgd_entry.Data(),nprod);
	    //cout << i+nbkg+3 << " " << nprod << " " << lgd_entry.Data() << endl;
	    NiceAddEntry(lgd,h,lgd_entry.Data(),"L"); 
	}
	lgd->Draw("SAME");	
    }// show legend


    // Draw the KS:
    TLatex *ks = new TLatex();
    ks->SetTextFont(62);
    ks->SetTextColor(1);   
    TString ks_val = Form("KS = %3.2f",KS);
    ks->SetTextAlign(11); ks->SetTextSize(0.03); // ks->SetTextAngle(90); 
    ks->DrawTextNDC(0.83,0.93,ks_val.Data());
    TString chi2_val = Form("#chi^{2}/ndf = %3.1f",chi2ndf);
    ks->SetNDC(true); ks->DrawLatex(0.83,0.97,chi2_val.Data());
    //
    // Voila!
    //
}
void plotSystFracs(TList* HistList, TH1F* compT, std::string name){

  gROOT->SetBatch();
  system("mkdir -p plots/ada/systs");
  system("mkdir -p plots/grad/systs");

  std::string bdt;
  TString str = compT->GetName();
  if (str.Contains("ada")) bdt="ada";
  if (str.Contains("grad")) bdt="grad";

  int nHists=HistList->GetEntries();
  TH1F *comp = linearBin(compT);
  
  gROOT->SetStyle("Plain");
  gROOT->ForceStyle();
  gStyle->SetOptStat(0);
  TCanvas *canv = new TCanvas("","",700,700);
  
  TLegend *leg = new TLegend(0.6,0.6,0.88,0.88);
  leg->SetLineColor(0);
  leg->SetFillColor(0);
  
  TF1 *line = new TF1("line","0.0",0.,comp->GetBinLowEdge(comp->GetNbinsX()+1));
  line->SetLineColor(kBlack);
  TF1 *line1 = new TF1("line","10.0",0.,comp->GetBinLowEdge(comp->GetNbinsX()+1));
  line1->SetLineColor(kGray+2);
  line1->SetLineStyle(2);
  TF1 *line2 = new TF1("line","-10.0",0.,comp->GetBinLowEdge(comp->GetNbinsX()+1));
  line2->SetLineColor(kGray+2);
  line2->SetLineStyle(2);
  
  int colors[10] = {kBlue,kMagenta,kGreen,kCyan,kRed,kBlue+3,kOrange+1,kSpring-1,kMagenta+3,kGreen+3};
  int color=0;
  for (int i=0; i<nHists; i++){
    TH1F *systHist = linearBin((TH1F*)HistList->At(i));
    systHist->Add(comp,-1);
    systHist->Divide(comp);
    systHist->Scale(100.);
    std::string systStr = systHist->GetName();
    int ind = systStr.rfind("cat0");
    std::string systName = systStr.substr(ind+5,systStr.size());
    systHist->SetLineColor(colors[color]);
    systHist->SetTitle(Form("%s",name.c_str()));
    systHist->GetYaxis()->SetTitle("Difference over nominal %");
    systHist->GetYaxis()->SetTitleOffset(1.4);
    systHist->GetXaxis()->SetTitle("BDT output");
    systHist->GetYaxis()->SetRangeUser(-100.,250);
    if (int(systName.find("Up"))>0){
      systHist->SetLineStyle(1);
      systName = systName.substr(0,systName.rfind("Up"));
      leg->AddEntry(systHist,systName.c_str(),"l");
      color++;
    }
    else if (int(systName.find("Down"))>0){
      systHist->SetLineStyle(2);
      systName = systName.substr(0,systName.rfind("Down"));
    }
    if (i==0) systHist->DrawCopy("hist");
    else systHist->DrawCopy("same hist");
  }
  leg->Draw("same");
  line->Draw("same");
  line1->Draw("same");
  line2->Draw("same");
  canv->Print(("plots/"+bdt+"/systs/"+name+".png").c_str(),"png");
  
  delete canv;
  
  systCalls++;
  
}
Пример #26
0
   void constrained_scan( const char* wsfile = "outputfiles/ws.root",
                          const char* new_poi_name="mu_bg_4b_msig_met1",
                          double constraintWidth=1.5,
                          int npoiPoints = 20,
                          double poiMinVal = 0.,
                          double poiMaxVal = 10.0,
                          double ymax = 9.,
                          int verbLevel=1  ) {

      TString outputdir("outputfiles") ;

      gStyle->SetOptStat(0) ;

      TFile* wstf = new TFile( wsfile ) ;
      RooWorkspace* ws = dynamic_cast<RooWorkspace*>( wstf->Get("ws") );
      ws->Print() ;

      RooDataSet* rds = (RooDataSet*) ws->obj( "hbb_observed_rds" ) ;
      cout << "\n\n\n  ===== RooDataSet ====================\n\n" << endl ;
      rds->Print() ;
      rds->printMultiline(cout, 1, kTRUE, "") ;

      RooRealVar* rv_sig_strength = ws->var("sig_strength") ;
      if ( rv_sig_strength == 0x0 ) { printf("\n\n *** can't find sig_strength in workspace.\n\n" ) ; return ; }

      RooAbsPdf* likelihood = ws->pdf("likelihood") ;
      if ( likelihood == 0x0 ) { printf("\n\n *** can't find likelihood in workspace.\n\n" ) ; return ; }
      printf("\n\n Likelihood:\n") ;
      likelihood -> Print() ;



      /////rv_sig_strength -> setConstant( kFALSE ) ;
      rv_sig_strength -> setVal(0.) ;
      rv_sig_strength -> setConstant( kTRUE ) ;

      likelihood->fitTo( *rds, Save(false), PrintLevel(0), Hesse(true), Strategy(1) ) ;
      //RooFitResult* fitResult = likelihood->fitTo( *rds, Save(true), PrintLevel(0), Hesse(true), Strategy(1) ) ;
      //double minNllSusyFloat = fitResult->minNll() ;
      //double susy_ss_atMinNll = rv_sig_strength -> getVal() ;

      RooMsgService::instance().getStream(1).removeTopic(Minimization) ;
      RooMsgService::instance().getStream(1).removeTopic(Fitting) ;



     //-- Construct the new POI parameter.
      RooAbsReal* new_poi_rar(0x0) ;

      new_poi_rar = ws->var( new_poi_name ) ;
      if ( new_poi_rar == 0x0 ) {
         printf("\n\n New POI %s is not a variable.  Trying function.\n\n", new_poi_name ) ;
         new_poi_rar = ws->function( new_poi_name ) ;
         if ( new_poi_rar == 0x0 ) {
            printf("\n\n New POI %s is not a function.  I quit.\n\n", new_poi_name ) ;
            return ;
         } else {
            printf("\n Found it.\n\n") ;
         }
      } else {
         printf("\n\n     New POI %s is a variable with current value %.1f.\n\n", new_poi_name, new_poi_rar->getVal() ) ;
      }

       double startPoiVal = new_poi_rar->getVal() ;


       RooAbsReal* nll = likelihood -> createNLL( *rds, Verbose(true) ) ;

       RooRealVar* rrv_poiValue = new RooRealVar( "poiValue", "poiValue", 0., -10000., 10000. ) ;

       RooRealVar* rrv_constraintWidth = new RooRealVar("constraintWidth","constraintWidth", 0.1, 0.1, 1000. ) ;
       rrv_constraintWidth -> setVal( constraintWidth ) ;
       rrv_constraintWidth -> setConstant(kTRUE) ;


       RooMinuit* rminuit( 0x0 ) ;


       RooMinuit* rminuit_uc = new RooMinuit( *nll  ) ;

       rminuit_uc->setPrintLevel(verbLevel-1) ;
       rminuit_uc->setNoWarn() ;

       rminuit_uc->migrad() ;
       rminuit_uc->hesse() ;

       RooFitResult* rfr_uc = rminuit_uc->fit("mr") ;

       double floatParInitVal[10000] ;
       char   floatParName[10000][100] ;
       int nFloatParInitVal(0) ;
       RooArgList ral_floats = rfr_uc->floatParsFinal() ;
       TIterator* floatParIter = ral_floats.createIterator() ;
       {
          RooRealVar* par ;
          while ( (par = (RooRealVar*) floatParIter->Next()) ) {
             sprintf( floatParName[nFloatParInitVal], "%s", par->GetName() ) ;
             floatParInitVal[nFloatParInitVal] = par->getVal() ;
             nFloatParInitVal++ ;
          }
       }


       printf("\n\n Unbiased best value for new POI %s is : %7.1f\n\n", new_poi_rar->GetName(), new_poi_rar->getVal() ) ;
       double best_poi_val = new_poi_rar->getVal() ;

       char minuit_formula[10000] ;
       sprintf( minuit_formula, "%s+%s*(%s-%s)*(%s-%s)",
         nll->GetName(),
         rrv_constraintWidth->GetName(),
         new_poi_rar->GetName(), rrv_poiValue->GetName(),
         new_poi_rar->GetName(), rrv_poiValue->GetName()
          ) ;

       printf("\n\n Creating new minuit variable with formula: %s\n\n", minuit_formula ) ;
       RooFormulaVar* new_minuit_var = new RooFormulaVar("new_minuit_var", minuit_formula,
           RooArgList( *nll,
                       *rrv_constraintWidth,
                       *new_poi_rar, *rrv_poiValue,
                       *new_poi_rar, *rrv_poiValue
                       ) ) ;

       printf("\n\n Current value is %.2f\n\n",
            new_minuit_var->getVal() ) ;

       rminuit = new RooMinuit( *new_minuit_var ) ;


       RooAbsReal* plot_var = nll ;

       printf("\n\n Current value is %.2f\n\n",
            plot_var->getVal() ) ;


       rminuit->setPrintLevel(verbLevel-1) ;
       if ( verbLevel <=0 ) { rminuit->setNoWarn() ; }


       if ( poiMinVal < 0. && poiMaxVal < 0. ) {

          printf("\n\n Automatic determination of scan range.\n\n") ;

          if ( startPoiVal <= 0. ) {
             printf("\n\n *** POI starting value zero or negative %g.  Quit.\n\n\n", startPoiVal ) ;
             return ;
          }

          poiMinVal = startPoiVal - 3.5 * sqrt(startPoiVal) ;
          poiMaxVal = startPoiVal + 6.0 * sqrt(startPoiVal) ;

          if ( poiMinVal < 0. ) { poiMinVal = 0. ; }

          printf("    Start val = %g.   Scan range:   %g  to  %g\n\n", startPoiVal, poiMinVal, poiMaxVal ) ;


       }



    //----------------------------------------------------------------------------------------------


       double poiVals_scanDown[1000] ;
       double nllVals_scanDown[1000] ;

       //-- Do scan down from best value.

       printf("\n\n +++++ Starting scan down from best value.\n\n") ;

       double minNllVal(1.e9) ;

       for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) {

          ////double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*(npoiPoints-1)) ;
          double poiValue = best_poi_val - poivi*(best_poi_val-poiMinVal)/(1.*(npoiPoints/2-1)) ;

          rrv_poiValue -> setVal( poiValue ) ;
          rrv_poiValue -> setConstant( kTRUE ) ;


       //+++++++++++++++++++++++++++++++++++

          rminuit->migrad() ;
          rminuit->hesse() ;
          RooFitResult* rfr = rminuit->save() ;

       //+++++++++++++++++++++++++++++++++++


          if ( verbLevel > 0 ) { rfr->Print("v") ; }


          float fit_minuit_var_val = rfr->minNll() ;

          printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI :    %.5f   %.5f   %.5f   %.5f\n",
                poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ;
          cout << flush ;



          poiVals_scanDown[poivi] = new_poi_rar->getVal() ;
          nllVals_scanDown[poivi] = plot_var->getVal() ;

          if ( nllVals_scanDown[poivi] < minNllVal ) { minNllVal = nllVals_scanDown[poivi] ; }

          delete rfr ;


       } // poivi


       printf("\n\n +++++ Resetting floats to best fit values.\n\n") ;

       for ( int pi=0; pi<nFloatParInitVal; pi++ ) {
          RooRealVar* par = ws->var( floatParName[pi] ) ;
          par->setVal( floatParInitVal[pi] ) ;
       } // pi.

       printf("\n\n +++++ Starting scan up from best value.\n\n") ;

      //-- Now do scan up.

       double poiVals_scanUp[1000] ;
       double nllVals_scanUp[1000] ;

       for ( int poivi=0; poivi < npoiPoints/2 ; poivi++ ) {

          double poiValue = best_poi_val + poivi*(poiMaxVal-best_poi_val)/(1.*(npoiPoints/2-1)) ;

          rrv_poiValue -> setVal( poiValue ) ;
          rrv_poiValue -> setConstant( kTRUE ) ;


       //+++++++++++++++++++++++++++++++++++

          rminuit->migrad() ;
          rminuit->hesse() ;
          RooFitResult* rfr = rminuit->save() ;

       //+++++++++++++++++++++++++++++++++++


          if ( verbLevel > 0 ) { rfr->Print("v") ; }


          float fit_minuit_var_val = rfr->minNll() ;

          printf(" %02d : poi constraint = %.2f : allvars : MinuitVar, createNLL, PV, POI :    %.5f   %.5f   %.5f   %.5f\n",
                poivi, rrv_poiValue->getVal(), fit_minuit_var_val, nll->getVal(), plot_var->getVal(), new_poi_rar->getVal() ) ;
          cout << flush ;

          poiVals_scanUp[poivi] = new_poi_rar->getVal() ;
          nllVals_scanUp[poivi] = plot_var->getVal() ;

          if ( nllVals_scanUp[poivi] < minNllVal ) { minNllVal = nllVals_scanUp[poivi] ; }

          delete rfr ;


       } // poivi





       double poiVals[1000] ;
       double nllVals[1000] ;

       int pointCount(0) ;
       for ( int pi=0; pi<npoiPoints/2; pi++ ) {
          poiVals[pi] = poiVals_scanDown[(npoiPoints/2-1)-pi] ;
          nllVals[pi] = nllVals_scanDown[(npoiPoints/2-1)-pi] ;
          pointCount++ ;
       }
       for ( int pi=1; pi<npoiPoints/2; pi++ ) {
          poiVals[pointCount] = poiVals_scanUp[pi] ;
          nllVals[pointCount] = nllVals_scanUp[pi] ;
          pointCount++ ;
       }
       npoiPoints = pointCount ;

       printf("\n\n --- TGraph arrays:\n") ;
       for ( int i=0; i<npoiPoints; i++ ) {
          printf("  %2d : poi = %6.1f, nll = %g\n", i, poiVals[i], nllVals[i] ) ;
       }
       printf("\n\n") ;

       double nllDiffVals[1000] ;

       double poiAtMinlnL(-1.) ;
       double poiAtMinusDelta2(-1.) ;
       double poiAtPlusDelta2(-1.) ;
       for ( int poivi=0; poivi < npoiPoints ; poivi++ ) {
          nllDiffVals[poivi] = 2.*(nllVals[poivi] - minNllVal) ;
          double poiValue = poiMinVal + poivi*(poiMaxVal-poiMinVal)/(1.*npoiPoints) ;
          if ( nllDiffVals[poivi] < 0.01 ) { poiAtMinlnL = poiValue ; }
          if ( poiAtMinusDelta2 < 0. && nllDiffVals[poivi] < 2.5 ) { poiAtMinusDelta2 = poiValue ; }
          if ( poiAtMinlnL > 0. && poiAtPlusDelta2 < 0. && nllDiffVals[poivi] > 2.0 ) { poiAtPlusDelta2 = poiValue ; }
       } // poivi

       printf("\n\n Estimates for poi at delta ln L = -2, 0, +2:  %g ,   %g ,   %g\n\n", poiAtMinusDelta2, poiAtMinlnL, poiAtPlusDelta2 ) ;




      //--- Main canvas

       TCanvas* cscan = (TCanvas*) gDirectory->FindObject("cscan") ;
       if ( cscan == 0x0 ) {
          printf("\n Creating canvas.\n\n") ;
          cscan = new TCanvas("cscan","Delta nll") ;
       }


       char gname[1000] ;

       TGraph* graph = new TGraph( npoiPoints, poiVals, nllDiffVals ) ;
       sprintf( gname, "scan_%s", new_poi_name ) ;
       graph->SetName( gname ) ;

       double poiBest(-1.) ;
       double poiMinus1stdv(-1.) ;
       double poiPlus1stdv(-1.) ;
       double poiMinus2stdv(-1.) ;
       double poiPlus2stdv(-1.) ;
       double twoDeltalnLMin(1e9) ;

       int nscan(1000) ;
       for ( int xi=0; xi<nscan; xi++ ) {

          double x = poiVals[0] + xi*(poiVals[npoiPoints-1]-poiVals[0])/(nscan-1) ;

          double twoDeltalnL = graph -> Eval( x, 0, "S" ) ;

          if ( poiMinus1stdv < 0. && twoDeltalnL < 1.0 ) { poiMinus1stdv = x ; printf(" set m1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}
          if ( poiMinus2stdv < 0. && twoDeltalnL < 4.0 ) { poiMinus2stdv = x ; printf(" set m2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}
          if ( twoDeltalnL < twoDeltalnLMin ) { poiBest = x ; twoDeltalnLMin = twoDeltalnL ; }
          if ( twoDeltalnLMin < 0.3 && poiPlus1stdv < 0. && twoDeltalnL > 1.0 ) { poiPlus1stdv = x ; printf(" set p1 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}
          if ( twoDeltalnLMin < 0.3 && poiPlus2stdv < 0. && twoDeltalnL > 4.0 ) { poiPlus2stdv = x ; printf(" set p2 : %d, x=%g, 2dnll=%g\n", xi, x, twoDeltalnL) ;}

          if ( xi%100 == 0 ) { printf( " %4d : poi=%6.2f,  2DeltalnL = %6.2f\n", xi, x, twoDeltalnL ) ; }

       }
       printf("\n\n POI estimate :  %g  +%g  -%g    [%g,%g],   two sigma errors: +%g  -%g   [%g,%g]\n\n",
               poiBest,
               (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), poiMinus1stdv, poiPlus1stdv,
               (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv), poiMinus2stdv, poiPlus2stdv
               ) ;

       printf(" %s val,pm1sig,pm2sig: %7.2f  %7.2f  %7.2f  %7.2f  %7.2f\n",
          new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv), (poiPlus2stdv-poiBest), (poiBest-poiMinus2stdv) ) ;

       char htitle[1000] ;
       sprintf(htitle, "%s profile likelihood scan: -2ln(L/Lm)", new_poi_name ) ;
       TH1F* hscan = new TH1F("hscan", htitle, 10, poiMinVal, poiMaxVal ) ;
       hscan->SetMinimum(0.) ;
       hscan->SetMaximum(ymax) ;


       hscan->DrawCopy() ;
       graph->SetLineColor(4) ;
       graph->SetLineWidth(3) ;
       graph->Draw("CP") ;
       gPad->SetGridx(1) ;
       gPad->SetGridy(1) ;
       cscan->Update() ;

       TLine* line = new TLine() ;
       line->SetLineColor(2) ;
       line->DrawLine(poiMinVal, 1., poiPlus1stdv, 1.) ;
       line->DrawLine(poiMinus1stdv,0., poiMinus1stdv, 1.) ;
       line->DrawLine(poiPlus1stdv ,0., poiPlus1stdv , 1.) ;

       TText* text = new TText() ;
       text->SetTextSize(0.04) ;
       char tstring[1000] ;

       sprintf( tstring, "%s = %.1f +%.1f -%.1f", new_poi_name, poiBest, (poiPlus1stdv-poiBest), (poiBest-poiMinus1stdv) ) ;
       text -> DrawTextNDC( 0.15, 0.85, tstring ) ;

       sprintf( tstring, "68%% interval [%.1f,  %.1f]", poiMinus1stdv, poiPlus1stdv ) ;
       text -> DrawTextNDC( 0.15, 0.78, tstring ) ;


       char hname[1000] ;
       sprintf( hname, "hscanout_%s", new_poi_name ) ;
       TH1F* hsout = new TH1F( hname,"scan results",4,0.,4.) ;
       double obsVal(-1.) ;
       hsout->SetBinContent(1, obsVal ) ;
       hsout->SetBinContent(2, poiPlus1stdv ) ;
       hsout->SetBinContent(3, poiBest ) ;
       hsout->SetBinContent(4, poiMinus1stdv ) ;
       TAxis* xaxis = hsout->GetXaxis() ;
       xaxis->SetBinLabel(1,"Observed val.") ;
       xaxis->SetBinLabel(2,"Model+1sd") ;
       xaxis->SetBinLabel(3,"Model") ;
       xaxis->SetBinLabel(4,"Model-1sd") ;

       char outrootfile[10000] ;
       sprintf( outrootfile, "%s/scan-ff-%s.root", outputdir.Data(), new_poi_name ) ;

       char outpdffile[10000] ;
       sprintf( outpdffile, "%s/scan-ff-%s.pdf", outputdir.Data(), new_poi_name ) ;

       cscan->Update() ; cscan->Draw() ;

       printf("\n Saving %s\n", outpdffile ) ;
       cscan->SaveAs( outpdffile ) ;



     //--- save in root file

       printf("\n Saving %s\n", outrootfile ) ;
       TFile fout(outrootfile,"recreate") ;
       graph->Write() ;
       hsout->Write() ;
       fout.Close() ;

       delete ws ;
       wstf->Close() ;




   } // constrained_scan.
//void pi0_mfitpeak(char *FileName, char *HistName, Int_t etapi0flag) 
void pi0_mfitpeak(TH1F *mh1, Int_t etapi0flag, float xmin, float xmax, int npol,float res[],int posFlag, const char *dirName, const char *histName, float text_x, float text_y, const char *texName) 
  
{
  TGaxis::SetMaxDigits(3);


  // TVirtualFitter::SetDefaultFitter("Minuit");
  


  // This script attempts to fit any pi0 peak so that the freaking fit function would converge
  // currently background is fitted to a pol4 function and the peak by a gaussian;
  // results are not very nice
  // usage  .x pi0_mfitpeak.C++ ("pi0calib.root","minv_spb")
  // or eg.  .x pi0_mfitpeak.C ("../pi0anal/pi0ana_punorm.root","minv_spb",0)

  gROOT->Reset();
  //  gStyle->SetOptFit();
  //  gStyle->SetOptFit(0);
  //  gStyle->SetOptStat(0);
  //  gStyle->SetOptTitle(0);
Bool_t NOTE=1;
  if(NOTE) gStyle->SetCanvasBorderMode(0);

  gStyle->SetPadTopMargin(0.08);
  gStyle->SetPadBottomMargin(0.12);
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadRightMargin(0.08);

  mh1->GetXaxis()->SetRangeUser(xmin,xmax);
  
  Int_t highx=500;
  TCanvas *c2 = new TCanvas("c2","",200,10,highx,500);


    // cout<<FileName<<" "<<HistName<<endl;

  //     TFile f(FileName);
  //   TH1F *mh1 = (TH1F*) f.Get(HistName);
      mh1->SetMarkerStyle(20);
      mh1->SetMarkerSize(1.);
      mh1->SetStats(0); // 1/0 to set the stat box

   mh1->GetXaxis()->SetTitle("Invariant Mass of Photon Pairs (GeV/c^{2})");


   float binwidth = mh1->GetBinWidth(1);
   
   char *ytitle = new char[100];

   sprintf(ytitle,"Photon Pairs / %4.3f GeV/c^{2}",binwidth);
   

   mh1->GetYaxis()->SetTitle(ytitle);


   mh1->GetXaxis()->SetTitleSize(0.055);
   mh1->GetYaxis()->SetTitleSize(0.055);
   mh1->GetXaxis()->SetLabelSize(0.045);
   mh1->GetYaxis()->SetLabelSize(0.045);
   mh1->GetXaxis()->SetTitleOffset(0.90);
   mh1->GetXaxis()->CenterTitle();
   mh1->GetYaxis()->SetTitleOffset(1.32);
   

   // First work with the histogram and find the peak and fit ranges
   TAxis *xaxis = mh1->GetXaxis();
   Float_t binsiz= xaxis->GetBinCenter(3) - xaxis->GetBinCenter(2);
   Int_t nbins = xaxis->GetNbins(); 
   Float_t nevtperbin0[10000];
   Float_t errorbin0[10000];
   Float_t nevttot;
   Float_t maxbin=0; Int_t nmaxbin=0, nminbord=0, nmaxbord=nbins;
   
   for (Int_t nn=1; nn <= nbins; nn++)
     {
       nevtperbin0[nn] = mh1->GetBinContent(nn); 
       if(nevtperbin0[nn] > maxbin) { maxbin=nevtperbin0[nn]; nmaxbin=nn; }
       errorbin0[nn] = mh1->GetBinError(nn); 
       nevttot+=nevtperbin0[nn];
       if(nevtperbin0[nn] > 0 && nminbord == 0) nminbord=nn; 
       if(nevtperbin0[nn] == 0 && (nn > nminbord +10) && nmaxbord==0 && nminbord > 0) nmaxbord=nn; 
     }
   cout<<"Minbordl "<<nminbord<<" with events: "<<nevtperbin0[nminbord]<<endl;
   cout<<"Maxbordl "<<nmaxbord<<" with events: "<<nevtperbin0[nmaxbord]<<endl;
   nminbord+=0;
   nmaxbord-=0;
   Int_t nmin0=nminbord;
   while(nevtperbin0[nminbord] < nevtperbin0[nmaxbin]*0.025) nminbord++;
   while(nevtperbin0[nmaxbord] < nevtperbin0[nmaxbin]*0.025) nmaxbord--;
   // the above was just to get the info and low/high bins

   // Set the fit range ! This is for total fit !	 
   Float_t fitl=xmin;
     float fith=xmax;
   //     Float_t fitl=0.07, fith=0.2;// this works better for pileup
   //         Float_t fitl=0.08, fith=0.18;// this works even better for pileup
     //  if(etapi0flag == 1)
     // {
     //  fitl=0.35; fith=0.75;
     //}
     

     //   if(fitl < xaxis->GetBinCenter(nmin0)) fitl = xaxis->GetBinCenter(nmin0);
   //if(fith > xaxis->GetBinCenter(nmaxbord)) fith = xaxis->GetBinCenter(nmaxbord);
 
   


   cout<<" fit range "<<fitl<<" -- "<<fith<<endl;

   cout <<"Bin size "<<binsiz<<endl;
   cout<<"Total events "<<nevttot<<endl;
   cout<<"MaxBin "<<nmaxbin<<" with events: "<<nevtperbin0[nmaxbin]<<endl;
   cout<<"Minbord "<<nminbord<<" with events: "<<nevtperbin0[nminbord]<<endl;
   cout<<"Maxbord "<<nmaxbord<<" with events: "<<nevtperbin0[nmaxbord]<<endl;
      mh1->DrawCopy("sep");

      Float_t lowgauss=0.135-4.*0.010;
      Float_t highgauss=0.135+4.*0.010;
      if(etapi0flag == 1)
	{
	  lowgauss=0.55-5.*0.025;
              highgauss=0.55+5.*0.025;
	}
      Int_t nlowgauss=Int_t((lowgauss-xaxis->GetBinCenter(1))/Float_t(binsiz)+0.5);
      Int_t nhighgauss=Int_t((highgauss-xaxis->GetBinCenter(1))/Float_t(binsiz)+0.5);
      cout <<xaxis->GetBinCenter(nlowgauss)<<" "<<xaxis->GetBinCenter(nhighgauss)<<endl;
   // now make the "background" histogram and fit it with p4
      Float_t lowvalgauss=nevtperbin0[nlowgauss];
      Float_t increm=(nevtperbin0[nhighgauss]-nevtperbin0[nlowgauss])/Float_t(nhighgauss-nlowgauss);
      TH1F *hbkg = (TH1F*)mh1->Clone();
      hbkg->SetName("bkg_clone");
      for (Int_t nn=nlowgauss; nn<=nhighgauss; nn++)
	{
	  hbkg->SetBinContent(nn,Float_t(lowvalgauss+(nn-nlowgauss)*increm));
	  hbkg->SetBinError(nn,sqrt(lowvalgauss+(nn-nlowgauss)*increm));
	}
      hbkg->DrawCopy("samesep");
      //      break;
      // Now define the "gaussian" histogram
      TH1F *hgauss = (TH1F*)mh1->Clone();
      hgauss->SetName("gauss_clone");
      hgauss->Sumw2();
      hgauss->Add(mh1,hbkg,1,-1); // if errors are independent Add needs to be used !
       for (Int_t nn=1; nn <= nbins; nn++)
	 {
	   if(hgauss->GetBinContent(nn) < 0.) hgauss->SetBinContent(nn,0.001*nevtperbin0[nmaxbin]);
	   hgauss->SetBinError(nn,sqrt(hgauss->GetBinContent(nn)));
	 }

   // Declare function with wich to fit
       TF1 *g1 = new TF1("g1","gaus",lowgauss,highgauss);
   hgauss->Fit(g1,"R0");
   hgauss->DrawCopy("sep");
   g1->Draw("same");
   //  break;

   char *polff = new char[20];

   sprintf(polff,"pol%d",npol);
   
   TF1 *p4bkg; 
   if(etapi0flag != 1)
     p4bkg   = new TF1("pm2",polff, xaxis->GetBinCenter(nminbord),xaxis->GetBinCenter(nmaxbord));
   else
     p4bkg   = new TF1("pm2",polff, 0.35,0.75);
   
   

   hbkg->Fit(p4bkg,"R0");
   hbkg->DrawCopy("sep");
   p4bkg->SetLineStyle(kDashed);
   p4bkg->Draw("same");
   // break;
   
   
   Double_t par[20],parf[20],errparf[20];
   g1->GetParameters(&par[0]);
   p4bkg->GetParameters(&par[3]);

   char *totff = new char[20];
   
   sprintf(totff,"gaus(0)+pol%d(3)",npol);
   
   
   TF1 *total = new TF1("total",totff,fitl,fith);
   TF1 *p4bkgfin   = new TF1("pm2",polff,fitl,fith);
   total->SetParameters(par);

   if(etapi0flag==0){
     total->SetParLimits(1,0.10,0.15);
     total->SetParLimits(2,0.135*0.06,0.135*0.3);
     
   }else{
     total->SetParLimits(1,0.35,0.65);
   }
   
   
   //  total->FixParameter(1,1.21340e-01); 
   // total->FixParameter(2,2.69780e-02);
   
   
   

   

   mh1->Fit(total,"R0");
   
   cout<<" yield.. "<< total->GetParameter(0) <<"+/- " << total->GetParError(0)<<endl;
   

     total->GetParameters(parf);


     for( Int_t nn=0; nn < 3+npol+1; nn++) errparf[nn]=total->GetParError(nn);
     g1->SetParameters(&parf[0]);
     p4bkgfin->SetParameters(&parf[3]);
     cout <<" Piz Mass = "<<parf[1]*1000.<<" +- "<<errparf[1]*1000.<<
       " Sigma ="<<parf[2]*1000.<<" +- "<<errparf[2]*1000.<<endl;
      cout << " Sigma Rel. = "<< parf[2]/parf[1]<<" +- "
	   << errparf[2]/parf[1] <<endl;

    Float_t int_min=parf[1]-3.*parf[2];
    Float_t int_max=parf[1]+3.*parf[2];
    Float_t sig_peak=g1->Integral(int_min,int_max)/binsiz;
    Float_t bkgd_peak=p4bkgfin->Integral(int_min,int_max)/binsiz;
    cout<<" In +-3. sigma window: Signal="<<sig_peak<<" Bkgd="<<bkgd_peak<<endl;
    Float_t SB=sig_peak/bkgd_peak; Float_t SBerr=SB*(sqrt(1./sig_peak+1./bkgd_peak));
    cout<<" Signal/Bkgd "<<SB<<" +- "<<SBerr<<endl;   

    int_min=parf[1]-2.*parf[2];
    int_max=parf[1]+2.*parf[2];
    sig_peak=g1->Integral(int_min,int_max)/binsiz;
    bkgd_peak=p4bkgfin->Integral(int_min,int_max)/binsiz;
    cout<<" In +-2.sigma window: Signal="<<sig_peak<<" Bkgd="<<bkgd_peak<<endl;
    SB=sig_peak/bkgd_peak; SBerr=SB*(sqrt(1./sig_peak+1./bkgd_peak));
    cout<<" Signal/Bkgd "<<SB<<" +- "<<SBerr<<endl;   
 			

    float S = sig_peak; 
    float B = bkgd_peak; 
    
    int_min=parf[1]-20.*parf[2];
    int_max=parf[1]+20.*parf[2];
    float S_all = g1->Integral(int_min,int_max)/binsiz;
    
    

    float test_sall =  parf[0] * parf[2] * sqrt(acos(-1)) / binsiz; 
    
    cout<<"signal all: "<< S_all << " "<< test_sall <<endl; 
    
    float Serr_all = errparf[0]/ parf[0] * S_all; 
    


    res[0] = S_all; 
    res[1] = Serr_all; 

    res[2] = parf[1]; 
    res[3] = errparf[1];
    
    res[4] = parf[2]; 
    res[5] = errparf[2];

    res[6] = SB; 
    res[7] = SBerr; 
    


    total->SetLineWidth(3);
    
   total->SetLineColor(kBlue);

   p4bkgfin->SetLineWidth(3);
   
   p4bkgfin->SetLineColor(kRed);
   mh1->DrawCopy("sep");

   //   total->SetRange(0.07,0.185);
   //    p4bkgfin->SetRange(0.07,0.185);
   total->Draw("same");
   p4bkgfin->SetLineStyle(kDashed);
   p4bkgfin->Draw("same");   

   TLatex l;
   
   //   l.SetTextSize(0.06);
   l.SetTextSize(0.05);
   
   
   l.SetTextColor(1);
   l.SetNDC();
   
  
   float sigma = parf[2]/ parf[1]*100; 
   float sigmaerr = errparf[2]/ parf[1]*100; 
   char *sigma_name = new char[50]; 
   if(sigmaerr>0.005)
     sprintf(sigma_name,"#sigma = %3.2f #pm %3.2f %% ",sigma,sigmaerr);
   else sprintf(sigma_name,"#sigma = %3.2f %% ",sigma);
   
   if(posFlag==1){
     l.DrawLatex(0.54,0.75,sigma_name);
   }else if( posFlag==2){
     l.DrawLatex(0.54,0.3,sigma_name);

   }
      
      //  sprintf(sigma_name,"S/B = %3.2f #pm %3.2f ",SB,SBerr);
      //
      sprintf(sigma_name,"S = %2.1f #pm %2.1f",S_all,Serr_all);
	      //
      
      // l.DrawLatex(0.5,0.5,sigma_name);
      
      sprintf(sigma_name,"M = %3.1f #pm %3.1f MeV",parf[1]*1000.,errparf[1]*1000);
      if(posFlag==1){
      l.DrawLatex(0.54,0.82,sigma_name);
      }else if( posFlag==2){
	l.DrawLatex(0.54,0.37,sigma_name);

      }
      ///l.DrawLatex(0.169,470.,"d)");


      c2->Modified();
   c2->Update();
   //   c2->SaveAs("nice_pi0.gif");

   
   
   if( text_x >0 && text_y >0){
    TLatex *   tex = new TLatex(text_x, text_y, texName);
    tex->SetNDC();
    tex->SetTextSize(0.06);
    tex->SetLineWidth(2);
    tex->Draw();
  }
  

   char *filename = new char[1000];

   
   sprintf(filename,"%s/%s.gif",dirName,histName);
   c2->Print(filename);
   sprintf(filename,"%s/%s.C",dirName,histName);
   c2->Print(filename);
   
   // .x pi0_mfitpeak.C ("pi0ana_508030.root","minv_spb",0)
   // .x pi0_mfitpeak.C ("pi0ana_npu.root","minv_bkg",0)  
   // .x pi0_mfitpeak.C ("pi0ana_punormv2.root","minv_spb",0)
}
Пример #28
0
void CompareRawSpectrapPbPbp(int ieta)
{
  bool SavePlots=kTRUE;
  
  double EtaMin[8] = {-2.0, -1.5, -1.0, -0.5, 0.5, 1.0, 1.5, -1.0 };
  double EtaMax[8] = {-1.5, -1.0, -0.5,  0.5, 1.0, 1.5, 2.0,  1.0 };

  double RevEtaMin[8];
  double RevEtaMax[8];

  for(int j=0; j<8; j++)
  {
    RevEtaMin[j]=-EtaMax[j];
    RevEtaMax[j]=-EtaMin[j];
  }

//  int ieta=6; //0 to 7
 
  double StartPoint=50.;
  double EndPoint;

  if(TMath::Abs(EtaMin[ieta])==TMath::Abs(EtaMax[ieta]))  EndPoint = 430.;
  else if(ieta>0 && ieta<4 )         EndPoint = 300;
  else EndPoint = 250; 
  
 // TFile *f1 = new TFile(Form("/home/xuq/Documents/HI/RpA/output/UnfoldedOutputs/PPb_UnfoPriorGen_akPu3PFKurtForestEtaWeightNoIDCut_jtpt20_EtaBin%.f_%.f_Inc_v13.root",RevEtaMin[ieta]*10,RevEtaMax[ieta]*10));//PPb no residual unfolding
  TFile *f1 = new TFile(Form("/home/xuq/Documents/HI/RpA/output/UnfoldedOutputs/PPb_UnfoPriorGen_akPu3PFKurtMCNoIDCut_MC_jtpt20_EtaBin%.f_%.f_Inc_v8.root",RevEtaMin[ieta]*10,RevEtaMax[ieta]*10));//PPb no residual unfolding
  TFile *f2 = new TFile(Form("/home/xuq/Documents/HI/RpA/output/UnfoldedOutputs/PbP_UnfoPriorGen_akPu3PFKurtMCNoIDCut_MC_jtpt20_EtaBin%.f_%.f_Inc_v8.root",EtaMin[ieta]*10,EtaMax[ieta]*10));//PPb no residual unfolding

  
 TH1F *h1eta = (TH1F*)f1->Get(Form("hGen0"));
 TH1F *h2eta = (TH1F*)f2->Get(Form("hGen0"));



  double Lumi1 = 20.7*10E6;
  double Lumi2 = 14.0*10E6;
 
  TCanvas *c1 = new TCanvas("c1","c1",0,0,650,650);
  makeMultiPanelCanvas(c1,1,2,0.0,0.0,0.12,0.01,0.06);
  
  gStyle->SetOptStat(0);
  
  c1->cd(1)->SetLogy();
  
  TLegend *t1=new TLegend(0.35,0.75,0.8,0.93);
  t1->SetFillColor(0);
  t1->SetBorderSize(0);
  t1->SetFillStyle(0);
  t1->SetTextFont(63);
  t1->SetTextSize(17);

  TH1F *hDum =new TH1F("hdum","",50,StartPoint,EndPoint);
  hDum->SetMaximum(5.00E-3);
  hDum->SetMinimum(5.00E-10);
  hDum->GetYaxis()->SetTitle("d#sigma/dp_{T}");
  hDum->GetYaxis()->SetTitleSize(0.055);
  hDum->GetYaxis()->SetLabelSize(0.045);
  hDum->GetYaxis()->CenterTitle();
  
  hDum->DrawCopy();
//  h1eta->Scale(1./Lumi1);
//  h2eta->Scale(1./Lumi2);

  h1eta->GetXaxis()->SetRangeUser(StartPoint+5,EndPoint);
  h1eta->SetMarkerStyle(24);
  h1eta->SetMarkerColor(kBlue);
  h1eta->SetLineColor(kBlue);
  h1eta->SetMarkerSize(1.2);
 
  h2eta->GetXaxis()->SetRangeUser(StartPoint+5,EndPoint);
  h2eta->SetMarkerStyle(20);
  h2eta->SetMarkerColor(kRed);
  h2eta->SetLineColor(kRed);
  h2eta->SetMarkerSize(1.2);

  h1eta->DrawCopy("same");
  h2eta->DrawCopy("same");
  
  t1->AddEntry(h1eta,Form("PPb (%2.1f<#eta_{CM}<%2.1f)",EtaMin[ieta],EtaMax[ieta]),"P");
  t1->AddEntry(h2eta,Form("PbP (%2.1f<#eta_{CM}<%2.1f)",EtaMin[ieta],EtaMax[ieta]),"P");
 
  t1->Draw("same");
  c1->Update();


//-----------------------------------ratio-----------------------------------
  c1->cd(2);
  TH1F *ratio1=h1eta->Clone(h1eta->GetName());
  ratio1->Divide(h2eta);
  ratio1->SetMarkerSize(1.2);
  ratio1->SetMarkerStyle(21);
  ratio1->SetMarkerColor(kBlue);
  TH1F *hDum2 = new TH1F("hDum2","",50,StartPoint,EndPoint);
  hDum2->SetMaximum(1.45);
  hDum2->SetMinimum(0.65);
  hDum2->GetXaxis()->SetTitle("p_{T}[GeV/c]");
  hDum2->GetXaxis()->SetTitleSize(0.055);
  hDum2->GetXaxis()->SetLabelSize(0.045);
  hDum2->GetXaxis()->CenterTitle();

  hDum2->GetYaxis()->SetTitle("pPb/Pbp" );
  hDum2->GetYaxis()->SetTitleSize(0.055);
  hDum2->GetYaxis()->SetLabelSize(0.045);
  hDum2->GetYaxis()->CenterTitle();

  hDum2->DrawCopy();
  ratio1->DrawCopy("same");

  c1->Update();  

  TLine* l1 = new TLine(StartPoint,1.,EndPoint,1.);
  l1->SetLineWidth(1);
  l1->SetLineStyle(3);
  l1->SetLineColor(kBlack);
  l1->Draw();


  
  if(SavePlots) {
    c1->SaveAs(Form("ComparegenptSpectrapPb_PbpEta%.f_%.f.pdf",EtaMin[ieta]*10,EtaMax[ieta]*10));
   }


}
Пример #29
0
//================================================
void forZebo()
{
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);

  TCanvas *c = new TCanvas("RHIC_vs_ALICE","RHIC_vs_ALICE",850,750);
  gPad->SetBottomMargin(0.13);
  gPad->SetLeftMargin(0.13);
  gPad->SetTopMargin(0.05);
  gPad->SetRightMargin(0.05);
  TH1F *h = new TH1F("histogram",";Event activity;#frac{N_{J/#psi}}{<N_{J/#psi}>}",7,0,4.5);
  h->GetYaxis()->SetRangeUser(0,13.2);
  h->GetXaxis()->SetTitleFont(62);
  h->GetXaxis()->SetTitleSize(0.04);
  h->GetXaxis()->SetTitleOffset(1.2);
  h->GetXaxis()->SetLabelFont(62);
  h->GetXaxis()->SetLabelSize(0.035);
  h->GetYaxis()->SetTitleFont(62);
  h->GetYaxis()->SetTitleSize(0.04);
  h->GetYaxis()->SetTitleOffset(1.2);
  h->GetYaxis()->SetLabelFont(62);
  h->GetYaxis()->SetLabelSize(0.035);
  h->DrawCopy();

  TFile *fin = TFile::Open(Form("HP2015.pp.Jpsi.root"),"read");

  // STAR
  TGraphAsymmErrors *ratio = (TGraphAsymmErrors*)fin->Get("STAR_Run13_pp500_Jpsi_mumu_pT0");
  TGraphAsymmErrors *sys = (TGraphAsymmErrors*)fin->Get("STAR_Run13_pp500_Jpsi_mumu_pT0_sys");
  ratio->Draw("sames PEZ");
  sys->Draw("sameE5");

  TGraphErrors *gr = (TGraphErrors*)fin->Get("STAR_Run11_pp500_Jpsi_ee_pT4");
  TGraphAsymmErrors *grSys = (TGraphAsymmErrors*)fin->Get("STAR_Run11_pp500_Jpsi_ee_pT4_sys");
  gr->Draw("sames PEZ");
  grSys->Draw("sameE5");


  // ALICE
  TGraphAsymmErrors *gRatioJ = (TGraphAsymmErrors*)fin->Get("ALICE_pp7000_Jpsi_ee_pT0");
  TGraphAsymmErrors *gSysJ = (TGraphAsymmErrors*)fin->Get("ALICE_pp7000_Jpsi_ee_pT0_sys");
  gRatioJ->Draw("sames PEZ");
  gSysJ->Draw("sameE5");

  TGraphAsymmErrors *gRatioD = (TGraphAsymmErrors*)fin->Get("ALICE_pp7000_D_pT2_4");
  TGraphAsymmErrors *gSysD = (TGraphAsymmErrors*)fin->Get("ALICE_pp7000_D_pT2_4_sys");
  gRatioD->Draw("sames PEZ");
  gSysD->Draw("sameE5");

  leg = new TLegend(0.15,0.65,0.34,0.93);
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->SetTextSize(0.031);
  leg->SetHeader("p+p collisions");
  leg->AddEntry(ratio,"STAR 500 GeV: J/#psi#rightarrow#mu^{+}#mu^{-}, |y|<0.5, p_{T}>0 GeV/c","P");
  leg->AddEntry(gr,"STAR 500 GeV: J/#psi#rightarrowe^{+}e^{-}, |y|<1, p_{T}>4 GeV/c","P");
  leg->AddEntry(gRatioJ,"ALICE 7 TeV: J/#psi#rightarrowe^{+}e^{-}, |y|<0.9, p_{T}>0 GeV/c","P");
  leg->AddEntry(gRatioD,"ALICE 7 TeV: D meason, |y|<0.5, 2<p_{T}<4 GeV/c","P");
  leg->Draw();

  TPaveText *syserr = new TPaveText(0.38,0.14,0.85,0.2,"brNDC");
  syserr->SetFillStyle(0);
  syserr->SetBorderSize(0);
  syserr->SetTextSize(0.03);
  syserr->SetTextAlign(11);
  syserr->AddText("STAR data points");
  syserr->AddText("+15% one-sided error along both x- and y- direction");
  syserr->SetTextFont(32);
  syserr->SetTextColor(1);
  syserr->Draw();

  TLine *line = new TLine(0,0,4.5,4.5);
  line->SetLineStyle(2);
  line->SetLineWidth(2);
  line->Draw();

  TPaveText *star = new TPaveText(0.28,0.5,0.38,0.55,"brNDC");
  star->SetFillStyle(0);
  star->SetBorderSize(0);
  star->SetTextSize(0.045); 
  star->AddText("STAR preliminary");
  star->SetTextFont(20);
  star->SetTextColor(2);
  star->Draw();
}
Пример #30
0
void CompareCent(){
gStyle->SetOptStat(kFALSE);
gStyle->SetErrorX(0);
TString coll="PbP";
bool Save=kTRUE;
TF1 * fCen = new TF1("fCen","[0]*exp([1]+[2]*x+[3]*x*x+[4]*x*x*x+[5]*x*x*x*x+[6]*x*x*x*x*x)", 0., 100.);
if(coll=="PPb"){
//fCen->SetParameters(1.20916e-02, 5.02157e+00, -3.38300e-02, 1.87647e-03, -6.76442e-05, 9.08602e-07, -4.01536e-09);//parameterize on 05.03 after approval
//fCen->SetParameters(7.92204e-03, 4.52005e+00, 9.77340e-02, -5.00362e-03, 9.74735e-05, -8.93897e-07, 3.39375e-09);//parameterize on new official MC after QM on 12/03/14
fCen->SetParameters(6.06918e-03, 4.84487e+00, 4.26255e-02, -1.30682e-03, 1.94753e-05, -2.53606e-07, 1.61323e-09); //! parameterize on new official MC using double side HF on 02/02/15
TH1F* histodata=(TH1F*)fDataPPb->Get("Cent");
TH1F* histo1=(TH1F*)fMCPPb->Get("Cent");
//TH1F* histo2=(TH1F*)fNMCPPb->Get("Cent");
TH1F* histo2=(TH1F*)fMCPPb->Get("CentW");
TString data="Pb going positive side";
}
//fCen->SetParameters(8.68073e-03, 5.09356e+00, -1.33053e-02, 1.46904e-03, -6.99681e-05, 1.06721e-06, -5.21398e-09); //original
else if(coll=="PbP"){
//fCen->SetParameters(1.05408e-02, 5.27477e+00, -8.03382e-02, 3.51669e-03, -8.85332e-05, 1.08917e-06, -4.90091e-09);
//fCen->SetParameters(1.14851e-02, 5.31172e+00, -8.52366e-02, 3.00268e-03, -6.04667e-05, 6.24105e-07, -2.43580e-09);
//fCen->SetParameters(2.89263e-02, 3.43643e+00, 5.62562e-02, -1.86555e-03, 1.97924e-06, 3.15416e-07, -1.97946e-09);//parameterize on new official MC after QM on 12/03/14
fCen->SetParameters(5.10893e-03,4.88698e+00,8.37930e-02,-3.77127e-03, 7.90191e-05,-9.04877e-07, 4.26221e-09); //! parameterize on new official MC using double side HF on 02/02/15
TH1F* histodata=(TH1F*)fDataPbP->Get("Cent");
TH1F* histo1=(TH1F*)fMCPbP->Get("Cent");
//TH1F* histo2=(TH1F*)fNMCPbP->Get("Cent");
TH1F* histo2=(TH1F*)fMCPbP->Get("CentW");
TString data="Proton going positive side";
}
histo1->SetName(Form("%sNewMC_unweighted",coll.Data()));
histo2->SetName(Form("%sNewMC_weighted",coll.Data()));
histodata->SetName(Form("%sData",coll.Data()));
//histo1=(TH1F*)histo1->Rebin(Nbin_vz,"histo1",binbound_vz);
//histo2=(TH1F*)histo2->Rebin(Nbin_vz,"histo2",binbound_vz);
histo1->Scale(1/histo1->Integral());
histo2->Scale(1/histo2->Integral());
histodata->Scale(1/histodata->Integral());
histo1->SetMarkerStyle(24);
histo1->SetMarkerSize(1.2);
histo1->SetMarkerColor(4);
histo1->SetLineColor(4);
histo2->SetMarkerStyle(0);
histo2->SetMarkerSize(0);
histo2->SetFillStyle(3004);
histo2->SetFillColor(2);
histo2->SetLineColor(2);
//histo2->SetMarkerColor(4);
//histo2->SetMarkerColor(2);
histodata->SetMarkerStyle(20);
histodata->SetMarkerSize(1.2);
histodata->SetMarkerColor(1);
histodata->SetLineColor(1);

TCanvas* c1 = new TCanvas("c1"," ",500,500);
TCanvas* c2 = new TCanvas("c2"," ",500,500);
makeMultiPanelCanvas(c1,1,1,-0.16,0,0.16,0.14,0.03);
makeMultiPanelCanvas(c2,1,1,-0.16,0,0.16,0.14,0.03);

TH1F* hFrame=new TH1F("","",100,0,100);
fixedFontHist(hFrame,1.2,1.7);
hFrame->SetTitle("");
hFrame->GetXaxis()->SetTitleSize(0.05);
hFrame->GetYaxis()->SetTitleSize(0.05);
hFrame->GetXaxis()->SetTitle("Centrality");
hFrame->GetYaxis()->SetTitle("Event Fraction");
hFrame->GetXaxis()->SetLimits(0,100);
//hFrame->GetXaxis()->SetLimits(-3,3);
hFrame->GetYaxis()->SetRangeUser(0,9.2e-2);
c1->cd(1);
hFrame->DrawCopy();
histodata->Draw("same");
histo1->Draw("same");
histo2->Draw("HIST same");
TLegend *leg1=new TLegend(0.20,0.80,0.85,0.92);
TLegend *leg2=new TLegend(0.20,0.80,0.85,0.92);
leg1->SetBorderSize(0);
leg2->SetBorderSize(0);
leg1->SetFillColor(0);
leg2->SetFillColor(0);
leg1->SetTextSize(0.04);
leg2->SetTextSize(0.04);
leg1->AddEntry(histo1,"Before Centrality weighting","lp");
leg1->AddEntry(histo2,"After Centrality weighting","lfp");
//leg1->AddEntry(histo2,"Before Centrality weighting Last 2 pthat","lfp");
leg1->AddEntry(histodata,data,"lp");
leg1->Draw("same");
TLatex *T1=new TLatex(0.25,0.92,"");
T1->SetNDC();
T1->SetTextAlign(12);
T1->SetTextSize(0.05);
T1->SetTextColor(1);
T1->SetTextFont(42);
T1->Draw("same");
c2->cd(1);
hFrame->GetYaxis()->SetTitle("Data/MC");
hFrame->GetXaxis()->SetLimits(0,100);
hFrame->GetYaxis()->SetRangeUser(0,2);
hFrame->DrawCopy();
TH1F* ratio = (TH1F*)histodata->Clone(Form("%sratio",coll.Data()));
//ratio->SetName("ratio");
ratio->Divide(histo1);
/*ratio->Fit(fCen);
cout<<fCen->GetNDF()<<endl;
cout<<fCen->GetChisquare()<<endl;
for(int icent=0;icent<=6;icent++)
cout<<fCen->GetParameter(icent)<<",";
cout<<endl;*/
ratio->DrawCopy("same");
fCen->SetLineColor(2);
fCen->Draw("same");
leg2->AddEntry(ratio,data,"lp");
leg2->AddEntry(fCen,"reweighting function","lp");
leg2->Draw("same");
if(Save){
TFile *fout = new TFile("CentCompare.root","Update");
fout->cd();
ratio->Write("",TObject::kOverwrite);
histo1->Write("",TObject::kOverwrite);
histo2->Write("",TObject::kOverwrite);
histodata->Write("",TObject::kOverwrite);
fout->Close();
c2->Print(Form("ratio_Cent_%s.png",coll.Data()));
c1->Print(Form("CentCompare_Data%s.png",coll.Data()));
c1->Print(Form("CentCompare_Data%s.pdf",coll.Data()));
}

}