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 |
|
---|
77 | ClassImp(MSimPointingPos);
|
---|
78 |
|
---|
79 | using namespace std;
|
---|
80 |
|
---|
81 | // --------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Default Constructor.
|
---|
84 | //
|
---|
85 | MSimPointingPos::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 | //
|
---|
97 | // Search for all necessary containers
|
---|
98 | //
|
---|
99 | Int_t MSimPointingPos::PreProcess(MParList *pList)
|
---|
100 | {
|
---|
101 | fPointing = (MPointingPos*)pList->FindCreateObj("MPointingPos");
|
---|
102 | if (!fPointing)
|
---|
103 | return kFALSE;
|
---|
104 |
|
---|
105 | fRunHeader = (MCorsikaRunHeader*)pList->FindObject("MCorsikaRunHeader");
|
---|
106 | if (!fRunHeader)
|
---|
107 | {
|
---|
108 | *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
|
---|
109 | return kFALSE;
|
---|
110 | }
|
---|
111 |
|
---|
112 | fEvtHeader = (MCorsikaEvtHeader*)pList->FindObject("MCorsikaEvtHeader");
|
---|
113 | if (!fEvtHeader)
|
---|
114 | {
|
---|
115 | *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
|
---|
116 | return kFALSE;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (!IsOffTargetObservation())
|
---|
120 | return kTRUE;
|
---|
121 |
|
---|
122 | *fLog << inf;
|
---|
123 | *fLog << "Off target observations switched on with" << endl;
|
---|
124 | if (fOffTargetDistance>0)
|
---|
125 | {
|
---|
126 | *fLog <<" a pointing distance of " << GetOffTargetDistance() << "deg ";
|
---|
127 | if (fOffTargetPhi<0)
|
---|
128 | *fLog << "randomly distributed in phi." << endl;
|
---|
129 | else
|
---|
130 | *fLog << "and phi=" << GetOffTargetPhi() << "deg." << endl;
|
---|
131 | }
|
---|
132 | else
|
---|
133 | *fLog << " a homogenous distribution up to a distance of " << -GetOffTargetDistance() << "deg " << endl;
|
---|
134 |
|
---|
135 | return kTRUE;
|
---|
136 | }
|
---|
137 |
|
---|
138 | Bool_t MSimPointingPos::ReInit(MParList *pList)
|
---|
139 | {
|
---|
140 | if (fRunHeader->HasViewCone() && IsOffTargetObservation())
|
---|
141 | {
|
---|
142 | *fLog << warn;
|
---|
143 | *fLog << "WARNING - Combining the view cone option with off-target observations doesn't make sense." << endl;
|
---|
144 | *fLog << " Option for off-target observations will be ignored." << endl;
|
---|
145 | }
|
---|
146 | // FIXME: Check also the enlightened region on the ground!
|
---|
147 | return kTRUE;
|
---|
148 | }
|
---|
149 |
|
---|
150 | void MSimPointingPos::GetDelta(Double_t &dtheta, Double_t &dphi) const
|
---|
151 | {
|
---|
152 | if (fOffTargetDistance>0)
|
---|
153 | {
|
---|
154 | dtheta = fOffTargetDistance;
|
---|
155 | dphi = fOffTargetPhi>0 ? fOffTargetPhi : gRandom->Uniform(TMath::TwoPi());
|
---|
156 | }
|
---|
157 | else
|
---|
158 | {
|
---|
159 | dtheta = TMath::Sqrt(gRandom->Uniform(fOffTargetDistance));
|
---|
160 | dphi = gRandom->Uniform(TMath::TwoPi());
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | // --------------------------------------------------------------------------
|
---|
165 | //
|
---|
166 | Int_t MSimPointingPos::Process()
|
---|
167 | {
|
---|
168 | // If a view cone is given use the fixed telescope orientation
|
---|
169 | const Bool_t viewcone = fRunHeader->HasViewCone();
|
---|
170 |
|
---|
171 | // Local sky coordinates (direction of telescope axis)
|
---|
172 | Double_t zd = viewcone ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg(); // x==north
|
---|
173 | Double_t az = viewcone ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg(); // y==west
|
---|
174 |
|
---|
175 | if (!viewcone)
|
---|
176 | {
|
---|
177 | Double_t dtheta, dphi;
|
---|
178 | GetDelta(dtheta, dphi);
|
---|
179 |
|
---|
180 | const Double_t theta = zd*TMath::DegToRad();
|
---|
181 | const Double_t phi = az*TMath::DegToRad();
|
---|
182 |
|
---|
183 | TVector3 src, pnt;
|
---|
184 | src.SetMagThetaPhi(1, theta, phi);
|
---|
185 | pnt.SetMagThetaPhi(1, theta+dtheta, phi);
|
---|
186 |
|
---|
187 | pnt.Rotate(dphi, src);
|
---|
188 |
|
---|
189 | zd = pnt.Theta()*TMath::RadToDeg();
|
---|
190 | az = pnt.Phi() *TMath::RadToDeg();
|
---|
191 | }
|
---|
192 |
|
---|
193 | // Transform the corsika coordinate system (north is magnetic north)
|
---|
194 | // into the telescopes local coordinate system. Note, that all vectors
|
---|
195 | // are already correctly oriented.
|
---|
196 | az += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
|
---|
197 |
|
---|
198 | // Setup the pointing position
|
---|
199 | fPointing->SetLocalPosition(zd, az);
|
---|
200 |
|
---|
201 | // Calculate incident angle between magnetic field direction
|
---|
202 | // and pointing direction ( phi and theta? )
|
---|
203 |
|
---|
204 | return kTRUE;
|
---|
205 | }
|
---|
206 |
|
---|
207 | Int_t MSimPointingPos::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
208 | {
|
---|
209 | Bool_t rc = kFALSE;
|
---|
210 | if (IsEnvDefined(env, prefix, "OffTargetDistance", print))
|
---|
211 | {
|
---|
212 | rc = kTRUE;
|
---|
213 | SetOffTargetDistance(GetEnvValue(env, prefix, "OffTargetDistance", GetOffTargetDistance()));
|
---|
214 | }
|
---|
215 |
|
---|
216 | if (IsEnvDefined(env, prefix, "OffTargetPhi", print))
|
---|
217 | {
|
---|
218 | rc = kTRUE;
|
---|
219 | SetOffTargetPhi(GetEnvValue(env, prefix, "OffTargetPhi", GetOffTargetPhi()));
|
---|
220 | }
|
---|
221 |
|
---|
222 | return rc;
|
---|
223 | }
|
---|
224 |
|
---|