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

Last change on this file since 2591 was 2571, 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)
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 const Double_t T = (*tm);///3600;
168 t = T>12*3600?T-24*3600:T;
169 }
170
171 const Double_t v = fData->GetValue()*fScale;
172
173 fGraph->SetPoint(fGraph->GetN(), t, v);
174
175 return kTRUE;
176}
177
178// --------------------------------------------------------------------------
179//
180// Creates a new canvas and draws the histogram into it.
181//
182// Possible options are:
183// PROFX: Draw a x-profile into the histogram (for 2D histograms only)
184// PROFY: Draw a y-profile into the histogram (for 2D histograms only)
185// ONLY: Draw the profile histogram only (for 2D histograms only)
186//
187// If the kIsLog?-Bit is set the axis is displayed lkogarithmically.
188// eg this is set when applying a logarithmic MBinning
189//
190// Be careful: The histogram belongs to this object and won't get deleted
191// together with the canvas.
192//
193void MHVsTime::Draw(Option_t *opt)
194{
195 if (fGraph->GetN()==0)
196 return;
197
198 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
199 pad->SetBorderMode(0);
200
201 AppendPad("");
202
203 TString str(opt);
204
205 if (fUseEventNumber)
206 fGraph->GetHistogram()->SetXTitle("Event Number");
207 else
208 {
209 fGraph->GetHistogram()->SetXTitle("Time");
210 fGraph->GetHistogram()->GetXaxis()->SetTimeFormat("%H:%M:%S");
211 fGraph->GetHistogram()->GetXaxis()->SetTimeDisplay(1);
212 fGraph->GetHistogram()->GetXaxis()->SetLabelSize(0.033);
213 }
214 fGraph->GetHistogram()->SetYTitle(GetRule());
215 fGraph->Draw("AP");
216 if (fGraph->TestBit(kIsLogy))
217 pad->SetLogy();
218
219 pad->Modified();
220 pad->Update();
221}
222
223// --------------------------------------------------------------------------
224//
225// Used to rebuild a MHVsTime object of the same type (data members,
226// dimension, ...)
227//
228MParContainer *MHVsTime::New() const
229{
230 MHVsTime *h=new MHVsTime(fData ? (const char*)GetRule() : NULL);
231 h->SetScale(fScale);
232 if (fUseEventNumber)
233 h->SetUseEventNumber();
234 return h;
235}
236
237TString MHVsTime::GetRule() const
238{
239 return fData ? fData->GetRule() : (TString)"";
240}
241
242// --------------------------------------------------------------------------
243//
244// Returns the total number of bins in a histogram (excluding under- and
245// overflow bins)
246//
247Int_t MHVsTime::GetNbins() const
248{
249 return fGraph->GetN();
250}
251/*
252TH1 *MHVsTime::GetHist()
253{
254 return fGraph ? fGraph->GetHistogram() : 0;
255}
256
257const TH1 *MHVsTime::GetHist() const
258{
259 return fGraph ? fGraph->GetHistogram() : 0;
260}
261
262TH1 *MHVsTime::GetHistByName(const TString name)
263{
264 return GetHist();
265}
266*/
Note: See TracBrowser for help on using the repository browser.