 |
Computation of 95 % C.L. limits with stat. errors
Source code name: "stat_limits_exclusion_lnq.py"
Programming language: Python
Topic: Statistics/Limits
DMelt Version 1. Last modified: 05/09/2015. License: Pro
https://datamelt.org/code/cache/stat_limits_exclusion_lnq_1914.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
# This program demonstrates the computation of 95 % C.L. limits.
# Statistical errors are included in the treatment.
#
# Signal hypothesis is excluded at the 95% CL if CLs = 0.05
# and at more than the 95% CL if CLs < 0.05, assuming that signal is present
#
# Authors: Christophe.Delaere@cern.ch on 21.08.02 and Sergei Chekanov
from java.awt import Color,Font
from java.util import Random
from jhplot import *
from jhpro.stat import *
c1 = HPlot("Canvas",500,600,1,2)
c1.setGTitle("Computation of 95 % C.L. limits")
c1.visible()
c1.setRange(-4,4,0.0,120)
c1.setNameX("Variable")
c1.setNameY("Events")
# set
background = H1D("Background",30,-4.0,4.0)
background.setColor(Color.green)
background.setFill(1)
background.setFillColor(Color.green)
background.setErrAll(0)
signal = H1D("Signal",30,-4.0,4.0)
signal.setFill(1)
signal.setFillColor(Color.red)
signal.setColor(Color.red)
data = H1D("Data",30,-4.0,4.0)
data.setColor(Color.black)
data.setStyle("p")
r=Random()
for i in range(25000):
background.fill(r.nextGaussian(),0.02)
signal.fill(1+0.2*r.nextGaussian(),0.001)
for i in range(500):
data.fill(r.nextGaussian(),1.0)
sigback=background.oper(signal,"Signal+Background","+")
sigback.setErrAll(0)
c1.cd(1,1)
c1.draw(signal)
c1.draw(background)
c1.draw(sigback)
c1.draw(data)
print "Calculating .."
datasource = DataSource(signal, background,data)
climit = CLimits(datasource, 100000)
confidence = climit.getLimit()
print "CLs : " ,confidence.getCLs()
print "CLb : " ,confidence.getCLb()
print "CLsb : " ,confidence.getCLsb()
print "expected : " ,confidence.getExpectedCLs_b()
print "expected : " ,confidence.getExpectedCLb_b()
print "expected : " ,confidence.getExpectedCLb_b()
print "--> Signal hypothesis is excluded at level (%) ", (1-confidence.getCLs())*100.
c1.cd(1,2)
c1.setAutoRange()
c1.setNameX("-lnQ")
c1.setNameY("Events")
hb=confidence.getLNQb(50,-40,40)
hb.setColor(Color.red)
hsb=confidence.getLNQsb(50,-40,40)
c1.draw(hb)
c1.draw(hsb)
# export to some image (png,eps,pdf,jpeg...)
# c1.export(Editor.DocMasterName()+".png");
# edit the image
# IEditor(Editor.DocMasterName()+".png");
You see the box below because you did not login.