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

Last change on this file since 4448 was 2893, checked in by tbretz, 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 {
100 *fLog << err << GetDescriptor() << ": No MGeomCam found." << endl;
101 return kFALSE;
102 }
103
104 if (fSum)
105 delete (fSum);
106 if (fRms)
107 delete (fRms);
108
109 const TString name = fNameEvt.IsNull() ? fName : fNameEvt;
110
111 fSum = new MHCamera(*cam, name+";avg", fTitle);
112 fSum->SetYTitle("a.u.");
113 fSum->SetBit(MHCamera::kProfile);
114 if(TestBit(MHCamera::kVariance))
115 fSum->SetBit(MHCamera::kVariance);
116
117 fRms = new MHCamera(*cam, name+";rms", fTitle);
118 fRms->SetYTitle("a.u.");
119
120 return kTRUE;
121}
122
123// --------------------------------------------------------------------------
124//
125// Fill the histograms with data from a MCamEvent-Container.
126//
127Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
128{
129 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
130 if (!evt)
131 {
132 *fLog << err << dbginf << "Got no MCamEvent as argument of Fill()..." << endl;
133 return kFALSE;
134 }
135 fSum->AddCamContent(*evt, fType);
136 fRms->SetCamContent(*fSum, 1);
137 return kTRUE;
138}
139
140// --------------------------------------------------------------------------
141//
142// Scale the sum container with the number of entries
143//
144Bool_t MHCamEvent::Finalize()
145{
146 //fRms->AddCamContent(*fSum, 1);
147 return kTRUE;
148}
149
150// --------------------------------------------------------------------------
151//
152// Take the mean of the sum histogram and print all pixel indices
153// which are above sum+s*rms
154//
155void MHCamEvent::PrintOutliers(Float_t s) const
156{
157 const Double_t mean = fSum->GetMean();
158 const Double_t rms = fSum->GetRMS();
159
160 *fLog << all << underline << GetDescriptor() << ": Mean=" << mean << ", Rms=" << rms << endl;
161
162 for (UInt_t i=0; i<fSum->GetNumPixels(); i++)
163 {
164 if (!fSum->IsUsed(i))
165 continue;
166
167 if ((*fSum)[i+1]>mean+s*rms)
168 *fLog << "Contents of Pixel-Index #" << i << ": " << (*fSum)[i+1] << " > " << s << "*rms" << endl;
169 }
170}
171
172// --------------------------------------------------------------------------
173//
174// Return fSum for "sum" and fRms for "rms"
175//
176TH1 *MHCamEvent::GetHistByName(const TString name)
177{
178// name.ToLower();
179
180 if (name=="sum")
181 return fSum;
182 if (name=="rms")
183 return fRms;
184
185 return NULL;
186}
187
188void MHCamEvent::Draw(Option_t *)
189{
190 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
191 pad->SetBorderMode(0);
192
193 pad->Divide(1,2);
194
195 pad->cd(1);
196 gPad->SetBorderMode(0);
197 fSum->Draw("EPhist");
198
199 pad->cd(2);
200 gPad->SetBorderMode(0);
201 gPad->Divide(2, 1);
202 pad = gPad;
203
204 pad->cd(1);
205 gPad->SetBorderMode(0);
206 fSum->Draw();
207
208 pad->cd(2);
209 gPad->SetBorderMode(0);
210 fRms->Draw();
211}
Note: See TracBrowser for help on using the repository browser.