source: trunk/MagicSoft/Mars/mhvstime/MHPixVsTime.cc@ 5756

Last change on this file since 5756 was 4891, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 6.6 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-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHPixVsTime
28//
29// Display the pixel content versus time or event number
30//
31// Axis titles
32// ===========
33//
34// 1) If no other title is given the rule for the y-axis is used.
35// 2) If the MH3 has a non-default title (MH3::SetTitle called)
36// this title is set as the histogram title. It can be used to overwrite
37// the axis titles. For more information see TH1::SetTitle, eg.
38// SetTitle("MyGraph;;Counts");
39// The title for the x-axis is ignored and set automatically (MAKE SURE
40// YOU HAVE TWO SEMICOLON!)
41//
42/////////////////////////////////////////////////////////////////////////////
43#include "MHPixVsTime.h"
44
45#include <TCanvas.h>
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MParList.h"
51#include "MCamEvent.h"
52
53#include "MGeomCam.h"
54
55#include "MRawEvtHeader.h"
56#include "MTime.h"
57
58ClassImp(MHPixVsTime);
59
60using namespace std;
61
62const TString MHPixVsTime::gsDefName = "MHPixVsTime";
63const TString MHPixVsTime::gsDefTitle = "Graph of pixel content vs. time";
64
65// --------------------------------------------------------------------------
66//
67// Initialize the name and title of the task.
68//
69MHPixVsTime::MHPixVsTime(Int_t idx, const char *name, const char *title)
70 : fIndex(idx), fEvt(NULL), fType(0), fTypeErr(-1)
71{
72 //
73 // set the name and title of this object
74 //
75 fName = name ? name : gsDefName.Data();
76 fTitle = title ? title : gsDefTitle.Data();
77
78 TString t("Pixel Index #");
79 t += idx;
80 t += " vs Time";
81
82 fGraph = new TGraphErrors;
83 fGraph->SetName("MCamEvent");
84 fGraph->SetTitle(t);
85}
86
87// --------------------------------------------------------------------------
88//
89// Delete the corresponding camera display if available
90//
91MHPixVsTime::~MHPixVsTime()
92{
93 if (fGraph)
94 delete fGraph;
95}
96
97// --------------------------------------------------------------------------
98//
99// Set the name of the TGraph and the MHPixVsTime container
100//
101void MHPixVsTime::SetName(const char *name)
102{
103 fGraph->SetName(name);
104 MParContainer::SetName(name);
105}
106
107// --------------------------------------------------------------------------
108//
109// Set the title of the TGraph and the MHPixVsTime container
110//
111void MHPixVsTime::SetTitle(const char *title)
112{
113 fGraph->SetTitle(title);
114 MParContainer::SetTitle(title);
115}
116
117// --------------------------------------------------------------------------
118//
119// Get the event (MPixVsTime) the histogram might be filled with. If
120// it is not given, it is assumed, that it is filled with the argument
121// of the Fill function.
122// Looks for the camera geometry MGeomCam and resets the sum histogram.
123//
124Bool_t MHPixVsTime::SetupFill(const MParList *plist)
125{
126 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
127 if (!fEvt)
128 {
129 if (!fNameEvt.IsNull())
130 {
131 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
132 return kFALSE;
133 }
134 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
135 }
136
137 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
138 if (!fCam)
139 {
140 *fLog << err << "MGeomCam not found... aborting." << endl;
141 return kFALSE;
142 }
143
144 if (!fNameTime.IsNull())
145 {
146 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
147 if (!fTime)
148 {
149 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
150 return kFALSE;
151 }
152 }
153 else
154 {
155 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
156 if (!fHeader)
157 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
158 }
159
160 if (fTitle!=gsDefTitle)
161 fGraph->SetTitle(fTitle);
162
163 return kTRUE;
164}
165
166// --------------------------------------------------------------------------
167//
168// Fill the histograms with data from a MPixVsTime-Container.
169//
170Bool_t MHPixVsTime::Fill(const MParContainer *par, const Stat_t w)
171{
172 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
173 if (!evt)
174 {
175 *fLog << err << dbginf << "No MCamEvent found..." << endl;
176 return kFALSE;
177 }
178
179 Double_t val = 0;
180 Double_t rms = 0;
181 evt->GetPixelContent(val, fIndex, *fCam, fType);
182 if (TMath::IsNaN(val))
183 return kCONTINUE;
184
185 Double_t t = 0;
186 if (!fNameTime.IsNull())
187 t = fTime->GetAxisTime();
188 else
189 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
190
191 fGraph->SetPoint(fGraph->GetN(), t, val);
192
193 if (fTypeErr>=0)
194 {
195 evt->GetPixelContent(rms, fIndex, *fCam, fType);
196 if (TMath::IsNaN(rms))
197 return kCONTINUE;
198 }
199
200 fGraph->SetPointError(fGraph->GetN()-1, 0, rms);
201 return kTRUE;
202}
203
204// --------------------------------------------------------------------------
205//
206// Return histogram of TGraph
207//
208TH1 *MHPixVsTime::GetHistByName(const TString name)
209{
210 return fGraph->GetHistogram();
211}
212
213void MHPixVsTime::Draw(Option_t *opt)
214{
215
216 if (fGraph->GetN()==0)
217 return;
218
219 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
220 pad->SetBorderMode(0);
221
222 AppendPad("");
223
224 TString str(opt);
225
226 TH1 *h = fGraph->GetHistogram();
227
228 h->SetXTitle("Time");
229 if (!fNameTime.IsNull())
230 {
231 TAxis *axe = h->GetXaxis();
232 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
233 axe->SetTimeDisplay(1);
234 axe->SetLabelSize(0.033);
235 }
236
237
238 if (!str.Contains("A"))
239 str += "A";
240 if (!str.Contains("P"))
241 str += "P";
242
243 if (str.Contains("same", TString::kIgnoreCase))
244 {
245 str.ReplaceAll("same", "");
246 str.ReplaceAll("A", "");
247 }
248
249 fGraph->Draw(str);
250
251 pad->Modified();
252 pad->Update();
253}
Note: See TracBrowser for help on using the repository browser.