FairRoot/PandaRoot
mzfunctions.cxx
Go to the documentation of this file.
1 
7 //c/c++
8 #include <stdlib.h>
9 #include <iostream>
10 #include <fstream>
11 #include <sstream>
12 #include <cmath>
13 
14 //mz
15 #include "mzparameters.h"
16 #include "mzfunctions.h"
17 
18 //ranlux
19 #include "ranlxs.h"
20 #include "ranlxd.h"
21 
22 void ranlxs(float r[], int n);
23 void ranlxd(double r[], int n);
24 
25 void rlxs_init(int level, int seed);
26 void rlxd_init(int level, int seed);
27 
28 using namespace std;
29 
30 double mzdelta(int i, int k)
31 {
40  double d;
41 
42  if( k==i )
43  {
44  d=1.0;
45  }
46  else{
47  d=0.0;
48  }
49 
50  return d;
51 }
52 
53 double mzvscalar(int n, double* p, double* q)
54 {
67  double s;
68 
69 
70  if( !(n==2||n==3||n==4) ){
71  printf("ERROR: function mzvscalar called with flag n out of range \n");
72  printf(" => n should take the value 2,3 or 4 \n");
73  printf("\n\n");
74  exit(1);
75  }
76 
77 
78  if (n==2) {
79  s = p[1]*q[1] + p[2]*q[2];
80  }
81 
82  if (n==3) {
83  s = p[1]*q[1] + p[2]*q[2] + p[3]*q[3];
84  }
85 
86  if (n==4) {
87  s = p[0]*q[0] -1.0*p[1]*q[1] -1.0*p[2]*q[2] -1.0*p[3]*q[3];
88  }
89 
90  return s;
91 }
92 
93 double mzvmod2(int n, double* p)
94 {
107  double m2;
108 
109 
110  if( !(n==2||n==3||n==4) ){
111  printf("ERROR: function mzvmod2 called with flag n out of range \n");
112  printf(" => n should take the value 2,3 or 4 \n");
113  printf("\n\n");
114  exit(1);
115  }
116 
117 
118  m2 = mzvscalar(n,p,p);
119 
120  return m2;
121 }
122 
123 void mzboost(int flag, double* p, double* q, double* q_prime)
124 {
135  int i,k;
136 
137  double m;
138  double gamma;
139  double p_uni[4];
140 
141  double L[4][4];
142  double LI[4][4];
143 
144  double mztemp;
145 
146 
147 
148  //computing matrix L(p)
149 
150  m=pow(mzvmod2(4,p),0.5);
151  gamma=p[0]/m;
152 
153 
154  for (i=1; i<=3; i++) {
155  p_uni[i]=p[i]/pow(mzvmod2(3,p),0.5);
156  }
157 
158 
159  L[0][0]=gamma;
160 
161 
162  for (i=1; i<=3; i++) {
163  L[0][i] = p_uni[i] * pow((gamma*gamma - 1.0),0.5);
164  L[i][0] = L[0][i];
165  }
166 
167 
168  for (i=1; i<=3; i++) {
169  for (k=1; k<=3; k++) {
170  L[i][k] = mzdelta(i,k) + (gamma -1.0)*p_uni[i]*p_uni[k];
171  }
172  }
173 
174 
175 
176 
177  //inverting matrix L(p)
178 
179  LI[0][0]=L[0][0];
180 
181  for (i=1; i<=3; i++) {
182  LI[0][i] = -1.0*L[i][0];
183  LI[i][0] = -1.0*L[0][i];
184  }
185 
186  for (i=1; i<=3; i++) {
187  for (k=1; k<=3; k++) {
188  LI[i][k] = L[k][i];
189  }
190  }
191 
192 
193 
194  //boosting 4-mom q
195 
196  for (i=0; i<=3; i++) {
197  mztemp = 0.0;
198  for (k=0; k<=3; k++) {
199  if (flag==0) mztemp = mztemp + LI[i][k]*q[k];
200  if (flag==1) mztemp = mztemp + L[i][k]*q[k];
201  }
202  q_prime[i] =mztemp;
203  }
204 
205 }
206 
207 double mzenergy(double m, double p_x, double p_y, double p_z)
208 {
216  double E;
217 
218  E=pow(m*m +p_x*p_x +p_y*p_y +p_z*p_z,0.5);
219 
220  return E;
221 }
222 
223 double mzpolar(double* p)
224 {
232  double PI=acos(-1.0);
233 
234  double theta;
235 
236  double pmod;
237  double costheta;
238 
239  pmod=pow(mzvmod2(3,p),0.5);
240 
241  if(pmod==0.0){
242  cerr << "WARNING: mzpolar called with p[1]=p[2]=p[3]=0.0 " << endl;
243  return 9999.;
244  }
245 
246  costheta = p[3]/pmod;
247 
248  if(costheta > 1.0) costheta=1.0;
249  if(costheta < -1.0) costheta=-1.0;
250 
251  theta = acos(costheta) * 180.0 / PI ;
252 
253 
254  return theta;
255 }
256 
257 
258 double mzazimuthal(double* p)
259 {
267  double PI=acos(-1.0);
268 
269  double phi;
270 
271  if ( (p[1]==0.) && (p[2]==0.0) ) {
272  cerr << "WARNING: mzazimuthal called with p[1]=p[2]=0.0 " << endl;
273  return 9999.;
274  }
275 
276 
277  phi=atan2(p[2],p[1])*180.0/PI;
278 
279 
280  if (phi<0.0) phi = phi + 360.0;
281 
282  return phi;
283 }
284 
285 double mzcospolar(double* p)
286 {
294  double costheta;
295 
296  double pmod;
297 
298  pmod=pow(mzvmod2(3,p),0.5);
299 
300  if(pmod==0.0){
301  cerr << "WARNING: mzcospolar called with p[1]=p[2]=p[3]=0.0 " << endl;
302  return 9999.;
303  }
304 
305  costheta = p[3]/pmod;
306 
307  return costheta;
308 }
309 
310 double mzangle(double* p, double* q)
311 {
320  double PI=acos(-1.0);
321 
322  double alpha;
323 
324  double scalar, pmod, qmod, cosalpha;
325 
326  pmod=pow(mzvmod2(3,p),0.5);
327  qmod=pow(mzvmod2(3,q),0.5);
328 
329  scalar=mzvscalar(3,p,q);
330 
331  if(pmod==0.0){
332  cerr << "WARNING: mzangle called with p[1]=p[2]=p[3]=0.0 " << endl;
333  return 9999.;
334  }
335 
336  if(qmod==0.0){
337  cerr << "WARNING: mzangle called with q[1]=q[2]=q[3]=0.0 " << endl;
338  return 9999.;
339  }
340 
341 
342  cosalpha=scalar/(pmod*qmod);
343 
344  if(cosalpha > 1.0) cosalpha=1.0;
345  if(cosalpha < -1.0) cosalpha=-1.0;
346 
347  alpha=acos(cosalpha) * 180.0 / PI;
348 
349 
350  return alpha;
351 }
352 
353 double mzrnd(double a, double b){
368  double y;
369 
370  int dim=1;
371  double rvec[dim];
372  double x;
373 
374  //check arguments
375  if(b<=a){
376  printf("ERROR: function mzrnd called with arguments b<=a \n");
377  printf(" => argument b should be larger than argument a \n");
378  printf("\n\n");
379  exit(1);
380  }
381 
382  ranlxd(rvec,dim); //generate random number in interval [0,1]
383  x=rvec[0];
384  y=(b-a)*x + a;
385 
386  return y;
387 }
388 
389 double mzcomplexmod(double Re_z, double Im_z){
403  double y;
404 
405  y=pow(Re_z*Re_z + Im_z*Im_z,0.5);
406 
407  return y;
408 }
409 
410 double mz_E_to_s(double E){
425  double s;
426 
427  double M=mp;
428 
429  double p_p[4]; //lab frame: 4-mom p (proton target)
430  double pbar_p[4]; //lab frame: 4-mom pbar (anti-proton beam)
431  double pbarp_p[4]; //lab frame: 4-mom pbarpsystem
432  double P; //lab frame: pz pbar
433 
434 
435  //check argument range
436  if(E<M){
437  printf("ERROR: function mz_E_to_s called with argument E out of range \n");
438  printf(" => E should be larger than the proton mass M = %5.3f GeV\n",M);
439  printf("\n\n");
440  exit(1);
441  }
442 
443 
444  //4-mom of p (lab frame)
445  p_p[0]=M;
446  p_p[1]=0.;
447  p_p[2]=0.;
448  p_p[3]=0.;
449 
450 
451  //4-mom of pbar (lab frame)
452  P=pow((E*E-M*M),0.5);
453 
454  pbar_p[0]=E;
455  pbar_p[1]=0.;
456  pbar_p[2]=0.;
457  pbar_p[3]=P;
458 
459 
460  //4-mom pbarpsystem (lab frame)
461  for(int i=0; i<4; i++){
462  pbarp_p[i]=p_p[i]+pbar_p[i];
463  }
464 
465  s=mzvmod2(4,pbarp_p);
466 
467  return s;
468 }
469 
470 double mz_legendre_polynomial(int n, double x){
485  double y;
486 
487  //checking parameter range...
488  if( !( (n>=0)&&(n<=10) ) ){
489  printf("ERROR: function mz_legendre_polynomial called with n out of range \n");
490  printf(" => n should be contained in the interval [0,10]\n");
491  printf("\n\n");
492  exit(1);
493  }
494 
495  if( !( (x>=-1.0)&&(x<=1.0) ) ){
496  printf("ERROR: function mz_legendre_polynomial called with x out of range \n");
497  printf(" => x should be contained in the interval [-1.0,1.0]\n");
498  printf("\n\n");
499  exit(1);
500  }
501 
502 
503  if(n==0){
504  y=1.0;
505  }
506 
507  if(n==1){
508  y=x;
509  }
510 
511  if(n==2){
512  y=(1.0/2.0)*(3.0*pow(x,2.0) -1.0);
513  }
514 
515  if(n==3){
516  y=(1.0/2.0)*(5.0*pow(x,3.0) -3.0*x);
517  }
518 
519  if(n==4){
520  y=(1.0/8.0)*(35.0*pow(x,4.0) -30.0*pow(x,2.0) +3.0);
521  }
522 
523  if(n==5){
524  y=(1.0/8.0)*(63.0*pow(x,5.0) -70.0*pow(x,3.0) +15.0*x);
525  }
526 
527  if(n==6){
528  y=(1.0/16.0)*(231.0*pow(x,6.0) -315.0*pow(x,4.0)
529  +105.0*pow(x,2.0) -5.0);
530  }
531 
532  if(n==7){
533  y=(1.0/16.0)*(429.0*pow(x,7.0) -693.0*pow(x,5.0)
534  +315.0*pow(x,3.0) -35.0*x);
535  }
536 
537  if(n==8){
538  y=(1.0/128.0)*(6435.0*pow(x,8.0) -12012.0*pow(x,6.0)
539  +6930.0*pow(x,4.0) -1260.0*pow(x,2.0)
540  +35.0);
541  }
542 
543  if(n==9){
544  y=(1.0/128.0)*(12155.0*pow(x,9.0) -25740.0*pow(x,7.0)
545  +18018.0*pow(x,5.0) -4620.0*pow(x,3.0)
546  +315.0*x);
547  }
548 
549  if(n==10){
550  y=(1.0/256.0)*(46189.0*pow(x,10.0) -109395.0*pow(x,8.0)
551  +90090.0*pow(x,6.0) -30030*pow(x,4.0)
552  +3465.0*pow(x,2.0) -63.0);
553  }
554 
555  return y;
556 }
557 
558 double mz_linear_extrapolation(double x1, double y1,
559  double x2, double y2,
560  double x)
561 {
579  double y;
580  double a,b;
581 
582  //checking parameter range...
583  if(x2==x1){
584  printf("ERROR: function mz_linear_extrapolation called with x_2=x_1 \n");
585  printf(" => argument x_2 should be different from argument x_1 \n");
586  printf("\n\n");
587  exit(1);
588  }
589 
590  a = (y1-y2)/(x1-x2);
591  b = y1-a*x1;
592 
593  y = a*x+b;
594 
595  return y;
596 }
597 
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
void ranlxd(double r[], int n)
Definition: ranlxd.cxx:571
double mzcomplexmod(double Re_z, double Im_z)
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
double mzangle(double *p, double *q)
void rlxd_init(int level, int seed)
Definition: ranlxd.cxx:501
double mzdelta(int i, int k)
Definition: mzfunctions.cxx:30
double r
Definition: RiemannTest.C:14
TObjArray * d
Int_t i
Definition: run_full.C:25
__m128 m
Definition: P4_F32vec4.h:28
TTree * b
exit(0)
double mzvmod2(int n, double *p)
Definition: mzfunctions.cxx:93
TLorentzVector s
Definition: Pnd2DStar.C:50
int n
static const double mp
Definition: mzparameters.h:11
Double_t p
Definition: anasim.C:58
double mzcospolar(double *p)
void ranlxs(float r[], int n)
Definition: ranlxs.cxx:566
double mzrnd(double a, double b)
TString m2(TString pts, TString exts="e px py pz")
Definition: invexp.C:117
Int_t a
Definition: anaLmdDigi.C:126
const Double_t PI
unsigned int seed
double mz_linear_extrapolation(double x1, double y1, double x2, double y2, double x)
void mzboost(int flag, double *p, double *q, double *q_prime)
double mzenergy(double m, double p_x, double p_y, double p_z)
double mzvscalar(int n, double *p, double *q)
Definition: mzfunctions.cxx:53
friend F32vec4 atan2(const F32vec4 &y, const F32vec4 &x)
Definition: P4_F32vec4.h:117
GeV c P
Double_t x
double mzazimuthal(double *p)
Double_t y
double alpha
Definition: f_Init.h:9
double mz_E_to_s(double E)
void rlxs_init(int level, int seed)
Definition: ranlxs.cxx:495
double mz_legendre_polynomial(int n, double x)
double mzpolar(double *p)