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

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