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

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