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