Changeset 8154 for trunk/MagicSoft/Mars/mextralgo
- Timestamp:
- 10/24/06 09:26:10 (18 years ago)
- Location:
- trunk/MagicSoft/Mars/mextralgo
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.cc
r8072 r8154 38 38 } 39 39 40 // ----------------------------------------------------------------------------- 41 // 42 // Calculates the chi2 of the fit, once the weights have been iterated. 43 // Argument: time, obtained after a call to EvalDigitalFilterHiGain 44 // 45 Float_t MExtralgoDigitalFilter::GetChisq(const Int_t maxp, const Int_t frac, const Float_t sum) const 46 { 47 /* 48 TMatrix g (windowh,1); 49 TMatrix gt(windowh,1); 50 TMatrix y (windowh,1); 51 52 const Float_t etau = fFineAdjustHi*sumhi; 53 const Float_t t_fine = TMath::Abs(fFineAdjustHi)< 1./fBinningResolutionHiGain ? -fFineAdjustHi : 0.; 54 55 // if (t_fine==0.) 56 // return -1.; 57 58 if (fDebug) 59 gLog << all << " fMaxPHi: " << fMaxPHi << " fIterPHi " << fIterPHi << " t_fine: " << t_fine << endl; 60 61 // 62 // Slide with a window of size windowh over the sample 63 // and calculate the arrays by interpolating the pulse shape using the 64 // fine-tuned time information. 65 // 66 for (Int_t sample=0; sample < windowh; sample++) 67 { 68 const Int_t idx = fArrBinningResHalfHiGain[sample] + fIterPHi; 69 const Int_t ids = fMaxPHi + sample; 70 71 y [sample][0] = fHiGainSignalDF[ids]; 72 g [sample][0] = t_fine >= 0 73 ? (fPulseShapeHiGain[idx] + t_fine*(fPulseShapeHiGain[idx+1] -fPulseShapeHiGain[idx]) )*sumhi 74 : (fPulseShapeHiGain[idx] + t_fine*(fPulseShapeHiGain[idx] -fPulseShapeHiGain[idx-1]))*sumhi; 75 gt[sample][0] = t_fine >= 0 76 ? (fPulseShapeDotHiGain[idx] + t_fine*(fPulseShapeDotHiGain[idx+1]-fPulseShapeDotHiGain[idx]) )*etau 77 : (fPulseShapeDotHiGain[idx] + t_fine*(fPulseShapeDotHiGain[idx] -fPulseShapeDotHiGain[idx-1]) )*etau; 78 } 79 80 TMatrix second = y - g - gt; 81 TMatrix first(TMatrix::kTransposed,second); 82 TMatrix chisq = first * ((*fBHiInv)*second); 83 84 return chisq[0][0]/(windowh-2); 85 */ 86 /* 87 88 TMatrix S(fWindowSize, 1); // Signal (start==start of window) 89 for (int i=0; i<fWindowSize; i++) 90 S[i][0] = fVal[i+maxp]; 91 92 TMatrix g(fWindowSize, 1); 93 //TMatrix gT(fWindowSize, 1); 94 95 for (int i=0; i<fWindowSize; i++) 96 { 97 Int_t idx = fWeightsPerBin*i + frac; 98 99 // FIXME: Maybe we could do an interpolation on time-fineadj? 100 //Float_t slope = fPulseShapeHiGain[idx+1] -fPulseShapeHiGain[idx]; 101 //Float_t slopet = fPulseShapeDotHiGain[idx+1]-fPulseShapeDotHiGain[idx]; 102 103 g[i][0] = fPulseShapeHiGain[idx] *sumhi; 104 //gT[i][0] = fPulseShapeHiGainDot[idx]*tau; 105 } 106 107 TMatrix Ainv; // Autocorrelation Matrix (inverted) 108 109 TMatrix m = S - g;// - gT; 110 TMatrix mT(TMatrix::kTransposed, m); 111 112 TMatrix chisq = mT * (Ainv*m); 113 114 return chisq[0][0]/(fWindowSize-2); 115 */ 116 117 Double_t sumc = 0; 118 119 TMatrix d(fWindowSize, 1); // Signal (start==start of window) 120 for (int i=0; i<fWindowSize; i++) 121 { 122 d[i][0] = fVal[i+maxp]/sum - fPulseShape[fWeightsPerBin*i + frac]; 123 sumc += d[i][0]*d[i][0]; 124 } 125 126 /* 127 TMatrix Ainv; // Autocorrelation Matrix (inverted) 128 129 TMatrix dT(TMatrix::kTransposed, d); 130 131 TMatrix chisq = dT * (*fAinv*d); 132 */ 133 return sumc;//chisq[0][0]/(fWindowSize-2); 134 } 135 40 136 #include <iostream> 41 void MExtralgoDigitalFilter::Extract( )137 void MExtralgoDigitalFilter::Extract(Int_t maxpos) 42 138 { 43 139 fSignal = 0; // default is: no pulse found … … 54 150 // Calculate the sum of the first fWindowSize slices 55 151 // 56 57 // For the case of an even numberof weights/bin there is 152 // For the case of an even number of weights/bin there is 58 153 // no central bin.So we create an artificial central bin. 59 154 for (Int_t i=0; i<fNum-fWindowSize+1; i++) … … 66 161 } 67 162 } 163 164 /* 165 // This could be for a fast but less accurate extraction.... 166 maxamp = Eval(fWeightsAmp, maxpos-fWindowSize/2); 167 maxp = maxpos-fWindowSize/2; 168 */ 169 68 170 // The number of available slices were smaller than the 69 171 // extraction window size of the extractor … … 136 238 fTime -= timefineadjust; 137 239 } 240 138 241 139 242 #include <TH1.h> … … 145 248 #include <TProfile.h> 146 249 147 Bool_t MExtralgoDigitalFilter::CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb)250 Int_t MExtralgoDigitalFilter::CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb) 148 251 { 149 252 const Int_t weightsperbin = wpb<=0?shape.GetNbinsX()/autocorr.GetNbinsX():wpb; … … 154 257 cout << " Shape: " << shape.GetNbinsX() << endl; 155 258 cout << " ACorr: " << autocorr.GetNbinsX() << endl; 156 return kFALSE;259 return -1; 157 260 } 158 261 … … 180 283 // FIXME: DELETE!!! 181 284 TH1 &derivative = *static_cast<TH1*>(shape.Clone()); 285 derivative.SetDirectory(0); 182 286 derivative.Reset(); 183 287 … … 233 337 { 234 338 cout << "ERROR - Division by zero: denom[0][0]==0 for i=" << i << "." << endl; 235 return kFALSE;339 return -1; 236 340 } 237 341 … … 248 352 } 249 353 250 return kTRUE;354 return first*weightsperbin; 251 355 } 252 356 253 void MExtralgoDigitalFilter::CalculateWeights2(TH1F &shape, const TH2F&autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb)357 Int_t MExtralgoDigitalFilter::CalculateWeights2(TH1 &shape, const TH2 &autocorr, TArrayF &weightsamp, TArrayF &weightstime, Int_t wpb) 254 358 { 255 359 const Int_t weightsperbin = wpb<=0?shape.GetNbinsX()/autocorr.GetNbinsX():wpb; … … 260 364 cout << " Shape: " << shape.GetNbinsX() << endl; 261 365 cout << " ACorr: " << autocorr.GetNbinsX() << endl; 262 return ;366 return -1; 263 367 } 264 368 … … 282 386 TSpline5 val("Signal", &gr); 283 387 284 TH1F derivative(shape); 388 // FIXME: DELETE!!! 389 TH1 &derivative = *static_cast<TH1*>(shape.Clone()); 390 derivative.SetDirectory(0); 285 391 derivative.Reset(); 286 392 … … 331 437 const TMatrixD denom = (gT*(B*g))*(dT*(B*d)) - (dT*(B*g))*(dT*(B*g)); 332 438 439 if (denom[0][0]==0) 440 { 441 cout << "ERROR - Division by zero: denom[0][0]==0 for i=" << i << "." << endl; 442 return -1; 443 } 444 333 445 const TMatrixD w_amp = (dT*(B*d))*(gT*B) - (gT*(B*d))*(dT*B); 334 446 const TMatrixD w_time = (gT*(B*g))*(dT*B) - (gT*(B*d))*(gT*B); … … 342 454 } 343 455 } 456 return first*weightsperbin; 344 457 } 345 /*346 Int_t start = fBinningResolutionHiGain*(fSignalStartBinHiGain + 1);347 for (Int_t i = -fBinningResolutionHiGain/2+1; i<=fBinningResolutionHiGain/2; i++)348 {349 // i = -4...5350 for (Int_t count=0; count < fWindowSizeHiGain; count++)351 {352 // count=0: pos=10*(start+0) + 10 + i353 // count=1: pos=10*(start+1) + 10 + i354 // count=2: pos=10*(start+2) + 10 + i355 // count=3: pos=10*(start+3) + 10 + i356 }357 358 for (Int_t count=0; count < fWindowSizeHiGain; count++)359 {360 // count=0: pos = 10*0 + 5 +i-1361 // count=1: pos = 10*1 + 5 +i-1362 // count=2: pos = 10*2 + 5 +i-1363 // count=3: pos = 10*3 + 5 +i-1364 }365 }366 367 Int_t start = fBinningResolutionLoGain*fSignalStartBinLoGain + fBinningResolutionLoGain/2;368 for (Int_t i = -fBinningResolutionLoGain/2+1; i<=fBinningResolutionLoGain/2; i++)369 {370 // i=-4..5371 for (Int_t count=0; count < fWindowSizeLoGain; count++)372 {373 // count=0: pos = 10*(start+0) + 5 + i374 // count=1: pos = 10*(start+1) + 5 + i375 // count=2: pos = 10*(start+2) + 5 + i376 // count=3: pos = 10*(start+3) + 5 + i377 }378 379 for (Int_t count=0; count < fWindowSizeLoGain; count++)380 {381 // count=0: pos = 10*0 + 5 +i-1382 // count=1: pos = 10*1 + 5 +i-1383 // count=2: pos = 10*2 + 5 +i-1384 // count=3: pos = 10*3 + 5 +i-1385 }386 }387 */ -
trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.h
r8072 r8154 2 2 #define MARS_MExtralgoDigitalFilter 3 3 4 #ifndef ROOT_T ROOT5 #include <T ROOT.h>4 #ifndef ROOT_TMatrix 5 #include <TMatrix.h> 6 6 #endif 7 7 … … 12 12 class TArrayF; 13 13 14 //#include <TMatrix.h> 15 14 16 class MExtralgoDigitalFilter 15 17 { 16 18 private: 17 19 // Input 18 Float_t *fVal;19 Int_t 20 const Float_t *fVal; 21 Int_t fNum; 20 22 21 23 Float_t const *fWeightsAmp; 22 24 Float_t const *fWeightsTime; 25 Float_t const *fPulseShape; 26 27 const TMatrix *fAinv; 23 28 24 29 const Int_t fWeightsPerBin; // Number of weights per data bin … … 30 35 Float_t fSignal; 31 36 Float_t fSignalDev; 37 38 Float_t GetChisq(const Int_t maxp, const Int_t frac, const Float_t sum) const; 39 40 inline Double_t ChiSq(const Double_t sum, const Int_t startv, const Int_t startw=0) const 41 { 42 // 43 // Slide with a window of size windowsize over the sample 44 // and multiply the entries with the corresponding weights 45 // 46 Double_t chisq = 0; 47 48 // Shift the start of the weight to the center of sample 0 49 Float_t const *w = fPulseShape + startw; 50 51 const Float_t *beg = fVal+startv; 52 for (Float_t const *pex=beg; pex<beg+fWindowSize; pex++) 53 { 54 const Double_t c = *w - *pex/sum; 55 chisq += c*c; 56 w += fWeightsPerBin; 57 } 58 return chisq; 59 } 32 60 33 61 // Weights: Weights to evaluate … … 45 73 Float_t const *w = weights + startw; 46 74 47 Float_t *constbeg = fVal+startv;75 const Float_t *beg = fVal+startv; 48 76 for (Float_t const *pex=beg; pex<beg+fWindowSize; pex++) 49 77 { … … 115 143 116 144 public: 117 MExtralgoDigitalFilter(Int_t res, Int_t windowsize, Float_t *wa, Float_t *wt )145 MExtralgoDigitalFilter(Int_t res, Int_t windowsize, Float_t *wa, Float_t *wt, Float_t *ps=0, TMatrix *ainv=0) 118 146 : fVal(0), fNum(0), fWeightsAmp(wa+res/2), fWeightsTime(wt+res/2), 119 f WeightsPerBin(res), fWindowSize(windowsize),147 fPulseShape(ps), fAinv(ainv), fWeightsPerBin(res), fWindowSize(windowsize), 120 148 fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1) 121 149 { 122 150 } 123 151 124 void SetData(Int_t n, Float_t *val) { fNum=n; fVal=val; }152 void SetData(Int_t n, Float_t const *val) { fNum=n; fVal=val; } 125 153 126 154 Float_t GetTime() const { return fTime; } … … 134 162 135 163 Float_t ExtractNoise(Int_t iter) const; 136 void Extract( );164 void Extract(Int_t maxpos=-1); 137 165 138 static Bool_t CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1);139 static void CalculateWeights2(TH1F &shape, const TH2F&autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1);166 static Int_t CalculateWeights(TH1 &shape, const TH2 &autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1); 167 static Int_t CalculateWeights2(TH1 &shape, const TH2 &autocorr, TArrayF &wa, TArrayF &wt, Int_t wpb=-1); 140 168 }; 141 169 -
trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc
r7999 r8154 207 207 } 208 208 209 #include <TRandom.h> 209 210 Float_t MExtralgoSpline::ExtractNoise(Int_t iter) 210 211 { 211 const Float_t nsx = iter * fResolution;212 const Float_t nsx = gRandom->Uniform(); //iter * fResolution; 212 213 213 214 if (fExtractionType == kAmplitude) … … 223 224 fSignalDev = -1; 224 225 fTimeDev = -1; 225 226 /* 226 227 // 227 228 // Allow no saturated slice and … … 229 230 // 230 231 231 /*232 232 const Bool_t limlo = maxbin < TMath::Ceil(fRiseTime); 233 233 const Bool_t limup = maxbin > fNum-TMath::Ceil(fFallTime)-1; … … 248 248 return; 249 249 } 250 */251 252 fTimeDev = fResolution;253 250 254 251 // … … 256 253 // 257 254 258 259 /*260 255 Float_t step = 0.2; // start with step size of 1ns and loop again with the smaller one 261 256 … … 346 341 } 347 342 } 348 */ 349 343 344 fTime = maxpos; 345 fTimeDev = fResolution; 346 fSignal = CalcIntegral(maxpos); 347 fSignalDev = 0; // means: is valid 348 349 return; 350 */ 350 351 // --- Start NEW --- 351 352 … … 369 370 370 371 Float_t maxpos, maxval; 372 // FIXME: Check the dfeault if no maximum found!!! 371 373 GetMaxAroundI(maxbin, maxpos, maxval); 372 374 … … 376 378 { 377 379 fTime = maxpos; 380 fTimeDev = fResolution; 378 381 fSignal = maxval; 379 382 fSignalDev = 0; // means: is valid … … 381 384 } 382 385 383 //384 // Loop from the beginning of the slice upwards to reach the maxhalf:385 // With means of bisection:386 //387 /*388 static const Float_t sqrt2 = TMath::Sqrt(2.);389 390 step = sqrt2*3*0.061;//fRiseTime;391 Float_t x = maxpos-0.86-3*0.061;//fRiseTime*1.25;392 393 // step = sqrt2*0.5;//fRiseTime;394 // Float_t x = maxpos-1.25;//fRiseTime*1.25;395 396 Int_t cnt =0;397 while (cnt++<30)398 {399 const Float_t y=EvalAt(x);400 401 if (TMath::Abs(y-maxval/2)<fResolution)402 break;403 404 step /= sqrt2; // /2405 x += y>maxval/2 ? -step : +step;406 }407 */408 409 386 // Search downwards for maxval/2 410 387 // By doing also a search upwards we could extract the pulse width … … 412 389 413 390 fTime = x1; 391 fTimeDev = fResolution; 414 392 fSignal = CalcIntegral(maxpos); 415 393 fSignalDev = 0; // means: is valid 416 394 417 //if (fSignal>100) 418 // cout << "V=" << maxpos-x1 << endl; 395 // 396 // Loop from the beginning of the slice upwards to reach the maxhalf: 397 // With means of bisection: 398 // 399 /* 400 static const Float_t sqrt2 = TMath::Sqrt(2.); 401 402 step = sqrt2*3*0.061;//fRiseTime; 403 Float_t x = maxpos-0.86-3*0.061;//fRiseTime*1.25; 404 405 // step = sqrt2*0.5;//fRiseTime; 406 // Float_t x = maxpos-1.25;//fRiseTime*1.25; 407 408 Int_t cnt =0; 409 while (cnt++<30) 410 { 411 const Float_t y=EvalAt(x); 412 413 if (TMath::Abs(y-maxval/2)<fResolution) 414 break; 415 416 step /= sqrt2; // /2 417 x += y>maxval/2 ? -step : +step; 418 } 419 */ 419 420 420 421 // … … 422 423 // 423 424 // fTime = cnt==31 ? -1 : x; 425 // fTimeDev = fResolution; 424 426 // fSignal = cnt==31 ? CalcIntegral(x) : CalcIntegral(maxpos); 425 427 // fSignalDev = 0; // means: is valid -
trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h
r7999 r8154 21 21 22 22 // Input 23 Float_t *fVal;24 Int_t fNum;23 Float_t const *fVal; 24 const Int_t fNum; 25 25 26 26 Float_t *fDer1; … … 238 238 239 239 // Take a default in case no maximum is found 240 // FIXME: Check THIS!!! 240 241 xmax=i; 241 242 ymax=fVal[i]; … … 438 439 439 440 public: 440 MExtralgoSpline( Float_t *val, Int_t n, Float_t *der1, Float_t *der2)441 MExtralgoSpline(const Float_t *val, Int_t n, Float_t *der1, Float_t *der2) 441 442 : fExtractionType(kIntegral), fVal(val), fNum(n), fDer1(der1), fDer2(der2), fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1) 442 443 {
Note:
See TracChangeset
for help on using the changeset viewer.