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