{
"cells": [
{
"cell_type": "markdown",
"id": "80279272",
"metadata": {},
"source": [
"# hist042_TProfile2Poly_module_error\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Filip Ilic \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:12 PM."
]
},
{
"cell_type": "markdown",
"id": "a9949052",
"metadata": {},
"source": [
" Arguments are defined. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "701fc0f5",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:57.518264Z",
"iopub.status.busy": "2026-05-19T20:12:57.518133Z",
"iopub.status.idle": "2026-05-19T20:12:57.840400Z",
"shell.execute_reply": "2026-05-19T20:12:57.839832Z"
}
},
"outputs": [],
"source": [
"Int_t numEvents = 1000000;"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2b6d9239",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:57.842355Z",
"iopub.status.busy": "2026-05-19T20:12:57.842229Z",
"iopub.status.idle": "2026-05-19T20:12:58.046518Z",
"shell.execute_reply": "2026-05-19T20:12:58.045919Z"
}
},
"outputs": [],
"source": [
"TCanvas *c1 = new TCanvas(\"c1\", \"4 Malfunctioning Panels\", 800, 400);\n",
"c1->Divide(3, 1);"
]
},
{
"cell_type": "markdown",
"id": "298bdd13",
"metadata": {},
"source": [
"-------------------- Construct detector bins ------------------------"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0a62d56a",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:58.048707Z",
"iopub.status.busy": "2026-05-19T20:12:58.048533Z",
"iopub.status.idle": "2026-05-19T20:12:58.259244Z",
"shell.execute_reply": "2026-05-19T20:12:58.258596Z"
}
},
"outputs": [],
"source": [
"auto th2p = new TH2Poly();\n",
"auto avg = new TProfile2Poly();\n",
"auto err = new TProfile2Poly();\n",
"\n",
"std::ifstream infile;\n",
"TString dir = gROOT->GetTutorialDir();\n",
"dir.Append(\"/hist/data/tprofile2poly_tutorial.data\");\n",
"infile.open(dir.Data());\n",
"\n",
"if (!infile) // Verify that the file was open successfully\n",
"{\n",
" std::cerr << dir.Data() << std::endl; // Report error\n",
" std::cerr << \"Error code: \" << std::strerror(errno) << std::endl; // Get some info as to why\n",
" return;\n",
"}\n",
"\n",
"std::vector> allCoords;\n",
"Double_t a, b;\n",
"while (infile >> a >> b)\n",
" allCoords.emplace_back(a, b);\n",
"\n",
"if (allCoords.size() % 3 != 0) {\n",
" std::cout << \"[ERROR] Bad file\" << std::endl;\n",
" return;\n",
"}\n",
"\n",
"Double_t x[3], y[3];\n",
"for (Int_t i = 0; i < allCoords.size(); i += 3) {\n",
" x[0] = allCoords[i + 0].first;\n",
" y[0] = allCoords[i + 0].second;\n",
" x[1] = allCoords[i + 1].first;\n",
" y[1] = allCoords[i + 1].second;\n",
" x[2] = allCoords[i + 2].first;\n",
" y[2] = allCoords[i + 2].second;\n",
" th2p->AddBin(3, x, y);\n",
" avg->AddBin(3, x, y);\n",
" err->AddBin(3, x, y);\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "defaa88d",
"metadata": {},
"source": [
"-------------------- Generate particles ------------------------"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f422663d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:58.269393Z",
"iopub.status.busy": "2026-05-19T20:12:58.269269Z",
"iopub.status.idle": "2026-05-19T20:12:59.094784Z",
"shell.execute_reply": "2026-05-19T20:12:59.085683Z"
}
},
"outputs": [],
"source": [
"TRandom ran;\n",
"for (int j = 0; j < numEvents; ++j) {\n",
" Double_t r1 = ran.Gaus(0, 10);\n",
" Double_t r2 = ran.Gaus(0, 8);\n",
" Double_t rok = ran.Gaus(20, 2);\n",
" Double_t rbad1 = ran.Gaus(1, 2);\n",
" Double_t rbad2 = ran.Gaus(2, 0);\n",
"\n",
" Double_t val = rok;\n",
" // -------------------- Malfunctioning panels -------------------\n",
" if (th2p->IsInsideBin(4, r1, r2))\n",
" val = rok - rbad1;\n",
" if (th2p->IsInsideBin(20, r1, r2))\n",
" val = rok - rbad2;\n",
" if (th2p->IsInsideBin(13, r1, r2))\n",
" val = rok + rbad1;\n",
" if (th2p->IsInsideBin(37, r1, r2))\n",
" val = rok + rbad2;\n",
"\n",
" // -------------------- Fill histograms ------------------------\n",
" th2p->Fill(r1, r2, val);\n",
" avg->Fill(r1, r2, val);\n",
" err->Fill(r1, r2, val);\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "a6f7b473",
"metadata": {},
"source": [
"-------------------- Display end state ------------------------"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "688ec559",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:59.096405Z",
"iopub.status.busy": "2026-05-19T20:12:59.096286Z",
"iopub.status.idle": "2026-05-19T20:12:59.299409Z",
"shell.execute_reply": "2026-05-19T20:12:59.298810Z"
}
},
"outputs": [],
"source": [
"c1->cd(1);\n",
"th2p->SetStats(0);\n",
"th2p->SetTitle(\"total hits\");\n",
"th2p->Draw(\"COLZ\");\n",
"\n",
"c1->cd(2);\n",
"avg->SetStats(0);\n",
"avg->SetTitle(\"average charge\");\n",
"avg->Draw(\"COLZ\");\n",
"\n",
"c1->cd(3);\n",
"err->SetStats(0);\n",
"err->SetContentToError();\n",
"err->SetTitle(\"error\");\n",
"err->Draw(\"COLZ\");"
]
},
{
"cell_type": "markdown",
"id": "4bf6ae36",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "d9784cd7",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:59.301408Z",
"iopub.status.busy": "2026-05-19T20:12:59.301291Z",
"iopub.status.idle": "2026-05-19T20:12:59.508825Z",
"shell.execute_reply": "2026-05-19T20:12:59.506852Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"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
}