#include #include #include #include #include #include "TMath.h" #include #include "Riostream.h" void Splot() { TString INPUT_path = ""; TString OUTPUT_path = ""; TFile *file = TFile::Open(INPUT_path, "read");//input file TTree *tree = (TTree*)file->Get("data"); TF1 *signal = new TF1 ("signal","(ROOT::Math::crystalball_function(-x, [0], [1], [2], [3]))*[4]+(ROOT::Math::crystalball_function(x, [5], [6], [2], -[3]))*[4]",5400,6000);//pdf functions TF1 *background = new TF1("background","expo(0)",5400,6000); float pdfsignal, pdfbckgr, mass; TBranch *pdfsignalbr = tree->Branch("pdfsignalbr",&pdfsignal,"pdfsignal/F");//pdf branches for sig&background TBranch *pdfbckgrbr = tree->Branch("pdfbckgrbr",&pdfbckgr,"pdfbckgr/F"); tree->SetBranchAddress("FinalMass",&mass); int totalentries = tree->GetEntries(); int nentries[2]; background->SetParameters(12.49,-0.001389);//parameters obtained from fitting signal->SetParameters(1.108,1.001,15.92,-5625,1075,0.736,1.549); nentries[0] = round((signal->Integral(5400,6000)/10));//for approximating number of signal and background events fot tsplot nentries[1] = round((background->Integral(5400,6000))/10); std::cout<GetEntry(iterator); pdfsignal = signal->Eval(mass); pdfbckgr = background->Eval(mass); pdfsignalbr->Fill(); pdfbckgrbr->Fill(); } TFile *file2 = TFile::Open(OUTPUT_path, "recreate");//output file TTree *tree2 = tree->CloneTree();//create a new tree from the input tree+pdf branches tree2->Write(); file->Close(); TSPlot *splot = new TSPlot(1,1,totalentries,2,tree2); splot->SetTreeSelection("nSPDHits:FinalMass:pdfsignalbr:pdfbckgrbr"); splot->SetInitialNumbersOfSpecies(nentries); splot->MakeSPlot("VV"); splot->FillSWeightsHists(100); splot->Write(); file2->Close(); }