#ifndef GEOMETRYHELPER_H
#define GEOMETRYHELPER_H
//_____________________________________________________________________________
///
/// \class GeometryHelper 
///
/// Utility class provides methods to access geometry data used by the fitter.  
///
/// \author Sergei avva@fnal.gov
///

#include "UgliGeometry/UgliGeomHandle.h"
#include "Plex/PlexPlaneId.h"

#include "StripABC.h"

class CandStripHandle;
class CandTrackHandle;
class TrackContext;

class GeometryHelper {

public: 
    GeometryHelper(const VldContext& vldc);    
    GeometryHelper(const TrackContext& );
    
    ///
    /// z-position of the i-th plane
    ///
    Double_t    GetZ(PlexPlaneId id);
     
    ///
    /// z-position of the track vertex
    ///
    Double_t    GetZVtx(PlexPlaneId id, Int_t idir);
    
    /// 
    /// radiation lengths in the i-th plane (both steel and scint)
    ///
    Double_t    GetX0(PlexPlaneId id);
    
    ///
    /// steel thickness 
    ///
    Double_t    GetdZSteel(PlexPlaneId id); 
   
    ///
    ///
    ///
    UgliScintPlnHandle GetScintPlnHandle(const PlexPlaneId& planeid) 
                            { return fUgh.GetScintPlnHandle(planeid);};
    
    ///
    /// UV <-> XY conversion functions
    ///
    void        xy2uv(Float_t x, Float_t y, Float_t &u, Float_t &v) const
                    { fUgh.xy2uv(x, y, u, v); };

    void        uv2xy(Float_t u, Float_t v, Float_t &x, Float_t &y) const
                    { fUgh.uv2xy(u, v, x, y); };
    
    void        xy2uv(Double_t x, Double_t y, Double_t &u, Double_t &v) const
                    { fUgh.xy2uv(x, y, u, v); };

    void        uv2xy(Double_t u, Double_t v, Double_t &x, Double_t &y) const
                    { fUgh.uv2xy(u, v, x, y); };
    
    ///
    /// get position of the strip corrected for plane rotations
    ///
    Float_t     GetRotationCorrectedTPos(const CandStripHandle* csh, 
                                        const CandTrackHandle* cth);
    
    ///
    /// get position of the strip corrected for plane rotations
    ///
    Float_t     GetRotationCorrectedTPos(const Reco::Strip_t strip, 
                                        const CandTrackHandle* cth);
    
private:
    VldContext       fVldc;
    UgliGeomHandle   fUgh;
};

#endif
