source: trunk/MagicSoft/Mars/mhist/MHPixVsTime.cc@ 3088

Last change on this file since 3088 was 3088, 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// MHPixVsTime
28//
29// A histogram to store the sum of camera events. This can be photons,
30// currents or enything else derived from MPixVsTime
31//
32/////////////////////////////////////////////////////////////////////////////
33#include "MHPixVsTime.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
43#include "MGeomCam.h"
44
45#include "MRawEvtHeader.h"
46#include "MTime.h"
47
48ClassImp(MHPixVsTime);
49
50using namespace std;
51
52// --------------------------------------------------------------------------
53//
54// Initialize the name and title of the task.
55// Resets the sum histogram
56//
57MHPixVsTime::MHPixVsTime(Int_t idx, const char *name, const char *title)
58 : fIndex(idx), fEvt(NULL), fType(0)
59{
60 //
61 // set the name and title of this object
62 //
63 fName = name ? name : "MHPixVsTime";
64 fTitle = title ? title : "Average of MPixVsTimes";
65
66 TString t("Pixel Index #");
67 t += idx;
68 t += " vs Time";
69
70 fGraph = new TGraph;
71 fGraph->SetName("MCamEvent");
72 fGraph->SetTitle(t);
73}
74
75// --------------------------------------------------------------------------
76//
77// Delete the corresponding camera display if available
78//
79MHPixVsTime::~MHPixVsTime()
80{
81 if(fGraph)
82 delete fGraph;
83}
84
85// --------------------------------------------------------------------------
86//
87// Get the event (MPixVsTime) the histogram might be filled with. If
88// it is not given, it is assumed, that it is filled with the argument
89// of the Fill function.
90// Looks for the camera geometry MGeomCam and resets the sum histogram.
91//
92Bool_t MHPixVsTime::SetupFill(const MParList *plist)
93{
94 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
95 if (!fEvt)
96 {
97 if (!fNameEvt.IsNull())
98 {
99 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
100 return kFALSE;
101 }
102 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
103 }
104
105 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
106 if (!fCam)
107 {
108 *fLog << err << "MGeomCam not found... aborting." << endl;
109 return kFALSE;
110 }
111
112 if (!fNameTime.IsNull())
113 {
114 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
115 if (!fTime)
116 {
117 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
118 return kFALSE;
119 }
120 }
121 else
122 {
123 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
124 if (!fHeader)
125 {
126 *fLog << err << "MRawEvtHeader not found... abort." << endl;
127 return kFALSE;
128 }
129 }
130
131 return kTRUE;
132}
133
134// --------------------------------------------------------------------------
135//
136// Fill the histograms with data from a MPixVsTime-Container.
137//
138Bool_t MHPixVsTime::Fill(const MParContainer *par, const Stat_t w)
139{
140 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
141 if (!evt)
142 {
143 *fLog << err << dbginf << "No MCamEvent found..." << endl;
144 return kFALSE;
145 }
146
147 Double_t val = 0;
148 evt->GetPixelContent(val, fIndex, *fCam, fType);
149 if (TMath::IsNaN(val))
150 return kCONTINUE;
151
152 Double_t t = 0;
153 if (!fNameTime.IsNull())
154 t = fTime->GetAxisTime();
155 else
156 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
157
158 fGraph->SetPoint(fGraph->GetN(), t, val);
159 return kTRUE;
160}
161
162// --------------------------------------------------------------------------
163//
164// Scale the sum container with the number of entries
165//
166Bool_t MHPixVsTime::Finalize()
167{
168 return kTRUE;
169}
170
171// --------------------------------------------------------------------------
172//
173// Return fSum.
174//
175TH1 *MHPixVsTime::GetHistByName(const TString name)
176{
177 return fGraph->GetHistogram();
178}
179
180void MHPixVsTime::Draw(Option_t *opt)
181{
182
183 if (fGraph->GetN()==0)
184 return;
185
186 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
187 pad->SetBorderMode(0);
188
189 AppendPad("");
190
191 TString str(opt);
192
193 fGraph->GetHistogram()->SetXTitle("Time");
194 fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00");
195 fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
196 fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
197
198 fGraph->GetHistogram()->SetYTitle("");
199
200 if (!str.Contains("A"))
201 str += "A";
202 if (!str.Contains("P"))
203 str += "P";
204
205 if (str.Contains("same", TString::kIgnoreCase))
206 {
207 str.ReplaceAll("same", "");
208 str.ReplaceAll("A", "");
209 }
210
211 fGraph->Draw(str);
212
213 pad->Modified();
214 pad->Update();
215
216}
Note: See TracBrowser for help on using the repository browser.