source: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc@ 4134

Last change on this file since 4134 was 4134, checked in by gaug, 21 years ago
*** empty log message ***
File size: 37.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, 02/2004 <mailto:markus@ifae.es>
20!
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJCalibration
28//
29// Do one calibration loop over serious of runs with the same pulser
30// colour and the same intensity. The following containers (rectangular) and
31// tasks (ellipses) are called to produce an MCalibrationChargeCam and to
32// update the MCalibrationQECam: (MCalibrate is not called from this class)
33//
34//Begin_Html
35/*
36<img src="images/CalibClasses.gif">
37*/
38//End_Html
39//
40// Different signal extractors can be set with the command SetExtractor()
41// Only extractors deriving from MExtractor can be set, default is MExtractSlidingWindow
42//
43// Different arrival time extractors can be set with the command SetTimeExtractor()
44// Only extractors deriving from MExtractTime can be set, default is MExtractTimeSpline
45//
46// At the end of the eventloop, plots and results are displayed, depending on
47// the flags set (see DisplayResult())
48//
49// If the flag SetFullDisplay() is set, all MHCameras will be displayed.
50// if the flag SetDataCheckDisplay() is set, only the most important ones are displayed
51// Otherwise, (default: SetNormalDisplay()), a good selection of plots is given
52//
53// If the flag SetDataCheck() is set, the calibration is used as in the data check at
54// La Palma, which mean especially running it on raw data files.
55//
56// See also: MHCalibrationChargePix, MHCalibrationChargeCam, MHGausEvents
57// MHCalibrationChargeBlindPix, MHCalibrationChargePINDiode
58// MCalibrationChargePix, MCalibrationChargeCam, MCalibrationChargeCalc
59// MCalibrationChargeBlindPix, MCalibrationChargePINDiode,
60// MCalibrationQECam, MBadPixelsPix, MBadPixelsCam
61//
62// If the flag RelTimeCalibration() is set, a calibration of the relative arrival
63// times is also performed. The following containers (rectangular) and
64// tasks (ellipses) are called to produce an MCalibrationRelTimeCam used by
65// MCalibrateTime to correct timing offset between pixels: (MCalibrateTime is not
66// called from this class)
67//
68//Begin_Html
69/*
70<img src="images/RelTimeClasses.gif">
71*/
72//End_Html
73//
74// Different arrival time extractors can be chosen via the command SetArrivalTimeLevel(UInt_t i)
75// Up to now, the following extractors are available:
76// i=1: Use MArrivalTimeCalc (using MCubicSpline, arrival time == position at half maximum)
77// i=2: Use MArrivalTimeCalc2 (mean time of fWindowSize time slices with the highest integral content: default)
78//
79// See also: MHCalibrationRelTimePix, MHCalibrationRelTimeCam, MHGausEvents
80// MCalibrationRelTimePix, MCalibrationRelTimeCam
81// MBadPixelsPix, MBadPixelsCam
82//
83/////////////////////////////////////////////////////////////////////////////
84#include "MJCalibration.h"
85
86#include <TFile.h>
87#include <TStyle.h>
88#include <TCanvas.h>
89#include <TSystem.h>
90
91#include "MLog.h"
92#include "MLogManip.h"
93
94#include "MRunIter.h"
95#include "MParList.h"
96#include "MTaskList.h"
97#include "MEvtLoop.h"
98
99#include "MHCamera.h"
100#include "MGeomCam.h"
101
102#include "MPedestalCam.h"
103#include "MCalibrationCam.h"
104#include "MCalibrationQECam.h"
105#include "MCalibrationChargeCam.h"
106#include "MCalibrationChargePINDiode.h"
107#include "MCalibrationChargeBlindPix.h"
108#include "MCalibrationChargeCalc.h"
109
110#include "MHGausEvents.h"
111#include "MHCalibrationCam.h"
112#include "MHCalibrationChargeCam.h"
113#include "MHCalibrationChargeBlindPix.h"
114#include "MHCalibrationRelTimeCam.h"
115#include "MCalibrationRelTimeCam.h"
116#include "MCalibrationRelTimeCalc.h"
117
118#include "MReadMarsFile.h"
119#include "MRawFileRead.h"
120#include "MGeomApply.h"
121#include "MBadPixelsMerge.h"
122#include "MBadPixelsCam.h"
123#include "MExtractTime.h"
124#include "MExtractor.h"
125#include "MExtractPINDiode.h"
126#include "MExtractBlindPixel.h"
127#include "MExtractSlidingWindow.h"
128#include "MExtractTimeSpline.h"
129#include "MFCosmics.h"
130#include "MContinue.h"
131#include "MFillH.h"
132
133#include "MArrivalTimeCam.h"
134
135#include "MStatusDisplay.h"
136
137ClassImp(MJCalibration);
138
139using namespace std;
140
141const Int_t MJCalibration::gkIFAEBoxInaugurationRun = 20113;
142// --------------------------------------------------------------------------
143//
144// Default constructor.
145//
146// Sets fRuns to 0, fExtractor to NULL, fTimeExtractor to NULL, fColor to kNONE,
147// fDisplay to kNormalDisplay, fRelTime to kFALSE, fDataCheck to kFALSE
148//
149MJCalibration::MJCalibration(const char *name, const char *title)
150 : fRuns(0), fExtractor(NULL), fTimeExtractor(NULL),
151 fColor(MCalibrationCam::kNONE), fDisplayType(kNormalDisplay),
152 fRelTimes(kFALSE), fDataCheck(kFALSE)
153{
154 fName = name ? name : "MJCalibration";
155 fTitle = title ? title : "Tool to create the calibration constants for one calibration run";
156
157}
158
159
160// --------------------------------------------------------------------------
161//
162// Display the results in MStatusDisplay:
163//
164// - Add "Calibration" to the MStatusDisplay title
165// - Retrieve the MGeomCam from MParList
166// - Initialize the following MHCamera's:
167// 1) MCalibrationPix::GetMean()
168// 2) MCalibrationPix::Sigma()
169// 3) MCalibrationChargePix::GetRSigma()
170// 4) MCalibrationChargePix::GetRSigmaPerCharge()
171// 5) MCalibrationChargePix::GetPheFFactorMethod()
172// 6) MCalibrationChargePix::GetMeanConvFADC2Phe()
173// 7) MCalibrationChargePix::GetMeanFFactorFADC2Phot()
174// 8) MCalibrationQEPix::GetQECascadesFFactor()
175// 9) MCalibrationQEPix::GetQECascadesBlindPixel()
176// 10) MCalibrationQEPix::GetQECascadesPINDiode()
177// 11) MCalibrationQEPix::GetQECascadesCombined()
178// 12) MCalibrationQEPix::IsAverageQEFFactorAvailable()
179// 13) MCalibrationQEPix::IsAverageQEBlindPixelAvailable()
180// 14) MCalibrationQEPix::IsAverageQEPINDiodeAvailable()
181// 15) MCalibrationQEPix::IsAverageQECombinedAvailable()
182// 16) MCalibrationChargePix::IsHiGainSaturation()
183// 17) MCalibrationPix::GetHiLoMeansDivided()
184// 18) MCalibrationPix::GetHiLoSigmasDivided()
185// 19) MCalibrationChargePix::GetHiGainPickup()
186// 20) MCalibrationChargePix::GetLoGainPickup()
187// 21) MCalibrationChargePix::GetHiGainBlackout()
188// 22) MCalibrationChargePix::GetLoGainBlackout()
189// 23) MCalibrationPix::IsExcluded()
190// 24) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnsuitableRun)
191// 25) MBadPixelsPix::IsUnsuitable(MBadPixelsPix::kUnreliableRun)
192// 26) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainOscillating)
193// 27) MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kLoGainOscillating)
194// 28) MCalibrationChargePix::GetAbsTimeMean()
195// 29) MCalibrationChargePix::GetAbsTimeRms()
196//
197// If the flag SetFullDisplay() is set, all MHCameras will be displayed.
198// if the flag SetDataCheckDisplay() is set, only the most important ones are displayed
199// and otherwise, (default: SetNormalDisplay()), a good selection of plots is given
200//
201void MJCalibration::DisplayResult(MParList &plist)
202{
203 if (!fDisplay)
204 return;
205
206 //
207 // Update display
208 //
209 TString title = fDisplay->GetTitle();
210 title += "-- Calibration ";
211 title += fRuns->GetRunsAsString();
212 title += " --";
213 fDisplay->SetTitle(title);
214
215 //
216 // Get container from list
217 //
218 MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
219
220 // Create histograms to display
221 MHCamera disp1 (geomcam, Form("%s%s","Charge",(fRuns->GetRunsAsFileName()).Data()),
222 "Fitted Mean Charges");
223 MHCamera disp2 (geomcam, Form("%s%s","SigmaCharge",(fRuns->GetRunsAsFileName()).Data()),
224 "Sigma of Fitted Charges");
225 MHCamera disp3 (geomcam, Form("%s%s","RSigma",(fRuns->GetRunsAsFileName()).Data()),
226 "Reduced Sigmas");
227 MHCamera disp4 (geomcam, Form("%s%s","RSigmaPerCharge",(fRuns->GetRunsAsFileName()).Data()),
228 "Reduced Sigma per Charge");
229 MHCamera disp5 (geomcam, Form("%s%s","NumPhes",(fRuns->GetRunsAsFileName()).Data()),
230 "Nr. of Phe's (F-Factor Method)");
231 MHCamera disp6 (geomcam, Form("%s%s","ConvFADC2Phes",(fRuns->GetRunsAsFileName()).Data()),
232 "Conversion Factor (F-Factor Method)");
233 MHCamera disp7 (geomcam, Form("%s%s","TotalFFactor",(fRuns->GetRunsAsFileName()).Data()),
234 "Total F-Factor (F-Factor Method)");
235 MHCamera disp8 (geomcam, Form("%s%s","CascadesQEFFactor",(fRuns->GetRunsAsFileName()).Data()),
236 "Cascades QE (F-Factor Method)");
237 MHCamera disp9 (geomcam, Form("%s%s","CascadesQEBlindPix",(fRuns->GetRunsAsFileName()).Data()),
238 "Cascades QE (Blind Pixel Method)");
239 MHCamera disp10(geomcam, Form("%s%s","CascadesQEPINDiode",(fRuns->GetRunsAsFileName()).Data()),
240 "Cascades QE (PIN Diode Method)");
241 MHCamera disp11(geomcam, Form("%s%s","CascadesQECombined",(fRuns->GetRunsAsFileName()).Data()),
242 "Cascades QE (Combined Method)");
243 MHCamera disp12(geomcam, Form("%s%s","FFactorValid",(fRuns->GetRunsAsFileName()).Data()),
244 "Pixels with valid F-Factor calibration");
245 MHCamera disp13(geomcam, Form("%s%s","BlindPixelValid",(fRuns->GetRunsAsFileName()).Data()),
246 "Pixels with valid BlindPixel calibration");
247 MHCamera disp14(geomcam, Form("%s%s","PINdiodeValid",(fRuns->GetRunsAsFileName()).Data()),
248 "Pixels with valid PINDiode calibration");
249 MHCamera disp15(geomcam, Form("%s%s","CombinedValid",(fRuns->GetRunsAsFileName()).Data()),
250 "Pixels with valid Combined calibration");
251 MHCamera disp16(geomcam, Form("%s%s","Saturation",(fRuns->GetRunsAsFileName()).Data()),
252 "Pixels with saturated Hi Gain");
253 MHCamera disp17(geomcam, Form("%s%s","ConversionMeans",(fRuns->GetRunsAsFileName()).Data()),
254 "Conversion HiGain.vs.LoGain Means");
255 MHCamera disp18(geomcam, Form("%s%s","ConversionSigmas",(fRuns->GetRunsAsFileName()).Data()),
256 "Conversion HiGain.vs.LoGain Sigmas");
257 MHCamera disp19(geomcam, Form("%s%s","HiGainPickup",(fRuns->GetRunsAsFileName()).Data()),
258 "Number Pickup events Hi Gain");
259 MHCamera disp20(geomcam, Form("%s%s","LoGainPickup",(fRuns->GetRunsAsFileName()).Data()),
260 "Number Pickup events Lo Gain");
261 MHCamera disp21(geomcam, Form("%s%s","HiGainBlackout",(fRuns->GetRunsAsFileName()).Data()),
262 "Number Blackout events Hi Gain");
263 MHCamera disp22(geomcam, Form("%s%s","LoGainBlackout",(fRuns->GetRunsAsFileName()).Data()),
264 "Number Blackout events Lo Gain");
265 MHCamera disp23(geomcam, Form("%s%s","Excluded",(fRuns->GetRunsAsFileName()).Data()),
266 "Pixels previously excluded");
267 MHCamera disp24(geomcam, Form("%s%s","UnSuitable",(fRuns->GetRunsAsFileName()).Data()),
268 "Pixels not suited for further analysis");
269 MHCamera disp25(geomcam, Form("%s%s","UnReliable",(fRuns->GetRunsAsFileName()).Data()),
270 "Pixels not reliable for further analysis");
271 MHCamera disp26(geomcam, Form("%s%s","HiGainOscillating",(fRuns->GetRunsAsFileName()).Data()),
272 "Oscillating Pixels High Gain");
273 MHCamera disp27(geomcam, Form("%s%s","LoGainOscillating",(fRuns->GetRunsAsFileName()).Data()),
274 "Oscillating Pixels Low Gain");
275 MHCamera disp28(geomcam, Form("%s%s","AbsTimeMean",(fRuns->GetRunsAsFileName()).Data()),
276 "Abs. Arrival Times");
277 MHCamera disp29(geomcam, Form("%s%s","AbsTimeRms",(fRuns->GetRunsAsFileName()).Data()),
278 "RMS of Arrival Times");
279 MHCamera disp30(geomcam, Form("%s%s","MeanTime",(fRuns->GetRunsAsFileName()).Data()),
280 "Mean Rel. Arrival Times");
281 MHCamera disp31(geomcam, Form("%s%s","SigmaTime",(fRuns->GetRunsAsFileName()).Data()),
282 "Sigma Rel. Arrival Times");
283 MHCamera disp32(geomcam, Form("%s%s","TimeProb",(fRuns->GetRunsAsFileName()).Data()),
284 "Probability of Time Fit");
285 MHCamera disp33(geomcam, Form("%s%s","TimeNotFitValid",(fRuns->GetRunsAsFileName()).Data()),
286 "Pixels with not valid fit results");
287 MHCamera disp34(geomcam, Form("%s%s","TimeOscillating",(fRuns->GetRunsAsFileName()).Data()),
288 "Oscillating Pixels");
289
290 // Fitted charge means and sigmas
291 disp1.SetCamContent(fCalibrationCam, 0);
292 disp1.SetCamError( fCalibrationCam, 1);
293 disp2.SetCamContent(fCalibrationCam, 2);
294 disp2.SetCamError( fCalibrationCam, 3);
295
296 // Reduced Sigmas and reduced sigmas per charge
297 disp3.SetCamContent(fCalibrationCam, 5);
298 disp3.SetCamError( fCalibrationCam, 6);
299 disp4.SetCamContent(fCalibrationCam, 7);
300 disp4.SetCamError( fCalibrationCam, 8);
301
302 // F-Factor Method
303 disp5.SetCamContent(fCalibrationCam, 9);
304 disp5.SetCamError( fCalibrationCam, 10);
305 disp6.SetCamContent(fCalibrationCam, 11);
306 disp6.SetCamError( fCalibrationCam, 12);
307 disp7.SetCamContent(fCalibrationCam, 13);
308 disp7.SetCamError( fCalibrationCam, 14);
309
310 // Quantum Efficiencies
311 disp8.SetCamContent (fQECam, 0 );
312 disp8.SetCamError (fQECam, 1 );
313 disp9.SetCamContent (fQECam, 2 );
314 disp9.SetCamError (fQECam, 3 );
315 disp10.SetCamContent(fQECam, 4 );
316 disp10.SetCamError (fQECam, 5 );
317 disp11.SetCamContent(fQECam, 6 );
318 disp11.SetCamError (fQECam, 7 );
319
320 // Valid flags
321 disp12.SetCamContent(fQECam, 8 );
322 disp13.SetCamContent(fQECam, 9 );
323 disp14.SetCamContent(fQECam, 10);
324 disp15.SetCamContent(fQECam, 11);
325
326 // Conversion Hi-Lo
327 disp16.SetCamContent(fCalibrationCam, 25);
328 disp17.SetCamContent(fCalibrationCam, 16);
329 disp17.SetCamError (fCalibrationCam, 17);
330 disp18.SetCamContent(fCalibrationCam, 18);
331 disp18.SetCamError (fCalibrationCam, 19);
332
333 // Pickup and Blackout
334 disp19.SetCamContent(fCalibrationCam, 21);
335 disp20.SetCamContent(fCalibrationCam, 22);
336 disp21.SetCamContent(fCalibrationCam, 23);
337 disp22.SetCamContent(fCalibrationCam, 24);
338
339 // Pixels with defects
340 disp23.SetCamContent(fCalibrationCam, 20);
341 disp24.SetCamContent(fBadPixels, 1);
342 disp25.SetCamContent(fBadPixels, 3);
343
344 // Oscillations
345 disp26.SetCamContent(fBadPixels, 10);
346 disp27.SetCamContent(fBadPixels, 11);
347
348 // Arrival Times
349 disp28.SetCamContent(fCalibrationCam, 26);
350 disp28.SetCamError( fCalibrationCam, 27);
351 disp29.SetCamContent(fCalibrationCam, 27);
352
353 disp1.SetYTitle("Q [FADC counts]");
354 disp2.SetYTitle("\\sigma_{Q} [FADC counts]");
355
356 disp3.SetYTitle("\\sqrt{\\sigma^{2}_{Q} - RMS^{2}_{Ped}} [FADC Counts]");
357 disp4.SetYTitle("Red.Sigma/<Q> [1]");
358
359 disp5.SetYTitle("Nr. Phe's [1]");
360 disp6.SetYTitle("Conv.Factor [PhE/FADC counts]");
361 disp7.SetYTitle("Total F-Factor [1]");
362
363 disp8.SetYTitle("QE [1]");
364 disp9.SetYTitle("QE [1]");
365 disp10.SetYTitle("QE [1]");
366 disp11.SetYTitle("QE [1]");
367
368 disp12.SetYTitle("[1]");
369 disp13.SetYTitle("[1]");
370 disp14.SetYTitle("[1]");
371 disp15.SetYTitle("[1]");
372 disp16.SetYTitle("[1]");
373
374 disp17.SetYTitle("<Q>(High)/<Q>(Low) [1]");
375 disp18.SetYTitle("\\sigma_{Q}(High)/\\sigma_{Q}(Low) [1]");
376
377 disp19.SetYTitle("[1]");
378 disp20.SetYTitle("[1]");
379 disp21.SetYTitle("[1]");
380 disp22.SetYTitle("[1]");
381 disp23.SetYTitle("[1]");
382 disp24.SetYTitle("[1]");
383 disp25.SetYTitle("[1]");
384 disp26.SetYTitle("[1]");
385 disp27.SetYTitle("[1]");
386
387 disp28.SetYTitle("Mean Abs. Time [FADC slice]");
388 disp29.SetYTitle("RMS Abs. Time [FADC slices]");
389
390 if (fRelTimes)
391 {
392
393 disp30.SetCamContent(fRelTimeCam,0);
394 disp30.SetCamError( fRelTimeCam,1);
395 disp31.SetCamContent(fRelTimeCam,2);
396 disp31.SetCamError( fRelTimeCam,3);
397 disp32.SetCamContent(fRelTimeCam,4);
398 disp33.SetCamContent(fBadPixels,20);
399 disp34.SetCamContent(fBadPixels,21);
400
401 disp30.SetYTitle("Time Offset [FADC units]");
402 disp31.SetYTitle("Timing resolution [FADC units]");
403 disp32.SetYTitle("P_{Time} [1]");
404 disp33.SetYTitle("[1]");
405 disp34.SetYTitle("[1]");
406 }
407
408 if (fDisplayType == kDataCheckDisplay)
409 {
410 TCanvas &c1 = fDisplay->AddTab("Fit.Charge");
411 c1.Divide(3, 3);
412
413 CamDraw(c1, 1, 3, disp1, 2);
414 CamDraw(c1, 2, 3, disp4, 2);
415 CamDraw(c1, 3, 3, disp28, 2);
416
417 // F-Factor
418 TCanvas &c2 = fDisplay->AddTab("Phe's");
419 c2.Divide(3,4);
420
421 CamDraw(c2, 1, 3, disp6, 2, 1);
422 CamDraw(c2, 2, 3, disp7, 2, 1);
423 CamDraw(c2, 3, 3, disp8, 2, 1);
424
425 // QE's
426 TCanvas &c3 = fDisplay->AddTab("QE's");
427 c3.Divide(3,4);
428
429 CamDraw(c3, 1, 3, disp8, 2, 1);
430 CamDraw(c3, 2, 3, disp9, 2, 1);
431 CamDraw(c3, 3, 3, disp10, 2, 1);
432
433 // Defects
434 TCanvas &c4 = fDisplay->AddTab("Defect");
435 // c4.Divide(3,2);
436 c4.Divide(2,2);
437
438 // CamDraw(c4, 1, 3, disp23, 0);
439 // CamDraw(c4, 2, 3, disp24, 0);
440 // CamDraw(c4, 3, 3, disp25, 0);
441 CamDraw(c4, 1, 2, disp24, 0);
442 CamDraw(c4, 2, 2, disp25, 0);
443
444 if (fRelTimes)
445 {
446 // Rel. Times
447 TCanvas &c5 = fDisplay->AddTab("Rel. Times");
448 c5.Divide(2,4);
449
450 CamDraw(c5, 1, 2, disp30, 2);
451 CamDraw(c5, 2, 2, disp31, 2);
452 }
453
454
455 return;
456 }
457
458 if (fDisplayType == kNormalDisplay)
459 {
460
461 // Charges
462 TCanvas &c11 = fDisplay->AddTab("Fit.Charge");
463 c11.Divide(2, 4);
464
465 CamDraw(c11, 1, 2, disp1, 5, 1);
466 CamDraw(c11, 2, 2, disp2, 5, 1);
467
468 // Reduced Sigmas
469 TCanvas &c12 = fDisplay->AddTab("Red.Sigma");
470 c12.Divide(2,4);
471
472 CamDraw(c12, 1, 2, disp3, 5, 1);
473 CamDraw(c12, 2, 2, disp4, 5, 1);
474
475 // F-Factor
476 TCanvas &c13 = fDisplay->AddTab("Phe's");
477 c13.Divide(3,4);
478
479 CamDraw(c13, 1, 3, disp5, 5, 1);
480 CamDraw(c13, 2, 3, disp6, 5, 1);
481 CamDraw(c13, 3, 3, disp7, 5, 1);
482
483 // QE's
484 TCanvas &c14 = fDisplay->AddTab("QE's");
485 c14.Divide(4,4);
486
487 CamDraw(c14, 1, 4, disp8, 5, 1);
488 CamDraw(c14, 2, 4, disp9, 5, 1);
489 CamDraw(c14, 3, 4, disp10, 5, 1);
490 CamDraw(c14, 4, 4, disp11, 5, 1);
491
492 // Defects
493 TCanvas &c15 = fDisplay->AddTab("Defect");
494 // c15.Divide(5,2);
495 c15.Divide(4,2);
496
497 /*
498 CamDraw(c15, 1, 5, disp23, 0);
499 CamDraw(c15, 2, 5, disp24, 0);
500 CamDraw(c15, 3, 5, disp25, 0);
501 CamDraw(c15, 4, 5, disp26, 0);
502 CamDraw(c15, 5, 5, disp27, 0);
503 */
504 CamDraw(c15, 1, 4, disp24, 0);
505 CamDraw(c15, 2, 4, disp25, 0);
506 CamDraw(c15, 3, 4, disp26, 0);
507 CamDraw(c15, 4, 4, disp27, 0);
508
509 // Abs. Times
510 TCanvas &c16 = fDisplay->AddTab("Abs. Times");
511 c16.Divide(2,3);
512
513 CamDraw(c16, 1, 2, disp28, 5);
514 CamDraw(c16, 2, 2, disp29, 5);
515
516 if (fRelTimes)
517 {
518 // Rel. Times
519 TCanvas &c17 = fDisplay->AddTab("Rel. Times");
520 c17.Divide(2,4);
521
522 CamDraw(c17, 1, 2, disp30, 5, 1);
523 CamDraw(c17, 2, 2, disp31, 5, 1);
524 }
525
526 return;
527 }
528
529 if (fDisplayType == kFullDisplay)
530 {
531
532 MHCalibrationChargeBlindPix *blind = (MHCalibrationChargeBlindPix*)plist.FindObject("MHCalibrationChargeBlindPix");
533 blind->DrawClone();
534 gPad->GetCanvas()->SaveAs(Form("%s%s%s",blind->GetName(),(fRuns->GetRunsAsString()).Data(),".root"));
535
536 MHCalibrationChargeCam *ccm = (MHCalibrationChargeCam*)plist.FindObject("MHCalibrationChargeCam");
537 ccm->DrawClone();
538 gPad->GetCanvas()->SaveAs(Form("%s%s%s",ccm->GetName(),(fRuns->GetRunsAsString()).Data(),".root"));
539
540 MHCalibrationRelTimeCam *rel = (MHCalibrationRelTimeCam*)plist.FindObject("MHCalibrationRelTimeCam");
541 rel->DrawClone();
542 gPad->GetCanvas()->SaveAs(Form("%s%s%s",rel->GetName(),(fRuns->GetRunsAsString()).Data(),".root"));
543
544 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationChargeCam");
545
546 for (Int_t aidx=0;aidx<cam->GetAverageAreas();aidx++)
547 {
548 cam->GetAverageHiGainArea(aidx).DrawClone("all");
549 cam->GetAverageLoGainArea(aidx).DrawClone("all");
550 }
551
552 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
553 {
554 cam->GetAverageHiGainSector(sector).DrawClone("all");
555 cam->GetAverageLoGainSector(sector).DrawClone("all");
556 }
557
558 // Charges
559 TCanvas &c21 = fDisplay->AddTab("Fit.Charge");
560 c21.Divide(2, 4);
561
562 CamDraw(c21, 1, 2, disp1, 2, 1);
563 CamDraw(c21, 2, 2, disp2, 2, 1);
564
565 // Reduced Sigmas
566 TCanvas &c23 = fDisplay->AddTab("Red.Sigma");
567 c23.Divide(2,4);
568
569 CamDraw(c23, 1, 2, disp3, 2, 1);
570 CamDraw(c23, 2, 2, disp4, 2, 1);
571
572 // F-Factor
573 TCanvas &c24 = fDisplay->AddTab("Phe's");
574 c24.Divide(3,4);
575
576 CamDraw(c24, 1, 3, disp5, 2, 1);
577 CamDraw(c24, 2, 3, disp6, 2, 1);
578 CamDraw(c24, 3, 3, disp7, 2, 1);
579
580 // QE's
581 TCanvas &c25 = fDisplay->AddTab("QE's");
582 c25.Divide(4,4);
583
584 CamDraw(c25, 1, 4, disp8, 2, 1);
585 CamDraw(c25, 2, 4, disp9, 2, 1);
586 CamDraw(c25, 3, 4, disp10, 2, 1);
587 CamDraw(c25, 4, 4, disp11, 2, 1);
588
589 // Validity
590 TCanvas &c26 = fDisplay->AddTab("Valid");
591 c26.Divide(4,2);
592
593 CamDraw(c26, 1, 4, disp12, 0);
594 CamDraw(c26, 2, 4, disp13, 0);
595 CamDraw(c26, 3, 4, disp14, 0);
596 CamDraw(c26, 4, 4, disp15, 0);
597
598 // Other info
599 TCanvas &c27 = fDisplay->AddTab("HiLoGain");
600 c27.Divide(3,3);
601
602 CamDraw(c27, 1, 3, disp16, 0);
603 CamDraw(c27, 2, 3, disp17, 1);
604 CamDraw(c27, 3, 3, disp18, 1);
605
606 // Pickup
607 TCanvas &c28 = fDisplay->AddTab("Pickup");
608 c28.Divide(4,2);
609
610 CamDraw(c28, 1, 4, disp19, 0);
611 CamDraw(c28, 2, 4, disp20, 0);
612 CamDraw(c28, 3, 4, disp21, 0);
613 CamDraw(c28, 4, 4, disp22, 0);
614
615 // Defects
616 TCanvas &c29 = fDisplay->AddTab("Defect");
617 // c29.Divide(5,2);
618 c29.Divide(4,2);
619
620 CamDraw(c29, 1, 4, disp24, 0);
621 CamDraw(c29, 2, 4, disp25, 0);
622 CamDraw(c29, 3, 4, disp26, 0);
623 CamDraw(c29, 4, 4, disp27, 0);
624
625 // Abs. Times
626 TCanvas &c30 = fDisplay->AddTab("Abs. Times");
627 c30.Divide(2,3);
628
629 CamDraw(c30, 1, 2, disp28, 2);
630 CamDraw(c30, 2, 2, disp29, 1);
631
632 if (fRelTimes)
633 {
634 // Rel. Times
635 TCanvas &c31 = fDisplay->AddTab("Rel. Times");
636 c31.Divide(3,4);
637
638 CamDraw(c31, 1, 3, disp30, 2, 1);
639 CamDraw(c31, 2, 3, disp31, 2, 1);
640 CamDraw(c31, 3, 3, disp32, 4, 1);
641
642 // Time Defects
643 TCanvas &c32 = fDisplay->AddTab("Time Def.");
644 c32.Divide(2,2);
645
646 CamDraw(c32, 1, 2, disp33,0);
647 CamDraw(c32, 2, 2, disp34,0);
648
649 MHCalibrationCam *cam = (MHCalibrationCam*)plist.FindObject("MHCalibrationRelTimeCam");
650
651 for (Int_t aidx=0;aidx<cam->GetAverageAreas();aidx++)
652 {
653 cam->GetAverageHiGainArea(aidx).DrawClone("fourierevents");
654 cam->GetAverageLoGainArea(aidx).DrawClone("fourierevents");
655 }
656
657 for (Int_t sector=1;sector<cam->GetAverageSectors();sector++)
658 {
659 cam->GetAverageHiGainSector(sector).DrawClone("fourierevents");
660 cam->GetAverageLoGainSector(sector).DrawClone("fourierevents");
661 }
662
663 }
664
665 return;
666 }
667}
668
669
670
671// --------------------------------------------------------------------------
672//
673// Find the colour of the pulsing LED:
674// - If the run number is smaller than gkIFAEBoxInaugurationRun, take MCalibrationCam::kCT1
675// - Otherwise find the colour out of the run name
676// - If no colour is found, return kFALSE
677//
678Bool_t MJCalibration::FindColor()
679{
680
681 const UInt_t nruns = fRuns->GetNumRuns();
682
683 if (nruns == 0)
684 return kFALSE;
685
686 TArrayI arr = fRuns->GetRuns();
687
688 if (arr[nruns-1] < gkIFAEBoxInaugurationRun)
689 {
690 *fLog << "Found colour kCT1 in runs: " << fRuns->GetRunsAsString() << endl;
691 fColor = MCalibrationCam::kCT1;
692 return kTRUE;
693 }
694
695 TString filenames;
696
697 while (!(filenames=((MDirIter*)fRuns)->Next()).IsNull())
698 {
699
700 filenames.ToLower();
701
702 //
703 // Here starts the list of runs where the shifters did not put
704 // a colour, but which have been found out by other means
705 //
706 if (filenames.Contains("_20660_"))
707 if (fColor == MCalibrationCam::kNONE)
708 {
709 *fLog << "Found colour: kGREEN in " << filenames << endl;
710 fColor = MCalibrationCam::kGREEN;
711 }
712 else if (fColor != MCalibrationCam::kGREEN)
713 {
714 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
715 return kFALSE;
716 }
717
718 if (filenames.Contains("_20661_"))
719 if (fColor == MCalibrationCam::kNONE)
720 {
721 *fLog << "Found colour: kGREEN in " << filenames << endl;
722 fColor = MCalibrationCam::kGREEN;
723 }
724 else if (fColor != MCalibrationCam::kGREEN)
725 {
726 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
727 return kFALSE;
728 }
729
730 //
731 // Here start the runs where the shifter put
732 // the colour
733 //
734 if (filenames.Contains("green"))
735 if (fColor == MCalibrationCam::kNONE)
736 {
737 *fLog << "Found colour: kGREEN in " << filenames << endl;
738 fColor = MCalibrationCam::kGREEN;
739 }
740 else if (fColor != MCalibrationCam::kGREEN)
741 {
742 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
743 return kFALSE;
744 }
745
746 if (filenames.Contains("blue"))
747 if (fColor == MCalibrationCam::kNONE)
748 {
749 *fLog << "Found colour: kBLUE in " << filenames << endl;
750 fColor = MCalibrationCam::kBLUE;
751 }
752 else if (fColor != MCalibrationCam::kBLUE)
753 {
754 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
755 return kFALSE;
756 }
757
758 if (filenames.Contains("uv"))
759 if (fColor == MCalibrationCam::kNONE)
760 {
761 *fLog << "Found colour: kUV in " << filenames << endl;
762 fColor = MCalibrationCam::kUV;
763 }
764 else if (fColor != MCalibrationCam::kUV)
765 {
766 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
767 return kFALSE;
768 }
769
770 if (filenames.Contains("ct1"))
771 if (fColor == MCalibrationCam::kNONE)
772 {
773 *fLog << "Found colour: kCT1 in " << filenames << endl;
774 fColor = MCalibrationCam::kCT1;
775 }
776 else if (fColor != MCalibrationCam::kCT1)
777 {
778 *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
779 return kFALSE;
780 }
781
782 }
783
784 if (fColor == MCalibrationCam::kNONE)
785 {
786 *fLog << "No colour found in filenames of runs: " << fRuns->GetRunsAsString()
787 << "... abort" << endl;
788 return kFALSE;
789 }
790
791 return kTRUE;
792}
793
794
795
796
797// --------------------------------------------------------------------------
798//
799// Retrieve the output file written by WriteResult()
800//
801const char* MJCalibration::GetOutputFile() const
802{
803
804 if (!fRuns)
805 return "";
806
807 return Form("%s/%s-F1.root", (const char*)fOutputPath, (const char*)fRuns->GetRunsAsFileName());
808}
809
810
811// --------------------------------------------------------------------------
812//
813// Call the ProcessFile(MPedestalCam)
814//
815Bool_t MJCalibration::Process(MPedestalCam &pedcam)
816{
817 if (!ReadCalibrationCam())
818 return ProcessFile(pedcam);
819
820 return kTRUE;
821}
822
823// --------------------------------------------------------------------------
824//
825// Execute the task list and the eventloop:
826//
827// - Check if there are fRuns, otherwise return
828// - Check the colour of the files in fRuns (FindColor()), otherwise return
829// - Check for consistency between run numbers and number of files
830// - Add fRuns to MReadMarsFile
831// - Put into MParList:
832// 1) MPedestalCam (pedcam)
833// 2) MCalibrationQECam (fQECam)
834// 3) MCalibrationChargeCam (fCalibrationCam)
835// 4) MCalibrationRelTimeCam (fRelTimeCam) (only if flag fRelTimes is chosen)
836// 5) MBadPixelsCam (fBadPixels)
837// 6) MCalibrationChargePINDiode
838// 7) MCalibrationChargeBlindPix
839// - Put into the MTaskList:
840// 1) MReadMarsFile
841// 2) MBadPixelsMerge
842// 3) MGeomApply
843// 4) MExtractor
844// 5) MExtractPINDiode
845// 6) MExtractBlindPixel
846// 7) MExtractTime (only if flag fRelTimes is chosen)
847// 8) MContinue(MFCosmics)
848// 9) MFillH("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode")
849// 10) MFillH("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel")
850// 11) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam")
851// 12) MFillH("MHCalibrationChargeCam", "MExtractedSignalCam")
852// 13) MCalibrationChargeCalc
853// 14) MFillH("MHCalibrationRelTimeCam", "MArrivalTimeCam") (only if flag fRelTimes is chosen)
854// 15) MCalibrationRelTimeCalc
855// - Execute MEvtLoop
856// - DisplayResult()
857// - WriteResult()
858//
859Bool_t MJCalibration::ProcessFile(MPedestalCam &pedcam)
860{
861 if (!fRuns)
862 {
863 *fLog << err << "No Runs choosen... abort." << endl;
864 return kFALSE;
865 }
866
867 if (fRuns->GetNumRuns() != fRuns->GetNumEntries())
868 {
869 *fLog << err << "Number of files found doesn't match number of runs... abort."
870 << fRuns->GetNumRuns() << " vs. " << fRuns->GetNumEntries() << endl;
871 return kFALSE;
872 }
873
874 *fLog << inf;
875 fLog->Separator(GetDescriptor());
876
877 if (!FindColor())
878 return kFALSE;
879
880 *fLog << "Calculate MCalibrationCam from Runs " << fRuns->GetRunsAsString() << endl;
881 *fLog << endl;
882
883 // Setup Tasklist
884 MParList plist;
885 MTaskList tlist;
886 plist.AddToList(&tlist);
887
888 MReadMarsFile read("Events");
889 MRawFileRead rawread("");
890
891 if (fDataCheck)
892 {
893// rawread.AddFiles(*fRuns);
894 tlist.AddToList(&rawread);
895 }
896 else
897 {
898 read.DisableAutoScheme();
899 static_cast<MRead&>(read).AddFiles(*fRuns);
900 tlist.AddToList(&read);
901 }
902
903 MCalibrationChargePINDiode pindiode;
904 MCalibrationChargeBlindPix blindpix;
905
906 plist.AddToList(&pedcam);
907 plist.AddToList(&fBadPixels);
908 plist.AddToList(&fQECam);
909 plist.AddToList(&fCalibrationCam);
910 plist.AddToList(&fRelTimeCam);
911 plist.AddToList(&pindiode);
912 plist.AddToList(&blindpix);
913
914 MGeomApply apply;
915 // MBadPixelsMerge merge(&fBadPixels);
916 MExtractPINDiode pinext;
917 MExtractBlindPixel blindext;
918 MExtractSlidingWindow extract2;
919 MExtractTimeSpline timespline;
920 MCalibrationChargeCalc calcalc;
921 calcalc.SetOutputPath(fOutputPath);
922 calcalc.SetOutputFile(Form("%s-ChargeCalibStat.txt",(const char*)fRuns->GetRunsAsFileName()));
923
924 MCalibrationRelTimeCalc timecalc;
925 timecalc.SetOutputPath(fOutputPath);
926 timecalc.SetOutputFile(Form("%s-TimeCalibStat.txt",(const char*)fRuns->GetRunsAsFileName()));
927
928 //
929 // As long as there are no DM's, have to colour by hand
930 //
931 calcalc.SetPulserColor(fColor);
932
933 MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
934 MFillH fillbnd("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
935 MFillH fillcam("MHCalibrationChargeCam", "MExtractedSignalCam");
936 MFillH filltme("MHCalibrationRelTimeCam", "MArrivalTimeCam");
937 fillpin.SetNameTab("PINDiode");
938 fillbnd.SetNameTab("BlindPix");
939 fillcam.SetNameTab("Charge");
940 filltme.SetNameTab("RelTimes");
941
942
943 //
944 // Apply a filter against cosmics
945 // (will have to be needed in the future
946 // when the calibration hardware-trigger is working)
947 //
948 MFCosmics cosmics;
949 MContinue cont(&cosmics);
950
951 // tlist.AddToList(&merge);
952 tlist.AddToList(&apply);
953
954 if (fExtractor)
955 tlist.AddToList(fExtractor);
956 else
957 {
958 *fLog << warn << GetDescriptor()
959 << ": No extractor has been chosen, take default MExtractSlidingWindow " << endl;
960 tlist.AddToList(&extract2);
961 }
962
963
964 tlist.AddToList(&pinext);
965 tlist.AddToList(&blindext);
966
967 if (fRelTimes)
968 {
969 if (fTimeExtractor)
970 tlist.AddToList(fTimeExtractor);
971 else
972 {
973 *fLog << warn << GetDescriptor()
974 << ": No extractor has been chosen, take default MTimeExtractSpline " << endl;
975 tlist.AddToList(&timespline);
976 }
977 }
978
979 if (fColor == MCalibrationCam::kCT1)
980 tlist.AddToList(&cont);
981
982 tlist.AddToList(&fillcam);
983 tlist.AddToList(&fillpin);
984 tlist.AddToList(&fillbnd);
985 tlist.AddToList(&calcalc);
986
987 if (fRelTimes)
988 {
989 tlist.AddToList(&filltme);
990 tlist.AddToList(&timecalc);
991 }
992
993
994 // Create and setup the eventloop
995 MEvtLoop evtloop(fName);
996 evtloop.SetParList(&plist);
997 evtloop.SetDisplay(fDisplay);
998 evtloop.SetLogStream(fLog);
999
1000 // Execute first analysis
1001 if (!evtloop.Eventloop())
1002 {
1003 *fLog << err << GetDescriptor() << ": Failed." << endl;
1004 return kFALSE;
1005 }
1006
1007 tlist.PrintStatistics();
1008
1009 DisplayResult(plist);
1010
1011 if (!WriteResult())
1012 return kFALSE;
1013
1014 *fLog << inf << GetDescriptor() << ": Done." << endl;
1015
1016 return kTRUE;
1017}
1018
1019// --------------------------------------------------------------------------
1020//
1021// Read the following containers from GetOutputFile()
1022// - MCalibrationChargeCam
1023// - MCalibrationQECam
1024// - MBadPixelsCam
1025//
1026Bool_t MJCalibration::ReadCalibrationCam()
1027{
1028 const TString fname = GetOutputFile();
1029
1030 if (gSystem->AccessPathName(fname, kFileExists))
1031 {
1032 *fLog << err << "Input file " << fname << " doesn't exist." << endl;
1033 return kFALSE;
1034 }
1035
1036 *fLog << inf << "Reading from file: " << fname << endl;
1037
1038 TFile file(fname, "READ");
1039 if (fCalibrationCam.Read()<=0)
1040 {
1041 *fLog << err << "Unable to read MCalibrationChargeCam from " << fname << endl;
1042 return kFALSE;
1043 }
1044
1045 if (fQECam.Read()<=0)
1046 {
1047 *fLog << err << "Unable to read MCalibrationQECam from " << fname << endl;
1048 return kFALSE;
1049 }
1050
1051 if (fRelTimeCam.Read()<=0)
1052 {
1053 *fLog << err << "Unable to read MCalibrationRelTimeCam from " << fname << endl;
1054 return kFALSE;
1055 }
1056
1057 if (file.FindKey("MBadPixelsCam"))
1058 {
1059 MBadPixelsCam bad;
1060 if (bad.Read()<=0)
1061 {
1062 *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
1063 return kFALSE;
1064 }
1065 fBadPixels.Merge(bad);
1066 }
1067
1068 if (fDisplay /*&& !fDisplay->GetCanvas("Pedestals")*/) // FIXME!
1069 fDisplay->Read();
1070
1071 return kTRUE;
1072}
1073
1074
1075// --------------------------------------------------------------------------
1076//
1077// Set the path for output files, written by WriteResult()
1078//
1079void MJCalibration::SetOutputPath(const char *path)
1080{
1081 fOutputPath = path;
1082 if (fOutputPath.EndsWith("/"))
1083 fOutputPath = fOutputPath(0, fOutputPath.Length()-1);
1084}
1085
1086
1087// --------------------------------------------------------------------------
1088//
1089// Write the result into the output file GetOutputFile(), if fOutputPath exists.
1090//
1091// The following containers are written:
1092// - MStatusDisplay
1093// - MCalibrationChargeCam
1094// - MCalibrationQECam
1095// - MBadPixelsCam
1096//
1097Bool_t MJCalibration::WriteResult()
1098{
1099 if (fOutputPath.IsNull())
1100 return kTRUE;
1101
1102 const TString oname(GetOutputFile());
1103
1104 *fLog << inf << "Writing to file: " << oname << endl;
1105
1106 TFile file(oname, "UPDATE");
1107
1108 if (fDisplay && fDisplay->Write()<=0)
1109 {
1110 *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
1111 return kFALSE;
1112 }
1113
1114 if (fCalibrationCam.Write()<=0)
1115 {
1116 *fLog << err << "Unable to write MCalibrationChargeCam to " << oname << endl;
1117 return kFALSE;
1118 }
1119
1120 if (fQECam.Write()<=0)
1121 {
1122 *fLog << err << "Unable to write MCalibrationQECam to " << oname << endl;
1123 return kFALSE;
1124 }
1125
1126 if (fRelTimes)
1127 if (fRelTimeCam.Write()<=0)
1128 {
1129 *fLog << err << "Unable to write MCalibrationQECam to " << oname << endl;
1130 return kFALSE;
1131 }
1132
1133 if (fBadPixels.Write()<=0)
1134 {
1135 *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
1136 return kFALSE;
1137 }
1138
1139 return kTRUE;
1140
1141}
1142
1143
1144
1145
1146
1147
1148
Note: See TracBrowser for help on using the repository browser.