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

Last change on this file since 9613 was 9361, 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), fGeom(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 fGeom = (MGeomCam*)pl->FindObject("MGeomCam");
92 if (!fGeom)
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 fNum = 0;
124
125 return kTRUE;
126}
127
128// --------------------------------------------------------------------------
129//
130// All source positions are buffered until the time of the effective on
131// time time stamp changes. Then the observation time is split into
132// identical parts and the histogram is filled by these events. The
133// effective on time time stamp is reset and the buffered source positions
134// deleted.
135//
136Int_t MHSrcPosCam::Fill(const MParContainer *par, const Stat_t w)
137{
138 const MSrcPosCam *cam = dynamic_cast<const MSrcPosCam*>(par);
139 if (!cam)
140 {
141 *fLog << err << dbginf << "Got no MSrcPosCam as argument of Fill()..." << endl;
142 return kERROR;
143 }
144
145 if (!fEffOnTime)
146 {
147 const TVector2 v(cam->GetXY()*fGeom->GetConvMm2Deg());
148 fHist.Fill(v.X(), v.Y(), w);
149 return kTRUE;
150 }
151
152 // Increase array size if necessary
153 if (fNum==fPositions.GetSize())
154 fPositions.Expand(fNum*2);
155
156 // buffer position into array (could be speed up a little bit more
157 // by using ExpandCreate and memcpy)
158 new (fPositions[fNum++]) TVector2(cam->GetXY()*fGeom->GetConvMm2Deg());
159
160 // Check if there is a new effective on time
161 if (fTimeLastEffOn==MTime())
162 fTimeLastEffOn=*fTimeEffOn;
163
164 if (fTimeLastEffOn == *fTimeEffOn)
165 return kTRUE;
166
167 // Split the observation time to all buffered events
168 const Double_t scale = fEffOnTime->GetVal()/fNum;
169
170 // Fill histogram from array
171 for (int i=0; i<fNum; i++)
172 {
173 const TVector2 &v = (TVector2&)*fPositions[i];
174 fHist.Fill(v.X(), v.Y(), scale*w);
175 }
176
177 // reset time stamp and remove all buffered positions
178 fTimeLastEffOn = *fTimeEffOn;
179 fNum = 0;
180
181 return kTRUE;
182}
183
184// --------------------------------------------------------------------------
185//
186void MHSrcPosCam::Paint(Option_t *)
187{
188 MH::SetPalette("pretty", 99);
189}
190
191// --------------------------------------------------------------------------
192//
193void MHSrcPosCam::Draw(Option_t *)
194{
195 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
196 pad->SetBorderMode(0);
197
198 //pad->Divide(2,2);
199
200 gPad->SetLeftMargin(0.25);
201 gPad->SetRightMargin(0.25);
202
203 gPad->SetGridx();
204 gPad->SetGridy();
205
206 AppendPad();
207
208 fHist.Draw("colz");
209
210 if (fHist.GetXaxis()->GetXmax()>0.5)
211 {
212 // Typical wobble distance +/- 1 shaftencoder step
213 TEllipse el;
214 el.SetFillStyle(0);
215 el.SetLineColor(kBlack);
216 el.SetLineStyle(kDashed);
217 el.DrawEllipse(0, 0, 0.4, 0, 0, 360, 0);
218 el.SetLineColor(17);
219 el.DrawEllipse(0, 0, 0.4-0.022, 0, 0, 360, 0);
220 el.DrawEllipse(0, 0, 0.4+0.022, 0, 0, 360, 0);
221 }
222}
223
Note: See TracBrowser for help on using the repository browser.