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, 2008
|
---|
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 |
|
---|
40 | ClassImp(MCorsikaEvtHeader);
|
---|
41 |
|
---|
42 | using namespace std;
|
---|
43 |
|
---|
44 | // --------------------------------------------------------------------------
|
---|
45 | //
|
---|
46 | // Default constructor. Create the array to store the data.
|
---|
47 | //
|
---|
48 | MCorsikaEvtHeader::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 | //
|
---|
58 | void 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 | //
|
---|
79 | Int_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 | fZd = f[9];
|
---|
112 | fAz = TMath::Pi()-f[10];
|
---|
113 |
|
---|
114 | const Int_t n = TMath::Nint(f[96]);
|
---|
115 | if (n!=1)
|
---|
116 | {
|
---|
117 | *fLog << err << "ERROR - Currently only one impact parameter per event is supported." << endl;
|
---|
118 | return kFALSE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | //fX = f[97];
|
---|
122 | //fY = f[117];
|
---|
123 |
|
---|
124 | fX = f[117];
|
---|
125 | fY = -f[97];
|
---|
126 | /*
|
---|
127 | if (fEvtNumber==1)
|
---|
128 | {
|
---|
129 | header.fZdMin = f[79];
|
---|
130 | header.fZdMax = f[80];
|
---|
131 | header.fAzMin = 180-f[81];
|
---|
132 | header.fAzMax = 180-f[82];
|
---|
133 |
|
---|
134 | header.fViewConeInnerAngle = f[151];
|
---|
135 | header.fViewConeOuterAngle = f[152];
|
---|
136 |
|
---|
137 | header.Print();
|
---|
138 | }
|
---|
139 | */
|
---|
140 | fin.seekg(1088-273*4, ios::cur);
|
---|
141 |
|
---|
142 | return !fin.eof();
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | // this member function is for reading the event end block
|
---|
147 |
|
---|
148 | Bool_t MCorsikaEvtHeader::ReadEvtEnd(std::istream &fin)
|
---|
149 | {
|
---|
150 | //fin.seekg(-1088,ios::cur);
|
---|
151 |
|
---|
152 | Float_t f[2];
|
---|
153 | fin.read((char*)&f, 2*4);
|
---|
154 |
|
---|
155 | const UInt_t evtnum = TMath::Nint(f[0]);
|
---|
156 | if (evtnum!=fEvtNumber)
|
---|
157 | {
|
---|
158 | *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
|
---|
159 | *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
|
---|
160 | return kERROR;
|
---|
161 | }
|
---|
162 |
|
---|
163 | fWeightedNumPhotons = f[1];
|
---|
164 |
|
---|
165 | fin.seekg(1080,ios::cur);
|
---|
166 |
|
---|
167 | return !fin.eof();
|
---|
168 | }
|
---|
169 |
|
---|