{
"cells": [
{
"cell_type": "markdown",
"id": "f1d81fae",
"metadata": {},
"source": [
"# FITS_tutorial8\n",
"Open a FITS file with columns containing variable-length arrays.\n",
"\n",
"ABOUT THE DATA: To illustrate such a case we use a Redistribution\n",
"Matrix File (RMF) conform with the HEASARC OGIP specifications\n",
"OGIP definition\n",
"https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/spectra/ogip_92_007/ogip_92_007.html\n",
"RMF defintion\n",
"https://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.html#tth_sEc3.1\n",
"\n",
"Variable-length arrays are used to return the non-null row elements of a\n",
"sparse matrix containing the probability of detecting a photon of a given\n",
"energy at a given detector channel.\n",
"\n",
"The test data file, rmf.fits, is taken from the test data of the sherpa X-ray\n",
"analysis tools\n",
"https://cxc.harvard.edu/sherpa/\n",
"the original file is available under the repository\n",
"https://github.com/sherpa/sherpa-test-data\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Cosimo Nigro \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:14 PM."
]
},
{
"cell_type": "markdown",
"id": "ddea0077",
"metadata": {},
"source": [
"let us read the first header data unit, opening the file with a FITS viewer\n",
"we see that the following cells contain variable-length arrays with values\n",
"row 215 column \"F_CHAN\": (1, 68)\n",
"row 215 column \"N_CHAN\": (66, 130)\n",
"row 215 column \"MATRIX\" : (5.8425176E-6, 7.290097E-6, 8.188037E-6, 9.157882E-6, 1.018355E-5, ..)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "455f4255",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:14:15.061272Z",
"iopub.status.busy": "2026-05-19T20:14:15.061144Z",
"iopub.status.idle": "2026-05-19T20:14:15.374664Z",
"shell.execute_reply": "2026-05-19T20:14:15.374014Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"reading in row 215, column F_CHAN \n",
"(1.000000, 68.000000) \n",
"reading in row 215, column N_CHAN \n",
"(66.000000, 130.000000) \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : The selected HDU contains a Table Extension\n"
]
}
],
"source": [
"TString dir = gROOT->GetTutorialDir();\n",
"TFITSHDU* hdu = new TFITSHDU(dir + \"/io/fitsio/rmf.fits\", 1);\n",
"int rownum = 214; // FITS tables are indexed starting from 1\n",
"TString colname1 = \"F_CHAN\";\n",
"TString colname2 = \"N_CHAN\";\n",
"TString colname3 = \"MATRIX\";\n",
"\n",
"printf(\"reading in row %d, column %s \\n\", rownum+1, colname1.Data());\n",
"TArrayD *arr1 = hdu->GetTabVarLengthVectorCell(rownum, colname1);\n",
"printf(\"(%f, %f) \\n\", arr1->At(0), arr1->At(1));\n",
"\n",
"printf(\"reading in row %d, column %s \\n\", rownum+1, colname2.Data());\n",
"TArrayD *arr2 = hdu->GetTabVarLengthVectorCell(rownum, colname2);\n",
"printf(\"(%f, %f) \\n\", arr2->At(0), arr2->At(1));"
]
},
{
"cell_type": "markdown",
"id": "df1a9f9c",
"metadata": {},
"source": [
"printing only the first 5 values in the array"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ac85e132",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:14:15.376363Z",
"iopub.status.busy": "2026-05-19T20:14:15.376197Z",
"iopub.status.idle": "2026-05-19T20:14:15.581299Z",
"shell.execute_reply": "2026-05-19T20:14:15.580627Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"reading in row 215, column MATRIX \n",
"(5.842518e-06, 7.290097e-06, 8.188037e-06, 9.157882e-06, 1.018355e-05, ...) \n"
]
}
],
"source": [
"printf(\"reading in row %d, column %s \\n\", rownum+1, colname3.Data());\n",
"TArrayD *arr3 = hdu->GetTabVarLengthVectorCell(rownum, colname3);\n",
"printf(\"(%e, %e, %e, %e, %e, ...) \\n\", arr3->At(0), arr3->At(1), arr3->At(2), arr3->At(3), arr3->At(4));"
]
},
{
"cell_type": "markdown",
"id": "04a8a3cc",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "a4127705",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:14:15.582717Z",
"iopub.status.busy": "2026-05-19T20:14:15.582569Z",
"iopub.status.idle": "2026-05-19T20:14:15.787018Z",
"shell.execute_reply": "2026-05-19T20:14:15.786583Z"
}
},
"outputs": [],
"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
}