Changeset 4609 for trunk/MagicSoft/Mars/mpedestal
- Timestamp:
- 08/13/04 14:59:17 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mpedestal
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc
r4601 r4609 185 185 fGeom(NULL), fPedContainerName("MPedestalCam") 186 186 { 187 fName = name ? name : "MPedCalcFromLoGain"; 188 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 189 190 AddToBranchList("fHiGainPixId"); 191 AddToBranchList("fHiGainFadcSamples"); 192 193 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); 194 195 SetMaxHiGainVar(fgMaxHiGainVar); 196 SetPedestalUpdate(kTRUE); 197 Clear(); 187 fName = name ? name : "MPedCalcFromLoGain"; 188 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 189 190 AddToBranchList("fHiGainPixId"); 191 AddToBranchList("fLoGainPixId"); 192 AddToBranchList("fHiGainFadcSamples"); 193 AddToBranchList("fLoGainFadcSamples"); 194 195 SetRange(); 196 SetMaxHiGainVar(); 197 SetPedestalUpdate(kTRUE); 198 199 Clear(); 198 200 } 199 201 … … 208 210 void MPedCalcFromLoGain::Clear(const Option_t *o) 209 211 { 210 fRawEvt = NULL;211 fRunHeader = NULL;212 fPedestals = NULL;213 214 // If the size is yet set, set the size215 if (fSumx.GetSize()>0)216 {217 // Reset contents of arrays.218 fSumx.Reset();219 fSumx2.Reset();220 fSumAB0.Reset();221 fSumAB1.Reset();222 fNumEventsUsed.Reset();223 fTotalCounter.Reset();224 }212 fRawEvt = NULL; 213 fRunHeader = NULL; 214 fPedestals = NULL; 215 216 // If the size is yet set, set the size 217 if (fSumx.GetSize()>0) 218 { 219 // Reset contents of arrays. 220 fSumx.Reset(); 221 fSumx2.Reset(); 222 fSumAB0.Reset(); 223 fSumAB1.Reset(); 224 fNumEventsUsed.Reset(); 225 fTotalCounter.Reset(); 226 } 225 227 } 226 228 … … 235 237 void MPedCalcFromLoGain::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast) 236 238 { 237 MExtractor::SetRange(hifirst,hilast,lofirst,lolast);238 239 //240 // Redo the checks if the window is still inside the ranges241 //242 SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain);239 MExtractor::SetRange(hifirst, hilast, lofirst, lolast); 240 241 // 242 // Redo the checks if the window is still inside the ranges 243 // 244 SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain); 243 245 } 244 246 … … 247 249 void MPedCalcFromLoGain::SetMaxHiGainVar(Byte_t maxvar) 248 250 { 249 fMaxHiGainVar = maxvar;251 fMaxHiGainVar = maxvar; 250 252 } 251 253 … … 265 267 void MPedCalcFromLoGain::SetWindowSize(Byte_t windowh, Byte_t windowl) 266 268 { 267 fWindowSizeHiGain = windowh & ~1; 268 fWindowSizeLoGain = windowl & ~1; 269 270 if (fWindowSizeHiGain != windowh) 271 *fLog << warn << GetDescriptor() << ": Hi Gain window size has to be even, set to: " 272 << int(fWindowSizeHiGain) << " samples " << endl; 269 fWindowSizeHiGain = windowh & ~1; 270 fWindowSizeLoGain = windowl & ~1; 273 271 274 if (fWindowSizeLoGain != windowl) 275 *fLog << warn << GetDescriptor() << ": Lo Gain window size has to be even, set to: " 276 << int(fWindowSizeLoGain) << " samples " << endl; 272 if (fWindowSizeHiGain != windowh) 273 { 274 *fLog << warn; 275 *fLog << GetDescriptor() << ": HiGain window has to be even, set to: "; 276 *fLog << int(fWindowSizeHiGain) << " samples " << endl; 277 } 277 278 278 const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1; 279 const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1; 280 281 if (fWindowSizeHiGain > availhirange) 282 { 283 *fLog << warn << GetDescriptor() 284 << Form(": Hi Gain window size: %2i is bigger than available range: [%2i,%2i]", 285 (int)fWindowSizeHiGain, (int)fHiGainFirst, (int)fHiGainLast) << endl; 286 *fLog << warn << GetDescriptor() 287 << ": Will set window size to: " << (int)availhirange << endl; 288 fWindowSizeHiGain = availhirange; 289 } 279 if (fWindowSizeLoGain != windowl) 280 { 281 *fLog << warn; 282 *fLog << GetDescriptor() << ": Lo Gain window has to be even, set to: "; 283 *fLog << int(fWindowSizeLoGain) << " samples " << endl; 284 } 285 286 const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1; 287 const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1; 290 288 291 if (fWindowSizeLoGain > availlorange) 292 { 293 *fLog << warn << GetDescriptor() 294 << Form(": Lo Gain window size: %2i is bigger than available range: [%2i,%2i]", 295 (int)fWindowSizeLoGain, (int)fLoGainFirst, (int)fLoGainLast) << endl; 296 *fLog << warn << GetDescriptor() 297 << ": Will set window size to: " << (int)availlorange << endl; 298 fWindowSizeLoGain = availlorange; 299 } 300 301 fNumHiGainSamples = (Float_t)fWindowSizeHiGain; 302 fNumLoGainSamples = (Float_t)fWindowSizeLoGain; 303 304 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples); 305 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples); 289 if (fWindowSizeHiGain > availhirange) 290 { 291 *fLog << warn; 292 *fLog << GetDescriptor() << ": HiGain window " << (int)fWindowSizeHiGain; 293 *fLog << " out of range [" << (int)fHiGainFirst; 294 *fLog << "," << (int)fHiGainLast << "]" << endl; 295 *fLog << "Will set window size to " << (int)availhirange << endl; 296 fWindowSizeHiGain = availhirange; 297 } 298 299 if (fWindowSizeLoGain > availlorange) 300 { 301 *fLog << warn; 302 *fLog << GetDescriptor() << ": LoGain window " << (int)fWindowSizeLoGain; 303 *fLog << " out of range [" << (int)fLoGainFirst; 304 *fLog << "," << (int)fLoGainLast << "]" << endl; 305 *fLog << "Will set window size to " << (int)availlorange << endl; 306 fWindowSizeLoGain = availlorange; 307 } 308 /* 309 fNumHiGainSamples = (Float_t)fWindowSizeHiGain; 310 fNumLoGainSamples = (Float_t)fWindowSizeLoGain; 311 312 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples); 313 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples); 314 */ 306 315 } 307 316 … … 369 378 Bool_t MPedCalcFromLoGain::ReInit(MParList *pList) 370 379 { 371 Int_t lastdesired = (Int_t)fLoGainLast; 372 Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1; 373 374 if (lastdesired > lastavailable) 375 { 376 const Int_t diff = lastdesired - lastavailable; 377 *fLog << endl; 378 *fLog << warn << GetDescriptor() 379 << Form(": Selected Lo Gain FADC Window [%2i,%2i] ranges out of the available limits: [0,%2i].", 380 (int)fLoGainFirst, lastdesired, lastavailable) << endl; 381 *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl; 382 SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff); 383 } 384 385 lastdesired = (Int_t)fHiGainLast; 386 lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1; 387 388 if (lastdesired > lastavailable) 389 { 390 const Int_t diff = lastdesired - lastavailable; 391 *fLog << endl; 392 *fLog << warn << GetDescriptor() 393 << Form(": Selected Hi Gain Range [%2i,%2i] ranges out of the available limits: [0,%2i].", 394 (int)fHiGainFirst, lastdesired, lastavailable) << endl; 395 *fLog << warn << GetDescriptor() 396 << Form(": Will possibly use %2i samples from the Low-Gain for the High-Gain range", diff) 397 << endl; 398 fHiGainLast -= diff; 399 fHiLoLast = diff; 400 } 401 402 lastdesired = (Int_t)fHiGainFirst+fWindowSizeHiGain-1; 403 lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1; 404 405 if (lastdesired > lastavailable) 406 { 407 const Int_t diff = lastdesired - lastavailable; 408 *fLog << endl; 409 *fLog << warn << GetDescriptor() 410 << Form(": Selected Hi Gain FADC Window size %2i ranges out of the available limits: [0,%2i].", 411 (int)fWindowSizeHiGain, lastavailable) << endl; 412 *fLog << warn << GetDescriptor() 413 << Form(": Will use %2i samples from the Low-Gain for the High-Gain extraction", diff) 414 << endl; 415 416 if ((Int_t)fWindowSizeHiGain > diff) 417 { 418 fWindowSizeHiGain -= diff; 419 fWindowSizeLoGain += diff; 420 } 421 else 422 { 423 fWindowSizeLoGain += fWindowSizeHiGain; 424 fLoGainFirst = diff-fWindowSizeHiGain; 425 fWindowSizeHiGain = 0; 426 } 427 } 428 429 430 // If the size is not yet set, set the size 431 if (fSumx.GetSize()==0) 432 { 433 const Int_t npixels = fPedestals->GetSize(); 434 435 fSumx. Set(npixels); 436 fSumx2.Set(npixels); 437 fSumAB0.Set(npixels); 438 fSumAB1.Set(npixels); 439 fNumEventsUsed.Set(npixels); 440 fTotalCounter.Set(npixels); 441 442 // Reset contents of arrays. 443 fSumx.Reset(); 444 fSumx2.Reset(); 445 fSumAB0.Reset(); 446 fSumAB1.Reset(); 447 fNumEventsUsed.Reset(); 448 fTotalCounter.Reset(); 449 } 450 451 if (fWindowSizeHiGain==0 && fWindowSizeLoGain==0) 452 { 453 *fLog << err << GetDescriptor() 454 << ": Number of extracted Slices is 0, abort ... " << endl; 455 return kFALSE; 456 } 457 458 *fLog << endl; 459 *fLog << inf << GetDescriptor() << ": Taking " << (int)fWindowSizeHiGain 460 << " HiGain FADC samples starting with slice: " << (int)fHiGainFirst << endl; 461 *fLog << inf << GetDescriptor() << ": Taking " << (int)fWindowSizeLoGain 462 << " LoGain FADC samples starting with slice: " << (int)fLoGainFirst << endl; 463 464 return kTRUE; 380 if (fRunHeader->GetNumSamplesHiGain()<1) 381 { 382 *fLog << err << "ERROR - Number of available HiGainSamples<1... abort." << endl; 383 return kFALSE; 384 } 385 if (fRunHeader->GetNumSamplesLoGain()<1) 386 { 387 *fLog << err << "ERROR - Number of available LoGainSamples<1... abort." << endl; 388 return kFALSE; 389 } 390 391 fHiGainFirst = TMath::Max(fHiGainFirst, 0); 392 fHiGainLast = TMath::Min(fHiGainLast, fRunHeader->GetNumSamplesHiGain()-1); 393 394 fLoGainFirst = TMath::Max(fLoGainFirst, 0); 395 fLoGainLast = TMath::Min(fLoGainLast, fRunHeader->GetNumSamplesLoGain()-1); 396 397 fWindowSizeHiGain = TMath::Min(fWindowSizeHiGain, fHiGainLast-fHiGainFirst+1); 398 fWindowSizeLoGain = TMath::Min(fWindowSizeLoGain, fLoGainLast-fLoGainFirst+1); 399 400 SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast); 401 402 *fLog << inf << endl; 403 *fLog << "Taking " << Form("%2d", (int)fWindowSizeHiGain) << " HiGain from " << (int)fHiGainFirst << endl; 404 *fLog << "Taking " << Form("%2d", (int)fWindowSizeLoGain) << " LoGain from " << (int)fLoGainFirst << endl; 405 406 if (fWindowSizeHiGain==0) 407 { 408 *fLog << err << "ERROR - HiGain windows size == 0... abort." << endl; 409 return kFALSE; 410 } 411 if (fWindowSizeLoGain==0) 412 { 413 *fLog << err << "ERROR - HiGain windows size == 0... abort." << endl; 414 return kFALSE; 415 } 416 417 // If the size is not yet set, set the size 418 if (fSumx.GetSize()==0) 419 { 420 const Int_t npixels = fPedestals->GetSize(); 421 422 fSumx. Set(npixels); 423 fSumx2.Set(npixels); 424 fSumAB0.Set(npixels); 425 fSumAB1.Set(npixels); 426 fNumEventsUsed.Set(npixels); 427 fTotalCounter.Set(npixels); 428 429 // Reset contents of arrays. 430 fSumx.Reset(); 431 fSumx2.Reset(); 432 fSumAB0.Reset(); 433 fSumAB1.Reset(); 434 fNumEventsUsed.Reset(); 435 fTotalCounter.Reset(); 436 } 437 438 return kTRUE; 465 439 } 466 440 … … 515 489 // Find the maximum and minimum signal per slice in the high gain window 516 490 do { 517 if (*ptr > max) {491 if (*ptr > max) 518 492 max = *ptr; 519 } 520 if (*ptr < min) { 493 if (*ptr < min) 521 494 min = *ptr; 522 }523 495 } while (++ptr != end); 524 496 … … 527 499 continue; 528 500 529 Byte_t *firstSlice = pixel.GetLoGainSamples() + fLoGainFirst; 530 Byte_t *lastSlice = firstSlice + fWindowSizeLoGain; 531 532 Byte_t *slice = firstSlice; 501 ptr = pixel.GetLoGainSamples() + fLoGainFirst; 502 end = ptr + fWindowSizeLoGain; 503 504 Byte_t *firstSlice = ptr; 505 533 506 do { 534 sum += * slice;535 sqr += * slice * *slice;536 } while (++ slice != lastSlice);507 sum += *ptr; 508 sqr += *ptr * *ptr; 509 } while (++ptr != end); 537 510 538 511 const Float_t msum = (Float_t)sum; … … 569 542 570 543 if (fPedestalUpdate) 544 { 545 fPedestals->ReCalc(*fGeom); 571 546 fPedestals->SetReadyToSave(); 547 } 572 548 573 549 return kTRUE; … … 581 557 { 582 558 // Compute pedestals and rms from the whole run 583 if (fPedestalUpdate )559 if (fPedestalUpdate || GetNumExecutions()<1) 584 560 return kTRUE; 585 561 586 *fLog << flush << inf << "Calculating Pedestals..." << flush; 562 *fLog << flush << inf << "Calculating pedestals..." << flush; 563 564 Double_t sum = 0; 587 565 588 566 const Int_t npix = fGeom->GetNumPixels(); … … 592 570 if (n>1) 593 571 Calc(n, idx); 594 } 595 572 sum += n; 573 } 574 575 *fLog << flush << inf << "Calculating means..." << flush; 576 577 fPedestals->SetTotalEntries((UInt_t)(sum/npix*(fWindowSizeLoGain+fWindowSizeHiGain))); 578 fPedestals->ReCalc(*fGeom); 596 579 fPedestals->SetReadyToSave(); 597 580 return kTRUE; … … 621 604 SetWindowSize(hw, lw); 622 605 623 Int_t num = fNumEventsDump;624 606 if (IsEnvDefined(env, prefix, "NumEventsDump", print)) 625 607 { 626 num = GetEnvValue(env, prefix, "NumEventsDump", num);608 SetDumpEvents(GetEnvValue(env, prefix, "NumEventsDump", fNumEventsDump)); 627 609 rc = kTRUE; 628 610 } 629 SetDumpEvents(num); 630 631 Byte_t max = fMaxHiGainVar; 611 632 612 if (IsEnvDefined(env, prefix, "MaxHiGainVar", print)) 633 613 { 634 max = GetEnvValue(env, prefix, "MaxHiGainVar", max);614 SetMaxHiGainVar(GetEnvValue(env, prefix, "MaxHiGainVar", fMaxHiGainVar)); 635 615 rc = kTRUE; 636 616 } 637 SetMaxHiGainVar(max); 638 639 Bool_t upd = fPedestalUpdate; 617 640 618 if (IsEnvDefined(env, prefix, "PedestalUpdate", print)) 641 619 { 642 upd = GetEnvValue(env, prefix, "PedestalUpdate", upd);620 SetPedestalUpdate(GetEnvValue(env, prefix, "PedestalUpdate", fPedestalUpdate)); 643 621 rc = kTRUE; 644 622 } 645 SetPedestalUpdate(upd);646 623 647 624 return rc; -
trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h
r4601 r4609 62 62 63 63 // Setter 64 void SetRange(Byte_t hifirst= 0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);65 void SetWindowSize(Byte_t windowh= 0, Byte_t windowl=0);66 void SetMaxHiGainVar(Byte_t maxvar= 0);64 void SetRange(Byte_t hifirst=fgHiGainFirst, Byte_t hilast=fgHiGainLast, Byte_t lofirst=fgLoGainFirst, Byte_t lolast=fgLoGainLast); 65 void SetWindowSize(Byte_t windowh=fgHiGainWindowSize, Byte_t windowl=fgLoGainWindowSize); 66 void SetMaxHiGainVar(Byte_t maxvar=fgMaxHiGainVar); 67 67 void SetDumpEvents(UInt_t dumpevents = 0) {fNumEventsDump = dumpevents;} 68 68 void SetPedestalUpdate(Bool_t pedupdate) {fPedestalUpdate = pedupdate;} -
trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
r4601 r4609 394 394 395 395 const Int_t npixels = fPedestals->GetSize(); 396 const Int_t areas = fPedestals->GetAverageAreas();397 const Int_t sectors = fPedestals->GetAverageSectors();396 // const Int_t areas = fPedestals->GetAverageAreas(); 397 // const Int_t sectors = fPedestals->GetAverageSectors(); 398 398 399 399 if (fSumx.GetSize()==0) … … 402 402 fSumx2.Set(npixels); 403 403 404 fAreaSumx. Set(areas);405 fAreaSumx2.Set(areas);406 fAreaValid.Set(areas);407 408 fSectorSumx. Set(sectors);409 fSectorSumx2.Set(sectors);410 fSectorValid.Set(sectors);404 // fAreaSumx. Set(areas); 405 // fAreaSumx2.Set(areas); 406 // fAreaValid.Set(areas); 407 408 // fSectorSumx. Set(sectors); 409 // fSectorSumx2.Set(sectors); 410 // fSectorValid.Set(sectors); 411 411 412 412 fSumx.Reset(); … … 439 439 Int_t MPedCalcPedRun::Process() 440 440 { 441 MRawEvtPixelIter pixel(fRawEvt); 442 443 while (pixel.Next()) 444 { 445 const UInt_t idx = pixel.GetPixelId(); 446 447 Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst; 448 Byte_t *end = ptr + fWindowSizeHiGain; 449 450 UInt_t sum = 0; 451 UInt_t sqr = 0; 452 453 if (fWindowSizeHiGain != 0) 454 { 455 do 456 { 457 sum += *ptr; 458 sqr += *ptr * *ptr; 459 } 460 while (++ptr != end); 461 } 462 463 if (fWindowSizeLoGain != 0) 464 { 465 ptr = pixel.GetLoGainSamples() + fLoGainFirst; 466 end = ptr + fWindowSizeLoGain; 467 468 do 469 { 470 sum += *ptr; 471 sqr += *ptr * *ptr; 472 } 473 while (++ptr != end); 474 } 475 476 const Float_t msum = (Float_t)sum; 477 478 // 479 // These three lines have been uncommented by Markus Gaug 480 // If anybody needs them, please contact me!! 481 // 482 // const Float_t higainped = msum/fNumHiGainSlices; 483 // const Float_t higainrms = TMath::Sqrt((msqr-msum*msum/fNumHiGainSlices)/(fNumHiGainSlices-1.)); 484 // (*fPedestals)[idx].Set(higainped, higainrms); 485 486 fSumx[idx] += msum; 487 // 488 // The old version: 489 // 490 // const Float_t msqr = (Float_t)sqr; 491 // fSumx2[idx] += msqr; 492 // 493 // The new version: 494 // 495 const Float_t sqrsum = msum*msum; 496 fSumx2[idx] += sqrsum; 497 } 498 499 fNumSamplesTot += fWindowSizeHiGain + fWindowSizeLoGain; 500 501 return kTRUE; 502 /* 441 503 MRawEvtPixelIter pixel(fRawEvt); 442 504 … … 445 507 const UInt_t idx = pixel.GetPixelId(); 446 508 const UInt_t aidx = (*fGeom)[idx].GetAidx(); 447 const UInt_t sector = (*fGeom)[idx].GetSector(); 509 const UInt_t sector = (*fGeom)[idx].GetSector(); 448 510 449 511 Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst; … … 490 552 fSumx[idx] += msum; 491 553 fAreaSumx[aidx] += msum; 492 fSectorSumx[sector] += msum; 554 fSectorSumx[sector] += msum; 493 555 // 494 556 // The old version: … … 502 564 fSumx2[idx] += sqrsum; 503 565 fAreaSumx2[aidx] += sqrsum; 504 fSectorSumx2[sector] += sqrsum; 566 fSectorSumx2[sector] += sqrsum; 505 567 } 506 568 507 569 fPedestals->SetReadyToSave(); 508 570 fNumSamplesTot += fWindowSizeHiGain + fWindowSizeLoGain; 509 571 */ 510 572 return kTRUE; 511 573 } … … 517 579 Int_t MPedCalcPedRun::PostProcess() 518 580 { 519 // Compute pedestals and rms from the whole run 520 const ULong_t n = fNumSamplesTot; 521 const ULong_t nevts = GetNumExecutions(); 522 523 MRawEvtPixelIter pixel(fRawEvt); 524 525 while (pixel.Next()) 526 { 527 528 const Int_t pixid = pixel.GetPixelId(); 529 const UInt_t aidx = (*fGeom)[pixid].GetAidx(); 530 const UInt_t sector = (*fGeom)[pixid].GetSector(); 531 532 fAreaValid [aidx]++; 533 fSectorValid[sector]++; 534 535 const Float_t sum = fSumx.At(pixid); 536 const Float_t sum2 = fSumx2.At(pixid); 537 const Float_t higainped = sum/n; 538 // 539 // The old version: 540 // 541 // const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.)); 542 // 543 // The new version: 544 // 545 // 1. Calculate the Variance of the sums: 546 Float_t higainVar = (sum2-sum*sum/nevts)/(nevts-1.); 547 // 2. Scale the variance to the number of slices: 548 higainVar /= (Float_t)(fWindowSizeHiGain+fWindowSizeLoGain); 549 // 3. Calculate the RMS from the Variance: 550 (*fPedestals)[pixid].Set(higainped, higainVar < 0 ? 0. : TMath::Sqrt(higainVar)); 551 552 } 581 const ULong_t nevts = GetNumExecutions(); 582 if (nevts<1) 583 { 584 *fLog << err << "ERROR - Not enough events recorded...abort." << endl; 585 return kFALSE; 586 } 587 588 *fLog << flush << inf << "Calculating pedestals..." << flush; 589 590 // Compute pedestals and rms from the whole run 591 const ULong_t n = fNumSamplesTot; 592 const ULong_t npix = fGeom->GetNumPixels(); 593 594 for (UInt_t pixidx=0; pixidx<npix; pixidx++) 595 { 596 const Float_t sum = fSumx.At(pixidx); 597 const Float_t sum2 = fSumx2.At(pixidx); 598 const Float_t higainped = sum/n; 599 // 600 // The old version: 601 // 602 // const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.)); 603 // 604 // The new version: 605 // 606 // 1. Calculate the Variance of the sums: 607 Float_t higainVar = (sum2-sum*sum/nevts)/(nevts-1.); 608 // 2. Scale the variance to the number of slices: 609 higainVar /= (Float_t)(fWindowSizeHiGain+fWindowSizeLoGain); 610 // 3. Calculate the RMS from the Variance: 611 (*fPedestals)[pixidx].Set(higainped, higainVar < 0 ? 0. : TMath::Sqrt(higainVar), 0, nevts); 612 } 613 614 *fLog << flush << inf << "Calculating means..." << flush; 615 616 fPedestals->SetTotalEntries(fNumSamplesTot); 617 fPedestals->ReCalc(*fGeom); 618 fPedestals->SetReadyToSave(); 619 620 return kTRUE; 553 621 554 622 // 555 623 // Loop over the (two) area indices to get the averaged pedestal per aidx 556 624 // 625 /* 626 627 // Compute pedestals and rms from the whole run 628 const ULong_t n = fNumSamplesTot; 629 const ULong_t nevts = GetNumExecutions(); 630 631 MRawEvtPixelIter pixel(fRawEvt); 632 633 while (pixel.Next()) 634 { 635 const Int_t pixid = pixel.GetPixelId(); 636 const UInt_t aidx = (*fGeom)[pixid].GetAidx(); 637 const UInt_t sector = (*fGeom)[pixid].GetSector(); 638 639 fAreaValid [aidx]++; 640 fSectorValid[sector]++; 641 642 const Float_t sum = fSumx.At(pixid); 643 const Float_t sum2 = fSumx2.At(pixid); 644 const Float_t higainped = sum/n; 645 // 646 // The old version: 647 // 648 // const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.)); 649 // 650 // The new version: 651 // 652 // 1. Calculate the Variance of the sums: 653 Float_t higainVar = (sum2-sum*sum/nevts)/(nevts-1.); 654 // 2. Scale the variance to the number of slices: 655 higainVar /= (Float_t)(fWindowSizeHiGain+fWindowSizeLoGain); 656 // 3. Calculate the RMS from the Variance: 657 (*fPedestals)[pixid].Set(higainped, higainVar < 0 ? 0. : TMath::Sqrt(higainVar), 0, nevts); 658 } 557 659 for (Int_t aidx=0; aidx<fAreaValid.GetSize(); aidx++) 558 660 { … … 582 684 fPedestals->GetAverageArea(aidx).Set(higainped, higainrms); 583 685 } 584 686 */ 585 687 // 586 688 // Loop over the (six) sector indices to get the averaged pedestal per sector 587 689 // 690 /* 588 691 for (Int_t sector=0; sector<fSectorValid.GetSize(); sector++) 589 692 { … … 613 716 fPedestals->GetAverageSector(sector).Set(higainped, higainrms); 614 717 } 615 616 718 fPedestals->SetTotalEntries(fNumSamplesTot); 617 719 fPedestals->SetReadyToSave(); 618 720 619 721 return kTRUE; 722 */ 620 723 } 621 724 -
trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h
r4601 r4609 33 33 TArrayD fSumx; // sum of values 34 34 TArrayD fSumx2; // sum of squared values 35 /* 35 36 TArrayD fAreaSumx; // averaged sum of values per area idx 36 37 TArrayD fAreaSumx2; // averaged sum of squared values per area idx … … 39 40 TArrayD fSectorSumx2; // averaged sum of squared values per sector 40 41 TArrayI fSectorValid; // number of valid pixel with sector idx 42 */ 41 43 42 44 Int_t PreProcess (MParList *pList); -
trunk/MagicSoft/Mars/mpedestal/MPedPhotCam.cc
r4384 r4609 229 229 void MPedPhotCam::ReCalc(const MGeomCam &geom, MBadPixelsCam *bad) 230 230 { 231 232 231 const Int_t np = GetSize(); 233 232 const Int_t ns = GetNumSectors(); 234 233 const Int_t na = GetNumAreas(); 235 236 237 234 238 235 TArrayI acnt(na); … … 243 240 TArrayD ssumr(ns); 244 241 245 246 242 for (int i=0; i<np; i++) 247 243 { 248 249 250 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun)) 251 continue; //was: .IsBad() 244 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun)) 245 continue; //was: .IsBad() 252 246 253 247 // Create sums for areas and sectors … … 268 262 ssumr[sect] += ne*rms; 269 263 scnt[sect] += ne; 270 271 272 }273 274 for (int i=0; i<ns; i++){275 if (scnt[i]>0) GetSector(i).Set(ssumx[i]/scnt[i], ssumr[i]/scnt[i], scnt[i]);276 else GetSector(i).Set(-1., -1., 0);277 } 278 279 for (int i=0; i<na; i++){280 if (acnt[i]>0)GetArea(i).Set(asumx[i]/acnt[i], asumr[i]/acnt[i], acnt[i]);281 else GetArea(i).Set(-1., -1., 0);282 }264 } 265 266 for (int i=0; i<ns; i++) 267 if (scnt[i]>0) 268 GetSector(i).Set(ssumx[i]/scnt[i], ssumr[i]/scnt[i], scnt[i]); 269 else 270 GetSector(i).Clear(); 271 272 for (int i=0; i<na; i++) 273 if (acnt[i]>0) 274 GetArea(i).Set(asumx[i]/acnt[i], asumr[i]/acnt[i], acnt[i]); 275 else 276 GetArea(i).Clear(); 283 277 } 284 278 -
trunk/MagicSoft/Mars/mpedestal/MPedPhotCam.h
r4384 r4609 51 51 void Print(Option_t *o="") const; 52 52 53 void ReCalc(const MGeomCam &geom, MBadPixelsCam *bad );53 void ReCalc(const MGeomCam &geom, MBadPixelsCam *bad=NULL); 54 54 55 55 Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const; -
trunk/MagicSoft/Mars/mpedestal/MPedestalCam.cc
r4404 r4609 35 35 #include "MPedestalPix.h" 36 36 37 #include <TArrayI.h> 38 #include <TArrayD.h> 39 37 40 #include <TClonesArray.h> 38 41 … … 43 46 44 47 #include "MGeomCam.h" 48 #include "MGeomPix.h" 49 50 #include "MBadPixelsCam.h" 51 #include "MBadPixelsPix.h" 45 52 46 53 ClassImp(MPedestalCam); … … 311 318 } 312 319 313 Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const { 314 315 if (GetSize() <= idx) 316 return kFALSE; 317 318 if (!(*this)[idx].IsValid()) 319 return kFALSE; 320 321 switch (type) { 320 // -------------------------------------------------------------------------- 321 // 322 // Calculates the avarage pedestal and pedestal rms for all sectors 323 // and pixel sizes. The geometry container is used to get the necessary 324 // geometry information (sector number, size index) If the bad pixel 325 // container is given all pixels which have the flag 'bad' are ignored 326 // in the calculation of the sector and size average. 327 // 328 void MPedestalCam::ReCalc(const MGeomCam &geom, MBadPixelsCam *bad) 329 { 330 const Int_t np = GetSize(); 331 const Int_t ns = geom.GetNumSectors(); 332 const Int_t na = geom.GetNumAreas(); 333 334 TArrayI acnt(na); 335 TArrayI scnt(ns); 336 TArrayD asumx(na); 337 TArrayD ssumx(ns); 338 TArrayD asumr(na); 339 TArrayD ssumr(ns); 340 341 for (int i=0; i<np; i++) 342 { 343 if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun)) 344 continue; //was: .IsBad() 345 346 // Create sums for areas and sectors 347 const UInt_t aidx = geom[i].GetAidx(); 348 const UInt_t sect = geom[i].GetSector(); 349 350 const MPedestalPix &pix = (*this)[i]; 351 352 const UInt_t ne = pix.GetNumEvents(); 353 const Float_t mean = pix.GetPedestal(); 354 const Float_t rms = pix.GetPedestalRms(); 355 356 asumx[aidx] += ne*mean; 357 asumr[aidx] += ne*rms; 358 acnt[aidx] += ne; 359 360 ssumx[sect] += ne*mean; 361 ssumr[sect] += ne*rms; 362 scnt[sect] += ne; 363 } 364 365 for (int i=0; i<ns; i++) 366 if (scnt[i]>0) 367 GetAverageSector(i).Set(ssumx[i]/scnt[i], ssumr[i]/scnt[i], 0, scnt[i]); 368 else 369 GetAverageSector(i).Clear(); 370 371 for (int i=0; i<na; i++) 372 if (acnt[i]>0) 373 GetAverageArea(i).Set(asumx[i]/acnt[i], asumr[i]/acnt[i], 0, acnt[i]); 374 else 375 GetAverageArea(i).Clear(); 376 } 377 378 Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const 379 { 380 if (GetSize() <= idx) 381 return kFALSE; 382 383 if (!(*this)[idx].IsValid()) 384 return kFALSE; 385 386 switch (type) 387 { 322 388 case 0: 323 val = (*this)[idx].GetPedestal();324 break;389 val = (*this)[idx].GetPedestal(); 390 break; 325 391 case 1: 326 val = fTotalEntries > 0 ?327 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries) 328 329 break;392 val = fTotalEntries > 0 ? 393 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries) 394 : (*this)[idx].GetPedestalError(); 395 break; 330 396 case 2: 331 val = (*this)[idx].GetPedestalRms();332 break;397 val = (*this)[idx].GetPedestalRms(); 398 break; 333 399 case 3: 334 val = fTotalEntries > 0 ?335 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries)/2. 336 337 break;400 val = fTotalEntries > 0 ? 401 (*this)[idx].GetPedestalRms()/TMath::Sqrt((Float_t)fTotalEntries)/2. 402 : (*this)[idx].GetPedestalRmsError(); 403 break; 338 404 default: 339 return kFALSE;405 return kFALSE; 340 406 } 341 return kTRUE;407 return kTRUE; 342 408 } 343 409 344 410 void MPedestalCam::DrawPixelContent(Int_t idx) const 345 411 { 346 *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl;347 } 412 *fLog << warn << "MPedestalCam::DrawPixelContent - not available." << endl; 413 } -
trunk/MagicSoft/Mars/mpedestal/MPedestalCam.h
r3803 r4609 13 13 class MGeomCam; 14 14 class MPedestalPix; 15 class MBadPixelsCam; 15 16 16 17 class MPedestalCam : public MParContainer, public MCamEvent … … 51 52 void InitAverageSectors ( const UInt_t i ); 52 53 54 void ReCalc(const MGeomCam &geom, MBadPixelsCam *bad=NULL); 55 53 56 void Print(Option_t *o="") const; 54 57 -
trunk/MagicSoft/Mars/mpedestal/MPedestalPix.h
r4556 r4609 37 37 Float_t GetPedestalRmsError() const { return fNumEvents>0 ? fPedestalRms/TMath::Sqrt((Float_t)fNumEvents/2) : 0; } 38 38 39 UInt_t GetNumEvents() const { return fNumEvents; } 40 39 41 Bool_t IsValid() const; 40 42
Note:
See TracChangeset
for help on using the changeset viewer.