source: trunk/MagicSoft/Mars/mhist/MHCerPhotEvt.cc@ 2001

Last change on this file since 2001 was 1990, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.1 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// MHCerPhotEvt
28//
29/////////////////////////////////////////////////////////////////////////////
30#include "MHCerPhotEvt.h"
31
32#include <TCanvas.h>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38#include "MCerPhotEvt.h"
39#include "MCamDisplay.h"
40
41#include "MGeomCam.h"
42#include "MGeomPix.h"
43
44ClassImp(MHCerPhotEvt);
45
46// --------------------------------------------------------------------------
47//
48// Reset all pixels to 0 and reset fEntries to 0.
49//
50void MHCerPhotEvt::Clear()
51{
52 fSum.Reset();
53 fSum.InitSize(577);
54 for (int i=0; i<577; i++)
55 {
56 fSum.AddPixel(i, 0, 0);
57 fSum[i].SetPixelUnused();
58 }
59
60 fEntries = 0;
61}
62
63// --------------------------------------------------------------------------
64//
65// Initialize the name and title of the task.
66// Resets the sum histogram
67//
68MHCerPhotEvt::MHCerPhotEvt(const char *name, const char *title)
69 : fCam(NULL), fEvt(NULL), fDispl(NULL)
70{
71 //
72 // set the name and title of this object
73 //
74 fName = name ? name : "MHCerPhotEvt";
75 fTitle = title ? title : "Average of MCerPhotEvts";
76
77 Clear();
78}
79
80// --------------------------------------------------------------------------
81//
82// Delete the corresponding camera display if available
83//
84MHCerPhotEvt::~MHCerPhotEvt()
85{
86 if (fDispl)
87 delete fDispl;
88}
89
90// --------------------------------------------------------------------------
91//
92// Get the event (MCerPhotEvt) the histogram might be filled with. If
93// it is not given, it is assumed, that it is filled with the argument
94// of the Fill function.
95// Looks for the camera geometry MGeomCam and resets the sum histogram.
96//
97Bool_t MHCerPhotEvt::SetupFill(const MParList *plist)
98{
99 fEvt = (MCerPhotEvt*)plist->FindObject("MCerPhotEvt");
100 if (!fEvt)
101 *fLog << warn << GetDescriptor() << ": No MCerPhotEvt available..." << endl;
102
103 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
104 if (!fCam)
105 *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
106
107 Clear();
108
109 return kTRUE;
110}
111
112// --------------------------------------------------------------------------
113//
114// Fill the histograms with data from a MCerPhotEvt-Container.
115//
116Bool_t MHCerPhotEvt::Fill(const MParContainer *par, Double_t w)
117{
118 const MCerPhotEvt *evt = par ? (MCerPhotEvt*)par : fEvt;
119 if (!evt)
120 {
121 *fLog << err << dbginf << "No MCerPhotEvt found..." << endl;
122 return kFALSE;
123 }
124
125 const UInt_t n = evt->GetNumPixels();
126
127 for (UInt_t i=0; i<n; i++)
128 {
129 const MCerPhotPix &pix = (*evt)[i];
130
131 const Int_t id = pix.GetPixId();
132
133 const Double_t ratio = fCam ? fCam->GetPixRatio(id) : 1;
134
135 const Double_t val = pix.GetNumPhotons()/ratio;
136
137 fSum[id].SetPixelUsed();
138 fSum[id].AddNumPhotons(val);
139 }
140
141 fEntries++;
142
143 return kTRUE;
144}
145
146// --------------------------------------------------------------------------
147//
148// Scale the sum container with the number of entries
149//
150Bool_t MHCerPhotEvt::Finalize()
151{
152 fSum.Scale(fEntries);
153 return kTRUE;
154}
155
156// --------------------------------------------------------------------------
157//
158// Draw clone
159//
160TObject *MHCerPhotEvt::DrawClone(Option_t *opt) const
161{
162 return MH::DrawClone(opt, 750, 600);
163}
164
165// --------------------------------------------------------------------------
166//
167// Draw the present 'fill status'
168//
169void MHCerPhotEvt::Draw(Option_t *)
170{
171 if (!fCam)
172 {
173 *fLog << warn << "WARNING - Cannot draw " << GetDescriptor() << ": No Camera Geometry available." << endl;
174 return;
175 }
176
177 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 750, 600);
178 pad->SetBorderMode(0);
179
180 AppendPad("");
181}
182
183// --------------------------------------------------------------------------
184//
185// If a camera display is not yet assigned, assign a new one.
186//
187void MHCerPhotEvt::Paint(Option_t *option="")
188{
189 if (!fCam)
190 {
191 *fLog << warn << "WARNING - Cannot paint " << GetDescriptor() << ": No Camera Geometry available." << endl;
192 return;
193 }
194
195 if (!fDispl)
196 fDispl = new MCamDisplay(fCam);
197
198 fDispl->FillPhotNum(fSum);
199 fDispl->Paint();
200}
Note: See TracBrowser for help on using the repository browser.