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

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