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 | const Int_t rc=fInFormat->SeekNextBlock("EVTH", 1202);
|
---|
132 | if (rc!=kTRUE)
|
---|
133 | return rc;
|
---|
134 |
|
---|
135 | Float_t f[273];
|
---|
136 | if (!fInFormat->ReadData(272, f))
|
---|
137 | return kERROR;
|
---|
138 |
|
---|
139 | fEvtNumber = TMath::Nint(f[0]);
|
---|
140 | // fParticleID = TMath::Nint(f[1]);
|
---|
141 |
|
---|
142 | fTotalEnergy = f[2];
|
---|
143 | fStartAltitude = f[3];
|
---|
144 | fFirstTargetNum = f[4];
|
---|
145 | fFirstInteractionHeight = f[5]; // FIXME: Could be negative
|
---|
146 |
|
---|
147 | // Pointing opposite particle direction
|
---|
148 | // (x=north, y=west, z=upwards)
|
---|
149 | //fMomentumX = f[6];
|
---|
150 | //fMomentumY = f[7];
|
---|
151 | //fMomentumZ = f[8];
|
---|
152 | // Pointing along particle direction
|
---|
153 | // (x=east, y=north, z=upwards)
|
---|
154 | fMomentumX = f[7];
|
---|
155 | fMomentumY = -f[6];
|
---|
156 | fMomentumZ = -f[8]; // Does this minus make sense?!
|
---|
157 |
|
---|
158 | fZd = f[9];
|
---|
159 | fAz = TMath::Pi()-f[10];
|
---|
160 |
|
---|
161 | // f[96] // Number of reuse of event [max=20]
|
---|
162 |
|
---|
163 | memcpy(fTempX, f +97, 20*sizeof(Float_t));
|
---|
164 | memcpy(fTempY, f+117, 20*sizeof(Float_t));
|
---|
165 |
|
---|
166 | // FIXME: Check fNumReuse<20
|
---|
167 | // fX = f[117 + fNumReuse];
|
---|
168 | // fY = -f[ 97 + fNumReuse];
|
---|
169 |
|
---|
170 | fWeightedNumPhotons = 0;
|
---|
171 |
|
---|
172 | return fInFormat->Eof() ? kERROR : kTRUE;
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | // this member function is for reading the event end block
|
---|
177 |
|
---|
178 | Int_t MCorsikaEvtHeader::ReadEvtEnd(MCorsikaFormat * fInFormat)
|
---|
179 | {
|
---|
180 | if (fInFormat->SeekNextBlock("EVTE", 1209)!=kTRUE)
|
---|
181 | return kERROR;
|
---|
182 |
|
---|
183 | //fin.seekg(-1088,ios::cur);
|
---|
184 |
|
---|
185 | Float_t f[2];
|
---|
186 | if (!fInFormat->ReadData(2, f))
|
---|
187 | return kERROR;
|
---|
188 |
|
---|
189 | const UInt_t evtnum = TMath::Nint(f[0]);
|
---|
190 | if (evtnum!=fEvtNumber)
|
---|
191 | {
|
---|
192 | *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
|
---|
193 | *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
|
---|
194 | return kERROR;
|
---|
195 | }
|
---|
196 |
|
---|
197 | // FIXME: What's the meaning of this if in case of reusing the event this number
|
---|
198 | // exists only once?
|
---|
199 | fWeightedNumPhotons = f[1];
|
---|
200 |
|
---|
201 | return fInFormat->Eof() ? kERROR : kTRUE;
|
---|
202 | }
|
---|