Changeset 8151 for trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc
- Timestamp:
- 10/24/06 08:58:13 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.