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

Last change on this file since 3007 was 3007, checked in by gaug, 21 years ago
*** empty log message ***
File size: 16.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): 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 MExtractSignal 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 pedcalc.SetUseHists();
63
64 tlist.AddToList(&read);
65 tlist.AddToList(&geomapl);
66 tlist.AddToList(&sigcalc);
67 tlist.AddToList(&pedcalc);
68
69 MGeomCamMagic geomcam;
70 MPedestalCam pedcam;
71 plist.AddToList(&geomcam);
72 plist.AddToList(&pedcam);
73
74 //
75 // Create and setup the eventloop
76 //
77 MEvtLoop evtloop;
78 evtloop.SetParList(&plist);
79
80 //
81 // Execute first analysis
82 //
83 if (!evtloop.Eventloop())
84 return;
85
86 tlist.PrintStatistics();
87
88 pedcam[17].DrawClone();
89
90 MStatusDisplay *d1 = new MStatusDisplay;
91 d1->SetUpdateTime(3000);
92 d1->Resize(850,700);
93
94 MHCamera dispped0 (geomcam, "MPedestalPix;Pedestal", "Mean per Slice");
95 MHCamera dispped1 (geomcam, "MPedestalPix;PedestalErr", "Mean Error per Slice");
96 MHCamera dispped2 (geomcam, "MPedestalPix;PedestalRms", "RMS per Slice");
97 MHCamera dispped3 (geomcam, "MPedestalPix;PedestalRmsErr", "RMS Error per Slice");
98 MHCamera dispped4 (geomcam, "MPedestalPix;Mean", "Fitted Mean per Slice");
99 MHCamera dispped5 (geomcam, "MPedestalPix;MeanErr", "Fitted Error of Mean per Slice");
100 MHCamera dispped6 (geomcam, "MPedestalPix;Sigma", "Fitted Sigma per Slice");
101 MHCamera dispped7 (geomcam, "MPedestalPix;SigmaErr", "Fitted Error of Sigma per Slice");
102 MHCamera dispped8 (geomcam, "MPedestalPix;Prob", "Probability of Fit");
103 MHCamera dispped9 (geomcam, "MPedestalPix;DeltaPedestalMean", "Rel. Diff. Mean per Slice (Calc.-Fitte)");
104 MHCamera dispped11 (geomcam, "MPedestalPix;DeltaPedestalMeanError", "Rel. Diff. Mean Error per Slice (Calc.-Fitted)");
105 MHCamera dispped12 (geomcam, "MPedestalPix;DeltaRmsSigma", "Rel. Diff. RMS per Slice (Calc.-Fitted)");
106 MHCamera dispped14 (geomcam, "MPedestalPix;DeltaRmsSigmaError", "Rel. Diff. RMS Error per Slice (Calc.-Fitted)");
107
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.02);
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
308 disp1.SetCamContent(calcam, 0);
309 disp1.SetCamError(calcam,1);
310
311 disp3.SetCamContent(calcam, 2);
312 disp3.SetCamError(calcam,3);
313
314 disp5.SetCamContent(calcam, 4);
315
316 disp6.SetCamContent(calcam, 5);
317 disp6.SetCamError(calcam, 6);
318 disp7.SetCamContent(calcam, 6);
319 disp8.SetCamContent(calcam, 7);
320
321 disp9.SetCamContent(calcam, 8);
322 disp9.SetCamError(calcam, 9);
323
324 disp10.SetCamContent(calcam, 9);
325 disp11.SetCamContent(calcam, 10);
326
327 disp12.SetCamContent(calcam, 11);
328 disp12.SetCamError(calcam, 12);
329
330 disp13.SetCamContent(calcam, 13);
331 disp13.SetCamError(calcam, 14);
332
333 disp14.SetCamContent(calcam, 15);
334 disp15.SetCamContent(calcam, 16);
335 disp16.SetCamContent(calcam, 17);
336
337
338 disp1.SetYTitle("Charge [FADC counts]");
339 disp3.SetYTitle("\\sigma_{Charge} [FADC counts]");
340 disp5.SetYTitle("P_{Charge} [1]");
341 disp6.SetYTitle("Arr. Time [ns]");
342 disp7.SetYTitle("\\sigma_{Time} [ns]");
343 disp8.SetYTitle("P_{Time} [1]");
344 disp9.SetYTitle("Ped [FADC Counts ]");
345 disp10.SetYTitle("RMS_{Ped} [FADC Counts ]");
346 disp11.SetYTitle("\\sqrt{\\sigma^{2}_{Charge} - RMS^{2}_{Ped}} [FADC Counts]");
347 disp12.SetYTitle("Nr. Photo-Electrons [1]");
348 disp13.SetYTitle("Conversion Factor [PhE/FADC Count]");
349 disp14.SetYTitle("Nr. Photons [1]");
350 disp15.SetYTitle("Conversion Factor [Phot/FADC Count]");
351 disp16.SetYTitle("Reduced Sigma / Charge [1]");
352
353 MStatusDisplay *d3 = new MStatusDisplay;
354 d3->SetUpdateTime(3000);
355 d3->Resize(850,700);
356
357 gStyle->SetOptStat(1111);
358 gStyle->SetOptFit();
359
360 // Charges
361 TCanvas &c1 = d3->AddTab("Fitted Charges");
362 c1.Divide(2,3);
363
364 CamDraw(c1,disp1,calcam,1,2,1);
365 CamDraw(c1,disp3,calcam,2,2,1);
366
367 // Fit Probability
368 TCanvas &c2 = d3->AddTab("Fit Prob.");
369 c2.Divide(1,3);
370
371 CamDraw(c2,disp5,calcam,1,1,3);
372
373 // Times
374 TCanvas &c3 = d3->AddTab("Fitted Rel. Times");
375 c3.Divide(3,3);
376
377 CamDraw(c3,disp6,calcam,1,3,1);
378 CamDraw(c3,disp7,calcam,2,3,1);
379 CamDraw(c3,disp8,calcam,3,3,0);
380
381 // Pedestals
382 TCanvas &c4 = d3->AddTab("Pedestals");
383 c4.Divide(2,3);
384
385 CamDraw(c4,disp9,calcam,1,2,0);
386 CamDraw(c4,disp10,calcam,2,2,1);
387
388 // Reduced Sigmas
389 TCanvas &c5 = d3->AddTab("Reduced Sigmas");
390 c5.Divide(2,3);
391
392 // CamDraw(c5,disp11,calcam,1,2,1);
393 CamDraw(c5,disp11,calcam,1,2,2);
394 CamDraw(c5,disp16,calcam,2,2,1);
395
396 // F-Factor Method
397 TCanvas &c6 = d3->AddTab("F-Factor Method");
398 c6.Divide(2,3);
399
400 CamDraw(c6,disp12,calcam,1,2,1);
401 CamDraw(c6,disp13,calcam,2,2,1);
402
403 // Blind Pixel Method
404 TCanvas &c7 = d3->AddTab("Blind Pixel Method");
405 c7.Divide(2, 3);
406
407 CamDraw(c7,disp14,calcam,1,2,9);
408 CamDraw(c7,disp15,calcam,2,2,1);
409
410}
411
412void CamDraw(TCanvas &c, MHCamera &cam, MCamEvent &evt, Int_t i, Int_t j, Int_t fit)
413{
414
415 c.cd(i);
416 gPad->SetBorderMode(0);
417 MHCamera *obj1=(MHCamera*)cam.DrawCopy("hist");
418 obj1->AddNotify(evt);
419
420 c.cd(i+j);
421 gPad->SetBorderMode(0);
422 obj1->Draw();
423 ((MHCamera*)obj1)->SetPrettyPalette();
424
425 c.cd(i+2*j);
426 gPad->SetBorderMode(0);
427 TH1D *obj2 = (TH1D*)obj1->Projection();
428 obj2->Draw();
429 obj2->SetBit(kCanDelete);
430
431 const Double_t min = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
432 const Double_t max = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
433 const Double_t integ = obj2->Integral("width")/2.5066283;
434 const Double_t mean = obj2->GetMean();
435 const Double_t rms = obj2->GetRMS();
436 const Double_t width = max-min;
437
438 if (rms == 0. || width == 0. )
439 return;
440
441 switch (fit)
442 {
443 case 0:
444 TF1 *sgaus = new TF1("sgaus","gaus(0)",min,max);
445 sgaus->SetBit(kCanDelete);
446 sgaus->SetParNames("Area","#mu","#sigma");
447 sgaus->SetParameters(integ/rms,mean,rms);
448 sgaus->SetParLimits(0,0.,integ);
449 sgaus->SetParLimits(1,min,max);
450 sgaus->SetParLimits(2,0,width/1.5);
451 obj2->Fit("sgaus","QLR");
452 obj2->GetFunction("sgaus")->SetLineColor(kYellow);
453 break;
454
455 case 1:
456 TString dgausform = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
457 dgausform += "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
458 TF1 *dgaus = new TF1("dgaus",dgausform.Data(),min,max);
459 dgaus->SetBit(kCanDelete);
460 dgaus->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}","A_{2}","#mu_{2}","#sigma_{2}");
461 dgaus->SetParameters(integ,(min+mean)/2.,width/4.,
462 integ/width/2.,(max+mean)/2.,width/4.);
463 // The left-sided Gauss
464 dgaus->SetParLimits(0,integ-1.5,integ+1.5);
465 dgaus->SetParLimits(1,min+(width/10.),mean);
466 dgaus->SetParLimits(2,0,width/2.);
467 // The right-sided Gauss
468 dgaus->SetParLimits(3,0,integ);
469 dgaus->SetParLimits(4,mean,max-(width/10.));
470 dgaus->SetParLimits(5,0,width/2.);
471 obj2->Fit("dgaus","QLRM");
472 obj2->GetFunction("dgaus")->SetLineColor(kYellow);
473 break;
474
475 case 2:
476 TString tgausform = "([0]-[3]-[6])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])";
477 tgausform += "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])";
478 tgausform += "+[6]/[8]*exp(-0.5*(x-[7])*(x-[7])/[8]/[8])";
479 TF1 *tgaus = new TF1("tgaus",tgausform.Data(),min,max);
480 tgaus->SetBit(kCanDelete);
481 tgaus->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}",
482 "A_{2}","#mu_{2}","#sigma_{2}",
483 "A_{3}","#mu_{3}","#sigma_{3}");
484 tgaus->SetParameters(integ,(min+mean)/2,width/4.,
485 integ/width/3.,(max+mean)/2.,width/4.,
486 integ/width/3.,mean,width/2.);
487 // The left-sided Gauss
488 tgaus->SetParLimits(0,integ-1.5,integ+1.5);
489 tgaus->SetParLimits(1,min+(width/10.),mean);
490 tgaus->SetParLimits(2,width/15.,width/2.);
491 // The right-sided Gauss
492 tgaus->SetParLimits(3,0.,integ);
493 tgaus->SetParLimits(4,mean,max-(width/10.));
494 tgaus->SetParLimits(5,width/15.,width/2.);
495 // The Gauss describing the outliers
496 tgaus->SetParLimits(6,0.,integ);
497 tgaus->SetParLimits(7,min,max);
498 tgaus->SetParLimits(8,width/4.,width/1.5);
499 obj2->Fit("tgaus","QLRM");
500 obj2->GetFunction("tgaus")->SetLineColor(kYellow);
501 break;
502 case 3:
503 obj2->Fit("pol0","Q");
504 obj2->GetFunction("pol0")->SetLineColor(kYellow);
505 break;
506 case 9:
507 break;
508 default:
509 obj2->Fit("gaus","Q");
510 obj2->GetFunction("gaus")->SetLineColor(kYellow);
511 break;
512 }
513
514}
Note: See TracBrowser for help on using the repository browser.