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

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