Changeset 3476 for trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc
- Timestamp:
- 03/11/04 16:32:11 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbadpixels/MBadPixelsTreat.cc
r3126 r3476 36 36 // Input Containers: 37 37 // MCerPhotEvt 38 // MPedPhotCam 38 39 // MBadPixelsCam 40 // [MGeomCam] 39 41 // 40 42 // Output Containers: … … 45 47 46 48 #include <fstream> 49 50 #include <TArrayD.h> 47 51 48 52 #include "MLog.h" … … 114 118 if (!fGeomCam && TESTBIT(fFlags, kUseInterpolation)) 115 119 { 116 *fLog << err << " No camera geometry available... can't use interpolation." << endl;120 *fLog << err << "MGeomCam not found... can't use interpolation." << endl; 117 121 return kFALSE; 118 122 } 119 123 120 124 return kTRUE; 125 } 126 127 // -------------------------------------------------------------------------- 128 // 129 // Replaces each pixel (signal, signal error, pedestal, pedestal rms) 130 // by the average of its surrounding pixels. 131 // If TESTBIT(fFlags, kUseCentralPixel) is set the central pixel is also 132 // included. 133 // 134 void MBadPixelsTreat::InterpolateSignal() const 135 { 136 const UShort_t entries = fGeomCam->GetNumPixels(); 137 138 // 139 // Create arrays 140 // 141 TArrayD nphot(entries); 142 TArrayD perr(entries); 143 144 // 145 // Loop over all pixels 146 // 147 for (UShort_t i=0; i<entries; i++) 148 { 149 // 150 // Check whether pixel with idx i is blind 151 // 152 if (!(*fBadPixels)[i].IsBad()) 153 continue; 154 155 // 156 // Get a pointer to this pixel. If it is not yet existing 157 // create a new entry for this pixel in MCerPhotEvt 158 // 159 MCerPhotPix *pix = fEvt->GetPixById(i); 160 if (!pix) 161 pix = fEvt->AddPixel(i, 0, 0); 162 163 // 164 // Get the corresponding geometry and pedestal 165 // 166 const MGeomPix &gpix = (*fGeomCam)[i]; 167 168 // Do Not-Use-Central-Pixel 169 const Bool_t nucp = !TESTBIT(fFlags, kUseCentralPixel); 170 171 Int_t num = nucp ? 0 : 1; 172 173 nphot[i] = nucp ? 0 : pix->GetNumPhotons(); 174 perr[i] = nucp ? 0 : Pow2(pix->GetErrorPhot()); 175 176 // 177 // The values are rescaled to the small pixels area for the right comparison 178 // 179 const Double_t ratio = fGeomCam->GetPixRatio(i); 180 181 nphot[i] *= ratio; 182 perr[i] *= ratio; 183 184 // 185 // Loop over all its neighbors 186 // 187 const Int_t n = gpix.GetNumNeighbors(); 188 for (int j=0; j<n; j++) 189 { 190 const UShort_t nidx = gpix.GetNeighbor(j); 191 192 // 193 // Do not use blind neighbors 194 // 195 if (!(*fBadPixels)[i].IsBad()) 196 continue; 197 198 // 199 // Check whether the neighbor has a signal stored 200 // 201 const MCerPhotPix *evtpix = fEvt->GetPixById(nidx); 202 if (!evtpix) 203 continue; 204 205 // 206 // Get the geometry for the neighbor 207 // 208 const Double_t nratio = fGeomCam->GetPixRatio(nidx); 209 210 // 211 //The error is calculated as the quadratic sum of the errors 212 // 213 nphot[i] += nratio*evtpix->GetNumPhotons(); 214 perr[i] += nratio* Pow2(evtpix->GetErrorPhot()); 215 216 num++; 217 } 218 219 // 220 // Now the mean is calculated and the values rescaled back 221 // to the pixel area 222 // 223 nphot[i] /= (num*ratio); 224 perr[i] = TMath::Sqrt(perr[i]/(num*ratio)); 225 226 // Check if there are enough neighbors to calculate the mean 227 // If not, unmap the pixel. The maximum number of blind neighbors 228 // should be 2 229 if (num<3) 230 { 231 pix->SetPixelUnmapped(); 232 continue; 233 } 234 235 pix->Set(nphot[i], perr[i]); 236 } 237 } 238 239 // -------------------------------------------------------------------------- 240 // 241 void MBadPixelsTreat::InterpolatePedestals() const 242 { 243 const Int_t entries = fPedPhot->GetSize(); 244 245 TArrayD ped(entries); 246 TArrayD rms(entries); 247 248 // 249 // Loop over all pixels 250 // 251 for (UShort_t i=0; i<entries; i++) 252 { 253 // 254 // Check whether pixel with idx i is blind 255 // 256 if (!(*fBadPixels)[i].IsBad()) 257 continue; 258 259 // 260 // Get the corresponding geometry and pedestal 261 // 262 const MGeomPix &gpix = (*fGeomCam)[i]; 263 const MPedPhotPix &ppix = (*fPedPhot)[i]; 264 265 // Do Not-Use-Central-Pixel 266 const Bool_t nucp = !TESTBIT(fFlags, kUseCentralPixel); 267 268 Int_t num = nucp ? 0 : 1; 269 270 ped[i] = nucp ? 0 : ppix.GetMean(); 271 rms[i] = nucp ? 0 : Pow2(ppix.GetRms()); 272 273 // 274 // The values are rescaled to the small pixels area for the right comparison 275 // 276 const Double_t ratio = fGeomCam->GetPixRatio(i); 277 278 ped[i] *= ratio; 279 rms[i] *= ratio; 280 281 // 282 // Loop over all its neighbors 283 // 284 const Int_t n = gpix.GetNumNeighbors(); 285 for (int j=0; j<n; j++) 286 { 287 const UShort_t nidx = gpix.GetNeighbor(j); 288 289 // 290 // Do not use blind neighbors 291 // 292 if (!(*fBadPixels)[i].IsBad()) 293 continue; 294 295 // 296 // Get the geometry for the neighbor 297 // 298 const Double_t nratio = fGeomCam->GetPixRatio(nidx); 299 const MPedPhotPix &nppix = (*fPedPhot)[nidx]; 300 301 // 302 //The error is calculated as the quadratic sum of the errors 303 // 304 ped[i] += (nratio*nppix.GetMean()); 305 rms[i] += nratio*Pow2(nppix.GetRms()); 306 307 num++; 308 } 309 310 // Check if there are enough neighbors to calculate the mean 311 // If not, unmap the pixel. The minimum number of good neighbors 312 // should be 3 313 if (num < 3) 314 { 315 MCerPhotPix *pix =fEvt->GetPixById(i); 316 if (!pix) 317 pix = fEvt->AddPixel(i, 0, 0); 318 pix->SetPixelUnmapped(); 319 continue; 320 } 321 322 // 323 // Now the mean is calculated and the values rescaled back 324 // to the pixel area 325 // 326 ped[i] /= (num*ratio); 327 rms[i] = TMath::Sqrt(rms[i]/(num*ratio)); 328 329 (*fPedPhot)[i].Set(ped[i], rms[i]); 330 } 121 331 } 122 332 … … 177 387 nphot[i] = nucp ? 0 : pix->GetNumPhotons(); 178 388 ped[i] = nucp ? 0 : ppix.GetMean(); 179 perr[i] = nucp ? 0 : Sqr(pix->GetErrorPhot());180 pedrms[i] = nucp ? 0 : Sqr(ppix.GetRms());389 perr[i] = nucp ? 0 : Pow2(pix->GetErrorPhot()); 390 pedrms[i] = nucp ? 0 : Pow2(ppix.GetRms()); 181 391 182 392 // … … 187 397 nphot[i] *= ratio; 188 398 ped[i] *= ratio; 189 perr[i] *= Sqr(ratio);190 pedrms[i] *= Sqr(pedrms[i]);399 perr[i] *= Pow2(ratio); 400 pedrms[i] *= Pow2(pedrms[i]); 191 401 192 402 // … … 222 432 ped[i] += nratio*nppix.GetMean(); 223 433 nphot[i] += nratio*evtpix->GetNumPhotons(); 224 perr[i] += Sqr(nratio*evtpix->GetErrorPhot());225 pedrms[i] += Sqr(nratio*nppix.GetRms());434 perr[i] += Pow2(nratio*evtpix->GetErrorPhot()); 435 pedrms[i] += Pow2(nratio*nppix.GetRms()); 226 436 227 437 num++; … … 294 504 Int_t MBadPixelsTreat::Process() 295 505 { 506 /* 507 if (TESTBIT(fFlags, kCheckPedestalRms)) 508 { 509 // if the number of blind pixels is too high, do not interpolate 510 if (CheckPedestalRms()==kFALSE) 511 return kTRUE; 512 513 if (TESTBIT(fFlags, kUseInterpolation)) 514 InterpolatePedestals(); 515 } 516 */ 517 296 518 if (TESTBIT(fFlags, kUseInterpolation) && fGeomCam) 297 519 Interpolate(); … … 299 521 Unmap(); 300 522 523 524 //fErrors[0]++; 525 301 526 return kTRUE; 302 527 }
Note:
See TracChangeset
for help on using the changeset viewer.