source: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc@ 6219

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