Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:53

0001 //////////////////////////////////////////////////////////////////////////////
0002 // Usage:
0003 // .L FitPV.C+g
0004 //             For carrying out Gaussian convoluted Landau function to
0005 //             the charge
0006 //     void doFit(infile, text, iPeriod, etaMin, etamax, dmin, dmax, vxmin,
0007 //                vxmax, phimin, phimax, phiInc, ifHPD, writeExtraText)
0008 //
0009 //
0010 //  where
0011 //   infile  (std::string) Nme of the input file
0012 //   text    (std::string)
0013 //   iPeriod (int)         ieta value of the tower
0014 //   etaMin  (int)       | range of ieta's to
0015 //   etaMax  (int)       | be considered
0016 //   dmin, dmax (int)      range of depths to be done
0017 //   vxmin,vxmax(int)      range of number of vertex to be considered
0018 //   phiMin  (int)       | range of iphi's to
0019 //   phiMax  (int)       | be considered
0020 //   phiInc  (int)         incerement in phi (1 or 2 depending on iphi value)
0021 //   ifHPD   (bool)        if the ditribution is from HPD or SiPM
0022 //   writeExtraText(bool)  if extra text to be written
0023 //
0024 ///////////////////////////////////////////////////////////////////////////////
0025 
0026 #include <TArrow.h>
0027 #include <TASImage.h>
0028 #include <TCanvas.h>
0029 #include <TChain.h>
0030 #include <TFile.h>
0031 #include <TF1.h>
0032 #include <TFitResult.h>
0033 #include <TFitResultPtr.h>
0034 #include <TGraph.h>
0035 #include <TGraphErrors.h>
0036 #include <TGraphAsymmErrors.h>
0037 #include <TH1D.h>
0038 #include <TH2D.h>
0039 #include <TLatex.h>
0040 #include <TLegend.h>
0041 #include <TPaveStats.h>
0042 #include <TPaveText.h>
0043 #include <TProfile.h>
0044 #include <TROOT.h>
0045 #include <TStyle.h>
0046 
0047 #include <cstdlib>
0048 #include <iomanip>
0049 #include <iostream>
0050 #include <fstream>
0051 #include <map>
0052 #include <string>
0053 #include <vector>
0054 
0055 using namespace RooFit;
0056 
0057 void setTDRStyle() {
0058   TStyle* tdrStyle = new TStyle("tdrStyle", "Style for P-TDR");
0059 
0060   // For the canvas:
0061   tdrStyle->SetCanvasBorderMode(0);
0062   tdrStyle->SetCanvasColor(kWhite);
0063   tdrStyle->SetCanvasDefH(600);  //Height of canvas
0064   tdrStyle->SetCanvasDefW(600);  //Width of canvas
0065   tdrStyle->SetCanvasDefX(0);    //POsition on screen
0066   tdrStyle->SetCanvasDefY(0);
0067 
0068   // For the Pad:
0069   tdrStyle->SetPadBorderMode(0);
0070   // tdrStyle->SetPadBorderSize(Width_t size = 1);
0071   tdrStyle->SetPadColor(kWhite);
0072   tdrStyle->SetPadGridX(false);
0073   tdrStyle->SetPadGridY(false);
0074   tdrStyle->SetGridColor(0);
0075   tdrStyle->SetGridStyle(3);
0076   tdrStyle->SetGridWidth(1);
0077 
0078   // For the frame:
0079   tdrStyle->SetFrameBorderMode(0);
0080   tdrStyle->SetFrameBorderSize(1);
0081   tdrStyle->SetFrameFillColor(0);
0082   tdrStyle->SetFrameFillStyle(0);
0083   tdrStyle->SetFrameLineColor(1);
0084   tdrStyle->SetFrameLineStyle(1);
0085   tdrStyle->SetFrameLineWidth(1);
0086 
0087   // For the histo:
0088   // tdrStyle->SetHistFillColor(1);
0089   // tdrStyle->SetHistFillStyle(0);
0090   tdrStyle->SetHistLineColor(1);
0091   tdrStyle->SetHistLineStyle(0);
0092   tdrStyle->SetHistLineWidth(1);
0093   // tdrStyle->SetLegoInnerR(Float_t rad = 0.5);
0094   tdrStyle->SetNumberContours(20);
0095 
0096   tdrStyle->SetEndErrorSize(2);
0097   // tdrStyle->SetErrorMarker(20);
0098   // tdrStyle->SetErrorX(0.);
0099 
0100   tdrStyle->SetMarkerStyle(20);
0101 
0102   //For the fit/function:
0103   tdrStyle->SetOptFit(1);
0104   tdrStyle->SetFitFormat("5.4g");
0105   tdrStyle->SetFuncColor(2);
0106   tdrStyle->SetFuncStyle(1);
0107   tdrStyle->SetFuncWidth(1);
0108 
0109   //For the date:
0110   tdrStyle->SetOptDate(0);
0111   // tdrStyle->SetDateX(Float_t x = 0.01);
0112   // tdrStyle->SetDateY(Float_t y = 0.01);
0113 
0114   // For the statistics box:
0115   tdrStyle->SetOptFile(0);
0116   tdrStyle->SetOptStat(0);  // To display the mean and RMS:   SetOptStat("mr");
0117   tdrStyle->SetStatColor(kWhite);
0118   tdrStyle->SetStatFont(42);
0119   tdrStyle->SetStatFontSize(0.025);
0120   tdrStyle->SetStatTextColor(1);
0121   tdrStyle->SetStatFormat("6.4g");
0122   tdrStyle->SetStatBorderSize(1);
0123   tdrStyle->SetStatH(0.1);
0124   tdrStyle->SetStatW(0.15);
0125   // tdrStyle->SetStatStyle(Style_t style = 1001);
0126   // tdrStyle->SetStatX(Float_t x = 0);
0127   // tdrStyle->SetStatY(Float_t y = 0);
0128 
0129   // Margins:
0130   tdrStyle->SetPadTopMargin(0.05);
0131   tdrStyle->SetPadBottomMargin(0.13);
0132   tdrStyle->SetPadLeftMargin(0.16);
0133   tdrStyle->SetPadRightMargin(0.02);
0134 
0135   // For the Global title:
0136 
0137   tdrStyle->SetOptTitle(0);
0138   tdrStyle->SetTitleFont(42);
0139   tdrStyle->SetTitleColor(1);
0140   tdrStyle->SetTitleTextColor(1);
0141   tdrStyle->SetTitleFillColor(10);
0142   tdrStyle->SetTitleFontSize(0.05);
0143   // tdrStyle->SetTitleH(0); // Set the height of the title box
0144   // tdrStyle->SetTitleW(0); // Set the width of the title box
0145   // tdrStyle->SetTitleX(0); // Set the position of the title box
0146   // tdrStyle->SetTitleY(0.985); // Set the position of the title box
0147   // tdrStyle->SetTitleStyle(Style_t style = 1001);
0148   // tdrStyle->SetTitleBorderSize(2);
0149 
0150   // For the axis titles:
0151 
0152   tdrStyle->SetTitleColor(1, "XYZ");
0153   tdrStyle->SetTitleFont(42, "XYZ");
0154   tdrStyle->SetTitleSize(0.06, "XYZ");
0155   // tdrStyle->SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
0156   // tdrStyle->SetTitleYSize(Float_t size = 0.02);
0157   tdrStyle->SetTitleXOffset(0.9);
0158   tdrStyle->SetTitleYOffset(1.25);
0159   // tdrStyle->SetTitleOffset(1.1, "Y"); // Another way to set the Offset
0160 
0161   // For the axis labels:
0162 
0163   tdrStyle->SetLabelColor(1, "XYZ");
0164   tdrStyle->SetLabelFont(42, "XYZ");
0165   tdrStyle->SetLabelOffset(0.007, "XYZ");
0166   tdrStyle->SetLabelSize(0.05, "XYZ");
0167 
0168   // For the axis:
0169 
0170   tdrStyle->SetAxisColor(1, "XYZ");
0171   tdrStyle->SetStripDecimals(kTRUE);
0172   tdrStyle->SetTickLength(0.03, "XYZ");
0173   tdrStyle->SetNdivisions(510, "XYZ");
0174   tdrStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
0175   tdrStyle->SetPadTickY(1);
0176 
0177   // Change for log plots:
0178   tdrStyle->SetOptLogx(0);
0179   tdrStyle->SetOptLogy(0);
0180   tdrStyle->SetOptLogz(0);
0181 
0182   // Postscript options:
0183   tdrStyle->SetPaperSize(20., 20.);
0184   tdrStyle->SetHatchesLineWidth(5);
0185   tdrStyle->SetHatchesSpacing(0.05);
0186 
0187   tdrStyle->cd();
0188 }
0189 
0190 void CMS_lumi(TPad* pad, int iPeriod, int iPosX) {
0191   TString cmsText = "CMS";
0192   const float cmsTextFont = 61;
0193   const bool writeExtraText = false;
0194   TString extraText = "Preliminary";
0195   const float extraTextFont = 52;
0196   const float lumiTextSize = 0.6;
0197   const float lumiTextOffset = 0.2;
0198   const float cmsTextSize = 0.75;
0199   const float relPosX = 0.045;
0200   const float relPosY = 0.035;
0201   const float relExtraDY = 1.2;
0202   const float extraOverCmsTextSize = 0.76;
0203   TString lumi_13TeV = "20.1 fb^{-1}";
0204   TString lumi_8TeV = "19.7 fb^{-1}";
0205   TString lumi_7TeV = "5.1 fb^{-1}";
0206   TString lumi_sqrtS = "";
0207   const bool drawLogo = false;
0208 
0209   bool outOfFrame = (iPosX / 10 == 0) ? true : false;
0210   int alignY_ = 3;
0211   int alignX_ = 2;
0212   if (iPosX / 10 == 0)
0213     alignX_ = 1;
0214   if (iPosX == 0)
0215     alignX_ = 1;
0216   if (iPosX == 0)
0217     alignY_ = 1;
0218   if (iPosX / 10 == 1)
0219     alignX_ = 1;
0220   if (iPosX / 10 == 2)
0221     alignX_ = 2;
0222   if (iPosX / 10 == 3)
0223     alignX_ = 3;
0224   //if( iPosX == 0  ) relPosX = 0.12;
0225   int align_ = 10 * alignX_ + alignY_;
0226 
0227   float H = pad->GetWh();
0228   float W = pad->GetWw();
0229   float l = pad->GetLeftMargin();
0230   float t = pad->GetTopMargin();
0231   float r = pad->GetRightMargin();
0232   float b = pad->GetBottomMargin();
0233   //  float e = 0.025;
0234 
0235   pad->cd();
0236 
0237   TString lumiText;
0238   if (iPeriod == 1) {
0239     lumiText += lumi_7TeV;
0240     lumiText += " (7 TeV)";
0241   } else if (iPeriod == 2) {
0242     lumiText += lumi_8TeV;
0243     lumiText += " (8 TeV)";
0244   } else if (iPeriod == 3) {
0245     lumiText = lumi_8TeV;
0246     lumiText += " (8 TeV)";
0247     lumiText += " + ";
0248     lumiText += lumi_7TeV;
0249     lumiText += " (7 TeV)";
0250   } else if (iPeriod == 4) {
0251     lumiText += lumi_13TeV;
0252     lumiText += " (13 TeV)";
0253   } else if (iPeriod == 7) {
0254     if (outOfFrame)
0255       lumiText += "#scale[0.85]{";
0256     lumiText += lumi_13TeV;
0257     lumiText += " (13 TeV)";
0258     lumiText += " + ";
0259     lumiText += lumi_8TeV;
0260     lumiText += " (8 TeV)";
0261     lumiText += " + ";
0262     lumiText += lumi_7TeV;
0263     lumiText += " (7 TeV)";
0264     if (outOfFrame)
0265       lumiText += "}";
0266   } else if (iPeriod == 12) {
0267     lumiText += "8 TeV";
0268   } else if (iPeriod == 0) {
0269     lumiText += lumi_sqrtS;
0270   }
0271 
0272   std::cout << lumiText << endl;
0273 
0274   TLatex latex;
0275   latex.SetNDC();
0276   latex.SetTextAngle(0);
0277   latex.SetTextColor(kBlack);
0278 
0279   float extraTextSize = extraOverCmsTextSize * cmsTextSize;
0280 
0281   latex.SetTextFont(42);
0282   latex.SetTextAlign(31);
0283   latex.SetTextSize(lumiTextSize * t);
0284   latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumiText);
0285 
0286   if (outOfFrame) {
0287     latex.SetTextFont(cmsTextFont);
0288     latex.SetTextAlign(11);
0289     latex.SetTextSize(cmsTextSize * t);
0290     latex.DrawLatex(l, 1 - t + lumiTextOffset * t, cmsText);
0291   }
0292 
0293   pad->cd();
0294 
0295   float posX_ = 0;
0296   if (iPosX % 10 <= 1) {
0297     posX_ = l + relPosX * (1 - l - r);
0298   } else if (iPosX % 10 == 2) {
0299     posX_ = l + 0.5 * (1 - l - r);
0300   } else if (iPosX % 10 == 3) {
0301     posX_ = 1 - r - relPosX * (1 - l - r);
0302   }
0303   float posY_ = 1 - t - relPosY * (1 - t - b);
0304   if (!outOfFrame) {
0305     if (drawLogo) {
0306       posX_ = l + 0.045 * (1 - l - r) * W / H;
0307       posY_ = 1 - t - 0.045 * (1 - t - b);
0308       float xl_0 = posX_;
0309       float yl_0 = posY_ - 0.15;
0310       float xl_1 = posX_ + 0.15 * H / W;
0311       float yl_1 = posY_;
0312       TASImage* CMS_logo = new TASImage("CMS-BW-label.png");
0313       TPad* pad_logo = new TPad("logo", "logo", xl_0, yl_0, xl_1, yl_1);
0314       pad_logo->Draw();
0315       pad_logo->cd();
0316       CMS_logo->Draw("X");
0317       pad_logo->Modified();
0318       pad->cd();
0319     } else {
0320       latex.SetTextFont(cmsTextFont);
0321       latex.SetTextSize(cmsTextSize * t);
0322       latex.SetTextAlign(align_);
0323       latex.DrawLatex(posX_, posY_, cmsText);
0324       if (writeExtraText) {
0325         latex.SetTextFont(extraTextFont);
0326         latex.SetTextAlign(align_);
0327         latex.SetTextSize(extraTextSize * t);
0328         latex.DrawLatex(posX_, posY_ - relExtraDY * cmsTextSize * t, extraText);
0329       }
0330     }
0331   } else if (writeExtraText) {
0332     if (iPosX == 0) {
0333       posX_ = l + relPosX * (1 - l - r);
0334       posY_ = 1 - t + lumiTextOffset * t;
0335     }
0336     latex.SetTextFont(extraTextFont);
0337     latex.SetTextSize(extraTextSize * t);
0338     latex.SetTextAlign(align_);
0339     latex.DrawLatex(posX_, posY_, extraText);
0340   }
0341   return;
0342 }
0343 
0344 TCanvas* example_plot(int iPeriod,
0345                       int iPos,
0346                       int ieta,
0347                       int phi,
0348                       int idep,
0349                       int inv,
0350                       TFile* f,
0351                       std::string sample1,
0352                       bool writeExtraText,
0353                       bool ifHPD,
0354                       std::string outfile) {
0355   int W = 800;
0356   int H = 600;
0357   int H_ref = 600;
0358   int W_ref = 800;
0359 
0360   // references for T, B, L, R
0361   float T = 0.08 * H_ref;
0362   float B = 0.12 * H_ref;
0363   float L = 0.12 * W_ref;
0364   float R = 0.04 * W_ref;
0365   TString canvName = "FigExample_";
0366   canvName += W;
0367   canvName += "-";
0368   canvName += H;
0369   canvName += "_";
0370   canvName += iPeriod;
0371   if (writeExtraText)
0372     canvName += "-prelim";
0373   if (iPos % 10 == 0)
0374     canvName += "-out";
0375   else if (iPos % 10 == 1)
0376     canvName += "-left";
0377   else if (iPos % 10 == 2)
0378     canvName += "-center";
0379   else if (iPos % 10 == 3)
0380     canvName += "-right";
0381 
0382   TCanvas* canv = new TCanvas(canvName, canvName, 50, 50, W, H);
0383   canv->SetFillColor(0);
0384   canv->SetBorderMode(0);
0385   canv->SetFrameFillStyle(0);
0386   canv->SetFrameBorderMode(0);
0387   canv->SetLeftMargin(L / W);
0388   canv->SetRightMargin(R / W);
0389   canv->SetTopMargin(T / H);
0390   canv->SetBottomMargin(B / H);
0391   canv->SetTickx(0);
0392   canv->SetTicky(0);
0393 
0394   TH1* h = new TH1F("h", "h", 40, 70, 110);
0395   // h->GetXaxis()->SetNdivisions(6,5,0);
0396   // h->GetXaxis()->SetTitle("m_{e^{+}e^{-}} (GeV)");
0397   h->GetYaxis()->SetNdivisions(6, 5, 0);
0398   h->GetYaxis()->SetTitleOffset(1);
0399   h->GetYaxis()->SetTitle("Tracks");
0400   h->SetMaximum(260);
0401   if (iPos == 1)
0402     h->SetMaximum(300);
0403   h->Draw();
0404 
0405   int histLineColor = kOrange + 7;
0406   int histFillColor = kOrange - 2;
0407   float markerSize = 1.0;
0408 
0409   {
0410     TLatex latex;
0411     int n_ = 2;
0412 
0413     float x1_l = 0.92;
0414     float y1_l = 0.60;
0415 
0416     float dx_l = 0.30;
0417     float dy_l = 0.18;
0418     float x0_l = x1_l - dx_l;
0419     float y0_l = y1_l - dy_l;
0420 
0421     TPad* legend = new TPad("legend_0", "legend_0", x0_l, y0_l, x1_l, y1_l);
0422     //    legend->SetFillColor( kGray );
0423     legend->Draw();
0424     legend->cd();
0425 
0426     float ar_l = dy_l / dx_l;
0427 
0428     float x_l[1];
0429     float ex_l[1];
0430     float y_l[1];
0431     float ey_l[1];
0432 
0433     //    float gap_ = 0.09/ar_l;
0434     float gap_ = 1. / (n_ + 1);
0435 
0436     float bwx_ = 0.12;
0437     float bwy_ = gap_ / 1.5;
0438 
0439     x_l[0] = 1.2 * bwx_;
0440     //    y_l[0] = 1-(1-0.10)/ar_l;
0441     y_l[0] = 1 - gap_;
0442     ex_l[0] = 0;
0443     ey_l[0] = 0.04 / ar_l;
0444 
0445     TGraph* gr_l = new TGraphErrors(1, x_l, y_l, ex_l, ey_l);
0446 
0447     gStyle->SetEndErrorSize(0);
0448     gr_l->SetMarkerSize(0.9);
0449     gr_l->Draw("0P");
0450 
0451     latex.SetTextFont(42);
0452     latex.SetTextAngle(0);
0453     latex.SetTextColor(kBlack);
0454     latex.SetTextSize(0.25);
0455     latex.SetTextAlign(12);
0456 
0457     TLine line_;
0458     TBox box_;
0459     float xx_ = x_l[0];
0460     float yy_ = y_l[0];
0461     latex.DrawLatex(xx_ + 1. * bwx_, yy_, "Data");
0462 
0463     yy_ -= gap_;
0464     box_.SetLineStyle(kSolid);
0465     box_.SetLineWidth(1);
0466     // box_.SetLineColor( kBlack );
0467     box_.SetLineColor(histLineColor);
0468     box_.SetFillColor(histFillColor);
0469     box_.DrawBox(xx_ - bwx_ / 2, yy_ - bwy_ / 2, xx_ + bwx_ / 2, yy_ + bwy_ / 2);
0470     box_.SetFillStyle(0);
0471     box_.DrawBox(xx_ - bwx_ / 2, yy_ - bwy_ / 2, xx_ + bwx_ / 2, yy_ + bwy_ / 2);
0472     latex.DrawLatex(xx_ + 1. * bwx_, yy_, "Z #rightarrow e^{+}e^{-} (MC)");
0473 
0474     canv->cd();
0475   }
0476 
0477   {
0478     char name[256], name1[256], name1a[256], name1b[256], name1c[256];
0479 
0480     //  if(idep  == 0) vari=10000;
0481     int hmax = ifHPD ? 25 : 5000;
0482     RooRealVar t("t", "Charge [fC]", 0, hmax);
0483 
0484     int rbo = 0;
0485     std::cout << "problem:"
0486               << "ieta"
0487               << ":" << ieta << std::endl;
0488     std::cout << "problem:"
0489               << "idep"
0490               << ":" << idep << std::endl;
0491     std::cout << "problem:"
0492               << "inv"
0493               << ":" << inv << std::endl;
0494 
0495     //sprintf(name1,"DieMuonEta%d/ChrgE%dF1D%dV%dP0",ieta,ieta, idep, inv); ChrgE19F72D5V1P0
0496     sprintf(name1, "DieMuonEta%d/ChrgE%dF%dD%dV%dP0", ieta, ieta, phi, idep, inv);
0497 
0498     TH1F* h1 = (TH1F*)f->Get(name1);
0499     // if (!h1) continue;
0500     if (h1->GetBinContent(1) > h1->GetBinContent(2))
0501       h1->SetBinContent(1, 0);
0502     std::cout << "did you pass" << std::endl;
0503     std::cout << h1->Integral() << std::endl;
0504     //      if(h->Integral() >= 1) continue;
0505     std::cout << "you didnt" << std::endl;
0506 
0507     // h1->Scale(1.0/h1->Integral());
0508     // h1->Sumw2();
0509     int nrebin = ifHPD ? 100 : 200;
0510     h1->Rebin(nrebin);
0511     h1->Sumw2();
0512     // h ->SetBinContent(1,0);
0513     // h->GetXaxis()->SetRangeUser(0,5.);
0514     // if ((i  == 2  &&  hi ==3) || (i  == 2  &&  hi == 4 ) ) { h->Rebin(40) ;} else if( i == 5) { h->Rebin(50);} else {h->Rebin(80);}
0515     std::cout << name1 << std::endl;
0516     // h->SetBinContent(1,0);
0517     // RooDataHist data("data", "binned version of data",t,Import(*h));
0518     RooDataHist data("data", "binned version of data", t, Import(*h1));
0519 
0520     // Construct landau(t,ml,sl) ;
0521     std::cout << "==============================================================" << std::endl;
0522     std::cout << "mean of landau:" << h1->GetMean() << ":" << h1->GetXaxis()->GetXmax() << std::endl;
0523     std::cout << "==============================================================" << std::endl;
0524     // double ijk=3; double klm= 0.9;
0525     // if (i >= 10 && i <= 20) ijk=1.5;
0526     // if (i > 20) { ijk=7; klm=9;}
0527     double mlstrt = (ifHPD) ? 0.2 : 200.0;
0528     double mlmaxi = (ifHPD) ? 20. : 4000.0;
0529     double slstrt = (ifHPD) ? 0.019 : 150.019;
0530     double slmaxi = (ifHPD) ? 20. : 5000.0;
0531     RooRealVar ml("ml", "mean landau", mlstrt, 0, mlmaxi);
0532     RooRealVar sl("sl", "sigma landau", slstrt, 0, slmaxi);
0533     RooLandau landau("lx", "lx", t, ml, sl);
0534     // RooRealVar mg("mg","mg",1100);//,0,1300);//,0,1.3);
0535     // RooRealVar mg("mg","mg",600, 500,800);
0536     std::cout << "mean before gauss" << h->GetMean() << std::endl;
0537     double sgstrt = (ifHPD) ? 0.003 : 100.003;
0538     double sgmini = (ifHPD) ? 0.001 : 0.0;
0539     double sgmaxi = (ifHPD) ? 20. : 2000.0;
0540     RooRealVar mg("mg", "mg", 0);
0541     RooRealVar sg("sg", "sg", sgstrt, sgmini, sgmaxi);
0542     RooGaussian gauss("gauss", "gauss", t, mg, sg);
0543 
0544     //  RooRealVar sgl("sgl","sgl",1300,1000,1400);
0545     //  RooRealVar sgr("sgr","sgr",2000,1700,3000);
0546     //  RooBifurGauss lxg("lxg", "lxg", t,mg, sgl,sgr);
0547 
0548     // C o n s t r u c t   c o n v o l u t i o n   p d f
0549     // ---------------------------------------
0550 
0551     // Construct landau (x) gauss
0552     char nameo[256];
0553     sprintf(nameo, "charge for ieta%d_iphi%d_depth%d", ieta, phi, idep + 1);
0554     RooNumConvPdf lxg("lxg", "gauss (x) landau convolution", t, gauss, landau);  //landau,gauss) ;
0555     // S a m p l e ,   f i t   a n d   p l o t   c o n v o l u t e d   p d f
0556     // ----------------------------------------------------------------------
0557 
0558     lxg.fitTo(data, Minos(kTRUE));
0559 
0560     RooPlot* frame = t.frame(Title(nameo));
0561     data.plotOn(frame);
0562 
0563     lxg.plotOn(frame);
0564     lxg.paramOn(frame, Layout(0.7, 0.95, 0.9));  //LineColor(kRed),LineStyle(kDashed));
0565 
0566     sprintf(name1a, "i#eta=%d", ieta);
0567     //sprintf(name1c, "depth=%d, NVtx=%d", idep+1,inv+1);
0568     sprintf(name1b, "i#phi=%d", phi);
0569     sprintf(name1c, "depth=%d", idep + 1);
0570     frame->GetYaxis()->SetTitle("Events");
0571     frame->GetYaxis()->SetTitleOffset(1.0);
0572     TLatex* txt = new TLatex(0.7, 0.65, name1a);
0573     TLatex* txt1 = new TLatex(0.7, 0.6, name1b);
0574     TLatex* txt2 = new TLatex(0.7, 0.55, name1c);
0575 
0576     txt->SetNDC();
0577     txt->SetTextSize(0.04);
0578     txt1->SetNDC();
0579     txt1->SetTextSize(0.04);
0580     txt2->SetNDC();
0581     txt2->SetTextSize(0.04);
0582 
0583     // txt->SetTextColor(kRed) ;
0584     frame->addObject(txt);
0585     frame->addObject(txt1);
0586     frame->addObject(txt2);
0587     frame->SetTitle("");
0588 
0589     frame->Draw();
0590 
0591     TF1* f1 = lxg.asTF(RooArgList(t));
0592     Double_t xmax = f1->GetMaximumX();
0593     Double_t peak = ml.getVal();
0594 
0595     Double_t chiSquare = frame->chiSquare();
0596 
0597     std::ofstream log1(outfile.c_str(), std::ios_base::app | std::ios_base::out);
0598     //log1<<"depth"<<i+1<<"\t"<<"vtx bin"<< hi << "\t"<< xmax<<"\t"<<h->GetStdDevError()<<std::endl; //Standard deviation error
0599 
0600     //double gError = mg->getError();
0601     double lError = ml.getError();
0602     //double error = sqrt(gError*gError + lError*lError);
0603     log1 << sample1.c_str() << "\tieta " << ieta << "\tiphi " << phi << "\t\tDEP " << (idep + 1) << "\tNvtx " << inv
0604          << "\t" << peak << "\t" << lError << "\t" << chiSquare << std::endl;
0605     log1.close();
0606   }
0607 
0608   // writing the lumi information and the CMS "logo"
0609   CMS_lumi(canv, iPeriod, iPos);
0610   canv->Update();
0611   canv->RedrawAxis();
0612   canv->GetFrame()->Draw();
0613 
0614   // h->Draw();
0615   // char name1[256];
0616   char name_out[256], name_out1[256];
0617 
0618   char name1[256];
0619   sprintf(name1, "ieta%d_iphi%d_depth%d", ieta, phi, (idep + 1));
0620   //    canv->SaveAs("check.png");
0621 
0622   canv->SaveAs(("out_" + sample1).c_str() + TString(name1) + ".pdf", ".pdf");
0623   canv->SaveAs(("out_" + sample1).c_str() + TString(name1) + ".png", ".png");
0624   canv->SaveAs(("out_" + sample1).c_str() + TString(name1) + ".root", ".root");
0625 
0626   return canv;
0627 }
0628 
0629 void doFit(std::string infile,
0630            std::string text,
0631            int iPeriod = 0,
0632            int etaMin = 2,
0633            int etamax = 3,
0634            int dmin = 1,
0635            int dmax = 1,
0636            int vxmin = 2,
0637            int vxmax = 2,
0638            int phimin = 1,
0639            int phimax = 72,
0640            int phiInc = 1,
0641            bool ifHPD = true,
0642            bool writeExtraText = false) {
0643   TFile* f = new TFile(infile.c_str());
0644   if (f != 0) {
0645     setTDRStyle();
0646     for (unsigned int ieta = etaMin; ieta <= etamax; ieta++) {
0647       for (unsigned int idep = dmin; idep <= dmax; idep++) {
0648         // NVtx
0649         for (unsigned int inv = vxmin; inv <= vxmax; inv++) {
0650           for (unsigned int phi = phimin; phi <= phimax; phi += phiInc) {
0651             example_plot(iPeriod, 0, ieta, phi, idep, inv, f, text, writeExtraText, ifHPD, text);
0652           }
0653         }
0654       }
0655     }
0656     f->Close();
0657   }
0658 }