ROOT
master
Reference Guide
Loading...
Searching...
No Matches
FITS_tutorial5.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_FITS
3
/// \notebook
4
/// Open a FITS file whose primary array represents
5
/// a spectrum (flux vs wavelength)
6
///
7
/// \macro_code
8
/// \macro_output
9
///
10
/// \author Claudi Martinez
11
12
using
Upvd_t
= std::unique_ptr<TVectorD>;
13
14
void
FITS_tutorial5
()
15
{
16
// We open a FITS file that contains a table with 9 rows and 8 columns. Column 4 has name
17
// 'mag' and contains a vector of 6 numeric components. The values of vectors in rows 1 and 2 (column 4) are:
18
// Row1: (99.0, 24.768, 23.215, 21.68, 21.076, 20.857)
19
// Row2: (99.0, 21.689, 20.206, 18.86, 18.32 , 18.128 )
20
// WARNING: when coding, row and column indices start from 0
21
22
TString
dir =
gROOT
->GetTutorialDir();
23
24
// Open the table
25
TFITSHDU
hdu
(dir +
"/io/fitsio/sample4.fits[1]"
);
26
27
// Read vectors at rows 1 and 2 (indices 0 and 1)
28
std::array<Upvd_t, 2>
vs
{
Upvd_t
(
hdu
.GetTabRealVectorCell(0,
"mag"
)),
Upvd_t
(
hdu
.GetTabRealVectorCell(1,
"mag"
))};
29
for
(
auto
&&
v
:
vs
) {
30
for
(
auto
i :
ROOT
::
TSeqI
(
v
->GetNoElements())) {
31
if
(i > 0)
32
printf
(
", "
);
33
printf
(
"%lg"
, (*
v
)[i]);
// NOTE: the asterisk is for using the overloaded [] operator of the TVectorD object
34
}
35
printf
(
")\n"
);
36
}
37
38
// We now dump all rows using the function GetTabRealVectorCells()
39
std::unique_ptr<TObjArray>
vectorCollection
(
hdu
.GetTabRealVectorCells(
"mag"
));
40
for
(
auto
vObj
: *
vectorCollection
) {
41
auto
&
v
= *
static_cast<
TVectorD
*
>
(
vObj
);
42
for
(
auto
i :
ROOT
::
TSeqI
(
v
.GetNoElements())) {
43
if
(i > 0)
printf
(
", "
);
44
printf
(
"%lg"
, (
v
[i]));
45
}
46
printf
(
")\n"
);
47
}
48
}
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
gROOT
#define gROOT
Definition
TROOT.h:411
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TFITSHDU
FITS file interface class.
Definition
TFITS.h:35
TString
Basic string class.
Definition
TString.h:138
TVectorT< Double_t >
ROOT
Namespace for new ROOT classes and functions.
Definition
EExecutionPolicy.hxx:4
ROOT::TSeqI
TSeq< int > TSeqI
Definition
TSeq.hxx:203
v
@ v
Definition
rootcling_impl.cxx:3683
tutorials
io
fitsio
FITS_tutorial5.C
ROOT master - Reference Guide Generated on Wed Sep 3 2025 04:32:29 (GVA Time) using Doxygen 1.10.0