#include "RingImage.h"

void RingImage::DrawImage( TString opt , int col ){
   float c = 3.e11; //mm/s
   float q_x = 400. ; //Quartz definition
   float x_step = 0.5 , x_max = 1300.;

   float n = 1.4;
   float theta_c = acos( 1 / n / beta );

   TGraph *g = new TGraph();

   int index = 0;

   float top_init = ( in_z / sin( theta_c ) ) / ( c / n );

   for( float x = -1*x_max; x < x_max;x+=x_step){
      float p_length = sqrt( in_z * in_z + x * x ) / sin( theta_c ) ;
      float top = p_length / ( c / n ) - top_init;

      float x_detect;
      int q_turn = abs( (int)x%(int)q_x );
      q_turn /= (int)( q_x/2 );
      if( ( q_turn % 2 ) < 1 ){
         if( x > 0 ){
            x_detect = ( (int)x % (int)q_x ) * ( x/fabs(x) ) * pow( -1 , ( ( abs( (int)(x/q_x) )%2 ) + 2 ) ) ;
         }else{
            x_detect = -1 * ( (int)x % (int)q_x ) * ( x/fabs(x) ) * pow( -1 , ( ( abs( (int)(x/q_x) )%2 ) + 2 ) ) ;
         }
      }else{
            x_detect = ( q_x - fabs( (int)x%(int)q_x ) ) * ( x/fabs(x) ) * pow( -1 , ( ( abs( (int)(x/q_x) )%2 ) + 2 ) );
      }

      g->SetPoint( index , x_detect , top );

      index++;
   }

   g->SetMarkerColor( col );
   g->Draw( opt );

};
