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

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