source: tags/Mars-V0.10/mhvstime/MHSectorVsTime.cc

Last change on this file was 8022, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 9.2 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// Class Version 2:
68// ----------------
69// + Double_t fMinimum; // User defined minimum
70// + Double_t fMaximum; // User defined maximum
71//
72//
73/////////////////////////////////////////////////////////////////////////////
74#include "MHSectorVsTime.h"
75
76#include <TCanvas.h>
77#include <TGraphErrors.h>
78
79#include "MLog.h"
80#include "MLogManip.h"
81
82#include "MParList.h"
83#include "MCamEvent.h"
84
85#include "MGeomCam.h"
86
87#include "MRawEvtHeader.h"
88#include "MTime.h"
89
90ClassImp(MHSectorVsTime);
91
92using namespace std;
93
94const TString MHSectorVsTime::gsDefName = "MHSectorVsTime";
95const TString MHSectorVsTime::gsDefTitle = "Graph of sector mean vs. time";
96
97// --------------------------------------------------------------------------
98//
99// Initialize the name and title of the task. If fErrType>=0 the variance is
100// taken into account.
101//
102MHSectorVsTime::MHSectorVsTime(const char *name, const char *title)
103 : fGraph(0), fEvt(NULL), fMinimum(-1111), fMaximum(-1111),
104 fType(0), fTypeErr(-1)
105{
106 //
107 // set the name and title of this object
108 //
109 fName = name ? name : gsDefName.Data();
110 fTitle = title ? title : gsDefTitle.Data();
111}
112
113// --------------------------------------------------------------------------
114//
115// Delete the fGraph
116//
117MHSectorVsTime::~MHSectorVsTime()
118{
119 if (fGraph)
120 delete fGraph;
121}
122
123// --------------------------------------------------------------------------
124//
125// Set the name of the TGraph and the MHVsTime container
126//
127void MHSectorVsTime::SetName(const char *name)
128{
129 if (fGraph)
130 fGraph->SetName(name);
131 MParContainer::SetName(name);
132}
133
134// --------------------------------------------------------------------------
135//
136// Set the title of the TGraph and the MHVsTime container
137//
138void MHSectorVsTime::SetTitle(const char *title)
139{
140 if (fGraph)
141 fGraph->SetTitle(title);
142 MParContainer::SetTitle(title);
143}
144
145
146// --------------------------------------------------------------------------
147//
148// Get the event (MPixVsTime) the histogram might be filled with. If
149// it is not given, it is assumed, that it is filled with the argument
150// of the Fill function.
151// Looks for the camera geometry MGeomCam and resets the sum histogram.
152// Create and/or initialize fGraph
153//
154Bool_t MHSectorVsTime::SetupFill(const MParList *plist)
155{
156 fEvt = dynamic_cast<MCamEvent*>(plist->FindObject(fNameEvt, "MCamEvent"));
157 if (!fEvt)
158 {
159 if (!fNameEvt.IsNull())
160 {
161 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
162 return kFALSE;
163 }
164 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
165 }
166
167 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
168 if (!fCam)
169 {
170 *fLog << err << "MGeomCam not found... aborting." << endl;
171 return kFALSE;
172 }
173
174 fHCamera.SetGeometry(*fCam);
175
176 if (!fNameTime.IsNull())
177 {
178 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
179 if (!fTime)
180 {
181 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
182 return kFALSE;
183 }
184 }
185 else
186 {
187 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
188 if (!fHeader)
189 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
190 }
191
192 if (fGraph)
193 delete fGraph;
194
195 fGraph = fTypeErr<0 ? new TGraph : new TGraphErrors;
196 fGraph->SetName(fEvt ? dynamic_cast<TObject*>(fEvt)->GetName() : "MCamEvent");
197 fGraph->SetTitle(fTitle==gsDefTitle?"Camera":fTitle.Data());
198 fGraph->SetMarkerStyle(kFullDotMedium);
199
200 fMin = FLT_MAX;
201 fMax = -FLT_MAX;
202
203 return kTRUE;
204}
205
206// --------------------------------------------------------------------------
207//
208// Fill the histograms with data from a MCamEvent
209//
210Bool_t MHSectorVsTime::Fill(const MParContainer *par, const Stat_t w)
211{
212 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
213 if (!evt)
214 {
215 *fLog << err << dbginf << "No MCamEvent found..." << endl;
216 return kFALSE;
217 }
218
219 Double_t t = 0;
220 if (!fNameTime.IsNull())
221 t = fTime->GetAxisTime();
222 else
223 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
224
225
226 fHCamera.SetCamContent(*evt, fType);
227
228 const Double_t val0 = fHCamera.GetMeanSectors(fSectors, fAreaIndex);
229
230 if (!TMath::Finite(val0))
231 return kTRUE;
232
233 fGraph->SetPoint(fGraph->GetN(), t, val0);
234
235 if (fTypeErr>=0)
236 {
237 const Double_t rms0 = fHCamera.GetRmsSectors(fSectors, fAreaIndex);
238 if (!TMath::Finite(rms0))
239 return kTRUE;
240 ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
241 }
242
243 fMin = TMath::Min(fMin, val0);
244 fMax = TMath::Max(fMax, val0);
245
246 return kTRUE;
247}
248
249// --------------------------------------------------------------------------
250//
251// Set Minimum and Maximum;
252//
253Bool_t MHSectorVsTime::Finalize()
254{
255 const Double_t add = (fMax-fMin)*0.15;
256
257 if (fMinimum==-1111)
258 fGraph->SetMinimum(fMin-add);
259 if (fMaximum==-1111)
260 fGraph->SetMaximum(fMax+add);
261
262 return kTRUE;
263}
264
265// --------------------------------------------------------------------------
266//
267// Return fHistogram from TGraph
268//
269TH1 *MHSectorVsTime::GetHistByName(const TString name) const
270{
271 return fGraph->GetHistogram();
272}
273
274void MHSectorVsTime::Paint(Option_t *opt)
275{
276 if (!fGraph)
277 return;
278
279 if (fGraph->GetN()==0)
280 return;
281
282 TString str(opt);
283 if (!str.Contains("A"))
284 str += "A";
285 if (!str.Contains("P"))
286 str += "P";
287 if (str.Contains("same", TString::kIgnoreCase))
288 {
289 str.ReplaceAll("same", "");
290 str.ReplaceAll("A", "");
291 }
292
293 // This is not done automatically anymore since root 5.12/00
294 // and it is necessary to force a proper update of the axis.
295 TH1 *h = fGraph->GetHistogram();
296 if (h)
297 {
298 delete h;
299 fGraph->SetHistogram(0);
300 h = fGraph->GetHistogram();
301 }
302
303 h->SetXTitle("Time");
304
305 if (!fNameTime.IsNull())
306 {
307 TAxis *axe = h->GetXaxis();
308 axe->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
309 axe->SetTimeDisplay(1);
310 axe->SetLabelSize(0.033);
311 h->GetYaxis()->SetTitleOffset(1.15);
312 }
313
314 // If this is set to early the plot remains empty in root 5.12/00
315 if (fMinimum!=-1111)
316 fGraph->SetMinimum(fMinimum);
317 if (fMaximum!=-1111)
318 fGraph->SetMaximum(fMaximum);
319
320 // This is a workaround if the TGraph has only one point.
321 // Otherwise MStatusDisplay::Update hangs.
322 gPad->GetListOfPrimitives()->Remove(fGraph);
323 fGraph->Draw(fGraph->GetN()<2 ? "A" : str.Data());
324}
325
326// --------------------------------------------------------------------------
327//
328// This displays the TGraph like you expect it to be (eg. time on the axis)
329// It should also make sure, that the displayed time always is UTC and
330// not local time...
331//
332void MHSectorVsTime::Draw(Option_t *opt)
333{
334 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
335 pad->SetBorderMode(0);
336 AppendPad(opt);
337}
Note: See TracBrowser for help on using the repository browser.