Changeset 7043 for trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc
- Timestamp:
- 05/17/05 12:08:31 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msignal/MExtractPINDiode.cc
r4896 r7043 25 25 ////////////////////////////////////////////////////////////////////////////// 26 26 // 27 // 27 // MExtractPINDiode 28 28 // 29 29 // Extracts the signal from a fixed window in a given range. 30 30 // 31 31 // Call: SetRange(fHiGainFirst, fHiGainLast, fLoGainFirst, fLoGainLast) 32 // to modify the ranges. Ranges have to be an even number. In case of odd33 // ranges, the last slice will be reduced by one.32 // to modify the ranges. 33 // 34 34 // Defaults are: 35 35 // 36 // fHiGainFirst = fgHiGainFirst = 3 37 // fHiGainLast = fgHiGainLast = 14 38 // fLoGainFirst = fgLoGainFirst = 3 39 // fLoGainLast = fgLoGainLast = 14 36 // fHiGainFirst = fgHiGainFirst = 0 37 // fHiGainLast = fgHiGainLast = 29 38 // fLoGainFirst = fgLoGainFirst = 0 39 // fLoGainLast = fgLoGainLast = 0 40 // 41 // The FADC slices are fit by a Gaussian around the pulse maximum. 42 // The following figures show two typical (high-intensity and low-intensity) 43 // pulses together with the applied fit: 44 // 45 //Begin_Html 46 /* 47 <img src="images/PINDiode_pulse_high.gif"> 48 <img src="images/PINDiode_pulse_low.gif"> 49 */ 50 //End_Html 51 // 52 // The fit ranges can be modified with the functions: 53 // - SetLowerFitLimit() 54 // - SetUpperFitLimit() 55 // 56 // Defaults are: 57 // - fLowerFitLimit: 2 58 // - fUpperFitLimit: 5 40 59 // 41 60 ////////////////////////////////////////////////////////////////////////////// … … 44 63 #include <fstream> 45 64 65 #include <TF1.h> 66 #include <TH1.h> 67 #include <TPad.h> 68 46 69 #include "MLog.h" 47 70 #include "MLogManip.h" … … 61 84 using namespace std; 62 85 63 const UInt_t MExtractPINDiode::fgPINDiodeIdx = 100; 64 const Byte_t MExtractPINDiode::fgHiGainFirst = 0; 65 const Byte_t MExtractPINDiode::fgHiGainLast = 14; 66 const Byte_t MExtractPINDiode::fgLoGainFirst = 0; 67 const Byte_t MExtractPINDiode::fgLoGainLast = 14; 86 const UInt_t MExtractPINDiode::fgPINDiodeIdx = 3; 87 const Byte_t MExtractPINDiode::fgHiGainFirst = 0; 88 const Byte_t MExtractPINDiode::fgHiGainLast = 29; 89 const Byte_t MExtractPINDiode::fgLoGainFirst = 0; 90 const Byte_t MExtractPINDiode::fgLoGainLast = 0; 91 const Byte_t MExtractPINDiode::fgLowerFitLimit = 2; 92 const Byte_t MExtractPINDiode::fgUpperFitLimit = 5; 93 68 94 // -------------------------------------------------------------------------- 69 95 // … … 72 98 // Calls: 73 99 // - SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast) 74 // - SetPINDiodeIdx() 100 // 101 // - Set fPINDiodeIdx to fgPINDiodeIdx 102 // - Set fLowerFitLimit to fgLowerFitLimit 103 // - Set fUpperFitLimit to fgUpperFitLimit 75 104 // 76 105 MExtractPINDiode::MExtractPINDiode(const char *name, const char *title) 77 { 78 106 : fSlices(NULL) 107 { 108 79 109 fName = name ? name : "MExtractPINDiode"; 80 110 fTitle = title ? title : "Task to extract the signal from the FADC slices"; … … 82 112 SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast); 83 113 SetPINDiodeIdx(); 114 115 SetLowerFitLimit(); 116 SetUpperFitLimit(); 117 118 fPedMean.Set(2); 119 } 120 121 // -------------------------------------------------------------------------- 122 // 123 // - delete the histogram fSlices, if it exists 124 // 125 MExtractPINDiode::~MExtractPINDiode() 126 { 127 if (fSlices) 128 delete fSlices; 84 129 } 85 130 … … 89 134 // 90 135 // Checks: 91 // - if the window defined by (fHiGainLast-fHiGainFirst-1) are odd, subtract one 92 // - if the window defined by (fLoGainLast-fLoGainFirst-1) are odd, subtract one 93 // - if the Hi Gain window is smaller than 2, set fHiGainLast to fHiGainFirst+1 94 // - if the Lo Gain window is smaller than 2, set fLoGainLast to fLoGainFirst+1 136 // - if the Hi Gain window is smaller than 4, set fHiGainLast to fHiGainFirst+3 95 137 // 96 138 // Calls: … … 99 141 // Sets: 100 142 // - fNumHiGainSamples to: (Float_t)(fHiGainLast-fHiGainFirst+1) 101 // - fNumLoGainSamples to: (Float_t)(fLoGainLast-fLoGainFirst+1)143 // - fNumLoGainSamples to: 0. 102 144 // - fSqrtHiGainSamples to: TMath::Sqrt(fNumHiGainSamples) 103 // - fSqrtLoGainSamples to: TMath::Sqrt(fNumLoGainSamples)145 // - fSqrtLoGainSamples to: 0. 104 146 // 105 147 void MExtractPINDiode::SetRange(Byte_t hifirst, Byte_t hilast, Byte_t lofirst, Byte_t lolast) 106 148 { 107 149 108 const Byte_t window = hilast-hifirst+1+lolast-lofirst+1; 109 const Byte_t weven = window & ~1; 110 111 if (weven != window) 150 lofirst = 0; 151 lolast = 0; 152 153 const Byte_t window = hilast-hifirst+1; 154 155 if (window<4) 112 156 { 113 157 *fLog << warn << GetDescriptor() 114 << Form("%s%2i%s%2i",": Total window size has to be even, set last slice from " 115 ,(int)lolast," to ",(int)(lolast-1)) << endl; 116 lolast -= 1; 117 } 118 119 if (window<2) 120 { 121 *fLog << warn << GetDescriptor() 122 << Form("%s%2i%s%2i",": Total window is smaller than 2 FADC sampes, set last slice from" 123 ,(int)lolast," to ",(int)(lofirst+1)) << endl; 124 hilast = hifirst+1; 125 } 126 158 << Form("%s%2i%s%2i",": Total window is smaller than 4 FADC sampes, set last slice from" 159 ,(int)lolast," to ",(int)(lofirst+3)) << endl; 160 hilast = hifirst+3; 161 } 127 162 128 163 MExtractor::SetRange(hifirst,hilast,lofirst,lolast); 129 164 130 165 fNumHiGainSamples = (Float_t)(fHiGainLast-fHiGainFirst+1); 131 fNumLoGainSamples = (fLoGainLast == 0) ? 0. : (Float_t)(fLoGainLast-fLoGainFirst+1);166 fNumLoGainSamples = 0.; 132 167 133 168 fSqrtHiGainSamples = TMath::Sqrt(fNumHiGainSamples); 134 fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples); 135 136 fNumSamples = (fLoGainLast == 0) 137 ? fHiGainLast-fHiGainFirst+1 138 : fHiGainLast-fHiGainFirst+1+fLoGainLast-fLoGainFirst+1; 139 fSqrtSamples = TMath::Sqrt((Float_t)fNumSamples); 169 fSqrtLoGainSamples = 0.; 140 170 141 171 } … … 149 179 // they were not found: 150 180 // 181 // - MRawEvtData2 151 182 // - MExtractedPINDiode 183 // 184 // Initializes fPedMean to: 185 // - fPedMean[0]: pedestal + AB-offset 186 // - fPedMean[1]: pedestal - AB-offset 187 // 188 // Initializes TH1F fSlices to [fHiGainFirst-0.5,fHiGainLast+0.5] 152 189 // 153 190 Int_t MExtractPINDiode::PreProcess(MParList *pList) … … 157 194 return kFALSE; 158 195 196 fRawEvt = NULL; 197 fRawEvt = (MRawEvtData*)pList->FindObject(AddSerialNumber("MRawEvtData2")); 198 if (!fRawEvt) 199 { 200 *fLog << err << AddSerialNumber("MRawEvtData2") << " not found... aborting." << endl; 201 return kFALSE; 202 } 203 159 204 fPINDiode = (MExtractedSignalPINDiode*)pList->FindCreateObj(AddSerialNumber("MExtractedSignalPINDiode")); 160 205 if (!fPINDiode) 161 206 return kFALSE; 162 207 208 fPedMean.Reset(); 209 163 210 const MPedestalPix &ped = (*fPedestals)[fPINDiodeIdx]; 164 211 165 166 167 fPedestal = ped.GetPedestal();168 fPedRms = ped.GetPedestalRms();169 170 171 172 173 212 if (&ped) 213 { 214 fPedMean[0] = ped.GetPedestal() + ped.GetPedestalABoffset(); 215 fPedMean[1] = ped.GetPedestal() - ped.GetPedestalABoffset(); 216 } 217 else 218 { 219 *fLog << err << " Cannot find MPedestalPix of the PIN Diode (idx=" 220 << fPINDiodeIdx << ")" << endl; 174 221 return kFALSE; 175 } 176 177 return kTRUE; 222 } 223 224 if (fSlices) 225 delete fSlices; 226 227 fSlices = new TH1F("PINDiode","PIN Diode fitted slices",(Int_t)(fHiGainLast-fHiGainFirst+1), 228 fHiGainFirst-0.5,fHiGainLast+0.5); 229 fSlices->SetDirectory(NULL); 230 231 return kTRUE; 178 232 } 179 233 … … 190 244 191 245 fPINDiode->SetUsedFADCSlices(fHiGainFirst, fLoGainLast); 192 246 247 *fLog << endl; 248 *fLog << inf << "Taking " << fNumHiGainSamples 249 << " HiGain samples from slice " << (Int_t)fHiGainFirst 250 << " to " << (Int_t)(fHiGainLast+fHiLoLast) << " incl" << endl; 251 193 252 return kTRUE; 194 195 } 196 197 198 199 void MExtractPINDiode::FindSignalandVarianceHiGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const 200 { 201 202 Byte_t *end = ptr + fHiGainLast - fHiGainFirst + 1; 203 253 } 254 255 256 257 258 // ---------------------------------------------------------------------------------- 259 // 260 // Extracts the (pedestal-subtracted) FADC slices between fHiGainFirst and fHiGainLast 261 // and fills them into the histogram fSlices. Memorizes the position of maximum at 262 // maxpos. 263 // 264 // Checks for saturation 265 // 266 // Fits fSlices to a Gaussian in the ranges: maxpos-fLowerFitLimit, maxpos+fUpperFitLimit 267 // 268 // Writes fit results into MExtractedSignalPINDiode 269 // 270 Int_t MExtractPINDiode::Process() 271 { 272 273 274 MRawEvtPixelIter pixel(fRawEvt); 275 276 fPINDiode->Clear(); 277 fSlices->Reset(); 278 279 pixel.Jump(fPINDiodeIdx); 280 281 Byte_t sat = 0; 282 283 Int_t higainsamples = pixel.GetNumHiGainSamples(); 284 Int_t logainsamples = pixel.GetNumLoGainSamples(); 285 286 const Bool_t higainabflag = pixel.HasABFlag(); 287 Byte_t *ptr = pixel.GetHiGainSamples()+fHiGainFirst; 288 Byte_t *end = ptr+higainsamples; 289 290 Int_t cnt=0; 291 292 Float_t max = 0.; 293 Int_t maxpos = 0; 294 204 295 while (ptr<end) 205 296 { 206 sum += *ptr;207 sum2 += *ptr * *ptr;208 209 if (*ptr++ >= fSaturationLimit)210 sat++;211 }212 }213 214 void MExtractPINDiode::FindSignalandVarianceLoGain(Byte_t *ptr, Int_t &sum, Int_t &sum2, Byte_t &sat) const215 {216 217 Byte_t *end = ptr + fLoGainLast - fLoGainFirst + 1;218 219 while (ptr<end)220 {221 sum += *ptr;222 sum2 += *ptr * *ptr;223 297 224 if (*ptr++ >= fSaturationLimit) 225 sat++; 226 } 227 } 228 229 230 231 // -------------------------------------------------------------------------- 232 // 233 // Calculate the integral of the FADC time slices and store them as a new 234 // pixel in the MExtractedPINDiode container. 235 // 236 Int_t MExtractPINDiode::Process() 237 { 238 239 240 MRawEvtPixelIter pixel(fRawEvt); 241 242 fPINDiode->Clear(); 243 244 pixel.Jump(fPINDiodeIdx); 245 246 Int_t sum = 0; 247 Int_t sum2 = 0; 248 Byte_t sat = 0; 249 Int_t max = 0; 250 251 // 252 // Calculate first the time: 253 // 254 const Int_t maxhi = pixel.GetIdxMaxHiGainSample(); 255 const Int_t maxlo = pixel.GetIdxMaxLoGainSample(); 256 257 if (maxhi > maxlo) 258 max = maxhi; 259 else 260 max = maxlo + pixel.GetNumHiGainSamples(); 261 262 FindSignalandVarianceHiGain(pixel.GetHiGainSamples()+fHiGainFirst,sum,sum2,sat); 263 if (pixel.HasLoGain()) 264 FindSignalandVarianceLoGain(pixel.GetLoGainSamples()+fLoGainFirst,sum,sum2,sat); 265 266 const Float_t var = ((Float_t)sum2 - (Float_t)sum*sum/fNumSamples)/(fNumSamples-1); 267 const Float_t rms = TMath::Sqrt(var); 268 269 // 270 // FIXME: The following formulae have to be revised!! 271 // 272 fPINDiode->SetExtractedSignal(sum - fPedestal*fNumSamples, fPedRms*fSqrtSamples); 273 fPINDiode->SetExtractedRms (rms, rms/2./fSqrtSamples); 274 fPINDiode->SetExtractedTime (max, rms/fSqrtSamples); 275 fPINDiode->SetSaturation(sat); 298 if (*ptr >= fSaturationLimit) 299 { 300 sat++; 301 break; 302 } 303 304 const Float_t cont = (Float_t)*ptr - fPedMean[(cnt + higainabflag) & 0x1]; 305 fSlices->Fill(cnt,cont); 306 307 if (cont > max) 308 { 309 max = cont; 310 maxpos = cnt; 311 } 312 313 ptr++; 314 cnt++; 315 } 316 317 cnt = 0; 318 319 if (pixel.HasLoGain() && !sat) 320 { 321 322 ptr = pixel.GetLoGainSamples(); 323 end = ptr+logainsamples; 324 325 const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1; 326 327 while (ptr<end) 328 { 329 330 if (*ptr >= fSaturationLimit) 331 { 332 sat++; 333 break; 334 } 335 336 const Float_t cont = (Float_t)*ptr - fPedMean[(cnt + logainabflag) & 0x1]; 337 338 fSlices->Fill(cnt+ higainsamples,cont); 339 340 if (cont > max) 341 { 342 max = cont; 343 maxpos = cnt+higainsamples; 344 } 345 ptr++; 346 cnt++; 347 } 348 } 349 350 if (sat) 351 { 352 fPINDiode->SetSaturation(1); 353 return kTRUE; 354 } 355 356 fSlices->Fit("gaus", "RQ", "", maxpos-fLowerFitLimit,maxpos+fUpperFitLimit); 357 358 TF1 *gausfunc = fSlices->GetFunction("gaus"); 359 360 fPINDiode->SetExtractedSignal(gausfunc->GetParameter(0), gausfunc->GetParError(0)); 361 fPINDiode->SetExtractedTime (gausfunc->GetParameter(1), gausfunc->GetParError(1)); 362 fPINDiode->SetExtractedSigma (gausfunc->GetParameter(2), gausfunc->GetParError(2)); 363 fPINDiode->SetExtractedChi2 (gausfunc->GetChisquare()); 276 364 fPINDiode->SetReadyToSave(); 277 365 278 366 return kTRUE; 279 367 } 280 368 369 // ---------------------------------------------------------------------------------- 370 // 371 // deletes fSlices and sets pointer to NULL 372 // 373 Int_t MExtractPINDiode::PostProcess() 374 { 375 376 delete fSlices; 377 fSlices = NULL; 378 379 return kTRUE; 380 }
Note:
See TracChangeset
for help on using the changeset viewer.