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

Last change on this file since 4128 was 4115, checked in by reyes, 21 years ago
*** empty log message ***
File size: 7.3 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 "MGeomCamMagic.h"
53#include "MHCamera.h"
54#include "MPedestalCam.h"
55#include "MBadPixelsCam.h"
56
57#include "MReadMarsFile.h"
58#include "MRawFileRead.h"
59#include "MGeomApply.h"
60#include "MBadPixelsMerge.h"
61#include "MPedCalcPedRun.h"
62
63ClassImp(MJPedestal);
64
65using namespace std;
66// --------------------------------------------------------------------------
67//
68// Default constructor.
69//
70// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
71//
72MJPedestal::MJPedestal(const char *name, const char *title)
73 : fRuns(0), fExtractor(NULL), fDataCheck(kFALSE)
74{
75 fName = name ? name : "MJPedestal";
76 fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
77}
78
79TString MJPedestal::GetOutputFile() const
80{
81 if (!fRuns)
82 return "";
83
84 return Form("%s/%s-F0.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
85}
86
87Bool_t MJPedestal::ReadPedestalCam()
88{
89 const TString fname = GetOutputFile();
90
91 if (gSystem->AccessPathName(fname, kFileExists))
92 {
93 *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
94 return kFALSE;
95 }
96
97 *fLog << inf << "Reading from file: " << fname << endl;
98
99 TFile file(fname, "READ");
100 if (fPedestalCam.Read()<=0)
101 {
102 *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
103 return kFALSE;
104 }
105
106 if (file.FindKey("MBadPixelsCam"))
107 {
108 MBadPixelsCam bad;
109 if (bad.Read()<=0)
110 {
111 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
112 return kFALSE;
113 }
114 fBadPixels.Merge(bad);
115 }
116
117 if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
118 fDisplay->Read();
119
120 return kTRUE;
121}
122
123
124void MJPedestal::DisplayResult(MParList &plist)
125{
126
127 if (!fDisplay)
128 return;
129
130 //
131 // Update display
132 //
133 TString title = fDisplay->GetTitle();
134 title += "-- Pedestal ";
135 title += fRuns->GetRunsAsString();
136 title += " --";
137 fDisplay->SetTitle(title);
138
139 //
140 // Get container from list
141 //
142 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
143
144 //
145 // Create container to display
146 //
147 MHCamera disp0(geomcam, "MPedestalCam;ped", "Pedestal");
148 MHCamera disp1(geomcam, "MPedestalCam;RMS", "Ped. RMS");
149
150 disp0.SetCamContent(fPedestalCam, 0);
151 disp0.SetCamError (fPedestalCam, 1);
152
153 disp1.SetCamContent(fPedestalCam, 2);
154 disp1.SetCamError (fPedestalCam, 3);
155
156 disp0.SetYTitle("P [fadc/slice]");
157 disp1.SetYTitle("\\sigma_{P} [fadc/slice]");
158
159 //
160 // Display data
161 //
162 TCanvas &c3 = fDisplay->AddTab("Pedestals");
163 c3.Divide(2,3);
164
165 CamDraw(c3, 1, 2, disp0, 1);
166 CamDraw(c3, 2, 2, disp1, 6);
167}
168
169Bool_t MJPedestal::WriteResult()
170{
171 if (fOutputPath.IsNull())
172 return kTRUE;
173
174 const TString oname(GetOutputFile());
175
176 *fLog << inf << "Writing to file: " << oname << endl;
177
178 TFile file(oname, "UPDATE");
179
180 if (fDisplay && fDisplay->Write()<=0)
181 {
182 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
183 return kFALSE;
184 }
185
186 if (fPedestalCam.Write()<=0)
187 {
188 *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
189 return kFALSE;
190 }
191
192 if (fBadPixels.Write()<=0)
193 {
194 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
195 return kFALSE;
196 }
197
198 return kTRUE;
199}
200
201void MJPedestal::SetOutputPath(const char *path)
202{
203 fOutputPath = path;
204 if (fOutputPath.EndsWith("/"))
205 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
206}
207
208Bool_t MJPedestal::Process()
209{
210 if (!ReadPedestalCam())
211 return ProcessFile();
212
213 return kTRUE;
214}
215
216Bool_t MJPedestal::ProcessFile()
217{
218 if (!fRuns)
219 {
220 *fLog << err << "No Runs choosen... abort." << endl;
221 return kFALSE;
222 }
223 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
224 {
225 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
226 return kFALSE;
227 }
228
229 *fLog << inf;
230 fLog->Separator(GetDescriptor());
231 *fLog << "Calculate MPedestalCam from Runs " << fRuns->GetRunsAsString() << endl;
232 *fLog << endl;
233
234 MParList plist;
235 MTaskList tlist;
236 plist.AddToList(&tlist);
237
238 MGeomCamMagic magiccam;
239 MReadMarsFile read("Events");
240 MRawFileRead rawread(NULL);
241
242 if (fDataCheck)
243 {
244 rawread.AddFiles(*fRuns);
245 tlist.AddToList(&rawread);
246 }
247 else
248 {
249 read.DisableAutoScheme();
250 static_cast<MRead&>(read).AddFiles(*fRuns);
251 tlist.AddToList(&read);
252 }
253 // Enable logging to file
254 //*fLog.SetOutputFile(lname, kTRUE);
255
256 // Setup Tasklist
257 plist.AddToList(&magiccam);
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.