source: trunk/Mars/mstarcam/MStarPos.cc@ 12540

Last change on this file since 12540 was 4709, checked in by rwagner, 20 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 expressed
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Javier López , 4/2004 <mailto:jlopez@ifae.es>
19! Robert Wagner, 7/2004 <mailto:rwagner@mppmu.mpg.de>
20! Wolfgang Wittek, 8/2004 <mailto:wittek@mppmu.mpg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24!
25\* ======================================================================== */
26#include "MStarPos.h"
27
28#include <TEllipse.h>
29#include <TMarker.h>
30
31#include "MLog.h"
32#include "MLogManip.h"
33
34ClassImp(MStarPos);
35
36using namespace std;
37
38MStarPos::MStarPos(const char *name, const char *title)
39{
40
41 fName = name ? name : "MStarPos";
42 fTitle = title ? title : "";
43
44 Reset();
45}
46
47void MStarPos::Reset()
48{
49
50 //Expected position on camera
51 fMagExp = 0.;
52 fXExp = 0.;
53 fYExp = 0.;
54
55 //Ideal position on camera
56 fMagIdeal = 0.;
57 fXIdeal = 0.;
58 fYIdeal = 0.;
59
60 //Info from calculation
61 fMagCalc = 0.;
62 fMaxCalc = 0.;
63 fMeanXCalc = 0.;
64 fMeanYCalc = 0.;
65 fSigmaXCalc = 0.;
66 fSigmaYCalc = 0.;
67 fCorrXYCalc = 0.;
68 fXXErrCalc = 0.;
69 fXYErrCalc = 0.;
70 fYYErrCalc = 0.;
71
72 //Info from Gauss fit
73 fMagFit = 0.;
74 fMaxFit = 0.;
75 fMeanXFit = 0.;
76 fMeanYFit = 0.;
77 fSigmaXFit = 0.;
78 fSigmaYFit = 0.;
79 fCorrXYFit = 0.;
80 fXXErrFit = 0.;
81 fXYErrFit = 0.;
82 fYYErrFit = 0.;
83
84 fChiSquareFit = 0.;
85 fNdofFit = 1;
86
87}
88
89void MStarPos::SetExpValues(Float_t mag, Float_t x, Float_t y)
90{
91 fMagExp = mag;
92 fXExp = x;
93 fYExp = y;
94}
95
96void MStarPos::SetIdealValues(Float_t mag, Float_t x, Float_t y)
97{
98 fMagIdeal = mag;
99 fXIdeal = x;
100 fYIdeal = y;
101}
102
103void MStarPos::SetCalcValues(Float_t mag, Float_t max, Float_t x, Float_t y,
104 Float_t sigmaX, Float_t sigmaY, Float_t correlation,
105 Float_t xx, Float_t xy, Float_t yy)
106{
107 fMagCalc = mag;
108 fMaxCalc = max;
109 fMeanXCalc = x;
110 fMeanYCalc = y;
111 fSigmaXCalc = sigmaX;
112 fSigmaYCalc = sigmaY;
113 fCorrXYCalc = correlation;
114 fXXErrCalc = xx;
115 fXYErrCalc = xy;
116 fYYErrCalc = yy;
117}
118
119
120void MStarPos::SetFitValues(
121 Float_t mag, Float_t max, Float_t x, Float_t y,
122 Float_t sigmaX, Float_t sigmaY, Float_t correlation,
123 Float_t xx, Float_t xy, Float_t yy,
124 Float_t chiSquare, Int_t ndof)
125{
126 fMagFit = mag;
127 fMaxFit = max;
128 fMeanXFit = x;
129 fMeanYFit = y;
130 fSigmaXFit = sigmaX;
131 fSigmaYFit = sigmaY;
132 fCorrXYFit = correlation;
133 fXXErrFit = xx;
134 fXYErrFit = xy;
135 fYYErrFit = yy;
136
137 fChiSquareFit = chiSquare;
138 fNdofFit = ndof;
139}
140
141
142// --------------------------------------------------------------------------
143//
144// Paint the ellipse corresponding to the parameters
145//
146void MStarPos::Paint(Option_t *opt)
147{
148 //Print a cross in the expected position
149 TMarker mexp(fXExp, fYExp, 29);
150 mexp.SetMarkerSize(3);
151 mexp.SetMarkerColor(94);
152 mexp.Paint();
153
154 if (fSigmaXCalc>0. && fSigmaYCalc>0.)
155 {
156 TEllipse ecalc(fMeanXCalc, fMeanYCalc, fSigmaXCalc, fSigmaYCalc,
157 0, 360, 0);
158 ecalc.SetLineWidth(3);
159 //ecalc.SetLineColor(kBlue);
160 ecalc.SetLineColor(kMagenta);
161 ecalc.Paint();
162 }
163
164 if (fSigmaXFit>0. && fSigmaYFit>0.)
165 {
166 //Print a cross in the fitted position
167 //TMarker mFit(fMeanXFit, fMeanYFit, 3);
168 //mFit.SetMarkerSize(3);
169 //mFit.SetMarkerColor(1);
170 //mFit.Paint();
171
172 Double_t cxx = fSigmaXFit*fSigmaXFit;
173 Double_t cyy = fSigmaYFit*fSigmaYFit;
174 Double_t d = cyy - cxx;
175 Double_t cxy = fCorrXYFit * fSigmaXFit * fSigmaYFit;
176 Double_t tandel;
177 if (cxy != 0.0)
178 tandel = ( d + sqrt(d*d + 4.0*cxy*cxy) ) / (2.0*cxy);
179 else
180 tandel = 0.0;
181
182 Double_t sindel = tandel / sqrt(1.0 + tandel*tandel);
183 Double_t delta = TMath::ASin(sindel);
184
185 Double_t major = (cxx + 2.0*tandel*cxy + tandel*tandel*cyy)
186 / (1.0 + tandel*tandel);
187
188 Double_t minor = (tandel*tandel*cxx - 2.0*tandel*cxy + cyy)
189 / (1.0 + tandel*tandel);
190
191 TEllipse efit(fMeanXFit, fMeanYFit, sqrt(major), sqrt(minor),
192 0, 360, delta*kRad2Deg);
193 efit.SetLineWidth(3);
194 //efit.SetLineColor(kMagenta);
195 //efit.SetLineColor(kBlack);
196 efit.Paint();
197 }
198}
199
200void MStarPos::Print(Option_t *opt) const
201{
202 TString o = opt;
203
204 if (o.Contains("name", TString::kIgnoreCase) || opt == NULL)
205 {
206 *fLog << inf << "Star Name: \"" << this->GetName() << "\"" << endl;
207 }
208
209 if (o.Contains("mag", TString::kIgnoreCase) || opt == NULL)
210 {
211
212 *fLog << inf << "Star magnitude:" << endl;
213 *fLog << inf << " Ideal \t" << setw(4) << fMagIdeal << endl;
214 *fLog << inf << " Expected \t" << setw(4) << fMagExp << endl;
215 *fLog << inf << " Calcultated \t " << setw(4) << fMagCalc << endl;
216 *fLog << inf << " Fitted \t " << setw(4) << fMagFit << endl;
217 }
218
219 if (o.Contains("max", TString::kIgnoreCase) || opt == NULL)
220 {
221 *fLog << inf << "Star Maximum:" << endl;
222 *fLog << inf << " Calcultated \t " << setw(4) << fMaxCalc << " uA"
223 << endl;
224 *fLog << inf << " Fitted \t " << setw(4) << fMaxFit << " uA" << endl;
225 }
226
227 if (o.Contains("pos", TString::kIgnoreCase) || opt == NULL)
228 {
229 *fLog << inf << "Star position:" << endl;
230 *fLog << inf << " Ideal \t X " << setw(4) << fXIdeal
231 << " mm \tY " << setw(4) << fYIdeal << " mm" << endl;
232 *fLog << inf << " Expected \t X " << setw(4) << fXExp
233 << " mm \tY " << setw(4) << fYExp << " mm" << endl;
234 *fLog << inf << " Calcultated \t X " << setw(4) << fMeanXCalc
235 << " mm \tY " << setw(4) << fMeanYCalc << " mm" << endl;
236 *fLog << inf << " Fitted \t X " << setw(4) << fMeanXFit
237 << " mm \tY " << setw(4) << fMeanYFit << " mm" << endl;
238 }
239
240 if (o.Contains("siz", TString::kIgnoreCase) || opt == NULL)
241 {
242 *fLog << inf << "Star size:" << endl;
243 *fLog << inf << " Calcultated \t X " << setw(4) << fSigmaXCalc
244 << " mm \tY " << setw(4) << fSigmaYCalc << " mm \t correlation "
245 << setw(4) << fCorrXYCalc << endl;
246 *fLog << inf << " Fitted \t X " << setw(4) << fSigmaXFit
247 << " mm \tY " << setw(4) << fSigmaYFit << " mm \t correlation "
248 << setw(4) << fCorrXYFit << endl;
249 }
250
251 if (o.Contains("chi", TString::kIgnoreCase) || opt == NULL)
252 {
253 *fLog << inf << "Star Fit Quality:" << endl;
254 *fLog << inf << " ChiSquareFit/NdofFit \t " << setw(3)
255 << fChiSquareFit << "/" << fNdofFit << endl;
256 }
257
258 if (o.Contains("err", TString::kIgnoreCase) || opt == NULL)
259 {
260 *fLog << inf << "Error Matrix of (fMeanX,fMeanY) :"
261 << endl;
262 *fLog << inf << " xxCalc,xyCalc,yyCalc \t " << setw(3) << fXXErrCalc
263 << ", " << fXYErrCalc << ", " << fYYErrCalc << endl;
264 *fLog << inf << " xxFit,xyFit,yyFit \t " << setw(3) << fXXErrFit << ", "
265 << fXYErrFit << ", " << fYYErrFit << endl;
266 }
267
268
269}
270//--------------------------------------------------------------------------
271
272
273
274
275
276
277
278
279
Note: See TracBrowser for help on using the repository browser.