]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TFluka/magfld.cxx
Using TMath::Abs instead of fabs
[u/mrichter/AliRoot.git] / TFluka / magfld.cxx
1 #include "TVirtualMCApplication.h"
2 #include "Fdblprc.h"  //(DBLPRC) fluka common
3 //
4 // #include "TCallf77.h"
5
6 #ifndef WIN32
7 #define magfld magfld_
8 #define type_of_call
9 #else
10 #define magfld MAGFLD
11 #define type_of_call  _stdcall
12 #endif
13
14 extern "C" void type_of_call magfld(double& x,   double& y,   double& z, 
15                                     double& btx, double& bty, double& btz, double& b, 
16                                     int&    nreg,int& idisc)
17 {
18
19 /*
20 *----------------------------------------------------------------------*
21 *                                                                      *
22 *                                                                      *
23 *     Input variables:                                                 *
24 *            x,y,z = current position                                  *
25 *            nreg  = current region                                    *
26 *     Output variables:                                                *
27 *            btx,bty,btz = cosines of the magn. field vector           *
28 *            B = magnetic field intensity (Tesla)                      *
29 *            idisc = set to 1 if the particle has to be discarded      *
30 *                                                                      *
31 *----------------------------------------------------------------------*
32 */
33     
34     idisc = 0;
35     
36     Double_t bc[3];
37     Double_t xc[3];
38     
39     xc[1] = x;
40     xc[0] = y;
41     xc[2] = z;
42     
43     
44         
45     (TVirtualMCApplication::Instance())->Field(xc, bc);
46     
47     b = sqrt(bc[0] * bc[0] + bc[1] * bc[1] + bc[2] * bc[2]);
48     if (b) {
49         btx = bc[1]/b;
50         bty = bc[0]/b;
51         Double_t btt = btx * btx + bty * bty;
52         if (btt >= (Double_t) 1.) {
53             btx /= TMath::Sqrt(btt);
54             bty /= TMath::Sqrt(btt);
55             b   /= TMath::Sqrt(btt);
56             btz =  (Double_t) 0.;
57         } else {
58             btz = TMath::Sqrt((Double_t) 1. -  btt);
59         }
60     } else {
61         btx = 0.;
62         bty = 0.;
63         btz = 1.;
64     }
65     
66     // from kG to T
67     b /= (Double_t) 10.;
68