Changeset 5378 for trunk/MagicSoft/Mars/mpedestal
- Timestamp:
- 11/11/04 09:47:56 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mpedestal
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc
r5372 r5378 31 31 ///////////////////////////////////////////////////////////////////////////// 32 32 // 33 //34 //35 33 // MPedCalcLoGain 36 //37 34 // 38 35 // This task is devide form MPedCalcPedRun, described below. However, It … … 157 154 using namespace std; 158 155 159 const Int_t MPedCalcFromLoGain::fgCheckWinFirst =0;160 const Int_t MPedCalcFromLoGain::fgCheckWinLast= 29;161 const Int_t MPedCalcFromLoGain::fgExtractWinFirst= 15;162 const Int_t MPedCalcFromLoGain::fgExtractWinSize =6;163 const Int_t MPedCalcFromLoGain::fgMaxSignalVar= 40;156 const UShort_t MPedCalcFromLoGain::fgCheckWinFirst = 0; 157 const UShort_t MPedCalcFromLoGain::fgCheckWinLast = 29; 158 const UShort_t MPedCalcFromLoGain::fgExtractWinFirst = 15; 159 const UShort_t MPedCalcFromLoGain::fgExtractWinSize = 6; 160 const UShort_t MPedCalcFromLoGain::fgMaxSignalVar = 40; 164 161 165 162 // -------------------------------------------------------------------------- … … 177 174 // 178 175 MPedCalcFromLoGain::MPedCalcFromLoGain(const char *name, const char *title) 179 : fGeom(NULL), fPedContainerName("MPedestalCam") 180 { 181 182 fName = name ? name : "MPedCalcFromLoGain"; 183 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 184 185 AddToBranchList("fHiGainPixId"); 186 AddToBranchList("fHiGainFadcSamples"); 187 188 SetCheckRange(fgCheckWinFirst, fgCheckWinLast); 189 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize); 190 191 SetMaxSignalVar(fgMaxSignalVar); 192 SetPedestalUpdate(kTRUE); 193 Clear(); 194 176 : fGeom(NULL), fNamePedestalCam("MPedestalCam") 177 { 178 fName = name ? name : "MPedCalcFromLoGain"; 179 fTitle = title ? title : "Task to calculate pedestals from lo-gains"; 180 181 AddToBranchList("fHiGainPixId"); 182 AddToBranchList("fLoGainPixId"); 183 AddToBranchList("fHiGainFadcSamples"); 184 AddToBranchList("fLoGainFadcSamples"); 185 186 SetCheckRange(fgCheckWinFirst, fgCheckWinLast); 187 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize); 188 189 SetMaxSignalVar(fgMaxSignalVar); 190 SetPedestalUpdate(kTRUE); 191 192 Clear(); 193 } 194 195 void MPedCalcFromLoGain::ResetArrays() 196 { 197 // Reset contents of arrays. 198 fSumx.Reset(); 199 fSumx2.Reset(); 200 fSumAB0.Reset(); 201 fSumAB1.Reset(); 202 fNumEventsUsed.Reset(); 203 fTotalCounter.Reset(); 195 204 } 196 205 … … 219 228 // If the size is yet set, set the size 220 229 if (fSumx.GetSize()>0) 221 { 222 // Reset contents of arrays. 223 fSumx.Reset(); 224 fSumx2.Reset(); 225 fSumAB0.Reset(); 226 fSumAB1.Reset(); 227 fNumEventsUsed.Reset(); 228 fTotalCounter.Reset(); 229 } 230 ResetArrays(); 230 231 } 231 232 … … 237 238 // Exits, if the the last argument is smaller than the first 238 239 // 239 void MPedCalcFromLoGain::SetCheckRange(Int_t chfirst, Int_t chlast) 240 { 241 242 if(chfirst<0) 243 { 244 *fLog << warn << GetDescriptor() 245 << ": First slice in window to check for Signal <0, adjust:" << endl; 246 exit(-1); 247 } 248 249 if(chlast<=chfirst) 250 { 251 *fLog << warn << GetDescriptor() 252 << ": Last slice in Check window smaller than first slice in window, adjust:" << endl; 253 exit(-1); 254 } 255 256 fCheckWinFirst = chfirst; 257 fCheckWinLast = chlast; 258 259 } 260 261 // -------------------------------------------------------------------------- 262 // 263 // Exits: 240 Bool_t MPedCalcFromLoGain::SetCheckRange(UShort_t chfirst, UShort_t chlast) 241 { 242 Bool_t rc = kTRUE; 243 244 if (chlast<=chfirst) 245 { 246 *fLog << warn << GetDescriptor(); 247 *fLog << " - WARNING: Last slice in SetCheckRange smaller than first slice... set to first+2" << endl; 248 chlast = chfirst+1; 249 rc = kFALSE; 250 } 251 252 fCheckWinFirst = chfirst; 253 fCheckWinLast = chlast; 254 255 return rc; 256 } 257 258 // -------------------------------------------------------------------------- 259 // 260 // Checks: 264 261 // - if a window is odd 265 // 266 void MPedCalcFromLoGain::SetExtractWindow(Int_t windowf, Int_t windows) 267 { 268 269 if(windowf<0) 270 { 271 *fLog << warn << GetDescriptor() 272 << Form(": First slice in Extract window has to be >0, adjust:")<< endl; 273 exit(-1); 274 } 275 276 Int_t odd = windows & 0x1; 277 278 if (odd||(windows==0)) 279 { 280 *fLog << warn << GetDescriptor() << ": Extract window size has to be even and larger 0, adjust!"<< endl; 281 exit(-1); 282 } 283 284 fExtractWinSize = windows; 285 fExtractWinFirst = windowf; 286 fExtractWinLast = fExtractWinFirst+fExtractWinSize-1; 287 262 // 263 Bool_t MPedCalcFromLoGain::SetExtractWindow(UShort_t windowf, UShort_t windows) 264 { 265 Bool_t rc = kTRUE; 266 267 const Int_t odd = windows & 0x1; 268 269 if (odd || windows==0) 270 { 271 *fLog << warn << GetDescriptor(); 272 *fLog << " - WARNING: Window size in SetExtraxtWindow has to be even and > 0... adjusting!" << endl; 273 windows += 1; 274 rc = kFALSE; 275 } 276 277 fExtractWinSize = windows; 278 fExtractWinFirst = windowf; 279 fExtractWinLast = fExtractWinFirst+fExtractWinSize-1; 280 281 // 282 // NO RANGE CHECK IMPLEMENTED, YET 283 // 288 284 /* 289 285 const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1; … … 309 305 fWindowSizeLoGain = availlorange; 310 306 } 311 */ 307 */ 308 309 return rc; 312 310 } 313 311 … … 330 328 Clear(); 331 329 332 fRawEvt = (MRawEvtData*)pList->FindObject( "MRawEvtData");330 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData")); 333 331 if (!fRawEvt) 334 332 { 335 *fLog << err << "MRawEvtDatanot found... aborting." << endl;333 *fLog << err << AddSerialNumber("MRawEvtData") << " not found... aborting." << endl; 336 334 return kFALSE; 337 335 } … … 344 342 } 345 343 346 fGeom = (MGeomCam*)pList->FindObject( "MGeomCam");344 fGeom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam")); 347 345 if (!fGeom) 348 346 { 349 *fLog << err << "MGeomCamnot found... aborting." << endl;347 *fLog << err << AddSerialNumber("MGeomCam") << " not found... aborting." << endl; 350 348 return kFALSE; 351 349 } 352 350 353 354 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fPedContainerName)); 351 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam", AddSerialNumber(fNamePedestalCam)); 355 352 if (!fPedestals) 356 353 return kFALSE; 357 354 358 359 *fLog << inf << "Parameters used for pedestal calculation:"<<endl; 360 *fLog << inf <<"Flag Pedestal Update: "<<fPedestalUpdate<<endl; 361 *fLog << inf <<"CheckWindow: First slice: "<<fCheckWinFirst<<"; Last slice: "<<fCheckWinLast<<endl; 362 *fLog << inf <<"ExtractWindow: First slice: "<<fExtractWinFirst<<"; Last slice: "<<fExtractWinLast<<endl; 363 *fLog << inf <<"Max allowed signal variation: "<<fMaxSignalVar<<endl; 355 *fLog << inf; 356 Print(); 357 364 358 return kTRUE; 365 359 } … … 384 378 Bool_t MPedCalcFromLoGain::ReInit(MParList *pList) 385 379 { 386 387 Int_t lastavailableslice = (Int_t)fRunHeader->GetNumSamplesHiGain() 388 +(Int_t)fRunHeader->GetNumSamplesLoGain()-1; 389 Int_t lastextractslice = fExtractWinSize+ fExtractWinFirst - 1; 390 391 if ( lastextractslice > lastavailableslice ) //changed to override check 392 { 393 *fLog << endl; 394 *fLog << warn << GetDescriptor() 395 << Form(": Selected Extract Window ranges out of the available limits adjust. Last available slice is %2i", 396 lastavailableslice) << endl; 397 return kFALSE; 398 } 399 400 if ( fCheckWinLast > lastavailableslice ) //changed to override check 401 { 402 *fLog << endl; 403 *fLog << warn << GetDescriptor() 404 << Form(": Last Check Window slice is out of the available limits adjust. Last available slice is %2i", 405 lastavailableslice) << endl; 406 return kFALSE; 407 } 408 409 410 380 Int_t lastavailableslice = fRunHeader->GetNumSamplesHiGain()+fRunHeader->GetNumSamplesLoGain()-1; 381 Int_t lastextractslice = fExtractWinSize + fExtractWinFirst - 1; 382 383 if (lastextractslice>lastavailableslice)//changed to override check 384 { 385 *fLog << warn << GetDescriptor(); 386 *fLog << " - WARNING: Selected Extract Window ranges out of range...adjusting to last available slice "; 387 *fLog << lastavailableslice << endl; 388 389 lastextractslice=lastavailableslice; 390 } 391 392 if (fCheckWinLast>lastavailableslice)//changed to override check 393 { 394 *fLog << warn << GetDescriptor(); 395 *fLog << " - WARNING: Last Check Window slice out of range...adjusting to last available slice "; 396 *fLog << lastavailableslice << endl; 397 398 fCheckWinLast=lastavailableslice; 399 } 400 401 411 402 // If the size is not yet set, set the size 412 403 if (fSumx.GetSize()==0) … … 421 412 fTotalCounter.Set(npixels); 422 413 423 // Reset contents of arrays. 424 fSumx.Reset(); 425 fSumx2.Reset(); 426 fSumAB0.Reset(); 427 fSumAB1.Reset(); 428 fNumEventsUsed.Reset(); 429 fTotalCounter.Reset(); 414 ResetArrays(); 430 415 } 431 416 … … 473 458 // Returns the pointer to slice "slice". 474 459 // 475 UInt_t MPedCalcFromLoGain::GetSlice(MRawEvtPixelIter *pixel, UInt_t slice) 476 { 477 478 const UInt_t nh = (Int_t)fRunHeader->GetNumSamplesHiGain(); 479 480 Byte_t *ptr; 481 482 if(slice>=nh) 483 { 484 ptr = pixel->GetLoGainSamples(); 485 ptr += slice - nh; 486 } 487 else 488 { 489 ptr = pixel->GetHiGainSamples(); 490 ptr += slice; 491 } 460 UShort_t MPedCalcFromLoGain::GetSlice(MRawEvtPixelIter *pixel, UInt_t slice) 461 { 462 const UShort_t nh = (Int_t)fRunHeader->GetNumSamplesHiGain(); 463 464 Byte_t *ptr; 465 466 if(slice<nh) 467 ptr = pixel->GetHiGainSamples() + slice; 468 else 469 ptr = pixel->GetLoGainSamples() + slice - nh; 492 470 493 471 return *ptr; … … 506 484 while (pixel.Next()) 507 485 { 508 509 const UInt_t idx = pixel.GetPixelId(); 510 511 Int_t max = 0; 512 Int_t min = 1025; 513 486 const UInt_t idx = pixel.GetPixelId(); 487 488 UShort_t max = 0; 489 UShort_t min = (UShort_t)-1; 490 514 491 // Find the maximum and minimum signal per slice in the high gain window 515 516 for(Int_t slice=fCheckWinFirst; slice<=fCheckWinLast; slice++) 517 { 518 519 Int_t svalue = GetSlice(&pixel,slice); 520 if (svalue > max) { 492 for (Int_t slice=fCheckWinFirst; slice<=fCheckWinLast; slice++) 493 { 494 const UShort_t svalue = GetSlice(&pixel,slice); 495 if (svalue > max) 521 496 max = svalue; 522 } 523 if (svalue < min) { 497 if (svalue < min) 524 498 min = svalue; 525 }526 499 } 527 500 … … 535 508 //extract pedestal 536 509 for(Int_t slice=fExtractWinFirst; slice<=fExtractWinLast; slice++) 537 { 538 539 540 510 { 511 const UInt_t svalue = GetSlice(&pixel,slice); 512 sum += svalue; 513 sqr += svalue*svalue; 541 514 } 542 515 543 const Float_t msum = (Float_t)sum; 544 const Float_t sqrsum = msum*msum; 545 546 fSumx[idx] += msum; 547 fSumx2[idx] += sqrsum; 516 fSumx[idx] += sum; 517 fSumx2[idx] += sum*sum; 518 548 519 fNumEventsUsed[idx]++; 549 520 550 521 // Calculate the amplitude of the 150MHz "AB" noise 551 552 Int_t abFlag = (fExtractWinFirst + pixel.HasABFlag()) & 0x1; 553 554 //cout << " MPedCalcFromLoGain: idx: " << idx << " abFlag: " << abFlag << endl; 555 556 for (Int_t islice=fExtractWinFirst; islice<=fExtractWinLast; islice+=2) 522 UShort_t abFlag = (fExtractWinFirst + pixel.HasABFlag()) & 0x1; 523 524 for (UShort_t islice=fExtractWinFirst; islice<=fExtractWinLast; islice+=2) 557 525 { 558 Int_t sliceAB0 = islice + abFlag;559 Int_t sliceAB1 = islice - abFlag + 1;526 const UShort_t sliceAB0 = islice + abFlag; 527 const UShort_t sliceAB1 = islice - abFlag + 1; 560 528 fSumAB0[idx] += GetSlice(&pixel, sliceAB0); 561 529 fSumAB1[idx] += GetSlice(&pixel, sliceAB1); 562 530 } 563 531 564 if (!fPedestalUpdate || fNumEventsUsed[idx]<fNumEventsDump)532 if (!fPedestalUpdate || (UInt_t)fNumEventsUsed[idx]<fNumEventsDump) 565 533 continue; 566 534 … … 605 573 606 574 575 // -------------------------------------------------------------------------- 576 // 577 // The following resources are available: 578 // FirstCheckWindowSlice: 0 579 // LastCheckWindowSlice: 29 580 // ExtractWindowFirst: 15 581 // ExtractWindowSize: 6 582 // NumEventsDump: 583 // 607 584 Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 608 585 { … … 612 589 Bool_t rc=kFALSE; 613 590 614 Int_t fs = fCheckWinFirst; 591 // Find resources for CheckWindow 592 Int_t fs = fCheckWinFirst; 615 593 Int_t ls = fCheckWinLast; 616 617 if (IsEnvDefined(env, prefix, "FirstCheckWindowSlice", print)){618 fs = GetEnvValue(env, prefix, " FirstCheckWindowSlice", fs);594 if (IsEnvDefined(env, prefix, "CheckWinFirst", print)) 595 { 596 fs = GetEnvValue(env, prefix, "CheckWinFirst", fs); 619 597 rc = kTRUE; 620 598 } 621 if (IsEnvDefined(env, prefix, "LastCheckWindowSlice", print)){ 622 ls = GetEnvValue(env, prefix, "LastCheckWindowSlice", ls); 599 if (IsEnvDefined(env, prefix, "CheckWinLast", print)) 600 { 601 ls = GetEnvValue(env, prefix, "CheckWinLast", ls); 623 602 rc = kTRUE; 624 603 } … … 626 605 SetCheckRange(fs,ls); 627 606 628 607 // Find resources for ExtractWindow 629 608 Int_t lw = fExtractWinSize; 630 609 Int_t wf = fExtractWinFirst; 631 632 if (IsEnvDefined(env, prefix, "ExtractWindowSize", print)){633 lw = GetEnvValue(env, prefix, "ExtractWindowSize", lw);634 rc = kTRUE;635 } 636 637 if (IsEnvDefined(env, prefix, "ExtractWin dowFirst", print)){638 wf = GetEnvValue(env, prefix, "ExtractWindowFirst", wf);639 rc = kTRUE;640 }641 610 if (IsEnvDefined(env, prefix, "ExtractWinSize", print)) 611 { 612 lw = GetEnvValue(env, prefix, "ExtractWinSize", lw); 613 rc = kTRUE; 614 } 615 616 if (IsEnvDefined(env, prefix, "ExtractWinFirst", print)) 617 { 618 wf = GetEnvValue(env, prefix, "ExtractWinFirst", wf); 619 rc = kTRUE; 620 } 642 621 SetExtractWindow(wf,lw); 643 622 644 Int_t num = fNumEventsDump;623 // find resource for numeventsdump 645 624 if (IsEnvDefined(env, prefix, "NumEventsDump", print)) 646 625 { 647 num = GetEnvValue(env, prefix, "NumEventsDump", num);626 SetNumEventsDump(GetEnvValue(env, prefix, "NumEventsDump", (Int_t)fNumEventsDump)); 648 627 rc = kTRUE; 649 628 } 650 SetNumEventsDump(num); 651 652 Int_t max = fMaxSignalVar; 629 630 // find resource for maximum signal variation 653 631 if (IsEnvDefined(env, prefix, "MaxSignalVar", print)) 654 632 { 655 max = GetEnvValue(env, prefix, "MaxSignalVar", max);633 SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar)); 656 634 rc = kTRUE; 657 635 } 658 SetMaxSignalVar(max); 659 660 Bool_t upd = fPedestalUpdate; 636 637 // find resource for pedestal update 661 638 if (IsEnvDefined(env, prefix, "PedestalUpdate", print)) 662 639 { 663 upd = GetEnvValue(env, prefix, "PedestalUpdate", upd);640 SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate)); 664 641 rc = kTRUE; 665 642 } 666 SetPedestalUpdate(upd);667 643 668 644 return rc; 669 645 } 646 647 void MPedCalcFromLoGain::Print(Option_t *o) const 648 { 649 *fLog << GetDescriptor() << ":" << endl; 650 *fLog << "Parameters used for pedestal calculation from " << fNamePedestalCam << ":"<<endl; 651 *fLog << "CheckWindow from slice " << fCheckWinFirst << " to " << fCheckWinLast << endl; 652 *fLog << "ExtractWindow from slice " << fExtractWinFirst << " to " << fExtractWinLast << endl; 653 *fLog << "Max allowed signal variation: " << fMaxSignalVar << endl; 654 *fLog << "Pedestal Update is " << (fPedestalUpdate?"on":"off") << endl; 655 MExtractor::Print(o); 656 } -
trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h
r5372 r5378 20 20 class MPedCalcFromLoGain : public MExtractor 21 21 { 22 static const Int_t fgCheckWinFirst;// First FADC slice to check for signal (currently set to: 0)23 static const Int_t fgCheckWinLast;// Last FADC slice to check for signal (currently set to: 29)24 static const Int_t fgExtractWinFirst;// First FADC slice to use for pedestal calculation (currently set to: 15)25 static const Int_t fgExtractWinSize;// number of successive slices used to calculate pedestal (currently set to: 6)26 static const Int_t fgMaxSignalVar; // The maximum difference between the highest and lowest slice22 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 fgExtractWinFirst; // First FADC slice to use for pedestal calculation (currently set to: 15) 25 static const UShort_t fgExtractWinSize; // number of successive slices used to calculate pedestal (currently set to: 6) 26 static const UShort_t fgMaxSignalVar; // The maximum difference between the highest and lowest slice 27 27 28 Int_t fNumEventsDump; // Number of event after which MPedestalCam gets updated28 MGeomCam *fGeom; // Camera geometry 29 29 30 Int_t fMaxSignalVar; 31 Int_t fCheckWinFirst; 32 Int_t fCheckWinLast; 33 Int_t fExtractWinSize; // Number of slices to calculate the pedestal from 34 Int_t fExtractWinFirst; 35 Int_t fExtractWinLast; 30 UInt_t fNumEventsDump; // Number of event after which MPedestalCam gets updated 31 32 UShort_t fMaxSignalVar; 33 UShort_t fCheckWinFirst; 34 UShort_t fCheckWinLast; 35 UShort_t fExtractWinSize; // Number of slices to calculate the pedestal from 36 UShort_t fExtractWinFirst; 37 UShort_t fExtractWinLast; 36 38 37 39 Bool_t fPedestalUpdate; 38 40 39 MGeomCam *fGeom; // Camera geometry 40 TString fPedContainerName; // name of the 'MPedestalCam' container 41 TString fNamePedestalCam; // name of the 'MPedestalCam' container 41 42 42 43 TArrayI fNumEventsUsed; // Number of events used for pedestal calc for each pixel … … 58 59 59 60 //Helper function to extract slice values by slice number 60 UInt_t GetSlice(MRawEvtPixelIter *pixel, UInt_t slice); 61 UShort_t GetSlice(MRawEvtPixelIter *pixel, UInt_t slice); 62 void ResetArrays(); 61 63 62 64 public: … … 65 67 // TObject 66 68 void Clear(const Option_t *o=""); 69 void Print(Option_t *o="") const; 67 70 68 71 // Setter 69 void SetCheckRange(Int_t checkfirst=0, Int_t checklast=29); 70 void SetExtractWindow(Int_t extractfirst=15, Int_t windowsize=6); 71 void SetMaxSignalVar(Int_t maxvar=40) { fMaxSignalVar = maxvar; } 72 Bool_t SetCheckRange(UShort_t checkfirst=fgCheckWinFirst, UShort_t checklast=fgCheckWinLast); 73 Bool_t SetExtractWindow(UShort_t extractfirst=fgExtractWinFirst, UShort_t windowsize=fgExtractWinSize); 74 75 void SetMaxSignalVar(UShort_t maxvar=40) { fMaxSignalVar = maxvar; } 72 76 void SetNumEventsDump(UInt_t dumpevents = 500) { fNumEventsDump = dumpevents;} 73 77 void SetPedestalUpdate(Bool_t pedupdate) {fPedestalUpdate = pedupdate;} 74 78 75 void Set PedContainerName(const char *name) { fPedContainerName= name; }79 void SetNamePedestalCam(const char *name) { fNamePedestalCam = name; } 76 80 77 81 // Getter
Note:
See TracChangeset
for help on using the changeset viewer.