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/camera.cxx

    r3044 r5072  
    2121//
    2222// $RCSfile: camera.cxx,v $
    23 // $Revision: 1.68 $
    24 // $Author: blanch $
    25 // $Date: 2004-02-06 17:39:24 $
     23// $Revision: 1.69 $
     24// $Author: moralejo $
     25// $Date: 2004-09-16 15:16:34 $
    2626//
    2727////////////////////////////////////////////////////////////////////////
     
    8484#include "MGeomCamCT1Daniel.h"
    8585#include "MGeomPix.h"
     86#include "MGeomCorsikaCT.h"
    8687
    8788/*!@"
     
    151152static int ct_Number;       
    152153
    153 //@: Camera geometries
    154 static int ct_Geometry;       
    155 
    156154//@: list of showers to be skipped
    157155static int *Skip;
     
    200198
    201199//@: Properties of the FADC
    202 static float FADC_response_ampl = MFADC_RESPONSE_INTEGRAL;
     200static int FADC_shape = 0;
     201static float FADC_response_integ = MFADC_RESPONSE_INTEGRAL;
    203202static float FADC_response_fwhm = MFADC_RESPONSE_FWHM;
    204 static float FADC_resp_ampl_out = MFADC_RESPONSE_INTEGRAL;
     203static int FADC_shape_out = 0;
     204static float FADC_resp_integ_out = MFADC_RESPONSE_INTEGRAL;
    205205static float FADC_resp_fwhm_out = MFADC_RESPONSE_FWHM;
    206 static float FADC_noise = 2.0;
     206static float FADC_noise_inner = 2.0;
     207static float FADC_noise_outer = 2.0;
    207208static float DIGITAL_noise = 2.0;
    208209static float FADC_high2low = HIGH2LOWGAIN;
     
    210211//@: Trigger conditions for a single trigger mode
    211212static float **qThreshold; 
    212 static int Trigger_multiplicity[100];
    213 static int Trigger_topology[100];
     213static int Trigger_multiplicity[MAX_NUMBER_OF_CTS];
     214static int Trigger_topology[MAX_NUMBER_OF_CTS];
    214215
    215216//@: Upper and lower edges of the trigger loop
     
    222223static int Trigger_loop_utop = 2;
    223224
     225//@: Direction of each shower
     226static  float Zenith = 0.0;
     227static  float Azimutal = 90.0;
     228
     229//@: Miss Pointing Simulation
     230static   int missPointing = 0;
     231static   float missP_x = 0.0;
     232static   float missP_y = 0.0;
     233
     234//@: Point Spread Function Added
     235static  float Spot_x=0.0;
     236static  float Spot_y=0.0;
     237static  float Spotsigma=0.0;
     238
     239 
    224240//!@}
    225241
     
    259275
    260276//@: number of datapoints for the QE curve
    261 static int pointsQE[100];
     277static int pointsQE[MAX_NUMBER_OF_CTS];
    262278
    263279//@: table of QE
    264280static float *QElambda;
    265281
    266 //@: table of lightguide = WC;
     282//@: table of lightguide = WC;  WC_outer for outer pixels.
    267283static float **WC;
     284static float **WC_outer;
    268285
    269286//@: number of datapoints for the WC curve
     
    313330  //@'
    314331
    315   char inname_CT[100][256];   //@< array of names for each CT input file
     332  char **inname_CT;   //@< array of names for each CT input file
    316333  char starfieldname[256];    //@< starfield input file name
    317334  char qe_filename[256];       //@< qe input file name
     
    328345
    329346  char flag[SIZE_OF_FLAGS + 1];  //@< flags in the .rfl file
    330   char flag_new[SIZE_OF_FLAGS + 1];              //@< New flag for the run header in the .rfl file
    331   char GeometryName[100][50];            //@< Name of MGeomCam for each CT
    332   int GeometryCamera[100];           //@< Identification of MGeomCam for each CT
    333   int TriggerPixels[100];          //@< Number of pixels in the trigger region for each CT
     347  char flag_new[SIZE_OF_FLAGS + 1];  //@< New flag for the run header in the .rfl file
     348  char **GeometryName;   //@< Name of MGeomCam for each CT
     349  int GeometryCamera[MAX_NUMBER_OF_CTS];  //@< Identification of MGeomCam for each CT
     350  int TriggerPixels[MAX_NUMBER_OF_CTS]; //@< Number of pixels in the trigger region for each CT
    334351
    335352  int reflector_file_version=0;  //@< vrsion of he reflector file
    336353
    337   FILE *inputfile[100];            //@< stream for the input file
     354  FILE *inputfile[MAX_NUMBER_OF_CTS]; //@< stream for the input file
    338355
    339356  ofstream datafile;          //@< stream for the data file
    340357
    341358  MCRunHeader mcrunh;                //@< Run Header class (MC)
    342   MCEventHeader mcevth[100];      //@< Event Header class (MC)
    343   MCEventHeader_2 mcevth_2[100];   //@< Event Header class (MC) for reflector > 0.6
     359  MCEventHeader mcevth[MAX_NUMBER_OF_CTS]; //@< Event Header class (MC)
     360  MCEventHeader_2 mcevth_2[MAX_NUMBER_OF_CTS];   //@< Event Header class (MC) for reflector > 0.6
    344361  MCCphoton cphoton;          //@< Cherenkov Photon class (MC)
    345362
    346363  int inumphe;                //@< number of photoelectrons in an event from showers
    347   int inumphe_CT[100];        //@< number of photoelectrons in an event from showers
    348   float inumphensb[100];             //@< number of photoelectrons in an event from nsb
     364  int inumphe_CT[MAX_NUMBER_OF_CTS]; //@< number of photoelectrons in an event from showers
     365  float inumphensb[MAX_NUMBER_OF_CTS];  //@< number of photoelectrons in an event from nsb
    349366
    350367  float arrtmin_ns;           //@ arrival time of the first photoelectron
    351368  float arrtmax_ns;           //@ arrival time of the last photoelectron
    352369
    353   float thetaCT[100], phiCT[100];       //@< parameters of a given shower
     370  float thetaCT[MAX_NUMBER_OF_CTS], phiCT[MAX_NUMBER_OF_CTS];  //@< theta and phi of telescopes
     371
     372  //@: Coordinates of telescopes in Corsika's coordinate system
     373  float CTx[MAX_NUMBER_OF_CTS];
     374  float CTy[MAX_NUMBER_OF_CTS];
     375  float CTz[MAX_NUMBER_OF_CTS];
     376
     377  float mirror_frac[MAX_NUMBER_OF_CTS];
     378
    354379  float thetashw, phishw;     //@< parameters of a given shower
    355380  float coreX, coreY;         //@< core position
    356   float impactD[100];              //@< impact parameter
     381  float impactD[MAX_NUMBER_OF_CTS];  //@< impact parameter
    357382  float l1, m1, n1;           //@< auxiliary variables
    358   float l2, m2, n2;           //@< auxiliary variables
    359   float num, den;      //@< auxiliary variables
    360   float factorqe_NSB[100];          //@< factor on the NSB depending of QE
     383  float factorqe_NSB[MAX_NUMBER_OF_CTS]; //@< factor on the NSB depending of QE
    361384
    362385  int nshow=0;                //@< partial number of shower in a given run
    363386  int ntshow=0;               //@< total number of showers
    364   int ncph[100];            //@< partial number of photons in a given run
    365   int ntcph[100];                //@< total number of photons
     387  int ncph[MAX_NUMBER_OF_CTS];  //@< partial number of photons in a given run
     388  int ntcph[MAX_NUMBER_OF_CTS]; //@< total number of photons
    366389
    367390  int ibr, j, k;                //@< simple counters
     
    375398  int nphe2NSB;               //@< From how many phe will we simulate NSB?
    376399  float meanNSB;              //@< diffuse NSB mean value (phe per ns per central pixel)
    377   float diffnsb_phepns[100][iMAXNUMPIX];  //@< diffuse NSB values for each pixel 
    378                                      //@< derived from meanNSB
    379   float nsbrate_phepns[iMAXNUMPIX][iNUMWAVEBANDS];    //@< non-diffuse nsb
    380                                                      //@< photoelectron rates
    381   float nsb_phepns[100][iMAXNUMPIX];                 //@< NSB values for each pixel
    382   float nsb_phepns_rotated[100][iMAXNUMPIX];         //@< NSB values for each pixel after rotation
     400  float **diffnsb_phepns; 
     401  //@< diffuse NSB values for each pixel derived from meanNSB
     402
     403  float **nsbrate_phepns;  //@< non-diffuse nsb
     404                                                    //@< photoelectron rates
     405  float **nsb_phepns;
     406  //@< NSB values for each pixel
     407
     408  float **nsb_phepns_rotated;
     409  //@< NSB values for each pixel after rotation
    383410
    384411  Float_t nsb_trigresp[TRIGGER_TIME_SLICES];    //@< array to write the trigger
     
    406433  int flagstoring = 0;
    407434
    408   int ntrigger[100];           //@< number of triggers in the whole file
     435  int ntrigger[MAX_NUMBER_OF_CTS];  //@< number of triggers in the whole file
    409436  int btrigger = 0;           //@< trigger flag
    410437  int ithrescount;            //@< counter for loop over threshold trigger
     
    435462  Float_t telestheta = 0.0;
    436463  Float_t telesphi = 0.0;
    437   Float_t sofftheta = 0.0;
    438   Float_t soffphi = 0.0;
    439464  UInt_t corsika = 5200 ;
    440465  Float_t maxpimpact = 0.0;
     
    453478  //@'
    454479
    455   qThreshold = new float *[100];
    456   for(int i=0;i<100;i++)
     480  inname_CT = new char *[MAX_NUMBER_OF_CTS];
     481  GeometryName = new char *[MAX_NUMBER_OF_CTS];
     482  diffnsb_phepns = new float *[MAX_NUMBER_OF_CTS];
     483  nsb_phepns = new float *[MAX_NUMBER_OF_CTS];
     484  nsb_phepns_rotated = new float *[MAX_NUMBER_OF_CTS];
     485
     486  for(int i=0;i<MAX_NUMBER_OF_CTS;i++)
     487    {
     488      inname_CT[i] = new char[256];
     489      GeometryName[i] = new char[50];
     490      diffnsb_phepns[i] = new float[iMAXNUMPIX];
     491      nsb_phepns[i] = new float[iMAXNUMPIX];
     492      nsb_phepns_rotated[i] = new float[iMAXNUMPIX];
     493      CTx[i] = 0.; CTy[i] = 0.; CTz[i] = 0.;
     494    }
     495
     496  nsbrate_phepns = new float *[iMAXNUMPIX];
     497  for(int i=0;i<iMAXNUMPIX;i++)
     498    nsbrate_phepns[i] = new float[iNUMWAVEBANDS];
     499   
     500  qThreshold = new float *[MAX_NUMBER_OF_CTS];
     501  for(int i=0;i<MAX_NUMBER_OF_CTS;i++)
    457502    qThreshold[i] = new float [CAMERA_PIXELS];
    458503
    459504  for(int i=0;i<iMAXNUMPIX;i++){
    460     for(int ict=0;ict<100;ict++){     
     505    for(int ict=0;ict<MAX_NUMBER_OF_CTS;ict++){     
    461506      nsb_phepns[ict][i]=0;
    462507      nsb_phepns_rotated[ict][i]=0;
     
    465510      nsbrate_phepns[i][j]=0.0;    //@< Starlight rates initialised at 0.0
    466511  }
    467   for(int i=0;i<100;i++)
     512  for(int i=0;i<MAX_NUMBER_OF_CTS;i++)
    468513    ntcph[i]=0;
    469514  /*!@'
     
    527572
    528573  ct_Number=get_ct_number();
    529   ct_Geometry=get_ct_geometry();
     574  if (ct_Number > MAX_NUMBER_OF_CTS)
     575    {
     576      error( SIGNATURE, "Number of telescopes is larger than maximum allowed (%i). Stoping camera program ...", MAX_NUMBER_OF_CTS);
     577      exit(1);
     578    }
    530579
    531580  for(int ict=0;ict<ct_Number;ict++){
    532581    ntrigger[ict]=0;
    533     if(ct_Geometry>=ict*10){
    534       GeometryCamera[ict]=int(ct_Geometry/pow(10.0,ict))%10;
    535     }
    536     else
    537       GeometryCamera[ict]=0;
     582    GeometryCamera[ict]=get_ct_geometry(ict);
     583
     584    //
     585    // Get telescope coordinates (if supplied) from  input card (units cm).
     586    //
     587    CTx[ict] = get_telescope_location_cm(ict,0);
     588    CTy[ict] = get_telescope_location_cm(ict,1);
     589    CTz[ict] = get_telescope_location_cm(ict,2);
     590
     591    //
     592    // Get fraction of operative mirror:
     593    //
     594    mirror_frac[ict] = get_mirror_fraction(ict);
    538595  }
    539596
     
    615672  get_secure_threhold(&riseDiskThres,&secureDiskThres);
    616673
    617   get_FADC_properties( &FADC_response_ampl, &FADC_response_fwhm,
    618                        &FADC_resp_ampl_out, &FADC_resp_fwhm_out);
     674  get_FADC_properties
     675    (&FADC_shape, &FADC_response_integ, &FADC_response_fwhm,
     676     &FADC_shape_out, &FADC_resp_integ_out, &FADC_resp_fwhm_out);
     677
    619678  FADC_high2low=get_High_to_Low();
    620679
    621   // FIXME --- tirgger properties may depend on the Camrea geometry
     680  // FIXME --- trigger properties may depend on the Camera geometry
    622681
    623682  get_Trigger_properties( &Trigger_gate_length, &Trigger_overlaping_time, &Trigger_response_ampl, &Trigger_response_fwhm);
     
    630689    (Trigger_loop_utop-Trigger_loop_ltop+1);
    631690
    632   // Trigger loop operation is not implemented for Multi telscopes
     691  // Trigger loop operation is not implemented for Multi telescopes
    633692
    634693  if ( Trigger_Loop && ct_Number > 1 ){
     
    651710
    652711  for(int ict=0;ict<ct_Number;ict++)
    653     strcpy( inname_CT[ict], get_input_filename(ict) );
     712    {
     713      strcpy( inname_CT[ict], get_input_filename(ict) );
     714      if (strlen(inname_CT[ict]) == 0)
     715        {
     716          printf("\nError: missing input file name for CT id = %d. Exiting.\n\n", ict);
     717          exit(1);
     718        }
     719    }
    654720
    655721  strcpy( starfieldname, get_starfield_filename() );
     
    662728  // get different parameters of the simulation
    663729
    664   addElecNoise = add_elec_noise(&FADC_noise, &DIGITAL_noise, &Trigger_noise);
     730  addElecNoise = add_elec_noise(&FADC_noise_inner, &FADC_noise_outer, &DIGITAL_noise, &Trigger_noise);
    665731  simulateNSB = get_nsb( &meanNSB, &nphe2NSB ); 
     732  missPointing = get_misspointing(&missP_x,&missP_y);
     733  Spotsigma = get_sigma_xy_cm_spot(&Spot_x,&Spot_y);
    666734
    667735
     
    681749        "Geometry ", GeometryName[ict]);
    682750    strcpy( qe_filename, get_qe_filename(ict));
     751
     752    printf("Telescope coordinates (cm): %.1f %.1f %.1f\n", CTx[ict], CTy[ict], CTz[ict]);
    683753
    684754    // Look to factor for NSB respect to emi_coat PMTs
     
    748818 
    749819  log(SIGNATURE,
    750       "%s:\n\t%20s: %s\n\t%20s: %s\n\t%20s: %s\n\t%20s: %3.2f(%s) %3.2f+%3.2f(%s) %s\n",
     820      "%s:\n\t%20s: %s\n\t%20s: %s\n\t%20s: %s\n\t%20s: %s %3.2f, %s %3.2f (%s), %3.2f (%s) + %3.2f (%s) %s\n",
    751821      "Flags",
    752822      "Data_From_STDIN",   ONoff(Data_From_STDIN), 
    753823      "Write_All_Events",  ONoff(Write_All_Images),
    754824      "Rotate Starfield",  ONoff(Starfield_rotate),
    755       "Electronic Noise",  Trigger_noise,"trigger",
    756       FADC_noise,DIGITAL_noise,"fadc",ONoff(addElecNoise)
     825      "Electronic Noise",  "trigger (rel. noise): ", Trigger_noise,
     826      "FADC (ADC counts): ", FADC_noise_inner, "inner pixels",
     827      FADC_noise_outer, "outer pixels",
     828      DIGITAL_noise, "added digital noise at FADC", ONoff(addElecNoise)
    757829      );
    758830
     
    779851
    780852  ntriggerloop= new int ** [(int)((Trigger_loop_uthres-Trigger_loop_lthres)
    781                            /Trigger_loop_sthres)];
     853                           /Trigger_loop_sthres)+1];
    782854  for (ithrescount=0, fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;fthrescount+=Trigger_loop_sthres, ithrescount++){
    783855    ntriggerloop[ithrescount]= new int * [Trigger_loop_umult-Trigger_loop_lmult+1];
     
    821893
    822894  Int_t Lev0, Lev1;
    823   Int_t Lev0MT[100], Lev1MT[100];
     895  Int_t Lev0MT[MAX_NUMBER_OF_CTS], Lev1MT[MAX_NUMBER_OF_CTS];
    824896 
    825897  fadcValues    =  new TArrayC(FADC_SLICES);
     
    843915
    844916  for (int i=0; i<ct_Number;i++){
    845     Trigger_CT[i] = new  MTrigger(TriggerPixels[i],
     917    Trigger_CT[i] = new MTrigger(TriggerPixels[i],
    846918                    ((MGeomCam*)(camgeom.UncheckedAt(i))),
    847919                    Trigger_gate_length,
    848920                    Trigger_overlaping_time,
    849921                    Trigger_response_ampl,
    850                     Trigger_response_fwhm);  //@< A instance of the Class MTrigger
     922                    Trigger_response_fwhm, i);  //@< A instance of the Class MTrigger
    851923    Trigger_CT[i]->SetSeed(UInt_t(i+get_seeds(0)));
    852924  }
     
    912984    Fadc_CT[i] =
    913985      new  MFadc(((MGeomCam*)(camgeom.UncheckedAt(i)))->GetNumPixels(),
    914                  FADC_response_ampl,FADC_response_fwhm,
    915                  FADC_resp_ampl_out,FADC_resp_fwhm_out,
     986                 FADC_shape,
     987                 FADC_response_integ,FADC_response_fwhm,
     988                 FADC_shape_out,
     989                 FADC_resp_integ_out,FADC_resp_fwhm_out,
    916990                 get_trig_delay()
    917991          ) ; //@< A instance of the Class MFadc
     
    9401014   
    9411015    // Generate database for the Fadc electronic noise
    942     if (addElecNoise){       
    943       Fadc_CT[ict]->SetElecNoise(FADC_noise);
    944       Fadc_CT[ict]->SetDigitalNoise(DIGITAL_noise);
    945     }
     1016
     1017    if (!addElecNoise)
     1018        continue;
     1019
     1020    MGeomCam *camg = (MGeomCam*)(camgeom.UncheckedAt(ict));
     1021    UInt_t n_inner_pixels;  // Number of inner(small) pixels
     1022    for (n_inner_pixels = 0; n_inner_pixels < camg->GetNumPixels();
     1023         n_inner_pixels ++)
     1024    {
     1025        if (camg->GetPixRatio(n_inner_pixels) < 1.)
     1026            break;
     1027    }
     1028    Fadc_CT[ict]->SetElecNoise(FADC_noise_inner, FADC_noise_outer,
     1029                               n_inner_pixels);
     1030    Fadc_CT[ict]->SetDigitalNoise(DIGITAL_noise);
    9461031  }
    9471032
     
    9551040  MRawRunHeader *RunHeader= new MRawRunHeader();
    9561041  MMcRunHeader  *McRunHeader = new MMcRunHeader();
    957   MMcCorsikaRunHeader  *McCorsikaRunHeader = new MMcCorsikaRunHeader();
     1042  MMcCorsikaRunHeader  *McCorsikaRunHeader = new MMcCorsikaRunHeader("","",ct_Number);
     1043
     1044
     1045  for (int i = 0; i < ct_Number; i++)
     1046    McCorsikaRunHeader->FillCT(CTx[i], CTy[i], CTz[i], -1., -1., -1., -1., i);
     1047
    9581048
    9591049  MMcConfigRunHeader  **McConfigRunHeader = NULL;
     
    9731063      EvtHeader[i] = new MRawEvtHeader();
    9741064    }
     1065
    9751066  }
    9761067
     
    10151106  char help[4]; 
    10161107
    1017   HeaderTree.Branch("MRawRunHeader","MRawRunHeader",
     1108  HeaderTree.Branch("MRawRunHeader.","MRawRunHeader",
    10181109                    &RunHeader);
    10191110
    1020   HeaderTree.Branch("MMcRunHeader","MMcRunHeader",
     1111  HeaderTree.Branch("MMcRunHeader.","MMcRunHeader",
    10211112                    &McRunHeader);
    10221113
    1023   HeaderTree.Branch("MMcCorsikaRunHeader","MMcCorsikaRunHeader",
    1024                     &McCorsikaRunHeader);
     1114  HeaderTree.Branch("MMcCorsikaRunHeader.","MMcCorsikaRunHeader",
     1115                    &McCorsikaRunHeader);
    10251116
    10261117  if(!Trigger_Loop && Write_McTrig && ct_Number==1){
    10271118   
    1028     HeaderTree.Branch("MMcTrigHeader","MMcTrigHeader",
     1119    HeaderTree.Branch("MMcTrigHeader.","MMcTrigHeader",
    10291120                      &HeaderTrig[0]);
    10301121  }
     1122
    10311123  if (ct_Number==1){
    1032     HeaderTree.Branch("MGeomCam",GeometryName[0],
    1033                       &camdummy[0]);
    1034     HeaderTree.Branch("MMcConfigRunHeader","MMcConfigRunHeader",
     1124    //    HeaderTree.Branch("MGeomCam.", "MGeomCam", &camdummy[0]);
     1125    HeaderTree.Branch("MGeomCam.", GeometryName[0], &camdummy[0]);
     1126    HeaderTree.Branch("MMcConfigRunHeader.","MMcConfigRunHeader",
    10351127                      &McConfigRunHeader[0]);
    10361128  }
    10371129  else{
    1038     char branchname[20];
     1130    char branchname[256];
    10391131    for (int ict=0; ict<ct_Number;ict++){
    10401132      sprintf(help,"%i",ict+1);
     
    10421134      strcat (branchname, & help[0]);
    10431135      strcat (branchname, ".");
    1044       HeaderTree.Branch(branchname,GeometryName[ict],
     1136      HeaderTree.Branch(branchname, GeometryName[ict],
    10451137                        &camdummy[ict]);
    10461138    }
     
    10581150  if ((Trigger_Loop || ct_Number>1) && Write_McTrig){
    10591151    ibr=0;
    1060     for(char branchname[20];ibr<numberBranches;ibr++){
     1152    for(char branchname[256];ibr<numberBranches;ibr++){
    10611153     
    10621154      sprintf(help,"%i",ibr+1);
     
    10711163  if(!Trigger_Loop && Write_McFADC && ct_Number==1){
    10721164   
    1073     HeaderTree.Branch("MMcFadcHeader","MMcFadcHeader",
     1165    HeaderTree.Branch("MMcFadcHeader.","MMcFadcHeader",
    10741166                      &HeaderFadc[0]);
    10751167  }
    10761168  if ((Trigger_Loop || ct_Number>1) && Write_McFADC){
    10771169    ibr=0;
    1078     for(char branchname[20];ibr<numberBranches;ibr++){
     1170    for(char branchname[256];ibr<numberBranches;ibr++){
    10791171     
    10801172      sprintf(help,"%i",ibr+1);
     
    10821174      strcat (branchname, & help[0]);
    10831175      strcat (branchname, ".");
     1176
    10841177      HeaderTree.Branch(branchname,"MMcFadcHeader",
    10851178                        &HeaderFadc[ibr]);
     
    10941187  RunHeader->SetRunType(256);
    10951188  RunHeader->SetRunNumber(0);
    1096   RunHeader->SetNumSamples(0,FADC_SLICES);
     1189  RunHeader->SetNumSamples(FADC_SLICES, FADC_SLICES);
    10971190  RunHeader->SetNumCrates(1);
    10981191  RunHeader->SetNumPixInCrate(ct_NPixels);
     
    11491242 
    11501243  //  Fill branches for MMcFadcHeader
    1151 
    1152   for(int i=0;i<ct_NPixels;i++){
    1153       fadc_elecnoise[i]=FADC_noise;
    1154       fadc_diginoise[i]=DIGITAL_noise;
    1155   }
    1156 
    11571244  Fadc_CT[0]->GetPedestals(&fadc_pedestals[0]);
    11581245
    11591246  if(!Trigger_Loop && Write_McFADC && ct_Number==1){
    11601247
    1161     HeaderFadc[0]->SetShape(0.0);
    1162     HeaderFadc[0]->SetAmplitud(FADC_response_ampl*2.35/
    1163                                sqrt(2*M_PI*FADC_response_fwhm
    1164                                     *FADC_response_fwhm),
    1165                                FADC_resp_ampl_out*2.35/
    1166                                sqrt(2*M_PI*FADC_resp_fwhm_out
    1167                                     *FADC_resp_fwhm_out));
     1248      for(int k = 0; k < ct_NPixels; k++){
     1249          if ( ((MGeomCam*)(camgeom.UncheckedAt(0)))->GetPixRatio(k) < 1.)
     1250              fadc_elecnoise[k]=FADC_noise_outer; // outer pixels
     1251          else
     1252              fadc_elecnoise[k]=FADC_noise_inner; // inner pixels
     1253
     1254          fadc_diginoise[k]=DIGITAL_noise;
     1255      }
     1256
     1257    HeaderFadc[0]->SetShape(FADC_shape);
     1258    HeaderFadc[0]->SetShapeOuter(FADC_shape_out);
     1259    HeaderFadc[0]->SetAmplitud(FADC_response_integ,
     1260                               FADC_resp_integ_out);
    11681261    HeaderFadc[0]->SetFwhm(FADC_response_fwhm,FADC_resp_fwhm_out);
    11691262    HeaderFadc[0]->SetLow2High(FADC_high2low);
     
    11731266                                ((MGeomCam*)(camgeom.UncheckedAt(0)))->GetNumPixels());
    11741267  }
     1268
    11751269  if(!Trigger_Loop && Write_McFADC && ct_Number>1){
    11761270    for(int i=0;i<ct_Number;i++){
     1271
     1272      for(int k = 0; k < ct_NPixels; k++){
     1273          if ( ((MGeomCam*)(camgeom.UncheckedAt(i)))->GetPixRatio(k) < 1.)
     1274              fadc_elecnoise[k]=FADC_noise_outer; // outer pixels
     1275          else
     1276              fadc_elecnoise[k]=FADC_noise_inner; // inner pixels
     1277
     1278          fadc_diginoise[k]=DIGITAL_noise;
     1279      }
     1280
    11771281      Fadc_CT[i]->GetPedestals(&fadc_pedestals[0]);
    1178       HeaderFadc[i]->SetShape(0.0);
    1179       HeaderFadc[i]->SetAmplitud(FADC_response_ampl*2.35/
    1180                                  sqrt(2*M_PI*FADC_response_fwhm
    1181                                       *FADC_response_fwhm),
    1182                                  FADC_resp_ampl_out*2.35/
    1183                                  sqrt(2*M_PI*FADC_resp_fwhm_out
    1184                                       *FADC_resp_fwhm_out));
     1282      HeaderFadc[i]->SetShape(FADC_shape);
     1283      HeaderFadc[i]->SetShapeOuter(FADC_shape_out);
     1284      HeaderFadc[i]->SetAmplitud(FADC_response_integ,
     1285                                 FADC_resp_integ_out);
    11851286      HeaderFadc[i]->SetFwhm(FADC_response_fwhm,FADC_resp_fwhm_out);
    11861287      HeaderFadc[i]->SetLow2High(FADC_high2low);
     
    11891290                                  ((MGeomCam*)(camgeom.UncheckedAt(i)))->GetNumPixels());
    11901291    }
    1191   } 
     1292  }
     1293 
    11921294  if(Trigger_Loop && Write_McFADC){
     1295
     1296    for(int k = 0; k < ct_NPixels; k++){
     1297        if ( ((MGeomCam*)(camgeom.UncheckedAt(0)))->GetPixRatio(k) < 1.)
     1298            fadc_elecnoise[k]=FADC_noise_outer; // outer
     1299        else
     1300            fadc_elecnoise[k]=FADC_noise_inner; // inner
     1301
     1302        fadc_diginoise[k]=DIGITAL_noise;
     1303    }
     1304
    11931305    int iconcount;
    11941306    for (iconcount=0,ithrescount=0,fthrescount=Trigger_loop_lthres;fthrescount<=Trigger_loop_uthres;ithrescount++, fthrescount+=Trigger_loop_sthres){
     
    11961308        for(itopocount=0;itopocount<=Trigger_loop_utop-Trigger_loop_ltop;itopocount++){
    11971309          Fadc_CT[0]->GetPedestals(&fadc_pedestals[0]);
    1198           HeaderFadc[iconcount]->SetShape(0.0);
    1199           HeaderFadc[iconcount]->SetAmplitud(FADC_response_ampl*2.35/
    1200                                              sqrt(2*M_PI*FADC_response_fwhm
    1201                                                   *FADC_response_fwhm),
    1202                                              FADC_resp_ampl_out*2.35/
    1203                                              sqrt(2*M_PI*FADC_resp_fwhm_out
    1204                                                   *FADC_resp_fwhm_out));
     1310          HeaderFadc[iconcount]->SetShape(FADC_shape);
     1311          HeaderFadc[iconcount]->SetShapeOuter(FADC_shape_out);
     1312          HeaderFadc[iconcount]->SetAmplitud(FADC_response_integ,
     1313                                             FADC_resp_integ_out);
    12051314          HeaderFadc[iconcount]->SetFwhm(FADC_response_fwhm,
    12061315                                         FADC_resp_fwhm_out);
     
    12221331  }
    12231332
    1224 
    12251333  //      create a Tree for the Event data stream
    12261334  TTree EvtTree("Events","Normal Triggered Events");
     
    12281336  if (Write_McEvt && ct_Number==1){
    12291337
    1230     EvtTree.Branch("MMcEvt","MMcEvt",
     1338    EvtTree.Branch("MMcEvt.","MMcEvt",
    12311339                   &McEvt[0]);
    12321340  }
     
    12341342  if (Write_McEvt && ct_Number!=1){
    12351343    ibr=0;
    1236     for(char branchname[10];ibr<numberBranches;ibr++){
     1344    for(char branchname[256];ibr<numberBranches;ibr++){
    12371345     
    12381346      sprintf(help,"%i",ibr+1);
     
    12481356   
    12491357    if (Write_RawEvt){
    1250       EvtTree.Branch("MRawEvtHeader","MRawEvtHeader",
     1358      EvtTree.Branch("MRawEvtHeader.","MRawEvtHeader",
    12511359                     &EvtHeader[0]);
    1252       EvtTree.Branch("MRawEvtData","MRawEvtData",
     1360      EvtTree.Branch("MRawEvtData.","MRawEvtData",
    12531361                     &EvtData[0]);
    12541362    }
    12551363    if (Write_McTrig){
    1256       EvtTree.Branch("MMcTrig","MMcTrig",
     1364      EvtTree.Branch("MMcTrig.","MMcTrig",
    12571365                     &McTrig[0]);
    12581366    }   
     
    12621370    if (Write_McTrig){
    12631371      ibr=0;
    1264       for(char branchname[10];ibr<numberBranches;ibr++){
     1372      for(char branchname[256];ibr<numberBranches;ibr++){
    12651373     
    12661374        sprintf(help,"%i",ibr+1);
     
    12761384  if ((Trigger_Loop || ct_Number>1) && Write_RawEvt){
    12771385    ibr=0;
    1278     for(char branchname[15];ibr<numberBranches;ibr++){
     1386    for(char branchname[256];ibr<numberBranches;ibr++){
    12791387     
    12801388      sprintf(help,"%i",ibr+1);
     
    12861394    }
    12871395    ibr=0;
    1288     for(char branchname[15];ibr<numberBranches;ibr++){
     1396    for(char branchname[256];ibr<numberBranches;ibr++){
    12891397     
    12901398      sprintf(help,"%i",ibr+1);
     
    13151423  }
    13161424 
    1317 
    13181425  // prepare the NSB simulation
    13191426
    13201427  //  Instance of the Mlons class
    1321   MLons lons(Trigger_response_ampl, Trigger_response_fwhm,
    1322              FADC_response_ampl,FADC_response_fwhm);
     1428  MLons lons(0.0, Trigger_response_ampl, Trigger_response_fwhm,
     1429             float(FADC_shape),FADC_response_integ,FADC_response_fwhm);
    13231430
    13241431  lons.SetSeed(Int_t(get_seeds(1)/get_seeds(0))+1);
     
    13271434
    13281435  //  Instance of the Mlons class
    1329   MLons lons_outer(Trigger_response_ampl, Trigger_response_fwhm,
    1330                    FADC_resp_ampl_out,FADC_resp_fwhm_out);
     1436  MLons lons_outer(0.0, Trigger_response_ampl, Trigger_response_fwhm,
     1437                   float(FADC_shape_out),FADC_resp_integ_out,FADC_resp_fwhm_out);
    13311438
    13321439  lons_outer.SetSeed(Int_t(get_seeds(1)/get_seeds(0))+2);
     
    13401447    //
    13411448   
    1342     // FIXME --- star NSB different for each camera?
     1449    //
     1450    // FIXME! --- star NSB different for each camera?
     1451    // Then we will have to use mirror_frac[ict]
     1452    //
    13431453    log(SIGNATURE,"Produce NSB rates from Star Field");
    13441454
     
    13461456                          ((MGeomCam*)(camgeom.UncheckedAt(0))),
    13471457                          nsbrate_phepns,
    1348                           0);
     1458                          0,
     1459                          mirror_frac[0]);
     1460
     1461
     1462    //
     1463    // Call to "produce_nsbrates" above accounts ONLY for
     1464    // non-diffuse NSB (i.e. from stars). NOTE: produce_nsbrates already
     1465    // accounts for the possibly different light collection efficiencies
     1466    // of inner and outer pixels, through a call (see function) to
     1467    // "produce_phes". The output array nsbrate_phepns contains only the
     1468    // rates due to individual stars in the FOV, and not diffuse NSB light!
     1469    //
    13491470
    13501471    if (k != 0){
     
    13581479    for(int ict=0;ict<ct_Number;ict++){     
    13591480     
    1360       // First we set the factor due to the mirror size respect to the MAGIC mirror.
     1481      // First we set the factor due to the mirror size with respect to the normal
     1482      // MAGIC mirror geometry.
    13611483     
    13621484      switch(GeometryCamera[ict]){
     
    13791501      }
    13801502
    1381       factorNSB_ct=factorNSB_ct/
     1503      factorNSB_ct = factorNSB_ct /
    13821504        ((*((MGeomCam*)(camgeom.UncheckedAt(ict)))).GetCameraDist()*1000*
    13831505         (*((MGeomCam*)(camgeom.UncheckedAt(ict)))).GetCameraDist()*1000*
    1384          PIXEL_SIZE*PIXEL_SIZE);
     1506         PIXEL_SIZE*PIXEL_SIZE); //  [mm^-2]
    13851507
    13861508      for(UInt_t ui=0;
    13871509          ui<((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels(); ui++){
    13881510        const Float_t size=
    1389           (*((MGeomCam*)(camgeom.UncheckedAt(ict))))[ui].GetD();
    1390         diffnsb_phepns[ict][ui] = (Int_t(meanNSB*factorNSB_ct*100*size*size+0.5))/(100.0)*factorqe_NSB[ict];
     1511          (*((MGeomCam*)(camgeom.UncheckedAt(ict))))[ui].GetD();
     1512        // Returns distance [mm] between two paralel sides of pixel
     1513
     1514
     1515        Float_t diffusensb = meanNSB*mirror_frac[ict];
     1516
     1517        //
     1518        // If pixel is outer pixel:
     1519        //
     1520        if ( ((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetPixRatio(ui) < 1. )
     1521          diffusensb *= WC_outer[1][90] / WC[1][90];
     1522        //
     1523        // FIXME! Correction above is for (possibly) different light collection efficiencies of
     1524        // inner and outer pixels. For the moment we assume the angular dependence of the light
     1525        // collection is the same and hence use simply the ratio of efficiencies for light impinging
     1526        // perpendicular to the camera plane (index 90 stands for 90 degrees)
     1527        //
     1528
     1529        diffnsb_phepns[ict][ui] = (Int_t(diffusensb*factorNSB_ct*100*size*size+0.5))/(100.0)*factorqe_NSB[ict];
    13911530      }
    13921531    }
     
    13961535    for(int ict=0;ict<ct_Number;ict++){     
    13971536      for(j=0;j<iNUMWAVEBANDS;j++){
    1398         // calculate the effect of the atmospheric extinction
     1537        // calculate the effect of the atmospheric extinction (for stars!)
    13991538       
    14001539        zenfactor = pow(10., -0.4 * ext[j] );
     
    14111550  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    14121551  //
    1413   //  Now 500 empty event with the conditin in which the camera is run
    1414   //  are simulated. IN this way one gets an estimation of the
    1415   //  sigma for the pedestal of each FADC channel.
    1416   //  This sigma computtaion is done assuming any noise taht effects
     1552  //  Now 500 empty events with the condition in which the camera is run
     1553  //  are simulated. In this way one gets an estimation of the
     1554  //  fluctuations of the pedestal of each FADC channel.
     1555  //  This computation is done assuming any noise that affects
    14171556  //  the FADC but there is no rotation of the Star Field (otherwise it
    1418   //  should be done for each event)
     1557  //  should be done for each event). So it is valid if no starfield
     1558  //  rotation is used.
     1559  //
     1560  //  Changed 20/03/2004, AM: now we no longer calculate the individual
     1561  //  FADC slice RMS. Due to correlations in the noise of neighboring
     1562  //  slides, it follows that RMS(sum_n_slices) != sqrt(n)*RMS(single_slice)
     1563  //
     1564  //  In the analysis in Mars, however, the RMS of the fluctuations of the
     1565  //  signal (resulting from the integration of n slices) is estimated as
     1566  //  sqrt(n) * MMcFadcHeader.fPedesSigmaHigh, where the latter value,
     1567  //  stored in the camera output, is calculated in the next lines of code.
     1568  //  We have then made the following, as is being done also in real data:
     1569  //  calculate the RMS of the distribution of the sum of 14 slices, then
     1570  //  the stored value is
     1571  //  MMcFadcHeader.fPedesSigmaHigh = RMS(sum_14_slices)/sqrt(14), and the
     1572  //  same for the low gain. It can be seen that the RMS of the sum of n
     1573  //  slices, with n not too low (n>=6 or so), is more or less:
     1574  //  RMS(sum_n_slices) ~ sqrt(n) * RMS(sum_14_slices)/sqrt(14)
     1575  //
     1576  //  The reason to sum 14 slices (and not 15) comes from the fact that in
     1577  //  real data there is a FADC clock noise affecting differently odd and
     1578  //  even FADC slices, so always an even number of them is added up so that
     1579  //  this cancels out. So we do the calculation in the same way as in real
     1580  //  data.
    14191581  //
    14201582  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     1583
     1584  Int_t empty_events = 500;
     1585  Int_t n_slices = 14;
    14211586
    14221587  for(int ict=0;ict<ct_Number;ict++){
     
    14271592      fadc_sigma_low[ui]=0.0;
    14281593    }
    1429     for(int ie=0;ie<500;ie++){
     1594    for(int ie=0; ie < empty_events; ie++){
    14301595      Fadc_CT[ict]->Reset() ;
    14311596      if (addElecNoise){       
    1432         Fadc_CT[ict]->ElecNoise(FADC_noise) ;
     1597        Fadc_CT[ict]->ElecNoise() ;
    14331598      }
    14341599      if(simulateNSB){
     
    14551620      }
    14561621      Fadc_CT[ict]->Pedestals();
     1622
    14571623      for(UInt_t ui=0;
    14581624          ui<((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels();
    1459           ui++){
    1460         fadc_sigma[ui]+=(Fadc_CT[ict]->GetPedestalNoise(ui,1))/500.0;
    1461         fadc_sigma_low[ui]+=(Fadc_CT[ict]->GetPedestalNoise(ui,0))/500.0;
     1625          ui++)
     1626        {
     1627          //
     1628          // We add up n_slices FADC slices (pedestal subtracted), then
     1629          // calculate the sigma_n-1 of this sum for the number of generated
     1630          // noise events (=empty_events).
     1631          //
     1632          Float_t sumslices = Fadc_CT[ict]->AddNoiseInSlices(ui,1,n_slices);
     1633          fadc_sigma[ui] += sumslices*sumslices;
     1634
     1635          // Now the low gain:
     1636          sumslices = Fadc_CT[ict]->AddNoiseInSlices(ui,0,n_slices);
     1637          fadc_sigma_low[ui]+= sumslices*sumslices;
     1638        }
     1639    }
     1640
     1641    for(UInt_t ui=0;
     1642        ui<((MGeomCam*)(camgeom.UncheckedAt(ict)))->GetNumPixels();
     1643        ui++)
     1644      {
     1645        Float_t s_high = fadc_sigma[ui] / (Float_t)(empty_events-1) /
     1646          (Float_t)(n_slices);
     1647        fadc_sigma[ui] = sqrt(s_high);
     1648
     1649        Float_t s_low = fadc_sigma_low[ui] / (Float_t)(empty_events-1) /
     1650          (Float_t)(n_slices);
     1651        fadc_sigma_low[ui] = sqrt(s_low);
    14621652      }
    1463     }
     1653
    14641654    HeaderFadc[ict]->SetPedestalSigma(&fadc_sigma_low[0],&fadc_sigma[0],
    14651655                                      ((MGeomCam*)(camgeom.UncheckedAt(ict)))
     
    15601750        }
    15611751
    1562         fread((char*)&mcrunh,(SIZE_OF_MCRUNHEADER)*sizeof(float), 1, inputfile[ict] );
     1752        //      fread((char*)&mcrunh,(SIZE_OF_MCRUNHEADER)*sizeof(float), 1, inputfile[ict] );
     1753        //  AM, changed reading method, 02/2004:
     1754
     1755        mcrunh.read(inputfile[ict]);
     1756
    15631757      }
    15641758     
     
    15981792        if (reflector_file_version<6){
    15991793          for(int ict=0;ict<ct_Number;ict++)
    1600             fread( (char*)&mcevth[ict], mcevth[ict].mysize(),
    1601                    1, inputfile[ict] );
     1794            {
     1795              mcevth[ict].read(inputfile[ict]);
     1796            }
     1797
    16021798        }
    16031799        else{
    16041800          for(int ict=0;ict<ct_Number;ict++)
    1605             fread( (char*)&mcevth_2[ict], mcevth_2[ict].mysize(),
    1606                    1, inputfile[ict] );
     1801            {
     1802              mcevth_2[ict].read(inputfile[ict]);
     1803            }
    16071804        }
    16081805
    1609         // calculate impact parameter (shortest distance betwee the original
    1610         // trajectory of the primary (assumed shower-axis) and the
    1611         // direction where the telescope points to
     1806        //
     1807        // AM March 2004 simplified impact parameter calculation,
     1808        // and allowed for correct estimate also for telescopes not
     1809        // placed at Corsika's origin of coordinates (0.,0.).
     1810        // FIXME: telescope coordinates still set by the user in the
     1811        // input card, since they are not available in the reflector
     1812        // file!
     1813        //
     1814        // Calculate impact parameter as distance between telescope
     1815        // location and shower axis. In the previous implementation,
     1816        // the definition was the distance between telescope axis and
     1817        // shower axis, but this has less physical meaning in general.
     1818        // Light yield depends above all on distance to shower axis!
     1819        // Of course for shower axis paralel to telescope the old and
     1820        // the new definitions of impact parameter agree.
    16121821        //
    1613         // we use the following equation, given that the shower core position
    1614         // is (x1,y1,z1)=(x,y,0),the  trajectory is given by (l1,m1,n1),
    1615         // and the telescope position and orientation are (x2,y2,z2)=(0,0,0)
    1616         // and (l2,m2,n2)
    1617         //
    1618         //               |                     |
    1619         //               | x1-x2  y1-y2  z1-z2 |
    1620         //               |                     |
    1621         //             + |   l1     m1     n1  |
    1622         //             - |                     |
    1623         //               |   l2     m2     n2  |
    1624         //               |                     |
    1625         // dist = ------------------------------------        ( > 0 )
    1626         //        [ |l1 m1|2   |m1 n1|2   |n1 l1|2 ]1/2
    1627         //        [ |     |  + |     |  + |     |  ]
    1628         //        [ |l2 m2|    |m2 n2|    |n2 l2|  ]
    1629         //
    1630         // playing a little bit, we get this reduced for in our case:
    1631         //
    1632         //
    1633         // dist = (- m2 n1 x + m1 n2 x + l2 n1 y - l1 n2 y - l2 m1 z + l1 m2 z) /
    1634         //         [(l2^2 (m1^2 + n1^2) + (m2 n1 - m1 n2)^2 -
    1635         //          2 l1 l2 (m1 m2 + n1 n2) + l1^2 (m2^2 + n2^2) ] ^(1/2)
    1636        
     1822
     1823
    16371824        // read the direction of the incoming shower
    16381825        // It is done only for one telescope since it is suposed
     
    16461833          phishw = mcevth_2[0].get_phi();
    16471834        }
     1835        Zenith=thetashw; Azimutal=phishw;
    16481836       
    16491837        // calculate vector for shower
     
    16531841        n1 = cos(thetashw);
    16541842
    1655         if (reflector_file_version<6){
    1656 
    1657           mcevth[0].get_core(&coreX, &coreY);   
    1658          
    1659           for(int ict=0;ict<ct_Number;ict++){
    1660             // read the deviation of the telescope with respect to the shower
    1661             mcevth[ict].get_deviations ( &thetaCT[ict], &phiCT[ict] );
    1662 
    1663             if ( (thetaCT[ict] == 0.) && (phiCT[ict] == 0.) ) {
    1664          
    1665               // CT was looking to the source (both lines are parallel)
    1666               // therefore, we calculate the impact parameter as the distance
    1667               // between the CT axis and the core position
    1668 
    1669               impactD[ict] = dist_r_P( 0., 0., 0., l1, m1, n1, coreX, coreY, 0. );
    1670               thetaCT[ict] += thetashw;
    1671               phiCT[ict]   += phishw;
    1672             } else {
    1673            
    1674               // the shower comes off-axis
    1675            
    1676               // obtain with this the final direction of the CT
    1677              
    1678               thetaCT[ict] += thetashw;
    1679               phiCT[ict]   += phishw;
    1680              
    1681               // calculate vector for telescope
    1682            
    1683               l2 = sin(thetaCT[ict])*cos(phiCT[ict]);
    1684               m2 = sin(thetaCT[ict])*sin(phiCT[ict]);
    1685               n2 = cos(thetaCT[ict]);
    1686              
    1687               num = (m1*n2*coreX - m2*n1*coreX + l2*n1*coreY - l1*n2*coreY);
    1688               den = (SQR(l1*m2 - l2*m1) +
    1689                      SQR(m1*n2 - m2*n1) +
    1690                      SQR(n1*l2 - n2*l1));
    1691               den = sqrt(den);
    1692               impactD[ict] = fabs(num)/den;
    1693             }
    1694           }
    1695         }
    1696         else{
    1697           mcevth_2[0].get_core(&coreX, &coreY);
    1698           for(int ict=0;ict<ct_Number;ict++){
    1699             thetaCT[ict]=mcevth_2[ict].get_theta_CT();
    1700             phiCT[ict]=mcevth_2[ict].get_phi_CT();
    1701             if ( (thetaCT[ict] == thetashw) && (phiCT[ict] == phishw) ) {
    1702          
    1703               // CT was looking to the source (both lines are parallel)
    1704               // therefore, we calculate the impact parameter as the distance
    1705               // between the CT axis and the core position
    1706 
    1707               impactD[ict] = dist_r_P( 0., 0., 0., l1, m1, n1, coreX, coreY, 0. );
    1708            
    1709             } else {
    1710            
    1711               // the shower comes off-axis
    1712            
    1713               // calculate vector for telescope
    1714            
    1715               l2 = sin(thetaCT[ict])*cos(phiCT[ict]);
    1716               m2 = sin(thetaCT[ict])*sin(phiCT[ict]);
    1717               n2 = cos(thetaCT[ict]);
    1718            
    1719               num = (m1*n2*coreX - m2*n1*coreX + l2*n1*coreY - l1*n2*coreY);
    1720               den = (SQR(l1*m2 - l2*m1) +
    1721                      SQR(m1*n2 - m2*n1) +
    1722                      SQR(n1*l2 - n2*l1));
    1723               den = sqrt(den);
    1724            
    1725               impactD[ict] = fabs(num)/den;
    1726            
    1727             }
    1728           }
    1729         }
     1843        //
     1844        // Note, A.M.:
     1845        // Attention! "core vector from mcevth*.get_core
     1846        // is the vector from the core to the telescope!
     1847        //
     1848        Float_t core2ct_x;
     1849        Float_t core2ct_y;
     1850
     1851        if (reflector_file_version<6)
     1852          mcevth[0].get_core(&core2ct_x, &core2ct_y);   
     1853        else
     1854          mcevth_2[0].get_core(&core2ct_x, &core2ct_y);
     1855
     1856        //
     1857        // Then true core position in Corsika's system is:
     1858        //
     1859
     1860        coreX = CTx[0] - core2ct_x;
     1861        coreY = CTy[0] - core2ct_y;
     1862
     1863        //
     1864        // FIXME: This may not work fine for CTs at z != 0 !!
     1865        //
     1866        for(int ict=0;ict<ct_Number;ict++)
     1867          impactD[ict] = dist_r_P( CTx[ict], CTy[ict], CTz[ict],
     1868                                   l1, m1, n1, coreX, coreY, 0. );
     1869
    17301870
    17311871        // energy cut
     
    17721912                            &arrtmin_ns, // will be changed by the function!
    17731913                            &arrtmax_ns, // will be changed by the function!
    1774                             ict);
     1914                            ict,
     1915                            mirror_frac[ict]);
    17751916
    17761917          inumphe=(inumphe<inumphe_CT[ict])?inumphe_CT[ict]:inumphe;
     
    19082049            Trigger_CT[ict]->ElecNoise(Trigger_noise) ;
    19092050           
    1910             Fadc_CT[ict]->ElecNoise(FADC_noise) ;
     2051            Fadc_CT[ict]->ElecNoise() ;
    19112052          }
    19122053        }
     
    20792220                             mcevth[0].get_phi(),
    20802221                             mcevth[0].get_core(),
    2081                              mcevth[0].get_coreX(),
    2082                              mcevth[0].get_coreY(),
     2222                             coreX,
     2223                             coreY,
    20832224                             impactD[0],
    20842225                             phiCT[0],
     
    21162257                             mcevth_2[0].get_phi(),
    21172258                             mcevth_2[0].get_core(),
    2118                              mcevth_2[0].get_coreX(),
    2119                              mcevth_2[0].get_coreY(),
     2259                             coreX,
     2260                             coreY,
    21202261                             impactD[0],
    21212262                             mcevth_2[0].get_phi_CT(),
     
    23142455              //
    23152456           
     2457
    23162458              for (int ict=0;ict<ct_Number;ict++){
    23172459                Float_t ftime, ltime;
     
    23272469                                  mcevth[ict].get_phi(),
    23282470                                  mcevth[ict].get_core(),
    2329                                   mcevth[ict].get_coreX(),
    2330                                   mcevth[ict].get_coreY(),
     2471                                  coreX,
     2472                                  coreY,
    23312473                                  impactD[ict],
    23322474                                  phiCT[ict],
     
    23642506                                  mcevth_2[ict].get_phi(),
    23652507                                  mcevth_2[ict].get_core(),
    2366                                   mcevth_2[ict].get_coreX(),
    2367                                   mcevth_2[ict].get_coreY(),
     2508                                  coreX,
     2509                                  coreY,
    23682510                                  impactD[ict],
    23692511                                  mcevth_2[ict].get_phi_CT(),
     
    24702612          for(int ict=0;ict<ct_Number;ict++){
    24712613            read_ascii(inputfile[ict], McConfigRunHeader[ict]);
    2472 
    2473             if (get_sigma_xy_cm_spot() > 0.)
     2614            McConfigRunHeader[ict]->SetMissPointingX(missP_x);
     2615            McConfigRunHeader[ict]->SetMissPointingY(missP_y);
     2616            if ( Spotsigma > 0.)
    24742617            {
    2475                 Float_t spotsigma = McConfigRunHeader[ict]->GetPointSpread();
    2476                 Float_t newsigma = sqrt(spotsigma * spotsigma +
    2477                     get_sigma_xy_cm_spot() * get_sigma_xy_cm_spot());
    2478                 McConfigRunHeader[ict]->SetPointSpread(newsigma);
     2618                Float_t ref_spotsigma = McConfigRunHeader[ict]->GetPointSpread();
     2619                Float_t newsigma = sqrt(ref_spotsigma * ref_spotsigma +
     2620                    Spot_x* Spot_x);
     2621                McConfigRunHeader[ict]->SetPointSpreadX(newsigma);
     2622                newsigma = sqrt(ref_spotsigma * ref_spotsigma + Spot_y* Spot_y);
     2623                McConfigRunHeader[ict]->SetPointSpreadY(newsigma);
    24792624            }
    24802625          }
     
    25342679  }
    25352680
    2536   get_source_off(&sofftheta,&soffphi);
    25372681  if(!Trigger_Loop) icontrigger=0;
    25382682  time (&ltime);
     
    25642708                    telestheta,
    25652709                    telesphi,
    2566                     sofftheta,
    2567                     soffphi,
    25682710                    shthetamax,
    25692711                    shthetamin,
     
    26052747                    telestheta,
    26062748                    telesphi,
    2607                     sofftheta,
    2608                     soffphi,
    26092749                    shthetamax,
    26102750                    shthetamin,
     
    26232763  // Fill some missing values for MRawRunHeader
    26242764
    2625   RunHeader->SetRunNumber(rnum);
     2765  RunHeader->SetRunNumber((UInt_t)rnum);
    26262766  RunHeader->SetNumEvents(nstoredevents);
    26272767
     
    26882828    }
    26892829   
    2690     // Store Light Guides factors in the output file
    2691     TArrayF theta_lg;
    2692     TArrayF factor_lg;
    2693     theta_lg.Set(pointsWC,WC[0]);
    2694     factor_lg.Set(pointsWC,WC[1]);
    2695     McConfigRunHeader[ict]->SetLightGuides(theta_lg,factor_lg);
     2830    // Store Light Collection factors in the output file
     2831    TArrayF theta_lc;
     2832    TArrayF factor_lc;
     2833    TArrayF factor_lc_outer;
     2834
     2835    theta_lc.Set(pointsWC,WC[0]);
     2836    factor_lc.Set(pointsWC,WC[1]);
     2837    factor_lc_outer.Set(pointsWC,WC_outer[1]);
     2838
     2839    McConfigRunHeader[ict]->SetLightCollection(theta_lc, factor_lc,
     2840                                               factor_lc_outer);
    26962841 
    26972842  }
     
    29803125      break;
    29813126
    2982     if ( ((i-1) < ct_NPixels) && ((i-1) > -1) &&
     3127    if ( (i < ct_NPixels) && (i > -1) &&
    29833128         ((j-1) < pointsQE[ict])   && ((j-1) > -1) ) {
    2984       QE[ict][i-1][0][j-1] = QElambda[j-1];
    2985       QE[ict][i-1][1][j-1] = qe;
     3129      QE[ict][i][0][j-1] = QElambda[j-1];
     3130      QE[ict][i][1][j-1] = qe;
    29863131    }
    29873132
     
    30363181
    30373182  //------------------------------------------------------------
    3038   // Read Light Guides data
     3183  // Read Light Collection data
    30393184
    30403185  // try to open the file
     
    30553200  // get line from the file
    30563201
    3057   wcfile.getline(line, LINE_MAX_LENGTH);
    3058  
     3202  do
     3203    wcfile.getline(line, LINE_MAX_LENGTH);
     3204  while (line[0] == '#');
     3205
    30593206  // get the number of datapoints
    30603207   
     
    30713218    sscanf(line, "%f %f", &WC[0][i], &WC[1][i]);
    30723219  }
    3073    
     3220
     3221  //
     3222  // Now read info for outer pixels
     3223  //
     3224  WC_outer = new float * [2];
     3225  WC_outer[0] = new float[pointsWC];
     3226  WC_outer[1] = new float[pointsWC];
     3227
     3228  do
     3229    wcfile.getline(line, LINE_MAX_LENGTH);
     3230  while (line[0] == '#');
     3231
     3232  if (wcfile.eof())
     3233    {
     3234      log("read_WC", "ERROR. Missing data for outer pixels in file \"%s\"...\n",WC_FILE);
     3235      log("read_WC", "EXITING camera\n");
     3236      exit(-1);
     3237    }
     3238
     3239  sscanf(line, "%f %f", &WC_outer[0][0], &WC_outer[1][0]);
     3240  for ( i=1; i<pointsWC; ++i ) {
     3241    wcfile.getline(line, LINE_MAX_LENGTH);
     3242    sscanf(line, "%f %f", &WC_outer[0][i], &WC_outer[1][i]);
     3243  }
     3244
    30743245  // close file
    30753246
     
    35483719// dist_r_P
    35493720//
    3550 // distance straight line r - point P
     3721// distance straight line r (x+t*l, y+t*m, z+t*n) to point P(a,b,c)
     3722//
     3723// We assume that vector (l, m, n) is normalized l^2+m^2+n^2 = 1
    35513724//------------------------------------------------------------
    35523725
     
    35593732          sqrt((SQR((a-x)*m-(b-y)*l) +
    35603733                SQR((b-y)*n-(c-z)*m) +
    3561                 SQR((c-z)*l-(a-x)*n))/
    3562                (SQR(l)+SQR(m)+SQR(n))
    3563                )
     3734                SQR((c-z)*l-(a-x)*n)))
    35643735          );
    35653736}
     
    36363807int size_rotated(
    36373808    float *rotated,
    3638     float nsb[iMAXNUMPIX],
     3809    float *nsb,
    36393810    float rho)
    36403811{
     
    37373908                  class MFadc *fadc,
    37383909                  int *itotnphe, // total number of produced photoelectrons
    3739                   float nphe[iMAXNUMPIX], // number of photoelectrons in each pixel
     3910                  float *nphe, // number of photoelectrons in each pixel
    37403911                  int *incph,       // total number of cph within camera
    37413912                  float *tmin_ns,   // minimum arrival time of all phes
    37423913                  float *tmax_ns,    // maximum arrival time of all phes
    3743                   int ict      // Telescope that is being analised to get the right QE.
     3914                  int ict,      // Telescope that is being analised to get the right QE.
     3915                  float mirror_fraction // Fraction of total mirror really present
    37443916                   ){
    37453917
    37463918  static uint i;
    37473919  static int k, ipixnum;
    3748   static float cx, cy, wl, qe, t;
    3749   static float cu, cv, cw;
     3920  static float cx, cy, wl, qe;
     3921  static float cw;
    37503922  static MCCphoton photon;
    37513923  static float **qept;
     
    37533925  static float radius_mm;
    37543926
     3927  Float_t t;
     3928
    37553929  // reset variables
    37563930
     
    37613935  }
    37623936
     3937  *itotnphe = 0;
    37633938  *incph = 0;
    37643939
     
    37683943  random.SetSeed((Int_t)(get_seeds(0)*get_seeds(1)));
    37693944
    3770   float spotsigma = get_sigma_xy_cm_spot();
     3945  float C1, C2, C3, rho;
     3946
    37713947
    37723948  //- - - - - - - - - - - - - - - - - - - - - - - - -
     
    37793955 
    37803956  // read the photons data
    3781  
    3782  
     3957
    37833958  // loop over the photons
    37843959 
    37853960  while (1) {
    37863961
    3787     fread ( flag, SIZE_OF_FLAGS, 1, sp );
     3962    photon.read(sp);
     3963    photon.get_flag(flag);
    37883964
    37893965    if (isA( flag, FLAG_END_OF_EVENT ))
    3790         break;
    3791          
    3792     memcpy( (char*)&photon, flag, SIZE_OF_FLAGS );
    3793    
    3794     fread( ((char*)&photon)+SIZE_OF_FLAGS, photon.mysize()-SIZE_OF_FLAGS, 1, sp );
    3795          
     3966      {
     3967        fseek (sp, SIZE_OF_FLAGS-photon.mysize(), SEEK_CUR);
     3968        break; 
     3969      }
    37963970
    37973971    //  Check if photon is inside trigger time range
    37983972
    3799     t = photon.get_t() ; 
     3973    t = photon.get_t() ;
    38003974
    38013975    if (t-*tmin_ns>TOTAL_TRIGGER_TIME) {
    38023976        continue;
    38033977    }
    3804          
     3978
     3979    //
     3980    // Account for possibly missing mirrors, or lower reflectivity...
     3981    // mirror_fraction is the fraction of the total mirror really
     3982    // working.
     3983    //
     3984    if (mirror_fraction < 1.)
     3985        if (RandomNumber > mirror_fraction)
     3986            continue;
     3987
    38053988    //
    38063989    // Pixelization
     
    38103993    cy = photon.get_y();
    38113994
    3812 
    3813     if (spotsigma > 0.)
     3995    if (Spotsigma > 0.)
    38143996    {
    3815         cx += random.Gaus(0.,spotsigma);
    3816         cy += random.Gaus(0.,spotsigma);
    3817     }
     3997        cx += random.Gaus(0.,Spot_x);
     3998        cy += random.Gaus(0.,Spot_y);
     3999    }
     4000    if (missPointing > 0.)
     4001    {
     4002      // We should take intot acount the rotation of the FoV
     4003      C1 = 0.48 * sin(Zenith) - 0.87 * cos(Zenith) * cos(Azimutal);
     4004      C3 = (0.87 * cos(Zenith) - 0.48 * sin(Zenith) * cos(Azimutal));
     4005      C2 = sqrt( sin(Zenith) * sin(Zenith) * sin(Azimutal) * sin(Azimutal) + C3 * C3 );
     4006      rho = acos( C1/C2 );
     4007      rho=(sin(Azimutal)<0 ? (2 * 3.14159 - rho) : rho);
     4008
     4009      rho = rho*180/3.14159;
     4010
     4011      cx += (missP_x*cos(rho)-missP_y*sin(rho))/(10*camgeom->GetConvMm2Deg());
     4012      cy += (missP_x*sin(rho)+missP_y*cos(rho))/(10*camgeom->GetConvMm2Deg());
     4013    }
     4014   
    38184015
    38194016    // get wavelength
     
    38494046   
    38504047    // set pointer to the QE table of the relevant pixel
    3851          
     4048
    38524049    qept = (float **)QE[ict][ipixnum];
    38534050         
     
    38704067    qe = lin_interpol(qept[0][k-1], qept[1][k-1], qept[0][k], qept[1][k], wl) / 100.0;
    38714068
    3872     // Apply incient angular correction due to Light Guides
    3873 
    3874     cu=photon.get_u();
    3875     cv=photon.get_v();
    3876     cw=90.0-acos(sqrt(1-cu*cu-cv*cv))*3.14159/180.0;
    3877 
    3878     // find data point in the QE table (-> k)
    3879 
    3880     k = 0;
    3881     while (k < pointsWC-1 && WC[0][k] < cw){
    3882       k++;
    3883     }
    3884 
    3885      // correct the qe with WC data.
    3886 
    3887     qe = qe*lin_interpol(WC[0][k-1], WC[1][k-1], WC[0][k], WC[1][k], cw);
     4069    //
     4070    // Apply incient angular correction due to Light Guides, plexiglas,
     4071    // 1st dynode collection efficiency, double crossings... etc.
     4072    // This information is contained in the file Data/LightCollection.dat
     4073    //
     4074    cw=photon.get_phi()*180./3.14159265;
     4075
     4076    // find data point in the WC table (-> k)
     4077
     4078    if ( camgeom->GetPixRatio(ipixnum) < 1.) // => Pixel is outer pixel
     4079      {
     4080        k = 0;
     4081        while (k < pointsWC-1 && WC_outer[0][k] < cw)
     4082          k++;
     4083        // correct the qe with WC data.
     4084        qe = qe*lin_interpol(WC_outer[0][k-1], WC_outer[1][k-1],
     4085                             WC_outer[0][k],   WC_outer[1][k], cw);
     4086      }
     4087
     4088    else    // => Pixel is inner pixel
     4089      {
     4090        k = 0;
     4091        while (k < pointsWC-1 && WC[0][k] < cw)
     4092          k++;
     4093        // correct the qe with WC data.
     4094        qe = qe*lin_interpol(WC[0][k-1], WC[1][k-1], WC[0][k], WC[1][k], cw);
     4095      }
     4096
    38884097
    38894098   // if random > quantum efficiency, reject it
     
    39024111         
    39034112    nphe[ipixnum] += 1.0;
    3904          
     4113
     4114
    39054115    // store the new photoelectron
    39064116
     
    39294139int produce_nsbrates( char *iname, // the starfield input file name
    39304140                      MGeomCam *camgeom, // camera layout
    3931                       float rate_phepns[iMAXNUMPIX][iNUMWAVEBANDS], // the product of this function:
    3932                                                // the NSB rates in phe/ns for each pixel
    3933                       int ict
    3934                       ){
    3935 
     4141                      float **rate_phepns,
     4142                      // the product of this function:
     4143                      // the NSB rates in phe/ns for each pixel
     4144                      int ict,
     4145                      float mirror_fraction)
     4146{
    39364147  uint i, j; // counters
    39374148  int k, ii; // counters
     
    39594170  char flag_new[4];
    39604171
     4172
    39614173  // open input file
    39624174 
     
    39654177  infile = fopen( iname, "r" );
    39664178
    3967   // check if the satrfield input file exists
     4179  // check if the starfield input file exists
    39684180
    39694181  if ( infile == NULL ) {
     
    39754187    return (0);
    39764188  }
    3977  
     4189
    39784190  // get signature, and check it
    39794191 
     
    39824194  }
    39834195
    3984   // Instance of MTrigger and MFadc
    3985 
    3986   MTrigger trigger(camgeom->GetNumPixels(),camgeom,Trigger_gate_length, Trigger_overlaping_time, Trigger_response_ampl, Trigger_response_fwhm);
    3987   MFadc flashadc(camgeom->GetNumPixels());
    3988 
    3989   // initialize flag
    3990  
     4196  // Instance of MTrigger and MFadc; needed here only as dummies for
     4197  // a call to produce_phes (see below).
     4198  // 15/09/2004, A. Moralejo, changed "trigger" and "flashadc" to
     4199  // pointers, the former static allocation caused memory problems and
     4200  // segmentation fault in some systems.
     4201
     4202  MTrigger* trigger = new MTrigger(camgeom->GetNumPixels(),camgeom,
     4203                                   Trigger_gate_length,
     4204                                   Trigger_overlaping_time,
     4205                                   Trigger_response_ampl,
     4206                                   Trigger_response_fwhm);
     4207
     4208  MFadc* flashadc = new MFadc(camgeom->GetNumPixels(),
     4209                              FADC_shape,
     4210                              FADC_response_integ,FADC_response_fwhm,
     4211                              FADC_shape_out,
     4212                              FADC_resp_integ_out,FADC_resp_fwhm_out,
     4213                              get_trig_delay());
     4214
     4215  // initialize flag 
    39914216  strcpy( cflag, "                                        \0" );
    39924217
     
    40384263       
    40394264        if (reflector_file_version<6)
    4040           fread( (char*)&evth, evth.mysize(), 1, infile );
     4265          //      fread( (char*)&evth, evth.mysize(), 1, infile );
     4266          evth.read(infile);
    40414267        else
    4042           fread( (char*)&evth_2, evth_2.mysize(), 1, infile );
    4043          
     4268          //      fread( (char*)&evth_2, evth_2.mysize(), 1, infile );
     4269          evth_2.read(infile);
     4270
    40444271        if (reflector_file_version<6)
    40454272          integtime_ns = evth.get_energy();
     
    40814308                              wl_nm[i],
    40824309                              wl_nm[i+1],
    4083                               &trigger,  // this is a dummy here
    4084                               &flashadc, // this is a dummy here
     4310                              trigger,  // this is a dummy here
     4311                              flashadc, // this is a dummy here
    40854312                              &itnphe,
    40864313                              nphe, // we want this!
     
    40884315                              &tmin_ns,
    40894316                              &tmax_ns,
    4090                               0
    4091                               ); // photons from starfield
     4317                              0,
     4318                              mirror_fraction); // photons from starfield
    40924319
    40934320            if( k != 0 ){ // non-zero returnvalue means error
     
    41244351
    41254352  return(0);
    4126 
    4127 }
    4128 
    4129 
    4130 //------------------------------------------------------------
    4131 // @name produce_nsb_phes
    4132 //                                     
    4133 // @desc produce the photoelectrons from the nsbrates
    4134 //
    4135 // @date Thu Feb 17 17:10:40 CET 2000
    4136 // @function @code
    4137 //------------------------------------------------------------
    4138 
    4139 int produce_nsb_phes( float *atmin_ns,
    4140                       float *atmax_ns,
    4141                       float theta_rad,
    4142                       struct camera *cam,
    4143                       float nsbr_phepns[iMAXNUMPIX][iNUMWAVEBANDS],
    4144                       float difnsbr_phepns[iMAXNUMPIX],
    4145                       float extinction[iNUMWAVEBANDS],
    4146                       float fnpx[iMAXNUMPIX],
    4147                       MTrigger *trigger,
    4148                       MFadc *fadc,
    4149                       int *inphe,
    4150                       float base_mv[iMAXNUMPIX]){
    4151 
    4152   float simtime_ns; // NSB simulation time
    4153   int i, j, k, ii;
    4154   float zenfactor;  //  correction factor calculated from the extinction
    4155   int inumnsbphe;   //  number of photoelectrons caused by NSB
    4156 
    4157   float t;
    4158   TRandom random;             // Random numbers generator
    4159 
    4160   random.SetSeed(get_seeds(1));
    4161 
    4162   ii = *inphe; // avoid dereferencing
    4163                
    4164   // check if the arrival times are set; if not generate them
    4165 
    4166   if(*atmin_ns <SIMTIMEOFFSET_NS || *atmin_ns > *atmax_ns){
    4167     *atmin_ns = 0.;
    4168     *atmax_ns = simtime_ns = TOTAL_TRIGGER_TIME;
    4169 
    4170   }
    4171   else{ // extend the event time window by the given offsets
    4172 
    4173     *atmin_ns = *atmin_ns - SIMTIMEOFFSET_NS;
    4174     *atmax_ns = *atmax_ns + SIMTIMEOFFSET_NS;
    4175 
    4176     simtime_ns = *atmax_ns - *atmin_ns;
    4177 
    4178     // make sure the simulated time is long enough for the FADC
    4179     // simulation and not too long
    4180 
    4181     if(simtime_ns< TOTAL_TRIGGER_TIME){
    4182       *atmin_ns = *atmin_ns -(TOTAL_TRIGGER_TIME-simtime_ns)/2;
    4183       *atmax_ns = *atmin_ns + TOTAL_TRIGGER_TIME;
    4184       simtime_ns = TOTAL_TRIGGER_TIME;
    4185     }
    4186 
    4187     if(simtime_ns> TOTAL_TRIGGER_TIME){
    4188       *atmax_ns =*atmin_ns + TOTAL_TRIGGER_TIME;
    4189       simtime_ns = TOTAL_TRIGGER_TIME;
    4190     }
    4191  
    4192   }
    4193 
    4194   // initialize baselines
    4195 
    4196   for(i=0; i<cam->inumpixels; i++){
    4197     base_mv[i] = 0.;
    4198   }
    4199 
    4200   // calculate baselines and generate phes
    4201 
    4202   for(i=0; i<iNUMWAVEBANDS; i++){ // loop over the wavebands
    4203    
    4204     // calculate the effect of the atmospheric extinction
    4205    
    4206     zenfactor = pow(10., -0.4 * extinction[i]/cos(theta_rad) );
    4207    
    4208     for(j=0; j<cam->inumpixels; j++){ // loop over the pixels
    4209      
    4210       inumnsbphe = (int) ((zenfactor * nsbr_phepns[j][i] + difnsbr_phepns[j]/iNUMWAVEBANDS) 
    4211                           * simtime_ns );
    4212 
    4213       base_mv[j] += inumnsbphe;
    4214 
    4215       // randomize
    4216 
    4217       if (inumnsbphe>0.0){
    4218         inumnsbphe = random.Poisson (inumnsbphe );
    4219       }
    4220 
    4221       // create the photoelectrons
    4222      
    4223       for(k=0; k < inumnsbphe; k++){
    4224        
    4225         t=(RandomNumber * simtime_ns);
    4226 
    4227         (*fadc).Fill(j,t ,(*trigger).FillNSB(j,t));
    4228        
    4229         ii++; // increment total number of photoelectons
    4230        
    4231         fnpx[j] += 1.; // increment number of photoelectrons in this pixel
    4232 
    4233       }
    4234      
    4235     } // end for(j=0 ...
    4236   } // end for(i=0 ...
    4237 
    4238   // finish baseline calculation
    4239 
    4240   for(i=0; i<cam->inumpixels; i++){
    4241     base_mv[i] *= RESPONSE_FWHM * RESPONSE_AMPLITUDE / simtime_ns;
    4242   }
    4243 
    4244   *inphe = ii; // update the pointer
    4245 
    4246   return(0);
    42474353}
    42484354
     
    42574363//
    42584364// $Log: not supported by cvs2svn $
     4365//
     4366// Revision 1.70  2004/09/15 A. Moralejo
     4367// Changed "flashadc" and "trigger" in procedure produce_nsbrates from
     4368// objects to pointers (followed by dynamical allocation). This is only
     4369// to avoid memory problems (-> segmentation fault) in some systems.
     4370// Introduced missing initialization to 0 of *itotnphe in produce_phes.
     4371// Now the number of phes produced by stars shown on the screen make sense.
     4372//
     4373// Revision 1.69  2004/03/30
     4374// Changed calculation of MMcFadcHeader.fPedesSigmaHigh and
     4375// MMcFadcHeader.fPedesSigmaLow to do as in real data (see comments in
     4376// code). Changed meaning of MMcFadcHeader.fAmplFadc and fAmplFadcOuter,
     4377// from amplitude to integral of single photoelectron pulse in FADC
     4378// counts. Added possibility to choose a realistic pulse shaped (as
     4379// measured using pulpo). Changed file Data/lightguides.dat by
     4380// Data/LightCollection.dat, intended to contain the information on
     4381// light collection efficiency regarding Winston cones, plexiglas, double
     4382// PMT crossing and colection efficiency of 1st dynode of PMT. Now the
     4383// information for inner and outer pixels can be different, since in the
     4384// LightCollection.dat file they are set independently.
     4385//
     4386// Revision 1.68  2004/02/06 17:39:24  blanch
     4387// Compiling with root 3.05 and updating MARS files.
     4388//
    42594389// Revision 1.67  2004/01/30 09:51:18  blanch
    42604390// [Changes mainly done by A. Moralejo]
     
    42654395// has been introduced.
    42664396//
    4267 // The possibilty to unlarge the point spread function has been introduced
     4397// The possibilty to enlarge the point spread function has been introduced
    42684398// in order to be able to simualte the current data.
    42694399//
Note: See TracChangeset for help on using the changeset viewer.