Example #1
0
void offline(const char* FileName="test", Int_t mode = 0)
{
  if (strcmp(FileName, "") == 0 || mode == 0 || mode > 2)
    {
      cout << "Error in input of offline('fileName',mode):" << endl
	   << "mode 1: c/cbar; mode 2: b/bbar." << endl
	   << "Need File Name: ''pythia_tree_Aug##_#''" << endl;
      abort();
    }
  
  // Set Style parameters for this macro
  //gStyle->SetOptTitle(1); // Show Title (off by default for cleanliness)
  gErrorIgnoreLevel = kError; // Set Verbosity Level (kPrint shows all)

   // Set Output options
  Int_t number;
  checkBatchMode();
  Bool_t makePDF = checkMakePDF();
  Bool_t makeROOT= checkMakeRoot();

  // Use mode input to decide whether C or B templates to work on
  char type[10] = "X";
  if(mode == 1)
    sprintf(type, "C");
  if(mode == 2)
    sprintf(type, "B");

  // Open output file
  char fname[100];
  TFile* file;
  if(makeROOT){
    sprintf(fname,"/Users/zach/Research/pythia/ptHatTemplate/%s_%s_processed.root",FileName,type);
    file = new TFile(fname,"RECREATE");
    if (file->IsOpen()==kFALSE)
      {
	std::cout << "!!! Outfile Not Opened !!!" << std::endl;
	makeROOT = kFALSE;
      }
  }

  // Initialize Histos for Summing and other global vars
  const Int_t numPtHatBins = 8;
  const Int_t numPtBins = anaConst::nPtBins;
  Float_t lowpt[numPtBins],highpt[numPtBins];
  for(Int_t c=0; c< numPtBins; c++){
    lowpt[c] = anaConst::lpt[c];
    highpt[c] = anaConst::hpt[c];
  }
  Float_t hptCut=anaConst::hptCut;
  Float_t hptMax=25; // Set max above range to allow overflow

  TH1F* ptHat     = new TH1F("pThat", "" ,1500, 0, 150);
  TH1F* ptHatCorr = new TH1F("pThatCorrected", "" ,1500, 0, 150);
  TH3F* mh3delPhi;
  TH2F* mh2npePt;
  TH1F* hStats;
  TH2F* mh2ptHatPt;
  TH1D* projpthatall;
  char hist[100];
  TH1F* delPhi[numPtBins];
  TH1F* NpeY[numPtBins];
  TH1F* ptNorm;
  TH1D* projDelPhi[numPtBins];
  TH1D* projNpeY[numPtBins];
  TH1D* projptHat[numPtBins];
  TH1F* temp;
  TH1F* delPhi2535 = new TH1F("delPhi2535","",200,-10,10);
  TH1F* trigCount = new TH1F("trigCount","",10,0,10);
  Float_t norm2535;
  for(Int_t ptbin=0; ptbin<numPtBins; ptbin++) // initialize all before the actual sorting
    { delPhi[ptbin]= new TH1F(Form("delPhi_%i",ptbin), "Delta Phi" ,200, -10, 10);
      delPhi[ptbin]->Sumw2();
      NpeY[ptbin] = new TH1F(Form("NpeY_%i",ptbin),"NpeY",60,-3,3);
    }
  ptNorm = new TH1F("ptNorm", "pT Norm" ,200, 0, 20);
  ptNorm ->Sumw2();
      
  Float_t totalNorm[numPtBins]={0.};
  Double_t wt=0.;
   
  Int_t pthatlow[numPtHatBins] = {0,1,2,4,8,16,32,64};
  Int_t pthathigh[numPtHatBins]= {1,2,4,8,16,32,64,128};

  // Make Canvases
  TCanvas* deltaPhi = new TCanvas("deltaPhi","Pythia Delta Phi",150,0,1150,1000);
  deltaPhi -> Divide(4,3);
  TCanvas* ptHatC = new TCanvas("ptHatC","ptHat Stitching Comparison",150,0,1150,1000);
  ptHatC   -> Divide(1,2);

  TPaveText* lbl[numPtBins];
  char textLabel[100];
  char name[1000];
 
  // Loop over all ptHat bins
  for(Int_t pthBin=0; pthBin < numPtHatBins; pthBin++)
    {
      
      // Open ROOT File (example: output/pythia_tree_Aug31_1_C2_4.root)
      sprintf(name,"/Users/zach/Research/pythia/ptHatTemplate/%s_%s%i_%i.root",FileName,type,pthatlow[pthBin],pthathigh[pthBin]); 
      TFile *f = new TFile(name,"READ");
      if (f->IsOpen()==kFALSE)
	{ std::cout << "!!! File Not Found !!!" << std::endl;
	  exit(1); }
      else
	{ cout << name << " is open!" << endl;}
            
      char histName[100];
      // Get Histos from run output
     
      sprintf(hist, "histo3D%s0", type);
      mh3delPhi    = (TH3F*)f->Get(hist);
      sprintf(hist, "histos2D%s1", type);
      mh2npePt     = (TH2F*)f->Get(hist);
      sprintf(hist, "histos2D%s10", type);
      mh2ptHatPt   = (TH2F*)f->Get(hist);
      sprintf(hist, "hStatistics");
      hStats       = (TH1F*)f->Get(hist);
      sprintf(hist, "delPhi");
      temp         = (TH1F*)f->Get(hist);
      sprintf(hist, "trigCount");
      trigCount    = (TH1F*)f->Get(hist);
          
      // Calculate Weight factors
      wt = 1e9*1e-3*(hStats->GetBinContent(1)/hStats->GetBinContent(2)); // Taken from Zhenyu's method. The 1e# factors are luminosity(?) corrections?
      projpthatall = mh2ptHatPt->ProjectionY("test",0,-1);
      ptHat -> Add(projpthatall);
      ptHatCorr -> Add(projpthatall,wt);

      // pt bin independent
      delPhi2535 -> Add(temp,wt); // still need weight from pthat
      //trigCount -> Scale(wt);     // "      "    "     "     "
      norm2535 += trigCount->GetBinContent(1);
      //delPhi2535 -> Scale(1./norm2535);
   
      // Analyze each ptH bin individually, adding to the overall hists
      for(Int_t ptbin=0; ptbin<numPtBins; ptbin++)
	{
	  // DEBUGcout << "pthbin: " << pthBin << " ptbin: " << ptbin << endl;
	  projDelPhi[ptbin] = mh3delPhi->ProjectionZ(Form("projDelPhi_%i",ptbin),mh3delPhi->GetXaxis()->FindBin(lowpt[ptbin]),mh3delPhi->GetXaxis()->FindBin(highpt[ptbin])-1,mh3delPhi->GetYaxis()->FindBin(hptCut),mh3delPhi->GetYaxis()->FindBin(hptMax));
	  projNpeY[ptbin]   = mh2npePt->ProjectionY(Form("projNpeY_%i",ptbin),mh2npePt->GetXaxis()->FindBin(lowpt[ptbin]),mh2npePt->GetXaxis()->FindBin(highpt[ptbin])-1);
	  projptHat[ptbin]  = mh2ptHatPt->ProjectionY(Form("projPtHat_%i",ptbin),mh2ptHatPt->GetXaxis()->FindBin(lowpt[ptbin]),mh2ptHatPt->GetXaxis()->FindBin(highpt[ptbin])-1);
	
	  delPhi[ptbin] -> Add(projDelPhi[ptbin],wt);
	  NpeY[ptbin] -> Add(projNpeY[ptbin],wt);
	  
	  // Calculate scaling Factor
	  Double_t Norm = NpeY[ptbin]->Integral();
	  ptNorm->SetBinContent(ptNorm->GetBin(ptbin+1),Norm);
	  totalNorm[ptbin] += Norm;
	 
	}
    }

  // For making plots

  ptHatC->cd(1);
  gPad-> SetLogy();
  ptHat->GetXaxis()->SetTitle("pT-Hat (GeV/c)");
  ptHat->SetTitle("Raw pT Hat");
  ptHat->Draw();
  ptHatC->cd(2);
  gPad-> SetLogy();
  ptHatCorr->GetXaxis()->SetTitle("pT-Hat (GeV/c)");
  ptHatCorr->SetTitle("Weighted pT Hat");
  ptHatCorr->Draw();
  
  for(Int_t ptbin=0; ptbin<numPtBins; ptbin++)
    {
      // Init necessary plotting tools
      lbl[ptbin] = new TPaveText(.2,.8,.5,.85,Form("NB NDC%i",ptbin));
      sprintf(textLabel,"%.1f < P_{T,e} < %.1f",lowpt[ptbin],highpt[ptbin]);
      lbl[ptbin]->AddText(textLabel);
      lbl[ptbin]->SetFillColor(kWhite);

      deltaPhi->cd(ptbin+1);
      delPhi[ptbin]->GetXaxis()->SetTitle("#Delta#phi_{eh}");
      // delPhi[ptbin]->Sumw2();
      //cout << totalNorm[ptbin] << endl;
      //delPhi[ptbin]->Scale(wt);
      delPhi[ptbin]->GetYaxis()->SetTitle("1/N_{NPE} #upoint dN/d(#Delta)#phi");
      delPhi[ptbin]->GetXaxis()->SetRangeUser(-3.5,3.5);
      if(ptbin == 0)
	{
	  if(mode == 1)
	    delPhi[ptbin]->SetTitle("Pythia NPE-had #Delta#phi - c/#bar{c}");
	  if(mode == 2)
	    delPhi[ptbin]->SetTitle("Pythia NPE-had #Delta#phi - b/#bar{b}");
	}
      else
	delPhi[ptbin]->SetTitle("");
      if(ptbin < 13){
	delPhi[ptbin]->Draw("E");
	lbl[ptbin]->Draw("same");
      }
    }
  
      
  // Make PDF with output canvases
  if(makePDF)
    {
      //Set front page
      TCanvas* fp = new TCanvas("fp","Front Page",100,0,1000,900);
      fp->cd();
      TBox *bLabel = new TBox(0.01, 0.88, 0.99, 0.99);
      bLabel->SetFillColor(38);
      bLabel->Draw();
      TLatex tl;
      tl.SetNDC();
      tl.SetTextColor(kWhite);
      tl.SetTextSize(0.033);
      char tlName[100];
      char tlName2[100];
      
      TString titlename = FileName;
      int found = titlename.Last('/');
      if(found >= 0){
	titlename.Replace(0, found+1, "");
      } 
      sprintf(tlName, "RUN 12 NPE-h   #Delta#phi Pythia Templates");
      tl.SetTextSize(0.05);
      tl.SetTextColor(kWhite);
      tl.DrawLatex(0.05, 0.92,tlName);
      
      TBox *bFoot = new TBox(0.01, 0.01, 0.99, 0.12);
      bFoot->SetFillColor(38);
      bFoot->Draw();
      tl.SetTextColor(kWhite);
      tl.SetTextSize(0.05);
      tl.DrawLatex(0.05, 0.05, (new TDatime())->AsString());
      tl.SetTextColor(kBlack);
      tl.SetTextSize(0.03);
      tl.DrawLatex(0.1, 0.14, titlename);
      sprintf(tlName,"TEST");
      tl.DrawLatex(0.1, 0.8,tlName);
      
      // Place canvases in order
      TCanvas* temp = new TCanvas();
      sprintf(name, "%s.pdf[", FileName);
      temp->Print(name);
      sprintf(name, "%s.pdf", FileName);
      temp = fp; // print front page
      temp->Print(name);
      temp = ptHatC;
      temp->Print(name);
      temp = deltaPhi;
      temp->Print(name);
      sprintf(name, "%s.pdf]", FileName);
      temp->Print(name);
    }

  if(makeROOT)
    {
      file->Write();
      file->Close();
    }
}
Example #2
0
void plotTemplates()
{
   char name[1000];
   sprintf(name,"/Users/zach/Research/pythia/ptHatTemplate/outputs/currentB.root");
   TFile *fB = new TFile(name,"READ");
   sprintf(name,"/Users/zach/Research/pythia/ptHatTemplate/outputs/currentC.root");
   TFile *fC = new TFile(name,"READ");
   if (fB->IsOpen()==kFALSE || fC->IsOpen()==kFALSE)
     { std::cout << "!!!!!! Either B or C File not found !!!!!!" << std::endl
		 << "Looking for currentC.root and currentB.root." << std::endl;
	 exit(1); }
   
   // Set constants and projection bins
   const Int_t numPtBins = anaConst::nPtBins;
   Float_t lowpt[numPtBins],highpt[numPtBins];
   for(Int_t c=0; c< numPtBins; c++){
     lowpt[c] = anaConst::lpt[c];
     highpt[c] = anaConst::hpt[c];
   }
  Float_t hptCut=anaConst::hptCut;
   
   // Make Canvases
   TCanvas* deltaPhi = new TCanvas("deltaPhi","Pythia Delta Phi",150,0,1150,1000);
   deltaPhi->Divide(4,3);
   TCanvas* singlePlot = new TCanvas("deltaPhiSP","Pythia Delta Phi",150,0,1150,1000);
   
   // Make histos
   TH1D* projB[numPtBins];
   TH1D* projC[numPtBins];
   TH1F* bPtNorms;
   TH1F* cPtNorms;
   Float_t norm0,norm2,normB,normC;

   // Get ptbin independent hists
   bPtNorms   = (TH1F*)fB->Get("ptNorm");
   cPtNorms   = (TH1F*)fC->Get("ptNorm");


  // Get and Draw histos
  TPaveText* lbl[numPtBins];
  char textLabel[100];

  for(Int_t ptbin=0; ptbin<numPtBins; ptbin++)
    {
      // Init necessary plotting tools
      lbl[ptbin] = new TPaveText(.2,.76,.5,.82,Form("NB NDC%i",ptbin));
      sprintf(textLabel,"%.1f < P_{T,e} < %.1f",lowpt[ptbin],highpt[ptbin]);
      lbl[ptbin]->AddText(textLabel);
      lbl[ptbin]->SetFillColor(kWhite);

      projB[ptbin] = (TH1D*)fB->Get(Form("delPhi_%i",ptbin));
      projC[ptbin] = (TH1D*)fC->Get(Form("delPhi_%i",ptbin));

      // Get Normalizations
      normB = bPtNorms->GetBinContent(bPtNorms->GetBin(ptbin+1));
      normC = cPtNorms->GetBinContent(cPtNorms->GetBin(ptbin+1));
      //projB[ptbin] ->Scale(1./normB);
      //projC[ptbin] ->Scale(1./normC);
      
      deltaPhi->cd(ptbin+1);
      projB[ptbin]->SetLineColor(kRed);
      projC[ptbin]->SetLineColor(kBlack);
      //projC[ptbin]->GetYaxis()->SetRangeUser(0.,1.5);
      projB[ptbin]->Draw();
      projC[ptbin]->Draw("same");
      lbl[ptbin]  ->Draw("same");

      TLegend* leg = new TLegend(0.5,0.73,0.85,0.85);
      leg->AddEntry(projB[ptbin],"b#bar{b}->NPE","lpe");
      leg->AddEntry(projC[ptbin],"c#bar{c}->NPE","lpe");
      leg->Draw();

      if(ptbin == 1)
	{
	  singlePlot->cd();
	  projC[ptbin]->Draw();
	  projB[ptbin]->Draw("same");
	  lbl[ptbin]  ->Draw("same");
	  leg->Draw("same");
	}
    }

}
void checkFitCBBW(float mass,float width,string channel, string modelName,double Ymax,bool testGeneratedKinematics=0,bool testKinematicsWithoutSelection =0)
{
  
   
  float gamma = width*mass;
  
  std::ostringstream s;
  s<< mass;
  std::string Mass(s.str());
  std::ostringstream ss; int temp_width = width*10;
  ss<<temp_width;
  std::string swidth(ss.str());
  
  
  string sMCname = "MC sample, m_{VV}="+Mass+", width=0."+swidth;
  string suffix ="#"+channel;
  if(channel.find("mu")==string::npos)
  {
    suffix = "e";
  }
  string name= modelName+" #rightarrow "+suffix+", m_{WW} = "+Mass;
  string soutput_pdf_name = "/usr/users/dschaefer/root/results/testFit/M"+Mass+"/"+modelName+"_M"+Mass+"_"+"width0p"+swidth+"_"+channel+"_matchedJet.pdf";
  if(testGeneratedKinematics)
  {
    soutput_pdf_name = "/usr/users/dschaefer/root/results/testFit/M"+Mass+"/"+modelName+"_M"+Mass+"_"+"width0p"+swidth+"_"+channel+"_matchedJet_gen.pdf";
  }
  if(testKinematicsWithoutSelection)
  {
    soutput_pdf_name = "/usr/users/dschaefer/root/results/testFit/M"+Mass+"/"+modelName+"_M"+Mass+"_"+"width0p"+swidth+"_"+channel+"_withoutSelections.pdf";
  }
  string sfile_narrow;
  if(mass == 800 or mass ==1600)
  {
    sfile_narrow ="/usr/users/dschaefer/root/results/BulkGrav/BulkGrav_M"+Mass+"_width0p0_mWW_"+channel+".root";
    if(testKinematicsWithoutSelection)
    {
       sfile_narrow ="/usr/users/dschaefer/root/results/BulkGrav/BulkGrav_M"+Mass+"_width0p0_mWW_"+channel+"_withoutSelection.root";
    }
  }
  else
  {
  sfile_narrow ="/usr/users/dschaefer/root/results/Wprime/Wprime_M"+Mass+"_width0p0_mWW_"+channel+".root";

  }
  string sfile_width ="/usr/users/dschaefer/root/results/"+modelName+"/"+modelName+"_M"+Mass+"_width0p"+swidth+"_mWW_"+channel+".root";
  if(testGeneratedKinematics)
  {
    sfile_width ="/usr/users/dschaefer/root/results/"+modelName+"/"+modelName+"_M"+Mass+"_width0p"+swidth+"_mWW_"+channel+"_gen.root";
  }
  if(testKinematicsWithoutSelection)
  {
    sfile_width ="/usr/users/dschaefer/root/results/"+modelName+"/"+modelName+"_M"+Mass+"_width0p"+swidth+"_mWW_"+channel+"_withoutSelection.root";
  }
  const char* file_width = sfile_width.c_str();
  const char* file_narrow = sfile_narrow.c_str();
  const char* MCname= sMCname.c_str();
  const char* title = name.c_str();
  const char* output_pdf_name = soutput_pdf_name.c_str();
  
  TFile *f = new TFile(file_width,"READ");
  TFile *f_narrow = new TFile(file_narrow,"READ");
  TH1F* h = (TH1F*) f->Get("hmWW");
  TH1F* h_narrow = (TH1F*) f_narrow->Get("hmWW");
  int tmp = h_narrow->GetSize()-2;
  double massMax_narrow = h_narrow->GetBinLowEdge(h_narrow->GetBin(tmp));
  double massMin_narrow = h_narrow->GetBinLowEdge(0);
  tmp = h->GetSize()-2;
  double massMax_width = h->GetBinLowEdge(h->GetBin(tmp));
  double massMin_width = h->GetBinLowEdge(0);
  RooRealVar m_narrow("m","m",massMin_narrow, massMax_narrow);
  RooRealVar m_width("m_w","m_w",massMin_width,massMax_width);
  
  float mCBMin;
  float mCBMax;
  float sCB;
  float sCBMin;
  float sCBMax;
  float n1;
  float n1Max;
  float n1Min;
  float n2Max;
  float n2Min;
  float n2;
  float alpha1;
  float alpha11Min;
  float alpha1Max;
  float alpha1Min;
  float alpha2Max;
  float alpha2Min;
  float alpha2;
  
 
  
  if(mass == 800)
  {
    
   sCB =50; sCBMin =40; sCBMax=70;
   n1 = 15.; n1Min=5.;n1Max =25.;
   n2 = 15.; n2Min=5.;n2Max =25.;
   alpha1 =1.5;alpha1Min=1.;alpha1Max=1.9;
   alpha2 =1.64;alpha2Min=1.;alpha2Max=1.9;
  }
  if(mass == 1200)
  {
    
   sCB =50; sCBMin =40; sCBMax=70;
   n1 = 15.; n1Min=5.;n1Max =25.;
   n2 = 15.; n2Min=5.;n2Max =25.;
   alpha1 =1.5;alpha1Min=1.;alpha1Max=1.9;
   alpha2 =1.64;alpha2Min=1.;alpha2Max=1.9;
  }
  if(mass == 2000)
  {
    sCB =150; sCBMin =110; sCBMax=175;
   n1 = 10.; n1Min=0.01;n1Max =35.;
   n2 = 20; n2Min=0.01;n2Max =35.;
   alpha1 =1.5;alpha1Min=0.5;alpha1Max=3.;
   alpha2 =1.5;alpha2Min=0.5;alpha2Max=3.0;
    
  }
  if(mass == 3000)
  {
   sCB =150; sCBMin =110; sCBMax=175;
   n1 = 10.; n1Min=0.01;n1Max =35.;
   n2 = 20; n2Min=0.01;n2Max =35.;
   alpha1 =1.5;alpha1Min=0.5;alpha1Max=3.;
   alpha2 =1.5;alpha2Min=0.5;alpha2Max=3.0;
  }
  if(mass==4000)
  {
  sCB =200; sCBMin =140; sCBMax=230;
   n1 = 10.; n1Min=0.01;n1Max =35.;
   n2 = 20; n2Min=0.01;n2Max =35.;
   alpha1 =1.5;alpha1Min=0.5;alpha1Max=3.;
   alpha2 =1.5;alpha2Min=0.5;alpha2Max=3.0;
  }
  
 
  
  
  
  
  RooRealVar m_new = m_width;
  m_new.setBins(1000,"cache");
  RooRealVar mean_CB("mean_CB","mean_CB",mass+90,mass-20,mass+100);
  RooRealVar sigma_CB("sigma_CB","sigma_CB",sCB,sCBMin,sCBMax);
  RooRealVar n1_CB("n1_CB","n1_CB",n1,n1Min,n1Max);
  RooRealVar alpha2_CB("alpha2_CB","alpha2_CB",alpha2,alpha2Min,alpha2Max);
  RooRealVar n2_CB("n2_CB","n2_CB",n2,n2Min,n2Max);
  RooRealVar alpha1_CB("alpha1_CB","alpha1_CB",alpha1,alpha1Min,alpha1Max); 
  
  RooRealVar mean_conv("mean_conv","mean_conv",0);
  RooRealVar width_BW("width_BW","width_BW",gamma);
 
  
  RooDoubleCrystalBall CB("CB","CB",m_narrow,mean_CB,sigma_CB,alpha1_CB,n1_CB,alpha2_CB,n2_CB);
  
  RooDataHist dh_narrow("dh_narrow","dh_narrow",m_narrow,Import(*h_narrow));
  CB.fitTo(dh_narrow);
  mean_CB.getVal();
  sigma_CB.getVal();
  n1_CB.getVal();
  n2_CB.getVal();
  alpha1_CB.getVal();
  alpha2_CB.getVal();
  RooBWRunPdf BW("BW","BW",m_new,mean_CB,width_BW);
  RooDoubleCrystalBall CB_fitted("CB_fitted","CB_fitted",m_new,mean_conv,sigma_CB,alpha1_CB,n1_CB,alpha2_CB,n2_CB);
  
  RooDataHist dh("dh","dh",m_width,Import(*h));
  
  RooPlot* frame = m_width.frame();
  frame->GetXaxis()->SetTitle("m_{VV} [GeV]");
  frame->SetTitle(title);
  frame->GetYaxis()->SetTitleOffset(1.4);
  frame->setPadFactor(1);
  dh.plotOn(frame,"name_dh");
  
  if(testKinematicsWithoutSelection)
  {
    RooBWRunPdf BW_withoutSelection("BW_wS","BW_wS",m_width,mean_CB,width_BW);
    BW_withoutSelection.plotOn(frame,"name_model_pdf");
   
  }
  else
  {
  RooFFTConvPdf model_pdf("conv","conv",m_new,BW,CB_fitted); 
  model_pdf.setBufferFraction(5.0);
  model_pdf.plotOn(frame,"name_model_pdf");
  }

  
 
  
  //BW.plotOn(frame,MarkerColor(kRed),LineColor(kRed));
  //CB.plotOn(frame,MarkerColor(kGreen),LineColor(kGreen));
  
  
  //model_pdf.fitTo(dh);
  
  RooPlot* frame_narrow_fit = m_narrow.frame();
  frame_narrow_fit->GetXaxis()->SetTitle("m_{VV} [GeV]");
  frame_narrow_fit->SetTitle("Double Crystall Ball");
  dh_narrow.plotOn(frame_narrow_fit);
  CB.plotOn(frame_narrow_fit);
  
  
  
  TCanvas* canvas1 = new TCanvas("canvas1","canvas1",400,600);
  gPad->SetLeftMargin(0.15);
  TPad* pad1 = new TPad("pad1","pad1",0.,0.2,1.,1.0);
  TPad* pad2 = new TPad("pad2","pad2",0.,0.,1.0,0.2);
  pad1->SetLeftMargin(0.15);
  pad2->SetLeftMargin(0.15);
  pad1->Draw();
  pad2->Draw();
  pad1->cd();
  frame->GetYaxis()->SetTitleOffset(2.0);
  //double Ymax = 400;
  frame->SetMaximum(Ymax);
  frame->Draw();
  TString dh_name = frame->nameOf(0);
  TString model_pdf_name = frame->nameOf(1);
  TLegend* leg = new TLegend(0.48,0.89,0.89,0.8);//0.48,0.89,0.9,0.8)
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->AddEntry(frame->findObject(dh_name),MCname,"lep");
  if(testKinematicsWithoutSelection)
  {
  leg->AddEntry(frame->findObject(model_pdf_name),"Breit-Wigner ","L");
  }
  else
  {
    leg->AddEntry(frame->findObject(model_pdf_name),"(CB*BW)(m) ","L");
  }
  leg->Draw();
  double chi2 = frame->chiSquare();
  string schi2 = "X^{2} ="+std::to_string(chi2); 
  const char* textChi2 = schi2.c_str();
  TLatex text;
  text.SetTextFont(43);
  text.SetTextSize(16);
  text.DrawLatex(massMin_width+(massMax_width-massMin_width)/10.,Ymax-Ymax/10.,textChi2);
  
  RooPlot* frame2 = m_width.frame();
  frame2->addObject(frame->pullHist());
  frame2->SetMinimum(-25);
  frame2->SetMaximum(15);
  frame2->SetTitle("pulls");
  pad2->cd();
  frame2->Draw();
  canvas1->SaveAs(output_pdf_name);
  
  TCanvas* canvas2 = new TCanvas("canvas2","canvas2",400,400);
  canvas2->cd();
  frame_narrow_fit->Draw();
 
   
}