Exemple #1
0
void fitscatterplot()
{
   //example illustrating how to fit a 2-d histogram of type y=f(x)
   //Author: Rene Brun

   // generate a 2-d histogram using a TCutG
   TFile *f;
   f = new TFile("../../../rootfiles/closure/pPb/185_220/Merged.root");
   TH2D *h2 = new TH2D("h2","h2",1000,-0.3,0.3,1000,-0.3,0.3);



   TCanvas *c1 = new TCanvas("c1","show profile",1,1,600,600);
   //c1->Divide(2,1,0.01,0.01);

   h2 = (TH2D*)f->Get("demo/genrecoach");

   double r;
   r = h2->GetCorrelationFactor();



   /*
   h2->Rebin2D(5,1);
   r = h2->GetCorrelationFactor();
   c1->cd(2);

   //use a TProfile to convert the 2-d to 1-d problem
   TProfile *prof = h2->ProfileX();
   //prof->Fit("pol1");
   prof->GetYaxis()->SetRangeUser(-0.08,0.08);
   prof->GetXaxis()->SetRangeUser(-0.08,0.08);
   prof->SetYTitle("A_{ch}");
   prof -> GetXaxis() -> CenterTitle();
   prof -> GetYaxis() -> CenterTitle();
   prof->SetLabelOffset(0.006,"Y");
   prof->SetTitleOffset(1.800,"Y");
   prof->SetMarkerStyle(20);
   prof->SetMarkerColor(kBlack);
   prof->SetMarkerSize (0.3);
   prof->SetMarkerStyle(1);
   prof->SetLineStyle(1);
   prof->SetLineWidth(1);   
   prof->Fit("pol1");
   TF1 *fit1 = prof->GetListOfFunctions()->FindObject("pol1");
   TLatex* text2 = makeLatex(Form("slope : %.3f #pm %.3f",fit1->GetParameter(1),fit1->GetParError(1)),0.55,0.25) ;


   if(fit1)
   {
      fit1->SetLineColor(kRed); 
      fit1->SetLineWidth(3);
      fit1->SetLineStyle(1);
   }

  // text_a->Draw("Same");
   text2->Draw("Same");
   TF1 *fa1 = new TF1("fa1","0",-10,10); 
   fa1->SetLineColor(kBlack);
   fa1->SetLineWidth(1);
   fa1->DrawClone("Same");
   prof->DrawClone("Same");



*/
   c1->cd(1);
   c1->cd(1)->SetRightMargin(0.12);


   h2 -> GetXaxis()->CenterTitle();
   h2 -> GetYaxis()->CenterTitle();
   h2 ->GetXaxis()->SetRangeUser(-0.4, 0.4);
   h2 ->GetYaxis()->SetRangeUser(-0.4, 0.4);
   h2->Rebin2D(8,8);



   h2->Draw("colz");

 //  prof->SetLineColor(kRed); 
//   prof->SetLineWidth(5);


//   prof->Draw("Same");


   TLatex* text3 = makeLatex(Form("correlationfactor : %f",r),0.40,0.17) ;

   text3->Draw("same");


 //  text_a->Draw("Same");



   /*
   TH1D* ChargeAsym;


   f = new TFile("../../../rootfiles/closure/Merged.root");
   ChargeAsym = (TH1D*)f->Get("demo/ChargeAsym");
   ChargeAsym->GetXaxis()->SetRangeUser(-0.25,0.25);
   ChargeAsym->GetXaxis()->SetTitle("Observed A_{ch}");
   ChargeAsym->GetYaxis()->SetTitle(" Counts ");
   ChargeAsym->GetXaxis()->CenterTitle();
   ChargeAsym->GetYaxis()->CenterTitle();
   ChargeAsym->SetTitleOffset(1.8,"Y");



   c1->cd(1);
   ChargeAsym->Draw();





   //prof->Draw();   

   */

   SaveCanvas(c1,"pics",Form("fitscatterplot_clsouretest_pPb_185_220"));

}
void achDistwithVerticalLines()
{   

   TH1D* achdist[6];
   TH1D* achdisttemp[6][7];
   int ntrklist[7] = {90,120,150,185,220,260,300};

//   TH1D* achdist[6];
//   int centralitylist[7] = {30,40,50,60,70,80,90}
   gStyle->SetLegendFont(42);
   TCanvas* c1 = new TCanvas("c1","c1",1,1,600,600);


   //f = new TFile("~/Summer2016/rootfiles/FinalResult_0106/Main_PbPb_Merged.root");
      f = new TFile("~/Summer2016/rootfiles/FinalResult_0106/Main_pPb_Merged.root");


   achdist[3] = (TH1D*)f->Get("demo_n3/ChargeAsym");
  // achdist[3]->Rebin(5);

   achdist[3]->GetXaxis()->SetRangeUser(-0.25, 0.25);
  // achdist[3]->GetYaxis()->SetRangeUser(0, 500000);

   //achdist[3]->SetMarkerColor(kBlue);

 /*  TLine *l1 = new TLine(-0.07,0,-0.07,300000);
   TLine *l2 = new TLine(-0.03,0,-0.03,400000);
   TLine *l3 = new TLine(-0.01,0,-0.01,450000);
   TLine *l4 = new TLine(0.01,0,0.01,450000);
   TLine *l5 = new TLine(0.03,0,0.03,400000);
   TLine *l6 = new TLine(0.07,0,0.07,300000);
*/
   TLine *l1 = new TLine(-0.085,0,-0.085,300000);
   TLine *l2 = new TLine(-0.05,0,-0.05,400000);
   TLine *l3 = new TLine(-0.025,0,-0.025,450000);
   TLine *l4 = new TLine(0.025,0,0.025,450000);
   TLine *l5 = new TLine(0.05,0,0.05,400000);
   TLine *l6 = new TLine(0.085,0,0.085,300000);
   l1->SetLineColor(kBlue);
   l1->SetLineStyle(2);
   l1->SetLineWidth(3);

   l2->SetLineColor(kBlue);
   l2->SetLineStyle(2);
   l2->SetLineWidth(3);

   l3->SetLineColor(kBlue);
   l3->SetLineStyle(2);
   l3->SetLineWidth(3);

   l4->SetLineColor(kBlue);
   l4->SetLineStyle(2);
   l4->SetLineWidth(3);

   l5->SetLineColor(kBlue);
   l5->SetLineStyle(2);
   l5->SetLineWidth(3);

   l6->SetLineColor(kBlue);
   l6->SetLineStyle(2);
   l6->SetLineWidth(3);



   achdist[3]->Draw();
   achdist[3]->GetXaxis()->SetTitle("Observed A_{ch}");
   achdist[3]->GetYaxis()->SetTitle("Count");
   achdist[3]->GetXaxis()->CenterTitle();
   achdist[3]->GetYaxis()->CenterTitle();
   achdist[3]->SetTitleSize  (0.040,"X");
   achdist[3]->SetTitleOffset(1.4,"X");
   achdist[3]->SetTitleFont  (42,"X");
   achdist[3]->SetLabelOffset(0.006,"X");
   achdist[3]->SetLabelSize  (0.040,"X");
   achdist[3]->SetLabelFont  (42   ,"X");

   achdist[3]->SetTitleSize  (0.040,"Y");
   achdist[3]->SetTitleOffset(2.2,"Y");
   achdist[3]->SetTitleFont  (42,"Y");
   achdist[3]->SetLabelOffset(0.006,"Y");
   achdist[3]->SetLabelSize  (0.040,"Y");
   achdist[3]->SetLabelFont  (42   ,"Y");
   achdist[3]->SetLineWidth(0);
   TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.23,0.87) ;

   TLatex* text_b = makeLatex("30-40%",0.23,0.82) ;

   TLatex* text_c = makeLatex("0.3 < p_{T} < 3.0 GeV/c",0.23,0.75) ;

   text_a->SetTextFont(42);

   text_b->SetTextFont(42);

   text_c->SetTextFont(42);

   text_a->DrawClone("Same");
   text_b->DrawClone("Same");
   //text_c->DrawClone("Same");


   l1->Draw("same");
   l2->Draw("same");
   l3->Draw("same");
   l4->Draw("same");
   l5->Draw("same");
   l6->Draw("same");
   SaveCanvas(c1,"pics","achwithverticallines");

}
  /** Output Latex table of options.*/
  void 
  RegisteredOptions::writeLatexOptionsTable(std::ostream &of, ExtraCategoriesInfo which){
  std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption> > 
           registered_options = RegisteredOptionsList();

  //Print table header
  //of<<"\\begin{threeparttable}"<<std::endl
  of<<"\\topcaption{\\label{tab:options} "<<std::endl
    <<"List of options and compatibility with the different algorithms."<<std::endl
    <<"}"<<std::endl;
  of<<"\\tablehead{\\hline "<<std::endl
    <<"Option & type & ";
  //of<<" default & ";
  of<<"{\\tt B-BB} & {\\tt B-OA} & {\\tt B-QG} & {\\tt B-Hyb} & {\\tt B-Ecp} & {\\tt B-iFP} & {\\tt Cbc\\_Par} \\\\"<<std::endl
    <<"\\hline"<<std::endl
    <<"\\hline}"<<std::endl;
  of<<"\\tabletail{\\hline \\multicolumn{9}{|c|}{continued on next page}\\\\"
    <<"\\hline}"<<std::endl; 
  of<<"\\tablelasttail{\\hline}"<<std::endl;
  of<<"{\\footnotesize"<<std::endl;
  of<<"\\begin{xtabular}{@{}|@{\\;}l@{\\;}|@{\\;}r@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{}}"<<std::endl;

  //sort options by categories and alphabetical order
  std::list< Ipopt::RegisteredOption * > sortedOptions;
 
  for(std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption > >::iterator i = 
          registered_options.begin(); i != registered_options.end() ; i++){
     if(categoriesInfo(i->second->RegisteringCategory()) == which)
     sortedOptions.push_back(GetRawPtr(i->second));
     }

   sortedOptions.sort(optionsCmp());
   std::string registeringCategory = "";
   for(std::list< Ipopt::RegisteredOption * >::iterator i = sortedOptions.begin();
       i != sortedOptions.end() ; i++)
   {
     if((*i)->RegisteringCategory() != registeringCategory){
     registeringCategory = (*i)->RegisteringCategory();
     of<<"\\hline"<<std::endl
       <<"\\multicolumn{1}{|c}{} & \\multicolumn{8}{l|}{"
       <<registeringCategory<<"}\\\\"<<std::endl
       <<"\\hline"<<std::endl;
     }
     
     of<<makeLatex((*i)->Name())<<"& "<<OptionType2Char((*i)->Type())//<<"& "
       //<<makeLatex(defaultAsString(*i))
       <<"& "<<( (isValidForBBB((*i)->Name()))? "$\\surd$" : "-" )
       <<"& "<<( (isValidForBOA((*i)->Name()))? "$\\surd$" : "-" )
       <<"& "<<( (isValidForBQG((*i)->Name()))? "$\\surd$" : "-" )
       <<"& "<<( (isValidForHybrid((*i)->Name()))? "$\\surd$" : "-" )
       <<"& "<<( (isValidForBEcp((*i)->Name()))? "$\\surd$" : "-" )
       <<"& "<<( (isValidForBiFP((*i)->Name()))? "$\\surd$" : "-" )
       <<"& "<<( (isValidForCbc((*i)->Name()))? "$\\surd$" : "-" )
       <<"\\\\"<<std::endl;
   }
   //Print table end
  of<<"\\hline"<<std::endl
    <<"\\end{xtabular}"<<std::endl;
  of<<"}"<<std::endl;
#if 0
  of<<"\\begin{tablenotes}"<<std::endl
    <<"\\item $\\strut^*$ option is available"<<std::endl
    <<"        for MILP subsolver (it is only passed if the {\\tt milp\\_subsolver} optio"<<std::endl
    <<"        see Subsection \\ref{sec:milp_opt})."<<std::endl
    <<"       \\item $\\strut^1$ disabled for stability reasons."<<std::endl
    <<"\\end{tablenotes}"<<std::endl
    <<"\\end{threeparttable} "<<std::endl;
#endif
  }