I repost this email because I don't think I got a response.
Below is a macro calculating scalar products between two vectors
using TVectors and arrays. I have been running ROOT 2.00/11 for
SunOS5.4 under SunOS5.5.
In both loops in the first iteration the scalar product calculated
using TVectors is zero. Any explanation?
Thank you and regards,
Michal Lijowski
------------------------------------------------------------------------
Michal Lijowski Washington University
Research Associate St. Louis, MO 63130-4899, USA
Department of Physics phone: 314-935-6285
Campus Box 1105 email: lijowski@cosray2.wustl.edu
------------------------------------------------------------------------
{
gROOT -> Reset();
gBenchmark -> Start("test_vectors");
Double_t av[4][2] = {
-8.997, -0.015,
-9.021, -0.260,
-8.998, -0.021,
-9.021, -0.027};
Double_t bv[4][2] = {
0.0260, -8.982,
0.0250, -8.988,
0.0340, -8.985,
0.0280, -8.992};
TVector va(0, 1), vb(0, 1);
for (Int_t jj = 0; jj < 4; jj++) {
Double_t avn = sqrt(av[jj][0] * av[jj][0] + av[jj][1] * av[jj][1]);
Double_t bvn = sqrt(bv[jj][0] * bv[jj][0] + bv[jj][1] * bv[jj][1]);
Double_t cosine = (av[jj][0] * bv[jj][0] + av[jj][1] * bv[jj][1]) / (avn * bvn);
printf(" %d av %f %f bv %f %f cosine %f\n", jj, av[jj][0], av[jj][1], bv[jj][0], bv[jj][1], cosine);
Int_t ll = 0;
for (Int_t ii = va.GetLwb(); ii <= va.GetUpb(); ii++) {
va(ii) = (float) av[jj][ll];
vb(ii) = (float) bv[jj][ll];
ll++;
}
va.Print();
vb.Print();
cosine = Assert(va * vb) / (sqrt(va.Norm2Sqr() * vb.Norm2Sqr()));
printf(" cosine %f\n", cosine);
}
for (jj = 3; jj >=0; jj--) {
Double_t avn = sqrt(av[jj][0] * av[jj][0] + av[jj][1] * av[jj][1]);
Double_t bvn = sqrt(bv[jj][0] * bv[jj][0] + bv[jj][1] * bv[jj][1]);
Double_t cosine = (av[jj][0] * bv[jj][0] + av[jj][1] * bv[jj][1]) / (avn * bvn);
printf(" %d av %f %f bv %f %f cosine %f\n", jj, av[jj][0], av[jj][1], bv[jj][0], bv[jj][1], cosine);
ll = 0;
for (Int_t ii = va.GetLwb(); ii <= va.GetUpb(); ii++) {
va(ii) = (float) av[jj][ll];
vb(ii) = (float) bv[jj][ll];
ll++;
}
va.Print();
vb.Print();
cosine = Assert(va * vb) / (sqrt(va.Norm2Sqr() * vb.Norm2Sqr()));
printf(" cosine %f\n", cosine );
}
gBenchmark -> Show("test_vectors");
}
Here is an output.
0 av -8.997000 -0.015000 bv 0.026000 -8.982000 cosine -0.001227
cosine 0.000000
1 av -9.021000 -0.260000 bv 0.025000 -8.988000 cosine 0.026029
cosine 0.026029
2 av -8.998000 -0.021000 bv 0.034000 -8.985000 cosine -0.001450
cosine -0.001450
3 av -9.021000 -0.027000 bv 0.028000 -8.992000 cosine -0.000121
cosine -0.000121
3 av -9.021000 -0.027000 bv 0.028000 -8.992000 cosine -0.000121
cosine 0.000000
2 av -8.998000 -0.021000 bv 0.034000 -8.985000 cosine -0.001450
cosine -0.001450
1 av -9.021000 -0.260000 bv 0.025000 -8.988000 cosine 0.026029
cosine 0.026029
0 av -8.997000 -0.015000 bv 0.026000 -8.982000 cosine -0.001227
cosine -0.001227