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

Last change on this file since 4054 was 2624, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.0 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//
60// fHeadTail removed
61//
62/////////////////////////////////////////////////////////////////////////////
63#include "MHillasSrc.h"
64
65#include <fstream>
66#include <TArrayF.h>
67
68#include "MLog.h"
69#include "MLogManip.h"
70
71#include "MGeomCam.h"
72#include "MSrcPosCam.h"
73
74ClassImp(MHillasSrc);
75
76using namespace std;
77
78// --------------------------------------------------------------------------
79//
80// Default constructor.
81//
82MHillasSrc::MHillasSrc(const char *name, const char *title)
83{
84 fName = name ? name : "MHillasSrc";
85 fTitle = title ? title : "Parameters depending in source position";
86}
87
88void MHillasSrc::Reset()
89{
90 fDist = -1;
91 fAlpha = 0;
92 fCosDeltaAlpha = 0;
93}
94
95// --------------------------------------------------------------------------
96//
97// Calculation of source-dependent parameters
98// In case you don't call Calc from within an eventloop make sure, that
99// you call the Reset member function before.
100//
101Bool_t MHillasSrc::Calc(const MHillas *hillas)
102{
103 const Double_t mx = hillas->GetMeanX(); // [mm]
104 const Double_t my = hillas->GetMeanY(); // [mm]
105
106 const Double_t sx = mx - fSrcPos->GetX(); // [mm]
107 const Double_t sy = my - fSrcPos->GetY(); // [mm]
108
109 const Double_t sd = hillas->GetSinDelta(); // [1]
110 const Double_t cd = hillas->GetCosDelta(); // [1]
111
112 //
113 // Distance from source position to center of ellipse.
114 // If the distance is 0 distance, Alpha is not specified.
115 // The calculation has failed and returnes kFALSE.
116 //
117 const Double_t dist = sqrt(sx*sx + sy*sy); // [mm]
118 if (dist==0)
119 return kFALSE;
120
121 //
122 // Calculate Alpha and Cosda = cos(d,a)
123 // The sign of Cosda will be used for quantities containing
124 // a head-tail information
125 //
126 // *OLD* const Double_t arg = (sy-tand*sx) / (dist*sqrt(tand*tand+1));
127 // *OLD* fAlpha = asin(arg)*kRad2Deg;
128 //
129 const Double_t arg1 = cd*sy-sd*sx; // [mm]
130 const Double_t arg2 = cd*sx+sd*sy; // [mm]
131
132 //
133 // Due to numerical uncertanties in the calculation of the
134 // square root (dist) and arg1 it can happen (in less than 1e-5 cases)
135 // that the absolute value of arg exceeds 1. Because this uncertainty
136 // results in an Delta Alpha which is still less than 1e-3 we don't care
137 // about this uncertainty in general and simply set values which exceed
138 // to 1 saving its sign.
139 //
140 const Double_t arg = arg1/dist;
141 fAlpha = TMath::Abs(arg)>1 ? TMath::Sign(90., arg) : asin(arg)*kRad2Deg; // [deg]
142
143 fCosDeltaAlpha = arg2/dist; // [1]
144 fDist = dist; // [mm]
145
146 SetReadyToSave();
147
148 return kTRUE;
149}
150
151// --------------------------------------------------------------------------
152//
153// Print contents of MHillasSrc to *fLog
154//
155void MHillasSrc::Print(Option_t *) const
156{
157 *fLog << all;
158 *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
159 *fLog << " - Dist [mm] = " << fDist << endl;
160 *fLog << " - Alpha [deg] = " << fAlpha << endl;
161 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
162}
163
164// --------------------------------------------------------------------------
165//
166// Print contents of MHillasSrc to *fLog depending on the geometry in
167// units of deg.
168//
169void MHillasSrc::Print(const MGeomCam &geom) const
170{
171 *fLog << all;
172 *fLog << "Source dependant Image Parameters (" << GetName() << ")" << endl;
173 *fLog << " - Dist [deg] = " << fDist*geom.GetConvMm2Deg() << endl;
174 *fLog << " - Alpha [deg] = " << fAlpha << endl;
175 *fLog << " - CosDeltaAlpha = " << fCosDeltaAlpha << endl;
176}
177
178// --------------------------------------------------------------------------
179//
180// This function is ment for special usage, please never try to set
181// values via this function
182//
183void MHillasSrc::Set(const TArrayF &arr)
184{
185 if (arr.GetSize() != 3)
186 return;
187
188 fAlpha = arr.At(0); // [deg] angle of major axis with vector to src
189 fDist = arr.At(1); // [mm] distance between src and center of ellipse
190 fCosDeltaAlpha = arr.At(2); // [1] cosine of angle between d and a
191}
Note: See TracBrowser for help on using the repository browser.