source: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc@ 9331

Last change on this file since 9331 was 9312, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 7.4 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//
37////////////////////////////////////////////////////////////////////////////
38
39#include "MCorsikaRunHeader.h"
40
41#include <fstream>
42#include <iomanip>
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MMcEvt.hxx"
48
49ClassImp(MCorsikaRunHeader);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Default constructor. Creates array which stores the pixel assignment.
56//
57//
58MCorsikaRunHeader::MCorsikaRunHeader(const char *name, const char *title)
59 : fNumObsLevel(0), fZdMin(0), fZdMax(-1), fAzMin(0), fAzMax(0),
60 fViewConeInnerAngle(0), fViewConeOuterAngle(-1)
61{
62 fName = name ? name : "MCorsikaRunHeader";
63 fTitle = title ? title : "Raw Run Header Information";
64}
65
66// --------------------------------------------------------------------------
67//
68// Read in one run header from the binary file
69//
70Bool_t MCorsikaRunHeader::ReadEvt(istream& fin)
71{
72 char runh[4];
73 fin.read(runh, 4);
74 if (memcmp(runh, "RUNH", 4))
75 {
76 *fLog << err << "ERROR - Wrong identifier: RUNH expected." << endl;
77 return kFALSE;
78 }
79
80 Float_t f[68];
81 fin.read((char*)f, 68);
82
83 fRunNumber = TMath::Nint(f[0]);
84 fNumEvents = 0;
85
86 fRunStart.SetCorsikaTime(f[1]);
87
88 fProgramVersion = f[2]; //FIXME: INT???
89 fNumObsLevel = TMath::Nint(f[3]);
90
91 if (fNumObsLevel!=1)
92 {
93 *fLog << err << "ERROR - Currently only one observation level is allowed." << endl;
94 return kFALSE;
95 }
96
97 memset(fObsLevel, 0, 10*4);
98 memcpy(fObsLevel, f+4, fNumObsLevel*4);
99
100 fSlopeSpectrum = f[14];
101 fEnergyMin = f[15];
102 fEnergyMax = f[16];
103
104 fin.seekg(1020, ios::cur); // skip the remaining data of this block
105
106 // -------------------- Read first event header -------------------
107
108 // FIXME: Add sanity checks!
109
110 // f[76] Cherenkov flag:
111 // bit(1) : CERENKOV option compiled in
112 // bit(2) : IACT option compiled in
113 // bit(3) : CEFFIC option compiled in
114 // bit(4) : ATMEXT option compiled in
115 // bit(5) : ATMEXT option used with refraction enabled
116 // bit(6) : VOLUMEDET option compiled in
117 // bit(7) : CURVED option compiled in
118 // bit(9) : SLATN option compiled in
119 // 11-21 : table number for externam athmosphere (but<1024)
120 //
121 // f[78] Curved athmosphere? (0=flat, 1=curved)
122 // f[84] cherenkov bunch size
123 // f[93] flag for additinal muon information of particle output file
124 // f[145] Muon multiple scattering flag
125 // f[156] altitude of horizontal shower axis
126
127 char evth[4];
128 fin.read(evth, 4);
129 if (memcmp(evth, "EVTH", 4))
130 {
131 *fLog << err << "ERROR - Wrong identifier: EVTH expected." << endl;
132 return kFALSE;
133 }
134
135 Float_t g[273];
136 fin.read((char*)&g, 273*4);
137 if (fin.eof())
138 return kFALSE;
139
140 fin.seekg(-274*4, ios::cur);
141
142 const Int_t n = TMath::Nint(g[96]); // Number i of uses of each cherenkov event
143 if (n!=1)
144 {
145 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
146 return kFALSE;
147 }
148
149 fParticleID = TMath::Nint(g[1]);
150
151 fImpactMax = g[86];
152
153 fZdMin = g[79]; // lower edge of theta in °
154 fZdMax = g[80]; // upper edge of theta in °
155 fAzMin = 180-g[81]; // lower edge of phi in °
156 fAzMax = 180-g[82]; // upper edge of phi in °
157 // FIXME: Correct for direction of magnetic field!
158
159 fWavelengthMin = g[95]; // Cherenkov bandwidth lower end in nm
160 fWavelengthMax = g[96]; // Cherenkov bandwidth upper end in nm
161
162 fViewConeInnerAngle = g[151]; // inner angle of view cone (°)
163 fViewConeOuterAngle = g[152]; // outer angle of view cone (°)
164
165 return kTRUE;
166}
167
168Bool_t MCorsikaRunHeader::ReadEvtEnd(istream& fin)
169{
170 char runh[4];
171 fin.read(runh, 4);
172 if (memcmp(runh, "RUNE", 4))
173 {
174 *fLog << err << "ERROR - Wrong identifier: RUNE expected." << endl;
175 return kFALSE;
176 }
177
178 Float_t f[2];
179 fin.read((char*)f, 2*4);
180
181 const UInt_t runnum = TMath::Nint(f[0]);
182 if (runnum!=fRunNumber)
183 {
184 *fLog << err << "ERROR - Mismatch in stream: Run number in RUNE (";
185 *fLog << runnum << ") doesn't match RUNH (" << fRunNumber << ")." << endl;
186 return kFALSE;
187 }
188
189 fNumEvents = TMath::Nint(f[1]);
190
191 fin.seekg(270*4, ios::cur); // skip the remaining data of this block
192
193 return kTRUE;
194}
195
196Bool_t MCorsikaRunHeader::SeekEvtEnd(istream &fin)
197{
198 // Search subblockwise backward (Block: 5733*4 = 21*273*4)
199 for (int i=1; i<22; i++)
200 {
201 fin.seekg(-i*273*4, ios::end);
202
203 char runh[4];
204 fin.read(runh, 4);
205
206 if (!memcmp(runh, "RUNE", 4))
207 {
208 fin.seekg(-4, ios::cur);
209 return kTRUE;
210 }
211 }
212
213 return kFALSE;
214}
215
216// --------------------------------------------------------------------------
217//
218// print run header information on *fLog. The option 'header' supresses
219// the pixel index translation table.
220//
221void MCorsikaRunHeader::Print(Option_t *t) const
222{
223 *fLog << all << endl;
224 *fLog << "Run Number: " << fRunNumber << " (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
225 *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
226 if (fNumEvents>0)
227 *fLog << "Num Events: " << fNumEvents << endl;
228 *fLog << "Obs Level: ";
229 for (Byte_t i=0; i<fNumObsLevel; i++)
230 *fLog << " " << fObsLevel[i]/100. << "m";
231 *fLog << endl;
232 *fLog << "Spectrum: Slope=" << fSlopeSpectrum << " (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" << endl;
233
234 if (fViewConeOuterAngle>0)
235 *fLog << "ViewCone: " << fViewConeInnerAngle << "deg-" << fViewConeOuterAngle << "deg" << endl;
236
237 if (fZdMax>=0)
238 {
239 *fLog << "Zd/Az: " << fZdMin << "deg";
240 if (fZdMin==fZdMax)
241 *fLog << " (fixed)";
242 else
243 *fLog << "-" << fZdMax << "deg";
244 *fLog << " / " << fAzMin << "deg";
245 if (fAzMin==fAzMax)
246 *fLog << " (fixed)";
247 else
248 *fLog << "-" << fAzMax << "deg";
249 *fLog << endl;
250 }
251}
252
Note: See TracBrowser for help on using the repository browser.