Logo ROOT   6.18/05
Reference Guide
FITS_tutorial5.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_FITS
3/// \notebook
4///
5/// Open a FITS file whose primary array represents
6/// a spectrum (flux vs wavelength)
7///
8/// \macro_code
9/// \macro_output
10///
11/// \author Claudi Martinez
12
13using Upvd_t = std::unique_ptr<TVectorD>;
14
15void FITS_tutorial5()
16{
17 // We open a FITS file that contains a table with 9 rows and 8 columns. Column 4 has name
18 // 'mag' and contains a vector of 6 numeric components. The values of vectors in rows 1 and 2 (column 4) are:
19 // Row1: (99.0, 24.768, 23.215, 21.68, 21.076, 20.857)
20 // Row2: (99.0, 21.689, 20.206, 18.86, 18.32 , 18.128 )
21 // WARNING: when coding, row and column indices start from 0
22
23 TString dir = gROOT->GetTutorialDir();
24
25 // Open the table
26 TFITSHDU hdu(dir + "/fitsio/sample4.fits[1]");
27
28 // Read vectors at rows 1 and 2 (indices 0 and 1)
29 std::array<Upvd_t, 2> vs{Upvd_t(hdu.GetTabRealVectorCell(0, "mag")), Upvd_t(hdu.GetTabRealVectorCell(1, "mag"))};
30 for (auto &&v : vs) {
31 for(auto i : ROOT::TSeqI(v->GetNoElements())) {
32 if (i > 0)
33 printf(", ");
34 printf("%lg", (*v)[i]); // NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
35 }
36 printf(")\n");
37 }
38
39 // We now dump all rows using the function GetTabRealVectorCells()
40 std::unique_ptr<TObjArray> vectorCollection(hdu.GetTabRealVectorCells("mag"));
41 for (auto vObj : *vectorCollection) {
42 auto &v = *static_cast<TVectorD*>(vObj);
43 for (auto i : ROOT::TSeqI(v.GetNoElements())) {
44 if (i > 0) printf(", ");
45 printf("%lg", (v[i]));
46 }
47 printf(")\n");
48 }
49}
SVector< double, 2 > v
Definition: Dict.h:5
#define gROOT
Definition: TROOT.h:414
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
FITS file interface class.
Definition: TFITS.h:34
Basic string class.
Definition: TString.h:131