source: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc@ 4296

Last change on this file since 4296 was 4189, checked in by gaug, 20 years ago
*** empty log message ***
File size: 7.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, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Markus Gaug ,04/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MJPedestal
29//
30/////////////////////////////////////////////////////////////////////////////
31#include "MJPedestal.h"
32
33#include <TF1.h>
34#include <TFile.h>
35#include <TStyle.h>
36#include <TString.h>
37#include <TCanvas.h>
38#include <TSystem.h>
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MRunIter.h"
44#include "MParList.h"
45#include "MTaskList.h"
46#include "MEvtLoop.h"
47#include "MExtractor.h"
48
49#include "MStatusDisplay.h"
50
51#include "MGeomCam.h"
52#include "MHCamera.h"
53#include "MPedestalCam.h"
54#include "MBadPixelsCam.h"
55
56#include "MReadMarsFile.h"
57#include "MRawFileRead.h"
58#include "MGeomApply.h"
59#include "MBadPixelsMerge.h"
60#include "MPedCalcPedRun.h"
61
62ClassImp(MJPedestal);
63
64using namespace std;
65// --------------------------------------------------------------------------
66//
67// Default constructor.
68//
69// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
70//
71MJPedestal::MJPedestal(const char *name, const char *title)
72 : fRuns(0), fExtractor(NULL), fDataCheck(kFALSE)
73{
74 fName = name ? name : "MJPedestal";
75 fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
76}
77
78const char* MJPedestal::GetOutputFile() const
79{
80
81 if (!fRuns)
82 return "";
83
84 return Form("%s/%s-F0.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
85
86}
87
88Bool_t MJPedestal::ReadPedestalCam()
89{
90
91 const TString fname = GetOutputFile();
92
93 if (gSystem->AccessPathName(fname, kFileExists))
94 {
95 *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
96 return kFALSE;
97 }
98
99 *fLog << inf << "Reading from file: " << fname << endl;
100
101 TFile file(fname, "READ");
102 if (fPedestalCam.Read()<=0)
103 {
104 *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
105 return kFALSE;
106 }
107
108 if (file.FindKey("MBadPixelsCam"))
109 {
110 MBadPixelsCam bad;
111 if (bad.Read()<=0)
112 {
113 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
114 return kFALSE;
115 }
116 fBadPixels.Merge(bad);
117 }
118
119 if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
120 fDisplay->Read();
121
122 return kTRUE;
123}
124
125
126void MJPedestal::DisplayResult(MParList &plist)
127{
128
129 if (!fDisplay)
130 return;
131
132 //
133 // Update display
134 //
135 TString title = fDisplay->GetTitle();
136 title += "-- Pedestal ";
137 title += fRuns->GetRunsAsString();
138 title += " --";
139 fDisplay->SetTitle(title);
140
141 //
142 // Get container from list
143 //
144 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
145
146 //
147 // Create container to display
148 //
149 MHCamera disp0(geomcam, "MPedestalCam;ped", "Pedestal");
150 MHCamera disp1(geomcam, "MPedestalCam;RMS", "Ped. RMS");
151
152 disp0.SetCamContent(fPedestalCam, 0);
153 disp0.SetCamError (fPedestalCam, 1);
154
155 disp1.SetCamContent(fPedestalCam, 2);
156 disp1.SetCamError (fPedestalCam, 3);
157
158 disp0.SetYTitle("P [fadc/slice]");
159 disp1.SetYTitle("\\sigma_{P} [fadc/slice]");
160
161 //
162 // Display data
163 //
164 TCanvas &c3 = fDisplay->AddTab("Pedestals");
165 c3.Divide(2,3);
166
167 disp0.CamDraw(c3, 1, 2, 1);
168 disp1.CamDraw(c3, 2, 2, 6);
169}
170
171Bool_t MJPedestal::WriteResult()
172{
173 if (fOutputPath.IsNull())
174 return kTRUE;
175
176 const TString oname(GetOutputFile());
177
178 *fLog << inf << "Writing to file: " << oname << endl;
179
180 TFile file(oname, "UPDATE");
181
182 if (fDisplay && fDisplay->Write()<=0)
183 {
184 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
185 return kFALSE;
186 }
187
188 if (fPedestalCam.Write()<=0)
189 {
190 *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
191 return kFALSE;
192 }
193
194 if (fBadPixels.Write()<=0)
195 {
196 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
197 return kFALSE;
198 }
199
200 return kTRUE;
201}
202
203void MJPedestal::SetOutputPath(const char *path)
204{
205 fOutputPath = path;
206 if (fOutputPath.EndsWith("/"))
207 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
208}
209
210Bool_t MJPedestal::Process()
211{
212 if (!ReadPedestalCam())
213 return ProcessFile();
214
215 return kTRUE;
216}
217
218Bool_t MJPedestal::ProcessFile()
219{
220 if (!fRuns)
221 {
222 *fLog << err << "No Runs choosen... abort." << endl;
223 return kFALSE;
224 }
225 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
226 {
227 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
228 return kFALSE;
229 }
230
231 *fLog << inf;
232 fLog->Separator(GetDescriptor());
233 *fLog << "Calculate MPedestalCam from Runs " << fRuns->GetRunsAsString() << endl;
234 *fLog << endl;
235
236 MParList plist;
237 MTaskList tlist;
238 plist.AddToList(&tlist);
239
240 MReadMarsFile read("Events");
241 MRawFileRead rawread(NULL);
242
243 if (fDataCheck)
244 {
245 rawread.AddFiles(*fRuns);
246 tlist.AddToList(&rawread);
247 }
248 else
249 {
250 read.DisableAutoScheme();
251 static_cast<MRead&>(read).AddFiles(*fRuns);
252 tlist.AddToList(&read);
253 }
254 // Enable logging to file
255 //*fLog.SetOutputFile(lname, kTRUE);
256
257 // Setup Tasklist
258 plist.AddToList(&fPedestalCam);
259 plist.AddToList(&fBadPixels);
260
261 MGeomApply geomapl;
262 // MBadPixelsMerge merge(&fBadPixels);
263 MPedCalcPedRun pedcalc;
264
265 if (fExtractor)
266 {
267 pedcalc.SetWindowSize((Int_t)fExtractor->GetNumHiGainSamples());
268 pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
269 }
270 else
271 {
272 *fLog << warn << GetDescriptor()
273 << ": No extractor has been chosen, take default number of FADC samples " << endl;
274 }
275
276 tlist.AddToList(&geomapl);
277 // tlist.AddToList(&merge);
278 //tlist.AddToList(&sigcalc);
279 tlist.AddToList(&pedcalc);
280
281 //
282 // Execute the eventloop
283 //
284 MEvtLoop evtloop(fName);
285 evtloop.SetParList(&plist);
286 evtloop.SetDisplay(fDisplay);
287 evtloop.SetLogStream(fLog);
288
289 // Execute first analysis
290 if (!evtloop.Eventloop())
291 {
292 *fLog << err << GetDescriptor() << ": Failed." << endl;
293 return kFALSE;
294 }
295
296 tlist.PrintStatistics();
297
298 DisplayResult(plist);
299
300 if (!WriteResult())
301 return kFALSE;
302
303 *fLog << inf << GetDescriptor() << ": Done." << endl;
304
305 return kTRUE;
306}
Note: See TracBrowser for help on using the repository browser.