``` 1 # Statistics. Computation of 95 % C.L. limits. 2 # This program demonstrates the computation of 95 % C.L. limits. 3 # Statistical errors are included in the treatment. 4 # 5 # 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",500,600,1,2) 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.cd(1,1) 50 c1.draw(signal) 51 c1.draw(background) 52 c1.draw(sigback) 53 c1.draw(data) 54 55 print "Calculating .." 56 datasource = DataSource(signal, background,data) 57 climit = CLimits(datasource, 100000) 58 confidence = climit.getLimit() 59 print "CLs : " ,confidence.getCLs() 60 print "CLb : " ,confidence.getCLb() 61 print "CLsb : " ,confidence.getCLsb() 62 print "expected : " ,confidence.getExpectedCLs_b() 63 print "expected : " ,confidence.getExpectedCLb_b() 64 print "expected : " ,confidence.getExpectedCLb_b() 65 print "--> Signal hypothesis is excluded at level (%) ", (1-confidence.getCLs())*100. 66 67 68 c1.cd(1,2) 69 c1.setAutoRange() 70 c1.setNameX("-lnQ") 71 c1.setNameY("Events") 72 hb=confidence.getLNQb(50,-40,40) 73 hb.setColor(Color.red) 74 hsb=confidence.getLNQsb(50,-40,40) 75 c1.draw(hb) 76 c1.draw(hsb) 77 78 79 80 81 # export to some image (png,eps,pdf,jpeg...) 82 # c1.export(Editor.DocMasterName()+".png"); 83 # edit the image 84 # IEditor(Editor.DocMasterName()+".png"); ### © jHepWork. S.Chekanov ### ```