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, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MHVsTime
|
---|
28 | //
|
---|
29 | // Use this class if you want to display any rule vs time (or event number)
|
---|
30 | //
|
---|
31 | // eg.
|
---|
32 | // MHVsTime hist("MHillas.fAlpha");
|
---|
33 | // MHVsTime hist("MPointintPos.GetAbsErr");
|
---|
34 | // MHVsTime hist("MPointintPos.GetAbsErr*kRad2Deg");
|
---|
35 | //
|
---|
36 | // To set a maximum number of data-points (eg. to display the last 20min
|
---|
37 | // only) call SetMaxPts(200)
|
---|
38 | //
|
---|
39 | // SetMaxPts(-1) disables this feature.
|
---|
40 | //
|
---|
41 | /////////////////////////////////////////////////////////////////////////////
|
---|
42 | #include "MHVsTime.h"
|
---|
43 |
|
---|
44 | #include <ctype.h> // tolower
|
---|
45 | #include <fstream>
|
---|
46 |
|
---|
47 | #include <TPad.h>
|
---|
48 | #include <TStyle.h>
|
---|
49 | #include <TCanvas.h>
|
---|
50 |
|
---|
51 | #include <TGraph.h>
|
---|
52 |
|
---|
53 | #include "MLog.h"
|
---|
54 | #include "MLogManip.h"
|
---|
55 |
|
---|
56 | #include "MTime.h"
|
---|
57 | #include "MParList.h"
|
---|
58 | #include "MDataChain.h"
|
---|
59 | #include "MRawEvtHeader.h"
|
---|
60 |
|
---|
61 | ClassImp(MHVsTime);
|
---|
62 |
|
---|
63 | using namespace std;
|
---|
64 |
|
---|
65 | static const TString gsDefName = "MHVsTime";
|
---|
66 | static const TString gsDefTitle = "Container for a graph vs time/evtnumber";
|
---|
67 |
|
---|
68 | // --------------------------------------------------------------------------
|
---|
69 | //
|
---|
70 | // Default constructor. For more informations about a valid rule
|
---|
71 | // see MDataChain.
|
---|
72 | //
|
---|
73 | MHVsTime::MHVsTime(const char *rule)
|
---|
74 | : fGraph(NULL), fData(NULL), fScale(1), fMaxPts(-1), fUseEventNumber(0)
|
---|
75 | {
|
---|
76 | fName = gsDefName;
|
---|
77 | fTitle = gsDefTitle;
|
---|
78 |
|
---|
79 | if (!rule)
|
---|
80 | return;
|
---|
81 |
|
---|
82 | fGraph = new TGraph;
|
---|
83 | fData = new MDataChain(rule);
|
---|
84 | }
|
---|
85 |
|
---|
86 | // --------------------------------------------------------------------------
|
---|
87 | //
|
---|
88 | // Deletes the histogram
|
---|
89 | //
|
---|
90 | MHVsTime::~MHVsTime()
|
---|
91 | {
|
---|
92 | if (fGraph)
|
---|
93 | delete fGraph;
|
---|
94 |
|
---|
95 | if (fData)
|
---|
96 | delete fData;
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Return the data members used by the data chain to be used in
|
---|
102 | // MTask::AddBranchToList
|
---|
103 | //
|
---|
104 | TString MHVsTime::GetDataMember() const
|
---|
105 | {
|
---|
106 | return fData ? fData->GetDataMember() : (TString)"";
|
---|
107 | }
|
---|
108 |
|
---|
109 | // --------------------------------------------------------------------------
|
---|
110 | //
|
---|
111 | // PreProcess the MDataChain. Create a new TGraph. Delete an old one if
|
---|
112 | // already allocated.
|
---|
113 | //
|
---|
114 | Bool_t MHVsTime::SetupFill(const MParList *plist)
|
---|
115 | {
|
---|
116 | // reset histogram (necessary if the same eventloop is run more than once)
|
---|
117 | //fGraph->Reset();
|
---|
118 |
|
---|
119 | if (fData && !fData->PreProcess(plist))
|
---|
120 | return kFALSE;
|
---|
121 |
|
---|
122 | if (fGraph)
|
---|
123 | {
|
---|
124 | delete fGraph;
|
---|
125 | fGraph = new TGraph;
|
---|
126 | }
|
---|
127 |
|
---|
128 | TString title(fData ? GetRule() : (TString)"Histogram");
|
---|
129 | title += " vs ";
|
---|
130 | title += fUseEventNumber ? "Event Number" : "Time";
|
---|
131 |
|
---|
132 | fGraph->SetNameTitle(fName, title);
|
---|
133 |
|
---|
134 | return kTRUE;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // --------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // Set the name of the TGraph and the MHVsTime container
|
---|
140 | //
|
---|
141 | void MHVsTime::SetName(const char *name)
|
---|
142 | {
|
---|
143 | fGraph->SetName(name);
|
---|
144 | MParContainer::SetName(name);
|
---|
145 | }
|
---|
146 |
|
---|
147 | // --------------------------------------------------------------------------
|
---|
148 | //
|
---|
149 | // Set the title of the TGraph and the MHVsTime container
|
---|
150 | //
|
---|
151 | void MHVsTime::SetTitle(const char *title)
|
---|
152 | {
|
---|
153 | fGraph->SetTitle(title);
|
---|
154 | MParContainer::SetTitle(title);
|
---|
155 | }
|
---|
156 |
|
---|
157 | // --------------------------------------------------------------------------
|
---|
158 | //
|
---|
159 | // Set the next data point. If the graph exceeds fMaxPts remove the first
|
---|
160 | //
|
---|
161 | Bool_t MHVsTime::Fill(const MParContainer *par, const Stat_t w)
|
---|
162 | {
|
---|
163 | Double_t t = 0;
|
---|
164 | if (fUseEventNumber)
|
---|
165 | {
|
---|
166 | const MRawEvtHeader *h = dynamic_cast<const MRawEvtHeader*>(par);
|
---|
167 | t = h ? h->GetDAQEvtNumber() : fGraph->GetN();
|
---|
168 | }
|
---|
169 | else
|
---|
170 | {
|
---|
171 | const MTime *tm = dynamic_cast<const MTime*>(par);
|
---|
172 | if (!tm)
|
---|
173 | {
|
---|
174 | *fLog << err << dbginf << "No MTime found..." << endl;
|
---|
175 | return kFALSE;
|
---|
176 | }
|
---|
177 | // If the time is not valid skip this entry
|
---|
178 | if (!*tm)
|
---|
179 | return kTRUE;
|
---|
180 | t = tm->GetAxisTime();
|
---|
181 | }
|
---|
182 |
|
---|
183 | const Double_t v = fData->GetValue()*fScale;
|
---|
184 |
|
---|
185 | if (fMaxPts>0 && fGraph->GetN()>fMaxPts)
|
---|
186 | fGraph->RemovePoint(0);
|
---|
187 |
|
---|
188 | fGraph->SetPoint(fGraph->GetN(), t, v);
|
---|
189 |
|
---|
190 | return kTRUE;
|
---|
191 | }
|
---|
192 |
|
---|
193 | // --------------------------------------------------------------------------
|
---|
194 | //
|
---|
195 | // This displays the TGraph like you expect it to be (eg. time on the axis)
|
---|
196 | // It should also make sure, that the displayed time always is UTC and
|
---|
197 | // not local time...
|
---|
198 | //
|
---|
199 | void MHVsTime::Draw(Option_t *opt)
|
---|
200 | {
|
---|
201 | if (fGraph->GetN()==0)
|
---|
202 | return;
|
---|
203 |
|
---|
204 | TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
|
---|
205 | pad->SetBorderMode(0);
|
---|
206 |
|
---|
207 | AppendPad("");
|
---|
208 |
|
---|
209 | TString str(opt);
|
---|
210 |
|
---|
211 | if (fUseEventNumber)
|
---|
212 | fGraph->GetHistogram()->SetXTitle("Event Number");
|
---|
213 | else
|
---|
214 | {
|
---|
215 | fGraph->GetHistogram()->SetXTitle("Time");
|
---|
216 | fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00");
|
---|
217 | fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
|
---|
218 | fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
|
---|
219 | }
|
---|
220 | fGraph->GetHistogram()->SetYTitle(GetRule());
|
---|
221 |
|
---|
222 | if (!str.Contains("A"))
|
---|
223 | str += "A";
|
---|
224 | if (!str.Contains("P"))
|
---|
225 | str += "P";
|
---|
226 |
|
---|
227 | if (str.Contains("same", TString::kIgnoreCase))
|
---|
228 | {
|
---|
229 | str.ReplaceAll("same", "");
|
---|
230 | str.ReplaceAll("A", "");
|
---|
231 | }
|
---|
232 |
|
---|
233 | fGraph->Draw(str);
|
---|
234 | if (fGraph->TestBit(kIsLogy))
|
---|
235 | pad->SetLogy();
|
---|
236 |
|
---|
237 | pad->Modified();
|
---|
238 | pad->Update();
|
---|
239 | }
|
---|
240 |
|
---|
241 | // --------------------------------------------------------------------------
|
---|
242 | //
|
---|
243 | // Used to rebuild a MHVsTime object of the same type (data members,
|
---|
244 | // dimension, ...)
|
---|
245 | //
|
---|
246 | MParContainer *MHVsTime::New() const
|
---|
247 | {
|
---|
248 | MHVsTime *h=new MHVsTime(fData ? (const char*)GetRule() : NULL);
|
---|
249 | h->SetScale(fScale);
|
---|
250 | if (fUseEventNumber)
|
---|
251 | h->SetUseEventNumber();
|
---|
252 | h->SetMaxPts(fMaxPts);
|
---|
253 | return h;
|
---|
254 | }
|
---|
255 |
|
---|
256 | TString MHVsTime::GetRule() const
|
---|
257 | {
|
---|
258 | return fData ? fData->GetRule() : (TString)"";
|
---|
259 | }
|
---|
260 |
|
---|
261 | // --------------------------------------------------------------------------
|
---|
262 | //
|
---|
263 | // Returns the total number of bins in a histogram (excluding under- and
|
---|
264 | // overflow bins)
|
---|
265 | //
|
---|
266 | Int_t MHVsTime::GetNbins() const
|
---|
267 | {
|
---|
268 | return fGraph->GetN();
|
---|
269 | }
|
---|
270 | /*
|
---|
271 | TH1 *MHVsTime::GetHist()
|
---|
272 | {
|
---|
273 | return fGraph ? fGraph->GetHistogram() : 0;
|
---|
274 | }
|
---|
275 |
|
---|
276 | const TH1 *MHVsTime::GetHist() const
|
---|
277 | {
|
---|
278 | return fGraph ? fGraph->GetHistogram() : 0;
|
---|
279 | }
|
---|
280 |
|
---|
281 | TH1 *MHVsTime::GetHistByName(const TString name)
|
---|
282 | {
|
---|
283 | return GetHist();
|
---|
284 | }
|
---|
285 | */
|
---|