Skip to content

Commit 5ed6796

Browse files
fuhlig1karabowi
authored andcommitted
refactor: Remove gMC
Use the static TVirualMC::GetMC() method instead of the global pointer.
1 parent ab4db5e commit 5ed6796

File tree

16 files changed

+101
-79
lines changed

16 files changed

+101
-79
lines changed

examples/common/mcstack/FairStack.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <TLorentzVector.h> // for TLorentzVector
2424
#include <TParticle.h> // for TParticle
2525
#include <TRefArray.h> // for TRefArray
26-
#include <TVirtualMC.h> // for gMC
26+
#include <TVirtualMC.h> // for TVirtualMC
2727

2828
using std::pair;
2929

@@ -314,7 +314,7 @@ void FairStack::Reset()
314314

315315
void FairStack::Register()
316316
{
317-
if (gMC) {
317+
if (TVirtualMC::GetMC()) {
318318
FairRootManager::Instance()->Register("MCTrack", "Stack", fTracks, kTRUE);
319319
} else {
320320
FairRootManager::Instance()->RegisterAny("MCTrack", fTracks, kTRUE);

examples/simulation/Tutorial4/gconfig/DecayConfig.C

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ void DecayConfig()
3939
// i)particle decays not defined in concrete monte carlo, or
4040
// ii)particles for which the concrete monte carlo is told
4141
// to use the external decayer for its type via:
42-
// gMC->SetUserDecay(pdgId);
42+
// TVirtualMC::GetMC()->SetUserDecay(pdgId);
4343
// If this is invoked, the external decayer will be used for particles
4444
// of type pdgId even if the concrete monte carlo has a decay mode
4545
// already defined for that particle type.
46-
gMC->SetExternalDecayer(decayer);
46+
TVirtualMC::GetMC()->SetExternalDecayer(decayer);
4747

4848
TPythia6& pythia6 = *(TPythia6::Instance());
4949

@@ -57,8 +57,8 @@ void DecayConfig()
5757
for (Int_t ipartnf = 0; ipartnf < npartnf; ipartnf++) {
5858
Int_t ipdg = pdgnf[ipartnf];
5959

60-
if (TString(gMC->GetName()) == "TGeant3")
61-
gMC->SetUserDecay(ipdg); // Force the decay to be done w/external decayer
60+
if (TString(TVirtualMC::GetMC()->GetName()) == "TGeant3")
61+
TVirtualMC::GetMC()->SetUserDecay(ipdg); // Force the decay to be done w/external decayer
6262

6363
pythia6.SetMDCY(pythia6.Pycomp(ipdg), 1, 1); // Activate decay in pythia
6464
}
@@ -76,8 +76,8 @@ void DecayConfig()
7676
Int_t pdghq[nparthq] = {421, 3122, -3122};
7777
for (Int_t iparthq = 0; iparthq < nparthq; iparthq++) {
7878
Int_t ipdg = pdghq[iparthq];
79-
if (TString(gMC->GetName()) == "TGeant3")
80-
gMC->SetUserDecay(ipdg); // Force the decay to be done w/external decayer
79+
if (TString(TVirtualMC::GetMC()->GetName()) == "TGeant3")
80+
TVirtualMC::GetMC()->SetUserDecay(ipdg); // Force the decay to be done w/external decayer
8181
pythia6.SetMDCY(pythia6.Pycomp(ipdg), 1, 1); // Activate decay in pythia
8282
}
8383
// Set pi0 to be stable in pythia6 so that Geant3 can handle decay.

examples/simulation/Tutorial4/gconfig/SetCuts.C

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,35 @@ void SetCuts()
2626
//
2727
// The default settings refer to a complete simulation which generates and follows also the secondary particles.
2828

29-
gMC->SetProcess("PAIR", 1); /** pair production*/
30-
gMC->SetProcess("COMP", 1); /**Compton scattering*/
31-
gMC->SetProcess("PHOT", 1); /** photo electric effect */
32-
gMC->SetProcess("PFIS", 0); /**photofission*/
33-
gMC->SetProcess("DRAY", 1); /**delta-ray*/
34-
gMC->SetProcess("ANNI", 1); /**annihilation*/
35-
gMC->SetProcess("BREM", 1); /**bremsstrahlung*/
36-
gMC->SetProcess("HADR", 1); /**hadronic process*/
37-
gMC->SetProcess("MUNU", 1); /**muon nuclear interaction*/
38-
gMC->SetProcess("DCAY", 1); /**decay*/
39-
gMC->SetProcess("LOSS", 1); /**energy loss*/
40-
gMC->SetProcess("MULS", 0); /**multiple scattering*/
29+
TVirtualMC* MC = TVirtualMC::GetMC();
30+
31+
MC->SetProcess("PAIR", 1); /** pair production*/
32+
MC->SetProcess("COMP", 1); /**Compton scattering*/
33+
MC->SetProcess("PHOT", 1); /** photo electric effect */
34+
MC->SetProcess("PFIS", 0); /**photofission*/
35+
MC->SetProcess("DRAY", 1); /**delta-ray*/
36+
MC->SetProcess("ANNI", 1); /**annihilation*/
37+
MC->SetProcess("BREM", 1); /**bremsstrahlung*/
38+
MC->SetProcess("HADR", 1); /**hadronic process*/
39+
MC->SetProcess("MUNU", 1); /**muon nuclear interaction*/
40+
MC->SetProcess("DCAY", 1); /**decay*/
41+
MC->SetProcess("LOSS", 1); /**energy loss*/
42+
MC->SetProcess("MULS", 0); /**multiple scattering*/
4143

4244
Double_t cut1 = 1.0E-3; // GeV --> 1 MeV
4345
Double_t cutb = 1.0E4; // GeV --> 10 TeV
4446
Double_t tofmax = 1.E10; // seconds
4547
cout << "SetCuts Macro: Setting cuts.." << endl;
4648

47-
gMC->SetCut("CUTGAM", cut1); /** gammas (GeV)*/
48-
gMC->SetCut("CUTELE", cut1); /** electrons (GeV)*/
49-
gMC->SetCut("CUTNEU", cut1); /** neutral hadrons (GeV)*/
50-
gMC->SetCut("CUTHAD", cut1); /** charged hadrons (GeV)*/
51-
gMC->SetCut("CUTMUO", cut1); /** muons (GeV)*/
52-
gMC->SetCut("BCUTE", cut1); /** electron bremsstrahlung (GeV)*/
53-
gMC->SetCut("BCUTM", cut1); /** muon and hadron bremsstrahlung(GeV)*/
54-
gMC->SetCut("DCUTE", cut1); /** delta-rays by electrons (GeV)*/
55-
gMC->SetCut("DCUTM", cut1); /** delta-rays by muons (GeV)*/
56-
gMC->SetCut("PPCUTM", cut1); /** direct pair production by muons (GeV)*/
57-
gMC->SetCut("TOFMAX", tofmax); /**time of flight cut in seconds*/
49+
MC->SetCut("CUTGAM", cut1); /** gammas (GeV)*/
50+
MC->SetCut("CUTELE", cut1); /** electrons (GeV)*/
51+
MC->SetCut("CUTNEU", cut1); /** neutral hadrons (GeV)*/
52+
MC->SetCut("CUTHAD", cut1); /** charged hadrons (GeV)*/
53+
MC->SetCut("CUTMUO", cut1); /** muons (GeV)*/
54+
MC->SetCut("BCUTE", cut1); /** electron bremsstrahlung (GeV)*/
55+
MC->SetCut("BCUTM", cut1); /** muon and hadron bremsstrahlung(GeV)*/
56+
MC->SetCut("DCUTE", cut1); /** delta-rays by electrons (GeV)*/
57+
MC->SetCut("DCUTM", cut1); /** delta-rays by muons (GeV)*/
58+
MC->SetCut("PPCUTM", cut1); /** direct pair production by muons (GeV)*/
59+
MC->SetCut("TOFMAX", tofmax); /**time of flight cut in seconds*/
5860
}

examples/simulation/Tutorial4/gconfig/flConfig.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ void Config()
1414

1515
cout << "GConfig: Fluka has been created." << endl;
1616

17-
FairStack *st = new FairStack();
17+
FairStack* st = new FairStack();
1818
st->SetMinPoints(0);
19-
gMC->SetStack(st);
20-
gMC->SetProcess("CKOV", 1);
19+
TVirtualMC::GetMC()->SetStack(st);
20+
TVirtualMC::GetMC()->SetProcess("CKOV", 1);
2121

2222
// set the common cuts
2323
TString configm(gSystem->Getenv("VMCWORKDIR"));

fairroot/base/sim/FairDetector.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ FairDetector::FairDetector(const FairDetector& rhs)
4242
, fDetId(rhs.fDetId)
4343
{}
4444

45-
FairDetector::~FairDetector() { delete flGeoPar; }
45+
FairDetector::~FairDetector()
46+
{
47+
delete flGeoPar;
48+
}
4649

4750
FairDetector& FairDetector::operator=(const FairDetector& rhs)
4851
{
@@ -88,7 +91,7 @@ void FairDetector::Initialize()
8891
// ---
8992

9093
// Define sensitive volumes if in MT
91-
if (gMC->IsMT()) {
94+
if (TVirtualMC::GetMC()->IsMT()) {
9295
std::cout << "Define sensitive volume " << std::endl;
9396
DefineSensitiveVolumes();
9497
}

fairroot/base/sim/FairGenericStack.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ FairGenericStack::FairGenericStack(Int_t)
5151
{}
5252
#pragma GCC diagnostic pop
5353

54-
FairGenericStack::~FairGenericStack() { delete fDetIter; }
54+
FairGenericStack::~FairGenericStack()
55+
{
56+
delete fDetIter;
57+
}
5558

5659
#pragma GCC diagnostic push
5760
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
@@ -114,7 +117,8 @@ void FairGenericStack::FastSimMoveParticleTo(Double_t xx,
114117
LOG(fatal) << "FairStack::FastSimMoveParticleTo(" << xx << "," << yy << "," << zz << ": " << curVolName << " = "
115118
<< targetVolName << ") crashes the simulation.";
116119
} else {
117-
LOG(debug) << "gMC says track is in \"" << curVolName << "\" moving particle to \"" << targetVolName << "\".";
120+
LOG(debug) << "TVirtualMC::GetMC() says track is in \"" << curVolName << "\" moving particle to \""
121+
<< targetVolName << "\".";
118122
}
119123

120124
Int_t tobedone = 1;

fairroot/base/sim/FairMCApplication.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ void FairMCApplication::InitOnWorker()
463463
RegisterOutput();
464464
}
465465

466-
// Cache thread-local gMC
467-
fMC = gMC;
466+
// Cache thread-local TVirtualMC::GetMC()
467+
fMC = TVirtualMC::GetMC();
468468

469469
// Set data to MC
470470
fMC->SetStack(fStack.get());
@@ -636,10 +636,10 @@ void FairMCApplication::FinishEvent()
636636
// ---
637637
LOG(debug) << "[" << fRootManager->GetInstanceId()
638638
<< " FairMCMCApplication::FinishEvent: " << fMCEventHeader->GetEventID() << " (MC "
639-
<< gMC->CurrentEvent() << ")";
640-
if (gMC->IsMT() && fRun->GetSink()->GetSinkType() == kONLINESINK)
639+
<< TVirtualMC::GetMC()->CurrentEvent() << ")";
640+
if (TVirtualMC::GetMC()->IsMT() && fRun->GetSink()->GetSinkType() == kONLINESINK)
641641
{ // fix the rare case when running G4 multithreaded on MQ
642-
fMCEventHeader->SetEventID(gMC->CurrentEvent() + 1);
642+
fMCEventHeader->SetEventID(TVirtualMC::GetMC()->CurrentEvent() + 1);
643643
}
644644

645645
// --> Fill the stack output array
@@ -684,7 +684,7 @@ void FairMCApplication::FinishEvent()
684684

685685
// Store information about runtime for one event and memory consuption
686686
// for later usage.
687-
if (fRun->IsRunInfoGenerated() && !gMC->IsMT()) {
687+
if (fRun->IsRunInfoGenerated() && !TVirtualMC::GetMC()->IsMT()) {
688688
fRunInfo.StoreInfo();
689689
}
690690
}

fairroot/fastsim/FairFastSimModel.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ void FairFastSimModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
7474
int nofSecondaries(0);
7575
int movedParticleIndex(0);
7676
std::tie(movedParticleIndex, firstSecondary, nofSecondaries) =
77-
((FairGenericStack*)(gMC->GetStack()))->FastSimGetMovedIndex();
77+
((FairGenericStack*)(TVirtualMC::GetMC()->GetStack()))->FastSimGetMovedIndex();
7878
if (movedParticleIndex == -2) {
7979
FairMCApplication::Instance()->Stepping();
8080
std::tie(movedParticleIndex, firstSecondary, nofSecondaries) =
81-
((FairGenericStack*)(gMC->GetStack()))->FastSimGetMovedIndex();
81+
((FairGenericStack*)(TVirtualMC::GetMC()->GetStack()))->FastSimGetMovedIndex();
8282
}
83-
TClonesArray* particles = ((FairGenericStack*)(gMC->GetStack()))->GetListOfParticles();
83+
TClonesArray* particles = ((FairGenericStack*)(TVirtualMC::GetMC()->GetStack()))->GetListOfParticles();
8484
if (nofSecondaries != 0) {
8585
fastStep.SetNumberOfSecondaryTracks(nofSecondaries);
8686

@@ -110,8 +110,8 @@ void FairFastSimModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
110110
}
111111
}
112112

113-
LOG(debug) << "FairFastSimModel::DoIt() moving particle " << gMC->GetStack()->GetCurrentTrackNumber() << " (pos #"
114-
<< movedParticleIndex << ").";
113+
LOG(debug) << "FairFastSimModel::DoIt() moving particle "
114+
<< TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber() << " (pos #" << movedParticleIndex << ").";
115115
if (movedParticleIndex != -1) {
116116
TParticle* particle = (TParticle*)particles->At(movedParticleIndex);
117117

@@ -143,5 +143,5 @@ void FairFastSimModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
143143

144144
gGeoManager->SetCurrentPoint(particle->Vx(), particle->Vy(), particle->Vz());
145145
}
146-
((FairGenericStack*)(gMC->GetStack()))->FastSimClearMovedIndex();
146+
((FairGenericStack*)(TVirtualMC::GetMC()->GetStack()))->FastSimClearMovedIndex();
147147
}

templates/NewDetector_root_containers/NewDetector.cxx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ Bool_t NewDetector::ProcessHits(FairVolume* vol)
107107

108108
// Create NewDetectorPoint at exit of active volume
109109
if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
110-
|| TVirtualMC::GetMC()->IsTrackDisappeared()) {
110+
|| TVirtualMC::GetMC()->IsTrackDisappeared())
111+
{
111112
fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
112113
fVolumeID = vol->getMCid();
113114
if (fELoss == 0.) {
@@ -145,7 +146,7 @@ void NewDetector::Register()
145146
only during the simulation.
146147
*/
147148

148-
if (!gMC->IsMT()) {
149+
if (!TVirtualMC::GetMC()->IsMT()) {
149150
GetRootManager().Register("NewDetectorPoint", "NewDetector", fNewDetectorPointCollection, kTRUE);
150151
} else {
151152
GetRootManager().RegisterAny("NewDetectorPoint", fNewDetectorPointCollection, kTRUE);
@@ -161,7 +162,10 @@ TClonesArray* NewDetector::GetCollection(Int_t iColl) const
161162
}
162163
}
163164

164-
void NewDetector::Reset() { fNewDetectorPointCollection->Clear(); }
165+
void NewDetector::Reset()
166+
{
167+
fNewDetectorPointCollection->Clear();
168+
}
165169

166170
void NewDetector::ConstructGeometry()
167171
{
@@ -231,7 +235,10 @@ NewDetectorPoint* NewDetector::AddHit(Int_t trackID,
231235
return new (clref[size]) NewDetectorPoint(trackID, detID, pos, mom, time, length, eLoss);
232236
}
233237

234-
FairModule* NewDetector::CloneModule() const { return new NewDetector(*this); }
238+
FairModule* NewDetector::CloneModule() const
239+
{
240+
return new NewDetector(*this);
241+
}
235242

236243
void NewDetector::DefineSensitiveVolumes()
237244
{

templates/project_root_containers/MyProjData/MyProjStack.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <TLorentzVector.h> // for TLorentzVector
2626
#include <TParticle.h> // for TParticle
2727
#include <TRefArray.h> // for TRefArray
28-
#include <TVirtualMC.h> // for gMC
28+
#include <TVirtualMC.h> // for TVirtualMC
2929
#include <iosfwd> // for ostream
3030
#include <iostream> // for operator<<, etc
3131
#include <stddef.h> // for NULL
@@ -355,7 +355,7 @@ void MyProjStack::Reset()
355355
// ----- Public method Register ----------------------------------------
356356
void MyProjStack::Register()
357357
{
358-
if (gMC && (!gMC->IsMT())) {
358+
if (TVirtualMC::GetMC() && (!TVirtualMC::GetMC()->IsMT())) {
359359
FairRootManager::Instance()->Register("MCTrack", "Stack", fTracks, kTRUE);
360360
} else {
361361
FairRootManager::Instance()->RegisterAny("MCTrack", fTracks, kTRUE);

0 commit comments

Comments
 (0)