Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/// \macro_image
18/// \macro_output
19/// \macro_code
20///
21/// \authors Anna Kreshuk, Muriel Pivc
22
23#include "TSPlot.h"
24#include "TTree.h"
25#include "TH1.h"
26#include "TCanvas.h"
27#include "TFile.h"
28#include "TPaveLabel.h"
29#include "TPad.h"
30#include "TPaveText.h"
31
32#include <iostream>
33
34void TestSPlot()
35{
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(
44 dataFile, "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("Mes:dE:F:MesSignal:dESignal:FSignal:MesBackground:"
55 "dEBackground:FBackground");
56
57 // Set the initial estimates of the number of events in each species
58 //- used as initial parameter values for the Minuit likelihood fit
59 Int_t ne[2];
60 ne[0] = 500;
61 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", "sPlots of Mes and F signal and background", 800, 600);
84 myc->SetFillColor(40);
85
86 TPaveText *pt = new TPaveText(0.02, 0.85, 0.98, 0.98);
87 pt->SetFillColor(18);
88 pt->SetTextFont(20);
89 pt->SetTextColor(4);
90 pt->AddText("sPlots of Mes and F signal and background,");
91 pt->AddText("obtained by the tutorial TestSPlot.C on BABAR MC "
92 "data (sPlot_toyMC.fit)");
93 TText *t3 = pt->AddText("M. Pivk and F. R. Le Diberder, Nucl.Inst.Meth.A, physics/0402083");
94 t3->SetTextColor(1);
95 t3->SetTextFont(30);
96 pt->Draw();
97
98 TPad *pad1 = new TPad("pad1", "Mes signal", 0.02, 0.43, 0.48, 0.83, 33);
99 TPad *pad2 = new TPad("pad2", "Mes background", 0.5, 0.43, 0.98, 0.83, 33);
100 TPad *pad3 = new TPad("pad3", "F signal", 0.02, 0.02, 0.48, 0.41, 33);
101 TPad *pad4 = new TPad("pad4", "F background", 0.5, 0.02, 0.98, 0.41, 33);
102 pad1->Draw();
103 pad2->Draw();
104 pad3->Draw();
105 pad4->Draw();
106
107 pad1->cd();
108 pad1->SetGrid();
109 TH1D *sweight00 = splot->GetSWeightsHist(-1, 0, 0);
110 sweight00->SetTitle("Mes signal");
111 sweight00->SetStats(kFALSE);
112 sweight00->Draw("e");
113 sweight00->SetMarkerStyle(21);
114 sweight00->SetMarkerSize(0.7);
115 sweight00->SetMarkerColor(2);
116 sweight00->SetLineColor(2);
117 sweight00->GetXaxis()->SetLabelSize(0.05);
118 sweight00->GetYaxis()->SetLabelSize(0.06);
119 sweight00->GetXaxis()->SetLabelOffset(0.02);
120
121 pad2->cd();
122 pad2->SetGrid();
123 TH1D *sweight10 = splot->GetSWeightsHist(-1, 1, 0);
124 sweight10->SetTitle("Mes background");
125 sweight10->SetStats(kFALSE);
126 sweight10->Draw("e");
127 sweight10->SetMarkerStyle(21);
128 sweight10->SetMarkerSize(0.7);
129 sweight10->SetMarkerColor(2);
130 sweight10->SetLineColor(2);
131 sweight10->GetXaxis()->SetLabelSize(0.05);
132 sweight10->GetYaxis()->SetLabelSize(0.06);
133 sweight10->GetXaxis()->SetLabelOffset(0.02);
134
135 pad3->cd();
136 pad3->SetGrid();
137 TH1D *sweight02 = splot->GetSWeightsHist(-1, 0, 2);
138 sweight02->SetTitle("F signal");
139 sweight02->SetStats(kFALSE);
140 sweight02->Draw("e");
141 sweight02->SetMarkerStyle(21);
142 sweight02->SetMarkerSize(0.7);
143 sweight02->SetMarkerColor(2);
144 sweight02->SetLineColor(2);
145 sweight02->GetXaxis()->SetLabelSize(0.06);
146 sweight02->GetYaxis()->SetLabelSize(0.06);
147 sweight02->GetXaxis()->SetLabelOffset(0.01);
148
149 pad4->cd();
150 pad4->SetGrid();
151 TH1D *sweight12 = splot->GetSWeightsHist(-1, 1, 2);
152 sweight12->SetTitle("F background");
153 sweight12->SetStats(kFALSE);
154 sweight12->Draw("e");
155 sweight12->SetMarkerStyle(21);
156 sweight12->SetMarkerSize(0.7);
157 sweight12->SetMarkerColor(2);
158 sweight12->SetLineColor(2);
159 sweight12->GetXaxis()->SetLabelSize(0.06);
160 sweight12->GetYaxis()->SetLabelSize(0.06);
161 sweight02->GetXaxis()->SetLabelOffset(0.01);
162 myc->cd();
163}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:50
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:52
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:926
The most important graphics class in the ROOT system.
Definition TPad.h:28
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.
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
<div class="legacybox"><h2>Legacy Code</h2> TSPlot is a legacy interface: there will be no bug fixes ...
Definition TSPlot.h:21
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:714
virtual const char * UnixPathName(const char *unixpathname)
Convert from a local pathname to a Unix pathname.
Definition TSystem.cxx:1077
Base class for several text objects.
Definition TText.h:22
A TTree represents a columnar dataset.
Definition TTree.h:89
TPaveText * pt