#ifndef CherenkovDisplay_h
#define  CherenkovDisplay_h

#include "WCSimWrap.h"
#include "THKCherenkov.h"
#include "THKCherenkov2D.h"
class CherenkovDisplay {
    public:
        CherenkovDisplay(float maxR,float minZ,float maxZ,WCSimRootGeom* wcsimrootgeom) : 
        maxR(maxR),minZ(minZ),maxZ(maxZ),wcsimrootgeom(wcsimrootgeom) {} ;

        CherenkovDisplay() :maxR(0),minZ(0),maxZ(0),wcsimrootgeom(nullptr) {};
        void             SetLimits(float maxR,float minZ,float maxZ)
        {this->maxR=maxR;this->minZ=minZ;this->maxZ=maxZ; }
        void             SetWCSimGeom(WCSimRootGeom *input){wcsimrootgeom=input;};

        bool createCherenkov(THKCherenkov* cone,THKCherenkov2D* cone2D,
            TString Name,Color_t colour,
            double Momentum,double theta,double phi,float Mass,double pos[3],bool dotted=kFALSE );
        void searchForTube(int *List,int xI,int yI,int maxYStep,
            double pos[3],double cerenkov[3],bool debug,int tubes[3]);
        void  lineTubeIntersect(double cerenkov[3],double pos[3],float cylinderR,float &xc,float &xy);
        bool FindConeEnd(double pos[3],double cerenkov[3],double endPoint[3],int &location);
        double cosAngleToTube(double pos[3],double cerenkov[3],int tubeId);
        void UnrollView(double position[3],int location);
        void PreProcessGeometry();   



        static void CartesianToPolar(double  &mom,double &theta,double  &phi,double p[3]);
        static void polarToCartesian(double   mom,double  theta,double  phi,double p[3]);
        

    private:
        float maxR,minZ,maxZ;

        int  zIndex(float Z);
        int  xyIndex(float xOry);
        int  phiIndex(float x,float y);  
        void validateId(int tubeID);
        double DotProduct(double a[],double b[],int n);
        void copyPointsFromArray(double P[],double &X, double &Y,double &Z){
            X=P[0];Y=P[1];Z=P[2]; }
        void copyPointsToArray(double &X, double &Y,double &Z,double P[]){
            P[0]=X;P[1]=Y;P[2]=Z; }

        int   nZvalues;
        int maxZIndex,maxPhiIndex,maxXIndex,maxYIndex,maxTube{-1},nextMaxTube{-1},nextNextMaxTube{-1};
        int *CylinderTubeList;
        int *NegativeCapTubeList;
        int *PositiveCapTubeList;
        WCSimRootGeom *wcsimrootgeom;
    };
#endif