Logo ROOT  
Reference Guide
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
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
15/// NOTE: This script requires a data file `$ROOTSYS/tutorials/splot/TestSPlot_toyMC.dat`.
17/// \notebook -js
18/// \macro_image
19/// \macro_output
20/// \macro_code
22/// \authors Anna Kreshuk, Muriel Pivc
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"
34void TestSPlot()
36 TString dir = gSystem->UnixPathName(__FILE__);
37 dir.ReplaceAll("TestSPlot.C","");
38 dir.ReplaceAll("/./","/");
39 TString dataFile = Form("%sTestSPlot_toyMC.dat",dir.Data());
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",' ');
46 TSPlot *splot = new TSPlot(0, 3, 5420, 2, datatree);
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");
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;
64 //Compute the weights
65 splot->MakeSPlot();
67 //Fill the sPlots
68 splot->FillSWeightsHists(25);
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.
83 TCanvas *myc = new TCanvas("myc",
84 "sPlots of Mes and F signal and background", 800, 600);
85 myc->SetFillColor(40);
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();
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();
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);
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);
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);
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();
int Int_t
Definition: RtypesCore.h:45
const Bool_t kFALSE
Definition: RtypesCore.h:92
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels.
Definition: TAttAxis.cxx:203
virtual void SetLabelOffset(Float_t offset=0.005)
Set distance between the axis and the labels.
Definition: TAttAxis.cxx:192
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:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition: TCanvas.cxx:708
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:618
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
Definition: TH1.cxx:6678
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:320
TAxis * GetYaxis()
Definition: TH1.h:321
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3073
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8830
The most important graphics class in the ROOT system.
Definition: TPad.h:26
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
Definition: TPad.h:327
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition: TPad.cxx:603
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1299
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:183
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:234
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:698
TH1D * GetSWeightsHist(Int_t ixvar, Int_t ispecies, Int_t iyexcl=-1)
Returns the histogram of a variable, weighted with sWeights.
Definition: TSPlot.cxx:832
void MakeSPlot(Option_t *option="v")
Calculates the sWeights.
Definition: TSPlot.cxx:404
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:868
void SetInitialNumbersOfSpecies(Int_t *numbers)
Set the initial number of events of each species - used as initial estimates in minuit.
Definition: TSPlot.cxx:388
Basic string class.
Definition: TString.h:136
const char * Data() const
Definition: TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition: TSystem.cxx:1061
Base class for several text objects.
Definition: TText.h:22
A TTree represents a columnar dataset.
Definition: TTree.h:79
virtual Long64_t ReadFile(const char *filename, const char *branchDescriptor="", char delimiter=' ')
Create or simply read branches from filename.
Definition: TTree.cxx:7528
TPaveText * pt