source: trunk/Mars/mcorsika/MCorsikaEvtHeader.cc@ 9841

Last change on this file since 9841 was 9616, checked in by rohlfs, 14 years ago
can read also EventIO files
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, 2000-2010
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MCorsikaEvtHeader
28//
29// Class Version 2:
30// ----------------
31// - UInt_t fParticleID
32//
33//
34/////////////////////////////////////////////////////////////////////////////
35#include "MCorsikaEvtHeader.h"
36#include "MCorsikaFormat.h"
37
38#include <iomanip>
39#include <fstream>
40
41#include <TMath.h>
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46//#include "MMcEvt.hxx"
47
48ClassImp(MCorsikaEvtHeader);
49
50using namespace std;
51
52// --------------------------------------------------------------------------
53//
54// Default constructor. Create the array to store the data.
55//
56MCorsikaEvtHeader::MCorsikaEvtHeader(const char *name, const char *title)
57 : fX(0), fY(0)
58{
59 fName = name ? name : "MCorsikaEvtHeader";
60 fTitle = title ? title : "Raw Event Header Information";
61}
62
63// --------------------------------------------------------------------------
64//
65// Return Impact (distance of ground incident point from telescope axis)
66//
67// Distance d between a point q and a line u (via p):
68// d = | ( vec(q) - vec(p) ) x vec(u) | / | vec(u) |
69//
70// If p = 0
71//
72// ==> d = | vec(q) x vec(u) | / | vec(u) |
73// w := q = (x/y/0)
74// v := u = (Alt/Az)
75//
76// For Alt/Az = Theta/Phi:
77//
78// x = r sin(theta) cos(phi)
79// y = r sin(theta) sin(phi)
80// z = r cos(theta)
81//
82// ( -q3*u2 ) ( -cos(theta)*y )
83// vec(q) x vec(u) = ( q3*u1 ) = ( cos(theta)*x )
84// ( q1*u2-q2*u1 ) ( sin(theta) cos(phi) * y - sin(theta) sin(phi) * x )
85//
86// ==> d = sqrt( cos(theta)^2 (x^2 + y^2 ) +
87// sin(theta)^2 ( cos(phi) y + sin(phi) x)^2 )
88//
89Double_t MCorsikaEvtHeader::GetImpact() const
90{
91 const Double_t c = TMath::Cos(fZd);
92 const Double_t s = TMath::Sin(fZd);
93
94 const Double_t p = TMath::Cos(fAz)*fX - TMath::Sin(fAz)*fY;
95
96 return TMath::Sqrt(c*c*(fX*fX + fY*fY) + s*s* p*p);
97}
98
99// --------------------------------------------------------------------------
100//
101// This member function prints all Data of one Event to *fLog.
102//
103void MCorsikaEvtHeader::Print(Option_t *o) const
104{
105 *fLog << all;
106 *fLog << "Event Number: " << dec << fEvtNumber << endl;
107// *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
108 *fLog << "Energy: " << fTotalEnergy << "GeV" << endl;
109 *fLog << "Starting Altitude: " << fStartAltitude << "g/cm" << UTF8::kSquare << endl;
110 *fLog << "Number of 1st Target: " << fFirstTargetNum << endl,
111 *fLog << "Height of 1st Interaction: " << fFirstInteractionHeight/100. << "m" << endl;
112 *fLog << "Momentum X/Y/Z (GeV/c): " << fMomentumX << "/" << fMomentumY << "/" << fMomentumZ << endl;
113 *fLog << "Zenith/Azimuth Angle: " << fZd*TMath::RadToDeg() << UTF8::kDeg << "/" << fAz*TMath::RadToDeg() << UTF8::kDeg << endl;
114 *fLog << "Impact X/Y: " << fX/100. << "m/" << fY/100. << "m (r=" << TMath::Hypot(fX, fY)/100. << "m)" << endl;
115 *fLog << "Weighted Num Photons: " << fWeightedNumPhotons << endl;
116 *fLog << endl;
117}
118
119// --------------------------------------------------------------------------
120//
121// read the EVTH information from the input stream
122// return FALSE if there is no header anymore, else TRUE
123//
124Int_t MCorsikaEvtHeader::ReadEvt(MCorsikaFormat * fInFormat)
125{
126
127 if (!fInFormat->SeekNextBlock("EVTH", 1202))
128 return kFALSE;
129
130 Float_t f[273];
131 if (!fInFormat->ReadData(272, f))
132 return kFALSE;
133
134 fEvtNumber = TMath::Nint(f[0]);
135// fParticleID = TMath::Nint(f[1]);
136
137 fTotalEnergy = f[2];
138 fStartAltitude = f[3];
139 fFirstTargetNum = f[4];
140 fFirstInteractionHeight = f[5]; // FIXME: Could be negative
141
142 // Pointing opposite particle direction
143 // (x=north, y=west, z=upwards)
144 //fMomentumX = f[6];
145 //fMomentumY = f[7];
146 //fMomentumZ = f[8];
147 // Pointing along particle direction
148 // (x=east, y=north, z=upwards)
149 fMomentumX = f[7];
150 fMomentumY = -f[6];
151 fMomentumZ = -f[8]; // Does this minus make sense?!
152
153 // FIXME: Correct for direction of magnetic field!
154 fZd = f[9];
155 fAz = TMath::Pi()-f[10];
156
157 const Int_t n = TMath::Nint(f[96]);
158 if (n!=1)
159 {
160 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
161 *fLog << warn << "WARNING - This error is replaced by a warning." << endl;
162 }
163
164 fX = f[117]; //fX = f[97];
165 fY = -f[97]; //fY = f[117];
166
167 return !fInFormat->Eof();
168}
169
170
171// this member function is for reading the event end block
172
173Bool_t MCorsikaEvtHeader::ReadEvtEnd(MCorsikaFormat * fInFormat)
174{
175
176 if (!fInFormat->SeekNextBlock("EVTE", 1209))
177 return kFALSE;
178
179 //fin.seekg(-1088,ios::cur);
180
181 Float_t f[2];
182
183 if (!fInFormat->ReadData(2, f))
184 return kFALSE;
185
186 const UInt_t evtnum = TMath::Nint(f[0]);
187 if (evtnum!=fEvtNumber)
188 {
189 *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
190 *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
191 return kERROR;
192 }
193
194 fWeightedNumPhotons = f[1];
195
196 return !fInFormat->Eof();
197}
198
Note: See TracBrowser for help on using the repository browser.