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

Last change on this file since 4691 was 4691, checked in by marcos, 20 years ago
*** empty log message ***
File size: 7.6 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 fSplineZd = NULL;
210 fSplineAz = NULL;
211 fSplineRa = NULL;
212 fSplineDec = NULL;
213}
214
215MExtrapolatePointingPos::~MExtrapolatePointingPos()
216{
217 if(fSplineZd)
218 delete fSplineZd;
219 if(fSplineAz)
220 delete fSplineAz;
221 if(fSplineRa)
222 delete fSplineRa;
223 if(fSplineDec)
224 delete fSplineDec;
225}
226
227
228// --------------------------------------------------------------------------
229//
230// Input:
231// - MTime
232//
233// Output:
234// - MPointingPos
235//
236Int_t MExtrapolatePointingPos::PreProcess( MParList *pList )
237{
238 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
239 if (!fRunHeader)
240 {
241 *fLog << err << "MRunHeader not found... aborting." << endl;
242 return kFALSE;
243 }
244
245 fEvtTime = (MTime*)pList->FindObject("MTime");
246 if (!fEvtTime)
247 {
248 *fLog << err << "MTime not found... aborting." << endl;
249 return kFALSE;
250 }
251
252 fPointingPos = (MPointingPos*)pList->FindCreateObj("MPointingPos");
253 if (!fPointingPos)
254 return kFALSE;
255
256
257 if( !ReadDriveReport(fFilename) )
258 return kFALSE;
259
260
261 return kTRUE;
262}
263
264
265// --------------------------------------------------------------------------
266//
267// Get the run start time, and get the pointing position for that time
268//
269Int_t MExtrapolatePointingPos::Process()
270{
271
272 //const Int_t run = fRunHeader->GetRunNumber();
273 const MTime* StartRunTime = &fRunHeader->GetRunStart();
274 const Double_t time = StartRunTime->GetTime();
275
276
277 //
278 // Check that we have drive report for this time
279 //
280 if( *StartRunTime<fFirstDriveTime || *StartRunTime>fLastDriveTime)
281 {
282 *fLog << err << dbginf << GetName() << ": Run time " << *StartRunTime
283 << " outside range of drive reports (" << fFirstDriveTime
284 << ", " << fLastDriveTime << ")" << endl;
285 return kFALSE;
286 }
287
288 //if(run < 20000)
289 // time = fEvtTime->GetTime();
290 //else
291 // time = StartRunTime->GetTime();
292
293
294 const Double_t zd = fSplineZd->Eval( time );
295 const Double_t az = fSplineAz->Eval( time );
296 const Double_t ra = fSplineRa->Eval( time );
297 const Double_t dec = fSplineDec->Eval( time );
298
299 fPointingPos->SetLocalPosition( zd, az );
300 fPointingPos->SetSkyPosition( ra*TMath::DegToRad()/15, dec*TMath::DegToRad());
301
302 // *fLog << " PointingPos: time = " << time << " (" << *fEvtTime << ") (zd, az, ra, dec) = (" << zd << ", " << az << ", " << ra << ", " << dec << ")" << endl;
303
304
305 return kTRUE;
306}
307
308
Note: See TracBrowser for help on using the repository browser.