source: trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc@ 9340

Last change on this file since 9340 was 9340, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 7.4 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@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25///////////////////////////////////////////////////////////////////////
26//
27// MHHillasSrc
28//
29// This class contains histograms for every Hillas parameter
30//
31///////////////////////////////////////////////////////////////////////
32#include "MHHillasSrc.h"
33
34#include <math.h>
35
36#include <TH1.h>
37#include <TPad.h>
38#include <TCanvas.h>
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MGeomCam.h"
44
45#include "MParList.h"
46
47#include "MHillasSrc.h"
48
49ClassImp(MHHillasSrc);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Setup four histograms for Alpha, and Dist
56//
57MHHillasSrc::MHHillasSrc(const char *name, const char *title)
58 : fGeom(0)
59{
60 //
61 // set the name and title of this object
62 //
63 fName = name ? name : "MHHillasSrc";
64 fTitle = title ? title : "Container for Hillas histograms";
65
66 //
67 // loop over all Pixels and create two histograms
68 // one for the Low and one for the High gain
69 // connect all the histogram with the container fHist
70 //
71 fAlpha = new TH1F("Alpha", "Alpha of Ellipse", 90, -90, 90);
72 fDist = new TH1F("Dist", "Dist of Ellipse", 70, 0, 623);
73 fCosDA = new TH1F("CosDA", "cos(Delta,Alpha) of Ellipse", 101, -1, 1);
74 fDCA = new TH1F("DCA", "Distance of closest aproach", 101, -500, 500);
75 fDCADelta = new TH1F("DCADelta", "Angle between shower and x-axis", 80, 0, 360);
76
77 fAlpha->SetDirectory(NULL);
78 fDist->SetDirectory(NULL);
79 fCosDA->SetDirectory(NULL);
80 fDCA->SetDirectory(NULL);
81 fDCADelta->SetDirectory(NULL);
82
83 fAlpha->SetXTitle("\\alpha [\\circ]");
84 fDist->SetXTitle("Dist [\\circ]");
85 fCosDA->SetXTitle("cos(\\delta,\\alpha)");
86 fDCA->SetXTitle("DCA [\\circ]");
87 fDCADelta->SetXTitle("DCADelta [0, 2\\pi]");
88
89 fAlpha->SetYTitle("Counts");
90 fDist->SetYTitle("Counts");
91 fCosDA->SetYTitle("Counts");
92 fDCA->SetYTitle("Counts");
93 fDCADelta->SetYTitle("Counts");
94
95 fAlpha->SetMinimum(0);
96 fCosDA->SetMinimum(0);
97 fDCADelta->SetMinimum(0);
98}
99
100// --------------------------------------------------------------------------
101//
102// Delete the four histograms
103//
104MHHillasSrc::~MHHillasSrc()
105{
106 delete fAlpha;
107 delete fDist;
108 delete fCosDA;
109 delete fDCA;
110 delete fDCADelta;
111}
112
113// --------------------------------------------------------------------------
114//
115// Setup the Binning for the histograms automatically if the correct
116// instances of MBinning (with the names 'BinningAlpha' and 'BinningDist')
117// are found in the parameter list
118// Use this function if you want to set the conversion factor which
119// is used to convert the mm-scale in the camera plain into the deg-scale
120// used for histogram presentations. The conversion factor is part of
121// the camera geometry. Please create a corresponding MGeomCam container.
122//
123Bool_t MHHillasSrc::SetupFill(const MParList *plist)
124{
125 fGeom = (MGeomCam*)plist->FindObject("MGeomCam");
126 if (!fGeom)
127 {
128 *fLog << err << "MGeomCam not found... abort." << endl;
129 return kFALSE;
130 }
131
132 ApplyBinning(*plist, "Alpha", fAlpha);
133 ApplyBinning(*plist, "Dist", fDist);
134 ApplyBinning(*plist, "DCA", fDCA);
135 ApplyBinning(*plist, "DCADelta", fDCADelta);
136
137 return kTRUE;
138}
139
140// --------------------------------------------------------------------------
141//
142// Fill the four histograms with data from a MHillas-Container.
143// Be careful: Only call this with an object of type MHillas
144//
145Int_t MHHillasSrc::Fill(const MParContainer *par, const Stat_t w)
146{
147 if (!par)
148 {
149 *fLog << err << "MHHillasSrc::Fill: Pointer (!=NULL) expected." << endl;
150 return kERROR;
151 }
152
153 const MHillasSrc &h = *(MHillasSrc*)par;
154
155 const Double_t scale = fGeom->GetConvMm2Deg();
156
157 fAlpha->Fill(h.GetAlpha(), w);
158 fDist ->Fill(h.GetDist()*scale, w);
159 fCosDA->Fill(h.GetCosDeltaAlpha(), w);
160 fDCA ->Fill(h.GetDCA()*scale, w);
161 fDCADelta->Fill(h.GetDCADelta(), w);
162
163 return kTRUE;
164}
165
166// --------------------------------------------------------------------------
167//
168// Creates a new canvas and draws the two histograms into it.
169// Be careful: The histograms belongs to this object and won't get deleted
170// together with the canvas.
171//
172void MHHillasSrc::Draw(Option_t *o)
173{
174 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
175 pad->SetBorderMode(0);
176
177 AppendPad("");
178
179 // FIXME: Display Source position
180
181 // FIXME: If same-option given make two independant y-axis!
182 const TString opt(o);
183 const Bool_t same = opt.Contains("same");
184
185 if (!same)
186 pad->Divide(2,2);
187 else
188 {
189 fAlpha->SetName("AlphaSame");
190 fDist ->SetName("DistSame");
191 fCosDA->SetName("CosDASame");
192 fDCA ->SetName("DCASame");
193 fDCADelta->SetName("DCADeltaSame");
194
195 fAlpha->SetDirectory(0);
196 fDist ->SetDirectory(0);
197 fCosDA->SetDirectory(0);
198 fDCA ->SetDirectory(0);
199 fDCADelta->SetDirectory(0);
200
201 fAlpha->SetLineColor(kGreen);
202 fDist->SetLineColor(kGreen);
203 fDCA->SetLineColor(kGreen);
204 fCosDA->SetLineColor(kGreen);
205 fDCADelta->SetLineColor(kGreen);
206 }
207
208 pad->cd(1);
209 gPad->SetBorderMode(0);
210 gPad->SetGridx();
211 gPad->SetGridy();
212 RemoveFromPad("AlphaSame");
213 fAlpha->Draw(same?"same":"");
214
215 pad->cd(2);
216 gPad->SetBorderMode(0);
217 gPad->SetGridx();
218 gPad->SetGridy();
219 RemoveFromPad("DistSame");
220 fDist->Draw(same?"same":"");
221
222 pad->cd(3);
223 gPad->SetBorderMode(0);
224 gPad->SetGridx();
225 gPad->SetGridy();
226 RemoveFromPad("DCASame");
227 fDCA->Draw(same?"same":"");
228
229 pad->cd(4);
230 gPad->SetBorderMode(0);
231 gPad->SetGridx();
232 gPad->SetGridy();
233
234 TVirtualPad *p = gPad;
235 if (!same)
236 p->Divide(1,2);
237 p->cd(1);
238 gPad->SetBorderMode(0);
239 gPad->SetGridx();
240 gPad->SetGridy();
241 RemoveFromPad("CosDASame");
242 fCosDA->Draw(same?"same":"");
243
244 p->cd(2);
245 gPad->SetBorderMode(0);
246 gPad->SetGridx();
247 gPad->SetGridy();
248 RemoveFromPad("DCADeltaSame");
249 fDCADelta->Draw(same?"same":"");
250}
251
252void MHHillasSrc::Paint(Option_t *opt)
253{
254 if (fCosDA->GetEntries()==0)
255 return;
256
257 TVirtualPad *savepad = gPad;
258 savepad->cd(4);
259 gPad->SetLogy();
260 gPad = savepad;
261}
262
263TH1 *MHHillasSrc::GetHistByName(const TString name) const
264{
265 if (name.Contains("Alpha", TString::kIgnoreCase))
266 return fAlpha;
267 if (name.Contains("Dist", TString::kIgnoreCase))
268 return fDist;
269 if (name.Contains("CosDA", TString::kIgnoreCase))
270 return fCosDA;
271
272 return NULL;
273}
Note: See TracBrowser for help on using the repository browser.