INTEGRALPlanckGaiaPOLARCHEOPSEuclidATHENA
HEAVENSFACTCTALOFTSPICAJEM-EUSOXIPEeXTPTheseus
XRISMMAGBOUNDSMARTNet
ISDCCDCI
Data Centre for Astrophysics
Astronomy Department of the University of Geneva
Astro ROOT

Tutorials
ROSETTE (CO)
 

All macros of the tutorials with their test data can be downloaded.


FITS table to TTree conversion

table2tree()
{
// A FITS table is read from a FITS file, and converted into 
// a ROOT tree. The tree is displayed with its TreeViewer.

   // read one table extension from the FITS file
   // SPI.-FEE3-HRW is the extension name of the FITS table
   TFTable * table = TFReadTable("spi_raw_acs.fits.gz", "SPI.-FEE3-HRW");
   if (table)
      {
      // convert the table into a TTree
      TTree * tree = table->MakeTree();
      delete table;

      // view the data
      tree->StartViewer();     
      }
}

FITS table to TGraph conversion

table2graph()
{
// A FITS table is read from a FITS file, and converted into 
// a ROOT TGraph. The graph is displayd.


   // read one table extension from the FITS file
   // SPI.-FEE8-HRW is the extension name of the FITS table
   TFTable * table = TFReadTable("spi_raw_acs.fits.gz", "SPI.-FEE8-HRW");
   if (table)
      {
      // use the two columns PACK_TIME and FEE65 of the table 
      // to crate a TGraph. 
      TGraph * graph = table->MakeGraph("PACK_TIME", "FEE65");
      delete table;

      // display the data
      graph->Draw("AL");     
      }
}

FITS image to TH2D conversion

image2histogram()
{
// read an FITS image, convert it into a 
// ROOT histogram and display it

   // The image we want to display is the extension
   // SPI.-SKY.-IMA in the image.fits file.
   TFFloatImg * img = TFReadImage("image.fits", "SPI.-SKY.-IMA");
   if (img == NULL)
      {
      TFError::PrintErrors();
      return;
      }

   // create a TH2D histogram and display it
   TH2D * hist = img->MakeHisto();
   hist->Draw("surf4");

}


Note: The following two examples does not work since ROOT version 4.01.04 on Sun solaris.
The problem is reported, but not yet fixed.

Image Display

image_display1()
{
// create an astronomical image display directly from a FITS file
// and display it.

   // The image we want to display is the third HDU in the file
   // image.fits.
   AstroImage * disp = new AstroImage("image.fits", NULL, 3);

   // read a color palette, it was written to the file via the
   // color editor (Save button)
   TFile *fpal = new TFile("image.pal.root", "READ");
   TImagePalette *palette = (TImagePalette*)fpal->Get("TImagePalette");
   delete fpal;

   // use the palette for this image
   disp->SetPalette(palette);
   delete palette;

   // draw the image and open its palette editor
   disp->Draw();
   disp->StartPaletteEditor();
}
image_display2()
{
// read an FITS image, modify it slightly and display the 
// result.

   // The image we want to display is the extension SPI.-SKY.-IMA
   // in the image.fits file.
   TFFloatImg * img = TFReadImage("image.fits", "SPI.-SKY.-IMA");
   if (img == NULL)
      {
      TFError::PrintErrors();
      return;
      }

   // get the size of image. We know it has two dimensions
   UInt_t size[2];
   img->GetSize(size);

   // cut all values above 8
   for (UInt_t x = 0; x < size[1]; x++)
      for (UInt_t y = 0; y < size[0]; y++)
         if ( (Float_t)((*img)[y][x]) > 8.0)
            (*img)[y][x] = 8.0;

   // open a window and open the status bar to display the 
   // coordinates and value of the image pixel at the mouse position
   TCanvas * win = new TCanvas("image", "SPI", 100, 100, 550, 524);
   win->ToggleEventStatus();

   // create the image display for the just read and slightly
   // modified image
   AstroImage * disp = new AstroImage(img);

   // we don't need the image any more
   delete img;

   // draw the image
   disp->Draw();
}
 

 
Back to AstroRoot main page.