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

Last change on this file since 4181 was 4164, checked in by gaug, 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
79const char* MJPedestal::GetOutputFile() const
80{
81
82 if (!fRuns)
83 return "";
84
85 return Form("%s/%s-F0.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
86
87}
88
89Bool_t MJPedestal::ReadPedestalCam()
90{
91
92 const TString fname = GetOutputFile();
93
94 if (gSystem->AccessPathName(fname, kFileExists))
95 {
96 *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
97 return kFALSE;
98 }
99
100 *fLog << inf << "Reading from file: " << fname << endl;
101
102 TFile file(fname, "READ");
103 if (fPedestalCam.Read()<=0)
104 {
105 *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
106 return kFALSE;
107 }
108
109 if (file.FindKey("MBadPixelsCam"))
110 {
111 MBadPixelsCam bad;
112 if (bad.Read()<=0)
113 {
114 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
115 return kFALSE;
116 }
117 fBadPixels.Merge(bad);
118 }
119
120 if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
121 fDisplay->Read();
122
123 return kTRUE;
124}
125
126
127void MJPedestal::DisplayResult(MParList &plist)
128{
129
130 if (!fDisplay)
131 return;
132
133 //
134 // Update display
135 //
136 TString title = fDisplay->GetTitle();
137 title += "-- Pedestal ";
138 title += fRuns->GetRunsAsString();
139 title += " --";
140 fDisplay->SetTitle(title);
141
142 //
143 // Get container from list
144 //
145 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
146
147 //
148 // Create container to display
149 //
150 MHCamera disp0(geomcam, "MPedestalCam;ped", "Pedestal");
151 MHCamera disp1(geomcam, "MPedestalCam;RMS", "Ped. RMS");
152
153 disp0.SetCamContent(fPedestalCam, 0);
154 disp0.SetCamError (fPedestalCam, 1);
155
156 disp1.SetCamContent(fPedestalCam, 2);
157 disp1.SetCamError (fPedestalCam, 3);
158
159 disp0.SetYTitle("P [fadc/slice]");
160 disp1.SetYTitle("\\sigma_{P} [fadc/slice]");
161
162 //
163 // Display data
164 //
165 TCanvas &c3 = fDisplay->AddTab("Pedestals");
166 c3.Divide(2,3);
167
168 CamDraw(c3, 1, 2, disp0, 1);
169 CamDraw(c3, 2, 2, disp1, 6);
170}
171
172Bool_t MJPedestal::WriteResult()
173{
174 if (fOutputPath.IsNull())
175 return kTRUE;
176
177 const TString oname(GetOutputFile());
178
179 *fLog << inf << "Writing to file: " << oname << endl;
180
181 TFile file(oname, "UPDATE");
182
183 if (fDisplay && fDisplay->Write()<=0)
184 {
185 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
186 return kFALSE;
187 }
188
189 if (fPedestalCam.Write()<=0)
190 {
191 *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
192 return kFALSE;
193 }
194
195 if (fBadPixels.Write()<=0)
196 {
197 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
198 return kFALSE;
199 }
200
201 return kTRUE;
202}
203
204void MJPedestal::SetOutputPath(const char *path)
205{
206 fOutputPath = path;
207 if (fOutputPath.EndsWith("/"))
208 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
209}
210
211Bool_t MJPedestal::Process()
212{
213 if (!ReadPedestalCam())
214 return ProcessFile();
215
216 return kTRUE;
217}
218
219Bool_t MJPedestal::ProcessFile()
220{
221 if (!fRuns)
222 {
223 *fLog << err << "No Runs choosen... abort." << endl;
224 return kFALSE;
225 }
226 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
227 {
228 *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
229 return kFALSE;
230 }
231
232 *fLog << inf;
233 fLog->Separator(GetDescriptor());
234 *fLog << "Calculate MPedestalCam from Runs " << fRuns->GetRunsAsString() << endl;
235 *fLog << endl;
236
237 MParList plist;
238 MTaskList tlist;
239 plist.AddToList(&tlist);
240
241 MGeomCamMagic magiccam;
242 MReadMarsFile read("Events");
243 MRawFileRead rawread(NULL);
244
245 if (fDataCheck)
246 {
247 rawread.AddFiles(*fRuns);
248 tlist.AddToList(&rawread);
249 }
250 else
251 {
252 read.DisableAutoScheme();
253 static_cast<MRead&>(read).AddFiles(*fRuns);
254 tlist.AddToList(&read);
255 }
256 // Enable logging to file
257 //*fLog.SetOutputFile(lname, kTRUE);
258
259 // Setup Tasklist
260 plist.AddToList(&magiccam);
261 plist.AddToList(&fPedestalCam);
262 plist.AddToList(&fBadPixels);
263
264 MGeomApply geomapl;
265 // MBadPixelsMerge merge(&fBadPixels);
266 MPedCalcPedRun pedcalc;
267
268 if (fExtractor)
269 {
270 pedcalc.SetWindowSize((Int_t)fExtractor->GetNumHiGainSamples());
271 pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
272 }
273 else
274 {
275 *fLog << warn << GetDescriptor()
276 << ": No extractor has been chosen, take default number of FADC samples " << endl;
277 }
278
279 tlist.AddToList(&geomapl);
280 // tlist.AddToList(&merge);
281 //tlist.AddToList(&sigcalc);
282 tlist.AddToList(&pedcalc);
283
284 //
285 // Execute the eventloop
286 //
287 MEvtLoop evtloop(fName);
288 evtloop.SetParList(&plist);
289 evtloop.SetDisplay(fDisplay);
290 evtloop.SetLogStream(fLog);
291
292 // Execute first analysis
293 if (!evtloop.Eventloop())
294 {
295 *fLog << err << GetDescriptor() << ": Failed." << endl;
296 return kFALSE;
297 }
298
299 tlist.PrintStatistics();
300
301 DisplayResult(plist);
302
303 if (!WriteResult())
304 return kFALSE;
305
306 *fLog << inf << GetDescriptor() << ": Done." << endl;
307
308 return kTRUE;
309}
Note: See TracBrowser for help on using the repository browser.