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 | ! Author(s): Markus Gaug, 4/2004 <mailto:markus@ifae.es>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2000-2005
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MJPedestal
|
---|
29 | //
|
---|
30 | // Resource file entries are case sensitive!
|
---|
31 | //
|
---|
32 | /////////////////////////////////////////////////////////////////////////////
|
---|
33 | #include "MJPedestal.h"
|
---|
34 |
|
---|
35 | // C/C++ includes
|
---|
36 | #include <fstream>
|
---|
37 |
|
---|
38 | // root classes
|
---|
39 | #include <TF1.h>
|
---|
40 | #include <TEnv.h>
|
---|
41 | #include <TFile.h>
|
---|
42 | #include <TLine.h>
|
---|
43 | #include <TLatex.h>
|
---|
44 | #include <TString.h>
|
---|
45 | #include <TCanvas.h>
|
---|
46 | #include <TSystem.h>
|
---|
47 | #include <TLegend.h>
|
---|
48 | #include <TPad.h>
|
---|
49 | #include <TEnv.h>
|
---|
50 | #include <TH2F.h>
|
---|
51 |
|
---|
52 | // mars core
|
---|
53 | #include "MLog.h"
|
---|
54 | #include "MLogManip.h"
|
---|
55 |
|
---|
56 | #include "MTaskEnv.h"
|
---|
57 | #include "MSequence.h"
|
---|
58 | #include "MRunIter.h"
|
---|
59 | #include "MParList.h"
|
---|
60 | #include "MTaskList.h"
|
---|
61 | #include "MEvtLoop.h"
|
---|
62 |
|
---|
63 | #include "MStatusDisplay.h"
|
---|
64 | #include "MFEventSelector.h"
|
---|
65 |
|
---|
66 | // Other basic classes
|
---|
67 | #include "MExtractTimeAndCharge.h"
|
---|
68 |
|
---|
69 | // parameter containers
|
---|
70 | #include "MGeomCam.h"
|
---|
71 | #include "MHCamera.h"
|
---|
72 | #include "MPedestalPix.h"
|
---|
73 |
|
---|
74 | #include "MCalibrationPedCam.h"
|
---|
75 | #include "MCalibrationPix.h"
|
---|
76 | #include "MHPedestalPix.h"
|
---|
77 | #include "MHCalibrationPulseTimeCam.h"
|
---|
78 | #include "MCalibrationPulseTimeCam.h"
|
---|
79 |
|
---|
80 | // tasks
|
---|
81 | #include "MReadMarsFile.h"
|
---|
82 | #include "MRawFileRead.h"
|
---|
83 | #include "MRawEvtData.h"
|
---|
84 | #include "MGeomApply.h"
|
---|
85 | #include "MTriggerPatternDecode.h"
|
---|
86 | #include "MBadPixelsMerge.h"
|
---|
87 | #include "MFillH.h"
|
---|
88 | #include "MPedCalcPedRun.h"
|
---|
89 | #include "MPedCalcFromLoGain.h"
|
---|
90 | #include "MFTriggerPattern.h"
|
---|
91 | #include "MBadPixelsCalc.h"
|
---|
92 |
|
---|
93 | #include "MPedPhotCam.h"
|
---|
94 | #include "MPedPhotPix.h"
|
---|
95 | #include "MPedestalCam.h"
|
---|
96 | #include "MPedestalPix.h"
|
---|
97 |
|
---|
98 | ClassImp(MJPedestal);
|
---|
99 |
|
---|
100 | using namespace std;
|
---|
101 |
|
---|
102 | const TString MJPedestal::fgReferenceFile = "mjobs/pedestalref.rc";
|
---|
103 | const TString MJPedestal::fgBadPixelsFile = "mjobs/badpixels_0_559.rc";
|
---|
104 | const Float_t MJPedestal::fgExtractWinLeft = 2.5;
|
---|
105 | const Float_t MJPedestal::fgExtractWinRight = 4.5;
|
---|
106 |
|
---|
107 | // --------------------------------------------------------------------------
|
---|
108 | //
|
---|
109 | // Default constructor.
|
---|
110 | //
|
---|
111 | // Sets:
|
---|
112 | // - fExtractor to NULL,
|
---|
113 | // - fExtractType to kUsePedRun
|
---|
114 | // - fStorage to Normal Storage
|
---|
115 | // - fExtractorResolution to kFALSE
|
---|
116 | //
|
---|
117 | MJPedestal::MJPedestal(const char *name, const char *title)
|
---|
118 | : fExtractor(NULL), fDisplayType(kDisplayDataCheck),
|
---|
119 | fExtractType(kUsePedRun), fExtractionType(kFundamental),
|
---|
120 | fIsUseHists(kFALSE), fDeadPixelCheck(kFALSE)
|
---|
121 | {
|
---|
122 | fName = name ? name : "MJPedestal";
|
---|
123 | fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
|
---|
124 |
|
---|
125 | SetUsePedRun();
|
---|
126 | SetPathIn("");
|
---|
127 | SetReferenceFile();
|
---|
128 | SetBadPixelsFile();
|
---|
129 |
|
---|
130 | SetExtractWinLeft();
|
---|
131 | SetExtractWinRight();
|
---|
132 | //
|
---|
133 | // Default references for case that no value references file is there
|
---|
134 | // (should not occur)
|
---|
135 | //
|
---|
136 |
|
---|
137 | fPedestalMin = 4.;
|
---|
138 | fPedestalMax = 16.;
|
---|
139 | fPedRmsMin = 0.;
|
---|
140 | fPedRmsMax = 20.;
|
---|
141 | fRefPedClosedLids = 9.635;
|
---|
142 | fRefPedExtraGalactic = 9.93;
|
---|
143 | fRefPedGalactic = 10.03;
|
---|
144 | fRefPedRmsClosedLidsInner = 1.7;
|
---|
145 | fRefPedRmsExtraGalacticInner = 5.6;
|
---|
146 | fRefPedRmsGalacticInner = 6.92;
|
---|
147 | fRefPedRmsClosedLidsOuter = 1.7;
|
---|
148 | fRefPedRmsExtraGalacticOuter = 3.35;
|
---|
149 | fRefPedRmsGalacticOuter = 4.2;
|
---|
150 | }
|
---|
151 |
|
---|
152 | MJPedestal::~MJPedestal()
|
---|
153 | {
|
---|
154 | if (fExtractor)
|
---|
155 | delete fExtractor;
|
---|
156 | }
|
---|
157 |
|
---|
158 | const char* MJPedestal::GetOutputFileName() const
|
---|
159 | {
|
---|
160 | return Form("pedest%08d.root", fSequence.GetSequence());
|
---|
161 | }
|
---|
162 |
|
---|
163 | MExtractor *MJPedestal::ReadCalibration()
|
---|
164 | {
|
---|
165 | const TString fname = Form("%s/calib%08d.root", fPathIn.Data(), fSequence.GetSequence());
|
---|
166 |
|
---|
167 | *fLog << inf << "Reading extractor from file: " << fname << endl;
|
---|
168 |
|
---|
169 | TFile file(fname, "READ");
|
---|
170 | if (!file.IsOpen())
|
---|
171 | {
|
---|
172 | *fLog << err << dbginf << "ERROR - Could not open file " << fname << endl;
|
---|
173 | return NULL;
|
---|
174 | }
|
---|
175 |
|
---|
176 | if (file.FindKey("MBadPixelsCam"))
|
---|
177 | {
|
---|
178 | MBadPixelsCam bad;
|
---|
179 | if (bad.Read()<=0)
|
---|
180 | *fLog << warn << "Unable to read MBadPixelsCam from " << fname << endl;
|
---|
181 | else
|
---|
182 | fBadPixels.Merge(bad);
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (fExtractor)
|
---|
186 | return fExtractor;
|
---|
187 |
|
---|
188 | TObject *o=0;
|
---|
189 | o = file.Get("ExtractSignal");
|
---|
190 | if (o && !o->InheritsFrom(MExtractor::Class()))
|
---|
191 | {
|
---|
192 | *fLog << err << dbginf << "ERROR - ExtractSignal read from " << fname << " doesn't inherit from MExtractor!" << endl;
|
---|
193 | return NULL;
|
---|
194 | }
|
---|
195 | return o ? (MExtractor*)o->Clone("ExtractSignal") : NULL;
|
---|
196 | }
|
---|
197 |
|
---|
198 | //---------------------------------------------------------------------------------
|
---|
199 | //
|
---|
200 | // Display the results.
|
---|
201 | // If Display type "kDataCheck" was chosen, also the reference lines are displayed.
|
---|
202 | //
|
---|
203 | void MJPedestal::DisplayResult(MParList &plist)
|
---|
204 | {
|
---|
205 | if (!fDisplay)
|
---|
206 | return;
|
---|
207 |
|
---|
208 | //
|
---|
209 | // Update display
|
---|
210 | //
|
---|
211 | TString title = fDisplay->GetTitle();
|
---|
212 | title += "-- Pedestal ";
|
---|
213 | title += fSequence.GetName();
|
---|
214 | title += " --";
|
---|
215 | fDisplay->SetTitle(title);
|
---|
216 |
|
---|
217 | //
|
---|
218 | // Get container from list
|
---|
219 | //
|
---|
220 | MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
|
---|
221 | // MCalibrationPedCam &calpedcam = *(MCalibrationPedCam*)plist.FindObject("MCalibrationPedCam");
|
---|
222 |
|
---|
223 | //
|
---|
224 | // Create container to display
|
---|
225 | //
|
---|
226 | MHCamera disp0 (geomcam, "MPedestalCam;ped", "Mean Pedestal");
|
---|
227 | MHCamera disp1 (geomcam, "MPedestalCam;RMS", "Pedestal RMS");
|
---|
228 | MHCamera disp2 (geomcam, "MCalibPedCam;histmean", "Mean Pedestal (Hist.)");
|
---|
229 | MHCamera disp3 (geomcam, "MCalibPedCam;histsigma", "Pedestal RMS (Hist.)");
|
---|
230 | MHCamera disp4 (geomcam, "MCalibPedCam;ped", "Mean Pedestal");
|
---|
231 | MHCamera disp5 (geomcam, "MCalibPedCam;RMS", "Pedestal RMS");
|
---|
232 | MHCamera disp6 (geomcam, "MCalibDiffCam;ped", "Diff. Mean Pedestal (Hist.)");
|
---|
233 | MHCamera disp7 (geomcam, "MCalibDiffCam;RMS", "Diff. Pedestal RMS (Hist.)");
|
---|
234 | MHCamera disp8 (geomcam, "MCalibDiffCam;ped", "Diff. Mean Pedestal");
|
---|
235 | MHCamera disp9 (geomcam, "MCalibDiffCam;AbsRMS", "Diff. Abs. Pedestal RMS");
|
---|
236 | MHCamera disp10(geomcam, "MCalibDiffCam;RelRMS", "Diff. Rel. Pedestal RMS");
|
---|
237 |
|
---|
238 | disp0.SetCamContent(fPedestalCamOut, 0);
|
---|
239 | disp0.SetCamError (fPedestalCamOut, 1);
|
---|
240 |
|
---|
241 | disp1.SetCamContent(fPedestalCamOut, 2);
|
---|
242 | disp1.SetCamError (fPedestalCamOut, 3);
|
---|
243 |
|
---|
244 | /*
|
---|
245 | if (fIsUseHists)
|
---|
246 | {
|
---|
247 | disp2.SetCamContent(calpedcam, 0);
|
---|
248 | disp2.SetCamError (calpedcam, 1);
|
---|
249 |
|
---|
250 | disp3.SetCamContent(calpedcam, 2);
|
---|
251 | disp3.SetCamError (calpedcam, 3);
|
---|
252 |
|
---|
253 | disp4.SetCamContent(calpedcam, 5);
|
---|
254 | disp4.SetCamError (calpedcam, 6);
|
---|
255 |
|
---|
256 | disp5.SetCamContent(calpedcam, 7);
|
---|
257 | disp5.SetCamError (calpedcam, 8);
|
---|
258 |
|
---|
259 | for (UInt_t i=0;i<geomcam.GetNumPixels();i++)
|
---|
260 | {
|
---|
261 |
|
---|
262 | MPedestalPix &ped = fPedestalCamOut[i];
|
---|
263 | MCalibrationPix &hist = calpedcam [i];
|
---|
264 | MBadPixelsPix &bad = fBadPixels[i];
|
---|
265 |
|
---|
266 | if (bad.IsUnsuitable())
|
---|
267 | continue;
|
---|
268 |
|
---|
269 | disp6.Fill(i,ped.GetPedestal()-hist.GetHiGainMean());
|
---|
270 | disp6.SetUsed(i);
|
---|
271 |
|
---|
272 | disp7.Fill(i,hist.GetHiGainSigma()-ped.GetPedestalRms());
|
---|
273 | if (TMath::Abs(ped.GetPedestalRms()-hist.GetHiGainSigma()) < 4.0)
|
---|
274 | disp7.SetUsed(i);
|
---|
275 |
|
---|
276 | disp8.Fill(i,ped.GetPedestal()-hist.GetLoGainMean());
|
---|
277 | disp8.SetUsed(i);
|
---|
278 |
|
---|
279 | disp9.Fill(i,hist.GetLoGainSigma()-ped.GetPedestalRms());
|
---|
280 | if (TMath::Abs(hist.GetLoGainSigma() - ped.GetPedestalRms()) < 4.0)
|
---|
281 | disp9.SetUsed(i);
|
---|
282 | }
|
---|
283 | }
|
---|
284 | */
|
---|
285 |
|
---|
286 | if (fExtractionType!=kFundamental/*fExtractorResolution*/)
|
---|
287 | {
|
---|
288 | for (UInt_t i=0;i<geomcam.GetNumPixels();i++)
|
---|
289 | {
|
---|
290 |
|
---|
291 | MPedestalPix &pedo = fPedestalCamOut[i];
|
---|
292 | MPedestalPix &pedi = fPedestalCamIn[i];
|
---|
293 | MBadPixelsPix &bad = fBadPixels[i];
|
---|
294 |
|
---|
295 | if (bad.IsUnsuitable())
|
---|
296 | continue;
|
---|
297 |
|
---|
298 | const Float_t diff = pedo.GetPedestalRms()-pedi.GetPedestalRms();
|
---|
299 | const Float_t sum = 0.5*(pedo.GetPedestalRms()+pedi.GetPedestalRms());
|
---|
300 |
|
---|
301 | disp9.Fill(i,pedo.GetPedestalRms()-pedi.GetPedestalRms());
|
---|
302 | if (pedo.IsValid() && pedi.IsValid())
|
---|
303 | disp9.SetUsed(i);
|
---|
304 |
|
---|
305 | disp10.Fill(i,sum == 0. ? 0. : diff/sum);
|
---|
306 | if (pedo.IsValid() && pedi.IsValid() && sum != 0.)
|
---|
307 | disp10.SetUsed(i);
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | disp0.SetYTitle("P [cts/slice]");
|
---|
312 | disp1.SetYTitle("P_{rms} [cts/slice]");
|
---|
313 | disp2.SetYTitle("Hist. Mean [cts/slice]");
|
---|
314 | disp3.SetYTitle("Hist. Sigma [cts/slice]");
|
---|
315 | disp4.SetYTitle("Calc. Mean [cts/slice]");
|
---|
316 | disp5.SetYTitle("Calc. RMS [cts/slice]");
|
---|
317 | disp6.SetYTitle("Diff. Mean [cts/slice]");
|
---|
318 | disp7.SetYTitle("Diff. RMS [cts/slice]");
|
---|
319 | disp8.SetYTitle("Diff. Mean [cts/slice]");
|
---|
320 | disp9.SetYTitle("Abs.Diff.RMS [cts/slice]");
|
---|
321 | disp10.SetYTitle("Rel.Diff.RMS [1]");
|
---|
322 |
|
---|
323 | //
|
---|
324 | // Display data
|
---|
325 | //
|
---|
326 | if (fDisplayType != kDisplayDataCheck && fExtractionType==kFundamental/*fExtractorResolution*/)
|
---|
327 | {
|
---|
328 | TCanvas &c3 = fDisplay->AddTab("Pedestals");
|
---|
329 | c3.Divide(2,3);
|
---|
330 |
|
---|
331 | disp0.CamDraw(c3, 1, 2, 1);
|
---|
332 | disp1.CamDraw(c3, 2, 2, 6);
|
---|
333 | return;
|
---|
334 | }
|
---|
335 |
|
---|
336 | #if 0
|
---|
337 | if (fIsUseHists)
|
---|
338 | {
|
---|
339 |
|
---|
340 | TCanvas &c3 = fDisplay->AddTab("Extractor Hist.");
|
---|
341 | c3.Divide(2,3);
|
---|
342 |
|
---|
343 | disp2.CamDraw(c3, 1, 2, 1);
|
---|
344 | disp3.CamDraw(c3, 2, 2, 5);
|
---|
345 |
|
---|
346 | TCanvas &c4 = fDisplay->AddTab("Extractor Calc.");
|
---|
347 | c4.Divide(2,3);
|
---|
348 |
|
---|
349 | disp4.CamDraw(c4, 1, 2, 1);
|
---|
350 | disp5.CamDraw(c4, 2, 2, 5);
|
---|
351 |
|
---|
352 | /*
|
---|
353 | TCanvas &c5 = fDisplay->AddTab("Difference Hist.");
|
---|
354 | c5.Divide(2,3);
|
---|
355 |
|
---|
356 | disp6.CamDraw(c5, 1, 2, 1);
|
---|
357 | disp7.CamDraw(c5, 2, 2, 5);
|
---|
358 | */
|
---|
359 |
|
---|
360 | TCanvas &c6 = fDisplay->AddTab("Difference Calc.");
|
---|
361 | c6.Divide(2,3);
|
---|
362 |
|
---|
363 | disp8.CamDraw(c6, 1, 2, 1);
|
---|
364 | disp9.CamDraw(c6, 2, 2, 5);
|
---|
365 | return;
|
---|
366 | }
|
---|
367 | #endif
|
---|
368 | if (fDisplayType == kDisplayDataCheck)
|
---|
369 | {
|
---|
370 |
|
---|
371 | TCanvas &c3 = fDisplay->AddTab(fExtractionType!=kFundamental/*fExtractorResolution*/ ? "PedExtrd" : "Ped");
|
---|
372 | c3.Divide(2,3);
|
---|
373 |
|
---|
374 | c3.cd(1);
|
---|
375 | gPad->SetBorderMode(0);
|
---|
376 | gPad->SetTicks();
|
---|
377 | MHCamera *obj1=(MHCamera*)disp0.DrawCopy("hist");
|
---|
378 | //
|
---|
379 | // for the datacheck, fix the ranges!!
|
---|
380 | //
|
---|
381 | if (fExtractionType==kFundamental/*!fExtractorResolution*/)
|
---|
382 | {
|
---|
383 | obj1->SetMinimum(fPedestalMin);
|
---|
384 | obj1->SetMaximum(fPedestalMax);
|
---|
385 | }
|
---|
386 | //
|
---|
387 | // Set the datacheck sizes:
|
---|
388 | //
|
---|
389 | FixDataCheckHist((TH1D*)obj1);
|
---|
390 | //
|
---|
391 | // set reference lines
|
---|
392 | //
|
---|
393 | DisplayReferenceLines(obj1,0);
|
---|
394 | //
|
---|
395 | // end reference lines
|
---|
396 | //
|
---|
397 | c3.cd(3);
|
---|
398 | gPad->SetBorderMode(0);
|
---|
399 | obj1->SetPrettyPalette();
|
---|
400 | obj1->Draw();
|
---|
401 |
|
---|
402 | c3.cd(5);
|
---|
403 | gPad->SetBorderMode(0);
|
---|
404 | gPad->SetTicks();
|
---|
405 | TH1D *obj2 = (TH1D*)obj1->Projection(obj1->GetName());
|
---|
406 | obj2->Draw();
|
---|
407 | obj2->SetBit(kCanDelete);
|
---|
408 | obj2->Fit("gaus","Q");
|
---|
409 | obj2->GetFunction("gaus")->SetLineColor(kYellow);
|
---|
410 | //
|
---|
411 | // Set the datacheck sizes:
|
---|
412 | //
|
---|
413 | FixDataCheckHist(obj2);
|
---|
414 | obj2->SetStats(1);
|
---|
415 |
|
---|
416 | c3.cd(2);
|
---|
417 | gPad->SetBorderMode(0);
|
---|
418 | gPad->SetTicks();
|
---|
419 | MHCamera *obj3=(MHCamera*)disp1.DrawCopy("hist");
|
---|
420 | //
|
---|
421 | // for the datacheck, fix the ranges!!
|
---|
422 | //
|
---|
423 | obj3->SetMinimum(fPedRmsMin);
|
---|
424 | obj3->SetMaximum(fPedRmsMax);
|
---|
425 | //
|
---|
426 | // Set the datacheck sizes:
|
---|
427 | //
|
---|
428 | FixDataCheckHist((TH1D*)obj3);
|
---|
429 | //
|
---|
430 | // set reference lines
|
---|
431 | //
|
---|
432 | DisplayReferenceLines(obj3,1);
|
---|
433 |
|
---|
434 | c3.cd(4);
|
---|
435 | gPad->SetBorderMode(0);
|
---|
436 | obj3->SetPrettyPalette();
|
---|
437 | obj3->Draw();
|
---|
438 |
|
---|
439 | c3.cd(6);
|
---|
440 | gPad->SetBorderMode(0);
|
---|
441 |
|
---|
442 | if (geomcam.InheritsFrom("MGeomCamMagic"))
|
---|
443 | {
|
---|
444 | TArrayI inner(1);
|
---|
445 | inner[0] = 0;
|
---|
446 |
|
---|
447 | TArrayI outer(1);
|
---|
448 | outer[0] = 1;
|
---|
449 |
|
---|
450 | TArrayI s0(6);
|
---|
451 | s0[0] = 6;
|
---|
452 | s0[1] = 1;
|
---|
453 | s0[2] = 2;
|
---|
454 | s0[3] = 3;
|
---|
455 | s0[4] = 4;
|
---|
456 | s0[5] = 5;
|
---|
457 |
|
---|
458 | TArrayI s1(3);
|
---|
459 | s1[0] = 6;
|
---|
460 | s1[1] = 1;
|
---|
461 | s1[2] = 2;
|
---|
462 |
|
---|
463 | TArrayI s2(3);
|
---|
464 | s2[0] = 3;
|
---|
465 | s2[1] = 4;
|
---|
466 | s2[2] = 5;
|
---|
467 |
|
---|
468 | TVirtualPad *pad = gPad;
|
---|
469 | pad->Divide(2,1);
|
---|
470 |
|
---|
471 | TH1D *inout[2];
|
---|
472 | inout[0] = disp1.ProjectionS(s0, inner, "Inner");
|
---|
473 | inout[1] = disp1.ProjectionS(s0, outer, "Outer");
|
---|
474 | FixDataCheckHist(inout[0]);
|
---|
475 | FixDataCheckHist(inout[1]);
|
---|
476 |
|
---|
477 | inout[0]->SetTitle(Form("%s %s",disp1.GetTitle(),"Inner"));
|
---|
478 | inout[1]->SetTitle(Form("%s %s",disp1.GetTitle(),"Outer"));
|
---|
479 |
|
---|
480 |
|
---|
481 | for (int i=0; i<2; i++)
|
---|
482 | {
|
---|
483 | pad->cd(i+1);
|
---|
484 | gPad->SetBorderMode(0);
|
---|
485 | gPad->SetTicks();
|
---|
486 |
|
---|
487 | inout[i]->SetDirectory(NULL);
|
---|
488 | inout[i]->SetLineColor(kRed+i);
|
---|
489 | inout[i]->SetBit(kCanDelete);
|
---|
490 | inout[i]->Draw();
|
---|
491 | inout[i]->Fit("gaus", "Q");
|
---|
492 |
|
---|
493 | TLegend *leg2 = new TLegend(0.6,0.2,0.9,0.55);
|
---|
494 | leg2->SetHeader(inout[i]->GetName());
|
---|
495 | leg2->AddEntry(inout[i], inout[i]->GetName(), "l");
|
---|
496 |
|
---|
497 | //
|
---|
498 | // Display the outliers as dead and noisy pixels
|
---|
499 | //
|
---|
500 | DisplayOutliers(inout[i]);
|
---|
501 |
|
---|
502 | //
|
---|
503 | // Display the two half of the camera separately
|
---|
504 | //
|
---|
505 | TH1D *half[2];
|
---|
506 | half[0] = disp1.ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2");
|
---|
507 | half[1] = disp1.ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5");
|
---|
508 |
|
---|
509 | for (int j=0; j<2; j++)
|
---|
510 | {
|
---|
511 | half[j]->SetLineColor(kRed+i+2*j+1);
|
---|
512 | half[j]->SetDirectory(NULL);
|
---|
513 | half[j]->SetBit(kCanDelete);
|
---|
514 | half[j]->Draw("same");
|
---|
515 | leg2->AddEntry(half[j], half[j]->GetName(), "l");
|
---|
516 | }
|
---|
517 | leg2->Draw();
|
---|
518 | delete leg2;
|
---|
519 | }
|
---|
520 | return;
|
---|
521 | }
|
---|
522 | }
|
---|
523 |
|
---|
524 | if (fExtractionType!=kFundamental/*fExtractorResolution*/)
|
---|
525 | {
|
---|
526 |
|
---|
527 | TCanvas &c3 = fDisplay->AddTab(fExtractionType==kWithExtractor?"PedExtrd":"PedRndm");
|
---|
528 | c3.Divide(2,3);
|
---|
529 |
|
---|
530 | disp0.CamDraw(c3, 1, 2, 1);
|
---|
531 | disp1.CamDraw(c3, 2, 2, 6);
|
---|
532 |
|
---|
533 | TCanvas &c13 = fDisplay->AddTab(fExtractionType==kWithExtractor?"DiffExtrd":"DiffRndm");
|
---|
534 | c13.Divide(2,3);
|
---|
535 |
|
---|
536 | disp9.CamDraw(c13, 1, 2, 5);
|
---|
537 | disp10.CamDraw(c13, 2, 2, 5);
|
---|
538 | return;
|
---|
539 | }
|
---|
540 | }
|
---|
541 |
|
---|
542 |
|
---|
543 | void MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
|
---|
544 | {
|
---|
545 |
|
---|
546 | Double_t x = cam->GetNbinsX();
|
---|
547 |
|
---|
548 | const MGeomCam *geom = cam->GetGeometry();
|
---|
549 |
|
---|
550 | if (geom->InheritsFrom("MGeomCamMagic"))
|
---|
551 | x = what ? 397 : cam->GetNbinsX();
|
---|
552 |
|
---|
553 | TLine line;
|
---|
554 | line.SetLineStyle(kDashed);
|
---|
555 | line.SetLineWidth(3);
|
---|
556 | line.SetLineColor(kBlue);
|
---|
557 |
|
---|
558 | TLegend *leg = new TLegend(0.6,0.75,0.9,0.99);
|
---|
559 | leg->SetBit(kCanDelete);
|
---|
560 |
|
---|
561 | if (fExtractionType==kWithExtractorRndm && !(what))
|
---|
562 | {
|
---|
563 | TLine *l0 = line.DrawLine(0,0.,cam->GetNbinsX(),0.);
|
---|
564 | l0->SetBit(kCanDelete);
|
---|
565 | leg->AddEntry(l0, "Reference","l");
|
---|
566 | leg->Draw();
|
---|
567 | return;
|
---|
568 | }
|
---|
569 |
|
---|
570 | line.SetLineColor(kBlue);
|
---|
571 | TLine *l1 = line.DrawLine(0, what ? fRefPedRmsGalacticInner : fRefPedGalactic,
|
---|
572 | x, what ? fRefPedRmsGalacticInner : fRefPedGalactic);
|
---|
573 | l1->SetBit(kCanDelete);
|
---|
574 | line.SetLineColor(kYellow);
|
---|
575 | TLine *l2 = line.DrawLine(0, what ? fRefPedRmsExtraGalacticInner : fRefPedExtraGalactic,
|
---|
576 | x, what ? fRefPedRmsExtraGalacticInner : fRefPedExtraGalactic);
|
---|
577 | l2->SetBit(kCanDelete);
|
---|
578 | line.SetLineColor(kMagenta);
|
---|
579 | TLine *l3 = line.DrawLine(0, what ? fRefPedRmsClosedLidsInner : fRefPedClosedLids,
|
---|
580 | x, what ? fRefPedRmsClosedLidsInner : fRefPedClosedLids);
|
---|
581 | l3->SetBit(kCanDelete);
|
---|
582 |
|
---|
583 | if (geom->InheritsFrom("MGeomCamMagic"))
|
---|
584 | if (what)
|
---|
585 | {
|
---|
586 | const Double_t x2 = cam->GetNbinsX();
|
---|
587 |
|
---|
588 | line.SetLineColor(kBlue);
|
---|
589 | line.DrawLine(398, fRefPedRmsGalacticOuter,
|
---|
590 | x2, fRefPedRmsGalacticOuter);
|
---|
591 |
|
---|
592 | line.SetLineColor(kYellow);
|
---|
593 | line.DrawLine(398, fRefPedRmsExtraGalacticOuter,
|
---|
594 | x2, fRefPedRmsExtraGalacticOuter);
|
---|
595 |
|
---|
596 | line.SetLineColor(kMagenta);
|
---|
597 | line.DrawLine(398, fRefPedRmsClosedLidsOuter,
|
---|
598 | x2, fRefPedRmsClosedLidsOuter);
|
---|
599 | }
|
---|
600 |
|
---|
601 |
|
---|
602 | leg->AddEntry(l1, "Galactic Source","l");
|
---|
603 | leg->AddEntry(l2, "Extra-Galactic Source","l");
|
---|
604 | leg->AddEntry(l3, "Closed Lids","l");
|
---|
605 | leg->Draw();
|
---|
606 | }
|
---|
607 |
|
---|
608 | void MJPedestal::DisplayOutliers(TH1D *hist) const
|
---|
609 | {
|
---|
610 | const Float_t mean = hist->GetFunction("gaus")->GetParameter(1);
|
---|
611 | const Float_t lolim = mean - 3.5*hist->GetFunction("gaus")->GetParameter(2);
|
---|
612 | const Float_t uplim = mean + 3.5*hist->GetFunction("gaus")->GetParameter(2);
|
---|
613 | const Stat_t dead = hist->Integral(0,hist->FindBin(lolim)-1);
|
---|
614 | const Stat_t noisy = hist->Integral(hist->FindBin(uplim)+1,hist->GetNbinsX()+1);
|
---|
615 |
|
---|
616 | TLatex deadtex;
|
---|
617 | deadtex.SetTextSize(0.06);
|
---|
618 | deadtex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.1,Form("%3i dead pixels",(Int_t)dead));
|
---|
619 |
|
---|
620 | TLatex noisytex;
|
---|
621 | noisytex.SetTextSize(0.06);
|
---|
622 | noisytex.DrawLatex(0.1,hist->GetBinContent(hist->GetMaximumBin())/1.2,Form("%3i noisy pixels",(Int_t)noisy));
|
---|
623 | }
|
---|
624 |
|
---|
625 | void MJPedestal::FixDataCheckHist(TH1D *hist) const
|
---|
626 | {
|
---|
627 | hist->SetDirectory(NULL);
|
---|
628 | hist->SetStats(0);
|
---|
629 |
|
---|
630 | //
|
---|
631 | // set the labels bigger
|
---|
632 | //
|
---|
633 | TAxis *xaxe = hist->GetXaxis();
|
---|
634 | TAxis *yaxe = hist->GetYaxis();
|
---|
635 |
|
---|
636 | xaxe->CenterTitle();
|
---|
637 | yaxe->CenterTitle();
|
---|
638 | xaxe->SetTitleSize(0.06);
|
---|
639 | yaxe->SetTitleSize(0.06);
|
---|
640 | xaxe->SetTitleOffset(0.8);
|
---|
641 | yaxe->SetTitleOffset(0.5);
|
---|
642 | xaxe->SetLabelSize(0.05);
|
---|
643 | yaxe->SetLabelSize(0.05);
|
---|
644 | }
|
---|
645 |
|
---|
646 | /*
|
---|
647 | Bool_t MJPedestal::WriteEventloop(MEvtLoop &evtloop) const
|
---|
648 | {
|
---|
649 | if (fOutputPath.IsNull())
|
---|
650 | return kTRUE;
|
---|
651 |
|
---|
652 | const TString oname(GetOutputFile());
|
---|
653 |
|
---|
654 | *fLog << inf << "Writing to file: " << oname << endl;
|
---|
655 |
|
---|
656 | TFile file(oname, fOverwrite?"RECREATE":"NEW", "File created by MJPedestal", 9);
|
---|
657 | if (!file.IsOpen())
|
---|
658 | {
|
---|
659 | *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
|
---|
660 | return kFALSE;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if (evtloop.Write(fName)<=0)
|
---|
664 | {
|
---|
665 | *fLog << err << "Unable to write MEvtloop to " << oname << endl;
|
---|
666 | return kFALSE;
|
---|
667 | }
|
---|
668 |
|
---|
669 | return kTRUE;
|
---|
670 | }
|
---|
671 | */
|
---|
672 |
|
---|
673 | void MJPedestal::SetExtractor(MExtractor* ext)
|
---|
674 | {
|
---|
675 | if (ext)
|
---|
676 | {
|
---|
677 | if (fExtractor)
|
---|
678 | delete fExtractor;
|
---|
679 | fExtractor = ext ? (MExtractor*)ext->Clone(ext->GetName()) : NULL;
|
---|
680 | }
|
---|
681 | else
|
---|
682 | fExtractor = 0;
|
---|
683 | }
|
---|
684 |
|
---|
685 | // --------------------------------------------------------------------------
|
---|
686 | //
|
---|
687 | // Read the following values from resource file:
|
---|
688 | //
|
---|
689 | // PedestalMin
|
---|
690 | // PedestalMax
|
---|
691 | //
|
---|
692 | // PedRmsMin
|
---|
693 | // PedRmsMax
|
---|
694 | //
|
---|
695 | // RefPedClosedLids
|
---|
696 | // RefPedExtraGalactic
|
---|
697 | // RefPedGalactic
|
---|
698 | //
|
---|
699 | // RefPedRmsClosedLidsInner
|
---|
700 | // RefPedRmsExtraGalacticInner
|
---|
701 | // RefPedRmsGalacticInner
|
---|
702 | // RefPedRmsClosedLidsOuter
|
---|
703 | // RefPedRmsExtraGalacticOuter
|
---|
704 | // RefPedRmsGalacticOuter
|
---|
705 | //
|
---|
706 | void MJPedestal::ReadReferenceFile()
|
---|
707 | {
|
---|
708 | TEnv refenv(fReferenceFile);
|
---|
709 |
|
---|
710 | fPedestalMin = refenv.GetValue("PedestalMin",fPedestalMin);
|
---|
711 | fPedestalMax = refenv.GetValue("PedestalMax",fPedestalMax);
|
---|
712 | fPedRmsMin = refenv.GetValue("PedRmsMin",fPedRmsMin);
|
---|
713 | fPedRmsMax = refenv.GetValue("PedRmsMax",fPedRmsMax);
|
---|
714 | fRefPedClosedLids = refenv.GetValue("RefPedClosedLids",fRefPedClosedLids);
|
---|
715 | fRefPedExtraGalactic = refenv.GetValue("RefPedExtraGalactic",fRefPedExtraGalactic);
|
---|
716 | fRefPedGalactic = refenv.GetValue("RefPedGalactic",fRefPedGalactic);
|
---|
717 | fRefPedRmsClosedLidsInner = refenv.GetValue("RefPedRmsClosedLidsInner",fRefPedRmsClosedLidsInner);
|
---|
718 | fRefPedRmsExtraGalacticInner = refenv.GetValue("RefPedRmsExtraGalacticInner",fRefPedRmsExtraGalacticInner);
|
---|
719 | fRefPedRmsGalacticInner = refenv.GetValue("RefPedRmsGalacticInner",fRefPedRmsGalacticInner);
|
---|
720 | fRefPedRmsClosedLidsOuter = refenv.GetValue("RefPedRmsClosedLidsOuter",fRefPedRmsClosedLidsOuter);
|
---|
721 | fRefPedRmsExtraGalacticOuter = refenv.GetValue("RefPedRmsExtraGalacticOuter",fRefPedRmsExtraGalacticOuter);
|
---|
722 | fRefPedRmsGalacticOuter = refenv.GetValue("RefPedRmsGalacticOuter",fRefPedRmsGalacticOuter);
|
---|
723 | }
|
---|
724 |
|
---|
725 | // --------------------------------------------------------------------------
|
---|
726 | //
|
---|
727 | // The following resource options are available:
|
---|
728 | //
|
---|
729 | // Do a datacheck run (read raw-data and enable display)
|
---|
730 | // Prefix.DataCheck: Yes, No <default>
|
---|
731 | //
|
---|
732 | // Setup display type
|
---|
733 | // Prefix.Display: normal <default>, datacheck, none
|
---|
734 | //
|
---|
735 | // Use cosmic data instead of pedestal data (DatRuns)
|
---|
736 | // Prefix.UseData: Yes, No <default>
|
---|
737 | //
|
---|
738 | // Write an output file with pedestals and status-display
|
---|
739 | // Prefix.DisableOutput: Yes, No <default>
|
---|
740 | //
|
---|
741 | // Name of a file containing reference values (see ReadReferenceFile)
|
---|
742 | // Prefix.ReferenceFile: filename
|
---|
743 | // (see ReadReferenceFile)
|
---|
744 | //
|
---|
745 | Bool_t MJPedestal::CheckEnvLocal()
|
---|
746 | {
|
---|
747 | if (HasEnv("Display"))
|
---|
748 | {
|
---|
749 | TString type = GetEnv("Display", "normal");
|
---|
750 | type.ToLower();
|
---|
751 | if (type==(TString)"normal")
|
---|
752 | fDisplayType = kDisplayNormal;
|
---|
753 | if (type==(TString)"datacheck")
|
---|
754 | fDisplayType = kDisplayDataCheck;
|
---|
755 | if (type==(TString)"none")
|
---|
756 | fDisplayType = kDisplayNone;
|
---|
757 | }
|
---|
758 |
|
---|
759 |
|
---|
760 | SetExtractWinLeft (GetEnv("ExtractWinLeft", fExtractWinLeft ));
|
---|
761 | SetExtractWinRight(GetEnv("ExtractWinRight", fExtractWinRight));
|
---|
762 |
|
---|
763 | if (!MJCalib::CheckEnvLocal())
|
---|
764 | return kFALSE;
|
---|
765 |
|
---|
766 | if (HasEnv("UseData"))
|
---|
767 | fExtractType = GetEnv("UseData",kFALSE) ? kUseData : kUsePedRun;
|
---|
768 |
|
---|
769 | if (IsUseMC() && fExtractType==kUseData)
|
---|
770 | {
|
---|
771 | // The reason is, that the standard data files contains empty
|
---|
772 | // (untriggered) events. If we would loop over the default 500
|
---|
773 | // first events of the data file you would calculate the
|
---|
774 | // pedestal from only some single events...
|
---|
775 | *fLog << inf;
|
---|
776 | *fLog << "Sorry, you cannot extract the starting pedestal from the first" << endl;
|
---|
777 | *fLog << "events in your data files... using pedestal file instead. The" << endl;
|
---|
778 | *fLog << "result should not differ..." << endl;
|
---|
779 | fExtractType = kUsePedRun;
|
---|
780 | }
|
---|
781 |
|
---|
782 |
|
---|
783 | if (HasEnv("UseHists"))
|
---|
784 | if (GetEnv("UseHists",kFALSE))
|
---|
785 | fIsUseHists = kTRUE;
|
---|
786 |
|
---|
787 | SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
|
---|
788 |
|
---|
789 | fDeadPixelCheck = GetEnv("DeadPixelsCheck", fDeadPixelCheck);
|
---|
790 |
|
---|
791 | fBadPixelsFile = GetEnv("BadPixelsFile",fBadPixelsFile.Data());
|
---|
792 | fReferenceFile = GetEnv("ReferenceFile",fReferenceFile.Data());
|
---|
793 | ReadReferenceFile();
|
---|
794 |
|
---|
795 | // ------------- Do not put simple resource below --------------
|
---|
796 |
|
---|
797 | // Setup an environment task
|
---|
798 | MTaskEnv tenv("ExtractSignal");
|
---|
799 | tenv.SetDefault(fExtractor);
|
---|
800 |
|
---|
801 | // check the resource file for it
|
---|
802 | if (!CheckEnv(tenv))
|
---|
803 | return kFALSE;
|
---|
804 |
|
---|
805 | // if (tenv.ReadEnv(*GetEnv(), GetEnvPrefix()+".ExtractSignal", GetEnvDebug()>2)==kERROR)
|
---|
806 | // return kFALSE;
|
---|
807 |
|
---|
808 | // If the resource file didn't change the default we are done
|
---|
809 | if (fExtractor==tenv.GetTask())
|
---|
810 | return kTRUE;
|
---|
811 |
|
---|
812 | // If it changed the default check its inheritance...
|
---|
813 | if (!tenv.GetTask()->InheritsFrom(MExtractor::Class()))
|
---|
814 | {
|
---|
815 | *fLog << err << "ERROR: ExtractSignal from resource file doesn't inherit from MExtractor.... abort." << endl;
|
---|
816 | return kFALSE;
|
---|
817 | }
|
---|
818 |
|
---|
819 | // ..and store it
|
---|
820 | SetExtractor((MExtractor*)tenv.GetTask());
|
---|
821 |
|
---|
822 | return kTRUE;
|
---|
823 | }
|
---|
824 |
|
---|
825 | //---------------------------------------------------------------------------------
|
---|
826 | //
|
---|
827 | // Try to write the created MPedestalCam in the output file.
|
---|
828 | // If possible, also an MBadPixelsCam and the corresponding display is written.
|
---|
829 | //
|
---|
830 | // In case of Storage type "kNoStorage" or if any of the containers
|
---|
831 | // cannot be written, return kFALSE, otherwise kTRUE.
|
---|
832 | //
|
---|
833 | Bool_t MJPedestal::WriteResult()
|
---|
834 | {
|
---|
835 | if (IsNoStorage())
|
---|
836 | return kTRUE;
|
---|
837 |
|
---|
838 | TObjArray cont;
|
---|
839 |
|
---|
840 | cont.Add(&fPedestalCamOut);
|
---|
841 | cont.Add(&fBadPixels);
|
---|
842 |
|
---|
843 | return WriteContainer(cont, GetOutputFileName(), fOverwrite?"RECREATE":"NEW");
|
---|
844 | }
|
---|
845 |
|
---|
846 | Bool_t MJPedestal::PulsePosCheck(const MParList &plist) const
|
---|
847 | {
|
---|
848 | if (fIsPixelCheck)
|
---|
849 | {
|
---|
850 | MHPedestalCam *hcam = (MHPedestalCam*)plist.FindObject("MHPedestalCam");
|
---|
851 | if (hcam)
|
---|
852 | {
|
---|
853 | MHPedestalPix &pix1 = (MHPedestalPix&)(*hcam)[fCheckedPixId];
|
---|
854 | pix1.DrawClone("");
|
---|
855 | }
|
---|
856 | }
|
---|
857 |
|
---|
858 | if (!fIsPulsePosCheck)
|
---|
859 | return kTRUE;
|
---|
860 |
|
---|
861 | Int_t numhigainsamples = 0;
|
---|
862 | Int_t numlogainsamples = 0;
|
---|
863 |
|
---|
864 | Float_t meanpulsetime = 0.;
|
---|
865 | Float_t rmspulsetime = 0.;
|
---|
866 |
|
---|
867 | if (IsUseMC())
|
---|
868 | {
|
---|
869 | //
|
---|
870 | // FIXME:
|
---|
871 | // The MC cannot run over the first 2000 pedestal events since almost all
|
---|
872 | // events are empty, therefore a pulse pos. check is not possible, either.
|
---|
873 | // For the moment, have to fix the problem hardcoded...
|
---|
874 | //
|
---|
875 | // MMcEvt *evt = (MMcEvt*)plist.FindObject("MMcEvt");
|
---|
876 | // const Float_t meanpulsetime = evt->GetFadcTimeJitter();
|
---|
877 | meanpulsetime = 4.5;
|
---|
878 | rmspulsetime = 1.0;
|
---|
879 |
|
---|
880 | numhigainsamples = 15;
|
---|
881 | numlogainsamples = 15;
|
---|
882 |
|
---|
883 | }
|
---|
884 | else
|
---|
885 | {
|
---|
886 | if (fIsPixelCheck)
|
---|
887 | {
|
---|
888 | MHCalibrationPulseTimeCam *hcam = (MHCalibrationPulseTimeCam*)plist.FindObject("MHCalibrationPulseTimeCam");
|
---|
889 | if (!hcam)
|
---|
890 | {
|
---|
891 | *fLog << err << "MHCalibrationPulseTimeCam not found... abort." << endl;
|
---|
892 | return kFALSE;
|
---|
893 | }
|
---|
894 | hcam->DrawClone();
|
---|
895 | gPad->SaveAs(Form("%s/PulsePosTest_all.root",fPathOut.Data()));
|
---|
896 |
|
---|
897 | MHCalibrationPix &pix = (*hcam)[fCheckedPixId];
|
---|
898 | pix.DrawClone();
|
---|
899 | gPad->SaveAs(Form("%s/PulsePosTest_Pixel%04d.root",fPathOut.Data(),fCheckedPixId));
|
---|
900 | }
|
---|
901 |
|
---|
902 | MCalibrationPulseTimeCam *cam = (MCalibrationPulseTimeCam*)plist.FindObject("MCalibrationPulseTimeCam");
|
---|
903 | if (!cam)
|
---|
904 | {
|
---|
905 | *fLog << err << "MCalibrationPulseTimeCam not found... abort." << endl;
|
---|
906 | return kFALSE;
|
---|
907 | }
|
---|
908 |
|
---|
909 | meanpulsetime = cam->GetAverageArea(0).GetHiGainMean();
|
---|
910 | rmspulsetime = cam->GetAverageArea(0).GetHiGainRms();
|
---|
911 |
|
---|
912 | MRawEvtData *data = (MRawEvtData*)plist.FindObject("MRawEvtData");
|
---|
913 | if (!data)
|
---|
914 | {
|
---|
915 | *fLog << err << "MRawEvtData not found... abort." << endl;
|
---|
916 | return kFALSE;
|
---|
917 | }
|
---|
918 |
|
---|
919 | numhigainsamples = data->GetNumHiGainSamples();
|
---|
920 | numlogainsamples = data->GetNumLoGainSamples();
|
---|
921 | }
|
---|
922 |
|
---|
923 | *fLog << all << "Mean pulse time (" << (IsUseMC()?"MC":"cosmics") << "): ";
|
---|
924 | *fLog << meanpulsetime << "+-" << rmspulsetime << endl;
|
---|
925 |
|
---|
926 | const MExtractTimeAndCharge *ext = dynamic_cast<MExtractTimeAndCharge*>(fExtractor);
|
---|
927 |
|
---|
928 | //
|
---|
929 | // Get the ranges for the new extractor setting
|
---|
930 | //
|
---|
931 | const Int_t newfirst = TMath::Nint(meanpulsetime-fExtractWinLeft);
|
---|
932 |
|
---|
933 | Int_t wshigain = ext ? ext->GetWindowSizeHiGain() : 6;
|
---|
934 | if (wshigain > 6)
|
---|
935 | wshigain = 6;
|
---|
936 |
|
---|
937 | Int_t wslogain = ext ? ext->GetWindowSizeLoGain() : 4;
|
---|
938 | if (wslogain > 4)
|
---|
939 | wslogain = 4;
|
---|
940 |
|
---|
941 | const Int_t newlast = TMath::Nint(meanpulsetime+fExtractWinRight);
|
---|
942 |
|
---|
943 | *fLog << underline;
|
---|
944 | *fLog << "Try to set new range limits: (" << newfirst << "," << newlast;
|
---|
945 | *fLog << "+" << wshigain << "," << newfirst-1 << "," << newlast << "+";
|
---|
946 | *fLog << wslogain << ")" << endl;
|
---|
947 |
|
---|
948 | //
|
---|
949 | // Check the ranges for the new extractor setting
|
---|
950 | //
|
---|
951 | if (newfirst < 0)
|
---|
952 | {
|
---|
953 | *fLog << err << "Pulse is too much to the left, cannot go below 0!" << endl;
|
---|
954 | return kFALSE;
|
---|
955 |
|
---|
956 | }
|
---|
957 | if (newlast+wshigain > numhigainsamples+numlogainsamples-1)
|
---|
958 | {
|
---|
959 | *fLog << err << "Pulse is too much to the right, cannot go beyond limits: ";
|
---|
960 | *fLog << numhigainsamples << "+" << numlogainsamples << "-1" << endl;
|
---|
961 | *fLog << " Cannot extract at all!" << endl;
|
---|
962 | return kFALSE;
|
---|
963 | }
|
---|
964 | if (newlast+wslogain > numlogainsamples)
|
---|
965 | {
|
---|
966 | *fLog << err << "Pulse is too much to the right, cannot go beyond logain limits!" << endl;
|
---|
967 | *fLog << endl;
|
---|
968 | *fLog << "Try to use a different extractor (e.g. with a window size of only 4 sl.) or:" << endl;
|
---|
969 | *fLog << "Set the limit to a lower value (callisto.rc):" << endl;
|
---|
970 | *fLog << " MJPedestalY2:ExtractWinRight: 4.5" << endl;
|
---|
971 | *fLog << "(ATTENTION, you will lose late cosmics pulses!)" << endl;
|
---|
972 | *fLog << endl;
|
---|
973 | return kFALSE;
|
---|
974 | }
|
---|
975 |
|
---|
976 | //
|
---|
977 | // Set and store the new ranges
|
---|
978 | //
|
---|
979 | const Int_t hi0 = newfirst;
|
---|
980 | const Int_t hi1 = newlast+wshigain;
|
---|
981 |
|
---|
982 | const Int_t lo0 = newfirst>0 ? newfirst-1 : newfirst;
|
---|
983 | const Int_t lo1 = numlogainsamples-1;
|
---|
984 |
|
---|
985 | fExtractor->SetRange(hi0, hi1, lo0, lo1);
|
---|
986 | return kTRUE;
|
---|
987 | }
|
---|
988 |
|
---|
989 | Bool_t MJPedestal::Process()
|
---|
990 | {
|
---|
991 | if (!fSequence.IsValid())
|
---|
992 | {
|
---|
993 | *fLog << err << "ERROR - Sequence invalid..." << endl;
|
---|
994 | return kFALSE;
|
---|
995 | }
|
---|
996 |
|
---|
997 | // --------------------------------------------------------------------------------
|
---|
998 |
|
---|
999 | const TString type = IsUseData() ? "data" : "pedestal";
|
---|
1000 |
|
---|
1001 | *fLog << inf;
|
---|
1002 | fLog->Separator(GetDescriptor());
|
---|
1003 | *fLog << "Calculate MPedestalCam from " << type << "-runs ";
|
---|
1004 | *fLog << fSequence.GetName() << endl;
|
---|
1005 | *fLog << endl;
|
---|
1006 |
|
---|
1007 | // --------------------------------------------------------------------------------
|
---|
1008 |
|
---|
1009 | if (!CheckEnv())
|
---|
1010 | return kFALSE;
|
---|
1011 |
|
---|
1012 | MParList plist;
|
---|
1013 | MTaskList tlist;
|
---|
1014 | plist.AddToList(&tlist);
|
---|
1015 | plist.AddToList(this); // take care of fDisplay!
|
---|
1016 |
|
---|
1017 | MReadMarsFile read("Events");
|
---|
1018 | MRawFileRead rawread(NULL);
|
---|
1019 |
|
---|
1020 | MDirIter iter;
|
---|
1021 | if (fSequence.IsValid())
|
---|
1022 | {
|
---|
1023 | const Int_t n0 = IsUseData()
|
---|
1024 | ? fSequence.SetupDatRuns(iter, fPathData, IsUseRawData())
|
---|
1025 | : fSequence.SetupPedRuns(iter, fPathData, IsUseRawData());
|
---|
1026 | const Int_t n1 = IsUseData()
|
---|
1027 | ? fSequence.GetNumDatRuns()
|
---|
1028 | : fSequence.GetNumPedRuns();
|
---|
1029 | if (n0==0)
|
---|
1030 | {
|
---|
1031 | *fLog << err << "ERROR - No " << type << " input files of sequence found in " << (fPathData.IsNull()?"<default>":fPathData.Data()) << endl;
|
---|
1032 | return kFALSE;
|
---|
1033 | }
|
---|
1034 | if (n0!=n1)
|
---|
1035 | {
|
---|
1036 | *fLog << err << "ERROR - Number of " << type << " files found (" << n0 << ") in " << (fPathData.IsNull()?"<default>":fPathData.Data()) << " doesn't match number of files in sequence (" << n1 << ")" << endl;
|
---|
1037 | if (fLog->GetDebugLevel()>4)
|
---|
1038 | {
|
---|
1039 | *fLog << dbg << "Files which are searched:" << endl;
|
---|
1040 | iter.Print();
|
---|
1041 | }
|
---|
1042 | return kFALSE;
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | if (IsUseRawData())
|
---|
1047 | {
|
---|
1048 | rawread.AddFiles(iter);
|
---|
1049 | tlist.AddToList(&rawread);
|
---|
1050 | }
|
---|
1051 | else
|
---|
1052 | {
|
---|
1053 | read.DisableAutoScheme();
|
---|
1054 | read.AddFiles(iter);
|
---|
1055 | tlist.AddToList(&read);
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | // Setup Tasklist
|
---|
1059 | plist.AddToList(&fPedestalCamOut);
|
---|
1060 | plist.AddToList(&fBadPixels);
|
---|
1061 |
|
---|
1062 | //
|
---|
1063 | // Read bad pixels from outside
|
---|
1064 | //
|
---|
1065 | if (!fBadPixelsFile.IsNull())
|
---|
1066 | {
|
---|
1067 | *fLog << inf << "Excluding: " << fBadPixelsFile << endl;
|
---|
1068 | ifstream fin(fBadPixelsFile.Data());
|
---|
1069 | fBadPixels.AsciiRead((istream&)fin);
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | MGeomApply geomapl;
|
---|
1073 | MBadPixelsMerge merge(&fBadPixels);
|
---|
1074 |
|
---|
1075 | MPedCalcPedRun pedcalc;
|
---|
1076 | pedcalc.SetPedestalUpdate(kFALSE);
|
---|
1077 |
|
---|
1078 | MPedCalcFromLoGain pedlogain;
|
---|
1079 | pedlogain.SetPedestalUpdate(kFALSE);
|
---|
1080 |
|
---|
1081 | MHPedestalCam hpedcam;
|
---|
1082 | if (fExtractionType != kFundamental)
|
---|
1083 | hpedcam.SetRenorm(kTRUE);
|
---|
1084 | // fPedestalHist.SetRenorm(kTRUE);
|
---|
1085 | // fPedestalHist.SetPedestalsOut(&fPedestalCamOut);
|
---|
1086 | hpedcam.SetPedestalsOut(&fPedestalCamOut);
|
---|
1087 |
|
---|
1088 | MPedestalCam pedinter;
|
---|
1089 | pedinter.SetName("MPedestalCamIntermediate");
|
---|
1090 |
|
---|
1091 | MFillH fillped(&hpedcam, "MPedestalCamIntermediate", "FillPedCam");
|
---|
1092 | // MFillH fillped(&fPedestalHist, "MPedestalCamIntermediate", "FillPedCam");
|
---|
1093 | MFillH fillpul("MHCalibrationPulseTimeCam", "MRawEvtData", "FillPulseTime");
|
---|
1094 | fillped.SetBit(MFillH::kDoNotDisplay);
|
---|
1095 | fillpul.SetBit(MFillH::kDoNotDisplay);
|
---|
1096 |
|
---|
1097 | tlist.AddToList(&geomapl);
|
---|
1098 | tlist.AddToList(&merge);
|
---|
1099 |
|
---|
1100 | if (!fPathIn.IsNull())
|
---|
1101 | {
|
---|
1102 | fExtractor = ReadCalibration();
|
---|
1103 | if (!fExtractor)
|
---|
1104 | return kFALSE;
|
---|
1105 |
|
---|
1106 | // The requested setup might have been overwritten
|
---|
1107 | if (!CheckEnv(*fExtractor))
|
---|
1108 | return kFALSE;
|
---|
1109 |
|
---|
1110 | *fLog << all;
|
---|
1111 | *fLog << underline << "Signal Extractor found in calibration file and setup:" << endl;
|
---|
1112 | fExtractor->Print();
|
---|
1113 | *fLog << endl;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | // This will make that for data with version less than 5, where
|
---|
1117 | // trigger patterns were not yet correct, all the events in the real
|
---|
1118 | // data file will be processed. In any case there are no interleaved
|
---|
1119 | // calibration events in such data, so this is fine.
|
---|
1120 | MTriggerPatternDecode decode;
|
---|
1121 | MFTriggerPattern fcalib("CalibFilter");
|
---|
1122 | fcalib.SetDefault(kFALSE);
|
---|
1123 | fcalib.RequireCalibration();
|
---|
1124 | fcalib.SetInverted();
|
---|
1125 |
|
---|
1126 | tlist.AddToList(&decode);
|
---|
1127 |
|
---|
1128 | if (fIsPulsePosCheck)
|
---|
1129 | {
|
---|
1130 | fillpul.SetFilter(&fcalib);
|
---|
1131 | tlist.AddToList(&fcalib);
|
---|
1132 | tlist.AddToList(&fillpul);
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | // ----------------------------------------------------------------------
|
---|
1136 | // Now we make sure, that in all cases the ranges are setup correctly
|
---|
1137 | // ----------------------------------------------------------------------
|
---|
1138 | MTaskEnv taskenv("ExtractPedestal");
|
---|
1139 | switch (fExtractType)
|
---|
1140 | {
|
---|
1141 | case kUsePedRun:
|
---|
1142 | // In case other than 'fundamental' second argument is obsolete
|
---|
1143 | // pedcalc.SetExtractWindow(0,14); // kUsePedRun (take default from class)
|
---|
1144 | taskenv.SetDefault(&pedcalc);
|
---|
1145 | tlist.AddToList(&taskenv);
|
---|
1146 | break;
|
---|
1147 |
|
---|
1148 | case kUseData:
|
---|
1149 | // In case other than 'fundamental' second argument is obsolete
|
---|
1150 | // pedlogain.SetExtractWindow(15,14); // kUseData (take default from class)
|
---|
1151 | taskenv.SetDefault(&pedlogain);
|
---|
1152 | tlist.AddToList(&taskenv);
|
---|
1153 | break;
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | if (fIsUseHists && fExtractor)
|
---|
1157 | {
|
---|
1158 | if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
|
---|
1159 | {
|
---|
1160 | if (fExtractionType!=kFundamental)
|
---|
1161 | {
|
---|
1162 | const MExtractTimeAndCharge &e = *static_cast<MExtractTimeAndCharge*>(fExtractor);
|
---|
1163 | hpedcam.SetFitStart(-5*e.GetWindowSizeHiGain());
|
---|
1164 | }
|
---|
1165 | else
|
---|
1166 | hpedcam.SetFitStart(10.);
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | pedcalc.SetIntermediateStorage();
|
---|
1170 | pedlogain.SetIntermediateStorage();
|
---|
1171 | plist.AddToList(&pedinter);
|
---|
1172 | plist.AddToList(&hpedcam);
|
---|
1173 | // plist.AddToList(&fPedestalHist);
|
---|
1174 | tlist.AddToList(&fillped);
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | pedcalc.SetPedestalsIn(&fPedestalCamIn);
|
---|
1178 | pedlogain.SetPedestalsIn(&fPedestalCamIn);
|
---|
1179 |
|
---|
1180 | pedcalc.SetPedestalsInter(&pedinter);
|
---|
1181 | pedlogain.SetPedestalsInter(&pedinter);
|
---|
1182 | pedcalc.SetPedestalsOut(&fPedestalCamOut);
|
---|
1183 | pedlogain.SetPedestalsOut(&fPedestalCamOut);
|
---|
1184 |
|
---|
1185 | // kFundamental
|
---|
1186 | if (fExtractor)
|
---|
1187 | {
|
---|
1188 | fExtractor->SetPedestals(&fPedestalCamIn);
|
---|
1189 |
|
---|
1190 | if (fExtractionType!=kFundamental)
|
---|
1191 | {
|
---|
1192 | pedcalc.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
|
---|
1193 | pedlogain.SetRandomCalculation(fExtractionType==kWithExtractorRndm);
|
---|
1194 |
|
---|
1195 | pedcalc.SetExtractor((MExtractTimeAndCharge*)fExtractor);
|
---|
1196 | pedlogain.SetExtractor((MExtractTimeAndCharge*)fExtractor);
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
|
---|
1200 | {
|
---|
1201 |
|
---|
1202 | const Float_t f = 0.1+fExtractor->GetHiGainFirst();
|
---|
1203 | const Int_t win = ((MExtractTimeAndCharge*)fExtractor)->GetWindowSizeHiGain();
|
---|
1204 | pedcalc.SetExtractWindow((Int_t)f, win);
|
---|
1205 | pedlogain.SetExtractWindow((Int_t)(15+f), win);
|
---|
1206 |
|
---|
1207 | }
|
---|
1208 | else
|
---|
1209 | {
|
---|
1210 | const Float_t f = 0.1+fExtractor->GetHiGainFirst();
|
---|
1211 | const Float_t n = 0.1+fExtractor->GetNumHiGainSamples();
|
---|
1212 | pedcalc.SetExtractWindow((Int_t)f, (Int_t)n);
|
---|
1213 | pedlogain.SetExtractWindow((Int_t)(15+f), (Int_t)n);
|
---|
1214 |
|
---|
1215 | if (fExtractionType!=kFundamental)
|
---|
1216 | {
|
---|
1217 | *fLog << inf;
|
---|
1218 | *fLog << "Signal extractor doesn't inherit from MExtractTimeAndCharge..." << endl;
|
---|
1219 | *fLog << " --> falling back to fundamental pedestal extraction." << endl;
|
---|
1220 | fExtractionType=kFundamental;
|
---|
1221 | }
|
---|
1222 | }
|
---|
1223 | }
|
---|
1224 | else
|
---|
1225 | {
|
---|
1226 | *fLog << warn << GetDescriptor() << ": WARNING - No extractor has been handed over! " << endl;
|
---|
1227 | *fLog << "Taking default window for pedestal extraction. The calculated pedestal RMS" << endl;
|
---|
1228 | *fLog << "will probably not match with future pedestal RMS' from different extraction" << endl;
|
---|
1229 | *fLog << "windows." << endl;
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | //
|
---|
1233 | // Execute the eventloop
|
---|
1234 | //
|
---|
1235 | MEvtLoop evtloop(fName);
|
---|
1236 | evtloop.SetParList(&plist);
|
---|
1237 | evtloop.SetDisplay(fDisplay);
|
---|
1238 | evtloop.SetLogStream(fLog);
|
---|
1239 | if (!SetupEnv(evtloop))
|
---|
1240 | return kFALSE;
|
---|
1241 |
|
---|
1242 | // if (!WriteEventloop(evtloop))
|
---|
1243 | // return kFALSE;
|
---|
1244 |
|
---|
1245 | // Execute first analysis
|
---|
1246 | if (!evtloop.Eventloop(fMaxEvents))
|
---|
1247 | {
|
---|
1248 | *fLog << err << GetDescriptor() << ": Failed." << endl;
|
---|
1249 | return kFALSE;
|
---|
1250 | }
|
---|
1251 |
|
---|
1252 | if (fDeadPixelCheck)
|
---|
1253 | {
|
---|
1254 | MBadPixelsCalc calc;
|
---|
1255 | calc.SetPedestalLevelVarianceLo(4.5);
|
---|
1256 | calc.SetPedestalLevelVarianceHi();
|
---|
1257 | calc.SetPedestalLevel();
|
---|
1258 | if (!CheckEnv(calc))
|
---|
1259 | return kFALSE;
|
---|
1260 | calc.SetGeomCam(dynamic_cast<MGeomCam*>(plist.FindObject("MGeomCam")));
|
---|
1261 | if (!calc.CheckPedestalRms(fBadPixels, fPedestalCamOut))
|
---|
1262 | {
|
---|
1263 | *fLog << err << "ERROR - MBadPixelsCalc::CheckPedestalRms failed...." << endl;
|
---|
1264 | return kFALSE;
|
---|
1265 | }
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | if (fDisplayType!=kDisplayNone)
|
---|
1269 | DisplayResult(plist);
|
---|
1270 |
|
---|
1271 | if (!WriteResult())
|
---|
1272 | return kFALSE;
|
---|
1273 |
|
---|
1274 | if (!PulsePosCheck(plist))
|
---|
1275 | return kFALSE;
|
---|
1276 |
|
---|
1277 | *fLog << all << GetDescriptor() << ": Done." << endl;
|
---|
1278 | *fLog << endl << endl;
|
---|
1279 |
|
---|
1280 | return kTRUE;
|
---|
1281 | }
|
---|