Skip to content

Commit d365a7a

Browse files
ihrivnacsawenzel
authored andcommitted
Update for MT simulation (version 2)
- Replaced calls to FairGenericRootManager with FairRootManager (now thread-safe) - Migrated code in Detectors and DataFormats to MT - Implemented CloneModule() method where missing - Moved definition of sensitive volumes in detectors from ConstructGeometry() to Initialize(), to get it called on threads - Changed static local variables defined during event processing in static thread_local - Implemented o2::Stack::FinishPrimary(), which has been added in FairGenericStack base class, and removed the hook for calling this code from commonConfig.C. The code still requires clean-up by the author of the Stack class to avoid mIsG4Like test here.
1 parent 90449e8 commit d365a7a

15 files changed

Lines changed: 209 additions & 69 deletions

File tree

DataFormats/simulation/src/Stack.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ Stack::Stack(const Stack& rhs)
7777
mEnergyCut(rhs.mEnergyCut),
7878
mIsG4Like(rhs.mIsG4Like)
7979
{
80-
LOG(FATAL) << "copy constructor called" << FairLogger::endl;
81-
mTracks = new std::vector<MCTrack>(rhs.mTracks->size());
80+
LOG(DEBUG) << "copy constructor called" << FairLogger::endl;
81+
mTracks = new std::vector<MCTrack>();
82+
// LOG(INFO) << "Stack::Stack(rhs) " << this << " mTracks " << mTracks << std::endl;
8283
}
8384

8485
Stack::~Stack()
@@ -331,6 +332,13 @@ void Stack::UpdateTrackIndex(TRefArray* detList)
331332
LOG(DEBUG) << "Stack::UpdateTrackIndex: ...stack and " << nColl << " collections updated.";
332333
}
333334

335+
void Stack::FinishPrimary()
336+
{
337+
if ( mIsG4Like ) {
338+
notifyFinishPrimary();
339+
}
340+
}
341+
334342
void Stack::Reset()
335343
{
336344
mIndex = 0;
@@ -350,6 +358,7 @@ void Stack::Reset()
350358
}
351359

352360
void Stack::Register() { FairRootManager::Instance()->RegisterAny("MCTrack", mTracks, kTRUE); }
361+
353362
void Stack::Print(Int_t iVerbose) const
354363
{
355364
cout << "-I- Stack: Number of primaries = " << mNumberOfPrimaryParticles << endl;

Detectors/EMCAL/simulation/include/EMCALSimulation/Detector.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ class Detector : public o2::Base::DetImpl<Detector>
5858
///
5959
~Detector() override = default;
6060

61+
///
62+
/// Clone this object (used in MT mode only)
63+
///
64+
FairModule *CloneModule() const override;
65+
6166
///
6267
/// Initializing detector
6368
///
@@ -165,6 +170,11 @@ class Detector : public o2::Base::DetImpl<Detector>
165170
Double_t CalculateLightYield(Double_t energydeposit, Double_t tracklength, Int_t charge) const;
166171

167172
private:
173+
///
174+
/// Copy constructor (used in MT)
175+
///
176+
Detector(const Detector& rhs);
177+
168178
Int_t mBirkC0;
169179
Double_t mBirkC1;
170180
Double_t mBirkC2;

Detectors/EMCAL/simulation/src/Detector.cxx

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,44 @@ Detector::Detector(Bool_t active)
6666
mSampleWidth += 2. * geo->GetTrd1BondPaperThick();
6767
}
6868

69-
void Detector::Initialize() { o2::Base::Detector::Initialize(); }
69+
Detector::Detector(const Detector& rhs)
70+
: o2::Base::DetImpl<Detector>(rhs),
71+
mBirkC0(rhs.mBirkC0),
72+
mBirkC1(rhs.mBirkC1),
73+
mBirkC2(rhs.mBirkC2),
74+
mHits(new std::vector<Hit>),
75+
mGeometry(rhs.mGeometry),
76+
mCurrentTrackID(-1),
77+
mCurrentCellID(-1),
78+
mCurrentHit(nullptr),
79+
mSampleWidth(rhs.mSampleWidth),
80+
mSmodPar0(rhs.mSmodPar0),
81+
mSmodPar1(rhs.mSmodPar1),
82+
mSmodPar2(rhs.mSmodPar2),
83+
mInnerEdge(rhs.mInnerEdge)
84+
85+
{
86+
for ( int i=0; i<5; ++i) {
87+
mParEMOD[i] = rhs.mParEMOD[i];
88+
}
89+
}
90+
91+
FairModule* Detector::CloneModule() const
92+
{
93+
return new Detector(*this);
94+
}
95+
96+
void Detector::Initialize()
97+
{
98+
// Define sensitive volume
99+
TGeoVolume* vsense = gGeoManager->GetVolume("SCMX");
100+
if (vsense)
101+
AddSensitiveVolume(vsense);
102+
else
103+
LOG(ERROR) << "EMCAL Sensitive volume SCMX not found ... No hit creation!\n";
104+
105+
o2::Base::Detector::Initialize();
106+
}
70107

71108
void Detector::EndOfEvent() { Reset(); }
72109

@@ -92,13 +129,6 @@ void Detector::ConstructGeometry()
92129
CreateShiskebabGeometry();
93130

94131
gGeoManager->CheckGeometry();
95-
96-
// Define sensitive volume
97-
TGeoVolume* vsense = gGeoManager->GetVolume("SCMX");
98-
if (vsense)
99-
AddSensitiveVolume(vsense);
100-
else
101-
LOG(ERROR) << "EMCAL Sensitive volume SCMX not found ... No hit creation!\n";
102132
}
103133

104134
Bool_t Detector::ProcessHits(FairVolume* v)

Detectors/FIT/simulation/src/Detector.cxx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,18 @@ Detector::Detector(Bool_t Active)
4141
// TString gn(geo->GetName());
4242
}
4343

44-
void Detector::Initialize() { o2::Base::Detector::Initialize(); }
44+
void Detector::Initialize()
45+
{
46+
// FIXME: we need to register the sensitive volumes with FairRoot
47+
TGeoVolume* v = gGeoManager->GetVolume("0REG");
48+
if (v == nullptr)
49+
printf("Sensitive volume 0REG not found!!!!!!!!");
50+
else {
51+
AddSensitiveVolume(v);
52+
}
53+
54+
o2::Base::Detector::Initialize();
55+
}
4556

4657
void Detector::ConstructGeometry()
4758
{
@@ -180,14 +191,6 @@ void Detector::ConstructGeometry()
180191

181192
// MCP + 4 x wrapped radiator + 4xphotocathod + MCP + Al top in front of radiators
182193
SetOneMCP(ins);
183-
184-
// FIXME: we need to register the sensitive volumes with FairRoot
185-
TGeoVolume* v = gGeoManager->GetVolume("0REG");
186-
if (v == nullptr)
187-
printf("Sensitive volume 0REG not found!!!!!!!!");
188-
else {
189-
AddSensitiveVolume(v);
190-
}
191194
}
192195

193196
//_________________________________________

Detectors/ITSMFT/ITS/simulation/src/Detector.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "FairRun.h" // for FairRun
2929
#include "FairRuntimeDb.h" // for FairRuntimeDb
3030
#include "FairVolume.h" // for FairVolume
31+
#include "FairRootManager.h"
3132

3233
#include "TGeoManager.h" // for TGeoManager, gGeoManager
3334
#include "TGeoTube.h" // for TGeoTube
@@ -276,6 +277,9 @@ Detector &Detector::operator=(const Detector &rhs)
276277

277278
void Detector::Initialize()
278279
{
280+
// Define the list of sensitive volumes
281+
defineSensitiveVolumes();
282+
279283
for (int i = 0; i < sNumberLayers; i++) {
280284
mLayerID[i] = gMC ? TVirtualMC::GetMC()->VolId(mLayerName[i]) : 0;
281285
}
@@ -589,7 +593,6 @@ void Detector::Register()
589593
// parameter to kFALSE means that this collection will not be written to the file,
590594
// it will exist only during the simulation
591595

592-
// FIXME: fix MT interface
593596
if (FairRootManager::Instance()) {
594597
FairRootManager::Instance()->RegisterAny(addNameTo("Hit").data(), mHits, kTRUE);
595598
}
@@ -770,9 +773,6 @@ void Detector::ConstructGeometry()
770773

771774
// Construct the detector geometry
772775
constructDetectorGeometry();
773-
774-
// Define the list of sensitive volumes
775-
defineSensitiveVolumes();
776776
}
777777

778778
void Detector::constructDetectorGeometry()

Detectors/ITSMFT/MFT/simulation/src/Detector.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "FairLogger.h"
3333
#include "FairRootManager.h"
3434
#include "FairVolume.h"
35+
#include "FairRootManager.h"
3536

3637
using o2::ITSMFT::Hit;
3738
using namespace o2::MFT;
@@ -101,7 +102,6 @@ void Detector::Initialize()
101102
defineSensitiveVolumes();
102103

103104
FairDetector::Initialize();
104-
105105
}
106106

107107
//_____________________________________________________________________________

Detectors/Passive/include/DetectorsPassive/FrameStructure.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class FrameStructure : public FairModule
3737
/** destructor */
3838
~FrameStructure() override = default;
3939

40+
/** Clone this object (used in MT mode only) */
41+
FairModule* CloneModule() const override;
42+
4043
/** Create the module geometry */
4144
void ConstructGeometry() override;
4245

@@ -45,6 +48,9 @@ class FrameStructure : public FairModule
4548
// set if to be constructed with/without holes
4649
void setHoles(bool flag) { mWithHoles = true; }
4750
private:
51+
/** copy constructor (used in MT mode only) */
52+
FrameStructure(const FrameStructure& rhs);
53+
4854
void makeHeatScreen(const char* name, float dyP, int rot1, int rot2);
4955
void createWebFrame(const char* name, float dHz, float theta0, float phi0);
5056
void createMaterials();

Detectors/Passive/src/FrameStructure.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ const char* TOPNAME = "cave";
4141

4242
FrameStructure::FrameStructure(const char* name, const char* Title) : FairModule(name, Title) {}
4343

44+
FrameStructure::FrameStructure(const FrameStructure& rhs) : FairModule(rhs)
45+
{}
46+
47+
FairModule* FrameStructure::CloneModule() const
48+
{
49+
std::cout << "cloning FrameStructure - now the right one !" << std::endl;
50+
return new FrameStructure(*this);
51+
}
52+
4453
void FrameStructure::makeHeatScreen(const char* name, float dyP, int rot1, int rot2)
4554
{
4655
// Heat screen panel

Detectors/TOF/simulation/include/TOFSimulation/Detector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Detector : public o2::Base::DetImpl<Detector>
5353

5454
~Detector() override = default;
5555

56+
FairModule* CloneModule() const override;
57+
5658
void Initialize() final;
5759

5860
Bool_t ProcessHits(FairVolume* v = nullptr) final;
@@ -80,6 +82,9 @@ class Detector : public o2::Base::DetImpl<Detector>
8082
virtual void MaterialMixer(Float_t* p, const Float_t* const a, const Float_t* const m, Int_t n) const final;
8183

8284
private:
85+
/// copy constructor (used in MT)
86+
Detector(const Detector& rhs);
87+
8388
void createModules(Float_t xtof, Float_t ytof, Float_t zlenA, Float_t xFLT, Float_t yFLT, Float_t zFLTA) const;
8489
void makeStripsInModules(Float_t ytof, Float_t zlenA) const;
8590
void createModuleCovers(Float_t xtof, Float_t zlenA) const;

Detectors/TOF/simulation/src/Detector.cxx

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
// or submit itself to any jurisdiction.
1010

1111
#include "TGeoManager.h" // for TGeoManager
12-
#include "TLorentzVector.h"
1312
#include "TMath.h"
1413
#include "TString.h"
1514

1615
#include "FairLogger.h"
17-
#include "FairRootManager.h"
1816
#include "FairVolume.h"
17+
#include "FairRootManager.h"
1918

2019
#include "TOFSimulation/Detector.h"
2120

@@ -34,12 +33,40 @@ Detector::Detector(Bool_t active)
3433
mTOFSectors[i] = 1;
3534
}
3635

37-
void Detector::Initialize() { o2::Base::Detector::Initialize(); }
36+
Detector::Detector(const Detector& rhs)
37+
: o2::Base::DetImpl<Detector>(rhs),
38+
mEventNr(0),
39+
mTOFHoles(rhs.mTOFHoles),
40+
mHits(new std::vector<HitType>)
41+
{
42+
for (Int_t i = 0; i < Geo::NSECTORS; i++)
43+
mTOFSectors[i] = rhs.mTOFSectors[i];
44+
}
45+
46+
FairModule* Detector::CloneModule() const
47+
{
48+
return new Detector(*this);
49+
}
50+
51+
void Detector::Initialize()
52+
{
53+
TGeoVolume* v = gGeoManager->GetVolume("FPAD");
54+
if (v == nullptr)
55+
printf("Sensitive volume FSEN not found!!!!!!!!");
56+
else {
57+
AddSensitiveVolume(v);
58+
}
59+
60+
o2::Base::Detector::Initialize();
61+
}
62+
3863
Bool_t Detector::ProcessHits(FairVolume* v)
3964
{
40-
static auto* refMC = TVirtualMC::GetMC();
65+
static thread_local auto* refMC = TVirtualMC::GetMC();
66+
67+
static thread_local TLorentzVector position2;
68+
refMC->TrackPosition(position2);
4169

42-
static TLorentzVector position2;
4370
refMC->TrackPosition(position2);
4471
Float_t radius = TMath::Sqrt(position2.X() * position2.X() + position2.Y() * position2.Y());
4572
LOG(DEBUG) << "Process hit in TOF volume ar R=" << radius << " - Z=" << position2.Z() << FairLogger::endl;
@@ -56,7 +83,7 @@ Bool_t Detector::ProcessHits(FairVolume* v)
5683
return kFALSE; // wo se need a threshold?
5784

5885
// ADD HIT
59-
static TLorentzVector position;
86+
static thread_local TLorentzVector position;
6087
refMC->TrackPosition(position);
6188
float time = refMC->TrackTime() * 1.0e09;
6289
auto stack = static_cast<o2::Data::Stack*>(refMC->GetStack());
@@ -84,8 +111,7 @@ Bool_t Detector::ProcessHits(FairVolume* v)
84111

85112
void Detector::Register()
86113
{
87-
auto* mgr = FairRootManager::Instance();
88-
mgr->RegisterAny(addNameTo("Hit").data(), mHits, kTRUE);
114+
FairRootManager::Instance()->RegisterAny(addNameTo("Hit").data(), mHits, kTRUE);
89115
}
90116

91117
void Detector::Reset()
@@ -281,13 +307,6 @@ void Detector::ConstructGeometry()
281307
DefineGeometry(xTof, yTof, zTof);
282308

283309
LOG(INFO) << "Loaded TOF geometry" << FairLogger::endl;
284-
285-
TGeoVolume* v = gGeoManager->GetVolume("FPAD");
286-
if (v == nullptr)
287-
printf("Sensitive volume FSEN not found!!!!!!!!");
288-
else {
289-
AddSensitiveVolume(v);
290-
}
291310
}
292311

293312
void Detector::EndOfEvent() { Reset(); }

0 commit comments

Comments
 (0)