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): Roger Firpo 04/2004 <mailto:jlopez@ifae.es>
|
---|
19 | ! Author(s): Javier López 05/2004 <mailto:jlopez@ifae.es>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | //////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MSrcPosFromStars
|
---|
29 | //
|
---|
30 | // Task to set the position of the source using the positions of the stars
|
---|
31 | // in the field of view of the source
|
---|
32 | //
|
---|
33 | // Output Containers:
|
---|
34 | // MSrcPosCam
|
---|
35 | //
|
---|
36 | //////////////////////////////////////////////////////////////////////////////
|
---|
37 |
|
---|
38 |
|
---|
39 | #include "MSrcPosFromStars.h"
|
---|
40 |
|
---|
41 | #include <TList.h>
|
---|
42 |
|
---|
43 | #include "MSrcPosCam.h"
|
---|
44 | #include "MStarLocalCam.h"
|
---|
45 | #include "MStarLocalPos.h"
|
---|
46 |
|
---|
47 | #include "MLog.h"
|
---|
48 | #include "MLogManip.h"
|
---|
49 |
|
---|
50 | #include "MParList.h"
|
---|
51 |
|
---|
52 | ClassImp(MSrcPosFromStars);
|
---|
53 |
|
---|
54 | using namespace std;
|
---|
55 |
|
---|
56 | static const TString gsDefName = "MSrcPosFromStars";
|
---|
57 | static const TString gsDefTitle = "task to calculate the position of the source using the position of stars";
|
---|
58 |
|
---|
59 | // -------------------------------------------------------------------------
|
---|
60 | //
|
---|
61 | // Default constructor.
|
---|
62 | //
|
---|
63 | MSrcPosFromStars::MSrcPosFromStars(Float_t first, Float_t second, const char *name, const char *title)
|
---|
64 | : fStars(NULL), fNumStars(2), fDistanceFirstStar(first), fDistanceSecondStar(second)
|
---|
65 | {
|
---|
66 | fName = name ? name : gsDefName.Data();
|
---|
67 | fTitle = title ? title : gsDefTitle.Data();
|
---|
68 |
|
---|
69 | }
|
---|
70 |
|
---|
71 | // -------------------------------------------------------------------------
|
---|
72 | //
|
---|
73 | Int_t MSrcPosFromStars::PreProcess(MParList *pList)
|
---|
74 | {
|
---|
75 |
|
---|
76 | if(!MSrcPlace::PreProcess(pList))
|
---|
77 | return kFALSE;
|
---|
78 |
|
---|
79 | fStars = (MStarLocalCam*)pList->FindObject(AddSerialNumber("MStarLocalCam"));
|
---|
80 | if (!fStars)
|
---|
81 | {
|
---|
82 | *fLog << err << AddSerialNumber("MStarLocalCam") << " not found ... aborting" << endl;
|
---|
83 | return kFALSE;
|
---|
84 | }
|
---|
85 |
|
---|
86 | return kTRUE;
|
---|
87 | }
|
---|
88 |
|
---|
89 | // --------------------------------------------------------------------------
|
---|
90 | //
|
---|
91 | //
|
---|
92 | Int_t MSrcPosFromStars::ComputeNewSrcPosition()
|
---|
93 | {
|
---|
94 |
|
---|
95 | if (fDistanceFirstStar == 0. || fDistanceSecondStar == 0.)
|
---|
96 | {
|
---|
97 | if (fStars->GetNumStars() > 0)
|
---|
98 | {
|
---|
99 |
|
---|
100 | //Look for the star closer to the center of the camera
|
---|
101 | TIter Next(fStars->GetList());
|
---|
102 | MStarLocalPos* star;
|
---|
103 | Float_t mindist = 600; //mm
|
---|
104 | UInt_t starnum = 0;
|
---|
105 | Int_t select = -1;
|
---|
106 | while ((star=(MStarLocalPos*)Next()))
|
---|
107 | {
|
---|
108 | Float_t dist = TMath::Sqrt(star->GetMeanX()*star->GetMeanX() +
|
---|
109 | star->GetMeanY()*star->GetMeanY());
|
---|
110 | if (dist < mindist)
|
---|
111 | {
|
---|
112 | mindist = dist;
|
---|
113 | select = starnum;
|
---|
114 | }
|
---|
115 |
|
---|
116 | starnum++;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (select < 0)
|
---|
120 | {
|
---|
121 | *fLog << err << "Not found star closer to center" << endl;
|
---|
122 | return kFALSE;
|
---|
123 | }
|
---|
124 |
|
---|
125 | MStarLocalPos& selecStar = (*fStars)[select];
|
---|
126 |
|
---|
127 | if (selecStar.GetChiSquareNdof() > 0. && selecStar.GetChiSquareNdof() < 10.)
|
---|
128 | {
|
---|
129 |
|
---|
130 | Float_t selecStarPosX = selecStar.GetMeanX();
|
---|
131 | Float_t selecStarPosY = selecStar.GetMeanY();
|
---|
132 |
|
---|
133 | GetOutputSrcPosCam()->SetXY(selecStarPosX,selecStarPosY);
|
---|
134 | }
|
---|
135 | }
|
---|
136 | }
|
---|
137 | else if (fStars->GetNumStars() == fNumStars)
|
---|
138 | {
|
---|
139 |
|
---|
140 | MStarLocalPos& firstStar = (*fStars)[0];
|
---|
141 | MStarLocalPos& secondStar = (*fStars)[1];
|
---|
142 |
|
---|
143 | if (firstStar.GetChiSquareNdof() > 0. && firstStar.GetChiSquareNdof() < 10. &&
|
---|
144 | secondStar.GetChiSquareNdof() > 0. && secondStar.GetChiSquareNdof() < 10.)
|
---|
145 | {
|
---|
146 |
|
---|
147 | Float_t firstStarPosX = firstStar.GetMeanX();
|
---|
148 | Float_t firstStarPosY = firstStar.GetMeanY();
|
---|
149 |
|
---|
150 | Float_t secondStarPosX = secondStar.GetMeanX();
|
---|
151 | Float_t secondStarPosY = secondStar.GetMeanY();
|
---|
152 |
|
---|
153 | Float_t distanceStars = sqrt(pow(firstStarPosX - secondStarPosX,2) + pow(firstStarPosY - secondStarPosY,2));
|
---|
154 | Float_t sin_alpha = (secondStarPosY - firstStarPosY) / distanceStars;
|
---|
155 | Float_t cos_alpha = (secondStarPosX - firstStarPosX) / distanceStars;
|
---|
156 |
|
---|
157 | Float_t x = (pow(fDistanceFirstStar,2) - pow(fDistanceSecondStar,2) + pow(distanceStars,2)) / (2 * distanceStars);
|
---|
158 |
|
---|
159 | Float_t arg = 4 * pow(distanceStars,2) * pow(fDistanceFirstStar,2) - pow(pow(fDistanceFirstStar,2) - pow(fDistanceSecondStar,2) + pow(distanceStars,2),2);
|
---|
160 |
|
---|
161 | if (arg >= 0.)
|
---|
162 | {
|
---|
163 |
|
---|
164 | Float_t y = sqrt(arg) / (2 * distanceStars);
|
---|
165 |
|
---|
166 | Float_t xc1 = firstStarPosX + x * cos_alpha - y * sin_alpha;
|
---|
167 | Float_t yc1 = firstStarPosY + x * sin_alpha + y * cos_alpha;
|
---|
168 |
|
---|
169 | Float_t xc2 = firstStarPosX + x * cos_alpha + y * sin_alpha;
|
---|
170 | Float_t yc2 = firstStarPosY + x * sin_alpha - y * cos_alpha;
|
---|
171 |
|
---|
172 | if (sqrt(xc1*xc1 + yc1*yc1) < sqrt(xc2*xc2 + yc2*yc2))
|
---|
173 | GetOutputSrcPosCam()->SetXY(xc1,yc1);
|
---|
174 | else
|
---|
175 | GetOutputSrcPosCam()->SetXY(xc2,yc2);
|
---|
176 | }
|
---|
177 | else
|
---|
178 | *fLog << warn << GetName() << " negative argument [" << arg << "] for sqrt()" << endl;
|
---|
179 |
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | return kTRUE;
|
---|
184 | }
|
---|
185 |
|
---|