NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
Nc4Vector.cxx
Go to the documentation of this file.
1
31
33
157
158#include "Nc4Vector.h"
159#include "Riostream.h"
160
161ClassImp(Nc4Vector); // Class implementation to enable ROOT I/O
162
165{
173
174 fUser=0;
175 SetZero();
176 fScalar=1;
177}
178
180{
186
187 if (fUser)
188 {
189 delete fUser;
190 fUser=0;
191 }
192}
193
195{
201
203 fV2=v.fV2;
204 fDv2=v.fDv2;
205 fV0=v.fV0;
206 fDv0=v.fDv0;
208 fV=v.fV;
209 fUser=0;
211}
212
214{
220
222 fV2=q.fV2;
223 fDv2=q.fDv2;
224 fV0=q.fV0;
225 fDv0=q.fDv0;
227 fV=q.fV;
229
230 return *this;
231}
232
234{
240
242 fV2=q.fV2;
243 fDv2=q.fDv2;
244 fV0=q.fV0;
245 fDv0=q.fDv0;
247 fV=q.fV;
249}
250
252{
259
260 fV2=0;
261 fDv2=0;
262 fV0=0;
263 fDv0=0;
264 fDresult=0;
265 fV.SetZero();
266 if (fUser)
267 {
268 delete fUser;
269 fUser=0;
270 }
271}
272
273void Nc4Vector::SetVector(Double_t v0,Nc3Vector& v)
274{
284
285 fScalar=1;
286 fV0=v0;
287 fV=v;
288 fV2=pow(v0,2)-fV.Dot(fV);
290}
291
292void Nc4Vector::SetVector(Double_t* v,TString f,TString u)
293{
310
311 fScalar=1;
312 Double_t a[3];
313 for (Int_t i=0; i<3; i++)
314 {
315 a[i]=v[i+1];
316 }
317 fV0=v[0];
318 fV.SetVector(a,f,u);
319 fV2=pow(fV0,2)-fV.Dot(fV);
320 fDv2=0;
321 fDv0=0;
322 fDresult=0;
323}
324
325void Nc4Vector::SetVector(Double_t v0,Double_t v1,Double_t v2,Double_t v3,TString f,TString u)
326{
343
344 Double_t vec[4];
345 vec[0]=v0;
346 vec[1]=v1;
347 vec[2]=v2;
348 vec[3]=v3;
349 SetVector(vec,f,u);
350}
351
352void Nc4Vector::GetVector(Double_t* v,TString f,TString u)
353{
370
371 if (fScalar)
372 {
373 v[0]=fV0;
374 }
375 else
376 {
377 v[0]=sqrt(fV.Dot(fV)+fV2);
378 }
379 Double_t a[3];
380 fV.GetVector(a,f,u);
381 for (Int_t i=0; i<3; i++)
382 {
383 v[i+1]=a[i];
384 }
385}
386
387void Nc4Vector::SetVector(Float_t* v,TString f,TString u)
388{
407
408 Double_t vec[4];
409 for (Int_t i=0; i<4; i++)
410 {
411 vec[i]=v[i];
412 }
413 SetVector(vec,f,u);
414}
415
416void Nc4Vector::GetVector(Float_t* v,TString f,TString u)
417{
434
435 Double_t vec[4];
436 GetVector(vec,f,u);
437 for (Int_t i=0; i<4; i++)
438 {
439 v[i]=vec[i];
440 }
441}
442
444{
452
453 if (fScalar)
454 {
456 return fV0;
457 }
458 else
459 {
460 Double_t dot=fV.Dot(fV);
461 Double_t ddot=fV.GetResultError();
462 Double_t v02=dot+fV2;
463 Double_t dv02=sqrt(pow(ddot,2)+pow(fDv2,2));
464 Double_t v0=sqrt(fabs(v02));
465 Double_t dv0=0;
466 if (v0) dv0=dv02/(2.*v0);
467 fDresult=dv0;
468 return v0;
469 }
470}
471
473{
481
482 Int_t val=fV.HasVector();
483 return val;
484}
485
487{
495
496 Int_t val=fV.HasErrors();
497 return val;
498}
499
501{
508
509 return fDresult;
510}
511
512void Nc4Vector::SetScalar(Double_t v0,Double_t dv0)
513{
524
525 fScalar=1;
526 fV0=v0;
527 fV2=pow(v0,2)-fV.Dot(fV);
528 SetScalarError(dv0);
529}
530
532{
540
541 fDv0=dv0;
542 if (fScalar)
543 {
544 Double_t norm=fV.GetNorm();
545 Double_t dnorm=fV.GetResultError();
546 fDv2=sqrt(pow(2.*fV0*fDv0,2)+pow(2.*norm*dnorm,2));
547 }
548 fDresult=0;
549}
550
552{
563
564 fV=v;
565 if (fScalar)
566 {
568 }
569 else
570 {
572 }
573}
574
575void Nc4Vector::Set3Vector(Double_t* v,TString f,TString u)
576{
596
597 Double_t a[3];
598 for (Int_t i=0; i<3; i++)
599 {
600 a[i]=v[i];
601 }
602 fV.SetVector(a,f,u);
603
604 if (fScalar)
605 {
607 }
608 else
609 {
611 }
612}
613
614void Nc4Vector::Set3Vector(Float_t* v,TString f,TString u)
615{
632
633 Double_t vec[3];
634 for (Int_t i=0; i<3; i++)
635 {
636 vec[i]=v[i];
637 }
638 Set3Vector(vec,f,u);
639}
640
641void Nc4Vector::Set3Vector(Double_t v1,Double_t v2,Double_t v3,TString f,TString u)
642{
662
663 Double_t vec[3];
664 vec[0]=v1;
665 vec[1]=v2;
666 vec[2]=v3;
667 Set3Vector(vec,f,u);
668}
669
670void Nc4Vector::SetInvariant(Double_t v2,Double_t dv2)
671{
682
683 fScalar=0;
684 fV2=v2;
685 fDv2=dv2;
686 fV0=GetScalar();
688 fDresult=0;
689}
690
692{
700
701 fDv2=dv2;
702 if (!fScalar)
703 {
705 }
706 fDresult=0;
707}
708
710{
718
719 if (!fScalar)
720 {
722 return fV2;
723 }
724 else
725 {
726 Double_t inv=Dot(*this);
727 return inv;
728 }
729}
730
732{
738
739 return fV;
740}
741
742void Nc4Vector::SetErrors(Double_t* e,TString f,TString u)
743{
759
760 Double_t a[3];
761 for (Int_t i=0; i<3; i++)
762 {
763 a[i]=e[i+1];
764 }
765 SetScalarError(e[0]);
766 fV.SetErrors(a,f,u);
767}
768
769void Nc4Vector::SetErrors(Double_t e0,Double_t e1,Double_t e2,Double_t e3,TString f,TString u)
770{
786
787 Double_t vec[4];
788 vec[0]=e0;
789 vec[1]=e1;
790 vec[2]=e2;
791 vec[3]=e3;
792 SetErrors(vec,f,u);
793}
794
795void Nc4Vector::SetErrors(Float_t* e,TString f,TString u)
796{
812
813 Double_t a[4];
814 for (Int_t i=0; i<4; i++)
815 {
816 a[i]=e[i];
817 }
818 SetErrors(a,f,u);
819}
820
821void Nc4Vector::GetErrors(Double_t* e,TString f,TString u)
822{
839
840 Double_t a[3];
841 fV.GetErrors(a,f,u);
842
843 // Dummy invokation of GetScalar to obtain automatic proper error determination
844 e[0]=GetScalar();
845
846 e[0]=GetResultError();
847
848 for (Int_t i=0; i<3; i++)
849 {
850 e[i+1]=a[i];
851 }
852}
853
854void Nc4Vector::GetErrors(Float_t* e,TString f,TString u)
855{
872
873 Double_t a[4];
874 GetErrors(a,f,u);
875 for (Int_t i=0; i<4; i++)
876 {
877 e[i]=a[i];
878 }
879}
880
881void Nc4Vector::Data(TString f,TString u)
882{
899
900 if (f=="car" || f=="sph" || f=="cyl")
901 {
902 Double_t vec[4],err[4];
903 GetVector(vec,f,u);
904 GetErrors(err,f,u);
905 Double_t inv=GetInvariant();
906 Double_t dinv=GetResultError();
907 if (fV.HasVector())
908 {
909 cout << " Contravariant vector in " << f.Data() << " (" << u.Data() << ") coordinates : "
910 << vec[0] << " " << vec[1] << " " << vec[2] << " " << vec[3] << endl;
911 }
912 else
913 {
914 cout << " 4-Vector not initialised." << endl;
915 }
916 if (fV.HasErrors())
917 {
918 cout << " ------------- Errors in " << f.Data() << " (" << u.Data() << ") coordinates : "
919 << err[0] << " " << err[1] << " " << err[2] << " " << err[3] << endl;
920 }
921 if (fV.HasVector())
922 {
923 cout << " --- Lorentz invariant (v^2) : " << inv << " error : " << dinv << endl;
924 }
925 }
926 else
927 {
928 cout << " *Nc4Vector::Data* Unsupported frame : " << f.Data() << endl
929 << " Possible frames are 'car', 'sph' and 'cyl'." << endl;
930 }
931}
932
934{
940
941 Double_t dotpro=0;
942 Double_t a0=GetScalar();
943 Double_t da0=GetResultError();
944 if ((this) == &q) // Check for special case v.Dot(v)
945 {
946 Double_t norm=fV.GetNorm();
947 Double_t dnorm=fV.GetResultError();
948 dotpro=pow(a0,2)-pow(norm,2);
949 fDresult=sqrt(pow(2.*a0*da0,2)+pow(2.*norm*dnorm,2));
950 }
951 else
952 {
953 Double_t b0=q.GetScalar();
954 Double_t db0=q.GetResultError();
955 Nc3Vector b=q.Get3Vector();
956
957 Double_t dot=fV.Dot(b);
958 Double_t ddot=fV.GetResultError();
959
960 dotpro=a0*b0-dot;
961
962 fDresult=sqrt(pow(b0*da0,2)+pow(a0*db0,2)+pow(ddot,2));
963 }
964
965 return dotpro;
966}
967
969{
976
977 Double_t a0=GetScalar();
978 Double_t da0=GetResultError();
980 Double_t b0=q.GetScalar();
981 Double_t db0=q.GetResultError();
982 Nc3Vector b=q.Get3Vector();
983
984 Double_t c0=a0+b0;
985 Nc3Vector c=a+b;
986 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
987
988 Nc4Vector v;
989 v.SetVector(c0,c);
990 v.SetScalarError(dc0);
991 return v;
992}
993
995{
1002
1003 Double_t a0=GetScalar();
1004 Double_t da0=GetResultError();
1006 Double_t b0=q.GetScalar();
1007 Double_t db0=q.GetResultError();
1008 Nc3Vector b=q.Get3Vector();
1009
1010 Double_t c0=a0-b0;
1011 Nc3Vector c=a-b;
1012 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
1013
1014 Nc4Vector v;
1015 v.SetVector(c0,c);
1016 v.SetScalarError(dc0);
1017 return v;
1018}
1019
1021{
1028
1029 Double_t a0=GetScalar();
1030 Double_t da0=GetResultError();
1032
1033 a0*=s;
1034 a*=s;
1035 da0*=s;
1036
1037 Nc4Vector v;
1038 v.SetVector(a0,a);
1039 v.SetScalarError(da0);
1040
1041 return v;
1042}
1043
1045{
1052
1053 if (fabs(s)<1.e-20) // Protect against division by 0
1054 {
1055 cout << " *Nc4Vector::/* Division by 0 detected. No action taken." << endl;
1056 return *this;
1057 }
1058 else
1059 {
1060 Double_t a0=GetScalar();
1061 Double_t da0=GetResultError();
1063
1064 a0/=s;
1065 a/=s;
1066 da0/=s;
1067
1068 Nc4Vector v;
1069 v.SetVector(a0,a);
1070 v.SetScalarError(da0);
1071
1072 return v;
1073 }
1074}
1075
1077{
1084
1085 Double_t a0=GetScalar();
1086 Double_t da0=GetResultError();
1088 Double_t b0=q.GetScalar();
1089 Double_t db0=q.GetResultError();
1090 Nc3Vector b=q.Get3Vector();
1091
1092 Double_t c0=a0+b0;
1093 Nc3Vector c=a+b;
1094 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
1095
1096 SetVector(c0,c);
1097 SetScalarError(dc0);
1098
1099 return *this;
1100}
1101
1103{
1110
1111 Double_t a0=GetScalar();
1112 Double_t da0=GetResultError();
1114 Double_t b0=q.GetScalar();
1115 Double_t db0=q.GetResultError();
1116 Nc3Vector b=q.Get3Vector();
1117
1118 Double_t c0=a0-b0;
1119 Nc3Vector c=a-b;
1120 Double_t dc0=sqrt(pow(da0,2)+pow(db0,2));
1121
1122 SetVector(c0,c);
1123 SetScalarError(dc0);
1124
1125 return *this;
1126}
1127
1129{
1136
1137 Double_t a0=GetScalar();
1138 Double_t da0=GetResultError();
1140
1141 a0*=s;
1142 a*=s;
1143 da0*=s;
1144
1145 SetVector(a0,a);
1146 SetScalarError(da0);
1147
1148 return *this;
1149}
1150
1152{
1159
1160 if (fabs(s)<1.e-20) // Protect against division by 0
1161 {
1162 cout << " *Nc4Vector::/* Division by 0 detected. No action taken." << endl;
1163 return *this;
1164 }
1165 else
1166 {
1167 Double_t a0=GetScalar();
1168 Double_t da0=GetResultError();
1170
1171 a0/=s;
1172 a/=s;
1173 da0/=s;
1174
1175 SetVector(a0,a);
1176 SetScalarError(da0);
1177
1178 return *this;
1179 }
1180}
1181
1183{
1189
1190 return fScalar;
1191}
1192
1194{
1201
1202 return fV.GetVecTrans();
1203}
1204
1206{
1213
1214 return fV.GetVecLong();
1215}
1216
1218{
1228
1229 Double_t a[3],ea[3];
1230
1231 fV.GetVector(a,"sph");
1232 fV.GetErrors(ea,"sph");
1233
1234 Double_t s=GetScalar();
1235 Double_t ds=GetResultError();
1236
1237 Double_t st,dst2;
1238 st=s*sin(a[1]);
1239 dst2=pow((sin(a[1])*ds),2)+pow((s*cos(a[1])*ea[1]),2);
1240
1241 fDresult=sqrt(dst2);
1242 return fabs(st);
1243}
1244
1246{
1256
1257 Double_t a[3],ea[3];
1258
1259 fV.GetVector(a,"sph");
1260 fV.GetErrors(ea,"sph");
1261
1262 Double_t s=GetScalar();
1263 Double_t ds=GetResultError();
1264
1265 Double_t sl,dsl2;
1266 sl=s*cos(a[1]);
1267 dsl2=pow((cos(a[1])*ds),2)+pow((s*sin(a[1])*ea[1]),2);
1268
1269 fDresult=sqrt(dsl2);
1270 return sl;
1271}
1272
1274{
1282
1283 Double_t eta=fV.GetPseudoRapidity();
1284 fDresult=fV.GetResultError();
1285 return eta;
1286}
1287
1289{
1295
1296 Nc3Vector beta;
1297 if (fabs(fV0)>0.) beta=fV/fV0;
1298 if (fabs(fDv0)>0.)
1299 {
1300 Double_t vecv[3],errv[3],errb[3];
1301 Double_t sqerr=0;
1302 fV.GetVector(vecv,"car");
1303 fV.GetErrors(errv,"car");
1304 for (Int_t i=0; i<3; i++)
1305 {
1306 sqerr=pow((errv[i]/fV0),2)+pow((vecv[i]*fDv0/(fV0*fV0)),2);
1307 errb[i]=sqrt(sqerr);
1308 }
1309 beta.SetErrors(errb,"car");
1310 }
1311 return beta;
1312}
1313
1315{
1321
1322 Nc3Vector beta=GetBetaVector();
1323 Double_t val=beta.GetNorm();
1324 fDresult=beta.GetResultError();
1325 return val;
1326}
1327
1329{
1336
1337 Double_t gamma=-1;
1338 fDresult=0;
1339 Double_t inv=sqrt(fabs(fV2));
1340 if (inv>0.)
1341 {
1342 Double_t dinv=fDv2/(2.*inv);
1343 gamma=fV0/inv;
1344 Double_t sqerr=pow((fDv0/inv),2)+pow((fV0*dinv/fV2),2);
1345 fDresult=sqrt(sqerr);
1346 }
1347 return gamma;
1348}
1349
1350Double_t Nc4Vector::GetX(Int_t i,TString f,TString u)
1351{
1369
1370 fDresult=0;
1371
1372 if (i<0 || i>3) return 0;
1373
1374 Double_t x=0;
1375
1376 if (i==0)
1377 {
1378 x=GetScalar();
1379 }
1380 else
1381 {
1382 x=fV.GetX(i,f,u);
1383 fDresult=fV.GetResultError();
1384 }
1385
1386 return x;
1387}
1388
1390{
1401
1402 Nc3Vector v1=fV;
1403 Nc3Vector v2=q.Get3Vector();
1404
1405 Double_t ang=v1.GetOpeningAngle(v2,u);
1407
1408 return ang;
1409}
1410
1412{
1423
1424 Nc3Vector v1=fV;
1425
1426 Double_t ang=v1.GetOpeningAngle(q,u);
1428
1429 return ang;
1430}
1431
1433{
1460
1461 if (fUser)
1462 {
1463 delete fUser;
1464 fUser=0;
1465 }
1466
1467 if (s) fUser=(NcSignal*)s->Clone();
1468}
1469
1471{
1477
1478 return fUser;
1479}
1480
ClassImp(Nc4Vector)
Handling of 3-vectors in various reference frames.
Definition Nc3Vector.h:15
void SetErrors(Double_t *e, TString f, TString u="rad")
virtual Double_t GetOpeningAngle(Nc3Vector &q, TString u="rad")
Double_t GetResultError() const
Double_t GetNorm()
Handling of Lorentz 4-vectors in various reference frames.
Definition Nc4Vector.h:14
Double32_t fV2
Definition Nc4Vector.h:72
Double_t GetPseudoRapidity()
void SetInvariant(Double_t v2, Double_t dv2=0)
Nc4Vector & operator-=(Nc4Vector &q)
Double_t GetScaTrans()
Int_t HasErrors() const
Nc4Vector operator*(Double_t s)
void SetScalar(Double_t v0, Double_t dv0=0)
Nc4Vector operator+(Nc4Vector &q)
virtual void SetZero()
Double_t GetX(Int_t i, TString f, TString u="rad")
Nc4Vector & operator=(const Nc4Vector &q)
Nc3Vector GetBetaVector() const
Double_t Dot(Nc4Vector &q)
Int_t fScalar
Definition Nc4Vector.h:78
virtual Double_t GetOpeningAngle(Nc4Vector &q, TString u="rad")
virtual ~Nc4Vector()
virtual void Load(Nc4Vector &q)
Double_t GetScaLong()
Nc4Vector operator/(Double_t s)
void SetUserData(NcSignal *s)
void SetVector(Double_t v0, Nc3Vector &v)
Nc3Vector GetVecLong() const
Double_t GetGamma()
Double32_t fDv0
Definition Nc4Vector.h:76
NcSignal * fUser
Definition Nc4Vector.h:81
Double_t GetResultError() const
void SetErrors(Double_t *v, TString f, TString u="rad")
Nc4Vector & operator+=(Nc4Vector &q)
Double_t GetInvariant()
Int_t GetScalarFlag() const
void GetVector(Double_t *v, TString f, TString u="rad")
Double_t GetBeta()
virtual void Data(TString f="car", TString u="rad")
Nc4Vector operator-(Nc4Vector &q)
void Set3Vector(Nc3Vector &v)
Double32_t fV0
Definition Nc4Vector.h:73
void GetErrors(Double_t *v, TString f, TString u="rad")
Nc4Vector & operator/=(Double_t s)
Double_t GetScalar()
Int_t HasVector() const
Nc3Vector GetVecTrans() const
Nc3Vector Get3Vector() const
Nc4Vector & operator*=(Double_t s)
Nc3Vector fV
Definition Nc4Vector.h:74
NcSignal * GetUserData() const
Double32_t fDv2
Definition Nc4Vector.h:75
void SetInvariantError(Double_t dv2)
void SetScalarError(Double_t dv0)
Double32_t fDresult
! The error on the scalar result of an operation (e.g. dotproduct)
Definition Nc4Vector.h:77
Generic handling of (extrapolated) detector signals.
Definition NcSignal.h:23
virtual TObject * Clone(const char *name="") const