Changeset 8151 for trunk/MagicSoft
- Timestamp:
- 10/24/06 08:58:13 (18 years ago)
- Location:
- trunk/MagicSoft/Mars/mpedestal
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc
r7188 r8151 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.23 2006-10-24 07:58:13 tbretz Exp $ 3 ! -------------------------------------------------------------------------- 2 4 ! 3 5 ! * … … 17 19 ! 18 20 ! Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es> 21 ! Author(s): Thomas Bretz 01/2004 <mailto:tbretz@astro.uni-wuerzburg.de> 19 22 ! 20 ! Copyright: MAGIC Software Development, 2000-200 423 ! Copyright: MAGIC Software Development, 2000-2006 21 24 ! 22 25 ! … … 159 162 #include "MRawEvtHeader.h" 160 163 #include "MRawEvtPixelIter.h" 161 #include "MRawEvtData.h"162 164 163 165 #include "MPedestalPix.h" … … 167 169 #include "MGeomCam.h" 168 170 169 #include "MTaskEnv.h"170 171 #include "MExtractTimeAndCharge.h" 172 #include "MPedestalSubtractedEvt.h" 171 173 172 174 ClassImp(MExtractPedestal); … … 174 176 using namespace std; 175 177 176 const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam"; 177 const TString MExtractPedestal::fgNameRawEvtData = "MRawEvtData"; 178 const UInt_t MExtractPedestal::fgNumDump = 500; 178 const TString MExtractPedestal::fgNamePedestalCam = "MPedestalCam"; 179 const TString MExtractPedestal::fgNameRawEvtData = "MRawEvtData"; 180 181 const UShort_t MExtractPedestal::fgCheckWinFirst = 0; 182 const UShort_t MExtractPedestal::fgCheckWinLast = 29; 183 const UShort_t MExtractPedestal::fgMaxSignalVar = 40; 179 184 180 185 // -------------------------------------------------------------------------- … … 186 191 // 187 192 // Calls: 188 // - AddToBranchList("fHiGainPixId");189 // - AddToBranchList("fHiGainFadcSamples");190 193 // - Clear() 191 194 // 192 195 MExtractPedestal::MExtractPedestal(const char *name, const char *title) 193 : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), fPedestalsOut(NULL), 194 fExtractor(NULL), fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE) 196 : fGeom(NULL), fPedestalsIn(NULL), fPedestalsInter(NULL), 197 fPedestalsOut(NULL), fExtractor(NULL), fSignal(0), 198 fExtractWinFirst(0), fExtractWinSize(0), fUseSpecialPixels(kFALSE) 195 199 { 196 200 fName = name ? name : "MExtractPedestal"; 197 201 fTitle = title ? title : "Base class to calculate pedestals"; 198 202 199 AddToBranchList("fHiGainPixId");200 AddToBranchList("fLoGainPixId");201 AddToBranchList("fHiGainFadcSamples");202 AddToBranchList("fLoGainFadcSamples");203 204 203 SetIntermediateStorage( kFALSE ); 205 SetPedestalUpdate ( kTRUE );206 204 SetRandomCalculation ( kTRUE ); 207 205 … … 210 208 SetNamePedestalCamInter(); 211 209 SetNameRawEvtData(); 212 SetNumDump(); 210 211 SetCheckRange(fgCheckWinFirst, fgCheckWinLast); 212 SetMaxSignalVar(fgMaxSignalVar); 213 213 214 214 Clear(); 215 215 } 216 216 217 // -------------------------------------------------------------------------- 218 // 219 // Call reset() of all Arays 220 // 217 221 void MExtractPedestal::ResetArrays() 218 222 { … … 244 248 // - fRawEvt to NULL 245 249 // - fRunHeader to NULL 246 // - fEvtHeader to NULL247 250 // 248 251 void MExtractPedestal::Clear(const Option_t *o) … … 251 254 fRawEvt = NULL; 252 255 fRunHeader = NULL; 253 fEvtHeader = NULL;254 256 255 257 // If the size is yet set, set the size … … 269 271 Bool_t rc = kTRUE; 270 272 271 const Int_t odd = windows & 0x1;273 const Int_t odd = TMath::Odd(windows); 272 274 273 275 if (odd && !fExtractor) … … 275 277 *fLog << warn << GetDescriptor(); 276 278 *fLog << " - WARNING: Window size in SetExtractWindow has to be even... "; 277 *fLog << " raising from " << windows << " to ";278 windows += 1;279 *fLog << " lowering from " << windows << " to "; 280 windows -= 1; 279 281 *fLog << windows << "!" << endl; 280 282 rc = kFALSE; … … 292 294 fExtractWinFirst = windowf; 293 295 fExtractWinLast = fExtractWinFirst+fExtractWinSize-1; 296 297 return rc; 298 } 299 300 // -------------------------------------------------------------------------- 301 // 302 // SetCheckRange: 303 // 304 // Exits, if the first argument is smaller than 0 305 // Exits, if the the last argument is smaller than the first 306 // 307 Bool_t MExtractPedestal::SetCheckRange(UShort_t chfirst, UShort_t chlast) 308 { 309 310 Bool_t rc = kTRUE; 294 311 312 if (chlast<=chfirst) 313 { 314 *fLog << warn << GetDescriptor(); 315 *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl; 316 chlast = chfirst+1; 317 rc = kFALSE; 318 } 319 320 fCheckWinFirst = chfirst; 321 fCheckWinLast = chlast; 322 295 323 return rc; 324 } 325 326 327 // -------------------------------------------------------------------------- 328 // 329 // Check (and if neccesary: correct) the extraction and check ranges. 330 // 331 void MExtractPedestal::CheckExtractionWindow() 332 { 333 // fSignal->GetNumSamples() not yet initialized!!! 334 const UInt_t num = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain(); 335 336 if (fCheckWinLast >= num) 337 { 338 *fLog << warn << endl; 339 *fLog << "Selected CheckWindow [" << fCheckWinFirst << "," << fCheckWinLast; 340 *fLog << "] ranges out of range [0," << num-1 << "]." << endl; 341 *fLog << "Resetting upper edge." << endl; 342 343 fCheckWinLast = num; 344 } 345 346 if (fExtractWinLast >= num) 347 { 348 *fLog << warn << endl; 349 *fLog << "Selected ExtractWindow [" << fExtractWinFirst << "," << fExtractWinLast; 350 *fLog << "] ranges out of range [0," << num-1 << "]." << endl; 351 *fLog << "Resetting upper edge." << endl; 352 353 fExtractWinLast = num; 354 } 355 356 fExtractWinSize = fExtractWinLast-fExtractWinFirst+1; 357 358 if (fExtractor || TMath::Even(fExtractWinSize)) 359 return; 360 361 fExtractWinLast += fExtractWinLast==num-1 ? -1 : +1; 362 363 *fLog << warn << endl; 364 *fLog << "ExtractionWindow odd..."; 365 *fLog << "New extraction window [" << fExtractWinFirst << "," << fExtractWinLast << "]" << endl; 366 367 fExtractWinSize = fExtractWinLast-fExtractWinFirst+1; 296 368 } 297 369 … … 338 410 } 339 411 340 fEvtHeader = (MRawEvtHeader*)pList->FindObject(AddSerialNumber("MRawEvtHeader"));341 if (!fEvtHeader)342 {343 *fLog << err << AddSerialNumber("MRawEvtHeader") << " not found... aborting." << endl;344 return kFALSE;345 }346 347 412 fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam")); 348 413 if (!fGeom) 349 414 { 350 415 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl; 416 return kFALSE; 417 } 418 419 fSignal = (MPedestalSubtractedEvt*)pList->FindObject(AddSerialNumber("MPedestalSubtractedEvt")); 420 if (!fSignal) 421 { 422 *fLog << err << AddSerialNumber("MPedestalSubtractedEvt") << " not found... aborting." << endl; 351 423 return kFALSE; 352 424 } … … 376 448 } 377 449 378 *fLog << inf;379 Print();380 381 450 return fExtractor ? fExtractor->CallPreProcess(pList) : kTRUE; 382 451 } 383 452 453 //----------------------------------------------------------------------- 454 // 455 // Call Calc(). If fExtractor!=NULL enclose the call in setting the 456 // NoiseCalculation to fRandomCalculation 457 // 384 458 Int_t MExtractPedestal::Process() 385 459 { … … 491 565 if (fExtractor) 492 566 { 493 if (! ((MTask*)fExtractor)->ReInit(pList))567 if (!fExtractor->ReInit(pList)) 494 568 return kFALSE; 495 569 496 SetExtractWindow(fExtractor->GetHiGainFirst(), (Int_t)TMath::Nint(fExtractor->GetNumHiGainSamples())); 497 } 570 // If an extractor is set determin the window size automatically! 571 fExtractWinFirst = fExtractor->GetHiGainFirst(); 572 fExtractWinLast = fExtractor->GetHiGainLast(); 573 574 // fSignal->GetNumSamples() not yet initialized!!! 575 const UInt_t num = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain(); 576 if (fExtractWinLast >= num) 577 { 578 *fLog << err << GetDescriptor(); 579 *fLog << " - ERROR: Selected fExtractWinLast out of range." << endl; 580 return kFALSE; 581 } 582 } 583 584 CheckExtractionWindow(); 498 585 499 586 return kTRUE; 500 587 } 501 588 589 // --------------------------------------------------------------------------------- 590 // 591 // PostProcess the extractor if available 592 // 502 593 Int_t MExtractPedestal::PostProcess() 503 594 { … … 506 597 } 507 598 599 // --------------------------------------------------------------------------------- 600 // 601 // Check whether the signal variation between fCheckWinFirst and fCheckWinLast 602 // exceeds fMaxSignalVar or the signal is greater than 250 603 // 604 Bool_t MExtractPedestal::CheckVariation(UInt_t idx) const 605 { 606 // This is the fast workaround to put hi- and lo-gains together 607 Byte_t *slices = fSignal->GetSamplesRaw(idx);//pixel.GetSamples(); 608 609 // Start 'real' work 610 UShort_t max = 0; 611 UShort_t min = (UShort_t)-1; 612 613 // Find the maximum and minimum signal per slice in the high gain window 614 for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++) 615 { 616 if (*slice > max) 617 max = *slice; 618 if (*slice < min) 619 min = *slice; 620 } 621 622 // If the maximum in the high gain window is smaller than 623 return max-min<fMaxSignalVar && max<250; 624 } 625 626 // --------------------------------------------------------------------------------- 627 // 628 // Invoke the hi-gain extraction starting at fExtractWinFirst+offset 629 // for fExtractWinLast-fExtractWinFirst+1 slices. If Noise calculation 630 // is set it is up to the signal extractor to do the right thing. 631 // 632 // Returns the extracted signal. 633 // 634 Float_t MExtractPedestal::CalcExtractor(const MRawEvtPixelIter &pixel, Int_t offset) const 635 { 636 // Use the same extraction window as for signal extraction 637 const Int_t first = fExtractWinFirst; 638 const Int_t last = fExtractWinLast; 639 640 const Int_t start = first+offset; 641 642 const Int_t range = last-first+1; 643 644 // This check is already done in CheckExtractionWindow 645 // if (range>pixel.GetNumSamples()-start) 646 // range = pixel.GetNumSamples()-start; 647 648 const Int_t idx = pixel.GetPixelId(); 649 650 // Do some handling if maxpos is last slice? 651 const Int_t maxposhi = fSignal->GetMax(idx, start, start+range-1); 652 653 const Float_t *sig = fSignal->GetSamples(idx); 654 655 // The pedestal is extracted with the hi-gain extractor (eg. digital 656 // filter weights) but from the lo-gains 657 Float_t dummy[3]; 658 Float_t sum = 0; 659 fExtractor->FindTimeAndChargeHiGain2(sig+start, range, sum, 660 dummy[0], dummy[1], dummy[2], 661 0, maxposhi); 662 return sum; 663 } 664 665 // --------------------------------------------------------------------------------- 666 // 667 // Sum slices from fExtractWinFirst to fExtractWinLast. The total sum is 668 // returned. ab0 and ab1 will contain the total sum splitted by the 669 // AB-flag. If the AB-flag is invalid ab0=ab1=0 is returned. 670 // 671 UInt_t MExtractPedestal::CalcSums(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t &ab0, UInt_t &ab1) const 672 { 673 const Int_t first = fExtractWinFirst+offset; 674 675 Byte_t *ptr = fSignal->GetSamplesRaw(pixel.GetPixelId())+first; 676 Byte_t *end = ptr + fExtractWinSize; 677 678 Int_t abflag = pixel.HasABFlag() + first; 679 680 UInt_t ab[2] = { 0, 0 }; 681 while (ptr<end) 682 ab[abflag++ & 0x1] += *ptr++; 683 684 // This check if for old data without AB-Flag in the data 685 const Bool_t valid = pixel.IsABFlagValid(); 686 687 ab0 = valid ? ab[0] : 0; 688 ab1 = valid ? ab[1] : 0; 689 690 return ab0+ab1; 691 } 508 692 509 693 // -------------------------------------------------------------------------- … … 512 696 // ExtractWindowFirst: 15 513 697 // ExtractWindowSize: 6 514 // NumEventsDump: 500515 698 // PedestalUpdate: yes 516 699 // RandomCalculation: yes … … 520 703 Bool_t rc=kFALSE; 521 704 522 // find resource for numdump523 if (IsEnvDefined(env, prefix, "NumDump", print))524 {525 const Int_t num = GetEnvValue(env, prefix, "NumDump", -1);526 if (num<=0)527 {528 *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl;529 return kERROR;530 }531 532 SetNumDump(num);533 rc = kTRUE;534 }535 536 705 // find resource for fUseSpecialPixels 537 706 if (IsEnvDefined(env, prefix, "UseSpecialPixels", print)) 538 707 { 539 708 SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels)); 540 rc = kTRUE;541 }542 543 // find resource for numeventsdump544 if (IsEnvDefined(env, prefix, "NumEventsDump", print))545 {546 SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump));547 rc = kTRUE;548 }549 550 // find resource for numeventsdump551 if (IsEnvDefined(env, prefix, "NumAreasDump", print))552 {553 SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump));554 rc = kTRUE;555 }556 557 // find resource for numeventsdump558 if (IsEnvDefined(env, prefix, "NumSectorsDump", print))559 {560 SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump));561 rc = kTRUE;562 }563 564 // find resource for pedestal update565 if (IsEnvDefined(env, prefix, "PedestalUpdate", print))566 {567 SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate));568 709 rc = kTRUE; 569 710 } … … 598 739 SetExtractWindow(ef,es); 599 740 741 // Find resources for CheckWindow 742 Int_t cfs = fCheckWinFirst; 743 Int_t cls = fCheckWinLast; 744 if (IsEnvDefined(env, prefix, "CheckWinFirst", print)) 745 { 746 cfs = GetEnvValue(env, prefix, "CheckWinFirst", cfs); 747 rc = kTRUE; 748 } 749 if (IsEnvDefined(env, prefix, "CheckWinLast", print)) 750 { 751 cls = GetEnvValue(env, prefix, "CheckWinLast", cls); 752 rc = kTRUE; 753 } 754 755 SetCheckRange(cfs,cls); 756 757 // find resource for maximum signal variation 758 if (IsEnvDefined(env, prefix, "MaxSignalVar", print)) 759 { 760 SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar)); 761 rc = kTRUE; 762 } 763 600 764 // find resource for MPedestalCam 601 765 if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print)) … … 648 812 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; 649 813 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; 814 // The pedestal extracted with the extractor is divided by 815 // the number of hi-gain samples because the calibration 816 // multiplies by this number 650 817 651 818 // 5. Calculate the RMS from the Variance: 652 819 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var); 653 820 821 // abOffs contains only half of the signal as ped. 822 // Therefor abOffs is not the full, but the half amplitude 654 823 (*fPedestalsOut)[pixid].Set(ped, rms, abOffs, nevts); 655 824 } … … 683 852 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; 684 853 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; 854 // The pedestal extracted with the extractor is divided by 855 // the number of hi-gain samples because the calibration 856 // multiplies by this number 685 857 686 858 // 5. Scale the mean, variance and AB-noise to the number of pixels: … … 692 864 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var); 693 865 866 // abOffs contains only half of the signal as ped. 867 // Therefor abOffs is not the full, but the half amplitude 694 868 fPedestalsOut->GetAverageArea(aidx).Set(ped, rms, abOffs, nevts); 695 869 } … … 723 897 var /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; 724 898 abOffs /= fExtractor ? fExtractor->GetNumHiGainSamples() : fExtractWinSize; 899 // The pedestal extracted with the extractor is divided by 900 // the number of hi-gain samples because the calibration 901 // multiplies by this number 725 902 726 903 // 5. Scale the mean, variance and AB-noise to the number of pixels: … … 732 909 const Double_t rms = var<0 ? 0 : TMath::Sqrt(var); 733 910 911 // abOffs contains only half of the signal as ped. 912 // Therefor abOffs is not the full, but the half amplitude 734 913 fPedestalsOut->GetAverageSector(sector).Set(ped, rms, abOffs, nevts); 735 914 } 736 915 916 //----------------------------------------------------------------------- 917 // 737 918 void MExtractPedestal::Print(Option_t *o) const 738 919 { … … 742 923 *fLog << "Name of output MPedestalCam: " << (fPedestalsOut?fPedestalsOut->GetName():fNamePedestalCamOut.Data()) << " (" << fPedestalsOut << ")" << endl; 743 924 *fLog << "Intermediate Storage is " << (fIntermediateStorage?"on":"off") << endl; 744 *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl;745 925 *fLog << "Special pixel mode " << (fUseSpecialPixels?"on":"off") << endl; 746 if (fPedestalUpdate)747 {748 *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl;749 *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl;750 *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl;751 }752 926 if (fExtractor) 753 927 { … … 755 929 *fLog << (fRandomCalculation?"":"non-") << "random)" << endl; 756 930 } 757 } 931 *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << fExtractWinLast << " incl." << endl; 932 *fLog << "CheckWindow from slice " << fCheckWinFirst << " to " << fCheckWinLast << " incl." << endl; 933 *fLog << "Max.allowed signal variation: " << fMaxSignalVar << endl; 934 } -
trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h
r7188 r8151 20 20 class MRawEvtHeader; 21 21 class MExtractTimeAndCharge; 22 class MPedestalSubtractedEvt; 23 class MRawEvtPixelIter; 22 24 23 25 class MExtractPedestal : public MTask … … 26 28 static const TString fgNamePedestalCam; //! "MPedestalCam" 27 29 static const TString fgNameRawEvtData; //! "MRawEvtData" 28 static const UInt_t fgNumDump; //! 30 31 static const UShort_t fgCheckWinFirst; //! First FADC slice to check for signal (currently set to: 0) 32 static const UShort_t fgCheckWinLast; //! Last FADC slice to check for signal (currently set to: 29) 33 static const UShort_t fgMaxSignalVar; //! The maximum difference between the highest and lowest slice 29 34 30 35 TString fNamePedestalCamIn; // Name of the incoming 'MPedestalCam' container … … 45 50 MRawEvtData *fRawEvt; //! Raw event data (time slices) 46 51 MRawRunHeader *fRunHeader; //! RunHeader information 47 MRawEvtHeader *fEvtHeader; //! EvtHeader information48 52 MExtractTimeAndCharge *fExtractor; // Possible Extractor 53 MPedestalSubtractedEvt *fSignal; //! 49 54 50 55 UShort_t fExtractWinFirst; // First FADC slice to extract pedestal from 51 56 UShort_t fExtractWinSize; // Number of slices to calculate the pedestal from 52 57 UShort_t fExtractWinLast; // Last FADC slice to extract pedestal from 53 54 U Int_t fNumEventsDump; // Number of event after which MPedestalCam gets updated55 U Int_t fNumAreasDump; // Number of events after which averaged areas gets updated56 UInt_t fNumSectorsDump; // Number of events after which averaged sectors gets updated 57 58 Bool_t fPedestalUpdate; // Flag if the pedestal shall be updated after every fNumEventsDump 58 59 UShort_t fCheckWinFirst; 60 UShort_t fCheckWinLast; 61 62 UShort_t fMaxSignalVar; 63 59 64 Bool_t fUseSpecialPixels; // Flag if the special pixels shall be treated 60 65 … … 92 97 void CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector); 93 98 99 Float_t CalcExtractor(const MRawEvtPixelIter &pixel, Int_t offset) const; 100 UInt_t CalcSums(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t &ab0, UInt_t &ab1) const; 101 Bool_t CheckVariation(UInt_t idx) const; 102 103 void CheckExtractionWindow(); 104 94 105 public: 95 106 MExtractPedestal(const char *name=NULL, const char *title=NULL); … … 98 109 void Print(const Option_t *o="") const; 99 110 111 // Setters 100 112 Bool_t SetExtractWindow(UShort_t first, UShort_t size); 113 Bool_t SetCheckRange(UShort_t checkfirst=fgCheckWinFirst, UShort_t checklast=fgCheckWinLast); 101 114 102 void SetNumEventsDump (UInt_t dumpevents=fgNumDump) { fNumEventsDump = dumpevents; } 103 void SetNumAreasDump (UInt_t dumpevents=fgNumDump) { fNumAreasDump = dumpevents; } 104 void SetNumSectorsDump(UInt_t dumpevents=fgNumDump) { fNumSectorsDump = dumpevents; } 105 void SetNumDump (UInt_t n=fgNumDump) { fNumEventsDump=n; fNumAreasDump=n; fNumSectorsDump=n; } 115 void SetMaxSignalVar(UShort_t maxvar=40) { fMaxSignalVar = maxvar; } 106 116 107 117 // names … … 120 130 void SetIntermediateStorage (Bool_t b=kTRUE) { fIntermediateStorage = b; } 121 131 void SetUseSpecialPixels (Bool_t b=kTRUE) { fUseSpecialPixels = b; } 122 void SetPedestalUpdate (Bool_t b=kTRUE) { fPedestalUpdate = b; }123 132 void SetRandomCalculation (Bool_t b=kTRUE) { fRandomCalculation = b; } 124 133 -
trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc
r6325 r8151 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MPedCalcFromLoGain.cc,v 1.34 2006-10-24 07:58:13 tbretz Exp $ 3 ! -------------------------------------------------------------------------- 2 4 ! 3 5 ! * … … 24 26 ! Author(s): Nepomuk Otte 10/2004 <mailto:otte@mppmu.mpg.de> 25 27 ! 26 ! Copyright: MAGIC Software Development, 2000-200 428 ! Copyright: MAGIC Software Development, 2000-2006 27 29 ! 28 30 ! … … 142 144 #include "MRawRunHeader.h" 143 145 #include "MRawEvtPixelIter.h" 144 #include "MRawEvtData.h"145 146 146 147 #include "MPedestalPix.h" … … 151 152 152 153 #include "MExtractPedestal.h" 153 #include "M ExtractTimeAndCharge.h"154 #include "MPedestalSubtractedEvt.h" 154 155 155 156 ClassImp(MPedCalcFromLoGain); … … 157 158 using namespace std; 158 159 159 const UShort_t MPedCalcFromLoGain::fgCheckWinFirst = 0;160 const UShort_t MPedCalcFromLoGain::fgCheckWinLast = 29;161 160 const UShort_t MPedCalcFromLoGain::fgExtractWinFirst = 17; 162 161 const UShort_t MPedCalcFromLoGain::fgExtractWinSize = 6; 163 const U Short_t MPedCalcFromLoGain::fgMaxSignalVar = 40;162 const UInt_t MPedCalcFromLoGain::fgNumDump = 500; 164 163 165 164 // -------------------------------------------------------------------------- … … 167 166 // Default constructor: 168 167 // 169 // Sets:170 // - all pointers to NULL171 //172 168 // Calls: 173 // - AddToBranchList("fHiGainPixId"); 174 // - AddToBranchList("fHiGainFadcSamples"); 175 // - SetCheckRange(fgCheckWinFirst, fgCheckWinLast, fgExtractWinFirst, fgExtractWinSize) 169 // - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize) 176 170 // 177 171 MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title) … … 180 174 fTitle = title ? title : "Task to calculate pedestals from lo-gains"; 181 175 182 SetCheckRange(fgCheckWinFirst, fgCheckWinLast);183 176 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize); 184 185 SetMaxSignalVar(fgMaxSignalVar); 186 } 187 177 SetPedestalUpdate(kTRUE); 178 SetNumDump(); 179 } 180 181 // -------------------------------------------------------------------------- 182 // 183 // Call MExtractPedestl::ResetArrays aand reset fNumAventsUsed and 184 // fTotalCounter 185 // 188 186 void MPedCalcFromLoGain::ResetArrays() 189 187 { … … 192 190 fNumEventsUsed.Reset(); 193 191 fTotalCounter.Reset(); 194 }195 196 // --------------------------------------------------------------------------197 //198 // SetCheckRange:199 //200 // Exits, if the first argument is smaller than 0201 // Exits, if the the last argument is smaller than the first202 //203 Bool_t MPedCalcFromLoGain::SetCheckRange(UShort_t chfirst, UShort_t chlast)204 {205 206 Bool_t rc = kTRUE;207 208 if (chlast<=chfirst)209 {210 *fLog << warn << GetDescriptor();211 *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl;212 chlast = chfirst+1;213 rc = kFALSE;214 }215 216 fCheckWinFirst = chfirst;217 fCheckWinLast = chlast;218 219 return rc;220 192 } 221 193 … … 231 203 Bool_t MPedCalcFromLoGain::ReInit(MParList *pList) 232 204 { 233 234 const UShort_t hisamples = fRunHeader->GetNumSamplesHiGain(); 235 const UShort_t losamples = fRunHeader->GetNumSamplesLoGain(); 236 237 fSlices.Set(hisamples+losamples); 238 239 UShort_t lastavailable = hisamples+losamples-1; 240 241 if (fExtractor) 242 fExtractWinLast = fExtractWinFirst + fExtractor->GetWindowSizeHiGain() - 1; 243 244 // If the size is not yet set, set the size 245 if (fSumx.GetSize()==0) 246 { 247 const Int_t npixels = fPedestalsOut->GetSize(); 248 fNumEventsUsed.Set(npixels); 249 fTotalCounter.Set(npixels); 250 } 251 252 if (fCheckWinLast > lastavailable) //changed to override check 253 { 254 *fLog << warn << GetDescriptor(); 255 *fLog << " - WARNING: Last Check Window slice out of range...adjusting to last available slice "; 256 *fLog << lastavailable << endl; 257 258 fCheckWinLast = lastavailable; 259 } 260 261 if (fExtractWinLast > lastavailable) 262 { 263 if (fExtractor) 264 { 265 *fLog << err << GetDescriptor(); 266 *fLog << " - ERROR: Selected Last Extraction Window: " 267 << fExtractWinFirst + fExtractor->GetWindowSizeHiGain()-1 268 << "ranges out of range: " << lastavailable-1 << endl; 269 return kFALSE; 270 } 271 else 272 { 273 const UShort_t diff = fExtractWinLast - lastavailable; 274 *fLog << warn << GetDescriptor(); 275 *fLog << " - WARNING: Selected Extract Window ranges out of range...adjusting to last available slice "; 276 *fLog << lastavailable << endl; 277 278 fExtractWinLast -= diff; 279 fExtractWinSize -= diff; 280 } 281 } 282 283 return MExtractPedestal::ReInit(pList); 205 // If the size is not yet set, set the size 206 if (fSumx.GetSize()==0) 207 { 208 const Int_t npixels = fPedestalsOut->GetSize(); 209 fNumEventsUsed.Set(npixels); 210 fTotalCounter.Set(npixels); 211 } 212 213 if (!MExtractPedestal::ReInit(pList)) 214 return kFALSE; 215 216 return kTRUE; 284 217 } 285 218 … … 292 225 Int_t MPedCalcFromLoGain::Calc() 293 226 { 294 // This is the workaround to put hi- and lo-gains together295 const Int_t nhigain = fRunHeader->GetNumSamplesHiGain();296 const Int_t nlogain = fRunHeader->GetNumSamplesLoGain();297 298 Byte_t *slices = fSlices.GetArray();299 300 227 // Real Process 301 228 MRawEvtPixelIter pixel(fRawEvt); … … 303 230 while (pixel.Next()) 304 231 { 305 // This is the fast workaround to put hi- and lo-gains together306 memcpy(slices, pixel.GetHiGainSamples(), nhigain);307 memcpy(slices+nhigain, pixel.GetLoGainSamples(), nlogain);308 309 // Start 'real' work310 232 const UInt_t idx = pixel.GetPixelId(); 233 234 if (!CheckVariation(idx)) 235 continue; 236 237 //extract pedestal 238 UInt_t ab[2]; 239 const Float_t sum = fExtractor ? 240 CalcExtractor(pixel, pixel.GetNumHiGainSamples()) : 241 CalcSums(pixel, pixel.GetNumHiGainSamples(), ab[0], ab[1]); 311 242 312 243 const UInt_t aidx = (*fGeom)[idx].GetAidx(); 313 244 const UInt_t sector = (*fGeom)[idx].GetSector(); 314 315 UShort_t max = 0;316 UShort_t min = (UShort_t)-1;317 318 // Find the maximum and minimum signal per slice in the high gain window319 for (Byte_t *slice=slices+fCheckWinFirst; slice<=slices+fCheckWinLast; slice++)320 {321 if (*slice > max)322 max = *slice;323 if (*slice < min)324 min = *slice;325 }326 327 // If the maximum in the high gain window is smaller than328 if (max-min>=fMaxSignalVar || max>=250)329 continue;330 331 Float_t sum = 0.;332 333 //extract pedestal334 if (fExtractor)335 CalcExtractor(pixel, sum, (*fPedestalsIn)[idx]);336 else337 {338 UInt_t sumi = 0;339 for(Byte_t *slice=slices+fExtractWinFirst; slice<=slices+fExtractWinLast; slice++)340 sumi += *slice;341 sum = (Float_t)sumi;342 }343 245 344 246 const Float_t sqrsum = sum*sum; … … 352 254 353 255 if (fIntermediateStorage) 354 (*fPedestalsInter)[idx].Set(sum,0.,0.,fNumEventsUsed[idx]);256 (*fPedestalsInter)[idx].Set(sum, 0, 0, fNumEventsUsed[idx]); 355 257 356 258 fNumEventsUsed[idx] ++; … … 358 260 fSectorFilled [sector]++; 359 261 360 if (!fExtractor )262 if (!fExtractor && pixel.IsABFlagValid()) 361 263 { 362 // 363 // Calculate the amplitude of the 150MHz "AB" noise 364 // 365 const UShort_t abFlag = (fExtractWinFirst + pixel.HasABFlag()) & 0x1; 366 367 for (Byte_t *slice=slices+fExtractWinFirst; slice<=slices+fExtractWinLast; slice+=2) 368 { 369 const UShort_t ab0 = *(slice + abFlag); 370 const UShort_t ab1 = *(slice - abFlag + 1); 371 372 fSumAB0[idx] += ab0; 373 fSumAB1[idx] += ab1; 374 fAreaSumAB0[aidx] += ab0; 375 fAreaSumAB1[aidx] += ab1; 376 fSectorSumAB0[aidx] += ab0; 377 fSectorSumAB1[aidx] += ab1; 378 } 264 fSumAB0[idx] += ab[0]; 265 fSumAB1[idx] += ab[1]; 266 fAreaSumAB0[aidx] += ab[0]; 267 fAreaSumAB1[aidx] += ab[1]; 268 fSectorSumAB0[aidx] += ab[0]; 269 fSectorSumAB1[aidx] += ab[1]; 379 270 } 380 271 … … 425 316 CalcAreaResults(fAreaFilled[aidx], fAreaValid[aidx], aidx); 426 317 427 }428 429 void MPedCalcFromLoGain::CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped)430 {431 Byte_t sat = 0;432 Byte_t *logain = pixel.GetLoGainSamples() + fExtractWinFirst;433 434 const Bool_t logainabflag = (pixel.HasABFlag() + pixel.GetNumHiGainSamples()) & 0x1;435 436 Float_t dummy;437 fExtractor->FindTimeAndChargeHiGain(logain,logain,sum,dummy,dummy,dummy,sat,ped,logainabflag);438 318 } 439 319 … … 469 349 } 470 350 471 472 351 // -------------------------------------------------------------------------- 473 352 // 474 353 // The following resources are available: 475 // FirstCheckWindowSlice: 0476 // LastCheckWindowSlice: 29477 // MaxSignalVar: 40478 354 // 479 355 Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print) … … 481 357 Bool_t rc=kFALSE; 482 358 483 // Find resources for CheckWindow 484 Int_t fs = fCheckWinFirst; 485 Int_t ls = fCheckWinLast; 486 if (IsEnvDefined(env, prefix, "CheckWinFirst", print)) 487 { 488 fs = GetEnvValue(env, prefix, "CheckWinFirst", fs); 359 // find resource for pedestal update 360 if (IsEnvDefined(env, prefix, "PedestalUpdate", print)) 361 { 362 SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate)); 489 363 rc = kTRUE; 490 364 } 491 if (IsEnvDefined(env, prefix, "CheckWinLast", print)) 492 { 493 ls = GetEnvValue(env, prefix, "CheckWinLast", ls); 365 366 // find resource for numdump 367 if (IsEnvDefined(env, prefix, "NumDump", print)) 368 { 369 const Int_t num = GetEnvValue(env, prefix, "NumDump", -1); 370 if (num<=0) 371 { 372 *fLog << err << GetDescriptor() << ": ERROR - NumDump invalid!" << endl; 373 return kERROR; 374 } 375 376 SetNumDump(num); 494 377 rc = kTRUE; 495 378 } 496 379 497 SetCheckRange(fs,ls); 498 499 // find resource for maximum signal variation 500 if (IsEnvDefined(env, prefix, "MaxSignalVar", print)) 501 { 502 SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar)); 380 // find resource for numeventsdump 381 if (IsEnvDefined(env, prefix, "NumEventsDump", print)) 382 { 383 SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump)); 503 384 rc = kTRUE; 504 385 } 505 386 506 return MExtractPedestal::ReadEnv(env,prefix,print) ? kTRUE : rc; 387 // find resource for numeventsdump 388 if (IsEnvDefined(env, prefix, "NumAreasDump", print)) 389 { 390 SetNumAreasDump(GetEnvValue(env, prefix, "NumAreasDump", (Int_t)fNumAreasDump)); 391 rc = kTRUE; 392 } 393 394 // find resource for numeventsdump 395 if (IsEnvDefined(env, prefix, "NumSectorsDump", print)) 396 { 397 SetNumSectorsDump(GetEnvValue(env, prefix, "NumSectorsDump", (Int_t)fNumSectorsDump)); 398 rc = kTRUE; 399 } 400 401 return rc; 507 402 } 508 403 509 404 void MPedCalcFromLoGain::Print(Option_t *o) const 510 405 { 511 512 406 MExtractPedestal::Print(o); 513 407 514 const Int_t last = fExtractor515 ? fExtractWinFirst + fExtractor->GetWindowSizeHiGain() -1516 : fExtractWinLast;517 518 *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << last << " incl."<< endl;519 *fLog << "Max.allowed signal variation: " << fMaxSignalVar<< endl;520 *fLog << "CheckWindow from slice " << fCheckWinFirst << " to " << fCheckWinLast << " incl." << endl;521 } 408 *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl; 409 if (fPedestalUpdate) 410 { 411 *fLog << "Num evts for pedestal calc: " << fNumEventsDump << endl; 412 *fLog << "Num evts for avg.areas calc: " << fNumAreasDump << endl; 413 *fLog << "Num evts for avg.sector calc: " << fNumSectorsDump << endl; 414 } 415 } -
trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h
r5715 r8151 14 14 #endif 15 15 16 class MRawEvtPixelIter;16 //class MRawEvtPixelIter; 17 17 class MPedestalPix; 18 18 … … 20 20 { 21 21 private: 22 static const UShort_t fgCheckWinFirst; // First FADC slice to check for signal (currently set to: 0)23 static const UShort_t fgCheckWinLast; // Last FADC slice to check for signal (currently set to: 29)24 static const UShort_t fgMaxSignalVar; // The maximum difference between the highest and lowest slice25 22 static const UShort_t fgExtractWinFirst; // First FADC slice to use for pedestal calculation (currently set to: 15) 26 23 static const UShort_t fgExtractWinSize; // number of successive slices used to calculate pedestal (currently set to: 6) 24 static const UInt_t fgNumDump; //! 27 25 28 U Short_t fMaxSignalVar;29 U Short_t fCheckWinFirst;30 U Short_t fCheckWinLast;26 UInt_t fNumEventsDump; // Number of event after which MPedestalCam gets updated 27 UInt_t fNumAreasDump; // Number of events after which averaged areas gets updated 28 UInt_t fNumSectorsDump; // Number of events after which averaged sectors gets updated 31 29 32 30 TArrayI fNumEventsUsed; //! Number of events used for pedestal calc for each pixel 33 31 TArrayI fTotalCounter; //! Counter for dumping values to Pedestal Container 34 32 35 MArrayB fSlices; //! workaround to put hi- and lo-gain slices together33 Bool_t fPedestalUpdate; // Flag if the pedestal shall be updated after every fNumEventsDump 36 34 37 Bool_t fRandomCalculation; 35 // MParContainer 36 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 38 37 38 // MTask 39 39 Bool_t ReInit(MParList *pList); 40 Int_t Calc();41 40 Int_t PostProcess(); 42 41 43 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 42 // MExtractPedestal 43 Int_t Calc(); 44 44 45 45 //Helper function to extract slice values by slice number 46 void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped);46 //void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped); 47 47 void ResetArrays(); 48 48 … … 53 53 MPedCalcFromLoGain(const char *name=NULL, const char *title=NULL); 54 54 55 void Print(Option_t *o="") const;56 57 // Setters58 Bool_t SetCheckRange(UShort_t checkfirst=fgCheckWinFirst, UShort_t checklast=fgCheckWinLast);59 void SetMaxSignalVar(UShort_t maxvar=40) { fMaxSignalVar = maxvar; }60 61 55 // Getters 62 56 TArrayI *GetNumEventsUsed() { return &fNumEventsUsed; } 57 58 void SetNumEventsDump (UInt_t dumpevents=fgNumDump) { fNumEventsDump = dumpevents; } 59 void SetNumAreasDump (UInt_t dumpevents=fgNumDump) { fNumAreasDump = dumpevents; } 60 void SetNumSectorsDump(UInt_t dumpevents=fgNumDump) { fNumSectorsDump = dumpevents; } 61 void SetNumDump (UInt_t n=fgNumDump) { fNumEventsDump=n; fNumAreasDump=n; fNumSectorsDump=n; } 62 63 void SetPedestalUpdate(Bool_t b=kTRUE) { fPedestalUpdate = b; } 64 65 void Print(Option_t *o="") const; 63 66 64 67 ClassDef(MPedCalcFromLoGain, 1) // Task to calculate pedestals from data runs -
trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
r7188 r8151 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MPedCalcPedRun.cc,v 1.49 2006-10-24 07:58:13 tbretz Exp $ 3 ! -------------------------------------------------------------------------- 2 4 ! 3 5 ! * … … 22 24 ! Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es> 23 25 ! 24 ! Copyright: MAGIC Software Development, 2000-200 426 ! Copyright: MAGIC Software Development, 2000-2006 25 27 ! 26 28 ! … … 137 139 138 140 #include "MExtractPedestal.h" 139 #include "M ExtractTimeAndCharge.h"141 #include "MPedestalSubtractedEvt.h" 140 142 141 143 #include "MTriggerPattern.h" … … 147 149 const UShort_t MPedCalcPedRun::fgExtractWinFirst = 0; 148 150 const UShort_t MPedCalcPedRun::fgExtractWinSize = 6; 151 149 152 const UInt_t MPedCalcPedRun::gkFirstRunWithFinalBits = 45605; 153 150 154 // -------------------------------------------------------------------------- 151 155 // 152 156 // Default constructor: 153 157 // 154 // Sets:155 // - all pointers to NULL156 // - fWindowSizeHiGain to fgHiGainWindowSize157 // - fWindowSizeLoGain to fgLoGainWindowSize158 //159 158 // Calls: 160 // - AddToBranchList("fHiGainPixId"); 161 // - AddToBranchList("fHiGainFadcSamples"); 162 // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast) 159 // - SetExtractWindow(fgExtractWinFirst, fgExtractWinSize) 163 160 // 164 161 MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title) 165 : fOverlap(0), fIsFirstPedRun(kFALSE), fUsedEvents(0), fTrigPattern(NULL) 166 { 167 fName = name ? name : "MPedCalcPedRun"; 168 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 169 170 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize); 171 172 // SetNumEventsDump(1001); 173 // SetNumAreasDump(1001); 174 // SetNumSectorsDump(1001); 175 } 176 177 // -------------------------------------------------------------------------- 178 // 179 // In case that the variables fExtractLast is greater than the number of 180 // High-Gain FADC samples obtained from the run header, the flag 181 // fOverlap is set to the difference and fExtractLast is set back by the 182 // same number of slices. 183 // 184 void MPedCalcPedRun::CheckExtractionWindow() 185 { 186 const UShort_t lastavailable = fRunHeader->GetNumSamplesHiGain()-1; 187 188 if (fExtractWinLast <= lastavailable) 189 return; 190 191 const UShort_t diff = fExtractWinLast - lastavailable; 192 193 *fLog << warn << endl; 194 *fLog << "Selected ExtractWindow [" << fExtractWinFirst << "," << fExtractWinLast; 195 *fLog << "] ranges out of range [0," << lastavailable << "]." << endl; 196 *fLog << "Using " << diff << " samples from the 'Lo-Gain' slices for the pedestal extraction" << endl; 197 198 fExtractWinLast -= diff; 199 fOverlap = diff; 200 } 201 162 : fIsFirstPedRun(kFALSE), fUsedEvents(0), fTrigPattern(NULL) 163 { 164 fName = name ? name : "MPedCalcPedRun"; 165 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 166 167 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize); 168 } 169 170 // -------------------------------------------------------------------------- 171 // 172 // Call MExtractPedestal::reset and set fUsedEvents to 0. 173 // 202 174 void MPedCalcPedRun::Reset() 203 175 { 204 205 MExtractPedestal::ResetArrays(); 206 fUsedEvents = 0; 176 MExtractPedestal::ResetArrays(); 177 fUsedEvents = 0; 207 178 } 208 179 … … 213 184 Int_t MPedCalcPedRun::PreProcess(MParList *pList) 214 185 { 215 216 fUsedEvents = 0; 217 fIsFirstPedRun = kTRUE; 218 fIsNotPedRun = kFALSE; 219 220 fTrigPattern = (MTriggerPattern*)pList->FindObject("MTriggerPattern"); 221 if (!fTrigPattern) 222 *fLog << inf << "MTriggerPattern not found... Cannot use interlaced pedestal events." << endl; 223 224 return MExtractPedestal::PreProcess(pList); 186 fUsedEvents = 0; 187 fIsFirstPedRun = kTRUE; 188 fIsNotPedRun = kFALSE; 189 190 fTrigPattern = (MTriggerPattern*)pList->FindObject("MTriggerPattern"); 191 if (!fTrigPattern) 192 *fLog << inf << "MTriggerPattern not found... Cannot use interlaced pedestal events." << endl; 193 194 return MExtractPedestal::PreProcess(pList); 225 195 } 226 196 … … 232 202 Bool_t MPedCalcPedRun::ReInit(MParList *pList) 233 203 { 234 235 if (!MExtractPedestal::ReInit(pList)) 236 return kFALSE; 237 238 CheckExtractionWindow(); 239 240 // 241 // If this is the first ped run, the next run (call to ReInit) 242 // is not the first anymore 243 // 244 switch (fRunHeader->GetRunType()) 245 { 246 case MRawRunHeader::kRTPedestal: 247 case MRawRunHeader::kRTMonteCarlo: 248 fIsFirstPedRun = kFALSE; 249 fIsNotPedRun = kFALSE; 250 return kTRUE; 251 252 case MRawRunHeader::kRTCalibration: 253 { 254 TString proj(fRunHeader->GetProjectName()); 255 proj.ToLower(); 256 257 // test if a continuous light run has been declared as calibration... 258 if (proj.Contains("cl")) 259 { 260 fIsFirstPedRun = kFALSE; 261 fIsNotPedRun = kFALSE; 262 return kTRUE; 263 } 264 } 265 } 266 267 fIsNotPedRun = kTRUE; 268 269 // 270 // If this is the first call to ReInit (before reading the first file) 271 // nothing should be done. It occurs for the case that the first treated 272 // file is not of pedestal type. 273 // 274 if (fIsFirstPedRun) 204 if (!MExtractPedestal::ReInit(pList)) 205 return kFALSE; 206 207 // 208 // If this is the first ped run, the next run (call to ReInit) 209 // is not the first anymore 210 // 211 switch (fRunHeader->GetRunType()) 212 { 213 case MRawRunHeader::kRTPedestal: 214 case MRawRunHeader::kRTMonteCarlo: 215 fIsFirstPedRun = kFALSE; 216 fIsNotPedRun = kFALSE; 217 return kTRUE; 218 219 case MRawRunHeader::kRTCalibration: 220 { 221 TString proj(fRunHeader->GetProjectName()); 222 proj.ToLower(); 223 224 // test if a continuous light run has been declared as calibration... 225 if (proj.Contains("cl")) 226 { 227 fIsFirstPedRun = kFALSE; 228 fIsNotPedRun = kFALSE; 229 return kTRUE; 230 } 231 } 232 } 233 234 fIsNotPedRun = kTRUE; 235 236 // 237 // If this is the first call to ReInit (before reading the first file) 238 // nothing should be done. It occurs for the case that the first treated 239 // file is not of pedestal type. 240 // 241 if (fIsFirstPedRun) 242 return kTRUE; 243 244 // 245 // In the other case, produce the MPedestalCam to be use the subsequent 246 // (non-pedestal) events 247 // 248 *fLog << inf << "Finalizing pedestal calculations..." << flush; 249 250 if (!Finalize()) 251 return kFALSE; 252 253 Reset(); 254 275 255 return kTRUE; 276 277 //278 // In the other case, produce the MPedestalCam to be use the subsequent279 // (non-pedestal) events280 //281 *fLog << inf << "Finalizing pedestal calculations..." << flush;282 283 if (!Finalize())284 return kFALSE;285 286 Reset();287 288 return kTRUE;289 256 } 290 257 … … 300 267 Int_t MPedCalcPedRun::Calc() 301 268 { 302 if (fIsNotPedRun && !IsPedBitSet()) 269 if (fIsNotPedRun && !IsPedBitSet()) 270 return kTRUE; 271 272 fUsedEvents++; 273 274 MRawEvtPixelIter pixel(fRawEvt); 275 while (pixel.Next()) 276 { 277 const UInt_t idx = pixel.GetPixelId(); 278 279 if (!CheckVariation(idx)) 280 continue; 281 282 //extract pedestal 283 UInt_t ab[2]; 284 const Float_t sum = fExtractor ? 285 CalcExtractor(pixel, 0) : 286 CalcSums(pixel, 0, ab[0], ab[1]); 287 288 if (fIntermediateStorage) 289 (*fPedestalsInter)[idx].Set(sum, 0, 0, fUsedEvents); 290 291 const Float_t sqrsum = sum*sum; 292 293 fSumx[idx] += sum; 294 fSumx2[idx] += sqrsum; 295 296 fSumAB0[idx] += ab[0]; 297 fSumAB1[idx] += ab[1]; 298 299 if (fUseSpecialPixels) 300 continue; 301 302 const UInt_t aidx = (*fGeom)[idx].GetAidx(); 303 const UInt_t sector = (*fGeom)[idx].GetSector(); 304 305 fAreaSumx[aidx] += sum; 306 fAreaSumx2[aidx] += sqrsum; 307 fSectorSumx[sector] += sum; 308 fSectorSumx2[sector] += sqrsum; 309 310 fAreaSumAB0[aidx] += ab[0]; 311 fAreaSumAB1[aidx] += ab[1]; 312 fSectorSumAB0[aidx] += ab[0]; 313 fSectorSumAB1[aidx] += ab[1]; 314 } 315 316 fPedestalsOut->SetReadyToSave(); 317 303 318 return kTRUE; 304 305 // if (fUsedEvents == fNumEventsDump)306 // {307 // *fLog << endl;308 // *fLog << inf << GetDescriptor() << " : Finalize pedestal calculations..." << flush;309 // Finalize();310 // Reset();311 // }312 313 fUsedEvents++;314 315 MRawEvtPixelIter pixel(fRawEvt);316 317 while (pixel.Next())318 {319 const UInt_t idx = pixel.GetPixelId();320 321 Float_t sum = 0.;322 UInt_t ab0 = 0;323 UInt_t ab1 = 0;324 325 if (fExtractor)326 CalcExtractor(pixel, sum, (*fPedestalsIn)[idx]);327 else328 CalcSums(pixel, sum, ab0, ab1);329 330 fSumx[idx] += sum;331 332 if (fIntermediateStorage)333 (*fPedestalsInter)[idx].Set(sum,0.,0.,fUsedEvents);334 335 const Float_t sqrsum = sum*sum;336 337 fSumx2[idx] += sqrsum;338 fSumAB0[idx] += ab0;339 fSumAB1[idx] += ab1;340 341 if (fUseSpecialPixels)342 continue;343 344 const UInt_t aidx = (*fGeom)[idx].GetAidx();345 const UInt_t sector = (*fGeom)[idx].GetSector();346 347 fAreaSumx[aidx] += sum;348 fSectorSumx[sector] += sum;349 350 fAreaSumx2[aidx] += sqrsum;351 fSectorSumx2[sector] += sqrsum;352 353 fAreaSumAB0[aidx] += ab0;354 fAreaSumAB1[aidx] += ab1;355 356 fSectorSumAB0[aidx] += ab0;357 fSectorSumAB1[aidx] += ab1;358 }359 360 fPedestalsOut->SetReadyToSave();361 362 return kTRUE;363 }364 365 366 void MPedCalcPedRun::CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped)367 {368 const Bool_t abflag = pixel.HasABFlag();369 370 Byte_t *first = pixel.GetHiGainSamples() + fExtractWinFirst;371 Byte_t *logain = pixel.GetLoGainSamples();372 373 Byte_t sat = 0;374 375 Float_t dummy;376 fExtractor->FindTimeAndChargeHiGain(first,logain,sum,dummy,dummy,dummy,sat,ped,abflag);377 }378 379 void MPedCalcPedRun::CalcSums(const MRawEvtPixelIter &pixel, Float_t &sum, UInt_t &ab0, UInt_t &ab1)380 {381 382 Byte_t *higain = pixel.GetHiGainSamples() + fExtractWinFirst;383 Byte_t *ptr = higain;384 Byte_t *end = ptr + fExtractWinSize;385 386 const Bool_t abflag = pixel.HasABFlag();387 388 Int_t sumi = 0;389 390 Int_t cnt = 0;391 do392 {393 sumi += *ptr;394 if (!pixel.IsABFlagValid())395 continue;396 397 const Int_t abFlag = (fExtractWinFirst + abflag + cnt) & 0x1;398 if (abFlag)399 ab1 += *ptr;400 else401 ab0 += *ptr;402 403 cnt++;404 } while (++ptr != end);405 406 if (fOverlap != 0)407 {408 ptr = pixel.GetLoGainSamples();409 end = ptr + fOverlap;410 411 do412 {413 sumi += *ptr;414 if (!pixel.IsABFlagValid())415 continue;416 417 const Int_t abFlag = (fExtractWinFirst + abflag + cnt) & 0x1;418 if (abFlag)419 ab1 += *ptr;420 else421 ab0 += *ptr;422 423 cnt++;424 } while (++ptr != end);425 }426 427 sum = (Float_t)sumi;428 319 } 429 320 … … 472 363 } 473 364 365 //----------------------------------------------------------------------- 366 // 367 // PostProcess MExtractPedestal and call Finalize 368 // 474 369 Int_t MPedCalcPedRun::PostProcess() 475 370 { … … 501 396 } 502 397 398 //----------------------------------------------------------------------- 399 // 503 400 void MPedCalcPedRun::Print(Option_t *o) const 504 401 { 505 402 MExtractPedestal::Print(o); 506 403 507 const Int_t last = fExtractor508 ? fExtractWinFirst + fExtractor->GetWindowSizeHiGain() -1509 : fExtractWinLast;510 511 *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << last << " incl." << endl;512 *fLog << "Num overlap lo-gain slices: " << fOverlap << endl;513 404 *fLog << "First pedrun out of sequence: " << (fIsFirstPedRun?"yes":"no") << endl; 514 405 *fLog << "Number of used events so far: " << fUsedEvents << endl; -
trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h
r5887 r8151 7 7 8 8 class MTriggerPattern; 9 class MRawEvtPixelIter;10 9 class MPedestalPix; 11 10 … … 16 15 static const UShort_t fgExtractWinSize; // Extraction Size Hi-Gain (currently set to: 14) 17 16 static const UInt_t gkFirstRunWithFinalBits; // First Run with pedestal trigger bit at place 3 18 19 UShort_t fOverlap; // Number of overlapping slices from High-Gain to Low-Gain20 17 21 18 Bool_t fIsFirstPedRun; //! Flag to tell if the first run out of many is used … … 32 29 Int_t PostProcess(); 33 30 34 void CheckExtractionWindow();35 void CalcSums(const MRawEvtPixelIter &pixel, Float_t &sum, UInt_t &ab0, UInt_t &ab1);36 void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped);31 //void CheckExtractionWindow(); 32 //UInt_t CalcSums(const MRawEvtPixelIter &pixel, UInt_t &ab0, UInt_t &ab1); 33 //void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped); 37 34 38 35 public: -
trunk/MagicSoft/Mars/mpedestal/Makefile
r5847 r8151 40 40 MPedestalCam.cc \ 41 41 MPedestalPix.cc \ 42 MHPedestalCor.cc \ 43 MPedestalSubtract.cc \ 44 MPedestalSubtractedEvt.cc \ 42 45 MPedCalcFromData.cc 43 46 -
trunk/MagicSoft/Mars/mpedestal/PedestalLinkDef.h
r5477 r8151 17 17 #pragma link C++ class MPedestalCam+; 18 18 #pragma link C++ class MPedestalPix+; 19 #pragma link C++ class MPedestalSubtract+; 20 #pragma link C++ class MPedestalSubtractedEvt+; 19 21 #pragma link C++ class MPedCalcFromData+; 20 22 23 #pragma link C++ class MHPedestalCor+; 24 21 25 #endif
Note:
See TracChangeset
for help on using the changeset viewer.