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 |
|
---|
62 | ClassImp(MJPedestal);
|
---|
63 |
|
---|
64 | using namespace std;
|
---|
65 | // --------------------------------------------------------------------------
|
---|
66 | //
|
---|
67 | // Default constructor.
|
---|
68 | //
|
---|
69 | // Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
|
---|
70 | //
|
---|
71 | MJPedestal::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 |
|
---|
78 | TString 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 |
|
---|
86 | Bool_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 |
|
---|
123 | void 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 |
|
---|
168 | Bool_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 |
|
---|
200 | void MJPedestal::SetOutputPath(const char *path)
|
---|
201 | {
|
---|
202 | fOutputPath = path;
|
---|
203 | if (fOutputPath.EndsWith("/"))
|
---|
204 | fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
|
---|
205 | }
|
---|
206 |
|
---|
207 | Bool_t MJPedestal::Process()
|
---|
208 | {
|
---|
209 | if (!ReadPedestalCam())
|
---|
210 | return ProcessFile();
|
---|
211 |
|
---|
212 | return kTRUE;
|
---|
213 | }
|
---|
214 |
|
---|
215 | Bool_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 | MPedCalcPedRun pedcalc;
|
---|
261 |
|
---|
262 | if (fExtractor)
|
---|
263 | {
|
---|
264 | pedcalc.SetWindowSize((Int_t)fExtractor->GetNumHiGainSamples());
|
---|
265 | pedcalc.SetRange(fExtractor->GetHiGainFirst(), fExtractor->GetHiGainLast());
|
---|
266 | }
|
---|
267 | else
|
---|
268 | {
|
---|
269 | *fLog << warn << GetDescriptor()
|
---|
270 | << ": No extractor has been chosen, take default number of FADC samples " << endl;
|
---|
271 | }
|
---|
272 |
|
---|
273 | tlist.AddToList(&geomapl);
|
---|
274 | // tlist.AddToList(&merge);
|
---|
275 | //tlist.AddToList(&sigcalc);
|
---|
276 | tlist.AddToList(&pedcalc);
|
---|
277 |
|
---|
278 | //
|
---|
279 | // Execute the eventloop
|
---|
280 | //
|
---|
281 | MEvtLoop evtloop(fName);
|
---|
282 | evtloop.SetParList(&plist);
|
---|
283 | evtloop.SetDisplay(fDisplay);
|
---|
284 | evtloop.SetLogStream(fLog);
|
---|
285 |
|
---|
286 | // Execute first analysis
|
---|
287 | if (!evtloop.Eventloop())
|
---|
288 | {
|
---|
289 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
290 | return kFALSE;
|
---|
291 | }
|
---|
292 |
|
---|
293 | tlist.PrintStatistics();
|
---|
294 |
|
---|
295 | DisplayResult(plist);
|
---|
296 |
|
---|
297 | if (!WriteResult())
|
---|
298 | return kFALSE;
|
---|
299 |
|
---|
300 | *fLog << inf << GetDescriptor() << ": Done." << endl;
|
---|
301 |
|
---|
302 | return kTRUE;
|
---|
303 | }
|
---|