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