source: trunk/Mars/msim/MSimAtmosphere.cc@ 19763

Last change on this file since 19763 was 19763, checked in by tbretz, 5 years ago
Moved the atmosphere code to its own files and make it accessible from teh interpreter.
File size: 28.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of CheObs, the Modular Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appears in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: CheObs Software Development, 2000-2009
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MSimAtmosphere
28//
29// Task to calculate wavelength or incident angle dependent absorption
30//
31// Input Containers:
32// MPhotonEvent
33// MCorsikaRunHeader
34//
35// Output Containers:
36// MPhotonEvent
37//
38//////////////////////////////////////////////////////////////////////////////
39#include "MSimAtmosphere.h"
40
41#include <fstream>
42
43#include <TGraph.h>
44#include <TRandom.h>
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50
51#include "MCorsikaRunHeader.h"
52#include "MPhotonEvent.h"
53#include "MPhotonData.h"
54
55#include "MAtmosphere.h"
56
57ClassImp(MSimAtmosphere);
58
59using namespace std;
60/*
61// ==========================================================================
62//
63// January 2002, A. Moralejo: We now precalculate the slant paths for the
64// aerosol and Ozone vertical profiles, and then do an interpolation in
65// wavelength for every photon to get the optical depths. The parameters
66// used, defined below, have been taken from "Atmospheric Optics", by
67// L. Elterman and R.B. Toolin, chapter 7 of the "Handbook of geophysics
68// and Space environments". (S.L. Valley, editor). McGraw-Hill, NY 1965.
69//
70// WARNING: the Mie scattering and the Ozone absorption are implemented
71// to work only with photons produced at a height a.s.l larger than the
72// observation level. So this is not expected to work well for simulating
73// the telescope pointing at theta > 90 deg (for instance for neutrino
74// studies. Rayleigh scattering works even for light coming from below.
75//
76// Fixed bugs (of small influence) in Mie absorption implementation: there
77// were errors in the optical depths table, as well as a confusion:
78// height a.s.l. was used as if it was height above the telescope level.
79// The latter error was also present in the Ozone aborption implementation.
80//
81// On the other hand, now we have the tables AE_ABI and OZ_ABI with optical
82// depths between sea level and a height h (before it was between 2km a.s.l
83// and a height h). So that we can simulate also in the future a different
84// observation level.
85//
86// AM: WARNING: IF VERY LARGE zenith angle simulations are to be done (say
87// above 85 degrees, for neutrino primaries or any other purpose) this code
88// will have to be adapted accordingly and checked, since in principle it has
89// been written and tested to simulate the absorption of Cherenkov photons
90// arriving at the telescope from above.
91//
92// AM: WARNING 2: not to be used for wavelengths outside the range 250-700 nm
93//
94// January 2003, Abelardo Moralejo: found error in Ozone absorption treatment.
95// At large zenith angles, the air mass used was the one calculated for
96// Rayleigh scattering, but since the Ozone distribution is rather different
97// from the global distribution of air molecules, this is not a good
98// approximation. Now I have left in this code only the Rayleigh scattering,
99// and moved to atm.c the Mie scattering and Ozone absorption calculated in
100// a better way.
101//
102// A. Moralejo, January 2003: added some parameters for Mie scattering
103// and Ozone absorption derived from the clear standard atmosphere model
104// in "Atmospheric Optics", by L. Elterman and R.B. Toolin, chapter 7 of
105// the "Handbook of geophysics and Space environments". S.L. Valley,
106// editor. McGraw-Hill, NY 1965.
107//
108// AM, Jan 2003: Changed the meaning of the argument height: now it is the
109// true height above sea level at which a photon has been emitted, before
110// it was the height given by Corsika, measured in the vertical of the
111// observer and not in the vertical of the emitting particle.
112//
113//
114// MAGIC-Winter and MAGIC-Summer by M. Haffke,
115// parametrizing profiles obtained with MSIS:
116// http://uap-www.nrl.navy.mil/models_web/msis/msis_home.htm
117//
118//
119// The MAGIC-Winter and MAGIC-Summer parametrisations reproduce the MSIS
120// profiles for the 3 atmospheric layers from 0 up to 40 km height. Beyond
121// that height, it was not possible to achieve a good fit, but the amount
122// of residual atmosphere is so small that light absorption would be
123// negligible anyway. Showers develop well below 40 km.
124//
125//
126// The mass overburden is given by T = AATM + BATM * exp(-h/CATM)
127// The last layer of the US standard atmosphere (in which T varies
128// linearly with h) is above 100 km and has not been included here
129// because it should not matter.
130//
131class MAtmRayleigh
132{
133private:
134 static const Double_t fgMeanFreePath; // [g/cm^2] Mean free path for scattering Rayleigh XR
135
136 Double_t fR; // [cm] Earth radius to be used
137
138 Double_t fHeight[5]; // Layer boundaries (atmospheric layer)
139
140 // Parameters of the different atmospheres. We use the same parametrization
141 // shape as in Corsika atmospheric models (see Corsika manual, appendix D).
142 // The values here can be/are obtained from the Corsika output
143 //Float_t fAtmA[4]; // The index refers to the atmospheric layer (starting from sea level and going upwards)
144 Float_t fAtmB[4]; // The index refers to the atmospheric layer (starting from sea level and going upwards)
145 Float_t fAtmC[4]; // The index refers to the atmospheric layer (starting from sea level and going upwards)
146
147 Double_t fRho[5]; // Precalculated integrals for rayleigh scatterning
148
149 // --------------------------------------------------------------------------
150 //
151 // Precalcalculate the integrals from the observer level to the next
152 // atmpsheric layer below including the lower boundary. Thus a
153 // correct calculation is reduced to the calculation of the upper
154 // boundary.
155 //
156 // fRho[0] = B0;
157 // fRho[1] = B0-A0 + B1;
158 // fRho[2] = B0-A0 + B1-A1 + B2;
159 // fRho[3] = B0-A0 + B1-A1 + B2+A2 + B3;
160 // fRho[4] = B0-A0 + B1-A1 + B2+A2 + B3 - A3;
161 //
162 void PreCalcRho()
163 {
164 // Limits (height in cm) of the four layers in which
165 // atmosphere is parametrized.
166 // This is a stupid trick giving 0 for the integrals below
167 // the observer
168
169 // FIXME: Could be replaced by 0, AtmLay[0]-fAtmLay[3]
170
171 const Double_t h[5] =
172 {
173 fObsLevel, // fObsLevel, // 0km
174 TMath::Max(fObsLevel, 7.75e5), // TMath::Max(fObsLevel, 4e5), // 4km
175 16.5e5, // 10e5, // 10km
176 50.0e5, // 40e5, // 40km
177 105.0e5, // 100e5 // 100km
178 };
179
180 memcpy(fHeight, h, sizeof(Double_t)*5);
181
182 fRho[0] = 0;
183 for (int i=0; i<4; i++)
184 {
185 const Double_t b = fAtmB[i];
186 const Double_t c = fAtmC[i];
187
188 const Double_t h1 = h[i+1];
189 const Double_t h0 = h[i];
190
191 const Double_t B = b*TMath::Exp(-h0/c);
192 const Double_t A = b*TMath::Exp(-h1/c);
193
194 // Calculate rho for the i-th layer from the lower
195 // to the higher layer boundary.
196 // If height is within the layer only calculate up to height.
197 fRho[i] += B;
198 fRho[i+1] = fRho[i] - A;
199 }
200 }
201
202protected:
203 Double_t fObsLevel; // [cm] observation level a.s.l.
204
205public:
206 // Init an atmosphere from the data stored in MCorsikaRunHeader
207 MAtmRayleigh(const MCorsikaRunHeader &h)
208 {
209 Init(h);
210 }
211
212 // Defualt constructor
213 MAtmRayleigh() : fObsLevel(-1) { }
214
215 // Check if the ovservation level has been correctly initialized
216 // Used as a marker for correct initialization
217 Bool_t IsValid() const { return fObsLevel>=0; }
218
219 // Get the Earth radius to be used
220 Double_t R() const { return fR; }
221
222 // Init an atmosphere from the data stored in MCorsikaRunHeader
223 // This initialized fObsLevel, fR, fAtmB and fAtmC and
224 // PreCalcRho
225 void Init(const MCorsikaRunHeader &h)
226 {
227 // Observation level above earth radius
228 fObsLevel = h.GetObsLevel();
229
230 // Use earth radius as defined in Corsika
231 fR = h.EarthRadius();
232
233 //memcpy(fAtmA, (Float_t*)h.GetAtmosphericCoeffA(), sizeof(Float_t)*4);
234 memcpy(fAtmB, (Float_t*)h.GetAtmosphericCoeffB(), sizeof(Float_t)*4);
235 memcpy(fAtmC, (Float_t*)h.GetAtmosphericCoeffC(), sizeof(Float_t)*4);
236
237 PreCalcRho();
238 }
239
240 // Return the vertical thickness between the observer and height.
241 // Therefor the integral of the layers below (including the lower
242 // boudary) Have been precalculated by PreCalcRho
243 Double_t GetVerticalThickness(Double_t height) const
244 {
245 // FIXME: We could store the start point above obs-level
246 // (Does this really gain anything?)
247 Int_t i=0;
248 while (i<4 && height>fHeight[i+1])
249 i++;
250
251 const Double_t b = fAtmB[i];
252 const Double_t c = fAtmC[i];
253
254 return fRho[i] - b*TMath::Exp(-height/c);
255 }
256
257 Double_t CalcTransmission(Double_t height, Double_t wavelength, Double_t sin2) const
258 {
259 // sin2: sin(theta)^2
260 // height is the true height a.s.l.
261
262 // LARGE ZENITH ANGLE FACTOR (AIR MASS FACTOR):
263 // Air mass factor "airmass" calculated using a one-exponential
264 // density profile for the atmosphere,
265 //
266 // rho = rho_0 exp(-height/hscale) with hscale = 7.4 km
267 //
268 // The air mass factor is defined as I(theta)/I(0), the ratio of
269 // the optical paths I (in g/cm2) traversed between two given
270 // heights, at theta and at 0 deg z.a.
271
272 const Double_t H = height-fObsLevel;
273 const Double_t h = 2*H;
274
275 // Scale-height (cm) for Exponential density profile
276 const Double_t hscale = 7.4e5;
277 const Double_t f = 2*hscale;
278
279 // Precalc R*cos(theta)^2 (FIXME: Is ph.GetCosW2 more precise?)
280 const Double_t Rcos2 = fR * (1-sin2); // cos2 = 1 - sin2
281
282 const Double_t x1 = TMath::Sqrt((Rcos2 ) / f);
283 const Double_t x2 = TMath::Sqrt((Rcos2 + 2*h) / f);
284 const Double_t x3 = TMath::Sqrt((fR ) / f);
285 const Double_t x4 = TMath::Sqrt((fR + 2*h) / f);
286
287 // Return a -1 transmittance in the case the photon comes
288 // exactly from the observation level, because in that case the
289 // "air mass factor" would become infinity and the calculation
290 // is not valid!
291 if (fabs(x3-x4) < 1.e-10)
292 return -1.;
293
294 const Double_t e12 = erfc(x1) - erfc(x2);
295 const Double_t e34 = erfc(x3) - erfc(x4);
296
297 const Double_t airmass = TMath::Exp(-fR*sin2 / f) * e12/e34;
298
299 // Calculate the traversed "vertical thickness" of air using the
300 // US Standard atmosphere:
301 const Double_t Rho_tot = GetVerticalThickness(height);
302
303 // We now convert from "vertical thickness" to "slanted thickness"
304 // traversed by the photon on its way to the telescope, simply
305 // multiplying by the air mass factor m:
306 const Double_t Rho_Fi = airmass * Rho_tot;
307
308 // Finally we calculate the transmission coefficient for the Rayleigh
309 // scattering:
310 // AM Dec 2002, introduced ABS below to account (in the future) for
311 // possible photons coming from below the observation level.
312
313 const Double_t wl = 400./wavelength;
314
315 // Mean free path for scattering Rayleigh XR (g/cm^2)
316 return TMath::Exp(-TMath::Abs(Rho_Fi/fgMeanFreePath)*wl*wl*wl*wl);
317 }
318};
319
320// ==========================================================================
321
322class MAtmosphere : public MAtmRayleigh
323{
324private:
325 static const Double_t STEPTHETA; // aprox. 1 degree
326
327 // Aerosol number density for 31 heights a.s.l., from 0 to 30 km,
328 // in 1 km steps (units: cm^-3)
329 static const Double_t aero_n[31];
330
331 // Ozone concentration for 51 heights a.s.l., from 0 to 50 km,
332 // in 1 km steps (units: cm/km)
333 static const Double_t oz_conc[51];
334
335 // aerosol_path contains the path integrals for the aerosol number
336 // density (relative to the number density at sea level) between the
337 // observation level and a height h for different zenith angles. The
338 // first index indicate height above sea level in units of 100m, the
339 // second is the zenith angle in degrees.
340 float aerosol_path[301][90];
341
342 // ozone_path contains the path integrals for the ozone concentration
343 // between the observation level and a height h for different zenith
344 // angles. The first index indicate height above sea level in units
345 // of 100m, the second is the zenith angle in degrees.
346 float ozone_path[501][90];
347
348 // Interpolate the graph at wavelength
349 Double_t GetBeta(Double_t wavelength, const TGraph &g) const
350 {
351 // FIXME: This might not be the fastest because range
352 // checks are done for each call!
353 return g.GetN()==0 ? 0 : g.Eval(wavelength)*1e-5; // from km^-1 to cm^-1
354 }
355
356
357 //MSpline3 *fAbsCoeffOzone;
358 //MSpline3 *fAbsCoeffAerosols;
359
360 TGraph *fAbsCoeffOzone;
361 TGraph *fAbsCoeffAerosols;
362
363public:
364 MAtmosphere(const MCorsikaRunHeader &h) : fAbsCoeffOzone(0), fAbsCoeffAerosols(0)
365 {
366 Init(h);//, "ozone.txt", "aerosols.txt");
367 }
368
369 MAtmosphere(const char *name1=0, const char *name2=0) : fAbsCoeffOzone(0), fAbsCoeffAerosols(0)
370 {
371 if (name1)
372 InitOzone(name1);
373 if (name2)
374 InitAerosols(name2);
375 }
376
377 ~MAtmosphere()
378 {
379 if (fAbsCoeffOzone)
380 delete fAbsCoeffOzone;
381 if (fAbsCoeffAerosols)
382 delete fAbsCoeffAerosols;
383 }
384
385 Float_t GetWavelengthMin() const { return fAbsCoeffOzone && fAbsCoeffAerosols ? TMath::Max(fAbsCoeffOzone->GetX()[0], fAbsCoeffAerosols->GetX()[0]) : -1; }
386 Float_t GetWavelengthMax() const { return fAbsCoeffOzone && fAbsCoeffAerosols ? TMath::Min(fAbsCoeffOzone->GetX()[fAbsCoeffOzone->GetN()-1], fAbsCoeffAerosols->GetX()[fAbsCoeffAerosols->GetN()-1]) : -1; }
387
388 Bool_t HasValidOzone() const { return fAbsCoeffOzone && fAbsCoeffOzone->GetN()>0; }
389 Bool_t HasValidAerosol() const { return fAbsCoeffAerosols && fAbsCoeffAerosols->GetN()>0; }
390
391 Bool_t IsAllValid() const { return IsValid() && HasValidOzone() && HasValidAerosol(); }
392
393 void PreCalcOzone()
394 {
395 // It follows a precalculation of the slant path integrals we need
396 // for the estimate of the Mie scattering and Ozone absorption:
397 Double_t dh = 1.e3;
398 //const Double_t STEPTHETA = 1.74533e-2; // aprox. 1 degree
399
400 // Ozone absorption
401 for (Int_t j = 0; j < 90; j++)
402 {
403 const Double_t theta = j * STEPTHETA;
404 const Double_t sin2 = sin(theta)*sin(theta);
405 const Double_t H = R()+fObsLevel;
406
407 Double_t path_slant = 0;
408 for (Double_t h = fObsLevel; h <= 50e5; h += dh)
409 {
410 // h is the true height vertical above ground
411 if (fmod(h,1e4) == 0)
412 ozone_path[(int)(h/1e4)][j] = path_slant;
413
414 const Double_t km = h/1e5;
415 const Int_t i = TMath::FloorNint(km);
416 const Double_t l = R()+h;
417
418 const Double_t L = TMath::Sqrt(l*l - H*H * sin2);
419 const Double_t f = dh * l / L;
420
421 // Linear interpolation at h/1e5
422 Double_t interpol = oz_conc[i] + fmod(km, 1) * (oz_conc[i+1]-oz_conc[i]);
423
424 path_slant += f * interpol;
425 }
426 }
427 }
428
429 void PreCalcAerosol()
430 {
431 // It follows a precalculation of the slant path integrals we need
432 // for the estimate of the Mie scattering and Ozone absorption:
433 Double_t dh = 1.e3;
434 //const Double_t STEPTHETA = 1.74533e-2; // aprox. 1 degree
435
436 // Mie (aerosol):
437 for (Int_t j = 0; j < 90; j++)
438 {
439 const Double_t theta = j * STEPTHETA;
440 const Double_t sin2 = sin(theta)*sin(theta);
441 const Double_t H = R()+fObsLevel;
442
443 Double_t path_slant = 0;
444 for (Double_t h = fObsLevel; h <= 30e5; h += dh)
445 {
446 // h is the true height vertical above ground
447 if (fmod(h,1e4) == 0)
448 aerosol_path[(int)(h/1e4)][j] = path_slant;
449
450 const Double_t km = h/1e5;
451 const Int_t i = TMath::FloorNint(km);
452 const Double_t l = R()+h;
453
454 const Double_t L = TMath::Sqrt(l*l - H*H * sin2);
455 const Double_t f = dh * l / L;
456
457 // Linear interpolation at h/1e5
458 Double_t interpol = aero_n[i] + fmod(km, 1)*(aero_n[i+1]-aero_n[i]);
459
460 path_slant += f * interpol/aero_n[0]; // aero_n [km^-1]
461 }
462 }
463 }
464
465 Bool_t InitOzone(const TString name="")
466 {
467 if (!name.IsNull())
468 {
469 if (fAbsCoeffOzone)
470 delete fAbsCoeffOzone;
471
472 fAbsCoeffOzone = new TGraph(name);
473 fAbsCoeffOzone->Sort();
474 }
475
476 if (!HasValidAerosol())
477 return kFALSE;
478
479 if (IsValid())
480 PreCalcOzone();
481
482 return kTRUE;
483 }
484
485 Bool_t InitAerosols(const TString name="")
486 {
487 if (!name.IsNull())
488 {
489 if (fAbsCoeffAerosols)
490 delete fAbsCoeffAerosols;
491
492 fAbsCoeffAerosols = new TGraph(name);
493 fAbsCoeffAerosols->Sort();
494 }
495
496 if (!HasValidAerosol())
497 return kFALSE;
498
499 if (IsValid())
500 PreCalcAerosol();
501
502 return kTRUE;
503 }
504
505 void Init(const MCorsikaRunHeader &h, const char *name1=0, const char *name2=0)
506 {
507 MAtmRayleigh::Init(h);
508
509 InitOzone(name1);
510 InitAerosols(name2);
511 }
512
513 Double_t CalcOzoneAbsorption(Double_t h, Double_t wavelength, Double_t theta) const
514 {
515 if (!fAbsCoeffOzone)
516 return 1;
517
518 // ******* Ozone absorption *******
519 if (h > 50.e5)
520 h = 50.e5;
521
522 // Vigroux Ozone absorption coefficient a.s.l. through interpolation:
523 //const float oz_vigroux[15]= {1.06e2, 1.01e1, 8.98e-1, 6.40e-2, 1.80e-3, 0, 0, 3.50e-3, 3.45e-2, 9.20e-2, 1.32e-1, 6.20e-2, 2.30e-2, 1.00e-2, 0.00};
524 //const Double_t beta0 = getbeta(wavelength, oz_vigroux);
525 const Double_t beta0 = GetBeta(wavelength, *fAbsCoeffOzone);
526
527 // Now use the pre-calculated values of the path integral
528 // for h and theta
529 const UInt_t H = TMath::Nint(h/1e4);
530 const UInt_t T = TMath::Min(89, TMath::Nint(theta/STEPTHETA));
531
532 const Double_t path = ozone_path[H][T];
533
534 return TMath::Exp(-beta0*path);
535 }
536
537 Double_t CalcAerosolAbsorption(Double_t h, Double_t wavelength, Double_t theta) const
538 {
539 if (!fAbsCoeffAerosols)
540 return 1;
541
542 // ******* Mie (aerosol) *******
543 if (h > 30.e5)
544 h = 30.e5;
545
546 //const float aero_betap[15] = {0.27, 0.26, 0.25, 0.24, 0.24, 0.23, 0.20, 0.180, 0.167, 0.158, 0.150, 0.142, 0.135, 0.127, 0.120};
547 //const Double_t beta0 = getbeta(wavelength, aero_betap);
548 const Double_t beta0 = GetBeta(wavelength, *fAbsCoeffAerosols);
549
550 // Now use the pre-calculated values of the path integral
551 // for h and theta
552 const UInt_t H = TMath::Nint(h/1e4);
553 const UInt_t T = TMath::Min(89, TMath::Nint(theta/STEPTHETA));
554
555
556 const Double_t path = aerosol_path[H][T];
557
558 return TMath::Exp(-beta0*path);
559 }
560
561 Double_t GetTransmission(const MPhotonData &ph) const
562 {
563 const Double_t wavelength = ph.GetWavelength();
564 const Double_t height = ph.GetProductionHeight();
565
566 // Reduce the necessary number of floating point operations
567 // by storing the intermediate results
568 const Double_t sin2 = ph.GetSinW2();
569 const Double_t cost = TMath::Sqrt(1-sin2);
570 const Double_t theta = TMath::ACos(cost);
571
572 // Path from production height to obslevel
573 const Double_t z = height-fObsLevel;
574
575 // Distance of emission point to incident point on ground
576 const Double_t d = z/cost;
577
578 // Avoid problems if photon is very close to telescope:
579 if (TMath::Abs(d)<1)
580 return 1;
581
582 // Earth radius plus observation height (distance of telescope
583 // from earth center)
584 const Double_t H = R() + fObsLevel;
585
586 // We calculate h, the true height a.s.l.
587 // of the photon emission point in cm
588 const Double_t h = TMath::Sqrt(H*H + d*d + 2*H*z) - R();
589
590 // **** Rayleigh scattering: *****
591 const Double_t T_Ray = CalcTransmission(h, wavelength, sin2);
592 if (T_Ray<0)
593 return 0;
594
595 // ****** Ozone absorption: ******
596 const Double_t T_Oz = CalcOzoneAbsorption(h, wavelength, theta);
597
598 // ******** Mie (aerosol) ********
599 const Double_t T_Mie = CalcAerosolAbsorption(h, wavelength, theta);
600
601 // FIXME: What if I wanna display these values?
602
603 // Calculate final transmission coefficient
604 return T_Ray * T_Oz * T_Mie;
605 }
606};
607
608const Double_t MAtmosphere::STEPTHETA = 1.74533e-2; // aprox. 1 degree
609
610const Double_t MAtmRayleigh::fgMeanFreePath = 2970;
611
612const Double_t MAtmosphere::aero_n[31] = {200, 87, 38, 16, 7.2, 3.1, 1.1, 0.4, 0.14, 5.0e-2, 2.6e-2, 2.3e-2, 2.1e-2, 2.3e-2, 2.5e-2, 4.1e-2, 6.7e-2, 7.3e-2, 8.0e-2, 9.0e-2, 8.6e-2, 8.2e-2, 8.0e-2, 7.6e-2, 5.2e-2, 3.6e-2, 2.5e-2, 2.4e-2, 2.2e-2, 2.0e-2, 1.9e-2};
613
614const Double_t MAtmosphere::oz_conc[51]={0.3556603E-02, 0.3264150E-02, 0.2933961E-02, 0.2499999E-02, 0.2264150E-02, 0.2207546E-02, 0.2160377E-02, 0.2226414E-02, 0.2283018E-02, 0.2811320E-02, 0.3499999E-02, 0.4603772E-02, 0.6207545E-02, 0.8452828E-02, 0.9528299E-02, 0.9905657E-02, 0.1028302E-01, 0.1113207E-01, 0.1216981E-01, 0.1424528E-01, 0.1641509E-01, 0.1839622E-01, 0.1971697E-01, 0.1981131E-01, 0.1933962E-01, 0.1801886E-01, 0.1632075E-01, 0.1405660E-01, 0.1226415E-01, 0.1066037E-01, 0.9028300E-02, 0.7933960E-02, 0.6830187E-02, 0.5820753E-02, 0.4830188E-02, 0.4311319E-02, 0.3613206E-02, 0.3018867E-02, 0.2528301E-02, 0.2169811E-02, 0.1858490E-02, 0.1518867E-02, 0.1188679E-02, 0.9301884E-03, 0.7443394E-03, 0.5764149E-03, 0.4462263E-03, 0.3528301E-03, 0.2792452E-03, 0.2226415E-03, 0.1858490E-03};
615*/
616// ==========================================================================
617
618// --------------------------------------------------------------------------
619//
620// Default Constructor.
621//
622MSimAtmosphere::MSimAtmosphere(const char* name, const char *title)
623 : fRunHeader(0), fEvt(0), fAtmosphere(0),
624 fFileAerosols("resmc/atmosphere-aerosols.txt"),
625 fFileOzone("resmc/atmosphere-ozone.txt"),
626 fForce(kFALSE)
627{
628 fName = name ? name : "MSimAtmosphere";
629 fTitle = title ? title : "Simulate the wavelength and height-dependant atmpsheric absorption";
630
631 fAtmosphere = new MAtmosphere;
632}
633
634// --------------------------------------------------------------------------
635//
636// Calls Clear()
637//
638MSimAtmosphere::~MSimAtmosphere()
639{
640 delete fAtmosphere;
641}
642
643// --------------------------------------------------------------------------
644//
645// Search for the needed parameter containers. Read spline from file
646// calling ReadFile();
647//
648Int_t MSimAtmosphere::PreProcess(MParList *pList)
649{
650 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
651 if (!fEvt)
652 {
653 *fLog << err << "MPhotonEvent not found... aborting." << endl;
654 return kFALSE;
655 }
656
657
658 return kTRUE;
659}
660
661// --------------------------------------------------------------------------
662//
663Bool_t MSimAtmosphere::ReInit(MParList *pList)
664{
665 fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
666 if (!fRunHeader)
667 {
668 *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
669 return kFALSE;
670 }
671
672 if (fRunHeader->Has(MCorsikaRunHeader::kCeffic) && !fForce)
673 {
674 *fLog << inf << "CEFFIC enabled... task will be skipped." << endl;
675 return kTRUE;
676 }
677
678 //if (fRunHeader->Has(MCorsikaRunHeader::kRefraction))
679 // *fLog << inf << "Atmospheric refraction already applied in Corsika... skipping our own." << endl;
680
681 // FIXME: Check wavelength range
682
683 /*
684 if (h->GetWavelengthMin()<fSpline->GetXmin())
685 *fLog << warn << "WARNING - Lower bound of wavelength bandwidth exceeds lower bound of spline." << endl;
686
687 if (h->GetWavelengthMax()>fSpline->GetXmax())
688 *fLog << warn << "WARNING - Upper bound of wavelength bandwidth exceeds upper bound of spline." << endl;
689 */
690
691 fAtmosphere->Init(*fRunHeader, fFileOzone, fFileAerosols);
692
693 if (!fAtmosphere->IsAllValid())
694 {
695 *fLog << err << "ERROR - Something with the atmoshere's initialization went wrong!" << endl;
696 return kFALSE;
697 }
698
699 if (fRunHeader->GetWavelengthMin()<fAtmosphere->GetWavelengthMin())
700 *fLog << warn << "WARNING - Lower bound of wavelength bandwidth exceeds valid range of atmosphere." << endl;
701
702 if (fRunHeader->GetWavelengthMax()>fAtmosphere->GetWavelengthMax())
703 *fLog << warn << "WARNING - Lower bound of wavelength bandwidth exceeds valid range of atmosphere." << endl;
704
705 if (!fRunHeader->Has(MCorsikaRunHeader::kAtmext))
706 *fLog << warn << "WARNING - ATMEXT option not used for Corsika data." << endl;
707
708 if (!fRunHeader->Has(MCorsikaRunHeader::kRefraction))
709 *fLog << warn << "WARNING - Refraction calculation disabled for Corsika data." << endl;
710
711 return kTRUE;
712}
713
714// --------------------------------------------------------------------------
715//
716Int_t MSimAtmosphere::Process()
717{
718 // Skip the task if the CEFFIC option has been enabled and
719 // its excution has not been forced by the user
720 if (!fForce && fRunHeader->Has(MCorsikaRunHeader::kCeffic))
721 return kTRUE;
722
723 // Get the number of photons in the list
724 const Int_t num = fEvt->GetNumPhotons();
725
726 // FIMXE: Add checks for
727 // * upgoing particles
728 // * Can we take the full length until the camera into account?
729
730 // Counter for number of total and final events
731 Int_t cnt = 0;
732 for (Int_t i=0; i<num; i++)
733 {
734 // Get i-th photon from the list
735 const MPhotonData &ph = (*fEvt)[i];
736
737 // Get atmospheric transmission for this photon
738 const Double_t eff = fAtmosphere->GetTransmission(ph);
739
740 // Get a random value between 0 and 1 to determine whether the photon will survive
741 // gRandom->Rndm() = [0;1[
742 if (gRandom->Rndm()>=eff)
743 continue;
744
745 // Copy the surviving events bakc in the list
746 (*fEvt)[cnt++] = ph;
747 }
748
749 // Now we shrink the array to the number of new entries.
750 fEvt->Shrink(cnt);
751
752 return kTRUE;
753}
754
755/*
756 Int_t MSimWavelength::Process()
757 {
758 // Get the number of photons in the list
759 const Int_t num = fEvt->GetNumPhotons();
760
761 // FIMXE: Add checks for
762 // * upgoing particles
763 // * wavelength range
764 // * check if corsika atmosphere is switched on
765 // * Can we take the full length until the camera into account?
766
767 // Counter for number of total and final events
768 Int_t cnt = 0;
769 for (Int_t i=0; i<num; i++)
770 {
771 // Get i-th photon from the list
772 MPhotonData &ph = (*fEvt)[i];
773
774 const Double_t min = fRunHeader->GetWavelengthMin(); // WAVLGL
775 const Double_t max = fRunHeader->GetWavelengthMax(); // WAVLGU
776 const Double_t f = (max-min)/max;
777
778 // WAVELENGTH = 1. / (1/min - RD(1)/(min*max/(max-min)))
779
780
781 ph.SetWavelength(TMath::Nint(min / (1. - gRandom->Rndm()*f)));
782 }
783
784 return kTRUE;
785 }
786 */
787
788// --------------------------------------------------------------------------
789//
790// FileAerosols: resmc/atmosphere-aerosols.txt
791// FileOzone: resmc/atmosphere-ozone.txt
792//
793Int_t MSimAtmosphere::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
794{
795 Bool_t rc = kFALSE;
796
797 if (IsEnvDefined(env, prefix, "FileAerosols", print))
798 {
799 rc = kTRUE;
800 fFileAerosols = GetEnvValue(env, prefix, "FileAerosols", fFileAerosols);
801 }
802
803 if (IsEnvDefined(env, prefix, "FileOzone", print))
804 {
805 rc = kTRUE;
806 fFileOzone = GetEnvValue(env, prefix, "FileOzone", fFileOzone);
807 }
808
809 if (IsEnvDefined(env, prefix, "Force", print))
810 {
811 rc = kTRUE;
812 fForce = GetEnvValue(env, prefix, "Force", fForce);
813 }
814
815 return rc;
816}
Note: See TracBrowser for help on using the repository browser.