source: trunk/MagicSoft/Mars/mhist/MHCamEventRot.cc@ 3784

Last change on this file since 3784 was 3784, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.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): Thomas Bretz, 4/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHCamEventRot
28//
29// Derotate MCamEvent before filling a 2D histogram.
30//
31//////////////////////////////////////////////////////////////////////////////
32#include "MHCamEventRot.h"
33
34#include <TF1.h>
35#include <TH2.h>
36#include <TGraph.h>
37#include <TStyle.h>
38#include <TCanvas.h>
39#include <TPaveText.h>
40#include <TStopwatch.h>
41
42#include "MGeomCam.h"
43#include "MSrcPosCam.h"
44#include "MHillasSrc.h"
45#include "MTime.h"
46#include "MObservatory.h"
47#include "MPointingPos.h"
48#include "MAstroCatalog.h"
49#include "MAstroSky2Local.h"
50#include "MStatusDisplay.h"
51#include "MMath.h"
52
53#include "MBinning.h"
54#include "MParList.h"
55#include "MCamEvent.h"
56
57#include "MLog.h"
58#include "MLogManip.h"
59
60ClassImp(MHCamEventRot);
61
62using namespace std;
63
64// --------------------------------------------------------------------------
65//
66// Default Constructor
67//
68MHCamEventRot::MHCamEventRot(const char *name, const char *title)
69 : fTime(0), fPointPos(0), fObservatory(0), fType(0)
70{
71 //
72 // set the name and title of this object
73 //
74 fName = name ? name : "MHCamEventRot";
75 fTitle = title ? title : "Plot showing derotated MCamEvent data";
76
77 fHist.SetDirectory(NULL);
78
79 fHist.SetName("Alpha");
80 fHist.SetTitle("2D-plot of MCamEvents (derotated)");
81 fHist.SetXTitle("x [\\circ]");
82 fHist.SetYTitle("y [\\circ]");
83 fHist.SetZTitle("Counts");
84}
85
86// --------------------------------------------------------------------------
87//
88// Set binnings (takes BinningCamEvent) and prepare filling of the
89// histogram.
90//
91// Also search for MTime, MObservatory and MPointingPos
92//
93Bool_t MHCamEventRot::SetupFill(const MParList *plist)
94{
95 fGeom = (MGeomCam*)plist->FindObject("MGeomCam");
96 if (!fGeom)
97 {
98 *fLog << err << "MGeomCam not found... aborting." << endl;
99 return kFALSE;
100 }
101
102 MBinning binsa;
103 binsa.SetEdges(18, 0, 90);
104
105 const MBinning *bins = (MBinning*)plist->FindObject("BinningCamEvent");
106 if (!bins)
107 {
108 const Float_t r = (fGeom ? fGeom->GetMaxRadius()/3 : 200)*fGeom->GetConvMm2Deg();
109
110 MBinning b;
111 b.SetEdges(20, -r, r);
112 SetBinning(&fHist, &b, &b);
113 }
114 else
115 SetBinning(&fHist, bins, bins);
116
117 fPointPos = (MPointingPos*)plist->FindObject(AddSerialNumber("MPointingPos"));
118 if (!fPointPos)
119 *fLog << warn << "MPointingPos not found... no derotation." << endl;
120
121 fTime = (MTime*)plist->FindObject(AddSerialNumber("MTime"));
122 if (!fTime)
123 *fLog << warn << "MTime not found... no derotation." << endl;
124
125 fObservatory = (MObservatory*)plist->FindObject(AddSerialNumber("MObservatory"));
126 if (!fObservatory)
127 *fLog << warn << "MObservatory not found... no derotation." << endl;
128
129 // FIXME: Because the pointing position could change we must check
130 // for the current pointing position and add a offset in the
131 // Fill function!
132 fRa = fPointPos->GetRa();
133 fDec = fPointPos->GetDec();
134
135 return kTRUE;
136}
137
138// --------------------------------------------------------------------------
139//
140// Fill the histogram. For details see the code or the class description
141//
142Bool_t MHCamEventRot::Fill(const MParContainer *par, const Stat_t w)
143{
144 const MCamEvent *evt = dynamic_cast<const MCamEvent*>(par);
145 if (!evt)
146 {
147 *fLog << err << "MHCamEventRot::Fill: No container specified!" << endl;
148 return kFALSE;
149 }
150
151 // Get max radius...
152 // const Double_t maxr = fGeom->GetMaxRadius()*fGeom->GetConvMm2Deg();
153
154 // Get camera rotation angle
155 Double_t rho = 0;
156 if (fTime && fObservatory && fPointPos)
157 rho = fPointPos->RotationAngle(*fObservatory, *fTime);
158 //if (fPointPos)
159 // rho = fPointPos->RotationAngle(*fObservatory);
160
161 // Get number of bins and bin-centers
162 const Int_t nx = fHist.GetNbinsX();
163 const Int_t ny = fHist.GetNbinsY();
164 Axis_t cx[nx];
165 Axis_t cy[ny];
166 fHist.GetXaxis()->GetCenter(cx);
167 fHist.GetYaxis()->GetCenter(cy);
168
169 for (int ix=0; ix<nx; ix++)
170 {
171 for (int iy=0; iy<ny; iy++)
172 {
173 // check distance... to get a circle plot
174 //if (TMath::Hypot(cx[ix], cy[iy])>maxr)
175 // continue;
176
177 // rotate center of bin
178 TVector2 v(cx[ix], cy[iy]);
179 if (rho!=0)
180 v=v.Rotate(rho);
181
182 // FIXME: slow! Create Lookup table instead!
183 const Int_t idx = fGeom->GetPixelIdxDeg(v);
184
185 Double_t val;
186 if (idx<0 || !evt->GetPixelContent(val, idx, *fGeom, fType))
187 continue;
188
189 // Fill histogram
190 fHist.Fill(cx[ix], cy[iy], val);
191 }
192 }
193
194 return kTRUE;
195}
196
197// --------------------------------------------------------------------------
198//
199// Get the MAstroCatalog corresponding to fRa, fDec. The limiting magnitude
200// is set to 9, while the fov is equal to the current fov of the false
201// source plot.
202//
203TObject *MHCamEventRot::GetCatalog()
204{
205 const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
206
207 // Create catalog...
208 MAstroCatalog stars;
209 stars.SetLimMag(9);
210 stars.SetGuiActive(kFALSE);
211 stars.SetRadiusFOV(maxr);
212 stars.SetRaDec(fRa*TMath::DegToRad()*15, fDec*TMath::DegToRad());
213 stars.ReadBSC("bsc5.dat");
214
215 TObject *o = (MAstroCatalog*)stars.Clone();
216 o->SetBit(kCanDelete);
217
218 return o;
219}
220
221// --------------------------------------------------------------------------
222//
223// Draw the histogram
224//
225void MHCamEventRot::Draw(Option_t *opt)
226{
227 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
228 pad->SetBorderMode(0);
229
230 AppendPad("");
231
232 // draw the 2D histogram Sigmabar versus Theta
233 fHist.Draw(opt);
234 TObject *catalog = GetCatalog();
235 catalog->Draw("mirror same");
236}
Note: See TracBrowser for help on using the repository browser.