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

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