source: trunk/MagicSoft/Mars/msimreflector/MMirrorHex.cc@ 9285

Last change on this file since 9285 was 9252, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.7 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of CheObs, the Modular 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 appears 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, 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: CheObs Software Development, 2000-2009
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MMirrorHex
28//
29// A hexagonal spherical mirror
30//
31//////////////////////////////////////////////////////////////////////////////
32#include "MMirrorHex.h"
33
34#include <stdlib.h> // atof (Ubuntu 8.10)
35
36#include <TMath.h>
37#include <TObjArray.h>
38
39#include <TEllipse.h>
40#include <TVirtualPad.h>
41
42#include "MHexagon.h"
43#include "MQuaternion.h"
44
45ClassImp(MMirrorHex);
46
47using namespace std;
48
49const Double_t MMirrorHex::fgCos30 = TMath::Cos(30*TMath::DegToRad());
50const Double_t MMirrorHex::fgCos60 = TMath::Cos(60*TMath::DegToRad());
51const Double_t MMirrorHex::fgSin60 = TMath::Sin(60*TMath::DegToRad());
52
53// ------------------------------------------------------------------------
54//
55// This is a very rough estimate of whether a photon at a position p
56// can hit a mirror. The position might be off in z and the photon
57// still has to follow its trajectory. Nevertheless we can fairly assume
58// the the way to travel in x/y is pretty small so we can give a rather
59// good estimate of whether the photon can hit.
60//
61// never throw away a photon whihc can hit the mirror!
62//
63Bool_t MMirrorHex::CanHit(const MQuaternion &p) const
64{
65 // p is given in the reflectors coordinate frame. This is meant
66 // to be a fast check to sort out all mirrors which we can omit
67 // without time consuming calculations.
68
69 return TMath::Hypot(p.X()-X(), p.Y()-X())<1.05*fMaxR;
70}
71
72// ------------------------------------------------------------------------
73//
74// Check if the given position coincides with the mirror. The position
75// is assumed to be the incident point on the mirror's surface.
76//
77// The coordinates are in the mirrors coordinate frame.
78//
79// The action should coincide with what is painted in Paint()
80//
81Bool_t MMirrorHex::HasHit(const MQuaternion &p) const
82{
83 // p is the incident point in the mirror in the mirror's
84 // coordinate frame
85
86 // Black spot in the mirror center (here we can fairly ignore
87 // the distance from the plane to the mirror surface, as long
88 // as the black spot does not become too large)
89 if (p.R2()<0.5*0.5)
90 return kFALSE;
91
92 //
93 // Now check if point is outside of hexagon; just check x coordinate
94 // in three coordinate systems: the default one, in which two sides of
95 // the hexagon are paralel to the y axis (see camera displays) and two
96 // more, rotated with respect to that one by +- 60 degrees.
97 //
98 if (TMath::Abs(X())>fD/*/2*/)
99 return kFALSE;
100
101 const Double_t dxc = p.X()*fgCos60;
102 const Double_t dys = p.Y()*fgSin60;
103
104 if (TMath::Abs(dxc+dys)>fD/*/2*/)
105 return kFALSE;
106
107 if (TMath::Abs(dxc-dys)>fD/*/2*/)
108 return kFALSE;
109
110 return kTRUE;
111}
112
113// ------------------------------------------------------------------------
114//
115// Paint the mirror in x/y.
116//
117// The graphic should coincide with the action in HasHit
118//
119void MMirrorHex::Paint(Option_t *opt)
120{
121 MHexagon h;
122 TEllipse e;
123 if (!TString(opt).Contains("line", TString::kIgnoreCase))
124 {
125 h.SetLineStyle(0);
126 h.SetFillColor(17);
127 e.SetLineStyle(0);
128 e.SetFillColor(gPad->GetFillColor());
129 }
130 else
131 {
132 h.SetFillStyle(0);
133 e.SetFillStyle(0);
134 }
135
136 h.PaintHexagon(X(), Y(), fD*2);
137
138 if (!TString(opt).Contains("border", TString::kIgnoreCase))
139 e.PaintEllipse(X(), Y(), 0.5, 0.5, 0, 360, 0);
140}
141
142// ------------------------------------------------------------------------
143//
144// Read the mirror's setup from a file. The first eight tokens should be
145// ignored. (This could be fixed!)
146//
147// Here we read: D
148//
149Int_t MMirrorHex::ReadM(const TObjArray &tok)
150{
151 if (tok.GetSize()<9)
152 return -1;
153
154 const Double_t d = atof(tok[8]->GetName());
155
156 if (d<=0)
157 return -1;
158
159 SetD(d);
160
161 return 1;
162}
Note: See TracBrowser for help on using the repository browser.