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

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