source: trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc@ 4308

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