source: trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.cc@ 9291

Last change on this file since 9291 was 9252, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.4 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 "MQuaternion.h"
44
45ClassImp(MMirrorSquare);
46
47using namespace std;
48
49Double_t MMirrorSquare::GetMaxR() const
50{
51 return TMath::Sqrt(2.)*fSideLength;
52}
53
54// ------------------------------------------------------------------------
55//
56// This is a very rough estimate of whether a photon at a position p
57// can hit a mirror. The position might be off in z and the photon
58// still has to follow its trajectory. Nevertheless we can fairly assume
59// the the way to travel in x/y is pretty small so we can give a rather
60// good estimate of whether the photon can hit.
61//
62// never throw away a photon whihc can hit the mirror!
63//
64Bool_t MMirrorSquare::CanHit(const MQuaternion &p) const
65{
66 // p is given in the reflectors coordinate frame. This is meant
67 // to be a fast check to sort out all mirrors which we can omit
68 // without time consuming calculations.
69
70 // Check if this mirror can be hit at all
71 const Double_t dx = TMath::Abs(p.X()-X());
72 if (dx>fSideLength*1.05)
73 return kFALSE;
74
75 const Double_t dy = TMath::Abs(p.Y()-Y());
76 if (dy>fSideLength*1.05)
77 return kFALSE;
78
79 return kTRUE;
80}
81
82// ------------------------------------------------------------------------
83//
84// Check if the given position coincides with the mirror. The position
85// is assumed to be the incident point on the mirror's surface.
86//
87// The coordinates are in the mirrors coordinate frame.
88//
89// The action should coincide with what is painted in Paint()
90//
91Bool_t MMirrorSquare::HasHit(const MQuaternion &p) const
92{
93 // p is the incident point in the mirror in the mirror's
94 // coordinate frame
95
96 // Black spot in the mirror center (here we can fairly ignore
97 // the distance from the plane to the mirror surface, as long
98 // as the black spot does not become too large)
99 if (p.R2()<0.5*0.5)
100 return kFALSE;
101
102 // Check if the photon has really hit the square mirror
103 if (TMath::Max(fabs(p.X()), fabs(p.Y()))>fSideLength)
104 return kFALSE;
105
106 return kTRUE;
107}
108
109// ------------------------------------------------------------------------
110//
111// Paint the mirror in x/y.
112//
113// The graphic should coincide with the action in HasHit
114//
115void MMirrorSquare::Paint(Option_t *opt)
116{
117 TBox b;
118 TEllipse e;
119
120 if (!TString(opt).Contains("line", TString::kIgnoreCase))
121 {
122 b.SetFillColor(17);
123 b.SetLineStyle(0);
124 e.SetLineStyle(0);
125 e.SetFillColor(gPad->GetFillColor());
126 }
127 else
128 {
129 b.SetFillStyle(0);
130 e.SetFillStyle(0);
131 }
132
133 b.PaintBox(X()-fSideLength, Y()-fSideLength, X()+fSideLength, Y()+fSideLength);
134
135 if (!TString(opt).Contains("border", TString::kIgnoreCase))
136 e.PaintEllipse(X(), Y(), 0.5, 0.5, 0, 360, 0);
137}
138
139// ------------------------------------------------------------------------
140//
141// Read the mirror's setup from a file. The first eight tokens should be
142// ignored. (This could be fixed!)
143//
144// Here we read: L
145//
146Int_t MMirrorSquare::ReadM(const TObjArray &tok)
147{
148 if (tok.GetSize()<9)
149 return -1;
150
151 Double_t l = atof(tok[8]->GetName());
152
153 if (l<=0)
154 return -1;
155
156 fSideLength = l/2;
157
158 return 1;
159}
Note: See TracBrowser for help on using the repository browser.