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

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