double* IfitBin(TH1D* dataInput, TH1D* sigTemplate, TH1D* bkgTemplate)
{
   // Start TFractionFitter
   double Spara(0), eSpara(0);
   double Bpara(0), eBpara(0);
   TObjArray *mc = new TObjArray(2);
   mc->Add(sigTemplate);
   mc->Add(bkgTemplate);

   TFractionFitter *fitTemplate = new TFractionFitter(dataInput, mc);
   fitTemplate->Constrain(0, 0.0, 1.0);
   fitTemplate->Constrain(1, 0.0, 1.0);
   int status = fitTemplate->Fit();
   cout<<" Fitting status = "<<status<<endl;
   if (status == 0) {
      fitTemplate->GetResult(0, Spara, eSpara);
      fitTemplate->GetResult(1, Bpara, eBpara);

      cout<<" Fitting result = "<<endl;
      cout<<"               Chi2 = "<<fitTemplate->GetChisquare()<<endl;
      cout<<"                NDF = "<<fitTemplate->GetNDF()<<endl;
      cout<<"               Prob = "<<fitTemplate->GetProb()<<endl;
      cout<<"      Signal fraction     = "<<Spara<<"; Error = "<<eSpara<<endl;
      cout<<"      Background fraction = "<<Bpara<<"; Error = "<<eBpara<<endl;
   }

   TH1D *FitResultReal = (TH1D*)sigTemplate->Clone();
   TH1D *FitResultFake = (TH1D*)bkgTemplate->Clone();
   TH1D *FitResultAll  = (TH1D*)dataInput->Clone();
   FitResultReal->SetName("ResultReal");
   FitResultFake->SetName("ResultFake");
   FitResultAll->SetName("ResultAll");
   FitResultReal->Scale(1./FitResultReal->Integral()*Spara*dataInput->Integral());
   FitResultFake->Scale(1./FitResultFake->Integral()*Bpara*dataInput->Integral());
   FitResultAll->Reset();
   FitResultAll->Add(FitResultReal);
   FitResultAll->Add(FitResultFake);
   
   TCanvas *c1 = new TCanvas("c1", "", 600, 400);
   c1->cd();
   FitResultAll->SetXTitle("#sigma_{i#etai#eta}");
   FitResultAll->SetYTitle("Number of photons");
   FitResultAll->SetMinimum(0);
   FitResultAll->SetMaximum(FitResultAll->GetMaximum()*1.4);
   FitResultAll->SetLineColor(1);
   FitResultAll->SetLineWidth(2);
   FitResultAll->Draw();
   dataInput->SetMarkerStyle(21);
   dataInput->SetMarkerSize(0.7);
   dataInput->SetLineColor(1);
   dataInput->SetLineWidth(2);
   dataInput->Draw("PE1same");
   FitResultReal->SetLineColor(2);
   FitResultReal->SetFillColor(2);
   FitResultReal->SetFillStyle(3002);
   FitResultReal->Draw("same");
   FitResultFake->SetLineColor(4);
   FitResultFake->SetFillColor(4);
   FitResultFake->SetFillStyle(3004);
   FitResultFake->Draw("same");
   TLegend *leg1 = new TLegend(0.5,0.5,0.9,0.85);
   char text[200];
   leg1->SetFillColor(0);
   leg1->SetShadowColor(0);
   leg1->SetFillStyle(0);
   leg1->SetBorderSize(0);
   leg1->SetLineColor(0);
   sprintf(text,"Data: %5.1f events", dataInput->Integral());
   leg1->AddEntry(dataInput, text, "pl");
   sprintf(text,"Fitted: %5.1f events", FitResultAll->Integral());
   leg1->AddEntry(FitResultAll, text, "l");
   sprintf(text,"Signal %5.1f #pm %5.1f events", FitResultReal->Integral(), eSpara/Spara*FitResultReal->Integral());
   leg1->AddEntry(FitResultReal, text, "f");
   sprintf(text,"Background %5.1f #pm %5.1f events", FitResultFake->Integral(), eBpara/Bpara*FitResultFake->Integral());
   leg1->AddEntry(FitResultFake, text, "f");
   leg1->Draw();

   return;
}
Example #2
0
void testMultiTree()
{
   multiTreeUtil myTrees;
   myTrees.addFile("mc/ntuple-HiMPA_photon15GeV.root","Analysis",TCut("ptHat<30"),1);
   myTrees.addFile("mc/ntuple-HiMPA_photon30GeV.root","Analysis",TCut("ptHat<50"),896./9517.);
   myTrees.addFile("mc/ntuple-HiMPA_photon50GeV.root","Analysis",TCut(""),896./9517.*1521./11551.);

   // Draw Leading Et
   TCanvas *c = new TCanvas("c","",600,600);
   TH1D *h = new TH1D("h","",100,10,110);
   myTrees.Draw2(h,"et[0]","");
   h->SetXTitle("E_{T} (GeV)");

   // Draw r9
   TCanvas *c2 = new TCanvas("c2","",600,600);
   TH1D *h2 = new TH1D("h2","",100,0,0.02);
   myTrees.Draw2(h2,"sigmaIetaIeta[0]","abs(eta[0])<1.479");
   h2->SetXTitle("#sigma_{i#eta i#eta}");

   // Draw ptHat
   TCanvas *c3 = new TCanvas("c3","",600,600);
   c3->SetLogy();
   TH1D *h3 = new TH1D("h3","",100,10,110);
   myTrees.Draw(h3,"ptHat","");
   h3->SetXTitle("#hat{p_{T}} (GeV/c)");

   // Print the first tree
   myTrees.Print();

   // Get the first tree and draw something
   TCanvas *c4 = new TCanvas("c4","",600,600);
   myTrees.getTree(0)->Draw("et");
}
void drawDum(float min, float max, double drawXLabel){

   TH1D *hdum = new  TH1D("h","",10,120,220);
  hdum->SetMaximum(max);

  hdum->SetStats(0);

  if(drawXLabel) hdum->SetXTitle("(p_{T}^{j1}-p_{T}^{j2})/(p_{T}^{j1}+p_{T}^{j2})");
  hdum->GetXaxis()->SetLabelSize(20);
  hdum->GetXaxis()->SetLabelFont(43);
  hdum->GetXaxis()->SetTitleSize(22);
  hdum->GetXaxis()->SetTitleFont(43);
  hdum->GetXaxis()->SetTitleOffset(1.5);
  hdum->GetXaxis()->CenterTitle();

  hdum->GetXaxis()->SetNdivisions(905,true);

  hdum->SetYTitle("Event Fraction");

  hdum->GetYaxis()->SetLabelSize(20);
  hdum->GetYaxis()->SetLabelFont(43);
  hdum->GetYaxis()->SetTitleSize(20);
  hdum->GetYaxis()->SetTitleFont(43);
  hdum->GetYaxis()->SetTitleOffset(2.5);
  hdum->GetYaxis()->CenterTitle();

  hdum->SetAxisRange(0,0.2,"Y");

  hdum->Draw("");

}
//__________________________________________________________________________
void drawDum(float min, float max, double drawXLabel)
{

  TH1D *hdum = new TH1D("hdum","",20,0,1);
  hdum->SetMaximum(max);

  hdum->SetStats(0);

  if(drawXLabel) hdum->SetXTitle("A_{J} = (E_{T}^{j1}-E_{T}^{j2})/(E_{T}^{j1}+E_{T}^{j2})");
  hdum->GetXaxis()->SetLabelSize(20);
  hdum->GetXaxis()->SetLabelFont(43);
  hdum->GetXaxis()->SetTitleSize(22);
  hdum->GetXaxis()->SetTitleFont(43);
  hdum->GetXaxis()->SetTitleOffset(1.5);
  hdum->GetXaxis()->CenterTitle();

  hdum->GetXaxis()->SetNdivisions(905,true);

  hdum->SetYTitle("Ratio");

  hdum->GetYaxis()->SetLabelSize(20);
  hdum->GetYaxis()->SetLabelFont(43);
  hdum->GetYaxis()->SetTitleSize(20);
  hdum->GetYaxis()->SetTitleFont(43);
  hdum->GetYaxis()->SetTitleOffset(2.5);
  hdum->GetYaxis()->CenterTitle();

  hdum->SetAxisRange(0,0.2,"Y");

  hdum->Draw("");

}
Example #5
0
bool DrawPileupCorr(Str jetAlgo) {
  JetCalibrationTool *theJES = new JetCalibrationTool(jetAlgo,_jesFile,false);
  bool residual = theJES->JetAreaJES();

  TH1D *temp = new TH1D("","",100,-5,5);
  temp->SetXTitle("Jet #eta"); temp->SetYTitle("Jet offset at "+GetConstScale(jetAlgo)+"-scale [GeV]");
  if (residual) temp->SetYTitle("Residual jet offset at "+GetConstScale(jetAlgo)+"-scale [GeV]");
  temp->SetMinimum(-20); temp->SetMaximum(15); temp->SetStats(0);
  if ( residual && theJES->ResidualOffsetCorr_Description() == "" ) return false;
  Can->Clear(); temp->Draw();
  for (int npv=0;npv<9;++npv) {
    double NPV=(npv%3)*10, mu=(npv/3)*10;
    if (NPV==0) NPV=1;
    Graph *g = new Graph();
    FormatGraph(g,npv);
    for (int ieta=-50;ieta<50;++ieta) {
      double eta=0.05 + 0.1*ieta;
      double O = residual ? theJES->GetResidualOffset(eta,mu,NPV)/1000 :
	theJES->GetOffset(eta,mu,NPV)/1000; // convert to GeV
      g->SetPoint(g->GetN(),eta,O);
    }
    if (npv<4) DrawLabel(Form("N_{PV} = %.0f, #LT#mu#GT = %.0f",NPV,mu),0.18,0.35-0.04*npv,npv);
    else DrawLabel(Form("N_{PV} = %.0f, #LT#mu#GT = %.0f",NPV,mu),0.48,0.35-0.04*(npv-4),npv);
    
    g->Draw("P");
  }
  tex->SetNDC(); tex->SetTextAlign(12);
  if (residual)
    tex->DrawLatex(0.18,0.975,theJES->ResidualOffsetCorr_Description());
  else 
    tex->DrawLatex(0.18,0.975,theJES->OffsetCorr_Description());
  tex->DrawLatex(0.18,0.9,GetJetDesc(jetAlgo));
  return true;
}
Example #6
0
void peakAnalysis( string filename2 , string filenamelist ) {
   
    TFile * file0 = new TFile(filename2.c_str());
    TFile * file1 = new TFile(filenamelist.c_str());

    TTree * tree = (TTree*)file0->Get("tree");
    TEventList * listsel = (TEventList*)file1->Get("listofselected");

    TCanvas * can = new TCanvas( "canPeaks" , "Peak Analysis" , 7500 , 5500 , 900 , 600 );
    //can->SetLogy();
    can->SetGrid();
    can->cd();

    tree->SetEventList(listsel);
    tree->Draw("GEMDEnergyGauss_1.energy[0]>>htemp(10000,10000,10000)");
    TH1D * spectrum = (TH1D*)gDirectory->Get("htemp");

    spectrum->SetTitle("Energy Spectrum");
    spectrum->SetXTitle("Energy [keV]");
    spectrum->SetYTitle("Counts");
    //spectrum->SetStats(kFALSE);
    
    TSpectrum analyzer( 8 , 2 );
        // arg1: max number of peaks
        // arg2: resolution between peaks
    analyzer.Search( spectrum , 2 , "" , 0.0025);
        // arg2: sigma of the searched peaks
        // arg3: options
        // arg4: peaks with amplitude less than threshold*highest_peak are discarded

    vector<double> peaks;
    for ( int i = 0 ; i < analyzer.GetNPeaks() ; i++ ) {
        peaks.push_back(analyzer.GetPositionX()[i]);
    }
    sort(peaks.begin(),peaks.end());

    cout << endl << "########## PEAKS ##########" << endl;
    for ( int i = 0 ; i < peaks.size() ; i++ ) cout << i+1 << "\t" << peaks.at(i) << endl;

    cout << "###########################" << endl << endl;
   
	if ( peaks.size() < 6 ) { 
		cout << "ERROR: Not enough peaks found, try to modify TSpectrum parameters.\n\n";
		return;
	}

    ofstream file("calib.txt");

    file << "// calibration"                                     << endl
         << "// ch\tkeV"                                         << endl
         << peaks.at(0) << "\t1460.882 // 40K"                   << endl
         << peaks.at(1) << "\t1512.700 // 212Bi"                 << endl
         << peaks.at(2) << "\t1592.515 // 208Tl (double escape)" << endl
         << peaks.at(3) << "\t1620.738 // 212Bi"                 << endl
         << peaks.at(5) << "\t2103.513 // 208Tl (single escape)" << endl
         << peaks.at(6) << "\t2614.511 // 208Tl";

    return;
}
Example #7
0
void ptDependence()
{
   TFile *inf = new TFile("histos/ppMC.root");
   TTree *t = (TTree*) inf->Get("nt");

   const int nBins = 4;
   double ptBin[nBins+1] = {100,120,140,160,200};
//   const int nBins = 1;
//   double ptBin[nBins+1] = {100,400};
   
   TH1D *hProb = new TH1D("hProb","",nBins,ptBin);
   TH1D *hCSV = new TH1D("hCSV","",nBins,ptBin);
   TH1D *hSVTXM = new TH1D("hSVTXM","",nBins,ptBin);
   TProfile *pGen = new TProfile("pGen","",nBins,ptBin);
   
   for (int n=0; n<nBins;n++)
   {
      RooRealVar f1 = bfractionFit("discr_prob",0,3.5,ptBin[n],ptBin[n+1]);
      RooRealVar f2 = bfractionFit("discr_csvSimple",0,1,ptBin[n],ptBin[n+1]);
      RooRealVar f3 = bfractionFit("svtxm",0,6,ptBin[n],ptBin[n+1]);
      hProb->SetBinContent(n+1,f1.getVal());    
      hProb->SetBinError(n+1,f1.getError());    
      hCSV->SetBinContent(n+1,f2.getVal());    
      hCSV->SetBinError(n+1,f2.getError());    
      hSVTXM->SetBinContent(n+1,f3.getVal());    
      hSVTXM->SetBinError(n+1,f3.getError());    
   }
   
   TCanvas *c2 = new TCanvas("c2","",600,600);
   hProb->SetAxisRange(0,0.05,"Y");
   hProb->SetXTitle("Jet p_{T} (GeV/c)");
   hProb->SetYTitle("b-jet fraction");
   hProb->SetTitleOffset(1.5,"Y");
   hProb->Draw();
   hCSV->SetLineColor(2);
   hCSV->SetMarkerColor(2);
   hCSV->SetMarkerStyle(24);
   hCSV->Draw("same");
   hSVTXM->SetLineColor(4);
   hSVTXM->SetMarkerColor(4);
   hSVTXM->SetMarkerStyle(24);
//   hSVTXM->Draw("same");
   t->Draw("abs(refparton_flavorForB)==5:jtpt","","prof same");
   
   TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
   leg->SetBorderSize(0);
   leg->SetFillStyle(0);
   leg->SetFillColor(0);
   leg->AddEntry(hProb,"Jet Probability","pl");
   leg->AddEntry(hCSV,"CSV","pl");
//   leg->AddEntry(hSVTXM,"SV mass","pl");
   leg->Draw();
}
Example #8
0
void plotCentrality(){

  
  TFile* f4 = new TFile("histogram_test_MB_2760GeV.root");
  TH1D* cent  = f4->Get("demo/centhist");
  TCanvas* cd = new TCanvas("cd","",600,500);
  cd->SetLeftMargin(0.12);
  cd->SetRightMargin(0.02);
  cd->SetTopMargin(0.02);
  cd->SetBottomMargin(0.12);
  cd->SetTicks(1);
  cent->SetTitle("");
  cent->SetXTitle("Centrality (200 bins)");
  cent->SetYTitle("# of Events");
  cent->GetYaxis()->SetTitleOffset(1.2);
  cent->GetXaxis()->SetTitleOffset(1.2);
  cent->GetXaxis()->CenterTitle(1);
  cent->GetYaxis()->CenterTitle(1);
  cent->GetXaxis()->SetTitleSize(0.046);
  cent->GetYaxis()->SetTitleSize(0.046);
  cent->GetXaxis()->SetTitleFont(62);
  cent->GetYaxis()->SetTitleFont(62);
  cent->SetAxisRange(0,209,"Y");
  cent->SetAxisRange(0,203,"X");
  cent->SetMarkerStyle(20);
  cent->Sumw2();
  cent->SetMarkerSize(1);
  cent->SetMarkerColor(1);
  cent->SetLineColor(1);
  //cent->SetStats(0);
  cent->Draw("Pez");

    TLatex *tex1= new TLatex(55.5,125.060,"Hydjet 2.76TeV MB");
    tex1->SetTextColor(1);
    tex1->SetTextSize(0.05);
    tex1->SetTextFont(42);
    tex1->Draw();

    TLatex *tex2= new TLatex(55.5,99.054,"CMSSW_7_5_0_pre5");
    tex2->SetTextColor(1);
    tex2->SetTextSize(0.05);
    tex2->SetTextFont(42);
    //tex2->Draw();
  cd->SaveAs("centralityDist750x2760GeV.png");

}
Example #9
0
void CheckInitialESpectrum(std::string filename) {

  TFile* file = new TFile(filename.c_str(), "READ");
  TTree* tree = (TTree*) file->Get("tree");
  TFile* out_file = new TFile("plots.root", "UPDATE");

  double bin_width = 250; //keV
  double x_low = 0;
  double x_high = 25000;
  int n_bins_x = (x_high - x_low) / bin_width;
  
  TH1D* hInitialESpectrum = new TH1D("hInitialESpectrum", "Initial Energy Spectrum Generated", n_bins_x,x_low,x_high);
  hInitialESpectrum->SetXTitle("Energy [keV]");
  tree->Draw("(sqrt(i_px*i_px*1e6 + i_py*i_py*1e6 + i_pz*i_pz*1e6 + 938272*938272) - 938272)>>hInitialESpectrum");
  hInitialESpectrum->Write();

  out_file->Close();
}
void scan()
{
   TFile *outf = new TFile("result.root","recreate");

   TH1D *h = new TH1D("h","",6,20,50);
   int bin=1;
   for (int i=20;i<50;i+=5)
   {
      TF1 *f = bFeedDownFraction(i,i+5);
      h->SetBinContent(bin,f->GetParameter(2));
      h->SetBinError(bin,f->GetParError(2));
      bin++;
   }
   
   TCanvas *cResult = new TCanvas("cResult","",600,600);
   h->SetXTitle("D^{0} p_{T} (GeV/c)");
   h->SetYTitle("Prompt Fraction");
   h->Draw("e");
}
Example #11
0
void plot(TString var, TString varlatex, TString varname, Int_t nbins, Double_t vmin, Double_t vmax)
{
  cout<<"---- Processing - "<<var<<endl;
  cout<<"  -- Fill histograms"<<endl;
  TFile* ifBkg = new TFile(infnameBkg[isChannel]);
  TTree* ntBkg = (TTree*)ifBkg->Get(texNtuple[isChannel]);
  ntBkg->AddFriend("ntHlt");
  TFile* ifSgl = new TFile(infnameSgl[isChannel]);
  TTree* ntSgl = (TTree*)ifSgl->Get(texNtuple[isChannel]);
  ntSgl->AddFriend("ntHlt");
  ntSgl->AddFriend("ntHi");

  TH1D* hBkg = new TH1D(Form("hBkg_%s",varname.Data()),"",nbins,vmin,vmax);
  TH1D* hSgl = new TH1D(Form("hSgl_%s",varname.Data()),"",nbins,vmin,vmax);

  ntBkg->Project(Form("hBkg_%s",varname.Data()),var,Form("%s&&%s",selTriggerBkg[isChannel].Data(),selBkg[isChannel].Data()));
  ntSgl->Project(Form("hSgl_%s",varname.Data()),var,TCut(weight[isChannel])*Form("%s&&%s",selTriggerSgl[isChannel].Data(),selSgl[isChannel].Data()));

  cout<<"  -- Calculate normalization"<<endl;
  Double_t normBkg=0,normSgl=0;
  //normBkg = hBkg->GetEntries();
  //normSgl = hSgl->GetEntries();
  normBkg = hBkg->Integral(vmin,vmax);
  normSgl = hSgl->Integral(vmin,vmax);
  cout<<"     normBkg: "<<normBkg<<" ;   normSgl: "<<normSgl<<endl;

  cout<<"  -- Normalize histograms"<<endl;
  hBkg->Scale(1./normBkg);
  hSgl->Scale(1./normSgl); 

  cout<<"  -- Plot"<<endl;
  hBkg->SetXTitle(varlatex);
  hBkg->SetYTitle("#Probability");
  hBkg->SetTitleOffset(1.5,"Y");
  Double_t hisMax = (hBkg->GetMaximum()>hSgl->GetMaximum())?hBkg->GetMaximum():hSgl->GetMaximum();
  hBkg->SetMaximum(hisMax*1.2);

  hBkg->SetLineColor(kBlue+1);
  hBkg->SetFillStyle(1001);
  hBkg->SetFillColor(kBlue-9);
  hBkg->SetLineWidth(3);
  hBkg->SetStats(0);

  TH1D* hSglplot = new TH1D(Form("hSglplot_%s",varname.Data()),"",nbins,vmin,vmax);
  for(int ib=0;ib<nbins;ib++) hSglplot->SetBinContent(ib+1,hSgl->GetBinContent(ib+1));
  hSglplot->SetLineColor(kRed);
  hSglplot->SetFillStyle(3004);
  hSglplot->SetFillColor(kRed);
  hSglplot->SetLineWidth(3);
  hSglplot->SetStats(0);

  TCanvas* c = new TCanvas(Form("c_%s",varname.Data()),"",600,600);
  hBkg->Draw();
  hSglplot->Draw("same");

  cout<<"  -- Plot legends"<<endl;
  TLatex* tex = new TLatex(0.18,0.935,Form("5.02TeV %s",texPP[isChannel].Data()));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.055);
  tex->Draw();
  TLatex* texp;
  texp = new TLatex(0.68,0.935,texDecay[isChannel]);
  texp->SetNDC();
  texp->SetTextFont(42);
  texp->SetTextSize(0.055);
  texp->Draw();
  TLegend* leg = new TLegend(0.56,0.70,0.86,0.86);
  leg->AddEntry(hBkg,"Background","f");
  leg->AddEntry(hSglplot,"Signal","f");
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  leg->Draw("same");

  cout<<"  -- Save plots"<<endl;
  c->SaveAs(Form("plots/%s_%s/c_%s.pdf",texPP[isChannel].Data(),texNtuple[isChannel].Data(),varname.Data()));
  cout<<endl;
}
Example #12
0
void plotRBDphi( 
		double dphiCut=3.026,
		// double dphiCut=2.094,
	      double dphiCut2 = 3.026,
		 TString infname = "data.root",
		 TString pythia = "pythia.root",
		 TString mix = "mix.root",
		 bool useWeight = true,
		 bool drawXLabel = false,
		 bool drawLeg = true)
{		
  useWeight = 0;

  int threshold1 = 80;
  int threshold2 = 120;
  gStyle->SetErrorX(0); 
  TString cut1=Form("abs(eta1) < 2 && abs(eta2) < 2 && et1>%d&&et2>50",threshold1);
  TString cut2=Form("abs(eta1) < 2 && abs(eta2) < 2 && et1>%d&&et2>50",threshold2);
  cout <<cut1.Data()<<endl;
  cout <<cut2.Data()<<endl;

  TString trigcut = "";
  TString cstring = "";

  // open the data file
  TFile *inf = new TFile(infname.Data());
  TTree *nt =(TTree*)inf->FindObjectAny("nt");

  // open the pythia (MC) file
  TFile *infPythia = new TFile(pythia.Data());
  TTree *ntPythia = (TTree*) infPythia->FindObjectAny("nt");

  // open the datamix file
  TFile *infMix = new TFile(mix.Data());
  TTree *ntMix =(TTree*)infMix->FindObjectAny("nt");

  // open output
  TFile *outfile = new TFile("output.root","recreate");
  TNtuple *ntOut = new TNtuple("ntOut","","npart");


  nt->SetAlias("et1","pt1");
  nt->SetAlias("et2","pt2");

  ntMix->SetAlias("et1","pt1");
  ntMix->SetAlias("et2","pt2");
  ntPythia->SetAlias("et1","pt1");
  ntPythia->SetAlias("et2","pt2");

  //  ntMix->SetAlias("pt1","et1");
  //  ntMix->SetAlias("pt2","et2");

  //  ntPythia->SetAlias("pt1","et1");
  //  ntPythia->SetAlias("pt2","et2");

  ntPythia->SetAlias("weight","1");
  ntMix->SetAlias("weight","1");

  const int nBin = 6;
  double m[nBin+1] = {-1.5,-0.5,3.5,7.5,11.5,20.5,40.5};
  double npart[nBin] = {2,358.623,232.909,97.9521};
  double npart2[nBin] = {2,358.623,232.909,97.9521};
  
  double npartValue[40];
  npartValue[0] = 393.633;
  npartValue[1] = 368.819;
  npartValue[2] = 343.073;
  npartValue[3] = 317.625;
  npartValue[4] = 292.932;
  npartValue[5] = 271.917;
  npartValue[6] = 249.851;
  npartValue[7] = 230.72;
  npartValue[8] = 212.465;
  npartValue[9] = 194.752;
  npartValue[10] = 178.571;
  npartValue[11] = 163.23;
  npartValue[12] = 149.187;
  npartValue[13] = 136.011;
  npartValue[14] = 123.414;
  npartValue[15] = 111.7;
  npartValue[16] = 100.831;
  npartValue[17] = 90.7831;
  npartValue[18] = 80.9823;
  npartValue[19] = 72.6236;
  npartValue[20] = 64.1508;
  npartValue[21] = 56.6284;
  npartValue[22] = 49.9984;
  npartValue[23] = 43.3034;
  npartValue[24] = 37.8437;
  npartValue[25] = 32.6659;
  npartValue[26] = 27.83;
  npartValue[27] = 23.7892;
  npartValue[28] = 20.1745;
  npartValue[29] = 16.8453;
  npartValue[30] = 14.0322;
  npartValue[31] = 11.602;
  npartValue[32] = 9.52528;
  npartValue[33] = 7.6984;
  npartValue[34] = 6.446;
  npartValue[35] = 4.96683;
  npartValue[36] = 4.23649;
  npartValue[37] = 3.50147;
  npartValue[38] = 3.16107;
  npartValue[39] = 2.7877;

  TH1D *hTmp = new TH1D("hTmp","",100,-10,400);
  TH1D *h = new TH1D("h","",nBin,m);
  TH1D *hCut = new TH1D("hCut","",nBin,m);
  TH1D *h2 = new TH1D("h2","",nBin,m);
  TH1D *h2Cut = new TH1D("h2Cut","",nBin,m);

  TH1D *hStat = new TH1D("hStat","",nBin,m);
  TH1D *hNpartSum = new TH1D("hNpartSum","",nBin,m);
  TH1D *hStat2 = new TH1D("hStat2","",nBin,m);
  TH1D *hNpartSum2 = new TH1D("hNpartSum2","",nBin,m);


  Float_t bin=0;
  Float_t et1=0;
  nt->SetBranchAddress("bin",&bin);
  nt->SetBranchAddress("pt1",&et1);
  
  for (int i=0;i<nt->GetEntries();i++)
  {
     nt->GetEntry(i);
     if (et1<threshold1) continue;
     
     if (et1>threshold2) {
        hNpartSum2->Fill(bin,npartValue[(int)bin]);
        hStat2->Fill(bin); 
        if (et1>threshold1) {
        hNpartSum->Fill(bin,npartValue[(int)bin]);
        hStat->Fill(bin); 
	}
     }	 
  }

  hNpartSum->Divide(hStat);
  hNpartSum2->Divide(hStat2);
  
  for (int i=1;i<nBin;i++)
  {
     cout <<hNpartSum->GetBinContent(i+1)<<endl;
     npart[i]=hNpartSum->GetBinContent(i+1);
     cout <<hNpartSum2->GetBinContent(i+1)<<endl;
     npart2[i]=hNpartSum2->GetBinContent(i+1);
     
  }

  nt->Draw("bin>>h",Form("abs(dphi)>%f&&%s",dphiCut,cut1.Data()));
  nt->Draw("bin>>hCut",Form("%s",cut1.Data()));
  TGraphAsymmErrors *g = calcEff(hCut,h,npart);
  g->SetMarkerSize(1.25);

  cout <<cut2.Data()<<endl;
  nt->Draw("bin>>h2",Form("abs(dphi)>%f&&%s",dphiCut2,cut2.Data()));
  nt->Draw("bin>>h2Cut",Form("%s",cut2.Data()));
  TGraphAsymmErrors *g2 = calcEff(h2Cut,h2,npart2);
  g2->SetMarkerSize(1.25);


  ntPythia->Draw("bin>>h",Form("abs(dphi)>%f&&%s",dphiCut2,cut2.Data()));
  ntPythia->Draw("bin>>hCut",Form("%s",cut2.Data()));
  TGraphAsymmErrors *gPythia = calcEffpythia(hCut,h,npart);
  gPythia->SetMarkerSize(1.7);
  
  if(useWeight){
    ntMix->Draw("bin>>h",Form("weight*(abs(dphi)>%f&&%s)",dphiCut2,cut2.Data()));
    ntMix->Draw("bin>>hCut",Form("weight*(%s)",cut2.Data()));
  }else{
    ntMix->Draw("bin>>h",Form("(abs(dphi)>%f&&%s)",dphiCut2,cut2.Data()));
    ntMix->Draw("bin>>hCut",Form("(%s)",cut2.Data()));
  }
  TGraphAsymmErrors *gMix = calcEff(hCut,h,npart);
  gMix->SetMarkerSize(1.25);

  TCanvas *c = new TCanvas("c","",500,500);
  //  hTmp->SetMaximum(g->GetY()[0]*2.2);
  hTmp->SetMaximum(0.85);
  hTmp->SetMinimum(0.);

  hTmp->SetXTitle("N_{part}");
  hTmp->SetYTitle(Form("R_{B}(#Delta#phi_{12} > %.3f)",dphiCut));
  hTmp->GetXaxis()->CenterTitle();
  hTmp->GetYaxis()->CenterTitle();
  //  hTmp->GetYaxis()->SetTitleOffset(1.2);
  //  hTmp->GetYaxis()->SetTitleSize(0.055);
  hTmp->Draw();

  double errorbar = 0.02;
/*
  for(int i = 0; i < g->GetN(); ++i){
    double *x = g->GetX();
    double *y = g->GetY();
//    DrawTick(y[i],0.18*y[i],0.18*y[i],x[i],0.012,8.1,16);
  }
  g->Draw("p same");
  g2->SetMarkerStyle(4);
  */
  for(int i = 0; i < g2->GetN(); ++i){
    double *x = g2->GetX();
    double *y = g2->GetY();
    double err = 1.5*(0.0001129*x[i]);
    err = sqrt(err * err + 0.012*0.012);
    cout <<err/y[i]<<" "<<1.5*(0.0001129*x[i])/y[i]<<" "<<0.012/y[i]<<endl;
    double tickSize = 0.012;
    if (err<tickSize) tickSize=err;
    DrawTick(y[i],err,err,x[i],tickSize,8.1,dataColor);
  }
  gPythia->SetMarkerColor(4);
  gPythia->SetLineColor(4);
  gPythia->SetMarkerStyle(29);

  gMix->SetMarkerColor(4);
  gMix->SetLineColor(4);
  gMix->SetMarkerStyle(25);
  //  gMix->Draw("p same");
  gPythia->Draw("p same");

  g2->SetLineColor(dataColor);
  g2->SetMarkerColor(dataColor);

  g2->Draw("p same");

  TLine* pline = new TLine(0,gPythia->GetY()[0],400,gPythia->GetY()[0]);
  pline->SetLineColor(4);
  pline->SetLineStyle(4);
  pline->Draw();

  if(drawLeg){
    TLegend *t3=new TLegend(0.5,0.77,0.9,0.93); 
    t3->AddEntry(g2,"PbPb  #sqrt{s}_{_{NN}}=2.76 TeV","p");
    //    t3->AddEntry(gPythia,"PYTHIA","p");  
    //    t3->AddEntry(gMix,"PYTHIA+DATA","p");

    //    t3->AddEntry(g,"2011","p");
    //    t3->AddEntry(gMix,"2010","p");
    t3->AddEntry(gPythia,"pp #sqrt{s}=2.76 TeV","p");

    t3->SetFillColor(0);
    t3->SetBorderSize(0);
    t3->SetFillStyle(0);
    t3->SetTextFont(63);
    t3->SetTextSize(15);
    t3->Draw();
  }


  TLatex *cms = new TLatex(0.20,0.88,"CMS Preliminary");
  cms->SetNDC();
  cms->SetTextFont(63);
  cms->SetTextSize(18);
  cms->Draw();                                                                                                                                        
  TLatex tsel;
  tsel.SetNDC();
  tsel.SetTextFont(63);
  tsel.SetTextSize(15);
  tsel.DrawLatex(0.25,0.35,"p_{T,1} > 120 GeV/c");
  tsel.DrawLatex(0.25,0.275,"p_{T,2} > 30 GeV/c");
//  tsel.DrawLatex(0.25,0.20,"#Delta#phi_{12} > #frac{2}{3}#pi rad");

  TLatex *lumi = new TLatex(0.20,0.81,"#intL dt = 6.7 #mub^{-1}");
  lumi->SetNDC();
  lumi->SetTextFont(63);
  lumi->SetTextSize(15);
  lumi->Draw(); 
/*
  TF1 *f = new TF1("f","0.5+[0]*x");
  gMix->Fit("f");
  */
  TCanvas *c2 = new TCanvas("c2","",500,500);

  TGraphAsymmErrors *gRatio = divideGraph(g2,gMix);
  gRatio->Draw("ap");
  gRatio->Fit("pol1");
  //gRatio->Fit("pol0");
  
  c->Print(Form("fig/RB_dphi_%d_vs_Npart.eps",(int)(1000*dphiCut)));
  c->Print(Form("fig/RB_dphi_%d_vs_Npart.C",(int)(1000*dphiCut)));
  c->Print(Form("fig/RB_dphi_%d_vs_Npart.gif",(int)(1000*dphiCut)));
  c->Print(Form("fig/RB_dphi_%d_vs_Npart.pdf",(int)(1000*dphiCut)));


}
Example #13
0
void fitDstar(char *infname = "/data/wangj/MC2015/Dntuple/PbPb/ntD_Pythia8_5020GeV_DstarD0kpipipi_755patch3_GEN_SIM_PU_20151120_Dstar5p_tkPt2_20151126_Evt_All.root") {

    TFile *inf = new TFile(infname);
    //TTree *ntmix=(TTree*)inf->Get("ntDD0kpipipipi");
    TTree *ntmix=(TTree*)inf->Get("ntDD0kpipi");
    TH1D *h = new TH1D("h","",100,0.139,0.159);
    TCut cutTrk = "";//"trk1PixelHit>=2&&trk1StripHit>=10&&trk1Chi2ndf<5&&trk2PixelHit>=2&&trk2StripHit>=10&&trk2Chi2ndf<5";

    TCanvas *c = new TCanvas("c","",750,750);
    ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&(DsvpvDistance/DsvpvDisErr)>0.&&Dchi2cl>0.05&&Dalpha<1."&&cutTrk,"",10000000);
    //ntmix->Draw("Dmass-DtktkResmass>>h","abs(DtktkResmass-1.86486)<0.015&&Dpt>10&&Dtrk1Pt>0.5&&DRestrk1Pt>0.5&&DRestrk2Pt>0.5&&DRestrk3Pt>0.5&&DRestrk4Pt>0.5&&Dchi2cl>0.1&&Dalpha<0.2&&(DsvpvDistance/DsvpvDisErr)>.0"&&cutTrk,"",10000000);
    h->Sumw2();
    //   TF1 *f = new TF1("f","(1-exp(-(x-[8])/[0]))*(((x)/[8])**[1]+[2]*(((x)/[8])-1))*[3]+[4]*(TMath::Voigt(x-[5],[6],[7]))");
    TF1* f = new TF1("f","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong);
//   TF1 *f = new TF1("f","(1-exp(-(x-0.13957018)/[0]))*(((x)/0.13957018)**[1]+[2]*(((x)/0.13957018)-1))*[3]+[4]*(TMath::Gaus(x,[5],[6]))");
    //TF1 *f = new TF1("f","(1-exp(-(x-1.86486-0.13957018)/[0]))*(((x-1.86486)/0.13957018)**[1]+[2]*(((x-1.86486)/0.13957018)-1))*[3]+[4]*TMath::Gaus(x,[5],[6])");
    f->SetLineColor(4);
//   f->SetParameters(-2.3825e6,-7.99713e-1,-1.42957,-5.50069e10,5.33573,1.45491e-1,2.78677e-6,1.43145e-3,0.13957018);
//   f->SetParameters(-7.3e5,-2.2e1,5.24e-1,-7.18e9,2e2,1.45491e-1,9e-4,0.1,8e-4);
    f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4);
    f->FixParameter(9,15e-4);
    f->FixParameter(6,0.145491);
    f->FixParameter(7,8e-4);
    f->SetParLimits(8,0,1);
    h->Fit("f","LL");
    h->Fit("f","LL");
    h->Fit("f","LL","",0.142,0.147);
    f->ReleaseParameter(6);
    f->ReleaseParameter(7);
    f->ReleaseParameter(9);
    f->SetParLimits(7,1e-4,9e-4);
    f->SetParLimits(9,1e-4,9e-4);
    h->Fit("f","LL","",0.142,0.148);
    h->Fit("f","LL","",0.142,0.16);
    h->Fit("f","LL","",0.142,0.16);
    h->Fit("f","LL","",0.141,0.16);
    h->Fit("f","LL","",0.141,0.16);
    h->Fit("f","LL","",0.141,0.16);

    h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})");
    h->SetYTitle("Entries");
    h->SetStats(0);
    h->SetAxisRange(1,h->GetMaximum()*1.3,"Y");
    TF1 *f2 = (TF1*)f->Clone("f2");
    f2->SetParameter(5,0);
    f2->SetRange(0.141,0.16);
    TF1 *f3 = (TF1*)f->Clone("f3");
    f3->SetParameter(0,0);
    f3->SetParameter(1,0);
    f3->SetParameter(2,0);
    f3->SetParameter(3,0);
    f3->SetParameter(4,0);

    f->SetLineColor(4);
    f2->SetLineColor(4);
    f2->SetLineStyle(2);
    f3->SetLineStyle(2);
    f2->Draw("same");
    f3->SetLineColor(2);
    f3->SetFillStyle(3004);
    f3->SetFillColor(2);
    f3->Draw("same");

    c->SaveAs("canvasDstar.pdf");
}
void advancedNoiseAnalysis( unsigned int runNumber, unsigned int loop = 1) {
  
  string inputFileName = "./histo/run00" + toString( runNumber ) + "-ped-histo.root";
  string outputFileName = "./histo/run00" + toString( runNumber ) + "-adv-noise.root";
  

  // before opening the input and the output files, try to see if they
  // are not opened yet and in case close them before continue   
  TList * listOfOpenedFile = (TList*) gROOT->GetListOfFiles();
  for ( int i = 0; i < listOfOpenedFile->GetSize() ; ++i ) {
    TFile * file = (TFile*) listOfOpenedFile->At( i ) ;
    TString fileName(file->GetName());
    TString inputFileName1( inputFileName.c_str() );
    TString outputFileName1( outputFileName.c_str() );

    if (  ( fileName.Contains( inputFileName1 ) ) ||
	  ( inputFileName1.Contains( fileName ) ) ||
	  ( fileName.Contains( outputFileName1 ) ) ||
	  ( outputFileName1.Contains( fileName ) ) ) {
      cout << "Closing " << fileName << " before reopen " << endl;
      file->Close();
    }
  }


  // close also all the previously opened canvas
  TList * listOfOpenedCanvas = (TList*) gROOT->GetListOfCanvases();
  for ( int i = 0 ; i < listOfOpenedCanvas->GetSize() ; ++i ) {
    TCanvas * canvas = (TCanvas*) listOfOpenedCanvas->At( i );
    TString canvasName2 = canvas->GetName();
    if ( canvasName2.Contains( "det" ) ) {
      canvas->Close();
    }
  }

	 
  // now safely open the file
  TFile * inputFile = TFile::Open( inputFileName.c_str() ) ;
  TFile * outputFile = TFile::Open( outputFileName.c_str(), "RECREATE") ;
  TList * outputHistoList = new TList;

  // look into the inputFile for a folder named
  string pedeProcessorFolderName = "PedestalAndNoiseCalculator";
  TDirectoryFile * pedeProcessorFolder = (TDirectoryFile*) inputFile->Get( pedeProcessorFolderName.c_str() );
  
  if ( pedeProcessorFolder == 0 ) { 
    cerr << "No pedestal processor folder found in file " << inputFileName << endl;
    return ;
  }

  // this folder should contain one folder for each loop.
  string loopFolderName = "loop-" + toString( loop );
  TDirectoryFile * loopFolder = (TDirectoryFile *) pedeProcessorFolder->Get( loopFolderName.c_str() );
  
  if ( loopFolder == 0 ) {
    cerr << "No " << loopFolderName << " found in file " << inputFileName << endl;
    return ;
  }

  // guess the number of sensors from the number of subfolder in the loopfolder
  size_t nDetector = loopFolder->GetListOfKeys()->GetSize();
  cout << "This file contains " << nDetector << " detectors" << endl;

  // prepare arrays to store the mean and the rms of the noise distribution
  if ( noiseMean == NULL ) {
    delete [] noiseMean;
    noiseMean = NULL;
  }
  if ( noiseRMS == NULL ) {
    delete [] noiseRMS;
    noiseRMS = NULL;
  }
  if ( channel == NULL ) {
    delete [] channel;
    channel = NULL;
  }

  noiseMean = new double[ nDetector * kNChan ];
  noiseRMS  = new double[ nDetector * kNChan ];
  channel   = new double[ kNChan ];

  string canvasName = "comparison";
  string canvasTitle = "Noise comparison";

  TCanvas * comparisonCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  comparisonCanvas->Divide(1,2);
  
  TPad * topPad = (TPad*) comparisonCanvas->cd(1);
  topPad->Divide( nDetector );
  
  TPad * middlePad = (TPad *) comparisonCanvas->cd(2);
  middlePad->Divide( kNChan );


  // for each detector we have to get the noise map and to prepare 4
  // separe histos and maps
  for ( unsigned int iDetector = 0; iDetector < nDetector; iDetector++ ) {

    // get the noise map.
    string noiseMapName = "detector-" + toString( iDetector ) ;
    noiseMapName += "/NoiseMap-d" + toString( iDetector )  ;
    noiseMapName += "-l" + toString( loop ) ;
 
    TH2D * noiseMap = ( TH2D* ) loopFolder->Get( noiseMapName.c_str() ); 
    

    // create a folder in the output file
    TDirectory * subfolder = outputFile->mkdir( string( "detector_" + toString( iDetector ) ).c_str(),
						string( "detector_" + toString( iDetector ) ).c_str()
						);
    subfolder->cd();

    
    string canvasName = "det" + toString( iDetector );
    string canvasTitle = "Detector " + toString( iDetector );
    
    TCanvas * canvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
    canvas->Divide( kNChan, 2 );

    // ok now start the loop on channels
    for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) { 
	
      if ( iDetector == 0 ) channel[iChan] = iChan - 0.5;

      string tempName = "NoiseMap_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      string tempTitle = "NoiseMap Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ;

      TH2D * noiseMapCh = new TH2D ( tempName.c_str() , tempTitle.c_str(), 
				     kXPixel / kNChan , -0.5 + xLimit[ iChan ] , -0.5 + xLimit[ iChan + 1 ],
				     kYPixel, -0.5, -0.5 + kYPixel );
      noiseMapCh->SetXTitle("X [pixel]");
      noiseMapCh->SetYTitle("Y [pixel]");
      noiseMapCh->SetZTitle("Noise [ADC]");
      noiseMapCh->SetStats( false );
      outputHistoList->Add( noiseMapCh ) ;

      tempName = "NoiseDist_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      
      tempTitle = "NoiseDist Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ; 

      TH1D * noiseDistCh = new TH1D( tempName.c_str(), tempTitle.c_str(), 50, 0., 10. );
      noiseDistCh->SetXTitle("Noise [ADC]");
      noiseDistCh->SetLineColor( kColor[iDetector]  );
      noiseDistCh->SetLineStyle( iChan + 2 );
      noiseDistCh->SetLineWidth( 2 );
      outputHistoList->Add( noiseDistCh );

      // let's start looping on pixels now
      for ( size_t yPixel = 1 ; yPixel <= kYPixel ; ++yPixel ) {
	for ( size_t xPixel = xLimit[ iChan ] + 1; xPixel <= xLimit[ iChan +1 ] ; ++xPixel ) {
	  double noise = noiseMap->GetBinContent( xPixel , yPixel );
	  noiseMapCh->Fill( xPixel - 1 , yPixel - 1, noise );
	  noiseDistCh->Fill( noise );
	  
	}
      }

      canvas->cd( iChan + 1 ) ;
      noiseMapCh->Draw("colz");
      canvas->cd( iChan + kNChan + 1  );
      noiseDistCh->Draw();
      
      topPad->cd( iDetector + 1 );
      if ( iChan == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }

      middlePad->cd( iChan + 1 );
      if ( iDetector == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }


      noiseMean[ kNChan * iDetector + iChan ] = noiseDistCh->GetMean();
      noiseRMS[ kNChan * iDetector  + iChan ] = noiseDistCh->GetRMS();
    }
    canvas->Write();

  }

  canvasName = "summary";
  canvasTitle = "Noise summary";

  TCanvas * summaryCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  summaryCanvas->SetGridx(1);
  TLegend * legend = new TLegend(0.5, 4.8, 1.5, 4.3,"","br");;
  

  for ( size_t iDetector = 0 ; iDetector < nDetector ; ++iDetector ) {
    
    TGraphErrors * gr = new TGraphErrors( kNChan, channel, &noiseMean[ iDetector * kNChan ], NULL, &noiseRMS[ iDetector * kNChan ] );
    gr->SetName( string( "NoisePerChannel_d" + toString( iDetector )).c_str());
    gr->SetTitle(string("Detector " + toString( iDetector )).c_str());
    gr->GetXaxis()->SetTitle("Channel #");
    gr->GetYaxis()->SetTitle("Noise [ADC]");
    gr->GetXaxis()->SetNdivisions( 5 );
    gr->GetXaxis()->SetLabelSize( 0 );
    gr->SetMarkerStyle( iDetector + 1 );
    gr->SetMarkerColor( kColor[iDetector] );
    gr->SetLineColor( kColor[iDetector] );
    gr->SetLineWidth( 2 );

    
    legend->AddEntry( gr, string("Detector " + toString( iDetector )).c_str(), "LP");

    if ( iDetector == 0 ) {
      gr->Draw("ALP");
    } else {
      gr->Draw("LP");
    }
    

  }

  
  
  legend->Draw();

  for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) {
    
    TPaveLabel * label = new TPaveLabel( iChan - 0.75 , 3.2 , iChan -0.25 , 3, string("Ch " + toString( iChan ) ).c_str());
    label->Draw();
  }


  summaryCanvas->Write();
  comparisonCanvas->Write();

  outputHistoList->Write();

  

 
} 
TF1 *bFeedDownFraction(double ptMin=20,double ptMax=25)
{
/*
   TFile *infMCP = new TFile("miniNtuplePrompt.root");
   TFile *infMCNP = new TFile("miniNtupleNonPrompt.root");
   TFile *infData = new TFile("miniData.root");
*/

   TFile *infMCP = new TFile("ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root");
   TFile *infMCNP = new TFile("ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_nonprompt_D0_dPt0tkPt0p5_pthatweight.root");
   // TFile *infData = new TFile("miniData.root");
   TFile *infData = new TFile("ppData.root");
    
   TTree *tMCP = (TTree*)infMCP->Get("ntDkpi");
   TTree *tMCNP = (TTree*)infMCNP->Get("ntDkpi");
   TTree *tMCPHI = (TTree*)infMCP->Get("ntHi");
   TTree *tMCNPHI = (TTree*)infMCNP->Get("ntHi");
   TTree *tData = (TTree*)infData->Get("ntDkpi");
   tMCP->AddFriend(tMCPHI);
   tMCNP->AddFriend(tMCNPHI);
   
   
   TFile *outf = new TFile(Form("output-%.0f-%.0f.root",ptMin,ptMax),"recreate");
   TNtuple *nt = new TNtuple("nt","","ptMin:ptMax:Frac:FracErr");
   TCanvas *cSideband = new TCanvas("cSideband","Data Sideband",1200,1200);
   cSideband->Divide(2,2);
   cSideband->cd(1);


   TCut cutpp ="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>2.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk2PixelHit+Dtrk2StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)";
   TCut cutmc="(Dgen==23333||Dgen==23344)";
   TCut cutpt=Form("Dpt>%f&&Dpt<%f",ptMin,ptMax);
   TCut cutSignal = "abs(Dmass-1.8649)<0.025";
   TCut cutSideband = "abs(Dmass-1.8649)>0.075&&abs(Dmass-1.8649)<0.1";
 //  TCut weightfuncFtionreco="((TMath::Erf((log(DsvpvDisErr))*(Dgenpt*Dgenpt*(-0.001)+0.1021*Dgenpt+1.247)+(Dgenpt*Dgenpt*(-0.0032)+0.2912*Dgenpt+6.8275))+1))*(pow(10,-0.168499*Dgenpt+3.872855+Dgenpt*Dgenpt*0.000556)+pow(10,-0.068599*Dgenpt+2.512265+Dgenpt*Dgenpt*0.000331))";
   TCut weightfunctionreco = "pthatweight";
   int nBin=20;
   double binL=3.5;
   double binH=103.5;
   double fitRangeL=3.5;
   double fitRangeH=100.5;

   if (ptMax<=6) {
      fitRangeH=43.5;
      binH=43.5;
   }

   float bins[6+1]={3.5,5.5,8.5,10.5,20.5,30.5,50.5};
   
   TH1D *hSideband = new TH1D("hSideband","Sideband",nBin,binL,binH);
   TH1D *hData = new TH1D("hData","Data",nBin,binL,binH);
   TH1D *hMCPSignal = new TH1D("hMCPSignal","Prompt",nBin,binL,binH);
   TH1D *hMCNPSignal = new TH1D("hMCNPSignal","Non-prompt",nBin,binL,binH);
   TH1D *hMCPSideband = new TH1D("hMCPSideband","",nBin,binL,binH);
   TH1D *hMCNPSideband = new TH1D("hMCNPSideband","",nBin,binL,binH);
   hSideband->Sumw2();
   hData->Sumw2();
   hMCPSignal->Sumw2();
   hMCNPSignal->Sumw2();

   
   tData->Draw("(DsvpvDistance/DsvpvDisErr)>>hSideband",cutpt&&cutpp&&cutSideband);
   tData->Draw("(DsvpvDistance/DsvpvDisErr)>>hData",cutpt&&cutpp&&cutSignal);
   tMCP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCPSignal",weightfunctionreco*(cutpt&&cutpp&&cutSignal&&cutmc));
   //tMCP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCPSideband",cutpt&&cutpp&&cutSideband);
   tMCNP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCNPSignal",weightfunctionreco*(cutpt&&cutpp&&cutSignal&&cutmc));
   //tMCNP->Draw("(DsvpvDistance/DsvpvDisErr)>>hMCNPSideband",cutpt&&cutpp&&cutSideband);
   
   hSideband->Scale(1./1.);
   hData->Add(hSideband,-1);
   normalize(hData,1);
   normalize(hMCPSignal,2);
   normalize(hMCNPSignal,4);
   normalize(hSideband,kGreen+2);
   
   
   
   TF1 *fSideband = new TF1("fSideband","[0]*(exp([1]*x+[2])+[3]*exp([4]*x+[5])+[6]*exp([7]*x+[8]))");     
   TF1 *fMCPSignal = new TF1("fMCPSignal","[0]*(exp([1]*x+[2])+[3]*exp([4]*x+[5])+[6]*exp([7]*x+[8]))");
   TF1 *fMCNPSignal = new TF1("fMCNPSignal","[0]*(exp([1]*x+[2])+[3]*exp([4]*x+[5])+[6]*exp([7]*x+[8]))");
   
   fSideband->SetParameters(0,-0.1,0.2,-0,-2,0.006,-0.01,-0.11,-0.04,0,0.001);
   fMCNPSignal->SetParameters(0,-0.1,0.1,-0,-0.02,0.006,-0.01,-0.11,-0.04,0,0.001);
   fMCPSignal->SetParameters(0,-0.1,0.1,-0,-0.02,0.006,-0.01,-0.11,-0.04,0,0.001);
//   fMCNPSignal->FixParameter(3,0);
//   fMCPSignal->FixParameter(3,0);
   fMCPSignal->SetParLimits(1,-100,0);   
   fMCPSignal->SetParLimits(4,-100,0);   
   fMCPSignal->SetParLimits(7,-100,0);   
   fMCNPSignal->SetParLimits(1,-100,0);   
   fMCNPSignal->SetParLimits(4,-100,0);   
   fMCNPSignal->SetParLimits(7,-100,0);   
   fMCPSignal->SetParLimits(0,0,1e10);   
   fMCPSignal->SetParLimits(3,0,1e10);   
   fMCPSignal->SetParLimits(6,0,1e10);   
   fMCNPSignal->SetParLimits(0,0,1e10);   
   fMCNPSignal->SetParLimits(3,0,1e10);   
   fMCNPSignal->SetParLimits(6,0,1e10);   

   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   
   
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","LL q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","m q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","m q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband","m q","",fitRangeL,fitRangeH);
   hSideband->Fit("fSideband"," q","",fitRangeL,fitRangeH);
   double normSideband = hSideband->Integral(0,0.12);
   
   cSideband->cd(2);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","LL q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","m q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","m q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal","m q","",fitRangeL,fitRangeH);
   hMCPSignal->Fit("fMCPSignal"," m q","",fitRangeL,fitRangeH);
   double normMCPSignal = hMCPSignal->Integral(0,0.12);

   cSideband->cd(3);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","LL q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal"," q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   hMCNPSignal->Fit("fMCNPSignal","m q","",fitRangeL,fitRangeH);
   
   double normMCNPSignal = hMCNPSignal->Integral(0,0.12);
   
   
   string sSideband = Form("(%e)*(exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e)))",fSideband->GetParameter(0),fSideband->GetParameter(1),fSideband->GetParameter(2),fSideband->GetParameter(3),fSideband->GetParameter(4),fSideband->GetParameter(5),fSideband->GetParameter(6),fSideband->GetParameter(7),fSideband->GetParameter(8));
   string sMCPSignal = Form("(%e)*(exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e)))",fMCPSignal->GetParameter(0),fMCPSignal->GetParameter(1),fMCPSignal->GetParameter(2),fMCPSignal->GetParameter(3),fMCPSignal->GetParameter(4),fMCPSignal->GetParameter(5),fMCPSignal->GetParameter(6),fMCPSignal->GetParameter(7),fMCPSignal->GetParameter(8));
   
   string sMCNPSignal = Form("(%e)*(exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e))+(%e)*exp((%e)*x+(%e)))",fMCNPSignal->GetParameter(0),fMCNPSignal->GetParameter(1),fMCNPSignal->GetParameter(2),fMCNPSignal->GetParameter(3),fMCNPSignal->GetParameter(4),fMCNPSignal->GetParameter(5),fMCNPSignal->GetParameter(6),fMCNPSignal->GetParameter(7),fMCNPSignal->GetParameter(8));
   
   
   string function;
   function="0*("+sSideband+")+[1]*([2]*"+sMCPSignal+"+(1-[2])*("+sMCNPSignal+"))";
   string functionNP;
   functionNP="0*("+sSideband+")+[1]*(0*"+sMCPSignal+"+(1-[2])*("+sMCNPSignal+"))";
   
    
   TCanvas *cFit = new TCanvas("cFit","Fit",600,600);
   TF1 *f = new TF1("f",function.c_str());
   f->SetParameters(1,0.1,0.9,0,0.1);
   f->SetParLimits(0,0,1000);
   f->SetParLimits(2,-1,2);
   f->SetLineColor(2);
   f->SetFillColor(2);
   f->SetFillStyle(3001);
   f->Draw("same");   
   hData->SetAxisRange(fitRangeL,fitRangeH,"X");
   hData->Fit("f","LL");
   hData->Fit("f","LL");
   hData->Fit("f","LL");
   hData->Fit("f","LL");
   hData->Fit("f","m");
   hData->SetXTitle("Flight Distance Significance");
   hData->SetYTitle("Event Fraction");
   
   TF1 *fNP = new TF1("fNP",functionNP.c_str());
   fNP->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2));
   fNP->SetRange(fitRangeL,fitRangeH*2);
   fNP->SetLineColor(4);
   fNP->SetFillStyle(3001);
   fNP->SetFillColor(4);
   hData->SetStats(0);
   hData->Draw("same");
   fNP->Draw("same");  

   cout <<fNP->Integral(3.5,60)/f->Integral(3.5,60)<<endl;

   TLegend *leg = new TLegend(0.5,0.7,0.9,0.9);
   leg->SetBorderSize(0);
   leg->SetFillStyle(0);
   leg->AddEntry(hData,"pp data","pl");
   leg->AddEntry(f,Form("Prompt Fraction %.1f #pm %.1f %%",100*f->GetParameter(2),100*f->GetParError(2)),""); 
   leg->AddEntry(f,"Prompt D^{0}","f");
   leg->AddEntry(fNP,"Non-Prompt D^{0}","f");
   
   leg->Draw();
   
   cSideband->cd(4);
   hMCPSignal->Draw("hist");
   hSideband->Draw("hist same");
   hMCNPSignal->Draw("hist same");
   hData->Draw("same");
   nt->Fill(ptMin,ptMax,f->GetParameter(2),f->GetParError(2));
   nt->Write();
   outf->Write();
//   outf->Close();	
   return f;
}
Example #16
0
void etaPlotter(){

  double HFbins[6] = {0,10,15,20,30,70};
  double multBins[7] = {0,35,60,90,110,150,1000};
  
  TFile *f0 = new TFile("FullForest_v77_etaLT3_akPu3PF.root","OLD");
  if(!f0){ cout << "You don't have this jet collection yet!!" << endl; exit(0);}
  TTree *dijetTree = (TTree*)f0->Get("dijetTree");

  TFile *f2 = new TFile("PythiaPP_MC_akPu3PF.root","OLD");
  TTree *ppTree = (TTree*)f2->Get("dijetTree");

  TFile *f3 = new TFile("YaxianPPData_etaLT3_akPu3PF.root","OLD");
  TTree *ppDatTree = (TTree*)f3->Get("dijetTree");
  
  TFile *f4 = new TFile("PythiaMIT_out_v77_etaLT3_akPu3PF.root","OLD");
  TTree *mcTree = (TTree*)f4->Get("dijetTree");

  TFile *f5 = new TFile("PbPb_ReReco_Full_etaLT3_akPu3PF.root","OLD");
  TTree *pbpbtree = (TTree*)f5->Get("dijetTree");

  TH1D *etaDistropPb[6];
  TH1D *etaDistroppData[6];
  TH1D *etaDistroppMC[6];
  TH1D *etaDistropPbMC[6];
  TH1D *etaDistroPbPb[6];

  TH2D *avgEtapPb[3];
  TH2D *avgEtapp[3];
  TH2D *avgEtapPbMC[3];
  TH2D *avgEtappMC[3];

  char* histoname = new char[30];
  char* histotitle = new char[50];
  for(int i=0; i<6; i++){
    sprintf(histoname,"%s%d","etaDistropPb_",i+1);
    sprintf(histotitle,"%s%d","Dijet Eta distro, HF bin",i+1);
    if(i==5){ sprintf(histoname,"%s%d","etaDistropPb_",0); sprintf(histotitle,"%s%d","Dijet Eta distro, HF bin",0); }
    etaDistropPb[i] = new TH1D(histoname,histotitle,12,-3,3);
    etaDistropPb[i]->Sumw2();
    sprintf(histoname,"%s%d","etaDistroppData_",i);
    etaDistroppData[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroppData[i]->Sumw2();
    etaDistroppData[i]->SetMarkerColor(2);
    etaDistroppData[i]->SetLineColor(2);
    sprintf(histoname,"%s%d","etaDistroppMC_",i);
    etaDistroppMC[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroppMC[i]->Sumw2();
    etaDistroppMC[i]->SetMarkerColor(4);
    etaDistroppMC[i]->SetLineColor(4);
    sprintf(histoname,"%s%d","etaDistropPbMC_",i);
    etaDistropPbMC[i] = new TH1D(histoname,"",12,-3,3);
    etaDistropPbMC[i]->Sumw2();
    etaDistropPbMC[i]->SetMarkerColor(8);
    etaDistropPbMC[i]->SetLineColor(8);
    sprintf(histoname,"%s%d","etaDistroPbPb_",i);
    etaDistroPbPb[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroPbPb[i]->Sumw2();
    etaDistroPbPb[i]->SetMarkerColor(8);
    etaDistroPbPb[i]->SetLineColor(8);
  }
  for(int i=0; i<3; i++){
    sprintf(histoname,"%s%d","avgEtapPb_",i);
    avgEtapPb[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapPb[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtapp_",i);
    avgEtapp[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapp[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtapPbMC_",i);
    avgEtapPbMC[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapPbMC[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtappMC_",i);
    avgEtappMC[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtappMC[i]->Sumw2();
  }
  
  //pPb Data
  double pt1,pt2,phi1,phi2,eta1,eta2,hiHF,rawPt1,rawPt2, hiHFminus;
  bool PU;
  int tracks;
  dijetTree->SetBranchAddress("pt1",&pt1);
  dijetTree->SetBranchAddress("pt2",&pt2);
  dijetTree->SetBranchAddress("rawPt1",&rawPt1);
  dijetTree->SetBranchAddress("rawPt2",&rawPt2);
  dijetTree->SetBranchAddress("phi1",&phi1);
  dijetTree->SetBranchAddress("phi2",&phi2);
  dijetTree->SetBranchAddress("eta1",&eta1);
  dijetTree->SetBranchAddress("eta2",&eta2);
  dijetTree->SetBranchAddress("tracks",&tracks);
  dijetTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  dijetTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  dijetTree->SetBranchAddress("PUFilterGplus",&PU);
  for(int i=0; i<dijetTree->GetEntries(); i++){
    dijetTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && hiHF<70){
      avgEtapPb[0]->Fill(eta1,acos(cos(phi1-phi2)));
      avgEtapPb[1]->Fill(eta2,acos(cos(phi1-phi2)));
      avgEtapPb[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[0] && tracks<multBins[1] && */hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[2] && tracks<multBins[3] && */hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[3] && tracks<multBins[4] && */hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[4] && tracks<multBins[5] && */hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[5] && tracks<multBins[6] && */hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[4]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && acos(cos(phi1-phi2))>2.0944){
      etaDistropPb[5]->Fill((eta1+eta2)/2);
    }
  }

  //pPb MC
  double weight, MCentries, pthat;
  mcTree->SetBranchAddress("pt1",&pt1);
  mcTree->SetBranchAddress("pt2",&pt2);
  mcTree->SetBranchAddress("rawPt1",&rawPt1);
  mcTree->SetBranchAddress("rawPt2",&rawPt2);
  mcTree->SetBranchAddress("tracks",&tracks);
  mcTree->SetBranchAddress("pthat",&pthat);
  mcTree->SetBranchAddress("phi1",&phi1);
  mcTree->SetBranchAddress("phi2",&phi2);
  mcTree->SetBranchAddress("eta1",&eta1);
  mcTree->SetBranchAddress("eta2",&eta2);
  mcTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  mcTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  mcTree->SetBranchAddress("weight",&weight);
  mcTree->SetBranchAddress("MCpthatEntries",&MCentries);
  for(int i=0; i<mcTree->GetEntries(); i++){
    mcTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>50 && hiHF<70){
      avgEtapPbMC[0]->Fill(eta1,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtapPbMC[1]->Fill(eta2,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtapPbMC[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)),(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[0] && tracks<multBins[1] &&*/ hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[0]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[2] && tracks<multBins[3] && */hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[1]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[3] && tracks<multBins[4] && */hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[2]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[4] && tracks<multBins[5] && */hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[3]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[5] && tracks<multBins[6] && */hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[4]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
  }

  //pp MC
  ppTree->SetBranchAddress("pt1",&pt1);
  ppTree->SetBranchAddress("pt2",&pt2);
  ppTree->SetBranchAddress("rawPt1",&rawPt1);
  ppTree->SetBranchAddress("rawPt2",&rawPt2);
  ppTree->SetBranchAddress("weight",&weight);
  ppTree->SetBranchAddress("MCpthatEntries",&MCentries);
  ppTree->SetBranchAddress("phi1",&phi1);
  ppTree->SetBranchAddress("phi2",&phi2);
  ppTree->SetBranchAddress("eta1",&eta1);
  ppTree->SetBranchAddress("eta2",&eta2);
  ppTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  ppTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<ppTree->GetEntries(); i++){
    ppTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>50 && hiHF<70 && acos(cos(phi1-phi2)>2.0944)){
      avgEtappMC[0]->Fill(eta1,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtappMC[1]->Fill(eta2,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtappMC[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)),(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[0]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[1]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[2]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[3]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[4]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
  }

  //pp data
  ppDatTree->SetBranchAddress("pt1",&pt1);
  ppDatTree->SetBranchAddress("pt2",&pt2);
  ppDatTree->SetBranchAddress("rawPt1",&rawPt1);
  ppDatTree->SetBranchAddress("rawPt2",&rawPt2);
  ppDatTree->SetBranchAddress("phi1",&phi1);
  ppDatTree->SetBranchAddress("phi2",&phi2);
  ppDatTree->SetBranchAddress("eta1",&eta1);
  ppDatTree->SetBranchAddress("eta2",&eta2);
  ppDatTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  ppDatTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<ppDatTree->GetEntries(); i++){
    ppDatTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF<70){
      avgEtapp[0]->Fill(eta1,acos(cos(phi1-phi2)));
      avgEtapp[1]->Fill(eta2,acos(cos(phi1-phi2)));
      avgEtapp[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[4]->Fill((eta1+eta2)/2);
    }
  }

  pbpbtree->SetBranchAddress("pt1",&pt1);
  pbpbtree->SetBranchAddress("pt2",&pt2);
  pbpbtree->SetBranchAddress("rawPt1",&rawPt1);
  pbpbtree->SetBranchAddress("rawPt2",&rawPt2);
  pbpbtree->SetBranchAddress("phi1",&phi1);
  pbpbtree->SetBranchAddress("phi2",&phi2);
  pbpbtree->SetBranchAddress("eta1",&eta1);
  pbpbtree->SetBranchAddress("eta2",&eta2);
  pbpbtree->SetBranchAddress("hiHFplusEta4",&hiHF);
  pbpbtree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<pbpbtree->GetEntries(); i++){
    pbpbtree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<50 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=50 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[4]->Fill((eta1+eta2)/2);
    }
  }

  TCanvas *c2 = new TCanvas("c2","",1400,800);
  c2->cd();
  makeMultiPanelCanvas(c2,3,2,0.,0.,0.2,0.2,0.05);
  for(int i=0; i<5; i++){
    c2->cd(i+1);
    cout << "pPb:  " << etaDistropPb[i]->Integral() << endl;
    etaDistropPb[i]->Scale(1./etaDistropPb[i]->Integral());
    etaDistropPb[i]->SetMaximum(0.2);
    etaDistropPb[i]->SetYTitle("Event Fraction");
    etaDistropPb[i]->SetXTitle("(#eta_{1}+#eta_{2})/2");
    //etaDistropPb[i]->SetXTitle("#eta_{leading}");
    etaDistropPb[i]->Draw();
    cout << "ppMC:  " << etaDistroppMC[i]->Integral() << endl;
    etaDistroppMC[i]->Scale(1./etaDistroppMC[i]->Integral());
    etaDistroppMC[i]->Draw("same");
    etaDistropPbMC[i]->Scale(1./etaDistropPbMC[i]->Integral());
    etaDistropPbMC[i]->Draw("same");
    //if(etaDistroppData[i]->Integral() != 0){
    cout << "pp:  " << etaDistroppData[i]->Integral() << endl;
    etaDistroppData[i]->Scale(1./etaDistroppData[i]->Integral());
    etaDistroppData[i]->Draw("same");
    //}
    if(i==0){
      TLatex *l1 = new TLatex(0.5, 0.15,"E_{T}^{|#eta|<4}<20");
      l1->Draw();
    }
    if(i==1){
      TLatex *l2 = new TLatex(0.5, 0.15, "20#leqE_{T}^{|#eta|<4}<25");
      l2->Draw();
    }
    if(i==2){
      TLatex *l3 = new TLatex(0.5, 0.15, "25#leqE_{T}^{|#eta|<4}<30");
      l3->Draw();
    }
    if(i==3){
      TLatex *l4 = new TLatex(0.5, 0.15, "30#leqE_{T}^{|#eta|<4}<40");
      l4->Draw();
    }
    if(i==4){
      TLatex *l5 = new TLatex(0.5, 0.15, "40#leqE_{T}^{|#eta|<4}");
      l5->Draw();
    }
    if(i==0){
      TLegend *leg = new TLegend(0.2,0.77,0.80,0.91);
      leg->AddEntry(etaDistropPb[i],"pPb Data, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistroppMC[i], "pp PYTHIA MC, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistropPbMC[i], "pPb HIJING+PYTHIA MC, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistroppData[i], "pp Data, #sqrt{s}=2.76 TeV");
      leg->SetFillColor(0);
      leg->SetBorderSize(0);
      leg->Draw();
    }
  }
  
  TCanvas *c3 = new TCanvas("c3","",1400,600);
  c3->Divide(3,1);
  TH1D *profpPb[3];
  TH1D *profpp[3];
  TH1D *profpPbMC[3];
  TH1D *profppMC[3];
  for(int i=0; i<3; i++){
    c3->cd(i+1);
    profpPb[i] = avgEtapPb[i]->ProfileX();
    profpPb[i]->SetMaximum(3.0);
    profpPb[i]->SetMinimum(2.81);
    if(i==0) profpPb[i]->SetXTitle("#eta_{leading}");
    if(i==1) profpPb[i]->SetXTitle("#eta_{subleading}");
    if(i==2) profpPb[i]->SetXTitle("(#eta_{1}+#eta_{2})/2");
    profpPb[i]->SetYTitle("<#Delta#phi>");
    //profpPb[i]->Scale(1./profpPb[i]->Integral());
    profpPb[i]->Draw();
    profpp[i] = avgEtapp[i]->ProfileX();
    //profpp[i]->Scale(1./profpp[i]->Integral());
    profpp[i]->SetMarkerColor(4);
    profpp[i]->SetLineColor(4);
    profpp[i]->Draw("same");
    profpPbMC[i] = avgEtapPbMC[i]->ProfileX();
    //profpPbMC[i]->Scale(1./profpPbMC[i]->Integral());
    profpPbMC[i]->SetMarkerColor(2);
    profpPbMC[i]->SetLineColor(2);
    profpPbMC[i]->Draw("same");
    profppMC[i] = avgEtappMC[i]->ProfileX();
    // profppMC[i]->Scale(1./profppMC[i]->Integral());
    profppMC[i]->SetMarkerColor(8);
    profppMC[i]->SetLineColor(8);
    profppMC[i]->Draw("same");
  }

  //Plot mean
  /*Double_t pPb_nmult[5] = {5.658, 12.3924,17.3349,24.0448,36.3906};
  Double_t pPb_avgPt[5] = {etaDistropPb[0]->GetMean(), etaDistropPb[1]->GetMean(), etaDistropPb[2]->GetMean(), etaDistropPb[3]->GetMean(), etaDistropPb[4]->GetMean()};
  Double_t pPb_nmultErr[5] = {0.0097,0.01997,0.028038,0.0343,0.07198};
  Double_t pPb_avgPtErr[5] = {etaDistropPb[0]->GetMeanError(), etaDistropPb[1]->GetMeanError(), etaDistropPb[2]->GetMeanError(), etaDistropPb[3]->GetMeanError(), etaDistropPb[4]->GetMeanError()};

  Double_t MC_nmult[5] = {5.20261,12.3461,17.3005,23.8401,34.7769};
  Double_t MC_avgPt[5] = {etaDistropPbMC[0]->GetMean(), etaDistropPbMC[1]->GetMean(), etaDistropPbMC[2]->GetMean(), etaDistropPbMC[3]->GetMean(), etaDistropPbMC[4]->GetMean()};
  Double_t MC_nmultErr[5] = {0.0043,0.01139,0.01656.0.0211,0.0549};
  Double_t MC_avgPtErr[5] = {etaDistropPbMC[0]->GetMeanError(), etaDistropPbMC[1]->GetMeanError(), etaDistropPbMC[2]->GetMeanError(), etaDistropPbMC[3]->GetMeanError(), etaDistropPbMC[4]->GetMeanError()};

  Double_t PbPb_nmult[4] = {11.6405,30.6015,49.7908,64.897};
  Double_t PbPb_avgPt[4] = {etaDistroPbPb[0]->GetMean(), etaDistroPbPb[1]->GetMean(), etaDistroPbPb[2]->GetMean(), etaDistroPbPb[3]->GetMean()};
  Double_t PbPb_nmultErr[4] = {0.2618,0.2188,0.1961,0.1493};
  Double_t PbPb_avgPtErr[4] = {etaDistroPbPb[0]->GetMeanError(), etaDistroPbPb[1]->GetMeanError(), etaDistroPbPb[2]->GetMeanError(), etaDistroPbPb[3]->GetMeanError()};*/

 
  //Double_t pPb_nmult[5] = {5.658, 12.3924,17.3349,24.0448,36.3906}; //for hiHFplusEta4
  Double_t pPb_nmult[5] = {12.699,22.424,27.356,34.192,47.624}; //for HFplusEta4 + HFminusEta4
  Double_t pPb_avgPt[5] = {findDelPhiAngle(etaDistropPb[0],1), findDelPhiAngle(etaDistropPb[1],1), findDelPhiAngle(etaDistropPb[2],1), findDelPhiAngle(etaDistropPb[3],1), findDelPhiAngle(etaDistropPb[4],1)};
  Double_t pPb_nmultErr[5] = {0.012, 0.0296, 0.0375, 0.0406, 0.0715};
  Double_t pPb_avgPtErr[5] = {findDelPhiAngle(etaDistropPb[0],2), findDelPhiAngle(etaDistropPb[1],2), findDelPhiAngle(etaDistropPb[2],2), findDelPhiAngle(etaDistropPb[3],2), findDelPhiAngle(etaDistropPb[4],2)};

  //Double_t MC_nmult[5] = {5.20261,12.3461,17.3005,23.8401,34.7769}; //for hiHFplusEta4
  Double_t MC_nmult[5] = {11.9707, 22.4454, 27.4279, 34.4833, 47.2613}; //for hiHFplusEta4 + hiHFminusEta4
  //Double_t MC_nmult[5] = {1,3,5,8,12}; //for signal only sample
  Double_t MC_avgPt[5] = {findDelPhiAngle(etaDistropPbMC[0],1), findDelPhiAngle(etaDistropPbMC[1],1), findDelPhiAngle(etaDistropPbMC[2],1), findDelPhiAngle(etaDistropPbMC[3],1), findDelPhiAngle(etaDistropPbMC[4],1)};
  Double_t MC_nmultErr[5] = {0.004,0.013,0.015,0.015,0.022};
  Double_t MC_avgPtErr[5] = {findDelPhiAngle(etaDistropPbMC[0],2), findDelPhiAngle(etaDistropPbMC[1],2), findDelPhiAngle(etaDistropPbMC[2],2), findDelPhiAngle(etaDistropPbMC[3],2), findDelPhiAngle(etaDistropPbMC[4],2)};

  Double_t PbPb_nmult[3] = {15.1924, 37.45, 71.267};
  Double_t PbPb_avgPt[3] = {findDelPhiAngle(etaDistroPbPb[0],1), findDelPhiAngle(etaDistroPbPb[1],1), findDelPhiAngle(etaDistroPbPb[2],1)};
  Double_t PbPb_nmultErr[3] = {0.274, 0.296, 0.262};
  Double_t PbPb_avgPtErr[3] = {findDelPhiAngle(etaDistroPbPb[0],2), findDelPhiAngle(etaDistroPbPb[1],2), findDelPhiAngle(etaDistroPbPb[2],2)};

  Double_t pp_nmult[4] = {6.504, 21.78, 26.17, 31.65};
  Double_t pp_avgPt[4] = {findDelPhiAngle(etaDistroppData[0],1), findDelPhiAngle(etaDistroppData[1],1), findDelPhiAngle(etaDistroppData[2],1), findDelPhiAngle(etaDistroppData[3],1)};
  Double_t pp_nmultErr[4] = {0.04, 1.29, 3.62, 5.63};
  Double_t pp_avgPtErr[4] = {findDelPhiAngle(etaDistroppData[0],2), findDelPhiAngle(etaDistroppData[1],2), findDelPhiAngle(etaDistroppData[2],2), findDelPhiAngle(etaDistroppData[3],2)};

  /* TH1D *ppSum = etaDistroppData[0]->Clone("ppSum");
  for(int i=1; i<5; i++){
    ppSum->Add(etaDistroppData[i]);
  }
  Double_t pp_nmult[1] = {3.5};
  Double_t pp_nmultErr[1] = {0.1};
  Double_t pp_avgPt[1] = {findDelPhiAngle(ppSum,1)};
  Double_t pp_avgPtErr[1] = {findDelPhiAngle(ppSum,2)};*/

  TGraphErrors *centr2[3];
  centr2[0] = new TGraphErrors(5,pPb_nmult, pPb_avgPt, pPb_nmultErr, pPb_avgPtErr);
  centr2[1] = new TGraphErrors(3,PbPb_nmult, PbPb_avgPt, PbPb_nmultErr, PbPb_avgPtErr);
  centr2[2] = new TGraphErrors(5,MC_nmult, MC_avgPt, MC_nmultErr, MC_avgPtErr);
  centr2[3] = new TGraphErrors(1,pp_nmult, pp_avgPt, pp_nmultErr, pp_avgPtErr);
  TLatex *label1 = new TLatex(40,0.1,"|#eta|< 3");
  TH1D *temp = new TH1D("temp","",1,0,60);
  temp->SetMaximum(-0.1);
  temp->SetMinimum(-0.7);
  temp->SetXTitle("E_{T}^{HF[|#eta|>4]}");
  temp->SetYTitle("((#eta_{1}+#eta_{2})/2)_{#mu}");
  temp->GetXaxis()->CenterTitle();
  temp->GetYaxis()->CenterTitle();
  temp->GetYaxis()->SetLabelSize(0.08);
  temp->GetYaxis()->SetTitleOffset(0.5);
  temp->SetTitleSize(0.1, "y");
  temp->GetXaxis()->SetLabelSize(0.08);
  //temp->GetXaxis()->SetTitleOffset(0.5);
  temp->SetTitleSize(0.1, "x");
  TCanvas *c4 = new TCanvas("c4","",600,600);
  c4->cd();
  temp->Draw();
  centr2[0]->Draw("P,same");
  centr2[1]->SetLineColor(8);
  centr2[1]->SetMarkerColor(8);
  centr2[1]->SetMarkerStyle(25);
  //centr2[1]->Draw("P,same");
  centr2[2]->SetLineColor(2);
  centr2[2]->SetMarkerColor(2);
  centr2[2]->Draw("P,same");
  centr2[3]->SetMarkerColor(4);
  centr2[3]->SetLineColor(4);
  centr2[3]->SetMarkerStyle(24);
  //centr2[3]->Draw("P,same");
  //label1->Draw();

  etaDistropPb[0]->Scale(1./etaDistropPb[0]->Integral());
  TFile *fout = new TFile("hist_output_etaLT3_akPu3PF_ForPawan.root","UPDATE");
  fout->cd();
  for(int i=0; i<6; i++){
    etaDistropPb[i]->Write();
  }
  centr2[0]->SetNameTitle("dijEta","Dijet Eta vs Hf");
  centr2[0]->Write();
  fout->Close();
}
Example #17
0
TF1* fitDstar5prongs(TTree* nt, Double_t ptmin, Double_t ptmax)
{
  static int count5p=0;
  count5p++;
  
  TCanvas* c = new TCanvas(Form("c_5p_%d",count5p),"",600,600);
  TH1D* h = new TH1D(Form("h_5p_%d",count5p),"",60,0.140,0.160);
  TF1* f = new TF1(Form("f_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x+[5]*((1-[8])*TMath::Gaus(x,[6],[7])/(sqrt(2*3.14159)*[7])+[8]*TMath::Gaus(x,[6],[9])/(sqrt(2*3.14159)*[9]))",minmass3prong,maxmass3prong);
  nt->Project(Form("h_5p_%d",count5p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata5p.Data(),triggerselection[isData].Data(),ptmin,ptmax));   
    
  f->SetLineColor(4);
  f->SetParameters(0,0,0,0,0,2e2,1.45491e-1,9e-4,0.1,8e-4);
  f->FixParameter(9,15e-4);
  f->FixParameter(6,0.145491);
  f->FixParameter(7,8e-4);
  f->SetParLimits(8,0,1);
  f->SetParLimits(5,0,100000);
  h->Fit(Form("f_5p_%d",count5p),"LL");
  h->Fit(Form("f_5p_%d",count5p),"LL");
  h->Fit(Form("f_5p_%d",count5p),"LL","",minmass3prong,maxmass3prong);
  f->ReleaseParameter(6);
  f->ReleaseParameter(7);
  f->ReleaseParameter(9);
  f->SetParLimits(6,0.144,0.147);
  f->SetParLimits(7,1e-4,9e-4);
  f->SetParLimits(9,1e-4,9e-4);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.148);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.142,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16);
  h->Fit(Form("f_5p_%d",count5p),"LL","",0.141,0.16);

  TF1* background = new TF1(Form("background_5p_%d",count5p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x");
  background->SetParameter(0,f->GetParameter(0));
  background->SetParameter(1,f->GetParameter(1));
  background->SetParameter(2,f->GetParameter(2));
  background->SetParameter(3,f->GetParameter(3));
  background->SetParameter(4,f->GetParameter(4));
  background->SetLineColor(4);
  background->SetRange(minmass3prong,maxmass3prong);
  background->SetLineStyle(2);
  
  TF1* mass = new TF1(Form("fmass_5p_%d",count5p),"[0]*((1-[3])*TMath::Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+[3]*TMath::Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
  mass->SetParameters(f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8),f->GetParameter(9));
  mass->SetParError(0,f->GetParError(5));
  mass->SetParError(1,f->GetParError(6));
  mass->SetParError(2,f->GetParError(7));
  mass->SetParError(3,f->GetParError(8));
  mass->SetParError(4,f->GetParError(9));
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);
    
  h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})");
  h->SetYTitle("Entries / (1/3 MeV/c^{2})");
  h->SetStats(0);
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
  h->GetXaxis()->SetTitleOffset(1.3);
  h->GetYaxis()->SetTitleOffset(1.8);
  h->GetXaxis()->SetLabelOffset(0.007);
  h->GetYaxis()->SetLabelOffset(0.007);
  h->GetXaxis()->SetTitleSize(0.045);
  h->GetYaxis()->SetTitleSize(0.045);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.04);
  h->GetYaxis()->SetLabelSize(0.04);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);
  h->SetStats(0);
  h->Draw("e");

  background->Draw("same");   
  mass->SetRange(0.142,0.152);	
  mass->Draw("same");
  f->Draw("same");
  
  Double_t yield = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong;
  Double_t yieldErr = mass->Integral(minmass5prong,maxmass5prong)/binwidth5prong*mass->GetParError(0)/mass->GetParameter(0);

  TLatex* tex;
  TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.20,0.79,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  c->SaveAs(Form("plots/pp/DMass_%s_5prongs-%d.pdf",texData[isData].Data(),count5p));
  
  return mass;
}
Example #18
0
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax){   
   //cout<<cut.Data()<<endl;
   static int count=0;
   count++;

   TCanvas *c= new TCanvas(Form("c%d",count),"",600,600);
   TH1D *h = new TH1D(Form("h%d",count),"",50,5,6);
   TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6);

   TString iNP="(7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01)))";
   TF1* fNP = new TF1("fNP",iNP);
   float normNP = fNP->Integral(5,6);
   TString signal = "([5]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[5])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))";
   TF1 *f = new TF1(Form("f%d",count),Form("[0]*%s+[3]+[4]*x+(%s/%f)*([0]/%f)",signal.Data(),iNP.Data(),Ratio*(1+Change),normNP));

   nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax));   
   ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax));   
   clean0(h);
   h->Draw();
   f->SetParLimits(4,-1000,0);
   f->SetParLimits(2,0.01,0.05);
   f->SetParLimits(6,0.01,0.05);
   f->SetParLimits(5,0,1);

   f->SetParameter(0,setparam0);
   f->SetParameter(1,setparam1);
   f->SetParameter(2,setparam2);
   f->SetParameter(6,setparam3);
   f->FixParameter(1,fixparam1);
   h->GetEntries();

   hMC->Fit(Form("f%d",count),"q","",5,6);
   hMC->Fit(Form("f%d",count),"q","",5,6);
   f->ReleaseParameter(1);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L m","",5,6);

   f->FixParameter(1,f->GetParameter(1));
   f->FixParameter(2,f->GetParameter(2));
   f->FixParameter(5,f->GetParameter(5));
   f->FixParameter(6,f->GetParameter(6));
   
   h->Fit(Form("f%d",count),"q","",5,6);
   h->Fit(Form("f%d",count),"q","",5,6);
   f->ReleaseParameter(1);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L m","",5,6);
   h->SetMarkerSize(0.8);
   h->SetMarkerStyle(20);
   cout <<h->GetEntries()<<endl;

   // function for background shape plotting. take the fit result from f
   TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x");
   background->SetParameter(0,f->GetParameter(3));
   background->SetParameter(1,f->GetParameter(4));
   background->SetLineColor(4);
   background->SetRange(5,6);
   background->SetLineStyle(2);
   
   //cout<<"======="<<normNP<<"======="<<endl;
   // function for signal shape plotting. take the fit result from f
   TF1 *Bkpi = new TF1(Form("fBkpi",count),Form("([0]/(%f*%f))*%s",Ratio*(1+Change),normNP,iNP.Data()));
   Bkpi->SetParameter(0,f->GetParameter(0));
   Bkpi->SetLineColor(kGreen+1);
   Bkpi->SetFillColor(kGreen+1);
//   Bkpi->SetRange(5.00,5.28);
   Bkpi->SetRange(5.00,6.00);
   Bkpi->SetLineStyle(1);
   Bkpi->SetFillStyle(3004);

   // function for signal shape plotting. take the fit result from f
   TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
   mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(5),f->GetParameter(6));
   mass->SetParError(0,f->GetParError(0));
   mass->SetParError(1,f->GetParError(1));
   mass->SetParError(2,f->GetParError(2));
   mass->SetParError(3,f->GetParError(7));
   mass->SetParError(4,f->GetParError(8));
   mass->SetLineColor(2);
   mass->SetLineStyle(2);

   double yield = mass->Integral(5,6)/0.02;
   double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0);

//   cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl;
   h->SetMarkerStyle(24);
   h->SetStats(0);
   h->Draw("e");   
   h->SetXTitle("M_{B} (GeV/c^{2})");
   h->SetYTitle("Entries / (20 MeV/c^{2})");
   h->GetXaxis()->CenterTitle();
   h->GetYaxis()->CenterTitle();
   h->SetTitleOffset(1.5,"Y");
   h->SetAxisRange(0,h->GetMaximum()*1.2,"Y");
   Bkpi->Draw("same");
   background->Draw("same");   
   mass->SetRange(5,6);
   mass->Draw("same");
   mass->SetLineStyle(2);
   mass->SetFillStyle(3004);
   mass->SetFillColor(2);
   f->Draw("same");

   // Draw the legend:)   
   TLegend *leg = myLegend(0.50,0.5,0.86,0.89);
   leg->AddEntry(h,"CMS Preliminary","");
   leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV","");
   leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),"");
   leg->AddEntry(h,"Data","pl");
   leg->AddEntry(f,"Fit","l");
   leg->AddEntry(mass,"Signal","f");
   leg->AddEntry(background,"Combinatorial Background","l");
   leg->AddEntry(Bkpi,"Non-prompt J/#psi","f");
   leg->Draw();
   TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50);
   leg2->AddEntry(h,"B^{+} meson","");
   leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),"");
   leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f", yield, yieldErr),"");
   leg2->Draw();
   TLegend *leg3 = myLegend(0.02,0.83,0.37,0.92);
   if(Change==0) leg3->AddEntry((TObject*)0,Form("Ratio=%.2f",Ratio),"");
   else leg3->AddEntry((TObject*)0,Form("Ratio=%.2f(%.1f%)",Ratio*(1+Change),Change*100),"");
   leg3->Draw();

   if(Change==0) c->SaveAs("BplusApplyRatio.pdf");
   if(Change>0) c->SaveAs("BplusApplyRatioPlus.pdf");
   if(Change<0) c->SaveAs("BplusApplyRatioMinus.pdf");

   return mass;
}
Example #19
0
TF1* fit(float ptmin, float ptmax, int s, int b, int widVar)
{

    static int count=0;
    count++;

  TCanvas* c = new TCanvas(Form("c_%.0f_%.0f",ptmin,ptmax),"",400,400);
  TFile* infile = new TFile(Form("%s/%s_%.0f_%.0f.root",infname.Data(),collisionsystem.Data(),ptmin,ptmax));
  TH1D* h = (TH1D*)infile->Get("h");                    h->SetName(Form("h_%.0f_%.0f",ptmin,ptmax));
  TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal");    hMCSignal->SetName(Form("hMCSignal_%.0f_%.0f",ptmin,ptmax));
    
  TF1* f;  
  TF1* background;
  TF1* bkpi;
  TF1* mass;

  if(b==0) f = new TF1(Form("f%d",count),Form("%s+%s+%s",sig[s].Data(),sig_bkg[s].Data(),bkgerf.Data()), 5.0, 6.0);
  else f = new TF1(Form("f%d",count),Form("%s+%s+%s",sig[s].Data(),bkg[b].Data(),bkgerf.Data()), 5.0, 6.0);

    clean0(h);
    h->Draw();

    double hmin = h->GetBinContent(h->GetMinimumBin());
    double hmax = h->GetBinContent(h->GetMaximumBin());
    double havg = h->Integral();

    double mcmin = hMCSignal->GetBinContent(h->GetMinimumBin());
    double mcmax = hMCSignal->GetBinContent(h->GetMaximumBin());
    double mcavg = hMCSignal->Integral();

    f->SetParLimits(0,0,2*hmax);
    f->SetParLimits(1,5.27,5.29);
    f->SetParLimits(2,0.01,0.05);
    f->SetParLimits(8,0.01,0.05);
    f->SetParLimits(7,0,1);
    f->SetParLimits(6,0,1);
    if(s==1) f->SetParLimits(9,0,1);
    //if(s==2) f->SetParLimits(10,1,10);
    if(b==0 && sigmax[s]==8)
    {
	//f->SetParLimits(9,0.5*hmin,1.5*hmax);
	f->SetParLimits(10,-1000,0);
    }
    if(b==0 && sigmax[s]==10)
    {
	//f->SetParLimits(11,0.5*hmin,1.5*hmax);
	f->SetParLimits(12,-1000,0);
    }
    if(b==3)
    {
	//f->SetParLimits(9,0,1.5*hmax);
	f->SetParLimits(10,-100,0);
    }

    f->SetParLimits(3,0,1000);
    f->FixParameter(4,NPpar[0]);
    f->FixParameter(5,NPpar[1]);

    f->SetParameter(0,100);
    f->SetParameter(1,5.28);
    f->SetParameter(2,0.05);
    f->SetParameter(8,0.03);

    f->FixParameter(1,5.279);
    f->FixParameter(3,0);
    if(s==2) f->FixParameter(7,0);

    if(s>0 && bkgmax[b]>=11) f->FixParameter(11,0);
    if(s>0 && bkgmax[b]>=12) f->FixParameter(12,0); 
 
    h->GetEntries();
    hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
    hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
    f->ReleaseParameter(1);
    f->SetParLimits(1,5.27,5.29);
    hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
    hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
    hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
    hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);

    f->FixParameter(1,f->GetParameter(1));
    f->FixParameter(2,f->GetParameter(2));  
    f->FixParameter(7,f->GetParameter(7)); 
    f->FixParameter(8,f->GetParameter(8));
    f->FixParameter(6,f->GetParameter(6));
    if(sigmax[s]>=9) f->FixParameter(9,f->GetParameter(9));
    if(sigmax[s]>=10) f->FixParameter(10,f->GetParameter(10));

    if(s==2) 
    {
	f->ReleaseParameter(7);
	f->SetParLimits(7,0,1);
    }
 
    if(s>0 && bkgmax[b]>=11) f->ReleaseParameter(11);
    if(s>0 && bkgmax[b]>=12) f->ReleaseParameter(12); 
    f->ReleaseParameter(3);
    f->SetParLimits(3,0,1000);
 
    h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
    h->Fit(Form("f%d",count),"q","",minhisto,maxhisto);
    f->ReleaseParameter(1);
    f->SetParLimits(1,5.27,5.29);
    h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
    h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
    h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto);
    h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto);
    
    if(b==0)
    {
	background = new TF1(Form("background%d",count),bkg_new[b].Data(),minhisto,maxhisto);
	background->SetParameter(0,f->GetParameter(sigmax[s]+1));
	background->SetParameter(1,f->GetParameter(sigmax[s]+2));
    }
    else
    {
	background = new TF1(Form("background%d",count),bkg_new[b].Data(),minhisto,maxhisto);
	background->SetParameter(0,f->GetParameter(9));
	background->SetParameter(1,f->GetParameter(10));
	if(bkgmax[b]>=11) background->SetParameter(2,f->GetParameter(11));
	if(bkgmax[b]>=12) background->SetParameter(3,f->GetParameter(12));
    }

    bkpi = new TF1(Form("bpki%d",count),bkgerf_new.Data(),minhisto,maxhisto);
    bkpi->SetParameter(0,f->GetParameter(3));
    bkpi->SetParameter(1,NPpar[0]);
    bkpi->SetParameter(2,NPpar[1]);

    mass = new TF1(Form("fmass%d",count),sig_new[s].Data(),minhisto,maxhisto);
    if(s==0 || s==3) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6));
    if(s==1) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6),f->GetParameter(9));
    if(s==2) mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8),f->GetParameter(6),f->GetParameter(9),f->GetParameter(10));

    mass->SetParError(0,f->GetParError(0));
    mass->SetParError(1,f->GetParError(1));
    mass->SetParError(2,f->GetParError(2));
    mass->SetParError(3,f->GetParError(7));
    mass->SetParError(4,f->GetParError(8));
    mass->SetParError(5,f->GetParError(6));
    if(sigmax[s]>=9) mass->SetParError(6,f->GetParError(9));
    if(sigmax[s]>=10) mass->SetParError(7,f->GetParError(10));

      f->SetLineColor(kRed);
      f->SetLineWidth(2);

   background->SetLineColor(4);
   background->SetLineStyle(2);
   background->SetLineWidth(3);
   background->SetRange(minhisto,maxhisto);
   
   bkpi->SetFillColor(kGreen+4);
   bkpi->SetFillStyle(3005);
   bkpi->SetLineColor(kGreen+4);
   bkpi->SetLineWidth(3);

   mass->SetLineColor(kOrange-3);
   mass->SetLineStyle(2);
   mass->SetLineWidth(3);
   mass->SetFillColor(kOrange-3);
   mass->SetFillStyle(3002);

  h->SetXTitle("m_{#mu#muK} (GeV/c^{2})");
  h->SetYTitle("Entries / (5 MeV/c^{2})");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
  h->GetXaxis()->SetTitleOffset(1.0);
  h->GetYaxis()->SetTitleOffset(1.5);
  h->GetXaxis()->SetLabelOffset(0.008);
  h->GetYaxis()->SetLabelOffset(0.008);
  h->GetXaxis()->SetTitleSize(0.060);
  h->GetYaxis()->SetTitleSize(0.060);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.06);
  h->GetYaxis()->SetLabelSize(0.06);
  h->Draw("e");
  
  double axisymin = -0.05;
  h->SetAxisRange(axisymin,h->GetMaximum()*1.2,"Y");
  h->GetXaxis()->SetNdivisions(-50205);
  int ci = TColor::GetColor("#000099");
  h->SetLineColor(ci);
  h->SetStats(0);
  
      h->SetMarkerStyle(20); // 24?
      h->SetMarkerSize(0.8);

   h->Draw("e");
   bkpi->Draw("same");
   background->Draw("same");   
   mass->SetRange(minhisto,maxhisto);
   mass->Draw("same");
   f->Draw("same");

   yield = mass->Integral(minhisto,maxhisto)/binwidthmass;
   yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0);

  TLegend* leg = new TLegend(0.55,0.45,0.875,0.76,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.05);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"B^{+} Signal","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->AddEntry(bkpi,"B #rightarrow J/#psi X","f");
  leg->Draw("same");

  TLatex* texCms = new TLatex(0.225,0.87, "#scale[1.25]{CMS} Preliminary");
  texCms->SetNDC();
  texCms->SetTextAlign(12);
  texCms->SetTextSize(0.04);
  texCms->SetTextFont(42);
  texCms->Draw();

  TLatex* texCol;
  if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.39,0.94, Form("25.8 pb^{-1} (%s #sqrt{s_{NN}} = 5.02 TeV)","pp"));
  else texCol= new TLatex(0.35,0.94, Form("345 #mub^{-1} (%s #sqrt{s_{NN}} = 5.02 TeV)","PbPb"));
  texCol->SetNDC();
  texCol->SetTextSize(0.05);
  texCol->SetLineWidth(2);
  texCol->SetTextFont(42);
  texCol->Draw();

  TLatex* tex;
  
  tex = new TLatex(0.53,0.85,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.05);
  tex->SetLineWidth(2);
  tex->Draw();
  
  if(centmax>0){
  TString texper="%";
  tex = new TLatex(0.225,0.78,Form("Centrality %.0f-%.0f%s",centmin,centmax,texper.Data()));//0.2612903,0.8425793
  tex->SetNDC();
  tex->SetTextColor(1);
  tex->SetTextFont(42);
  tex->SetTextSize(0.05);
  tex->SetLineWidth(2);
  tex->Draw();
  }

  tex = new TLatex(0.77,0.78,"|y_{lab}| < 2.4");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.05);
  tex->SetLineWidth(2);
  tex->Draw();

  tex = new TLatex(0.30,0.54,"B^{+}");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.06);
  tex->SetLineWidth(2);
  tex->Draw();

    if(widVar==0) 
      c->SaveAs(Form("SystPDF/%s_%s_%s_%.0f_%.0f.pdf",collisionsystem.Data(),signame[s].Data(),bkgname[b].Data(),ptmin,ptmax));
    else
      c->SaveAs(Form("SystPDF/%s_%s_%.0f_%.0f.pdf",collisionsystem.Data(),"widvar",ptmin,ptmax));

    return mass;
}
Example #20
0
void comparePhi(double ajMin=0,double ajMax=1)
{
    char *title="";
    TFile *inf = new TFile("ntv3_data50v2_djcalo_100_50.root");
    TTree *tData = (TTree*) inf->FindObjectAny("ntjt");
    TFile *inf2 = new TFile("ntv3_dj_HyUQ80v3_djcalo_100_50.root");
    TTree *tMC = (TTree*) inf2->FindObjectAny("ntjt");

    const int nBin = 10;
    double delta = 0.0; //shift
    double Bins[nBin+1];
    double BinsMC[nBin+1];
    for (int i=0; i<nBin+1; i++)
    {
        Bins[i]=-PI+2*PI/(double)nBin*i;
        BinsMC[i]=-PI+2*PI/(double)nBin*i+delta;
        cout <<Bins[i]<<endl;
    }



    TCanvas *c = new TCanvas("c","",600,600);

    TH1D *p = new TH1D("p","",nBin,BinsMC);
    TH1D *p2 = new TH1D("p2","",nBin,BinsMC);
    p->Sumw2();
    p2->Sumw2();

    TCut evtCut = Form("Aj>%f&&Aj<%f&&nljet>120&&abs(nljetacorr)<1.6&&aljet>50&&abs(aljetacorr)<1.6&&!maskEvt&&cent<30&&abs(jdphi)>2./3.*3.14159",ajMin,ajMax);

    tMC->Draw("nljphi>>p",evtCut*"weight");
    tData->Draw("nljphi>>p2",evtCut);


    p->SetMarkerStyle(20);
    p2->SetMarkerStyle(25);
    p->Scale(1./p->Integral());
    p2->Scale(1./p2->Integral());
    p->SetAxisRange(0,0.25,"Y");
    p->Draw();
    p2->SetMarkerColor(2);
    p2->SetLineColor(2);
    p2->Draw("same");

    p->SetXTitle("#phi_{Leading Jet}");
    p->SetYTitle("Event fraction");

// ====================
    TLegend *leg = new TLegend(0.45,0.68,0.92,0.9);
    leg->SetFillStyle(0);
    leg->SetBorderSize(0);
    leg->SetTextFont(63);
    leg->SetTextSize(16);
    leg->AddEntry("p",Form("%.2f < A_{J} < %.2f",ajMin,ajMax),"");
    leg->AddEntry("p","PYTHIA + HYDJET","pl");
    leg->AddEntry("p2","Data","pl");
    leg->Draw();

    c->SaveAs(Form("compareJetPhi-%.2f-%.2f.gif",ajMin,ajMax));
    c->SaveAs(Form("compareJetPhi-%.2f-%.2f.eps",ajMin,ajMax));


    TCanvas *c2 = new TCanvas("c2","",600,0,600,600);
    TH1D *hRatio = (TH1D*)p->Clone();
    hRatio->SetName("hRatio");
    hRatio->Divide(p2);
    hRatio->SetAxisRange(0.5,3,"Y");
    hRatio->SetYTitle("MC / Data");
    hRatio->Draw();

    TLine *l = new TLine(Bins[0],1,PI,1);
    l->Draw();

    c2->SaveAs(Form("compareJetPhiRatio-%.2f-%.2f.gif",ajMin,ajMax));
    c2->SaveAs(Form("compareJetPhiRatio-%.2f-%.2f.eps",ajMin,ajMax));

}
Example #21
0
void EtaPhi::Loop()
{
    if (fChain == 0) return;

    Long64_t nentries = fChain->GetEntriesFast();

    Long64_t nbytes = 0, nb = 0;
    cout << "Choose event, -1 for no choice" << endl;
    int choice;
    cin >> choice;
    for (Long64_t jentry=0; jentry<nentries;jentry++) {
        Long64_t ientry = LoadTree(jentry);
        if (ientry < 0) break;
        fChain->GetEntry(jentry);

        bool stahp = false;
        int count = 0;
        vector<int> jets;
        double phi_sum = 0;

        if ( choice >= 0 && choice != jentry )
            continue;

        cout << jentry << endl;
        for ( int j = 0; j < fJets; ++j ) {
            int fl = fFlav[j];
            TLorentzVector t(fX[j],fY[j],fZ[j],fT[j]);
            if (fl < 0 || fl == 10) {
                continue;
            }

            jets.push_back(j);

            cout << "  " << fl << endl;
            if ( fl != 0 )
                ++count;

            if ( fabs(t.Rapidity()) > 3 && jets.size() < 3 ) {
                stahp = true;
                break;
            }
            phi_sum += t.Phi();
        }

        if ( stahp || (count > 1 && choice == -1) ) {
            continue;
        }

        if ( !accept() )
            continue;
        TCanvas* c1 = new TCanvas("c1", "c1", 1200, 1000);
        TH1D* th = new TH1D("","",100,-5.0,5.0);
        gStyle->SetOptStat(0);
        th->SetMinimum(-TMath::Pi());
        th->SetMaximum(TMath::Pi());
        th->SetXTitle("y");
        th->SetYTitle("#phi");
        th->Draw("P");
        phi_sum /= jets.size();

        for ( unsigned j = 0; j < jets.size(); ++j ) {
            TLorentzVector t(fX[jets[j]],fY[jets[j]],fZ[jets[j]],fT[jets[j]]);
            TEllipse *el = new TEllipse(t.Rapidity(),phif(t.Phi(),phi_sum),0.5,0.5);
            Color_t ell_col = kRed+1;
            if (j == 1)
                ell_col = kRed;
            else if (j == 2)
                ell_col = kMagenta;
            else if (j == 3)
                ell_col = kCyan+2;
            else if (j > 3)
                ell_col = kBlue;
            el->SetLineColor(ell_col);
            el->SetFillStyle(0);
            el->Draw("same");
        }

        for ( int j = 0; j < fJets; ++j ) {
            int fl = fFlav[j];
            TLorentzVector t(fX[j],fY[j],fZ[j],fT[j]);

            if (fl == 10)
                continue;

            fl *= -1;
            double saizu = TMath::Log10(t.Pt()/0.01);
            Color_t col;
            Style_t sty;

            if ( fl == 10 ) {
                col = kBlue;
                sty = kCircle;
            } else if ( fl == 11 ) {
                col = kAzure + 7;
                sty = kCircle;
            } else if ( fl == 12 ) {
                col = kRed;
                sty = kOpenSquare;
            } else if ( fl == 13 ) {
                col = kGreen-7;
                sty = kCircle;
            } else if ( fl == 14 ) {
                col = kYellow + 1;
                sty = kCircle;
            } else if ( fl == 15 ) {
                col = kGreen+2;
                sty = kOpenSquare;
            //} else if ( fl == 7 || fl == 8 ) {
            //    col = kBlack;
            //    sty = kOpenSquare;
            } else if ( fl == 9 ) {
                col = kMagenta;
                sty = kDiamond;
            } else {
                continue;
            }

            if (saizu < 0)
                continue;

            if ( fl == 13 || fl == 14 || fl == 15 || fl == 9 )
                saizu *= 2;

            TGraph *f = new TGraph(1);
            f->SetPoint(0,t.Rapidity(),phif(t.Phi(),phi_sum));
            f->SetMarkerStyle(sty);
            f->SetMarkerColor(col);
            f->SetMarkerSize(saizu);
            f->Draw("sameP");
        }
        break;
   }

}
Example #22
0
/** 
 * 
 * 
 * @param o 
 * @param useWeights 
 * @param correct
 *
 * @ingroup pwglf_forward_scripts_tests
 */
void
TestPoisson(Double_t o=.3, bool useWeights=false, bool correct=true)
{
  const char* load = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C";
  if (!gROOT->GetClass("AliAODForwardMult")) {
    gROOT->Macro(load);
    gROOT->GetInterpreter()->UnloadFile(gSystem->ExpandPathName(load));
  }
  
  // --- Parameters of this script -----------------------------------
  Int_t      nBin =  5;  // Our detector matrix size 
  Int_t      nMax = TMath::Max(Int_t(nBin * nBin * o + .5)+nBin/2,nBin);  
  Int_t      nEv  = 10000; // Number of events
  Double_t   mp   = o;   // The 'hit' probability 


  TH2D* base = new TH2D("base", "Basic histogram", 
			nBin,-.5, nBin-.5, nBin, -.5, nBin-.5);
  base->SetXTitle("#eta");
  base->SetYTitle("#varphi");
  base->SetDirectory(0);
  base->SetOption("colz");

  Int_t tN1=nMax;    Double_t tMin1; Double_t tMax1;
  Int_t tN2=nMax*10; Double_t tMin2; Double_t tMax2=nMax;
  MakeIntegerAxis(tN1, tMin1, tMax1);
  MakeIntegerAxis(tN2, tMin2, tMax2);
  TH2D* corr = new TH2D("comp", "Comparison", 
			tN1, tMin1, tMax1, tN2, tMin2, tMax2);
  corr->SetXTitle("Input");
  corr->SetYTitle("Poisson");
  corr->SetDirectory(0);
  corr->SetOption("colz");
  corr->SetStats(0);
  TLine* lcorr = new TLine(0, 0, tMax2, tMax2);

  Int_t mm = TMath::Max(Int_t(nBin * o + .5),nBin/2);
  tN2=mm*10; tMax2 = mm;
  MakeIntegerAxis(tN2, tMin2, tMax2);
  Info("", "Making mean w/nbins=%d,range=[%f,%f]", tN2, tMin2, tMax2);
  TH2D* mean = new TH2D("mean", "Mean comparison", 
			tN2, tMin2, tMax2, tN2, tMin2, tMax2);
  mean->SetXTitle("Input");
  mean->SetYTitle("Poisson");
  mean->SetDirectory(0);
  mean->SetOption("colz");
  mean->SetStats(0);
  TLine* lmean = new TLine(tMin2, tMin2, tMax2, tMax2);

  TH1D* dist = new TH1D("dist", "Distribution of hits", tN1, tMin1, tMax1);
  dist->SetXTitle("s");
  dist->SetYTitle("P(s)");
  dist->SetFillColor(kRed+1);
  dist->SetFillStyle(3001);
  dist->SetDirectory(0);

  TH1D* diff = new TH1D("diff", "P-T", 100, -25, 25);
  diff->SetXTitle("Difference");
  diff->SetFillColor(kRed+1);
  diff->SetFillStyle(3001);
  diff->SetYTitle("Prob");

  AliPoissonCalculator* c = new AliPoissonCalculator("ignored");
  c->Init(nBin ,nBin);

  for (Int_t i = 0; i < nEv; i++) { 
    c->Reset(base);
    base->Reset();

    for (Int_t iEta = 0; iEta < nBin; iEta++) { 
      for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { 
	// Throw a die 
	Int_t m = gRandom->Poisson(mp);
	dist->Fill(m);

	// Fill into our base histogram 
	base->Fill(iEta, iPhi, m);

	// Fill into poisson calculator 
	c->Fill(iEta, iPhi, m > 0, (useWeights ? m : 1));
      }
    }
    // Calculate the result 
    TH2D* res = c->Result(correct);
    
    // Now loop and compare 
    Double_t mBase = 0;
    Double_t mPois = 0;
    for (Int_t iEta = 0; iEta < nBin; iEta++) { 
      for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { 
	Double_t p = res->GetBinContent(iEta, iPhi);
	Double_t t = base->GetBinContent(iEta, iPhi);

	mBase += t;
	mPois += p;
	corr->Fill(t, p);
	diff->Fill(p-t);
      }
    }
    Int_t nn = nBin * nBin;
    mean->Fill(mBase / nn, mPois / nn);
  }

  TCanvas* cc = new TCanvas("c", "c", 900, 900);
  cc->SetFillColor(0);
  cc->SetFillStyle(0);
  cc->SetBorderMode(0);
  cc->SetRightMargin(0.02);
  cc->SetTopMargin(0.02);
  cc->Divide(2,2);
  
  TVirtualPad* pp = cc->cd(1);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.15);
  pp->SetTopMargin(0.02);
  pp->SetLogz();
  pp->SetGridx();
  pp->SetGridy();
  corr->Draw();
  lcorr->Draw();

  pp = cc->cd(2);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.02);
  pp->SetTopMargin(0.02);
#if 0
  c->GetMean()->Draw();
#elif 1 
  pp->SetLogy();
  diff->Draw();
#elif 1
  c->GetOccupancy()->Draw();
#else
  pp->SetLogy();
  dist->SetStats(0);
  dist->Scale(1. / dist->Integral());
  dist->Draw();
  TH1D* m1 = c->GetMean();
  m1->Scale(1. / m1->Integral());
  m1->Draw("same");
  Double_t eI;
  Double_t ii = 100 * dist->Integral(2, 0);
  TLatex* ll = new TLatex(.97, .85, 
			  Form("Input #bar{m}: %5.3f", mp));
  ll->SetNDC();
  ll->SetTextFont(132);
  ll->SetTextAlign(31);
  ll->Draw();
  ll->DrawLatex(.97, .75, Form("Result #bar{m}: %5.3f", dist->GetMean()));
  ll->DrawLatex(.97, .65, Form("Occupancy: #int_{1}^{#infty}P(s)ds = %6.2f%%",
			       ii));
			 
#endif

  pp = cc->cd(3);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.15);
  pp->SetTopMargin(0.02);
  pp->SetGridx();
  pp->SetGridy();
  c->GetCorrection()->Draw();

  pp = cc->cd(4);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.15);
  pp->SetTopMargin(0.02);
  pp->SetLogz();
  pp->SetGridx();
  pp->SetGridy();
  mean->Draw();
  lmean->Draw();

  cc->cd();
}
Example #23
0
void dimuonLoop(float ptmin, float ptmax, float ymin, float ymax, int i)
{
  TFile *infData = new TFile(inputdata);
  TFile *infMC = new TFile(inputmc);
  TTree *ntData = (TTree*) infData->Get("ntKp");
  TTree *ntMC = (TTree*) infMC->Get("ntKp");

  TCanvas *c = new TCanvas(Form("c%i",i),"",600,600);
  //if (logy) c->SetLogy();
  
  TH1D* hData = new TH1D("hData","",50,2.85,3.35);
  TH1D* hMC = new TH1D("hMC","",50,2.85,3.35);

  ntData->Project("hData","mumumass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax));
  ntMC->Project("hMC","mumumass",Form("%s&&(pt>%f&&pt<%f)&&(y>%f&&y<%f)",cut.Data(),ptmin,ptmax,ymin,ymax));

  hData->Sumw2();

  double normData=0,normMC=0;
  normData = hData->GetEntries();
  normMC = hMC->GetEntries();
  cout<<normData<<" "<<normMC<<endl;
  
  hData->Scale(1./normData);
  hMC->Scale(1./normMC); 

  hData->Sumw2();

  hMC->SetXTitle("#mu#mu mass");
  hMC->SetYTitle("#Probability");
  hMC->SetTitleOffset(1.5,"Y");
  if(hData->GetMaximum()>hMC->GetMaximum()) hMC->SetMaximum(hData->GetMaximum()*1.1);
  else hMC->SetMaximum(hMC->GetMaximum()*1.1);

  //hData->SetLineColor(kBlue+1);
  //hData->SetFillStyle(1001);
  //hData->SetFillColor(kBlue-9);
  //hData->SetLineWidth(3);
  hData->SetMarkerStyle(8);
  hData->SetStats(0);

  hMC->SetLineColor(kRed);
  hMC->SetFillStyle(3004);
  hMC->SetFillColor(kRed);
  hMC->SetLineWidth(3);
  hMC->SetStats(0);

  hMC->Draw();
  hData->Draw("same lep");
  
  TLegend *leg = new TLegend(0.11,0.75,0.50,0.9);
  leg->AddEntry(hData,"data","lep");
  leg->AddEntry(hMC,"MC","f");
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  leg->Draw("same");
  TLegend *leg1 = new TLegend(0.60,0.7,0.90,0.9);
  leg1->AddEntry((TObject*)0,Form("%s",particle.Data()),"");
  leg1->AddEntry((TObject*)0,Form("%.0f<p_{T}<%.0f GeV",ptmin,ptmax),"");
  leg1->AddEntry((TObject*)0,Form("%.1f<y_{CM}<%.1f",ymin,ymax),"");
  leg1->SetBorderSize(0);
  leg1->SetFillStyle(0);
  leg1->Draw("same");

  c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_yDM_%i.pdf",i));
  //c->SaveAs(Form("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_%i.pdf",i));
  //c->SaveAs("MuonResult/plot_Bplus_chi2_trkPt/dimuon_DM_incl_1.pdf");
}
void photonTemplateProducer(int cutOpt=3, int ppHI = kHI, int isoChoice = kSumIso, int isoCut = -100, bool onlygjEvents=false, float specialSbCut=10, float mcSigShift=0, float sbBkgShift=0) {
  
  CutAndBinCollection cab;
  cab.setCuts(cutOpt);
  int nPtBin = cab.getNPtBin();
  vector<double> ptBinVector = cab.getPtBin();
  double ptBin[100];
  for ( int i = 0 ; i<=nPtBin ;i++) {
    ptBin[i] = ptBinVector[i];
  }
  
  int nCentBin = cab.getNCentBin();
  vector<double> centBinVector = cab.getCentBin();
  double centBin[100];
  for ( int i = 0 ; i<=nCentBin ;i++) {
    centBin[i] = centBinVector[i];
  }
  
  TString pphiLabel = "";
  if ( ppHI == kPP) pphiLabel = "pp";
  
  TCanvas* c1[5];
    
   TH1D* hData[5][5];
   TH1D* hSig[5][5];
   TH1D* hBkg[5][5];
   
   //   TH1D* hDatapp[5];
   //   TH1D* hSigpp[5];
   //   TH1D* hBkgpp[5];
   
   TH1D* hBkgMCsr[5][5];
   TH1D* hBkgMCsb[5][5];
      
   TH1D* rawSpectra[5];
   TH1D* finSpectra[5];
    
   TH2D* hPurity2D = new TH2D("hPurity2D",";pT(GeV);Centrality bin",nPtBin,ptBin,nCentBin,centBin);
   
   int nCent(-1);
   if ( ppHI == kHI ) nCent = nCentBin;
   if ( ppHI == kPP ) nCent = 1;
   
   for ( int icent = 1 ; icent<=nCent ; icent++) {
      rawSpectra[icent] = new TH1D(Form("rawSpec_icent%d_%s",icent,getIsoLabel(isoChoice).Data()),"",nPtBin,ptBin);
   }

   
   for (int ipt = 1; ipt <= nPtBin ; ipt++) { 
      c1[ipt] = new TCanvas(Form("c1_ipt%d",ipt),"",700,700);
      if ( ppHI == kHI )  makeMultiPanelCanvas(c1[ipt],nCent/2,2,0.0,0.0,0.2,0.15,0.02);

      TCut ptCut = Form("corrPt>%.2f && corrPt<%.2f",(float)ptBin[ipt-1],(float)ptBin[ipt]); 
      

      for ( int icent = 1 ; icent<=nCent ; icent++) { 
	 int lowCent =  centBinVector[icent-1];    
	 int highCent = centBinVector[icent]-1;
	 
	 hData[icent][ipt]  = new TH1D(Form("hData_cent%d_pt%d",icent,ipt),";shower shape (#sigma_{#eta#eta});Entries per photon candidate;",25,0,0.025);
	 hSig[icent][ipt]   = (TH1D*)hData[icent][ipt]->Clone(Form("hSig_cent%d_pt%d",icent,ipt));
	 hBkg[icent][ipt]   = (TH1D*)hData[icent][ipt]->Clone(Form("hBkg_cent%d_pt%d",icent,ipt));
	 hBkgMCsr[icent][ipt] = (TH1D*)hData[icent][ipt]->Clone(Form("hBkgMCsr_cent%d_pt%d",icent,ipt));
	 hBkgMCsb[icent][ipt] =(TH1D*)hData[icent][ipt]->Clone(Form("hBkgMCsb_cent%d_pt%d",icent,ipt));
	
	 TString fNamedata = fNameHIdata;
	 if ( ppHI == kPP ) fNamedata = fNamePPdata;
	 
	 getTemplate(ppHI, hSig[icent][ipt],"meaningless",isoChoice,isoCut, kSig,lowCent,highCent,ptCut,onlygjEvents,specialSbCut,mcSigShift);
	 getTemplate(ppHI, hData[icent][ipt],fNamedata ,isoChoice,isoCut, kData,lowCent,highCent,ptCut,onlygjEvents,specialSbCut);
	 if ( ppHI == kHI) {
	   getTemplate(ppHI, hBkg[icent][ipt], fNamedata ,isoChoice,isoCut, kSBB,lowCent,highCent,ptCut,onlygjEvents,specialSbCut,sbBkgShift);
	 }
	 if ( ppHI == kPP)
           getTemplate(ppHI, hBkg[icent][ipt], fNamedata ,isoChoice,isoCut, kSBBpp,lowCent,highCent,ptCut,onlygjEvents,specialSbCut);
	 
      }
            
      
      for ( int icent = 1 ; icent<=nCent ; icent++) {
	int lowerCent = centBinVector[icent-1];
	int upperCent =centBinVector[icent]-1;
	 
	 c1[ipt]->cd(nCent - icent+1);
	 fitResult fitr = doFit ( hSig[icent][ipt], hBkg[icent][ipt], hData[icent][ipt], 0.005,0.025);
	 if ( icent== nCent) drawPatch(0,0,0.05,0.14,0,1001, "ndc");
	 
	 cout << " shift = " << mcSigShift << endl;
	 cout << " purity = " << fitr.purity010 << endl;

	 
	 if ( ptBin[ipt]> 200)
	    drawText(Form(" E_{T}^{#gamma} > %d GeV", (int)ptBin[ipt-1]),0.5680963,0.529118);
	 else
	    drawText(Form("%d - %d GeV", (int)ptBin[ipt-1], (int)ptBin[ipt]),0.5680963,0.529118);
	 
	 if ( ppHI == kHI) {
	   drawText(Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),0.5680963,0.4369118);
	 }
	 else if ( ppHI == kPP) {
	   drawText("7TeV pp",0.5680963,0.4369118);
         }
	 
	 
	 
	 if ( (icent == nCent) || (icent == 2)) 
	   drawText(Form("Purity(#sigma_{#eta#eta} < 0.01) : %.0f%%", (float)fitr.purity010*100),0.5680963,0.3569118,1,15);
	 else 
	   drawText(Form("Purity(#sigma_{#eta#eta} < 0.01) : %.0f%%", (float)fitr.purity010*100),0.4980963,0.3569118,1,15);
	 
	 drawText(Form("#pm %.0f%% (stat)", float( 100. * fitr.purity010 * (float)fitr.nSigErr / (float)fitr.nSig ) ),0.6680963,0.2869118,1,15);
	 
	 
	 hPurity2D->SetBinContent(ipt,icent,fitr.purity010);
	 hPurity2D->SetBinError  (ipt,icent,fitr.purity010* fitr.nSigErr/fitr.nSig);

	 rawSpectra[icent]->SetBinContent( ipt, fitr.nSig);
	 rawSpectra[icent]->SetBinError(   ipt,fitr.nSigErr);

	 TString aa = "";
	 if (isoChoice == kSumIso)  aa = "Sum Iso Method";
	 if (isoChoice == k3dIso)   aa = "3d Cut Method";
	 if (isoChoice == kFisher)  aa = "Fisher Method";
	 
	 if ( (ppHI == kHI)  && ( icent==nCent -1) )
	   drawText(aa.Data(),0.1980963,0.8569118,1,20);
	 else if ( ppHI == kPP) 
	   drawText(aa.Data(),0.1980963,0.8569118,1,20);
	 
	 if ( icent<= 2) drawPatch(0,0,0.05,0.14,0,1001, ndcOpt);
	 //	 drawPatch(0.9,0.05,1.01,0.14,0,1001,ndcOpt);
	 if  ( (ppHI == kPP) && ( mcSigShift != 0 )) 
           drawText(Form("Signal template shifted by %f",mcSigShift),0.1980963,0.7569118,1,15);
	 if  ( (ppHI == kHI) && ( mcSigShift != 0 ) && (icent==3))
	   drawText(Form("Signal template shifted by %f",mcSigShift),0.1980963,0.7569118,1,15);


      }   
      
      TString ppLabel ="";  
      if ( ppHI == kPP) ppLabel = "_pp";
      TString shiftLabel="";
      if ( mcSigShift != 0 )  shiftLabel = Form("_%fSigShifted",(float)mcSigShift);
      c1[ipt]->SaveAs(Form("fittingPurity%s_%s_pt%d%s.pdf",ppLabel.Data(), getIsoLabel(isoChoice).Data(),ipt,shiftLabel.Data()));

   }
   
   // efficiency plots          
   TCanvas* c2  = new TCanvas("c2","",700,700); //100 + nCent_std*300,400);
   if ( ppHI == kHI) makeMultiPanelCanvas(c2,nCent/2,2,0.0,0.0,0.2,0.15,0.02);
   
   TH1D* heff[7][5];
   TH1D* heffGj[5];
   TH1D* heffDphi[5];
   TH1D* effSingleBin = new TH1D("effSingleBin","",1,60,100000);
   TGraphAsymmErrors* geff[7][5];
   TGraphAsymmErrors* gSingleBin = new TGraphAsymmErrors();
   TGraphAsymmErrors* geffGj[5];
   TGraphAsymmErrors* geffDphi[5];
   
   for (int icent = 1; icent <=nCent; icent++) {
     for ( int iid=1 ; iid<=5; iid++) {
       heff[icent][iid] = new TH1D(Form("heff_icent%d_id%d",icent,iid),";photon E_{T} (GeV);Efficiency",nPtBin, ptBin);
       if ( isoChoice == kSumIso2)
	 heff[icent][iid]->SetName(Form("heff_icent%d_id%d_isoCut%d",icent,iid,(int)isoCut));
       if ( isoChoice == kSumIso3)
	 heff[icent][iid]->SetName(Form("heff_icent%d_id%d_sbIsoCut%d",icent,iid,(int)specialSbCut));
       
       geff[icent][iid] = new TGraphAsymmErrors();
       geff[icent][iid]->SetName(Form("geff_%s",heff[icent][iid]->GetName()));
     }
     heffGj[icent]   = new TH1D(Form("heff_icent%d_Gj",  icent),";x_J#gamma;Efficiency",10,0,2);
     heffDphi[icent] = new TH1D(Form("heff_icent%d_Dphi",icent),";#Delta#phi of pair;Efficiency",9,0.3141592,3.141592);
     geffGj[icent] = new TGraphAsymmErrors();
     geffDphi[icent] = new TGraphAsymmErrors();

   }
   
   TCut srIsoCut = getIsoCut(isoChoice,isoCut);
   int nId=4;
   for (int icent = 1; icent <=nCent ; icent++) {
     int lowCent = centBinVector[icent-1];
     int highCent = centBinVector[icent]-1;
     TCut centCut      = Form("yEvt.hiBin >= %d && yEvt.hiBin<= %d",lowCent,highCent);
     if ( ppHI == kPP ) centCut = "";
     getEff("genMatchedPt",heff[icent][1],geff[icent][1],centCut, "swissCrx<0.90 && seedTime<4");
     getEff("genMatchedPt",heff[icent][2],geff[icent][2],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1");
     getEff("genMatchedPt",heff[icent][3],geff[icent][3],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1" && srIsoCut);
     getEff("genMatchedPt",heff[icent][4],geff[icent][4],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1 && sigmaIetaIeta<0.010"&& srIsoCut);
     effSingleBin->Reset();
     getEff("genMatchedPt",effSingleBin, gSingleBin, centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1" && srIsoCut);
     
     
     cout << " here Gj" << endl;
     getEff("yJet.jtpt/photonEt",heffGj[icent],geffGj[icent], centCut && " genIso<5 && abs(genMomId)<=22 && photonEt>60 && abs(yJet.jteta)<2 && yJet.jtpt>30 && acos(cos(photonPhi-yJet.jtphi))>2.749", "hovere<0.1 && sigmaIetaIeta<0.010 && (cc4+cr4+ct4PtCut20)/0.9<1",true);
     getEff("acos(cos(photonPhi-yJet.jtphi))",heffDphi[icent],geffDphi[icent],centCut && " genIso<5 && abs(genMomId)<=22 && photonEt>60 && abs(yJet.jteta)<2 && yJet.jtpt>30", "hovere<0.1 && sigmaIetaIeta<0.010 && (cc4+cr4+ct4PtCut20)/0.9<1",true);
   }
   
   for (int icent = 1; icent <=nCent; icent++) {
     for ( int iid=1 ; iid<=nId ; iid++) {
       handsomeTH1(heff[icent][iid],ycolor[iid]);
       handsomeTGraph(geff[icent][iid],ycolor[iid]);
     }
   }
   

   
   
   
   TH1D* htmp = (TH1D*)heff[1][1]->Clone("htmp");
   htmp->Reset();
   htmp->SetAxisRange(0,1.3,"Y");
   htmp->SetYTitle("Efficiency");
   handsomeTH1(htmp);
   
   for (int icent = 1; icent <=nCent; icent++) {
      int lowerCent = centBinVector[icent-1];
      int upperCent = centBinVector[icent]-1;
      if ( ppHI == kHI) c2->cd(nCent - icent + 1);
      htmp->DrawCopy();
      for ( int iid=1 ; iid<=nId ; iid++) {
         heff[icent][iid]->Draw("p same");
         geff[icent][iid]->Draw("p");
	 
      }
      if ( ( icent == nCent ) ||   ( ppHI == kPP)  )
         {
            TLegend* leg1 =  new TLegend(0.25,0.20,0.95,0.55,NULL,"brNDC");
            easyLeg(leg1,"Photon ID efficiency");
            leg1->AddEntry(heff[icent][1],"spike rejection","lp");
            leg1->AddEntry(heff[icent][2],"+ H/E < 0.1","lp");
	    if (isoChoice == kSumIso)
	      leg1->AddEntry(heff[icent][3],"+ SumIso cut","lp");
	    if (isoChoice == kFisher) 
	      leg1->AddEntry(heff[icent][3],"+ Fisher cut","lp");
	    leg1->AddEntry(heff[icent][4],"+ #sigma_{#eta#eta} <0.010","lp");
            leg1->Draw();
         }
      drawText(Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),0.5680963,0.8369118);
      if ( icent<=2) drawPatch(0,0,0.05,0.14,0,1001,ndcOpt);
      //  drawPatch(0.9,0.05,1.01,0.14,0,1001,ndcOpt);
      
   }
   
   
   c2->SaveAs(Form("photonID_efficiency_%s.pdf",getIsoLabel(isoChoice).Data()));  

   TCanvas* c2b  = new TCanvas("c2b","",1000,500); //100 + nCent_std*300,400);                                             
   c2b->Divide(2,1);
   c2b->cd(1);
   TH1D* htmpG = (TH1D*)heffGj[1]->Clone("htmpG");
   htmpG->Reset();
   htmpG->SetAxisRange(0,1.3,"Y");
   htmpG->SetYTitle("Efficiency");
   handsomeTH1(htmpG);   
      
   TLegend* legCent = new TLegend(0.4657258,0.2245763,1,0.4512712,NULL,"brNDC");
   easyLeg(legCent,"Centrality");
   if (isoChoice == kSumIso)  easyLeg(legCent,"SumIso Method");
   if (isoChoice == kFisher)  easyLeg(legCent,"Fisher Method");
   cout<< " heffGj "<< endl << endl<< endl;
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(heffGj[icent],ycolor[icent]);
     heffGj[icent]->Fit("pol1");
     heffGj[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     heffGj[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   htmpG->DrawCopy();
   for (int icent = 1; icent <=nCent; icent++) {
     heffGj[icent]->Draw("same");
     int lowerCent = centBinVector[icent-1];     int upperCent = centBinVector[icent]-1;
     legCent->AddEntry(heffGj[icent],Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),"pl");
   }
   legCent->Draw();

   c2b->cd(2);
   TH1D* htmpDp = new TH1D("htmpDp",";#Delta#phi of pair;Efficiency",10,0,3.14);
   htmpDp->Reset();
   htmpDp->SetAxisRange(0,1.3,"Y");
   htmpDp->SetYTitle("Efficiency");
   handsomeTH1(htmpDp);
   cout << " heffDphi " << endl << endl << endl ;
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(heffDphi[icent],ycolor[icent]);
     heffDphi[icent]->Fit("pol1");
     heffDphi[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     heffDphi[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   htmpDp->DrawCopy();
   for (int icent = 1; icent <=nCent; icent++) {
     heffDphi[icent]->Draw("same");
   }
   legCent->Draw();
   
   c2b->SaveAs(Form("photonID_efficiency_%s_2.pdf",getIsoLabel(isoChoice).Data()));
   
   
   TCanvas* c3 = new TCanvas("cPurity","",500,500);

   TH1D* hPurity[10];
   for (int icent = 1; icent <=nCent; icent++) {
     hPurity[icent] = (TH1D*)hPurity2D->ProjectionX(Form("purity1D_icent%d",icent),icent,icent);
     hPurity[icent]->Fit("pol1");
     hPurity[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     hPurity[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   TH1D* tempPurity = (TH1D*)hPurity[1]->Clone("purityTemp");
   tempPurity->Reset();
   handsomeTH1(tempPurity,1);
   tempPurity->SetXTitle("pT (Gev)");
   tempPurity->SetYTitle("Purity");
   tempPurity->SetAxisRange(0.45,1.2,"Y");

   tempPurity->Draw();
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(hPurity[icent],ycolor[icent]);
     hPurity[icent]->Draw("same");
   }
   TLegend* legPurity = new TLegend(0.4657258,0.2245763,1,0.4512712,NULL,"brNDC");
   easyLeg(legPurity,"Purity");
   if (isoChoice == kSumIso)  easyLeg(legPurity,"SumIso Method");
   if (isoChoice == kFisher)  easyLeg(legPurity,"Fisher Method");
   for (int icent = 1; icent <=nCent; icent++){
     int lowerCent = centBinVector[icent-1];     int upperCent = centBinVector[icent]-1;
     legPurity->AddEntry(hPurity[icent],Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),"pl");
   }
   legPurity->Draw();
   
   if ( !onlygjEvents) 
     drawText("inclusive photon",0.25,0.2);
   
   c3->SaveAs(Form("purity_%s.pdf",getIsoLabel(isoChoice).Data()));
  
   
   TCanvas* c4 = new TCanvas("efficiencyCorrection","",1000,500);
   c4->Divide(2,1);
   c4->cd(1);
   for (int icent = 1; icent <=nCent; icent++) {
      TH1ScaleByWidth(rawSpectra[icent]);    // divide by width
      finSpectra[icent] = (TH1D*)rawSpectra[icent]->Clone(Form("finSpec_icent%d_%s",icent,getIsoLabel(isoChoice).Data()));
      if ( isoChoice == kSumIso2)
	 finSpectra[icent]->SetName(Form("finSpec_icent%d_%s_isoCut%d",icent,getIsoLabel(isoChoice).Data(),(int)isoCut));
      if ( isoChoice == kSumIso3)
         finSpectra[icent]->SetName(Form("finSpec_icent%d_%s_sbisoCut%d",icent,getIsoLabel(isoChoice).Data(),(int)specialSbCut));
      
      finSpectra[icent]->Divide(heff[icent][3]);
      handsomeTH1(finSpectra[icent],ycolor[icent]);
   }
   // TAA and centrality 
   //

   TFile outf = TFile(cab.getPurityFileName(),"recreate");
   hPurity2D->Write();
   for ( int icent=1 ; icent<=nCent ; icent++) {
      heff[icent][3]->Write();
      heff[icent][4]->Write();
      finSpectra[icent]->Write();
      hPurity[icent]->Write();
      for (int ipt = 1; ipt <= nPtBin ; ipt++) {
	hData[icent][ipt]->Write();
      }
      //      hBkgMCRatioFit[icent][1]->Write();

   }



   outf.Close();
}
Example #25
0
TF1* fitDstar3prongs(TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax)
{
  static int count3p=0;
  count3p++;
  
  TCanvas* c = new TCanvas(Form("c_3p_%d",count3p),"",600,600);
  TH1D* h = new TH1D(Form("h_3p_%d",count3p),"",60,0.14,0.16);
  TH1D* hMCSignal = new TH1D(Form("hMCSignal_3p_%d",count3p),"",60,0.14,0.16);
  TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_3p_%d",count3p),"",60,0.14,0.16);

  TF1* f = new TF1(Form("f_3p_%d",count3p),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*([12]*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10])+(1-[12])*Gaus(x,[1],[13])/(sqrt(2*3.14159)*[13])))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x+[11]*x*x*x*x",0.14,0.16);
  f->SetLineColor(kRed);
  nt->Project(Form("h_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f)",weight.Data(),seldata3p.Data(),triggerselection[isData].Data(),ptmin,ptmax));
  ntMC->Project(Form("hMCSignal_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23333))",weight.Data(),selmc3p.Data(),triggerselection[isData].Data(),ptmin,ptmax));
  ntMC->Project(Form("hMCSwapped_3p_%d",count3p),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f&&Dpt<%f&&(Dgen==23344))",weight.Data(),selswp3p.Data(),triggerselection[isData].Data(),ptmin,ptmax));

  f->FixParameter(7,1.);
  f->FixParameter(1,0.145491);
  f->FixParameter(2,2.e-3);
  f->FixParameter(10,5.e-4);
  f->FixParameter(13,1.e-4);
  f->FixParameter(3,0.);
  f->FixParameter(4,0.);
  f->FixParameter(5,0.);
  f->FixParameter(6,0.);
  f->FixParameter(11,0.);

  f->SetParLimits(9,0,1);
  f->SetParLimits(12,0,1);
  f->SetParLimits(0,0,1000000);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL");
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL");
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.142,0.155);
  f->ReleaseParameter(1);
  f->ReleaseParameter(2);
  f->ReleaseParameter(10);
  f->ReleaseParameter(13);
  f->SetParLimits(1,0.144,0.147);
  if(isData==0||isData==2) f->SetParLimits(2,5.e-4,5.e-3);
  else f->SetParLimits(2,5.e-4,7.e-3);
  f->SetParLimits(10,1.e-4,2.e-3);
  if(isData==0||isData==2) f->SetParLimits(13,5.e-5,3.e-4);
  else if(ptmin>20) f->SetParLimits(13,5.e-5,4.e-4);
  else f->SetParLimits(13,5.e-5,5.e-4);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.143,0.147);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  hMCSignal->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);

  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(10,f->GetParameter(10));
  f->FixParameter(13,f->GetParameter(13));
  f->FixParameter(9,f->GetParameter(9));
  f->FixParameter(12,f->GetParameter(12));
  f->FixParameter(7,0);
  f->SetParLimits(8,2.e-4,2.e-3);

  hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16);
  hMCSwapped->Fit(Form("f_3p_%d",count3p),"L q","",0.14,0.16);

  f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000)));
  f->FixParameter(8,f->GetParameter(8));
  f->ReleaseParameter(3);
  f->ReleaseParameter(4);
  f->ReleaseParameter(5);
  f->ReleaseParameter(6);
  f->ReleaseParameter(11);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  f->ReleaseParameter(1);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);
  h->Fit(Form("f_3p_%d",count3p),"LL","",0.14,0.16);

  TF1* background = new TF1(Form("background_3p_%d",count3p),"[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x");
  background->SetParameter(0,f->GetParameter(3));
  background->SetParameter(1,f->GetParameter(4));
  background->SetParameter(2,f->GetParameter(5));
  background->SetParameter(3,f->GetParameter(6));
  background->SetParameter(4,f->GetParameter(11));
  background->SetLineColor(4);
  background->SetLineStyle(2);
  
  TF1* mass = new TF1(Form("fmass_3p_%d",count3p),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*([6]*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])+(1-[6])*Gaus(x,[1],[7])/(sqrt(2*3.14159)*[7]))))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(12),f->GetParameter(13));
  mass->SetParError(0,f->GetParError(0));
  mass->SetParError(1,f->GetParError(1));
  mass->SetParError(2,f->GetParError(2));
  mass->SetParError(3,f->GetParError(7));
  mass->SetParError(4,f->GetParError(9));
  mass->SetParError(5,f->GetParError(10));
  mass->SetParError(6,f->GetParError(12));
  mass->SetParError(7,f->GetParError(13));
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);
  
  h->SetXTitle("M_{K#pi#pi}-M_{K#pi} (GeV/c^{2})");
  h->SetYTitle("Entries / (1/3 MeV/c^{2})");
  h->SetStats(0);
  h->SetAxisRange(1,h->GetMaximum()*1.3,"Y");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->GetXaxis()->SetTitleOffset(1.3);
  h->GetYaxis()->SetTitleOffset(1.8);
  h->GetXaxis()->SetLabelOffset(0.007);
  h->GetYaxis()->SetLabelOffset(0.007);
  h->GetXaxis()->SetTitleSize(0.045);
  h->GetYaxis()->SetTitleSize(0.045);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.04);
  h->GetYaxis()->SetLabelSize(0.04);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);
  h->SetStats(0);
  h->Draw("e");

  background->Draw("same");   
  mass->SetRange(0.142,0.152);	
  mass->Draw("same");
  f->Draw("same");

  Double_t yield = mass->Integral(0.14,0.16)/binwidth3prong;
  Double_t yieldErr = mass->Integral(0.14,0.16)/binwidth3prong*mass->GetParError(0)/mass->GetParameter(0);

  TLatex* tex;
  TLegend* leg = new TLegend(0.60,0.62,0.85,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry((TObject*)0,"D* D^{0}(K#pi)#pi",NULL);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  tex = new TLatex(0.61,0.58,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.20,0.79,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  tex = new TLatex(0.20,0.84,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  c->SaveAs(Form("plots/pp/DMass_%s_3prongs-%d.pdf",texData[isData].Data(),count3p));
  
  return mass;
}
void plotLeadingJet(int cbin,
		    TString infname,
		    TString pythia,
		    TString mix,
		    bool useWeight,
		    bool drawXLabel,
		    bool drawLeg)
{

  TString cut="et1>120 && et2>50 && dphi>2.5";
  TString cutpp="et1>120 && et2>50 && dphi>2.5";
  TString cstring = "";
  if(cbin==0) {
    cstring = "0-10%";
    cut+=" && bin>=0 && bin<4";
    cut+=" && ((et1-et2)/(et1+et2) > 0.3)";
  } else if (cbin==1) {
     cstring = "10-30%";
     cut+=" && bin>=4 && bin<12";
     cut+=" && ((et1-et2)/(et1+et2) > 0.3)";
  } else {
     cstring = "30-100%";
     cut+=" && bin>=12 && bin<40";
     cut+=" && ((et1-et2)/(et1+et2) > 0.3)";
  }
  
  // open the data file
  TFile *inf = new TFile(infname.Data());
  TTree *nt =(TTree*)inf->FindObjectAny("nt");

  // open the pythia (MC) file
  TFile *infPythia = new TFile(pythia.Data());
  TTree *ntPythia = (TTree*) infPythia->FindObjectAny("nt");

  // open the datamix file
  TFile *infMix = new TFile(mix.Data());
  TTree *ntMix =(TTree*)infMix->FindObjectAny("nt");


  // projection histogram
  TH1D *h = new TH1D("h","",10,60,135);
  TH1D *hPythia = new TH1D("hPythia","",10,60,135);
  TH1D *hDataMix = new TH1D("hDataMix","",10,60,135);
  nt->Draw("et2>>h",Form("(%s)",cut.Data())); 
   
  if (useWeight) {
    // use the weight value caluculated by Matt's analysis macro
    ntMix->Draw("et2>>hDataMix",Form("(%s)*weight",cut.Data())); 
  } else {
    // ignore centrality reweighting
    ntMix->Draw("et2>>hDataMix",Form("(%s)",cut.Data()));  
  }
    ntPythia->Draw("et2>>hPythia",Form("(%s)",cutpp.Data())); 
  // calculate the statistical error and normalize
  h->Sumw2();
  h->Scale(1./h->GetEntries());
  h->SetMarkerStyle(20);

  hPythia->Scale(1./hPythia->Integral(0,20));
  hPythia->SetLineColor(kBlue);
  hPythia->SetFillColor(kAzure-8);
  hPythia->SetFillStyle(3005);
   
  hPythia->SetStats(0);
  hPythia->Draw("hist");
  if(drawXLabel) hPythia->SetXTitle("Subleading Jet E_{T} (GeV)");

  hPythia->GetXaxis()->SetLabelSize(20);
  hPythia->GetXaxis()->SetLabelFont(43);
  hPythia->GetXaxis()->SetTitleSize(22);
  hPythia->GetXaxis()->SetTitleFont(43);
  hPythia->GetXaxis()->SetTitleOffset(1.5);
  hPythia->GetXaxis()->CenterTitle();

  hPythia->GetXaxis()->SetNdivisions(904,true);

  hPythia->SetYTitle("Event Fraction");

  hPythia->GetYaxis()->SetLabelSize(20);
  hPythia->GetYaxis()->SetLabelFont(43);
  hPythia->GetYaxis()->SetTitleSize(20);
  hPythia->GetYaxis()->SetTitleFont(43);
  hPythia->GetYaxis()->SetTitleOffset(2.5);
  hPythia->GetYaxis()->CenterTitle();

  hPythia->SetAxisRange(2E-3,3,"Y");
  hDataMix->SetAxisRange(2E-3,3,"Y");
  h->SetAxisRange(2E-3,3,"Y");


  h->Draw("same");

  hDataMix->Scale(1./hDataMix->Integral(0,20));
  hDataMix->SetLineColor(kRed);
  hDataMix->SetFillColor(kRed-9);
  hDataMix->SetFillStyle(3004);
  hDataMix->Draw("same");

  if(drawLeg){
     TLegend *t3=new TLegend(0.25,0.74,0.79,0.90);
    t3->AddEntry(h,"Pb+Pb  #sqrt{s}_{_{NN}}=2.76 TeV","pl");
    t3->AddEntry(hPythia,"PYTHIA","lf");
    t3->AddEntry(hDataMix,"embedded PYTHIA","lf");
    t3->SetFillColor(0);
    t3->SetBorderSize(0);
    t3->SetFillStyle(0);
    t3->SetTextFont(63);
    t3->SetTextSize(15);
    t3->Draw();
  }
  
}
TF1* fitDstar(TTree* nt, TTree* ntMC, Float_t ptmin, Bool_t plotgenmatch)
{
  TCanvas* c = new TCanvas(Form("c_5p_%.0f",ptmin),"",600,600);
  TH1D* h = new TH1D(Form("h_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSignal = new TH1D(Form("hMCSignal_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSignalplot = new TH1D(Form("hMCSignalplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSwapped = new TH1D(Form("hMCSwapped_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);
  TH1D* hMCSwappedplot = new TH1D(Form("hMCSwappedplot_5p_%.0f",ptmin),"",BINNUM,BINMIN,BINMAX);

  TF1* f = new TF1(Form("f_5p_%.0f",ptmin),"[0]*([4]*([6]*([12]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[12])*Gaus(x,[1],[11])/(sqrt(2*3.14159)*[11]))+(1-[6])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5]))+(1-[4])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3]))+[10]*((1-exp((0.13957-x)/[7]))*pow(x/0.13957,[8])+[9]*(x/0.13957-1))",BINMIN,BINMAX);
  nt->Project(Form("h_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightdata[isData].Data(),seldata5p[isData].Data(),triggerselectiondata[isData].Data(),ptmin));
  ntMC->Project(Form("hMCSignal_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selmc5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin));
  ntMC->Project(Form("hMCSwapped_5p_%.0f",ptmin),"Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isData].Data(),selswp5p[isData].Data(),triggerselectionmc[isData].Data(),ptmin));
  for(int ibin=0;ibin<BINNUM;ibin++) hMCSignalplot->SetBinContent(ibin+1,hMCSignal->GetBinContent(ibin+1));
  for(int ibin=0;ibin<BINNUM;ibin++) hMCSwappedplot->SetBinContent(ibin+1,hMCSwapped->GetBinContent(ibin+1));
  f->FixParameter(4,1.);
  f->FixParameter(1,0.145491);
  f->FixParameter(10,0);

  f->SetParLimits(0,0,1.e+5);
  f->SetParLimits(6,0,1.);
  f->SetParLimits(12,0,1.);
  f->SetParLimits(2,3.e-4,1.e-3);
  f->SetParameter(2,5.e-4);
  f->SetParLimits(11,1.6e-4,3.e-4);//1.5e-4 keyong
  f->SetParameter(11,2.e-4);
  f->SetParLimits(5,1.e-3,1.6e-3);
  f->SetParameter(5,1.e-3);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  f->ReleaseParameter(1);
  f->SetParLimits(1,minmass,maxmass);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass);
  hMCSignal->Fit(Form("f_5p_%.0f",ptmin),"LL","",minmass,maxmass);

  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(5,f->GetParameter(5));
  f->FixParameter(11,f->GetParameter(11));
  f->FixParameter(6,f->GetParameter(6));
  f->FixParameter(12,f->GetParameter(12));
  f->FixParameter(4,0);
  f->SetParLimits(3,2.e-4,2.e-3);
  f->SetParameter(3,1.e-3);

  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX);
  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",BINMIN,BINMAX);
  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass);
  hMCSwapped->Fit(Form("f_5p_%.0f",ptmin),"L q","",minmass,maxmass);

  f->FixParameter(4,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000)));
  f->FixParameter(3,f->GetParameter(3));

  f->SetParLimits(7,5.e-4,1.e-2);
  f->SetParameter(7,1.6e-3);
  f->SetParLimits(8,0.,15.);
  f->SetParameter(8,0.35);
  f->SetParLimits(9,-2.e+1,2.e+1);
  f->SetParameter(9,13.);

  f->ReleaseParameter(10);
  f->SetParLimits(10,0,1.e+6);

  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);

  f->ReleaseParameter(1);
  f->SetParLimits(1,minmass,maxmass);
  f->SetParameter(1,f->GetParameter(1));
  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);
  h->Fit(Form("f_5p_%.0f",ptmin),"LL","",BINMIN,BINMAX);

  TF1* background = new TF1(Form("background_5p_%.0f",ptmin),"[3]*((1-exp((0.13957-x)/[0]))*pow(x/0.13957,[1])+[2]*(x/0.13957-1))");
  background->SetParameters(f->GetParameter(7),f->GetParameter(8),f->GetParameter(9),f->GetParameter(10));
  background->SetRange(BINMIN,BINMAX);
  background->SetLineColor(4);
  background->SetLineWidth(3);
  background->SetLineStyle(2);

  TF1* mass = new TF1(Form("fmass_5p_%.0f",ptmin),"[0]*[3]*([5]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[6])/(sqrt(2*3.14159)*[6]))+(1-[5])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(11),f->GetParameter(12));
  mass->SetParError(0,f->GetParError(0));
  mass->SetParError(1,f->GetParError(1));
  mass->SetParError(2,f->GetParError(2));
  mass->SetParError(3,f->GetParError(4));
  mass->SetParError(4,f->GetParError(5));
  mass->SetParError(5,f->GetParError(6));
  mass->SetRange(BINMIN,BINMAX);
  mass->SetFillColor(kOrange-3);
  mass->SetFillStyle(3002);
  mass->SetLineColor(kOrange-3);
  mass->SetLineWidth(3);
  mass->SetLineStyle(2);

  TF1* massSwap = new TF1(Form("fmassSwap_5p_%.0f",ptmin),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])");
  massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(4),f->GetParameter(3));
  massSwap->SetRange(BINMIN,BINMAX);
  massSwap->SetFillColor(kGreen+4);
  massSwap->SetFillStyle(3005);
  massSwap->SetLineColor(kGreen+4);
  massSwap->SetLineWidth(3);
  massSwap->SetLineStyle(1);

  h->SetXTitle("M_{K#pi#pi#pi#pi}-M_{K#pi#pi#pi} (GeV/c^{2})");
  h->SetYTitle("Entries / (0.4 MeV/c^{2})");
  h->SetStats(0);
  h->SetAxisRange(0,h->GetMaximum()*1.3,"Y");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->GetXaxis()->SetTitleOffset(1.3);
  h->GetYaxis()->SetTitleOffset(1.8);
  h->GetXaxis()->SetLabelOffset(0.007);
  h->GetYaxis()->SetLabelOffset(0.007);
  h->GetXaxis()->SetTitleSize(0.045);
  h->GetYaxis()->SetTitleSize(0.045);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.04);
  h->GetYaxis()->SetLabelSize(0.04);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);
  h->SetStats(0);

  h->Draw("e");
  mass->Draw("same");
  massSwap->Draw("same");
  background->Draw("same");
  f->Draw("same");

  if(plotgenmatch&&(isData==MC_MB||isData==MC))
    {
      hMCSignalplot->SetMarkerSize(0.8);
      hMCSignalplot->SetMarkerColor(kMagenta+2);
      hMCSignalplot->Draw("psame");
      hMCSwappedplot->SetMarkerSize(0.8);
      hMCSwappedplot->SetMarkerColor(kGray+2);
      hMCSwappedplot->Draw("psame");
    }

  Float_t yield = mass->Integral(BINMIN,BINMAX)/BINWID;
  Float_t yieldErr = mass->Integral(BINMIN,BINMAX)/BINWID*mass->GetParError(0)/mass->GetParameter(0);
  cout<<mass->GetParameter(0)<<" "<<mass->Integral(BINMIN,BINMAX)<<endl;

  TLatex* tex;
  TLegend* leg = new TLegend(0.60,0.57,0.85,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry((TObject*)0,"D* D^{0}(K#pi#pi#pi)#pi",NULL);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"D*^{+}+D*^{-} Signal","f");
  leg->AddEntry(massSwap,"K-#pi swapped","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  tex = new TLatex(0.61,0.52,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  tex = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.65,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV");
  tex->SetNDC();
  tex->SetTextAlign(12);
  tex->SetTextSize(0.04);
  tex->SetTextFont(42);
  tex->Draw();
  tex = new TLatex(0.20,0.79,"|y| < 1.0");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  tex = new TLatex(0.20,0.84,Form("p_{T} > %.1f GeV/c",ptmin));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();

  c->SaveAs(Form("plots/pp/fitDstar5p/DMass_%s_%.0f.pdf",texData[isData].Data(),ptmin));

  return mass;
}
Example #28
0
//TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, float NPpar[])
TF1* fit(Float_t varval, Float_t ibin, Int_t isMC, TString npfit)
{
  TString tMC;
  if(isMC==1) tMC="MC";
  else tMC="Data";
  TCanvas* c = new TCanvas(Form("c_%s_%.0f",tMC.Data(),ibin),"",600,600);
  TFile* infile = new TFile(Form("%s_%s_%s_%s_%.0f.root",infname.Data(),collisionsystem.Data(),varname.Data(),tMC.Data(),ibin));
  TH1D* h = (TH1D*)infile->Get("h");                    h->SetName(Form("h_%s_%.0f",tMC.Data(),ibin));
  TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal");    hMCSignal->SetName(Form("hMCSignal_%s_%.0f",tMC.Data(),ibin));

  //TString iNP=Form("TMath::Erf((x-%f)/%f)+1", NPpar[0], NPpar[1]);
  TString iNP = npfit;
  TF1* f = new TF1(Form("f_%s_%.0f",tMC.Data(),ibin),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")");

  f->SetParLimits(3,0,1e5);
  f->SetParLimits(4,-1000,0);
  f->SetParLimits(2,0.01,0.05);
  f->SetParLimits(8,0.01,0.05);
  f->SetParLimits(7,0,1);
  f->SetParLimits(5,0,1000);
  if(isMC) {
    f->SetParLimits(3,0,1e2);
    f->SetParLimits(4,-100,0);
  }

  f->SetParameter(0,setparam0);
  f->SetParameter(1,setparam1);
  f->SetParameter(2,setparam2);
  f->SetParameter(8,setparam3);
  f->FixParameter(1,fixparam1);
  f->FixParameter(5,0);
  h->GetEntries();

  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  hMCSignal->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto);

  f->FixParameter(1,f->GetParameter(1));
  f->FixParameter(2,f->GetParameter(2));
  f->FixParameter(7,f->GetParameter(7));
  f->FixParameter(8,f->GetParameter(8));
  f->ReleaseParameter(5);
  
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"q","",minhisto,maxhisto);
  f->ReleaseParameter(1);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L q","",minhisto,maxhisto);
  h->Fit(Form("f_%s_%.0f",tMC.Data(),ibin),"L m","",minhisto,maxhisto);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);

  TF1 *background = new TF1(Form("background_%s_%.0f",tMC.Data(),ibin),"[0]+[1]*x");
  background->SetParameter(0,f->GetParameter(3));
  background->SetParameter(1,f->GetParameter(4));
  background->SetLineColor(4);
  background->SetRange(minhisto,maxhisto);
  background->SetLineStyle(2);
  
  TF1 *Bkpi = new TF1(Form("fBkpi_%s_%.0f",tMC.Data(),ibin),"[0]*("+iNP+")");
  Bkpi->SetParameter(0,f->GetParameter(5));
  Bkpi->SetLineColor(kGreen+1);
  Bkpi->SetRange(minhisto,maxhisto);
  Bkpi->SetLineStyle(1);
  Bkpi->SetFillStyle(3004);
  Bkpi->SetFillColor(kGreen+1);

  TF1 *mass = new TF1(Form("fmass_%s_%.0f",tMC.Data(),ibin),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
  mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8));
  mass->SetParError(0,f->GetParError(0));
  mass->SetParError(1,f->GetParError(1));
  mass->SetParError(2,f->GetParError(2));
  mass->SetParError(7,f->GetParError(7));
  mass->SetParError(8,f->GetParError(8));
  mass->SetLineColor(2);

  h->SetXTitle("m_{#mu#muK} (GeV/c^{2})");
  h->SetYTitle("Entries / (5 MeV/c^{2})");
  h->GetXaxis()->CenterTitle();
  h->GetYaxis()->CenterTitle();
  h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y");
  h->GetXaxis()->SetTitleOffset(1.3);
  h->GetYaxis()->SetTitleOffset(1.8);
  h->GetXaxis()->SetLabelOffset(0.007);
  h->GetYaxis()->SetLabelOffset(0.007);
  h->GetXaxis()->SetTitleSize(0.045);
  h->GetYaxis()->SetTitleSize(0.045);
  h->GetXaxis()->SetTitleFont(42);
  h->GetYaxis()->SetTitleFont(42);
  h->GetXaxis()->SetLabelFont(42);
  h->GetYaxis()->SetLabelFont(42);
  h->GetXaxis()->SetLabelSize(0.04);
  h->GetYaxis()->SetLabelSize(0.04);
  h->SetMarkerSize(0.8);
  h->SetMarkerStyle(20);
  h->SetStats(0);
  h->Draw("e");
  Bkpi->Draw("same");
  background->Draw("same");   
  mass->SetRange(minhisto,maxhisto);
  mass->Draw("same");
  mass->SetLineStyle(2);
  mass->SetFillStyle(3004);
  mass->SetFillColor(2);
  f->Draw("same");

  Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass;
  Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0);
  
  std::cout<<"YIELD="<<yield<<std::endl;
  TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextSize(0.04);
  leg->SetTextFont(42);
  leg->SetFillStyle(0);
  leg->AddEntry(h,"Data","pl");
  leg->AddEntry(f,"Fit","l");
  leg->AddEntry(mass,"B^{+} Signal","f");
  leg->AddEntry(background,"Combinatorial","l");
  leg->Draw("same");

  TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
  texCms->SetNDC();
  texCms->SetTextAlign(12);
  texCms->SetTextSize(0.04);
  texCms->SetTextFont(42);
  texCms->Draw();

  TLatex* texCol;
  if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp"));
  else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb"));
  texCol->SetNDC();
  texCol->SetTextAlign(32);
  texCol->SetTextSize(0.04);
  texCol->SetTextFont(42);
  texCol->Draw();

  TLatex* tex;

  if(ibin>0)
    {
      if(isLarger==1) tex = new TLatex(0.22,0.78,Form("%s > %.3f",vartex.Data(),varval));
      else tex = new TLatex(0.22,0.78,Form("%s < %.3f",vartex.Data(),varval));
    }
  else tex = new TLatex(0.22,0.78,Form("%s",_nominalcut.Data()));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();

  tex = new TLatex(0.22,0.83,"|y| < 2.4");
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();

  tex = new TLatex(0.22,0.73,Form("N_{B} = %.0f #pm %.0f",yield,yieldErr));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->SetLineWidth(2);
  tex->Draw();

  c->SaveAs(Form("plotFits/DMass_%s_%s_%s_%.0f.pdf",collisionsystem.Data(),varname.Data(),tMC.Data(),ibin));
  return mass;
}
void balanceMetVsAj(TString infname = "dj_HCPR-J50U-hiGoodMergedTracks_OfficialSelv2_Final0_120_50.root",
                    TCut myCut = "cent<30", char *title = "",bool drawLegend = false,
                    bool drawSys = true
		    )
{
   // ===========================================================
   // Get Input
   // ===========================================================
   TFile *inf = new TFile(infname);
   TTree *t = (TTree*)inf->Get("ntjt");


   t->SetAlias("metxMergedAll","(metOutOfConex0+metOutOfConex1+metOutOfConex2+metOutOfConex3+metOutOfConex4+metOutOfConex5)");
   t->SetAlias("metxMerged0","(metOutOfConex0)");
   t->SetAlias("metxMerged1","(metOutOfConex1)");
   t->SetAlias("metxMerged2","(metOutOfConex2)");
   t->SetAlias("metxMerged3","(metOutOfConex3)");
   t->SetAlias("metxMerged4","(metOutOfConex4+metOutOfConex5)");

   // ===========================================================
   // Analysis Setup
   // ===========================================================
   const int nBin = 5;
   double bins[nBin+1] = {0.5,1.0,1.5,4,8,1000};
   int colors[5] = {kBlue-10,kYellow-7, kOrange-2,kGreen-5,kRed-3};
   
   const int nBinAj = 4;
   double ajBins[nBinAj+1] = {0.0001,0.11,0.22,0.33,0.49999};
   // Selection cut
   TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>2./3*TMath::Pi()&&!maskEvt";
//   TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>3&&!maskEvt";

   cout << "Sel evt: " << t->GetEntries(evtCut&&myCut) << endl;

   // ===========================================================
   // Find Average Weights
   // ===========================================================
   TH1D *hw[nBinAj];
   float meanWt[nBinAj];
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      hw[iaj] = new TH1D(Form("hw_aj%d",iaj),"",1000,0,100);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("weight>>hw_aj%d",iaj), evtCut&&myCut&&ajCut);
      meanWt[iaj] = hw[iaj]->GetMean();
      cout << " <Weight>: " << meanWt[iaj] << endl;
   }

   // ===========================================================
   // Draw Weighted Averages
   // ===========================================================
   TH1D *ppos[nBin];
   TH1D *pneg[nBin];
   TH1D *pe[nBin];
   for (int i=0;i<nBin;i++)
   {
      TH1D *h1 = new TH1D(Form("h1%d",i),"",nBinAj,ajBins);
      TH1D *h2 = new TH1D(Form("h2%d",i),"",nBinAj,ajBins);
      TH1D *he[nBinAj];
      
      // =================================
      // Get Weighted Mean for each Aj bin
      // =================================
      h1->Sumw2();
      h2->Sumw2();
      t->Draw(Form("Aj>>h1%d",i), "weight"*(evtCut&&myCut));
      t->Draw(Form("Aj>>h2%d",i), Form("((-weight*metxMerged%d))",i)*(evtCut&&myCut));
      
      pe[i]=(TH1D*)h2->Clone();
      pe[i]->SetName(Form("p%d",i));     
      pe[i]->Divide(h1);
      ppos[i] = new TH1D(Form("ppos%d",i),"",nBinAj,ajBins);
      ppos[i]->SetLineColor(1);     
      ppos[i]->SetMarkerColor(colors[i]);
      ppos[i]->SetFillColor(colors[i]);
      ppos[i]->SetFillStyle(1001);
      pneg[i] = new TH1D(Form("pneg%d",i),"",nBinAj,ajBins);
      pneg[i]->SetLineColor(1);     
      pneg[i]->SetMarkerColor(colors[i]);
      pneg[i]->SetFillColor(colors[i]);
      pneg[i]->SetFillStyle(1001);

      // =================================
      // Caculated Stat Error of the Mean
      // =================================
      cout << "Stat Error for pt bin " << i << ": ";
      for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
         he[iaj] = new TH1D(Form("he%d_aj%d",i,iaj),"",100,-200,200);
         TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
         t->Draw(Form("((metxMerged%d))>>he%d_aj%d",i,i,iaj), "weight" * evtCut&&myCut&&ajCut);
         float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
	 cout << theError << " ";
	 pe[i]->SetBinError(iaj+1, theError);
      }
      cout << endl;
   }

   // Stack
   for (int i=nBin-1;i>=0;i--)
   {
      for(int iaj = 0 ; iaj< nBinAj ; iaj++) {
         double posVal=0, negVal=0;
         double posValErr=0, negValErr=0;
         if (i!=nBin-1) {
            posVal = ppos[i+1]->GetBinContent(iaj+1);
            posValErr = ppos[i+1]->GetBinError(iaj+1);
            negVal = pneg[i+1]->GetBinContent(iaj+1);
            negValErr = pneg[i+1]->GetBinError(iaj+1);
         }
         if (pe[i]->GetBinContent(iaj+1)<0) {
            negVal+=pe[i]->GetBinContent(iaj+1);
            negValErr=pe[i]->GetBinError(iaj+1);
            posValErr=0;
         } else if (pe[i]->GetBinContent(iaj+1)>0) {
            posVal+=pe[i]->GetBinContent(iaj+1);
            posValErr=pe[i]->GetBinError(iaj+1);
            negValErr=0;
         } 
         ppos[i]->SetBinContent(iaj+1,posVal);
         ppos[i]->SetBinError(iaj+1,posValErr);
         pneg[i]->SetBinContent(iaj+1,negVal);
         pneg[i]->SetBinError(iaj+1,negValErr);
      }
   }
   
   TH1D *pall;
   TH1D *pallE;
   TH1D *h1 = new TH1D(Form("hAll1"),"",nBinAj,ajBins);
   TH1D *h2 = new TH1D(Form("hAll2"),"",nBinAj,ajBins);

   h1->Sumw2();
   h2->Sumw2();
   t->Draw(Form("Aj>>hAll1"), "weight"*(evtCut&&myCut));
   t->Draw(Form("Aj>>hAll2"), Form("((-weight*metxMergedAll))")*(evtCut&&myCut));
   pall=(TH1D*)h2->Clone();
   pall->SetName("pall");
   pall->Divide(h1);

   // replace the sys error from pallE to pall 
   TH1D *he[nBinAj];
   cout << "Stat Error for All pt: ";
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      he[iaj] = new TH1D(Form("heAll_aj%d",iaj),"",100,-200,200);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("((metxMergedAll))>>heAll_aj%d",iaj), "weight" * evtCut&&myCut&&ajCut);
      float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
      cout << theError << " ";
      pall->SetBinError(iaj+1,  theError);
   }
   cout << endl;

   pall->SetXTitle("A_{J}");
   pall->SetYTitle("<#slash{p}_{T}^{#parallel}> (GeV/c)");
   pall->GetXaxis()->CenterTitle();
   pall->GetYaxis()->CenterTitle();
   pall->GetXaxis()->SetLabelSize(22);
   pall->GetXaxis()->SetLabelFont(43);
   pall->GetXaxis()->SetTitleSize(24);
   pall->GetXaxis()->SetTitleFont(43);
   pall->GetYaxis()->SetLabelSize(22);
   pall->GetYaxis()->SetLabelFont(43);
   pall->GetYaxis()->SetTitleSize(24);
   pall->GetYaxis()->SetTitleFont(43);
   pall->GetXaxis()->SetTitleOffset(1.8);
   pall->GetYaxis()->SetTitleOffset(2.4);
   pall->SetNdivisions(505);
   pall->SetAxisRange(-59.9,59.9,"Y");
   pall->SetMarkerSize(1);
   pall->Draw("E");
   float addSys = 0;
   if ( drawSys==1)   addSys=0; // No sys error at this moment

   // ====================
   // Finally Draw
   // ====================
   for (int i=0;i<nBin;++i) {
      ppos[i]->SetLineWidth(1);
      ppos[i]->Draw("hist same");
      pneg[i]->SetLineWidth(1);
      pneg[i]->Draw("hist same");
   }
   
   // ====================
   // Draw Statistical Error bars
   // ====================
   for (int i=0;i<nBin;++i) {
      if ( i==0 )       drawErrorShift(ppos[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(ppos[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(ppos[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(ppos[i],0.016,addSys);
      if ( i==0 )       drawErrorShift(pneg[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(pneg[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(pneg[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(pneg[i],0.016,addSys);
   }
   pall->Draw("E same");
   
   // ====================
   // Draw Systematic Errors
   // ====================
   if (drawSys == 1) {
      for(int i = 0; i < nBinAj; ++i){
        double x = pall->GetBinCenter(i+1);
        double y = pall->GetBinContent(i+1);
        // Quote the difference between GEN and RECO in >8 Bin (20%) before adjusting eff as systematics
        double err = fabs(pe[nBin-1]->GetBinContent(i+1)*0.2);
        DrawTick(y,err,err,x,1,0.02,1);
      }
   }

   // ====================
   // Draw Legend
   // ====================
   TLegend *leg = new TLegend(0.10,0.68,0.70,0.96);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->SetTextFont(63);
   leg->SetTextSize(16);
   leg->AddEntry(pall,Form("> %.1f GeV/c",bins[0]),"pl");
   for (int i=0;i<nBin;++i) {
      if (i!=nBin-1){
         leg->AddEntry(ppos[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"f");
      } else {
         leg->AddEntry(ppos[i],Form("> %.1f GeV/c",bins[i]),"f");
      }
   }

   if (drawLegend) leg->Draw();

   TLine * l0 = new TLine(0,0,0.5,0);
   l0->SetLineStyle(2);
   l0->Draw();


   TLine * l1 = new TLine(0.0001,-10,0.0001,10);
   l1->Draw();

   TText *titleText = new TText(0.3,30,title);
   titleText->Draw();
}
void drawSys_merged() {
  //  TH1::SetDefaultSumw2();
    gStyle -> SetOptStat(0);
    const int kPPcentral = 1;
    const int kPPperipheral =2 ;
    const int kHIcentral =  3;
    const int kHIperipheral = 4;
    const int kPADATA = 5;
    const int kPAMC = 6;

  TH1D* dNdJetPt[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* dNdJetPtSys[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* dNdJetPtSysIaa[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* meanJetPt[7];   // [collision] [Before/After variation]
  TH1D* meanJetPtSys[7];   // [collision] [Before/After variation]
  TH1D* meanRjg[7];
  TH1D* meanRjgSys[7];
  
  TH1D* bmeanJetPt[7];   // [collision] [Before/After variation]
  TH1D* bmeanJetPtSys[7];   // [collision] [Before/After variation]
  TH1D* bmeanRjg[7];
  TH1D* bmeanRjgSys[7];
  
  TFile * f = new TFile("../resultHistograms_ppSmeared10030.root");
  bmeanJetPt[1]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  bmeanRjg[1]  =(TH1D*)f->Get(Form("meanRjg_pp"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[1][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pp_ptBin%d", ipt ));
  }  

  f   = new TFile("../resultHistograms_ppSmeared13099.root");
  bmeanJetPt[2]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  bmeanRjg[2]  =(TH1D*)f->Get(Form("meanRjg_pp"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[2][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pp_ptBin%d", ipt ));
  }  
  
  // pbpb
  f =   new TFile("../resultHistograms_jetResCorrection.root");
  bmeanJetPt[3]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin1"));
  bmeanRjg[3]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin1"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[3][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pbpb_centralityBin1_ptBin%d", ipt ));
  }
  bmeanJetPt[4]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin2"));
  bmeanRjg[4]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin2"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[4][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pbpb_centralityBin2_ptBin%d", ipt ));
  }
  // pPb
  f =   new TFile("../resultHistograms_jetResCorrection.root");
  bmeanJetPt[5]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  bmeanRjg[5]  =(TH1D*)f->Get(Form("meanRjg_ppb"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[5][ipt] = (TH1D*)f->Get(Form("dNdJetPt_ppb_ptBin%d", ipt ));
  }
  
  f =   new TFile("../resultHistograms_MC_recoIsoPhoton.root");
  bmeanJetPt[6]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  bmeanRjg[6]  =(TH1D*)f->Get(Form("meanRjg_ppb"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[6][ipt] = (TH1D*)f->Get(Form("dNdJetPt_ppb_ptBin%d", ipt ));
  }  
  
  
  TFile* fSys = new TFile("../merged/relativeSys_merged.root");
  
  bmeanJetPtSys[1]  =(TH1D*)fSys->Get("meanJetPt_pp_uncertainty_merged");
  bmeanRjgSys[1]  =(TH1D*)fSys->Get(Form("meanRjg_pp_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[1][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pp_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[2] = (TH1D*)bmeanJetPtSys[1]->Clone(Form("%s_2",bmeanJetPtSys[1]->GetName()));
  bmeanRjgSys[2] = (TH1D*)bmeanRjgSys[1]->Clone(Form("%s_2",bmeanRjgSys[1]->GetName()));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[2][ipt] = (TH1D*)dNdJetPtSysIaa[1][ipt]->Clone(Form("%s_2",dNdJetPtSysIaa[1][ipt]->GetName()));
  }
  bmeanJetPtSys[3]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin1_uncertainty_merged");
  bmeanRjgSys[3]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin1_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[3][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pbpb_centralityBin1_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[4]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin2_uncertainty_merged");
  bmeanRjgSys[4]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin2_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[4][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pbpb_centralityBin2_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[5]  =(TH1D*)fSys->Get("meanJetPt_ppb_uncertainty_merged");
  bmeanRjgSys[5]  =(TH1D*)fSys->Get(Form("meanRjg_ppb_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[5][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_ppb_ptBin%d_uncertainty_merged",  ipt ));
  }


  
  // transplant the uncertainty  
  for ( int coll = 1 ; coll<=5 ; coll++) {
    for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
      dNdJetPtSys[coll][ipt] = (TH1D*) dNdJetPt[coll][ipt]->Clone(Form("dNdJetPtSys_coll%d_ipt%d",coll,ipt));
      dNdJetPtSys[coll][ipt]->Reset();
      for ( int ibin = 1 ; ibin<= dNdJetPtSys[coll][ipt]->GetNbinsX() ; ibin++) {
	float xx = dNdJetPtSys[coll][ipt]->GetBinCenter(ibin);
	float yy = dNdJetPtSysIaa[coll][ipt]->GetBinContent ( dNdJetPtSysIaa[coll][ipt]->FindBin(xx) );
	if ( yy>1 ) yy = 1;
	dNdJetPtSys[coll][ipt]->SetBinContent(ibin,yy);

      }
    }
  }

  for(int icoll=1; icoll<=6; icoll++){
      meanJetPt[icoll] = new TH1D(Form("%s_corrected", bmeanJetPt[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      meanRjg[icoll] = new TH1D(Form("%s_corrected", bmeanRjg[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      if(icoll<6){
          meanJetPtSys[icoll] = new TH1D(Form("%s_corrected", bmeanJetPtSys[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
          meanRjgSys[icoll] = new TH1D(Form("%s_corrected", bmeanRjgSys[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      }
  }

  for(int icoll=1; icoll<=6; icoll++){ 
      meanPtHist(bmeanJetPt[icoll], meanJetPt[icoll]);    
      meanPtHist(bmeanRjg[icoll],  meanRjg[icoll]); 
      if(icoll<6){
          meanPtHist(bmeanJetPtSys[icoll],meanJetPtSys[icoll]) ;  
          meanPtHist(bmeanRjgSys[icoll], meanRjgSys[icoll]); 
      }
  } 

  // RJG!!
  TCanvas* c2 = new TCanvas("c1","",1000,500);
  c2->Divide(2,1);
  c2->cd(2);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  TH1D* tempR = new TH1D("tempR",";p_{T}^{#gamma};R_{j#gamma}",100,40,130);
  tempR->Reset();  
  handsomeTH1(tempR,0);
  tempR->SetAxisRange(0,1.2,"Y");
  tempR->Draw();
  drawSys(meanRjg[1], meanRjgSys[1], kGreen);
  drawSys(meanRjg[3], meanRjgSys[3]);
  meanRjg[1]->Draw("same");
  handsomeTH1(meanRjg[3],2 );
//  meanRjg[3]->SetMarkerStyle(24);
  meanRjg[3]->Draw("same");
  if ( 1==1 ){ 
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");    
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanRjg[3],"PbPb 0-30%","p");
    ly->AddEntry(meanRjg[1],"pp (smeared)","p");
    ly->Draw();
  }


  c2->cd(1);
  tempR->Draw();
  handsomeTH1(meanRjg[2],1 );
  drawSys(meanRjg[2], meanRjgSys[2], kGreen);
  drawSys(meanRjg[4], meanRjgSys[4]);
  meanRjg[2]->Draw("same");
  handsomeTH1(meanRjg[4],2 );
  meanRjg[4]->SetMarkerStyle(24);
  meanRjg[4]->Draw("same");
  if ( 1==1 ){ 
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");    
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanRjg[4],"PbPb 30-100%","p");
    ly->AddEntry(meanRjg[2],"pp (smeared)","p");
    ly->Draw();
  }
  c2->SaveAs("pT_depedence_rjg_pp_pbpb.pdf");

  
  TCanvas* c2pa = new TCanvas("c1pa","",500,500);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)                         
  //  tempR->Draw();
  TH1D* tempJ = new TH1D("tempJ",";p_{T}^{#gamma}; <p_{T}^{Jet}>",100,40,130);
  tempJ->Reset();
  handsomeTH1(tempJ,0);
  tempJ->SetAxisRange(0,100,"Y");
  tempJ->Draw();
  drawSys(meanJetPt[5], meanJetPtSys[5], kYellow);
  handsomeTH1(meanJetPt[5],2);
  handsomeTH1(meanJetPt[6],1);
  meanJetPt[5]->Draw("same");
  meanJetPt[6]->Draw("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.4484643,0.3088445,0.9140673,0.50102941,NULL,"brNDC");
    easyLeg(ly,"5.02TeV pPb");
    ly->AddEntry(meanJetPt[5],"DATA","p");
    ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  c2pa->SaveAs("pT_dependence_rjg_pA_figure1.pdf");

  TCanvas* c3pa = new TCanvas("c3pa","",500,500);
  tempR->Draw();
  drawSys(meanRjg[5], meanRjgSys[5], kYellow);
  handsomeTH1(meanRjg[5],2);
  handsomeTH1(meanRjg[6],1);
  meanRjg[5]->Draw("same");
  meanRjg[6]->Draw("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.4484643,0.3088445,0.9140673,0.50102941,NULL,"brNDC");
    easyLeg(ly,"5.02TeV pPb");
    ly->AddEntry(meanRjg[5],"DATA","p");
    ly->AddEntry(meanRjg[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }  
  c3pa->SaveAs("pT_dependence_jetPt_pA_figure2.pdf");

  TCanvas* c3 = new TCanvas("c3","",1000,500);
  c3->Divide(2,1);
  c3->cd(2);
  handsomeTH1(meanJetPt[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)                                                       
   tempJ->Draw();
  drawSys(meanJetPt[1], meanJetPtSys[1], kGreen);
  drawSys(meanJetPt[3], meanJetPtSys[3]);
  meanJetPt[1]->Draw("same");
  handsomeTH1(meanJetPt[3],2 );
  meanJetPt[3]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanJetPt[3],"PbPb 0-30%","p");
    ly->AddEntry(meanJetPt[1],"pp (smeared)","p");
    ly->Draw();
  }
  
  c3->cd(1);
  tempJ->Draw();
  handsomeTH1(meanJetPt[2],1 );
//  meanJetPt[2]->Draw();
  drawSys(meanJetPt[2], meanJetPtSys[2], kGreen);
  drawSys(meanJetPt[4], meanJetPtSys[4]);
  meanJetPt[2]->Draw("same");
  handsomeTH1(meanJetPt[4],2 );
  meanJetPt[4]->SetMarkerStyle(24);
  meanJetPt[4]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
    ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
    ly->Draw();
  }
  c3->SaveAs("pT_dependence_jetPt_pp_pbpb.pdf");
  
  TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);
  TCanvas* c5 = new TCanvas("c5","",1200,700);
  makeMultiPanelCanvas(c5,nPtBin,2,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    c5->cd(ipt+nPtBin);
    // draw pp                                                                                                                                           
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");                                                                                                        
    hTempPt->SetAxisRange(0,0.07,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[1][ipt], dNdJetPtSys[1][ipt], kGreen);
    drawSys(dNdJetPt[3][ipt], dNdJetPtSys[3][ipt], kYellow);
    handsomeTH1(dNdJetPt[3][ipt],2);
    dNdJetPt[1][ipt]->Draw("same");
    dNdJetPt[3][ipt]->Draw("same");
    if ( ipt == 1 ) {
      TLegend *ly = new TLegend(0.4484643,0.6988445,0.9140673,0.9102941,NULL,"brNDC");
      easyLeg(ly,"2.76TeV");
      ly->AddEntry(meanJetPt[1],"PbPb 0-30%","p");
      ly->AddEntry(meanJetPt[3],"pp (smeared)","p");
      ly->Draw();
    }
 

    c5->cd(ipt);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[2][ipt], dNdJetPtSys[2][ipt], kGreen);
    drawSys(dNdJetPt[4][ipt], dNdJetPtSys[4][ipt], kYellow);
    handsomeTH1(dNdJetPt[4][ipt],2);
    dNdJetPt[4][ipt]->SetMarkerStyle(24);
    dNdJetPt[2][ipt]->Draw("same");
    dNdJetPt[4][ipt]->Draw("same");
    if ( ipt==1 ){
      TLegend *ly = new TLegend(0.4484643,0.5088445,0.9140673,0.75102941,NULL,"brNDC");
      easyLeg(ly,"2.76TeV");
      ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
      ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
      ly->Draw();
    }

    double dx1=0.15;
    if ( ipt == nPtBin )
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823                                           
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823                       

    
  }
  c5->SaveAs("pT_dependence_jetPt_pp_pbpb_distribution.pdf");

  TCanvas* c5pa = new TCanvas("c5pa","",1200,350);
  makeMultiPanelCanvas(c5pa,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    c5pa->cd(ipt);
    // draw pp                                                                                                                                           
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");                                                                                                        
    hTempPt->SetAxisRange(0,0.07,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[5][ipt], dNdJetPtSys[5][ipt], kYellow);
    handsomeTH1(dNdJetPt[5][ipt],2);
    dNdJetPt[6][ipt]->Draw("same");
    dNdJetPt[5][ipt]->Draw("same");
    if ( ipt == 1 ) {
      TLegend *ly = new TLegend(0.4855983,0.5529059,0.9512013,0.7645899,NULL,"brNDC");
      easyLeg(ly,"5.02TeV pPb");
      ly->AddEntry(meanJetPt[5],"Data","p");
      ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
      ly->Draw();
    }
    double dx1=0.15;
    if ( ipt == nPtBin )
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823                                           
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823                       
    
    
  }
  c5pa->SaveAs("pT_dependence_jetPt_pA_distribution.pdf");
  
  
  
}