#ifndef SEARCHEVENT_INCD
#define SEARCHEVENT_INCD

#include "TTimeStamp.h"
#include "Evt.hh"
#include "astro/Astro.hh"
#include "definitions.hh"

/*! A simple summary event to be used in source-searches and
  for pseudo-experiment generation */

struct SearchEvent  
{
  unsigned index                {0};                   // index into a DataSet' data vector   
  channel chan                  {undefined_channel};   // shower, track, ...
  flavor flav                   {undefined_flavor};    // flavor (mc truth)
  int source                    {0};                   // unique id of the component that generated this event (mc truth)
               
  double zenith                 {0};                   // reconstructed zenith angle of the origin of the track ( i.e. acos(-trk.dir.z) )
  double azimuth                {0};                   // reconstructed azimuth angle of the origin of the track
  TTimeStamp t                  {0};                   // time of detection (truth==measured)
  EquatorialCoords coordinates  {0,0};                 // reconstrued coordinates (from zenith, azimuth, time)

  double Eproxy                 {0};                   // energy estimate - or equivalent
  double direction_uncertainty  {0};
  double Eproxy_uncertainty     {0};  


  Evt* evt = nullptr ; /*! pointer to original aanet event, can be null */

    
  bool check_yourself_before_you_wreck_yourself()
  {
    if ( zenith < 0  || zenith > pi     ) return false;
    if ( azimuth < 0 || azimuth > 2 *pi ) return false;
    if ( Eproxy > 8 )                     return false;
    // add more here.
    return true;
  }


  const char* __str__() const;
  string str() const { return __str__(); }

  SearchEvent() {}

  SearchEvent( double ra, double dec, double E ) : 
    coordinates( ra, dec ), Eproxy(E) {}
   
  SearchEvent( double zenith, double azimuth, const TTimeStamp& t , double E) :
    zenith( zenith ), azimuth( azimuth ), t(t), Eproxy(E) {}

  void compute_coordinates(const Det& det) 
  {
    Vec d;
    d.set_angles( zenith, azimuth );
    coordinates = EquatorialCoords( det, -d , t );
  }

  void compute_source_direction( const Det& det ) 
  {
    Vec d = -coordinates.track_direction( det, t );
    zenith  = d.theta();
    azimuth = d.phi();
  }

  double distance( const SearchEvent& other ) const 
  {
    return coordinates.distance( other.coordinates );
  }

  double distance ( double ra, double dec ) const 
  {
    return coordinates.distance( {ra, dec } );
  }

  ClassDefNV( SearchEvent, 1 );
};


namespace cling
{
  inline std::string printValue(const SearchEvent* e)
  {
    return e->__str__();
  }
}




#endif