otsdaq_utilities  v2_05_02_indev
JSRootMath.js
1 
7 (function( factory ) {
8  if ( typeof define === "function" && define.amd ) {
9  define( ['JSRootCore'], factory );
10  } else if (typeof exports === 'object' && typeof module !== 'undefined') {
11  factory(require("./JSRootCore.js"));
12  } else {
13  if (typeof JSROOT == 'undefined')
14  throw new Error("This extension requires JSRootCore.js", "JSRootMath.js");
15  if (typeof JSROOT.Math == "object")
16  throw new Error("This JSROOT Math already loaded", "JSRootMath.js");
17  factory(JSROOT);
18  }
19 } (function(JSROOT) {
20  // math methods for Javascript ROOT
21 
22  "use strict";
23 
24  JSROOT.sources.push("math");
25 
26  JSROOT.Math = {};
27 
29  JSROOT.Math.lgam = function( x ) {
30  var p, q, u, w, z, i, sgngam = 1;
31  var kMAXLGM = 2.556348e305;
32  var LS2PI = 0.91893853320467274178;
33 
34  var A = [
35  8.11614167470508450300E-4,
36  -5.95061904284301438324E-4,
37  7.93650340457716943945E-4,
38  -2.77777777730099687205E-3,
39  8.33333333333331927722E-2
40  ];
41 
42  var B = [
43  -1.37825152569120859100E3,
44  -3.88016315134637840924E4,
45  -3.31612992738871184744E5,
46  -1.16237097492762307383E6,
47  -1.72173700820839662146E6,
48  -8.53555664245765465627E5
49  ];
50 
51  var C = [
52  /* 1.00000000000000000000E0, */
53  -3.51815701436523470549E2,
54  -1.70642106651881159223E4,
55  -2.20528590553854454839E5,
56  -1.13933444367982507207E6,
57  -2.53252307177582951285E6,
58  -2.01889141433532773231E6
59  ];
60 
61  if (x >= Number.POSITIVE_INFINITY)
62  return(Number.POSITIVE_INFINITY);
63 
64  if ( x < -34.0 ) {
65  q = -x;
66  w = this.lgam(q);
67  p = Math.floor(q);
68  if ( p==q )//_unur_FP_same(p,q)
69  return (Number.POSITIVE_INFINITY);
70  i = Math.round(p);
71  if ( (i & 1) == 0 )
72  sgngam = -1;
73  else
74  sgngam = 1;
75  z = q - p;
76  if ( z > 0.5 ) {
77  p += 1.0;
78  z = p - q;
79  }
80  z = q * Math.sin( Math.PI * z );
81  if ( z < 1e-300 )
82  return (Number.POSITIVE_INFINITY);
83  z = Math.log(Math.PI) - Math.log( z ) - w;
84  return( z );
85  }
86  if ( x < 13.0 ) {
87  z = 1.0;
88  p = 0.0;
89  u = x;
90  while ( u >= 3.0 ) {
91  p -= 1.0;
92  u = x + p;
93  z *= u;
94  }
95  while ( u < 2.0 ) {
96  if ( u < 1e-300 )
97  return (Number.POSITIVE_INFINITY);
98  z /= u;
99  p += 1.0;
100  u = x + p;
101  }
102  if ( z < 0.0 ) {
103  sgngam = -1;
104  z = -z;
105  }
106  else
107  sgngam = 1;
108  if ( u == 2.0 )
109  return( Math.log(z) );
110  p -= 2.0;
111  x = x + p;
112  p = x * this.Polynomialeval(x, B, 5 ) / this.Polynomial1eval( x, C, 6);
113  return( Math.log(z) + p );
114  }
115  if ( x > kMAXLGM )
116  return( sgngam * Number.POSITIVE_INFINITY );
117 
118  q = ( x - 0.5 ) * Math.log(x) - x + LS2PI;
119  if ( x > 1.0e8 )
120  return( q );
121 
122  p = 1.0/(x*x);
123  if ( x >= 1000.0 )
124  q += ((7.9365079365079365079365e-4 * p
125  - 2.7777777777777777777778e-3) *p
126  + 0.0833333333333333333333) / x;
127  else
128  q += this.Polynomialeval( p, A, 4 ) / x;
129  return( q );
130  };
131 
138  JSROOT.Math.Polynomialeval = function(x, a, N) {
139  if (N==0) return a[0];
140  else {
141  var pom = a[0];
142  for (var i=1; i <= N; ++i)
143  pom = pom *x + a[i];
144  return pom;
145  }
146  };
147 
154  JSROOT.Math.Polynomial1eval = function(x, a, N) {
155  if (N==0) return a[0];
156  else {
157  var pom = x + a[0];
158  for (var i=1; i < N; ++i)
159  pom = pom *x + a[i];
160  return pom;
161  }
162  };
163 
165  JSROOT.Math.ndtri = function( y0 ) {
166  if ( y0 <= 0.0 )
167  return( Number.NEGATIVE_INFINITY );
168  if ( y0 >= 1.0 )
169  return( Number.POSITIVE_INFINITY );
170 
171  var P0 = new Array(
172  -5.99633501014107895267E1,
173  9.80010754185999661536E1,
174  -5.66762857469070293439E1,
175  1.39312609387279679503E1,
176  -1.23916583867381258016E0
177  );
178 
179  var Q0 = new Array(
180  1.95448858338141759834E0,
181  4.67627912898881538453E0,
182  8.63602421390890590575E1,
183  -2.25462687854119370527E2,
184  2.00260212380060660359E2,
185  -8.20372256168333339912E1,
186  1.59056225126211695515E1,
187  -1.18331621121330003142E0
188  );
189 
190  var P1 = new Array(
191  4.05544892305962419923E0,
192  3.15251094599893866154E1,
193  5.71628192246421288162E1,
194  4.40805073893200834700E1,
195  1.46849561928858024014E1,
196  2.18663306850790267539E0,
197  -1.40256079171354495875E-1,
198  -3.50424626827848203418E-2,
199  -8.57456785154685413611E-4
200  );
201 
202  var Q1 = new Array(
203  1.57799883256466749731E1,
204  4.53907635128879210584E1,
205  4.13172038254672030440E1,
206  1.50425385692907503408E1,
207  2.50464946208309415979E0,
208  -1.42182922854787788574E-1,
209  -3.80806407691578277194E-2,
210  -9.33259480895457427372E-4
211  );
212 
213  var P2 = new Array(
214  3.23774891776946035970E0,
215  6.91522889068984211695E0,
216  3.93881025292474443415E0,
217  1.33303460815807542389E0,
218  2.01485389549179081538E-1,
219  1.23716634817820021358E-2,
220  3.01581553508235416007E-4,
221  2.65806974686737550832E-6,
222  6.23974539184983293730E-9
223  );
224 
225  var Q2 = new Array(
226  6.02427039364742014255E0,
227  3.67983563856160859403E0,
228  1.37702099489081330271E0,
229  2.16236993594496635890E-1,
230  1.34204006088543189037E-2,
231  3.28014464682127739104E-4,
232  2.89247864745380683936E-6,
233  6.79019408009981274425E-9
234  );
235 
236  var s2pi = 2.50662827463100050242e0;
237  var code = 1;
238  var y = y0;
239  var x, z, y2, x0, x1;
240 
241  if ( y > (1.0 - 0.13533528323661269189) ) {
242  y = 1.0 - y;
243  code = 0;
244  }
245  if ( y > 0.13533528323661269189 ) {
246  y = y - 0.5;
247  y2 = y * y;
248  x = y + y * (y2 * this.Polynomialeval( y2, P0, 4)/ this.Polynomial1eval( y2, Q0, 8 ));
249  x = x * s2pi;
250  return(x);
251  }
252  x = Math.sqrt( -2.0 * Math.log(y) );
253  x0 = x - Math.log(x)/x;
254  z = 1.0/x;
255  if ( x < 8.0 )
256  x1 = z * this.Polynomialeval( z, P1, 8 )/ this.Polynomial1eval( z, Q1, 8 );
257  else
258  x1 = z * this.Polynomialeval( z, P2, 8 )/ this.Polynomial1eval( z, Q2, 8 );
259  x = x0 - x1;
260  if ( code != 0 )
261  x = -x;
262  return( x );
263  };
264 
265  JSROOT.Math.normal_quantile = function(z, sigma) {
266  return sigma * JSROOT.Math.ndtri(z);
267  };
268 
270  JSROOT.Math.igam = function(a,x) {
271  var kMACHEP = 1.11022302462515654042363166809e-16;
272  var kMAXLOG = 709.782712893383973096206318587;
273  var ans, ax, c, r;
274 
275  // LM: for negative values returns 1.0 instead of zero
276  // This is correct if a is a negative integer since Gamma(-n) = +/- inf
277  if (a <= 0) return 1.0;
278 
279  if (x <= 0) return 0.0;
280 
281  if( (x > 1.0) && (x > a ) )
282  return 1.0 - this.igamc(a,x);
283 
284  /* Compute x**a * exp(-x) / gamma(a) */
285  ax = a * Math.log(x) - x - this.lgam(a);
286  if( ax < -kMAXLOG )
287  return 0.0;
288 
289  ax = Math.exp(ax);
290 
291  /* power series */
292  r = a;
293  c = 1.0;
294  ans = 1.0;
295 
296  do
297  {
298  r += 1.0;
299  c *= x/r;
300  ans += c;
301  }
302  while( c/ans > kMACHEP );
303 
304  return ans * ax/a;
305  };
306 
308  JSROOT.Math.igamc = function(a,x) {
309  var kMACHEP = 1.11022302462515654042363166809e-16;
310  var kMAXLOG = 709.782712893383973096206318587;
311 
312  var kBig = 4.503599627370496e15;
313  var kBiginv = 2.22044604925031308085e-16;
314 
315  var ans, ax, c, yc, r, t, y, z;
316  var pk, pkm1, pkm2, qk, qkm1, qkm2;
317 
318  // LM: for negative values returns 0.0
319  // This is correct if a is a negative integer since Gamma(-n) = +/- inf
320  if (a <= 0) return 0.0;
321 
322  if (x <= 0) return 1.0;
323 
324  if( (x < 1.0) || (x < a) )
325  return ( 1.0 - JSROOT.Math.igam(a,x) );
326 
327  ax = a * Math.log(x) - x - JSROOT.Math.lgam(a);
328  if( ax < -kMAXLOG )
329  return( 0.0 );
330 
331  ax = Math.exp(ax);
332 
333  /* continued fraction */
334  y = 1.0 - a;
335  z = x + y + 1.0;
336  c = 0.0;
337  pkm2 = 1.0;
338  qkm2 = x;
339  pkm1 = x + 1.0;
340  qkm1 = z * x;
341  ans = pkm1/qkm1;
342 
343  do
344  {
345  c += 1.0;
346  y += 1.0;
347  z += 2.0;
348  yc = y * c;
349  pk = pkm1 * z - pkm2 * yc;
350  qk = qkm1 * z - qkm2 * yc;
351  if(qk)
352  {
353  r = pk/qk;
354  t = Math.abs( (ans - r)/r );
355  ans = r;
356  }
357  else
358  t = 1.0;
359  pkm2 = pkm1;
360  pkm1 = pk;
361  qkm2 = qkm1;
362  qkm1 = qk;
363  if( Math.abs(pk) > kBig )
364  {
365  pkm2 *= kBiginv;
366  pkm1 *= kBiginv;
367  qkm2 *= kBiginv;
368  qkm1 *= kBiginv;
369  }
370  }
371  while( t > kMACHEP );
372 
373  return ans * ax;
374  };
375 
377  JSROOT.Math.igami = function(a, y0) {
378  var x0, x1, x, yl, yh, y, d, lgm, dithresh, i, dir,
379  kMACHEP = 1.11022302462515654042363166809e-16;
380 
381  // check the domain
382  if (a <= 0) {
383  alert("igami : Wrong domain for parameter a (must be > 0)");
384  return 0;
385  }
386  if (y0 <= 0) {
387  return Number.POSITIVE_INFINITY;
388  }
389  if (y0 >= 1) {
390  return 0;
391  }
392  /* bound the solution */
393  var kMAXNUM = Number.MAX_VALUE;
394  x0 = kMAXNUM;
395  yl = 0;
396  x1 = 0;
397  yh = 1.0;
398  dithresh = 5.0 * kMACHEP;
399 
400  /* approximation to inverse function */
401  d = 1.0/(9.0*a);
402  y = ( 1.0 - d - this.ndtri(y0) * Math.sqrt(d) );
403  x = a * y * y * y;
404 
405  lgm = this.lgam(a);
406 
407  for( i=0; i<10; ++i ) {
408  if ( x > x0 || x < x1 )
409  break;
410  y = this.igamc(a,x);
411  if ( y < yl || y > yh )
412  break;
413  if ( y < y0 ) {
414  x0 = x;
415  yl = y;
416  }
417  else {
418  x1 = x;
419  yh = y;
420  }
421  /* compute the derivative of the function at this point */
422  d = (a - 1.0) * Math.log(x) - x - lgm;
423  if ( d < -kMAXLOG )
424  break;
425  d = -Math.exp(d);
426  /* compute the step to the next approximation of x */
427  d = (y - y0)/d;
428  if ( Math.abs(d/x) < kMACHEP )
429  return( x );
430  x = x - d;
431  }
432  /* Resort to interval halving if Newton iteration did not converge. */
433  d = 0.0625;
434  if ( x0 == kMAXNUM ) {
435  if ( x <= 0.0 )
436  x = 1.0;
437  while ( x0 == kMAXNUM ) {
438  x = (1.0 + d) * x;
439  y = this.igamc( a, x );
440  if ( y < y0 ) {
441  x0 = x;
442  yl = y;
443  break;
444  }
445  d = d + d;
446  }
447  }
448  d = 0.5;
449  dir = 0;
450 
451  for( i=0; i<400; ++i ) {
452  x = x1 + d * (x0 - x1);
453  y = this.igamc( a, x );
454  lgm = (x0 - x1)/(x1 + x0);
455  if ( Math.abs(lgm) < dithresh )
456  break;
457  lgm = (y - y0)/y0;
458  if ( Math.abs(lgm) < dithresh )
459  break;
460  if ( x <= 0.0 )
461  break;
462  if ( y >= y0 ) {
463  x1 = x;
464  yh = y;
465  if ( dir < 0 ) {
466  dir = 0;
467  d = 0.5;
468  }
469  else if ( dir > 1 )
470  d = 0.5 * d + 0.5;
471  else
472  d = (y0 - yl)/(yh - yl);
473  dir += 1;
474  }
475  else {
476  x0 = x;
477  yl = y;
478  if ( dir > 0 ) {
479  dir = 0;
480  d = 0.5;
481  }
482  else if ( dir < -1 )
483  d = 0.5 * d;
484  else
485  d = (y0 - yl)/(yh - yl);
486  dir -= 1;
487  }
488  }
489  return x;
490  };
491 
493  JSROOT.Math.gamma_quantile_c = function(z, alpha, theta) {
494  return theta * this.igami( alpha, z);
495  };
496 
498  JSROOT.Math.gamma_quantile = function(z, alpha, theta) {
499  return theta * this.igami( alpha, 1.- z);
500  };
501 
503  JSROOT.Math.log10 = function(n) {
504  return Math.log(n) / Math.log(10);
505  };
506 
508  JSROOT.Math.landau_pdf = function(x, xi, x0) {
509  // LANDAU pdf : algorithm from CERNLIB G110 denlan
510  // same algorithm is used in GSL
511  if (x0===undefined) x0 = 0;
512  if (xi <= 0) return 0;
513  var v = (x - x0)/xi;
514  var u, ue, us, denlan;
515  var p1 = new Array(0.4259894875,-0.1249762550, 0.03984243700, -0.006298287635, 0.001511162253);
516  var q1 = new Array(1.0 ,-0.3388260629, 0.09594393323, -0.01608042283, 0.003778942063);
517  var p2 = new Array(0.1788541609, 0.1173957403, 0.01488850518, -0.001394989411, 0.0001283617211);
518  var q2 = new Array(1.0 , 0.7428795082, 0.3153932961, 0.06694219548, 0.008790609714);
519  var p3 = new Array(0.1788544503, 0.09359161662,0.006325387654, 0.00006611667319,-0.000002031049101);
520  var q3 = new Array(1.0 , 0.6097809921, 0.2560616665, 0.04746722384, 0.006957301675);
521  var p4 = new Array(0.9874054407, 118.6723273, 849.2794360, -743.7792444, 427.0262186);
522  var q4 = new Array(1.0 , 106.8615961, 337.6496214, 2016.712389, 1597.063511);
523  var p5 = new Array(1.003675074, 167.5702434, 4789.711289, 21217.86767, -22324.94910);
524  var q5 = new Array(1.0 , 156.9424537, 3745.310488, 9834.698876, 66924.28357);
525  var p6 = new Array(1.000827619, 664.9143136, 62972.92665, 475554.6998, -5743609.109);
526  var q6 = new Array(1.0 , 651.4101098, 56974.73333, 165917.4725, -2815759.939);
527  var a1 = new Array(0.04166666667,-0.01996527778, 0.02709538966);
528  var a2 = new Array(-1.845568670,-4.284640743);
529 
530  if (v < -5.5) {
531  u = Math.exp(v+1.0);
532  if (u < 1e-10) return 0.0;
533  ue = Math.exp(-1/u);
534  us = Math.sqrt(u);
535  denlan = 0.3989422803*(ue/us)*(1+(a1[0]+(a1[1]+a1[2]*u)*u)*u);
536  } else if(v < -1) {
537  u = Math.exp(-v-1);
538  denlan = Math.exp(-u)*Math.sqrt(u)*
539  (p1[0]+(p1[1]+(p1[2]+(p1[3]+p1[4]*v)*v)*v)*v)/
540  (q1[0]+(q1[1]+(q1[2]+(q1[3]+q1[4]*v)*v)*v)*v);
541  } else if(v < 1) {
542  denlan = (p2[0]+(p2[1]+(p2[2]+(p2[3]+p2[4]*v)*v)*v)*v)/
543  (q2[0]+(q2[1]+(q2[2]+(q2[3]+q2[4]*v)*v)*v)*v);
544  } else if(v < 5) {
545  denlan = (p3[0]+(p3[1]+(p3[2]+(p3[3]+p3[4]*v)*v)*v)*v)/
546  (q3[0]+(q3[1]+(q3[2]+(q3[3]+q3[4]*v)*v)*v)*v);
547  } else if(v < 12) {
548  u = 1/v;
549  denlan = u*u*(p4[0]+(p4[1]+(p4[2]+(p4[3]+p4[4]*u)*u)*u)*u)/
550  (q4[0]+(q4[1]+(q4[2]+(q4[3]+q4[4]*u)*u)*u)*u);
551  } else if(v < 50) {
552  u = 1/v;
553  denlan = u*u*(p5[0]+(p5[1]+(p5[2]+(p5[3]+p5[4]*u)*u)*u)*u)/
554  (q5[0]+(q5[1]+(q5[2]+(q5[3]+q5[4]*u)*u)*u)*u);
555  } else if(v < 300) {
556  u = 1/v;
557  denlan = u*u*(p6[0]+(p6[1]+(p6[2]+(p6[3]+p6[4]*u)*u)*u)*u)/
558  (q6[0]+(q6[1]+(q6[2]+(q6[3]+q6[4]*u)*u)*u)*u);
559  } else {
560  u = 1/(v-v*Math.log(v)/(v+1));
561  denlan = u*u*(1+(a2[0]+a2[1]*u)*u);
562  }
563  return denlan/xi;
564  };
565 
567  JSROOT.Math.Landau = function(x, mpv, sigma, norm) {
568  if (sigma <= 0) return 0;
569  var den = JSROOT.Math.landau_pdf((x - mpv) / sigma, 1, 0);
570  if (!norm) return den;
571  return den/sigma;
572  };
573 
575  JSROOT.Math.inc_gamma_c = function(a,x) {
576  return JSROOT.Math.igamc(a,x);
577  };
578 
580  JSROOT.Math.inc_gamma = function(a,x) {
581  return JSROOT.Math.igam(a,x);
582  };
583 
584  JSROOT.Math.lgamma = function(z) {
585  return JSROOT.Math.lgam(z);
586  };
587 
589  JSROOT.Math.inc_gamma = function(a,x) {
590  return JSROOT.Math.igam(a,x);
591  };
592 
593  JSROOT.Math.lgamma = function(z) {
594  return JSROOT.Math.lgam(z);
595  };
596 
598  JSROOT.Math.chisquared_cdf_c = function(x,r,x0) {
599  if (x0===undefined) x0 = 0;
600  return JSROOT.Math.inc_gamma_c ( 0.5 * r , 0.5*(x-x0) );
601  };
602 
604  JSROOT.Math.chisquared_cdf = function(x,r,x0) {
605  if (x0===undefined) x0 = 0;
606  return JSROOT.Math.inc_gamma ( 0.5 * r , 0.5*(x-x0) );
607  };
608 
610  JSROOT.Math.chisquared_pdf = function(x,r,x0) {
611  if (x0===undefined) x0 = 0;
612  if ((x-x0) < 0) return 0.0;
613  var a = r/2 -1.;
614  // let return inf for case x = x0 and treat special case of r = 2 otherwise will return nan
615  if (x == x0 && a == 0) return 0.5;
616 
617  return Math.exp ((r/2 - 1) * Math.log((x-x0)/2) - (x-x0)/2 - JSROOT.Math.lgamma(r/2))/2;
618  };
619 
621  JSROOT.Math.Prob = function(chi2, ndf) {
622  if (ndf <= 0) return 0; // Set CL to zero in case ndf<=0
623 
624  if (chi2 <= 0) {
625  if (chi2 < 0) return 0;
626  else return 1;
627  }
628 
629  return JSROOT.Math.chisquared_cdf_c(chi2,ndf,0);
630  };
631 
633  JSROOT.Math.Gaus = function(x, mean, sigma) {
634  return Math.exp(-0.5 * Math.pow((x-mean) / sigma, 2));
635  };
636 
638  JSROOT.Math.BreitWigner = function(x, mean, gamma) {
639  return gamma/((x-mean)*(x-mean) + gamma*gamma/4) / 2 / Math.PI;
640  }
641 
643  JSROOT.Math.gaus = function(f, x, i) {
644  // function used when gaus(0) used in the TFormula
645  return f.GetParValue(i+0) * Math.exp(-0.5 * Math.pow((x-f.GetParValue(i+1)) / f.GetParValue(i+2), 2));
646  };
647 
649  JSROOT.Math.gausn = function(f, x, i) {
650  return JSROOT.Math.gaus(f, x, i)/(Math.sqrt(2 * Math.PI) * f.GetParValue(i+2));
651  };
652 
654  JSROOT.Math.gausxy = function(f, x, y, i) {
655  // function used when xygaus(0) used in the TFormula
656 
657  return f.GetParValue(i+0) * Math.exp(-0.5 * Math.pow((x-f.GetParValue(i+1)) / f.GetParValue(i+2), 2))
658  * Math.exp(-0.5 * Math.pow((y-f.GetParValue(i+3)) / f.GetParValue(i+4), 2));
659  };
660 
661 
663  JSROOT.Math.expo = function(f, x, i) {
664  return Math.exp(f.GetParValue(i+0) + f.GetParValue(i+1) * x);
665  };
666 
668  JSROOT.Math.landau = function(f, x, i) {
669  return JSROOT.Math.Landau(x, f.GetParValue(i+1),f.GetParValue(i+2), false);
670  };
671 
673  JSROOT.Math.landaun = function(f, x, i) {
674  return JSROOT.Math.Landau(x, f.GetParValue(i+1),f.GetParValue(i+2), true);
675  };
676 
677  // =========================================================================
678 
679  JSROOT.getMoreMethods = function(m,typename, obj) {
680  // different methods which are typically used in TTree::Draw
681 
682  if (typename.indexOf("ROOT::Math::LorentzVector")===0) {
683  m.Px = m.X = function() { return this.fCoordinates.Px(); }
684  m.Py = m.Y = function() { return this.fCoordinates.Py(); }
685  m.Pz = m.Z = function() { return this.fCoordinates.Pz(); }
686  m.E = m.T = function() { return this.fCoordinates.E(); }
687  m.M2 = function() { return this.fCoordinates.M2(); }
688  m.M = function() { return this.fCoordinates.M(); }
689  m.R = m.P = function() { return this.fCoordinates.R(); }
690  m.P2 = function() { return this.P() * this.P(); }
691  m.Pt = m.pt = function() { return Math.sqrt(this.P2()); }
692  m.Phi = m.phi = function() { return Math.atan2(this.fCoordinates.Py(), this.fCoordinates.Px()); }
693  m.Eta = m.eta = function() { return Math.atanh(this.Pz()/this.P()); }
694  }
695 
696  if (typename.indexOf("ROOT::Math::PxPyPzE4D")===0) {
697  m.Px = m.X = function() { return this.fX; }
698  m.Py = m.Y = function() { return this.fY; }
699  m.Pz = m.Z = function() { return this.fZ; }
700  m.E = m.T = function() { return this.fT; }
701  m.P2 = function() { return this.fX*this.fX + this.fY*this.fY + this.fZ*this.fZ; }
702  m.R = m.P = function() { return Math.sqrt(this.P2()); }
703  m.Mag2 = m.M2 = function() { return this.fT*this.fT - this.fX*this.fX - this.fY*this.fY - this.fZ*this.fZ; }
704  m.Mag = m.M = function() {
705  var mm = this.M2();
706  if (mm >= 0) return Math.sqrt(mm);
707  return -Math.sqrt(-mm);
708  }
709  m.Perp2 = m.Pt2 = function() { return this.fX*this.fX + this.fY*this.fY;}
710  m.Pt = m.pt = function() { return Math.sqrt(this.P2()); }
711  m.Phi = m.phi = function() { return Math.atan2(this.fY, this.fX); }
712  m.Eta = m.eta = function() { return Math.atanh(this.Pz/this.P()); }
713  }
714  }
715 
716  return JSROOT;
717 
718 }));