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-2010
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MCorsikaEvtHeader
|
---|
28 | //
|
---|
29 | // Class Version 2:
|
---|
30 | // ----------------
|
---|
31 | // - UInt_t fParticleID
|
---|
32 | //
|
---|
33 | //
|
---|
34 | // Class Version 3:
|
---|
35 | // ----------------
|
---|
36 | // - UInt_t fNumReuse
|
---|
37 | //
|
---|
38 | //
|
---|
39 | /////////////////////////////////////////////////////////////////////////////
|
---|
40 | #include "MCorsikaEvtHeader.h"
|
---|
41 | #include "MCorsikaFormat.h"
|
---|
42 |
|
---|
43 | #include <iomanip>
|
---|
44 | #include <fstream>
|
---|
45 |
|
---|
46 | #include <TMath.h>
|
---|
47 |
|
---|
48 | #include "MLog.h"
|
---|
49 | #include "MLogManip.h"
|
---|
50 |
|
---|
51 | //#include "MMcEvt.hxx"
|
---|
52 |
|
---|
53 | ClassImp(MCorsikaEvtHeader);
|
---|
54 |
|
---|
55 | using namespace std;
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | // Default constructor. Create the array to store the data.
|
---|
60 | //
|
---|
61 | MCorsikaEvtHeader::MCorsikaEvtHeader(const char *name, const char *title)
|
---|
62 | : fNumReuse((UInt_t)-1), fX(0), fY(0)
|
---|
63 | {
|
---|
64 | fName = name ? name : "MCorsikaEvtHeader";
|
---|
65 | fTitle = title ? title : "Raw Event Header Information";
|
---|
66 | }
|
---|
67 |
|
---|
68 | // --------------------------------------------------------------------------
|
---|
69 | //
|
---|
70 | // Return Impact (distance of ground incident point from telescope axis)
|
---|
71 | //
|
---|
72 | // Distance d between a point q and a line u (via p):
|
---|
73 | // d = | ( vec(q) - vec(p) ) x vec(u) | / | vec(u) |
|
---|
74 | //
|
---|
75 | // If p = 0
|
---|
76 | //
|
---|
77 | // ==> d = | vec(q) x vec(u) | / | vec(u) |
|
---|
78 | // w := q = (x/y/0)
|
---|
79 | // v := u = (Alt/Az)
|
---|
80 | //
|
---|
81 | // For Alt/Az = Theta/Phi:
|
---|
82 | //
|
---|
83 | // x = r sin(theta) cos(phi)
|
---|
84 | // y = r sin(theta) sin(phi)
|
---|
85 | // z = r cos(theta)
|
---|
86 | //
|
---|
87 | // ( -q3*u2 ) ( -cos(theta)*y )
|
---|
88 | // vec(q) x vec(u) = ( q3*u1 ) = ( cos(theta)*x )
|
---|
89 | // ( q1*u2-q2*u1 ) ( sin(theta) cos(phi) * y - sin(theta) sin(phi) * x )
|
---|
90 | //
|
---|
91 | // ==> d = sqrt( cos(theta)^2 (x^2 + y^2 ) +
|
---|
92 | // sin(theta)^2 ( cos(phi) y + sin(phi) x)^2 )
|
---|
93 | //
|
---|
94 | Double_t MCorsikaEvtHeader::GetImpact() const
|
---|
95 | {
|
---|
96 | const Double_t c = TMath::Cos(fZd);
|
---|
97 | const Double_t s = TMath::Sin(fZd);
|
---|
98 |
|
---|
99 | const Double_t p = TMath::Cos(fAz)*fX - TMath::Sin(fAz)*fY;
|
---|
100 |
|
---|
101 | return TMath::Sqrt(c*c*(fX*fX + fY*fY) + s*s* p*p);
|
---|
102 | }
|
---|
103 |
|
---|
104 | // --------------------------------------------------------------------------
|
---|
105 | //
|
---|
106 | // This member function prints all Data of one Event to *fLog.
|
---|
107 | //
|
---|
108 | void MCorsikaEvtHeader::Print(Option_t *o) const
|
---|
109 | {
|
---|
110 | *fLog << all;
|
---|
111 | *fLog << "Event Number: " << dec << fEvtNumber << " (reused=" << fNumReuse << ")" << endl;
|
---|
112 | // *fLog << "Particle ID: " << MMcEvt::GetParticleName(fParticleID) << endl;
|
---|
113 | *fLog << "Energy: " << fTotalEnergy << "GeV" << endl;
|
---|
114 | *fLog << "Starting Altitude: " << fStartAltitude << "g/cm" << UTF8::kSquare << endl;
|
---|
115 | *fLog << "Number of 1st Target: " << fFirstTargetNum << endl,
|
---|
116 | *fLog << "Height of 1st Interaction: " << fFirstInteractionHeight/100. << "m" << endl;
|
---|
117 | *fLog << "Momentum X/Y/Z (GeV/c): " << fMomentumX << "/" << fMomentumY << "/" << fMomentumZ << endl;
|
---|
118 | *fLog << "Zenith/Azimuth Angle: " << fZd*TMath::RadToDeg() << UTF8::kDeg << "/" << fAz*TMath::RadToDeg() << UTF8::kDeg << endl;
|
---|
119 | *fLog << "Impact X/Y: " << fX/100. << "m/" << fY/100. << "m (r=" << TMath::Hypot(fX, fY)/100. << "m)" << endl;
|
---|
120 | *fLog << "Weighted Num Photons: " << fWeightedNumPhotons << endl;
|
---|
121 | *fLog << endl;
|
---|
122 | }
|
---|
123 |
|
---|
124 | // --------------------------------------------------------------------------
|
---|
125 | //
|
---|
126 | // read the EVTH information from the input stream
|
---|
127 | // return FALSE if there is no header anymore, else TRUE
|
---|
128 | //
|
---|
129 | Int_t MCorsikaEvtHeader::ReadEvt(MCorsikaFormat *fInFormat)
|
---|
130 | {
|
---|
131 | if (!fInFormat->SeekNextBlock("EVTH", 1202))
|
---|
132 | return kFALSE;
|
---|
133 |
|
---|
134 | Float_t f[273];
|
---|
135 | if (!fInFormat->ReadData(272, f))
|
---|
136 | return kFALSE;
|
---|
137 |
|
---|
138 | fEvtNumber = TMath::Nint(f[0]);
|
---|
139 | // fParticleID = TMath::Nint(f[1]);
|
---|
140 |
|
---|
141 | fTotalEnergy = f[2];
|
---|
142 | fStartAltitude = f[3];
|
---|
143 | fFirstTargetNum = f[4];
|
---|
144 | fFirstInteractionHeight = f[5]; // FIXME: Could be negative
|
---|
145 |
|
---|
146 | // Pointing opposite particle direction
|
---|
147 | // (x=north, y=west, z=upwards)
|
---|
148 | //fMomentumX = f[6];
|
---|
149 | //fMomentumY = f[7];
|
---|
150 | //fMomentumZ = f[8];
|
---|
151 | // Pointing along particle direction
|
---|
152 | // (x=east, y=north, z=upwards)
|
---|
153 | fMomentumX = f[7];
|
---|
154 | fMomentumY = -f[6];
|
---|
155 | fMomentumZ = -f[8]; // Does this minus make sense?!
|
---|
156 |
|
---|
157 | fZd = f[9];
|
---|
158 | fAz = TMath::Pi()-f[10];
|
---|
159 |
|
---|
160 | // f[96] // Number of reuse of event [max=20]
|
---|
161 |
|
---|
162 | // FIXME: Check fNumReuse<20
|
---|
163 | fX = f[117 + fNumReuse];
|
---|
164 | fY = -f[ 97 + fNumReuse];
|
---|
165 |
|
---|
166 | fWeightedNumPhotons = 0;
|
---|
167 |
|
---|
168 | return !fInFormat->Eof();
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | // this member function is for reading the event end block
|
---|
173 |
|
---|
174 | Int_t MCorsikaEvtHeader::ReadEvtEnd(MCorsikaFormat * fInFormat)
|
---|
175 | {
|
---|
176 | if (!fInFormat->SeekNextBlock("EVTE", 1209))
|
---|
177 | return kFALSE;
|
---|
178 |
|
---|
179 | //fin.seekg(-1088,ios::cur);
|
---|
180 |
|
---|
181 | Float_t f[2];
|
---|
182 |
|
---|
183 | if (!fInFormat->ReadData(2, f))
|
---|
184 | return kFALSE;
|
---|
185 |
|
---|
186 | const UInt_t evtnum = TMath::Nint(f[0]);
|
---|
187 | if (evtnum!=fEvtNumber)
|
---|
188 | {
|
---|
189 | *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
|
---|
190 | *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
|
---|
191 | return kERROR;
|
---|
192 | }
|
---|
193 |
|
---|
194 | // FIXME: What's the meaning of this if in case of reusing the event this number
|
---|
195 | // exists only once?
|
---|
196 | fWeightedNumPhotons = f[1];
|
---|
197 |
|
---|
198 | return !fInFormat->Eof();
|
---|
199 | }
|
---|