Changeset 8072 for trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.h
- Timestamp:
- 10/16/06 18:02:31 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mextralgo/MExtralgoDigitalFilter.h
r7942 r8072 5 5 #include <TROOT.h> 6 6 #endif 7 8 class TH1; 9 class TH2; 10 class TH1F; 11 class TH2F; 12 class TArrayF; 7 13 8 14 class MExtralgoDigitalFilter … … 13 19 Int_t fNum; 14 20 15 Float_t *fWeightsAmp;16 Float_t *fWeightsTime;21 Float_t const *fWeightsAmp; 22 Float_t const *fWeightsTime; 17 23 18 Int_t fWeightsPerBin; // Number of weights per data bin 24 const Int_t fWeightsPerBin; // Number of weights per data bin 25 const Int_t fWindowSize; 19 26 20 27 // Result … … 24 31 Float_t fSignalDev; 25 32 26 inline void Eval(Double_t &sumamp, Double_t &sumtime, const Int_t windowsize, const Int_t startv, const Int_t startw=0) const 33 // Weights: Weights to evaluate 34 // Startv: Index of first bin of data 35 // startw: Offset on the weights 36 inline Double_t Eval(Float_t const *weights, const Int_t startv, const Int_t startw=0) const 27 37 { 28 38 // … … 30 40 // and multiply the entries with the corresponding weights 31 41 // 32 sumamp = 0; 33 sumtime = 0; 42 Double_t sum = 0; 34 43 35 44 // Shift the start of the weight to the center of sample 0 36 Float_t const *w a = fWeightsAmp + fWeightsPerBin/2+ startw;37 Float_t const *wt = fWeightsTime + fWeightsPerBin/2 + startw; 45 Float_t const *w = weights + startw; 46 38 47 Float_t *const beg = fVal+startv; 48 for (Float_t const *pex=beg; pex<beg+fWindowSize; pex++) 49 { 50 sum += *w * *pex; 51 w += fWeightsPerBin; 52 } 53 return sum; 54 } 39 55 40 for (Float_t const *pex=beg; pex<beg+windowsize; pex++) 56 inline void AlignIntoLimits(Int_t &maxp, Int_t &frac) const 57 { 58 // Align maxp into available range (TO BE CHECKED) 59 if (maxp < 0) 41 60 { 42 sumamp += *wa * *pex; 43 sumtime += *wt * *pex; 44 45 // Step forward by one bin 46 wa += fWeightsPerBin; 47 wt += fWeightsPerBin; 61 maxp = 0; 62 frac = fWeightsPerBin/2-1; // Assume peak at the end of the last slice 63 } 64 if (maxp > fNum-fWindowSize) 65 { 66 maxp = fNum-fWindowSize; 67 frac = -fWeightsPerBin/2; // Assume peak at the beginning of the first slice 48 68 } 49 69 } 50 70 71 inline Int_t AlignExtractionWindow(Int_t &maxp, Int_t &frac, const Double_t ampsum) 72 { 73 // Align extraction window to signal position 74 75 const Double_t timesum = Eval(fWeightsTime, maxp, frac); 76 77 // Because fWeightsPerBin/2 doesn't correspond to the center 78 // of a bin the time-values extracted are slightly positive. 79 // They are roughly between -0.45 and 0.55 80 const Double_t binoffset = TMath::Even(fWeightsPerBin) ? 0.5 : 0; 81 82 // This is the time offset from the extraction position 83 Double_t tmoffset = (frac+binoffset)/fWeightsPerBin + timesum/ampsum; 84 85 // Convert the residual fraction of one slice into an 86 // offset position in the extraction weights 87 const Int_t integ = TMath::FloorNint(tmoffset+0.5); 88 89 /* 90 if (integ>0) 91 tmoffset=0.49-0.05; 92 if (integ<0) 93 tmoffset=-0.49-0.05; 94 integ=0; 95 */ 96 97 // move the extractor by an offset number of slices 98 // determined by the extracted time 99 maxp -= integ; 100 101 frac = TMath::FloorNint((tmoffset-integ)*fWeightsPerBin); 102 103 // Align maxp into available range (TO BE CHECKED) 104 AlignIntoLimits(maxp, frac); 105 106 return integ; 107 } 108 109 inline void AlignExtractionWindow(Int_t &maxp, Int_t &frac) 110 { 111 const Double_t amp = Eval(fWeightsAmp, maxp, frac); 112 if (amp!=0) 113 AlignExtractionWindow(maxp, frac, amp); 114 } 115 51 116 public: 52 MExtralgoDigitalFilter(Float_t *val, Int_t n, Float_t *wa, Float_t *wt) 53 : fVal(val), fNum(n), 54 fWeightsAmp(wa), fWeightsTime(wt), fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1) 117 MExtralgoDigitalFilter(Int_t res, Int_t windowsize, Float_t *wa, Float_t *wt) 118 : fVal(0), fNum(0), fWeightsAmp(wa+res/2), fWeightsTime(wt+res/2), 119 fWeightsPerBin(res), fWindowSize(windowsize), 120 fTime(0), fTimeDev(-1), fSignal(0), fSignalDev(-1) 55 121 { 56 122 } 57 123 58 void Set WeightsPerBin(Int_t res) { fWeightsPerBin=res; }124 void SetData(Int_t n, Float_t *val) { fNum=n; fVal=val; } 59 125 60 126 Float_t GetTime() const { return fTime; } … … 67 133 void GetTime(Float_t &sig, Float_t &dsig) const { sig=fTime; dsig=fTimeDev; } 68 134 69 Float_t ExtractNoise(Int_t iter, Int_t windowsize) const; 70 void Extract(Int_t windowsize, Float_t timeshift); 135 Float_t ExtractNoise(Int_t iter) const; 136 void Extract(); 137 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); 71 140 }; 72 141
Note:
See TracChangeset
for help on using the changeset viewer.