clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name DMagneticFieldMapSpoiled.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0 -D HAVE_CCDB -D HAVE_RCDB -D HAVE_EVIO -D HAVE_TMVA=1 -D RCDB_MYSQL=1 -D RCDB_SQLITE=1 -D SQLITE_USE_LEGACY_STRUCT=ON -I .Linux_CentOS7.7-x86_64-gcc4.8.5/libraries/HDGEOMETRY -I libraries/HDGEOMETRY -I . -I libraries -I libraries/include -I /w/halld-scifs17exp/home/sdobbs/clang/halld_recon/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I external/xstream/include -I /usr/include/tirpc -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/root/root-6.08.06/include -I /w/halld-scifs17exp/halld2/home/sdobbs/Software/jana/jana_0.8.2/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/ccdb/ccdb_1.06.06/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/rcdb/rcdb_0.06.00/cpp/include -I /usr/include/mysql -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlitecpp/SQLiteCpp-2.2.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlite/sqlite-3.13.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/hdds/hdds-4.9.0/Linux_CentOS7.7-x86_64-gcc4.8.5/src -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/xerces-c/xerces-c-3.1.4/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/evio/evio-4.4.6/Linux-x86_64/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward -internal-isystem /usr/local/include -internal-isystem /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/sdobbs/work/clang/halld_recon/src -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-01-21-110224-160369-1 -x c++ libraries/HDGEOMETRY/DMagneticFieldMapSpoiled.cc
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include "DMagneticFieldMapSpoiled.h" |
9 | #include "DMagneticFieldMapCalibDB.h" |
10 | |
11 | #include <iostream> |
12 | #include <cmath> |
13 | using namespace std; |
14 | |
15 | #include <JANA/JApplication.h> |
16 | #include <JANA/JParameterManager.h> |
17 | using namespace jana; |
18 | |
19 | #include <DVector3.h> |
20 | |
21 | |
22 | |
23 | |
24 | DMagneticFieldMapSpoiled::DMagneticFieldMapSpoiled(JApplication *japp, unsigned int run_number, string namepath) |
25 | { |
26 | bfield = new DMagneticFieldMapCalibDB(japp, run_number, namepath); |
27 | |
28 | initialized = false; |
29 | } |
30 | |
31 | |
32 | |
33 | |
34 | DMagneticFieldMapSpoiled::DMagneticFieldMapSpoiled(JCalibration *jcalib, string namepath) |
35 | { |
36 | bfield = new DMagneticFieldMapCalibDB(jcalib, namepath); |
37 | |
38 | initialized = false; |
39 | } |
40 | |
41 | |
42 | |
43 | |
44 | DMagneticFieldMapSpoiled::~DMagneticFieldMapSpoiled() |
45 | { |
46 | if(bfield)delete bfield; |
47 | } |
48 | |
49 | |
50 | |
51 | |
52 | void DMagneticFieldMapSpoiled::Init(void) |
53 | { |
54 | phi_amp = 0.0; |
55 | phi_omega = M_PI/(2.0*M_PI); |
56 | r_amp = 0.0; |
57 | r_omega = M_PI/65.0; |
58 | z_amp = 0.0; |
59 | z_omega = M_PI/(20.0); |
60 | |
61 | if(!gPARMS){ |
62 | _DBG_<<"gPARMS==NULL!"<<endl; |
63 | return; |
64 | } |
65 | |
66 | gPARMS->SetDefaultParameter("BFIELD:PHI_AMP", phi_amp); |
67 | gPARMS->SetDefaultParameter("BFIELD:PHI_OMEGA", phi_omega); |
68 | gPARMS->SetDefaultParameter("BFIELD:R_AMP", r_amp); |
69 | gPARMS->SetDefaultParameter("BFIELD:R_OMEGA", r_omega); |
70 | gPARMS->SetDefaultParameter("BFIELD:Z_AMP", z_amp); |
71 | gPARMS->SetDefaultParameter("BFIELD:Z_OMEGA", z_omega); |
72 | |
73 | initialized=true; |
74 | } |
75 | |
76 | void DMagneticFieldMapSpoiled::GetField(const DVector3 &pos,DVector3 &Bout) const{ |
77 | double Bx,By,Bz; |
| 1 | 'Bx' declared without an initial value | |
|
78 | GetField(pos.x(),pos.y(),pos.z(),Bx,By,Bz); |
| 2 | | Calling 'DMagneticFieldMapSpoiled::GetField' | |
|
| 7 | | Returning from 'DMagneticFieldMapSpoiled::GetField' | |
|
79 | Bout.SetXYZ(Bx,By,Bz); |
| 8 | | 1st function call argument is an uninitialized value |
|
80 | } |
81 | |
82 | |
83 | |
84 | |
85 | void DMagneticFieldMapSpoiled::GetField(double x, double y, double z, double &Bx, double &By, double &Bz, int method) const |
86 | { |
87 | if(!initialized){ |
| 3 | | Assuming field 'initialized' is false | |
|
| |
88 | DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this); |
89 | mythis->Init(); |
90 | } |
91 | if(!initialized)return; |
| |
| 6 | | Returning without writing to 'Bx' | |
|
92 | bfield->GetField(x, y, z, Bx, By, Bz, method); |
93 | |
94 | DVector3 B(Bx, By, Bz); |
95 | double r = sqrt(x*x + y*y); |
96 | double phi = atan2(y,x); |
97 | if(phi<0.0)phi+=2.0*M_PI; |
98 | |
99 | |
100 | double fac = phi_amp*sin(phi_omega*phi) + 1.0; |
101 | |
102 | |
103 | fac *= r_amp*sin(r_omega*r) + 1.0; |
104 | |
105 | |
106 | fac *= z_amp*sin(z_omega*z) + 1.0; |
107 | |
108 | B *= fac; |
109 | Bx = B.X(); |
110 | By = B.Y(); |
111 | Bz = B.Z(); |
112 | |
113 | } |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | double DMagneticFieldMapSpoiled::GetBz(double x, double y, double z) const |
120 | { |
121 | if(!initialized){ |
122 | DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this); |
123 | mythis->Init(); |
124 | } |
125 | if(!initialized)return 0.; |
126 | double Bx,By,Bz; |
127 | bfield->GetField(x, y, z, Bx, By, Bz); |
128 | |
129 | DVector3 B(Bx, By, Bz); |
130 | double r = sqrt(x*x + y*y); |
131 | double phi = atan2(y,x); |
132 | if(phi<0.0)phi+=2.0*M_PI; |
133 | |
134 | |
135 | double fac = phi_amp*sin(phi_omega*phi) + 1.0; |
136 | |
137 | |
138 | fac *= r_amp*sin(r_omega*r) + 1.0; |
139 | |
140 | |
141 | fac *= z_amp*sin(z_omega*z) + 1.0; |
142 | |
143 | B *= fac; |
144 | return B.Z(); |
145 | |
146 | } |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | void DMagneticFieldMapSpoiled::GetFieldGradient(double x, double y, double z, |
153 | double &dBxdx, double &dBxdy, |
154 | double &dBxdz, |
155 | double &dBydx, double &dBydy, |
156 | double &dBydz, |
157 | double &dBzdx, double &dBzdy, |
158 | double &dBzdz) const |
159 | { |
160 | if(!initialized){ |
161 | DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this); |
162 | mythis->Init(); |
163 | } |
164 | if(!initialized)return; |
165 | bfield->GetFieldGradient(x, y, z, dBxdx, dBxdy, dBxdz, dBydx, dBydy, dBydz, dBzdx, dBzdy, dBzdz); |
166 | } |
167 | |
168 | |
169 | void DMagneticFieldMapSpoiled::GetFieldBicubic(double x,double y,double z, |
170 | double &Bx,double &By,double &Bz) const{ |
171 | if(!initialized){ |
172 | DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this); |
173 | mythis->Init(); |
174 | } |
175 | if(!initialized)return; |
176 | bfield->GetFieldBicubic(x,y,z,Bx,By,Bz); |
177 | } |
178 | |
179 | |
180 | void DMagneticFieldMapSpoiled::GetFieldAndGradient(double x,double y,double z, |
181 | double &Bx,double &By, |
182 | double &Bz, |
183 | double &dBxdx, double &dBxdy, |
184 | double &dBxdz, |
185 | double &dBydx, double &dBydy, |
186 | double &dBydz, |
187 | double &dBzdx, double &dBzdy, |
188 | double &dBzdz) const{ |
189 | if(!initialized){ |
190 | DMagneticFieldMapSpoiled *mythis = const_cast<DMagneticFieldMapSpoiled*>(this); |
191 | mythis->Init(); |
192 | } |
193 | if(!initialized)return; |
194 | bfield->GetFieldAndGradient(x,y,z,Bx,By,Bz,dBxdx,dBxdy,dBxdz, |
195 | dBydx,dBydy,dBydz,dBzdx,dBzdy,dBzdz); |
196 | } |