source: trunk/MagicSoft/Mars/mhist/MHVsTime.cc@ 2794

Last change on this file since 2794 was 2632, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.7 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 fGraph->Draw("AP");
215 if (fGraph->TestBit(kIsLogy))
216 pad->SetLogy();
217
218 pad->Modified();
219 pad->Update();
220}
221
222// --------------------------------------------------------------------------
223//
224// Used to rebuild a MHVsTime object of the same type (data members,
225// dimension, ...)
226//
227MParContainer *MHVsTime::New() const
228{
229 MHVsTime *h=new MHVsTime(fData ? (const char*)GetRule() : NULL);
230 h->SetScale(fScale);
231 if (fUseEventNumber)
232 h->SetUseEventNumber();
233 return h;
234}
235
236TString MHVsTime::GetRule() const
237{
238 return fData ? fData->GetRule() : (TString)"";
239}
240
241// --------------------------------------------------------------------------
242//
243// Returns the total number of bins in a histogram (excluding under- and
244// overflow bins)
245//
246Int_t MHVsTime::GetNbins() const
247{
248 return fGraph->GetN();
249}
250/*
251TH1 *MHVsTime::GetHist()
252{
253 return fGraph ? fGraph->GetHistogram() : 0;
254}
255
256const TH1 *MHVsTime::GetHist() const
257{
258 return fGraph ? fGraph->GetHistogram() : 0;
259}
260
261TH1 *MHVsTime::GetHistByName(const TString name)
262{
263 return GetHist();
264}
265*/
Note: See TracBrowser for help on using the repository browser.