- Timestamp:
- 10/09/02 19:15:28 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Simulation/Detector/ReflectorII/reflector.c
r1431 r1535 13 13 * 14 14 * ---------------------------------------------------------------------- 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 * ---------------------------------------------------------------------- 15 24 */ 16 25 … … 36 45 static long writep = 0L; /* write ptr (on rflfile) */ 37 46 38 extern Cer Header *cheadp; /* var inited in header.c */39 extern Rfl Header *rheadp; /* var inited in header.c */47 extern CerEventHeader *cheadp; /* var inited in header.c */ 48 extern RflEventHeader *rheadp; /* var inited in header.c */ 40 49 41 50 /* Prototypes */ … … 43 52 FILE *GetNextFile(char *cername); 44 53 static int GetEvent(void); 45 static int ProcessEvent(CerHeader *cheadp, FILE *cerfile, FILE *rflfile); 54 static int ProcessEvent(CerEventHeader *cheadp, FILE *cerfile, FILE *rflfile); 55 void attach(FILE *f1, FILE *f2); 56 46 57 47 58 FILE *chkf = NULL; … … 51 62 52 63 main(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 */ 54 69 55 70 /* Read init & geometry parms, init files and vars */ … … 71 86 fwrite(FLAG_END_OF_FILE, SIZE_OF_FLAGS, 1, rflfile); 72 87 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 */ 74 102 Log(RFLF_CLOSE_LOG); 75 103 fclose(rflfile); … … 82 110 } /* end of main */ 83 111 84 static int ProcessEvent(Cer Header *cheadp, FILE *cerfile, FILE *rflfile)112 static int ProcessEvent(CerEventHeader *cheadp, FILE *cerfile, FILE *rflfile) 85 113 { extern int absorption(float wlen, float height, float theta); 86 114 extern int ph2cph(photon *ph, cphoton *cph); … … 92 120 extern void makeOmegaI(float theta, float phi); 93 121 94 char pp[256];95 122 96 123 /* Various counters: phs = absphs + refphs[0..3] + cphs */ … … 172 199 for (ph=0; ph<PH_IN_DATABLOCK; ph++) 173 200 { 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; 175 214 176 215 CPhotons[cphs].w = Photons[ph].w; 177 216 Photons[ph].w = wlen = (float) fmod(Photons[ph].w, 1000.); 178 217 179 /* TEMPORARY FIX,AM Nov 2001: we found that sometimes the value218 /* AM Nov 2001: we found that sometimes the value 180 219 stored in Photons[ph].w is not correct, and can result in a 181 220 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 } 187 232 188 233 /* ADDED AM May 2002: now we take into account the telescope … … 215 260 ph2cph(&Photons[ph], &CPhotons[cphs]))) 216 261 refphs[ref_type-1]++; 262 217 263 else /* Photon passed */ 218 264 { … … 260 306 rheadp->TimeLast = last; 261 307 262 /* Update Rfl Header with info on ph/cph nrs and write it */308 /* Update RflEventHeader with info on ph/cph nrs and write it */ 263 309 rheadp->CORSIKAPhs = phs; 264 310 rheadp->AtmAbsPhs = absphs; … … 268 314 rheadp->OutOfChamPhs = refphs[3]; 269 315 rheadp->CPhotons = (long) overflow * NR_OF_CPHOTONS + cphs; 270 fwrite(rheadp, sizeof(Rfl Header), 1, rflfile);271 272 /* for (myloop=0; myloop<sizeof(Rfl Header)/4; myloop++)316 fwrite(rheadp, sizeof(RflEventHeader), 1, rflfile); 317 318 /* for (myloop=0; myloop<sizeof(RflEventHeader)/4; myloop++) 273 319 * fprintf(chkf, "%e ", *((float *)rheadp+myloop)); 274 320 * fputc('\n', chkf); … … 284 330 fseek(tmpf, 0L, SEEK_SET); /* Start from the beginning */ 285 331 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 } 288 336 289 337 /* Reload data in CPhotons */ … … 291 339 292 340 /* Close (and delete) temp file */ 293 fclose(tmpf); } 341 fclose(tmpf); 342 } 294 343 295 344 /* Write (remaining) cphotons */ 345 296 346 fwrite(CPhotons, sizeof(cphoton), cphs, rflfile); 297 347 … … 308 358 309 359 static 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. */ 321 375 322 376 if (newFile 323 && (1 != fread(cheadp, sizeof(Cer Header), 1, cerfile)377 && (1 != fread(cheadp, sizeof(CerEventHeader), 1, cerfile) 324 378 || strncmp(cheadp->EVTH, "RUNH", 4))) 325 379 { isWrong = TRUE; } 326 380 327 381 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)) 333 395 { isWrong = TRUE; break; } 334 396 335 336 337 && first_Event <= (long)cheadp->EvtNumber338 && (long)cheadp->EvtNumber <= last_Event339 && low_Ecut <= cheadp->Etotal340 && 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) 341 403 { found = TRUE; } 342 404 343 344 345 405 /* File is finished: exit loop */ 406 else if (strncmp(cheadp->EVTH, "RUNE", 4) == 0) 407 break; 346 408 347 409 } while(found == FALSE);
Note:
See TracChangeset
for help on using the changeset viewer.