source: trunk/MagicSoft/Mars/mcorsika/MCorsikaEvtHeader.cc@ 9182

Last change on this file since 9182 was 9182, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 6.1 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 11/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: Software Development, 2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MCorsikaEvtHeader
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MCorsikaEvtHeader.h"
31
32#include <iomanip>
33#include <fstream>
34
35#include "MLog.h"
36#include "MLogManip.h"
37
38#include "MMcEvt.hxx"
39#include "MCorsikaRunHeader.h"
40
41ClassImp(MCorsikaEvtHeader);
42
43using namespace std;
44
45// --------------------------------------------------------------------------
46//
47// Default constructor. Create the array to store the data.
48//
49MCorsikaEvtHeader::MCorsikaEvtHeader(const char *name, const char *title)
50{
51 fName = name ? name : "MCorsikaEvtHeader";
52 fTitle = title ? title : "Raw Event Header Information";
53}
54
55// --------------------------------------------------------------------------
56//
57// This member function prints all Data of one Event to *fLog.
58//
59void MCorsikaEvtHeader::Print(Option_t *o) const
60{
61 *fLog << all;
62 *fLog << "Event Number: " << dec << fEvtNumber << endl;
63 *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
64 *fLog << "Energy: " << fTotalEnergy << "GeV" << endl;
65 *fLog << "Starting Altitude: " << fStartAltitude << "g/cm²" << endl;
66 *fLog << "Number of 1st Target: " << fFirstTargetNum << endl,
67 *fLog << "Height of 1st Interaction: " << fFirstInteractionHeight/100. << "m" << endl;
68 *fLog << "Momentum X/Y/Z (GeV/c): " << fMomentumX << "/" << fMomentumY << "/" << fMomentumZ << endl;
69 *fLog << "Zenith/Azimuth Angle: " << fZd*TMath::RadToDeg() << "°/" << fAz*TMath::RadToDeg() << "°" << endl;
70 *fLog << "Impact X/Y: " << fX/100. << "m/" << fY/100. << "m (r=" << TMath::Hypot(fX, fY)/100. << "m)" << endl;
71 *fLog << "Weighted Num Photons: " << fWeightedNumPhotons << endl;
72 *fLog << endl;
73}
74
75// --------------------------------------------------------------------------
76//
77// read the EVTH information from the input stream
78// return FALSE if there is no header anymore, else TRUE
79//
80Int_t MCorsikaEvtHeader::ReadEvt(std::istream &fin, MCorsikaRunHeader &header)
81{
82 char evth[4];
83 fin.read(evth, 4);
84 if (memcmp(evth, "EVTH", 4))
85 {
86 fin.seekg(-4, ios::cur);
87 return kFALSE;
88 }
89
90 Float_t f[273];
91 fin.read((char*)&f, 273*4);
92
93 fEvtNumber = TMath::Nint(f[0]);
94 fParticleID = TMath::Nint(f[1]);
95
96 fTotalEnergy = f[2];
97 fStartAltitude = f[3];
98 fFirstTargetNum = f[4];
99 fFirstInteractionHeight = f[5];
100
101 // Pointing opposite particle direction
102 // (x=north, y=west, z=upwards)
103 //fMomentumX = f[6];
104 //fMomentumY = f[7];
105 //fMomentumZ = f[8];
106 // Pointing along particle direction
107 // (x=east, y=north, z=upwards)
108 fMomentumX = -f[7];
109 fMomentumY = f[6];
110 fMomentumZ = -f[8];
111
112 fZd = f[9];
113 fAz = TMath::Pi()-f[10];
114
115 const Int_t n = TMath::Nint(f[96]);
116 if (n!=1)
117 {
118 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
119 return kFALSE;
120 }
121
122 //fX = f[97];
123 //fY = f[117];
124
125 fX = f[117];
126 fY = -f[97];
127
128 if (fEvtNumber==1)
129 {
130 header.fZdMin = f[79];
131 header.fZdMax = f[80];
132 header.fAzMin = 180-f[81];
133 header.fAzMax = 180-f[82];
134
135 header.fViewConeInnerAngle = f[151];
136 header.fViewConeOuterAngle = f[152];
137
138 header.Print();
139 }
140
141 fin.seekg(1088-273*4, ios::cur);
142
143 // f[76] Cherenkov flag:
144 // bit(1) : CERENKOV option compiled in
145 // bit(2) : IACT option compiled in
146 // bit(3) : CEFFIC option compiled in
147 // bit(4) : ATMEXT option compiled in
148 // bit(5) : ATMEXT option used with refaction enabled
149 // bit(6) : VOLUMEDET option compiled in
150 // bit(7) : CURVED option compiled in
151 // bit(9) : SLATN option compiled in
152 // 11-21 : table number for externam athmosphere (but<1024)
153 // f[78] Curved athmosphere? (0=flat, 1=curved)
154
155 // f[80] lower edge of theta in °
156 // f[81] upper edge of theta in °
157 // f[82] lower edge of phi in °
158 // f[83] upper edge of phi in °
159 // f[84] cherenkov bunch size
160
161 // f[93] flag for additinal muon information of particle output file
162
163 // f[95] Cherenkov bandwidth lower end in nm
164 // f[96] Cherenkov bandwidth upper end in nm
165
166 // f[97] Numbr i of uses of each cherenkov event
167 // f[145] Muon multiple scattering flag
168 // f[152] !! inner angle of view cone (°)
169 // f[153] !! outer angle of view cone (°)
170 // f[156] altitude of horizontal shower axis
171
172 return !fin.eof();
173}
174
175
176// this member function is for reading the event end block
177
178Bool_t MCorsikaEvtHeader::ReadEvtEnd(std::istream &fin)
179{
180 //fin.seekg(-1088,ios::cur);
181
182 Float_t f[2];
183 fin.read((char*)&f, 2*4);
184
185 const UInt_t evtnum = TMath::Nint(f[0]);
186 if (evtnum!=fEvtNumber)
187 {
188 *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
189 *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
190 return kERROR;
191 }
192
193 fWeightedNumPhotons = f[1];
194
195 fin.seekg(1080,ios::cur);
196
197 return !fin.eof();
198}
199
Note: See TracBrowser for help on using the repository browser.