source: trunk/Mars/mhvstime/MHSectorVsTime.cc@ 19868

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