ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/UfCode/UserArea/StatTools/stat.C
Revision: 1.1
Committed: Wed Dec 8 10:57:12 2010 UTC (14 years, 4 months ago) by kkotov
Content type: text/plain
Branch: MAIN
CVS Tags: V2012-H-02, V2012-01-00, V2011-01-01, V2011-01-00, AnnaDimuon, V01-00-01, V01-00-00, HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 kkotov 1.1 #include "RooPlot.h"
2     #include "RooRandom.h"
3     #include "RooRealVar.h"
4     #include "RooGaussian.h"
5     #include "RooPolynomial.h"
6     #include "RooArgSet.h"
7     #include "RooAddPdf.h"
8     #include "RooDataSet.h"
9     #include "RooExtendPdf.h"
10     #include "RooConstVar.h"
11    
12    
13     #ifndef __CINT__ // problem including this file with CINT
14     #include "RooGlobalFunc.h"
15     #endif
16    
17     #include "RooStats/FeldmanCousins.h"
18     #include "RooStats/PointSetInterval.h"
19    
20     #include "RooStats/ProfileLikelihoodCalculator.h"
21     #include "RooStats/LikelihoodIntervalPlot.h"
22    
23     #include "TCanvas.h"
24     #include "TH1F.h"
25     #include "TFile.h"
26     #include "TChain.h"
27    
28     #include "RooWorkspace.h"
29    
30     #include "RooDataHist.h"
31    
32     //#include "./_tdrstyle.C"
33    
34     void stat(int ntoys = 10000){
35     using namespace RooFit;
36     using namespace RooStats;
37     // setTDRStyle();
38     RooRandom::randomGenerator()->SetSeed(10);
39    
40     // Create a workspace to manage the project.
41     RooWorkspace* wspace = new RooWorkspace("myWS");
42    
43     // qT observable and its the range:
44     wspace->factory("qT[30.0, 1200.0]");
45    
46     // Luminosity:
47     wspace->factory("luminosity[35., 25., 45.]"); // Expect to accumulate up to 30/pb in 2010
48     // wspace->factory("Gaussian::prior_lumi(luminosity, 10.9, 0.05)"); // Assume 5% gaussian uncertainty for the luminosity
49     // Drell-Yan cross section:
50     wspace->factory("dy_xsec[1737.9, 1500, 2000]"); // NNLO Drell-Yan cross section given by FEWZz with m>20 (in pb)
51     // wspace->factory("Gaussian::prior_dy_xsec(dy_xsec, 1.7379, 0.0168)"); // see https://alcaraz.web.cern.ch/alcaraz/CROSS_SECTIONS.txt for details
52     // Drell-Yan acceptance:
53     wspace->factory("dy_acceptance[0.235, 0.0, 1.0]"); // Assuming 60<m<120 && VBTF selection
54     // wspace->factory("Gaussian::prior_dy_acc(dy_acceptance, 0.235, 0.00025)"); // Accuracy's estimate for an acceptance (difference between accTrue and accSim)
55     // Fraction of Drell-Yan in qT>30 range:
56     wspace->factory("dy_qTcut[0.166, 0.0, 1.0]"); // Number of Drell-Yan events with in the spectrum
57     // wspace->factory("Gaussian::prior_dy_qTcut(dy_qTcut, 0.166, 0.0001)"); // Accuracy's estimate for an acceptance (out of the blue)
58     // Net Drell-Yan yield:
59     wspace->factory("prod::dy_yield(luminosity, dy_xsec, dy_acceptance, dy_qTcut)");
60     // Make a simple model of Drell-Yan background
61     wspace->factory("dy_slope[0.64, 0.6, 0.8]");
62     // wspace->factory("Gaussian::prior_dy_slope(dy_slope, 0.64, 0.05)"); // I'll have to come up with something better here
63     wspace->factory("CEXPR::background('exp(-sqrt(qT)*dy_slope)', qT, dy_slope)");
64    
65     // Make a simple model of signal (no uncertainties here)
66     // wspace->factory("CEXPR::signal('4.38397e-01/14.55/(7.43366e-01 + exp(4.51335e-02*(qT-7.08881e+02)) + 2.27385e-04*(qT-8.47767e+02)*(qT-8.47767e+02))', qT)"); // Z' m=1500 GeV/c/c
67     // wspace->factory("CEXPR::signal('4.92212e+02/14.5/(-3.04459e+05 + exp(3.80391e-02*(qT-7.55088e+02)) + 9.11595e-03*(qT-6.81130e+03)*(qT-6.81130e+03))', qT)"); // Z' m=2000 GeV/c/c
68     wspace->factory("CEXPR::signal('343989./(2435.4 + exp(-0.008824*(qT-234.877)) + 0.087526879*(qT-234.877)*(qT-234.877))', qT)"); //ci05
69     wspace->factory("CEXPR::signal('1714311/(13545.8+ exp(-0.034854*(qT-401.749)) + 0.484819424*(qT-401.749)*(qT-401.749))', qT)"); //ci10
70     wspace->factory("CEXPR::signal('783571./(8064.4 + exp(-0.024829*(qT-558.958)) + 0.208610709*(qT-558.958)*(qT-558.958))', qT)"); //ci15
71     wspace->factory("CEXPR::signal('10.8808/(-0.102 + exp( 0.019262*(qT-366.378)) + 3.11203e-06*(qT-366.378)*(qT-366.378))', qT)"); //gi05
72     wspace->factory("CEXPR::signal('878.946/(2.7015 + exp( 0.021975*(qT-459.043)) + 2.58958e-04*(qT-459.043)*(qT-459.043))', qT)"); //gi10
73     wspace->factory("CEXPR::signal('1819.48/(12.188 + exp( 0.015487*(qT-639.073)) + 4.15408e-04*(qT-639.073)*(qT-639.073))', qT)"); //gi15
74     wspace->factory("CEXPR::signal('296.407/(2.6339 + exp( 0.06652 *(qT-220.041)) + 2.17778e-03*(qT-220.041)*(qT-220.041))', qT)"); //zp05
75     wspace->factory("CEXPR::signal('611.231/(3.6656 + exp( 0.030314*(qT-468.111)) + 6.99505e-04*(qT-468.111)*(qT-468.111))', qT)"); //zp10
76     wspace->factory("CEXPR::signal('567.34 /(10.927 + exp( 0.02028 *(qT-687.772)) + 5.33170e-04*(qT-687.772)*(qT-687.772))', qT)"); //zp15
77    
78     // Put signal and background together
79     wspace->factory("SUM::model(sig_yield[0,0,10]*signal, dy_yield*background)");
80    
81     // Background only model
82     wspace->factory("ExtendPdf::null(background, dy_yield)");
83    
84     RooAbsPdf* model = wspace->pdf("model");
85     RooAbsPdf* null = wspace->pdf("null");
86     RooRealVar* sig_yield = wspace->var("sig_yield");
87    
88     RooRealVar* luminosity = wspace->var("luminosity");
89     //luminosity->setConstant();
90     RooRealVar* dy_xsec = wspace->var("dy_xsec");
91     dy_xsec->setConstant();
92     RooRealVar* dy_acceptance = wspace->var("dy_acceptance");
93     dy_acceptance->setConstant();
94     RooRealVar* dy_qTcut = wspace->var("dy_qTcut");
95     dy_qTcut->setConstant();
96     RooRealVar* dy_slope = wspace->var("dy_slope");
97     //dy_slope->setConstant();
98    
99     // RooArgList observable( *(wspace->var("qT")) );
100    
101     ModelConfig modelConfig("sigBg");
102     modelConfig.SetWorkspace(*wspace);
103     modelConfig.SetPdf(*model);
104     RooArgSet POI(*sig_yield);
105     modelConfig.SetParameters(POI);
106     // modelConfig.SetObservables(observable);
107     wspace->Print();
108    
109     //wspace->writeToFile("myWS.root");
110    
111     RooRealVar* qT = wspace->var("qT");
112    
113     // Pseudo data:
114     // RooDataSet* data = model->generate(*qT,);
115     // RooDataSet* data = null->generate(*qT,RooFit::Extended());
116    
117     // Real data:
118     TFile *qTdata = new TFile("boostedZnew.root");
119     TTree *skim = (TTree*)qTdata->Get("skim");
120     // TChain *dataTree = new TChain("tree");
121     // dataTree->AddFile("../11pb/dimuons_merged_6860InvNb_nocosmics.root");
122     // dataTree->AddFile("../11pb/dimuons_Run2010B_PromptReco_v2_run147117to147454.root");
123     RooArgSet vars(*qT);
124     // RooDataSet* data = new RooDataSet("recoCandPt","recoCandPt",dataTree,vars,"recoCandMass>60 && recoCandMass<120");
125     RooDataSet* data = new RooDataSet("qTdata","qTdata",skim,vars);
126    
127     /*
128     TCanvas *q = new TCanvas();
129     RooPlot* frame = qT->frame();
130     data->plotOn(frame);
131     model->plotOn(frame);
132     frame->Draw();
133     return;
134     */
135     /*
136     // Set up the ProfileLikelihoodCalculator
137     ProfileLikelihoodCalculator plc(*data, *model, POI);
138     // ProfileLikelihoodCalculator usually make intervals: the 95% CL one-sided upper-limit is the same as the two-sided upper-limit of a 90% CL interval
139     plc.SetTestSize(0.10);
140     // Pointer to the confidence interval
141     model->fitTo(*data,SumW2Error(kFALSE)); // <-- problem
142     LikelihoodInterval* plcInterval = plc.GetInterval();
143     // Compute the upper limit: a fit is needed first in order to locate the minimum of the -log(likelihood) and ease the upper limit computation
144     model->fitTo(*data,SumW2Error(kFALSE)); // <-- problem
145     const double upperLimit = plcInterval->UpperLimit(*sig_yield); // <-- to simplify
146     // Make a plot of the profile-likelihood and confidence interval
147     LikelihoodIntervalPlot plot(plcInterval);
148     plot.Draw();
149    
150     std::cout << "One sided upper limit at 95% CL: "<< upperLimit << std::endl;
151     return;
152     */
153     RooStats::FeldmanCousins fc(*data,modelConfig);
154     fc.AdditionalNToysFactor(10);
155     fc.CreateConfBelt(true);
156     fc.SaveBeltToFile(true);
157     fc.SetTestSize(.05); // set size of test
158     fc.UseAdaptiveSampling(true);
159     fc.FluctuateNumDataEntries(true); // number counting analysis: dataset always has 1 entry with N events observed
160     fc.SetNBins(100); // number of points to test per parameter
161     // use the Feldman-Cousins tool
162     PointSetInterval* interval = (PointSetInterval*)fc.GetInterval();
163     std::cout << "is this point in the interval? " <<
164     interval->IsInInterval(RooArgSet(*sig_yield)) << std::endl;
165     std::cout << "interval is ["<<
166     interval->LowerLimit(*sig_yield) << ", " <<
167     interval->UpperLimit(*sig_yield) << "]" << endl;
168     }
169