source: trunk/MagicSoft/Mars/mtemp/meth/MHillasSrc.cc@ 4210

Last change on this file since 4210 was 4095, checked in by commichau, 21 years ago
*** empty log message ***
File size: 7.8 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 01/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! Author(s): Sabrina Stark 05/2004 <mailto:stark@particle.phys.ethz.ch>
23! Author(s): Sebastian Commichau 05/2004 <mailto:commichau@particle.phys.ethz.ch>
24!
25! Copyright: MAGIC Software Development, 2000-2002
26!
27!
28\* ======================================================================== */
29
30/////////////////////////////////////////////////////////////////////////////
31//
32// MHillasSrc
33//
34// Storage Container for image parameters
35//
36// source-dependent image parameters
37//
38//
39// Version 1:
40// ----------
41// fAlpha angle between major axis and line source-to-center
42// fDist distance from source to center of ellipse
43//
44//
45// Version 2:
46// ----------
47// fHeadTail added
48//
49//
50// Version 3:
51// ----------
52// fCosDeltaAlpha cosine of angle between d and a, where
53// - d is the vector from the source position to the
54// center of the ellipse
55// - a is a vector along the main axis of the ellipse,
56// defined with positive x-component
57//
58//
59// Version 4:
60// ----------
61//
62// fHeadTail removed
63//
64/////////////////////////////////////////////////////////////////////////////
65#include "MHillasSrc.h"
66
67#include <fstream>
68#include <TArrayF.h>
69
70#include "MLog.h"
71#include "MLogManip.h"
72
73#include "MGeomCam.h"
74#include "MSrcPosCam.h"
75
76ClassImp(MHillasSrc);
77
78using namespace std;
79
80// --------------------------------------------------------------------------
81//
82// Default constructor.
83//
84MHillasSrc::MHillasSrc(const char *name, const char *title)
85{
86 fName = name ? name : "MHillasSrc";
87 fTitle = title ? title : "Parameters depending in source position";
88}
89
90void MHillasSrc::Reset()
91{
92 fDist = -1;
93 fAlpha = 0;
94 fCosDeltaAlpha = 0;
95 fDCA = 0;
96 fDDCA = 0;
97}
98
99// --------------------------------------------------------------------------
100//
101// Calculation of source-dependent parameters
102// In case you don't call Calc from within an eventloop make sure, that
103// you call the Reset member function before.
104//
105Bool_t MHillasSrc::Calc(const MHillas *hillas)
106{
107 const Double_t mx = hillas->GetMeanX(); // [mm]
108 const Double_t my = hillas->GetMeanY(); // [mm]
109
110 const Double_t sx = mx - fSrcPos->GetX(); // [mm]
111 const Double_t sy = my - fSrcPos->GetY(); // [mm]
112
113 //
114 // DCA: Distance of Closest Approach.
115 // Minimal distance from the shower axis to a reference point.
116
117 Double_t fDdca = hillas->GetDelta();
118
119 // Distance between intersection point (DCA vector and the shower axis) and COG.
120 const Double_t fl = -(sx*TMath::Cos(fDdca) + sy*TMath::Sin(fDdca));
121
122 // Components of DCA vector
123 const Double_t fpd1 = TMath::Cos(fDdca)*fl+sx;
124 const Double_t fpd2 = TMath::Sin(fDdca)*fl+sy;
125
126 // Calculate DCA value
127 Double_t fdca = sqrt(fpd1*fpd1 + fpd2*fpd2);
128
129 // Determine the correct sign of the DCA (cross product of DCA vector and the
130 // vector going from the intersection point of the DCA vector with the shower axis
131 // to the COG)
132 if ((sx-fpd1)*fpd2-(sy-fpd2)*fpd1<0.)
133 fdca = -fdca;
134
135 // Calculate angle of the shower axis with respect to the x-axis
136 fDdca = TMath::ACos((sx-fpd1)/TMath::Abs(fl));
137
138 // Enlarge the interval of fDdca to [0, 2pi]
139 if((sy-fpd2)<0)
140 fDdca = 360/kRad2Deg-fDdca;
141
142
143 //
144 // Distance from source position to center of ellipse.
145 // If the distance is 0 distance, Alpha is not specified.
146 // The calculation has failed and returnes kFALSE.
147 //
148 const Double_t dist = sqrt(sx*sx + sy*sy); // [mm]
149 if (dist==0)
150 return kFALSE;
151
152 // Calculate Alpha and Cosda = cos(d,a)
153 // The sign of Cosda will be used for quantities containing
154 // a head-tail information
155 //
156 // *OLD* const Double_t arg = (sy-tand*sx) / (dist*sqrt(tand*tand+1));
157 // *OLD* fAlpha = asin(arg)*kRad2Deg;
158 //
159 // const Double_t arg1 = cd*sy-sd*sx; // [mm] ... equal abs(fdca)
160 // const Double_t arg2 = cd*sx+sd*sy; // [mm] ... equal abs(fl)
161 const Double_t arg1 = TMath::Abs(fdca); // [mm]
162 const Double_t arg2 = TMath::Abs(fl); // [mm]
163
164 //
165 // Due to numerical uncertanties in the calculation of the
166 // square root (dist) and arg1 it can happen (in less than 1e-5 cases)
167 // that the absolute value of arg exceeds 1. Because this uncertainty
168 // results in an Delta Alpha which is still less than 1e-3 we don't care
169 // about this uncertainty in general and simply set values which exceed
170 // to 1 saving its sign.
171 //
172 const Double_t arg = arg1/dist;
173 fAlpha = TMath::Abs(arg)>1 ? TMath::Sign(90., arg) : asin(arg)*kRad2Deg; // [deg]
174
175 fCosDeltaAlpha = arg2/dist; // [1]
176 fDist = dist; // [mm]
177 fDCA = fdca; // [mm]
178 fDDCA = fDdca; // [rad]
179
180 SetReadyToSave();
181
182 return kTRUE;
183}
184
185// --------------------------------------------------------------------------
186//
187// Print contents of MHillasSrc to *fLog
188//
189void MHillasSrc::Print(Option_t *) const
190{
191 *fLog << all;
192 *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
193 *fLog << " - Dist [mm] = " << fDist << endl;
194 *fLog << " - Alpha [deg] = " << fAlpha << endl;
195 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
196 *fLog << " - DCA [mm] = " << fDCA << endl;
197 *fLog << " - DeltaDCA [mm] = " << fDDCA << endl;
198}
199
200// --------------------------------------------------------------------------
201//
202// Print contents of MHillasSrc to *fLog depending on the geometry in
203// units of deg.
204//
205void MHillasSrc::Print(const MGeomCam &geom) const
206{
207 *fLog << all;
208 *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
209 *fLog << " - Dist [deg] = " << fDist*geom.GetConvMm2Deg() << endl;
210 *fLog << " - Alpha [deg] = " << fAlpha << endl;
211 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
212 *fLog << " - DCA [deg] = " << fDCA*geom.GetConvMm2Deg() << endl;
213 *fLog << " - DeltaDCA [mm] = " << fDDCA << endl;
214}
215
216// --------------------------------------------------------------------------
217//
218// This function is ment for special usage, please never try to set
219// values via this function
220//
221void MHillasSrc::Set(const TArrayF &arr)
222{
223 if (arr.GetSize() != 5)
224 return;
225
226 fAlpha = arr.At(0); // [deg] angle of major axis with vector to src
227 fDist = arr.At(1); // [mm] distance between src and center of ellipse
228 fCosDeltaAlpha = arr.At(2); // [1] cosine of angle between d and a
229 fDCA = arr.At(3); // [mm] distance between ref. point and shower axis
230 fDDCA = arr.At(4); // [rad] angle between shower axis and x-axis
231}
Note: See TracBrowser for help on using the repository browser.