source: trunk/Mars/mimage/MHillasSrc.cc@ 19405

Last change on this file since 19405 was 19207, checked in by tbretz, 6 years ago
Fixed a typo in a comment.
File size: 8.6 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 12/2000 <mailto:tbretz@uni-sw.gwdg.de>
19! Author(s): Harald Kornmayer 1/2001
20! Author(s): Rudolf Bock 10/2001 <mailto:Rudolf.Bock@cern.ch>
21! Author(s): Wolfgang Wittek 06/2002 <mailto:wittek@mppmu.mpg.de>
22!
23! Copyright: MAGIC Software Development, 2000-2002
24!
25!
26\* ======================================================================== */
27
28/////////////////////////////////////////////////////////////////////////////
29//
30// MHillasSrc
31//
32// Storage Container for image parameters
33//
34// source-dependent image parameters
35//
36//
37// Version 1:
38// ----------
39// fAlpha angle between major axis and line source-to-center
40// fDist distance from source to center of ellipse
41//
42//
43// Version 2:
44// ----------
45// fHeadTail added
46//
47//
48// Version 3:
49// ----------
50// fCosDeltaAlpha cosine of angle between d and a, where
51// - d is the vector from the source position to the
52// center of the ellipse
53// - a is a vector along the main axis of the ellipse,
54// defined with positive x-component
55//
56//
57// Version 4:
58// ----------
59// fHeadTail removed
60//
61//
62// Version 5:
63// ----------
64// - added Float_t fDCA; // [mm] Distance to closest approach 'DCA'
65// - added Float_t fDCADelta; // [deg] Angle of the shower axis with respect
66// to the x-axis [0,2pi]
67//
68/////////////////////////////////////////////////////////////////////////////
69#include "MHillasSrc.h"
70
71#include <TArrayF.h>
72
73#include <TLine.h>
74#include <TMarker.h>
75
76#include "MLog.h"
77#include "MLogManip.h"
78
79#include "MGeomCam.h"
80#include "MHillas.h"
81#include "MSrcPosCam.h"
82
83ClassImp(MHillasSrc);
84
85using namespace std;
86
87// --------------------------------------------------------------------------
88//
89// Default constructor.
90//
91MHillasSrc::MHillasSrc(const char *name, const char *title)
92{
93 fName = name ? name : "MHillasSrc";
94 fTitle = title ? title : "Parameters depending in source position";
95}
96
97void MHillasSrc::Reset()
98{
99 fDist = -1;
100 fAlpha = 0;
101 fCosDeltaAlpha = 0;
102
103 fDCA = -1;
104 fDCADelta = 0;
105}
106
107// --------------------------------------------------------------------------
108//
109// Calculation of source-dependent parameters
110// In case you don't call Calc from within an eventloop make sure, that
111// you call the Reset member function before.
112//
113Int_t MHillasSrc::Calc(const MHillas &hillas, double abberation)
114{
115 const Double_t mx = hillas.GetMeanX(); // [mm]
116 const Double_t my = hillas.GetMeanY(); // [mm]
117
118 // The abberation value corrects for the average shift of
119 // the CoG of a light distribution in the camera by the optics.
120 // The FACT reflector for example reflects the CoG to a point
121 // 2% further away than the master ray. This could be corrected
122 // moving all pixels (in the image parameter calculation) 2%
123 // inwards. Instead, simply the source position 'reflected'
124 // (as if it were the master ray) is moved 2% outwards in the
125 // camera.
126 const Double_t sx = mx - fSrcPos->GetX()*abberation; // [mm]
127 const Double_t sy = my - fSrcPos->GetY()*abberation; // [mm]
128
129 const Double_t sd = hillas.GetSinDelta(); // [1]
130 const Double_t cd = hillas.GetCosDelta(); // [1]
131
132 //
133 // Distance from source position to center of ellipse.
134 // If the distance is 0 distance, Alpha is not specified.
135 // The calculation has failed and returns kFALSE.
136 //
137 const Double_t dist = TMath::Sqrt(sx*sx + sy*sy); // [mm]
138 if (dist==0)
139 return 1;
140
141 //
142 // Calculate Alpha and Cosda = cos(d,a)
143 // The sign of Cosda will be used for quantities containing
144 // a head-tail information
145 //
146 // *OLD* const Double_t arg = (sy-tand*sx) / (dist*sqrt(tand*tand+1));
147 // *OLD* fAlpha = asin(arg)*kRad2Deg;
148 //
149 const Double_t arg2 = cd*sx + sd*sy; // [mm]
150 if (arg2==0)
151 return 2;
152
153 const Double_t arg1 = cd*sy - sd*sx; // [mm]
154
155 //
156 // Due to numerical uncertanties in the calculation of the
157 // square root (dist) and arg1 it can happen (in less than 1e-5 cases)
158 // that the absolute value of arg exceeds 1. Because this uncertainty
159 // results in an Delta Alpha which is still less than 1e-3 we don't care
160 // about this uncertainty in general and simply set values which exceed
161 // to 1 saving its sign.
162 //
163 const Double_t arg = arg1/dist;
164 fAlpha = TMath::Abs(arg)>1 ? TMath::Sign(90., arg) : TMath::ASin(arg)*TMath::RadToDeg(); // [deg]
165
166 fCosDeltaAlpha = arg2/dist; // [1]
167 fDist = dist; // [mm]
168
169 // ----- Calculation of Distance to closest approach 'DCA' -----
170
171 // Components of DCA vector
172 const Double_t fpd1 = sx - arg2*cd; // [mm]
173 const Double_t fpd2 = sy - arg2*sd; // [mm]
174
175 // Determine the correct sign of the DCA (cross product of DCA vector and the
176 // vector going from the intersection point of the DCA vector with the shower axis
177 // to the COG)
178 const Double_t sign = arg2*cd*fpd2 - arg2*sd*fpd1;
179 fDCA = TMath::Sign(TMath::Sqrt(fpd1*fpd1 + fpd2*fpd2), sign); // [mm]
180
181 // Calculate angle of the shower axis with respect to the x-axis
182 fDCADelta = TMath::ACos((sx-fpd1)/TMath::Abs(arg2))*TMath::RadToDeg(); // [deg]
183
184 // Enlarge the interval of fDdca to [0, 2pi]
185 if (sy < fpd2)
186 fDCADelta = 360 - fDCADelta;
187
188 SetReadyToSave();
189
190 return 0;
191}
192
193void MHillasSrc::Paint(Option_t *opt)
194{
195 const Float_t x = fSrcPos ? fSrcPos->GetX() : 0;
196 const Float_t y = fSrcPos ? fSrcPos->GetY() : 0;
197
198 TMarker m;
199 m.SetMarkerColor(kYellow);
200 m.SetMarkerStyle(kStar);
201 m.PaintMarker(x, y);
202/*
203 m.SetMarkerColor(kMagenta);
204 m.PaintMarker(fDist*cos((fDCADelta-fAlpha)*TMath::DegToRad()),
205 fDist*sin((fDCADelta-fAlpha)*TMath::DegToRad()));
206
207 TLine line;
208 line.SetLineWidth(1);
209 line.SetLineColor(108);
210
211 line.PaintLine(-radius, y, radius, y);
212 line.PaintLine(x, -radius, x, radius);
213
214 // COG line
215 TLine line(x, y, meanX, meanY);
216 line.SetLineWidth(1);
217 line.SetLineColor(2);
218 line.Paint();*/
219}
220
221// --------------------------------------------------------------------------
222//
223// Print contents of MHillasSrc to *fLog
224//
225void MHillasSrc::Print(Option_t *) const
226{
227 *fLog << all;
228 *fLog << GetDescriptor() << endl;
229 *fLog << " - Dist [mm] = " << fDist << endl;
230 *fLog << " - Alpha [deg] = " << fAlpha << endl;
231 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
232 *fLog << " - DCA [mm] = " << fDCA << endl;
233 *fLog << " - DCA delta [deg] = " << fDCADelta << endl;
234}
235
236// --------------------------------------------------------------------------
237//
238// Print contents of MHillasSrc to *fLog depending on the geometry in
239// units of deg.
240//
241void MHillasSrc::Print(const MGeomCam &geom) const
242{
243 *fLog << all;
244 *fLog << GetDescriptor() << endl;
245 *fLog << " - Dist [deg] = " << fDist*geom.GetConvMm2Deg() << endl;
246 *fLog << " - Alpha [deg] = " << fAlpha << endl;
247 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
248 *fLog << " - DCA [deg] = " << fDCA*geom.GetConvMm2Deg() << endl;
249 *fLog << " - DCA delta [deg] = " << fDCADelta << endl;
250}
251
252// --------------------------------------------------------------------------
253//
254// This function is ment for special usage, please never try to set
255// values via this function
256//
257void MHillasSrc::Set(const TArrayF &arr)
258{
259 if (arr.GetSize() != 5)
260 return;
261
262 fAlpha = arr.At(0); // [deg] angle of major axis with vector to src
263 fDist = arr.At(1); // [mm] distance between src and center of ellipse
264 fCosDeltaAlpha = arr.At(2); // [1] cosine of angle between d and a
265 fDCA = arr.At(3); // [mm]
266 fDCADelta = arr.At(4); // [mm]
267}
Note: See TracBrowser for help on using the repository browser.