Logo ROOT  
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
34void 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;
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}
int Int_t
Definition: RtypesCore.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:90
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:556
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition: TAttAxis.cxx:204
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition: TAttAxis.cxx:193
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition: TAttMarker.h:41
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
The Canvas class.
Definition: TCanvas.h:27
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:701
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:614
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6345
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:316
TAxis * GetYaxis()
Definition: TH1.h:317
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8446
The most important graphics class in the ROOT system.
Definition: TPad.h:29
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1284
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:330
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:593
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
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
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:233
A common method used in High Energy Physics to perform measurements is the maximum Likelihood method,...
Definition: TSPlot.h:21
void FillSWeightsHists(Int_t nbins=50)
The order of histograms in the array:
Definition: TSPlot.cxx:697
TH1D * GetSWeightsHist(Int_t ixvar, Int_t ispecies, Int_t iyexcl=-1)
Returns the histogram of a variable, weighted with sWeights.
Definition: TSPlot.cxx:831
void MakeSPlot(Option_t *option="v")
Calculates the sWeights.
Definition: TSPlot.cxx:403
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:867
void SetInitialNumbersOfSpecies(Int_t *numbers)
Set the initial number of events of each species - used as initial estimates in minuit.
Definition: TSPlot.cxx:387
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition: TSystem.cxx:1058
Base class for several text objects.
Definition: TText.h:23
A TTree represents a columnar dataset.
Definition: TTree.h:78
virtual Long64_t ReadFile(const char *filename, const char *branchDescriptor="", char delimiter=' ')
Create or simply read branches from filename.
Definition: TTree.cxx:7467
TPaveText * pt