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

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