source: trunk/Mars/mcorsika/MCorsikaEvtHeader.cc@ 18145

Last change on this file since 18145 was 15365, checked in by tbretz, 12 years ago
Stop processing if there is a nonsense number of reuse of shower.
File size: 6.2 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-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
53ClassImp(MCorsikaEvtHeader);
54
55using namespace std;
56
57// --------------------------------------------------------------------------
58//
59// Default constructor. Create the array to store the data.
60//
61MCorsikaEvtHeader::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//
94Double_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//
108void 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// get the EVTH information from the input parameter f
127//
128Int_t MCorsikaEvtHeader::ReadEvt(Float_t * f)
129{
130
131 fEvtNumber = TMath::Nint(f[0]);
132// fParticleID = TMath::Nint(f[1]);
133
134 fTotalEnergy = f[2];
135 fStartAltitude = f[3];
136 fFirstTargetNum = f[4];
137 fFirstInteractionHeight = f[5]; // FIXME: Could be negative
138
139 // Pointing opposite particle direction
140 // (x=north, y=west, z=upwards)
141 //fMomentumX = f[6];
142 //fMomentumY = f[7];
143 //fMomentumZ = f[8];
144 // Pointing along particle direction
145 // (x=east, y=north, z=upwards)
146 fMomentumX = f[7];
147 fMomentumY = -f[6];
148 fMomentumZ = -f[8]; // Does this minus make sense?!
149
150 fZd = f[9];
151 fAz = TMath::Pi()-f[10];
152
153 // f[96] // Number of reuse of event [max=20]
154 fTotReuse = TMath::Nint(f[96]);
155 if (fTotReuse > 20)
156 {
157 *fLog << err << "Number of reuse of shower is " << fTotReuse
158 << " But maximum implemented: 20" << endl;
159 return kERROR;
160 }
161
162 memcpy(fTempX, f +97, 20*sizeof(Float_t));
163 memcpy(fTempY, f+117, 20*sizeof(Float_t));
164
165
166 // FIXME: Check fNumReuse<20
167// fX = f[117 + fNumReuse];
168// fY = -f[ 97 + fNumReuse];
169
170 fWeightedNumPhotons = 0;
171
172 return kTRUE;
173}
174
175
176// this member function is for reading the event end block
177
178Int_t MCorsikaEvtHeader::ReadEvtEnd(MCorsikaFormat * fInFormat)
179{
180 Float_t f[272];
181 if (!fInFormat->Read(f, 272 * sizeof(Float_t)))
182 return kERROR;
183
184 const UInt_t evtnum = TMath::Nint(f[0]);
185 if (evtnum!=fEvtNumber)
186 {
187 *fLog << err << "ERROR - Mismatch in stream: Event number in EVTE (";
188 *fLog << evtnum << ") doesn't match EVTH (" << fEvtNumber << ")." << endl;
189 return kERROR;
190 }
191
192 // FIXME: What's the meaning of this if in case of reusing the event this number
193 // exists only once?
194 fWeightedNumPhotons = f[1];
195
196 return fInFormat->Eof() ? kERROR : kTRUE;
197}
Note: See TracBrowser for help on using the repository browser.