CMS 3D CMS Logo

TkBfield.cc

Go to the documentation of this file.
00001 #include <MagneticField/ParametrizedEngine/src/TkBfield.h>
00002 
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <math.h>
00008 
00009 using namespace std;
00010 using namespace magfieldparam;
00011 
00012 
00013 TkBfield::TkBfield(string fld) {
00014   double p1[]={4.90541,17.8768,2.02355,0.0210538,0.000321885,2.37511,0.00326725,2.07656,1.71879}; // 2.0T-2G
00015   double p2[]={4.41982,15.7732,3.02621,0.0197814,0.000515759,2.43385,0.00584258,2.11333,1.76079}; // 3.0T-2G
00016   double p3[]={4.30161,15.2586,3.51926,0.0183494,0.000606773,2.45110,0.00709986,2.12161,1.77038}; // 3.5T-2G
00017   double p4[]={4.24326,15.0201,3.81492,0.0178712,0.000656527,2.45818,0.00778695,2.12500,1.77436}; // 3.8T-2G
00018   double p5[]={4.21136,14.8824,4.01683,0.0175932,0.000695541,2.45311,0.00813447,2.11688,1.76076}; // 4.0T-2G
00019   prm[0]=0;
00020   if (fld=="2_0T") for (int i=0; i<9; i++) prm[i]=p1[i];
00021   if (fld=="3_0T") for (int i=0; i<9; i++) prm[i]=p2[i];
00022   if (fld=="3_5T") for (int i=0; i<9; i++) prm[i]=p3[i];
00023   if (fld=="3_8T") for (int i=0; i<9; i++) prm[i]=p4[i];
00024   if (fld=="4_0T") for (int i=0; i<9; i++) prm[i]=p5[i];
00025   //  cout<<std::endl<<"Instantiation of TkBfield with key "<<fld<<endl;
00026   if (!prm[0]) {
00027     throw cms::Exception("BadParameters") << "Undefined key - " // abort!"<<endl;
00028     <<"Defined keys are: \"2_0T\" \"3_0T\" \"3_5T\" \"3_8T\" and \"4_0T\""<<endl;
00029     // exit(1);
00030   }
00031   ap2=4*prm[0]*prm[0]/(prm[1]*prm[1]);  
00032   hb0=0.5*prm[2]*sqrt(1.0+ap2);
00033   hlova=1/sqrt(ap2);
00034   ainv=2*hlova/prm[1];
00035 //  coeff=1/(prm[8]*prm[8]);
00036 }
00037 
00038 void TkBfield::Bcyl (const double* x) {
00039   double r=sqrt(x[0]*x[0]+x[1]*x[1]);
00040   double z=x[2];
00041   //  if (r<1.15&&fabs(z)<2.8) // NOTE: check omitted, is done already by the wrapper! (NA)
00042     {
00043     z-=prm[3];                    // max Bz point is shifted in z
00044     double az=fabs(z);
00045     double zainv=z*ainv;
00046     double u=hlova-zainv;
00047     double v=hlova+zainv;
00048     double fu[4],gv[4];
00049     ffunkti(u,fu);
00050     ffunkti(v,gv);
00051     double rat=r*ainv;
00052     double rat2=rat*rat;
00053     Bw[0]=hb0*rat*(fu[1]-gv[1]-(fu[3]-gv[3])*rat2/8)/2;
00054     Bw[1]=0;
00055     Bw[2]=hb0*(fu[0]+gv[0]-(fu[2]+gv[2])*rat2/4);
00056     double corBr= prm[4]*r*z*(az-prm[5])*(az-prm[5]);
00057 //    double corBz=-prm[6]*exp(coeff*(az-prm[7])*(az-prm[7]));
00058 //    double corBz=-prm[6]/(1+coeff*(az-prm[7])*(az-prm[7]));
00059     double corBz=-prm[6]*(exp(-(z-prm[7])*(z-prm[7])/(prm[8]*prm[8]))
00060                         + exp(-(z+prm[7])*(z+prm[7])/(prm[8]*prm[8]))); // double Gaussian
00061     Bw[0]+=corBr;
00062     Bw[2]+=corBz;
00063 //   } else {
00064 //     cout <<"TkBfield: The point is outside the region r<1.15m && |z|<2.8m"<<endl;
00065     }
00066 }
00067 
00068 void TkBfield::ffunkti(const double u, double* ff) {
00069 // Function and its 3 derivatives
00070   double a,b,a2,u2;
00071   u2=u*u; 
00072   a=1/(1+u2);
00073   a2=-3*a*a;
00074   b=sqrt(a);
00075   ff[0]=u*b;
00076   ff[1]=a*b;
00077   ff[2]=a2*ff[0];
00078   ff[3]=a2*ff[1]*(1-4*u2);
00079 }
00080 
00081 void TkBfield::getBrfz(const double *x, double *Brfz) {
00082   Bcyl(x);
00083   for (int i=0; i<3; i++) Brfz[i]=Bw[i];
00084 }
00085 
00086 void TkBfield::getBxyz(const double *x, double *Bxyz) {
00087   Bcyl(x);
00088   double r=sqrt(x[0]*x[0]+x[1]*x[1]);
00089   double rinv=(r>0) ? 1/r:0;
00090   Bxyz[0]=Bw[0]*x[0]*rinv;
00091   Bxyz[1]=Bw[0]*x[1]*rinv;
00092   Bxyz[2]=Bw[2];
00093 }
00094 

Generated on Tue Jun 9 17:40:38 2009 for CMSSW by  doxygen 1.5.4