{
"cells": [
{
"cell_type": "markdown",
"id": "7df0dbb2",
"metadata": {},
"source": [
"# FITS_tutorial4\n",
"Open a FITS file whose primary array represents\n",
"a spectrum (flux vs wavelength).\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Claudi Martinez \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:13 PM."
]
},
{
"cell_type": "markdown",
"id": "4273ee11",
"metadata": {},
"source": [
"We open a FITS file that contains the primary HDU and a little data table.\n",
"The data table is extension #1 and it has 2 rows.\n",
"We want to read only the rows that have the column named DATAMAX greater than 2e-15 (there's only 1\n",
"matching row Data copyright: NASA"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "058a8621",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:14:01.580024Z",
"iopub.status.busy": "2026-05-19T20:14:01.579918Z",
"iopub.status.idle": "2026-05-19T20:14:01.898086Z",
"shell.execute_reply": "2026-05-19T20:14:01.897570Z"
}
},
"outputs": [],
"source": [
"TString dir = gROOT->GetTutorialDir();"
]
},
{
"cell_type": "markdown",
"id": "ee096ea9",
"metadata": {},
"source": [
"Open the table extension number 1)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9c9635ea",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:14:01.900088Z",
"iopub.status.busy": "2026-05-19T20:14:01.899964Z",
"iopub.status.idle": "2026-05-19T20:14:02.105420Z",
"shell.execute_reply": "2026-05-19T20:14:02.105053Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CRVAL1 : REAL NUMBER\n",
"CRPIX1 : REAL NUMBER\n",
"CD1_1 : REAL NUMBER\n",
"DATAMIN : REAL NUMBER\n",
"DATAMAX : REAL NUMBER\n",
"RA_APER : REAL NUMBER\n",
"DEC_APER : REAL NUMBER\n",
"FILLCNT : REAL NUMBER\n",
"ERRCNT : REAL NUMBER\n",
"FPKTTIME : REAL NUMBER\n",
"LPKTTIME : REAL NUMBER\n",
"CTYPE1 : STRING\n",
"APER_POS : STRING\n",
"PASS_DIR : REAL NUMBER\n",
"YPOS : REAL NUMBER\n",
"YTYPE : STRING\n",
"EXPOSURE : REAL NUMBER\n",
"X_OFFSET : REAL NUMBER\n",
"Y_OFFSET : REAL NUMBER\n",
"\n",
"CRVAL1 | CRPIX1 | CD1_1 | DATAMIN | DATAMAX | RA_APER | DEC_APER | FILLCNT | ERRCNT | FPKTTIME | LPKTTIME | CTYPE1 | APER_POS | PASS_DIR | YPOS | YTYPE | EXPOSURE | X_OFFSET | Y_OFFSET | \n",
"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
"1 | 1 | 1 | 0 | 2.7e-15 | 1.8e+02 | 39 | 0 | 0 | 4.9e+04 | 4.9e+04 | PIXEL | SINGLE | 0 | -1.5e+03 | OBJ | 31 | 0 | 0 | \n",
"v[0] = 2.73876e-15\n",
"Does the matched row have DATAMAX > 2e-15? :-)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : The selected HDU contains a Table Extension\n"
]
}
],
"source": [
"TFITSHDU hdu(dir + \"/io/fitsio/sample2.fits[1][DATAMAX > 2e-15]\");\n",
"\n",
"hdu.Print(\"T\");\n",
"\n",
"hdu.Print(\"T+\");\n",
"\n",
"std::unique_ptr vp(hdu.GetTabRealVectorColumn(\"DATAMAX\"));\n",
"const auto &v = *vp;\n",
"std::cout << \"v[0] = \" << v[0] << std::endl;\n",
"std::cout << \"Does the matched row have DATAMAX > 2e-15? :-)\" << std::endl;"
]
},
{
"cell_type": "markdown",
"id": "3018e330",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0f74c1e8",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:14:02.107041Z",
"iopub.status.busy": "2026-05-19T20:14:02.106930Z",
"iopub.status.idle": "2026-05-19T20:14:02.311341Z",
"shell.execute_reply": "2026-05-19T20:14:02.310733Z"
}
},
"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
}