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, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MAstroCamera
|
---|
28 | //
|
---|
29 | // A tools displaying stars from a catalog in the camera display.
|
---|
30 | //
|
---|
31 | // For a usage example see macros/starfield.C
|
---|
32 | //
|
---|
33 | // PRELIMINARY!!
|
---|
34 | //
|
---|
35 | /////////////////////////////////////////////////////////////////////////////
|
---|
36 | #include "MAstroCamera.h"
|
---|
37 |
|
---|
38 | #include <KeySymbols.h>
|
---|
39 |
|
---|
40 | #include <TH2.h>
|
---|
41 | #include <TMarker.h>
|
---|
42 | #include <TVirtualPad.h>
|
---|
43 |
|
---|
44 | #include "MLog.h"
|
---|
45 | #include "MLogManip.h"
|
---|
46 |
|
---|
47 | #include "MGeomCam.h"
|
---|
48 | #include "MGeomMirror.h"
|
---|
49 |
|
---|
50 | #include "MTime.h"
|
---|
51 | #include "../mhist/MHCamera.h"
|
---|
52 | #include "MObservatory.h"
|
---|
53 |
|
---|
54 | ClassImp(MAstroCamera);
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | MAstroCamera::MAstroCamera() : fGeom(0), fMirrors(0)
|
---|
59 | {
|
---|
60 | fMirror0 = new MGeomMirror;
|
---|
61 | fMirror0->SetMirrorContent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
|
---|
62 | }
|
---|
63 |
|
---|
64 | MAstroCamera::~MAstroCamera()
|
---|
65 | {
|
---|
66 | if (fGeom)
|
---|
67 | delete fGeom;
|
---|
68 | if (fMirrors)
|
---|
69 | delete fMirrors;
|
---|
70 |
|
---|
71 | delete fMirror0;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void MAstroCamera::SetMirrors(TClonesArray *arr)
|
---|
75 | {
|
---|
76 | if (!arr || arr->GetClass()!=MGeomMirror::Class())
|
---|
77 | return;
|
---|
78 |
|
---|
79 | const Int_t n = arr->GetSize();
|
---|
80 |
|
---|
81 | if (!fMirrors)
|
---|
82 | fMirrors = new TClonesArray(MGeomMirror::Class(), n);
|
---|
83 |
|
---|
84 | fMirrors->ExpandCreate(n);
|
---|
85 |
|
---|
86 | for (int i=0; i<n; i++)
|
---|
87 | memcpy((*fMirrors)[i], (*arr)[i], sizeof(MGeomMirror));
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 | void MAstroCamera::SetGeom(const MGeomCam &cam)
|
---|
92 | {
|
---|
93 | if (fGeom)
|
---|
94 | delete fGeom;
|
---|
95 |
|
---|
96 | fGeom = (MGeomCam*)cam.Clone();
|
---|
97 | }
|
---|
98 |
|
---|
99 | Int_t MAstroCamera::Convert(const TRotation &rot, TVector2 &v, Int_t type)
|
---|
100 | {
|
---|
101 | MVector3 w;
|
---|
102 |
|
---|
103 | switch (type)
|
---|
104 | {
|
---|
105 | case 1:
|
---|
106 | w.SetRaDec(v.X(), v.Y(), 1);
|
---|
107 | w = w.GetZdAz(*fTime, *fObservatory);
|
---|
108 | break;
|
---|
109 | case 2:
|
---|
110 | w.SetZdAz(v.Y(), v.X(), 1);
|
---|
111 | break;
|
---|
112 | default:
|
---|
113 | return kFALSE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | w *= rot;
|
---|
117 |
|
---|
118 | const TVector3 spot = fMirror0->GetReflection(w, fGeom->GetCameraDist())*1000;
|
---|
119 |
|
---|
120 | /*
|
---|
121 | --- Use this to plot the 'mean grid' instead of the grid of a
|
---|
122 | theoretical central mirror ---
|
---|
123 |
|
---|
124 | TVector3 spot;
|
---|
125 | const Int_t num = fConfig->GetNumMirror();
|
---|
126 | for (int i=0; i<num; i++)
|
---|
127 | spot += fConfig->GetMirror(i).GetReflection(w, fGeom->GetCameraDist())*1000;
|
---|
128 | spot *= 1./num;
|
---|
129 | */
|
---|
130 |
|
---|
131 | v.Set(spot(1), spot(0));
|
---|
132 |
|
---|
133 | const Float_t max = fGeom->GetMaxRadius()*0.70;
|
---|
134 | return v.X()>-max && v.Y()>-max && v.X()<max && v.Y()<max;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void MAstroCamera::DrawNet(const TRotation &rot)
|
---|
138 | {
|
---|
139 | TVector2 radec(fRaDec.Phi(), TMath::Pi()/2-fRaDec.Theta());
|
---|
140 | MAstroCatalog::DrawNet(radec, rot, 1);
|
---|
141 |
|
---|
142 | const TVector3 zdaz0 = fRaDec.GetZdAz(*fTime, *fObservatory);
|
---|
143 | TVector2 zdaz(zdaz0.Phi(), zdaz0.Theta());
|
---|
144 | MAstroCatalog::DrawNet(zdaz, rot, 2);
|
---|
145 | }
|
---|
146 |
|
---|
147 | TObject *FindObjectInPad(const char *name, TVirtualPad *pad)
|
---|
148 | {
|
---|
149 | if (!pad)
|
---|
150 | pad = gPad;
|
---|
151 |
|
---|
152 | if (!pad)
|
---|
153 | return NULL;
|
---|
154 |
|
---|
155 | TObject *o;
|
---|
156 |
|
---|
157 | TIter Next(pad->GetListOfPrimitives());
|
---|
158 | while ((o=Next()))
|
---|
159 | {
|
---|
160 | if (o->InheritsFrom(gROOT->GetClass(name)))
|
---|
161 | return o;
|
---|
162 |
|
---|
163 | if (o->InheritsFrom("TPad"))
|
---|
164 | if ((o = FindObjectInPad(name, (TVirtualPad*)o)))
|
---|
165 | return o;
|
---|
166 | }
|
---|
167 | return NULL;
|
---|
168 | }
|
---|
169 |
|
---|
170 | void MAstroCamera::AddPrimitives(Option_t *o)
|
---|
171 | {
|
---|
172 | if (!fTime || !fObservatory || !fMirrors)
|
---|
173 | {
|
---|
174 | cout << "Missing data..." << endl;
|
---|
175 | return;
|
---|
176 | }
|
---|
177 |
|
---|
178 | TString opt(o);
|
---|
179 | if (opt.IsNull())
|
---|
180 | opt = "*.";
|
---|
181 |
|
---|
182 | const Bool_t hashist = opt.Contains("h", TString::kIgnoreCase);
|
---|
183 | const Bool_t hasmean = opt.Contains("*", TString::kIgnoreCase);
|
---|
184 | const Bool_t hasdot = opt.Contains(".", TString::kIgnoreCase);
|
---|
185 | const Bool_t usecam = opt.Contains("c", TString::kIgnoreCase);
|
---|
186 |
|
---|
187 | TString str = fTime->GetSqlDateTime();
|
---|
188 | str += Form(" (\\alpha=%.1fh \\delta=%.1f\\circ)",
|
---|
189 | fRaDec.Phi()*TMath::RadToDeg()*24/360,
|
---|
190 | 90-fRaDec.Theta()*TMath::RadToDeg());
|
---|
191 |
|
---|
192 | // Get camera
|
---|
193 | MHCamera *camera=(MHCamera*)FindObjectInPad("MHCamera", gPad);
|
---|
194 | if (camera)
|
---|
195 | {
|
---|
196 | if (!camera->GetGeometry() || camera->GetGeometry()->IsA()!=fGeom->IsA())
|
---|
197 | camera->SetGeometry(*fGeom);
|
---|
198 | }
|
---|
199 | else
|
---|
200 | {
|
---|
201 | camera = new MHCamera(*fGeom);
|
---|
202 | camera->SetName("MHCamera");
|
---|
203 | camera->SetStats(0);
|
---|
204 | camera->SetInvDeepBlueSeaPalette();
|
---|
205 | camera->SetBit(kCanDelete);
|
---|
206 | camera->Draw();
|
---|
207 | }
|
---|
208 |
|
---|
209 | camera->SetTitle(str);
|
---|
210 |
|
---|
211 | gPad->cd(1);
|
---|
212 |
|
---|
213 | if (!usecam)
|
---|
214 | {
|
---|
215 | if (camera->GetEntries()==0)
|
---|
216 | camera->SetBit(MHCamera::kNoLegend);
|
---|
217 | }
|
---|
218 | else
|
---|
219 | {
|
---|
220 | camera->Reset();
|
---|
221 | camera->SetYTitle("arb.cur");
|
---|
222 | }
|
---|
223 |
|
---|
224 | TH2 *h=0;
|
---|
225 | if (hashist)
|
---|
226 | {
|
---|
227 | TH2F hist("","", 90, -650, 650, 90, -650, 650);
|
---|
228 | hist.SetMinimum(0);
|
---|
229 | h = (TH2*)hist.DrawCopy("samecont1");
|
---|
230 | }
|
---|
231 |
|
---|
232 | const TVector3 zdaz0 = fRaDec.GetZdAz(*fTime, *fObservatory);
|
---|
233 |
|
---|
234 | TRotation rot;
|
---|
235 | rot.RotateZ(-zdaz0.Phi());
|
---|
236 | rot.RotateY(-zdaz0.Theta());
|
---|
237 |
|
---|
238 | DrawNet(rot);
|
---|
239 |
|
---|
240 | MVector3 *radec;
|
---|
241 | TIter Next(&fList);
|
---|
242 |
|
---|
243 | while ((radec=(MVector3*)Next()))
|
---|
244 | {
|
---|
245 | const Double_t mag = radec->Magnitude();
|
---|
246 |
|
---|
247 | TVector3 star = radec->GetZdAz(*fTime, *fObservatory);
|
---|
248 |
|
---|
249 | // Rotate Star into telescope system
|
---|
250 | star *= rot;
|
---|
251 |
|
---|
252 | TVector3 mean;
|
---|
253 |
|
---|
254 | Int_t num = 0;
|
---|
255 |
|
---|
256 | MGeomMirror *mirror = 0;
|
---|
257 | TIter NextM(fMirrors);
|
---|
258 | while ((mirror=(MGeomMirror*)NextM()))
|
---|
259 | {
|
---|
260 | const TVector3 spot = mirror->GetReflection(star, fGeom->GetCameraDist())*1000;
|
---|
261 |
|
---|
262 | // calculate mean of all 'stars' hitting the camera plane
|
---|
263 | // by taking the sum of the intersection points between
|
---|
264 | // the light vector and the camera plane
|
---|
265 | mean += spot;
|
---|
266 |
|
---|
267 | if (hasdot)
|
---|
268 | {
|
---|
269 | TMarker *m=new TMarker(spot(1), spot(0), 1);
|
---|
270 | m->SetBit(kCannotPick);
|
---|
271 | m->SetBit(kCanDelete);
|
---|
272 | m->SetMarkerColor(kMagenta);
|
---|
273 | m->SetMarkerStyle(kDot);
|
---|
274 | fMapG.Add((Long_t)m, 0);
|
---|
275 | }
|
---|
276 | if (h)
|
---|
277 | h->Fill(spot(1), spot(0), pow(10, -mag/2.5));
|
---|
278 |
|
---|
279 | if (usecam)
|
---|
280 | camera->Fill(spot(1), spot(0), pow(10, -mag/2.5));
|
---|
281 |
|
---|
282 | num++;
|
---|
283 | }
|
---|
284 |
|
---|
285 | // transform meters into millimeters (camera display works with mm)
|
---|
286 | mean *= 1./num;
|
---|
287 |
|
---|
288 | DrawStar(mean(1), mean(0), *radec, !hasmean);
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | // ------------------------------------------------------------------------
|
---|
293 | //
|
---|
294 | // Execute a gui event on the camera
|
---|
295 | //
|
---|
296 | void MAstroCamera::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
|
---|
297 | {
|
---|
298 | if (event==kKeyPress && fTime)
|
---|
299 | switch (mp2)
|
---|
300 | {
|
---|
301 | case kKey_Plus:
|
---|
302 | fTime->SetMjd(fTime->GetMjd()+0.25/24);
|
---|
303 | SetBit(kHasChanged);
|
---|
304 | gPad->Modified();
|
---|
305 | gPad->Update();
|
---|
306 | return;
|
---|
307 | case kKey_Minus:
|
---|
308 | fTime->SetMjd(fTime->GetMjd()-0.25/24);
|
---|
309 | SetBit(kHasChanged);
|
---|
310 | gPad->Modified();
|
---|
311 | gPad->Update();
|
---|
312 | return;
|
---|
313 | }
|
---|
314 |
|
---|
315 | MAstroCatalog::ExecuteEvent(event, mp1, mp2);
|
---|
316 | }
|
---|