{
"cells": [
{
"cell_type": "markdown",
"id": "29873c4c",
"metadata": {},
"source": [
"# hist041_TProfile2Poly_realistic\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": "36d48627",
"metadata": {},
"source": [
" Arguments are defined. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "063ffa39",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:56.706881Z",
"iopub.status.busy": "2026-05-19T20:12:56.706776Z",
"iopub.status.idle": "2026-05-19T20:12:57.029363Z",
"shell.execute_reply": "2026-05-19T20:12:57.028987Z"
}
},
"outputs": [],
"source": [
"Int_t numEvents = 100000;"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f3c064ae",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:57.042329Z",
"iopub.status.busy": "2026-05-19T20:12:57.042193Z",
"iopub.status.idle": "2026-05-19T20:12:57.246158Z",
"shell.execute_reply": "2026-05-19T20:12:57.245766Z"
}
},
"outputs": [],
"source": [
"int NUM_LS = 8;\n",
"TCanvas *c1 = new TCanvas(\"c1\", \"moving charge\", 900, 400);\n",
"TCanvas *c2 = new TCanvas(\"c2\", \"Merge Individual moving charge plots\", 800, 400);\n",
"\n",
"c1->Divide(NUM_LS, 3);\n",
"c2->Divide(3, 1);"
]
},
{
"cell_type": "markdown",
"id": "82f2c65c",
"metadata": {},
"source": [
"-------------------- Construct Reference plot bins ------------------------"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a70a7081",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:57.250018Z",
"iopub.status.busy": "2026-05-19T20:12:57.249894Z",
"iopub.status.idle": "2026-05-19T20:12:57.757134Z",
"shell.execute_reply": "2026-05-19T20:12:57.756535Z"
}
},
"outputs": [],
"source": [
"auto new_avg = new TProfile2Poly();\n",
"\n",
"auto tot_avg_ls = new TProfile2Poly[NUM_LS];\n",
"auto det_avg_ls = new TProfile2Poly[NUM_LS];\n",
"auto det_err_ls = new TProfile2Poly[NUM_LS];\n",
"auto tot_merge = new TProfile2Poly();\n",
"auto det_avg_merge = new TProfile2Poly();\n",
"auto det_err_merge = new TProfile2Poly();\n",
"\n",
"float minx = -15;\n",
"float maxx = 15;\n",
"float miny = -15;\n",
"float maxy = 15;\n",
"float binsz = 0.5;\n",
"\n",
"for (float i = minx; i < maxx; i += binsz) {\n",
" for (float j = miny; j < maxy; j += binsz) {\n",
" tot_merge->AddBin(i, j, i + binsz, j + binsz);\n",
" for (int l = 0; l < NUM_LS; ++l) {\n",
" tot_avg_ls[l].AddBin(i, j, i + binsz, j + binsz);\n",
" }\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "5e5253a1",
"metadata": {},
"source": [
"-------------------- Construct detector bins ------------------------"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d9de67f3",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:57.760034Z",
"iopub.status.busy": "2026-05-19T20:12:57.759849Z",
"iopub.status.idle": "2026-05-19T20:12:58.023116Z",
"shell.execute_reply": "2026-05-19T20:12:58.022684Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" WE ARE AFTER LOADING DATA \n",
" WE ARE AFTER ADDING BINS \n"
]
}
],
"source": [
"auto h2p = new TH2Poly();\n",
"auto tp2p = new TProfile2Poly();\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",
"std::cout << \" WE ARE AFTER LOADING DATA \" << std::endl;\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",
" cout << \"[ERROR] Bad file\" << endl;\n",
" return;\n",
"}\n",
"\n",
"Double_t x[3], y[3];\n",
"for (int 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",
"\n",
" det_avg_merge->AddBin(3, x, y);\n",
" det_err_merge->AddBin(3, x, y);\n",
"\n",
" for (int l = 0; l < NUM_LS; ++l) {\n",
" det_avg_ls[l].AddBin(3, x, y);\n",
" det_err_ls[l].AddBin(3, x, y);\n",
" }\n",
"}\n",
"\n",
"std::cout << \" WE ARE AFTER ADDING BINS \" << std::endl;"
]
},
{
"cell_type": "markdown",
"id": "397d7426",
"metadata": {},
"source": [
"-------------------- Simulate particles ------------------------"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a524b639",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:58.029076Z",
"iopub.status.busy": "2026-05-19T20:12:58.028951Z",
"iopub.status.idle": "2026-05-19T20:12:58.232976Z",
"shell.execute_reply": "2026-05-19T20:12:58.232347Z"
}
},
"outputs": [],
"source": [
"TRandom ran;"
]
},
{
"cell_type": "markdown",
"id": "86bc2ac9",
"metadata": {},
"source": [
"moving error"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "68cf1f51",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:12:58.235656Z",
"iopub.status.busy": "2026-05-19T20:12:58.235467Z",
"iopub.status.idle": "2026-05-19T20:13:01.612862Z",
"shell.execute_reply": "2026-05-19T20:13:01.612464Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[In Progress] LumiSection 0\n",
"[In Progress] LumiSection 1\n",
"[In Progress] LumiSection 2\n",
"[In Progress] LumiSection 3\n",
"[In Progress] LumiSection 4\n",
"[In Progress] LumiSection 5\n",
"[In Progress] LumiSection 6\n",
"[In Progress] LumiSection 7\n",
"[In Progress] Merging\n"
]
}
],
"source": [
"Double_t xoffset1 = 0;\n",
"Double_t yoffset1 = 0;\n",
"Double_t xoffset2 = 0;\n",
"Double_t yoffset2 = 0;\n",
"\n",
"for (int i = 0; i <= NUM_LS - 1; ++i) { // LumiSection\n",
" std::cout << \"[In Progress] LumiSection \" << i << std::endl;\n",
" for (int j = 0; j < numEvents; ++j) { // Events\n",
" Double_t r1 = ran.Gaus(0, 10);\n",
" Double_t r2 = ran.Gaus(0, 8);\n",
" Double_t rok = ran.Gaus(10, 1);\n",
" Double_t rbad1 = ran.Gaus(8, 5);\n",
" Double_t rbad2 = ran.Gaus(-8, 5);\n",
"\n",
" Double_t val = rok;\n",
"\n",
" xoffset1 += 0.00002;\n",
" yoffset1 += 0.00002;\n",
"\n",
" xoffset2 += 0.00003;\n",
" yoffset2 += 0.00004;\n",
"\n",
" if (r2 > 3. - yoffset1 && r2 < 8. - yoffset1 && r1 > 1. + xoffset1 && r1 < 5. + xoffset1) {\n",
" val -= rbad1;\n",
" }\n",
"\n",
" if (r2 > -10 + yoffset2 && r2 < -8 + yoffset2 && r1 > -6 + xoffset2 && r1 < 8 + xoffset2) {\n",
" val -= rbad2;\n",
" }\n",
"\n",
" tot_avg_ls[i].Fill(r1, r2, val);\n",
" det_avg_ls[i].Fill(r1, r2, val);\n",
" det_err_ls[i].Fill(r1, r2, val);\n",
" }\n",
"\n",
" std::string title;\n",
"\n",
" c1->cd(i + 1);\n",
" title = \"Global View: Avg in LS \" + std::to_string(i);\n",
" tot_avg_ls[i].SetTitle(title.c_str());\n",
" tot_avg_ls[i].SetStats(false);\n",
" tot_avg_ls[i].Draw(\"COLZ\");\n",
" c1->Update();\n",
"\n",
" c1->cd((i + 1) + NUM_LS);\n",
" title = \"Detector View: Avg in LS \" + std::to_string(i);\n",
" det_avg_ls[i].SetTitle(title.c_str());\n",
" det_avg_ls[i].SetStats(false);\n",
" det_avg_ls[i].Draw(\"COLZ\");\n",
" c1->Update();\n",
"\n",
" c1->cd((i + 1) + (NUM_LS * 2));\n",
" title = \"Detector View: Error in LS \" + std::to_string(i);\n",
" det_err_ls[i].SetTitle(title.c_str());\n",
" det_err_ls[i].SetStats(false);\n",
" det_err_ls[i].SetContentToError();\n",
" det_err_ls[i].Draw(\"COLZ\");\n",
" c1->Update();\n",
"}\n",
"\n",
"std::vector tot_avg_v;\n",
"std::vector det_avg_v;\n",
"for (int t = 0; t < NUM_LS; t++) {\n",
" tot_avg_v.push_back(&tot_avg_ls[t]);\n",
" det_avg_v.push_back(&det_avg_ls[t]);\n",
"}\n",
"\n",
"std::cout << \"[In Progress] Merging\" << std::endl;\n",
"\n",
"tot_merge->Merge(tot_avg_v);\n",
"c2->cd(1);\n",
"tot_merge->SetTitle(\"Total average merge\");\n",
"tot_merge->Draw(\"COLZ\");\n",
"\n",
"det_avg_merge->Merge(det_avg_v);\n",
"c2->cd(2);\n",
"det_avg_merge->SetTitle(\"Detector average merge\");\n",
"det_avg_merge->SetContentToAverage(); // implicit\n",
"det_avg_merge->Draw(\"COLZ\");\n",
"\n",
"det_err_merge->Merge(det_avg_v);\n",
"c2->cd(3);\n",
"det_err_merge->SetTitle(\"Detector error merge\");\n",
"det_err_merge->SetContentToError();\n",
"det_err_merge->Draw(\"COLZ\");"
]
},
{
"cell_type": "markdown",
"id": "4a0083ff",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "d5d38849",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:13:01.621186Z",
"iopub.status.busy": "2026-05-19T20:13:01.621054Z",
"iopub.status.idle": "2026-05-19T20:13:02.662050Z",
"shell.execute_reply": "2026-05-19T20:13:02.661631Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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
}