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

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