Пример #1
0
void rf403_weightedevts()
{
  // C r e a t e   o b s e r v a b l e   a n d   u n w e i g h t e d   d a t a s e t 
  // -------------------------------------------------------------------------------

  // Declare observable
  RooRealVar x("x","x",-10,10) ;
  x.setBins(40) ;

  // Construction a uniform pdf
  RooPolynomial p0("px","px",x) ;

  // Sample 1000 events from pdf
  RooDataSet* data = p0.generate(x,1000) ;

 

  // C a l c u l a t e   w e i g h t   a n d   m a k e   d a t a s e t   w e i g h t e d 
  // -----------------------------------------------------------------------------------

  // Construct formula to calculate (fake) weight for events
  RooFormulaVar wFunc("w","event weight","(x*x+10)",x) ;

  // Add column with variable w to previously generated dataset
  RooRealVar* w = (RooRealVar*) data->addColumn(wFunc) ;

  // Dataset d is now a dataset with two observable (x,w) with 1000 entries
  data->Print() ;

  // Instruct dataset wdata in interpret w as event weight rather than as observable
  RooDataSet wdata(data->GetName(),data->GetTitle(),data,*data->get(),0,w->GetName()) ;

  // Dataset d is now a dataset with one observable (x) with 1000 entries and a sum of weights of ~430K
  wdata.Print() ;



  // U n b i n n e d   M L   f i t   t o   w e i g h t e d   d a t a 
  // ---------------------------------------------------------------

  // Construction quadratic polynomial pdf for fitting
  RooRealVar a0("a0","a0",1) ;
  RooRealVar a1("a1","a1",0,-1,1) ;
  RooRealVar a2("a2","a2",1,0,10) ;
  RooPolynomial p2("p2","p2",x,RooArgList(a0,a1,a2),0) ;

  // Fit quadratic polynomial to weighted data

  // NOTE: A plain Maximum likelihood fit to weighted data does in general 
  //       NOT result in correct error estimates, unless individual
  //       event weights represent Poisson statistics themselves.
  //       
  // Fit with 'wrong' errors
  RooFitResult* r_ml_wgt = p2.fitTo(wdata,Save()) ;
  
  // A first order correction to estimated parameter errors in an 
  // (unbinned) ML fit can be obtained by calculating the
  // covariance matrix as
  //
  //    V' = V C-1 V
  //
  // where V is the covariance matrix calculated from a fit
  // to -logL = - sum [ w_i log f(x_i) ] and C is the covariance
  // matrix calculated from -logL' = -sum [ w_i^2 log f(x_i) ] 
  // (i.e. the weights are applied squared)
  //
  // A fit in this mode can be performed as follows:

  RooFitResult* r_ml_wgt_corr = p2.fitTo(wdata,Save(),SumW2Error(kTRUE)) ;



  // P l o t   w e i g h e d   d a t a   a n d   f i t   r e s u l t 
  // ---------------------------------------------------------------

  // Construct plot frame
  RooPlot* frame = x.frame(Title("Unbinned ML fit, binned chi^2 fit to weighted data")) ;

  // Plot data using sum-of-weights-squared error rather than Poisson errors
  wdata.plotOn(frame,DataError(RooAbsData::SumW2)) ;

  // Overlay result of 2nd order polynomial fit to weighted data
  p2.plotOn(frame) ;



  // M L  F i t   o f   p d f   t o   e q u i v a l e n t  u n w e i g h t e d   d a t a s e t
  // -----------------------------------------------------------------------------------------
  
  // Construct a pdf with the same shape as p0 after weighting
  RooGenericPdf genPdf("genPdf","x*x+10",x) ;

  // Sample a dataset with the same number of events as data
  RooDataSet* data2 = genPdf.generate(x,1000) ;

  // Sample a dataset with the same number of weights as data
  RooDataSet* data3 = genPdf.generate(x,43000) ;

  // Fit the 2nd order polynomial to both unweighted datasets and save the results for comparison
  RooFitResult* r_ml_unw10 = p2.fitTo(*data2,Save()) ;
  RooFitResult* r_ml_unw43 = p2.fitTo(*data3,Save()) ;


  // C h i 2   f i t   o f   p d f   t o   b i n n e d   w e i g h t e d   d a t a s e t
  // ------------------------------------------------------------------------------------

  // Construct binned clone of unbinned weighted dataset
  RooDataHist* binnedData = wdata.binnedClone() ;
  binnedData->Print("v") ;

  // Perform chi2 fit to binned weighted dataset using sum-of-weights errors
  // 
  // NB: Within the usual approximations of a chi2 fit, a chi2 fit to weighted
  // data using sum-of-weights-squared errors does give correct error
  // estimates
  RooChi2Var chi2("chi2","chi2",p2,*binnedData,DataError(RooAbsData::SumW2)) ;
  RooMinuit m(chi2) ;
  m.migrad() ;
  m.hesse() ;

  // Plot chi^2 fit result on frame as well
  RooFitResult* r_chi2_wgt = m.save() ;
  p2.plotOn(frame,LineStyle(kDashed),LineColor(kRed)) ;



  // C o m p a r e   f i t   r e s u l t s   o f   c h i 2 , M L   f i t s   t o   ( u n ) w e i g h t e d   d a t a 
  // ---------------------------------------------------------------------------------------------------------------

  // Note that ML fit on 1Kevt of weighted data is closer to result of ML fit on 43Kevt of unweighted data 
  // than to 1Kevt of unweighted data, whereas the reference chi^2 fit with SumW2 error gives a result closer to
  // that of an unbinned ML fit to 1Kevt of unweighted data. 

  cout << "==> ML Fit results on 1K unweighted events" << endl ;
  r_ml_unw10->Print() ;
  cout << "==> ML Fit results on 43K unweighted events" << endl ;
  r_ml_unw43->Print() ;
  cout << "==> ML Fit results on 1K weighted events with a summed weight of 43K" << endl ;
  r_ml_wgt->Print() ;
  cout << "==> Corrected ML Fit results on 1K weighted events with a summed weight of 43K" << endl ;
  r_ml_wgt_corr->Print() ;
  cout << "==> Chi2 Fit results on 1K weighted events with a summed weight of 43K" << endl ;
  r_chi2_wgt->Print() ;


  new TCanvas("rf403_weightedevts","rf403_weightedevts",600,600) ;
  gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.8) ; frame->Draw() ;


}
Пример #2
0
void MakePlots(RooWorkspace* ws){

  // Here we make plots of the discriminating variable (invMass) after the fit
  // and of the control variable (isolation) after unfolding with sPlot.
  std::cout << "make plots" << std::endl;

  // make our canvas
  TCanvas* cdata = new TCanvas("sPlot","sPlot demo", 400, 600);
  cdata->Divide(1,3);

  // get what we need out of the workspace
  RooAbsPdf* model = ws->pdf("model");
  RooAbsPdf* zModel = ws->pdf("zModel");
  RooAbsPdf* qcdModel = ws->pdf("qcdModel");

  RooRealVar* isolation = ws->var("isolation");
  RooRealVar* invMass = ws->var("invMass");

  // note, we get the dataset with sWeights
  RooDataSet* data = (RooDataSet*) ws->data("dataWithSWeights");

  // this shouldn't be necessary, need to fix something with workspace
  // do this to set parameters back to their fitted values.
  model->fitTo(*data, Extended() );

  //plot invMass for data with full model and individual componenets overlayed
  //  TCanvas* cdata = new TCanvas();
  cdata->cd(1);
  RooPlot* frame = invMass->frame() ; 
  data->plotOn(frame ) ; 
  model->plotOn(frame) ;   
  model->plotOn(frame,Components(*zModel),LineStyle(kDashed), LineColor(kRed)) ;   
  model->plotOn(frame,Components(*qcdModel),LineStyle(kDashed),LineColor(kGreen)) ;   
    
  frame->SetTitle("Fit of model to discriminating variable");
  frame->Draw() ;
 

  // Now use the sWeights to show isolation distribution for Z and QCD.  
  // The SPlot class can make this easier, but here we demonstrait in more
  // detail how the sWeights are used.  The SPlot class should make this 
  // very easy and needs some more development.

  // Plot isolation for Z component.  
  // Do this by plotting all events weighted by the sWeight for the Z component.
  // The SPlot class adds a new variable that has the name of the corresponding
  // yield + "_sw".
  cdata->cd(2);

  // create weightfed data set 
  RooDataSet * dataw_z = new RooDataSet(data->GetName(),data->GetTitle(),data,*data->get(),0,"zYield_sw") ;

  RooPlot* frame2 = isolation->frame() ; 
  dataw_z->plotOn(frame2, DataError(RooAbsData::SumW2) ) ; 
    
  frame2->SetTitle("isolation distribution for Z");
  frame2->Draw() ;

  // Plot isolation for QCD component.  
  // Eg. plot all events weighted by the sWeight for the QCD component.
  // The SPlot class adds a new variable that has the name of the corresponding
  // yield + "_sw".
  cdata->cd(3);
  RooDataSet * dataw_qcd = new RooDataSet(data->GetName(),data->GetTitle(),data,*data->get(),0,"qcdYield_sw") ;
  RooPlot* frame3 = isolation->frame() ; 
  dataw_qcd->plotOn(frame3,DataError(RooAbsData::SumW2) ) ; 
    
  frame3->SetTitle("isolation distribution for QCD");
  frame3->Draw() ;

  //  cdata->SaveAs("SPlot.gif");

}
Пример #3
0
void ws_v03()
{
    gROOT->ProcessLine(".x ./mystyle.C");

    TFile *f1 = new TFile("K1_1270/ws_K1_1270.root");
    TFile *f2 = new TFile("K1_1400/ws_K1_1400.root");
    TFile *f3 = new TFile("K2_1430/ws_K2_1430.root");

    RooWorkspace* ws_K1_1270 = (RooWorkspace*) f1->Get("ws_K1_1270");
    RooWorkspace* ws_K1_1400 = (RooWorkspace*) f2->Get("ws_K1_1400");
    RooWorkspace* ws_K2_1430 = (RooWorkspace*) f3->Get("ws_K2_1430");
    ws_K1_1270->Print();
    ws_K1_1400->Print();
    ws_K2_1430->Print();

    // Importing variables from workspaces

    RooRealVar* m_Kpipi = ws_K1_1270 -> var("m_Kpipi");
    RooAbsPdf* totalPdf_K1_1270 = ws_K1_1270 -> pdf("totalPdf_K1_1270");
    RooAbsData* data_K1_1270 = ws_K1_1270 -> data("totalPdf_K1_1270Data");
    RooHistPdf* pdf_K1_1270_to_Krho = ws_K1_1270 -> pdf("histPdf_K1toKrho");

    /*RooRealVar* m_Kpipi = ws_K1_1400 -> var("m_Kpipi");*/
    /*RooAbsPdf* totalPdf_K1_1400 = ws_K1_1400 -> pdf("totalPdf_K1_1400");*/
    /*RooAbsData* data_K1_1400 = ws_K1_1400 -> data("totalPdf_K1_1400Data");*/
    /*RooHistPdf* pdf_K1_1400_to_Krho = ws_K1_1400 -> pdf("histPdf_K1_1400toKrho");*/

    /*RooRealVar* m_Kpipi = ws_K2_1430 -> var("m_Kpipi");*/
    /*RooAbsPdf* totalPdf_K2_1430 = ws_K2_1430 -> pdf("totalPdf_K2_1430");*/
    /*RooAbsData* data_K2_1430 = ws_K2_1430 -> data("totalPdf_K2_1430Data");*/
    /*RooHistPdf* pdf_K2_1430_to_Krho = ws_K2_1430 -> pdf("histPdf_K2_1430toKrho");*/

    // Plotting pdf

    /*TCanvas* c1 = new TCanvas("c1","canvas",20,20,1200,600);*/
    /*c1->Divide(3,1);*/
    /*c1->cd(1);*/
    /*RooPlot* frame_K1_1270 = m_Kpipi -> frame(Bins(200),Title("K1(1270) -> K#pi#pi"));*/
    /*data_K1_1270->plotOn(frame_K1_1270,DrawOption("C"));*/
    /*frame_K1_1270->Draw();*/
    /*c1->cd(2);*/
    /*RooPlot* frame_K1_1400 = m_Kpipi -> frame(Bins(200),Title("K1(1400) -> K#pi#pi"));*/
    /*data_K1_1400->plotOn(frame_K1_1400,DrawOption("C"));*/
    /*frame_K1_1400->Draw();*/
    /*c1->cd(3);*/
    /*RooPlot* frame_K2_1430= m_Kpipi -> frame(Bins(200),Title("K2*(1430) -> K#pi#pi"));*/
    /*data_K2_1430->plotOn(frame_K2_1430,DrawOption("C"));*/
    /*frame_K2_1430->Draw();*/

 ////////////////////////////////////////////////////////////////////////

    TFile *Fworkspace = new TFile("workspace.root");

    RooWorkspace* wsp = (RooWorkspace*) Fworkspace->Get("wsp");
    wsp->Print();

    RooRealVar* B_postcalib_M = wsp -> var("B_postcalib_M");
    RooRealVar* nsig_sw = wsp-> var("nsig_sw");
    RooRealVar* nbkg_sw = wsp-> var("nbkg_sw");
    RooRealVar* B_M13_Subst3_gamma2pi0 = wsp-> var("B_M13_Subst3_gamma2pi0");
    RooRealVar* B_M023 = wsp -> var("B_M023");
    RooRealVar* K_1_1270_plus_M = wsp -> var("K_1_1270_plus_M");
    RooRealVar* K_1_1270_plus_SMALLESTDELTACHI2 = wsp -> var("K_1_1270_plus_SMALLESTDELTACHI2");
    RooRealVar* gamma_CL = wsp -> var("gamma_CL");
    RooRealVar* piminus_PIDK = wsp -> var("piminus_PIDK");
    RooRealVar* piplus_PIDK = wsp -> var("piplus_PIDK");
    RooRealVar* Kplus_PIDp = wsp -> var("Kplus_PIDp");
    RooRealVar* Kplus_PIDK = wsp -> var("Kplus_PIDK");
    RooRealVar* B_M02 = wsp -> var("B_M02");
    RooRealVar* L_nsig = wsp -> var("L_nsig");
    RooRealVar* L_nbkg = wsp -> var("L_nbkg");

    RooArgSet arg(*B_postcalib_M,*gamma_CL,*B_M13_Subst3_gamma2pi0,*B_M023,*piminus_PIDK,*piplus_PIDK,*Kplus_PIDK,*Kplus_PIDp);
    arg.add(*K_1_1270_plus_M);
    arg.add(*K_1_1270_plus_SMALLESTDELTACHI2);
    arg.add(*B_M02);
    arg.add(*nsig_sw);
    arg.add(*L_nsig);
    arg.add(*nbkg_sw);
    arg.add(*L_nbkg);

    arg.add(*m_Kpipi);


    RooDataSet* DataSWeights = (RooDataSet*) wsp -> data("DataSWeights");
    RooFormulaVar newMass("m_Kpipi", "m_Kpipi", "K_1_1270_plus_M", RooArgList(*(wsp->var("K_1_1270_plus_M"))));
    DataSWeights->addColumn(newMass);
    RooDataSet* splot = new RooDataSet(DataSWeights->GetName(),DataSWeights->GetTitle(),DataSWeights,RooArgSet(arg),"","nsig_sw");


    // Defining here pdfs for other resonances to be fitted

// TRY TO ADD 2 SIMPLE BWs FOR K1 1270 AND K1 1400 AS WELL
// also, binned clone and try to fit a toy dataset

        // K1(1270)

    /*Double_t R = 0.0015; //  was 3.1 GeV-1*/
    /*RooRealVar mean_K1_1270("mean_K1_1270","",1272.,1262.,1282.);*/
    /*RooRealVar width_K1_1270("width_K1_1270","",90.,70.,110.);*/
    /*RooBreitWigner totalPdf_K1_1270("totalPdf_K1_1270","",*m_Kpipi,mean_K1_1270,width_K1_1270);*/
    /*[>RooRelBreitWigner totalPdf_K1_1270("totalPdf_K1_1270","totalPdf_K1_1270",*m_Kpipi,mean_K1_1270,width_K1_1270,RooConst(0),RooConst(R),RooConst(770.),RooConst(493.7));<]*/

        // K1(1400)

    RooRealVar mean_K1_1400("mean_K1_1400","",1403./*,1396.,1410.*/);
    RooRealVar width_K1_1400("width_K1_1400","",174./*,151.,197.*/);
    RooBreitWigner totalPdf_K1_1400("totalPdf_K1_1400","",*m_Kpipi,mean_K1_1400,width_K1_1400);
    /*RooRelBreitWigner totalPdf_K1_1400("totalPdf_K1_1400","totalPdf_K1_1400",*m_Kpipi,mean_K1_1400,width_K1_1400,RooConst(0),RooConst(R),RooConst(895.),RooConst(139.6));*/ //K*(892) pi is 93%

        // K2*(1430)

    RooRealVar mean_K2_1430("mean_K2_1430","",1432./*,1424.,1435.*/);
    RooRealVar width_K2_1430("width_K2_1430","",109./*,96.,114.*/);
    RooBreitWigner totalPdf_K2_1430("totalPdf_K2_1430","",*m_Kpipi,mean_K2_1430,width_K2_1430);

        // K3*(1780)

    RooRealVar mean_K3_1780("mean_K3_1780","mean_K3_1780",1776./*,1765.,1785.*/);
    RooRealVar width_K3_1780("width_K3_1780","width_K3_1780",159.7/*,150.,170.*/);
    RooBreitWigner K3_1780("K3_1780","K3_1780",*m_Kpipi,mean_K3_1780,width_K3_1780);

        // K2(1770)

    RooRealVar mean_K2_1770("mean_K2_1770","mean_K2_1770",1773./*,1763.,1783.*/);
    RooRealVar width_K2_1770("width_K2_1770","width_K2_1770",186./*,176.,196.*/);
    RooBreitWigner K2_1770("K2_1770","K2_1770",*m_Kpipi,mean_K2_1770,width_K2_1770);

        // K2(1580)

    RooRealVar mean_K2_1580("mean_K2_1580","mean_K2_1580",1580.);
    RooRealVar width_K2_1580("width_K2_1580","width_K2_1580",110.);
    RooBreitWigner K2_1580("K2_1580","K2_1580",*m_Kpipi,mean_K2_1580,width_K2_1580);

        // K2*(1980)

    RooRealVar mean_K2_1980("mean_K2_1980","mean_K2_1980",1973./*,1957.,1999.*/);
    RooRealVar width_K2_1980("width_K2_1980","width_K2_1980",373./*,303.,443.*/);
    RooBreitWigner K2_1980("K2_1980","K2_1980",*m_Kpipi,mean_K2_1980,width_K2_1980);

        // K*(1680)

    RooRealVar mean_K_1680("mean_K_1680","mean_K*_1680",1717./*,1690.,1744.*/);
    RooRealVar width_K_1680("width_K_1680","width_K*_1680",322./*,212.,432.*/);
    RooBreitWigner K_1680("K_1680","K*_1680",*m_Kpipi,mean_K_1680,width_K_1680);
    /*width_K_1680.setVal(322.);*/
    /*width_K_1680.setConstant(kTRUE);*/

        // K*(1410) mass 1414 +- 15 MeV , width 232 +- 21 MeV

    RooRealVar mean_K_1410("mean_K_1410","",1414./*,1399.,1429.*/);
    RooRealVar width_K_1410("width_K_1410","",232./*,253.,211.*/);
    RooBreitWigner K_1410("K_1410","",*m_Kpipi,mean_K_1410,width_K_1410);



    // here add pdfs and FIT sum of pdf to splot

    RooRealVar K1_1270_y("K1_1270_y","K1_1270_y",1000.,0.,10000.);

            // set constraints on yields (from PDG)
            RooFormulaVar r_K2_1430_y_low("r_K2_1430_y_low","r_K2_1430_y_low","(K1_1270_y/5.39)",K1_1270_y); // was 5.39 from PDG including 1 sigma error
            RooFormulaVar r_K2_1430_y_up("r_K2_1430_y_up","r_K2_1430_y_up","(K1_1270_y/1.65)",K1_1270_y);   // was 1.65

    /*RooFormulaVar K2_1430_y("K2_1430_y","K2_1430_y","K1_1270_y/3.",K1_1270_y); // K2_1430 yield is fixed to 1/3 of the K1_1270 yield (as found from Belle )*/
    RooRealVar K2_1430_y("K2_1430_y","K2_1430_y",100.,0.,1000.);
    /*K2_1430_y.setRange(r_K2_1430_y_low,r_K2_1430_y_up);*/

            RooRealVar r_K1_1400_y_low("r_K1_1400_y_low","r_K1_1400_y_low",0.); // only an upper limit is given for K1(1400)
            /*RooFormulaVar r_K1_1400_y_up("r_K1_1400_y_up","r_K1_1400_y_up","(K1_1270_y/2.86)*(2./9.)",K1_1270_y); // was 2.86 from PDG -> 2/9 because only*/
            RooFormulaVar r_K1_1400_y_up("r_K1_1400_y_up","r_K1_1400_y_up","(K1_1270_y/2.86)",K1_1270_y); // was 2.86 from PDG -> 2/9 because only

    RooRealVar K1_1400_y("K1_1400_y","K1_1400_y",100.,0.,1000.);
    /*K1_1400_y.setRange(r_K1_1400_y_low,r_K1_1400_y_up);*/

    RooRealVar K3_1780_y("K3_1780_y","K3_1780_y",100,0,10000.);
    RooRealVar K2_1770_y("K2_1770_y","K2_1770_y",100,0,10000.);
    RooRealVar K2_1580_y("K2_1580_y","K2_1580_y",100,0,10000.);
    RooRealVar K2_1980_y("K2_1980_y","K2_1980_y",100,0,10000.);
    RooRealVar K_1680_y("K_1680_y","K*_1680_y",100,0,10000.);
    RooRealVar K_1410_y("K_1410_y","K*_1410_y",100,0,10000.);

    RooArgList shapes;
    RooArgList yields;
    shapes.add(*totalPdf_K1_1270); // add pointer if getting them from ws
    shapes.add(totalPdf_K1_1400);
    shapes.add(totalPdf_K2_1430);
    shapes.add(K3_1780);
    /*shapes.add(K2_1770);*/
    shapes.add(K2_1580);
    shapes.add(K2_1980);
    shapes.add(K_1680);
    shapes.add(K_1410);
    yields.add(K1_1270_y);
    yields.add(K1_1400_y);
    yields.add(K2_1430_y);
    yields.add(K3_1780_y);
    /*yields.add(K2_1770_y);*/
    yields.add(K2_1580_y);
    yields.add(K2_1980_y);
    yields.add(K_1680_y);
    yields.add(K_1410_y);

    // Putting all pdfs together

    RooAddPdf PDF("PDF","total Pdf for the resonances considered", shapes,yields);

    /*PDF->fitTo(*splot,Extended(),SumW2Error(kFALSE),Range(1000,2000));*/
    PDF->fitTo(*splot,Extended(),SumW2Error(kTRUE),Range(1000,2000));

    // Defining frames for plotting

    RooPlot* frame_splot = m_Kpipi->frame(Title("sPlot of m_{K#pi#pi} [MeV/c^{2}]"),Range(1000,2000),Bins(50));
    splot->plotOn(frame_splot,Name("fitted_splot")/*,DataError(RooAbsData::SumW2)*/);

    PDF.paramOn(frame_splot,Layout(.65,.9,.99)); // Layout(xmin,ymin,ymax)
    PDF.plotOn(frame_splot,Components(*totalPdf_K1_1270),LineColor(kRed));
    PDF.plotOn(frame_splot,Components(totalPdf_K1_1400),LineColor(1));
    PDF.plotOn(frame_splot,Components(totalPdf_K2_1430),LineColor(51),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K3_1780),LineColor(kOrange),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K2_1770),LineColor(5),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K2_1580),LineColor(12),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K2_1980),LineColor(16),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K_1680),LineColor(32),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K_1410),LineColor(3),LineStyle(kDashed));
    PDF.plotOn(frame_splot);

    // Calculating residuals

    RooHist* hresid = frame_splot -> residHist();
    RooHist* hpull = frame_splot -> pullHist();

    /*RooPlot* frame2 = m_Kpipi.frame(1000,2000,25);*/
    /*frame2->addPlotable(hresid,"P");*/

    RooPlot* frame3 = m_Kpipi->frame(Title(" "),Range(1000,2000),Bins(25));
    frame3->addPlotable(hpull,"P");

    // Plotting

    TCanvas* canvas_sPlot = new TCanvas("canvas_sPlot","sPlot with weights",40,20,1200,800);
    canvas_sPlot->Divide(1,2);
    canvas_sPlot_1->SetPad(0.01,0.20,0.99,0.99);
    canvas_sPlot_2->SetPad(0.01,0.01,0.99,0.20);

    canvas_sPlot->cd(1);
    frame_splot->Draw();

    /*canvas_sPlot->cd(2);*/
    /*frame2->Draw();*/

    canvas_sPlot->cd(2);
    frame3->SetMinimum(-7);
    frame3->SetMaximum(+7);
    frame3->Draw();

    TLine *line = new TLine(1000.,-5.,2000.,-5);
    line->SetLineStyle(1);
    line->SetLineColor(2);
    line->SetLineWidth(1);
    line->Draw();
    line2 = new TLine(1000.,+5.,2000.,+5);
    line2->SetLineStyle(1);
    line2->SetLineColor(2);
    line2->SetLineWidth(1);
    line2->Draw();

    // CleanUp worspaces

    delete ws_K1_1270;
    delete ws_K1_1400;
    delete ws_K2_1430;
    delete wsp;

}
Пример #4
0
void ws_v05()
{
    gROOT->ProcessLine(".x ./mystyle.C");

    /*RooMsgService::instance().setSilentMode(true);*/
    /*RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING) ; //WAS WARNING*/

    // Variables definition

    Double_t xmin = 1000.;
    Double_t xmax = 2000.;
    Int_t nbins = 50;

    cout << "\n\n >>>> Importing shapes  \n\n" << endl;

    TFile *f1 = new TFile("K1_1270/ws_K1_1270.root");
    /*TFile *f2 = new TFile("K1_1400/ws_K1_1400.root");*/
    /*TFile *f3 = new TFile("K2_1430/ws_K2_1430.root");*/

    RooWorkspace* ws_K1_1270 = (RooWorkspace*) f1->Get("ws_K1_1270");
    /*RooWorkspace* ws_K1_1400 = (RooWorkspace*) f2->Get("ws_K1_1400");*/
    /*RooWorkspace* ws_K2_1430 = (RooWorkspace*) f3->Get("ws_K2_1430");*/
    ws_K1_1270->Print();
    /*ws_K1_1400->Print();*/
    /*ws_K2_1430->Print();*/

    // Importing variables from workspaces

    RooRealVar* m_Kpipi = ws_K1_1270 -> var("m_Kpipi");
    RooAbsPdf* totalPdf_K1_1270 = ws_K1_1270 -> pdf("histPdf_K1toKrho");
    RooAbsPdf* totalPdf_K1_1270_Kst0_1430 = ws_K1_1270 -> pdf("histPdf_Kstar1430pi");
    RooAbsPdf* totalPdf_K1_1270_Kst0_892 = ws_K1_1270 -> pdf("histPdf_Kstar892pi");
    /*RooAbsPdf* totalPdf_K1_1270 = ws_K1_1270 -> pdf("totalPdf_K1_1270");*/
    /*RooAbsData* data_K1_1270 = ws_K1_1270 -> data("totalPdf_K1_1270Data");*/
    /*RooHistPdf* pdf_K1_1270_to_Krho = ws_K1_1270 -> pdf("histPdf_K1toKrho");*/

///////
    /*TFile *MC = new TFile("radiativeVPG_MC11s20_B2K11270Gamma_magdown.root");*/
    /*TTree* t_tree = (TTree*)MC->Get("k1GammaMCStrip/DecayTree");*/
    /*TH1F* hist = new TH1F("hist","hist",nbins,xmin,xmax);*/
    /*Float_t mass = 0.;*/
    /*t_tree->SetBranchAddress("B_BMassFit_K_1_1270_plus_M",&mass);*/
    /*Int_t n2 = 0;*/
    /*for (int i=0;i<t_tree->GetEntries();i++)*/
    /*{*/
    /*t_tree->GetEntry(i);*/

    /*hist->Fill(mass);*/
    /*n2++;*/
    /*}*/
    /*RooDataHist datahist("datahist","datahist",*m_Kpipi,hist);*/
    /*RooHistPdf totalPdf_K1_1270("totalPdf_K1_1270","",*m_Kpipi,datahist,2);*/

//////
    /*RooRealVar* m_Kpipi = ws_K1_1400 -> var("m_Kpipi");*/
    /*RooAbsPdf* totalPdf_K1_1400 = ws_K1_1400 -> pdf("totalPdf_K1_1400");*/
    /*RooAbsData* data_K1_1400 = ws_K1_1400 -> data("totalPdf_K1_1400Data");*/
    /*RooHistPdf* pdf_K1_1400_to_Krho = ws_K1_1400 -> pdf("histPdf_K1_1400toKrho");*/

    /*RooRealVar* m_Kpipi = ws_K2_1430 -> var("m_Kpipi");*/
    /*RooAbsPdf* totalPdf_K2_1430 = ws_K2_1430 -> pdf("totalPdf_K2_1430");*/
    /*RooAbsData* data_K2_1430 = ws_K2_1430 -> data("totalPdf_K2_1430Data");*/
    /*RooHistPdf* pdf_K2_1430_to_Krho = ws_K2_1430 -> pdf("histPdf_K2_1430toKrho");*/

    // Plotting pdf

    /*TCanvas* c1 = new TCanvas("c1","canvas",20,20,1200,600);*/
    /*c1->Divide(3,1);*/
    /*c1->cd(1);*/
    /*RooPlot* frame_K1_1270 = m_Kpipi -> frame(Bins(200),Title("K1(1270) -> K#pi#pi"));*/
    /*data_K1_1270->plotOn(frame_K1_1270,DrawOption("C"));*/
    /*frame_K1_1270->Draw();*/
    /*c1->cd(2);*/
    /*RooPlot* frame_K1_1400 = m_Kpipi -> frame(Bins(200),Title("K1(1400) -> K#pi#pi"));*/
    /*data_K1_1400->plotOn(frame_K1_1400,DrawOption("C"));*/
    /*frame_K1_1400->Draw();*/
    /*c1->cd(3);*/
    /*RooPlot* frame_K2_1430= m_Kpipi -> frame(Bins(200),Title("K2*(1430) -> K#pi#pi"));*/
    /*data_K2_1430->plotOn(frame_K2_1430,DrawOption("C"));*/
    /*frame_K2_1430->Draw();*/

////////////////////////////////////////////////////////////////////////

    cout << "\n\n >>>> Importing sPlot  \n\n" << endl;

    TFile *Fworkspace = new TFile("workspace.root");

    RooWorkspace* wsp = (RooWorkspace*) Fworkspace->Get("wsp");
    wsp->Print();

    RooRealVar* B_postcalib_M = wsp -> var("B_postcalib_M");
    RooRealVar* nsig_sw = wsp-> var("nsig_sw");
    RooRealVar* nbkg_sw = wsp-> var("nbkg_sw");
    RooRealVar* B_M13_Subst3_gamma2pi0 = wsp-> var("B_M13_Subst3_gamma2pi0");
    RooRealVar* B_M023 = wsp -> var("B_M023");
    RooRealVar* K_1_1270_plus_M = wsp -> var("K_1_1270_plus_M");
    RooRealVar* K_1_1270_plus_SMALLESTDELTACHI2 = wsp -> var("K_1_1270_plus_SMALLESTDELTACHI2");
    RooRealVar* gamma_CL = wsp -> var("gamma_CL");
    RooRealVar* piminus_PIDK = wsp -> var("piminus_PIDK");
    RooRealVar* piplus_PIDK = wsp -> var("piplus_PIDK");
    RooRealVar* Kplus_PIDp = wsp -> var("Kplus_PIDp");
    RooRealVar* Kplus_PIDK = wsp -> var("Kplus_PIDK");
    RooRealVar* B_M02 = wsp -> var("B_M02");
    RooRealVar* L_nsig = wsp -> var("L_nsig");
    RooRealVar* L_nbkg = wsp -> var("L_nbkg");

    RooArgSet arg(*B_postcalib_M,*gamma_CL,*B_M13_Subst3_gamma2pi0,*B_M023,*piminus_PIDK,*piplus_PIDK,*Kplus_PIDK,*Kplus_PIDp);
    arg.add(*K_1_1270_plus_M);
    arg.add(*K_1_1270_plus_SMALLESTDELTACHI2);
    arg.add(*B_M02);
    arg.add(*nsig_sw);
    arg.add(*L_nsig);
    arg.add(*nbkg_sw);
    arg.add(*L_nbkg);

    arg.add(*m_Kpipi);


    RooDataSet* DataSWeights = (RooDataSet*) wsp -> data("DataSWeights");
    RooFormulaVar newMass("m_Kpipi", "m_Kpipi", "K_1_1270_plus_M", RooArgList(*(wsp->var("K_1_1270_plus_M"))));
    DataSWeights->addColumn(newMass);
    RooDataSet* splot = new RooDataSet(DataSWeights->GetName(),DataSWeights->GetTitle(),DataSWeights,RooArgSet(arg),"","nsig_sw");


    cout << "\n\n >>>> Defining components and fitting  \n\n" << endl;

    // Defining here pdfs for other resonances to be fitted

    // K1(1270)

    Double_t R = 0.0015; //  was 3.1 GeV-1
    RooRealVar mean_K1_1270("mean_K1_1270","",1272.,1262.,1282.);
    RooRealVar width_K1_1270("width_K1_1270","",90.,70.,110.);

    // K1(1270) -> K rho
    /*RooBreitWigner totalPdf_K1_1270("totalPdf_K1_1270","",*m_Kpipi,mean_K1_1270,width_K1_1270);*/
    /*RooRelBreitWigner totalPdf_K1_1270("totalPdf_K1_1270","totalPdf_K1_1270_rho",*m_Kpipi,mean_K1_1270,width_K1_1270,RooConst(0),RooConst(R),RooConst(770.),RooConst(493.7));*/

    // K1(1270) -> K*0(1430) pi
    /*RooBreitWigner totalPdf_K1_1270_Kst0_1430("totalPdf_K1_1270_Kst0_1430","totalPdf_K1_1270_Kst0_1430",*m_Kpipi,mean_K1_1270,width_K1_1270);*/
    /*RooRelBreitWigner totalPdf_K1_1270_Kst0_1430("totalPdf_K1_1270_Kst0_1430","totalPdf_K1_1270_Kst0_1430",*m_Kpipi,mean_K1_1270,width_K1_1270,RooConst(0),RooConst(R),RooConst(1425.),RooConst(139.6));*/

    // K1(1270) -> K*0(892) pi
    /*RooBreitWigner totalPdf_K1_1270_Kst0_892("totalPdf_K1_1270_Kst0_892","totalPdf_K1_1270_Kst0_892",*m_Kpipi,mean_K1_1270,width_K1_1270);*/
    /*RooRelBreitWigner totalPdf_K1_1270_Kst0_892("totalPdf_K1_1270_Kst0_892","totalPdf_K1_1270_Kst0_892",*m_Kpipi,mean_K1_1270,width_K1_1270,RooConst(0),RooConst(R),RooConst(895.5),RooConst(139.6));*/

    // K1(1400)

    RooRealVar mean_K1_1400("mean_K1_1400","",1403./*,1396.,1410.*/);
    RooRealVar width_K1_1400("width_K1_1400","",174./*,151.,197.*/);
    RooBreitWigner totalPdf_K1_1400("totalPdf_K1_1400","",*m_Kpipi,mean_K1_1400,width_K1_1400);
    /*[>RooRelBreitWigner totalPdf_K1_1400("totalPdf_K1_1400","totalPdf_K1_1400",*m_Kpipi,mean_K1_1400,width_K1_1400,RooConst(0),RooConst(R),RooConst(895.),RooConst(139.6)); //K*(892) pi is 93%<]*/

    // K2*(1430)

    RooRealVar mean_K2_1430("mean_K2_1430","",1432./*,1424.,1435.*/);
    RooRealVar width_K2_1430("width_K2_1430","",109./*,96.,114.*/);
    RooBreitWigner totalPdf_K2_1430("totalPdf_K2_1430","",*m_Kpipi,mean_K2_1430,width_K2_1430);

    // K3*(1780)

    RooRealVar mean_K3st_1780("mean_K3st_1780","mean_K3st_1780",1776./*,1765.,1785.*/);
    RooRealVar width_K3st_1780("width_K3st_1780","width_K3st_1780",159.7/*,150.,170.*/);
    RooBreitWigner K3st_1780("K3st_1780","K3st_1780",*m_Kpipi,mean_K3st_1780,width_K3st_1780);

    // K2(1770)

    RooRealVar mean_K2_1770("mean_K2_1770","mean_K2_1770",1773./*,1763.,1783.*/);
    RooRealVar width_K2_1770("width_K2_1770","width_K2_1770",186./*,176.,196.*/);
    RooBreitWigner K2_1770("K2_1770","K2_1770",*m_Kpipi,mean_K2_1770,width_K2_1770);

    // K2(1580)

    RooRealVar mean_K2_1580("mean_K2_1580","mean_K2_1580",1580.);
    RooRealVar width_K2_1580("width_K2_1580","width_K2_1580",110.);
    RooBreitWigner K2_1580("K2_1580","K2_1580",*m_Kpipi,mean_K2_1580,width_K2_1580);

    // K2*(1980)

    RooRealVar mean_K2st_1980("mean_K2st_1980","mean_K2st_1980",1973./*,1957.,1999.*/);
    RooRealVar width_K2st_1980("width_K2st_1980","width_K2st_1980",373./*,303.,443.*/);
    RooBreitWigner K2st_1980("K2st_1980","K2st_1980",*m_Kpipi,mean_K2st_1980,width_K2st_1980);

    // K*(1680)

    RooRealVar mean_Kst_1680("mean_Kst_1680","mean_K*_1680",1717./*,1690.,1744.*/);
    RooRealVar width_Kst_1680("width_Kst_1680","width_K*_1680",322./*,212.,432.*/);
    RooBreitWigner Kst_1680("Kst_1680","K*_1680",*m_Kpipi,mean_Kst_1680,width_Kst_1680);
    /*width_Kst_1680.setVal(322.);*/
    /*width_Kst_1680.setConstant(kTRUE);*/

    // K*(1410) mass 1414 +- 15 MeV , width 232 +- 21 MeV

    RooRealVar mean_Kst_1410("mean_Kst_1410","",1414./*,1399.,1429.*/);
    RooRealVar width_Kst_1410("width_Kst_1410","",232./*,253.,211.*/);
    RooBreitWigner Kst_1410("Kst_1410","",*m_Kpipi,mean_Kst_1410,width_Kst_1410);

    // Non resonant Kpipi

    RooRealVar c0("c0","c0",1.);
    RooRealVar c1("c1","c1",1.);
    RooRealVar c2("c2","c2",100.,200.);
    RooRealVar c3("c3","c3",-.1,+2.);
    RooRealVar c4("c4","c4",-2.,0.);
    RooGenericPdf non_resonant("non_resonant","non_resonant","(@0 + @1*@5)*exp(@2 + @3*@5 + @4*@5*@5)",RooArgList(c0,c1,c2,c3,c4,*m_Kpipi));
    /*RooRealVar par0("par0","par0",-2.,-100.,100.);*/
    /*RooRealVar par1("par1","par1",-2.,-100.,100.);*/
    /*RooRealVar par2("par2","par2",1.,-100.,100.);*/
    /*RooRealVar par3("par3","par3",1.,-100.,100.);*/
    /*RooChebychev non_resonant("non_resonant","non_resonant",*m_Kpipi,RooArgList(par0,par1,par2,par3));*/

    // defining the yields as the BR wrt K1(1270)

    RooRealVar K1_1270_Kst0_1430_br("K1_1270_Kst0_1430_br","K1_1270_Kst0_1430_br",0.41,0.,1.);
    RooRealVar K1_1270_Kst0_892_br("K1_1270_Kst0_892_br","K1_1270_Kst0_892_br",0.074,0.,1.);
    RooRealVar K1_1400_br("K1_1400_br","K1_1400_br",0.1226,0.,1.); // upper limit only
    /*RooRealVar K2_1430_br("K2_1430_br","K2_1430_br",0.07,0.,1.);*/
    /*RooRealVar K1_1400_br("K1_1400_br","K1_1400_br",0.1226,0.,0.13); // upper limit only*/
    RooRealVar K2_1430_br("K2_1430_br","K2_1430_br",0.07,0.05,0.09); // from Belle
    RooRealVar K3st_1780_br("K3st_1780_br","K3st_1780_br",0.1,0.,1.);
    RooRealVar K2_1770_br("K2_1770_br","K2_1770_br",0.1,0.,1.);
    RooRealVar K2_1580_br("K2_1580_br","K2_1580_br",0.1,0.,1.);
    RooRealVar K2st_1980_br("K2st_1980_br","K2st_1980_br",0.1,0.,1.);
    RooRealVar Kst_1680_br("Kst_1680_br","K*_1680_br",0.1,0.,1.);
    RooRealVar Kst_1410_br("Kst_1410_br","K*_1410_br",0.1,0.,.3);
    RooRealVar non_resonant_br("non_resonant_br","non_resonant_br",0.3,0.,2.);

    RooRealVar K1_1270_y("K1_1270_y","K1_1270_y",1000.,0.,10000.); // this is the yield of the K1(1270) TO rho
    RooFormulaVar K1_1270_Kst0_1430_y("K1_1270_Kst0_1430_y","K1_1270_Kst0_1430_y","@0*@1",RooArgList(K1_1270_Kst0_1430_br,K1_1270_y));
    RooFormulaVar K1_1270_Kst0_892_y("K1_1270_Kst0_892_y","K1_1270_Kst0_892_y","@0*@1",RooArgList(K1_1270_Kst0_892_br,K1_1270_y));
    RooFormulaVar K1_1400_y("K1_1400_y","K1_1400_y","@0*@1",RooArgList(K1_1400_br,K1_1270_y));
    RooFormulaVar K2_1430_y("K2_1430_y","K2_1430_y","@0*@1",RooArgList(K2_1430_br,K1_1270_y));
    RooFormulaVar K3st_1780_y("K3st_1780_y","K3st_1780_y","@0*@1",RooArgList(K3st_1780_br,K1_1270_y));
    RooFormulaVar K2_1770_y("K2_1770_y","K2_1770_y","@0*@1",RooArgList(K2_1770_br,K1_1270_y));
    RooFormulaVar K2_1580_y("K2_1580_y","K2_1580_y","@0*@1",RooArgList(K2_1580_br,K1_1270_y));
    RooFormulaVar K2st_1980_y("K2st_1980_y","K2st_1980_y","@0*@1",RooArgList(K2st_1980_br,K1_1270_y));
    RooFormulaVar Kst_1680_y("Kst_1680_y","Kst_1680_y","@0*@1",RooArgList(Kst_1680_br,K1_1270_y));
    RooFormulaVar Kst_1410_y("Kst_1410_y","Kst_1410_y","@0*@1",RooArgList(Kst_1410_br,K1_1270_y));
    RooFormulaVar non_resonant_y("non_resonant_y","non_resonant_y","@0*@1",RooArgList(non_resonant_br,K1_1270_y));

    // here add pdfs and FIT sum of pdf to splot
    //
    RooArgList shapes;
    RooArgList yields;
    shapes.add(*totalPdf_K1_1270);
    shapes.add(*totalPdf_K1_1270_Kst0_1430);
    shapes.add(*totalPdf_K1_1270_Kst0_892);
    shapes.add(totalPdf_K1_1400);
    shapes.add(totalPdf_K2_1430);
    shapes.add(K3st_1780);
    /*shapes.add(K2_1770);*/
    shapes.add(K2_1580);
    shapes.add(K2st_1980);
    shapes.add(Kst_1680);
    /*shapes.add(Kst_1410);*/
    /*shapes.add(non_resonant);*/

    yields.add(K1_1270_y);
    yields.add(K1_1270_Kst0_1430_y);
    yields.add(K1_1270_Kst0_892_y);
    yields.add(K1_1400_y);
    yields.add(K2_1430_y);
    yields.add(K3st_1780_y);
    /*yields.add(K2_1770_y);*/
    yields.add(K2_1580_y);
    yields.add(K2st_1980_y);
    yields.add(Kst_1680_y);
    /*yields.add(Kst_1410_y);*/
    /*yields.add(non_resonant_y);*/

    // Putting all pdfs together

    RooAddPdf PDF("PDF","total Pdf for the resonances considered", shapes,yields);

    /*PDF->fitTo(*splot,Extended(),SumW2Error(kFALSE),Range(1000,2000));*/
    PDF.fitTo(*splot,Extended(),SumW2Error(kTRUE),Range(xmin,xmax));

    // Defining frames for plotting

    cout << "\n\n >>>> Plotting  \n\n" << endl;

    RooPlot* frame_splot = m_Kpipi->frame(Title("sPlot of m_{K#pi#pi} [MeV/c^{2}]"),Range(xmin,xmax),Bins(nbins));
    splot->plotOn(frame_splot,Name("fitted_splot")/*,DataError(RooAbsData::SumW2)*/);

    PDF.paramOn(frame_splot,Layout(.65,.9,.99)); // Layout(xmin,ymin,ymax)
    PDF.plotOn(frame_splot,Components(*totalPdf_K1_1270),LineColor(kRed));
    PDF.plotOn(frame_splot,Components(*totalPdf_K1_1270_Kst0_1430),LineColor(kRed),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(*totalPdf_K1_1270_Kst0_892),LineColor(kRed));
    PDF.plotOn(frame_splot,Components(totalPdf_K1_1400),LineColor(1));
    PDF.plotOn(frame_splot,Components(totalPdf_K2_1430),LineColor(51),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K3st_1780),LineColor(kOrange),LineStyle(kDashed));
    /*PDF.plotOn(frame_splot,Components(K2_1770),LineColor(5),LineStyle(kDashed));*/
    PDF.plotOn(frame_splot,Components(K2_1580),LineColor(12),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(K2st_1980),LineColor(16),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(Kst_1680),LineColor(32),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(Kst_1410),LineColor(3),LineStyle(kDashed));
    PDF.plotOn(frame_splot,Components(non_resonant),LineColor(5),LineStyle(kDashed));
    PDF.plotOn(frame_splot);

    // Plotting with residuals

    TCanvas* canvas_sPlot = new TCanvas("canvas_sPlot","sPlot with weights",40,20,1200,800);
    plot_with_residuals(*canvas_sPlot,*frame_splot,*m_Kpipi,nbins,xmin,xmax); // residuals(TCanvas& _canvas,RooPlot& _frame,RooRealVar& var,Int_t& _nbins,Double_t& r_min,Double_t& r_max)

    // CleanUp worspaces

    delete ws_K1_1270;
    /*delete ws_K1_1400;*/
    /*delete ws_K2_1430;*/
    delete wsp;

    cout << "\n\n >>>> THE END  \n\n" << endl;

    /*cout << gMinuit->GetStatus() << endl;*/

}
Пример #5
0
void ws_v01()
{
    TFile *f1 = new TFile("K1_1270/ws_K1_1270.root");
    TFile *f2 = new TFile("K1_1400/ws_K1_1400.root");
    TFile *f3 = new TFile("K2_1430/ws_K2_1430.root");

    RooWorkspace* ws_K1_1270 = (RooWorkspace*) f1->Get("ws_K1_1270");
    RooWorkspace* ws_K1_1400 = (RooWorkspace*) f2->Get("ws_K1_1400");
    RooWorkspace* ws_K2_1430 = (RooWorkspace*) f3->Get("ws_K2_1430");
    ws_K1_1270->Print();
    ws_K1_1400->Print();
    ws_K2_1430->Print();

    // Importing variables from workspaces

    RooRealVar* m_Kpipi = ws_K1_1270 -> var("m_Kpipi");
    RooAbsPdf* totalPdf_K1_1270 = ws_K1_1270 -> pdf("totalPdf_K1_1270");
    RooAbsData* data_K1_1270 = ws_K1_1270 -> data("totalPdf_K1_1270Data");
    RooHistPdf* pdf_K1_1270_to_Krho = ws_K1_1270 -> pdf("histPdf_K1toKrho");

    RooRealVar* m_Kpipi = ws_K1_1400 -> var("m_Kpipi");
    RooAbsPdf* totalPdf_K1_1400 = ws_K1_1400 -> pdf("totalPdf_K1_1400");
    RooAbsData* data_K1_1400 = ws_K1_1400 -> data("totalPdf_K1_1400Data");
    RooHistPdf* pdf_K1_1400_to_Krho = ws_K1_1400 -> pdf("histPdf_K1_1400toKrho");

    RooRealVar* m_Kpipi = ws_K2_1430 -> var("m_Kpipi");
    RooAbsPdf* totalPdf_K2_1430 = ws_K2_1430 -> pdf("totalPdf_K2_1430");
    RooAbsData* data_K2_1430 = ws_K2_1430 -> data("totalPdf_K2_1430Data");
    RooHistPdf* pdf_K2_1430_to_Krho = ws_K2_1430 -> pdf("histPdf_K2_1430toKrho");

    // Plotting pdf

    TCanvas* c1 = new TCanvas("c1","canvas",20,20,1200,600);
    c1->Divide(3,1);
    c1->cd(1);
    RooPlot* frame_K1_1270 = m_Kpipi -> frame(Bins(200),Title("K1(1270) -> K#pi#pi"));
    data_K1_1270->plotOn(frame_K1_1270,DrawOption("C"));
    frame_K1_1270->Draw();
    c1->cd(2);
    RooPlot* frame_K1_1400 = m_Kpipi -> frame(Bins(200),Title("K1(1400) -> K#pi#pi"));
    data_K1_1400->plotOn(frame_K1_1400,DrawOption("C"));
    frame_K1_1400->Draw();
    c1->cd(3);
    RooPlot* frame_K2_1430= m_Kpipi -> frame(Bins(200),Title("K2*(1430) -> K#pi#pi"));
    data_K2_1430->plotOn(frame_K2_1430,DrawOption("C"));
    frame_K2_1430->Draw();

////////////////////////////////////////////////////////////////////////////

    /*TFile *MC = new TFile("MCTruthB2K1GammaPerChannel.root");*/
    /*TTree* t_tree = (TTree*)MC->Get("B2K1RhoKGamma/MCDecayTree");*/

    /*RooArgSet param(*m_Kpipi);*/
    /*RooDataSet MCdataset("MCdataset","MCdataset",param);*/

    /*Double_t K_1_1270_plus_TRUEM = 0.;*/

    /*t_tree->SetBranchAddress("K_1_1270_plus_TRUEM",&K_1_1270_plus_TRUEM);*/

    /*Int_t n = 0;*/
    /*for (int i=0;i<t_tree->GetEntries();i++)*/
    /*{*/
        /*t_tree->GetEntry(i);*/
        /**m_Kpipi_K1_1270 = K_1_1270_plus_TRUEM;*/

        /*MCdataset.add(param);*/
        /*n++;*/
    /*}*/

    /*pdf_K1_1270_to_Krho.fitTo(MCdataset,Extended(true));*/

    /*TCanvas* canvas = new TCanvas("canvas","MC data for K1(1270) -> #rho K",20,20,800,600);*/
    /*RooPlot* frame_MCdataset = m_Kpipi.frame(Bins(200));*/
    /*pdf_K1_1270_to_Krho.paramOn(frame_MCdataset);*/
    /*MCdataset.plotOn(frame_MCdataset,DrawOption("C"));*/
    /*pdf_K1_1270_to_Krho->plotOn(frame_MCdataset);*/
    /*frame_MCdataset->Draw();*/

 ////////////////////////////////////////////////////////////////////////

    TFile *Fworkspace = new TFile("workspace.root");

    RooWorkspace* wsp = (RooWorkspace*) Fworkspace->Get("wsp");
    wsp->Print();

    RooRealVar* B_postcalib_M = wsp -> var("B_postcalib_M");
    RooRealVar* nsig_sw = wsp-> var("nsig_sw");
    RooRealVar* nbkg_sw = wsp-> var("nbkg_sw");
    RooRealVar* B_M13_Subst3_gamma2pi0 = wsp-> var("B_M13_Subst3_gamma2pi0");
    RooRealVar* B_M023 = wsp -> var("B_M023");
    RooRealVar* K_1_1270_plus_M = wsp -> var("K_1_1270_plus_M");
    RooRealVar* K_1_1270_plus_SMALLESTDELTACHI2 = wsp -> var("K_1_1270_plus_SMALLESTDELTACHI2");
    RooRealVar* gamma_CL = wsp -> var("gamma_CL");
    RooRealVar* piminus_PIDK = wsp -> var("piminus_PIDK");
    RooRealVar* piplus_PIDK = wsp -> var("piplus_PIDK");
    RooRealVar* Kplus_PIDp = wsp -> var("Kplus_PIDp");
    RooRealVar* Kplus_PIDK = wsp -> var("Kplus_PIDK");
    RooRealVar* B_M02 = wsp -> var("B_M02");
    RooRealVar* L_nsig = wsp -> var("L_nsig");
    RooRealVar* L_nbkg = wsp -> var("L_nbkg");

    RooArgSet arg(*B_postcalib_M,*gamma_CL,*B_M13_Subst3_gamma2pi0,*B_M023,*piminus_PIDK,*piplus_PIDK,*Kplus_PIDK,*Kplus_PIDp);
    arg.add(*K_1_1270_plus_M);
    arg.add(*K_1_1270_plus_SMALLESTDELTACHI2);
    arg.add(*B_M02);
    arg.add(*nsig_sw);
    arg.add(*L_nsig);
    arg.add(*nbkg_sw);
    arg.add(*L_nbkg);

    arg.add(*m_Kpipi);


    RooDataSet* DataSWeights = (RooDataSet*) wsp -> data("DataSWeights");
    RooFormulaVar newMass("m_Kpipi", "m_Kpipi", "K_1_1270_plus_M", RooArgList(*(wsp->var("K_1_1270_plus_M"))));
    DataSWeights->addColumn(newMass);
    RooDataSet* splot = new RooDataSet(DataSWeights->GetName(),DataSWeights->GetTitle(),DataSWeights,RooArgSet(arg),"","nsig_sw");

    // here add pdfs and FIT sum of pdf to splot

    RooRealVar K1_1270_y("K1_1270_y","K1_1270_y",1000.,0.,10000.);
    RooRealVar K1_1400_y("K1_1400_y","K1_1400_y",100.,0.,10000.);
    /*RooRealVar K2_1430_y("K2_1430_y","K2_1430_y",300.,0.,10000.);*/
    RooFormulaVar K2_1430_y("K2_1430_y","K2_1430_y","K1_1270_y/3.",K1_1270_y); // K2_1430 yield is fixed to 1/3 of the K1_1270 yield (as found from Belle ... TO CHECK)

    RooArgList shapes;
    RooArgList yields;
    shapes.add(*totalPdf_K1_1270);
    shapes.add(*totalPdf_K1_1400);
    shapes.add(*totalPdf_K2_1430);
    yields.add(K1_1270_y);
    yields.add(K1_1400_y);
    yields.add(K2_1430_y);

    RooAddPdf PDF("PDF","total Pdf for the resonances considered", shapes,yields);

    PDF->fitTo(*splot,Extended(),SumW2Error(kTRUE),Range(1000,2000));

    // Plotting

    TCanvas* canvas_sPlot = new TCanvas("canvas_sPlot","sPlot with weights",40,20,800,600);
    RooPlot* frame_splot = m_Kpipi->frame(1000,2000,80);
    splot->plotOn(frame_splot);

    PDF->paramOn(frame_splot);
    PDF->plotOn(frame_splot,Components(*totalPdf_K1_1270),LineColor(kRed),LineStyle(kDashed));
    PDF->plotOn(frame_splot,Components(*totalPdf_K1_1400),LineColor(1),LineStyle(kDashed));
    PDF->plotOn(frame_splot,Components(*totalPdf_K2_1430),LineColor(51),LineStyle(kDashed));
    PDF->plotOn(frame_splot);
    frame_splot->Draw();

}