source: branches/Corsika7500Compatibility/mhvstime/MHSectorVsTime.cc@ 19536

Last change on this file since 19536 was 12880, checked in by tbretz, 13 years ago
Removed some old workarounds hopefully not necessary anymor with newer root version -- tested with 5.32.00 so far.
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 delete fGraph;
125}
126
127// --------------------------------------------------------------------------
128//
129// Set the name of the TGraph and the MHVsTime container
130//
131void MHSectorVsTime::SetName(const char *name)
132{
133 if (fGraph)
134 fGraph->SetName(name);
135 MParContainer::SetName(name);
136}
137
138// --------------------------------------------------------------------------
139//
140// Set the title of the TGraph and the MHVsTime container
141//
142void MHSectorVsTime::SetTitle(const char *title)
143{
144 if (fGraph)
145 fGraph->SetTitle(title);
146 MParContainer::SetTitle(title);
147}
148
149
150// --------------------------------------------------------------------------
151//
152// Get the event (MPixVsTime) the histogram might be filled with. If
153// it is not given, it is assumed, that it is filled with the argument
154// of the Fill function.
155// Looks for the camera geometry MGeomCam and resets the sum histogram.
156// Create and/or initialize fGraph
157//
158Bool_t MHSectorVsTime::SetupFill(const MParList *plist)
159{
160 fEvt = dynamic_cast<MCamEvent*>(plist->FindObject(fNameEvt, "MCamEvent"));
161 if (!fEvt)
162 {
163 if (!fNameEvt.IsNull())
164 {
165 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
166 return kFALSE;
167 }
168 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
169 }
170
171 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
172 if (!fCam)
173 {
174 *fLog << err << "MGeomCam not found... aborting." << endl;
175 return kFALSE;
176 }
177
178 fHCamera.SetGeometry(*fCam);
179
180 if (!fNameTime.IsNull())
181 {
182 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
183 if (!fTime)
184 {
185 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
186 return kFALSE;
187 }
188 }
189 else
190 {
191 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
192 if (!fHeader)
193 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
194 }
195
196 if (fGraph)
197 delete fGraph;
198
199 fGraph = fTypeErr<0 ? new TGraph : new TGraphErrors;
200 fGraph->SetName(fEvt ? dynamic_cast<TObject*>(fEvt)->GetName() : "MCamEvent");
201 fGraph->SetTitle(fTitle==gsDefTitle?"Camera":fTitle.Data());
202 fGraph->SetMarkerStyle(kFullDotMedium);
203
204 fMin = FLT_MAX;
205 fMax = -FLT_MAX;
206
207 return kTRUE;
208}
209
210// --------------------------------------------------------------------------
211//
212// Fill the histograms with data from a MCamEvent
213//
214Int_t MHSectorVsTime::Fill(const MParContainer *par, const Stat_t w)
215{
216 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
217 if (!evt)
218 {
219 *fLog << err << dbginf << "No MCamEvent found..." << endl;
220 return kERROR;
221 }
222
223 Double_t t = 0;
224 if (!fNameTime.IsNull())
225 t = fTime->GetAxisTime();
226 else
227 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
228
229
230 fHCamera.SetCamContent(*evt, fType);
231
232 const Double_t val0 = fUseMedian ?
233 fHCamera.GetMedianSectors(fSectors, fAreaIndex) :
234 fHCamera.GetMeanSectors(fSectors, fAreaIndex);
235
236 if (!TMath::Finite(val0))
237 return kTRUE;
238
239 fGraph->SetPoint(fGraph->GetN(), t, val0);
240
241 if (fTypeErr>=0)
242 {
243 const Double_t rms0 = fUseMedian ?
244 fHCamera.GetDevSectors(fSectors, fAreaIndex) :
245
246 fHCamera.GetRmsSectors(fSectors, fAreaIndex);
247 if (!TMath::Finite(rms0))
248 return kTRUE;
249
250 ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
251 }
252
253 fMin = TMath::Min(fMin, val0);
254 fMax = TMath::Max(fMax, val0);
255
256 return kTRUE;
257}
258
259// --------------------------------------------------------------------------
260//
261// Set Minimum and Maximum;
262//
263Bool_t MHSectorVsTime::Finalize()
264{
265 const Double_t add = (fMax-fMin)*0.15;
266
267 if (fMinimum==-1111)
268 fGraph->SetMinimum(fMin-add);
269 if (fMaximum==-1111)
270 fGraph->SetMaximum(fMax+add);
271
272 return kTRUE;
273}
274
275// --------------------------------------------------------------------------
276//
277// Return fHistogram from TGraph
278//
279TH1 *MHSectorVsTime::GetHistByName(const TString name) const
280{
281 return fGraph->GetHistogram();
282}
283
284// --------------------------------------------------------------------------
285//
286// This displays the TGraph like you expect it to be (eg. time on the axis)
287// It should also make sure, that the displayed time always is UTC and
288// not local time...
289//
290void MHSectorVsTime::Draw(Option_t *opt)
291{
292 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
293 pad->SetBorderMode(0);
294 pad->SetGrid();
295
296 AppendPad("");
297
298 // This is not done automatically anymore since root 5.12/00
299 // and it is necessary to force a proper update of the axis.
300 TH1 *h = fGraph->GetHistogram();
301
302 h->SetXTitle("Time");
303
304 if (!fNameTime.IsNull())
305 {
306 TAxis *axe = h->GetXaxis();
307 axe->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
308 axe->SetTimeDisplay(1);
309 axe->SetLabelSize(0.033);
310 h->GetYaxis()->SetTitleOffset(1.15);
311 }
312
313 // If this is set to early the plot remains empty in root 5.12/00
314 if (fMinimum!=-1111)
315 fGraph->SetMinimum(fMinimum);
316 if (fMaximum!=-1111)
317 fGraph->SetMaximum(fMaximum);
318
319 TString str(opt);
320 if (!str.Contains("A"))
321 str += "A";
322 if (!str.Contains("P"))
323 str += "P";
324 if (str.Contains("same", TString::kIgnoreCase))
325 {
326 str.ReplaceAll("same", "");
327 str.ReplaceAll("A", "");
328 }
329
330 fGraph->Draw(str.Data());
331}
332
333void MHSectorVsTime::RecursiveRemove(TObject *obj)
334{
335 if (obj==fGraph)
336 fGraph = 0;
337}
Note: See TracBrowser for help on using the repository browser.