using namespace RooFit; void Fit_weights() { //Defining Fit Model // --- Observable --- RooRealVar mes("mB","m_{B} (GeV/c^{2})",6.00,6.500) ; RooRealVar s12("s12","s12 [GeV/c^{2}]^{2}",0.,50.) ; RooRealVar s23("s23","s23 [GeV/c^{2}]^{2}",0.,50.) ; RooRealVar eventweight("weight","weight",0.0,1.0); //RooRealVar eventweight("weight","weight",2); // Partially Reconstructed, using CONVOLUTION // RooRealVar m0("m0","m_0 (GeV/c^{2})",6.1,6,6.5) ; RooRealVar slope("slope","slope",-25,-50,10) ; RooGaussian myGaus("resolution","gauss model",mes,RooFit::RooConst(0.0),RooFit::RooConst(0.021385)); RooArgusBG bkgArg("bkgArg","Argus Bkg",mes,m0,slope); RooFFTConvPdf PartReco( "PartReco", "", mes, bkgArg, myGaus ); PartReco.setBufferFraction(0.5); //RooFFTConvPdf PartReco2( "PartReco2", "", mes, bkgArg, myGaus ); // PartReco2.setBufferFraction(0.3); //RooFFTConvPdf PartReco3( "PartReco3", "", mes, bkgArg, myGaus ); //PartReco3.setBufferFraction(0.3); // Combine altogether RooRealVar Nsig("Nsig","signal evts",3000,0,2000000); RooRealVar Ncomb("Ncomb","comb bkg evts",1000,0,100000); // extended likelihood PDFs: //RooExtendPdf sige("sige","sige",signal,Nsig) ; //RooExtendPdf Combe("Ext Comb","Ext Comb",Comb,Ncomb) ; RooExtendPdf PartRecoSum("PartRecoSum"," ",PartReco,Ncomb); //Combine: //RooAddPdf sum("sum","g+p1",RooArgList(sige,Combe)); // Signal only: to be used for the matched Monte Carlo RooAddPdf sum("sum","PartReco",RooArgList(PartRecoSum)); // ********* READING DATA from NTUPLE and filling RooDataSet object ****** \\ TFile *f = TFile::Open("tree1.root"); TTree *treedata = (TTree*)f->Get("DecayTree"); RooDataSet *dataTemp = new RooDataSet("dataTemp","dataTemp",RooArgSet(mes,s12,s23)); Double_t Bmass,s12_DTF,s23_DTF; Bool_t B_L0HadronDecision_TOS1; Bool_t B_L0Global_TIS1; Bool_t B_Hlt1TrackAllL0Decision_TOS1; Bool_t B_Hlt2Topo2BodyBBDTDecision_TOS1; Bool_t B_Hlt2Topo3BodyBBDTDecision_TOS1; Bool_t B_Hlt2Topo4BodyBBDTDecision_TOS1; Double_t BDT; Double_t effpid; Bool_t Muon1,Muon2,Muon3; treedata->SetBranchAddress("B_L0HadronDecision_TOS",&B_L0HadronDecision_TOS1); treedata->SetBranchAddress("B_L0Global_TIS",&B_L0Global_TIS1); treedata->SetBranchAddress("B_Hlt1TrackAllL0Decision_TOS",&B_Hlt1TrackAllL0Decision_TOS1); treedata->SetBranchAddress("B_Hlt2Topo2BodyBBDTDecision_TOS",&B_Hlt2Topo2BodyBBDTDecision_TOS1); treedata->SetBranchAddress("B_Hlt2Topo3BodyBBDTDecision_TOS",&B_Hlt2Topo3BodyBBDTDecision_TOS1); treedata->SetBranchAddress("B_M",&Bmass); treedata->SetBranchAddress("s12_DTF",&s12_DTF); treedata->SetBranchAddress("s23_DTF",&s23_DTF); treedata->SetBranchAddress("BDT_KKpi2011_total",&BDT); treedata->SetBranchAddress("EffPidStrip2",&effpid); treedata->SetBranchAddress("d1_isMuon",&Muon1); treedata->SetBranchAddress("d2_isMuon",&Muon2); treedata->SetBranchAddress("d3_isMuon",&Muon3); Long64_t nentries = treedata->GetEntries(); cout<<"Entries data: "<GetEntry(i); if (i%100000 == 0) { cout << "Finished processing " << i << " events." << endl; } if ((B_L0HadronDecision_TOS1 == 1 || B_L0Global_TIS1 == 1) && (B_Hlt1TrackAllL0Decision_TOS1>0) && (B_Hlt2Topo2BodyBBDTDecision_TOS1>0 || B_Hlt2Topo3BodyBBDTDecision_TOS1>0 || B_Hlt2Topo4BodyBBDTDecision_TOS1>0) && (Bmass > 6000) && (Bmass < 6500) && (BDT > 0.04)) { if ((Muon1 == 0) && (Muon2 == 0) && (Muon3 == 0)) { mes = Bmass*0.001; s12 = s12_DTF; s23 = s23_DTF; eventweight = effpid; dataTemp->add(RooArgSet(mes,s12,s23)); /* if (Bmass > 6200) { eventweight = effpid; } else { eventweight = 2; } */ } } } dataTemp->addColumn(eventweight) RooDataSet *wdata = new RooDataSet("wdata", "wdata",*dataTemp->get(),RooFit::Import(*dataTemp),RooFit::WeightVar("eventweight")); cout << "Dataset cloned." << endl; // CALLING THE FITTER: mes.setRange("partreco",6,6.5); RooFitResult* fitRes = sum.fitTo(*wdata, RooFit::Save(true),RooFit::SumW2Error(kTRUE),RooFit::Strategy(2),RooFit::Range("partreco")); cout << "Fit Result successful" << endl; // PLOTTING THE RESULTS (FUNCTION, FITTED FUNCTION PARAMETERS AND DATA) RooPlot* xframe2 = mes.frame(100); wdata->plotOn(xframe2,RooFit::DataError(RooAbsData::SumW2)); //sum.plotOn(xframe2); //sum.paramOn(xframe2,wdata); xframe2->GetXaxis()->SetTitleSize(0.06); xframe2->GetXaxis()->SetLabelSize(0.05); xframe2->GetXaxis()->SetTitleFont(62); xframe2->GetXaxis()->SetLabelFont(62); xframe2->GetXaxis()->CenterTitle(); xframe2->GetYaxis()->SetTitleSize(0.06); xframe2->GetYaxis()->SetLabelSize(0.05); xframe2->GetYaxis()->SetTitleFont(62); xframe2->GetYaxis()->SetLabelFont(62); xframe2->GetYaxis()->CenterTitle(); xframe2->GetYaxis()->SetTitle("Entries"); xframe2->SetTitle(""); xframe2->Draw(); }