source: trunk/Mars/mcorsika/MCorsikaRunHeader.cc@ 19550

Last change on this file since 19550 was 19343, checked in by tbretz, 6 years ago
Reading and printing some more options from the file headers
File size: 13.8 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// Class Version 4:
50// ----------------
51// + UInt_t fCerenkovFileOption
52// + UInt_t fHadronModelLowEnergy
53// + UInt_t fHadronModelHighEnergy
54// + Float_t fTransitionEnergy
55// + Bool_t fCurvedAtmosphere
56// + Float_t fEnergyCutoffHadrons
57// + Float_t fEnergyCutoffMuons
58// + Float_t fEnergyCutoffElectrons
59// + Float_t fEnergyCutoffPhotons
60// + Float_t fThinningEnergyFractionH
61// + Float_t fThinningEnergyFractionEM
62// + Float_t fThinningWeightLimitH
63// + Float_t fThinningWeightLimitEM
64// + Float_t fThinningMaxRadius
65//
66////////////////////////////////////////////////////////////////////////////
67
68#include "MCorsikaRunHeader.h"
69#include "MCorsikaFormat.h"
70
71#include <fstream>
72#include <iomanip>
73
74#include "MLog.h"
75#include "MLogManip.h"
76
77#include "MMcEvt.hxx"
78
79ClassImp(MCorsikaRunHeader);
80
81using namespace std;
82
83const Double_t MCorsikaRunHeader::fgEarthRadius = 637131500; // [cm] Earth radius as defined in CORSIKA
84
85// --------------------------------------------------------------------------
86//
87// Default constructor. Creates array which stores the pixel assignment.
88//
89//
90MCorsikaRunHeader::MCorsikaRunHeader(const char *name, const char *title)
91 : fNumObsLevel(0), fImpactMax(-1), fZdMin(0), fZdMax(-1),
92 fAzMin(0), fAzMax(0), fViewConeInnerAngle(0), fViewConeOuterAngle(-1)
93{
94 fName = name ? name : "MCorsikaRunHeader";
95 fTitle = title ? title : "Raw Run Header Information";
96}
97
98// --------------------------------------------------------------------------
99//
100// Read in one run header from the binary file
101//
102Bool_t MCorsikaRunHeader::ReadEvt(MCorsikaFormat * fInFormat, const uint32_t &blockLength)
103{
104 vector<Float_t> f(blockLength);
105 if (!fInFormat->Read(f.data(), blockLength*sizeof(Float_t)))
106 return kFALSE;
107
108 fRunNumber = TMath::Nint(f[0]);
109 fNumEvents = 0;
110
111 fRunStart.SetCorsikaTime(f[1]);
112
113 fProgramVersion = f[2];
114 fNumObsLevel = TMath::Nint(f[3]);
115
116 if (fNumObsLevel!=1)
117 {
118 *fLog << err << "ERROR - Currently only one observation level is allowed." << endl;
119 return kFALSE;
120 }
121
122 memset(fObsLevel, 0, 10*4);
123 memcpy(fObsLevel, f.data()+4, fNumObsLevel*4);
124
125 fSlopeSpectrum = f[14];
126 fEnergyMin = f[15];
127 fEnergyMax = f[16];
128
129 fEnergyCutoffHadrons = f[17];
130 fEnergyCutoffMuons = f[18];
131 fEnergyCutoffElectrons = f[19];
132 fEnergyCutoffPhotons = f[20];
133
134 // Implemented in CORSIKA Version >= 6.822
135 fImpactMax = -1;
136
137 // CORSIKA scattering in a disc on the ground
138 if (f[246]>0 && f[247]==0 && !fInFormat->IsEventioFormat())
139 {
140 *fLog << warn << "WARNING - Events scattered in a disc on the ground." << endl;
141 fImpactMax = f[246];
142 }
143
144 // MMCS scattering in a disc perpendicular to the shower axis
145 if (f[246]==0 && f[247]>0)
146 fImpactMax = f[247];
147
148 // CORSIKA scattering in a rectangle on the ground
149 if (f[246]>0 && f[247]>0)
150 *fLog << warn << "WARNING - Events scattered in a rectangle on the ground." << endl;
151
152 // Implemented in CORSIKA Version >= 6.822
153 memcpy(fAtmosphericLayers, f.data()+248, 5*4);
154
155 memcpy(fAtmosphericCoeffA, f.data()+253, 5*4);
156 memcpy(fAtmosphericCoeffB, f.data()+258, 5*4);
157 memcpy(fAtmosphericCoeffC, f.data()+263, 5*4);
158
159 return kTRUE;
160}
161
162// --------------------------------------------------------------------------
163//
164// Read in one event header. It is called for the first event header after
165// a run header
166//
167Bool_t MCorsikaRunHeader::ReadEventHeader(Float_t * g)
168{
169
170 // -------------------- Read first event header -------------------
171
172 // FIXME: Add sanity checks!
173
174 // f[76] Cherenkov flag:
175 // bit(1) : CERENKOV option compiled in
176 // bit(2) : IACT option compiled in
177 // bit(3) : CEFFIC option compiled in
178 // bit(4) : ATMEXT option compiled in
179 // bit(5) : ATMEXT option used with refraction enabled
180 // bit(6) : VOLUMEDET option compiled in
181 // bit(7) : CURVED option compiled in
182 // bit(9) : SLATN option compiled in
183 // 11-21 : table number for externam athmosphere (but<1024)
184 //
185 // f[78] Curved athmosphere? (0=flat, 1=curved)
186 // f[84] cherenkov bunch size
187 // f[93] flag for additinal muon information of particle output file
188 // f[145] Muon multiple scattering flag
189
190
191 fNumReuse = TMath::Nint(g[96]); // Number i of uses of each cherenkov event
192
193 fParticleID = TMath::Nint(g[1]);
194
195 // MAGNETIC FIELD: x/z-component of earth magnetic field in muT
196 fMagneticFieldX = g[69]; // x-component ( BX)
197 fMagneticFieldZ = -g[70]; // z-component (-BZ)
198 fMagneticFieldAz = g[91]; // Azimuth angle of magnetic north expressed in telescope coordinates
199
200 fHadronModelLowEnergy = TMath::Nint(g[73]);
201 fHadronModelHighEnergy = TMath::Nint(g[74]);
202
203 // WITH rounding: unbelievable!
204 fCerenkovFlag = TMath::Nint(g[75]);
205 fCerenkovFileOption = TMath::Nint(g[90]);
206
207 fCurvedAtmosphere = TMath::Nint(g[77])==2;
208
209 fZdMin = g[79]; // lower edge of theta in °
210 fZdMax = g[80]; // upper edge of theta in °
211 fAzMin = 180-g[81]; // lower edge of phi in °
212 fAzMax = 180-g[82]; // upper edge of phi in °
213 // FIXME: Correct for direction of magnetic field!
214
215 if (TMath::Nint(g[83])!=1)
216 *fLog << warn << "WARNING - Cherenkov bunch size not 1, but " << g[83] << endl;
217
218 // g[84] Number of cherenkov detectors in x
219 // g[85] Number of cherenkov detectors in y
220 // g[86] Grid spacing x
221 // g[87] Grid spacing y
222 // g[88] Length of detectors in x
223 // g[89] Length of detectors in y
224
225 fImpactMax = -1;
226/*
227 // This is a trick to use CERARY for storage of the
228 // maximum simulated impact
229 if (TMath::Nint(g[84])==1 && TMath::Nint(g[85])==1 &&
230 TMath::Nint(g[88])==1 && TMath::Nint(g[89])==1 &&
231 g[86]==g[87])
232 fImpactMax = g[86];
233 */
234 fWavelengthMin = g[94]; // Cherenkov bandwidth lower end in nm
235 fWavelengthMax = g[95]; // Cherenkov bandwidth upper end in nm
236
237 fThinningEnergyFractionH = g[146]; // EFRCTHN
238 fThinningEnergyFractionEM = g[147]; // EFRCTHN*THINRAT
239 fThinningWeightLimitH = g[148]; // WMAX
240 fThinningWeightLimitEM = g[149]; // WMAX*WEITRAT
241 fThinningMaxRadius = g[150]; // Max radial radius for thinning
242
243 fViewConeInnerAngle = g[151]; // inner angle of view cone (°)
244 fViewConeOuterAngle = g[152]; // outer angle of view cone (°)
245
246 fTransitionEnergy = g[153];
247
248 return kTRUE;
249}
250
251Bool_t MCorsikaRunHeader::ReadEvtEnd(MCorsikaFormat * fInFormat, Bool_t runNumberVerify)
252{
253 Float_t f[2];
254 if (!fInFormat->Read(f, 2 * sizeof(Float_t)))
255 return kFALSE;
256
257 if (runNumberVerify)
258 {
259 const UInt_t runnum = TMath::Nint(f[0]);
260 if (runnum!=fRunNumber)
261 {
262 *fLog << err << "ERROR - Mismatch in stream: Run number in RUNE (";
263 *fLog << runnum << ") doesn't match RUNH (" << fRunNumber << ")." << endl;
264 return kFALSE;
265 }
266 }
267
268 fNumEvents = TMath::Nint(f[1]);
269
270 return kTRUE;
271}
272
273// --------------------------------------------------------------------------
274//
275// print run header information on *fLog. The option 'header' supresses
276// the pixel index translation table.
277//
278void MCorsikaRunHeader::Print(Option_t *t) const
279{
280 *fLog << all << endl;
281 *fLog << "Run Number: " << fRunNumber << " (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
282 *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
283 if (fNumEvents>0)
284 *fLog << "Num Events: " << fNumEvents << " (reuse " << fNumReuse << " times)" << endl;
285 *fLog << "Obs Level: ";
286 for (Byte_t i=0; i<fNumObsLevel; i++)
287 *fLog << " " << fObsLevel[i]/100. << "m";
288 *fLog << endl;
289
290 *fLog << "MagneticField: X/Z=(" << fMagneticFieldX << "/";
291 *fLog << fMagneticFieldZ << ")" << UTF8::kMu << "T Az=" << fMagneticFieldAz*TMath::RadToDeg() << UTF8::kDeg << " (magnetic North w.r.t. North)" << endl;
292
293 *fLog << "Spectrum: Slope=" << fSlopeSpectrum << " (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" << endl;
294 *fLog << "Wavelength: " << fWavelengthMin << "nm - " << fWavelengthMax << "nm" << endl;
295
296 if (fImpactMax>0)
297 *fLog << "ImpactMax: " << fImpactMax << "cm" << endl;
298 if (fViewConeOuterAngle>0)
299 *fLog << "ViewCone: " << fViewConeInnerAngle << UTF8::kDeg << " - " << fViewConeOuterAngle << UTF8::kDeg << endl;
300
301 *fLog << "Zd/Az: ";
302 if (fZdMax>=0 && fZdMin<360)
303 {
304 *fLog << fZdMin << UTF8::kDeg;
305 if (fZdMin==fZdMax)
306 *fLog << " (fixed)";
307 else
308 *fLog << "-" << fZdMax << UTF8::kDeg;
309 *fLog << " / " << fAzMin << UTF8::kDeg;
310 if (fAzMin==fAzMax)
311 *fLog << " (fixed)";
312 else
313 *fLog << "-" << fAzMax << UTF8::kDeg;
314 *fLog << " w.r.t. magnetic North." << endl;
315 }
316
317 if (fZdMin>=360) // 4010.7
318 *fLog << "-trajectory-" << endl;
319
320
321 if (fImpactMax>0)
322 *fLog << "Max.sim.Impact: " << fImpactMax << "cm" << endl;
323
324 *fLog << "Energy cutoff: ";
325 *fLog << fEnergyCutoffHadrons << "GeV (hadrons), ";
326 *fLog << fEnergyCutoffMuons << "GeV (muons), ";
327 *fLog << fEnergyCutoffElectrons << "GeV (electrons), ";
328 *fLog << fEnergyCutoffPhotons << "GeV (photons)";
329 *fLog << endl;
330
331 *fLog << "Thinning: ";
332 if (fThinningWeightLimitH>0)
333 {
334 *fLog << "HADRONIC: E/Eth>" << fThinningEnergyFractionH << " (w>" << fThinningWeightLimitH << "), ";
335 *fLog << "EM: E/Eth>" << fThinningEnergyFractionEM << " (w>" << fThinningWeightLimitEM << "), ";
336 *fLog << "R>" << fThinningMaxRadius << "cm";
337 *fLog << endl;
338 }
339 else
340 *fLog << "<off>" << endl;
341
342 *fLog << "Interact.model: ";
343 switch (fHadronModelLowEnergy)
344 {
345 case 1: *fLog << "GEISHA"; break;
346 case 2: *fLog << "UrQMD"; break;
347 case 3: *fLog << "FLUKA"; break;
348 default: *fLog << "<n/a>"; break;
349 }
350 *fLog << " / ";
351 switch (fHadronModelHighEnergy)
352 {
353 case 0: *fLog << "HDPM"; break;
354 case 1: *fLog << "VENUS"; break;
355 case 2: *fLog << "SIBYLL"; break;
356 case 3: *fLog << "QGSJET"; break;
357 case 4: *fLog << "DPMJET"; break;
358 case 5: *fLog << "neXus"; break;
359 case 6: *fLog << "EPOS"; break;
360 default: *fLog << "<n/a>"; break;
361 }
362 *fLog << " [lo/hi], Transition at " << fTransitionEnergy << " GeV" << endl;
363
364 *fLog << "Options used: ";
365 if (Has(kCerenkov))
366 *fLog << " CERENKOV";
367 if (Has(kIact))
368 *fLog << " IACT";
369 if (Has(kCeffic))
370 *fLog << " CEFFIC";
371 if (Has(kAtmext))
372 *fLog << " ATMEXT" << GetNumAtmosphericModel();
373 if (Has(kRefraction))
374 *fLog << " +Refraction";
375 if (Has(kVolumedet))
376 *fLog << " VOLUMEDET";
377 if (Has(kCurved))
378 *fLog << " CURVED" << (fCurvedAtmosphere?"<on>":"<off>");
379 if (Has(kSlant))
380 *fLog << " SLANT";
381 *fLog << " [" << hex << fCerenkovFlag << "]" << dec << endl;
382
383 if (Has(kCerenkov))
384 {
385 *fLog << "File format: ";
386 switch (fCerenkovFileOption)
387 {
388 case 0:
389 *fLog << "Cerenkov photons written to DAT-file.";
390 break;
391 case 1:
392 *fLog << "Cerenkov photons written to CER-file";
393 break;
394 case 2:
395 *fLog << "Cerenkov photons written to CER-file / Wavelength as 8th item in THIN option";
396 break;
397 default:
398 *fLog << "Cerenkov photons written to CER-file / Prod. height replaced by distance to array center.";
399 break;
400 }
401 *fLog << " [MCERFI=" << fCerenkovFileOption << "]" << endl;
402 }
403
404 if (HasLayers())
405 {
406 *fLog << "Atm.Layers: ";
407 for (int i=0; i<5; i++)
408 *fLog << " " << fAtmosphericLayers[i];
409 }
410 *fLog << endl;
411 *fLog << "Atm.Coeff A: ";
412 for (int i=0; i<5; i++)
413 *fLog << " " << fAtmosphericCoeffA[i];
414 *fLog << endl;
415 *fLog << "Atm.Coeff B: ";
416 for (int i=0; i<5; i++)
417 *fLog << " " << fAtmosphericCoeffB[i];
418 *fLog << endl;
419 *fLog << "Atm.Coeff C: ";
420 for (int i=0; i<5; i++)
421 *fLog << " " << fAtmosphericCoeffC[i];
422 *fLog << endl;
423
424
425}
426
Note: See TracBrowser for help on using the repository browser.