Skip to content

Commit e981b15

Browse files
authored
Merge pull request #48576 from civanch/preparation_for_gpu
[SIM] Minor code update for future use of GPU
2 parents e152e7e + a54ebc1 commit e981b15

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

SimG4Core/Application/src/RunManagerMTWorker.cc

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "SimG4Core/Notification/interface/BeginOfJob.h"
3333
#include "SimG4Core/Notification/interface/CMSSteppingVerbose.h"
3434
#include "SimG4Core/Notification/interface/SimTrackManager.h"
35+
#include "SimG4Core/Notification/interface/CurrentG4Track.h"
3536
#include "SimG4Core/Watcher/interface/SimWatcherFactory.h"
3637

3738
#include "SimG4Core/Geometry/interface/DDDWorld.h"
@@ -180,6 +181,9 @@ RunManagerMTWorker::RunManagerMTWorker(const edm::ParameterSet& p, edm::Consumes
180181
m_G4CommandsEndRun(p.getParameter<std::vector<std::string>>("G4CommandsEndRun")),
181182
m_p(p) {
182183
int id = getThreadIndex();
184+
if (id > CurrentG4Track::NumberOfThreads()) {
185+
CurrentG4Track::setNumberOfThreads(id);
186+
}
183187
edm::LogVerbatim("SimG4CoreApplication") << "RunManagerMTWorker for the thread " << id;
184188

185189
// Initialize per-thread output
@@ -744,44 +748,34 @@ void RunManagerMTWorker::DumpMagneticField(const G4Field* field, const std::stri
744748
// CMS magnetic field volume
745749
double rmax = 9000 * CLHEP::mm;
746750
double zmax = 24000 * CLHEP::mm;
747-
double phimax = CLHEP::twopi;
748751

749-
double dr = 2 * CLHEP::cm;
752+
double dx = 10 * CLHEP::cm;
750753
double dz = 10 * CLHEP::cm;
751-
double dphi = phimax / 32.;
752754

753-
int nr = G4lrint(rmax / dr);
755+
int nx = G4lrint(2 * rmax / dx);
754756
int nz = G4lrint(2 * zmax / dz);
755-
int nphi = G4lrint(phimax / dphi);
756757

757758
double point[4] = {0.0, 0.0, 0.0, 0.0};
758759
double bfield[3] = {0.0, 0.0, 0.0};
759760

760-
double z;
761-
double d1 = 1. / CLHEP::rad;
762761
double d2 = 1. / CLHEP::mm;
763762
double d3 = 1. / CLHEP::tesla;
764763

765764
fout << std::setprecision(6);
766-
fout << "### " << file << " CMS magnetic field: phi(rad) R(mm) Z(mm) Bx(tesla) By(tesla) Bz(tesla) ###" << G4endl;
767-
for (int k = 0; k <= nphi; ++k) {
768-
double phi = k * dphi;
769-
double cosf = cos(phi);
770-
double sinf = sin(phi);
771-
double r = 0.0;
772-
double z0 = -zmax;
773-
for (int i = 0; i <= nr; ++i) {
774-
z = z0;
765+
fout << "### " << file << " CMS magnetic field: X(mm) Y(mm) Z(mm) Bx(tesla) By(tesla) Bz(tesla) ###" << G4endl;
766+
for (int k = 0; k <= nx; ++k) {
767+
double x = k * dx - rmax;
768+
for (int i = 0; i <= nx; ++i) {
769+
double y = i * dx - rmax;
775770
for (int j = 0; j <= nz; ++j) {
776-
point[0] = r * cosf;
777-
point[1] = r * sinf;
771+
double z = j * dz - zmax;
772+
point[0] = x;
773+
point[1] = y;
778774
point[2] = z;
779775
field->GetFieldValue(point, bfield);
780-
fout << phi * d1 << " " << r * d2 << " " << z * d2 << " " << bfield[0] * d3 << " " << bfield[1] * d3 << " "
776+
fout << x * d2 << " " << y * d2 << " " << z * d2 << " " << bfield[0] * d3 << " " << bfield[1] * d3 << " "
781777
<< bfield[2] * d3 << G4endl;
782-
z += dz;
783778
}
784-
r += dr;
785779
}
786780
}
787781
fout.close();

SimG4Core/Notification/interface/CurrentG4Track.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
#include "G4Track.hh"
55

66
/** This class is NOT intended for general use.
7+
* It includes static methods needed in exceptional cases.
78
* It provides immediate access to the currently tracked G4Track
89
* for places that can't access this information easily,
910
* like StackingAction.
10-
* If an acceptable geant4 mechanism is found for this,
11-
* this class will be removed.
11+
* It also provide an access to the total number of threads in the run
1212
*/
1313

1414
class CurrentG4Track {
1515
public:
1616
static const G4Track *track();
17+
static int NumberOfThreads();
18+
static void setNumberOfThreads(int);
1719
static void setTrack(const G4Track *);
1820

1921
private:
2022
static thread_local const G4Track *m_track;
23+
static int m_nThreads;
2124
};
2225

2326
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#include "SimG4Core/Notification/interface/CurrentG4Track.h"
22

3+
int CurrentG4Track::m_nThreads = 0;
34
thread_local const G4Track* CurrentG4Track::m_track = nullptr;
45

56
void CurrentG4Track::setTrack(const G4Track* t) { m_track = t; }
67

78
const G4Track* CurrentG4Track::track() { return m_track; }
9+
10+
int CurrentG4Track::NumberOfThreads() { return m_nThreads; };
11+
12+
void CurrentG4Track::setNumberOfThreads(int n) { m_nThreads = n; };

0 commit comments

Comments
 (0)