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

Last change on this file since 3500 was 3500, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.9 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 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 rot.RotateZ(-TMath::Pi()/2); // align coordinate system
238
239 DrawNet(rot);
240
241 MVector3 *radec;
242 TIter Next(&fList);
243
244 while ((radec=(MVector3*)Next()))
245 {
246 const Double_t mag = radec->Magnitude();
247
248 TVector3 star = radec->GetZdAz(*fTime, *fObservatory);
249
250 // Rotate Star into telescope system
251 star *= rot;
252
253 TVector3 mean;
254
255 Int_t num = 0;
256
257 MGeomMirror *mirror = 0;
258 TIter NextM(fMirrors);
259 while ((mirror=(MGeomMirror*)NextM()))
260 {
261 const TVector3 spot = mirror->GetReflection(star, fGeom->GetCameraDist())*1000;
262
263 // calculate mean of all 'stars' hitting the camera plane
264 // by taking the sum of the intersection points between
265 // the light vector and the camera plane
266 mean += spot;
267
268 if (hasdot)
269 {
270 TMarker *m=new TMarker(spot(0), spot(1), 1);
271 m->SetBit(kCannotPick);
272 m->SetBit(kCanDelete);
273 m->SetMarkerColor(kMagenta);
274 m->SetMarkerStyle(kDot);
275 fMapG.Add((Long_t)m, 0);
276 }
277 if (h)
278 h->Fill(spot(0), spot(1), pow(10, -mag/2.5));
279
280 if (usecam)
281 camera->Fill(spot(0), spot(1), pow(10, -mag/2.5));
282
283 num++;
284 }
285
286 // transform meters into millimeters (camera display works with mm)
287 mean *= 1./num;
288
289 DrawStar(mean(0), mean(1), *radec, !hasmean, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)));
290 }
291}
292
293// ------------------------------------------------------------------------
294//
295// Execute a gui event on the camera
296//
297void MAstroCamera::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
298{
299 if (event==kKeyPress && fTime)
300 switch (mp2)
301 {
302 case kKey_Plus:
303 fTime->SetMjd(fTime->GetMjd()+0.25/24);
304 SetBit(kHasChanged);
305 gPad->Modified();
306 gPad->Update();
307 return;
308 case kKey_Minus:
309 fTime->SetMjd(fTime->GetMjd()-0.25/24);
310 SetBit(kHasChanged);
311 gPad->Modified();
312 gPad->Update();
313 return;
314 }
315
316 MAstroCatalog::ExecuteEvent(event, mp1, mp2);
317}
Note: See TracBrowser for help on using the repository browser.