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[ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/composite_calorimeter/src/CCalMagneticField.cc (Version 11.3.0) and /examples/advanced/composite_calorimeter/src/CCalMagneticField.cc (Version 9.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //////////////////////////////////////////////     26 ///////////////////////////////////////////////////////////////////////////////
 27 // File: CCalMagneticField.cc                      27 // File: CCalMagneticField.cc
 28 // Description: User Field class implementatio     28 // Description: User Field class implementation.
 29 //////////////////////////////////////////////     29 ///////////////////////////////////////////////////////////////////////////////
 30 #include <fstream>                             << 
 31                                                << 
 32 #include "CCalMagneticField.hh"                    30 #include "CCalMagneticField.hh"
 33 #include "CCalutils.hh"                            31 #include "CCalutils.hh"
 34 #include "G4SystemOfUnits.hh"                  << 
 35 #include "G4FieldManager.hh"                       32 #include "G4FieldManager.hh"
                                                   >>  33 #include <fstream>
 36                                                    34 
 37 //#define ddebug                                   35 //#define ddebug
 38 //#define debug                                    36 //#define debug
 39                                                    37 
 40 //Constructor and destructor:                      38 //Constructor and destructor:
 41                                                    39 
 42 CCalMagneticField::CCalMagneticField(const G4S     40 CCalMagneticField::CCalMagneticField(const G4String &filename) :
 43   fval(0), pos(0), slope(0), intercept(0)      <<  41   fval(0), pos(0), slope(0), intercept(0) {
 44 {                                              << 
 45 #ifdef debug                                   << 
 46   fVerbosity = 1;                              << 
 47 #else                                          << 
 48   fVerbosity = 0;                              << 
 49 #endif                                         << 
 50                                                    42 
 51   //Let's open the file                            43   //Let's open the file
 52   G4cout << " ==> Opening file " << filename <     44   G4cout << " ==> Opening file " << filename << " to read magnetic field..."
 53          << G4endl;                            <<  45        << G4endl;
 54   G4String pathName = std::getenv("CCAL_GLOBAL <<  46   G4String pathName = getenv("CCAL_GLOBALPATH");
 55   std::ifstream is;                                47   std::ifstream is;
 56   G4bool ok = openGeomFile(is, pathName, filen <<  48   bool ok = openGeomFile(is, pathName, filename);
 57                                                <<  49 
 58   if (ok) {                                        50   if (ok) {
 59     findDO(is, G4String("FLDM"));                  51     findDO(is, G4String("FLDM"));
 60     is >> fval >> npts >> xoff;                    52     is >> fval >> npts >> xoff;
 61                                                <<  53 #ifdef debug
 62     if (fVerbosity)                            <<  54     G4cout << "Field value " << fval << " # points " << npts << " offset in x "
 63       G4cout << "Field value " << fval << " #  <<  55    << xoff*mm << G4endl;
 64         " offset in x "                        <<  56 #endif
 65              << xoff*mm << G4endl;             << 
 66                                                    57 
 67     if (npts > 0) {                                58     if (npts > 0) {
 68       pos       = new G4double[npts];              59       pos       = new G4double[npts];
 69       slope     = new G4double[npts];              60       slope     = new G4double[npts];
 70       intercept = new G4double[npts];              61       intercept = new G4double[npts];
 71                                                    62 
 72       for (G4int i = 0; i < npts; i++) {           63       for (G4int i = 0; i < npts; i++) {
 73         is >> pos[i] >> slope[i] >> intercept[ <<  64   is >> pos[i] >> slope[i] >> intercept[i];
 74         if (fVerbosity)                        <<  65 #ifdef debug
 75           G4cout << tab << "Position " << i << <<  66   G4cout << tab << "Position " << i << " " << pos[i] << " Slope "
 76                  << slope[i] << " Intercept "  <<  67        << slope[i] << " Intercept " << intercept[i] << G4endl;
                                                   >>  68 #endif
 77       }                                            69       }
 78     }                                              70     }
 79                                                    71 
 80     //////////////////////////////////////////     72     ///////////////////////////////////////////////////////////////
 81     // Close the file                              73     // Close the file
 82     G4cout << " ==> Closing file " << filename     74     G4cout << " ==> Closing file " << filename << G4endl;
 83     is.close();                                    75     is.close();
 84   }                                                76   }
 85 }                                                  77 }
 86                                                    78 
 87                                                    79 
 88 CCalMagneticField::~CCalMagneticField() {          80 CCalMagneticField::~CCalMagneticField() {
 89   if (pos)                                         81   if (pos)
 90     delete[] pos;                                  82     delete[] pos;
 91   if (slope)                                       83   if (slope)
 92     delete[] slope;                                84     delete[] slope;
 93   if (intercept)                                   85   if (intercept)
 94     delete[] intercept;                            86     delete[] intercept;
 95 }                                                  87 }
 96                                                    88 
 97                                                    89 
 98 // Member functions                                90 // Member functions
 99                                                    91 
100 void CCalMagneticField::MagneticField(const G4 <<  92 void CCalMagneticField::MagneticField(const double x[3], double B[3]) const {
101 {                                              <<  93 
102   G4int i=0;                                       94   G4int i=0;
103   for (i=0; i<2; i++) {                            95   for (i=0; i<2; i++) {
104     B[i]   = 0*kilogauss;                          96     B[i]   = 0*kilogauss;
105   }                                                97   }
106                                                    98 
107   G4double m1=0;                               <<  99   G4double m=0, c=0;
108   G4double c1=0;                               << 
109   G4double xnew = x[0]/mm + xoff;                 100   G4double xnew = x[0]/mm + xoff;
110   if (npts > 0) {                                 101   if (npts > 0) {
111     for (i=0; i<npts; i++) {                      102     for (i=0; i<npts; i++) {
112       if (xnew > pos[i]*mm) {                     103       if (xnew > pos[i]*mm) {
113         m1 = slope[i];                         << 104   m = slope[i];
114         c1 = intercept[i];                     << 105         c = intercept[i];
115       }                                           106       }
116     }                                             107     }
117   }                                               108   }
118   G4double scor = c1 + m*xnew;                 << 109   G4double scor = c + m*xnew;
119   if (scor < 0.) scor = 0.;                       110   if (scor < 0.) scor = 0.;
120   if (scor > 1.) scor = 1.0;                      111   if (scor > 1.) scor = 1.0;
121                                                   112 
122   B[2] = scor*fval*kilogauss;                     113   B[2] = scor*fval*kilogauss;
123   if (fVerbosity)                              << 114 #ifdef ddebug
124     {                                          << 115   G4cout << "Field at x: " << x[0]/mm << "mm (" << xnew << ") = " << B[2]/tesla
125                                                << 116    << "T (m = " << m << ", c = " << c << ", scale = " << scor << ")"
126       G4cout << "Field at x: " << x[0]/mm << " << 117    << G4endl;
127         B[2]/tesla                             << 118 #endif
128              << "T (m = " << m1 << ", c = " << << 
129         c1 << ", scale = " << scor << ")"      << 
130              << G4endl;                        << 
131     }                                          << 
132 }                                                 119 }
133                                                   120 
134                                                   121 
135 CLHEP::Hep3Vector CCalMagneticField::             122 CLHEP::Hep3Vector CCalMagneticField::
136 MagneticField(const CLHEP::Hep3Vector point) c    123 MagneticField(const CLHEP::Hep3Vector point) const {
137                                                   124 
138   G4double x[3],B[3];                             125   G4double x[3],B[3];
139   CLHEP::Hep3Vector v;                            126   CLHEP::Hep3Vector v;
140                                                   127   
141   x[0] = point.x();                               128   x[0] = point.x();
142   x[1] = point.y();                               129   x[1] = point.y();
143   x[2] = point.z();                               130   x[2] = point.z();
144   CCalMagneticField::MagneticField(x, B);         131   CCalMagneticField::MagneticField(x, B);
145   v.setX(B[0]);                                   132   v.setX(B[0]);   
146   v.setY(B[1]);                                   133   v.setY(B[1]);   
147   v.setZ(B[2]);                                   134   v.setZ(B[2]);   
148   return v;                                       135   return v;
149 }                                                 136 }
150                                                   137 
151                                                   138 
152 void CCalMagneticField::GetFieldValue(const G4 << 139 void CCalMagneticField::GetFieldValue(const double x[3], double* B) const {
153   CCalMagneticField::MagneticField(x, B);         140   CCalMagneticField::MagneticField(x, B);
154 }                                                 141 }
155                                                   142 
156                                                   143