source: trunk/MagicSoft/Mars/macros/calibration.C@ 3025

Last change on this file since 3025 was 3013, checked in by gaug, 21 years ago
*** empty log message ***
File size: 17.4 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): Markus Gaug, 11/2003 <mailto:markus@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25const TString pedfile = "/mnt/Data/rootdata/CrabNebula/2004_01_27/20040126_12149_P_Cab-On_E.root";
26const TString calfile = "/mnt/Data/rootdata/CrabNebula/2004_01_27/20040126_12525_C_Cab-On_E.root";
27
28//const TString pedfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03522_P_Park_E.root";
29//const TString calfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03527_C_Park_E.root";
30
31void calibration(TString pedname=pedfile,
32 TString calname=calfile)
33{
34
35 //
36 // Create a empty Parameter List and an empty Task List
37 // The tasklist is identified in the eventloop by its name
38 //
39 MParList plist;
40
41 MTaskList tlist;
42 plist.AddToList(&tlist);
43
44 //
45 // Now setup the tasks and tasklist for the pedestals:
46 // ---------------------------------------------------
47 //
48
49 MReadMarsFile read("Events", pedname);
50 read.DisableAutoScheme();
51
52 MGeomApply geomapl;
53 MExtractSignal2 sigcalc;
54 //
55 // We saw that the signal jumps between slices,
56 // thus set the extraction range as high as possible
57 // Sliding window will be implemented asap.
58 //
59 // sigcalc.SetRange(1,14,1,14);
60
61 MPedCalcPedRun pedcalc;
62 // MFillH fill("MPedestalCam", "MExtractedSignalCam");
63
64 tlist.AddToList(&read);
65 tlist.AddToList(&geomapl);
66 tlist.AddToList(&sigcalc);
67 tlist.AddToList(&pedcalc);
68 // tlist.AddToList(&fill);
69
70 MGeomCamMagic geomcam;
71 MPedestalCam pedcam;
72 plist.AddToList(&geomcam);
73 plist.AddToList(&pedcam);
74
75 //
76 // Create and setup the eventloop
77 //
78 MEvtLoop evtloop;
79 evtloop.SetParList(&plist);
80
81 //
82 // Execute first analysis
83 //
84 if (!evtloop.Eventloop())
85 return;
86
87 tlist.PrintStatistics();
88
89 // pedcam[17].DrawClone();
90
91 MStatusDisplay *d1 = new MStatusDisplay;
92 d1->SetUpdateTime(3000);
93 d1->Resize(850,700);
94
95 MHCamera dispped0 (geomcam, "MPedestalPix;Pedestal", "Mean per Slice");
96 MHCamera dispped1 (geomcam, "MPedestalPix;PedestalErr", "Mean Error per Slice");
97 MHCamera dispped2 (geomcam, "MPedestalPix;PedestalRms", "RMS per Slice");
98 MHCamera dispped3 (geomcam, "MPedestalPix;PedestalRmsErr", "RMS Error per Slice");
99 MHCamera dispped4 (geomcam, "MPedestalPix;Mean", "Fitted Mean per Slice");
100 MHCamera dispped5 (geomcam, "MPedestalPix;MeanErr", "Fitted Error of Mean per Slice");
101 MHCamera dispped6 (geomcam, "MPedestalPix;Sigma", "Fitted Sigma per Slice");
102 MHCamera dispped7 (geomcam, "MPedestalPix;SigmaErr", "Fitted Error of Sigma per Slice");
103 MHCamera dispped8 (geomcam, "MPedestalPix;Prob", "Probability of Fit");
104 MHCamera dispped9 (geomcam, "MPedestalPix;DeltaPedestalMean", "Rel. Diff. Mean per Slice (Calc.-Fitte)");
105 MHCamera dispped11 (geomcam, "MPedestalPix;DeltaPedestalMeanError", "Rel. Diff. Mean Error per Slice (Calc.-Fitted)");
106 MHCamera dispped12 (geomcam, "MPedestalPix;DeltaRmsSigma", "Rel. Diff. RMS per Slice (Calc.-Fitted)");
107 MHCamera dispped14 (geomcam, "MPedestalPix;DeltaRmsSigmaError", "Rel. Diff. RMS Error per Slice (Calc.-Fitted)");
108 dispped0.SetCamContent(pedcam, 0);
109 dispped0.SetCamError(pedcam, 1);
110 dispped1.SetCamContent(pedcam, 1);
111 dispped2.SetCamContent(pedcam, 2);
112 dispped2.SetCamError(pedcam,3);
113 dispped3.SetCamContent(pedcam, 3);
114 dispped4.SetCamContent(pedcam, 4);
115 dispped4.SetCamError(pedcam, 5);
116 dispped5.SetCamContent(pedcam, 5);
117 dispped6.SetCamContent(pedcam, 6);
118 dispped6.SetCamError(pedcam, 7);
119 dispped7.SetCamContent(pedcam, 7);
120 dispped8.SetCamContent(pedcam, 8);
121 dispped9.SetCamContent(pedcam, 9);
122 dispped9.SetCamError(pedcam, 10);
123 dispped11.SetCamContent(pedcam, 11);
124 dispped12.SetCamContent(pedcam, 12);
125 dispped12.SetCamError(pedcam, 13);
126 dispped14.SetCamContent(pedcam, 14);
127
128 dispped0.SetYTitle("Calc. Pedestal per slice [FADC counts]");
129 dispped1.SetYTitle("Calc. Pedestal Error per slice [FADC counts]");
130 dispped2.SetYTitle("Calc. Pedestal RMS per slice [FADC counts]");
131 dispped3.SetYTitle("Calc. Pedestal RMS Error per slice [FADC counts]");
132 dispped4.SetYTitle("Fitted Mean per slice [FADC counts]");
133 dispped5.SetYTitle("Error of Fitted Mean per slice [FADC counts]");
134 dispped6.SetYTitle("Fitted Sigma per slice [FADC counts]");
135 dispped7.SetYTitle("Error of Fitted Sigma per slice [FADC counts]");
136 dispped8.SetYTitle("Fit Probability [1]");
137 dispped9.SetYTitle("Rel. Diff. Pedestal Calc.-Fitted per slice [1]");
138 dispped11.SetYTitle("Rel. Diff. Pedestal Error Calc.-Fitted per slice [1]");
139 dispped12.SetYTitle("Rel. Diff. Pedestal RMS Calc.-Fitted per slice [1]");
140 dispped14.SetYTitle("Rel. Diff. Pedestal RMS Error Calc.-Fitted per slice [1]");
141
142 gStyle->SetOptStat(1111);
143 gStyle->SetOptFit();
144
145 // Histogram values
146 TCanvas &b1 = d1->AddTab("Direct Calculation");
147 b1.Divide(4,3);
148
149 CamDraw(b1,dispped0,pedcam,1,4,0);
150 CamDraw(b1,dispped1,pedcam,2,4,2);
151 CamDraw(b1,dispped2,pedcam,3,4,2);
152 CamDraw(b1,dispped3,pedcam,4,4,2);
153
154 // Fitted values
155 TCanvas &b2 = d1->AddTab("Fits");
156 b2.Divide(4,3);
157
158 CamDraw(b2,dispped4,pedcam,1,4,0);
159 CamDraw(b2,dispped5,pedcam,2,4,1);
160 CamDraw(b2,dispped6,pedcam,3,4,0);
161 CamDraw(b2,dispped7,pedcam,4,4,1);
162
163
164 // Fits Probability
165 TCanvas &b3 = d1->AddTab("Fit Probabilities");
166 b3.Divide(1,3);
167
168 CamDraw(b3,dispped8,pedcam,1,1,3);
169
170 // Differences
171 TCanvas &c4 = d1->AddTab("Relative Difference Calculation-Fits");
172 c4.Divide(4,3);
173
174 CamDraw(c4,dispped9,pedcam,1,4,1);
175 CamDraw(c4,dispped11,pedcam,2,4,1);
176 CamDraw(c4,dispped12,pedcam,3,4,1);
177 CamDraw(c4,dispped14,pedcam,4,4,1);
178
179 //
180 // Create a empty Parameter List and an empty Task List
181 //
182 MParList plist2;
183 MTaskList tlist2;
184 plist2.AddToList(&tlist2);
185
186 MExtractedSignalCam sigcam;
187 MCalibrationCam calcam;
188 //
189 // Get the previously created MPedestalCam into the new Parameter List
190 //
191 plist2.AddToList(&geomcam);
192 plist2.AddToList(&pedcam);
193 plist2.AddToList(&sigcam);
194 plist2.AddToList(&calcam);
195
196 //
197 // Get the MAGIC geometry
198 //
199 tlist2.AddToList(&geomapl);
200
201 //
202 // Now setup the new tasks and tasklist for the calibration
203 // ---------------------------------------------------
204 //
205
206 MReadMarsFile read2("Events", calname);
207 read2.DisableAutoScheme();
208
209 // MExtractSignal sigcalc;
210 MArrivalTimeCalc timecalc;
211 MCalibrationCalc calcalc;
212
213 //
214 // Making the step size a bit bigger, gives us
215 // faster results
216 //
217 timecalc.SetStepSize(0.05);
218
219 //
220 // As long, as we don't have digital modules,
221 // we have to set the color of the pulser LED by hand
222 //
223 calcalc.SetPulserColor(MCalibrationCalc::kECT1);
224
225 //
226 // In case, we want to exclude a pre-defined list of bad pixels:
227 // (This is a preliminary feature)
228 //
229 //calcalc.ExcludePixelsFromAsciiFile("badpixels_all.dat");
230
231 //
232 // In case, you want to skip the blind pixel method:
233 // (NOT RECOMMENDED!!!)
234 //
235 // calcalc.SkipBlindPixelFit();
236
237 //
238 // In case, you want to skip the cosmics rejection
239 // (NOT RECOMMENDED!!!)
240 //
241 // calcalc.SkipCosmicsRejection();
242
243 //
244 // In case, you want to skip the quality checks
245 // (NOT RECOMMENDED!!!)
246 //
247 // calcalc.SkipQualityChecks();
248
249 //
250 // In case, we want to apply another fit function to the
251 // blind pixel
252 //
253 MCalibrationBlindPix *bp = calcam.GetBlindPixel();
254// bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPolya);
255 // bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPoisson4);
256
257 tlist2.AddToList(&read2);
258 tlist2.AddToList(&sigcalc);
259 //
260 // In case, you want to skip the somewhat lengthy calculation
261 // of the arrival times using a spline, uncomment the next line
262 //
263 tlist2.AddToList(&timecalc);
264 tlist2.AddToList(&calcalc);
265
266 //
267 // Create and setup the eventloop
268 //
269 MEvtLoop evtloop2;
270 evtloop2.SetParList(&plist2);
271
272 //
273 // Execute second analysis
274 //
275 if (!evtloop2.Eventloop())
276 return;
277
278 tlist2.PrintStatistics();
279
280 //
281 // print the most important results of all pixels
282 //
283 calcam.Print();
284
285 //
286 // just one example how to get the plots of individual pixels
287 //
288 calcam[17].DrawClone();
289
290 MHCamera disp1 (geomcam, "MCalibrationPix;Charge", "Fitted Mean Charges");
291 MHCamera disp3 (geomcam, "MCalibrationPix;SigmaCharge", "Sigma of Fitted Charges");
292 MHCamera disp5 (geomcam, "MCalibrationPix;ChargeProb", "Probability of Fit");
293 MHCamera disp6 (geomcam, "MCalibrationPix;Time", "Rel. Arrival Times");
294 MHCamera disp7 (geomcam, "MCalibrationPix;SigmaTime", "Sigma of Rel. Arrival Times");
295 MHCamera disp8 (geomcam, "MCalibrationPix;TimeProb", "Probability of Time Fit");
296 MHCamera disp9 (geomcam, "MCalibrationPix;Ped", "Pedestals");
297 MHCamera disp10 (geomcam, "MCalibrationPix;PedRms", "Pedestal RMS");
298 MHCamera disp11 (geomcam, "MCalibrationPix;RSigma", "Reduced Sigmas");
299 MHCamera disp12 (geomcam, "MCalibrationPix;PheFFactorMethod", "Nr. of Phe's (F-Factor Method)");
300 MHCamera disp13 (geomcam, "MCalibrationPix;MeanConversionFFactorMethod",
301 "Conversion Factor (F-Factor Method)");
302 MHCamera disp14 (geomcam, "MCalibrationPix;MeanPhotInsidePlexiglass",
303 "Nr. of Photons (Blind Pixel Method)");
304 MHCamera disp15 (geomcam, "MCalibrationPix;MeanConversionBlindPixelMethod",
305 "Conversion Factor (Blind Pixel Method)");
306 MHCamera disp16 (geomcam, "MCalibrationPix;RSigma/Charge", "Reduced Sigma per Charge");
307 MHCamera disp17 (geomcam, "MCalibrationPix;AbsTimeMean", "Abs. Arrival Times");
308 MHCamera disp18 (geomcam, "MCalibrationPix;AbsTimeRms", "RMS of Arrival Times");
309
310 disp1.SetCamContent(calcam, 0);
311 disp1.SetCamError(calcam,1);
312
313 disp3.SetCamContent(calcam, 2);
314 disp3.SetCamError(calcam,3);
315
316 disp5.SetCamContent(calcam, 4);
317
318 disp6.SetCamContent(calcam, 5);
319 disp6.SetCamError(calcam, 6);
320 disp7.SetCamContent(calcam, 6);
321 disp8.SetCamContent(calcam, 7);
322
323 disp9.SetCamContent(calcam, 8);
324 disp9.SetCamError(calcam, 9);
325
326 disp10.SetCamContent(calcam, 9);
327 disp11.SetCamContent(calcam, 10);
328
329 disp12.SetCamContent(calcam, 11);
330 disp12.SetCamError(calcam, 12);
331
332 disp13.SetCamContent(calcam, 13);
333 disp13.SetCamError(calcam, 14);
334
335 disp14.SetCamContent(calcam, 15);
336 disp15.SetCamContent(calcam, 16);
337 disp16.SetCamContent(calcam, 17);
338
339 disp17.SetCamContent(calcam, 18);
340 disp17.SetCamError(calcam, 19);
341 disp18.SetCamContent(calcam, 20);
342 disp18.SetCamError(calcam, 21);
343
344 disp1.SetYTitle("Charge [FADC counts]");
345 disp3.SetYTitle("\\sigma_{Charge} [FADC counts]");
346 disp5.SetYTitle("P_{Charge} [1]");
347 disp6.SetYTitle("Rel. Arr. Time [ns]");
348 disp7.SetYTitle("\\sigma_{Time} [ns]");
349 disp8.SetYTitle("P_{Time} [1]");
350 disp9.SetYTitle("Ped [FADC Counts ]");
351 disp10.SetYTitle("RMS_{Ped} [FADC Counts ]");
352 disp11.SetYTitle("\\sqrt{\\sigma^{2}_{Charge} - RMS^{2}_{Ped}} [FADC Counts]");
353 disp12.SetYTitle("Nr. Photo-Electrons [1]");
354 disp13.SetYTitle("Conversion Factor [PhE/FADC Count]");
355 disp14.SetYTitle("Nr. Photons [1]");
356 disp15.SetYTitle("Conversion Factor [Phot/FADC Count]");
357 disp16.SetYTitle("Reduced Sigma / Charge [1]");
358 disp17.SetYTitle("Mean Abs. Time [FADC slice]");
359 disp18.SetYTitle("RMS Abs. Time [FADC slices]");
360
361 MStatusDisplay *d3 = new MStatusDisplay;
362 d3->SetUpdateTime(3000);
363 d3->Resize(850,700);
364
365 gStyle->SetOptStat(1111);
366 gStyle->SetOptFit();
367
368 // Charges
369 TCanvas &c1 = d3->AddTab("Fitted Charges");
370 c1.Divide(2,3);
371
372 CamDraw(c1,disp1,calcam,1,2,1);
373 CamDraw(c1,disp3,calcam,2,2,1);
374
375 // Fit Probability
376 TCanvas &c2 = d3->AddTab("Fit Prob.");
377 c2.Divide(1,3);
378
379 CamDraw(c2,disp5,calcam,1,1,3);
380
381 // Rel. Times
382 TCanvas &c3 = d3->AddTab("Fitted Rel. Times");
383 c3.Divide(3,3);
384
385 CamDraw(c3,disp6,calcam,1,3,1);
386 CamDraw(c3,disp7,calcam,2,3,1);
387 CamDraw(c3,disp8,calcam,3,3,0);
388
389 // Abs. Times
390 TCanvas &c35 = d3->AddTab("Abs. Times");
391 c35.Divide(2,3);
392
393 CamDraw(c35,disp17,calcam,1,2,1);
394 CamDraw(c35,disp18,calcam,2,2,1);
395
396 // Pedestals
397 TCanvas &c4 = d3->AddTab("Pedestals");
398 c4.Divide(2,3);
399
400 CamDraw(c4,disp9,calcam,1,2,0);
401 CamDraw(c4,disp10,calcam,2,2,1);
402
403 // Reduced Sigmas
404 TCanvas &c5 = d3->AddTab("Reduced Sigmas");
405 c5.Divide(2,3);
406
407 // CamDraw(c5,disp11,calcam,1,2,1);
408 CamDraw(c5,disp11,calcam,1,2,2);
409 CamDraw(c5,disp16,calcam,2,2,1);
410
411 // F-Factor Method
412 TCanvas &c6 = d3->AddTab("F-Factor Method");
413 c6.Divide(2,3);
414
415 CamDraw(c6,disp12,calcam,1,2,1);
416 CamDraw(c6,disp13,calcam,2,2,1);
417
418 // Blind Pixel Method
419 TCanvas &c7 = d3->AddTab("Blind Pixel Method");
420 c7.Divide(2, 3);
421
422 CamDraw(c7,disp14,calcam,1,2,9);
423 CamDraw(c7,disp15,calcam,2,2,1);
424
425}
426
427void CamDraw(TCanvas &c, MHCamera &cam, MCamEvent &evt, Int_t i, Int_t j, Int_t fit)
428{
429
430 c.cd(i);
431 gPad->SetBorderMode(0);
432 MHCamera *obj1=(MHCamera*)cam.DrawCopy("hist");
433 obj1->AddNotify(evt);
434
435 c.cd(i+j);
436 gPad->SetBorderMode(0);
437 obj1->Draw();
438 ((MHCamera*)obj1)->SetPrettyPalette();
439
440 c.cd(i+2*j);
441 gPad->SetBorderMode(0);
442 TH1D *obj2 = (TH1D*)obj1->Projection();
443 obj2->Draw();
444 obj2->SetBit(kCanDelete);
445
446 const Double_t min = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
447 const Double_t max = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
448 const Double_t integ = obj2->Integral("width")/2.5066283;
449 const Double_t mean = obj2->GetMean();
450 const Double_t rms = obj2->GetRMS();
451 const Double_t width = max-min;
452
453 if (rms == 0. || width == 0. )
454 return;
455
456 switch (fit)
457 {
458 case 0:
459 TF1 *sgaus = new TF1("sgaus","gaus(0)",min,max);
460 sgaus->SetBit(kCanDelete);
461 sgaus->SetParNames("Area","#mu","#sigma");
462 sgaus->SetParameters(integ/rms,mean,rms);
463 sgaus->SetParLimits(0,0.,integ);
464 sgaus->SetParLimits(1,min,max);
465 sgaus->SetParLimits(2,0,width/1.5);
466 obj2->Fit("sgaus","QLR");
467 obj2->GetFunction("sgaus")->SetLineColor(kYellow);
468 break;
469
470 case 1:
471 TString dgausform = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
472 dgausform += "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
473 TF1 *dgaus = new TF1("dgaus",dgausform.Data(),min,max);
474 dgaus->SetBit(kCanDelete);
475 dgaus->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}","A_{2}","#mu_{2}","#sigma_{2}");
476 dgaus->SetParameters(integ,(min+mean)/2.,width/4.,
477 integ/width/2.,(max+mean)/2.,width/4.);
478 // The left-sided Gauss
479 dgaus->SetParLimits(0,integ-1.5,integ+1.5);
480 dgaus->SetParLimits(1,min+(width/10.),mean);
481 dgaus->SetParLimits(2,0,width/2.);
482 // The right-sided Gauss
483 dgaus->SetParLimits(3,0,integ);
484 dgaus->SetParLimits(4,mean,max-(width/10.));
485 dgaus->SetParLimits(5,0,width/2.);
486 obj2->Fit("dgaus","QLRM");
487 obj2->GetFunction("dgaus")->SetLineColor(kYellow);
488 break;
489
490 case 2:
491 TString tgausform = "([0]-[3]-[6])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
492 tgausform += "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
493 tgausform += "+[6]/[8]*exp(-0.5*(x-[7])*(x-[7])/[8]/[8])";
494 TF1 *tgaus = new TF1("tgaus",tgausform.Data(),min,max);
495 tgaus->SetBit(kCanDelete);
496 tgaus->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}",
497 "A_{2}","#mu_{2}","#sigma_{2}",
498 "A_{3}","#mu_{3}","#sigma_{3}");
499 tgaus->SetParameters(integ,(min+mean)/2,width/4.,
500 integ/width/3.,(max+mean)/2.,width/4.,
501 integ/width/3.,mean,width/2.);
502 // The left-sided Gauss
503 tgaus->SetParLimits(0,integ-1.5,integ+1.5);
504 tgaus->SetParLimits(1,min+(width/10.),mean);
505 tgaus->SetParLimits(2,width/15.,width/2.);
506 // The right-sided Gauss
507 tgaus->SetParLimits(3,0.,integ);
508 tgaus->SetParLimits(4,mean,max-(width/10.));
509 tgaus->SetParLimits(5,width/15.,width/2.);
510 // The Gauss describing the outliers
511 tgaus->SetParLimits(6,0.,integ);
512 tgaus->SetParLimits(7,min,max);
513 tgaus->SetParLimits(8,width/4.,width/1.5);
514 obj2->Fit("tgaus","QLRM");
515 obj2->GetFunction("tgaus")->SetLineColor(kYellow);
516 break;
517 case 3:
518 obj2->Fit("pol0","Q");
519 obj2->GetFunction("pol0")->SetLineColor(kYellow);
520 break;
521 case 9:
522 break;
523 default:
524 obj2->Fit("gaus","Q");
525 obj2->GetFunction("gaus")->SetLineColor(kYellow);
526 break;
527 }
528
529}
Note: See TracBrowser for help on using the repository browser.