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

Last change on this file since 9337 was 9336, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.8 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// This task is meant to simulate the pointing position (mirror orientation).
30// This depends on the direction from which the shower is coming but also
31// on the user request (e.g. Wobble mode).
32//
33// WARNING: Currently the telescope orientation is just fixed to the
34// direction in the run-header (if a view cone was given) or
35// the direction in the evt-header (if no view cone given)
36//
37// Input Containers:
38// MCorsikaRunHeader
39// MCorsikaEvtHeader
40//
41// Output Containers:
42// MPointingPos
43// PointingCorsika [MPointingPos]
44//
45//////////////////////////////////////////////////////////////////////////////
46#include "MSimPointingPos.h"
47
48#include <TRandom.h>
49#include <TVector3.h>
50
51#include "MLog.h"
52#include "MLogManip.h"
53
54#include "MParList.h"
55
56#include "MCorsikaEvtHeader.h"
57#include "MCorsikaRunHeader.h"
58
59#include "MPointingPos.h"
60
61ClassImp(MSimPointingPos);
62
63using namespace std;
64
65// --------------------------------------------------------------------------
66//
67// Default Constructor.
68//
69MSimPointingPos::MSimPointingPos(const char* name, const char *title)
70 : fRunHeader(0), fEvtHeader(0), fPointingCorsika(0), fPointingLocal(0),
71 fOffTargetDistance(-1), fOffTargetPhi(-1)
72
73{
74 fName = name ? name : "MSimPointingPos";
75 fTitle = title ? title : "Task to simulate the pointing position (mirror orientation)";
76}
77
78
79// --------------------------------------------------------------------------
80//
81// Search for all necessary containers
82//
83Int_t MSimPointingPos::PreProcess(MParList *pList)
84{
85 fPointingCorsika = (MPointingPos*)pList->FindCreateObj("MPointingPos", "PointingCorsika");
86 if (!fPointingCorsika)
87 return kFALSE;
88
89 fPointingLocal = (MPointingPos*)pList->FindCreateObj("MPointingPos");
90 if (!fPointingLocal)
91 return kFALSE;
92
93 fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
94 if (!fRunHeader)
95 {
96 *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 fEvtHeader = (MCorsikaEvtHeader*)pList->FindObject("MCorsikaEvtHeader");
101 if (!fEvtHeader)
102 {
103 *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
104 return kFALSE;
105 }
106
107 // FIXED offset
108 // Diffuse? ( FOV of camera folded with mirror diameter as Corsika input? )
109 // Hour angle!
110 // Angle to magnetic field!
111
112 if (IsOffTargetObservation())
113 {
114 *fLog << inf;
115 *fLog << "Off target observations switched on with" << endl;
116 *fLog <<" a pointing distance of " << GetOffTargetDistance() << "deg ";
117 if (fOffTargetPhi<0)
118 *fLog << "randomly distributed in phi." << endl;
119 else
120 *fLog << "and phi=" << GetOffTargetPhi() << "deg." << endl;
121 }
122
123 return kTRUE;
124}
125
126/*
127Bool_t MSimPointingPos::ReInit(MParList *pList)
128{
129 // FIXME: Check also the enlightened region on the ground!
130 return kTRUE;
131}
132*/
133
134// --------------------------------------------------------------------------
135//
136Int_t MSimPointingPos::Process()
137{
138
139 // If a view cone is given use the fixed telescope orientation
140 const Bool_t fixed = fRunHeader->HasViewCone();
141
142 // Local sky coordinates (direction of telescope axis)
143 /*const*/ Double_t zd = fixed ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg(); // x==north
144 /*const*/ Double_t az = fixed ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg(); // y==west
145
146 if (!fixed && IsOffTargetObservation())
147 {
148 const Double_t theta = zd*TMath::DegToRad();
149 const Double_t phi = az*TMath::DegToRad();
150
151 /*const*/ TVector3 source;
152 source.SetMagThetaPhi(1, theta, phi);
153
154 /*const*/ TVector3 point;
155 point.SetMagThetaPhi(1, theta+fOffTargetDistance, phi);
156
157 const Double_t delta = fOffTargetPhi>0 ? fOffTargetPhi :
158 gRandom->Uniform(TMath::TwoPi());
159
160 point.Rotate(delta, source);
161
162 zd = point.Theta()*TMath::RadToDeg();
163 az = point.Phi()*TMath::RadToDeg();
164 }
165
166 // Setup the pointing position
167 fPointingCorsika->SetLocalPosition(zd, az);
168 fPointingLocal->SetLocalPosition(zd, az+fRunHeader->GetMagneticFieldAz());
169
170 // Calculate incident angle between magnetic field direction
171 // and pointing direction ( phi and theta? )
172
173 return kTRUE;
174}
175
176Int_t MSimPointingPos::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
177{
178 Bool_t rc = kFALSE;
179 if (IsEnvDefined(env, prefix, "OffTargetDistance", print))
180 {
181 rc = kTRUE;
182 SetOffTargetDistance(GetEnvValue(env, prefix, "OffTargetDistance", GetOffTargetDistance()));
183 }
184
185 if (IsEnvDefined(env, prefix, "OffTargetPhi", print))
186 {
187 rc = kTRUE;
188 SetOffTargetPhi(GetEnvValue(env, prefix, "OffTargetPhi", GetOffTargetPhi()));
189 }
190
191 return rc;
192}
193
Note: See TracBrowser for help on using the repository browser.