NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
Nc3Vector.cxx
Go to the documentation of this file.
1
31
33
103
104#include "Nc3Vector.h"
105#include "Riostream.h"
106
107ClassImp(Nc3Vector); // Class implementation to enable ROOT I/O
108
111{
118
119 fNv=0;
120 fV=0;
121 fDresult=0;
122}
123
125{
131
132 if (fV)
133 {
134 delete[] fV;
135 fV=0;
136 }
137}
138
140{
146
147 fNv=v.fNv;
148 fV=0;
149 if (fNv) fV=new Double32_t[fNv];
150 for (Int_t i=0; i<fNv; i++)
151 {
152 fV[i]=v.fV[i];
153 }
155}
156
158{
164
165 fNv=0;
166 if (fV)
167 {
168 delete[] fV;
169 fV=0;
170 }
171
172 if (q.HasVector())
173 {
174 Double_t a[3];
175 q.GetVector(a,"sph");
176 SetVector(a,"sph");
177 }
178
179 if (q.HasErrors())
180 {
181 Double_t ea[3];
182 q.GetErrors(ea,"car");
183 SetErrors(ea,"car");
184 }
185
187
188 return *this;
189}
190
192{
198
199 fNv=q.fNv;
200 if (fV)
201 {
202 delete[] fV;
203 fV=0;
204 }
205 if (fNv) fV=new Double32_t[fNv];
206 for (Int_t i=0; i<fNv; i++)
207 {
208 fV[i]=q.fV[i];
209 }
211}
212
214{
220
221 fNv=0;
222 if (fV)
223 {
224 delete[] fV;
225 fV=0;
226 }
227 fDresult=0;
228}
229
230void Nc3Vector::SetVector(Double_t* v,TString f,TString u)
231{
245
246 fDresult=0;
247
248 // Initialisation of the new storage array
249 fNv=3;
250 if (fV) delete[] fV;
251 fV=new Double32_t[fNv];
252
253 Double_t pi=acos(-1.);
254 Double_t twopi=2.*pi;
255
256 Double_t fu=1.;
257 if (u == "deg") fu=pi/180.;
258
259 Int_t frame=0;
260 if (f == "car") frame=1;
261 if (f == "sph") frame=2;
262 if (f == "cyl") frame=3;
263
264 Double_t x,y,z,r,theta,phi,rho;
265
266 switch (frame)
267 {
268 case 1: // Cartesian coordinates
269 x=v[0];
270 y=v[1];
271 z=v[2];
272 r=sqrt(x*x+y*y+z*z);
273
274 // Determine theta in [0,pi]
275 theta=0;
276 if (z<0) theta=pi;
277 if (r)
278 {
279 if (fabs(z/r)<=1) theta=acos(z/r); // Puts theta in [0,pi]
280 }
281 if (theta<0) theta=fabs(theta); // To catch possible accuracy issue
282
283 // Determine phi in [0,twopi]
284 phi=0;
285 if (x || y) phi=atan2(y,x); // Puts phi in [-pi,pi]
286 if (phi<0) phi+=twopi;
287
288 fV[0]=r;
289 fV[1]=theta;
290 fV[2]=phi;
291 break;
292
293 case 2: // Spherical coordinates
294 r=v[0];
295 theta=v[1]*fu;
296 phi=v[2]*fu;
297
298 // Limit phi to the interval [0,twopi]
299 while (phi<0)
300 {
301 phi+=twopi;
302 }
303 while (phi>twopi)
304 {
305 phi-=twopi;
306 }
307
308 // Limit theta to the interval [-pi,pi]
309 while (theta<-pi)
310 {
311 theta+=twopi;
312 }
313 while (theta>pi)
314 {
315 theta-=twopi;
316 }
317 // Limit theta to the interval [0,pi]
318 if (theta<0)
319 {
320 theta=fabs(theta);
321 phi+=pi;
322 if (phi>twopi) phi-=twopi;
323 }
324
325 fV[0]=r;
326 fV[1]=theta;
327 fV[2]=phi;
328 break;
329
330 case 3: // Cylindrical coordinates
331 rho=v[0];
332 phi=v[1]*fu;
333 z=v[2];
334 r=sqrt(rho*rho+z*z);
335
336 // Limit phi to the interval [0,twopi]
337 while (phi<0)
338 {
339 phi+=twopi;
340 }
341 while (phi>twopi)
342 {
343 phi-=twopi;
344 }
345
346 // Determine theta in [0,pi]
347 theta=0;
348 if (z<0) theta=pi;
349 if (rho && r)
350 {
351 if (fabs(z/r)<=1) theta=acos(z/r); // Puts theta in [0,pi]
352 }
353 if (theta<0) theta=fabs(theta); // To catch possible accuracy issue
354
355 fV[0]=r;
356 fV[1]=theta;
357 fV[2]=phi;
358 break;
359
360 default: // Unsupported reference frame
361 cout << "*Nc3Vector::SetVector* Unsupported frame : " << f << endl
362 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
363
364 fNv=0;
365 if (fV) delete[] fV;
366 fV=0;
367 break;
368 }
369}
370
371void Nc3Vector::SetVector(Double_t v1,Double_t v2,Double_t v3,TString f,TString u)
372{
386
387 Double_t vec[3];
388 vec[0]=v1;
389 vec[1]=v2;
390 vec[2]=v3;
391 SetVector(vec,f,u);
392}
393
394void Nc3Vector::GetVector(Double_t* v,TString f,TString u) const
395{
408
409 if (!fNv)
410 {
411 v[0]=0;
412 v[1]=0;
413 v[2]=0;
414 return;
415 }
416
417 Double_t pi=acos(-1.);
418
419 Double_t fu=1.;
420 if (u == "deg") fu=180./pi;
421
422 Double_t r=fV[0];
423 Double_t theta=fV[1];
424 Double_t phi=fV[2];
425
426 Int_t frame=0;
427 if (f == "car") frame=1;
428 if (f == "sph") frame=2;
429 if (f == "cyl") frame=3;
430
431 switch (frame)
432 {
433 case 1: // Cartesian coordinates
434 v[0]=r*sin(theta)*cos(phi);
435 v[1]=r*sin(theta)*sin(phi);
436 v[2]=r*cos(theta);
437 break;
438
439 case 2: // Spherical coordinates
440 v[0]=r;
441 v[1]=theta*fu;
442 v[2]=phi*fu;
443 break;
444
445 case 3: // Cylindrical coordinates
446 v[0]=r*sin(theta);
447 v[1]=phi*fu;
448 v[2]=r*cos(theta);
449 break;
450
451 default: // Unsupported reference frame
452 cout << "*Nc3Vector::GetVector* Unsupported frame : " << f.Data() << endl
453 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
454 for (Int_t i=0; i<3; i++)
455 {
456 v[i]=0;
457 }
458 break;
459 }
460}
461
462void Nc3Vector::SetVector(Float_t* v,TString f,TString u)
463{
477
478 Double_t vec[3];
479 for (Int_t i=0; i<3; i++)
480 {
481 vec[i]=v[i];
482 }
483 SetVector(vec,f,u);
484}
485
486void Nc3Vector::GetVector(Float_t* v,TString f,TString u) const
487{
500
501 Double_t vec[3];
502 GetVector(vec,f,u);
503 for (Int_t i=0; i<3; i++)
504 {
505 v[i]=vec[i];
506 }
507}
508
509void Nc3Vector::SetErrors(Double_t* e,TString f,TString u)
510{
528
529 if (!fNv) return;
530
531 Double_t pi=acos(-1.);
532
533 Double_t fu=1.;
534 if (u == "deg") fu=pi/180.;
535
536 fDresult=0;
537
538 Int_t frame=0;
539 if (f == "car") frame=1;
540 if (f == "sph") frame=2;
541 if (f == "cyl") frame=3;
542
543 Double_t r=fV[0];
544 Double_t theta=fV[1];
545 Double_t phi=fV[2];
546
547 // Initialisation of the new storage array
548 if (fV) delete[] fV;
549 fNv=6;
550 if (!frame) fNv=3;
551 fV=new Double32_t[fNv];
552 fV[0]=r;
553 fV[1]=theta;
554 fV[2]=phi;
555
556 Double_t rho;
557 Double_t dx2,dy2,dz2;
558
559 switch (frame)
560 {
561 case 1: // Cartesian coordinates
562 fV[3]=fabs(e[0]);
563 fV[4]=fabs(e[1]);
564 fV[5]=fabs(e[2]);
565 break;
566
567 case 2: // Spherical coordinates
568 dx2=pow((cos(phi)*sin(theta)*e[0]),2)+pow((r*cos(theta)*cos(phi)*e[1]*fu),2)
569 +pow((r*sin(theta)*sin(phi)*e[2]*fu),2);
570 dy2=pow((sin(phi)*sin(theta)*e[0]),2)+pow((r*cos(theta)*sin(phi)*e[1]*fu),2)
571 +pow((r*sin(theta)*cos(phi)*e[2]*fu),2);
572 dz2=pow((cos(theta)*e[0]),2)+pow((r*sin(theta)*e[1]*fu),2);
573 fV[3]=sqrt(dx2);
574 fV[4]=sqrt(dy2);
575 fV[5]=sqrt(dz2);
576 break;
577
578 case 3: // Cylindrical coordinates
579 rho=r*sin(theta);
580 dx2=pow((cos(phi)*e[0]),2)+pow((rho*sin(phi)*e[1]*fu),2);
581 dy2=pow((sin(phi)*e[0]),2)+pow((rho*cos(phi)*e[1]*fu),2);
582 fV[3]=sqrt(dx2);
583 fV[4]=sqrt(dy2);
584 fV[5]=fabs(e[2]);
585 break;
586
587 default: // Unsupported reference frame
588 cout << "*Nc3Vector::SetErrors* Unsupported frame : " << f.Data() << endl
589 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
590 break;
591 }
592}
593
594void Nc3Vector::SetErrors(Double_t e1,Double_t e2,Double_t e3,TString f,TString u)
595{
613
614 Double_t vec[3];
615 vec[0]=e1;
616 vec[1]=e2;
617 vec[2]=e3;
618 SetErrors(vec,f,u);
619}
620
621void Nc3Vector::GetErrors(Double_t* e,TString f,TString u) const
622{
635
636 if (fNv<4)
637 {
638 e[0]=0;
639 e[1]=0;
640 e[2]=0;
641 return;
642 }
643
644 Double_t pi=acos(-1.);
645
646 Double_t fu=1.;
647 if (u == "deg") fu=180./pi;
648
649 Int_t frame=0;
650 if (f == "car") frame=1;
651 if (f == "sph") frame=2;
652 if (f == "cyl") frame=3;
653
654 Double_t r=fV[0];
655 Double_t theta=fV[1];
656 Double_t dx=fV[3];
657 Double_t dy=fV[4];
658 Double_t dz=fV[5];
659
660 Double_t dr2,dtheta2,dphi2,rho,drho2;
661 Double_t v[3];
662 Double_t rxy2; // Shorthand for (x*x+y*y)
663
664 switch (frame)
665 {
666 case 1: // Cartesian coordinates
667 e[0]=dx;
668 e[1]=dy;
669 e[2]=dz;
670 break;
671
672 case 2: // Spherical coordinates
673 GetVector(v,"car");
674 rxy2=pow(v[0],2)+pow(v[1],2);
675 if (sqrt(rxy2)<(r*1e-10)) rxy2=0;
676 if (r)
677 {
678 dr2=(pow((v[0]*dx),2)+pow((v[1]*dy),2)+pow((v[2]*dz),2))/(r*r);
679 }
680 else
681 {
682 dr2=0;
683 }
684 if (r)
685 {
686 dtheta2=rxy2*pow(dz,2)/pow(r,4);
687 if (v[2] && rxy2)
688 {
689 dtheta2+=rxy2*pow(v[2],2)*(pow((v[0]*dx),2)+pow((v[1]*dy),2)) /
690 pow(((pow(v[2],2)*rxy2)+pow(rxy2,2)),2);
691 }
692 }
693 else
694 {
695 dtheta2=0;
696 }
697 if (rxy2)
698 {
699 dphi2=(pow((v[1]*dx),2)+pow((v[0]*dy),2))/(pow(rxy2,2));
700 }
701 else
702 {
703 dphi2=0;
704 }
705 e[0]=sqrt(dr2);
706 e[1]=sqrt(dtheta2);
707 if (e[1]>pi) e[1]=pi;
708 e[2]=sqrt(dphi2);
709 if (e[2]>(2.*pi)) e[2]=2.*pi;
710 e[1]*=fu;
711 e[2]*=fu;
712 break;
713
714 case 3: // Cylindrical coordinates
715 GetVector(v,"car");
716 rho=fabs(r*sin(theta));
717 if (rho<(r*1e-10)) rho=0;
718 if (rho)
719 {
720 drho2=(pow((v[0]*dx),2)+pow((v[1]*dy),2))/(rho*rho);
721 }
722 else
723 {
724 drho2=0;
725 }
726 if (rho)
727 {
728 dphi2=(pow((v[1]*dx),2)+pow((v[0]*dy),2))/(pow(rho,4));
729 }
730 else
731 {
732 dphi2=0;
733 }
734 e[0]=sqrt(drho2);
735 e[1]=sqrt(dphi2);
736 if (e[1]>(2.*pi)) e[1]=2.*pi;
737 e[2]=dz;
738 e[1]*=fu;
739 break;
740
741 default: // Unsupported reference frame
742 cout << "*Nc3Vector::GetErrors* Unsupported frame : " << f.Data() << endl
743 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
744 for (Int_t i=0; i<3; i++)
745 {
746 e[i]=0;
747 }
748 break;
749 }
750}
751
752void Nc3Vector::SetErrors(Float_t* e,TString f,TString u)
753{
771
772 Double_t vec[3];
773 for (Int_t i=0; i<3; i++)
774 {
775 vec[i]=e[i];
776 }
777 SetErrors(vec,f,u);
778}
779
780void Nc3Vector::GetErrors(Float_t* e,TString f,TString u) const
781{
794
795 Double_t vec[3];
796 GetErrors(vec,f,u);
797 for (Int_t i=0; i<3; i++)
798 {
799 e[i]=vec[i];
800 }
801}
802
803void Nc3Vector::Data(TString f,TString u) const
804{
824
825 if ((f=="car" || f=="sph" || f=="cyl") && (u=="rad" || u=="deg" || u=="dms"|| u=="hms"))
826 {
827 if (!fNv)
828 {
829 cout << " 3-Vector not initialised." << endl;
830 }
831 else
832 {
833 Double_t vec[3];
834 GetVector(vec,f,"deg");
835 if (f=="car")
836 {
837 printf(" Vector in %-s coordinates : %.3e %.3e %.3e \n",f.Data(),vec[0],vec[1],vec[2]);
838 }
839 if (f=="sph")
840 {
841 printf(" Vector in %-s coordinates : %.3e ",f.Data(),vec[0]);
842 PrintAngle(vec[1],"deg",u,3,kTRUE); printf(" ");
843 PrintAngle(vec[2],"deg",u,3,kTRUE); printf("\n");
844 }
845 if (f=="cyl")
846 {
847 printf(" Vector in %-s coordinates : %.3e ",f.Data(),vec[0]);
848 PrintAngle(vec[1],"deg",u,3,kTRUE); printf(" ");
849 printf(" %.3e \n",vec[2]);
850 }
851 }
852 if (fNv==6)
853 {
854 Double_t err[3];
855 GetErrors(err,f,"deg");
856 if (f=="car")
857 {
858 printf(" Err. in %-s coordinates : %.3e %.3e %.3e \n",f.Data(),err[0],err[1],err[2]);
859 }
860 if (f=="sph")
861 {
862 printf(" Err. in %-s coordinates : %.3e ",f.Data(),err[0]);
863 PrintAngle(err[1],"deg",u,3,kTRUE); printf(" ");
864 PrintAngle(err[2],"deg",u,3,kTRUE); printf("\n");
865 }
866 if (f=="cyl")
867 {
868 printf(" Err. in %-s coordinates : %.3e ",f.Data(),err[0]);
869 PrintAngle(err[1],"deg",u,3,kTRUE); printf(" ");
870 printf(" %.3e \n",err[2]);
871 }
872 }
873 }
874 else
875 {
876 printf(" *Nc3Vector::Data* Unsupported input frame=%-s format=%-s \n",f.Data(),u.Data());
877 }
878}
879
881{
889
890 Int_t val=0;
891 if (fNv) val=1;
892 return val;
893}
894
896{
904
905 Int_t val=0;
906 if (fNv==6) val=1;
907 return val;
908}
909
911{
918
919 Double_t norm=0;
920 if (fV) norm=fV[0];
921
922 fDresult=0;
923 if (fNv==6)
924 {
925 Double_t e[3];
926 GetErrors(e,"sph");
927 fDresult=e[0];
928 }
929
930 return norm;
931}
932
934{
942
943 Double_t pi=acos(-1.);
944 Double_t v[3];
945 GetVector(v,"sph");
946 Double_t thetahalf=v[1]/2.;
947 Double_t arg=0;
948 if (v[1]<pi) arg=tan(thetahalf);
949 Double_t eta=9999;
950 if (arg>0) eta=-log(arg);
951
952 fDresult=0;
953 if (fNv==6)
954 {
955 Double_t e[3];
956 GetErrors(e,"sph");
957 Double_t prod=cos(thetahalf)*sin(thetahalf);
958 fDresult=0;
959 if (prod) fDresult=fabs(e[1]/2.*prod);
960 }
961
962 return eta;
963}
964
966{
973
974 Double_t dotpro=0;
975
976 if ((this) == &q) // Check for special case v.Dot(v)
977 {
978 Double_t norm=GetNorm();
979 Double_t dnorm=GetResultError();
980 dotpro=pow(norm,2);
981 fDresult=2.*norm*dnorm;
982 }
983 else
984 {
985 Double_t a[3],b[3];
986 Double_t ea[3],eb[3];
987 Double_t d2=0;
988
989 GetVector(a,"car");
990 GetErrors(ea,"car");
991 q.GetVector(b,"car");
992 q.GetErrors(eb,"car");
993 for (Int_t i=0; i<3; i++)
994 {
995 dotpro+=a[i]*b[i];
996 d2+=pow(b[i]*ea[i],2)+pow(a[i]*eb[i],2);
997 }
998 fDresult=sqrt(d2);
999 }
1000
1001 return dotpro;
1002}
1003
1005{
1012
1013 return fDresult;
1014}
1015
1017{
1024
1025 Double_t a[3],b[3],c[3];
1026
1027 GetVector(a,"car");
1028 q.GetVector(b,"car");
1029
1030 c[0]=a[1]*b[2]-a[2]*b[1];
1031 c[1]=a[2]*b[0]-a[0]*b[2];
1032 c[2]=a[0]*b[1]-a[1]*b[0];
1033
1034 Nc3Vector v;
1035 if (fNv && q.fNv) v.SetVector(c,"car");
1036
1037 if (fNv==6 || q.fNv==6)
1038 {
1039 Double_t ea[3],eb[3],ec[3],d2;
1040 GetErrors(ea,"car");
1041 q.GetErrors(eb,"car");
1042
1043 d2=pow(b[2]*ea[1],2)+pow(a[1]*eb[2],2)
1044 +pow(b[1]*ea[2],2)+pow(a[2]*eb[1],2);
1045 ec[0]=sqrt(d2);
1046
1047 d2=pow(b[0]*ea[2],2)+pow(a[2]*eb[0],2)
1048 +pow(b[2]*ea[0],2)+pow(a[0]*eb[2],2);
1049 ec[1]=sqrt(d2);
1050
1051 d2=pow(b[1]*ea[0],2)+pow(a[0]*eb[1],2)
1052 +pow(b[0]*ea[1],2)+pow(a[1]*eb[0],2);
1053 ec[2]=sqrt(d2);
1054
1055 v.SetErrors(ec,"car");
1056 }
1057
1058 return v;
1059}
1060
1062{
1069
1070 Double_t a[3],b[3];
1071
1072 GetVector(a,"car");
1073 q.GetVector(b,"car");
1074
1075 for (Int_t i=0; i<3; i++)
1076 {
1077 a[i]+=b[i];
1078 }
1079
1080 Nc3Vector v;
1081 if (fNv || q.fNv) v.SetVector(a,"car");
1082
1083 if (fNv==6 || q.fNv==6)
1084 {
1085 Double_t ea[3],eb[3];
1086 GetErrors(ea,"car");
1087 q.GetErrors(eb,"car");
1088
1089 for (Int_t j=0; j<3; j++)
1090 {
1091 ea[j]=sqrt(pow(ea[j],2)+pow(eb[j],2));
1092 }
1093
1094 v.SetErrors(ea,"car");
1095 }
1096
1097 return v;
1098}
1099
1101{
1108
1109 Double_t a[3],b[3];
1110
1111 GetVector(a,"car");
1112 q.GetVector(b,"car");
1113
1114 for (Int_t i=0; i<3; i++)
1115 {
1116 a[i]-=b[i];
1117 }
1118
1119 Nc3Vector v;
1120 if (fNv || q.fNv) v.SetVector(a,"car");
1121
1122 if (fNv==6 || q.fNv==6)
1123 {
1124 Double_t ea[3],eb[3];
1125 GetErrors(ea,"car");
1126 q.GetErrors(eb,"car");
1127
1128 for (Int_t j=0; j<3; j++)
1129 {
1130 ea[j]=sqrt(pow(ea[j],2)+pow(eb[j],2));
1131 }
1132
1133 v.SetErrors(ea,"car");
1134 }
1135
1136 return v;
1137}
1138
1140{
1147
1148 Double_t a[3];
1149 GetVector(a,"car");
1150
1151 for (Int_t i=0; i<3; i++)
1152 {
1153 a[i]*=s;
1154 }
1155
1156 Nc3Vector v;
1157 if (fNv) v.SetVector(a,"car");
1158
1159 if (fNv==6)
1160 {
1161 Double_t ea[3];
1162 GetErrors(ea,"car");
1163
1164 for (Int_t j=0; j<3; j++)
1165 {
1166 ea[j]*=s;
1167 }
1168
1169 v.SetErrors(ea,"car");
1170 }
1171
1172 return v;
1173}
1174
1176{
1183
1184 if (fabs(s)<1.e-20) // Protect against division by 0
1185 {
1186 cout << " *Nc3Vector::/* Division by 0 detected. No action taken." << endl;
1187 return *this;
1188 }
1189 else
1190 {
1191 Double_t a[3];
1192 GetVector(a,"car");
1193
1194 for (Int_t i=0; i<3; i++)
1195 {
1196 a[i]/=s;
1197 }
1198
1199 Nc3Vector v;
1200 if (fNv) v.SetVector(a,"car");
1201
1202 if (fNv==6)
1203 {
1204 Double_t ea[3];
1205 GetErrors(ea,"car");
1206
1207 for (Int_t j=0; j<3; j++)
1208 {
1209 ea[j]/=s;
1210 }
1211
1212 v.SetErrors(ea,"car");
1213 }
1214
1215 return v;
1216 }
1217}
1218
1220{
1227
1228 Double_t a[3],b[3],ea[3],eb[3];
1229
1230 Int_t nv=fNv;
1231 GetVector(a,"car");
1232 GetErrors(ea,"car");
1233 q.GetVector(b,"car");
1234 q.GetErrors(eb,"car");
1235
1236 for (Int_t i=0; i<3; i++)
1237 {
1238 a[i]+=b[i];
1239 }
1240
1241 if (nv || q.fNv) SetVector(a,"car");
1242
1243 if (nv==6 || q.fNv==6)
1244 {
1245 for (Int_t j=0; j<3; j++)
1246 {
1247 ea[j]=sqrt(pow(ea[j],2)+pow(eb[j],2));
1248 }
1249 SetErrors(ea,"car");
1250 }
1251
1252 return *this;
1253}
1254
1256{
1263
1264 Double_t a[3],b[3],ea[3],eb[3];
1265
1266 Int_t nv=fNv;
1267 GetVector(a,"car");
1268 GetErrors(ea,"car");
1269 q.GetVector(b,"car");
1270 q.GetErrors(eb,"car");
1271
1272 for (Int_t i=0; i<3; i++)
1273 {
1274 a[i]-=b[i];
1275 }
1276
1277 if (nv || q.fNv) SetVector(a,"car");
1278
1279 if (nv==6 || q.fNv==6)
1280 {
1281 for (Int_t j=0; j<3; j++)
1282 {
1283 ea[j]=sqrt(pow(ea[j],2)+pow(eb[j],2));
1284 }
1285 SetErrors(ea,"car");
1286 }
1287
1288 return *this;
1289}
1290
1292{
1299
1300 Double_t a[3],ea[3];
1301
1302 Int_t nv=fNv;
1303 GetVector(a,"car");
1304 GetErrors(ea,"car");
1305
1306 for (Int_t i=0; i<3; i++)
1307 {
1308 a[i]*=s;
1309 }
1310
1311 if (nv) SetVector(a,"car");
1312
1313 if (nv==6)
1314 {
1315 for (Int_t j=0; j<3; j++)
1316 {
1317 ea[j]*=s;
1318 }
1319 SetErrors(ea,"car");
1320 }
1321
1322 return *this;
1323}
1324
1326{
1333
1334 if (fabs(s)<1.e-20) // Protect against division by 0
1335 {
1336 cout << " *Nc3Vector::/=* Division by 0 detected. No action taken." << endl;
1337 return *this;
1338 }
1339 else
1340 {
1341 Double_t a[3],ea[3];
1342
1343 Int_t nv=fNv;
1344 GetVector(a,"car");
1345 GetErrors(ea,"car");
1346
1347 for (Int_t i=0; i<3; i++)
1348 {
1349 a[i]/=s;
1350 }
1351
1352 if (nv) SetVector(a,"car");
1353
1354 if (nv==6)
1355 {
1356 for (Int_t j=0; j<3; j++)
1357 {
1358 ea[j]/=s;
1359 }
1360 SetErrors(ea,"car");
1361 }
1362
1363 return *this;
1364 }
1365}
1366
1368{
1375
1376 Double_t pi=acos(-1.);
1377 Double_t a[3],ea[3];
1378
1379 GetVector(a,"sph");
1380 GetErrors(ea,"sph");
1381
1382 Double_t vt=a[0]*sin(a[1]);
1383 Double_t dvt2=pow((sin(a[1])*ea[0]),2)+pow((a[0]*cos(a[1])*ea[1]),2);
1384
1385 a[0]=fabs(vt);
1386 a[1]=pi/2.;
1387
1388 Nc3Vector v;
1389 if (fNv) v.SetVector(a,"sph");
1390
1391 if (fNv==6)
1392 {
1393 ea[0]=sqrt(dvt2);
1394 ea[1]=0;
1395 v.SetErrors(ea,"sph");
1396 }
1397
1398 return v;
1399}
1400
1402{
1409
1410 Double_t pi=acos(-1.);
1411 Double_t a[3],ea[3];
1412
1413 GetVector(a,"sph");
1414 GetErrors(ea,"sph");
1415
1416 Double_t vl=a[0]*cos(a[1]);
1417 Double_t dvl2=pow((cos(a[1])*ea[0]),2)+pow((a[0]*sin(a[1])*ea[1]),2);
1418
1419 a[0]=fabs(vl);
1420 a[1]=0;
1421 if (vl<0) a[1]=pi;
1422 a[2]=0;
1423
1424 Nc3Vector v;
1425 if (fNv) v.SetVector(a,"sph");
1426
1427 if (fNv==6)
1428 {
1429 ea[0]=sqrt(dvl2);
1430 ea[1]=0;
1431 ea[2]=0;
1432 v.SetErrors(ea,"sph");
1433 }
1434
1435 return v;
1436}
1437
1439{
1447
1448 Nc3Vector v(*this);
1449 if (!m) return v;
1450
1451 Double_t* mat=m->GetMatrix();
1452
1453 Double_t a[3],aprim[3];
1454
1455 if (fNv)
1456 {
1457 GetVector(a,"car");
1458 aprim[0]=a[0]*mat[0]+a[1]*mat[1]+a[2]*mat[2];
1459 aprim[1]=a[0]*mat[3]+a[1]*mat[4]+a[2]*mat[5];
1460 aprim[2]=a[0]*mat[6]+a[1]*mat[7]+a[2]*mat[8];
1461 v.SetVector(aprim,"car");
1462 }
1463
1464 if (fNv==6)
1465 {
1466 GetErrors(a,"car");
1467 aprim[0]=sqrt(pow(a[0]*mat[0],2)+pow(a[1]*mat[1],2)+pow(a[2]*mat[2],2));
1468 aprim[1]=sqrt(pow(a[0]*mat[3],2)+pow(a[1]*mat[4],2)+pow(a[2]*mat[5],2));
1469 aprim[2]=sqrt(pow(a[0]*mat[6],2)+pow(a[1]*mat[7],2)+pow(a[2]*mat[8],2));
1470 v.SetErrors(aprim,"car");
1471 }
1472
1473 return v;
1474}
1475
1477{
1488
1489 Nc3Vector v(*this);
1490 if (!m) return v;
1491
1492 Double_t* mat=m->GetMatrix();
1493
1494 Double_t a[3],aprim[3];
1495
1496 if (fNv)
1497 {
1498 GetVector(aprim,"car");
1499 a[0]=aprim[0]*mat[0]+aprim[1]*mat[3]+aprim[2]*mat[6];
1500 a[1]=aprim[0]*mat[1]+aprim[1]*mat[4]+aprim[2]*mat[7];
1501 a[2]=aprim[0]*mat[2]+aprim[1]*mat[5]+aprim[2]*mat[8];
1502 v.SetVector(a,"car");
1503 }
1504
1505 if (fNv==6)
1506 {
1507 GetErrors(aprim,"car");
1508 a[0]=sqrt(pow(aprim[0]*mat[0],2)+pow(aprim[1]*mat[3],2)+pow(aprim[2]*mat[6],2));
1509 a[1]=sqrt(pow(aprim[0]*mat[1],2)+pow(aprim[1]*mat[4],2)+pow(aprim[2]*mat[7],2));
1510 a[2]=sqrt(pow(aprim[0]*mat[2],2)+pow(aprim[1]*mat[5],2)+pow(aprim[2]*mat[8],2));
1511 v.SetErrors(a,"car");
1512 }
1513
1514 return v;
1515}
1516
1517Double_t Nc3Vector::GetX(Int_t i,TString f,TString u)
1518{
1536
1537 fDresult=0;
1538
1539 if (!fNv || i<1 || i>3) return 0;
1540
1541 Double_t vec[3];
1542 GetVector(vec,f,u);
1543
1544 if (fNv==6)
1545 {
1546 Double_t err[3];
1547 GetErrors(err,f,u);
1548 fDresult=err[i-1];
1549 }
1550
1551 return vec[i-1];
1552}
1553
1555{
1566
1567 Double_t ang=0;
1568
1569 if (GetNorm()<=0. || q.GetNorm()<=0.) return ang;
1570
1571 Double_t vec[3];
1572 Double_t err[3];
1573
1574 Nc3Vector v1;
1575 GetVector(vec,"sph");
1576 vec[0]=1.;
1577 v1.SetVector(vec,"sph");
1578
1579 if (fNv==6)
1580 {
1581 GetErrors(err,"sph");
1582 err[0]=0.;
1583 v1.SetErrors(err,"sph");
1584 }
1585
1586 Nc3Vector v2;
1587 q.GetVector(vec,"sph");
1588 vec[0]=1.;
1589 v2.SetVector(vec,"sph");
1590
1591 if (q.fNv==6)
1592 {
1593 q.GetErrors(err,"sph");
1594 err[0]=0.;
1595 v2.SetErrors(err,"sph");
1596 }
1597
1598 Double_t x=v1.Dot(v2);
1599 Double_t dx=fDresult;
1600 if (x>1.) x=1;
1601 if (x<-1.) x=-1;
1602 ang=acos(x);
1603 fDresult=0;
1604 if (fabs(x)<1.-dx) fDresult=dx/sqrt(1.-x*x);
1605
1606 if (u == "deg")
1607 {
1608 Double_t pi=acos(-1.);
1609 ang*=180./pi;
1610 fDresult*=180./pi;
1611 }
1612
1613 return ang;
1614}
1615
1616Double_t Nc3Vector::ConvertAngle(Double_t a,TString in,TString out) const
1617{
1638
1639 if (in==out) return a;
1640
1641 // Convert input to its absolute value in (fractional) degrees.
1642 Double_t pi=acos(-1.);
1643 Double_t epsilon=1.e-12; // Accuracy in (arc)seconds
1644 Int_t word=0,ddd=0,hh=0,mm=0,ss=0;
1645 Double_t s=0;
1646
1647 Double_t b=fabs(a);
1648
1649 if (in=="rad") b*=180./pi;
1650
1651 if (in=="hrs") b*=15.;
1652
1653 if (in=="dms")
1654 {
1655 word=Int_t(b);
1656 ddd=word/10000;
1657 word=word%10000;
1658 mm=word/100;
1659 ss=word%100;
1660 s=b-Double_t(ddd*10000+mm*100+ss);
1661 b=Double_t(ddd)+Double_t(mm)/60.+(Double_t(ss)+s)/3600.;
1662 }
1663
1664 if (in=="hms")
1665 {
1666 word=Int_t(b);
1667 hh=word/10000;
1668 word=word%10000;
1669 mm=word/100;
1670 ss=word%100;
1671 s=b-Double_t(hh*10000+mm*100+ss);
1672 b=15.*(Double_t(hh)+Double_t(mm)/60.+(Double_t(ss)+s)/3600.);
1673 }
1674
1675 while (b>360)
1676 {
1677 b-=360.;
1678 }
1679
1680 if (out=="rad") b*=pi/180.;
1681
1682 if (out=="hrs") b/=15.;
1683
1684 if (out=="dms")
1685 {
1686 ddd=Int_t(b);
1687 b=b-Double_t(ddd);
1688 b*=60.;
1689 mm=Int_t(b);
1690 b=b-Double_t(mm);
1691 b*=60.;
1692 ss=Int_t(b);
1693 s=b-Double_t(ss);
1694 if (s>(1.-epsilon))
1695 {
1696 s=0.;
1697 ss++;
1698 }
1699 while (ss>=60)
1700 {
1701 ss-=60;
1702 mm++;
1703 }
1704 while (mm>=60)
1705 {
1706 mm-=60;
1707 ddd++;
1708 }
1709 while (ddd>=360)
1710 {
1711 ddd-=360;
1712 }
1713 b=Double_t(10000*ddd+100*mm+ss)+s;
1714 }
1715
1716 if (out=="hms")
1717 {
1718 b/=15.;
1719 hh=Int_t(b);
1720 b=b-Double_t(hh);
1721 b*=60.;
1722 mm=Int_t(b);
1723 b=b-Double_t(mm);
1724 b*=60.;
1725 ss=Int_t(b);
1726 s=b-Double_t(ss);
1727 if (s>(1.-epsilon))
1728 {
1729 s=0.;
1730 ss++;
1731 }
1732 while (ss>=60)
1733 {
1734 ss-=60;
1735 mm++;
1736 }
1737 while (mm>=60)
1738 {
1739 mm-=60;
1740 hh++;
1741 }
1742 while (hh>=24)
1743 {
1744 hh-=24;
1745 }
1746 b=Double_t(10000*hh+100*mm+ss)+s;
1747 }
1748
1749 if (a<0) b=-b;
1750
1751 return b;
1752}
1753
1754void Nc3Vector::PrintAngle(Double_t a,TString in,TString out,Int_t ndig,Bool_t align) const
1755{
1791
1792 Double_t b=ConvertAngle(a,in,out);
1793
1794 if (out=="deg" || out=="rad")
1795 {
1796 if (align)
1797 {
1798 printf("%*.*f %-s",5+ndig,ndig,b,out.Data());
1799 }
1800 else
1801 {
1802 printf("%-.*f %-s",ndig,b,out.Data());
1803 }
1804 return;
1805 }
1806
1807 Double_t epsilon=1.e-12; // Accuracy in (arc)seconds
1808 Int_t word=0,ddd=0,hh=0,mm=0,ss=0;
1809 Double_t s;
1810
1811 if (out=="dms")
1812 {
1813 word=Int_t(b);
1814 word=abs(word);
1815 ddd=word/10000;
1816 word=word%10000;
1817 mm=word/100;
1818 ss=word%100;
1819 s=fabs(b)-Double_t(ddd*10000+mm*100+ss);
1820 if (s>(1.-epsilon))
1821 {
1822 s=0.;
1823 ss++;
1824 }
1825 while (ss>=60)
1826 {
1827 ss-=60;
1828 mm++;
1829 }
1830 while (mm>=60)
1831 {
1832 mm-=60;
1833 ddd++;
1834 }
1835 while (ddd>=360)
1836 {
1837 ddd-=360;
1838 }
1839 if (b<0) ddd=-ddd;
1840 s+=double(ss);
1841 if (align)
1842 {
1843 printf("%4dd %02d' %0*.*f\"",ddd,mm,3+ndig,ndig,s);
1844 }
1845 else
1846 {
1847 printf("%-dd %-d' %-.*f\"",ddd,mm,ndig,s);
1848 }
1849 return;
1850 }
1851
1852 if (out=="hms")
1853 {
1854 word=Int_t(b);
1855 word=abs(word);
1856 hh=word/10000;
1857 word=word%10000;
1858 mm=word/100;
1859 ss=word%100;
1860 s=fabs(b)-Double_t(hh*10000+mm*100+ss);
1861 if (s>(1.-epsilon))
1862 {
1863 s=0.;
1864 ss++;
1865 }
1866 while (ss>=60)
1867 {
1868 ss-=60;
1869 mm++;
1870 }
1871 while (mm>=60)
1872 {
1873 mm-=60;
1874 hh++;
1875 }
1876 while (hh>=24)
1877 {
1878 hh-=24;
1879 }
1880 if (b<0) hh=-hh;
1881 s+=double(ss);
1882 if (align)
1883 {
1884 printf("%3dh %02dm %0*.*fs",hh,mm,3+ndig,ndig,s);
1885 }
1886 else
1887 {
1888 printf("%-dh %-dm %-.*fs",hh,mm,ndig,s);
1889 }
1890 return;
1891 }
1892}
1893
ClassImp(Nc3Vector)
Handling of 3-vectors in various reference frames.
Definition Nc3Vector.h:15
Nc3Vector operator*(Double_t s) const
Double_t GetX(Int_t i, TString f, TString u="rad")
Double32_t fDresult
! Error on scalar result (e.g. norm or dotproduct)
Definition Nc3Vector.h:61
void GetErrors(Double_t *e, TString f, TString u="rad") const
void SetVector(Double_t *v, TString f, TString u="rad")
Nc3Vector & operator*=(Double_t s)
virtual void Load(Nc3Vector &q)
virtual void SetZero()
Nc3Vector & operator+=(Nc3Vector &q)
Nc3Vector Cross(Nc3Vector &q) const
virtual void Data(TString f="car", TString u="rad") const
Nc3Vector operator/(Double_t s) const
Nc3Vector & operator/=(Double_t s)
Nc3Vector operator+(Nc3Vector &q) const
Nc3Vector GetVecTrans() const
Nc3Vector operator-(Nc3Vector &q) const
Nc3Vector & operator=(const Nc3Vector &q)
void SetErrors(Double_t *e, TString f, TString u="rad")
virtual Double_t GetOpeningAngle(Nc3Vector &q, TString u="rad")
Double_t Dot(Nc3Vector &q)
Double_t GetPseudoRapidity()
Int_t fNv
Definition Nc3Vector.h:59
Double_t ConvertAngle(Double_t a, TString in, TString out) const
void PrintAngle(Double_t a, TString in, TString out, Int_t ndig=1, Bool_t align=kFALSE) const
Nc3Vector GetVecLong() const
Double_t GetResultError() const
void GetVector(Double_t *v, TString f, TString u="rad") const
Double32_t * fV
Definition Nc3Vector.h:60
Int_t HasErrors() const
Nc3Vector GetPrimed(TRotMatrix *m) const
Nc3Vector & operator-=(Nc3Vector &q)
virtual ~Nc3Vector()
Int_t HasVector() const
Nc3Vector GetUnprimed(TRotMatrix *m) const
Double_t GetNorm()