``` 1 # Statistics. Computation of 95 % C.L. limits using stat. and systematical errors. 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: 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 16 # just convinient print 17 def printCL(mess,confidence ): 18 print "\n------- "+mess+" -----------" 19 print "CLs : " ,confidence.getCLs() 20 print "CLb : " ,confidence.getCLb() 21 print "CLsb : " ,confidence.getCLsb() 22 print "expected : " ,confidence.getExpectedCLs_b() 23 print "expected : " ,confidence.getExpectedCLb_b() 24 print "expected : " ,confidence.getExpectedCLb_b() 25 print "--> Signal hypothesis is excluded at level (%) ", (1-confidence.getCLs())*100. 26 27 28 c1 = HPlot("Canvas") 29 c1.setRange(-4,4,0.0,110) 30 c1.visible() 31 # c1.setAutoRange() 32 c1.setGTitle("Computation of 95 % C.L. limits") 33 c1.setNameX("Variable") 34 c1.setNameY("Events") 35 36 37 # set 38 background = H1D("Background",30,-4.0,4.0) 39 background.setColor(Color.green) 40 background.setFill(1) 41 background.setFillColor(Color.green) 42 background.setErrAll(0) 43 44 signal = H1D("Signal",30,-4.0,4.0) 45 signal.setFill(1) 46 signal.setFillColor(Color.red) 47 signal.setColor(Color.red) 48 49 data = H1D("Data",30,-4.0,4.0) 50 data.setColor(Color.black) 51 data.setStyle("p") 52 53 r=Random() 54 for i in range(25000): 55 background.fill(r.nextGaussian(),0.02) 56 signal.fill(1+0.2*r.nextGaussian(),0.001) 57 for i in range(500): 58 data.fill(r.nextGaussian(),1.0) 59 60 sigback=background.oper(signal,"Signal+Background","+") 61 sigback.setErrAll(0) 62 63 c1.cd(1,1) 64 c1.draw(signal) 65 c1.draw(background) 66 c1.draw(sigback) 67 c1.draw(data) 68 69 # assume first that we do not have any systematics, only statistical uncertanties 70 print "Wait.." 71 d=DataSource() 72 d.addChannel(signal,background,data) 73 climit=CLimits(d, 100000) 74 printCL("No systematics", climit.getLimit()) 75 76 77 # assume data source has +/-2% systematics 78 print "Wait.." 79 d=DataSource() 80 d.addChannel(signal,background,data,0,0,0.02,"source") 81 d.addChannel(signal,background,data,0,0,-0.02,"source") 82 climit=CLimits(d, 100000) 83 printCL("Data with +/-5% systematics", climit.getLimit()) 84 85 # assume data source has +/-2% systematics and background has 5% systematics 86 print "Wait.." 87 d=DataSource() 88 d.addChannel(signal,background,data,0,0.05,0.02,"source") 89 d.addChannel(signal,background,data,0,-0.05,-0.02,"source") 90 climit=CLimits(d, 100000) 91 printCL("Data with +/-5% and background with +/-4% systematics", climit.getLimit()) 92 93 94 95 # export to some image (png,eps,pdf,jpeg...) 96 # c1.export(Editor.DocMasterName()+".png"); 97 # edit the image 98 # IEditor(Editor.DocMasterName()+".png"); ### © jHepWork. S.Chekanov ### ```