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

Last change on this file since 2563 was 2557, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 6.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, 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
50ClassImp(MHVsTime);
51
52using namespace std;
53
54static const TString gsDefName = "MHVsTime";
55static const TString gsDefTitle = "Container for a graph vs time";
56
57// --------------------------------------------------------------------------
58//
59// Default constructor.
60//
61MHVsTime::MHVsTime(const char *rule)
62 : fGraph(NULL), fData(NULL), fScale(1)
63{
64 fName = gsDefName;
65 fTitle = gsDefTitle;
66
67 if (!rule)
68 return;
69
70 fGraph = new TGraph;
71 fData = new MDataChain(rule);
72}
73
74// --------------------------------------------------------------------------
75//
76// Deletes the histogram
77//
78MHVsTime::~MHVsTime()
79{
80 if (fGraph)
81 delete fGraph;
82
83 if (fData)
84 delete fData;
85}
86
87// --------------------------------------------------------------------------
88//
89// Return the data members used by the data chain to be used in
90// MTask::AddBranchToList
91//
92TString MHVsTime::GetDataMember() const
93{
94 return fData ? fData->GetDataMember() : (TString)"";
95}
96
97// --------------------------------------------------------------------------
98//
99// Setup the Binning for the histograms automatically if the correct
100// instances of MBinning are found in the parameter list
101// For a more detailed description see class description above.
102//
103Bool_t MHVsTime::SetupFill(const MParList *plist)
104{
105 // reset histogram (necessary if the same eventloop is run more than once)
106 //fGraph->Reset();
107
108 if (fData && !fData->PreProcess(plist))
109 return kFALSE;
110
111 if (fGraph)
112 {
113 delete fGraph;
114 fGraph = new TGraph;
115 }
116
117 TString title(fData ? GetRule() : (TString)"Histogram");
118 title += " vs Time";
119
120 fGraph->SetNameTitle(fName, title);
121
122 return kTRUE;
123}
124
125// --------------------------------------------------------------------------
126//
127// Set the name of the histogram ant the MHVsTime container
128//
129void MHVsTime::SetName(const char *name)
130{
131 fGraph->SetName(name);
132 MParContainer::SetName(name);
133}
134
135// --------------------------------------------------------------------------
136//
137// Set the title of the histogram ant the MHVsTime container
138//
139void MHVsTime::SetTitle(const char *title)
140{
141 fGraph->SetTitle(title);
142 MParContainer::SetTitle(title);
143}
144
145// --------------------------------------------------------------------------
146//
147// Fills the one, two or three data members into our histogram
148//
149Bool_t MHVsTime::Fill(const MParContainer *par, const Stat_t w)
150{
151 const MTime *t = dynamic_cast<const MTime*>(par);
152 if (!t)
153 {
154 *fLog << err << dbginf << "No MTime found..." << endl;
155 return kFALSE;
156 }
157
158 const Double_t v = fData->GetValue()*fScale;
159 const Double_t T = (*t);///3600;
160
161 fGraph->SetPoint(fGraph->GetN(), T>12*3600?T-24*3600:T, v);
162
163 return kTRUE;
164}
165
166// --------------------------------------------------------------------------
167//
168// Creates a new canvas and draws the histogram into it.
169//
170// Possible options are:
171// PROFX: Draw a x-profile into the histogram (for 2D histograms only)
172// PROFY: Draw a y-profile into the histogram (for 2D histograms only)
173// ONLY: Draw the profile histogram only (for 2D histograms only)
174//
175// If the kIsLog?-Bit is set the axis is displayed lkogarithmically.
176// eg this is set when applying a logarithmic MBinning
177//
178// Be careful: The histogram belongs to this object and won't get deleted
179// together with the canvas.
180//
181void MHVsTime::Draw(Option_t *opt)
182{
183 if (fGraph->GetN()==0)
184 return;
185
186 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
187 pad->SetBorderMode(0);
188
189 AppendPad("");
190
191 TString str(opt);
192
193 fGraph->GetHistogram()->SetXTitle("Time");
194 fGraph->GetHistogram()->SetYTitle(GetRule());
195 fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%H:%M:%S");
196 fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
197 fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
198 fGraph->Draw("AP");
199 if (fGraph->TestBit(kIsLogy))
200 pad->SetLogy();
201
202 pad->Modified();
203 pad->Update();
204}
205
206// --------------------------------------------------------------------------
207//
208// Used to rebuild a MHVsTime object of the same type (data members,
209// dimension, ...)
210//
211MParContainer *MHVsTime::New() const
212{
213 MHVsTime *h=new MHVsTime(fData ? (const char*)GetRule() : NULL);
214 h->SetScale(fScale);
215 return h;
216}
217
218TString MHVsTime::GetRule() const
219{
220 return fData ? fData->GetRule() : (TString)"";
221}
222
223// --------------------------------------------------------------------------
224//
225// Returns the total number of bins in a histogram (excluding under- and
226// overflow bins)
227//
228Int_t MHVsTime::GetNbins() const
229{
230 return fGraph->GetN();
231}
232/*
233TH1 *MHVsTime::GetHist()
234{
235 return fGraph ? fGraph->GetHistogram() : 0;
236}
237
238const TH1 *MHVsTime::GetHist() const
239{
240 return fGraph ? fGraph->GetHistogram() : 0;
241}
242
243TH1 *MHVsTime::GetHistByName(const TString name)
244{
245 return GetHist();
246}
247*/
Note: See TracBrowser for help on using the repository browser.