source: trunk/MagicSoft/Mars/mpointing/MPointingPosCalc.cc@ 9492

Last change on this file since 9492 was 7115, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 5.3 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): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MPointingPosCalc
28//
29// Currently:
30//
31// * MC files: Copy the simulated telescope position (Telescope Theta,
32// Telescope Phi in MMcEvt) to MPointingPosition
33//
34// * Real Data: Copy the nominal poiting position (Nominal Zd, Nominal Az
35// in MReportDrive) to MPointingPosition
36//
37// We do a trick: Because it is not guranteed, that MReadReports calls
38// ReInit before the first event from the drive-tree is read (because
39// the first data event may have a time-stamp later than the first
40// drive event) we always assume that the current run is a data run.
41// If the assumption is true fReport should be initialized correctly.
42// For MC runs this should never happen, Because they are read though
43// MReadMarsFile which gurantees, that ReInit is always called before
44// Process. If we encounter such a case we stop execution.
45//
46// Future: Interpolate the pointing position for each event between two
47// consecutive drive reports.
48//
49// Input Container:
50// MRawRunHeader
51// [MMcEvt, MReportDrive]
52//
53// Output Container:
54// MPointingPosition
55//
56/////////////////////////////////////////////////////////////////////////////
57#include "MPointingPosCalc.h"
58
59#include "MLog.h"
60#include "MLogManip.h"
61
62#include "MParList.h"
63
64#include "MPointingPos.h"
65#include "MRawRunHeader.h"
66#include "MReportDrive.h"
67#include "MMcEvt.hxx"
68
69ClassImp(MPointingPosCalc);
70
71using namespace std;
72
73// --------------------------------------------------------------------------
74//
75// Search for MRawRunHeader. Get the run type from there. Depending on
76// the run type search either for MMcEvt or MReportDrive.
77//
78Bool_t MPointingPosCalc::ReInit(MParList *plist)
79{
80 MRawRunHeader *run = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
81 if (!run)
82 {
83 *fLog << err << "MRawRunHeader not found... aborting." << endl;
84 return kFALSE;
85 }
86
87 fRunType = run->GetRunType();
88
89 switch (fRunType)
90 {
91 case MRawRunHeader::kRTData:
92 if (!fReport)
93 {
94 *fLog << err << "MReportDrive not found... aborting." << endl;
95 return kFALSE;
96 }
97 return kTRUE;
98
99 case MRawRunHeader::kRTMonteCarlo:
100 fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
101 if (!fMcEvt)
102 {
103 *fLog << err << "MMcEvt not found... aborting." << endl;
104 return kFALSE;
105 }
106 return kTRUE;
107
108 case MRawRunHeader::kRTPedestal:
109 *fLog << err << "Cannot work in a pedestal Run!... aborting." << endl;
110 return kFALSE;
111
112 case MRawRunHeader::kRTCalibration:
113 *fLog << err << "Cannot work in a calibration Run!... aborting." << endl;
114 return kFALSE;
115
116 default:
117 *fLog << err << "Run Type " << fRunType << " unknown!... aborting." << endl;
118 return kFALSE;
119 }
120
121 return kTRUE;
122}
123
124// --------------------------------------------------------------------------
125//
126// Search for 'MPointingPos'. Create if not found.
127//
128Int_t MPointingPosCalc::PreProcess(MParList *plist)
129{
130 fPosition = (MPointingPos*)plist->FindCreateObj("MPointingPos");
131 fReport = (MReportDrive*)plist->FindObject("MReportDrive");
132
133 // We use kRTNone here as a placeholder for data runs.
134 fRunType = MRawRunHeader::kRTNone;
135
136 return fPosition ? kTRUE : kFALSE;
137}
138
139// --------------------------------------------------------------------------
140//
141// See class description.
142//
143Int_t MPointingPosCalc::Process()
144{
145 switch (fRunType)
146 {
147 case MRawRunHeader::kRTNone:
148 case MRawRunHeader::kRTData:
149 if (!fReport)
150 {
151 *fLog << warn;
152 *fLog << "MPointingPosCalc::Process: fReport==NULL && fRunType!=kRTMonteCarlo... abort!" << endl;
153 return kERROR;
154 }
155 fPosition->SetLocalPosition(fReport->GetNominalZd(), fReport->GetNominalAz());
156 fPosition->SetSkyPosition(fReport->GetRa(), fReport->GetDec());
157 return kTRUE;
158
159 case MRawRunHeader::kRTMonteCarlo:
160 if (!fMcEvt)
161 {
162 *fLog << warn;
163 *fLog << "MPointingPosCalc::Process: fMcEvt==NULL && fRunType==kRTMonteCarlo... abort!" << endl;
164 return kERROR;
165 }
166 fPosition->SetLocalPosition(fMcEvt->GetTelescopeTheta()*TMath::RadToDeg(), fMcEvt->GetTelescopePhi()*TMath::RadToDeg());
167 return kTRUE;
168 }
169 return kTRUE;
170}
Note: See TracBrowser for help on using the repository browser.