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

Last change on this file since 3666 was 3666, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.3 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// --------------------------------------------------------------------------
150//
151// Options:
152//
153// '*' Draw the mean of the reflections on all mirrors
154// '.' Draw a dot for the reflection on each mirror
155//
156void MAstroCamera::AddPrimitives(TString o)
157{
158 if (!fTime || !fObservatory || !fMirrors)
159 {
160 cout << "Missing data..." << endl;
161 return;
162 }
163
164 if (o.IsNull())
165 o = "*.";
166
167 const Bool_t hashist = o.Contains("h", TString::kIgnoreCase);
168 const Bool_t hasmean = o.Contains("*", TString::kIgnoreCase);
169 const Bool_t hasdot = o.Contains(".", TString::kIgnoreCase);
170 const Bool_t usecam = o.Contains("c", TString::kIgnoreCase);
171
172 // Get camera
173 MHCamera *camera=(MHCamera*)FindObjectInPad("MHCamera", gPad);
174 if (camera)
175 {
176 if (!camera->GetGeometry() || camera->GetGeometry()->IsA()!=fGeom->IsA())
177 camera->SetGeometry(*fGeom);
178 }
179 else
180 {
181 camera = new MHCamera(*fGeom);
182 camera->SetName("MHCamera");
183 camera->SetStats(0);
184 camera->SetInvDeepBlueSeaPalette();
185 camera->SetBit(kCanDelete);
186 camera->Draw();
187 }
188
189 camera->SetTitle(GetPadTitle());
190
191 gPad->cd(1);
192
193 if (!usecam)
194 {
195 if (camera->GetEntries()==0)
196 camera->SetBit(MHCamera::kNoLegend);
197 }
198 else
199 {
200 camera->Reset();
201 camera->SetYTitle("arb.cur");
202 }
203
204 TH2 *h=0;
205 if (hashist)
206 {
207 TH2F hist("","", 90, -650, 650, 90, -650, 650);
208 hist.SetMinimum(0);
209 h = (TH2*)hist.DrawCopy("samecont1");
210 }
211
212 const TRotation rot(GetGrid(kTRUE));
213
214 MVector3 *radec;
215 TIter Next(&fList);
216
217 while ((radec=(MVector3*)Next()))
218 {
219 const Double_t mag = radec->Magnitude();
220
221 TVector3 star(*radec);
222
223 // Rotate Star into telescope system
224 star *= rot;
225
226 TVector3 mean;
227
228 Int_t num = 0;
229
230 MGeomMirror *mirror = 0;
231 TIter NextM(fMirrors);
232 while ((mirror=(MGeomMirror*)NextM()))
233 {
234 const TVector3 spot = mirror->GetReflection(star, fGeom->GetCameraDist())*1000;
235
236 // calculate mean of all 'stars' hitting the camera plane
237 // by taking the sum of the intersection points between
238 // the light vector and the camera plane
239 mean += spot;
240
241 if (hasdot)
242 {
243 TMarker *m=new TMarker(spot(0), spot(1), 1);
244 m->SetMarkerColor(kMagenta);
245 m->SetMarkerStyle(kDot);
246 AddMap(m);
247 }
248 if (h)
249 h->Fill(spot(0), spot(1), pow(10, -mag/2.5));
250
251 if (usecam)
252 camera->Fill(spot(0), spot(1), pow(10, -mag/2.5));
253
254 num++;
255 }
256
257 // transform meters into millimeters (camera display works with mm)
258 mean *= 1./num;
259
260 DrawStar(mean(0), mean(1), *radec, !hasmean, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)));
261 }
262}
263
264// ------------------------------------------------------------------------
265//
266// Execute a gui event on the camera
267//
268void MAstroCamera::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
269{
270 if (event==kKeyPress && fTime)
271 switch (mp2)
272 {
273 case kKey_Plus:
274 fTime->SetMjd(fTime->GetMjd()+0.25/24);
275 Update(kTRUE);
276 return;
277
278 case kKey_Minus:
279 fTime->SetMjd(fTime->GetMjd()-0.25/24);
280 Update(kTRUE);
281 return;
282 }
283
284 MAstroCatalog::ExecuteEvent(event, mp1, mp2);
285}
Note: See TracBrowser for help on using the repository browser.