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

Last change on this file since 9401 was 9374, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.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{
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]; // FIXME: Could be negative
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[117]; //fX = f[97];
139 fY = -f[97]; //fY = f[117];
140
141 fin.seekg(1088-273*4, ios::cur);
142
143 return !fin.eof();
144}
145
146
147// this member function is for reading the event end block
148
149Bool_t MCorsikaEvtHeader::ReadEvtEnd(std::istream &fin)
150{
151 //fin.seekg(-1088,ios::cur);
152
153 Float_t f[2];
154 fin.read((char*)&f, 2*4);
155
156 const UInt_t evtnum = TMath::Nint(f[0]);
157 if (evtnum!=fEvtNumber)
158 {
159 *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
160 *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
161 return kERROR;
162 }
163
164 fWeightedNumPhotons = f[1];
165
166 fin.seekg(1080,ios::cur);
167
168 return !fin.eof();
169}
170
Note: See TracBrowser for help on using the repository browser.