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

Last change on this file since 2229 was 2229, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.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// 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#include "MGeomPix.h"
46
47ClassImp(MHCamEvent);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Initialize the name and title of the task.
54// Resets the sum histogram
55//
56MHCamEvent::MHCamEvent(const char *name, const char *title)
57 : fSum(NULL), fEvt(NULL), fType(0)
58{
59 //
60 // set the name and title of this object
61 //
62 fName = name ? name : "MHCamEvent";
63 fTitle = title ? title : "Average of MCamEvents";
64}
65
66// --------------------------------------------------------------------------
67//
68// Delete the corresponding camera display if available
69//
70MHCamEvent::~MHCamEvent()
71{
72 if (fSum)
73 delete fSum;
74}
75
76// --------------------------------------------------------------------------
77//
78// Get the event (MCamEvent) the histogram might be filled with. If
79// it is not given, it is assumed, that it is filled with the argument
80// of the Fill function.
81// Looks for the camera geometry MGeomCam and resets the sum histogram.
82//
83Bool_t MHCamEvent::SetupFill(const MParList *plist)
84{
85 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
86 if (!fEvt)
87 {
88 if (!fNameEvt.IsNull())
89 {
90 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
91 return kFALSE;
92 }
93 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
94 }
95
96 MGeomCam *cam = (MGeomCam*)plist->FindObject("MGeomCam");
97 if (!cam)
98 *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
99
100 if (fSum)
101 delete (fSum);
102 fSum = new MHCamera(*cam, fNameEvt+";avg", fTitle);
103 fSum->SetYTitle("a.u.");
104
105 return kTRUE;
106}
107
108// --------------------------------------------------------------------------
109//
110// Fill the histograms with data from a MCamEvent-Container.
111//
112Bool_t MHCamEvent::Fill(const MParContainer *par, const Stat_t w)
113{
114 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
115 if (!evt)
116 {
117 *fLog << err << dbginf << "No MCamEvent found..." << endl;
118 return kFALSE;
119 }
120 fSum->AddCamContent(*evt, fType);
121
122 return kTRUE;
123}
124
125// --------------------------------------------------------------------------
126//
127// Scale the sum container with the number of entries
128//
129Bool_t MHCamEvent::Finalize()
130{
131 if (fSum->GetEntries()>0)
132 fSum->Scale(100./fSum->GetEntries());
133 return kTRUE;
134}
135
136// --------------------------------------------------------------------------
137//
138// Return fSum.
139//
140TH1 *MHCamEvent::GetHistByName(const TString name)
141{
142 return fSum;
143}
144
145void MHCamEvent::Draw(Option_t *)
146{
147 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
148 pad->SetBorderMode(0);
149
150 pad->Divide(2,2);
151
152 pad->cd(1);
153 gPad->SetBorderMode(0);
154 gPad->Divide(1,1);
155 gPad->cd(1);
156 gPad->SetBorderMode(0);
157 fSum->Draw();
158
159 pad->cd(3);
160 gPad->SetBorderMode(0);
161 fSum->Draw("EPhist");
162}
Note: See TracBrowser for help on using the repository browser.