ROOT
v6-28
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 +
"/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
}
gROOT
#define gROOT
Definition
TROOT.h:405
TFITSHDU
FITS file interface class.
Definition
TFITS.h:35
TString
Basic string class.
Definition
TString.h:139
TVectorT< Double_t >
ROOT
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Definition
EExecutionPolicy.hxx:4
ROOT::TSeqI
TSeq< int > TSeqI
Definition
TSeq.hxx:203
v
@ v
Definition
rootcling_impl.cxx:3661
tutorials
fitsio
FITS_tutorial5.C
ROOT v6-28 - Reference Guide Generated on Wed Jun 26 2024 01:59:18 (GVA Time) using Doxygen 1.9.8