//=//////////////////////////////////////////////////////////////////////
//=
//= creadparam                
//=
//= @file        creadparam.h
//= @desc        Header file
//= @author      J C Gonzalez
//= @email       gonzalez@mppmu.mpg.de
//= @date        Thu May  7 16:24:22 1998
//=
//=----------------------------------------------------------------------
//=
//= Created: Thu May  7 16:24:22 1998
//= Author:  Jose Carlos Gonzalez
//= Purpose: Program for reflector simulation
//= Notes:   See files README for details
//=    
//=----------------------------------------------------------------------
//=
//= $RCSfile: creadparam.h,v $
//= $Revision: 1.33 $
//= $Author: moralejo $ 
//= $Date: 2005-02-17 09:15:28 $
//=
//=//////////////////////////////////////////////////////////////////////

#ifndef _creadparam_
#define _creadparam_

#ifndef _this_
#define _this_ creadparam
#endif

//!@}

//!@subsection Include files.

//!@{

#include <iostream>
#include <fstream>
#include <string>

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>

#include "jcmacros.h"
#include "jcdebug.h"

#include "camera-v.h"

#include "MTriggerDefine.h"
#include "MFadcDefine.h"
#include "Mdefine.h"

//!@}

//!@subsection Macro-definitions, and constants.

//!@{

// now we define the list PM_ITEM_LIST of possible items in
// the parameters file. note that they are functions of
// T(x). we will change T(x) to be the real item or the
// string of this item when needed

#define PM_ITEM_LIST   /* LIST OF ITEMS IN THE PARAMETERS FILE */  \
T(input_file),      /* input file */                              \
T(starfield_file),  /* starfield file */                          \
T(starfield_center),/* center of thestarfield FOV */              \
T(data_file),       /* data file */                               \
T(root_file),       /* ROOT file */                               \
T(ct_num),          /* number of CT, which is number of reflector files */ \
T(ct_geom),         /* class with the geometry of the CT camera */ \
T(qe_file),         /* file with the characteristics of the CT */ \
T(elec_noise_off),  /* de-activates ElecNoise for FADC and Trigger channels */\
T(fadc_pedestal),   /* Pedestal value for FADC */\
T(fadc_noise),      /* ElecNoise for FADC */\
T(trig_noise),      /* ElecNoise for trigger */\
T(sfr_on),          /* starfield rotation */  \
T(nsb_on),          /* activates NSB simulation */ \
T(nsb_off),         /* de-activates NSB simulation */ \
T(nsb_mean),        /* mean value of NSB contribution per pixel */ \
T(nsb_directory),   /* database for the NSB  */ \
T(nsb_dir_outer),   /* database for the NSB  */ \
T(pixel_thres),     /* value of q0 for trigger for a given pixel */ \
T(secure_disc),     /* Ac value to rise discrimnator threshold */ \
T(seeds),           /* seeds for random number generation */ \
T(data_from_stdin), /* to read data from STDIN */ \
T(skip),            /* skip pathological showers */ \
T(no_write_all_event_headers),/* do NOT write to output file all event
				 event headers (only those with trigger!)*/ \
T(nowrite_McEvt),   /* nowrite to file .root McEvt infos */ \
T(write_McTrig),    /* write to file .root McTrig infos */ \
T(write_McFadc),    /* write to file .root McFadc infos */ \
T(nowrite_RawEvt),  /* write to file .root RawData infos */ \
T(select_energy),   /* energy range to read: only for .phe files */ \
T(trigger_scan),    /* show signal in the diskriminator */ \
T(fadc_scan),       /* show fadc signal */ \
T(trigger_loop),    /* make loop over trigger conditions */ \
T(trigger_prop),    /* values of trigger properties */ \
T(fadc_prop),       /* values of fadc properties */ \
T(fadc_outer),      /* values of fadc properties for outer pixels */ \
T(fadc_GHz),        /* FADC sampling frequency (GHz) */ \
T(trigger_single),  /* trigger conditions */ \
T(Trigger_Loop_Output_Only_Specialists),   /* special steercard */ \
T(high_to_low),     /* High to Low gain ratio */ \
T(sigma_xy_cm_spot), /* Additional gaussian spread of mirror spot on camera */ \
T(sigma_x_cm_spot), /* Additional gaussian spread of mirror in x axis spot on camera */ \
T(sigma_y_cm_spot), /* Additional gaussian spread of mirror in y axis spot on camera */ \
T(misspoint_deg),   /* Additional misspointing of Telescope direction*/ \
T(trigger_delay),   /*  Delay in ns between beginning of FADC
                        time window and the trigger instant.*/ \
T(telescope_location_cm), /* Telescope coordinates in Corsika system */ \
T(mirror_fraction), /* Fraction of dish mirror really operative */ \
T(calibration_run), /* option to produce a calibration file */ \
T(gain_fluctuations_off), /* Switches off PMT gain fluctuations for signal */ \
T(noise_gain_fluctuations_off), /* Switches off PMT gain fluctuations for NSB noise */ \
T(pmt_jitter_ns), /* Sets the time jitter of each phe in the PMT */ \
T(end_file)         /* end of the parameters file */

#define T(x)  x             // define T() as the name as it is

enum ITEM_TYPE {
  PM_ITEM_LIST
};

#undef T

#define T(x)  #x              // define T() as the string of x

const char *const ITEM_NAMES[] = {
  PM_ITEM_LIST
};

#undef T

#define LINE_MAX_LENGTH  400
#define ITEM_MAX_LENGTH  40
#define PATH_MAX_LENGTH  256

//!@}

//!@subsection Prototypes of functions.

//!@{

//++
// prototypes
//--

void readparam(char * filename);
char *get_input_filename(int i);
char *get_starfield_filename(void);
void get_starfield_center(int *rh,int *rm,int *rs,int *dd,int *dm,int *ds);
int get_starfield_rotate(void);
char *get_data_filename(void);
char *get_root_filename(void);
char *get_loop_filename(void);
int get_ct_number(void);
int get_ct_geometry(int ict);
char *get_qe_filename(int ict=0);
char *get_nsb_directory(void);
char *get_nsb_directory_outer(void);
int add_elec_noise(float *fadcinner, float* fadcouter, 
		   float *digi, float *trig);
int get_nsb(float *n, int *m);
long int get_seeds(int n);
void get_skip_showers( int *s ); 
int get_nskip_showers( void ); 
int get_data_from_stdin(void);
int get_write_all_event_headers(void);
int get_write_McEvt(void);
int get_write_McTrig(void);
int get_write_McFadc(void);
int get_write_RawEvt(void);
int get_select_energy(float *le, float *ue);
int get_FADC_Scan(void);
int get_Trigger_Scan(void);
void get_Trigger_properties(float *gl, float *ot, float *ra, float *rf);
void get_FADC_properties(int *shape, float *ra, float *rf,int *shapeo, float *rao, float *rfo, 
			 float *fadc_spns, int *fadc_slices);
float get_FADC_pedestal(void);
int get_Trigger_Loop(float *lt, float *ut, float *st, int *lm, int *um, int *lg, int *ug);
void get_Trigger_Single(float **t, int *m, int *g);
void get_threshold(float *t);
void get_secure_threhold(float *ac, float *disc);
int get_indi_thres_pixel(void);
float get_High_to_Low(void);
float get_sigma_xy_cm_spot(float *x, float *y);
int get_misspointing(float *x, float *y);
float get_trig_delay(void);
float get_telescope_location_cm(int j, int icoor);
float get_mirror_fraction(int j);
float get_pmt_jitter_ns();

int   is_calibration_run();
void  get_calibration_properties(float *lambda, float *sigma_lambda, float *phot_per_pix,
 				 float *sigma_time, int *nevents, int *selected_pixel);
int   apply_gain_fluctuations();
int   apply_noise_gain_fluctuations();
//!@}

//!@{

#endif // ! _creadparam_

//!@}

//=------------------------------------------------------------
//!@subsection Log of this file.

//!@{

/*
 * $Log: not supported by cvs2svn $
 * Revision 1.32  2005/02/10 19:28:10  moralejo
 *
 * Substituted input card option "write_all_events" by
 * "write_all_event_headers". If set, this will make camera to write out
 * the event headers of all the processed events, no matter whether they
 * have triggered or not.
 *
 * Revision 1.31  2004/12/15 01:56:39  MAGIC
 *
 *  Added input card option pmt_jitter_ns to simulate the time jitter of
 *  PMTs. The input parameter is the sigma of a gaussian, which by
 *  default is sigma=0.25 ns. This jitter is applied to each phe-
 *  independently. We have not applied this to the NSB noise, since the
 *  arrival time of NSB photons is random and nothing would change.
 *
 * Revision 1.30  2004/11/17 11:36:07  moralejo
 * *** empty log message ***
 *
 * Revision 1.29  2004/10/26 13:58:59  moralejo
 *
 * Added option gain_fluctuations_off
 *
 * Revision 1.28  2004/10/13 17:05:05  moralejo
 * *** empty log message ***
 *
 * Revision 1.27  2004/10/12 13:32:02  moralejo
 * *** empty log message ***
 *
 * Revision 1.26  2004/09/17 14:48:21  moralejo
 *
 * Changes to adapt headers to c++ style.
 *
 * Revision 1.25  2004/09/16 15:27:08  moralejo
 * Updated in CVS after some time (see changes below)
 *
 *
 * Revision 1.23  2004/01/30 09:55:33  blanch
 * New "trigger_delay" and "sigma_xy_cm_spot" commands.
 *
 * Revision 1.22  2003/10/26 19:51:30  blanch
 * Header file for creadparam.cxx version 1.25
 *
 * Revision 1.21  2003/10/17 19:40:47  blanch
 * *** empty log message ***
 *
 * Revision 1.20  2003/09/23 17:38:59  blanch
 * *** empty log message ***
 *
 * Revision 1.19  2003/09/23 16:52:43  blanch
 * Header file for creadparam.cxx 1.22
 *
 * Revision 1.18  2003/09/15 10:23:31  blanch
 * Hedaer file for creadparam.cxx 1.21
 *
 * Revision 1.17  2003/07/17 18:05:13  blanch
 * Header file for creadparam.cxx 1.20
 *
 * Revision 1.16  2003/01/14 13:37:32  blanch
 * Option to set a dc value to rise the discriminator threshold has been added.
 *
 * Revision 1.15  2002/07/16 16:20:59  blanch
 * Modifications done for the camera.cxx version, where a first implementation
 * of the Star Field Rotation has been introduced.
 *
 * Revision 1.14  2002/03/15 15:17:57  blanch
 * Header file for creadparam.cxx v 1.16
 *
 * Revision 1.13  2002/03/04 17:20:50  blanch
 * Header file for creadparam.cxx 1.15
 *
 * Revision 1.12  2002/02/28 15:08:01  blanch
 * Header file for creadparam.cxx 1.14.
 *
 * Revision 1.11  2002/01/18 17:45:37  blanch
 * Header file for creadparam.cxx 1.13.
 *
 * Revision 1.10  2001/11/13 17:06:01  blanch
 * Header file for creadparam.cxx version 1.12
 *
 * Revision 1.9  2001/07/19 09:29:02  blanch
 * Header file for creadparam.cxx vrsion 1.10
 *
 * Revision 1.8  2001/03/05 10:44:44  blanch
 * Header file of creadparam.cxx version 1.9
 *
 * Revision 1.7  2001/02/23 10:56:10  magicsol
 * Header file for creadparam.cxx version 1.8
 *
 * Revision 1.6  2001/01/15 12:38:00  magicsol
 * *** empty log message ***
 *
 * Revision 1.5  2000/07/04 14:13:34  MagicSol
 * *** empty log message ***
 *
 * Revision 1.4  2000/05/11 14:23:28  blanch
 * Thi version owns to the version 1.4 of creadparam.cxx.
 *
 * Revision 1.3  2000/03/24 18:15:46  blanch
 * *** empty log message ***
 *
 * Revision 1.2  2000/02/18 17:50:07  petry
 * This version belongs to camera.cxx 1.5.
 * It version has been put in the repository in order to be
 * able to share the further development with others.
 *
 * If you need something working, wait or take an earlier one.
 * See file README
 *
 * Revision 1.1.1.1  1999/11/05 11:59:34  harald
 * This the starting point for CVS controlled further developments of the
 * camera program. The program was originally written by Jose Carlos. 
 * But here you can find a "rootified" version to the program. This means 
 * that there is no hbook stuff in it now. Also the output of the
 * program changed to the MagicRawDataFormat. 
 *
 * The "rootification" was done by Dirk Petry and Harald Kornmayer. 
 *
 * Revision 1.2  1999/10/22 15:01:29  petry
 * version sent to H.K. and N.M. on Fri Oct 22 1999
 *
 * Revision 1.1.1.1  1999/10/21 16:35:11  petry
 * first synthesised version
 *
 * Revision 1.7  1999/03/15  14:59:09  gonzalez
 * camera-1_1
 *
 * Revision 1.6  1999/03/02  09:56:13  gonzalez
 * *** empty log message ***
 *
 * Revision 1.5  1999/01/14  17:32:43  gonzalez
 * Added to camera the STDIN input option (data_from_input)
 *
 */

//!@}
//=EOF
