source: tags/Mars-V2.1/mpointing/MHSrcPosCam.cc

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