``` 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 # 1-CLb gives a probability that a background-only fluctuates and gives 6 # expected signal. If you will see 0 value - increase the number of MC simu 7 8 # for 5-sigma discovery, 1-CLb should be less then 2.87*10-7 9 # for 3-sigma discovery, 1-CLb should be less then 1.3 *10-3 10 11 # Authors: Christophe.Delaere@cern.ch (C++ example) and Sergei Chekanov (Java) 12 13 from java.awt import Color,Font 14 from java.util import Random 15 from jhplot import * 16 from jhpro.stat import * 17 18 c1 = HPlot("Canvas",600,400) 19 c1.setGTitle("Prob of background fluctuation") 20 c1.visible() 21 c1.setRange(-4,4,0.0,300) 22 c1.setNameX("Variable") 23 c1.setNameY("Events") 24 25 26 # set 27 background = H1D("Background",30,-4.0,4.0) 28 background.setColor(Color.green) 29 background.setFill(1) 30 background.setFillColor(Color.green) 31 background.setErrAll(0) 32 33 signal = H1D("Signal",30,-4.0,4.0) 34 signal.setFill(1) 35 signal.setFillColor(Color.red) 36 signal.setColor(Color.red) 37 38 data = H1D("Data",30,-4.0,4.0) 39 data.setColor(Color.black) 40 data.setStyle("p") 41 42 r=Random() 43 for i in range(1000): 44 background.fill(r.nextGaussian(),1.0) 45 data.fill(r.nextGaussian(),1.0) 46 47 for i in range(200): 48 signal.fill(1+0.2*r.nextGaussian(),1.0) 49 50 for i in range(70): 51 data.fill(1+0.2*r.nextGaussian(),1.0) 52 53 sigback=background.oper(signal,"Signal+Background","+") 54 sigback.setErrAll(0) 55 56 c1.draw(signal) 57 c1.draw(background) 58 c1.draw(sigback) 59 c1.draw(data) 60 61 62 print "Wait .. Calculating .." 63 datasource = DataSource(signal, background,data) 64 climit = CLimits(datasource,100000) 65 confidence = climit.getLimit() 66 print "CLs : " ,confidence.getCLs() 67 print "CLb : " ,confidence.getCLb() 68 print "CLsb : " ,confidence.getCLsb() 69 print "expected : " ,confidence.getExpectedCLs_b() 70 print "expected : " ,confidence.getExpectedCLb_b() 71 print "expected : " ,confidence.getExpectedCLb_b() 72 # probability that background only fluctuates to this peak is 73 print "Prob for background fluctuation", 1-confidence.getCLb() 74 75 76 # export to some image (png,eps,pdf,jpeg...) 77 # c1.export(Editor.DocMasterName()+".eps"); ### © jHepWork. S.Chekanov ### ```