source: trunk/MagicSoft/Mars/mhvstime/MHPixVsTime.cc@ 4884

Last change on this file since 4884 was 3539, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.5 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, 12/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MHPixVsTime
28//
29// Display the pixel content versus time or event number
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MHPixVsTime.h"
33
34#include <TCanvas.h>
35
36#include "MLog.h"
37#include "MLogManip.h"
38
39#include "MParList.h"
40#include "MCamEvent.h"
41
42#include "MGeomCam.h"
43
44#include "MRawEvtHeader.h"
45#include "MTime.h"
46
47ClassImp(MHPixVsTime);
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// Initialize the name and title of the task.
54//
55MHPixVsTime::MHPixVsTime(Int_t idx, const char *name, const char *title)
56 : fIndex(idx), fEvt(NULL), fType(0), fTypeErr(-1)
57{
58 //
59 // set the name and title of this object
60 //
61 fName = name ? name : "MHPixVsTime";
62 fTitle = title ? title : "Average of MPixVsTimes";
63
64 TString t("Pixel Index #");
65 t += idx;
66 t += " vs Time";
67
68 fGraph = new TGraphErrors;
69 fGraph->SetName("MCamEvent");
70 fGraph->SetTitle(t);
71}
72
73// --------------------------------------------------------------------------
74//
75// Delete the corresponding camera display if available
76//
77MHPixVsTime::~MHPixVsTime()
78{
79 if(fGraph)
80 delete fGraph;
81}
82
83// --------------------------------------------------------------------------
84//
85// Get the event (MPixVsTime) the histogram might be filled with. If
86// it is not given, it is assumed, that it is filled with the argument
87// of the Fill function.
88// Looks for the camera geometry MGeomCam and resets the sum histogram.
89//
90Bool_t MHPixVsTime::SetupFill(const MParList *plist)
91{
92 fEvt = (MCamEvent*)plist->FindObject(fNameEvt, "MCamEvent");
93 if (!fEvt)
94 {
95 if (!fNameEvt.IsNull())
96 {
97 *fLog << err << GetDescriptor() << ": No " << fNameEvt <<" [MCamEvent] available..." << endl;
98 return kFALSE;
99 }
100 *fLog << warn << GetDescriptor() << ": No MCamEvent available..." << endl;
101 }
102
103 fCam = (MGeomCam*)plist->FindObject("MGeomCam");
104 if (!fCam)
105 {
106 *fLog << err << "MGeomCam not found... aborting." << endl;
107 return kFALSE;
108 }
109
110 if (!fNameTime.IsNull())
111 {
112 fTime = (MTime*)plist->FindObject(fNameTime, "MTime");
113 if (!fTime)
114 {
115 *fLog << err << fNameTime << " [MTime] not found... abort." << endl;
116 return kFALSE;
117 }
118 }
119 else
120 {
121 fHeader = (MRawEvtHeader*)plist->FindObject("MRawEvtHeader");
122 if (!fHeader)
123 *fLog << warn << "MRawEvtHeader not found... using counter." << endl;
124 }
125
126 return kTRUE;
127}
128
129// --------------------------------------------------------------------------
130//
131// Fill the histograms with data from a MPixVsTime-Container.
132//
133Bool_t MHPixVsTime::Fill(const MParContainer *par, const Stat_t w)
134{
135 const MCamEvent *evt = par ? dynamic_cast<const MCamEvent*>(par) : fEvt;
136 if (!evt)
137 {
138 *fLog << err << dbginf << "No MCamEvent found..." << endl;
139 return kFALSE;
140 }
141
142 Double_t val = 0;
143 Double_t rms = 0;
144 evt->GetPixelContent(val, fIndex, *fCam, fType);
145 if (TMath::IsNaN(val))
146 return kCONTINUE;
147
148 Double_t t = 0;
149 if (!fNameTime.IsNull())
150 t = fTime->GetAxisTime();
151 else
152 t = fHeader ? fHeader->GetDAQEvtNumber() : fGraph->GetN();
153
154 fGraph->SetPoint(fGraph->GetN(), t, val);
155
156 if (fTypeErr>=0)
157 {
158 evt->GetPixelContent(rms, fIndex, *fCam, fType);
159 if (TMath::IsNaN(rms))
160 return kCONTINUE;
161 }
162
163 fGraph->SetPointError(fGraph->GetN()-1, 0, rms);
164 return kTRUE;
165}
166
167// --------------------------------------------------------------------------
168//
169// Return histogram of TGraph
170//
171TH1 *MHPixVsTime::GetHistByName(const TString name)
172{
173 return fGraph->GetHistogram();
174}
175
176void MHPixVsTime::Draw(Option_t *opt)
177{
178
179 if (fGraph->GetN()==0)
180 return;
181
182 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this);
183 pad->SetBorderMode(0);
184
185 AppendPad("");
186
187 TString str(opt);
188
189 TH1 *h = fGraph->GetHistogram();
190
191 h->SetXTitle("Time");
192 h->SetYTitle("");
193 if (!fNameTime.IsNull())
194 {
195 TAxis *axe = h->GetXaxis();
196 axe->SetTimeFormat("%H:%M:%S %F1995-01-01 00:00:00");
197 axe->SetTimeDisplay(1);
198 axe->SetLabelSize(0.033);
199 }
200
201
202 if (!str.Contains("A"))
203 str += "A";
204 if (!str.Contains("P"))
205 str += "P";
206
207 if (str.Contains("same", TString::kIgnoreCase))
208 {
209 str.ReplaceAll("same", "");
210 str.ReplaceAll("A", "");
211 }
212
213 fGraph->Draw(str);
214
215 pad->Modified();
216 pad->Update();
217}
Note: See TracBrowser for help on using the repository browser.