source: branches/Corsika7405Compatibility/mcorsika/MCorsikaRunHeader.cc@ 19187

Last change on this file since 19187 was 18179, checked in by dbaack, 10 years ago
File size: 10.9 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC 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 appear 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 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
19 Qi Zhe, 06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
20
21! Copyright: Software Development, 2000-2009
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MCorsikaRunHeader
29//
30// Root storage container for the RUN HEADER information
31//
32// Class Version 2:
33// ----------------
34// + UInt_t fParticleID
35// + Float_t fImpactMax
36// + Float_t fMagneticFieldX
37// + Float_t fMagneticFieldZ
38// + Float_t fMagneticFieldAz
39// + Float_t fAtmosphericLayers[5]
40// + Float_t fAtmosphericCoeffA[5]
41// + Float_t fAtmosphericCoeffB[5]
42// + Float_t fAtmosphericCoeffC[5]
43// + UInt_t fCerenkovFlag
44//
45// Class Version 3:
46// ----------------
47// + UInt_t fNumReuse
48//
49////////////////////////////////////////////////////////////////////////////
50
51#include "MCorsikaRunHeader.h"
52#include "MCorsikaFormat.h"
53
54#include <fstream>
55#include <iomanip>
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60#include "MMcEvt.hxx"
61
62ClassImp(MCorsikaRunHeader);
63
64using namespace std;
65
66const Double_t MCorsikaRunHeader::fgEarthRadius = 637131500; // [cm] Earth radius as defined in CORSIKA
67
68// --------------------------------------------------------------------------
69//
70// Default constructor. Creates array which stores the pixel assignment.
71//
72//
73MCorsikaRunHeader::MCorsikaRunHeader(const char *name, const char *title)
74 : fNumObsLevel(0), fImpactMax(-1), fZdMin(0), fZdMax(-1),
75 fAzMin(0), fAzMax(0), fViewConeInnerAngle(0), fViewConeOuterAngle(-1)
76{
77 fName = name ? name : "MCorsikaRunHeader";
78 fTitle = title ? title : "Raw Run Header Information";
79}
80
81// --------------------------------------------------------------------------
82//
83// Read in one run header from the binary file
84//
85Bool_t MCorsikaRunHeader::ReadEvt(MCorsikaFormat * fInFormat)
86{
87 Float_t f[272];
88 if (!fInFormat->Read(f, 272 * sizeof(Float_t)))
89 return kFALSE;
90
91 fRunNumber = TMath::Nint(f[0]);
92 fNumEvents = 0;
93
94 fRunStart.SetCorsikaTime(f[1]);
95
96 fProgramVersion = f[2];
97 fNumObsLevel = TMath::Nint(f[3]);
98
99 if (fNumObsLevel!=1)
100 {
101 *fLog << err << "ERROR - Currently only one observation level is allowed." << endl;
102 return kFALSE;
103 }
104
105 memset(fObsLevel, 0, 10*4);
106 memcpy(fObsLevel, f+4, fNumObsLevel*4);
107
108 fSlopeSpectrum = f[14];
109 fEnergyMin = f[15];
110 fEnergyMax = f[16];
111
112 // Implemented in CORSIKA Version >= 6.822
113 fImpactMax = -1;
114
115 // CORSIKA scattering in a disc on the ground
116 if (f[246]>0 && f[247]==0)
117 {
118 *fLog << warn << "WARNING - Events scattered in a disc on the ground." << endl;
119 fImpactMax = f[246];
120 }
121
122 // MMCS scattering in a disc perpendicular to the shower axis
123 if (f[246]==0 && f[247]>0)
124 fImpactMax = f[247];
125
126 // CORSIKA scattering in a rectangle on the ground
127 if (f[246]>0 && f[247]>0)
128 *fLog << warn << "WARNING - Events scattered in a rectangle on the ground." << endl;
129
130 // Implemented in CORSIKA Version >= 6.822
131 memcpy(fAtmosphericLayers, f+248, 5*4);
132
133 memcpy(fAtmosphericCoeffA, f+253, 5*4);
134 memcpy(fAtmosphericCoeffB, f+258, 5*4);
135 memcpy(fAtmosphericCoeffC, f+263, 5*4);
136
137 return kTRUE;
138}
139
140// --------------------------------------------------------------------------
141//
142// Read in one event header. It is called for the first event header after
143// a run header
144//
145Bool_t MCorsikaRunHeader::ReadEventHeader(Float_t * g)
146{
147
148 // -------------------- Read first event header -------------------
149
150 // FIXME: Add sanity checks!
151
152 // f[76] Cherenkov flag:
153 // bit(1) : CERENKOV option compiled in
154 // bit(2) : IACT option compiled in
155 // bit(3) : CEFFIC option compiled in
156 // bit(4) : ATMEXT option compiled in
157 // bit(5) : ATMEXT option used with refraction enabled
158 // bit(6) : VOLUMEDET option compiled in
159 // bit(7) : CURVED option compiled in
160 // bit(9) : SLATN option compiled in
161 // 11-21 : table number for externam athmosphere (but<1024)
162 //
163 // f[78] Curved athmosphere? (0=flat, 1=curved)
164 // f[84] cherenkov bunch size
165 // f[93] flag for additinal muon information of particle output file
166 // f[145] Muon multiple scattering flag
167
168
169 fNumReuse = TMath::Nint(g[96]); // Number i of uses of each cherenkov event
170
171 fParticleID = TMath::Nint(g[1]);
172
173 // MAGNETIC FIELD: x/z-component of earth magnetic field in muT
174 fMagneticFieldX = g[69]; // x-component ( BX)
175 fMagneticFieldZ = -g[70]; // z-component (-BZ)
176 fMagneticFieldAz = g[91]; // Azimuth angle of magnetic north expressed in telescope coordinates
177
178 // WITH rounding: unbelievable!
179 fCerenkovFlag = TMath::Nint(g[75]);
180
181 fZdMin = g[79]; // lower edge of theta in �
182 fZdMax = g[80]; // upper edge of theta in �
183 fAzMin = 180-g[81]; // lower edge of phi in �
184 fAzMax = 180-g[82]; // upper edge of phi in �
185 // FIXME: Correct for direction of magnetic field!
186
187 if (TMath::Nint(g[83])!=1)
188 *fLog << warn << "WARNING - Cherenkov bunch size not 1, but " << g[83] << endl;
189
190 // g[84] Number of cherenkov detectors in x
191 // g[85] Number of cherenkov detectors in y
192 // g[86] Grid spacing x
193 // g[87] Grid spacing y
194 // g[88] Length of detectors in x
195 // g[89] Length of detectors in y
196
197 fImpactMax = -1;
198/*
199 // This is a trick to use CERARY for storage of the
200 // maximum simulated impact
201 if (TMath::Nint(g[84])==1 && TMath::Nint(g[85])==1 &&
202 TMath::Nint(g[88])==1 && TMath::Nint(g[89])==1 &&
203 g[86]==g[87])
204 fImpactMax = g[86];
205 */
206 fWavelengthMin = g[94]; // Cherenkov bandwidth lower end in nm
207 fWavelengthMax = g[95]; // Cherenkov bandwidth upper end in nm
208
209 std::cout << "Version: " << fProgramVersion << std::endl;
210 std::cout << "Wavelength: " << fWavelengthMin << " - " << fWavelengthMax << std::endl;
211 if((abs(fWavelengthMax - 700)< 0.1) && (abs(fProgramVersion - 7.4005)< 1E-5)) fWavelengthMax = 900;
212
213 fViewConeInnerAngle = g[151]; // inner angle of view cone (�)
214 fViewConeOuterAngle = g[152]; // outer angle of view cone (�)
215
216 return kTRUE;
217}
218
219Bool_t MCorsikaRunHeader::ReadEvtEnd(MCorsikaFormat * fInFormat, Bool_t runNumberVerify)
220{
221 Float_t f[2];
222 if (!fInFormat->Read(f, 2 * sizeof(Float_t)))
223 return kFALSE;
224
225 if (runNumberVerify)
226 {
227 const UInt_t runnum = TMath::Nint(f[0]);
228 if (runnum!=fRunNumber)
229 {
230 *fLog << err << "ERROR - Mismatch in stream: Run number in RUNE (";
231 *fLog << runnum << ") doesn't match RUNH (" << fRunNumber << ")." << endl;
232 return kFALSE;
233 }
234 }
235
236 fNumEvents = TMath::Nint(f[1]);
237
238 return kTRUE;
239}
240
241Bool_t MCorsikaRunHeader::SeekEvtEnd(istream &fin)
242{
243 // Search subblockwise backward (Block: 5733*4 = 21*273*4)
244 for (int i=1; i<22; i++)
245 {
246 fin.seekg(-i*273*4, ios::end);
247
248 char runh[4];
249 fin.read(runh, 4);
250
251 if (!memcmp(runh, "RUNE", 4))
252 {
253 fin.seekg(-4, ios::cur);
254 return kTRUE;
255 }
256 }
257
258 return kFALSE;
259}
260
261// --------------------------------------------------------------------------
262//
263// print run header information on *fLog. The option 'header' supresses
264// the pixel index translation table.
265//
266void MCorsikaRunHeader::Print(Option_t *t) const
267{
268 *fLog << all << endl;
269 *fLog << "Run Number: " << fRunNumber << " (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
270 *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
271 if (fNumEvents>0)
272 *fLog << "Num Events: " << fNumEvents << " (reuse " << fNumReuse << " times)" << endl;
273 *fLog << "Obs Level: ";
274 for (Byte_t i=0; i<fNumObsLevel; i++)
275 *fLog << " " << fObsLevel[i]/100. << "m";
276 *fLog << endl;
277
278 *fLog << "MagneticField: X/Z=(" << fMagneticFieldX << "/";
279 *fLog << fMagneticFieldZ << ")" << UTF8::kMu << "T Az=" << fMagneticFieldAz*TMath::RadToDeg() << UTF8::kDeg << " (magnetic North w.r.t. North)" << endl;
280
281 *fLog << "Spectrum: Slope=" << fSlopeSpectrum << " (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" << endl;
282 *fLog << "Wavelength: " << fWavelengthMin << "nm - " << fWavelengthMax << "nm" << endl;
283
284 if (fImpactMax>0)
285 *fLog << "ImpactMax: " << fImpactMax << "cm" << endl;
286 if (fViewConeOuterAngle>0)
287 *fLog << "ViewCone: " << fViewConeInnerAngle << UTF8::kDeg << " - " << fViewConeOuterAngle << UTF8::kDeg << endl;
288
289 if (fZdMax>=0)
290 {
291 *fLog << "Zd/Az: " << fZdMin << UTF8::kDeg;
292 if (fZdMin==fZdMax)
293 *fLog << " (fixed)";
294 else
295 *fLog << "-" << fZdMax << UTF8::kDeg;
296 *fLog << " / " << fAzMin << UTF8::kDeg;
297 if (fAzMin==fAzMax)
298 *fLog << " (fixed)";
299 else
300 *fLog << "-" << fAzMax << UTF8::kDeg;
301 *fLog << " w.r.t. magnetic North." << endl;
302 }
303
304 if (fImpactMax>0)
305 *fLog << "Max.sim.Impact: " << fImpactMax << "cm" << endl;
306
307 *fLog << "Options used: ";
308 if (Has(kCerenkov))
309 *fLog << " CERENKOV";
310 if (Has(kIact))
311 *fLog << " IACT";
312 if (Has(kCeffic))
313 *fLog << " CEFFIC";
314 if (Has(kAtmext))
315 *fLog << " ATMEXT" << GetNumAtmosphericModel();
316 if (Has(kRefraction))
317 *fLog << " +Refraction";
318 if (Has(kVolumedet))
319 *fLog << " VOLUMEDET";
320 if (Has(kCurved))
321 *fLog << " CURVED";
322 if (Has(kSlant))
323 *fLog << " SLANT";
324 *fLog << endl;
325
326 if (HasLayers())
327 {
328 *fLog << "Atm.Layers: ";
329 for (int i=0; i<5; i++)
330 *fLog << " " << fAtmosphericLayers[i];
331 }
332 *fLog << "Atm.Coeff A: ";
333 for (int i=0; i<5; i++)
334 *fLog << " " << fAtmosphericCoeffA[i];
335 *fLog << endl;
336 *fLog << "Atm.Coeff B: ";
337 for (int i=0; i<5; i++)
338 *fLog << " " << fAtmosphericCoeffB[i];
339 *fLog << endl;
340 *fLog << "Atm.Coeff C: ";
341 for (int i=0; i<5; i++)
342 *fLog << " " << fAtmosphericCoeffC[i];
343 *fLog << endl;
344
345
346}
347
Note: See TracBrowser for help on using the repository browser.