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

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