source: trunk/Mars/mimage/MHVsSize.cc@ 12937

Last change on this file since 12937 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.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 2001 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Author(s): Wolfgang Wittek 2002 <mailto:wittek@mppmu.mpg.de>
20!
21! Copyright: MAGIC Software Development, 2000-2009
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MHVsSize
29//
30// This class contains histograms for the source independent image parameters
31//
32// ClassVersion 2:
33// ---------------
34// - fMm2Deg
35// - fUseMmScale
36//
37/////////////////////////////////////////////////////////////////////////////
38#include "MHVsSize.h"
39
40#include <TH2.h>
41#include <TPad.h>
42#include <TStyle.h>
43#include <TCanvas.h>
44
45#include "MLog.h"
46#include "MLogManip.h"
47
48#include "MParList.h"
49
50#include "MHillas.h"
51#include "MHillasSrc.h"
52#include "MHillasExt.h"
53#include "MNewImagePar.h"
54#include "MGeomCam.h"
55#include "MBinning.h"
56
57ClassImp(MHVsSize);
58
59using namespace std;
60
61// --------------------------------------------------------------------------
62//
63// Setup four histograms for Width, Length
64//
65MHVsSize::MHVsSize(const char *name, const char *title)
66 : fGeom(0), fHillas(0), fHillasExt(0), fNewImagePar(0)
67{
68 //
69 // set the name and title of this object
70 //
71 fName = name ? name : "MHVsSize";
72 fTitle = title ? title : "Source independent image parameters";
73
74 fLength.SetNameTitle("Length", "Length vs. Size");
75 fWidth.SetNameTitle( "Width", "Width vs. Size");
76 fDist.SetNameTitle( "Dist", "Dist vs. Size");
77 fConc1.SetNameTitle( "Conc1", "Conc1 vs. Size");
78 fArea.SetNameTitle( "Area", "Area vs. Size");
79 fM3Long.SetNameTitle("M3Long", "M3Long vs. Size");
80
81 fLength.SetDirectory(NULL);
82 fWidth.SetDirectory(NULL);
83 fDist.SetDirectory(NULL);
84 fConc1.SetDirectory(NULL);
85 fArea.SetDirectory(NULL);
86 fM3Long.SetDirectory(NULL);
87
88 fLength.SetXTitle("Size [phe]");
89 fWidth.SetXTitle("Size [phe]");
90 fDist.SetXTitle("Size [phe]");
91 fConc1.SetXTitle("Size [phe]");
92 fArea.SetXTitle("Size [phe]");
93 fM3Long.SetXTitle("Size [phe]");
94
95 fLength.SetYTitle("Length [\\circ]");
96 fWidth.SetYTitle("Width [\\circ]");
97 fDist.SetYTitle("Distance [\\circ]");
98 fConc1.SetYTitle("Conc1 [ratio]");
99 fArea.SetYTitle("Area [\\circ^{2}]");
100 fM3Long.SetYTitle("M3Long [\\circ]");
101
102 const MBinning binse( 50, 10, 1e5, "", "log");
103 const MBinning binsc(100, 3e-3, 1, "", "log");
104 const MBinning binsl(100, 0, 0.5);
105 const MBinning binsd(100, 0, 2.0);
106 const MBinning binsa(100, 0, 0.25);
107 const MBinning binsm(100, -1.5, 1.5);
108
109 MH::SetBinning(fLength, binse, binsl);
110 MH::SetBinning(fWidth, binse, binsl);
111 MH::SetBinning(fDist, binse, binsd);
112 MH::SetBinning(fConc1, binse, binsc);
113 MH::SetBinning(fArea, binse, binsa);
114 MH::SetBinning(fM3Long, binse, binsm);
115
116 fLength.UseCurrentStyle();
117 fWidth.UseCurrentStyle();
118 fDist.UseCurrentStyle();
119 fConc1.UseCurrentStyle();
120 fArea.UseCurrentStyle();
121 fM3Long.UseCurrentStyle();
122}
123
124// --------------------------------------------------------------------------
125//
126// Setup the Binning for the histograms automatically if the correct
127// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
128// are found in the parameter list
129// Use this function if you want to set the conversion factor which
130// is used to convert the mm-scale in the camera plain into the deg-scale
131// used for histogram presentations. The conversion factor is part of
132// the camera geometry. Please create a corresponding MGeomCam container.
133//
134Bool_t MHVsSize::SetupFill(const MParList *plist)
135{
136 fGeom = (MGeomCam*)plist->FindObject("MGeomCam");
137 if (!fGeom)
138 {
139 *fLog << err << "MGeomCam not found... abort." << endl;
140 return kFALSE;
141 }
142
143 fHillas = (MHillas*)plist->FindObject("MHillas");
144 if (!fHillas)
145 {
146 *fLog << err << "MHillas not found... abort." << endl;
147 return kFALSE;
148 }
149
150 fHillasExt = (MHillasExt*)plist->FindObject("MHillasExt");
151 if (!fHillasExt)
152 {
153 *fLog << err << "MHillasExt not found... abort." << endl;
154 return kFALSE;
155 }
156
157 fNewImagePar = (MNewImagePar*)plist->FindObject("MNewImagePar");
158 if (!fNewImagePar)
159 {
160 *fLog << err << "MNewImagePar not found... abort." << endl;
161 return kFALSE;
162 }
163
164 /*
165 ApplyBinning(*plist, "Width", "Size", fWidth);
166 ApplyBinning(*plist, "Length", "Size", fLength);
167 ApplyBinning(*plist, "Area", "Size", fArea);
168 ApplyBinning(*plist, "M3Long", "Size", fM3Long);
169 ApplyBinning(*plist, "Conc1", "Size", fConc1);
170 */
171
172 return kTRUE;
173}
174
175// --------------------------------------------------------------------------
176//
177// Fill the histograms with data from a MHillas-Container.
178// Be careful: Only call this with an object of type MHillas
179//
180Int_t MHVsSize::Fill(const MParContainer *par, const Stat_t w)
181{
182 const MHillasSrc *src = dynamic_cast<const MHillasSrc*>(par);
183 if (!src)
184 {
185 *fLog << err << "MHVsSize::Fill: Wrong argument... abort." << endl;
186 return kERROR;
187 }
188
189 const Double_t scale = fGeom->GetConvMm2Deg();
190
191 fLength.Fill(fHillas->GetSize(), scale*fHillas->GetLength(), w);
192 fWidth.Fill( fHillas->GetSize(), scale*fHillas->GetWidth(), w);
193 fDist.Fill( fHillas->GetSize(), scale*src->GetDist(), w);
194 fConc1.Fill( fHillas->GetSize(), fNewImagePar->GetConc1(), w);
195 fArea.Fill( fHillas->GetSize(), scale*scale*fHillas->GetArea(), w);
196 fM3Long.Fill(fHillas->GetSize(), scale*fHillasExt->GetM3Long()*TMath::Sign(1.0f, src->GetCosDeltaAlpha()), w);
197
198 return kTRUE;
199}
200
201// --------------------------------------------------------------------------
202//
203// Creates a new canvas and draws the four histograms into it.
204// Be careful: The histograms belongs to this object and won't get deleted
205// together with the canvas.
206//
207void MHVsSize::Draw(Option_t *o)
208{
209 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
210 pad->SetBorderMode(0);
211
212 AppendPad("");
213
214 TString opt(o);
215 opt.ToLower();
216
217 // FIXME: If same-option given make two independant y-axis!
218 const Bool_t same = opt.Contains("same");
219
220 if (!same)
221 pad->Divide(3,2);
222 else
223 {
224 fLength.SetName("LengthSame");
225 fWidth.SetName("WidthSame");
226 fDist.SetName("DistSame");
227 fConc1.SetName("Conc1Same");
228 fArea.SetName("AreaSame");
229 fM3Long.SetName("M3LongSame");
230
231 fLength.SetDirectory(0);
232 fWidth.SetDirectory(0);
233 fDist.SetDirectory(0);
234 fConc1.SetDirectory(0);
235 fArea.SetDirectory(0);
236 fM3Long.SetDirectory(0);
237
238 fDist.SetMarkerColor(kBlue);
239 fConc1.SetMarkerColor(kBlue);
240 fWidth.SetMarkerColor(kBlue);
241 fLength.SetMarkerColor(kBlue);
242 fArea.SetMarkerColor(kBlue);
243 fM3Long.SetMarkerColor(kBlue);
244 }
245
246 pad->cd(1);
247 gPad->SetBorderMode(0);
248 gPad->SetLogx();
249 RemoveFromPad("LengthSame");
250 fLength.Draw(same?"same":"");
251
252 pad->cd(2);
253 gPad->SetBorderMode(0);
254 gPad->SetLogx();
255 RemoveFromPad("WidthSame");
256 fWidth.Draw(same?"same":"");
257
258 pad->cd(3);
259 gPad->SetBorderMode(0);
260 gPad->SetLogx();
261 RemoveFromPad("DistSame");
262 fDist.Draw(same?"same":"");
263
264 pad->cd(4);
265 gPad->SetBorderMode(0);
266 gPad->SetLogx();
267 RemoveFromPad("AreaSame");
268 fArea.Draw(same?"same":"");
269
270 pad->cd(5);
271 gPad->SetBorderMode(0);
272 gPad->SetLogx();
273 RemoveFromPad("M3LongSame");
274 fM3Long.Draw(same?"same":"");
275
276 pad->cd(6);
277 gPad->SetBorderMode(0);
278 gPad->SetLogx();
279 gPad->SetLogy();
280 RemoveFromPad("Conc1Same");
281 fConc1.Draw(same?"same":"");
282}
Note: See TracBrowser for help on using the repository browser.