source: branches/AddingGoogleTestEnvironment/mpointing/MHSrcPosCam.cc@ 19779

Last change on this file since 19779 was 14891, checked in by tbretz, 12 years ago
Allow to set the wobble offset directly.
File size: 6.3 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, 2/2006 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2007
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MHSrcPosCam
28//
29//
30// FIXME: Use ReInit...
31//
32//////////////////////////////////////////////////////////////////////////////
33#include "MHSrcPosCam.h"
34
35#include <TVector2.h>
36#include <TCanvas.h>
37#include <TEllipse.h>
38
39#include "MGeomCam.h"
40#include "MSrcPosCam.h"
41#include "MParameters.h"
42#include "MPointingPos.h"
43
44#include "MString.h"
45#include "MBinning.h"
46#include "MParList.h"
47
48#include "MLog.h"
49#include "MLogManip.h"
50
51ClassImp(MHSrcPosCam);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Default Constructor
58//
59MHSrcPosCam::MHSrcPosCam(Float_t offset, const char *name, const char *title)
60 : fTimeEffOn(NULL), fEffOnTime(NULL), fSourcePos(NULL), fGeom(NULL),
61 fPositions("TVector2", 50000), fWobbleOffset(offset)
62{
63 //
64 // set the name and title of this object
65 //
66 fName = name ? name : "MHSrcPosCam";
67 fTitle = title ? title : "Histogram for source position distribution";
68
69 fHist.SetName("SourcePos");
70 fHist.SetTitle("Source position distribution in camera coordinates");
71 fHist.SetXTitle("dx [\\circ]");
72 fHist.SetYTitle("dy [\\circ]");
73 fHist.SetZTitle("T_{eff} [s]");
74 fHist.SetDirectory(NULL);
75 fHist.UseCurrentStyle();
76 fHist.GetXaxis()->CenterTitle();
77 fHist.GetYaxis()->CenterTitle();
78 fHist.SetContour(99);
79
80 const Float_t x = offset>0 ? offset+0.0499 : offset/2+0.0499;
81 const Int_t n = offset>0 ? 101 : 51;
82
83 const MBinning bins(n, -x, x); // bin=0.01ø ~0.5SE
84
85 MH::SetBinning(fHist, bins, bins);
86}
87
88Bool_t MHSrcPosCam::SetupFill(const MParList *pl)
89{
90 fGeom = (MGeomCam*)pl->FindObject("MGeomCam");
91 if (!fGeom)
92 {
93 *fLog << err << "ERROR - MGeomCam not found... aborting." << endl;
94 return kFALSE;
95 }
96
97 fTimeEffOn = (MTime*) pl->FindObject("MTimeEffectiveOnTime");
98 fEffOnTime = (MParameterD*)pl->FindObject("MEffectiveOnTime");
99
100 if (!fTimeEffOn && fEffOnTime)
101 {
102 *fLog << err << "ERROR - MTimeEffOnTime not found... aborting." << endl;
103 return kFALSE;
104 }
105 if (!fEffOnTime && fTimeEffOn)
106 {
107 *fLog << err << "ERROR - MEffectiveOnTime not found... aborting." << endl;
108 return kFALSE;
109 }
110
111 if (!fEffOnTime && !fTimeEffOn)
112 *fLog << inf << "Neither MTimeEffOnTime nor MEffectiveOnTime found... assuming MC." << endl;
113 else
114 fTimeLastEffOn = MTime();
115
116 const MPointingPos *pos = (MPointingPos*)pl->FindObject("MSourcePos", "MPointingPos");
117
118 const TString src = pos ? pos->GetString("radec") : "MonteCarlo";
119 fHist.SetTitle(MString::Format("SrcPos distribution in camera: %s", src.Data()));
120
121 fHist.Reset();
122 fNum = 0;
123
124 return kTRUE;
125}
126
127// --------------------------------------------------------------------------
128//
129// All source positions are buffered until the time of the effective on
130// time time stamp changes. Then the observation time is split into
131// identical parts and the histogram is filled by these events. The
132// effective on time time stamp is reset and the buffered source positions
133// deleted.
134//
135Int_t MHSrcPosCam::Fill(const MParContainer *par, const Stat_t w)
136{
137 const MSrcPosCam *cam = dynamic_cast<const MSrcPosCam*>(par);
138 if (!cam)
139 {
140 *fLog << err << dbginf << "Got no MSrcPosCam as argument of Fill()..." << endl;
141 return kERROR;
142 }
143
144 if (!fEffOnTime)
145 {
146 const TVector2 v(cam->GetXY()*fGeom->GetConvMm2Deg());
147 fHist.Fill(v.X(), v.Y(), w);
148 return kTRUE;
149 }
150
151 // Increase array size if necessary
152 if (fNum==fPositions.GetSize())
153 fPositions.Expand(fNum*2);
154
155 // buffer position into array (could be speed up a little bit more
156 // by using ExpandCreate and memcpy)
157 new (fPositions[fNum++]) TVector2(cam->GetXY()*fGeom->GetConvMm2Deg());
158
159 // Check if there is a new effective on time
160 if (fTimeLastEffOn==MTime())
161 fTimeLastEffOn=*fTimeEffOn;
162
163 if (fTimeLastEffOn == *fTimeEffOn)
164 return kTRUE;
165
166 // Split the observation time to all buffered events
167 const Double_t scale = fEffOnTime->GetVal()/fNum;
168
169 // Fill histogram from array
170 for (int i=0; i<fNum; i++)
171 {
172 const TVector2 &v = (TVector2&)*fPositions[i];
173 fHist.Fill(v.X(), v.Y(), scale*w);
174 }
175
176 // reset time stamp and remove all buffered positions
177 fTimeLastEffOn = *fTimeEffOn;
178 fNum = 0;
179
180 return kTRUE;
181}
182
183// --------------------------------------------------------------------------
184//
185void MHSrcPosCam::Paint(Option_t *)
186{
187 MH::SetPalette("pretty", 99);
188}
189
190// --------------------------------------------------------------------------
191//
192void MHSrcPosCam::Draw(Option_t *)
193{
194 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
195 pad->SetBorderMode(0);
196
197 //pad->Divide(2,2);
198
199 gPad->SetLeftMargin(0.25);
200 gPad->SetRightMargin(0.25);
201
202 gPad->SetGridx();
203 gPad->SetGridy();
204
205 AppendPad();
206
207 fHist.Draw("colz");
208
209 if (fHist.GetXaxis()->GetXmax()>0.5)
210 {
211 // Typical wobble distance +/- 1 shaftencoder step
212 TEllipse el;
213 el.SetFillStyle(0);
214 el.SetLineColor(kBlack);
215 el.SetLineStyle(kDashed);
216 el.DrawEllipse(0, 0, fWobbleOffset, 0, 0, 360, 0);
217 el.SetLineColor(17);
218 el.DrawEllipse(0, 0, fWobbleOffset-0.022, 0, 0, 360, 0);
219 el.DrawEllipse(0, 0, fWobbleOffset+0.022, 0, 0, 360, 0);
220 }
221}
222
Note: See TracBrowser for help on using the repository browser.