Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4FieldUtils.cc
이 파일의 문서화 페이지로 가기
1 // ********************************************************************
2 // * License and Disclaimer *
3 // * *
4 // * The Geant4 software is copyright of the Copyright Holders of *
5 // * the Geant4 Collaboration. It is provided under the terms and *
6 // * conditions of the Geant4 Software License, included in the file *
7 // * LICENSE and available at http://cern.ch/geant4/license . These *
8 // * include a list of copyright holders. *
9 // * *
10 // * Neither the authors of this software system, nor their employing *
11 // * institutes,nor the agencies providing financial support for this *
12 // * work make any representation or warranty, express or implied, *
13 // * regarding this software system or assume any liability for its *
14 // * use. Please see the license in the file LICENSE and URL above *
15 // * for the full disclaimer and the limitation of liability. *
16 // * *
17 // * This code implementation is the result of the scientific and *
18 // * technical work of the GEANT4 collaboration. *
19 // * By using, copying, modifying or distributing the software (or *
20 // * any work based on the software) you agree to acknowledge its *
21 // * use in resulting scientific publications, and indicate your *
22 // * acceptance of all terms of the Geant4 Software license. *
23 // ********************************************************************
24 //
25 //
26 // $Id: $
27 //
28 //
29 // Implementation by Dmitry Sorokin - GSoC 2017
30 // Work supported by Google as part of Google Summer of Code 2017.
31 // Supervision / code review: John Apostolakis
32 
33 
34 #include "G4FieldUtils.hh"
35 
36 namespace field_utils {
37 
39  const G4double y[],
40  const G4double yError[],
41  const G4double h,
42  const G4double errorTolerance)
43 {
44  // Accuracy for position
45  G4double error2 = getValue2(yError, Value3D::Position) / sqr(h);
46 
47  // Accuracy for momentum
48  const G4double momentum2 = getValue2(y, Value3D::Momentum);
49  if (momentum2 > 0) {
50  const G4double momentumError2 =
51  getValue2(yError, Value3D::Momentum) / momentum2;
52  error2 = std::max(error2, momentumError2);
53  } else {
54  G4Exception("field_utils::relativeError","Field001",
55  JustWarning, "found case of zero momentum");
56  }
57 #if 0
58  // Accuracy for spin
59  const G4double spin2 = getValue2(y, Value3D::Spin);
60  if (spin2 > 0) {
61  const G4double spinError2 = getValue2(yError, Value3D::Spin) / spin2;
62  error2 = std::max(error2, spinError2);
63  }
64 #endif
65  return std::sqrt(error2) / errorTolerance;
66 }
67 
68 } // field_utils
69 
T max(const T t1, const T t2)
brief Return the largest of the two arguments
Float_t y
Definition: compare.C:6
G4double relativeError(const G4double y[], const G4double yerr[], const G4double hstep, const G4double errorTolerance=1)
Definition: G4FieldUtils.cc:38
double G4double
Definition: G4Types.hh:76
G4double getValue2(const ArrayType &array, Value1D value)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
T sqr(const T &x)
Definition: templates.hh:145