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

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