ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
limit.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_math
3 /// This program demonstrates the computation of 95 % C.L. limits.
4 /// It uses a set of randomly created histograms.
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 ///
10 /// \author Christophe Delaere
11 
12 #include <iostream>
13 #include "TH1.h"
14 #include "THStack.h"
15 #include "TCanvas.h"
16 #include "TFrame.h"
17 #include "TRandom2.h"
18 #include "TSystem.h"
19 #include "TVector.h"
20 #include "TObjArray.h"
21 #include "TLimit.h"
22 #include "TLimitDataSource.h"
23 #include "TConfidenceLevel.h"
24 
25 using std::cout;
26 using std::endl;
27 
28 void limit() {
29  // Create a new canvas.
30  TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
31  c1->SetFillColor(42);
32 
33  // Create some histograms
34  TH1D* background = new TH1D("background","The expected background",30,-4,4);
35  TH1D* signal = new TH1D("signal","the expected signal",30,-4,4);
36  TH1D* data = new TH1D("data","some fake data points",30,-4,4);
37  background->SetFillColor(48);
38  signal->SetFillColor(41);
39  data->SetMarkerStyle(21);
40  data->SetMarkerColor(kBlue);
41  background->Sumw2(); // needed for stat uncertainty
42  signal->Sumw2(); // needed for stat uncertainty
43 
44  // Fill histograms randomly
45  TRandom2 r;
46  Float_t bg,sig,dt;
47  for (Int_t i = 0; i < 25000; i++) {
48  bg = r.Gaus(0,1);
49  sig = r.Gaus(1,.2);
50  background->Fill(bg,0.02);
51  signal->Fill(sig,0.001);
52  }
53  for (Int_t i = 0; i < 500; i++) {
54  dt = r.Gaus(0,1);
55  data->Fill(dt);
56  }
57  THStack *hs = new THStack("hs","Signal and background compared to data...");
58  hs->Add(background);
59  hs->Add(signal);
60  hs->Draw("hist");
61  data->Draw("PE1,Same");
62  c1->Modified();
63  c1->Update();
64  c1->GetFrame()->SetFillColor(21);
65  c1->GetFrame()->SetBorderSize(6);
66  c1->GetFrame()->SetBorderMode(-1);
67  c1->Modified();
68  c1->Update();
70 
71  // Compute the limits
72  cout << "Computing limits... " << endl;
73  TLimitDataSource* mydatasource = new TLimitDataSource(signal,background,data);
74  TConfidenceLevel *myconfidence = TLimit::ComputeLimit(mydatasource,50000);
75  cout << "CLs : " << myconfidence->CLs() << endl;
76  cout << "CLsb : " << myconfidence->CLsb() << endl;
77  cout << "CLb : " << myconfidence->CLb() << endl;
78  cout << "< CLs > : " << myconfidence->GetExpectedCLs_b() << endl;
79  cout << "< CLsb > : " << myconfidence->GetExpectedCLsb_b() << endl;
80  cout << "< CLb > : " << myconfidence->GetExpectedCLb_b() << endl;
81 
82  // Add stat uncertainty
83  cout << endl << "Computing limits with stat systematics... " << endl;
84  TConfidenceLevel *mystatconfidence = TLimit::ComputeLimit(mydatasource,50000,true);
85  cout << "CLs : " << mystatconfidence->CLs() << endl;
86  cout << "CLsb : " << mystatconfidence->CLsb() << endl;
87  cout << "CLb : " << mystatconfidence->CLb() << endl;
88  cout << "< CLs > : " << mystatconfidence->GetExpectedCLs_b() << endl;
89  cout << "< CLsb > : " << mystatconfidence->GetExpectedCLsb_b() << endl;
90  cout << "< CLb > : " << mystatconfidence->GetExpectedCLb_b() << endl;
91 
92  // Add some systematics
93  cout << endl << "Computing limits with systematics... " << endl;
94  TVectorD errorb(2);
95  TVectorD errors(2);
96  TObjArray* names = new TObjArray();
97  TObjString name1("bg uncertainty");
98  TObjString name2("sig uncertainty");
99  names->AddLast(&name1);
100  names->AddLast(&name2);
101  errorb[0]=0.05; // error source 1: 5%
102  errorb[1]=0; // error source 2: 0%
103  errors[0]=0; // error source 1: 0%
104  errors[1]=0.01; // error source 2: 1%
105  TLimitDataSource* mynewdatasource = new TLimitDataSource();
106  mynewdatasource->AddChannel(signal,background,data,&errors,&errorb,names);
107  TConfidenceLevel *mynewconfidence = TLimit::ComputeLimit(mynewdatasource,50000,true);
108  cout << "CLs : " << mynewconfidence->CLs() << endl;
109  cout << "CLsb : " << mynewconfidence->CLsb() << endl;
110  cout << "CLb : " << mynewconfidence->CLb() << endl;
111  cout << "< CLs > : " << mynewconfidence->GetExpectedCLs_b() << endl;
112  cout << "< CLsb > : " << mynewconfidence->GetExpectedCLsb_b() << endl;
113  cout << "< CLb > : " << mynewconfidence->GetExpectedCLb_b() << endl;
114 
115  // show canonical -2lnQ plots in a new canvas
116  // - The histogram of -2lnQ for background hypothesis (full)
117  // - The histogram of -2lnQ for signal and background hypothesis (dashed)
118  TCanvas *c2 = new TCanvas("c2");
119  myconfidence->Draw();
120 
121  // clean up (except histograms and canvas)
122  delete myconfidence;
123  delete mydatasource;
124  delete mystatconfidence;
125  delete mynewconfidence;
126  delete mynewdatasource;
127 }
Double_t CLs(bool use_sMC=kFALSE) const
Get the Confidence Level defined by CLs = CLsb/CLb.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
An array of TObjects.
Definition: TObjArray.h:39
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
Double_t GetExpectedCLs_b(Int_t sigma=0) const
The Histogram stack class.
Definition: THStack.h:35
Collectable string class.
Definition: TObjString.h:32
float Float_t
Definition: RtypesCore.h:53
virtual void SetBorderMode(Short_t bordermode)
Definition: TWbox.h:62
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
Definition: TRandom2.h:29
int Int_t
Definition: RtypesCore.h:41
This class serves as interface to feed data into the TLimit routines.
virtual void Draw(Option_t *chopt="")
Draw this multihist with its current attributes.
Definition: THStack.cxx:422
Double_t GetExpectedCLb_b(Int_t sigma=0) const
Get the expected Confidence Level for the background only if there is only background.
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2729
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:63
virtual void AddChannel(TH1 *, TH1 *, TH1 *)
ROOT::R::TRInterface & r
Definition: Object.C:4
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
static TConfidenceLevel * ComputeLimit(TLimitDataSource *data, Int_t nmc=50000, bool stat=false, TRandom *generator=0)
Definition: TLimit.cxx:103
Double_t GetExpectedCLsb_b(Int_t sigma=0) const
Get the expected Confidence Level for the signal plus background hypothesis if there is only backgrou...
Class to compute 95% CL limits.
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
The Canvas class.
Definition: TCanvas.h:48
void Draw(const Option_t *option="")
Display sort of a "canonical" -2lnQ plot.
virtual void Add(TH1 *h, Option_t *option="")
add a new histogram to the list Only 1-d and 2-d histograms currently supported.
Definition: THStack.cxx:336
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8350
virtual void AddLast(TObject *obj)
Add object in the next empty slot in the array.
Definition: TObjArray.cxx:169
std::vector< double > errors
Definition: TwoHistoFit2D.C:33
Definition: Rtypes.h:61
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
Double_t CLsb(bool use_sMC=kFALSE) const
Get the Confidence Level for the signal plus background hypothesis.
void Modified(Bool_t flag=1)
Definition: TPad.h:407
Double_t CLb(bool use_sMC=kFALSE) const
Get the Confidence Level for the background only.