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

Last change on this file since 7551 was 7355, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 8.8 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 if (fMinimum!=-1111)
201 fGraph->SetMinimum(fMinimum);
202 if (fMaximum!=-1111)
203 fGraph->SetMaximum(fMaximum);
204
205 fMin = FLT_MAX;
206 fMax = -FLT_MAX;
207
208 return kTRUE;
209}
210
211// --------------------------------------------------------------------------
212//
213// Fill the histograms with data from a MCamEvent
214//
215Bool_t MHSectorVsTime::Fill(const MParContainer *par, const Stat_t w)
216{
217 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
218 if (!evt)
219 {
220 *fLog << err << dbginf << "No MCamEvent found..." << endl;
221 return kFALSE;
222 }
223
224 Double_t t = 0;
225 if (!fNameTime.IsNull())
226 t = fTime->GetAxisTime();
227 else
228 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
229
230
231 fHCamera.SetCamContent(*evt, fType);
232
233 const Double_t val0 = fHCamera.GetMeanSectors(fSectors, fAreaIndex);
234
235 if (TMath::IsNaN(val0))
236 return kTRUE;
237
238 fGraph->SetPoint(fGraph->GetN(), t, val0);
239
240 if (fTypeErr>=0)
241 {
242 const Double_t rms0 = fHCamera.GetRmsSectors(fSectors, fAreaIndex);
243 if (TMath::IsNaN(rms0))
244 return kTRUE;
245 ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
246 }
247
248 fMin = TMath::Min(fMin, val0);
249 fMax = TMath::Max(fMax, val0);
250
251 return kTRUE;
252}
253
254// --------------------------------------------------------------------------
255//
256// Set Minimum and Maximum;
257//
258Bool_t MHSectorVsTime::Finalize()
259{
260 const Double_t add = (fMax-fMin)*0.15;
261
262 if (fMinimum==-1111)
263 fGraph->SetMinimum(fMin-add);
264 if (fMaximum==-1111)
265 fGraph->SetMaximum(fMax+add);
266
267 return kTRUE;
268}
269
270// --------------------------------------------------------------------------
271//
272// Return fHistogram from TGraph
273//
274TH1 *MHSectorVsTime::GetHistByName(const TString name) const
275{
276 return fGraph->GetHistogram();
277}
278
279void MHSectorVsTime::Paint(Option_t *opt)
280{
281 if (!fGraph)
282 return;
283
284 if (fGraph->GetN()==0)
285 return;
286
287 TString str(opt);
288 if (!str.Contains("A"))
289 str += "A";
290 if (!str.Contains("P"))
291 str += "P";
292 if (str.Contains("same", TString::kIgnoreCase))
293 {
294 str.ReplaceAll("same", "");
295 str.ReplaceAll("A", "");
296 }
297
298 TH1 *h = fGraph->GetHistogram();
299
300 h->SetXTitle("Time");
301
302 if (!fNameTime.IsNull())
303 {
304 TAxis *axe = h->GetXaxis();
305 axe->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
306 axe->SetTimeDisplay(1);
307 axe->SetLabelSize(0.033);
308 h->GetYaxis()->SetTitleOffset(1.15);
309 }
310
311 // This is a workaround if the TGraph has only one point.
312 // Otherwise MStatusDisplay::Update hangs.
313 gPad->GetListOfPrimitives()->Remove(fGraph);
314 fGraph->Draw(fGraph->GetN()<2 ? "A" : str.Data());
315}
316
317// --------------------------------------------------------------------------
318//
319// This displays the TGraph like you expect it to be (eg. time on the axis)
320// It should also make sure, that the displayed time always is UTC and
321// not local time...
322//
323void MHSectorVsTime::Draw(Option_t *opt)
324{
325 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
326 pad->SetBorderMode(0);
327 AppendPad(opt);
328}
Note: See TracBrowser for help on using the repository browser.