Ignore:
Timestamp:
10/09/02 19:15:28 (22 years ago)
Author:
bigongia
Message:
Version 0.6. Changed output format: added run header, changed event header,
             added ascii parameter files attached at the end of every output
             file to keep all info.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Simulation/Detector/ReflectorII/reflector.c

    r1431 r1535  
    1313 *
    1414 * ----------------------------------------------------------------------
     15 *
     16 *  Modified: October 2002
     17 *  Author:   Abelardo Moralejo
     18 *  Version 0.6: introduced a run header and changed event header to keep
     19 *  all information from CORSIKA. In addition, now the magic.def, axisdev.dat
     20 *  and reflectivity.dat are attached at the end of the reflector output file
     21 *  to keep also all the parameters with which the program is run.
     22 *
     23 * ----------------------------------------------------------------------
    1524 */
    1625
     
    3645static long writep = 0L;        /*  write ptr (on rflfile)      */
    3746
    38 extern CerHeader *cheadp;       /*  var inited in header.c      */
    39 extern RflHeader *rheadp;       /*  var inited in header.c      */
     47extern CerEventHeader *cheadp;  /*  var inited in header.c      */
     48extern RflEventHeader *rheadp;  /*  var inited in header.c      */
    4049
    4150/*  Prototypes  */
     
    4352FILE *GetNextFile(char *cername);
    4453static int GetEvent(void);
    45 static int ProcessEvent(CerHeader *cheadp, FILE *cerfile, FILE *rflfile);
     54static int ProcessEvent(CerEventHeader *cheadp, FILE *cerfile, FILE *rflfile);
     55void attach(FILE *f1, FILE *f2);
     56
    4657
    4758FILE *chkf = NULL;
     
    5162
    5263main(void)
    53 {   long event = 0L;            /*  event counter       */
     64{
     65    extern char axisdev_filename[256], reflectivity_filename[256];
     66    extern char geo_filename[256];
     67    FILE *dummy;
     68    long event = 0L;            /*  event counter       */
    5469
    5570    /*  Read init & geometry parms, init files and vars */
     
    7186    fwrite(FLAG_END_OF_FILE, SIZE_OF_FLAGS, 1, rflfile);
    7287
    73     /*  Close file  */
     88    /* Attach parameter files used for running the program: */
     89    dummy = fopen (geo_filename,"r");
     90    attach (rflfile, dummy);
     91    fclose(dummy);
     92
     93    dummy = fopen (axisdev_filename,"r");
     94    attach (rflfile, dummy);
     95    fclose(dummy);
     96
     97    dummy = fopen (reflectivity_filename,"r");
     98    attach (rflfile, dummy);
     99    fclose(dummy);
     100
     101    /*  Close reflector output file  */
    74102    Log(RFLF_CLOSE_LOG);
    75103    fclose(rflfile);
     
    82110  } /*  end of main  */
    83111
    84 static int ProcessEvent(CerHeader *cheadp, FILE *cerfile, FILE *rflfile)
     112static int ProcessEvent(CerEventHeader *cheadp, FILE *cerfile, FILE *rflfile)
    85113{   extern int absorption(float wlen, float height, float theta);
    86114    extern int ph2cph(photon *ph, cphoton *cph);
     
    92120    extern void makeOmegaI(float theta, float phi);
    93121
    94     char pp[256];
    95122
    96123    /*  Various counters: phs = absphs + refphs[0..3] + cphs  */
     
    172199        for (ph=0; ph<PH_IN_DATABLOCK; ph++)
    173200          {
    174             if (Photons[ph].w <= 0.) break;
     201            /* Added July 2002, AM: check integrity of photon info:
     202               Sometimes we found NaN values inside cerXXXXX file.
     203             */
     204            if (isnan(Photons[ph].w) || isnan(Photons[ph].x) ||
     205                isnan(Photons[ph].y) || isnan(Photons[ph].u) ||
     206                isnan(Photons[ph].v) || isnan(Photons[ph].t) ||
     207                isnan(Photons[ph].h))
     208              {
     209                printf("Warning: skipped one photon because its data contained Not-a-Number!\n");
     210                continue;
     211              }
     212
     213            if (! (Photons[ph].w > 0.) ) break;
    175214
    176215            CPhotons[cphs].w = Photons[ph].w;
    177216            Photons[ph].w = wlen = (float) fmod(Photons[ph].w, 1000.);
    178217
    179             /* TEMPORARY FIX, AM Nov 2001: we found that sometimes the value
     218            /* AM Nov 2001: we found that sometimes the value
    180219               stored in Photons[ph].w is not correct, and can result in a
    181220               wavelength beyond 600 nm, which makes the program crash later.
    182                Now we force wlen to its expected range:
    183                */
    184 
    185             wlen = MIN(MAX(290.,wlen),600.);
    186 
     221
     222               AM July 2002: we now simply skip the photon if the wavelength
     223               is not in the expected range, which we now take from the corsika
     224               event header (just in case we would change it in the future).
     225            */
     226
     227               if (wlen < cheadp->CWaveLower || wlen > cheadp->CWaveUpper)
     228                 {
     229                   printf("Warning: skipped one photon with strange wavelength: %f nm\n", wlen);
     230                   continue;
     231                 }
    187232
    188233            /* ADDED AM May 2002: now we take into account the telescope
     
    215260                           ph2cph(&Photons[ph], &CPhotons[cphs])))
    216261              refphs[ref_type-1]++;
     262
    217263            else                /*      Photon passed   */
    218264              {
     
    260306        rheadp->TimeLast  = last;
    261307
    262         /*  Update RflHeader with info on ph/cph nrs and write it  */
     308        /*  Update RflEventHeader with info on ph/cph nrs and write it  */
    263309        rheadp->CORSIKAPhs   = phs;
    264310        rheadp->AtmAbsPhs    = absphs;
     
    268314        rheadp->OutOfChamPhs = refphs[3];
    269315        rheadp->CPhotons     = (long) overflow * NR_OF_CPHOTONS + cphs;
    270         fwrite(rheadp, sizeof(RflHeader), 1, rflfile);
    271 
    272 /*        for (myloop=0; myloop<sizeof(RflHeader)/4; myloop++)
     316        fwrite(rheadp, sizeof(RflEventHeader), 1, rflfile);
     317
     318/*        for (myloop=0; myloop<sizeof(RflEventHeader)/4; myloop++)
    273319 *        fprintf(chkf, "%e ", *((float *)rheadp+myloop));
    274320 *        fputc('\n', chkf);
     
    284330            fseek(tmpf, 0L, SEEK_SET); /*  Start from the beginning  */
    285331            while (overflow--)
    286               { fread (CPhotons, sizeof(cphoton), NR_OF_CPHOTONS, tmpf);
    287                 fwrite(CPhotons, sizeof(cphoton), NR_OF_CPHOTONS, rflfile); }
     332              {
     333                fread (CPhotons, sizeof(cphoton), NR_OF_CPHOTONS, tmpf);
     334                fwrite(CPhotons, sizeof(cphoton), NR_OF_CPHOTONS, rflfile);
     335              }
    288336
    289337            /*  Reload data in CPhotons    */
     
    291339
    292340            /*  Close (and delete) temp file  */
    293             fclose(tmpf);  }
     341            fclose(tmpf); 
     342          }
    294343
    295344        /*  Write (remaining) cphotons  */
     345
    296346        fwrite(CPhotons, sizeof(cphoton), cphs, rflfile);
    297347
     
    308358
    309359static int GetEvent(void)
    310 {   int found = FALSE,          /*  event found         */
    311       isWrong = FALSE;          /*  cerfile is wrong    */
    312       static int newFile = TRUE; /*  if TRUE, check if cerfile is valid */
    313 
    314       do
    315         { /* In case the just-opened file is a valid cerfile,
    316              starting with a RUNH, loop until a valid event is found:
    317              id est with: first_Event <= EvtNumber <= last_Event
    318              and             low_Ecut <=  Etotal   <= high_Ecut
    319              If the search was successful, "found" is set to TRUE.
    320              If there are reading errors, "isWrong" is set to TRUE. */
     360{   
     361  int found = FALSE,          /*  event found           */
     362  isWrong = FALSE;            /*  cerfile is wrong      */
     363  static int newFile = TRUE;  /*  if TRUE, check if cerfile is valid    */
     364
     365  CerRunHeader cRunHead;
     366 
     367  do
     368    {
     369      /* In case the just-opened file is a valid cerfile,
     370         starting with a RUNH, loop until a valid event is found:
     371         id est with: first_Event <= EvtNumber <= last_Event
     372         and             low_Ecut <=  Etotal   <= high_Ecut
     373         If the search was successful, "found" is set to TRUE.
     374         If there are reading errors, "isWrong" is set to TRUE. */
    321375
    322376        if (newFile
    323          && (1 != fread(cheadp, sizeof(CerHeader), 1, cerfile)
     377         && (1 != fread(cheadp, sizeof(CerEventHeader), 1, cerfile)
    324378             || strncmp(cheadp->EVTH, "RUNH", 4)))
    325379        {   isWrong = TRUE;   }
    326380
    327381        else do
    328         {   /*  Push fileptr in case it is a "EVTH"  */
    329             readp = ftell(cerfile);
    330 
    331             /*  Error: exit loop  */
    332             if (1 != fread(cheadp, sizeof(CerHeader), 1, cerfile))
     382        {
     383          if (newFile)
     384            {
     385              /* Write Reflector "run header" (one per cer file!): */
     386              memcpy(&cRunHead, cheadp, sizeof(CerEventHeader));
     387              fwrite(&cRunHead, sizeof(CerRunHeader), 1, rflfile);
     388            }
     389
     390          /*  Push fileptr in case it is a "EVTH"  */
     391          readp = ftell(cerfile);
     392
     393          /*  Error: exit loop  */
     394          if (1 != fread(cheadp, sizeof(CerEventHeader), 1, cerfile))
    333395            {   isWrong = TRUE;    break;   }
    334396
    335             /*  Ok: set found at TRUE and exit loop  */
    336             if (strncmp(cheadp->EVTH, "EVTH", 4) == 0
    337              && first_Event <= (long)cheadp->EvtNumber
    338              &&                (long)cheadp->EvtNumber <= last_Event
    339              &&    low_Ecut <= cheadp->Etotal
    340              &&                cheadp->Etotal <= high_Ecut)
     397          /*  Ok: set found at TRUE and exit loop  */
     398          if (strncmp(cheadp->EVTH, "EVTH", 4) == 0
     399              && first_Event <= (long)cheadp->EvtNumber
     400              &&                       (long)cheadp->EvtNumber <= last_Event
     401              &&    low_Ecut <= cheadp->Etotal
     402              &&                       cheadp->Etotal <= high_Ecut)
    341403            {   found = TRUE;   }
    342404
    343             /*  File is finished: exit loop  */
    344             else if (strncmp(cheadp->EVTH, "RUNE", 4) == 0)
    345                 break;
     405          /*  File is finished: exit loop  */
     406          else if (strncmp(cheadp->EVTH, "RUNE", 4) == 0)
     407            break;
    346408
    347409        } while(found == FALSE);
Note: See TracChangeset for help on using the changeset viewer.