File indexing completed on 2024-04-06 12:22:42
0001 #ifndef __CINT__
0002 #include "RooGlobalFunc.h"
0003 #endif
0004 #include "RooRealVar.h"
0005 #include "RooDataSet.h"
0006 #include "RooGaussModel.h"
0007 #include "RooAddModel.h"
0008 #include "RooTruthModel.h"
0009 #include "RooDecay.h"
0010 #include "RooPlot.h"
0011 #include "RooLandau.h"
0012 #include "RooGaussian.h"
0013 #include "RooNumConvPdf.h"
0014 #include "RooExponential.h"
0015 #include "RooCBShape.h"
0016 #include "TCanvas.h"
0017 #include "TH1.h"
0018 #include "RooGenericPdf.h"
0019 #include "RooAddPdf.h"
0020 #include <sstream>
0021 #include "TFile.h"
0022 #include "RooDataHist.h"
0023 #include "RooExtendPdf.h"
0024
0025 void CrystalBallFitOnData_JPsi()
0026 {
0027 TFile inputFile("0_MuScleFit.root", "READ");
0028 TH1F * inputHisto = (TH1F*)inputFile.Get("hRecBestResAllEvents_Mass");
0029 inputHisto->Rebin(4);
0030
0031 double xMin = 2.5;
0032 double xMax = 4.;
0033 RooRealVar x("x", "Mass (GeV)", xMin, xMax);
0034
0035 RooDataHist histo("dh", "dh", x, Import(*inputHisto));
0036
0037
0038 RooRealVar peak("peak","peak", 3.095, 2.5, 4.);
0039 RooRealVar sigma("sigma","sigma", 0.04, 0.001, 0.1);
0040 RooRealVar alpha("alpha", "alpha", 1., 0., 10.);
0041 RooRealVar n("n", "n", 1., 0., 100.);
0042 RooCBShape signal("signal", "signal", x, peak, sigma, alpha, n);
0043
0044
0045 RooRealVar expCoeff("expCoeff", "exponential coefficient", -1., -10., 10.);
0046 RooExponential background("exponential", "exponential", x, expCoeff);
0047
0048 TFile outputFile("crystalBallFitOnData_JPsi.root", "RECREATE");
0049
0050
0051 int binXmin = inputHisto->FindBin( xMin );
0052 int binXmax = inputHisto->FindBin( xMax );
0053 Double_t fullIntegral = inputHisto->Integral(binXmin, binXmax);
0054
0055
0056 RooRealVar nSig("nSig", "signal fraction", 30, 0., fullIntegral);
0057 RooRealVar nBkg("nBkg", "background fraction", 20, 0., fullIntegral);
0058
0059 Double_t sbSigma = 3.;
0060
0061
0062 for( int i=0; i<2; ++i ) {
0063
0064 Double_t sbMin = peak.getVal() - sbSigma*sigma.getVal();
0065 Double_t sbMax = peak.getVal() + sbSigma*sigma.getVal();
0066 x.setRange("small", sbMin, sbMax);
0067 RooExtendPdf eSig("eSig", "eSig", signal, nSig, "small");
0068 RooExtendPdf eBkg("eBkg", "eBkg", background, nBkg, "small");
0069
0070
0071 RooAddPdf model("model", "model", RooArgList(eSig, eBkg));
0072
0073 model.fitTo(histo);
0074
0075 std::cout << "peak("<<i<<") = " << peak.getVal() << "+-" << peak.getError() << std::endl;
0076 std::cout << "sigma("<<i<<") = " << sigma.getVal() << "+-" << sigma.getError() << std::endl;
0077 if( i==1 ) {
0078 TCanvas canvas("canvas", "canvas", 1000, 800);
0079 canvas.cd();
0080 canvas.Draw();
0081 RooPlot* frame = x.frame();
0082 histo.plotOn(frame);
0083 model.plotOn(frame);
0084 model.paramOn(frame);
0085
0086 model.plotOn(frame, Components("exponential"), LineStyle(kDashed));
0087
0088 frame->Draw();
0089 frame->Write();
0090 canvas.Write();
0091 outputFile.Write();
0092 }
0093 }
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 };