source: trunk/MagicSoft/Mars/mhvstime/MHSectorVsTime.cc@ 7350

Last change on this file since 7350 was 7349, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 8.7 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, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHSectorVsTime
28//
29// Display the mean and its variance vs time of the whole camera or a
30// single sector
31//
32// 1) If no other title is given the rule for the y-axis is used.
33// 2) If the MH3 has a non-default title (MH3::SetTitle called)
34// this title is set as the histogram title. It can be used to overwrite
35// the axis titles. For more information see TH1::SetTitle, eg.
36// SetTitle("MyGraph;;Counts");
37// The title for the x-axis is ignored and set automatically (MAKE SURE
38// YOU HAVE TWO SEMICOLON!)
39//
40// Example:
41// --------
42// // Initialize histogram
43// MHSectorVsTime hist1;
44// hist1.SetNameTime("MTimeCurrents");
45// hist1.SetTitle("Title for your Graph;;Q [phe]");
46//
47// // Define sectors you want to display the mean from
48// TArrayI s0(3);
49// s0[0] = 6;
50// s0[1] = 1;
51// s0[2] = 2;
52//
53// // Define area index [0=inner, 1=outer]
54// TArrayI inner(1);
55// inner[0] = 0;
56//
57// // Don't call this if you want to have all sectors
58// hist1.SetSectors(s0);
59//
60// // Don't call this if you want to have all area indices
61// hist1.SetAreaIndex(inner);
62//
63// // Task to fill the histogram
64// MFillH fill1(&hist1, "MCameraDC");
65//
66//
67/////////////////////////////////////////////////////////////////////////////
68#include "MHSectorVsTime.h"
69
70#include <TCanvas.h>
71#include <TGraphErrors.h>
72
73#include "MLog.h"
74#include "MLogManip.h"
75
76#include "MParList.h"
77#include "MCamEvent.h"
78
79#include "MGeomCam.h"
80
81#include "MRawEvtHeader.h"
82#include "MTime.h"
83
84ClassImp(MHSectorVsTime);
85
86using namespace std;
87
88const TString MHSectorVsTime::gsDefName = "MHSectorVsTime";
89const TString MHSectorVsTime::gsDefTitle = "Graph of sector mean vs. time";
90
91// --------------------------------------------------------------------------
92//
93// Initialize the name and title of the task. If fErrType>=0 the variance is
94// taken into account.
95//
96MHSectorVsTime::MHSectorVsTime(const char *name, const char *title)
97 : fGraph(0), fEvt(NULL), fMinimum(-1111), fMaximum(-1111),
98 fType(0), fTypeErr(-1)
99{
100 //
101 // set the name and title of this object
102 //
103 fName = name ? name : gsDefName.Data();
104 fTitle = title ? title : gsDefTitle.Data();
105}
106
107// --------------------------------------------------------------------------
108//
109// Delete the fGraph
110//
111MHSectorVsTime::~MHSectorVsTime()
112{
113 if (fGraph)
114 delete fGraph;
115}
116
117// --------------------------------------------------------------------------
118//
119// Set the name of the TGraph and the MHVsTime container
120//
121void MHSectorVsTime::SetName(const char *name)
122{
123 if (fGraph)
124 fGraph->SetName(name);
125 MParContainer::SetName(name);
126}
127
128// --------------------------------------------------------------------------
129//
130// Set the title of the TGraph and the MHVsTime container
131//
132void MHSectorVsTime::SetTitle(const char *title)
133{
134 if (fGraph)
135 fGraph->SetTitle(title);
136 MParContainer::SetTitle(title);
137}
138
139
140// --------------------------------------------------------------------------
141//
142// Get the event (MPixVsTime) the histogram might be filled with. If
143// it is not given, it is assumed, that it is filled with the argument
144// of the Fill function.
145// Looks for the camera geometry MGeomCam and resets the sum histogram.
146// Create and/or initialize fGraph
147//
148Bool_t MHSectorVsTime::SetupFill(const MParList *plist)
149{
150 fEvt = dynamic_cast<MCamEvent*>(plist->FindObject(fNameEvt, "MCamEvent"));
151 if (!fEvt)
152 {
153 if (!fNameEvt.IsNull())
154 {
155 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
156 return kFALSE;
157 }
158 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
159 }
160
161 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
162 if (!fCam)
163 {
164 *fLog << err << "MGeomCam not found... aborting." << endl;
165 return kFALSE;
166 }
167
168 fHCamera.SetGeometry(*fCam);
169
170 if (!fNameTime.IsNull())
171 {
172 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
173 if (!fTime)
174 {
175 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
176 return kFALSE;
177 }
178 }
179 else
180 {
181 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
182 if (!fHeader)
183 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
184 }
185
186 if (fGraph)
187 delete fGraph;
188
189 fGraph = fTypeErr<0 ? new TGraph : new TGraphErrors;
190 fGraph->SetName(fEvt ? dynamic_cast<TObject*>(fEvt)->GetName() : "MCamEvent");
191 fGraph->SetTitle(fTitle==gsDefTitle?"Camera":fTitle.Data());
192 fGraph->SetMarkerStyle(kFullDotMedium);
193
194 if (fMinimum!=-1111)
195 fGraph->SetMinimum(fMinimum);
196 if (fMaximum!=-1111)
197 fGraph->SetMaximum(fMaximum);
198
199 fMin = FLT_MAX;
200 fMax = -FLT_MAX;
201
202 return kTRUE;
203}
204
205// --------------------------------------------------------------------------
206//
207// Fill the histograms with data from a MCamEvent
208//
209Bool_t MHSectorVsTime::Fill(const MParContainer *par, const Stat_t w)
210{
211 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
212 if (!evt)
213 {
214 *fLog << err << dbginf << "No MCamEvent found..." << endl;
215 return kFALSE;
216 }
217
218 Double_t t = 0;
219 if (!fNameTime.IsNull())
220 t = fTime->GetAxisTime();
221 else
222 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
223
224
225 fHCamera.SetCamContent(*evt, fType);
226
227 const Double_t val0 = fHCamera.GetMeanSectors(fSectors, fAreaIndex);
228
229 if (TMath::IsNaN(val0))
230 return kTRUE;
231
232 fGraph->SetPoint(fGraph->GetN(), t, val0);
233
234 if (fTypeErr>=0)
235 {
236 const Double_t rms0 = fHCamera.GetRmsSectors(fSectors, fAreaIndex);
237 if (TMath::IsNaN(rms0))
238 return kTRUE;
239 ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
240 }
241
242 fMin = TMath::Min(fMin, val0);
243 fMax = TMath::Max(fMax, val0);
244
245 return kTRUE;
246}
247
248// --------------------------------------------------------------------------
249//
250// Set Minimum and Maximum;
251//
252Bool_t MHSectorVsTime::Finalize()
253{
254 const Double_t add = (fMax-fMin)*0.15;
255
256 if (fMinimum==-1111)
257 fGraph->SetMinimum(fMin-add);
258 if (fMaximum==-1111)
259 fGraph->SetMaximum(fMax+add);
260
261 return kTRUE;
262}
263
264// --------------------------------------------------------------------------
265//
266// Return fHistogram from TGraph
267//
268TH1 *MHSectorVsTime::GetHistByName(const TString name) const
269{
270 return fGraph->GetHistogram();
271}
272
273void MHSectorVsTime::Paint(Option_t *opt)
274{
275 if (!fGraph)
276 return;
277
278 if (fGraph->GetN()==0)
279 return;
280
281 TString str(opt);
282 if (!str.Contains("A"))
283 str += "A";
284 if (!str.Contains("P"))
285 str += "P";
286 if (str.Contains("same", TString::kIgnoreCase))
287 {
288 str.ReplaceAll("same", "");
289 str.ReplaceAll("A", "");
290 }
291
292 TH1 *h = fGraph->GetHistogram();
293
294 h->SetXTitle("Time");
295
296 if (!fNameTime.IsNull())
297 {
298 TAxis *axe = h->GetXaxis();
299 axe->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
300 axe->SetTimeDisplay(1);
301 axe->SetLabelSize(0.033);
302 h->GetYaxis()->SetTitleOffset(1.15);
303 }
304
305 // This is a workaround if the TGraph has only one point.
306 // Otherwise MStatusDisplay::Update hangs.
307 gPad->GetListOfPrimitives()->Remove(fGraph);
308 fGraph->Draw(fGraph->GetN()<2 ? "A" : str.Data());
309}
310
311// --------------------------------------------------------------------------
312//
313// This displays the TGraph like you expect it to be (eg. time on the axis)
314// It should also make sure, that the displayed time always is UTC and
315// not local time...
316//
317void MHSectorVsTime::Draw(Option_t *opt)
318{
319 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
320 pad->SetBorderMode(0);
321 AppendPad(opt);
322}
Note: See TracBrowser for help on using the repository browser.