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, 02/2004 <mailto:markus@ifae.es>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MJCalibration
|
---|
29 | //
|
---|
30 | /////////////////////////////////////////////////////////////////////////////
|
---|
31 | #include "MJCalibration.h"
|
---|
32 |
|
---|
33 | #include <TF1.h>
|
---|
34 | #include <TFile.h>
|
---|
35 | #include <TStyle.h>
|
---|
36 | #include <TCanvas.h>
|
---|
37 | #include <TSystem.h>
|
---|
38 | #include <TProfile.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 |
|
---|
48 | #include "MHCamera.h"
|
---|
49 | #include "MGeomCam.h"
|
---|
50 |
|
---|
51 | #include "MPedestalCam.h"
|
---|
52 | #include "MCalibrationChargeCam.h"
|
---|
53 | #include "MCalibrationChargePINDiode.h"
|
---|
54 | #include "MCalibrationChargeBlindPix.h"
|
---|
55 | #include "MCalibrationChargeCalc.h"
|
---|
56 |
|
---|
57 | #include "MReadMarsFile.h"
|
---|
58 | #include "MGeomApply.h"
|
---|
59 | #include "MBadPixelsMerge.h"
|
---|
60 | #include "MBadPixelsCam.h"
|
---|
61 | #include "MExtractSignal.h"
|
---|
62 | #include "MExtractPINDiode.h"
|
---|
63 | #include "MExtractBlindPixel.h"
|
---|
64 | #include "MExtractSignal2.h"
|
---|
65 | #include "MFCosmics.h"
|
---|
66 | #include "MContinue.h"
|
---|
67 | #include "MFillH.h"
|
---|
68 |
|
---|
69 | #include "MJCalibration.h"
|
---|
70 | #include "MStatusDisplay.h"
|
---|
71 |
|
---|
72 | ClassImp(MJCalibration);
|
---|
73 |
|
---|
74 | using namespace std;
|
---|
75 |
|
---|
76 | MJCalibration::MJCalibration(const char *name, const char *title) : fRuns(0)
|
---|
77 | {
|
---|
78 | fName = name ? name : "MJCalibration";
|
---|
79 | fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
|
---|
80 | }
|
---|
81 |
|
---|
82 | void MJCalibration::DrawProjection(MHCamera *obj, Int_t fit) const
|
---|
83 | {
|
---|
84 |
|
---|
85 | TH1D *obj2 = (TH1D*)obj->Projection(obj->GetName());
|
---|
86 | obj2->SetDirectory(0);
|
---|
87 | obj2->Draw();
|
---|
88 | obj2->SetBit(kCanDelete);
|
---|
89 |
|
---|
90 | if (obj->GetGeomCam().InheritsFrom("MGeomCamMagic"))
|
---|
91 | {
|
---|
92 | TArrayI s0(3);
|
---|
93 | s0[0] = 6;
|
---|
94 | s0[1] = 1;
|
---|
95 | s0[2] = 2;
|
---|
96 |
|
---|
97 | TArrayI s1(3);
|
---|
98 | s1[0] = 3;
|
---|
99 | s1[1] = 4;
|
---|
100 | s1[2] = 5;
|
---|
101 |
|
---|
102 | TArrayI inner(1);
|
---|
103 | inner[0] = 0;
|
---|
104 |
|
---|
105 | TArrayI outer(1);
|
---|
106 | outer[0] = 1;
|
---|
107 |
|
---|
108 | // Just to get the right (maximum) binning
|
---|
109 | TH1D *half[4];
|
---|
110 | half[0] = obj->ProjectionS(s0, inner, "Sector 6-1-2 Inner");
|
---|
111 | half[1] = obj->ProjectionS(s1, inner, "Sector 3-4-5 Inner");
|
---|
112 | half[2] = obj->ProjectionS(s0, outer, "Sector 6-1-2 Outer");
|
---|
113 | half[3] = obj->ProjectionS(s1, outer, "Sector 3-4-5 Outer");
|
---|
114 |
|
---|
115 | for (int i=0; i<4; i++)
|
---|
116 | {
|
---|
117 | half[i]->SetLineColor(kRed+i);
|
---|
118 | half[i]->SetDirectory(0);
|
---|
119 | half[i]->SetBit(kCanDelete);
|
---|
120 | half[i]->Draw("same");
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | const Double_t min = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
|
---|
125 | const Double_t max = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
|
---|
126 | const Double_t integ = obj2->Integral("width")/2.5;
|
---|
127 | const Double_t mean = obj2->GetMean();
|
---|
128 | const Double_t rms = obj2->GetRMS();
|
---|
129 | const Double_t width = max-min;
|
---|
130 |
|
---|
131 | const TString dgausformula = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])"
|
---|
132 | "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
|
---|
133 |
|
---|
134 | const TString tgausformula = "([0]-[3]-[6])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])"
|
---|
135 | "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])"
|
---|
136 | "+[6]/[8]*exp(-0.5*(x-[7])*(x-[7])/[8]/[8])";
|
---|
137 | TF1 *f=0;
|
---|
138 | switch (fit)
|
---|
139 | {
|
---|
140 | case 1:
|
---|
141 | f = new TF1("sgaus", "gaus(0)", min, max);
|
---|
142 | f->SetLineColor(kYellow);
|
---|
143 | f->SetBit(kCanDelete);
|
---|
144 | f->SetParNames("Area", "#mu", "#sigma");
|
---|
145 | f->SetParameters(integ/rms, mean, rms);
|
---|
146 | f->SetParLimits(0, 0, integ);
|
---|
147 | f->SetParLimits(1, min, max);
|
---|
148 | f->SetParLimits(2, 0, width/1.5);
|
---|
149 |
|
---|
150 | obj2->Fit(f, "QLR");
|
---|
151 | break;
|
---|
152 |
|
---|
153 | case 2:
|
---|
154 | f = new TF1("dgaus",dgausformula.Data(),min,max);
|
---|
155 | f->SetLineColor(kYellow);
|
---|
156 | f->SetBit(kCanDelete);
|
---|
157 | f->SetParNames("A_{tot}", "#mu1", "#sigma1", "A2", "#mu2", "#sigma2");
|
---|
158 | f->SetParameters(integ,(min+mean)/2.,width/4.,
|
---|
159 | integ/width/2.,(max+mean)/2.,width/4.);
|
---|
160 | // The left-sided Gauss
|
---|
161 | f->SetParLimits(0,integ-1.5 , integ+1.5);
|
---|
162 | f->SetParLimits(1,min+(width/10.), mean);
|
---|
163 | f->SetParLimits(2,0 , width/2.);
|
---|
164 | // The right-sided Gauss
|
---|
165 | f->SetParLimits(3,0 , integ);
|
---|
166 | f->SetParLimits(4,mean, max-(width/10.));
|
---|
167 | f->SetParLimits(5,0 , width/2.);
|
---|
168 | obj2->Fit(f,"QLRM");
|
---|
169 | break;
|
---|
170 |
|
---|
171 | case 3:
|
---|
172 | f = new TF1("tgaus",tgausformula.Data(),min,max);
|
---|
173 | f->SetLineColor(kYellow);
|
---|
174 | f->SetBit(kCanDelete);
|
---|
175 | f->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}",
|
---|
176 | "A_{2}","#mu_{2}","#sigma_{2}",
|
---|
177 | "A_{3}","#mu_{3}","#sigma_{3}");
|
---|
178 | f->SetParameters(integ,(min+mean)/2,width/4.,
|
---|
179 | integ/width/3.,(max+mean)/2.,width/4.,
|
---|
180 | integ/width/3.,mean,width/2.);
|
---|
181 | // The left-sided Gauss
|
---|
182 | f->SetParLimits(0,integ-1.5,integ+1.5);
|
---|
183 | f->SetParLimits(1,min+(width/10.),mean);
|
---|
184 | f->SetParLimits(2,width/15.,width/2.);
|
---|
185 | // The right-sided Gauss
|
---|
186 | f->SetParLimits(3,0.,integ);
|
---|
187 | f->SetParLimits(4,mean,max-(width/10.));
|
---|
188 | f->SetParLimits(5,width/15.,width/2.);
|
---|
189 | // The Gauss describing the outliers
|
---|
190 | f->SetParLimits(6,0.,integ);
|
---|
191 | f->SetParLimits(7,min,max);
|
---|
192 | f->SetParLimits(8,width/4.,width/1.5);
|
---|
193 | obj2->Fit(f,"QLRM");
|
---|
194 | break;
|
---|
195 |
|
---|
196 | case 4:
|
---|
197 | obj2->Fit("pol0", "Q");
|
---|
198 | obj2->GetFunction("pol0")->SetLineColor(kYellow);
|
---|
199 | break;
|
---|
200 |
|
---|
201 | case 9:
|
---|
202 | break;
|
---|
203 |
|
---|
204 | default:
|
---|
205 | obj2->Fit("gaus", "Q");
|
---|
206 | obj2->GetFunction("gaus")->SetLineColor(kYellow);
|
---|
207 | break;
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | void MJCalibration::DrawRadialProfile(MHCamera *obj) const
|
---|
212 | {
|
---|
213 |
|
---|
214 | TProfile *obj2 = (TProfile*)obj->RadialProfile(obj->GetName());
|
---|
215 | obj2->SetDirectory(0);
|
---|
216 | obj2->Draw();
|
---|
217 | obj2->SetBit(kCanDelete);
|
---|
218 |
|
---|
219 | if (obj->GetGeomCam().InheritsFrom("MGeomCamMagic"))
|
---|
220 | {
|
---|
221 |
|
---|
222 | TArrayI s0(6);
|
---|
223 | s0[0] = 1;
|
---|
224 | s0[1] = 2;
|
---|
225 | s0[2] = 3;
|
---|
226 | s0[3] = 4;
|
---|
227 | s0[4] = 5;
|
---|
228 | s0[5] = 6;
|
---|
229 |
|
---|
230 | TArrayI inner(1);
|
---|
231 | inner[0] = 0;
|
---|
232 |
|
---|
233 | TArrayI outer(1);
|
---|
234 | outer[0] = 1;
|
---|
235 |
|
---|
236 | // Just to get the right (maximum) binning
|
---|
237 | TProfile *half[2];
|
---|
238 | half[0] = obj->RadialProfileS(s0, inner,Form("%s%s",obj->GetName(),"Inner"));
|
---|
239 | half[1] = obj->RadialProfileS(s0, outer,Form("%s%s",obj->GetName(),"Outer"));
|
---|
240 |
|
---|
241 | for (Int_t i=0; i<2; i++)
|
---|
242 | {
|
---|
243 | Double_t min = obj->GetGeomCam().GetMinRadius(i);
|
---|
244 | Double_t max = obj->GetGeomCam().GetMaxRadius(i);
|
---|
245 |
|
---|
246 | half[i]->SetLineColor(kRed+i);
|
---|
247 | half[i]->SetDirectory(0);
|
---|
248 | half[i]->SetBit(kCanDelete);
|
---|
249 | half[i]->Draw("same");
|
---|
250 | half[i]->Fit("pol1","Q","",min,max);
|
---|
251 | half[i]->GetFunction("pol1")->SetLineColor(kRed+i);
|
---|
252 | half[i]->GetFunction("pol1")->SetLineWidth(1);
|
---|
253 | }
|
---|
254 | }
|
---|
255 | }
|
---|
256 |
|
---|
257 |
|
---|
258 | void MJCalibration::CamDraw(TCanvas &c, const Int_t x, const Int_t y, const MHCamera &cam1,
|
---|
259 | const Int_t fit, const Int_t rad)
|
---|
260 | {
|
---|
261 | c.cd(x);
|
---|
262 | gPad->SetBorderMode(0);
|
---|
263 | gPad->SetTicks();
|
---|
264 | MHCamera *obj1=(MHCamera*)cam1.DrawCopy("hist");
|
---|
265 | obj1->SetDirectory(NULL);
|
---|
266 |
|
---|
267 | c.cd(x+y);
|
---|
268 | gPad->SetBorderMode(0);
|
---|
269 | obj1->SetPrettyPalette();
|
---|
270 | obj1->AddNotify(&fCalibrationCam);
|
---|
271 | obj1->Draw();
|
---|
272 |
|
---|
273 | if (rad)
|
---|
274 | {
|
---|
275 | c.cd(x+2*y);
|
---|
276 | gPad->SetBorderMode(0);
|
---|
277 | gPad->SetTicks();
|
---|
278 | DrawRadialProfile(obj1);
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|
282 | if (!fit)
|
---|
283 | return;
|
---|
284 |
|
---|
285 | c.cd(rad ? x+3*y : x+2*y);
|
---|
286 | gPad->SetBorderMode(0);
|
---|
287 | gPad->SetTicks();
|
---|
288 | DrawProjection(obj1, fit);
|
---|
289 | }
|
---|
290 |
|
---|
291 |
|
---|
292 | void MJCalibration::DisplayResult(MParList &plist)
|
---|
293 | {
|
---|
294 | if (!fDisplay)
|
---|
295 | return;
|
---|
296 |
|
---|
297 | //
|
---|
298 | // Update display
|
---|
299 | //
|
---|
300 | TString title = fDisplay->GetTitle();
|
---|
301 | title += "-- Calibration ";
|
---|
302 | title += fRuns->GetRunsAsString();
|
---|
303 | title += " --";
|
---|
304 | fDisplay->SetTitle(title);
|
---|
305 |
|
---|
306 | //
|
---|
307 | // Get container from list
|
---|
308 | //
|
---|
309 | MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
|
---|
310 |
|
---|
311 | // Create histograms to display
|
---|
312 | MHCamera disp1 (geomcam, "Cal;Charge", "Fitted Mean Charges");
|
---|
313 | MHCamera disp2 (geomcam, "Cal;SigmaCharge", "Sigma of Fitted Charges");
|
---|
314 | MHCamera disp3 (geomcam, "Cal;RSigma", "Reduced Sigmas");
|
---|
315 | MHCamera disp4 (geomcam, "Cal;RSigma/Charge", "Reduced Sigma per Charge");
|
---|
316 | MHCamera disp5 (geomcam, "Cal;FFactorPhe", "Nr. of Phe's (F-Factor Method)");
|
---|
317 | MHCamera disp6 (geomcam, "Cal;FFactorConv", "Conversion Factor (F-Factor Method)");
|
---|
318 | MHCamera disp7 (geomcam, "Cal;BlindPixConv", "Conversion Factor (Blind Pixel Method)");
|
---|
319 | MHCamera disp8 (geomcam, "Cal;PINDiodeConv", "Conversion Factor (PIN Diode Method)");
|
---|
320 | MHCamera disp9 (geomcam, "Cal;FFactorValid", "Pixels with valid F-Factor calibration");
|
---|
321 | MHCamera disp10(geomcam, "Cal;BlindPixelValid","Pixels with valid BlindPixel calibration");
|
---|
322 | MHCamera disp11(geomcam, "Cal;PINdiodeValid", "Pixels with valid PINDiode calibration");
|
---|
323 | MHCamera disp12(geomcam, "Cal;Excluded", "Pixels previously excluded");
|
---|
324 | MHCamera disp13(geomcam, "Cal;Saturation", "Pixels with saturated Hi Gain");
|
---|
325 | MHCamera disp14(geomcam, "Cal;HiGainPickup", "Number Pickup events Hi Gain");
|
---|
326 | MHCamera disp15(geomcam, "Cal;LoGainPickup", "Number Pickup events Lo Gain");
|
---|
327 | MHCamera disp16(geomcam, "Bad;UnSuitable", "Pixels not suited for further analysis");
|
---|
328 | MHCamera disp17(geomcam, "Bad;UnReliable", "Pixels not reliable for further analysis");
|
---|
329 | MHCamera disp18(geomcam, "Bad;Oscillation", "Oscillating Pixels");
|
---|
330 | MHCamera disp19(geomcam, "Cal;AbsTimeMean", "Abs. Arrival Times");
|
---|
331 | MHCamera disp20(geomcam, "Cal;AbsTimeRms", "RMS of Arrival Times");
|
---|
332 |
|
---|
333 | // Fitted charge means and sigmas
|
---|
334 | disp1.SetCamContent(fCalibrationCam, 0);
|
---|
335 | disp1.SetCamError( fCalibrationCam, 1);
|
---|
336 | disp2.SetCamContent(fCalibrationCam, 2);
|
---|
337 | disp2.SetCamError( fCalibrationCam, 3);
|
---|
338 |
|
---|
339 | // Reduced Sigmas and reduced sigmas per charge
|
---|
340 | disp3.SetCamContent(fCalibrationCam, 5);
|
---|
341 | disp3.SetCamError( fCalibrationCam, 6);
|
---|
342 | disp4.SetCamContent(fCalibrationCam, 7);
|
---|
343 | disp4.SetCamError( fCalibrationCam, 8);
|
---|
344 |
|
---|
345 | // Conversion Factors, Methods
|
---|
346 | disp5.SetCamContent(fCalibrationCam, 9);
|
---|
347 | disp5.SetCamError( fCalibrationCam, 10);
|
---|
348 | disp6.SetCamContent(fCalibrationCam, 11);
|
---|
349 | disp6.SetCamError( fCalibrationCam, 12);
|
---|
350 | disp7.SetCamContent(fCalibrationCam, 13);
|
---|
351 | disp7.SetCamError( fCalibrationCam, 14);
|
---|
352 | disp8.SetCamContent(fCalibrationCam, 16);
|
---|
353 | disp8.SetCamError( fCalibrationCam, 17);
|
---|
354 |
|
---|
355 | // Valid flags
|
---|
356 | disp9.SetCamContent (fCalibrationCam, 15);
|
---|
357 | disp10.SetCamContent(fCalibrationCam, 20);
|
---|
358 | disp11.SetCamContent(fCalibrationCam, 25);
|
---|
359 |
|
---|
360 | // Pixels behavior
|
---|
361 | disp12.SetCamContent(fCalibrationCam, 26);
|
---|
362 | disp13.SetCamContent(fCalibrationCam, 29);
|
---|
363 | disp14.SetCamContent(fCalibrationCam, 27);
|
---|
364 | disp15.SetCamContent(fCalibrationCam, 28);
|
---|
365 |
|
---|
366 | // Pixels with defects
|
---|
367 | disp16.SetCamContent(fBadPixels, 1);
|
---|
368 | disp17.SetCamContent(fBadPixels, 3);
|
---|
369 | disp18.SetCamContent(fBadPixels, 8);
|
---|
370 |
|
---|
371 | // Arrival Times
|
---|
372 | disp19.SetCamContent(fCalibrationCam, 34);
|
---|
373 | disp19.SetCamError( fCalibrationCam, 35);
|
---|
374 | disp20.SetCamContent(fCalibrationCam, 35);
|
---|
375 |
|
---|
376 | disp1.SetYTitle("Q [FADC units]");
|
---|
377 | disp2.SetYTitle("\\sigma_{Q} [FADC units]");
|
---|
378 |
|
---|
379 | disp3.SetYTitle("\\sqrt{\\sigma^{2}_{Q} - RMS^{2}_{Ped}} [FADC Counts]");
|
---|
380 | disp4.SetYTitle("Red.Sigma/<Q> [1]");
|
---|
381 |
|
---|
382 | disp5.SetYTitle("PhE [#]");
|
---|
383 | disp6.SetYTitle("Conv.Factor [PhE/FADC units]");
|
---|
384 |
|
---|
385 | disp7.SetYTitle("Conv.Factor [Phot/FADC Count]");
|
---|
386 | disp8.SetYTitle("Conv.Factor [Phot/FADC Count]");
|
---|
387 |
|
---|
388 | disp9.SetYTitle("[1]");
|
---|
389 | disp10.SetYTitle("[1]");
|
---|
390 | disp11.SetYTitle("[1]");
|
---|
391 | disp12.SetYTitle("[1]");
|
---|
392 | disp13.SetYTitle("[1]");
|
---|
393 | disp14.SetYTitle("[1]");
|
---|
394 | disp15.SetYTitle("[1]");
|
---|
395 | disp16.SetYTitle("[1]");
|
---|
396 | disp17.SetYTitle("[1]");
|
---|
397 | disp18.SetYTitle("[1]");
|
---|
398 | disp19.SetYTitle("Mean Abs. Time [FADC slice]");
|
---|
399 | disp20.SetYTitle("RMS Abs. Time [FADC slices]");
|
---|
400 |
|
---|
401 | gStyle->SetOptStat(1111);
|
---|
402 | gStyle->SetOptFit();
|
---|
403 |
|
---|
404 | // Charges
|
---|
405 | TCanvas &c1 = fDisplay->AddTab("Fit.Charge");
|
---|
406 | c1.Divide(2, 4);
|
---|
407 |
|
---|
408 | CamDraw(c1, 1, 2, disp1, 2, 1);
|
---|
409 | CamDraw(c1, 2, 2, disp2, 2, 1);
|
---|
410 |
|
---|
411 | // Reduced Sigmas
|
---|
412 | TCanvas &c3 = fDisplay->AddTab("Red.Sigma");
|
---|
413 | c3.Divide(2,4);
|
---|
414 |
|
---|
415 | CamDraw(c3, 1, 2, disp3, 2, 1);
|
---|
416 | CamDraw(c3, 2, 2, disp4, 2, 1);
|
---|
417 |
|
---|
418 | // Methods
|
---|
419 | TCanvas &c4 = fDisplay->AddTab("Methods");
|
---|
420 | c4.Divide(4,4);
|
---|
421 |
|
---|
422 | CamDraw(c4, 1, 4, disp5, 2, 1);
|
---|
423 | CamDraw(c4, 2, 4, disp6, 2, 1);
|
---|
424 | CamDraw(c4, 3, 4, disp7, 2, 1);
|
---|
425 | CamDraw(c4, 4, 4, disp8, 2, 1);
|
---|
426 |
|
---|
427 | // Validity
|
---|
428 | TCanvas &c5 = fDisplay->AddTab("Validity");
|
---|
429 | c5.Divide(3,2);
|
---|
430 |
|
---|
431 | CamDraw(c5, 1, 3, disp9 , 0);
|
---|
432 | CamDraw(c5, 2, 3, disp10, 0);
|
---|
433 | CamDraw(c5, 3, 3, disp11, 0);
|
---|
434 |
|
---|
435 | // Other info
|
---|
436 | TCanvas &c6 = fDisplay->AddTab("Behavior");
|
---|
437 | c6.Divide(4,2);
|
---|
438 |
|
---|
439 | CamDraw(c6, 1, 4, disp12, 0);
|
---|
440 | CamDraw(c6, 2, 4, disp13, 0);
|
---|
441 | CamDraw(c6, 3, 4, disp14, 0);
|
---|
442 | CamDraw(c6, 4, 4, disp15, 0);
|
---|
443 |
|
---|
444 | // Defects
|
---|
445 | TCanvas &c7 = fDisplay->AddTab("Defects");
|
---|
446 | c7.Divide(3,2);
|
---|
447 |
|
---|
448 | CamDraw(c7, 1, 3, disp16, 0);
|
---|
449 | CamDraw(c7, 2, 3, disp17, 0);
|
---|
450 | CamDraw(c7, 3, 3, disp18, 0);
|
---|
451 |
|
---|
452 | // Abs. Times
|
---|
453 | TCanvas &c8 = fDisplay->AddTab("Abs. Times");
|
---|
454 | c8.Divide(2,3);
|
---|
455 |
|
---|
456 | CamDraw(c8, 1, 2, disp19, 2);
|
---|
457 | CamDraw(c8, 2, 2, disp20, 1);
|
---|
458 |
|
---|
459 | }
|
---|
460 |
|
---|
461 | Bool_t MJCalibration::WriteResult()
|
---|
462 | {
|
---|
463 | if (fOutputPath.IsNull())
|
---|
464 | return kTRUE;
|
---|
465 |
|
---|
466 | const TString oname(GetOutputFile());
|
---|
467 |
|
---|
468 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
469 |
|
---|
470 | TFile file(oname, "UPDATE");
|
---|
471 |
|
---|
472 | if (fDisplay && fDisplay->Write()<=0)
|
---|
473 | {
|
---|
474 | *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
|
---|
475 | return kFALSE;
|
---|
476 | }
|
---|
477 |
|
---|
478 | if (fCalibrationCam.Write()<=0)
|
---|
479 | {
|
---|
480 | *fLog << err << "Unable to write MCalibrationCam to " << oname << endl;
|
---|
481 | return kFALSE;
|
---|
482 | }
|
---|
483 |
|
---|
484 | if (fBadPixels.Write()<=0)
|
---|
485 | {
|
---|
486 | *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
|
---|
487 | return kFALSE;
|
---|
488 | }
|
---|
489 |
|
---|
490 | return kTRUE;
|
---|
491 |
|
---|
492 | }
|
---|
493 |
|
---|
494 | void MJCalibration::SetOutputPath(const char *path)
|
---|
495 | {
|
---|
496 | fOutputPath = path;
|
---|
497 | if (fOutputPath.EndsWith("/"))
|
---|
498 | fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
|
---|
499 | }
|
---|
500 |
|
---|
501 | Bool_t MJCalibration::Process(MPedestalCam &pedcam)
|
---|
502 | {
|
---|
503 | if (!ReadCalibrationCam())
|
---|
504 | return ProcessFile(pedcam);
|
---|
505 |
|
---|
506 | return kTRUE;
|
---|
507 | }
|
---|
508 |
|
---|
509 | TString MJCalibration::GetOutputFile() const
|
---|
510 | {
|
---|
511 | if (!fRuns)
|
---|
512 | return "";
|
---|
513 |
|
---|
514 | return Form("%s/%s-F1.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
|
---|
515 | }
|
---|
516 |
|
---|
517 | Bool_t MJCalibration::ReadCalibrationCam()
|
---|
518 | {
|
---|
519 | const TString fname = GetOutputFile();
|
---|
520 |
|
---|
521 | if (gSystem->AccessPathName(fname, kFileExists))
|
---|
522 | {
|
---|
523 | *fLog << err << "Input file " << fname << " doesn't exist." << endl;
|
---|
524 | return kFALSE;
|
---|
525 | }
|
---|
526 |
|
---|
527 | *fLog << inf << "Reading from file: " << fname << endl;
|
---|
528 |
|
---|
529 | TFile file(fname, "READ");
|
---|
530 | if (fCalibrationCam.Read()<=0)
|
---|
531 | {
|
---|
532 | *fLog << err << "Unable to read MCalibrationCam from " << fname << endl;
|
---|
533 | return kFALSE;
|
---|
534 | }
|
---|
535 |
|
---|
536 | if (file.FindKey("MBadPixelsCam"))
|
---|
537 | {
|
---|
538 | MBadPixelsCam bad;
|
---|
539 | if (bad.Read()<=0)
|
---|
540 | {
|
---|
541 | *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
|
---|
542 | return kFALSE;
|
---|
543 | }
|
---|
544 | fBadPixels.Merge(bad);
|
---|
545 | }
|
---|
546 |
|
---|
547 | if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
|
---|
548 | fDisplay->Read();
|
---|
549 |
|
---|
550 | return kTRUE;
|
---|
551 | }
|
---|
552 |
|
---|
553 |
|
---|
554 | Bool_t MJCalibration::ProcessFile(MPedestalCam &pedcam)
|
---|
555 | {
|
---|
556 | if (!fRuns)
|
---|
557 | {
|
---|
558 | *fLog << err << "No Runs choosen... abort." << endl;
|
---|
559 | return kFALSE;
|
---|
560 | }
|
---|
561 | if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
|
---|
562 | {
|
---|
563 | *fLog << err << "Number of files found doesn't match number of runs... abort." << endl;
|
---|
564 | return kFALSE;
|
---|
565 | }
|
---|
566 |
|
---|
567 | *fLog << inf;
|
---|
568 | fLog->Separator(GetDescriptor());
|
---|
569 | *fLog << "Calculate MCalibrationCam from Runs " << fRuns->GetRunsAsString() << endl;
|
---|
570 | *fLog << endl;
|
---|
571 |
|
---|
572 | MReadMarsFile read("Events");
|
---|
573 | read.DisableAutoScheme();
|
---|
574 | static_cast<MRead&>(read).AddFiles(*fRuns);
|
---|
575 |
|
---|
576 | //
|
---|
577 | // As long, as we don't have digital modules,
|
---|
578 | // we have to set the color of the pulser LED by hand
|
---|
579 | //
|
---|
580 | MCalibrationChargePINDiode pindiode;
|
---|
581 | pindiode.SetColor(kCT1);
|
---|
582 |
|
---|
583 | MCalibrationChargeBlindPix blindpix;
|
---|
584 | blindpix.SetColor(kCT1);
|
---|
585 |
|
---|
586 | // Setup Tasklist
|
---|
587 | MParList plist;
|
---|
588 | plist.AddToList(&pedcam);
|
---|
589 | plist.AddToList(&fCalibrationCam);
|
---|
590 | plist.AddToList(&fBadPixels);
|
---|
591 | plist.AddToList(&pindiode);
|
---|
592 | plist.AddToList(&blindpix);
|
---|
593 |
|
---|
594 | MTaskList tlist;
|
---|
595 | plist.AddToList(&tlist);
|
---|
596 |
|
---|
597 | MGeomApply apply;
|
---|
598 | MBadPixelsMerge merge(&fBadPixels);
|
---|
599 | MExtractPINDiode pinext;
|
---|
600 | MExtractBlindPixel blindext;
|
---|
601 | // MExtractSignal extract; // Do not use this at the moment...
|
---|
602 | MExtractSignal2 extract;
|
---|
603 | MCalibrationChargeCalc calcalc;
|
---|
604 |
|
---|
605 | MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
|
---|
606 | MFillH fillbnd("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
|
---|
607 | MFillH fillcam("MHCalibrationChargeCam", "MExtractedSignalCam");
|
---|
608 | fillpin.SetNameTab("PINDiode");
|
---|
609 | fillbnd.SetNameTab("BlindPix");
|
---|
610 | fillcam.SetNameTab("Charge");
|
---|
611 |
|
---|
612 | //
|
---|
613 | // Apply a filter against cosmics
|
---|
614 | // (will have to be needed in the future
|
---|
615 | // when the calibration hardware-trigger is working)
|
---|
616 | //
|
---|
617 | MFCosmics cosmics;
|
---|
618 | MContinue cont(&cosmics);
|
---|
619 |
|
---|
620 | //calcalc.SkipBlindPixelFit();
|
---|
621 |
|
---|
622 | tlist.AddToList(&read);
|
---|
623 | tlist.AddToList(&merge);
|
---|
624 | tlist.AddToList(&apply);
|
---|
625 | tlist.AddToList(&extract);
|
---|
626 | tlist.AddToList(&pinext);
|
---|
627 | tlist.AddToList(&blindext);
|
---|
628 | tlist.AddToList(&cont);
|
---|
629 | tlist.AddToList(&fillcam);
|
---|
630 | tlist.AddToList(&fillpin);
|
---|
631 | tlist.AddToList(&fillbnd);
|
---|
632 | tlist.AddToList(&calcalc);
|
---|
633 |
|
---|
634 | // Create and setup the eventloop
|
---|
635 | MEvtLoop evtloop(fName);
|
---|
636 | evtloop.SetParList(&plist);
|
---|
637 | evtloop.SetDisplay(fDisplay);
|
---|
638 | evtloop.SetLogStream(fLog);
|
---|
639 |
|
---|
640 | // Execute first analysis
|
---|
641 | if (!evtloop.Eventloop())
|
---|
642 | {
|
---|
643 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
644 | return kFALSE;
|
---|
645 | }
|
---|
646 |
|
---|
647 | tlist.PrintStatistics();
|
---|
648 |
|
---|
649 | DisplayResult(plist);
|
---|
650 |
|
---|
651 | if (!WriteResult())
|
---|
652 | return kFALSE;
|
---|
653 |
|
---|
654 | *fLog << inf << GetDescriptor() << ": Done." << endl;
|
---|
655 |
|
---|
656 | return kTRUE;
|
---|
657 | }
|
---|