source: trunk/MagicSoft/Mars/mastro/MAstroCamera.cc@ 3518

Last change on this file since 3518 was 3518, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 8.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, 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
54ClassImp(MAstroCamera);
55
56using namespace std;
57
58MAstroCamera::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
64MAstroCamera::~MAstroCamera()
65{
66 if (fGeom)
67 delete fGeom;
68 if (fMirrors)
69 delete fMirrors;
70
71 delete fMirror0;
72}
73
74void 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
91void MAstroCamera::SetGeom(const MGeomCam &cam)
92{
93 if (fGeom)
94 delete fGeom;
95
96 fGeom = (MGeomCam*)cam.Clone();
97}
98
99Int_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(0), spot(1));
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
137void 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
147TObject *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
170void 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 const Float_t rho = fObservatory->RotationAngle(fRaDec.Phi(), TMath::Pi()/2-fRaDec.Theta(), *fTime);
188
189 TString str = fTime->GetSqlDateTime();
190 str += Form(" (\\alpha=%.1fh \\delta=%.1f\\circ) \\rho=%.1f\\circ",
191 fRaDec.Phi()/TMath::Pi()*12, 90-fRaDec.Theta()*TMath::RadToDeg(),
192 rho *TMath::RadToDeg());
193
194 // Get camera
195 MHCamera *camera=(MHCamera*)FindObjectInPad("MHCamera", gPad);
196 if (camera)
197 {
198 if (!camera->GetGeometry() || camera->GetGeometry()->IsA()!=fGeom->IsA())
199 camera->SetGeometry(*fGeom);
200 }
201 else
202 {
203 camera = new MHCamera(*fGeom);
204 camera->SetName("MHCamera");
205 camera->SetStats(0);
206 camera->SetInvDeepBlueSeaPalette();
207 camera->SetBit(kCanDelete);
208 camera->Draw();
209 }
210
211 camera->SetTitle(str);
212
213 gPad->cd(1);
214
215 if (!usecam)
216 {
217 if (camera->GetEntries()==0)
218 camera->SetBit(MHCamera::kNoLegend);
219 }
220 else
221 {
222 camera->Reset();
223 camera->SetYTitle("arb.cur");
224 }
225
226 TH2 *h=0;
227 if (hashist)
228 {
229 TH2F hist("","", 90, -650, 650, 90, -650, 650);
230 hist.SetMinimum(0);
231 h = (TH2*)hist.DrawCopy("samecont1");
232 }
233
234 const TVector3 zdaz0 = fRaDec.GetZdAz(*fTime, *fObservatory);
235
236 TRotation rot;
237 rot.RotateZ(-zdaz0.Phi());
238 rot.RotateY(-zdaz0.Theta());
239 rot.RotateZ(-TMath::Pi()/2); // align coordinate system
240
241 DrawNet(rot);
242
243 MVector3 *radec;
244 TIter Next(&fList);
245
246 while ((radec=(MVector3*)Next()))
247 {
248 const Double_t mag = radec->Magnitude();
249
250 TVector3 star = radec->GetZdAz(*fTime, *fObservatory);
251
252 // Rotate Star into telescope system
253 star *= rot;
254
255 TVector3 mean;
256
257 Int_t num = 0;
258
259 MGeomMirror *mirror = 0;
260 TIter NextM(fMirrors);
261 while ((mirror=(MGeomMirror*)NextM()))
262 {
263 const TVector3 spot = mirror->GetReflection(star, fGeom->GetCameraDist())*1000;
264
265 // calculate mean of all 'stars' hitting the camera plane
266 // by taking the sum of the intersection points between
267 // the light vector and the camera plane
268 mean += spot;
269
270 if (hasdot)
271 {
272 TMarker *m=new TMarker(spot(0), spot(1), 1);
273 m->SetBit(kCannotPick);
274 m->SetBit(kCanDelete);
275 m->SetMarkerColor(kMagenta);
276 m->SetMarkerStyle(kDot);
277 fMapG.Add((Long_t)m, 0);
278 }
279 if (h)
280 h->Fill(spot(0), spot(1), pow(10, -mag/2.5));
281
282 if (usecam)
283 camera->Fill(spot(0), spot(1), pow(10, -mag/2.5));
284
285 num++;
286 }
287
288 // transform meters into millimeters (camera display works with mm)
289 mean *= 1./num;
290
291 DrawStar(mean(0), mean(1), *radec, !hasmean, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)));
292 }
293}
294
295// ------------------------------------------------------------------------
296//
297// Execute a gui event on the camera
298//
299void MAstroCamera::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
300{
301 if (event==kKeyPress && fTime)
302 switch (mp2)
303 {
304 case kKey_Plus:
305 fTime->SetMjd(fTime->GetMjd()+0.25/24);
306 SetBit(kHasChanged);
307 gPad->Modified();
308 gPad->Update();
309 return;
310 case kKey_Minus:
311 fTime->SetMjd(fTime->GetMjd()-0.25/24);
312 SetBit(kHasChanged);
313 gPad->Modified();
314 gPad->Update();
315 return;
316 }
317
318 MAstroCatalog::ExecuteEvent(event, mp1, mp2);
319}
Note: See TracBrowser for help on using the repository browser.