Changeset 7409 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 11/18/05 17:15:30 (19 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/BaseIncl.h
r7181 r7409 1 1 #ifndef __CINT__ 2 2 3 #include <TArrayD.h> 3 4 #include <TVector3.h> 4 5 5 /*6 #include <fstream.h>7 8 #include <TFile.h>9 #include <TTree.h>10 11 #include <TGListBox.h>12 */13 14 6 #endif // __CINT__ -
trunk/MagicSoft/Mars/mbase/MLogHtml.cc
r6870 r7409 30 30 ////////////////////////////////////////////////////////////////////////////// 31 31 #include "MLogHtml.h" 32 33 #include <string.h> // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2 34 #include <errno.h> // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2 32 35 33 36 #include <fstream> // ofstream -
trunk/MagicSoft/Mars/mbase/MMath.cc
r7386 r7409 36 36 #endif 37 37 38 #ifndef ROOT_TArrayD 39 #include <TArrayD.h> 40 #endif 38 41 // -------------------------------------------------------------------------- 39 42 // … … 248 251 return InterpolParabLin(vx0, vy, TMath::Cos(x)); 249 252 } 253 254 // -------------------------------------------------------------------------- 255 // 256 // Analytically calculated result of a least square fit of: 257 // y = A*e^(B*x) 258 // Equal weights 259 // 260 // It returns TArrayD(2) = { A, B }; 261 // 262 // see: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html 263 // 264 TArrayD MMath::LeastSqFitExpW1(Int_t n, Double_t *x, Double_t *y) 265 { 266 Double_t sumxsqy = 0; 267 Double_t sumylny = 0; 268 Double_t sumxy = 0; 269 Double_t sumy = 0; 270 Double_t sumxylny = 0; 271 for (int i=0; i<n; i++) 272 { 273 sumylny += y[i]*TMath::Log(y[i]); 274 sumxy += x[i]*y[i]; 275 sumxsqy += x[i]*x[i]*y[i]; 276 sumxylny += x[i]*y[i]*TMath::Log(y[i]); 277 sumy += y[i]; 278 } 279 280 const Double_t dev = sumy*sumxsqy - sumxy*sumxy; 281 282 const Double_t a = (sumxsqy*sumylny - sumxy*sumxylny)/dev; 283 const Double_t b = (sumy*sumxylny - sumxy*sumylny)/dev; 284 285 TArrayD rc(2); 286 rc[0] = TMath::Exp(a); 287 rc[1] = b; 288 return rc; 289 } 290 291 // -------------------------------------------------------------------------- 292 // 293 // Analytically calculated result of a least square fit of: 294 // y = A*e^(B*x) 295 // Greater weights to smaller values 296 // 297 // It returns TArrayD(2) = { A, B }; 298 // 299 // see: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html 300 // 301 TArrayD MMath::LeastSqFitExp(Int_t n, Double_t *x, Double_t *y) 302 { 303 // -------- Greater weights to smaller values --------- 304 Double_t sumlny = 0; 305 Double_t sumxlny = 0; 306 Double_t sumxsq = 0; 307 Double_t sumx = 0; 308 for (int i=0; i<n; i++) 309 { 310 sumlny += TMath::Log(y[i]); 311 sumxlny += x[i]*TMath::Log(y[i]); 312 313 sumxsq += x[i]*x[i]; 314 sumx += x[i]; 315 } 316 317 const Double_t dev = n*sumxsq-sumx*sumx; 318 319 const Double_t a = (sumlny*sumxsq - sumx*sumxlny)/dev; 320 const Double_t b = (n*sumxlny - sumx*sumlny)/dev; 321 322 TArrayD rc(2); 323 rc[0] = TMath::Exp(a); 324 rc[1] = b; 325 return rc; 326 } 327 328 // -------------------------------------------------------------------------- 329 // 330 // Analytically calculated result of a least square fit of: 331 // y = A+B*ln(x) 332 // 333 // It returns TArrayD(2) = { A, B }; 334 // 335 // see: http://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html 336 // 337 TArrayD LeastSqFitLog(Int_t n, Double_t *x, Double_t *y) 338 { 339 Double_t sumylnx = 0; 340 Double_t sumy = 0; 341 Double_t sumlnx = 0; 342 Double_t sumlnxsq = 0; 343 for (int i=0; i<n; i++) 344 { 345 sumylnx += y[i]*TMath::Log(x[i]); 346 sumy += y[i]; 347 sumlnx += TMath::Log(x[i]); 348 sumlnxsq += TMath::Log(x[i])*TMath::Log(x[i]); 349 } 350 351 const Double_t b = (n*sumylnx-sumy*sumlnx)/(n*sumlnxsq-sumlnx*sumlnx); 352 const Double_t a = (sumy-b*sumlnx)/n; 353 354 TArrayD rc(2); 355 rc[0] = a; 356 rc[1] = b; 357 return rc; 358 } 359 360 // -------------------------------------------------------------------------- 361 // 362 // Analytically calculated result of a least square fit of: 363 // y = A*x^B 364 // 365 // It returns TArrayD(2) = { A, B }; 366 // 367 // see: http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html 368 // 369 TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y) 370 { 371 Double_t sumlnxlny = 0; 372 Double_t sumlnx = 0; 373 Double_t sumlny = 0; 374 Double_t sumlnxsq = 0; 375 for (int i=0; i<n; i++) 376 { 377 sumlnxlny += TMath::Log(x[i])*TMath::Log(y[i]); 378 sumlnx += TMath::Log(x[i]); 379 sumlny += TMath::Log(y[i]); 380 sumlnxsq += TMath::Log(x[i])*TMath::Log(x[i]); 381 } 382 383 const Double_t b = (n*sumlnxlny-sumlnx*sumlny)/(n*sumlnxsq-sumlnx*sumlnx); 384 const Double_t a = (sumlny-b*sumlnx)/n; 385 386 TArrayD rc(2); 387 rc[0] = TMath::Exp(a); 388 rc[1] = b; 389 return rc; 390 } -
trunk/MagicSoft/Mars/mbase/MMath.h
r7384 r7409 7 7 8 8 class TVector3; 9 class TArrayD; 9 10 10 11 namespace MMath … … 31 32 Double_t InterpolParabCos(const TVector3 &vx, const TVector3 &vy, Double_t x); 32 33 34 TArrayD LeastSqFitExpW1(Int_t n, Double_t *x, Double_t *y); 35 TArrayD LeastSqFitExp(Int_t n, Double_t *x, Double_t *y); 36 TArrayD LeastSqFitLog(Int_t n, Double_t *x, Double_t *y); 37 TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y); 38 33 39 inline Double_t Sgn(Double_t d) { return d<0 ? -1 : 1; } 34 40 }
Note:
See TracChangeset
for help on using the changeset viewer.