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

Last change on this file since 6965 was 4893, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.3 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/////////////////////////////////////////////////////////////////////////////
41#include "MHSectorVsTime.h"
42
43#include <TCanvas.h>
44#include <TGraphErrors.h>
45
46#include "MLog.h"
47#include "MLogManip.h"
48
49#include "MParList.h"
50#include "MCamEvent.h"
51
52#include "MGeomCam.h"
53
54#include "MRawEvtHeader.h"
55#include "MTime.h"
56
57ClassImp(MHSectorVsTime);
58
59using namespace std;
60
61const TString MHSectorVsTime::gsDefName = "MSectorHVsTime";
62const TString MHSectorVsTime::gsDefTitle = "Graph of sector mean vs. time";
63
64// --------------------------------------------------------------------------
65//
66// Initialize the name and title of the task. If fErrType>=0 the variance is
67// taken into account.
68//
69MHSectorVsTime::MHSectorVsTime(const char *name, const char *title)
70 : fGraph(0), fEvt(NULL), fType(0), fTypeErr(-1)
71{
72 //
73 // set the name and title of this object
74 //
75 fName = name ? name : gsDefName.Data();
76 fTitle = title ? title : gsDefTitle.Data();
77}
78
79// --------------------------------------------------------------------------
80//
81// Delete the fGraph
82//
83MHSectorVsTime::~MHSectorVsTime()
84{
85 if (fGraph)
86 delete fGraph;
87}
88
89// --------------------------------------------------------------------------
90//
91// Set the name of the TGraph and the MHVsTime container
92//
93void MHSectorVsTime::SetName(const char *name)
94{
95 fGraph->SetName(name);
96 MParContainer::SetName(name);
97}
98
99// --------------------------------------------------------------------------
100//
101// Set the title of the TGraph and the MHVsTime container
102//
103void MHSectorVsTime::SetTitle(const char *title)
104{
105 fGraph->SetTitle(title);
106 MParContainer::SetTitle(title);
107}
108
109
110// --------------------------------------------------------------------------
111//
112// Get the event (MPixVsTime) the histogram might be filled with. If
113// it is not given, it is assumed, that it is filled with the argument
114// of the Fill function.
115// Looks for the camera geometry MGeomCam and resets the sum histogram.
116// Create and/or initialize fGraph
117//
118Bool_t MHSectorVsTime::SetupFill(const MParList *plist)
119{
120 fEvt = dynamic_cast<MCamEvent*>(plist->FindObject(fNameEvt, "MCamEvent"));
121 if (!fEvt)
122 {
123 if (!fNameEvt.IsNull())
124 {
125 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
126 return kFALSE;
127 }
128 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
129 }
130
131 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
132 if (!fCam)
133 {
134 *fLog << err << "MGeomCam not found... aborting." << endl;
135 return kFALSE;
136 }
137
138 fHCamera.SetGeometry(*fCam);
139
140 if (!fNameTime.IsNull())
141 {
142 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
143 if (!fTime)
144 {
145 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
146 return kFALSE;
147 }
148 }
149 else
150 {
151 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
152 if (!fHeader)
153 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
154 }
155
156 if (fGraph)
157 delete fGraph;
158
159 fGraph = fTypeErr<0 ? new TGraph : new TGraphErrors;
160 fGraph->SetName(fEvt ? dynamic_cast<TObject*>(fEvt)->GetName() : "MCamEvent");
161 fGraph->SetTitle(fTitle==gsDefTitle?"Camera":fTitle.Data());
162
163 fMin = FLT_MAX;
164 fMax = -FLT_MAX;
165
166 return kTRUE;
167}
168
169// --------------------------------------------------------------------------
170//
171// Fill the histograms with data from a MCamEvent
172//
173Bool_t MHSectorVsTime::Fill(const MParContainer *par, const Stat_t w)
174{
175 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
176 if (!evt)
177 {
178 *fLog << err << dbginf << "No MCamEvent found..." << endl;
179 return kFALSE;
180 }
181
182 Double_t t = 0;
183 if (!fNameTime.IsNull())
184 t = fTime->GetAxisTime();
185 else
186 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
187
188
189 fHCamera.SetCamContent(*evt, fType);
190
191 const Double_t val0 = fHCamera.GetMeanSectors(fSectors, fAreaIndex);
192
193 if (TMath::IsNaN(val0)/* || TMath::IsNaN(rms0)*/)
194 return kCONTINUE;
195
196 fGraph->SetPoint(fGraph->GetN(), t, val0);
197
198 if (fTypeErr>=0)
199 {
200 const Double_t rms0 = fHCamera.GetRmsSectors(fSectors, fAreaIndex);
201 if (TMath::IsNaN(rms0))
202 return kCONTINUE;
203 ((TGraphErrors*)fGraph)->SetPointError(fGraph->GetN()-1, 0, rms0);
204 }
205
206 fMin = TMath::Min(fMin, val0);
207 fMax = TMath::Max(fMax, val0);
208
209 return kTRUE;
210}
211
212// --------------------------------------------------------------------------
213//
214// Set Minimum and Maximum;
215//
216Bool_t MHSectorVsTime::Finalize()
217{
218 const Double_t add = (fMax-fMin)*0.15;
219
220 fGraph->SetMinimum(fMin-add);
221 fGraph->SetMaximum(fMax+add);
222
223 *fLog << dbg << "Min=" << fMin << " " << fMin-add << endl;
224 *fLog << dbg << "Max=" << fMax << " " << fMax+add << endl;
225
226 return kTRUE;
227}
228
229// --------------------------------------------------------------------------
230//
231// Return fHistogram from TGraph
232//
233TH1 *MHSectorVsTime::GetHistByName(const TString name)
234{
235 return fGraph->GetHistogram();
236}
237
238void MHSectorVsTime::Draw(Option_t *opt)
239{
240 if (!fGraph)
241 return;
242
243 if (fGraph->GetN()==0)
244 return;
245
246 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
247 pad->SetBorderMode(0);
248
249 AppendPad("");
250
251 TString str(opt);
252
253 if (!str.Contains("A"))
254 str += "A";
255 if (!str.Contains("L"))
256 str += "L";
257
258 if (str.Contains("same", TString::kIgnoreCase))
259 {
260 str.ReplaceAll("same", "");
261 str.ReplaceAll("A", "");
262 }
263
264 TH1 *h = fGraph->GetHistogram();
265
266 h->SetXTitle("Time");
267
268 if (!fNameTime.IsNull())
269 {
270 TAxis *axe = h->GetXaxis();
271 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00 GMT");
272 axe->SetTimeDisplay(1);
273 axe->SetLabelSize(0.025);
274 }
275
276 fGraph->Draw(str);
277}
Note: See TracBrowser for help on using the repository browser.