source: branches/MarsMoreSimulationTruth/mimage/MHHillasSrc.cc@ 18752

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