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

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