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