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

Last change on this file since 9376 was 9303, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 9.7 KB
Line 
1/* ======================================================================== *\
2! $Name: not supported by cvs2svn $:$Id: MHSectorVsTime.cc,v 1.15 2009-02-07 20:47:55 tbretz Exp $
3! --------------------------------------------------------------------------
4!
5! *
6! * This file is part of MARS, the MAGIC Analysis and Reconstruction
7! * Software. It is distributed to you in the hope that it can be a useful
8! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9! * It is distributed WITHOUT ANY WARRANTY.
10! *
11! * Permission to use, copy, modify and distribute this software and its
12! * documentation for any purpose is hereby granted without fee,
13! * provided that the above copyright notice appear in all copies and
14! * that both that copyright notice and this permission notice appear
15! * in supporting documentation. It is provided "as is" without express
16! * or implied warranty.
17! *
18!
19!
20! Author(s): Thomas Bretz, 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2006
23!
24!
25\* ======================================================================== */
26
27/////////////////////////////////////////////////////////////////////////////
28//
29// MHSectorVsTime
30//
31// Display the mean and its variance vs time of the whole camera or a
32// single sector
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// Example:
43// --------
44// // Initialize histogram
45// MHSectorVsTime hist1;
46// hist1.SetNameTime("MTimeCurrents");
47// hist1.SetTitle("Title for your Graph;;Q [phe]");
48//
49// // Define sectors you want to display the mean from
50// TArrayI s0(3);
51// s0[0] = 6;
52// s0[1] = 1;
53// s0[2] = 2;
54//
55// // Define area index [0=inner, 1=outer]
56// TArrayI inner(1);
57// inner[0] = 0;
58//
59// // Don't call this if you want to have all sectors
60// hist1.SetSectors(s0);
61//
62// // Don't call this if you want to have all area indices
63// hist1.SetAreaIndex(inner);
64//
65// // Task to fill the histogram
66// MFillH fill1(&hist1, "MCameraDC");
67//
68//
69// Class Version 2:
70// ----------------
71// + Double_t fMinimum; // User defined minimum
72// + Double_t fMaximum; // User defined maximum
73//
74// Class Version 3:
75// ----------------
76// + Bool_t fUseMedian;
77//
78//
79/////////////////////////////////////////////////////////////////////////////
80#include "MHSectorVsTime.h"
81
82#include <TCanvas.h>
83#include <TGraphErrors.h>
84
85#include "MLog.h"
86#include "MLogManip.h"
87
88#include "MParList.h"
89#include "MCamEvent.h"
90
91#include "MGeomCam.h"
92
93#include "MRawEvtHeader.h"
94#include "MTime.h"
95
96ClassImp(MHSectorVsTime);
97
98using namespace std;
99
100const TString MHSectorVsTime::gsDefName = "MHSectorVsTime";
101const TString MHSectorVsTime::gsDefTitle = "Graph of sector mean vs. time";
102
103// --------------------------------------------------------------------------
104//
105// Initialize the name and title of the task. If fErrType>=0 the variance is
106// taken into account.
107//
108MHSectorVsTime::MHSectorVsTime(const char *name, const char *title)
109 : fGraph(0), fEvt(NULL), fMinimum(-1111), fMaximum(-1111), fUseMedian(kFALSE),
110 fType(0), fTypeErr(-1)
111{
112 //
113 // set the name and title of this object
114 //
115 fName = name ? name : gsDefName.Data();
116 fTitle = title ? title : gsDefTitle.Data();
117}
118
119// --------------------------------------------------------------------------
120//
121// Delete the fGraph
122//
123MHSectorVsTime::~MHSectorVsTime()
124{
125 if (fGraph)
126 delete fGraph;
127}
128
129// --------------------------------------------------------------------------
130//
131// Set the name of the TGraph and the MHVsTime container
132//
133void MHSectorVsTime::SetName(const char *name)
134{
135 if (fGraph)
136 fGraph->SetName(name);
137 MParContainer::SetName(name);
138}
139
140// --------------------------------------------------------------------------
141//
142// Set the title of the TGraph and the MHVsTime container
143//
144void MHSectorVsTime::SetTitle(const char *title)
145{
146 if (fGraph)
147 fGraph->SetTitle(title);
148 MParContainer::SetTitle(title);
149}
150
151
152// --------------------------------------------------------------------------
153//
154// Get the event (MPixVsTime) the histogram might be filled with. If
155// it is not given, it is assumed, that it is filled with the argument
156// of the Fill function.
157// Looks for the camera geometry MGeomCam and resets the sum histogram.
158// Create and/or initialize fGraph
159//
160Bool_t MHSectorVsTime::SetupFill(const MParList *plist)
161{
162 fEvt = dynamic_cast<MCamEvent*>(plist->FindObject(fNameEvt, "MCamEvent"));
163 if (!fEvt)
164 {
165 if (!fNameEvt.IsNull())
166 {
167 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
168 return kFALSE;
169 }
170 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
171 }
172
173 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
174 if (!fCam)
175 {
176 *fLog << err << "MGeomCam not found... aborting." << endl;
177 return kFALSE;
178 }
179
180 fHCamera.SetGeometry(*fCam);
181
182 if (!fNameTime.IsNull())
183 {
184 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
185 if (!fTime)
186 {
187 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
188 return kFALSE;
189 }
190 }
191 else
192 {
193 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
194 if (!fHeader)
195 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
196 }
197
198 if (fGraph)
199 delete fGraph;
200
201 fGraph = fTypeErr<0 ? new TGraph : new TGraphErrors;
202 fGraph->SetName(fEvt ? dynamic_cast<TObject*>(fEvt)->GetName() : "MCamEvent");
203 fGraph->SetTitle(fTitle==gsDefTitle?"Camera":fTitle.Data());
204 fGraph->SetMarkerStyle(kFullDotMedium);
205
206 fMin = FLT_MAX;
207 fMax = -FLT_MAX;
208
209 return kTRUE;
210}
211
212// --------------------------------------------------------------------------
213//
214// Fill the histograms with data from a MCamEvent
215//
216Int_t MHSectorVsTime::Fill(const MParContainer *par, const Stat_t w)
217{
218 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
219 if (!evt)
220 {
221 *fLog << err << dbginf << "No MCamEvent found..." << endl;
222 return kERROR;
223 }
224
225 Double_t t = 0;
226 if (!fNameTime.IsNull())
227 t = fTime->GetAxisTime();
228 else
229 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
230
231
232 fHCamera.SetCamContent(*evt, fType);
233
234 const Double_t val0 = fUseMedian ?
235 fHCamera.GetMedianSectors(fSectors, fAreaIndex) :
236 fHCamera.GetMeanSectors(fSectors, fAreaIndex);
237
238 if (!TMath::Finite(val0))
239 return kTRUE;
240
241 fGraph->SetPoint(fGraph->GetN(), t, val0);
242
243 if (fTypeErr>=0)
244 {
245 const Double_t rms0 = fUseMedian ?
246 fHCamera.GetDevSectors(fSectors, fAreaIndex) :
247
248 fHCamera.GetRmsSectors(fSectors, fAreaIndex);
249 if (!TMath::Finite(rms0))
250 return kTRUE;
251
252 ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
253 }
254
255 fMin = TMath::Min(fMin, val0);
256 fMax = TMath::Max(fMax, val0);
257
258 return kTRUE;
259}
260
261// --------------------------------------------------------------------------
262//
263// Set Minimum and Maximum;
264//
265Bool_t MHSectorVsTime::Finalize()
266{
267 const Double_t add = (fMax-fMin)*0.15;
268
269 if (fMinimum==-1111)
270 fGraph->SetMinimum(fMin-add);
271 if (fMaximum==-1111)
272 fGraph->SetMaximum(fMax+add);
273
274 return kTRUE;
275}
276
277// --------------------------------------------------------------------------
278//
279// Return fHistogram from TGraph
280//
281TH1 *MHSectorVsTime::GetHistByName(const TString name) const
282{
283 return fGraph->GetHistogram();
284}
285
286void MHSectorVsTime::Paint(Option_t *opt)
287{
288 if (!fGraph)
289 return;
290
291 if (fGraph->GetN()==0)
292 return;
293
294 TString str(opt);
295 if (!str.Contains("A"))
296 str += "A";
297 if (!str.Contains("P"))
298 str += "P";
299 if (str.Contains("same", TString::kIgnoreCase))
300 {
301 str.ReplaceAll("same", "");
302 str.ReplaceAll("A", "");
303 }
304
305 // This is not done automatically anymore since root 5.12/00
306 // and it is necessary to force a proper update of the axis.
307 TH1 *h = fGraph->GetHistogram();
308 if (h)
309 {
310 delete h;
311 fGraph->SetHistogram(0);
312 h = fGraph->GetHistogram();
313 }
314
315 h->SetXTitle("Time");
316
317 if (!fNameTime.IsNull())
318 {
319 TAxis *axe = h->GetXaxis();
320 axe->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
321 axe->SetTimeDisplay(1);
322 axe->SetLabelSize(0.033);
323 h->GetYaxis()->SetTitleOffset(1.15);
324 }
325
326 // If this is set to early the plot remains empty in root 5.12/00
327 if (fMinimum!=-1111)
328 fGraph->SetMinimum(fMinimum);
329 if (fMaximum!=-1111)
330 fGraph->SetMaximum(fMaximum);
331
332 // This is a workaround if the TGraph has only one point.
333 // Otherwise MStatusDisplay::Update hangs.
334 gPad->GetListOfPrimitives()->Remove(fGraph);
335 fGraph->Draw(fGraph->GetN()<2 ? "A" : str.Data());
336}
337
338// --------------------------------------------------------------------------
339//
340// This displays the TGraph like you expect it to be (eg. time on the axis)
341// It should also make sure, that the displayed time always is UTC and
342// not local time...
343//
344void MHSectorVsTime::Draw(Option_t *opt)
345{
346 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
347 pad->SetBorderMode(0);
348 pad->SetGridx();
349 pad->SetGridy();
350 AppendPad(opt);
351}
352
353void MHSectorVsTime::RecursiveRemove(TObject *obj)
354{
355 if (obj==fGraph)
356 fGraph = 0;
357}
Note: See TracBrowser for help on using the repository browser.