source: trunk/MagicSoft/Mars/mimage/MHillasSrc.cc@ 4819

Last change on this file since 4819 was 4817, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.5 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 <fstream>
72#include <TArrayF.h>
73
74#include "MLog.h"
75#include "MLogManip.h"
76
77#include "MGeomCam.h"
78#include "MSrcPosCam.h"
79
80ClassImp(MHillasSrc);
81
82using namespace std;
83
84// --------------------------------------------------------------------------
85//
86// Default constructor.
87//
88MHillasSrc::MHillasSrc(const char *name, const char *title)
89{
90 fName = name ? name : "MHillasSrc";
91 fTitle = title ? title : "Parameters depending in source position";
92}
93
94void MHillasSrc::Reset()
95{
96 fDist = -1;
97 fAlpha = 0;
98 fCosDeltaAlpha = 0;
99
100 fDCA = -1;
101 fDCADelta = 0;
102}
103
104// --------------------------------------------------------------------------
105//
106// Calculation of source-dependent parameters
107// In case you don't call Calc from within an eventloop make sure, that
108// you call the Reset member function before.
109//
110Int_t MHillasSrc::Calc(const MHillas &hillas)
111{
112 const Double_t mx = hillas.GetMeanX(); // [mm]
113 const Double_t my = hillas.GetMeanY(); // [mm]
114
115 const Double_t sx = mx - fSrcPos->GetX(); // [mm]
116 const Double_t sy = my - fSrcPos->GetY(); // [mm]
117
118 const Double_t sd = hillas.GetSinDelta(); // [1]
119 const Double_t cd = hillas.GetCosDelta(); // [1]
120
121 //
122 // Distance from source position to center of ellipse.
123 // If the distance is 0 distance, Alpha is not specified.
124 // The calculation has failed and returnes kFALSE.
125 //
126 const Double_t dist = TMath::Sqrt(sx*sx + sy*sy); // [mm]
127 if (dist==0)
128 return 1;
129
130 //
131 // Calculate Alpha and Cosda = cos(d,a)
132 // The sign of Cosda will be used for quantities containing
133 // a head-tail information
134 //
135 // *OLD* const Double_t arg = (sy-tand*sx) / (dist*sqrt(tand*tand+1));
136 // *OLD* fAlpha = asin(arg)*kRad2Deg;
137 //
138 const Double_t arg2 = cd*sx + sd*sy; // [mm]
139 if (arg2==0)
140 return 2;
141
142 const Double_t arg1 = cd*sy - sd*sx; // [mm]
143
144 //
145 // Due to numerical uncertanties in the calculation of the
146 // square root (dist) and arg1 it can happen (in less than 1e-5 cases)
147 // that the absolute value of arg exceeds 1. Because this uncertainty
148 // results in an Delta Alpha which is still less than 1e-3 we don't care
149 // about this uncertainty in general and simply set values which exceed
150 // to 1 saving its sign.
151 //
152 const Double_t arg = arg1/dist;
153 fAlpha = TMath::Abs(arg)>1 ? TMath::Sign(90., arg) : TMath::ASin(arg)*TMath::RadToDeg(); // [deg]
154
155 fCosDeltaAlpha = arg2/dist; // [1]
156 fDist = dist; // [mm]
157
158 // ----- Calculation of Distance to closest approach 'DCA' -----
159
160 // Components of DCA vector
161 const Double_t fpd1 = sx - arg2*cd; // [mm]
162 const Double_t fpd2 = sy - arg2*sd; // [mm]
163
164 // Determine the correct sign of the DCA (cross product of DCA vector and the
165 // vector going from the intersection point of the DCA vector with the shower axis
166 // to the COG)
167 const Double_t sign = arg2*cd*fpd2 - arg2*sd*fpd1;
168 fDCA = TMath::Sign(TMath::Sqrt(fpd1*fpd1 + fpd2*fpd2), sign); // [mm]
169
170 // Calculate angle of the shower axis with respect to the x-axis
171 fDCADelta = TMath::ACos((sx-fpd1)/TMath::Abs(arg2))*TMath::RadToDeg(); // [deg]
172
173 // Enlarge the interval of fDdca to [0, 2pi]
174 if (sy < fpd2)
175 fDCADelta = 360 - fDCADelta;
176
177 SetReadyToSave();
178
179 return 0;
180}
181
182// --------------------------------------------------------------------------
183//
184// Print contents of MHillasSrc to *fLog
185//
186void MHillasSrc::Print(Option_t *) const
187{
188 *fLog << all;
189 *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
190 *fLog << " - Dist [mm] = " << fDist << endl;
191 *fLog << " - Alpha [deg] = " << fAlpha << endl;
192 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
193 *fLog << " - DCA [mm] = " << fDCA << endl;
194 *fLog << " - DCA delta [deg] = " << fDCADelta*TMath::RadToDeg() << endl;
195}
196
197// --------------------------------------------------------------------------
198//
199// Print contents of MHillasSrc to *fLog depending on the geometry in
200// units of deg.
201//
202void MHillasSrc::Print(const MGeomCam &geom) const
203{
204 *fLog << all;
205 *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
206 *fLog << " - Dist [deg] = " << fDist*geom.GetConvMm2Deg() << endl;
207 *fLog << " - Alpha [deg] = " << fAlpha << endl;
208 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
209 *fLog << " - DCA [deg] = " << fDCA*geom.GetConvMm2Deg() << endl;
210 *fLog << " - DCA delta [deg] = " << fDCADelta*TMath::RadToDeg() << endl;
211}
212
213// --------------------------------------------------------------------------
214//
215// This function is ment for special usage, please never try to set
216// values via this function
217//
218void MHillasSrc::Set(const TArrayF &arr)
219{
220 if (arr.GetSize() != 5)
221 return;
222
223 fAlpha = arr.At(0); // [deg] angle of major axis with vector to src
224 fDist = arr.At(1); // [mm] distance between src and center of ellipse
225 fCosDeltaAlpha = arr.At(2); // [1] cosine of angle between d and a
226 fDCA = arr.At(3); // [mm]
227 fDCADelta = arr.At(4); // [mm]
228}
Note: See TracBrowser for help on using the repository browser.