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 Azimuth and
|
---|
29 | // Zenith angles
|
---|
30 | //
|
---|
31 | // Input Containers:
|
---|
32 | // MSrcPosCam
|
---|
33 | //
|
---|
34 | // Output Containers:
|
---|
35 | // MSrcPosCam
|
---|
36 | // MDCA
|
---|
37 | //
|
---|
38 | //////////////////////////////////////////////////////////////////////////////
|
---|
39 |
|
---|
40 | #include <fstream>
|
---|
41 | #include <math.h>
|
---|
42 |
|
---|
43 | #include "MParList.h"
|
---|
44 | #include "MRawRunHeader.h"
|
---|
45 | #include "MRawEvtHeader.h"
|
---|
46 | #include "MSrcRotate.h"
|
---|
47 | #include "MSrcPosCam.h"
|
---|
48 | #include "MDCA.h"
|
---|
49 |
|
---|
50 | #include "MAstroSky2Local.h"
|
---|
51 | #include "MObservatory.h"
|
---|
52 |
|
---|
53 | #include "MLog.h"
|
---|
54 | #include "MLogManip.h"
|
---|
55 |
|
---|
56 | ClassImp(MSrcRotate);
|
---|
57 |
|
---|
58 | using namespace std;
|
---|
59 |
|
---|
60 | static const TString gsDefName = "MSrcRotate";
|
---|
61 | static const TString gsDefTitle = "De-rotate position of the source";
|
---|
62 |
|
---|
63 | // -------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // Default constructor. The first (second) argument is the name of a container
|
---|
66 | // containing the source position in the camera plain, MScrPosCam (MDCA).
|
---|
67 | // The default is "MSrcPosCam" ("MDCA").
|
---|
68 | //
|
---|
69 | MSrcRotate::MSrcRotate(const char* srcPos, const char* dca, const char *name, const char *title)
|
---|
70 | : fSrcPos(NULL), fDCA(NULL), fRA(0), fDEC(0), fRunNumber(0)
|
---|
71 | {
|
---|
72 | fName = name ? name : gsDefName.Data();
|
---|
73 | fTitle = title ? title : gsDefTitle.Data();
|
---|
74 |
|
---|
75 | fSrcPosName = srcPos;
|
---|
76 | fDCAName = dca;
|
---|
77 | }
|
---|
78 |
|
---|
79 | // -------------------------------------------------------------------------
|
---|
80 | //
|
---|
81 | // Look for/create the needed containers
|
---|
82 | // Check whether RA and DEC have been initialized
|
---|
83 | //
|
---|
84 | Int_t MSrcRotate::PreProcess(MParList *pList)
|
---|
85 | {
|
---|
86 | // look for/create MSrcPosCam
|
---|
87 | fSrcPos = (MSrcPosCam*)pList->FindObject(AddSerialNumber(fSrcPosName), "MSrcPosCam");
|
---|
88 | if (!fSrcPos)
|
---|
89 | {
|
---|
90 | *fLog << warn << AddSerialNumber(fSrcPosName) << " [MSrcPosCam] not found... creating default container." << endl;
|
---|
91 | fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam", AddSerialNumber(fSrcPosName));
|
---|
92 | if(!fSrcPos)
|
---|
93 | return kFALSE;
|
---|
94 | }
|
---|
95 |
|
---|
96 | // look for/create MDCA
|
---|
97 | fDCA = (MDCA*)pList->FindObject(AddSerialNumber(fDCAName), "MDCA");
|
---|
98 | if (!fDCA)
|
---|
99 | {
|
---|
100 | *fLog << warn << AddSerialNumber(fDCAName) << " [MDCA] not found... creating default container." << endl;
|
---|
101 | fDCA = (MDCA*)pList->FindCreateObj("MDCA", AddSerialNumber(fDCAName));
|
---|
102 | if(!fDCA)
|
---|
103 | return kFALSE;
|
---|
104 | }
|
---|
105 |
|
---|
106 | // look for MRawRunHeader
|
---|
107 | fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
108 | if (!fRunHeader)
|
---|
109 | {
|
---|
110 | *fLog << err << "MSrcRotate::PreProcess Error: MRawRunHeader not found... aborting" << endl;
|
---|
111 | return kFALSE;
|
---|
112 | }
|
---|
113 |
|
---|
114 | // look for MRawEvtHeader
|
---|
115 | fEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
---|
116 | if (!fEvtHeader)
|
---|
117 | {
|
---|
118 | *fLog << err << "MSrcRotate::PreProcess Error: MRawEvtHeader not found... aborting." << endl;
|
---|
119 | return kFALSE;
|
---|
120 | }
|
---|
121 |
|
---|
122 | // look for/create the MObservatory
|
---|
123 | fObservatory = (MObservatory*)pList->FindCreateObj("MObservatory");
|
---|
124 | if(!fObservatory)
|
---|
125 | {
|
---|
126 | *fLog << err << "MSrcRotate::PreProcess Error: MObservatory not found... aborting." << endl;
|
---|
127 | return kFALSE;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // check RA and DEC
|
---|
131 | if(fRA==0. || fDEC ==0)
|
---|
132 | *fLog << warn << "MSrcRotate::PreProcess Warning: RA=" << fRA << "or DEC=" << fDEC << " could be not initialized" << endl;
|
---|
133 |
|
---|
134 | return kTRUE;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // -------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // Perform the rotation of the source position
|
---|
140 | //
|
---|
141 | // FIXME: for the time being, this is computed by assuming constant event rate
|
---|
142 | //
|
---|
143 | Int_t MSrcRotate::Process()
|
---|
144 | {
|
---|
145 | if(fRunHeader->GetRunNumber()!=fRunNumber)
|
---|
146 | {
|
---|
147 | fRunNumber=fRunHeader->GetRunNumber();
|
---|
148 |
|
---|
149 | // save the number of events, initial and final times
|
---|
150 | fNEvts = fRunHeader->GetNumEvents();
|
---|
151 | fFirstEvt = fEvtHeader->GetDAQEvtNumber();
|
---|
152 | fIniTime = fRunHeader->GetRunStart();
|
---|
153 | fFinTime = fRunHeader->GetRunEnd();
|
---|
154 | fDeltaT = (fFinTime.GetMjd()-fIniTime.GetMjd())/fNEvts;
|
---|
155 |
|
---|
156 | if((ULong_t)TMath::Nint(fIniTime.GetMjd())!=(ULong_t)TMath::Nint(fFinTime.GetMjd()))
|
---|
157 | {
|
---|
158 | *fLog << err << "MSrcRotate::Process Error: Inial and final MJDs are different ("<<fIniTime.GetMjd()<<"!="<<fFinTime.GetMjd()<<")" << endl;
|
---|
159 | return kFALSE;
|
---|
160 | }
|
---|
161 |
|
---|
162 | #ifdef DEBUG
|
---|
163 | cout << endl << "********************" << endl;
|
---|
164 | cout << "Run number: " << fRunHeader->GetRunNumber() << endl;
|
---|
165 | cout << "Number of events: " << fNEvts << endl;
|
---|
166 | cout << "First event: " << fFirstEvt << endl;
|
---|
167 | cout << "Initial MJD date: " << fIniTime.GetMjd() << endl;
|
---|
168 | cout << "Final MJD date: " << fFinTime.GetMjd() << endl;
|
---|
169 | cout << "Delta t: " << fDeltaT << endl;
|
---|
170 | #endif
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | // Compute the event time
|
---|
175 | // FIXME: for the time being, this is computed by assuming constant event rate
|
---|
176 | MTime eventTime;
|
---|
177 | Double_t newMJD = fIniTime.GetMjd() + (fFinTime.GetMjd()-fIniTime.GetMjd())*(fEvtHeader->GetDAQEvtNumber()-fFirstEvt)/fNEvts;
|
---|
178 | eventTime.SetMjd(newMJD);
|
---|
179 |
|
---|
180 | // de-rotate the source position
|
---|
181 | const MAstroSky2Local Observation(eventTime, *fObservatory);
|
---|
182 | Double_t rotationAngle = Observation.RotationAngle(fRA,fDEC);
|
---|
183 |
|
---|
184 | Float_t c = TMath::Cos(rotationAngle);
|
---|
185 | Float_t s = TMath::Sin(rotationAngle);
|
---|
186 | // perform a rotation of -rotationAngle to move the source back to the "initial" position
|
---|
187 | Float_t newX = c*fSrcPos->GetX()+s*fSrcPos->GetY();
|
---|
188 | Float_t newY = -s*fSrcPos->GetX()+c*fSrcPos->GetY();
|
---|
189 |
|
---|
190 | #ifdef DEBUG
|
---|
191 | Double_t rotationAngleComp = fObservatory->RotationAngle(0.1256,2.63);
|
---|
192 | cout << "Event " << fEvtHeader->GetDAQEvtNumber() << endl;
|
---|
193 | cout << "newMJD=" << newMJD <<", rotationAngle=" << rotationAngle <<", rotationAngleComp=" << rotationAngleComp << ", oldX="<<fIniSrcPos.GetX()<< ", oldY="<<fIniSrcPos.GetY()<< ", newX="<<newX<< ", newY="<<newY << endl,
|
---|
194 | #endif
|
---|
195 |
|
---|
196 | fSrcPos->SetX(newX);
|
---|
197 | fSrcPos->SetY(newY);
|
---|
198 | fDCA->SetRefPoint(newX,newY);
|
---|
199 |
|
---|
200 | return kTRUE;
|
---|
201 | }
|
---|