source: trunk/MagicSoft/Mars/mtemp/mifae/library/MSrcRotate.cc@ 6186

Last change on this file since 6186 was 4117, checked in by rico, 21 years ago
*** empty log message ***
File size: 6.7 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! Author(s): Javier Rico 04/2004 <mailto:jrico@ifae.es>
18!
19! Copyright: MAGIC Software Development, 2000-2004
20!
21!
22\* ======================================================================== */
23
24//////////////////////////////////////////////////////////////////////////////
25//
26// MSrcRotate
27//
28// Task to rotate the position of the source as a function of time
29//
30// Input Containers:
31// MSrcPosCam
32//
33// Output Containers:
34// MSrcPosCam
35//
36//////////////////////////////////////////////////////////////////////////////
37
38#include <fstream>
39#include <math.h>
40
41#include "MParList.h"
42#include "MRawRunHeader.h"
43#include "MRawEvtHeader.h"
44#include "MSrcRotate.h"
45
46#include "MAstroSky2Local.h"
47#include "MObservatory.h"
48#include "MSrcPosCam.h"
49
50#include "MLog.h"
51#include "MLogManip.h"
52
53ClassImp(MSrcRotate);
54
55using namespace std;
56
57static const TString gsDefName = "MSrcRotate";
58static const TString gsDefTitle = "Rotate position of the source";
59
60// -------------------------------------------------------------------------
61//
62// Default constructor. The first (second) argument is the name of the
63// input (output) MSrcPosCam object containing the source position in the
64// camera plain
65//
66MSrcRotate::MSrcRotate(const char* srcPosIn, const char* srcPosOut, const char *name, const char *title)
67 : fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0)
68{
69 fName = name ? name : gsDefName.Data();
70 fTitle = title ? title : gsDefTitle.Data();
71
72 SetInputSrcPosName(srcPosIn);
73 SetOutputSrcPosName(srcPosOut);
74
75 SetInternalHistoName(TString(fName)+"Hist");
76}
77
78// -------------------------------------------------------------------------
79//
80// Look for/create the needed containers
81// Check whether RA and DEC have been initialized
82//
83Int_t MSrcRotate::PreProcess(MParList *pList)
84{
85 if(!MSrcPlace::PreProcess(pList))
86 return kFALSE;
87
88 // look for MRawRunHeader
89 fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
90 if (!fRunHeader)
91 {
92 *fLog << err << "MSrcRotate::PreProcess Error: MRawRunHeader not found... aborting" << endl;
93 return kFALSE;
94 }
95
96 // look for MRawEvtHeader
97 fEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
98 if (!fEvtHeader)
99 {
100 *fLog << err << "MSrcRotate::PreProcess Error: MRawEvtHeader not found... aborting." << endl;
101 return kFALSE;
102 }
103
104 // look for/create the MObservatory
105 fObservatory = (MObservatory*)pList->FindCreateObj("MObservatory");
106 if(!fObservatory)
107 {
108 *fLog << err << "MSrcRotate::PreProcess Error: MObservatory not found... aborting." << endl;
109 return kFALSE;
110 }
111
112 // check RA and DEC
113 if(fRA==0. || fDEC ==0)
114 *fLog << warn << "MSrcRotate::PreProcess Warning: RA=" << fRA << "or DEC=" << fDEC << " could be not initialized" << endl;
115
116 return kTRUE;
117}
118
119// -------------------------------------------------------------------------
120//
121// Perform the rotation of the source position
122//
123// FIXME: for the time being, this is computed by assuming constant event rate
124//
125Int_t MSrcRotate::ComputeNewSrcPosition()
126{
127 if(fRunHeader->GetRunNumber()!=fRunNumber)
128 {
129 fRunNumber=fRunHeader->GetRunNumber();
130
131 // save the number of events, initial and final times
132 fNEvts = fRunHeader->GetNumEvents();
133 fIniTime = fRunHeader->GetRunStart();
134 fFinTime = fRunHeader->GetRunEnd();
135 fDeltaT = (fFinTime.GetMjd()-fIniTime.GetMjd())/fNEvts;
136
137 if((ULong_t)TMath::Nint(fIniTime.GetMjd())!=(ULong_t)TMath::Nint(fFinTime.GetMjd()))
138 {
139 *fLog << err << "MSrcRotate::ComputeNewSrcPosition Error: Inial and final MJDs are different ("<<fIniTime.GetMjd()<<"!="<<fFinTime.GetMjd()<<")" << endl;
140 return kFALSE;
141 }
142
143#ifdef DEBUG
144 cout << endl << "********************" << endl;
145 cout << "Run number: " << fRunHeader->GetRunNumber() << endl;
146 cout << "Number of events: " << fNEvts << endl;
147 cout << "Initial MJD date: " << fIniTime.GetMjd() << endl;
148 cout << "Final MJD date: " << fFinTime.GetMjd() << endl;
149 cout << "Delta t: " << fDeltaT << endl;
150#endif
151 }
152
153
154 // Compute the event time
155 // FIXME: for the time being, this is computed by assuming constant event rate
156 MTime eventTime;
157 Double_t newMJD = fIniTime.GetMjd() + (fFinTime.GetMjd()-fIniTime.GetMjd())*fEvtHeader->GetDAQEvtNumber()/fNEvts;
158 eventTime.SetMjd(newMJD);
159 MTime refTime;
160 refTime.SetMjd(fRefMJD);
161
162 // de-rotate the source position
163 const MAstroSky2Local Observation(eventTime, *fObservatory);
164 const MAstroSky2Local RefObservation(refTime, *fObservatory);
165
166#ifdef DEBUG
167 printf("Run:%d, Event:%d, iniMJD=%15.5f, finMJD=%15.5f, fDeltaT=%15.5f, newMJD=%15.5f, fRefMJD=%15.5f, rotation=%15.5f, ref=%15.5f\n",
168 fRunHeader->GetRunNumber(),fEvtHeader->GetDAQEvtNumber(),
169 fIniTime.GetMjd(),fFinTime.GetMjd(),fDeltaT,
170 newMJD,fRefMJD,Observation.RotationAngle(fRA,fDEC),
171 RefObservation.RotationAngle(fRA,fDEC));
172 // cout << "newMJD=" << newMJD << ", fRefMJD="<<fRefMJD<<", rotation="<<Observation.RotationAngle(fRA,fDEC)<<", ref="<<RefObservation.RotationAngle(fRA,fDEC)<< endl;
173#endif
174
175 Double_t rotationAngle = fRefMJD ?
176 Observation.RotationAngle(fRA,fDEC)-RefObservation.RotationAngle(fRA,fDEC) :
177 Observation.RotationAngle(fRA,fDEC) ;
178 MSrcPosCam* srcposIn = GetInputSrcPosCam();
179 MSrcPosCam* srcposOut = GetOutputSrcPosCam();
180
181 Float_t c = TMath::Cos(rotationAngle);
182 Float_t s = TMath::Sin(rotationAngle);
183 // perform a rotation of -rotationAngle to move the source back to the "initial" position
184 Float_t newX = c*srcposIn->GetX()-s*srcposIn->GetY();
185 Float_t newY = s*srcposIn->GetX()+c*srcposIn->GetY();
186
187#ifdef DEBUG
188 Double_t rotationAngleComp = fObservatory->RotationAngle(0.1256,2.63);
189 cout << "Event " << fEvtHeader->GetDAQEvtNumber() << endl;
190 cout << "newMJD=" << newMJD <<", rotationAngle=" << rotationAngle <<", rotationAngleComp=" << rotationAngleComp << ", oldX="<<fIniSrcPosIn.GetX()<< ", oldY="<<fIniSrcPosIn.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl;
191#endif
192
193 srcposOut->SetXY(newX,newY);
194
195 return kTRUE;
196}
Note: See TracBrowser for help on using the repository browser.