source: branches/AddingGoogleTestEnvironment/mhvstime/MHPixVsTime.cc@ 18527

Last change on this file since 18527 was 12923, checked in by tbretz, 13 years ago
Added the possibility to set min and max; increased version number accordingly
File size: 7.0 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:thomas.bretz@epfl.ch>
19!
20! Copyright: MAGIC Software Development, 2000-2012
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// Class Version 2:
44// ----------------
45// + fMaximum
46// + fMinumum
47//
48/////////////////////////////////////////////////////////////////////////////
49#include "MHPixVsTime.h"
50
51#include <TH1.h>
52#include <TCanvas.h>
53
54#include "MLog.h"
55#include "MLogManip.h"
56
57#include "MParList.h"
58#include "MCamEvent.h"
59
60#include "MGeomCam.h"
61
62#include "MRawEvtHeader.h"
63#include "MTime.h"
64
65ClassImp(MHPixVsTime);
66
67using namespace std;
68
69const TString MHPixVsTime::gsDefName = "MHPixVsTime";
70const TString MHPixVsTime::gsDefTitle = "Graph of pixel content vs. time";
71
72// --------------------------------------------------------------------------
73//
74// Initialize the name and title of the task.
75//
76MHPixVsTime::MHPixVsTime(Int_t idx, const char *name, const char *title)
77 : fIndex(idx), fEvt(NULL), fType(0), fTypeErr(-1), fMinimum(-1111), fMaximum(-1111)
78{
79 //
80 // set the name and title of this object
81 //
82 fName = name ? name : gsDefName.Data();
83 fTitle = title ? title : gsDefTitle.Data();
84
85 TString t("Pixel Index #");
86 t += idx;
87 t += " vs Time";
88
89 fGraph = new TGraphErrors;
90 fGraph->SetName("MCamEvent");
91 fGraph->SetTitle(t);
92}
93
94// --------------------------------------------------------------------------
95//
96// Delete the corresponding camera display if available
97//
98MHPixVsTime::~MHPixVsTime()
99{
100 if (fGraph)
101 delete fGraph;
102}
103
104// --------------------------------------------------------------------------
105//
106// Set the name of the TGraph and the MHPixVsTime container
107//
108void MHPixVsTime::SetName(const char *name)
109{
110 fGraph->SetName(name);
111 MParContainer::SetName(name);
112}
113
114// --------------------------------------------------------------------------
115//
116// Set the title of the TGraph and the MHPixVsTime container
117//
118void MHPixVsTime::SetTitle(const char *title)
119{
120 fGraph->SetTitle(title);
121 MParContainer::SetTitle(title);
122}
123
124// --------------------------------------------------------------------------
125//
126// Get the event (MPixVsTime) the histogram might be filled with. If
127// it is not given, it is assumed, that it is filled with the argument
128// of the Fill function.
129// Looks for the camera geometry MGeomCam and resets the sum histogram.
130//
131Bool_t MHPixVsTime::SetupFill(const MParList *plist)
132{
133 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
134 if (!fEvt)
135 {
136 if (!fNameEvt.IsNull())
137 {
138 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
139 return kFALSE;
140 }
141 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
142 }
143
144 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
145 if (!fCam)
146 {
147 *fLog << err << "MGeomCam not found... aborting." << endl;
148 return kFALSE;
149 }
150
151 if (!fNameTime.IsNull())
152 {
153 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
154 if (!fTime)
155 {
156 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
157 return kFALSE;
158 }
159 }
160 else
161 {
162 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
163 if (!fHeader)
164 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
165 }
166
167 if (fTitle!=gsDefTitle)
168 fGraph->SetTitle(fTitle);
169
170 return kTRUE;
171}
172
173// --------------------------------------------------------------------------
174//
175// Fill the histograms with data from a MPixVsTime-Container.
176//
177Int_t MHPixVsTime::Fill(const MParContainer *par, const Stat_t w)
178{
179 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
180 if (!evt)
181 {
182 *fLog << err << dbginf << "No MCamEvent found..." << endl;
183 return kERROR;
184 }
185
186 Double_t val = 0;
187 Double_t rms = 0;
188 evt->GetPixelContent(val, fIndex, *fCam, fType);
189 if (!TMath::Finite(val))
190 return kTRUE; // Use kCONTINUE with extreme care!
191
192 Double_t t = 0;
193 if (!fNameTime.IsNull())
194 t = fTime->GetAxisTime();
195 else
196 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
197
198 fGraph->SetPoint(fGraph->GetN(), t, val);
199
200 if (fTypeErr>=0)
201 {
202 evt->GetPixelContent(rms, fIndex, *fCam, fTypeErr);
203 if (!TMath::Finite(rms))
204 return kTRUE; // Use kCONTINUE with extreme care!
205 }
206
207 fGraph->SetPointError(fGraph->GetN()-1, 0, rms);
208 return kTRUE;
209}
210
211// --------------------------------------------------------------------------
212//
213// Return histogram of TGraph
214//
215TH1 *MHPixVsTime::GetHistByName(const TString name) const
216{
217 return fGraph->GetHistogram();
218}
219
220void MHPixVsTime::Draw(Option_t *opt)
221{
222 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
223 pad->SetBorderMode(0);
224 pad->SetGrid();
225
226 AppendPad("");
227
228 // This is not done automatically anymore since root 5.12/00
229 // and it is necessary to force a proper update of the axis.
230 TH1 *h = fGraph->GetHistogram();
231
232 h->SetXTitle("Time");
233
234 if (!fNameTime.IsNull())
235 {
236 TAxis *axe = h->GetXaxis();
237 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
238 axe->SetTimeDisplay(1);
239 axe->SetLabelSize(0.033);
240 }
241
242 if (fMinimum!=-1111)
243 fGraph->SetMinimum(fMinimum);
244 if (fMaximum!=-1111)
245 fGraph->SetMaximum(fMaximum);
246
247 TString str(opt);
248 if (!str.Contains("A"))
249 str += "A";
250 if (!str.Contains("P"))
251 str += "P";
252
253 if (str.Contains("same", TString::kIgnoreCase))
254 {
255 str.ReplaceAll("same", "");
256 str.ReplaceAll("A", "");
257 }
258
259 fGraph->Draw(str);
260}
Note: See TracBrowser for help on using the repository browser.