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

Last change on this file since 9291 was 9252, 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/////////////////////////////////////////////////////////////////////////////
30#include "MCorsikaEvtHeader.h"
31
32#include <iomanip>
33#include <fstream>
34
35#include <TMath.h>
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MMcEvt.hxx"
41
42ClassImp(MCorsikaEvtHeader);
43
44using namespace std;
45
46// --------------------------------------------------------------------------
47//
48// Default constructor. Create the array to store the data.
49//
50MCorsikaEvtHeader::MCorsikaEvtHeader(const char *name, const char *title)
51{
52 fName = name ? name : "MCorsikaEvtHeader";
53 fTitle = title ? title : "Raw Event Header Information";
54}
55
56// --------------------------------------------------------------------------
57//
58// Return Hypot(x, y)
59//
60Double_t MCorsikaEvtHeader::GetImpact() const
61{
62 return TMath::Hypot(fX, fY);
63}
64
65// --------------------------------------------------------------------------
66//
67// This member function prints all Data of one Event to *fLog.
68//
69void MCorsikaEvtHeader::Print(Option_t *o) const
70{
71 *fLog << all;
72 *fLog << "Event Number: " << dec << fEvtNumber << endl;
73 *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
74 *fLog << "Energy: " << fTotalEnergy << "GeV" << endl;
75 *fLog << "Starting Altitude: " << fStartAltitude << "g/cm²" << endl;
76 *fLog << "Number of 1st Target: " << fFirstTargetNum << endl,
77 *fLog << "Height of 1st Interaction: " << fFirstInteractionHeight/100. << "m" << endl;
78 *fLog << "Momentum X/Y/Z (GeV/c): " << fMomentumX << "/" << fMomentumY << "/" << fMomentumZ << endl;
79 *fLog << "Zenith/Azimuth Angle: " << fZd*TMath::RadToDeg() << "°/" << fAz*TMath::RadToDeg() << "°" << endl;
80 *fLog << "Impact X/Y: " << fX/100. << "m/" << fY/100. << "m (r=" << TMath::Hypot(fX, fY)/100. << "m)" << endl;
81 *fLog << "Weighted Num Photons: " << fWeightedNumPhotons << endl;
82 *fLog << endl;
83}
84
85// --------------------------------------------------------------------------
86//
87// read the EVTH information from the input stream
88// return FALSE if there is no header anymore, else TRUE
89//
90Int_t MCorsikaEvtHeader::ReadEvt(std::istream &fin)
91{
92 char evth[4];
93 fin.read(evth, 4);
94 if (memcmp(evth, "EVTH", 4))
95 {
96 fin.seekg(-4, ios::cur);
97 return kFALSE;
98 }
99
100 Float_t f[273];
101 fin.read((char*)&f, 273*4);
102
103 fEvtNumber = TMath::Nint(f[0]);
104 fParticleID = TMath::Nint(f[1]);
105
106 fTotalEnergy = f[2];
107 fStartAltitude = f[3];
108 fFirstTargetNum = f[4];
109 fFirstInteractionHeight = f[5];
110
111 // Pointing opposite particle direction
112 // (x=north, y=west, z=upwards)
113 //fMomentumX = f[6];
114 //fMomentumY = f[7];
115 //fMomentumZ = f[8];
116 // Pointing along particle direction
117 // (x=east, y=north, z=upwards)
118 fMomentumX = -f[7];
119 fMomentumY = f[6];
120 fMomentumZ = -f[8];
121
122 // FIXME: Correct for direction of magnetic field!
123 fZd = f[9];
124 fAz = TMath::Pi()-f[10];
125
126 const Int_t n = TMath::Nint(f[96]);
127 if (n!=1)
128 {
129 *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
130 return kFALSE;
131 }
132
133 //fX = f[97];
134 //fY = f[117];
135
136 fX = f[117];
137 fY = -f[97];
138
139 fin.seekg(1088-273*4, ios::cur);
140
141 return !fin.eof();
142}
143
144
145// this member function is for reading the event end block
146
147Bool_t MCorsikaEvtHeader::ReadEvtEnd(std::istream &fin)
148{
149 //fin.seekg(-1088,ios::cur);
150
151 Float_t f[2];
152 fin.read((char*)&f, 2*4);
153
154 const UInt_t evtnum = TMath::Nint(f[0]);
155 if (evtnum!=fEvtNumber)
156 {
157 *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
158 *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
159 return kERROR;
160 }
161
162 fWeightedNumPhotons = f[1];
163
164 fin.seekg(1080,ios::cur);
165
166 return !fin.eof();
167}
168
Note: See TracBrowser for help on using the repository browser.