@@ -188,18 +188,20 @@ bool LHCOpticsApproximator::Transport_m_GeV(double in_pos[3],
188188 double in[5 ];
189189 double out[5 ];
190190 double part_mom = 0.0 ;
191- for (int i = 0 ; i < 3 ; i++ )
191+ for (int i = 0 ; i < 3 ; ++i )
192192 part_mom += in_momentum[i] * in_momentum[i];
193193
194- part_mom = TMath::Sqrt (part_mom);
194+ part_mom = std::sqrt (part_mom);
195195
196196 in[0 ] = in_pos[0 ];
197197 in[1 ] = in_momentum[0 ] / nominal_beam_momentum_;
198198 in[2 ] = in_pos[1 ];
199199 in[3 ] = in_momentum[1 ] / nominal_beam_momentum_;
200200 in[4 ] = (part_mom - nominal_beam_momentum_) / nominal_beam_momentum_;
201201
202- bool res = Transport (in, out, check_apertures, true );
202+ if (!Transport (in, out, check_apertures, true )) {
203+ return false ;
204+ }
203205
204206 out_pos[0 ] = out[0 ];
205207 out_pos[1 ] = out[2 ];
@@ -208,11 +210,11 @@ bool LHCOpticsApproximator::Transport_m_GeV(double in_pos[3],
208210 out_momentum[0 ] = out[1 ] * nominal_beam_momentum_;
209211 out_momentum[1 ] = out[3 ] * nominal_beam_momentum_;
210212 double part_out_total_mom = (out[4 ] + 1 ) * nominal_beam_momentum_;
211- out_momentum[2 ] = TMath::Sqrt (part_out_total_mom * part_out_total_mom - out_momentum[0 ] * out_momentum[0 ] -
212- out_momentum[1 ] * out_momentum[1 ]);
213+ out_momentum[2 ] = std::sqrt (part_out_total_mom * part_out_total_mom - out_momentum[0 ] * out_momentum[0 ] -
214+ out_momentum[1 ] * out_momentum[1 ]);
213215 out_momentum[2 ] = TMath::Sign (out_momentum[2 ], in_momentum[2 ]);
214216
215- return res ;
217+ return true ;
216218}
217219
218220bool LHCOpticsApproximator::Transport (const MadKinematicDescriptor *in,
@@ -231,15 +233,17 @@ bool LHCOpticsApproximator::Transport(const MadKinematicDescriptor *in,
231233 input[4 ] = in->ksi ;
232234
233235 // transport inverts the coordinate systems
234- bool res = Transport (input, output, check_apertures, invert_beam_coord_sytems);
236+ if (!Transport (input, output, check_apertures, invert_beam_coord_sytems)) {
237+ return false ;
238+ }
235239
236240 out->x = output[0 ];
237241 out->theta_x = output[1 ];
238242 out->y = output[2 ];
239243 out->theta_y = output[3 ];
240244 out->ksi = output[4 ];
241245
242- return res ;
246+ return true ;
243247}
244248
245249LHCOpticsApproximator::LHCOpticsApproximator (const LHCOpticsApproximator &org)
@@ -760,7 +764,7 @@ void LHCOpticsApproximator::TestAperture(
760764 out_tree->SetBranchAddress (" par_accept" , &(entry[6 ]));
761765
762766 // int ind=0;
763- for (Long64_t i = 0 ; i < entries; i++ ) {
767+ for (Long64_t i = 0 ; i < entries; ++i ) {
764768 inp_tree->GetEntry (i);
765769
766770 // Don't invert the coordinate systems, appertures are defined in the
@@ -983,7 +987,7 @@ bool LHCApertureApproximator::CheckAperture(const double *in,
983987 double out[5 ];
984988 bool result = Transport (in, out, false , invert_beam_coord_sytems);
985989
986- if (ap_type_ == ApertureType::RECTELLIPSE) {
990+ if (result && ap_type_ == ApertureType::RECTELLIPSE) {
987991 result = result && out[0 ] < rect_x_ && out[0 ] > -rect_x_ && out[2 ] < rect_y_ && out[2 ] > -rect_y_ &&
988992 (out[0 ] * out[0 ] / (r_el_x_ * r_el_x_) + out[2 ] * out[2 ] / (r_el_y_ * r_el_y_) < 1 );
989993 }
@@ -1033,13 +1037,17 @@ void LHCOpticsApproximator::PrintCoordinateOpticalFunctions(TMultiDimFet ¶me
10331037void LHCOpticsApproximator::GetLinearApproximation (
10341038 double atPoint[], double &Cx, double &Lx, double &vx, double &Cy, double &Ly, double &vy, double &D, double ep) {
10351039 double out[2 ];
1036- Transport2D (atPoint, out);
1040+ if (!Transport2D (atPoint, out)) {
1041+ return ;
1042+ }
10371043 Cx = out[0 ];
10381044 Cy = out[1 ];
10391045
1040- for (int i = 0 ; i < 5 ; i++ ) {
1046+ for (int i = 0 ; i < 5 ; ++i ) {
10411047 atPoint[i] += ep;
1042- Transport2D (atPoint, out);
1048+ if (!Transport2D (atPoint, out)) {
1049+ continue ;
1050+ }
10431051 switch (i) {
10441052 case 0 :
10451053 vx = (out[0 ] - Cx) / ep;
@@ -1081,18 +1089,24 @@ void LHCOpticsApproximator::GetLineariasedTransportMatrixX(double mad_init_x,
10811089
10821090 double out[5 ];
10831091
1084- Transport (in, out);
1092+ if (!Transport (in, out)) {
1093+ return ;
1094+ };
10851095 double x1 = out[0 ];
10861096 double thx1 = out[1 ];
10871097
10881098 in[0 ] = mad_init_x + d_mad_x;
1089- Transport (in, out);
1099+ if (!Transport (in, out)) {
1100+ return ;
1101+ }
10901102 double x2_dx = out[0 ];
10911103 double thx2_dx = out[1 ];
10921104
10931105 in[0 ] = mad_init_x;
10941106 in[1 ] = mad_init_thx + d_mad_thx; // ?
1095- Transport (in, out);
1107+ if (!Transport (in, out)) {
1108+ return ;
1109+ }
10961110 double x2_dthx = out[0 ];
10971111 double thx2_dthx = out[1 ];
10981112
@@ -1125,18 +1139,24 @@ void LHCOpticsApproximator::GetLineariasedTransportMatrixY(double mad_init_x,
11251139
11261140 double out[5 ];
11271141
1128- Transport (in, out);
1142+ if (!Transport (in, out)) {
1143+ return ;
1144+ };
11291145 double y1 = out[2 ];
11301146 double thy1 = out[3 ];
11311147
11321148 in[2 ] = mad_init_y + d_mad_y;
1133- Transport (in, out);
1149+ if (!Transport (in, out)) {
1150+ return ;
1151+ }
11341152 double y2_dy = out[2 ];
11351153 double thy2_dy = out[3 ];
11361154
11371155 in[2 ] = mad_init_y;
11381156 in[3 ] = mad_init_thy + d_mad_thy; // ?
1139- Transport (in, out);
1157+ if (!Transport (in, out)) {
1158+ return ;
1159+ }
11401160 double y2_dthy = out[2 ];
11411161 double thy2_dthy = out[3 ];
11421162
@@ -1165,11 +1185,15 @@ double LHCOpticsApproximator::GetDx(double mad_init_x,
11651185
11661186 double out[5 ];
11671187
1168- Transport (in, out);
1188+ if (!Transport (in, out)) {
1189+ return 0.0 ;
1190+ }
11691191 double x1 = out[0 ];
11701192
11711193 in[4 ] = mad_init_xi + d_mad_xi;
1172- Transport (in, out);
1194+ if (!Transport (in, out)) {
1195+ return 0.0 ;
1196+ }
11731197 double x2_dxi = out[0 ];
11741198 double dispersion = (x2_dxi - x1) / d_mad_xi;
11751199
@@ -1194,11 +1218,15 @@ double LHCOpticsApproximator::GetDxds(double mad_init_x,
11941218
11951219 double out[5 ];
11961220
1197- Transport (in, out);
1221+ if (!Transport (in, out)) {
1222+ return 0.0 ;
1223+ }
11981224 double thx1 = out[1 ] / MADX_momentum_correction_factor;
11991225
12001226 in[4 ] = mad_init_xi + d_mad_xi;
1201- Transport (in, out);
1227+ if (!Transport (in, out)) {
1228+ return 0.0 ;
1229+ }
12021230 double thx2_dxi = out[1 ] / MADX_momentum_correction_factor;
12031231 double dispersion = (thx2_dxi - thx1) / d_mad_xi;
12041232
0 commit comments