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

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