source: trunk/MagicSoft/Mars/msim/MSimPointingPos.cc@ 9367

Last change on this file since 9367 was 9367, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 8.1 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// MSimPointingPos
28//
29//
30// This task is meant to simulate the pointing position (mirror orientation).
31// This depends on the direction from which the shower is coming but also
32// on the user request (e.g. Wobble mode).
33//
34//
35// If fOffTragetDistance==0 the telescope is oriented depending on the
36// view cone option. If a view cone was given the orientation is fixed to
37// the main direction around the view cone was produced. If no view
38// cone was given the telescope is oriented parallel to the shower axis.
39//
40// If no view cone option was given and off-target observations are switched
41// on by setting fOffTargetDistance!=0 the poitnting position is calculated:
42//
43// 1) fOffTargetDistance < 0:
44// The pointing position is randomly distributed in a disk of radius
45// -fOffTragetDistance. fOffTargetDistance is silently ignored.
46//
47// 2) fOffTargetDistance > 0:
48// The pointing position is set to a position in the given distance
49// away from the shower axis. If fOffTargetPhi>=0 it is fixed at
50// this phi value. For phi<0 it is randomly distributed at distances
51// fOffTargetDistance. (phi==0 is the direction of positive theta)
52//
53//
54// Input Containers:
55// MCorsikaRunHeader
56// MCorsikaEvtHeader
57//
58// Output Containers:
59// MPointingPos
60//
61//////////////////////////////////////////////////////////////////////////////
62#include "MSimPointingPos.h"
63
64#include <TRandom.h>
65#include <TVector3.h>
66
67#include "MLog.h"
68#include "MLogManip.h"
69
70#include "MParList.h"
71
72#include "MCorsikaEvtHeader.h"
73#include "MCorsikaRunHeader.h"
74
75#include "MPointingPos.h"
76
77ClassImp(MSimPointingPos);
78
79using namespace std;
80
81// --------------------------------------------------------------------------
82//
83// Default Constructor.
84//
85MSimPointingPos::MSimPointingPos(const char* name, const char *title)
86 : fRunHeader(0), fEvtHeader(0), fPointing(0),
87 fOffTargetDistance(0), fOffTargetPhi(-1)
88
89{
90 fName = name ? name : "MSimPointingPos";
91 fTitle = title ? title : "Task to simulate the pointing position (mirror orientation)";
92}
93
94// --------------------------------------------------------------------------
95//
96// Get the distance from the real source to the poitning position.
97//
98Double_t MSimPointingPos::GetOffTargetDistance() const
99{
100 return fOffTargetDistance==0 ? 0 : fOffTargetDistance*TMath::RadToDeg();
101}
102
103// --------------------------------------------------------------------------
104//
105// Get the phi angle counted from the upward direction the source position
106// is rotated. distance from the real source to the pointing position.
107// A negative value refers to a random distribution.
108//
109Double_t MSimPointingPos::GetOffTargetPhi() const
110{
111 return fOffTargetPhi<0 ? -1 : fOffTargetPhi*TMath::RadToDeg();
112}
113
114// --------------------------------------------------------------------------
115//
116// Set fOffTargetDistance, see also GetOffTargetDistance
117//
118void MSimPointingPos::SetOffTargetDistance(Double_t d)
119{
120 fOffTargetDistance = d==0 ? 0 : d*TMath::DegToRad();
121}
122
123// --------------------------------------------------------------------------
124//
125// Set fOffTargetPhi, see also GetOffTargetPhi
126//
127void MSimPointingPos::SetOffTargetPhi(Double_t p)
128{
129 fOffTargetPhi = p<0 ? -1 : p*TMath::DegToRad();
130}
131
132
133
134// --------------------------------------------------------------------------
135//
136// Search for all necessary containers
137//
138Int_t MSimPointingPos::PreProcess(MParList *pList)
139{
140 fPointing = (MPointingPos*)pList->FindCreateObj("MPointingPos");
141 if (!fPointing)
142 return kFALSE;
143
144 fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
145 if (!fRunHeader)
146 {
147 *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
148 return kFALSE;
149 }
150
151 fEvtHeader = (MCorsikaEvtHeader*)pList->FindObject("MCorsikaEvtHeader");
152 if (!fEvtHeader)
153 {
154 *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
155 return kFALSE;
156 }
157
158 if (!IsOffTargetObservation())
159 return kTRUE;
160
161 *fLog << inf;
162 *fLog << "Off target observations switched on with" << endl;
163 if (fOffTargetDistance>0)
164 {
165 *fLog <<" a pointing distance of " << GetOffTargetDistance() << "deg ";
166 if (fOffTargetPhi<0)
167 *fLog << "randomly distributed in phi." << endl;
168 else
169 *fLog << "and phi=" << GetOffTargetPhi() << "deg." << endl;
170 }
171 else
172 *fLog << " a homogenous distribution up to a distance of " << -GetOffTargetDistance() << "deg " << endl;
173
174 return kTRUE;
175}
176
177Bool_t MSimPointingPos::ReInit(MParList *pList)
178{
179 if (fRunHeader->HasViewCone() && IsOffTargetObservation())
180 {
181 *fLog << warn;
182 *fLog << "WARNING - Combining the view cone option with off-target observations doesn't make sense." << endl;
183 *fLog << " Option for off-target observations will be ignored." << endl;
184 }
185 // FIXME: Check also the enlightened region on the ground!
186 return kTRUE;
187}
188
189void MSimPointingPos::GetDelta(Double_t &dtheta, Double_t &dphi) const
190{
191 if (fOffTargetDistance>0)
192 {
193 dtheta = fOffTargetDistance;
194 dphi = fOffTargetPhi>=0 ? fOffTargetPhi : gRandom->Uniform(TMath::TwoPi());
195 }
196 else
197 {
198 dtheta = TMath::Sqrt(gRandom->Uniform(fOffTargetDistance));
199 dphi = gRandom->Uniform(TMath::TwoPi());
200 }
201}
202
203// --------------------------------------------------------------------------
204//
205Int_t MSimPointingPos::Process()
206{
207 // If a view cone is given use the fixed telescope orientation
208 const Bool_t viewcone = fRunHeader->HasViewCone();
209
210 // Local sky coordinates (direction of telescope axis)
211 Double_t zd = viewcone ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg(); // x==north
212 Double_t az = viewcone ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg(); // y==west
213
214 if (!viewcone)
215 {
216 Double_t dtheta, dphi;
217 GetDelta(dtheta, dphi);
218
219 const Double_t theta = zd*TMath::DegToRad();
220 const Double_t phi = az*TMath::DegToRad();
221
222 TVector3 src, pnt;
223 src.SetMagThetaPhi(1, theta, phi);
224 pnt.SetMagThetaPhi(1, theta+dtheta, phi);
225
226 pnt.Rotate(dphi, src);
227
228 zd = pnt.Theta()*TMath::RadToDeg();
229 az = pnt.Phi() *TMath::RadToDeg();
230 }
231
232 // Transform the corsika coordinate system (north is magnetic north)
233 // into the telescopes local coordinate system. Note, that all vectors
234 // are already correctly oriented.
235 az += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
236
237 // Setup the pointing position
238 fPointing->SetLocalPosition(zd, az);
239
240 // Calculate incident angle between magnetic field direction
241 // and pointing direction ( phi and theta? )
242
243 return kTRUE;
244}
245
246Int_t MSimPointingPos::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
247{
248 Bool_t rc = kFALSE;
249 if (IsEnvDefined(env, prefix, "OffTargetDistance", print))
250 {
251 rc = kTRUE;
252 SetOffTargetDistance(GetEnvValue(env, prefix, "OffTargetDistance", GetOffTargetDistance()));
253 }
254
255 if (IsEnvDefined(env, prefix, "OffTargetPhi", print))
256 {
257 rc = kTRUE;
258 SetOffTargetPhi(GetEnvValue(env, prefix, "OffTargetPhi", GetOffTargetPhi()));
259 }
260
261 return rc;
262}
263
Note: See TracBrowser for help on using the repository browser.