| 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 |
|
|---|
| 55 | ClassImp(MAstroCamera);
|
|---|
| 56 |
|
|---|
| 57 | using namespace std;
|
|---|
| 58 |
|
|---|
| 59 | MAstroCamera::MAstroCamera() : fGeom(0), fMirrors(0)
|
|---|
| 60 | {
|
|---|
| 61 | fMirror0 = new MGeomMirror;
|
|---|
| 62 | fMirror0->SetMirrorContent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | MAstroCamera::~MAstroCamera()
|
|---|
| 66 | {
|
|---|
| 67 | if (fGeom)
|
|---|
| 68 | delete fGeom;
|
|---|
| 69 | if (fMirrors)
|
|---|
| 70 | delete fMirrors;
|
|---|
| 71 |
|
|---|
| 72 | delete fMirror0;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | void MAstroCamera::SetMirrors(TClonesArray *arr)
|
|---|
| 76 | {
|
|---|
| 77 | if (!arr || arr->GetClass()!=MGeomMirror::Class())
|
|---|
| 78 | return;
|
|---|
| 79 |
|
|---|
| 80 | const Int_t n = arr->GetSize();
|
|---|
| 81 |
|
|---|
| 82 | if (!fMirrors)
|
|---|
| 83 | fMirrors = new TClonesArray(MGeomMirror::Class(), n);
|
|---|
| 84 |
|
|---|
| 85 | fMirrors->ExpandCreate(n);
|
|---|
| 86 |
|
|---|
| 87 | for (int i=0; i<n; i++)
|
|---|
| 88 | memcpy((*fMirrors)[i], (*arr)[i], sizeof(MGeomMirror));
|
|---|
| 89 |
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | void MAstroCamera::SetGeom(const MGeomCam &cam)
|
|---|
| 93 | {
|
|---|
| 94 | if (fGeom)
|
|---|
| 95 | delete fGeom;
|
|---|
| 96 |
|
|---|
| 97 | fGeom = (MGeomCam*)cam.Clone();
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | Int_t MAstroCamera::ConvertToPad(const TVector3 &w, TVector2 &v)
|
|---|
| 101 | {
|
|---|
| 102 | const TVector3 spot = fMirror0->GetReflection(w, fGeom->GetCameraDist())*1000;
|
|---|
| 103 |
|
|---|
| 104 | /*
|
|---|
| 105 | --- Use this to plot the 'mean grid' instead of the grid of a
|
|---|
| 106 | theoretical central mirror ---
|
|---|
| 107 |
|
|---|
| 108 | TVector3 spot;
|
|---|
| 109 | const Int_t num = fConfig->GetNumMirror();
|
|---|
| 110 | for (int i=0; i<num; i++)
|
|---|
| 111 | spot += fConfig->GetMirror(i).GetReflection(w, fGeom->GetCameraDist())*1000;
|
|---|
| 112 | spot *= 1./num;
|
|---|
| 113 | */
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | v.Set(spot(0), spot(1));
|
|---|
| 117 |
|
|---|
| 118 | const Float_t max = fGeom->GetMaxRadius()*0.70;
|
|---|
| 119 | return v.X()>-max && v.Y()>-max && v.X()<max && v.Y()<max;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void MAstroCamera::DrawNet(const TRotation &trans)
|
|---|
| 123 | {
|
|---|
| 124 | const TRotation rot(MAstroSky2Local(*fTime, *fObservatory));
|
|---|
| 125 |
|
|---|
| 126 | TVector2 radec(fRaDec.Phi(), fRaDec.Theta());
|
|---|
| 127 | MAstroCatalog::DrawNet(radec, trans*rot, 2);
|
|---|
| 128 |
|
|---|
| 129 | const TVector3 zdaz0 = MAstroSky2Local(*fTime, *fObservatory)*fRaDec;
|
|---|
| 130 | TVector2 zdaz(zdaz0.Phi(), zdaz0.Theta());
|
|---|
| 131 | MAstroCatalog::DrawNet(zdaz, trans, 1);
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | TObject *FindObjectInPad(const char *name, TVirtualPad *pad)
|
|---|
| 135 | {
|
|---|
| 136 | if (!pad)
|
|---|
| 137 | pad = gPad;
|
|---|
| 138 |
|
|---|
| 139 | if (!pad)
|
|---|
| 140 | return NULL;
|
|---|
| 141 |
|
|---|
| 142 | TObject *o;
|
|---|
| 143 |
|
|---|
| 144 | TIter Next(pad->GetListOfPrimitives());
|
|---|
| 145 | while ((o=Next()))
|
|---|
| 146 | {
|
|---|
| 147 | if (o->InheritsFrom(gROOT->GetClass(name)))
|
|---|
| 148 | return o;
|
|---|
| 149 |
|
|---|
| 150 | if (o->InheritsFrom("TPad"))
|
|---|
| 151 | if ((o = FindObjectInPad(name, (TVirtualPad*)o)))
|
|---|
| 152 | return o;
|
|---|
| 153 | }
|
|---|
| 154 | return NULL;
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | void MAstroCamera::AddPrimitives(Option_t *o)
|
|---|
| 158 | {
|
|---|
| 159 | if (!fTime || !fObservatory || !fMirrors)
|
|---|
| 160 | {
|
|---|
| 161 | cout << "Missing data..." << endl;
|
|---|
| 162 | return;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | TString opt(o);
|
|---|
| 166 | if (opt.IsNull())
|
|---|
| 167 | opt = "*.";
|
|---|
| 168 |
|
|---|
| 169 | const Bool_t hashist = opt.Contains("h", TString::kIgnoreCase);
|
|---|
| 170 | const Bool_t hasmean = opt.Contains("*", TString::kIgnoreCase);
|
|---|
| 171 | const Bool_t hasdot = opt.Contains(".", TString::kIgnoreCase);
|
|---|
| 172 | const Bool_t usecam = opt.Contains("c", TString::kIgnoreCase);
|
|---|
| 173 |
|
|---|
| 174 | MAstroSky2Local rot(*fTime, *fObservatory);
|
|---|
| 175 |
|
|---|
| 176 | const Float_t rho = rot.RotationAngle(fRaDec.Phi(), TMath::Pi()/2-fRaDec.Theta());
|
|---|
| 177 |
|
|---|
| 178 | TString str = fTime->GetSqlDateTime();
|
|---|
| 179 | str += Form(" (\\alpha=%.1fh \\delta=%.1f\\circ) \\rho=%.1f\\circ",
|
|---|
| 180 | fRaDec.Phi()/TMath::Pi()*12, 90-fRaDec.Theta()*TMath::RadToDeg(),
|
|---|
| 181 | rho *TMath::RadToDeg());
|
|---|
| 182 |
|
|---|
| 183 | // Get camera
|
|---|
| 184 | MHCamera *camera=(MHCamera*)FindObjectInPad("MHCamera", gPad);
|
|---|
| 185 | if (camera)
|
|---|
| 186 | {
|
|---|
| 187 | if (!camera->GetGeometry() || camera->GetGeometry()->IsA()!=fGeom->IsA())
|
|---|
| 188 | camera->SetGeometry(*fGeom);
|
|---|
| 189 | }
|
|---|
| 190 | else
|
|---|
| 191 | {
|
|---|
| 192 | camera = new MHCamera(*fGeom);
|
|---|
| 193 | camera->SetName("MHCamera");
|
|---|
| 194 | camera->SetStats(0);
|
|---|
| 195 | camera->SetInvDeepBlueSeaPalette();
|
|---|
| 196 | camera->SetBit(kCanDelete);
|
|---|
| 197 | camera->Draw();
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | camera->SetTitle(str);
|
|---|
| 201 |
|
|---|
| 202 | gPad->cd(1);
|
|---|
| 203 |
|
|---|
| 204 | if (!usecam)
|
|---|
| 205 | {
|
|---|
| 206 | if (camera->GetEntries()==0)
|
|---|
| 207 | camera->SetBit(MHCamera::kNoLegend);
|
|---|
| 208 | }
|
|---|
| 209 | else
|
|---|
| 210 | {
|
|---|
| 211 | camera->Reset();
|
|---|
| 212 | camera->SetYTitle("arb.cur");
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | TH2 *h=0;
|
|---|
| 216 | if (hashist)
|
|---|
| 217 | {
|
|---|
| 218 | TH2F hist("","", 90, -650, 650, 90, -650, 650);
|
|---|
| 219 | hist.SetMinimum(0);
|
|---|
| 220 | h = (TH2*)hist.DrawCopy("samecont1");
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | TVector3 zdaz0 = fRaDec;
|
|---|
| 224 | zdaz0 *= rot;
|
|---|
| 225 |
|
|---|
| 226 | cout << zdaz0.Phi()*TMath::RadToDeg() << " " << zdaz0.Theta()*TMath::RadToDeg() << endl;
|
|---|
| 227 |
|
|---|
| 228 | TVector3 test = zdaz0;
|
|---|
| 229 | test *= rot.Inverse();
|
|---|
| 230 |
|
|---|
| 231 | cout << test.Phi()*TMath::RadToDeg()/15 << " " << test.Theta()*TMath::RadToDeg() << endl;
|
|---|
| 232 |
|
|---|
| 233 | TRotation rot2;
|
|---|
| 234 | rot2.RotateZ(-zdaz0.Phi());
|
|---|
| 235 | rot2.RotateY(-zdaz0.Theta());
|
|---|
| 236 | rot2.RotateZ(-TMath::Pi()/2); // align coordinate system
|
|---|
| 237 |
|
|---|
| 238 | DrawNet(rot2);
|
|---|
| 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);
|
|---|
| 248 |
|
|---|
| 249 | // Calculate local coordinates
|
|---|
| 250 | star *= rot;
|
|---|
| 251 | // Rotate Star into telescope system
|
|---|
| 252 | star *= rot2;
|
|---|
| 253 |
|
|---|
| 254 | TVector3 mean;
|
|---|
| 255 |
|
|---|
| 256 | Int_t num = 0;
|
|---|
| 257 |
|
|---|
| 258 | MGeomMirror *mirror = 0;
|
|---|
| 259 | TIter NextM(fMirrors);
|
|---|
| 260 | while ((mirror=(MGeomMirror*)NextM()))
|
|---|
| 261 | {
|
|---|
| 262 | const TVector3 spot = mirror->GetReflection(star, fGeom->GetCameraDist())*1000;
|
|---|
| 263 |
|
|---|
| 264 | // calculate mean of all 'stars' hitting the camera plane
|
|---|
| 265 | // by taking the sum of the intersection points between
|
|---|
| 266 | // the light vector and the camera plane
|
|---|
| 267 | mean += spot;
|
|---|
| 268 |
|
|---|
| 269 | if (hasdot)
|
|---|
| 270 | {
|
|---|
| 271 | TMarker *m=new TMarker(spot(0), spot(1), 1);
|
|---|
| 272 | m->SetBit(kCannotPick);
|
|---|
| 273 | m->SetBit(kCanDelete);
|
|---|
| 274 | m->SetMarkerColor(kMagenta);
|
|---|
| 275 | m->SetMarkerStyle(kDot);
|
|---|
| 276 | AddMap(m);
|
|---|
| 277 | }
|
|---|
| 278 | if (h)
|
|---|
| 279 | h->Fill(spot(0), spot(1), pow(10, -mag/2.5));
|
|---|
| 280 |
|
|---|
| 281 | if (usecam)
|
|---|
| 282 | camera->Fill(spot(0), spot(1), pow(10, -mag/2.5));
|
|---|
| 283 |
|
|---|
| 284 | num++;
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | // transform meters into millimeters (camera display works with mm)
|
|---|
| 288 | mean *= 1./num;
|
|---|
| 289 |
|
|---|
| 290 | DrawStar(mean(0), mean(1), *radec, !hasmean, Form("x=%.1fmm y=%.1fmm", mean(0), mean(1)));
|
|---|
| 291 | }
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | // ------------------------------------------------------------------------
|
|---|
| 295 | //
|
|---|
| 296 | // Execute a gui event on the camera
|
|---|
| 297 | //
|
|---|
| 298 | void MAstroCamera::ExecuteEvent(Int_t event, Int_t mp1, Int_t mp2)
|
|---|
| 299 | {
|
|---|
| 300 | if (event==kKeyPress && fTime)
|
|---|
| 301 | switch (mp2)
|
|---|
| 302 | {
|
|---|
| 303 | case kKey_Plus:
|
|---|
| 304 | fTime->SetMjd(fTime->GetMjd()+0.25/24);
|
|---|
| 305 | SetBit(kHasChanged);
|
|---|
| 306 | gPad->Modified();
|
|---|
| 307 | gPad->Update();
|
|---|
| 308 | return;
|
|---|
| 309 |
|
|---|
| 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 | }
|
|---|