ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TestSPlot.C
Go to the documentation of this file.
1 #include "TSPlot.h"
2 #include "TTree.h"
3 #include "TH1.h"
4 #include "TCanvas.h"
5 #include "TFile.h"
6 #include "TPaveLabel.h"
7 #include "TPad.h"
8 #include "TPaveText.h"
9 #include "Riostream.h"
10 
11 void TestSPlot()
12 {
13 //This tutorial illustrates the use of class TSPlot and of the sPlots method
14 //
15 //It is an example of analysis of charmless B decays, performed for BABAR.
16 //One is dealing with a data sample in which two species are present:
17 //the first is termed signal and the second background.
18 //A maximum Likelihood fit is performed to obtain the two yields N1 and N2
19 //The fit relies on two discriminating variables collectively denoted y,
20 //which are chosen within three possible variables denoted Mes, dE and F.
21 //The variable which is not incorporated in y, is used as the control variable x.
22 //The distributions of discriminating variables and more details about the method
23 //can be found in the TSPlot class description
24 //
25 // NOTE: This script requires a data file "TestSPlot_toyMC.dat".
26 // This data file is not distributed in the standard ROOT binary tar file.
27 // You can download it from ftp://root.cern.ch/root/TestSPlot_toyMC.dat
28 //
29 //Authors: Anna Kreshuk, Muriel Pivc
30 
31  TString dir = gSystem->UnixPathName(__FILE__);
32  dir.ReplaceAll("TestSPlot.C","");
33  dir.ReplaceAll("/./","/");
34  TString dataFile = Form("%sTestSPlot_toyMC.dat",dir.Data());
35 
36  //Read the data and initialize a TSPlot object
37  TTree *datatree = new TTree("datatree", "datatree");
38  datatree->ReadFile(dataFile,
39  "Mes/D:dE/D:F/D:MesSignal/D:MesBackground/D:dESignal/D:dEBackground/D:FSignal/D:FBackground/D",' ');
40 
41  TSPlot *splot = new TSPlot(0, 3, 5420, 2, datatree);
42 
43  //Set the selection for data tree
44  //Note the order of the variables:
45  //first the control variables (not presented in this example),
46  //then the 3 discriminating variables, then their probability distribution
47  //functions for the first species(signal) and then their pdfs for the
48  //second species(background)
49  splot->SetTreeSelection(
50  "Mes:dE:F:MesSignal:dESignal:FSignal:MesBackground:"
51  "dEBackground:FBackground");
52 
53  //Set the initial estimates of the number of events in each species
54  //- used as initial parameter values for the Minuit likelihood fit
55  Int_t ne[2];
56  ne[0]=500; ne[1]=5000;
57  splot->SetInitialNumbersOfSpecies(ne);
58 
59  //Compute the weights
60  splot->MakeSPlot();
61 
62  //Fill the sPlots
63  splot->FillSWeightsHists(25);
64 
65  //Now let's look at the sPlots
66  //The first two histograms are sPlots for the Mes variable signal and
67  //background. dE and F were chosen as discriminating variables to determine
68  //N1 and N2, through a maximum Likelihood fit, and thus the sPlots for the
69  //control variable Mes, unknown to the fit, was contructed.
70  //One can see that the sPlot for signal reproduces the PDF correctly,
71  //even when the latter vanishes.
72  //
73  //The lower two histograms are sPlots for the F variables signal and
74  //background. dE and Mes were chosen as discriminating variables to
75  //determine N1 and N2, through a maximum Likelihood fit, and thus the
76  //sPlots for the control variable F, unknown to the fit, was contructed.
77 
78  TCanvas *myc = new TCanvas("myc",
79  "sPlots of Mes and F signal and background", 800, 600);
80  myc->SetFillColor(40);
81 
82  TPaveText *pt = new TPaveText(0.02,0.85,0.98,0.98);
83  pt->SetFillColor(18);
84  pt->SetTextFont(20);
85  pt->SetTextColor(4);
86  pt->AddText("sPlots of Mes and F signal and background,");
87  pt->AddText("obtained by the tutorial TestSPlot.C on BABAR MC "
88  "data (sPlot_toyMC.fit)");
89  TText *t3=pt->AddText(
90  "M. Pivk and F. R. Le Diberder, Nucl.Inst.Meth.A, physics/0402083");
91  t3->SetTextColor(1);
92  t3->SetTextFont(30);
93  pt->Draw();
94 
95  TPad* pad1 = new TPad("pad1","Mes signal",0.02,0.43,0.48,0.83,33);
96  TPad* pad2 = new TPad("pad2","Mes background",0.5,0.43,0.98,0.83,33);
97  TPad* pad3 = new TPad("pad3", "F signal", 0.02, 0.02, 0.48, 0.41,33);
98  TPad* pad4 = new TPad("pad4", "F background", 0.5, 0.02, 0.98, 0.41,33);
99  pad1->Draw();
100  pad2->Draw();
101  pad3->Draw();
102  pad4->Draw();
103 
104  pad1->cd();
105  pad1->SetGrid();
106  TH1D *sweight00 = splot->GetSWeightsHist(-1, 0, 0);
107  sweight00->SetTitle("Mes signal");
108  sweight00->SetStats(kFALSE);
109  sweight00->Draw("e");
110  sweight00->SetMarkerStyle(21);
111  sweight00->SetMarkerSize(0.7);
112  sweight00->SetMarkerColor(2);
113  sweight00->SetLineColor(2);
114  sweight00->GetXaxis()->SetLabelSize(0.05);
115  sweight00->GetYaxis()->SetLabelSize(0.06);
116  sweight00->GetXaxis()->SetLabelOffset(0.02);
117 
118  pad2->cd();
119  pad2->SetGrid();
120  TH1D *sweight10 = splot->GetSWeightsHist(-1, 1, 0);
121  sweight10->SetTitle("Mes background");
122  sweight10->SetStats(kFALSE);
123  sweight10->Draw("e");
124  sweight10->SetMarkerStyle(21);
125  sweight10->SetMarkerSize(0.7);
126  sweight10->SetMarkerColor(2);
127  sweight10->SetLineColor(2);
128  sweight10->GetXaxis()->SetLabelSize(0.05);
129  sweight10->GetYaxis()->SetLabelSize(0.06);
130  sweight10->GetXaxis()->SetLabelOffset(0.02);
131 
132  pad3->cd();
133  pad3->SetGrid();
134  TH1D *sweight02 = splot->GetSWeightsHist(-1, 0, 2);
135  sweight02->SetTitle("F signal");
136  sweight02->SetStats(kFALSE);
137  sweight02->Draw("e");
138  sweight02->SetMarkerStyle(21);
139  sweight02->SetMarkerSize(0.7);
140  sweight02->SetMarkerColor(2);
141  sweight02->SetLineColor(2);
142  sweight02->GetXaxis()->SetLabelSize(0.06);
143  sweight02->GetYaxis()->SetLabelSize(0.06);
144  sweight02->GetXaxis()->SetLabelOffset(0.01);
145 
146  pad4->cd();
147  pad4->SetGrid();
148  TH1D *sweight12 = splot->GetSWeightsHist(-1, 1, 2);
149  sweight12->SetTitle("F background");
150  sweight12->SetStats(kFALSE);
151  sweight12->Draw("e");
152  sweight12->SetMarkerStyle(21);
153  sweight12->SetMarkerSize(0.7);
154  sweight12->SetMarkerColor(2);
155  sweight12->SetLineColor(2);
156  sweight12->GetXaxis()->SetLabelSize(0.06);
157  sweight12->GetYaxis()->SetLabelSize(0.06);
158  sweight02->GetXaxis()->SetLabelOffset(0.01);
159  myc->cd();
160 }
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:211
void SetInitialNumbersOfSpecies(Int_t *numbers)
Set the initial number of events of each species - used as initial estimates in minuit.
Definition: TSPlot.cxx:527
void MakeSPlot(Option_t *option="v")
Calculates the sWeights The option controls the print level "Q" - no print out "V" - prints the estim...
Definition: TSPlot.cxx:542
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:160
TPad * pad1
Definition: hcons.C:13
TText * t3
Definition: rootenv.C:37
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
TPad * pad3
Definition: hcons.C:13
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels The distance is expressed in per cent of the pad width...
Definition: TAttAxis.cxx:176
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1020
const char * Data() const
Definition: TString.h:349
virtual void SetTextFont(Font_t tfont=62)
Definition: TAttText.h:59
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:326
Definition: TSPlot.h:21
virtual void SetMarkerColor(Color_t mcolor=1)
Definition: TAttMarker.h:51
Base class for several text objects.
Definition: TText.h:42
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
virtual void SetLineColor(Color_t lcolor)
Definition: TAttLine.h:54
tuple pad4
Definition: ntuple1.py:21
TPaveText * pt
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
The most important graphics class in the ROOT system.
Definition: TPad.h:46
char * Form(const char *fmt,...)
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
TAxis * GetYaxis()
Definition: TH1.h:320
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:187
virtual void SetMarkerSize(Size_t msize=1)
Definition: TAttMarker.h:54
void TestSPlot()
Definition: TestSPlot.C:11
The Canvas class.
Definition: TCanvas.h:48
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:35
void dir(char *path=0)
Definition: rootalias.C:30
TPad * pad2
Definition: hcons.C:13
void SetTreeSelection(const char *varexp="", const char *selection="", Long64_t firstentry=0)
Specifies the variables from the tree to be used for splot.
Definition: TSPlot.cxx:1000
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
A TTree object has a header with a name and a title.
Definition: TTree.h:98
virtual void SetTitle(const char *title)
Change (i.e.
Definition: TH1.cxx:6268
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8320
void FillSWeightsHists(Int_t nbins=50)
The order of histograms in the array: x0_species0, x0_species1,..., x1_species0, x1_species1,..., y0_species0, y0_species1,...
Definition: TSPlot.cxx:833
TAxis * GetXaxis()
Definition: TH1.h:319
TH1D * GetSWeightsHist(Int_t ixvar, Int_t ispecies, Int_t iyexcl=-1)
Returns the histogram of a variable, weithed with sWeights If histograms have not been already filled...
Definition: TSPlot.cxx:964