source: trunk/MagicSoft/Mars/mhist/MHCamEvent.cc@ 2853

Last change on this file since 2853 was 2816, checked in by reyes, 21 years ago
*** empty log message ***
File size: 5.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, 12/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHCamEvent
28//
29// A histogram to store the sum of camera events. This can be photons,
30// currents or enything else derived from MCamEvent
31//
32/////////////////////////////////////////////////////////////////////////////
33#include "MHCamEvent.h"
34
35#include <TCanvas.h>
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MParList.h"
41#include "MCamEvent.h"
42#include "MHCamera.h"
43
44#include "MGeomCam.h"
45
46ClassImp(MHCamEvent);
47
48using namespace std;
49
50// --------------------------------------------------------------------------
51//
52// Initialize the name and title of the task.
53// Resets the sum histogram
54//
55MHCamEvent::MHCamEvent(const char *name, const char *title)
56 : fSum(NULL), fRms(NULL), fEvt(NULL), fType(0)
57{
58 //
59 // set the name and title of this object
60 //
61 fName = name ? name : "MHCamEvent";
62 fTitle = title ? title : "Average of MCamEvents";
63}
64
65// --------------------------------------------------------------------------
66//
67// Delete the corresponding camera display if available
68//
69MHCamEvent::~MHCamEvent()
70{
71 if (fSum)
72 delete fSum;
73 if (fRms)
74 delete fRms;
75}
76
77// --------------------------------------------------------------------------
78//
79// Get the event (MCamEvent) the histogram might be filled with. If
80// it is not given, it is assumed, that it is filled with the argument
81// of the Fill function.
82// Looks for the camera geometry MGeomCam and resets the sum histogram.
83//
84Bool_t MHCamEvent::SetupFill(const MParList *plist)
85{
86 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
87 if (!fEvt)
88 {
89 if (!fNameEvt.IsNull())
90 {
91 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
92 return kFALSE;
93 }
94 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
95 }
96
97 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
98 if (!cam)
99 *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
100
101 if (fSum)
102 delete (fSum);
103 if (fRms)
104 delete (fRms);
105
106 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
107
108 fSum = new MHCamera(*cam, name+";avg", fTitle);
109 fSum->SetYTitle("a.u.");
110 fSum->SetBit(MHCamera::kProfile);
111 if(TestBit(MHCamera::kVariance))
112 fSum->SetBit(MHCamera::kVariance);
113
114 fRms = new MHCamera(*cam, name+";rms", fTitle);
115 fRms->SetYTitle("a.u.");
116 return kTRUE;
117}
118
119// --------------------------------------------------------------------------
120//
121// Fill the histograms with data from a MCamEvent-Container.
122//
123Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
124{
125 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
126 if (!evt)
127 {
128 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
129 return kFALSE;
130 }
131 fSum->AddCamContent(*evt, fType);
132 fRms->SetCamContent(*fSum, 1);
133 return kTRUE;
134}
135
136// --------------------------------------------------------------------------
137//
138// Scale the sum container with the number of entries
139//
140Bool_t MHCamEvent::Finalize()
141{
142 //fRms->AddCamContent(*fSum, 1);
143 return kTRUE;
144}
145
146// --------------------------------------------------------------------------
147//
148// Take the mean of the sum histogram and print all pixel indices
149// which are above sum+s*rms
150//
151void MHCamEvent::PrintOutliers(Float_t s) const
152{
153 const Double_t mean = fSum->GetMean();
154 const Double_t rms = fSum->GetRMS();
155
156 *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
157
158 for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
159 {
160 if (!fSum->IsUsed(i))
161 continue;
162
163 if ((*fSum)[i+1]>mean+s*rms)
164 *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
165 }
166}
167
168// --------------------------------------------------------------------------
169//
170// Return fSum for "sum" and fRms for "rms"
171//
172TH1 *MHCamEvent::GetHistByName(const TString name)
173{
174// name.ToLower();
175
176 if (name=="sum")
177 return fSum;
178 if (name=="rms")
179 return fRms;
180
181 return NULL;
182}
183
184void MHCamEvent::Draw(Option_t *)
185{
186 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
187 pad->SetBorderMode(0);
188
189 pad->Divide(1,2);
190
191 pad->cd(1);
192 gPad->SetBorderMode(0);
193 fSum->Draw("EPhist");
194
195 pad->cd(2);
196 gPad->SetBorderMode(0);
197 gPad->Divide(2, 1);
198 pad = gPad;
199
200 pad->cd(1);
201 gPad->SetBorderMode(0);
202 fSum->Draw();
203
204 pad->cd(2);
205 gPad->SetBorderMode(0);
206 fRms->Draw();
207}
Note: See TracBrowser for help on using the repository browser.