Changeset 5487 for trunk/MagicSoft/Mars/mpedestal
- Timestamp:
- 11/27/04 16:36:36 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mpedestal
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
r5357 r5487 109 109 // MRawEvtData 110 110 // MRawRunHeader 111 // MRawEvtHeader 111 112 // MGeomCam 112 113 // … … 118 119 ///////////////////////////////////////////////////////////////////////////// 119 120 #include "MPedCalcPedRun.h" 120 #include "MExtractor.h" 121 #include "MExtractPedestal.h" 122 123 #include "MExtractTimeAndCharge.h" 121 124 122 125 #include "MParList.h" … … 126 129 127 130 #include "MRawRunHeader.h" 131 #include "MRawEvtHeader.h" 128 132 #include "MRawEvtPixelIter.h" 129 133 #include "MRawEvtData.h" … … 135 139 #include "MGeomCam.h" 136 140 141 #include "MStatusDisplay.h" 142 137 143 ClassImp(MPedCalcPedRun); 138 144 139 145 using namespace std; 140 146 141 const Byte_t MPedCalcPedRun::fgHiGainFirst = 0; 142 const Byte_t MPedCalcPedRun::fgHiGainLast = 29; 143 const Byte_t MPedCalcPedRun::fgLoGainFirst = 0; 144 const Byte_t MPedCalcPedRun::fgLoGainLast = 14; 145 const Byte_t MPedCalcPedRun::fgHiGainWindowSize = 14; 146 const Byte_t MPedCalcPedRun::fgLoGainWindowSize = 0; 147 const UShort_t MPedCalcPedRun::fgExtractWinFirst = 0; 148 const UShort_t MPedCalcPedRun::fgExtractWinSize = 6; 149 const UInt_t MPedCalcPedRun::gkFirstRunWithFinalBits = 45589; 147 150 // -------------------------------------------------------------------------- 148 151 // … … 161 164 // 162 165 MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title) 163 : fWindowSizeHiGain(fgHiGainWindowSize), 164 fWindowSizeLoGain(fgLoGainWindowSize), 165 fGeom(NULL) 166 { 167 fName = name ? name : "MPedCalcPedRun"; 168 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 169 170 AddToBranchList("fHiGainPixId"); 171 AddToBranchList("fHiGainFadcSamples"); 172 173 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); 174 Clear(); 166 { 167 fName = name ? name : "MPedCalcPedRun"; 168 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 169 170 AddToBranchList("fHiGainPixId"); 171 AddToBranchList("fHiGainFadcSamples"); 172 173 SetExtractWindow(fgExtractWinFirst, fgExtractWinSize); 174 175 Clear(); 176 177 fFirstRun = kTRUE; 178 fSkip = kFALSE; 179 fOverlap = 0; 180 fUsedEvents = 0; 181 } 182 183 184 185 void MPedCalcPedRun::ResetArrays() 186 { 187 188 MExtractPedestal::ResetArrays(); 189 fUsedEvents = 0; 175 190 } 176 191 177 192 // -------------------------------------------------------------------------- 178 193 // 179 // Sets: 180 // - fNumSamplesTot to 0 181 // - fRawEvt to NULL 182 // - fRunHeader to NULL 183 // - fPedestals to NULL 184 // 185 void MPedCalcPedRun::Clear(const Option_t *o) 186 { 187 fNumSamplesTot = 0; 188 189 fRawEvt = NULL; 190 fRunHeader = NULL; 191 fPedestals = NULL; 192 193 // If the size is yet set, set the size 194 if (fSumx.GetSize()>0) 195 { 196 // Reset contents of arrays. 197 fSumx.Reset(); 198 fSumx2.Reset(); 199 fSumAB0.Reset(); 200 fSumAB1.Reset(); 201 202 fAreaSumx. Reset(); 203 fAreaSumx2.Reset(); 204 fAreaSumAB0.Reset(); 205 fAreaSumAB1.Reset(); 206 fAreaValid.Reset(); 207 208 fSectorSumx. Reset(); 209 fSectorSumx2.Reset(); 210 fSectorSumAB0.Reset(); 211 fSectorSumAB1.Reset(); 212 fSectorValid.Reset(); 213 } 214 } 215 216 // -------------------------------------------------------------------------- 217 // 218 // SetRange: 219 // 220 // Calls: 221 // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast); 222 // - SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain); 223 // 224 void MPedCalcPedRun::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast) 225 { 226 MExtractor::SetRange(hifirst,hilast,lofirst,lolast); 227 228 // 229 // Redo the checks if the window is still inside the ranges 230 // 231 SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain); 232 } 233 234 // -------------------------------------------------------------------------- 235 // 236 // Checks: 237 // - if a window is odd, subtract one 238 // - if a window is bigger than the one defined by the ranges, set it to the available range 239 // - if a window is smaller than 2, set it to 2 240 // 241 // Sets: 242 // - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain 243 // - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain 244 // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples) 245 // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples) 246 // 247 void MPedCalcPedRun::SetWindowSize(Byte_t windowh, Byte_t windowl) 248 { 249 250 fWindowSizeHiGain = windowh & ~1; 251 fWindowSizeLoGain = windowl & ~1; 252 253 if (fWindowSizeHiGain != windowh) 254 *fLog << warn << GetDescriptor() << ": Hi Gain window size has to be even, set to: " 255 << int(fWindowSizeHiGain) << " samples " << endl; 256 257 if (fWindowSizeLoGain != windowl) 258 *fLog << warn << GetDescriptor() << ": Lo Gain window size has to be even, set to: " 259 << int(fWindowSizeLoGain) << " samples " << endl; 260 261 if (fWindowSizeHiGain == 0) 262 { 263 *fLog << warn; 264 *fLog << GetDescriptor() << ": HiGain window currently set to 0, will set it to 2 samples " << endl; 265 fWindowSizeHiGain = 2; 266 } 267 268 const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1; 269 const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1; 270 271 if (fWindowSizeHiGain > availhirange) 272 { 273 *fLog << warn << GetDescriptor() 274 << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",(int)fWindowSizeHiGain, 275 " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl; 276 *fLog << warn << GetDescriptor() 277 << ": Will set window size to: " << (int)availhirange << endl; 278 fWindowSizeHiGain = availhirange; 279 } 280 281 if (fWindowSizeLoGain > availlorange) 282 { 283 *fLog << warn << GetDescriptor() 284 << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",(int)fWindowSizeLoGain, 285 " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl; 286 *fLog << warn << GetDescriptor() 287 << ": Will set window size to: " << (int)availlorange << endl; 288 fWindowSizeLoGain = availlorange; 289 } 290 291 292 fNumHiGainSamples = (Float_t)fWindowSizeHiGain; 293 fNumLoGainSamples = (Float_t)fWindowSizeLoGain; 294 295 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples); 296 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples); 297 } 298 299 // -------------------------------------------------------------------------- 300 // 301 // Look for the following input containers: 302 // 303 // - MRawEvtData 304 // - MRawRunHeader 305 // - MGeomCam 306 // 307 // The following output containers are also searched and created if 308 // they were not found: 309 // 310 // - MPedestalCam 311 // 312 Int_t MPedCalcPedRun::PreProcess( MParList *pList ) 313 { 314 Clear(); 315 316 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData"); 317 if (!fRawEvt) 318 { 319 *fLog << err << "MRawEvtData not found... aborting." << endl; 320 return kFALSE; 321 } 322 323 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader")); 324 if (!fRunHeader) 325 { 326 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl; 327 return kFALSE; 328 } 329 330 fGeom = (MGeomCam*)pList->FindObject("MGeomCam"); 331 if (!fGeom) 332 { 333 *fLog << err << "MGeomCam not found... aborting." << endl; 334 return kFALSE; 335 } 336 337 fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam"); 338 if (!fPedestals) 339 return kFALSE; 340 341 return kTRUE; 342 } 343 344 // -------------------------------------------------------------------------- 345 // 346 // The ReInit searches for: 347 // - MRawRunHeader::GetNumSamplesHiGain() 348 // - MRawRunHeader::GetNumSamplesLoGain() 349 // 350 // In case that the variables fHiGainLast and fLoGainLast are smaller than 351 // the even part of the number of samples obtained from the run header, a 352 // warning is given an the range is set back accordingly. A call to: 353 // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or 354 // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff) 355 // is performed in that case. The variable diff means here the difference 356 // between the requested range (fHiGainLast) and the available one. Note that 357 // the functions SetRange() are mostly overloaded and perform more checks, 358 // modifying the ranges again, if necessary. 194 // In case that the variables fExtractLast is greater than the number of 195 // High-Gain FADC samples obtained from the run header, the flag 196 // fOverlap is set to the difference and fExtractLast is set back by the 197 // same number of slices. 198 // 199 // The run type is checked for "Pedestal" (run type: 1) 200 // and the variable fSkip is set in that case 359 201 // 360 202 Bool_t MPedCalcPedRun::ReInit(MParList *pList) 361 203 { 362 204 363 Int_t lastdesired = (Int_t)fLoGainLast; 364 Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1; 365 366 if (lastdesired > lastavailable) 367 { 368 const Int_t diff = lastdesired - lastavailable; 369 *fLog << endl; 370 *fLog << warn << GetDescriptor() 371 << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [", 372 (int)fLoGainFirst,",",lastdesired, 373 "] ranges out of the available limits: [0,",lastavailable,"].") << endl; 374 *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl; 375 SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff); 376 } 377 378 lastdesired = (Int_t)fHiGainLast; 379 lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1; 380 381 if (lastdesired > lastavailable) 382 { 383 const Int_t diff = lastdesired - lastavailable; 205 MExtractPedestal::ReInit(pList); 206 207 const UShort_t lastavailable = fRunHeader->GetNumSamplesHiGain()-1; 208 209 if (fExtractWinLast > lastavailable) 210 { 211 const UShort_t diff = fExtractWinLast - lastavailable; 384 212 *fLog << endl; 385 213 *fLog << warn << GetDescriptor() 386 << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain Range[",387 (int)fHiGainFirst,",",lastdesired,388 "] ranges out of theavailable limits: [0,",lastavailable,"].") << endl;214 << Form("%s%2i%s%2i%s%2i%s",": Selected ExtractWindow [", 215 fExtractWinFirst,",",fExtractWinLast, 216 "] ranges out of available limits: [0,",lastavailable,"].") << endl; 389 217 *fLog << warn << GetDescriptor() 390 << Form("%s%2i%s",": Will possibly use ",diff," samples from the Low-Gain for the High-Gain range")218 << Form("%s%2i%s",": Will use ",diff," samples from the 'Low-Gain' slices for the pedestal extraction") 391 219 << endl; 392 fHiGainLast -= diff; 393 fHiLoLast = diff; 394 } 395 396 lastdesired = (Int_t)fHiGainFirst+fWindowSizeHiGain-1; 397 lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1; 398 399 if (lastdesired > lastavailable) 400 { 401 const Int_t diff = lastdesired - lastavailable; 402 *fLog << endl; 403 *fLog << warn << GetDescriptor() 404 << Form("%s%2i%s%2i%s",": Selected Hi Gain FADC Window size ", 405 (int)fWindowSizeHiGain, 406 " ranges out of the available limits: [0,",lastavailable,"].") << endl; 407 *fLog << warn << GetDescriptor() 408 << Form("%s%2i%s",": Will use ",diff," samples from the Low-Gain for the High-Gain extraction") 409 << endl; 410 411 if ((Int_t)fWindowSizeHiGain > diff) 220 fExtractWinLast -= diff; 221 fOverlap = diff; 222 } 223 224 const UShort_t runtype = fRunHeader->GetRunType(); 225 226 switch (runtype) 227 { 228 case 1: 229 fFirstRun = kFALSE; 230 fSkip = kFALSE; 231 return kTRUE; 232 break; 233 default: 234 fSkip = kTRUE; 235 if (!fFirstRun) 412 236 { 413 fWindowSizeHiGain -= diff; 414 fWindowSizeLoGain += diff; 237 *fLog << endl; 238 *fLog << inf << GetDescriptor() << " : Finalize pedestal calculations..." << flush; 239 CallPostProcess(); 240 Reset(); 415 241 } 416 else 417 { 418 fWindowSizeLoGain += fWindowSizeHiGain; 419 fLoGainFirst = diff-fWindowSizeHiGain; 420 fWindowSizeHiGain = 0; 421 } 422 } 423 424 425 const Int_t npixels = fPedestals->GetSize(); 426 const Int_t areas = fPedestals->GetAverageAreas(); 427 const Int_t sectors = fPedestals->GetAverageSectors(); 428 429 if (fSumx.GetSize()==0) 430 { 431 fSumx. Set(npixels); 432 fSumx2. Set(npixels); 433 fSumAB0.Set(npixels); 434 fSumAB1.Set(npixels); 435 436 fAreaSumx. Set(areas); 437 fAreaSumx2. Set(areas); 438 fAreaSumAB0.Set(areas); 439 fAreaSumAB1.Set(areas); 440 fAreaValid. Set(areas); 441 442 fSectorSumx. Set(sectors); 443 fSectorSumx2. Set(sectors); 444 fSectorSumAB0.Set(sectors); 445 fSectorSumAB1.Set(sectors); 446 fSectorValid. Set(sectors); 447 448 fSumx. Reset(); 449 fSumx2.Reset(); 450 } 451 452 if (fWindowSizeHiGain == 0 && fWindowSizeLoGain == 0) 453 { 454 *fLog << err << GetDescriptor() 455 << ": Number of extracted Slices is 0, abort ... " << endl; 456 return kFALSE; 457 } 458 459 460 *fLog << endl; 461 *fLog << inf << GetDescriptor() << ": Taking " << (int)fWindowSizeHiGain 462 << " HiGain FADC samples starting with slice: " << (int)fHiGainFirst << endl; 463 *fLog << inf << GetDescriptor() << ": Taking " << (int)fWindowSizeLoGain 464 << " LoGain FADC samples starting with slice: " << (int)fLoGainFirst << endl; 242 return kTRUE; 243 break; 244 } 245 246 Print(); 465 247 466 248 return kTRUE; … … 468 250 469 251 // -------------------------------------------------------------------------- 252 // 253 // Return kTRUE (without doing anything) in case that the run type is not 254 // equal to 1 (pedestal run) 470 255 // 471 256 // Fill the MPedestalCam container with the signal mean and rms for the event. … … 476 261 { 477 262 263 if (fSkip && !IsPedBitSet()) 264 return kTRUE; 265 266 /* 267 *fLog << err << dec << fEvtHeader->GetTriggerID() << endl; 268 for (Int_t i=16; i>= 0; i--) 269 *fLog << inf << (fEvtHeader->GetTriggerID() >> i & 1); 270 *fLog << endl; 271 *fLog << warn << hex << fEvtHeader->GetTriggerID() << endl; 272 */ 273 274 fUsedEvents++; 275 478 276 MRawEvtPixelIter pixel(fRawEvt); 479 277 … … 484 282 const UInt_t sector = (*fGeom)[idx].GetSector(); 485 283 486 Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst; 487 Byte_t *end = ptr + fWindowSizeHiGain; 488 489 UInt_t sum = 0; 490 UInt_t sqr = 0; 491 UInt_t ab0 = 0; 492 UInt_t ab1 = 0; 493 Int_t cnt = 0; 494 495 if (fWindowSizeHiGain != 0) 496 { 497 do 498 { 499 sum += *ptr; 500 sqr += *ptr * *ptr; 501 502 if (pixel.IsABFlagValid()) 503 { 504 const Int_t abFlag = (fHiGainFirst + pixel.HasABFlag() + cnt) & 0x1; 505 if (abFlag) 506 ab1 += *ptr; 507 else 508 ab0 += *ptr; 509 510 cnt++; 511 } 512 } 513 while (++ptr != end); 514 } 515 516 cnt = 0; 517 518 if (fWindowSizeLoGain != 0) 519 { 520 521 ptr = pixel.GetLoGainSamples() + fLoGainFirst; 522 end = ptr + fWindowSizeLoGain; 523 524 do 525 { 526 sum += *ptr; 527 sqr += *ptr * *ptr; 528 529 if (pixel.IsABFlagValid()) 530 { 531 const Int_t abFlag = (fLoGainFirst + pixel.GetNumHiGainSamples() + pixel.HasABFlag() + cnt) 532 & 0x1; 533 if (abFlag) 534 ab1 += *ptr; 535 else 536 ab0 += *ptr; 537 538 cnt++; 539 } 540 541 } 542 while (++ptr != end); 543 544 } 545 284 Float_t sum = 0.; 285 UInt_t ab0 = 0; 286 UInt_t ab1 = 0; 287 288 if (fExtractor) 289 CalcExtractor( &pixel, sum, (*fPedestalsIn)[idx]); 290 else 291 CalcSums( &pixel, sum, ab0, ab1); 292 546 293 const Float_t msum = (Float_t)sum; 547 548 //549 // These three lines have been uncommented by Markus Gaug550 // If anybody needs them, please contact me!!551 //552 // const Float_t higainped = msum/fNumHiGainSlices;553 // const Float_t higainrms = TMath::Sqrt((msqr-msum*msum/fNumHiGainSlices)/(fNumHiGainSlices-1.));554 // (*fPedestals)[idx].Set(higainped, higainrms);555 294 556 295 fSumx[idx] += msum; … … 558 297 fSectorSumx[sector] += msum; 559 298 560 //561 // The old version:562 //563 // const Float_t msqr = (Float_t)sqr;564 // fSumx2[idx] += msqr;565 //566 // The new version:567 //568 299 const Float_t sqrsum = msum*msum; 569 300 fSumx2[idx] += sqrsum; … … 571 302 fSectorSumx2[sector] += sqrsum; 572 303 573 //574 // Now, the sums separated for AB0 and AB1575 //576 304 fSumAB0[idx] += ab0; 577 305 fSumAB1[idx] += ab1; … … 584 312 } 585 313 586 fPedestals->SetReadyToSave(); 587 fNumSamplesTot += fWindowSizeHiGain + fWindowSizeLoGain; 314 fPedestalsOut->SetReadyToSave(); 588 315 589 316 return kTRUE; 590 317 } 591 318 319 320 321 void MPedCalcPedRun::CalcExtractor( MRawEvtPixelIter *pixel, Float_t &sum, MPedestalPix &ped) 322 { 323 324 Byte_t sat = 0; 325 Byte_t *first = pixel->GetHiGainSamples() + fExtractWinFirst; 326 Byte_t *logain = pixel->GetLoGainSamples(); 327 const Bool_t abflag = pixel->HasABFlag(); 328 Float_t dummy; 329 fExtractor->FindTimeAndChargeHiGain(first,logain,sum,dummy,dummy,dummy,sat,ped,abflag); 330 } 331 332 333 void MPedCalcPedRun::CalcSums( MRawEvtPixelIter *pixel, Float_t &sum, UInt_t &ab0, UInt_t &ab1) 334 { 335 336 Byte_t *higain = pixel->GetHiGainSamples() + fExtractWinFirst; 337 Byte_t *ptr = higain; 338 Byte_t *end = ptr + fExtractWinSize; 339 340 const Bool_t abflag = pixel->HasABFlag(); 341 342 Int_t sumi = 0; 343 344 Int_t cnt = 0; 345 do 346 { 347 sumi += *ptr; 348 if (pixel->IsABFlagValid()) 349 { 350 const Int_t abFlag = (fExtractWinFirst + abflag + cnt) & 0x1; 351 if (abFlag) 352 ab1 += *ptr; 353 else 354 ab0 += *ptr; 355 356 cnt++; 357 } 358 } 359 while (++ptr != end); 360 361 if (fOverlap != 0) 362 { 363 ptr = pixel->GetLoGainSamples(); 364 end = ptr + fOverlap; 365 366 do 367 { 368 sumi += *ptr; 369 if (pixel->IsABFlagValid()) 370 { 371 const Int_t abFlag = (fExtractWinFirst + abflag + cnt) & 0x1; 372 if (abFlag) 373 ab1 += *ptr; 374 else 375 ab0 += *ptr; 376 377 cnt++; 378 } 379 } 380 while (++ptr != end); 381 } 382 383 sum = (Float_t)sumi; 384 385 } 386 592 387 // -------------------------------------------------------------------------- 593 388 // … … 597 392 { 598 393 599 // Compute pedestals and rms from the whole run 600 const ULong_t n = fNumSamplesTot; 601 const ULong_t nevts = GetNumExecutions(); 394 if (fUsedEvents == 0) 395 return kTRUE; 602 396 603 397 MRawEvtPixelIter pixel(fRawEvt); … … 605 399 while (pixel.Next()) 606 400 { 607 608 401 const Int_t pixid = pixel.GetPixelId(); 609 const UInt_t aidx = (*fGeom)[pixid].GetAidx(); 610 const UInt_t sector = (*fGeom)[pixid].GetSector(); 611 612 fAreaValid [aidx]++; 613 fSectorValid[sector]++; 614 615 const Float_t sum = fSumx.At(pixid); 616 const Float_t sum2 = fSumx2.At(pixid); 617 const Float_t higainped = sum/n; 618 // 619 // The old version: 620 // 621 // const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.)); 622 // 623 // The new version: 624 // 625 // 1. Calculate the Variance of the sums: 626 Float_t higainVar = (sum2-sum*sum/nevts)/(nevts-1.); 627 // 2. Scale the variance to the number of slices: 628 higainVar /= (Float_t)(fWindowSizeHiGain+fWindowSizeLoGain); 629 // 3. Calculate the RMS from the Variance: 630 const Float_t rms = higainVar<0 ? 0. : TMath::Sqrt(higainVar); 631 // 4. Calculate the amplitude of the 150MHz "AB" noise 632 const Float_t abOffs = (fSumAB0.At(pixid) - fSumAB1.At(pixid)) / n; 633 634 (*fPedestals)[pixid].Set(higainped,rms,abOffs); 402 CalcPixResults(fUsedEvents,pixid); 635 403 } 636 404 … … 638 406 // Loop over the (two) area indices to get the averaged pedestal per aidx 639 407 // 640 for (Int_t aidx=0; aidx<fAreaValid.GetSize(); aidx++) 641 { 642 408 for (UInt_t aidx=0; aidx<fAreaValid.GetSize(); aidx++) 409 { 643 410 const Int_t napix = fAreaValid.At(aidx); 644 645 411 if (napix == 0) 646 412 continue; 647 413 648 const Float_t sum = fAreaSumx.At(aidx); 649 const Float_t sum2 = fAreaSumx2.At(aidx); 650 const ULong_t an = napix * n; 651 const ULong_t aevts = napix * nevts; 652 653 const Float_t higainped = sum/an; 654 655 // 1. Calculate the Variance of the sums: 656 Float_t higainVar = (sum2-sum*sum/aevts)/(aevts-1.); 657 // 2. Scale the variance to the number of slices: 658 higainVar /= fWindowSizeHiGain+fWindowSizeLoGain; 659 // 3. Calculate the RMS from the Variance: 660 Float_t higainrms = TMath::Sqrt(higainVar); 661 // 4. Re-scale it with the square root of the number of involved pixels 662 // in order to be comparable to the mean of pedRMS of that area 663 higainrms *= TMath::Sqrt((Float_t)napix); 664 // 5. Calculate the amplitude of the 150MHz "AB" noise 665 const Float_t abOffs = (fAreaSumAB0.At(aidx) - fAreaSumAB1.At(aidx)) / an; 666 667 fPedestals->GetAverageArea(aidx).Set(higainped, higainrms,abOffs); 414 CalcAreaResults(fUsedEvents,napix,aidx); 668 415 } 669 416 … … 671 418 // Loop over the (six) sector indices to get the averaged pedestal per sector 672 419 // 673 for (Int_t sector=0; sector<fSectorValid.GetSize(); sector++) 674 { 675 420 for (UInt_t sector=0; sector<fSectorValid.GetSize(); sector++) 421 { 676 422 const Int_t nspix = fSectorValid.At(sector); 677 678 423 if (nspix == 0) 679 424 continue; 680 425 681 const Float_t sum = fSectorSumx.At(sector); 682 const Float_t sum2 = fSectorSumx2.At(sector); 683 const ULong_t sn = nspix * n; 684 const ULong_t sevts = nspix * nevts; 685 686 const Float_t higainped = sum/sn; 687 688 // 1. Calculate the Variance of the sums: 689 Float_t higainVar = (sum2-sum*sum/sevts)/(sevts-1.); 690 // 2. Scale the variance to the number of slices: 691 higainVar /= fWindowSizeHiGain+fWindowSizeLoGain; 692 // 3. Calculate the RMS from the Variance: 693 Float_t higainrms = TMath::Sqrt(higainVar); 694 // 4. Re-scale it with the square root of the number of involved pixels 695 // in order to be comparable to the mean of pedRMS of that sector 696 higainrms *= TMath::Sqrt((Float_t)nspix); 697 // 5. Calculate the amplitude of the 150MHz "AB" noise 698 const Float_t abOffs = (fSectorSumAB0.At(sector) - fSectorSumAB1.At(sector)) / sn; 699 700 fPedestals->GetAverageSector(sector).Set(higainped, higainrms, abOffs); 701 } 702 703 fPedestals->SetTotalEntries(fNumSamplesTot); 704 fPedestals->SetReadyToSave(); 426 CalcSectorResults(fUsedEvents,nspix,sector); 427 } 428 429 fPedestalsOut->SetTotalEntries(fUsedEvents*fExtractWinSize); 430 fPedestalsOut->SetReadyToSave(); 705 431 706 432 return kTRUE; 707 433 } 708 434 709 Int_t MPedCalcPedRun::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 710 { 711 if (MExtractor::ReadEnv(env, prefix, print)==kERROR) 712 return kERROR; 713 714 Byte_t hw = fWindowSizeHiGain; 715 Byte_t lw = fWindowSizeLoGain; 716 717 Bool_t rc = kFALSE; 718 719 if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print)) 720 { 721 hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw); 722 rc=kTRUE; 723 } 724 725 if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print)) 726 { 727 lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw); 728 rc=kTRUE; 729 } 730 731 if (rc) 732 SetWindowSize(hw, lw); 733 734 return rc; 735 } 435 // ----------------------------------------------------------------------- 436 // 437 // Analogue to the MTask::CallPostProcess, but without the manipulation 438 // of the bit fIsPreProcessed. Needed in order to call PostProcess multiple 439 // times in the intensity calibration. 440 // 441 Int_t MPedCalcPedRun::CallPostProcess() 442 { 443 444 *fLog << all << fName << "... " << flush; 445 if (fDisplay) 446 fDisplay->SetStatusLine2(*this); 447 448 return PostProcess(); 449 } 450 451 //------------------------------------------------------------- 452 // 453 // Return if the pedestal bit was set from the calibration trigger box. 454 // The last but one bit is used for the "pedestal-bit". 455 // 456 // This bit is set since run gkFinalizationTriggerBit 457 // 458 Bool_t MPedCalcPedRun::IsPedBitSet() 459 { 460 if (fRunHeader->GetRunNumber() < gkFirstRunWithFinalBits) 461 return kFALSE; 462 463 return (fEvtHeader->GetTriggerID() >> 3 & 1); 464 } 465 466 void MPedCalcPedRun::Print(Option_t *o) const 467 { 468 469 MExtractPedestal::Print(o); 470 471 *fLog << "Number overlap low-gain slices: " << fOverlap << endl; 472 *fLog << "First run out of sequence: " << (fFirstRun?"yes":"no") << endl; 473 *fLog << "Skip this run: " << (fSkip?"yes":"no") << endl; 474 *fLog << "Number of used events so far: " << fUsedEvents << endl; 475 *fLog << endl; 476 } -
trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h
r5219 r5487 2 2 #define MARS_MPedCalcPedRun 3 3 4 #ifndef MARS_MExtract or5 #include "MExtract or.h"4 #ifndef MARS_MExtractPedestal 5 #include "MExtractPedestal.h" 6 6 #endif 7 7 8 #ifndef ROOT_TArrayD9 #include < TArrayD.h>8 #ifndef MARS_MArrayD 9 #include <MArrayD.h> 10 10 #endif 11 11 12 #ifndef ROOT_TArrayI13 #include < TArrayI.h>12 #ifndef MARS_MArrayI 13 #include <MArrayI.h> 14 14 #endif 15 15 16 class MGeomCam; 17 class MPedCalcPedRun : public MExtractor 16 class MRawEvtPixelIter; 17 class MPedestalPix; 18 class MPedCalcPedRun : public MExtractPedestal 18 19 { 19 20 20 static const Byte_t fgHiGainFirst; // First FADC slice Hi-Gain (currently set to: 3) 21 static const Byte_t fgHiGainLast; // Last FADC slice Hi-Gain (currently set to: 14) 22 static const Byte_t fgLoGainFirst; // First FADC slice Lo-Gain (currently set to: 3) 23 static const Byte_t fgLoGainLast; // Last FADC slice Lo-Gain (currently set to: 14) 24 static const Byte_t fgHiGainWindowSize; // The extraction window Hi-Gain 25 static const Byte_t fgLoGainWindowSize; // The extraction window Lo-Gain 21 static const UShort_t fgExtractWinFirst; // First FADC slice Hi-Gain (currently set to: 3) 22 static const UShort_t fgExtractWinSize; // Extraction Size Hi-Gain (currently set to: 14) 23 static const UInt_t gkFirstRunWithFinalBits; // First Run with pedestal trigger bit at place 3 26 24 27 UInt_t fNumSamplesTot; 28 Byte_t fWindowSizeHiGain; // Number of Hi Gain slices in window 29 Byte_t fWindowSizeLoGain; // Number of Lo Gain slices in window 25 UShort_t fOverlap; // Number of overlapping slices from High-Gain to Low-Gain 26 27 Bool_t fFirstRun; // Flag to tell if the first run out of many is used 28 Bool_t fSkip; // Flag to tell if the Process has to be skipped 29 ULong_t fUsedEvents; // Number of used (not skipped) events 30 30 31 MGeomCam *fGeom; // Camera geometry31 Bool_t IsPedBitSet(); 32 32 33 TArrayD fSumx; // sum of values34 TArrayD fSumx2; // sum of squared values35 TArrayD fSumAB0; // sum of ABFlag=0 slices36 TArrayD fSumAB1; // sum of ABFlag=1 slices37 TArrayD fAreaSumx; // averaged sum of values per area idx38 TArrayD fAreaSumx2; // averaged sum of squared values per area idx39 TArrayD fAreaSumAB0; // averaged sum of ABFlag=0 slices per area idx40 TArrayD fAreaSumAB1; // averaged sum of ABFlag=1 slices per area idx41 TArrayI fAreaValid; // number of valid pixel with area idx42 TArrayD fSectorSumx; // averaged sum of values per sector43 TArrayD fSectorSumx2; // averaged sum of squared values per sector44 TArrayD fSectorSumAB0; // averaged sum of ABFlag=0 slices per sector45 TArrayD fSectorSumAB1; // averaged sum of ABFlag=1 slices per sector46 TArrayI fSectorValid; // number of valid pixel with sector idx47 48 Int_t PreProcess (MParList *pList);49 33 Bool_t ReInit (MParList *pList); 50 34 Int_t Process (); 51 35 Int_t PostProcess(); 52 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 36 37 void ResetArrays(); 38 void CalcSums ( MRawEvtPixelIter *pixel, Float_t &sum, UInt_t &ab0, UInt_t &ab1); 39 void CalcExtractor( MRawEvtPixelIter *pixel, Float_t &sum, MPedestalPix &ped); 53 40 54 41 public: … … 56 43 MPedCalcPedRun(const char *name=NULL, const char *title=NULL); 57 44 58 void Clear(const Option_t *o=""); 45 Int_t CallPostProcess(); 46 47 void Print(Option_t *o="") const; 59 48 60 void SetRange ( const Byte_t hifirst=0, const Byte_t hilast=0, 61 const Byte_t lofirst=0, const Byte_t lolast=0 ); 62 void SetWindowSize ( const Byte_t windowh=0, const Byte_t windowl=0 ); 63 64 ClassDef(MPedCalcPedRun, 0) // Task to calculate pedestals from pedestal runs raw data 49 ClassDef(MPedCalcPedRun, 1) // Task to calculate pedestals from pedestal runs 65 50 }; 66 51
Note:
See TracChangeset
for help on using the changeset viewer.