source: trunk/MagicSoft/Mars/mpointing/MHSrcPosCam.cc@ 9029

Last change on this file since 9029 was 9000, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 6.2 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(Bool_t wobble, const char *name, const char *title)
60 : fTimeEffOn(NULL), fEffOnTime(NULL), fSourcePos(NULL),
61 fPositions("TVector2", 50000)
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 = wobble ? 0.5499 : 0.2499;
81 const Int_t n = wobble ? 101 : 51;
82
83 MBinning bins;
84 bins.SetEdges(n, -x, x); // bin=0.01ø ~0.5SE
85
86 MH::SetBinning(&fHist, &bins, &bins);
87}
88
89Bool_t MHSrcPosCam::SetupFill(const MParList *pl)
90{
91 MGeomCam *geom = (MGeomCam*)pl->FindObject("MGeomCam");
92 if (!geom)
93 {
94 *fLog << err << "ERROR - MGeomCam not found... aborting." << endl;
95 return kFALSE;
96 }
97
98 fTimeEffOn = (MTime*) pl->FindObject("MTimeEffectiveOnTime");
99 fEffOnTime = (MParameterD*)pl->FindObject("MEffectiveOnTime");
100
101 if (!fTimeEffOn && fEffOnTime)
102 {
103 *fLog << err << "ERROR - MTimeEffOnTime not found... aborting." << endl;
104 return kFALSE;
105 }
106 if (!fEffOnTime && fTimeEffOn)
107 {
108 *fLog << err << "ERROR - MEffectiveOnTime not found... aborting." << endl;
109 return kFALSE;
110 }
111
112 if (!fEffOnTime && !fTimeEffOn)
113 *fLog << inf << "Neither MTimeEffOnTime nor MEffectiveOnTime found... assuming MC." << endl;
114 else
115 fTimeLastEffOn = MTime();
116
117 const MPointingPos *pos = (MPointingPos*)pl->FindObject("MSourcePos", "MPointingPos");
118
119 const TString src = pos ? pos->GetString("radec") : "MonteCarlo";
120 fHist.SetTitle(MString::Format("SrcPos distribution in camera: %s", src.Data()));
121
122 fHist.Reset();
123 fConvMm2Deg = geom->GetConvMm2Deg();
124 fNum = 0;
125
126 return kTRUE;
127}
128
129// --------------------------------------------------------------------------
130//
131// All source positions are buffered until the time of the effective on
132// time time stamp changes. Then the observation time is split into
133// identical parts and the histogram is filled by these events. The
134// effective on time time stamp is reset and the buffered source positions
135// deleted.
136//
137Bool_t MHSrcPosCam::Fill(const MParContainer *par, const Stat_t w)
138{
139 const MSrcPosCam *cam = dynamic_cast<const MSrcPosCam*>(par);
140 if (!cam)
141 {
142 *fLog << err << dbginf << "Got no MSrcPosCam as argument of Fill()..." << endl;
143 return kFALSE;
144 }
145
146 if (!fEffOnTime)
147 {
148 const TVector2 v(cam->GetXY()*fConvMm2Deg);
149 fHist.Fill(v.X(), v.Y(), w);
150 return kTRUE;
151 }
152
153 // Increase array size if necessary
154 if (fNum==fPositions.GetSize())
155 fPositions.Expand(fNum*2);
156
157 // buffer position into array (could be speed up a little bit more
158 // by using ExpandCreate and memcpy)
159 new (fPositions[fNum++]) TVector2(cam->GetXY()*fConvMm2Deg);
160
161 // Check if there is a new effective on time
162 if (fTimeLastEffOn==MTime())
163 fTimeLastEffOn=*fTimeEffOn;
164
165 if (fTimeLastEffOn == *fTimeEffOn)
166 return kTRUE;
167
168 // Split the observation time to all buffered events
169 const Double_t scale = fEffOnTime->GetVal()/fNum;
170
171 // Fill histogram from array
172 for (int i=0; i<fNum; i++)
173 {
174 const TVector2 &v = (TVector2&)*fPositions[i];
175 fHist.Fill(v.X(), v.Y(), scale*w);
176 }
177
178 // reset time stamp and remove all buffered positions
179 fTimeLastEffOn = *fTimeEffOn;
180 fNum = 0;
181
182 return kTRUE;
183}
184
185// --------------------------------------------------------------------------
186//
187void MHSrcPosCam::Paint(Option_t *)
188{
189 MH::SetPalette("pretty", 99);
190}
191
192// --------------------------------------------------------------------------
193//
194void MHSrcPosCam::Draw(Option_t *)
195{
196 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
197 pad->SetBorderMode(0);
198
199 //pad->Divide(2,2);
200
201 gPad->SetLeftMargin(0.25);
202 gPad->SetRightMargin(0.25);
203
204 gPad->SetGridx();
205 gPad->SetGridy();
206
207 AppendPad();
208
209 fHist.Draw("colz");
210
211 if (fHist.GetXaxis()->GetXmax()>0.5)
212 {
213 // Typical wobble distance +/- 1 shaftencoder step
214 TEllipse el;
215 el.SetFillStyle(4000);
216 el.SetLineColor(kBlack);
217 el.SetLineStyle(kDashed);
218 el.DrawEllipse(0, 0, 0.4, 0, 0, 360, 0);
219 el.SetLineColor(17);
220 el.DrawEllipse(0, 0, 0.4-0.022, 0, 0, 360, 0);
221 el.DrawEllipse(0, 0, 0.4+0.022, 0, 0, 360, 0);
222 }
223}
224
Note: See TracBrowser for help on using the repository browser.