/* ======================================================================== *\
!
! *
! * This file is part of MARS, the MAGIC Analysis and Reconstruction
! * Software. It is distributed to you in the hope that it can be a useful
! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
! * It is distributed WITHOUT ANY WARRANTY.
! *
! * Permission to use, copy, modify and distribute this software and its
! * documentation for any purpose is hereby granted without fee,
! * provided that the above copyright notice appear in all copies and
! * that both that copyright notice and this permission notice appear
! * in supporting documentation. It is provided "as is" without express
! * or implied warranty.
! *
!
!
!   Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
!
!   Copyright: MAGIC Software Development, 2000-2004
!
!
\* ======================================================================== */

/////////////////////////////////////////////////////////////////////////////
//
// MPointingPos
//
// In this container we store the corrected pointing position of the
// telscope. The pointing coordinates are read into MReportDrive together
// with its time.
//
// MPointingPosCalc afterwards calculates corrections and checks for the
// cosistency of the coordinates. The result (the real coordinates)
// are stored in this container. No further correction should be necessary
// using MPointingPos.
//
// If you need the rotation angle of the starfield in the camera you can
// get it from here.
//
/////////////////////////////////////////////////////////////////////////////
#include "MPointingPos.h"

#include "MTime.h"
#include "MObservatory.h"
#include "MPointingDev.h"
#include "MAstroSky2Local.h"

ClassImp(MPointingPos);

using namespace std;

// --------------------------------------------------------------------------
//
// Get the corresponding rotation angle of the sky coordinate system
// seen with an Alt/Az telescope calculated from the stored local
// (Zd/Az) coordinates.
//
// For more information see MAstro::RotationAngle
//
Double_t MPointingPos::RotationAngle(const MObservatory &o) const
{
    return o.RotationAngle(fZd*TMath::DegToRad(), fAz*TMath::DegToRad());
}

// --------------------------------------------------------------------------
//
// Get the corresponding rotation angle of the sky coordinate system
// seen with an Alt/Az telescope calculated from the stored sky
// (Ra/Dec) coordinates.
//
// For more information see MAstro::RotationAngle
//
Double_t MPointingPos::RotationAngle(const MObservatory &o, const MTime &t, const MPointingDev *dev) const
{
    return dev ?
        MAstroSky2Local(t, o).RotationAngle(GetRaRad(), GetDecRad(), dev->GetDevZdRad(), dev->GetDevAzRad()):
        MAstroSky2Local(t, o).RotationAngle(GetRaRad(), GetDecRad());
}
