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