``` 1 # Statistics. Computation of 95 % C.L. limits. 2 # This program demonstrates the computation of 95 % C.L. limits. 3 # with correct treatment of statistical errors. 4 # 5 # Theory: Signal hypothesis is excluded at the 95% CL if CLs = 0.05 6 # and at more than the 95% CL if CLs < 0.05, assuming that signal is present 7 # 8 # Authors: Christophe.Delaere@cern.ch on 21.08.02 and Sergei Chekanov 9 10 from java.awt import Color,Font 11 from java.util import Random 12 from jhplot import * 13 from jhpro.stat import * 14 15 c1 = HPlot("Canvas",600,400) 16 c1.setGTitle("Computation of 95 % C.L. limits") 17 c1.visible() 18 c1.setRange(-4,4,0.0,120) 19 c1.setNameX("Variable") 20 c1.setNameY("Events") 21 22 23 # set 24 background = H1D("Background",30,-4.0,4.0) 25 background.setColor(Color.green) 26 background.setFill(1) 27 background.setFillColor(Color.green) 28 background.setErrAll(0) 29 30 signal = H1D("Signal",30,-4.0,4.0) 31 signal.setFill(1) 32 signal.setFillColor(Color.red) 33 signal.setColor(Color.red) 34 35 data = H1D("Data",30,-4.0,4.0) 36 data.setColor(Color.black) 37 data.setStyle("p") 38 39 r=Random() 40 for i in range(25000): 41 background.fill(r.nextGaussian(),0.02) 42 signal.fill(1+0.2*r.nextGaussian(),0.001) 43 for i in range(500): 44 data.fill(r.nextGaussian(),1.0) 45 46 sigback=background.oper(signal,"Signal+Background","+") 47 sigback.setErrAll(0) 48 49 c1.draw(signal) 50 c1.draw(background) 51 c1.draw(sigback) 52 c1.draw(data) 53 54 datasource = DataSource(signal, background,data) 55 climit = CLimits(datasource, 100000) 56 confidence = climit.getLimit() 57 print "CLs : " ,confidence.getCLs() 58 print "CLb : " ,confidence.getCLb() 59 print "CLsb : " ,confidence.getCLsb() 60 print "expected : " ,confidence.getExpectedCLs_b() 61 print "expected : " ,confidence.getExpectedCLb_b() 62 print "expected : " ,confidence.getExpectedCLb_b() 63 64 print "Signal hypothesis is excluded at level (%) ", (1-confidence.getCLs())*100. 65 66 # export to some image (png,eps,pdf,jpeg...) 67 # c1.export(Editor.DocMasterName()+".png"); 68 # edit the image 69 # IEditor(Editor.DocMasterName()+".png"); ### © jHepWork. S.Chekanov ### ```