source: tags/Mars-V0.8.4/mhvstime/MHVsTime.cc

Last change on this file was 3394, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.9 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, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHVsTime
28//
29// Preliminary: the docu may be wrong!
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MHVsTime.h"
33
34#include <ctype.h> // tolower
35#include <fstream>
36
37#include <TPad.h>
38#include <TStyle.h>
39#include <TCanvas.h>
40
41#include <TGraph.h>
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MTime.h"
47#include "MParList.h"
48#include "MDataChain.h"
49#include "MRawEvtHeader.h"
50
51ClassImp(MHVsTime);
52
53using namespace std;
54
55static const TString gsDefName = "MHVsTime";
56static const TString gsDefTitle = "Container for a graph vs time/evtnumber";
57
58// --------------------------------------------------------------------------
59//
60// Default constructor.
61//
62MHVsTime::MHVsTime(const char *rule)
63 : fGraph(NULL), fData(NULL), fScale(1), fUseEventNumber(0)
64{
65 fName = gsDefName;
66 fTitle = gsDefTitle;
67
68 if (!rule)
69 return;
70
71 fGraph = new TGraph;
72 fData = new MDataChain(rule);
73}
74
75// --------------------------------------------------------------------------
76//
77// Deletes the histogram
78//
79MHVsTime::~MHVsTime()
80{
81 if (fGraph)
82 delete fGraph;
83
84 if (fData)
85 delete fData;
86}
87
88// --------------------------------------------------------------------------
89//
90// Return the data members used by the data chain to be used in
91// MTask::AddBranchToList
92//
93TString MHVsTime::GetDataMember() const
94{
95 return fData ? fData->GetDataMember() : (TString)"";
96}
97
98// --------------------------------------------------------------------------
99//
100// Setup the Binning for the histograms automatically if the correct
101// instances of MBinning are found in the parameter list
102// For a more detailed description see class description above.
103//
104Bool_t MHVsTime::SetupFill(const MParList *plist)
105{
106 // reset histogram (necessary if the same eventloop is run more than once)
107 //fGraph->Reset();
108
109 if (fData && !fData->PreProcess(plist))
110 return kFALSE;
111
112 if (fGraph)
113 {
114 delete fGraph;
115 fGraph = new TGraph;
116 }
117
118 TString title(fData ? GetRule() : (TString)"Histogram");
119 title += " vs ";
120 title += fUseEventNumber ? "Event Number" : "Time";
121
122 fGraph->SetNameTitle(fName, title);
123
124 return kTRUE;
125}
126
127// --------------------------------------------------------------------------
128//
129// Set the name of the histogram ant the MHVsTime container
130//
131void MHVsTime::SetName(const char *name)
132{
133 fGraph->SetName(name);
134 MParContainer::SetName(name);
135}
136
137// --------------------------------------------------------------------------
138//
139// Set the title of the histogram ant the MHVsTime container
140//
141void MHVsTime::SetTitle(const char *title)
142{
143 fGraph->SetTitle(title);
144 MParContainer::SetTitle(title);
145}
146
147// --------------------------------------------------------------------------
148//
149// Fills the one, two or three data members into our histogram
150//
151Bool_t MHVsTime::Fill(const MParContainer *par, const Stat_t w)
152{
153 Double_t t = 0;
154 if (fUseEventNumber)
155 {
156 const MRawEvtHeader *h = dynamic_cast<const MRawEvtHeader*>(par);
157 t = h ? h->GetDAQEvtNumber() : fGraph->GetN();
158 }
159 else
160 {
161 const MTime *tm = dynamic_cast<const MTime*>(par);
162 if (!tm)
163 {
164 *fLog << err << dbginf << "No MTime found..." << endl;
165 return kFALSE;
166 }
167 t = tm->GetAxisTime();
168 }
169
170 const Double_t v = fData->GetValue()*fScale;
171
172 fGraph->SetPoint(fGraph->GetN(), t, v);
173
174 return kTRUE;
175}
176
177// --------------------------------------------------------------------------
178//
179// Creates a new canvas and draws the histogram into it.
180//
181// Possible options are:
182// PROFX: Draw a x-profile into the histogram (for 2D histograms only)
183// PROFY: Draw a y-profile into the histogram (for 2D histograms only)
184// ONLY: Draw the profile histogram only (for 2D histograms only)
185//
186// If the kIsLog?-Bit is set the axis is displayed lkogarithmically.
187// eg this is set when applying a logarithmic MBinning
188//
189// Be careful: The histogram belongs to this object and won't get deleted
190// together with the canvas.
191//
192void MHVsTime::Draw(Option_t *opt)
193{
194 if (fGraph->GetN()==0)
195 return;
196
197 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
198 pad->SetBorderMode(0);
199
200 AppendPad("");
201
202 TString str(opt);
203
204 if (fUseEventNumber)
205 fGraph->GetHistogram()->SetXTitle("Event Number");
206 else
207 {
208 fGraph->GetHistogram()->SetXTitle("Time");
209 fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00");
210 fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
211 fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
212 }
213 fGraph->GetHistogram()->SetYTitle(GetRule());
214
215 if (!str.Contains("A"))
216 str += "A";
217 if (!str.Contains("P"))
218 str += "P";
219
220 if (str.Contains("same", TString::kIgnoreCase))
221 {
222 str.ReplaceAll("same", "");
223 str.ReplaceAll("A", "");
224 }
225
226 fGraph->Draw(str);
227 if (fGraph->TestBit(kIsLogy))
228 pad->SetLogy();
229
230 pad->Modified();
231 pad->Update();
232}
233
234// --------------------------------------------------------------------------
235//
236// Used to rebuild a MHVsTime object of the same type (data members,
237// dimension, ...)
238//
239MParContainer *MHVsTime::New() const
240{
241 MHVsTime *h=new MHVsTime(fData ? (const char*)GetRule() : NULL);
242 h->SetScale(fScale);
243 if (fUseEventNumber)
244 h->SetUseEventNumber();
245 return h;
246}
247
248TString MHVsTime::GetRule() const
249{
250 return fData ? fData->GetRule() : (TString)"";
251}
252
253// --------------------------------------------------------------------------
254//
255// Returns the total number of bins in a histogram (excluding under- and
256// overflow bins)
257//
258Int_t MHVsTime::GetNbins() const
259{
260 return fGraph->GetN();
261}
262/*
263TH1 *MHVsTime::GetHist()
264{
265 return fGraph ? fGraph->GetHistogram() : 0;
266}
267
268const TH1 *MHVsTime::GetHist() const
269{
270 return fGraph ? fGraph->GetHistogram() : 0;
271}
272
273TH1 *MHVsTime::GetHistByName(const TString name)
274{
275 return GetHist();
276}
277*/
Note: See TracBrowser for help on using the repository browser.