source: branches/MarsWobble/msim/MSimPointingPos.cc@ 18237

Last change on this file since 18237 was 18165, checked in by ftemme, 10 years ago
Bugfix: wrong spelling of kFALSE, Copy and paste error: forgot to change the check for the fSimSourcePosition from fPointing to fSimSourcePosition
File size: 9.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// 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 fOffTargetDistance==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 pointing position is calculated:
42//
43// 1) fOffTargetDistance < 0:
44// The pointing position is randomly distributed in a disk of radius
45// -fOffTargetDistance. 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// The original zenith and azimuth coordinates of the shower axis are stored in
54// the MSimSourcePos container.
55//
56// If the view cone option was given and off-target observations are switched on
57// the orientation is fixed to the main direction around the view cone was
58// produced.
59// In addition a 'quasi'-simulated source position is calculated,
60// depending on fOffTargetDistance and fOffTargetPhi (see 1) and 2) above).
61// The corresponding zenith and azimuth coordinates are stored in the
62// MSimSourcePos container. This is of course not a physical source position,
63// but it can be used to determine the performance of wobble analysis on
64// background events (which are homogenous distributed).
65//
66//
67//
68// Input Containers:
69// MCorsikaRunHeader
70// MCorsikaEvtHeader
71//
72// Output Containers:
73// MPointingPos
74// MSimSourcePos
75//
76//////////////////////////////////////////////////////////////////////////////
77#include "MSimPointingPos.h"
78
79#include <TRandom.h>
80#include <TVector3.h>
81
82#include "MLog.h"
83#include "MLogManip.h"
84
85#include "MParList.h"
86
87#include "MCorsikaEvtHeader.h"
88#include "MCorsikaRunHeader.h"
89
90#include "MPointingPos.h"
91
92ClassImp(MSimPointingPos);
93
94using namespace std;
95
96// --------------------------------------------------------------------------
97//
98// Default Constructor.
99//
100MSimPointingPos::MSimPointingPos(const char* name, const char *title)
101 : fRunHeader(0), fEvtHeader(0), fPointing(0), fSimSourcePosition(0),
102 fOffTargetDistance(0), fOffTargetPhi(-1)
103
104{
105 fName = name ? name : "MSimPointingPos";
106 fTitle = title ? title : "Task to simulate the pointing position (mirror orientation)";
107}
108
109// --------------------------------------------------------------------------
110//
111// Get the distance from the real source to the poitning position.
112//
113Double_t MSimPointingPos::GetOffTargetDistance() const
114{
115 return fOffTargetDistance==0 ? 0 : fOffTargetDistance*TMath::RadToDeg();
116}
117
118// --------------------------------------------------------------------------
119//
120// Get the phi angle counted from the upward direction the source position
121// is rotated. distance from the real source to the pointing position.
122// A negative value refers to a random distribution.
123//
124Double_t MSimPointingPos::GetOffTargetPhi() const
125{
126 return fOffTargetPhi<0 ? -1 : fOffTargetPhi*TMath::RadToDeg();
127}
128
129// --------------------------------------------------------------------------
130//
131// Set fOffTargetDistance, see also GetOffTargetDistance
132//
133void MSimPointingPos::SetOffTargetDistance(Double_t d)
134{
135 fOffTargetDistance = d==0 ? 0 : d*TMath::DegToRad();
136}
137
138// --------------------------------------------------------------------------
139//
140// Set fOffTargetPhi, see also GetOffTargetPhi
141//
142void MSimPointingPos::SetOffTargetPhi(Double_t p)
143{
144 fOffTargetPhi = p<0 ? -1 : p*TMath::DegToRad();
145}
146
147
148
149// --------------------------------------------------------------------------
150//
151// Search for all necessary containers
152//
153Int_t MSimPointingPos::PreProcess(MParList *pList)
154{
155 fPointing = (MPointingPos*)pList->FindCreateObj("MPointingPos");
156 if (!fPointing)
157 return kFALSE;
158
159 fSimSourcePosition = (MPointingPos*)pList->FindCreateObj("MPointingPos","MSimSourcePos");
160 if (!fSimSourcePosition)
161 return kFALSE;
162
163 fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
164 if (!fRunHeader)
165 {
166 *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
167 return kFALSE;
168 }
169
170 fEvtHeader = (MCorsikaEvtHeader*)pList->FindObject("MCorsikaEvtHeader");
171 if (!fEvtHeader)
172 {
173 *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
174 return kFALSE;
175 }
176
177 if (!IsOffTargetObservation())
178 return kTRUE;
179
180 *fLog << inf;
181 *fLog << "Off target observations switched on with" << endl;
182 if (fOffTargetDistance>0)
183 {
184 *fLog <<" a pointing distance of " << GetOffTargetDistance() << "deg ";
185 if (fOffTargetPhi<0)
186 *fLog << "randomly distributed in phi." << endl;
187 else
188 *fLog << "and phi=" << GetOffTargetPhi() << "deg." << endl;
189 }
190 else
191 *fLog << " a homogenous distribution up to a distance of " << -GetOffTargetDistance() << "deg " << endl;
192
193 return kTRUE;
194}
195
196Bool_t MSimPointingPos::ReInit(MParList *pList)
197{
198 if (fRunHeader->HasViewCone() && IsOffTargetObservation())
199 {
200 *fLog << warn;
201 *fLog << "WARNING - Combining the view cone option with off-target pointing can lead to not homogenous events." << endl;
202 *fLog << " A simulated source position according to the off-target parameters will be created instead." << endl;
203 }
204 // FIXME: Check also the enlightened region on the ground!
205 return kTRUE;
206}
207
208void MSimPointingPos::GetDelta(Double_t &dtheta, Double_t &dphi) const
209{
210 if (fOffTargetDistance>0)
211 {
212 dtheta = fOffTargetDistance;
213 dphi = fOffTargetPhi>=0 ? fOffTargetPhi : gRandom->Uniform(TMath::TwoPi());
214 }
215 else
216 {
217 dtheta = TMath::Sqrt(gRandom->Uniform(fOffTargetDistance));
218 dphi = gRandom->Uniform(TMath::TwoPi());
219 }
220}
221
222// --------------------------------------------------------------------------
223//
224Int_t MSimPointingPos::Process()
225{
226 // If a view cone is given use the fixed telescope orientation
227 const Bool_t viewcone = fRunHeader->HasViewCone();
228
229 // Local sky coordinates (direction of telescope axis)
230 Double_t zdCorsika = viewcone ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg(); // x==north
231 Double_t azCorsika = viewcone ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg(); // y==west
232
233 // Calculate off target position in local sky coordinates
234 Double_t dtheta, dphi;
235 GetDelta(dtheta, dphi);
236
237 const Double_t theta = zdCorsika*TMath::DegToRad();
238 const Double_t phi = azCorsika*TMath::DegToRad();
239
240 TVector3 originalVector, wobbleVector;
241 originalVector.SetMagThetaPhi(1, theta, phi);
242 wobbleVector.SetMagThetaPhi(1, theta+dtheta, phi);
243
244 wobbleVector.Rotate(dphi, originalVector);
245
246 Double_t zdWobble, azWobble;
247 zdWobble = wobbleVector.Theta()*TMath::RadToDeg();
248 azWobble = wobbleVector.Phi() *TMath::RadToDeg();
249
250 // Transform the corsika coordinate system (north is magnetic north)
251 // into the telescopes local coordinate system. Note, that all vectors
252 // are already correctly oriented.
253 azCorsika += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
254 azWobble += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
255
256 // Setup the pointing and the simulated source position
257 if (!viewcone)
258 {
259 fPointing->SetLocalPosition(zdWobble, azWobble);
260 fSimSourcePosition->SetLocalPosition(zdCorsika, azCorsika);
261 }
262 else
263 {
264 fPointing->SetLocalPosition(zdCorsika, azCorsika);
265 fSimSourcePosition->SetLocalPosition(zdWobble, azWobble);
266 }
267
268 return kTRUE;
269}
270
271Int_t MSimPointingPos::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
272{
273 Bool_t rc = kFALSE;
274 if (IsEnvDefined(env, prefix, "OffTargetDistance", print))
275 {
276 rc = kTRUE;
277 SetOffTargetDistance(GetEnvValue(env, prefix, "OffTargetDistance", GetOffTargetDistance()));
278 }
279
280 if (IsEnvDefined(env, prefix, "OffTargetPhi", print))
281 {
282 rc = kTRUE;
283 SetOffTargetPhi(GetEnvValue(env, prefix, "OffTargetPhi", GetOffTargetPhi()));
284 }
285
286 return rc;
287}
288
Note: See TracBrowser for help on using the repository browser.