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

Last change on this file since 4087 was 4087, checked in by rico, 20 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// MDCA
36//
37//////////////////////////////////////////////////////////////////////////////
38
39#include <fstream>
40#include <math.h>
41
42#include "MParList.h"
43#include "MRawRunHeader.h"
44#include "MRawEvtHeader.h"
45#include "MSrcRotate.h"
46
47#include "MAstroSky2Local.h"
48#include "MObservatory.h"
49#include "MSrcPosCam.h"
50#include "MDCA.h"
51
52#include "MLog.h"
53#include "MLogManip.h"
54
55ClassImp(MSrcRotate);
56
57using namespace std;
58
59static const TString gsDefName = "MSrcRotate";
60static const TString gsDefTitle = "Rotate position of the source";
61
62// -------------------------------------------------------------------------
63//
64// Default constructor. The first (second) argument is the name of a container
65// containing the source position in the camera plain, MScrPosCam (MDCA).
66// The default is "MSrcPosCam" ("MDCA").
67//
68MSrcRotate::MSrcRotate(const char* srcPos, const char* dca, const char *name, const char *title)
69 : MSrcPlace(TString(gsDefName+"Hist").Data()), fRA(0), fDEC(0), fRefMJD(0), fRunNumber(0)
70{
71 fName = name ? name : gsDefName.Data();
72 fTitle = title ? title : gsDefTitle.Data();
73
74 SetSrcPosName(srcPos);
75 SetDCAName(dca);
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* srcpos = GetSrcPosCam();
179 MDCA* dca = GetDCA();
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*srcpos->GetX()-s*srcpos->GetY();
185 Float_t newY = s*srcpos->GetX()+c*srcpos->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="<<fIniSrcPos.GetX()<< ", oldY="<<fIniSrcPos.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl;
191#endif
192
193 srcpos->SetX(newX);
194 srcpos->SetY(newY);
195 dca->SetRefPoint(newX,newY);
196
197 return kTRUE;
198}
Note: See TracBrowser for help on using the repository browser.