source: trunk/MagicSoft/Mars/mimage/MHNewImagePar2.cc@ 7477

Last change on this file since 7477 was 6869, checked in by tbretz, 20 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, 03/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHNewImagePar2
28//
29////////////////////////////////////////////////////////////////////////////
30#include "MHNewImagePar2.h"
31
32#include <math.h>
33
34#include <TH1.h>
35#include <TPad.h>
36#include <TCanvas.h>
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MGeomCam.h"
42#include "MBinning.h"
43#include "MParList.h"
44
45#include "MHillas.h"
46#include "MNewImagePar2.h"
47
48ClassImp(MHNewImagePar2);
49
50using namespace std;
51
52// --------------------------------------------------------------------------
53//
54// Setup histograms
55//
56MHNewImagePar2::MHNewImagePar2(const char *name, const char *title)
57 : fMm2Deg(1), fUseMmScale(kTRUE)
58{
59 fName = name ? name : "MHNewImagePar2";
60 fTitle = title ? title : "Histograms of new image parameters 2";
61
62 fHistBorder1.SetName("Border1");
63 fHistBorder1.SetTitle("Border Line of border pixels (pixel border)");
64 fHistBorder1.SetXTitle("Border");
65 fHistBorder1.SetYTitle("Counts");
66 fHistBorder1.SetDirectory(NULL);
67 fHistBorder1.UseCurrentStyle();
68 fHistBorder1.SetFillStyle(4000);
69
70 fHistBorder2.SetName("Border2");
71 fHistBorder2.SetTitle("Border Line of border pixels (pixel center)");
72 fHistBorder2.SetXTitle("Border");
73 fHistBorder2.SetYTitle("Counts");
74 fHistBorder2.SetDirectory(NULL);
75 fHistBorder2.UseCurrentStyle();
76 fHistBorder2.SetLineColor(kBlue);
77 fHistBorder2.SetFillStyle(4000);
78}
79
80// --------------------------------------------------------------------------
81//
82// Setup the Binning for the histograms automatically if the correct
83// instances of MBinning
84//
85Bool_t MHNewImagePar2::SetupFill(const MParList *plist)
86{
87 MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
88 if (!geom)
89 *fLog << warn << GetDescriptor() << ": No Camera Geometry available. Using mm-scale for histograms." << endl;
90 else
91 {
92 fMm2Deg = geom->GetConvMm2Deg();
93 SetMmScale(kFALSE);
94 }
95
96 const MBinning *bins = (MBinning*)plist->FindObject("BinningBorder");
97 if (!bins)
98 {
99 const float r = geom ? 10 : 2967;
100
101 MBinning b;
102 b.SetEdges(87, 0, r);
103 b.Apply(fHistBorder1);
104 b.Apply(fHistBorder2);
105 }
106 else
107 {
108 bins->Apply(fHistBorder1);
109 bins->Apply(fHistBorder2);
110 }
111
112 return kTRUE;
113}
114
115
116// --------------------------------------------------------------------------
117//
118// Fill the histograms with data from a MNewImagePar2 container.
119//
120Bool_t MHNewImagePar2::Fill(const MParContainer *par, const Stat_t w)
121{
122 const MNewImagePar2 *h = dynamic_cast<const MNewImagePar2*>(par);
123 if (!h)
124 {
125 *fLog << err << "MHNewImagePar2::Fill: Pointer (!=NULL) expected." << endl;
126 return kFALSE;
127 }
128
129 const Double_t scale = fUseMmScale ? 1 : fMm2Deg;
130
131 fHistBorder1.Fill(h->GetBorderLinePixel() *scale, w);
132 fHistBorder2.Fill(h->GetBorderLineCenter()*scale, w);
133
134 return kTRUE;
135}
136
137// --------------------------------------------------------------------------
138//
139// With this function you can convert the histogram ('on the fly') between
140// degrees and millimeters.
141//
142void MHNewImagePar2::SetMmScale(Bool_t mmscale)
143{
144 if (fUseMmScale == mmscale)
145 return;
146
147 if (fMm2Deg<0)
148 {
149 *fLog << warn << dbginf << "Warning - Sorry, no conversion factor for conversion available." << endl;
150 return;
151 }
152
153 const Double_t scale = mmscale ? 1./fMm2Deg : fMm2Deg;
154 MH::ScaleAxis(&fHistBorder1, scale);
155 MH::ScaleAxis(&fHistBorder2, scale);
156
157 if (mmscale)
158 {
159 fHistBorder1.SetXTitle("L [mm]");
160 fHistBorder2.SetXTitle("L [mm]");
161 }
162 else
163 {
164 fHistBorder1.SetXTitle("L [\\circ]");
165 fHistBorder2.SetXTitle("L [\\circ]");
166 }
167
168 fUseMmScale = mmscale;
169}
170
171// --------------------------------------------------------------------------
172//
173// Use this function to setup your own conversion factor between degrees
174// and millimeters. The conversion factor should be the one calculated in
175// MGeomCam. Use this function with Caution: You could create wrong values
176// by setting up your own scale factor.
177//
178void MHNewImagePar2::SetMm2Deg(Float_t mmdeg)
179{
180 if (mmdeg<0)
181 {
182 *fLog << warn << dbginf << "Warning - Conversion factor < 0 - nonsense. Ignored." << endl;
183 return;
184 }
185
186 if (fMm2Deg>=0)
187 *fLog << warn << dbginf << "Warning - Conversion factor already set. Overwriting" << endl;
188
189 fMm2Deg = mmdeg;
190}
191
192// --------------------------------------------------------------------------
193//
194// Creates a new canvas and draws the two histograms into it.
195// Be careful: The histograms belongs to this object and won't get deleted
196// together with the canvas.
197//
198void MHNewImagePar2::Draw(Option_t *)
199{
200 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
201 pad->SetBorderMode(0);
202
203 AppendPad("");
204
205 gPad->SetBorderMode(0);
206 MH::DrawSame(fHistBorder1, fHistBorder2, "Border Line");
207}
Note: See TracBrowser for help on using the repository browser.