# F I T S_Tutorial 5¶

Open a FITS file whose primary array represents a spectrum (flux vs wavelength)

Author: Claudi Martinez
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Thursday, June 24, 2021 at 07:38 AM.

In [1]:
using Upvd_t = std::unique_ptr<TVectorD>;


We open a fits file that contains a table with 9 rows and 8 columns. column 4 has name 'mag' and contains a vector of 6 numeric components. The values of vectors in rows 1 and 2 (column 4) are: Row1: (99.0, 24.768, 23.215, 21.68, 21.076, 20.857) Row2: (99.0, 21.689, 20.206, 18.86, 18.32 , 18.128 ) WARNING: when coding, row and column indices start from 0

In [2]:
TString dir = gROOT->GetTutorialDir();


Open the table

In [3]:
TFITSHDU hdu(dir + "/fitsio/sample4.fits[1]");

Info in <TFITSHDU::LoadHDU>: The selected HDU contains a Table Extension


Read vectors at rows 1 and 2 (indices 0 and 1)

In [4]:
std::array<Upvd_t, 2> vs{Upvd_t(hdu.GetTabRealVectorCell(0, "mag")), Upvd_t(hdu.GetTabRealVectorCell(1, "mag"))};
for (auto &&v : vs) {
for(auto i : ROOT::TSeqI(v->GetNoElements())) {
if (i > 0)
printf(", ");
printf("%lg", (*v)[i]); // NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
}
printf(")\n");
}

99, 24.768, 23.215, 21.68, 21.076, 20.857)
99, 21.689, 20.206, 18.86, 18.32, 18.128)


We now dump all rows using the function gettabrealvectorcells()

In [5]:
std::unique_ptr<TObjArray> vectorCollection(hdu.GetTabRealVectorCells("mag"));
for (auto vObj : *vectorCollection) {
auto &v = *static_cast<TVectorD*>(vObj);
for (auto i : ROOT::TSeqI(v.GetNoElements())) {
if (i > 0) printf(", ");
printf("%lg", (v[i]));
}
printf(")\n");
}

99, 24.768, 23.215, 21.68, 21.076, 20.857)
99, 21.689, 20.206, 18.86, 18.32, 18.128)
99, 23.993, 22.575, 21.51, 21.07, 20.915)
99, 22.26, 20.717, 19.404, 18.888, 18.706)
99, 21.957, 20.41, 18.874, 18.271, 18.054)
99, 22.113, 20.535, 18.872, 18.229, 17.995)
99, 22.177, 20.678, 19.275, 18.714, 18.513)
99, 23.394, 21.846, 20.27, 19.649, 19.424)
99, 23.094, 21.452, 19.482, 18.723, 18.434)


Draw all canvases

In [6]:
gROOT->GetListOfCanvases()->Draw()