source: trunk/MagicSoft/Mars/mtemp/mucm/classes/MExtrapolatePointingPos.cc@ 6186

Last change on this file since 6186 was 4692, checked in by marcos, 20 years ago
*** empty log message ***
File size: 7.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC 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 appear 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): Marcos Lopez 03/2004 <mailto:marcos@gae.ucm.es>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MExtrapolatePointingPos
28//
29// In the PreProcess, read the drive report and store it in an TSpline.
30// In the Process, use the TSpline to calculate the PointingPos for the
31// time of the current event.
32//
33// Input Containers:
34// MRawEvtData
35//
36// Output Containers:
37// MPointingPos
38//
39//
40/////////////////////////////////////////////////////////////////////////////
41
42#include "MExtrapolatePointingPos.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include <TString.h>
48#include <TSpline.h>
49
50#include "MTaskList.h"
51#include "MParList.h"
52#include "MEvtLoop.h"
53#include "MReadReports.h"
54#include "MReportDrive.h"
55#include "MPointingPos.h"
56#include "MTime.h"
57#include "MRawRunHeader.h"
58
59#include <TCanvas.h>
60
61ClassImp(MExtrapolatePointingPos);
62
63using namespace std;
64
65
66// ---------------------------------------------------------------------------
67//
68// Read the drive report file for the whole night, a build from it the splines
69//
70Bool_t MExtrapolatePointingPos::ReadDriveReport(const TString filename)
71{
72
73 *fLog << endl << "["<< GetName() << "]: Loading report file \"" << filename << "\" into TSpline..." << endl;
74
75
76 //
77 // ParList
78 //
79 MParList plist;
80 MTaskList tlist;
81 plist.AddToList(&tlist);
82
83
84 //
85 // TaskList
86 //
87 MReadReports read;
88 read.AddTree("Drive");
89 read.AddFile(filename); // after the reading of the trees!!!
90 read.AddToBranchList("MReportDrive.*");
91
92 tlist.AddToList(&read);
93
94
95 //
96 // EventLoop
97 //
98 MEvtLoop evtloop;
99 evtloop.SetParList(&plist);
100
101 if (!evtloop.PreProcess())
102 return kFALSE;
103
104
105 TArrayD ReportTime(10000);
106 TArrayD CurrentZd(10000);
107 TArrayD CurrentAz(10000);
108 TArrayD NominalZd(10000);
109 TArrayD NominalAz(10000);
110 TArrayD Ra(10000);
111 TArrayD Dec(10000);
112
113
114 Int_t n=0;
115 while (tlist.Process())
116 {
117 MReportDrive* report = (MReportDrive*)plist.FindObject("MReportDrive");
118 MTime* reporttime = (MTime*)plist.FindObject("MTimeDrive");
119
120 if(n==0)
121 fFirstDriveTime = *reporttime;
122 else
123 fLastDriveTime = *reporttime;
124
125 //
126 // Sometimes there are two reports with the same time
127 //
128 if (reporttime->GetTime() == ReportTime[n-1])
129 {
130 cout << warn <<"["<< GetName() << "]: Warning: this report has the same time that the previous one...skipping it " << endl;
131 continue;
132 }
133
134 ReportTime[n] = reporttime->GetTime();
135 CurrentZd[n] = report->GetCurrentZd();
136 CurrentAz[n] = report->GetCurrentAz();
137 NominalZd[n] = report->GetNominalZd();
138 NominalAz[n] = report->GetNominalAz();
139 Ra[n] = report->GetRa();
140 Dec[n] = report->GetDec();
141
142 n++;
143 }
144
145 tlist.PrintStatistics();
146
147 *fLog << "["<< GetName() << "]: loaded " << n << " ReportDrive from "
148 << fFirstDriveTime << " to " << fLastDriveTime << endl << endl;
149
150
151 //
152 // Update the number of entries
153 //
154 ReportTime.Set(n);
155 CurrentZd.Set(n);
156 CurrentAz.Set(n);
157 NominalZd.Set(n);
158 NominalAz.Set(n);
159 Ra.Set(n);
160 Dec.Set(n);
161
162 // for(int i=0;i<ReportTime.GetSize();i++)
163// *fLog << i << " " << ReportTime[i] << " "
164// << CurrentZd[i] << " " << CurrentAz[i] << " "
165// << NominalZd[i] << " " << NominalAz[i] << " "
166// << Ra[i] << " " << Dec[i] << endl;
167
168
169 fSplineZd = new TSpline3("zenith",
170 ReportTime.GetArray(), NominalZd.GetArray(), n);
171 fSplineAz = new TSpline3("azimuth",
172 ReportTime.GetArray(), NominalAz.GetArray(), n);
173 fSplineRa = new TSpline3("RA",
174 ReportTime.GetArray(), Ra.GetArray(), n);
175 fSplineDec = new TSpline3("DEC",
176 ReportTime.GetArray(), Dec.GetArray(), n);
177
178
179
180 // TCanvas* c = new TCanvas();
181// c->Divide(2,2);
182// c->cd(1);
183// fSplineZd->Draw();
184// c->cd(2);
185// fSplineAz->Draw();
186// c->cd(3);
187// fSplineRa->Draw();
188// c->cd(4);
189// fSplineDec->Draw();
190// c->Modified();
191// c->Update();
192
193 return kTRUE;
194}
195
196
197// --------------------------------------------------------------------------
198//
199// Constructor
200//
201MExtrapolatePointingPos::MExtrapolatePointingPos(const TString filename, const char *name, const char *title)
202{
203 fName = name ? name : "MExtrapolatePointingPos";
204 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
205
206 fFilename = filename;
207
208 // Init
209 fError = kFALSE;
210 fSplineZd = NULL;
211 fSplineAz = NULL;
212 fSplineRa = NULL;
213 fSplineDec = NULL;
214}
215
216MExtrapolatePointingPos::~MExtrapolatePointingPos()
217{
218 if(fSplineZd)
219 delete fSplineZd;
220 if(fSplineAz)
221 delete fSplineAz;
222 if(fSplineRa)
223 delete fSplineRa;
224 if(fSplineDec)
225 delete fSplineDec;
226}
227
228
229// --------------------------------------------------------------------------
230//
231// Input:
232// - MTime
233//
234// Output:
235// - MPointingPos
236//
237Int_t MExtrapolatePointingPos::PreProcess( MParList *pList )
238{
239 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
240 if (!fRunHeader)
241 {
242 *fLog << err << "MRunHeader not found... aborting." << endl;
243 return kFALSE;
244 }
245
246 fEvtTime = (MTime*)pList->FindObject("MTime");
247 if (!fEvtTime)
248 {
249 *fLog << err << "MTime not found... aborting." << endl;
250 return kFALSE;
251 }
252
253 fPointingPos = (MPointingPos*)pList->FindCreateObj("MPointingPos");
254 if (!fPointingPos)
255 return kFALSE;
256
257
258 if( !ReadDriveReport(fFilename) )
259 return kFALSE;
260
261
262 return kTRUE;
263}
264
265
266// --------------------------------------------------------------------------
267//
268// Get the run start time, and get the pointing position for that time
269//
270Int_t MExtrapolatePointingPos::Process()
271{
272
273 //const Int_t run = fRunHeader->GetRunNumber();
274 const MTime* StartRunTime = &fRunHeader->GetRunStart();
275 const Double_t time = StartRunTime->GetTime();
276
277
278 //
279 // Check that we have drive report for this time
280 //
281 if( *StartRunTime<fFirstDriveTime || *StartRunTime>fLastDriveTime)
282 {
283 *fLog << err << dbginf << GetName() << ": Run time " << *StartRunTime
284 << " outside range of drive reports (" << fFirstDriveTime
285 << ", " << fLastDriveTime << ")" << endl;
286 fError = kTRUE;
287 return kFALSE;
288 }
289
290 //if(run < 20000)
291 // time = fEvtTime->GetTime();
292 //else
293 // time = StartRunTime->GetTime();
294
295
296 const Double_t zd = fSplineZd->Eval( time );
297 const Double_t az = fSplineAz->Eval( time );
298 const Double_t ra = fSplineRa->Eval( time );
299 const Double_t dec = fSplineDec->Eval( time );
300
301 fPointingPos->SetLocalPosition( zd, az );
302 fPointingPos->SetSkyPosition( ra*TMath::DegToRad()/15, dec*TMath::DegToRad());
303
304 // *fLog << " PointingPos: time = " << time << " (" << *fEvtTime << ") (zd, az, ra, dec) = (" << zd << ", " << az << ", " << ra << ", " << dec << ")" << endl;
305
306
307 return kTRUE;
308}
309
310
311// ----------------------------------------------------------------------------
312//
313//
314Int_t MExtrapolatePointingPos::PostProcess()
315{
316 return fError ? kFALSE : kTRUE;
317}
Note: See TracBrowser for help on using the repository browser.