Logo ROOT   6.14/05
Reference Guide
TestSPlot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_splot
3 /// This tutorial illustrates the use of class TSPlot and of the sPlots method
4 ///
5 /// It is an example of analysis of charmless B decays, performed for BABAR.
6 /// One is dealing with a data sample in which two species are present:
7 /// the first is termed signal and the second background.
8 /// A maximum Likelihood fit is performed to obtain the two yields N1 and N2
9 /// The fit relies on two discriminating variables collectively denoted y,
10 /// which are chosen within three possible variables denoted Mes, dE and F.
11 /// The variable which is not incorporated in y, is used as the control variable x.
12 /// The distributions of discriminating variables and more details about the method
13 /// can be found in the TSPlot class description
14 ///
15 /// NOTE: This script requires a data file `$ROOTSYS/tutorials/splot/TestSPlot_toyMC.dat`.
16 ///
17 /// \notebook -js
18 /// \macro_image
19 /// \macro_output
20 /// \macro_code
21 ///
22 /// \authors Anna Kreshuk, Muriel Pivc
23 
24 #include "TSPlot.h"
25 #include "TTree.h"
26 #include "TH1.h"
27 #include "TCanvas.h"
28 #include "TFile.h"
29 #include "TPaveLabel.h"
30 #include "TPad.h"
31 #include "TPaveText.h"
32 #include "Riostream.h"
33 
34 void TestSPlot()
35 {
36  TString dir = gSystem->UnixPathName(__FILE__);
37  dir.ReplaceAll("TestSPlot.C","");
38  dir.ReplaceAll("/./","/");
39  TString dataFile = Form("%sTestSPlot_toyMC.dat",dir.Data());
40 
41  //Read the data and initialize a TSPlot object
42  TTree *datatree = new TTree("datatree", "datatree");
43  datatree->ReadFile(dataFile,
44  "Mes/D:dE/D:F/D:MesSignal/D:MesBackground/D:dESignal/D:dEBackground/D:FSignal/D:FBackground/D",' ');
45 
46  TSPlot *splot = new TSPlot(0, 3, 5420, 2, datatree);
47 
48  //Set the selection for data tree
49  //Note the order of the variables:
50  //first the control variables (not presented in this example),
51  //then the 3 discriminating variables, then their probability distribution
52  //functions for the first species(signal) and then their pdfs for the
53  //second species(background)
54  splot->SetTreeSelection(
55  "Mes:dE:F:MesSignal:dESignal:FSignal:MesBackground:"
56  "dEBackground:FBackground");
57 
58  //Set the initial estimates of the number of events in each species
59  //- used as initial parameter values for the Minuit likelihood fit
60  Int_t ne[2];
61  ne[0]=500; ne[1]=5000;
62  splot->SetInitialNumbersOfSpecies(ne);
63 
64  //Compute the weights
65  splot->MakeSPlot();
66 
67  //Fill the sPlots
68  splot->FillSWeightsHists(25);
69 
70  //Now let's look at the sPlots
71  //The first two histograms are sPlots for the Mes variable signal and
72  //background. dE and F were chosen as discriminating variables to determine
73  //N1 and N2, through a maximum Likelihood fit, and thus the sPlots for the
74  //control variable Mes, unknown to the fit, was constructed.
75  //One can see that the sPlot for signal reproduces the PDF correctly,
76  //even when the latter vanishes.
77  //
78  //The lower two histograms are sPlots for the F variables signal and
79  //background. dE and Mes were chosen as discriminating variables to
80  //determine N1 and N2, through a maximum Likelihood fit, and thus the
81  //sPlots for the control variable F, unknown to the fit, was constructed.
82 
83  TCanvas *myc = new TCanvas("myc",
84  "sPlots of Mes and F signal and background", 800, 600);
85  myc->SetFillColor(40);
86 
87  TPaveText *pt = new TPaveText(0.02,0.85,0.98,0.98);
88  pt->SetFillColor(18);
89  pt->SetTextFont(20);
90  pt->SetTextColor(4);
91  pt->AddText("sPlots of Mes and F signal and background,");
92  pt->AddText("obtained by the tutorial TestSPlot.C on BABAR MC "
93  "data (sPlot_toyMC.fit)");
94  TText *t3=pt->AddText(
95  "M. Pivk and F. R. Le Diberder, Nucl.Inst.Meth.A, physics/0402083");
96  t3->SetTextColor(1);
97  t3->SetTextFont(30);
98  pt->Draw();
99 
100  TPad* pad1 = new TPad("pad1","Mes signal",0.02,0.43,0.48,0.83,33);
101  TPad* pad2 = new TPad("pad2","Mes background",0.5,0.43,0.98,0.83,33);
102  TPad* pad3 = new TPad("pad3", "F signal", 0.02, 0.02, 0.48, 0.41,33);
103  TPad* pad4 = new TPad("pad4", "F background", 0.5, 0.02, 0.98, 0.41,33);
104  pad1->Draw();
105  pad2->Draw();
106  pad3->Draw();
107  pad4->Draw();
108 
109  pad1->cd();
110  pad1->SetGrid();
111  TH1D *sweight00 = splot->GetSWeightsHist(-1, 0, 0);
112  sweight00->SetTitle("Mes signal");
113  sweight00->SetStats(kFALSE);
114  sweight00->Draw("e");
115  sweight00->SetMarkerStyle(21);
116  sweight00->SetMarkerSize(0.7);
117  sweight00->SetMarkerColor(2);
118  sweight00->SetLineColor(2);
119  sweight00->GetXaxis()->SetLabelSize(0.05);
120  sweight00->GetYaxis()->SetLabelSize(0.06);
121  sweight00->GetXaxis()->SetLabelOffset(0.02);
122 
123  pad2->cd();
124  pad2->SetGrid();
125  TH1D *sweight10 = splot->GetSWeightsHist(-1, 1, 0);
126  sweight10->SetTitle("Mes background");
127  sweight10->SetStats(kFALSE);
128  sweight10->Draw("e");
129  sweight10->SetMarkerStyle(21);
130  sweight10->SetMarkerSize(0.7);
131  sweight10->SetMarkerColor(2);
132  sweight10->SetLineColor(2);
133  sweight10->GetXaxis()->SetLabelSize(0.05);
134  sweight10->GetYaxis()->SetLabelSize(0.06);
135  sweight10->GetXaxis()->SetLabelOffset(0.02);
136 
137  pad3->cd();
138  pad3->SetGrid();
139  TH1D *sweight02 = splot->GetSWeightsHist(-1, 0, 2);
140  sweight02->SetTitle("F signal");
141  sweight02->SetStats(kFALSE);
142  sweight02->Draw("e");
143  sweight02->SetMarkerStyle(21);
144  sweight02->SetMarkerSize(0.7);
145  sweight02->SetMarkerColor(2);
146  sweight02->SetLineColor(2);
147  sweight02->GetXaxis()->SetLabelSize(0.06);
148  sweight02->GetYaxis()->SetLabelSize(0.06);
149  sweight02->GetXaxis()->SetLabelOffset(0.01);
150 
151  pad4->cd();
152  pad4->SetGrid();
153  TH1D *sweight12 = splot->GetSWeightsHist(-1, 1, 2);
154  sweight12->SetTitle("F background");
155  sweight12->SetStats(kFALSE);
156  sweight12->Draw("e");
157  sweight12->SetMarkerStyle(21);
158  sweight12->SetMarkerSize(0.7);
159  sweight12->SetMarkerColor(2);
160  sweight12->SetLineColor(2);
161  sweight12->GetXaxis()->SetLabelSize(0.06);
162  sweight12->GetYaxis()->SetLabelSize(0.06);
163  sweight02->GetXaxis()->SetLabelOffset(0.01);
164  myc->cd();
165 }
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:233
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:687
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
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:182
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
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:193
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1044
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:327
Definition: TSPlot.h:21
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
Base class for several text objects.
Definition: TText.h:23
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1281
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
TPaveText * pt
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
The most important graphics class in the ROOT system.
Definition: TPad.h:29
char * Form(const char *fmt,...)
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
TAxis * GetYaxis()
Definition: TH1.h:316
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:610
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:204
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
The Canvas class.
Definition: TCanvas.h:31
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
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)
Set the text color.
Definition: TAttText.h:43
A TTree object has a header with a name and a title.
Definition: TTree.h:70
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6192
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8284
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()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:315
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
const char * Data() const
Definition: TString.h:364