source: branches/Mars_McMismatchStudy/mhist/MHCamEventRot.cc@ 18815

Last change on this file since 18815 was 9851, checked in by tbretz, 14 years ago
Changed MH::SetBinning and similar functions to take references instead of pointers as arguments. For convenience wrappers for the old style functions are provided.
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 const MBinning b(41, -r, r);
131 SetBinning(fHist, b, b);
132 }
133 else
134 SetBinning(fHist, *bins, *bins);
135
136 fPointPos = (MPointingPos*)plist->FindObject(AddSerialNumber("MPointingPos"));
137 if (!fPointPos)
138 *fLog << warn << "MPointingPos not found... no derotation." << endl;
139
140 fTime = (MTime*)plist->FindObject(AddSerialNumber(fNameTime));
141 if (!fTime)
142 *fLog << warn << "MTime not found... no derotation." << endl;
143
144 fObservatory = (MObservatory*)plist->FindObject(AddSerialNumber("MObservatory"));
145 if (!fObservatory)
146 *fLog << warn << "MObservatory not found... no derotation." << endl;
147
148 // FIXME: Because the pointing position could change we must check
149 // for the current pointing position and add a offset in the
150 // Fill function!
151 if (fPointPos)
152 {
153 fRa = fPointPos->GetRa();
154 fDec = fPointPos->GetDec();
155 }
156
157 if (bins && bins->HasTitle())
158 fHist.SetZTitle(bins->GetTitle());
159 else
160 if (fTitle!=gsDefTitle)
161 {
162 fHist.SetTitle(fTitle);
163 fHist.SetXTitle("x [\\circ]");
164 fHist.SetYTitle("y [\\circ]");
165 }
166 else
167 if (!fTitle.Contains(";"))
168 fHist.SetZTitle(fUseThreshold==kNoBound?"a.u.":"Counts");
169
170 return kTRUE;
171}
172
173// --------------------------------------------------------------------------
174//
175// Fill the histogram. For details see the code or the class description
176//
177Int_t MHCamEventRot::Fill(const MParContainer *par, const Stat_t w)
178{
179 const MCamEvent *evt = dynamic_cast<const MCamEvent*>(par);
180 if (!evt)
181 {
182 *fLog << err << "MHCamEventRot::Fill: No container specified!" << endl;
183 return kERROR;
184 }
185
186 // Get max radius...
187 // const Double_t maxr = fGeom->GetMaxRadius()*fGeom->GetConvMm2Deg();
188
189 // Get camera rotation angle
190 Double_t rho = 0;
191 if (fTime && fObservatory && fPointPos)
192 rho = fPointPos->RotationAngle(*fObservatory, *fTime);
193 //if (fPointPos)
194 // rho = fPointPos->RotationAngle(*fObservatory);
195
196 // Get number of bins and bin-centers
197 const Int_t nx = fHist.GetNbinsX();
198 const Int_t ny = fHist.GetNbinsY();
199 Axis_t cx[nx];
200 Axis_t cy[ny];
201 fHist.GetXaxis()->GetCenter(cx);
202 fHist.GetYaxis()->GetCenter(cy);
203
204 for (int ix=0; ix<nx; ix++)
205 {
206 for (int iy=0; iy<ny; iy++)
207 {
208 // check distance... to get a circle plot
209 //if (TMath::Hypot(cx[ix], cy[iy])>maxr)
210 // continue;
211
212 // rotate center of bin
213 TVector2 v(cx[ix], cy[iy]);
214 if (rho!=0)
215 v=v.Rotate(rho);
216
217 // FIXME: slow! Create Lookup table instead!
218 const Int_t idx = fGeom->GetPixelIdxDeg(v);
219
220 Double_t val;
221 if (idx<0 || !evt->GetPixelContent(val, idx, *fGeom, fType))
222 continue;
223
224 // Fill histogram
225 if (fUseThreshold!=kNoBound)
226 {
227 if ((val>fThreshold && fUseThreshold==kIsLowerBound) ||
228 (val<fThreshold && fUseThreshold==kIsUpperBound))
229 fHist.Fill(cx[ix], cy[iy]);
230 }
231 else
232 fHist.Fill(cx[ix], cy[iy], val);
233 }
234 }
235
236 return kTRUE;
237}
238
239// --------------------------------------------------------------------------
240//
241// Get the MAstroCatalog corresponding to fRa, fDec. The limiting magnitude
242// is set to 9, while the fov is equal to the current fov of the false
243// source plot.
244//
245TObject *MHCamEventRot::GetCatalog()
246{
247 const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));
248
249 // Create catalog...
250 MAstroCatalog stars;
251 stars.SetLimMag(9);
252 stars.SetGuiActive(kFALSE);
253 stars.SetRadiusFOV(maxr);
254 stars.SetRaDec(fRa*TMath::DegToRad()*15, fDec*TMath::DegToRad());
255 stars.ReadBSC("bsc5.dat");
256
257 TObject *o = (MAstroCatalog*)stars.Clone();
258 o->SetBit(kCanDelete);
259
260 return o;
261}
262
263// --------------------------------------------------------------------------
264//
265// Draw the histogram
266//
267void MHCamEventRot::Draw(Option_t *opt)
268{
269 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
270 pad->SetBorderMode(0);
271
272 AppendPad("");
273
274 // draw the 2D histogram Sigmabar versus Theta
275 fHist.Draw(opt);
276 TObject *catalog = GetCatalog();
277 catalog->Draw("mirror same");
278}
Note: See TracBrowser for help on using the repository browser.