Changeset 9226 for trunk/MagicSoft/Mars/mextralgo
- Timestamp:
- 01/17/09 14:52:43 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/mextralgo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mextralgo/ExtralgoIncl.h
r7942 r9226 1 1 #ifndef __CINT__ 2 2 3 #include "../mbase/MArrayF.h" 4 3 5 #endif // __CINT__ -
trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc
r9212 r9226 18 18 ! Author(s): Markus Gaug 09/2004 <mailto:markus@ifae.es> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2002-200 820 ! Copyright: MAGIC Software Development, 2002-2009 21 21 ! 22 22 ! … … 120 120 // -------------------------------------------------------------------------- 121 121 // 122 // Returns the highest x value in [min;max[ at which the spline in123 // the bin i is equal to y124 // 125 // min and max are defined to be [0;1]126 // 127 // The default for min is 0, the default for max is 1128 // The defaule for y is 0129 // 130 Double_t MExtralgoSpline::FindY(Int_t i, Bool_t downwards, Double_t y, Double_t min, Double_t max) const122 // Solve the polynomial 123 // 124 // y = a*x^3 + b*x^2 + c*x + d' 125 // 0 = a*x^3 + b*x^2 + c*x + d' - y 126 // 127 // to find y in the i-th bin. Return the result as x1, x2, x3 and the return 128 // code from MMath::SolvPol3. 129 // 130 Int_t MExtralgoSpline::SolvePol3(Int_t i, Double_t y, Double_t &x1, Double_t &x2, Double_t &x3) const 131 131 { 132 132 // y = a*x^3 + b*x^2 + c*x + d' … … 145 145 // return -2; 146 146 147 return MMath::SolvePol3(a, b, c, d, x1, x2, x3); 148 } 149 150 // -------------------------------------------------------------------------- 151 // 152 // Returns the highest x value in [min;max[ at which the spline in 153 // the bin i is equal to y 154 // 155 // min and max must be in the range [0;1] 156 // 157 // The default for min is 0, the default for max is 1 158 // The default for y is 0 159 // 160 Double_t MExtralgoSpline::FindYdn(Int_t i, Double_t y, Double_t min, Double_t max) const 161 { 147 162 Double_t x1, x2, x3; 148 const Int_t rc = MMath::SolvePol3(a, b, c, d, x1, x2, x3); 149 150 if (downwards==kTRUE) 151 { 152 Double_t x = -1; 153 154 if (rc>0 && x1>=min && x1<max && x1>x) 155 x = x1; 156 if (rc>1 && x2>=min && x2<max && x2>x) 157 x = x2; 158 if (rc>2 && x3>=min && x3<max && x3>x) 159 x = x3; 160 161 return x<0 ? -2 : x+i; 162 } 163 else 164 { 165 Double_t x = 2; 166 167 if (rc>0 && x1>min && x1<=max && x1<x) 168 x = x1; 169 if (rc>1 && x2>min && x2<=max && x2<x) 170 x = x2; 171 if (rc>2 && x3>min && x3<=max && x3<x) 172 x = x3; 173 174 return x>1 ? -2 : x+i; 175 } 176 177 return -2; 163 const Int_t rc = SolvePol3(i, y, x1, x2, x3); 164 165 Double_t x = -1; 166 167 if (rc>0 && x1>=min && x1<max && x1>x) 168 x = x1; 169 if (rc>1 && x2>=min && x2<max && x2>x) 170 x = x2; 171 if (rc>2 && x3>=min && x3<max && x3>x) 172 x = x3; 173 174 return x<0 ? -2 : x+i; 175 } 176 177 // -------------------------------------------------------------------------- 178 // 179 // Returns the lowest x value in [min;max[ at which the spline in 180 // the bin i is equal to y 181 // 182 // min and max must be in the range [0;1] 183 // 184 // The default for min is 0, the default for max is 1 185 // The default for y is 0 186 // 187 Double_t MExtralgoSpline::FindYup(Int_t i, Double_t y, Double_t min, Double_t max) const 188 { 189 Double_t x1, x2, x3; 190 const Int_t rc = SolvePol3(i, y, x1, x2, x3); 191 192 Double_t x = 2; 193 194 if (rc>0 && x1>min && x1<=max && x1<x) 195 x = x1; 196 if (rc>1 && x2>min && x2<=max && x2<x) 197 x = x2; 198 if (rc>2 && x3>min && x3<=max && x3<x) 199 x = x3; 200 201 return x>1 ? -2 : x+i; 178 202 } 179 203 … … 181 205 // 182 206 // Search analytically downward for the value y of the spline, starting 183 // at x, until x==0. If y is not found -2 is returned.207 // at x, until x==0. If y is not found or out of range -2 is returned. 184 208 // 185 209 Double_t MExtralgoSpline::SearchYdn(Float_t x, Float_t y) const … … 192 216 return -2; 193 217 194 Double_t rc = FindY (i, kTRUE, y, 0, x-i);218 Double_t rc = FindYdn(i, y, 0, x-i); 195 219 while (--i>=0 && rc<0) 196 rc = FindY (i, kTRUE, y);220 rc = FindYdn(i, y); 197 221 198 222 return rc; 199 223 } 200 224 225 // -------------------------------------------------------------------------- 226 // 227 // Search analytically upwards for the value y of the spline, starting 228 // at x, until x==fNum-1. If y is not found or out of range -2 is returned. 229 // 201 230 Double_t MExtralgoSpline::SearchYup(Float_t x, Float_t y) const 202 231 { … … 208 237 return -2; 209 238 210 Double_t rc = FindY (i, kFALSE, y, x-i, 1.);239 Double_t rc = FindYup(i, y, x-i, 1.); 211 240 while (++i<fNum-1 && rc<0) 212 rc = FindY (i, kFALSE, y);241 rc = FindYup(i, y); 213 242 214 243 return rc; … … 222 251 Float_t MExtralgoSpline::CalcIntegral(Float_t pos) const 223 252 { 224 // In the future we will calculate the intgeral analytically.225 // It has been tested that it gives identical results within226 // acceptable differences.227 228 253 // We allow extrapolation of 1/2 slice. 229 254 const Float_t min = fRiseTime; //-0.5+fRiseTime; … … 236 261 237 262 return EvalInteg(pos-fRiseTime, pos+fFallTime); 263 } 264 265 MArrayF MExtralgoSpline::GetIntegral(bool norm) const 266 { 267 MArrayF val(fNum); 268 269 //val[0] = 0; 270 271 Double_t integ = 0; 272 for (int i=0; i<fNum-1; i++) 273 { 274 integ += EvalInteg(i); 275 276 val[i+1] = integ; 277 } 278 279 if (norm) 280 for (int i=0; i<fNum-1; i++) 281 val[i+1] /= val[fNum-1]; 282 283 return val; 238 284 } 239 285 -
trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h
r9212 r9226 6 6 #endif 7 7 8 class MArrayF; 8 9 class TComplex; 9 10 … … 75 76 } 76 77 77 Double_t FindY(Int_t i, Bool_t downwards, Double_t y=0, Double_t min=0, Double_t max=1) const; 78 Int_t SolvePol3(Int_t i, Double_t y, Double_t &x1, Double_t &x2, Double_t &x3) const; 79 Double_t FindYdn(Int_t i, Double_t y=0, Double_t min=0, Double_t max=1) const; 80 Double_t FindYup(Int_t i, Double_t y=0, Double_t min=0, Double_t max=1) const; 81 //Double_t FindY(Int_t i, Bool_t downwards, Double_t y=0, Double_t min=0, Double_t max=1) const; 78 82 79 83 Int_t EvalDerivEq0(const Int_t i, Double_t &x1, Double_t &x2) const; … … 153 157 } 154 158 155 // Identical to sum EvalInteg(i, 0, 1) for i=0 to i<b but much faster 159 // Identical to sum of EvalInteg(i, 0, 1) for i=a to i=b-1, 160 // but much faster 161 // It is identical to EvalInteg(fVal[a], fVal[b]) 156 162 // Be carefull: NO RANGECHECK! 157 163 inline Double_t EvalInteg(Int_t a, Int_t b) const … … 329 335 Double_t SearchYdn(Float_t y) const { return SearchYdn(fNum, y); } 330 336 Double_t SearchYup(Float_t y) const { return SearchYup(0, y); } 337 338 MArrayF GetIntegral(bool norm=true) const; 331 339 }; 332 340
Note:
See TracChangeset
for help on using the changeset viewer.