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 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MJPedestal
|
---|
28 | //
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MJPedestal.h"
|
---|
31 |
|
---|
32 | #include <TFile.h>
|
---|
33 | #include <TStyle.h>
|
---|
34 | #include <TCanvas.h>
|
---|
35 | #include <TSystem.h>
|
---|
36 |
|
---|
37 | #include "MLog.h"
|
---|
38 | #include "MLogManip.h"
|
---|
39 |
|
---|
40 | #include "MRunIter.h"
|
---|
41 | #include "MParList.h"
|
---|
42 | #include "MTaskList.h"
|
---|
43 | #include "MEvtLoop.h"
|
---|
44 |
|
---|
45 | #include "MStatusDisplay.h"
|
---|
46 |
|
---|
47 | #include "MHCamera.h"
|
---|
48 |
|
---|
49 | #include "MReadMarsFile.h"
|
---|
50 | #include "MGeomApply.h"
|
---|
51 | #include "MPedCalcPedRun.h"
|
---|
52 |
|
---|
53 | ClassImp(MJPedestal);
|
---|
54 |
|
---|
55 | using namespace std;
|
---|
56 |
|
---|
57 | MJPedestal::MJPedestal(const char *name, const char *title) : fRuns(0)
|
---|
58 | {
|
---|
59 | fName = name ? name : "MJPedestal";
|
---|
60 | fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
|
---|
61 | }
|
---|
62 |
|
---|
63 | TString MJPedestal::GetOutputFile() const
|
---|
64 | {
|
---|
65 | if (!fRuns)
|
---|
66 | return "";
|
---|
67 |
|
---|
68 | return Form("%s/%s-F0.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
|
---|
69 | }
|
---|
70 |
|
---|
71 | Bool_t MJPedestal::ReadPedestalCam()
|
---|
72 | {
|
---|
73 | const TString fname = GetOutputFile();
|
---|
74 |
|
---|
75 | if (gSystem->AccessPathName(fname, kFileExists))
|
---|
76 | {
|
---|
77 | *fLog << err << "Input file " << fname << " doesn't exist." << endl;
|
---|
78 | return kFALSE;
|
---|
79 | }
|
---|
80 |
|
---|
81 | *fLog << inf << "Reading from file: " << fname << endl;
|
---|
82 |
|
---|
83 | TFile file(fname, "READ");
|
---|
84 | if (fPedestalCam.Read()<=0)
|
---|
85 | {
|
---|
86 | *fLog << "Unable to read MPedestalCam from " << fname << endl;
|
---|
87 | return kFALSE;
|
---|
88 | }
|
---|
89 |
|
---|
90 | if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
|
---|
91 | fDisplay->Read();
|
---|
92 |
|
---|
93 | return kTRUE;
|
---|
94 | }
|
---|
95 |
|
---|
96 | void MJPedestal::DisplayResult(MParList &plist)
|
---|
97 | {
|
---|
98 | if (!fDisplay)
|
---|
99 | return;
|
---|
100 |
|
---|
101 | //
|
---|
102 | // Update display
|
---|
103 | //
|
---|
104 | TString title = fDisplay->GetTitle();
|
---|
105 | title += "-- Pedestal ";
|
---|
106 | title += fRuns->GetRunsAsString();
|
---|
107 | title += " --";
|
---|
108 | fDisplay->SetTitle(title);
|
---|
109 |
|
---|
110 | //
|
---|
111 | // Get coontainer from list
|
---|
112 | //
|
---|
113 | MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
|
---|
114 |
|
---|
115 | //
|
---|
116 | // Create container to display
|
---|
117 | //
|
---|
118 | MHCamera disp0(geomcam, "MPedestalCam;ped", "Pedestals");
|
---|
119 | MHCamera disp1(geomcam, "MPedestalCam;rms", "Pedestal RMS");
|
---|
120 |
|
---|
121 | disp0.SetCamContent(fPedestalCam, 0);
|
---|
122 | disp1.SetCamContent(fPedestalCam, 1);
|
---|
123 |
|
---|
124 | disp0.SetYTitle("P [fadc/slice]");
|
---|
125 | disp1.SetYTitle("P_{RMS} [fadc/slice]");
|
---|
126 |
|
---|
127 | //
|
---|
128 | // Display data
|
---|
129 | //
|
---|
130 | TObject *obj;
|
---|
131 |
|
---|
132 | TCanvas &c3 = fDisplay->AddTab("Pedestals");
|
---|
133 | c3.Divide(2,2);
|
---|
134 |
|
---|
135 | c3.cd(1);
|
---|
136 | gPad->SetBorderMode(0);
|
---|
137 | gStyle->SetOptStat(1101);
|
---|
138 | obj=disp0.DrawCopy("hist");
|
---|
139 |
|
---|
140 | c3.cd(3);
|
---|
141 | obj->Draw();
|
---|
142 |
|
---|
143 | c3.cd(2);
|
---|
144 | gPad->SetBorderMode(0);
|
---|
145 | gStyle->SetOptStat(1101);
|
---|
146 | obj=disp1.DrawCopy("hist");
|
---|
147 |
|
---|
148 | c3.cd(4);
|
---|
149 | obj->Draw();
|
---|
150 | }
|
---|
151 |
|
---|
152 | Bool_t MJPedestal::WriteResult()
|
---|
153 | {
|
---|
154 | if (fOutputPath.IsNull())
|
---|
155 | return kTRUE;
|
---|
156 |
|
---|
157 | const TString oname(GetOutputFile());
|
---|
158 |
|
---|
159 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
160 |
|
---|
161 | TFile file(oname, "UPDATE");
|
---|
162 |
|
---|
163 | if (fDisplay && fDisplay->Write()<=0)
|
---|
164 | {
|
---|
165 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
---|
166 | return kFALSE;
|
---|
167 | }
|
---|
168 |
|
---|
169 | if (fPedestalCam.Write()<=0)
|
---|
170 | {
|
---|
171 | *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
|
---|
172 | return kFALSE;
|
---|
173 | }
|
---|
174 | return kTRUE;
|
---|
175 | }
|
---|
176 |
|
---|
177 | void MJPedestal::SetOutputPath(const char *path)
|
---|
178 | {
|
---|
179 | fOutputPath = path;
|
---|
180 | if (fOutputPath.EndsWith("/"))
|
---|
181 | fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
|
---|
182 | }
|
---|
183 |
|
---|
184 | Bool_t MJPedestal::Process()
|
---|
185 | {
|
---|
186 | if (!ReadPedestalCam())
|
---|
187 | return ProcessFile();
|
---|
188 |
|
---|
189 | return kTRUE;
|
---|
190 | }
|
---|
191 |
|
---|
192 | Bool_t MJPedestal::ProcessFile()
|
---|
193 | {
|
---|
194 | if (!fRuns)
|
---|
195 | {
|
---|
196 | *fLog << err << "No Runs choosen... abort." << endl;
|
---|
197 | return kFALSE;
|
---|
198 | }
|
---|
199 | if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
|
---|
200 | {
|
---|
201 | *fLog << err << "Number of files found doesn't metch number of runs... abort." << endl;
|
---|
202 | return kFALSE;
|
---|
203 | }
|
---|
204 |
|
---|
205 | *fLog << inf;
|
---|
206 | fLog->Separator(GetDescriptor());
|
---|
207 | *fLog << "Calculate MPedestalCam from Runs " << fRuns->GetRunsAsString() << endl;
|
---|
208 | *fLog << endl;
|
---|
209 |
|
---|
210 | MReadMarsFile read("Events");
|
---|
211 | read.DisableAutoScheme();
|
---|
212 | static_cast<MRead&>(read).AddFiles(*fRuns);
|
---|
213 |
|
---|
214 | // Enable logging to file
|
---|
215 | //*fLog.SetOutputFile(lname, kTRUE);
|
---|
216 |
|
---|
217 | // Setup Tasklist
|
---|
218 | MParList plist;
|
---|
219 | plist.AddToList(&fPedestalCam);
|
---|
220 |
|
---|
221 | MTaskList tlist;
|
---|
222 | plist.AddToList(&tlist);
|
---|
223 |
|
---|
224 | MGeomApply geomapl;
|
---|
225 | //MExtractSignal sigcalc;
|
---|
226 | MPedCalcPedRun pedcalc;
|
---|
227 |
|
---|
228 | tlist.AddToList(&read);
|
---|
229 | tlist.AddToList(&geomapl);
|
---|
230 | //tlist.AddToList(&sigcalc);
|
---|
231 | tlist.AddToList(&pedcalc);
|
---|
232 |
|
---|
233 | //
|
---|
234 | // Execute the eventloop
|
---|
235 | //
|
---|
236 | MEvtLoop evtloop(fName);
|
---|
237 | evtloop.SetParList(&plist);
|
---|
238 | evtloop.SetDisplay(fDisplay);
|
---|
239 | evtloop.SetLogStream(fLog);
|
---|
240 |
|
---|
241 | // Execute first analysis
|
---|
242 | if (!evtloop.Eventloop())
|
---|
243 | {
|
---|
244 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
245 | return kFALSE;
|
---|
246 | }
|
---|
247 |
|
---|
248 | tlist.PrintStatistics();
|
---|
249 |
|
---|
250 | DisplayResult(plist);
|
---|
251 |
|
---|
252 | if (!WriteResult())
|
---|
253 | return kFALSE;
|
---|
254 |
|
---|
255 | *fLog << inf << GetDescriptor() << ": Done." << endl;
|
---|
256 |
|
---|
257 | return kTRUE;
|
---|
258 | }
|
---|