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

Last change on this file since 2895 was 2877, checked in by gaug, 21 years ago
*** empty log message ***
File size: 11.3 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
25// const TString pedfile = "/mnt/Data/rootdata/DarkPatch4/2003_11_27/20031126_03030_P_DarkPatch4_E.root";
26// const TString calfile = "/mnt/Data/rootdata/DarkPatch4/2004_01_17/20040116_*_C_DarkPatch2_E.root";
27
28const TString pedfile = "/mnt/Data/rootdata/Miscellaneous/2003_12_19/20031218_03522_P_Park_E.root";
29const 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 MPedCalcPedRun pedcalc;
54 MGeomCamMagic geomcam;
55 MPedestalCam pedcam;
56
57 tlist.AddToList(&read);
58 tlist.AddToList(&geomapl);
59 tlist.AddToList(&pedcalc);
60
61 plist.AddToList(&pedcam);
62
63 MHCamEvent hist("Pedestal");
64 hist.SetType(1);
65 plist.AddToList(&hist);
66 MFillH fill(&hist, "MPedestalCam");
67
68 tlist.AddToList(&fill);
69
70 MStatusDisplay *d1 = new MStatusDisplay;
71
72 //Set update time to 3s
73 d1->SetUpdateTime(3000);
74
75 //
76 // Create and setup the eventloop
77 //
78 MEvtLoop evtloop;
79 evtloop.SetParList(&plist);
80 evtloop.SetDisplay(d1);
81
82 //
83 // Execute first analysis
84 //
85 if (!evtloop.Eventloop())
86 return;
87
88 tlist.PrintStatistics();
89
90 //
91 // Create a empty Parameter List and an empty Task List
92 //
93 MParList plist2;
94 MTaskList tlist2;
95 plist2.AddToList(&tlist2);
96
97 MExtractedSignalCam sigcam;
98 MCalibrationCam calcam;
99 //
100 // Get the previously created MPedestalCam into the new Parameter List
101 //
102 plist2.AddToList(&pedcam);
103 plist2.AddToList(&sigcam);
104 plist2.AddToList(&calcam);
105
106 //
107 // Get the MAGIC geometry
108 //
109 tlist2.AddToList(&geomapl);
110 plist2.AddToList(&geomcam);
111
112 //
113 // Now setup the new tasks and tasklist for the calibration
114 // ---------------------------------------------------
115 //
116
117 MReadMarsFile read2("Events", calname);
118 read2.DisableAutoScheme();
119
120 MExtractSignal sigsig;
121 MCalibrationCalc calcalc;
122
123 //
124 // In case, we want to exclude a pre-defined list of bad pixels:
125 // (This is a preliminary feature)
126 //
127 // calcalc.ExcludePixelsFromAsciiFile("badpixels.dat");
128
129 //
130 // As long, as we don't have digital modules,
131 // we have to set the color of the pulser LED by hand
132 //
133 calcalc.SetPulserColor(MCalibrationCalc::kECT1);
134
135 //
136 // In case, we want to apply another fit function to the
137 // blind pixel
138 //
139 MCalibrationBlindPix *bp = calcam.GetBlindPixel();
140 bp->ChangeFitFunc(MHCalibrationBlindPixel::kEPoisson5);
141
142 tlist2.AddToList(&read2);
143 tlist2.AddToList(&sigsig);
144 tlist2.AddToList(&calcalc);
145
146 //
147 // Create and setup the eventloop
148 //
149 MEvtLoop evtloop2;
150 evtloop2.SetParList(&plist2);
151
152 //
153 // Execute second analysis
154 //
155 if (!evtloop2.Eventloop())
156 return;
157
158 tlist2.PrintStatistics();
159
160 //
161 // just one example how to get the plots of individual pixels
162 //
163 MCalibrationCam *cam = plist2.FindObject("MCalibrationCam");
164 cam.Print();
165
166 MHCamEvent camevt;
167 MHCamera disp1 (geomcam, "MCalibrationPix;Charge", "Fitted Mean Charges");
168 MHCamera disp3 (geomcam, "MCalibrationPix;SigmaCharge", "Sigma of Fitted Charges");
169 MHCamera disp5 (geomcam, "MCalibrationPix;ChargeProb", "Probability of Fit");
170 MHCamera disp6 (geomcam, "MCalibrationPix;Time", "Arrival Times");
171 MHCamera disp7 (geomcam, "MCalibrationPix;SigmaTime", "Sigma of Arrival Times");
172 MHCamera disp8 (geomcam, "MCalibrationPix;TimeChiSquare", "Chi Square of Time Fit");
173 MHCamera disp9 (geomcam, "MCalibrationPix;Ped", "Pedestals");
174 MHCamera disp10 (geomcam, "MCalibrationPix;PedRms", "Pedestal RMS");
175 MHCamera disp11 (geomcam, "MCalibrationPix;RSigma", "Reduced Sigmas");
176 MHCamera disp12 (geomcam, "MCalibrationPix;PheFFactorMethod", "Nr. of Phe's (F-Factor Method)");
177 MHCamera disp13 (geomcam, "MCalibrationPix;MeanConversionFFactorMethod",
178 "Conversion Factor (F-Factor Method)");
179 MHCamera disp14 (geomcam, "MCalibrationPix;MeanPhotInsidePlexiglass",
180 "Nr. of Photons (Blind Pixel Method)");
181 MHCamera disp15 (geomcam, "MCalibrationPix;MeanConversionBlindPixelMethod",
182 "Conversion Factor (Blind Pixel Method)");
183 MHCamera disp16 (geomcam, "MCalibrationPix;RSigma/Charge", "Reduced Sigma per Charge");
184
185 disp1.SetCamContent(*cam, 0);
186 disp1.SetCamError(*cam,1);
187
188 disp3.SetCamContent(*cam, 2);
189 disp3.SetCamError(*cam,3);
190
191 disp5.SetCamContent(*cam, 4);
192
193 disp6.SetCamContent(*cam, 5);
194 disp6.SetCamError(*cam, 6);
195 disp7.SetCamContent(*cam, 6);
196 disp8.SetCamContent(*cam, 7);
197
198 disp9.SetCamContent(*cam, 8);
199 disp9.SetCamError(*cam, 9);
200
201 disp10.SetCamContent(*cam, 9);
202 disp11.SetCamContent(*cam, 10);
203
204 disp12.SetCamContent(*cam, 11);
205 disp12.SetCamError(*cam, 12);
206
207 disp13.SetCamContent(*cam, 13);
208 disp13.SetCamError(*cam, 14);
209
210 disp14.SetCamContent(*cam, 15);
211 disp15.SetCamContent(*cam, 16);
212 disp16.SetCamContent(*cam, 17);
213
214
215 disp1.SetYTitle("Charge [FADC counts]");
216 disp3.SetYTitle("\\sigma_{Charge} [FADC counts]");
217 disp5.SetYTitle("P_{Charge} [1]");
218 disp6.SetYTitle("Arr. Time [Time Slice Nr.]");
219 disp7.SetYTitle("\\sigma_{Time} [Time Slices]");
220 disp8.SetYTitle("\\chi^{2}_{Time} [1]");
221 disp9.SetYTitle("Ped [FADC Counts ]");
222 disp10.SetYTitle("RMS_{Ped} [FADC Counts ]");
223 disp11.SetYTitle("\\sqrt{\\sigma^{2}_{Charge} - RMS^{2}_{Ped}} [FADC Counts]");
224 disp12.SetYTitle("Nr. Photo-Electrons [1]");
225 disp13.SetYTitle("Conversion Factor [PhE/FADC Count]");
226 disp14.SetYTitle("Nr. Photons [1]");
227 disp15.SetYTitle("Conversion Factor [Phot/FADC Count]");
228 disp16.SetYTitle("Reduced Sigma / Charge [1]");
229
230 MStatusDisplay *d3 = new MStatusDisplay;
231 d3->SetUpdateTime(3000);
232 d3->Resize(850,700);
233
234 gStyle->SetOptStat(1111);
235 gStyle->SetOptFit();
236
237 // Charges
238 TCanvas &c1 = d3->AddTab("Fitted Charges");
239 c1.Divide(2,3);
240
241 CamDraw(c1,disp1,cam,1,2,1);
242 CamDraw(c1,disp3,cam,2,2,2);
243
244 // Fit Probability
245 TCanvas &c2 = d3->AddTab("Fit Prob.");
246 c2.Divide(1,3);
247
248 CamDraw(c2,disp5,cam,1,1,3);
249
250 // Times
251 TCanvas &c3 = d3->AddTab("Fitted Times");
252 c3.Divide(3,3);
253
254 CamDraw(c3,disp6,cam,1,3,1);
255 CamDraw(c3,disp7,cam,2,3,0);
256 CamDraw(c3,disp8,cam,3,3,0);
257
258 // Pedestals
259 TCanvas &c4 = d3->AddTab("Pedestals");
260 c4.Divide(2,3);
261
262 CamDraw(c4,disp9,cam,1,2,0);
263 CamDraw(c4,disp10,cam,2,2,1);
264
265 // Reduced Sigmas
266 TCanvas &c5 = d3->AddTab("Reduced Sigmas");
267 c5.Divide(2,3);
268
269 CamDraw(c5,disp11,cam,1,2,2);
270 CamDraw(c5,disp16,cam,2,2,2);
271
272 // F-Factor Method
273 TCanvas &c6 = d3->AddTab("F-Factor Method");
274 c6.Divide(2,3);
275
276 CamDraw(c6,disp12,cam,1,2,1);
277 CamDraw(c6,disp13,cam,2,2,1);
278
279 // Blind Pixel Method
280 TCanvas &c7 = d3->AddTab("Blind Pixel Method");
281 c7.Divide(2, 3);
282
283 CamDraw(c7,disp14,cam,1,2,9);
284 CamDraw(c7,disp15,cam,2,2,1);
285
286}
287
288void CamDraw(TCanvas &c, MHCamera &cam, MCamEvent *evt, Int_t i, Int_t j, Int_t fit)
289{
290
291 c.cd(i);
292 gPad->SetBorderMode(0);
293 MHCamera *obj1=(MHCamera*)cam.DrawCopy("hist");
294 obj1->AddNotify(*evt);
295
296 c.cd(i+j);
297 gPad->SetBorderMode(0);
298 obj1->Draw();
299 ((MHCamera*)obj1)->SetPrettyPalette();
300
301 c.cd(i+2*j);
302 gPad->SetBorderMode(0);
303 Float_t he = gStyle->GetStatH();
304 Float_t wi = gStyle->GetStatH();
305 gStyle->SetStatH(0.4);
306 gStyle->SetStatW(0.25);
307
308 TH1D *obj2 = (TH1D*)obj1->Projection();
309 obj2->Draw();
310 obj2->SetBit(kCanDelete);
311
312 const Double_t min = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
313 const Double_t max = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
314 const Double_t integ = obj2->Integral("width")/2.5;
315 const Double_t mean = obj2->GetMean();
316 const Double_t rms = obj2->GetRMS();
317 const Double_t width = max-min;
318
319 switch (fit)
320 {
321 case 0:
322 TF1 *sgaus = new TF1("sgaus","gaus(0)",min,max);
323 sgaus->SetParNames("Area","#mu","#sigma");
324 sgaus->SetParameters(integ/rms,mean,rms);
325 sgaus->SetParLimits(0,0.,integ);
326 sgaus->SetParLimits(1,min,max);
327 sgaus->SetParLimits(2,0,width/1.5);
328 obj2->Fit("sgaus","QLR");
329 obj2->GetFunction("sgaus")->SetLineColor(kYellow);
330 break;
331
332 case 1:
333 TF1 *dgaus = new TF1("dgaus","gaus(0)+gaus(3)",min,max);
334 dgaus->SetParNames("A1","#mu1","#sigma1","A2","#mu2","#sigma2");
335 dgaus->SetParameters(integ/width,max-width/6.,width/4.,
336 integ/width,min+width/6.,width/4.);
337 dgaus->SetParLimits(0,0,integ);
338 dgaus->SetParLimits(1,min,max);
339 dgaus->SetParLimits(2,0,width/3.);
340 dgaus->SetParLimits(3,0,integ);
341 dgaus->SetParLimits(4,min,max);
342 dgaus->SetParLimits(5,0,width/3.);
343 obj2->Fit("dgaus","QLR");
344 obj2->GetFunction("dgaus")->SetLineColor(kYellow);
345 break;
346
347 case 2:
348 TF1 *tgaus = new TF1("tgaus","gaus(0)+gaus(3)+gaus(6)",min,max);
349 tgaus->SetParNames("A1","#mu1","#sigma1","A2","#mu2","#sigma2","A3","#mu3","#sigma3");
350 tgaus->SetParameters(integ/width,max-width/6.,width/4.,
351 integ/width,min+width/6.,width/4.,
352 integ/width,min+width/6.,width/2.);
353 tgaus->SetParLimits(0,0,integ);
354 tgaus->SetParLimits(1,min,max);
355 tgaus->SetParLimits(2,0,width/4.);
356 tgaus->SetParLimits(3,0,integ);
357 tgaus->SetParLimits(4,min,max);
358 tgaus->SetParLimits(5,0,width/4.);
359 tgaus->SetParLimits(6,0,integ);
360 tgaus->SetParLimits(7,min,max);
361 tgaus->SetParLimits(8,0,width/2.);
362 obj2->Fit("tgaus","QLR");
363 obj2->GetFunction("tgaus")->SetLineColor(kYellow);
364 break;
365 case 3:
366 obj2->Fit("pol0","Q");
367 obj2->GetFunction("pol0")->SetLineColor(kYellow);
368 break;
369 case 9:
370 break;
371 default:
372 obj2->Fit("gaus","Q");
373 obj2->GetFunction("gaus")->SetLineColor(kYellow);
374 break;
375 }
376
377 gStyle->SetStatH(he);
378 gStyle->SetStatW(wi);
379
380}
Note: See TracBrowser for help on using the repository browser.