source: trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.cc@ 9324

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