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

Last change on this file since 3611 was 3568, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 7.2 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 "MAstroSky2Local.h"
52#include "../mhist/MHCamera.h"
53#include "MObservatory.h"
54
55ClassImp(MAstroCamera);
56
57using namespace std;
58
59// --------------------------------------------------------------------------
60MAstroCamera::MAstroCamera() : fGeom(0), fMirrors(0)
61{
62 fMirror0 = new MGeomMirror;
63 fMirror0->SetMirrorContent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
64}
65
66// --------------------------------------------------------------------------
67MAstroCamera::~MAstroCamera()
68{
69 if (fGeom)
70 delete fGeom;
71 if (fMirrors)
72 delete fMirrors;
73
74 delete fMirror0;
75}
76
77// --------------------------------------------------------------------------
78void MAstroCamera::SetMirrors(TClonesArray &arr)
79{
80 if (arr.GetClass()!=MGeomMirror::Class())
81 return;
82
83 const Int_t n = arr.GetSize();
84
85 if (!fMirrors)
86 fMirrors = new TClonesArray(MGeomMirror::Class(), n);
87
88 fMirrors->ExpandCreate(n);
89
90 for (int i=0; i<n; i++)
91 memcpy((*fMirrors)[i], arr[i], sizeof(MGeomMirror));
92
93}
94
95// --------------------------------------------------------------------------
96void MAstroCamera::SetGeom(const MGeomCam &cam)
97{
98 if (fGeom)
99 delete fGeom;
100
101 fGeom = (MGeomCam*)cam.Clone();
102}
103
104// --------------------------------------------------------------------------
105Int_t MAstroCamera::ConvertToPad(const TVector3 &w, TVector2 &v) const
106{
107 /*
108 --- Use this to plot the 'mean grid' instead of the grid of a
109 theoretical central mirror ---
110
111 TVector3 spot;
112 const Int_t num = fConfig->GetNumMirror();
113 for (int i=0; i<num; i++)
114 spot += fConfig->GetMirror(i).GetReflection(w, fGeom->GetCameraDist())*1000;
115 spot *= 1./num;
116 */
117
118 const TVector3 spot = fMirror0->GetReflection(w, fGeom->GetCameraDist())*1000;
119 v.Set(spot(0), spot(1));
120
121 const Float_t max = fGeom->GetMaxRadius()*0.70;
122 return v.X()>-max && v.Y()>-max && v.X()<max && v.Y()<max;
123}
124
125// --------------------------------------------------------------------------
126TObject *FindObjectInPad(const char *name, TVirtualPad *pad)
127{
128 if (!pad)
129 pad = gPad;
130
131 if (!pad)
132 return NULL;
133
134 TObject *o;
135
136 TIter Next(pad->GetListOfPrimitives());
137 while ((o=Next()))
138 {
139 if (o->InheritsFrom(gROOT->GetClass(name)))
140 return o;
141
142 if (o->InheritsFrom("TPad"))
143 if ((o = FindObjectInPad(name, (TVirtualPad*)o)))
144 return o;
145 }
146 return NULL;
147}
148
149// --------------------------------------------------------------------------
150void MAstroCamera::AddPrimitives(Option_t *o)
151{
152 if (!fTime || !fObservatory || !fMirrors)
153 {
154 cout << "Missing data..." << endl;
155 return;
156 }
157
158 TString opt(o);
159 if (opt.IsNull())
160 opt = "*.";
161
162 const Bool_t hashist = opt.Contains("h", TString::kIgnoreCase);
163 const Bool_t hasmean = opt.Contains("*", TString::kIgnoreCase);
164 const Bool_t hasdot = opt.Contains(".", TString::kIgnoreCase);
165 const Bool_t usecam = opt.Contains("c", TString::kIgnoreCase);
166
167 // Get camera
168 MHCamera *camera=(MHCamera*)FindObjectInPad("MHCamera", gPad);
169 if (camera)
170 {
171 if (!camera->GetGeometry() || camera->GetGeometry()->IsA()!=fGeom->IsA())
172 camera->SetGeometry(*fGeom);
173 }
174 else
175 {
176 camera = new MHCamera(*fGeom);
177 camera->SetName("MHCamera");
178 camera->SetStats(0);
179 camera->SetInvDeepBlueSeaPalette();
180 camera->SetBit(kCanDelete);
181 camera->Draw();
182 }
183
184 camera->SetTitle(GetPadTitle());
185
186 gPad->cd(1);
187
188 if (!usecam)
189 {
190 if (camera->GetEntries()==0)
191 camera->SetBit(MHCamera::kNoLegend);
192 }
193 else
194 {
195 camera->Reset();
196 camera->SetYTitle("arb.cur");
197 }
198
199 TH2 *h=0;
200 if (hashist)
201 {
202 TH2F hist("","", 90, -650, 650, 90, -650, 650);
203 hist.SetMinimum(0);
204 h = (TH2*)hist.DrawCopy("samecont1");
205 }
206
207 const TRotation rot(GetGrid(kTRUE));
208
209 MVector3 *radec;
210 TIter Next(&fList);
211
212 while ((radec=(MVector3*)Next()))
213 {
214 const Double_t mag = radec->Magnitude();
215
216 TVector3 star(*radec);
217
218 // Rotate Star into telescope system
219 star *= rot;
220
221 TVector3 mean;
222
223 Int_t num = 0;
224
225 MGeomMirror *mirror = 0;
226 TIter NextM(fMirrors);
227 while ((mirror=(MGeomMirror*)NextM()))
228 {
229 const TVector3 spot = mirror->GetReflection(star, fGeom->GetCameraDist())*1000;
230
231 // calculate mean of all 'stars' hitting the camera plane
232 // by taking the sum of the intersection points between
233 // the light vector and the camera plane
234 mean += spot;
235
236 if (hasdot)
237 {
238 TMarker *m=new TMarker(spot(0), spot(1), 1);
239 m->SetMarkerColor(kMagenta);
240 m->SetMarkerStyle(kDot);
241 AddMap(m);
242 }
243 if (h)
244 h->Fill(spot(0), spot(1), pow(10, -mag/2.5));
245
246 if (usecam)
247 camera->Fill(spot(0), spot(1), pow(10, -mag/2.5));
248
249 num++;
250 }
251
252 // transform meters into millimeters (camera display works with mm)
253 mean *= 1./num;
254
255 DrawStar(mean(0), mean(1), *radec, !hasmean, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)));
256 }
257}
258
259// ------------------------------------------------------------------------
260//
261// Execute a gui event on the camera
262//
263void MAstroCamera::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
264{
265 if (event==kKeyPress && fTime)
266 switch (mp2)
267 {
268 case kKey_Plus:
269 fTime->SetMjd(fTime->GetMjd()+0.25/24);
270 Update(kTRUE);
271 return;
272
273 case kKey_Minus:
274 fTime->SetMjd(fTime->GetMjd()-0.25/24);
275 Update(kTRUE);
276 return;
277 }
278
279 MAstroCatalog::ExecuteEvent(event, mp1, mp2);
280}
Note: See TracBrowser for help on using the repository browser.