Changeset 3889 for trunk/MagicSoft/Mars/mpedestal
- Timestamp:
- 04/29/04 15:48:38 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
r3804 r3889 26 26 ! 27 27 \* ======================================================================== */ 28 29 28 ///////////////////////////////////////////////////////////////////////////// 30 29 // … … 70 69 // (and moreover asymmetric) and that they are also correlated.) 71 70 // 71 // Call: SetRange(higainfirst, higainlast, logainfirst, logainlast) 72 // to modify the ranges in which the window is allowed to move. 73 // Defaults are: 74 // 75 // fHiGainFirst = fgHiGainFirst = 0 76 // fHiGainLast = fgHiGainLast = 14 77 // fLoGainFirst = fgLoGainFirst = 0 78 // fLoGainLast = fgLoGainLast = 14 79 // 80 // Call: SetWindowSize(windowhigain, windowlogain) 81 // to modify the sliding window widths. Windows have to be an even number. 82 // In case of odd numbers, the window will be modified. 83 // 84 // Defaults are: 85 // 86 // fHiGainWindowSize = fgHiGainWindowSize = 14 87 // fLoGainWindowSize = fgLoGainWindowSize = 0 88 // 72 89 // 73 90 // Input Containers: 74 91 // MRawEvtData 92 // MRawRunHeader 93 // MGeomCam 75 94 // 76 95 // Output Containers: … … 80 99 ///////////////////////////////////////////////////////////////////////////// 81 100 #include "MPedCalcPedRun.h" 101 #include "MExtractor.h" 82 102 83 103 #include "MParList.h" … … 93 113 #include "MPedestalCam.h" 94 114 95 #include "MExtractedSignalPix.h"96 #include "MExtractedSignalCam.h"97 98 115 #include "MGeomPix.h" 99 116 #include "MGeomCam.h" … … 105 122 using namespace std; 106 123 107 // -------------------------------------------------------------------------- 108 // 109 // default constructor 124 const Byte_t MPedCalcPedRun::fgHiGainFirst = 0; 125 const Byte_t MPedCalcPedRun::fgHiGainLast = 14; 126 const Byte_t MPedCalcPedRun::fgLoGainFirst = 0; 127 const Byte_t MPedCalcPedRun::fgLoGainLast = 14; 128 const Byte_t MPedCalcPedRun::fgHiGainWindowSize = 14; 129 const Byte_t MPedCalcPedRun::fgLoGainWindowSize = 0; 130 // -------------------------------------------------------------------------- 131 // 132 // Default constructor: 133 // 134 // Sets: 135 // - fWindowSizeHiGain to fgHiGainWindowSize 136 // - fWindowSizeLoGain to fgLoGainWindowSize 137 // 138 // Calls: 139 // - AddToBranchList("fHiGainPixId"); 140 // - AddToBranchList("fHiGainFadcSamples"); 141 // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast) 142 // - Clear() 110 143 // 111 144 MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title) 112 : fRawEvt(NULL), fPedestals(NULL) 113 { 114 fName = name ? name : "MPedCalcPedRun"; 115 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 116 117 AddToBranchList("fHiGainPixId"); 118 AddToBranchList("fHiGainFadcSamples"); 119 120 fNumHiGainSamples = 0; 121 Clear(); 122 } 123 145 : fWindowSizeHiGain(fgHiGainWindowSize), 146 fWindowSizeLoGain(fgLoGainWindowSize) 147 { 148 fName = name ? name : "MPedCalcPedRun"; 149 fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data"; 150 151 AddToBranchList("fHiGainPixId"); 152 AddToBranchList("fHiGainFadcSamples"); 153 154 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); 155 Clear(); 156 } 157 158 // -------------------------------------------------------------------------- 159 // 160 // Sets: 161 // - fNumSamplesTot to 0 162 // - fRawEvt to NULL 163 // - fRunHeader to NULL 164 // - fPedestals to NULL 165 // 124 166 void MPedCalcPedRun::Clear(const Option_t *o) 125 167 { … … 128 170 129 171 fRawEvt = NULL; 172 fRunHeader = NULL; 130 173 fPedestals = NULL; 131 174 } 132 175 133 176 // -------------------------------------------------------------------------- 177 // 178 // SetRange: 179 // 180 // Calls: 181 // - MExtractor::SetRange(hifirst,hilast,lofirst,lolast); 182 // - SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain); 183 // 184 void MPedCalcPedRun::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast) 185 { 186 187 MExtractor::SetRange(hifirst,hilast,lofirst,lolast); 188 189 // 190 // Redo the checks if the window is still inside the ranges 191 // 192 SetWindowSize(fWindowSizeHiGain,fWindowSizeLoGain); 193 194 } 195 196 197 // -------------------------------------------------------------------------- 198 // 199 // Checks: 200 // - if a window is odd, subtract one 201 // - if a window is bigger than the one defined by the ranges, set it to the available range 202 // - if a window is smaller than 2, set it to 2 203 // 204 // Sets: 205 // - fNumHiGainSamples to: (Float_t)fWindowSizeHiGain 206 // - fNumLoGainSamples to: (Float_t)fWindowSizeLoGain 207 // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples) 208 // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples) 209 // 210 void MPedCalcPedRun::SetWindowSize(Byte_t windowh, Byte_t windowl) 211 { 212 213 fWindowSizeHiGain = windowh & ~1; 214 fWindowSizeLoGain = windowl & ~1; 215 216 if (fWindowSizeHiGain != windowh) 217 *fLog << warn << GetDescriptor() << ": Hi Gain window size has to be even, set to: " 218 << int(fWindowSizeHiGain) << " samples " << endl; 219 220 if (fWindowSizeLoGain != windowl) 221 *fLog << warn << GetDescriptor() << ": Lo Gain window size has to be even, set to: " 222 << int(fWindowSizeLoGain) << " samples " << endl; 223 224 const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1; 225 const Byte_t availlorange = (fLoGainLast-fLoGainFirst+1) & ~1; 226 227 if (fWindowSizeHiGain > availhirange) 228 { 229 *fLog << warn << GetDescriptor() 230 << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",(int)fWindowSizeHiGain, 231 " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl; 232 *fLog << warn << GetDescriptor() 233 << ": Will set window size to: " << (int)availhirange << endl; 234 fWindowSizeHiGain = availhirange; 235 } 236 237 if (fWindowSizeLoGain > availlorange) 238 { 239 *fLog << warn << GetDescriptor() 240 << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",(int)fWindowSizeLoGain, 241 " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl; 242 *fLog << warn << GetDescriptor() 243 << ": Will set window size to: " << (int)availlorange << endl; 244 fWindowSizeLoGain = availlorange; 245 } 246 247 248 fNumHiGainSamples = (Float_t)fWindowSizeHiGain; 249 fNumLoGainSamples = (Float_t)fWindowSizeLoGain; 250 251 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples); 252 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples); 253 254 } 255 256 257 134 258 // -------------------------------------------------------------------------- 135 259 // … … 137 261 // 138 262 // - MRawEvtData 263 // - MRawRunHeader 264 // - MGeomCam 139 265 // 140 266 // The following output containers are also searched and created if … … 155 281 } 156 282 283 fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader")); 284 if (!fRunHeader) 285 { 286 *fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl; 287 return kFALSE; 288 } 289 157 290 fGeom = (MGeomCam*)pList->FindObject("MGeomCam"); 158 291 if (!fGeom) … … 165 298 if (!fPedestals) 166 299 return kFALSE; 167 300 168 301 return kTRUE; 169 302 } … … 171 304 // -------------------------------------------------------------------------- 172 305 // 173 // The ReInit searches for the following input containers: 174 // - MRawRunHeader 175 // 176 // It also initializes the data arrays fSumx and fSumx2 177 // (only for the first read file) 178 // 306 // The ReInit searches for: 307 // - MRawRunHeader::GetNumSamplesHiGain() 308 // - MRawRunHeader::GetNumSamplesLoGain() 309 // 310 // In case that the variables fHiGainLast and fLoGainLast are smaller than 311 // the even part of the number of samples obtained from the run header, a 312 // warning is given an the range is set back accordingly. A call to: 313 // - SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast) or 314 // - SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff) 315 // is performed in that case. The variable diff means here the difference 316 // between the requested range (fHiGainLast) and the available one. Note that 317 // the functions SetRange() are mostly overloaded and perform more checks, 318 // modifying the ranges again, if necessary. 319 // 179 320 Bool_t MPedCalcPedRun::ReInit(MParList *pList) 180 321 { 181 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader"); 182 if (!runheader) 183 { 184 *fLog << warn << dbginf; 185 *fLog << "Warning - cannot check file type, MRawRunHeader not found." << endl; 186 } 187 else 188 if (runheader->IsMonteCarloRun()) 189 return kTRUE; 190 191 Int_t npixels = fPedestals->GetSize(); 192 Int_t areas = fPedestals->GetAverageAreas(); 193 Int_t sectors = fPedestals->GetAverageSectors(); 194 195 if (fSumx.GetSize()==0) 196 { 197 fSumx. Set(npixels); 198 fSumx2.Set(npixels); 199 200 fAreaSumx. Set(areas); 201 fAreaSumx2.Set(areas); 202 fAreaValid.Set(areas); 203 204 fSectorSumx. Set(sectors); 205 fSectorSumx2.Set(sectors); 206 fSectorValid.Set(sectors); 207 208 fSumx.Reset(); 209 fSumx2.Reset(); 210 } 211 212 // Calculate an even number for the hi gain samples to avoid 213 // biases due to the fluctuation in pedestal from one slice to 214 // the other one 215 fNumHiGainSamples = runheader->GetNumSamplesHiGain() & ~1; 216 217 return kTRUE; 322 323 Int_t lastdesired = (Int_t)fHiGainLast; 324 Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesHiGain()-1; 325 326 if (lastdesired > lastavailable) 327 { 328 const Int_t diff = lastdesired - lastavailable; 329 *fLog << endl; 330 *fLog << warn << GetDescriptor() 331 << Form("%s%2i%s%2i%s%2i%s",": Selected Hi Gain FADC Window [", 332 (int)fHiGainFirst,",",lastdesired, 333 "] ranges out of the available limits: [0,",lastavailable,"].") << endl; 334 *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fHiGainLast - diff) << endl; 335 SetRange(fHiGainFirst, fHiGainLast-diff, fLoGainFirst, fLoGainLast); 336 } 337 338 lastdesired = (Int_t)(fLoGainLast); 339 lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1; 340 341 if (lastdesired > lastavailable) 342 { 343 const Int_t diff = lastdesired - lastavailable; 344 *fLog << endl; 345 *fLog << warn << GetDescriptor() 346 << Form("%s%2i%s%2i%s%2i%s",": Selected Lo Gain FADC Window [", 347 (int)fLoGainFirst,",",lastdesired, 348 "] ranges out of the available limits: [0,",lastavailable,"].") << endl; 349 *fLog << GetDescriptor() << ": Will reduce the upper edge to " << (int)(fLoGainLast - diff) << endl; 350 SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast-diff); 351 } 352 353 Int_t npixels = fPedestals->GetSize(); 354 Int_t areas = fPedestals->GetAverageAreas(); 355 Int_t sectors = fPedestals->GetAverageSectors(); 356 357 if (fSumx.GetSize()==0) 358 { 359 fSumx. Set(npixels); 360 fSumx2.Set(npixels); 361 362 fAreaSumx. Set(areas); 363 fAreaSumx2.Set(areas); 364 fAreaValid.Set(areas); 365 366 fSectorSumx. Set(sectors); 367 fSectorSumx2.Set(sectors); 368 fSectorValid.Set(sectors); 369 370 fSumx.Reset(); 371 fSumx2.Reset(); 372 } 373 374 if (fWindowSizeHiGain == 0 && fWindowSizeLoGain == 0) 375 { 376 *fLog << err << GetDescriptor() 377 << ": Number of extracted Slices is 0, abort ... " << endl; 378 return kFALSE; 379 } 380 381 382 *fLog << endl; 383 *fLog << inf << GetDescriptor() << ": Taking " << (int)fWindowSizeHiGain 384 << " HiGain FADC samples starting with slice: " << (int)fHiGainFirst << endl; 385 *fLog << inf << GetDescriptor() << ": Taking " << (int)fWindowSizeLoGain 386 << " LoGain FADC samples starting with slice: " << (int)fLoGainFirst << endl; 387 388 return kTRUE; 389 218 390 } 219 391 // -------------------------------------------------------------------------- … … 235 407 const UInt_t sector = (*fGeom)[idx].GetSector(); 236 408 237 Byte_t *ptr = pixel.GetHiGainSamples() ;238 const Byte_t *end = ptr + fNumHiGainSamples;409 Byte_t *ptr = pixel.GetHiGainSamples() + fHiGainFirst; 410 Byte_t *end = ptr + fWindowSizeHiGain; 239 411 240 412 UInt_t sum = 0; … … 247 419 } 248 420 while (++ptr != end); 421 422 if (fWindowSizeLoGain != 0) 423 { 424 425 ptr = pixel.GetLoGainSamples() + fLoGainFirst; 426 end = ptr + fWindowSizeLoGain; 427 428 do 429 { 430 sum += *ptr; 431 sqr += *ptr * *ptr; 432 } 433 while (++ptr != end); 434 435 } 249 436 250 437 const Float_t msum = (Float_t)sum; … … 254 441 // If anybody needs them, please contact me!! 255 442 // 256 // const Float_t higainped = msum/fNumHiGainS amples;257 // const Float_t higainrms = TMath::Sqrt((msqr-msum*msum/fNumHiGainS amples)/(fNumHiGainSamples-1.));443 // const Float_t higainped = msum/fNumHiGainSlices; 444 // const Float_t higainrms = TMath::Sqrt((msqr-msum*msum/fNumHiGainSlices)/(fNumHiGainSlices-1.)); 258 445 // (*fPedestals)[idx].Set(higainped, higainrms); 259 446 … … 276 463 277 464 fPedestals->SetReadyToSave(); 278 fNumSamplesTot += fNumHiGainSamples; 279 465 fNumSamplesTot += fWindowSizeHiGain + fWindowSizeLoGain; 280 466 281 467 return kTRUE; … … 319 505 Float_t higainVar = (sum2-sum*sum/nevts)/(nevts-1.); 320 506 // 2. Scale the variance to the number of slices: 321 higainVar /= (Float_t) fNumHiGainSamples;507 higainVar /= (Float_t)(fWindowSizeHiGain+fWindowSizeLoGain); 322 508 // 3. Calculate the RMS from the Variance: 323 509 const Float_t higainrms = TMath::Sqrt(higainVar); … … 344 530 Float_t higainVar = (sum2-sum*sum/aevts)/(aevts-1.); 345 531 // 2. Scale the variance to the number of slices: 346 higainVar /= (Float_t)fNumHiGainSamples;532 higainVar /= fWindowSizeHiGain+fWindowSizeLoGain; 347 533 // 3. Calculate the RMS from the Variance: 348 534 Float_t higainrms = TMath::Sqrt(higainVar); … … 371 557 Float_t higainVar = (sum2-sum*sum/sevts)/(sevts-1.); 372 558 // 2. Scale the variance to the number of slices: 373 higainVar /= (Float_t)fNumHiGainSamples;559 higainVar /= fWindowSizeHiGain+fWindowSizeLoGain; 374 560 // 3. Calculate the RMS from the Variance: 375 561 Float_t higainrms = TMath::Sqrt(higainVar);
Note:
See TracChangeset
for help on using the changeset viewer.