source: trunk/MagicSoft/Mars/mhist/MHCurrents.cc@ 3414

Last change on this file since 3414 was 2377, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.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 12/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHCurrents
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MHCurrents.h"
31
32#include <TCanvas.h>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38#include "MBinning.h"
39#include "MCurrents.h"
40#include "MCamDisplay.h"
41
42#include "MGeomCam.h"
43#include "MGeomPix.h"
44
45ClassImp(MHCurrents);
46
47using namespace std;
48
49// --------------------------------------------------------------------------
50//
51// Reset all pixels to 0 and reset fEntries to 0.
52//
53void MHCurrents::Clear(const Option_t *)
54{
55 const Int_t n = fCam ? fCam->GetNumPixels() : 577;
56
57 // FIXME: Implement a clear function with setmem
58 fSum.Set(n); // also clears memory
59 fRms.Set(n);
60/* for (int i=0; i<577; i++)
61 {
62 fSum[i] = 0;
63 fRms[i] = 0;
64 }*/
65
66 fEntries = 0;
67}
68
69// --------------------------------------------------------------------------
70//
71// Initialize the name and title of the task.
72// Resets the sum histogram
73//
74MHCurrents::MHCurrents(const char *name, const char *title)
75 : /*fSum(577), fRms(577), */fCam(NULL), fEvt(NULL), fDispl(NULL)
76{
77 //
78 // set the name and title of this object
79 //
80 fName = name ? name : "MHCurrents";
81 fTitle = title ? title : "Average of MCurrents";
82
83 Clear();
84
85 fHist.SetName("currents;avg");
86 fHist.SetTitle("Avg.Currents [nA]");
87 fHist.SetXTitle("Pixel Index");
88 fHist.SetYTitle("A [nA]");
89 fHist.SetDirectory(NULL);
90 fHist.SetLineColor(kGreen);
91 fHist.SetMarkerStyle(kFullDotMedium);
92 fHist.SetMarkerSize(0.3);
93}
94
95// --------------------------------------------------------------------------
96//
97// Delete the corresponding camera display if available
98//
99MHCurrents::~MHCurrents()
100{
101 if (fDispl)
102 delete fDispl;
103}
104
105// --------------------------------------------------------------------------
106//
107// Get the event (MCerPhotEvt) the histogram might be filled with. If
108// it is not given, it is assumed, that it is filled with the argument
109// of the Fill function.
110// Looks for the camera geometry MGeomCam and resets the sum histogram.
111//
112Bool_t MHCurrents::SetupFill(const MParList *plist)
113{
114 fEvt = (MCurrents*)plist->FindObject("MCurrents");
115 if (!fEvt)
116 *fLog << warn << GetDescriptor() << ": No MCerPhotEvt available..." << endl;
117
118 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
119 /*
120 if (!fCam)
121 *fLog << warn << GetDescriptor() << ": No MGeomCam found... assuming Magic geometry!" << endl;
122 */
123 if (!fCam)
124 {
125 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
126 return kFALSE;
127 }
128
129 Clear();
130
131 const Int_t n = fSum.GetSize();
132
133 MBinning bins;
134 bins.SetEdges(n, -0.5, n-0.5);
135 bins.Apply(fHist);
136
137 return kTRUE;
138}
139
140// --------------------------------------------------------------------------
141//
142// Fill the histograms with data from a MCerPhotEvt-Container.
143//
144Bool_t MHCurrents::Fill(const MParContainer *par, const Stat_t w)
145{
146 const MCurrents *evt = par ? (MCurrents*)par : fEvt;
147 if (!evt)
148 {
149 *fLog << err << dbginf << "No MCurrents found..." << endl;
150 return kFALSE;
151 }
152
153 const Int_t n = fSum.GetSize();
154 for (UInt_t idx=0; idx<n; idx++)
155 {
156 Float_t val;
157 if (!evt->GetPixelContent(val, idx))
158 continue;
159
160 fSum[idx] += val;
161 fRms[idx] += val*val;
162
163 }
164
165 fEntries++;
166
167 return kTRUE;
168}
169
170// --------------------------------------------------------------------------
171//
172// Scale the sum container with the number of entries
173//
174Bool_t MHCurrents::Finalize()
175{
176 if (fEntries<2)
177 {
178 *fLog << warn << "WARNING - " << GetDescriptor() << " doesn't contain enough entries." << endl;
179 return kTRUE;
180 }
181
182 const Int_t n = fSum.GetSize();
183 for (UInt_t i=0; i<n; i++)
184 {
185 // calc sdev^2 for pixel index i
186 // var^2 = (sum[xi^2] - sum[xi]^2/n) / (n-1);
187 fRms[i] -= fSum[i]*fSum[i]/fEntries;
188 fRms[i] /= fEntries-1;
189
190 if (fRms[i]<0)
191 {
192 *fLog << warn << "WARNING - fRms[" << i <<"]= " << fRms[i] << " -> was set to 0 " << endl;
193 fRms[i]=0;
194 }
195
196 else
197 fRms[i] = TMath::Sqrt(fRms[i]);
198
199 // calc mean value for pixel index i
200 fSum[i] /= fEntries;
201
202 fHist.SetBinContent(i+1, fSum[i]);
203 fHist.SetBinError( i+1, fRms[i]);
204 }
205 return kTRUE;
206}
207
208// --------------------------------------------------------------------------
209//
210// Draw the present 'fill status'
211//
212void MHCurrents::Draw(Option_t *o)
213{
214 if (!fCam)
215 {
216 *fLog << warn << "WARNING - Cannot draw " << GetDescriptor() << ": No Camera Geometry available." << endl;
217 return;
218 }
219
220 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 750, 600);
221 pad->SetBorderMode(0);
222
223 SetDrawOption(o);
224 AppendPad("");
225}
226
227// --------------------------------------------------------------------------
228//
229// If a camera display is not yet assigned, assign a new one.
230//
231void MHCurrents::Paint(Option_t *option)
232{
233 if (!fCam)
234 {
235 *fLog << warn << "WARNING - Cannot paint " << GetDescriptor() << ": No Camera Geometry available." << endl;
236 return;
237 }
238
239 if (!fDispl)
240 fDispl = new MCamDisplay(fCam);
241
242 TString opt(GetDrawOption());
243
244 fDispl->Fill(opt.Contains("rms", TString::kIgnoreCase) ? fRms : fSum);
245 fDispl->Paint();
246}
Note: See TracBrowser for help on using the repository browser.