source: trunk/Mars/msimreflector/MMirrorSquare.cc@ 20003

Last change on this file since 20003 was 9948, checked in by tbretz, 14 years ago
Implemented missing WriteM into MMirrorSquare
File size: 5.2 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// MMirror
28//
29// A square type spherical mirror
30//
31//////////////////////////////////////////////////////////////////////////////
32#include "MMirrorSquare.h"
33
34#include <stdlib.h> // atof (Ubuntu 8.10)
35
36#include <TMath.h>
37#include <TObjArray.h>
38
39#include <TBox.h>
40#include <TEllipse.h>
41#include <TVirtualPad.h>
42
43#include "MLog.h"
44
45#include "MQuaternion.h"
46
47ClassImp(MMirrorSquare);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Return the max radius, i.e. the distance of the edges to zje center
54//
55Double_t MMirrorSquare::GetMaxR() const
56{
57 return TMath::Sqrt(2.)*fSideLength;
58}
59
60// --------------------------------------------------------------------------
61//
62// Return the aread of the square: l^2
63//
64Double_t MMirrorSquare::GetA() const
65{
66 return fSideLength*fSideLength*4;
67}
68
69// ------------------------------------------------------------------------
70//
71// This is a very rough estimate of whether a photon at a position p
72// can hit a mirror. The position might be off in z and the photon
73// still has to follow its trajectory. Nevertheless we can fairly assume
74// the the way to travel in x/y is pretty small so we can give a rather
75// good estimate of whether the photon can hit.
76//
77// never throw away a photon whihc can hit the mirror!
78//
79Bool_t MMirrorSquare::CanHit(const MQuaternion &p) const
80{
81 // p is given in the reflectors coordinate frame. This is meant
82 // to be a fast check to sort out all mirrors which we can omit
83 // without time consuming calculations.
84
85 // Check if this mirror can be hit at all
86 const Double_t dx = TMath::Abs(p.X()-X());
87 if (dx>fSideLength*1.05)
88 return kFALSE;
89
90 const Double_t dy = TMath::Abs(p.Y()-Y());
91 if (dy>fSideLength*1.05)
92 return kFALSE;
93
94 return kTRUE;
95}
96
97// ------------------------------------------------------------------------
98//
99// Check if the given position coincides with the mirror. The position
100// is assumed to be the incident point on the mirror's surface.
101//
102// The coordinates are in the mirrors coordinate frame.
103//
104// The action should coincide with what is painted in Paint()
105//
106Bool_t MMirrorSquare::HasHit(const MQuaternion &p) const
107{
108 // p is the incident point in the mirror in the mirror's
109 // coordinate frame
110
111 // Black spot in the mirror center (here we can fairly ignore
112 // the distance from the plane to the mirror surface, as long
113 // as the black spot does not become too large)
114 if (p.R2()<0.5*0.5)
115 return kFALSE;
116
117 // Check if the photon has really hit the square mirror
118 if (TMath::Max(fabs(p.X()), fabs(p.Y()))>fSideLength)
119 return kFALSE;
120
121 return kTRUE;
122}
123
124// ------------------------------------------------------------------------
125//
126// Paint the mirror in x/y.
127//
128// The graphic should coincide with the action in HasHit
129//
130void MMirrorSquare::Paint(Option_t *opt)
131{
132 TBox b;
133 TEllipse e;
134 b.SetFillColor(18);
135
136 if (!TString(opt).Contains("line", TString::kIgnoreCase))
137 {
138 b.SetFillColor(17);
139 b.SetLineStyle(0);
140 e.SetLineStyle(0);
141 e.SetFillColor(gPad->GetFillColor());
142 }
143
144 if (TString(opt).Contains("same", TString::kIgnoreCase))
145 {
146 b.SetFillStyle(0);
147 e.SetFillStyle(0);
148 }
149
150 b.PaintBox(X()-fSideLength, Y()-fSideLength, X()+fSideLength, Y()+fSideLength);
151
152 if (!TString(opt).Contains("border", TString::kIgnoreCase))
153 e.PaintEllipse(X(), Y(), 0.5, 0.5, 0, 360, 0);
154}
155
156// ------------------------------------------------------------------------
157//
158// Print the contents of the mirror
159//
160void MMirrorSquare::Print(Option_t *o) const
161{
162 MMirror::Print(o);
163 gLog << " " << fSideLength << endl;
164}
165
166// ------------------------------------------------------------------------
167//
168// Read the mirror's setup from a file. The first eight tokens should be
169// ignored. (This could be fixed!)
170//
171// Here we read: L
172//
173Int_t MMirrorSquare::ReadM(const TObjArray &tok)
174{
175 if (tok.GetEntries()!=1)
176 return -1;
177
178 Double_t l = atof(tok[0]->GetName());
179
180 if (l<=0)
181 return -1;
182
183 fSideLength = l/2;
184
185 return 1;
186}
187
188// ------------------------------------------------------------------------
189//
190void MMirrorSquare::WriteM(ostream &out) const
191{
192 out << fSideLength*2;
193}
Note: See TracBrowser for help on using the repository browser.