{
"cells": [
{
"cell_type": "markdown",
"id": "6648f6aa",
"metadata": {},
"source": [
"# TestSPlot\n",
"\n",
"\n",
"\n",
"**Author:** Anna Kreshuk, Muriel Pivc \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 19, 2024 at 07:19 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1ef2de59",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:54.348007Z",
"iopub.status.busy": "2024-03-19T19:19:54.347619Z",
"iopub.status.idle": "2024-03-19T19:19:55.365980Z",
"shell.execute_reply": "2024-03-19T19:19:55.357118Z"
}
},
"outputs": [],
"source": [
"TString dir = gSystem->UnixPathName(__FILE__);\n",
"dir.ReplaceAll(\"TestSPlot.C\",\"\");\n",
"dir.ReplaceAll(\"/./\",\"/\");\n",
"TString dataFile = Form(\"%sTestSPlot_toyMC.dat\",dir.Data());"
]
},
{
"cell_type": "markdown",
"id": "398c6dbe",
"metadata": {},
"source": [
"Read the data and initialize a TSPlot object"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "efa76561",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:55.389330Z",
"iopub.status.busy": "2024-03-19T19:19:55.388928Z",
"iopub.status.idle": "2024-03-19T19:19:55.760844Z",
"shell.execute_reply": "2024-03-19T19:19:55.759273Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Error in : Cannot open file: input_line_43TestSPlot_toyMC.dat\n"
]
}
],
"source": [
"TTree *datatree = new TTree(\"datatree\", \"datatree\");\n",
"datatree->ReadFile(dataFile,\n",
" \"Mes/D:dE/D:F/D:MesSignal/D:MesBackground/D:dESignal/D:dEBackground/D:FSignal/D:FBackground/D\",' ');\n",
"\n",
"TSPlot *splot = new TSPlot(0, 3, 5420, 2, datatree);"
]
},
{
"cell_type": "markdown",
"id": "497ce5e4",
"metadata": {},
"source": [
"Set the selection for data tree\n",
"Note the order of the variables:\n",
"first the control variables (not presented in this example),\n",
"then the 3 discriminating variables, then their probability distribution\n",
"functions for the first species(signal) and then their pdfs for the\n",
"second species(background)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "8882c610",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:55.765334Z",
"iopub.status.busy": "2024-03-19T19:19:55.764972Z",
"iopub.status.idle": "2024-03-19T19:19:55.980621Z",
"shell.execute_reply": "2024-03-19T19:19:55.978471Z"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Error in : Bad numerical expression : \"Mes\"\n",
"Error in : Bad numerical expression : \"dE\"\n",
"Error in : Bad numerical expression : \"F\"\n",
"Error in : Bad numerical expression : \"MesSignal\"\n",
"Error in : Bad numerical expression : \"dESignal\"\n",
"Error in : Bad numerical expression : \"FSignal\"\n",
"Error in : Bad numerical expression : \"MesBackground\"\n",
"Error in : Bad numerical expression : \"dEBackground\"\n",
"Error in : Bad numerical expression : \"FBackground\"\n"
]
}
],
"source": [
"splot->SetTreeSelection(\n",
" \"Mes:dE:F:MesSignal:dESignal:FSignal:MesBackground:\"\n",
" \"dEBackground:FBackground\");"
]
},
{
"cell_type": "markdown",
"id": "d0cc4a89",
"metadata": {},
"source": [
"Set the initial estimates of the number of events in each species\n",
"- used as initial parameter values for the Minuit likelihood fit"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "60116758",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:55.986872Z",
"iopub.status.busy": "2024-03-19T19:19:55.986470Z",
"iopub.status.idle": "2024-03-19T19:19:56.245651Z",
"shell.execute_reply": "2024-03-19T19:19:56.242945Z"
}
},
"outputs": [],
"source": [
"Int_t ne[2];\n",
"ne[0]=500; ne[1]=5000;\n",
"splot->SetInitialNumbersOfSpecies(ne);"
]
},
{
"cell_type": "markdown",
"id": "14c86972",
"metadata": {},
"source": [
"Compute the weights"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "70c19d58",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:56.263670Z",
"iopub.status.busy": "2024-03-19T19:19:56.263071Z",
"iopub.status.idle": "2024-03-19T19:19:56.531632Z",
"shell.execute_reply": "2024-03-19T19:19:56.530713Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" MINUIT WARNING IN MIGRAD \n",
" ============== Negative diagonal element 1 in Error Matrix\n",
" MINUIT WARNING IN MIGRAD \n",
" ============== Negative diagonal element 2 in Error Matrix\n",
" MINUIT WARNING IN MIGRAD \n",
" ============== 1.96534e+30 added to diagonal of error matrix\n",
" EIGENVALUES OF SECOND-DERIVATIVE MATRIX:\n",
" -9.5016e+40 9.5016e+40\n",
" MINUIT WARNING IN MIGRAD \n",
" ============== MATRIX FORCED POS-DEF BY ADDING 95110922270206366734853414489343240699904.000000 TO DIAGONAL.\n",
" MINUIT WARNING IN MIGRAD \n",
" ============== Negative diagonal element 1 in Error Matrix\n",
" MINUIT WARNING IN MIGRAD \n",
" ============== Negative diagonal element 2 in Error Matrix\n",
" MINUIT WARNING IN MIGRAD \n",
" ============== 2.76366e+70 added to diagonal of error matrix\n",
" EIGENVALUES OF SECOND-DERIVATIVE MATRIX:\n",
" -8.0291e+26 8.0291e+26\n",
" MINUIT WARNING IN MIGRAD \n",
" ============== MATRIX FORCED POS-DEF BY ADDING 803712985474000483866640384.000000 TO DIAGONAL.\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative enters zero, param 1\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
"estimated #of events in species 0 = 1965341412270845971893178400243712.000000\n",
"estimated #of events in species 1 = -4069244383970268134345104882936608575280971124842772064894976.000000\n",
"\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
"estimated #of events in species 0 = 1965341412270845971893178400243712.000000\n",
"estimated #of events in species 1 = -4069244383970268134345104882936608575280971124842772064894976.000000\n",
"\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
"estimated #of events in species 0 = 1965341412270845971893178400243712.000000\n",
"estimated #of events in species 1 = -4069244383970268134345104882936608575280971124842772064894976.000000\n",
"\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
" MINUIT WARNING IN HESSE\n",
" ============== Second derivative zero for parameter1\n",
"estimated #of events in species 0 = 1965341412270845971893178400243712.000000\n",
"estimated #of events in species 1 = -4069244383970268134345104882936608575280971124842772064894976.000000\n",
"\n"
]
}
],
"source": [
"splot->MakeSPlot();"
]
},
{
"cell_type": "markdown",
"id": "9a216618",
"metadata": {},
"source": [
"Fill the sPlots"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8f152c54",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:56.547867Z",
"iopub.status.busy": "2024-03-19T19:19:56.547487Z",
"iopub.status.idle": "2024-03-19T19:19:56.842706Z",
"shell.execute_reply": "2024-03-19T19:19:56.831477Z"
}
},
"outputs": [],
"source": [
"splot->FillSWeightsHists(25);"
]
},
{
"cell_type": "markdown",
"id": "34fd50f4",
"metadata": {},
"source": [
"Now let's look at the sPlots\n",
"The first two histograms are sPlots for the Mes variable signal and\n",
"background. dE and F were chosen as discriminating variables to determine\n",
"N1 and N2, through a maximum Likelihood fit, and thus the sPlots for the\n",
"control variable Mes, unknown to the fit, was constructed.\n",
"One can see that the sPlot for signal reproduces the PDF correctly,\n",
"even when the latter vanishes.\n",
"\n",
"The lower two histograms are sPlots for the F variables signal and\n",
"background. dE and Mes were chosen as discriminating variables to\n",
"determine N1 and N2, through a maximum Likelihood fit, and thus the\n",
"sPlots for the control variable F, unknown to the fit, was constructed."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "846ec2c2",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:56.855969Z",
"iopub.status.busy": "2024-03-19T19:19:56.855577Z",
"iopub.status.idle": "2024-03-19T19:19:57.148517Z",
"shell.execute_reply": "2024-03-19T19:19:57.139684Z"
}
},
"outputs": [],
"source": [
"TCanvas *myc = new TCanvas(\"myc\",\n",
"\"sPlots of Mes and F signal and background\", 800, 600);\n",
"myc->SetFillColor(40);\n",
"\n",
"TPaveText *pt = new TPaveText(0.02,0.85,0.98,0.98);\n",
"pt->SetFillColor(18);\n",
"pt->SetTextFont(20);\n",
"pt->SetTextColor(4);\n",
"pt->AddText(\"sPlots of Mes and F signal and background,\");\n",
"pt->AddText(\"obtained by the tutorial TestSPlot.C on BABAR MC \"\n",
" \"data (sPlot_toyMC.fit)\");\n",
"TText *t3=pt->AddText(\n",
" \"M. Pivk and F. R. Le Diberder, Nucl.Inst.Meth.A, physics/0402083\");\n",
"t3->SetTextColor(1);\n",
"t3->SetTextFont(30);\n",
"pt->Draw();\n",
"\n",
"TPad* pad1 = new TPad(\"pad1\",\"Mes signal\",0.02,0.43,0.48,0.83,33);\n",
"TPad* pad2 = new TPad(\"pad2\",\"Mes background\",0.5,0.43,0.98,0.83,33);\n",
"TPad* pad3 = new TPad(\"pad3\", \"F signal\", 0.02, 0.02, 0.48, 0.41,33);\n",
"TPad* pad4 = new TPad(\"pad4\", \"F background\", 0.5, 0.02, 0.98, 0.41,33);\n",
"pad1->Draw();\n",
"pad2->Draw();\n",
"pad3->Draw();\n",
"pad4->Draw();\n",
"\n",
"pad1->cd();\n",
"pad1->SetGrid();\n",
"TH1D *sweight00 = splot->GetSWeightsHist(-1, 0, 0);\n",
"sweight00->SetTitle(\"Mes signal\");\n",
"sweight00->SetStats(kFALSE);\n",
"sweight00->Draw(\"e\");\n",
"sweight00->SetMarkerStyle(21);\n",
"sweight00->SetMarkerSize(0.7);\n",
"sweight00->SetMarkerColor(2);\n",
"sweight00->SetLineColor(2);\n",
"sweight00->GetXaxis()->SetLabelSize(0.05);\n",
"sweight00->GetYaxis()->SetLabelSize(0.06);\n",
"sweight00->GetXaxis()->SetLabelOffset(0.02);\n",
"\n",
"pad2->cd();\n",
"pad2->SetGrid();\n",
"TH1D *sweight10 = splot->GetSWeightsHist(-1, 1, 0);\n",
"sweight10->SetTitle(\"Mes background\");\n",
"sweight10->SetStats(kFALSE);\n",
"sweight10->Draw(\"e\");\n",
"sweight10->SetMarkerStyle(21);\n",
"sweight10->SetMarkerSize(0.7);\n",
"sweight10->SetMarkerColor(2);\n",
"sweight10->SetLineColor(2);\n",
"sweight10->GetXaxis()->SetLabelSize(0.05);\n",
"sweight10->GetYaxis()->SetLabelSize(0.06);\n",
"sweight10->GetXaxis()->SetLabelOffset(0.02);\n",
"\n",
"pad3->cd();\n",
"pad3->SetGrid();\n",
"TH1D *sweight02 = splot->GetSWeightsHist(-1, 0, 2);\n",
"sweight02->SetTitle(\"F signal\");\n",
"sweight02->SetStats(kFALSE);\n",
"sweight02->Draw(\"e\");\n",
"sweight02->SetMarkerStyle(21);\n",
"sweight02->SetMarkerSize(0.7);\n",
"sweight02->SetMarkerColor(2);\n",
"sweight02->SetLineColor(2);\n",
"sweight02->GetXaxis()->SetLabelSize(0.06);\n",
"sweight02->GetYaxis()->SetLabelSize(0.06);\n",
"sweight02->GetXaxis()->SetLabelOffset(0.01);\n",
"\n",
"pad4->cd();\n",
"pad4->SetGrid();\n",
"TH1D *sweight12 = splot->GetSWeightsHist(-1, 1, 2);\n",
"sweight12->SetTitle(\"F background\");\n",
"sweight12->SetStats(kFALSE);\n",
"sweight12->Draw(\"e\");\n",
"sweight12->SetMarkerStyle(21);\n",
"sweight12->SetMarkerSize(0.7);\n",
"sweight12->SetMarkerColor(2);\n",
"sweight12->SetLineColor(2);\n",
"sweight12->GetXaxis()->SetLabelSize(0.06);\n",
"sweight12->GetYaxis()->SetLabelSize(0.06);\n",
"sweight02->GetXaxis()->SetLabelOffset(0.01);\n",
"myc->cd();"
]
},
{
"cell_type": "markdown",
"id": "8c1dffbd",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "295c9e89",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2024-03-19T19:19:57.182110Z",
"iopub.status.busy": "2024-03-19T19:19:57.181719Z",
"iopub.status.idle": "2024-03-19T19:19:57.773489Z",
"shell.execute_reply": "2024-03-19T19:19:57.772486Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Error in : illegal world coordinates range: x1=1250000018626452571502436941824.000000, y1=-0.131250, x2=-1250000018626452571502436941824.000000, y2=1.181250\n",
"Error in : illegal axis coordinates range: xmin=1000000000000000019884624838656.000000, ymin=0.000000, xmax=-1000000000000000019884624838656.000000, ymax=1.050000\n",
"Error in : illegal world coordinates range: x1=1250000018626452571502436941824.000000, y1=-0.131250, x2=-1250000018626452571502436941824.000000, y2=1.181250\n",
"Error in : illegal axis coordinates range: xmin=1000000000000000019884624838656.000000, ymin=0.000000, xmax=-1000000000000000019884624838656.000000, ymax=1.050000\n",
"Error in : illegal world coordinates range: x1=1250000018626452571502436941824.000000, y1=-0.131250, x2=-1250000018626452571502436941824.000000, y2=1.181250\n",
"Error in : illegal axis coordinates range: xmin=1000000000000000019884624838656.000000, ymin=0.000000, xmax=-1000000000000000019884624838656.000000, ymax=1.050000\n",
"Error in : illegal world coordinates range: x1=1250000018626452571502436941824.000000, y1=-0.131250, x2=-1250000018626452571502436941824.000000, y2=1.181250\n",
"Error in : illegal axis coordinates range: xmin=1000000000000000019884624838656.000000, ymin=0.000000, xmax=-1000000000000000019884624838656.000000, ymax=1.050000\n"
]
}
],
"source": [
"%jsroot on\n",
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}