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

Last change on this file since 9239 was 9236, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.2 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC 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 appear 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 11/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: 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 <TBox.h>
35#include <TEllipse.h>
36#include <TVirtualPad.h>
37
38#include "MQuaternion.h"
39
40ClassImp(MMirrorSquare);
41
42using namespace std;
43
44// ------------------------------------------------------------------------
45//
46// This is a very rough estimate of whether a photon at a position p
47// can hit a mirror. The position might be off in z and the photon
48// still has to follow its trajectory. Nevertheless we can fairly assume
49// the the way to travel in x/y is pretty small so we can give a rather
50// good estimate of whether the photon can hit.
51//
52// never throw away a photon whihc can hit the mirror!
53//
54Bool_t MMirrorSquare::CanHit(const MQuaternion &p) const
55{
56 // p is given in the reflectors coordinate frame. This is meant
57 // to be a fast check to sort out all mirrors which we can omit
58 // without time consuming calculations.
59
60 // Check if this mirror can be hit at all
61 const Double_t dx = TMath::Abs(p.X()-X());
62 if (dx>fSideLength*1.05)
63 return kFALSE;
64
65 const Double_t dy = TMath::Abs(p.Y()-Y());
66 if (dy>fSideLength*1.05)
67 return kFALSE;
68
69 return kTRUE;
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 MMirrorSquare::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 // Check if the photon has really hit the square mirror
93 if (TMath::Max(fabs(p.X()), fabs(p.Y()))>fSideLength)
94 return kFALSE;
95
96 return kTRUE;
97}
98
99// ------------------------------------------------------------------------
100//
101// Paint the mirror in x/y.
102//
103// The graphic should coincide with the action in HasHit
104//
105void MMirrorSquare::Paint(Option_t *opt)
106{
107 TBox b;
108 TEllipse e;
109
110 if (!TString(opt).Contains("line", TString::kIgnoreCase))
111 {
112 b.SetFillColor(17);
113 b.SetLineStyle(0);
114 e.SetLineStyle(0);
115 e.SetFillColor(gPad->GetFillColor());
116 }
117 else
118 {
119 b.SetFillStyle(0);
120 e.SetFillStyle(0);
121 }
122
123 b.PaintBox(X()-fSideLength, Y()-fSideLength, X()+fSideLength, Y()+fSideLength);
124
125 if (!TString(opt).Contains("border", TString::kIgnoreCase))
126 e.PaintEllipse(X(), Y(), 0.5, 0.5, 0, 360, 0);
127}
128
129// ------------------------------------------------------------------------
130//
131// Read the mirror's setup from a file. The first eight tokens should be
132// ignored. (This could be fixed!)
133//
134// Here we read: L
135//
136Int_t MMirrorSquare::ReadM(const TObjArray &tok)
137{
138 if (tok.GetSize()<9)
139 return -1;
140
141 Double_t l = atof(tok[8]->GetName());
142
143 if (l<=0)
144 return -1;
145
146 fSideLength = l/2;
147
148 return 1;
149}
Note: See TracBrowser for help on using the repository browser.