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

Last change on this file since 9331 was 9308, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.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 Hypot(x, y)
64//
65Double_t MCorsikaEvtHeader::GetImpact() const
66{
67 return TMath::Hypot(fX, fY);
68}
69
70// --------------------------------------------------------------------------
71//
72// This member function prints all Data of one Event to *fLog.
73//
74void MCorsikaEvtHeader::Print(Option_t *o) const
75{
76 *fLog << all;
77 *fLog << "Event Number: " << dec << fEvtNumber << endl;
78// *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
79 *fLog << "Energy: " << fTotalEnergy << "GeV" << endl;
80 *fLog << "Starting Altitude: " << fStartAltitude << "g/cm²" << endl;
81 *fLog << "Number of 1st Target: " << fFirstTargetNum << endl,
82 *fLog << "Height of 1st Interaction: " << fFirstInteractionHeight/100. << "m" << endl;
83 *fLog << "Momentum X/Y/Z (GeV/c): " << fMomentumX << "/" << fMomentumY << "/" << fMomentumZ << endl;
84 *fLog << "Zenith/Azimuth Angle: " << fZd*TMath::RadToDeg() << "°/" << fAz*TMath::RadToDeg() << "°" << endl;
85 *fLog << "Impact X/Y: " << fX/100. << "m/" << fY/100. << "m (r=" << TMath::Hypot(fX, fY)/100. << "m)" << endl;
86 *fLog << "Weighted Num Photons: " << fWeightedNumPhotons << endl;
87 *fLog << endl;
88}
89
90// --------------------------------------------------------------------------
91//
92// read the EVTH information from the input stream
93// return FALSE if there is no header anymore, else TRUE
94//
95Int_t MCorsikaEvtHeader::ReadEvt(std::istream &fin)
96{
97 char evth[4];
98 fin.read(evth, 4);
99 if (memcmp(evth, "EVTH", 4))
100 {
101 fin.seekg(-4, ios::cur);
102 return kFALSE;
103 }
104
105 Float_t f[273];
106 fin.read((char*)&f, 273*4);
107
108 fEvtNumber = TMath::Nint(f[0]);
109// fParticleID = TMath::Nint(f[1]);
110
111 fTotalEnergy = f[2];
112 fStartAltitude = f[3];
113 fFirstTargetNum = f[4];
114 fFirstInteractionHeight = f[5];
115
116 // Pointing opposite particle direction
117 // (x=north, y=west, z=upwards)
118 //fMomentumX = f[6];
119 //fMomentumY = f[7];
120 //fMomentumZ = f[8];
121 // Pointing along particle direction
122 // (x=east, y=north, z=upwards)
123 fMomentumX = -f[7];
124 fMomentumY = f[6];
125 fMomentumZ = -f[8];
126
127 // FIXME: Correct for direction of magnetic field!
128 fZd = f[9];
129 fAz = TMath::Pi()-f[10];
130
131 const Int_t n = TMath::Nint(f[96]);
132 if (n!=1)
133 {
134 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
135 return kFALSE;
136 }
137
138 //fX = f[97];
139 //fY = f[117];
140
141 fX = f[117];
142 fY = -f[97];
143
144 fin.seekg(1088-273*4, ios::cur);
145
146 return !fin.eof();
147}
148
149
150// this member function is for reading the event end block
151
152Bool_t MCorsikaEvtHeader::ReadEvtEnd(std::istream &fin)
153{
154 //fin.seekg(-1088,ios::cur);
155
156 Float_t f[2];
157 fin.read((char*)&f, 2*4);
158
159 const UInt_t evtnum = TMath::Nint(f[0]);
160 if (evtnum!=fEvtNumber)
161 {
162 *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
163 *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
164 return kERROR;
165 }
166
167 fWeightedNumPhotons = f[1];
168
169 fin.seekg(1080,ios::cur);
170
171 return !fin.eof();
172}
173
Note: See TracBrowser for help on using the repository browser.