Ignore:
Timestamp:
09/16/04 16:16:34 (20 years ago)
Author:
moralejo
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Simulation/Detector/Camera/creadparam.cxx

    r2965 r5072  
    1919//=
    2020//= $RCSfile: creadparam.cxx,v $
    21 //= $Revision: 1.26 $
    22 //= $Author: blanch $
    23 //= $Date: 2004-01-30 09:58:39 $
     21//= $Revision: 1.27 $
     22//= $Author: moralejo $
     23//= $Date: 2004-09-16 15:16:34 $
    2424//=
    2525//=//////////////////////////////////////////////////////////////////////
     
    5454
    5555#include "creadparam.h"
     56#include "camera.h"      // Needed for MAX_NUMBER_OF_CTS
    5657
    5758//!@}
     
    6869//!@{
    6970
    70 static char Input_filename[100][PATH_MAX_LENGTH];  //@< input filename
     71static char **Input_filename;  //@< input filename
    7172static char Starfield_filename[PATH_MAX_LENGTH]; //@< starfield input filename
    7273static int Starfield_center[6]={0,0,0,0,0,0}; //@< center of the starfield FOV
     
    7576static char ROOT_filename[PATH_MAX_LENGTH];   //@< data filename
    7677static char Loop_filename[PATH_MAX_LENGTH];   //@< special data filename
    77 static int  CT_geometry = 0;                  //@< CT camera geometry
     78static char CT_geom_string[256];              //@< Contains geometry ids of CTs 
    7879static int  CT_number = 1;                    //@< Number of CT
    79 static char QE_filename[100][PATH_MAX_LENGTH];    //@< name of the qe file
     80static char **QE_filename; //@< name of the qe file
    8081static char NSB_directory[PATH_MAX_LENGTH];   //@< database for NSB
    8182static char NSB_outer_directory[PATH_MAX_LENGTH];   //@< database for NSB
     
    8384static int ElecNoise = TRUE;                  //@< Will we add ElecNoise?
    8485static float FADC_pedestal = 10.0;            //@< Value for FADC Pedestal
    85 static float FADC_Noise = 2.0;                //@< Value for FADC ElecNoise
     86static float FADC_Noise_inner = 2.0;         //@< Value for FADC ElecNoise
     87static float FADC_Noise_outer = 2.0;         //@< Value for FADC ElecNoise
    8688static float Digital_Noise = 1.0;            //@< Value for FADC  digital Noise
    8789static float Trig_Noise = 0.3;                //@< Factor for Trigger ElecNoise
     
    8991static float meanNSB;           //@< NSB mean value (per pixel)
    9092static int nphe2NSB=0;          //@< Number of phe from shower to do NSB simulation
    91 static float qThreshold[100][CAMERA_PIXELS];    //@< Threshold values
     93static float **qThreshold; //@< Threshold values
    9294static int Individual_Thres = FALSE;
    9395static float RiseDisc = -1.0;
     
    112114static float Trigger_response_ampl = 1.0;
    113115static float Trigger_response_fwhm = 2.0;
    114 static float Trigger_threshold[100];
    115 static int Trigger_multiplicity[100];
    116 static int Trigger_topology[100];
     116static float Trigger_threshold[MAX_NUMBER_OF_CTS];
     117static int Trigger_multiplicity[MAX_NUMBER_OF_CTS];
     118static int Trigger_topology[MAX_NUMBER_OF_CTS];
    117119static float Trigger_loop_lthres = 3.0;
    118120static float Trigger_loop_uthres = 10.0;
     
    122124static int Trigger_loop_ltop = 0;
    123125static int Trigger_loop_utop = 2;
     126static int FADC_shape = 0;
    124127static float FADC_response_ampl = MFADC_RESPONSE_INTEGRAL;
    125128static float FADC_response_fwhm = MFADC_RESPONSE_FWHM;
     129static int FADC_shape_out = 0;
    126130static float FADC_resp_ampl_out = MFADC_RESPONSE_INTEGRAL;
    127131static float FADC_resp_fwhm_out = MFADC_RESPONSE_FWHM;
    128132static float High_to_Low = 10.0;      //@< Low gain channel respct to High
    129 static float Source_offset_th=0.;     //@<  Displacement in Theta of the
    130                                       //@< source from the center
    131 static float Source_offset_ph=0.;     //@<  Displacement in Phi of the
    132                                       //@< source from the center
    133 
    134 static float sigma_spot = -1.; // Sigma in x and y for additional
    135                                // gaussian spread of the mirror spot.
     133
     134static float sigma_x_spot = 0.; // Sigma in x and y (cm) for additional
     135static float sigma_y_spot = 0.; // gaussian spread of the mirror spot.
     136                               
     137static float misp_x = 0.; // Mispointing in x
     138static float misp_y = 0.; // Mispointing in y
    136139
    137140static float trig_delay = 25.;  // Delay in ns between beginning of FADC
    138141                                // time window and the trigger instant.
    139142
     143static float CTcoor[MAX_NUMBER_OF_CTS][3];
     144
     145static float m_fraction[MAX_NUMBER_OF_CTS];
     146
     147// Coordinates of CT locations, in centimeters, in the Corsika system.
    140148
    141149//!@}
     
    162170  char token[ITEM_MAX_LENGTH];   //@< a single token
    163171  int i, j, k;                      //@< dummy counters
    164   float aux, aux2;                    //@< auxiliar variable
     172  float aux, aux1, aux2;                    //@< auxiliar variable
    165173  int aux3, aux4;                    //@< auxiliar variable
    166174  ifstream ifile;
    167175  char filename_tmp[PATH_MAX_LENGTH];
     176
     177
     178  memset((char*)CT_geom_string, 0, sizeof(CT_geom_string));
     179
     180  Input_filename = new char *[MAX_NUMBER_OF_CTS];
     181  QE_filename = new char *[MAX_NUMBER_OF_CTS];
     182  qThreshold = new float *[MAX_NUMBER_OF_CTS];
     183
     184  for (int i = 0; i < MAX_NUMBER_OF_CTS; i++)
     185    {
     186      Input_filename[i] = new char[PATH_MAX_LENGTH];
     187      QE_filename[i] = new char[PATH_MAX_LENGTH];
     188      qThreshold[i] = new float[CAMERA_PIXELS];
     189      CTcoor[i][0] = 0.; CTcoor[i][1] = 0.; CTcoor[i][2] = 0.;
     190      m_fraction[i] = 1.;
     191    }
     192
    168193  // use cin or ifile (reading from STDIN or from parameters file?
    169194  if ( filename != NULL )
     
    259284      break;
    260285
    261     case ct_num:             //@< name of the telescope file
     286    case ct_num:             //@< number of telescopes
    262287         
    263288      // get the name of the ct_file from the line
     
    269294         
    270295      // get the name of the ct_file from the line
    271       sscanf(line, "%s %i", token, &CT_geometry);
     296      sscanf(line, "%s %s", token, CT_geom_string);
     297      if ( strlen(CT_geom_string) > MAX_NUMBER_OF_CTS )
     298        {
     299          printf("\nError: ct_geom option read from input card wrong:\n");
     300          printf("Number of digits (%d) is larger than maximum number\n",strlen(CT_geom_string) );
     301          printf("of allowed telescopes (%d). Exiting.\n\n", MAX_NUMBER_OF_CTS);
     302          exit(1);
     303        }
    272304
    273305      break;
     
    285317      // we will not add electronic noise for FADC and Trigger channels.
    286318      ElecNoise = FALSE;
    287       FADC_Noise = 0.0;
     319      FADC_Noise_inner = 0.0;
     320      FADC_Noise_outer = 0.0;
    288321      Trig_Noise =0.0;
    289322
    290323      break;
    291324
    292     case fadc_pedestal:              //@< FADC ElecNoise
     325    case fadc_pedestal:              //@< FADC pedestal
    293326         
    294327      // value for FADC Pedestal
     
    311344      break;
    312345
    313     case high_to_low:              //@< FADC ElecNoise
     346    case high_to_low:              //@< High to Low gain ratio
    314347         
    315348      // Value for the Low Gain channel respect to the High gain
     
    321354         
    322355      // value for FADC Elec Noise
    323       sscanf(line, "%s %f %f", token, &FADC_Noise, &Digital_Noise);
     356      sscanf(line, "%s %f %f %f", token,
     357             &FADC_Noise_inner, &FADC_Noise_outer,
     358             &Digital_Noise);
    324359
    325360      ElecNoise = TRUE;
     
    479514
    480515      //  Get parameters for the fadc  response for one phe
    481       sscanf(line, "%s %f %f", token, &FADC_response_ampl,&FADC_response_fwhm);
     516      sscanf(line, "%s %i %f %f", token, &FADC_shape, &FADC_response_ampl,&FADC_response_fwhm);
    482517
    483518      break;
     
    486521
    487522      //  Get parameters for the fadc  response for one phe
    488       sscanf(line, "%s %f %f", token, &FADC_resp_ampl_out,&FADC_resp_fwhm_out);
     523      sscanf(line, "%s %i %f %f", token, &FADC_shape_out, &FADC_resp_ampl_out,&FADC_resp_fwhm_out);
    489524
    490525      break;
     
    545580      break;
    546581
    547     case source_offset:
    548 
    549       //  Get offset of source
    550         sscanf(line, "%s %f %f", token, &Source_offset_th, &Source_offset_ph);
    551 
    552       break;
    553 
    554582    case Trigger_Loop_Output_Only_Specialists:
    555583
     
    563591      break;
    564592
     593    case trigger_delay:
     594
     595      sscanf(line, "%s %f", token, &trig_delay);
     596      break;
     597
     598
    565599    case sigma_xy_cm_spot:
    566600
    567       sscanf(line, "%s %f", token, &sigma_spot);
    568       break;
    569 
    570     case trigger_delay:
    571 
    572       sscanf(line, "%s %f", token, &trig_delay);
    573       break;
     601      sscanf(line, "%s %f", token, &sigma_x_spot);
     602      sigma_y_spot=sigma_x_spot;
     603      break;
     604
     605    case sigma_x_cm_spot:
     606
     607      sscanf(line, "%s %f", token, &sigma_x_spot);
     608      break;
     609
     610    case sigma_y_cm_spot:
     611
     612      sscanf(line, "%s %f", token, &sigma_y_spot);
     613      break;
     614
     615    case misspoint_deg:
     616
     617      sscanf(line, "%s %f %f", token, &misp_x, &misp_y);
     618      break;
     619
     620    case telescope_location_cm:
     621
     622      if ( 5 != sscanf(line, "%s %d %f %f %f", token, &j, &aux, &aux1, &aux2) )
     623        {
     624          printf("\nError: wrong number of arguments for command telescope_location_cm.\n");
     625          printf("Usage: telescope_location_cm ct_id x y z\n");
     626          printf("Coordinates must be written in centimeters.");
     627          printf("Exiting.\n\n");
     628          exit(1);
     629        }
     630
     631      if (j >= MAX_NUMBER_OF_CTS)
     632        {
     633          printf("\nError: coordinates were supplied for a telescope index (%d)\n", j);
     634          printf("larger than allowed. Valid telescope ids range from 0 to %d. Exiting.\n\n", MAX_NUMBER_OF_CTS-1);
     635          exit(1);
     636        }
     637      CTcoor[j][0] = aux;
     638      CTcoor[j][1] = aux1;
     639      CTcoor[j][2] = aux2;
     640
     641      break;
     642
     643    case mirror_fraction:
     644
     645        sscanf(line, "%s %d %f", token, &j, &aux);
     646        m_fraction[j] = aux;
     647       
     648        break;
    574649
    575650    case end_file:            //@< end of the parameters file
     
    761836//!@{
    762837int
    763 get_ct_geometry(void)
    764 {
    765   return (CT_geometry);
     838get_ct_geometry(int ict)
     839{
     840  char dummy[2];
     841  strncpy(dummy, &(CT_geom_string[ict]), 1);
     842  dummy[1] = '\0';
     843
     844  return ((int)atoi(dummy));
    766845}
    767846//!@}
     
    839918//!@{
    840919int
    841 add_elec_noise(float *fadc, float *digi, float *trig)
    842 {
    843   *fadc = FADC_Noise;
     920add_elec_noise(float *fadcinner, float*fadcouter, float *digi, float *trig)
     921{
     922  *fadcinner = FADC_Noise_inner;
     923  *fadcouter = FADC_Noise_outer;
     924
    844925  *digi = Digital_Noise;
    845926  *trig = Trig_Noise;
     
    11741255//!@{
    11751256void
    1176 get_FADC_properties(float *ra, float *rf, float *rao, float *rfo)
    1177 {
     1257get_FADC_properties(int *shape,float *ra, float *rf,
     1258                    int *shapeo, float *rao, float *rfo)
     1259{
     1260  *shape=FADC_shape;
    11781261  *ra=FADC_response_ampl;
    11791262  *rf=FADC_response_fwhm;
     1263  *shapeo=FADC_shape_out;
    11801264  *rao=FADC_resp_ampl_out;
    11811265  *rfo=FADC_resp_fwhm_out;
     
    12411325get_Trigger_Single(float **t, int *m, int *g)
    12421326{
    1243   for(int j=0;j<100;j++){
     1327  for(int j=0;j<MAX_NUMBER_OF_CTS;j++){
    12441328    for(int i=0;i<CAMERA_PIXELS;i++)
    12451329      t[j][i]=qThreshold[j][i];
     
    12511335
    12521336//!-----------------------------------------------------------
    1253 // @name get_source_off
    1254 //                                               
    1255 // @desc give the offset of the source to the center of the camera
    1256 //
    1257 //------------------------------------------------------------
    1258 // @function
    1259 
    1260 //!@{
    1261 void get_source_off(float *th, float *p){
    1262     *th=Source_offset_th;
    1263     *p=Source_offset_ph;
    1264 }
    1265 //!@}
    1266 
    1267 //!-----------------------------------------------------------
    12681337// @name get_FADC_pedesta
    12691338//                                               
     
    13001369}
    13011370
    1302 float get_sigma_xy_cm_spot(void){
    1303 
    1304   return sigma_spot;
     1371int get_misspointing(float *x, float *y){
     1372
     1373  *x=misp_x;
     1374  *y=misp_y;
     1375
     1376  if (misp_x == 0.0 && misp_y==0.0)
     1377    return 0;
     1378  else
     1379    return 1;
     1380
     1381}
     1382
     1383float get_sigma_xy_cm_spot(float *x, float *y){
     1384
     1385  *x=sigma_x_spot;
     1386  *y=sigma_y_spot;
     1387
     1388  if (sigma_x_spot > 0.0 || sigma_y_spot >0.0)
     1389    return 1.0;
     1390  else
     1391    return -1.0;
    13051392
    13061393}
     
    13111398
    13121399}
     1400
     1401float get_telescope_location_cm(int j, int icoor){
     1402
     1403  return CTcoor[j][icoor];
     1404
     1405}
     1406
     1407float get_mirror_fraction(int j){
     1408    return m_fraction[j];
     1409}
     1410
     1411
    13131412
    13141413//!@}
     
    13191418//
    13201419// $Log: not supported by cvs2svn $
     1420//
     1421// Revision 1.27  2004/05/12 A. Moralejo
     1422//
     1423// Changed fadc_noise command: now the two first numbers are respectively
     1424// the analogic electronic noise for inner (small) and outer (big) pixels
     1425// respectively. Last number is still the FADC digital noise which affects
     1426// equallly inner and outer pixels (as well as high and low gain).
     1427//
     1428// Revision 1.26  2004/01/30 09:58:39  blanch
     1429// [Changes done mainly by A. Moralejo]
     1430//
     1431// Two new commands of the input card have been added:
     1432//
     1433// sigma_xy_cm_spot: to enlarge the point spread function.
     1434// trigger_delay: to center the FADC signal
     1435//
     1436// There is also a check that the Pedestal is an integer, otherwise it
     1437// becames complex to get a reasonable rms for events without electronic noise.
     1438//
    13211439// Revision 1.25  2003/10/26 19:45:38  blanch
    13221440// The write_all_data input card command has been removed.
Note: See TracChangeset for help on using the changeset viewer.