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

Last change on this file since 2178 was 2178, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.6 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 // FIXME: Implement a clear function with setmem
56 for (int i=0; i<577; i++)
57 {
58 fSum[i] = 0;
59 fRms[i] = 0;
60 }
61
62 fEntries = 0;
63}
64
65// --------------------------------------------------------------------------
66//
67// Initialize the name and title of the task.
68// Resets the sum histogram
69//
70MHCurrents::MHCurrents(const char *name, const char *title)
71 : fSum(577), fRms(577), fCam(NULL), fEvt(NULL), fDispl(NULL)
72{
73 //
74 // set the name and title of this object
75 //
76 fName = name ? name : "MHCurrents";
77 fTitle = title ? title : "Average of MCerPhotEvts";
78
79 Clear();
80
81 fHist.SetName("currents");
82 fHist.SetTitle("Avg.Currents [nA]");
83 fHist.SetDirectory(NULL);
84 fHist.Sumw2();
85}
86
87// --------------------------------------------------------------------------
88//
89// Delete the corresponding camera display if available
90//
91MHCurrents::~MHCurrents()
92{
93 if (fDispl)
94 delete fDispl;
95}
96
97// --------------------------------------------------------------------------
98//
99// Get the event (MCerPhotEvt) the histogram might be filled with. If
100// it is not given, it is assumed, that it is filled with the argument
101// of the Fill function.
102// Looks for the camera geometry MGeomCam and resets the sum histogram.
103//
104Bool_t MHCurrents::SetupFill(const MParList *plist)
105{
106 fEvt = (MCurrents*)plist->FindObject("MCurrents");
107 if (!fEvt)
108 *fLog << warn << GetDescriptor() << ": No MCerPhotEvt available..." << endl;
109
110 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
111 if (!fCam)
112 *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
113
114 Clear();
115
116 MBinning bins;
117 bins.SetEdges(577, -0.5, 576.5);
118 bins.Apply(fHist);
119
120 return kTRUE;
121}
122
123// --------------------------------------------------------------------------
124//
125// Fill the histograms with data from a MCerPhotEvt-Container.
126//
127Bool_t MHCurrents::Fill(const MParContainer *par, const Stat_t w)
128{
129 const MCurrents *evt = par ? (MCurrents*)par : fEvt;
130 if (!evt)
131 {
132 *fLog << err << dbginf << "No MCurrents found..." << endl;
133 return kFALSE;
134 }
135
136 for (UInt_t idx=0; idx<577; idx++)
137 {
138 Float_t val;
139 if (!evt->GetPixelContent(val, idx))
140 continue;
141
142 fSum[idx] += val;
143 fRms[idx] += val*val;
144 }
145
146 fEntries++;
147
148 return kTRUE;
149}
150
151// --------------------------------------------------------------------------
152//
153// Scale the sum container with the number of entries
154//
155Bool_t MHCurrents::Finalize()
156{
157 if (fEntries<2)
158 {
159 *fLog << warn << "WARNING - " << GetDescriptor() << " doesn't contain enough entries." << endl;
160 return kTRUE;
161 }
162
163 for (UInt_t i=0; i<577; i++)
164 {
165 // calc sdev^2 for pixel index i
166 // var^2 = (sum[xi^2] - sum[xi]^2/n) / (n-1);
167 fRms[i] -= fSum[i]*fSum[i]/fEntries;
168 fRms[i] /= fEntries-1;
169 fRms[i] = TMath::Sqrt(fRms[i]);
170
171 // calc mean value for pixel index i
172 fSum[i] /= fEntries;
173
174 fHist.SetBinContent(i+1, fSum[i]);
175 fHist.SetBinError( i+1, fRms[i]);
176 }
177 return kTRUE;
178}
179
180// --------------------------------------------------------------------------
181//
182// Draw the present 'fill status'
183//
184void MHCurrents::Draw(Option_t *o)
185{
186 if (!fCam)
187 {
188 *fLog << warn << "WARNING - Cannot draw " << GetDescriptor() << ": No Camera Geometry available." << endl;
189 return;
190 }
191
192 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 750, 600);
193 pad->SetBorderMode(0);
194
195 SetDrawOption(o);
196 AppendPad("");
197}
198
199// --------------------------------------------------------------------------
200//
201// If a camera display is not yet assigned, assign a new one.
202//
203void MHCurrents::Paint(Option_t *option)
204{
205 if (!fCam)
206 {
207 *fLog << warn << "WARNING - Cannot paint " << GetDescriptor() << ": No Camera Geometry available." << endl;
208 return;
209 }
210
211 if (!fDispl)
212 fDispl = new MCamDisplay(fCam);
213
214 TString opt(GetDrawOption());
215
216 fDispl->Fill(opt.Contains("rms", TString::kIgnoreCase) ? fRms : fSum);
217 fDispl->Paint();
218}
Note: See TracBrowser for help on using the repository browser.