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