Logo ROOT  
Reference Guide
FITS_tutorial8.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_FITS
3/// \notebook
4///
5/// Open a FITS file with columns containing variable-length arrays.
6///
7/// ABOUT THE DATA: To illustrate such a case we use a Redistribution
8/// Matrix File (RMF) conform with the HEASARC OGIP specifications
9/// OGIP definition
10/// https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/spectra/ogip_92_007/ogip_92_007.html
11/// RMF defintion
12/// https://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.html#tth_sEc3.1
13///
14/// Variable-length arrays are used to return the non-null row elements of a
15/// sparse matrix containing the probability of detecting a photon of a given
16/// energy at a given detector channel.
17///
18/// The test data file, rmf.fits, is taken from the test data of the sherpa X-ray
19/// analysis tools
20/// https://cxc.harvard.edu/sherpa/
21/// the original file is available under the repository
22/// https://github.com/sherpa/sherpa-test-data
23///
24/// \macro_code
25/// \macro_output
26///
27/// \author Cosimo Nigro
28
29void FITS_tutorial8()
30{
31 // let us read the first header data unit, opening the file with a FITS viewer
32 // we see that the following cells contain variable-length arrays with values
33 // row 215 column "F_CHAN": (1, 68)
34 // row 215 column "N_CHAN": (66, 130)
35 // row 215 column "MATRIX" : (5.8425176E-6, 7.290097E-6, 8.188037E-6, 9.157882E-6, 1.018355E-5, ..)
36 TString dir = gROOT->GetTutorialDir();
37 TFITSHDU* hdu = new TFITSHDU(dir + "/fitsio/rmf.fits", 1);
38 int rownum = 214; // FITS tables are indexed starting from 1
39 TString colname1 = "F_CHAN";
40 TString colname2 = "N_CHAN";
41 TString colname3 = "MATRIX";
42
43 printf("reading in row %d, column %s \n", rownum+1, colname1.Data());
44 TArrayD *arr1 = hdu->GetTabVarLengthVectorCell(rownum, colname1);
45 printf("(%f, %f) \n", arr1->At(0), arr1->At(1));
46
47 printf("reading in row %d, column %s \n", rownum+1, colname2.Data());
48 TArrayD *arr2 = hdu->GetTabVarLengthVectorCell(rownum, colname2);
49 printf("(%f, %f) \n", arr2->At(0), arr2->At(1));
50
51 // printing only the first 5 values in the array
52 printf("reading in row %d, column %s \n", rownum+1, colname3.Data());
53 TArrayD *arr3 = hdu->GetTabVarLengthVectorCell(rownum, colname3);
54 printf("(%e, %e, %e, %e, %e, ...) \n", arr3->At(0), arr3->At(1), arr3->At(2), arr3->At(3), arr3->At(4));
55
56}
#define gROOT
Definition: TROOT.h:406
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
Double_t At(Int_t i) const
Definition: TArrayD.h:79
FITS file interface class.
Definition: TFITS.h:35
TArrayD * GetTabVarLengthVectorCell(Int_t rownum, Int_t colnum)
Get the variable-length array contained in a cell given by (row>=0, column name)
Definition: TFITS.cxx:1583
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364