5555#include < TObject.h> // for TObject
5656#include < TParticlePDG.h> // for TParticlePDG
5757#include < TROOT.h> // for TROOT, gROOT
58- #include < TRefArray.h> // for TRefArray
5958#include < TSystem.h> // for TSystem, gSystem
6059#include < TVirtualMC.h> // for TVirtualMC
6160#include < TVirtualMCStack.h> // for TVirtualMCStack
62- class TParticle ;
61+ #include < cfloat> // for DBL_MAX
62+ #include < cstdlib> // for getenv, exit
63+ #include < mutex> // std::mutex
64+ #include < utility> // for pair, move
6365
64- #include < float.h> // for DBL_MAX
65- #include < mutex> // std::mutex
66- #include < stdlib.h> // for getenv, exit
67- #include < utility> // for pair, move
68- std::mutex mtx; // mutex for critical section
66+ std::mutex mtx; // mutex for critical section
6967
7068using std::pair;
7169
7270// _____________________________________________________________________________
7371FairMCApplication::FairMCApplication (const char * name, const char * title, TObjArray* ModList, const char *)
7472 : TVirtualMCApplication(name, title)
75- , fActiveDetectors(nullptr )
7673 , fFairTaskList(nullptr )
7774 , fModules(ModList)
7875 , fPythiaDecayer(kFALSE )
@@ -81,18 +78,12 @@ FairMCApplication::FairMCApplication(const char* name, const char* title, TObjAr
8178 , fxField(nullptr )
8279 , fEvGen(nullptr )
8380 , fMcVersion(-1 )
84- , fTrajFilter(nullptr )
85- , fTrajAccepted(kFALSE )
8681 , fUserDecay(kFALSE )
8782 , fUserDecayConfig(" " )
8883 , fDebug(kFALSE )
8984 , fVolMap()
9085 , fModVolMap()
9186 , fTrkPos(TLorentzVector(0 , 0 , 0 , 0 ))
92- , fRadLength(kFALSE )
93- , fRadLenMan(nullptr )
94- , fRadMap(kFALSE )
95- , fRadMapMan(nullptr )
9687 , fEventHeader(nullptr )
9788 , fMCEventHeader(nullptr )
9889 , listActiveDetectors()
@@ -113,8 +104,6 @@ FairMCApplication::FairMCApplication(const char* name, const char* title, TObjAr
113104 LOG (debug) << " FairMCApplication-ctor " << this ;
114105
115106 fRootManager = &fRun ->GetRootManager ();
116- // Create and fill a list of active detectors
117- fActiveDetectors = new TRefArray ();
118107
119108 fListModules .reserve (fModules ->GetEntriesFast ());
120109 for (auto module : TRangeDynCast<FairModule>(fModules )) {
@@ -127,7 +116,7 @@ FairMCApplication::FairMCApplication(const char* name, const char* title, TObjAr
127116 if (detector) {
128117 listDetectors.push_back (detector);
129118 if (detector->IsActive ()) {
130- fActiveDetectors -> Add (detector);
119+ fActiveDetectors . Add (detector);
131120 listActiveDetectors.push_back (detector);
132121 }
133122 }
@@ -137,14 +126,12 @@ FairMCApplication::FairMCApplication(const char* name, const char* title, TObjAr
137126 fFairTaskList = new FairTask (" Task List" , 1 );
138127 gROOT ->GetListOfBrowsables ()->Add (fFairTaskList );
139128 fMcVersion = -1 ;
140- // Initialise fTrajFilter pointer
141- fTrajFilter = nullptr ;
142129}
143130
144131// _____________________________________________________________________________
145132FairMCApplication::FairMCApplication (const FairMCApplication& rhs, std::unique_ptr<FairRunSim> otherRunSim)
146133 : TVirtualMCApplication(rhs.GetName(), rhs.GetTitle())
147- , fActiveDetectors( nullptr )
134+ , fParent(&rhs )
148135 , fFairTaskList(nullptr )
149136 , fModules(nullptr )
150137 , fPythiaDecayer(kFALSE )
@@ -153,18 +140,12 @@ FairMCApplication::FairMCApplication(const FairMCApplication& rhs, std::unique_p
153140 , fxField(rhs.fxField)
154141 , fEvGen(nullptr )
155142 , fMcVersion(rhs.fMcVersion )
156- , fTrajFilter(nullptr )
157- , fTrajAccepted(kFALSE )
158143 , fUserDecay(kFALSE )
159144 , fUserDecayConfig(rhs.fUserDecayConfig )
160145 , fDebug(rhs.fDebug )
161146 , fVolMap()
162147 , fModVolMap()
163148 , fTrkPos(rhs.fTrkPos )
164- , fRadLength(kFALSE )
165- , fRadLenMan(nullptr )
166- , fRadMap(kFALSE )
167- , fRadMapMan(nullptr )
168149 , fEventHeader(nullptr )
169150 , fMCEventHeader(nullptr )
170151 , listActiveDetectors()
@@ -182,7 +163,6 @@ FairMCApplication::FairMCApplication(const FairMCApplication& rhs, std::unique_p
182163
183164 LOG (debug) << " FairMCApplication-copy-ctor " << this ;
184165
185- fParent = &rhs;
186166 fRun = fWorkerRunSim .get ();
187167 fRootManager = &fRun ->GetRootManager ();
188168
@@ -199,13 +179,12 @@ FairMCApplication::FairMCApplication(const FairMCApplication& rhs, std::unique_p
199179 }
200180
201181 // Create and fill a list of active detectors
202- fActiveDetectors = new TRefArray ();
203182 for (auto module : fListModules ) {
204183 auto detector = dynamic_cast <FairDetector*>(module );
205184 if (detector) {
206185 listDetectors.push_back (detector);
207186 if (detector->IsActive ()) {
208- fActiveDetectors -> Add (detector);
187+ fActiveDetectors . Add (detector);
209188 listActiveDetectors.push_back (detector);
210189 }
211190 }
@@ -226,7 +205,6 @@ FairMCApplication::FairMCApplication(const FairMCApplication& rhs, std::unique_p
226205// _____________________________________________________________________________
227206FairMCApplication::FairMCApplication ()
228207 : TVirtualMCApplication()
229- , fActiveDetectors(0 )
230208 , fFairTaskList(0 )
231209 , fModules(0 )
232210 , fPythiaDecayer(kFALSE )
@@ -235,18 +213,12 @@ FairMCApplication::FairMCApplication()
235213 , fxField(0 )
236214 , fEvGen(0 )
237215 , fMcVersion(-1 )
238- , fTrajFilter(nullptr )
239- , fTrajAccepted(kFALSE )
240216 , fUserDecay(kFALSE )
241217 , fUserDecayConfig(" " )
242218 , fDebug(kFALSE )
243219 , fVolMap()
244220 , fModVolMap()
245221 , fTrkPos(TLorentzVector(0 , 0 , 0 , 0 ))
246- , fRadLength(kFALSE )
247- , fRadLenMan(nullptr )
248- , fRadMap(kFALSE )
249- , fRadMapMan(nullptr )
250222 , fEventHeader(nullptr )
251223 , fMCEventHeader(nullptr )
252224 , listActiveDetectors()
@@ -266,7 +238,6 @@ FairMCApplication::~FairMCApplication()
266238{
267239 // Destructor
268240 // LOG(debug3) << "Enter Destructor of FairMCApplication";
269- delete fActiveDetectors ; // don't do fActiveDetectors->Delete() here
270241 // the modules are already deleted in FairRunSim
271242 // LOG(debug3) << "Leave Destructor of FairMCApplication";
272243 delete fMC ;
@@ -306,7 +277,9 @@ void FairMCApplication::InitMC(const char*, const char*)
306277 } else {
307278 fMcVersion = 3 ; // Geane
308279 }
309- fTrajFilter = FairTrajFilter::Instance ();
280+ if ((!fTrajFilter ) && fRun ->GetStoreTraj ()) {
281+ fTrajFilter = std::make_unique<FairTrajFilter>();
282+ }
310283
311284 LOG (info) << " Monte Carlo Engine Initialisation with: " << MCName.Data ();
312285}
@@ -319,7 +292,7 @@ void FairMCApplication::RunMC(Int_t nofEvents)
319292 fRunInfo .Reset ();
320293
321294 /* * Set the list of active detectors to the stack*/
322- fStack ->SetDetArrayList (fActiveDetectors );
295+ fStack ->SetDetArrayList (& fActiveDetectors );
323296
324297 // MC run.
325298 fMC ->ProcessRun (nofEvents);
@@ -436,7 +409,7 @@ void FairMCApplication::PreTrack()
436409 }
437410
438411 fTrajAccepted = kFALSE ;
439- if (nullptr != fTrajFilter ) {
412+ if (fTrajFilter ) {
440413 // Get the pointer to current track
441414 TParticle* particle = fStack ->GetCurrentTrack ();
442415 // LOG(debug) << " FairMCApplication::PreTrack(): " << particle;
@@ -466,12 +439,7 @@ TVirtualMCApplication* FairMCApplication::CloneForWorker() const
466439 workerRun->SetSink (std::unique_ptr<FairSink>{fRun ->GetSink ()->CloneSink ()});
467440 workerRun->SetMCEventHeader (new FairMCEventHeader (*(fRun ->GetMCEventHeader ())));
468441 workerRun->SetRunId (workerRun->GetMCEventHeader ()->GetRunID ());
469-
470- // Trajectories filter is created explicitly as we do not call
471- // FairRunSim::Init on workers
472- if (fRun ->GetStoreTraj ()) {
473- new FairTrajFilter ();
474- }
442+ workerRun->SetStoreTraj (fRun ->GetStoreTraj ());
475443
476444 // Create new FairMCApplication object on worker
477445 return new FairMCApplication (*this , std::move (workerRun));
@@ -669,7 +637,7 @@ void FairMCApplication::FinishEvent()
669637 // --> Fill the stack output array
670638 fStack ->FillTrackArray ();
671639 // --> Update track indizes in MCTracks and MCPoints
672- fStack ->UpdateTrackIndex (fActiveDetectors );
640+ fStack ->UpdateTrackIndex (& fActiveDetectors );
673641 // --> Screen output of stack
674642 // fStack->Print();
675643
@@ -693,16 +661,16 @@ void FairMCApplication::FinishEvent()
693661 }
694662
695663 fStack ->Reset ();
696- if (nullptr != fTrajFilter ) {
664+ if (fTrajFilter ) {
697665 fTrajFilter ->Reset ();
698666 // TObjArray* fListOfTracks=gGeoManager->GetListOfTracks();
699667 // fListOfTracks->Delete();
700668 gGeoManager ->GetListOfTracks ()->Delete ();
701669 }
702- if (nullptr != fRadLenMan ) {
670+ if (fRadLenMan ) {
703671 fRadLenMan ->Reset ();
704672 }
705- if (nullptr != fRadMapMan ) {
673+ if (fRadMapMan ) {
706674 fRadMapMan ->Reset ();
707675 }
708676
@@ -881,14 +849,16 @@ void FairMCApplication::InitGeometry()
881849
882850 LOG (info) << " Simulation RunID: " << runId;
883851
884- fTrajFilter = FairTrajFilter::Instance ();
885- if (nullptr != fTrajFilter ) {
852+ if ((!fTrajFilter ) && fRun ->GetStoreTraj ()) {
853+ fTrajFilter = std::make_unique<FairTrajFilter>();
854+ }
855+ if (fTrajFilter ) {
886856 fTrajFilter ->Init ();
887857 }
888- if (nullptr != fRadLenMan ) {
858+ if (fRadLenMan ) {
889859 fRadLenMan ->Init ();
890860 }
891- if (nullptr != fRadMapMan ) {
861+ if (fRadMapMan ) {
892862 fRadMapMan ->Init ();
893863 }
894864 if (fRadGridMan ) {
@@ -1272,7 +1242,7 @@ void FairMCApplication::SetRadiationLengthReg(Bool_t RadLen)
12721242{
12731243 fRadLength = RadLen;
12741244 if (fRadLength ) {
1275- fRadLenMan = new FairRadLenManager ();
1245+ fRadLenMan = std::make_unique< FairRadLenManager> ();
12761246 }
12771247}
12781248
@@ -1281,7 +1251,7 @@ void FairMCApplication::SetRadiationMapReg(Bool_t RadMap)
12811251{
12821252 fRadMap = RadMap;
12831253 if (fRadMap ) {
1284- fRadMapMan = new FairRadMapManager ();
1254+ fRadMapMan = std::make_unique< FairRadMapManager> ();
12851255 }
12861256}
12871257
0 commit comments