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

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