Skip to content

Commit 17b1c99

Browse files
committed
TVirtualMCSensitiveDetector: Cleanup of functions
Removed FairDetector::DefineSensitiveVolumes() function, the functionality moved to FairMCApplication private special copy constructor. Removed detector initialization from FairMCApplication::RegisterOutput(), the detectors are initialized in the VMC. Added few overrides for ProcessHits.
1 parent 9b9d611 commit 17b1c99

File tree

8 files changed

+22
-40
lines changed

8 files changed

+22
-40
lines changed

base/sim/FairDetector.cxx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -45,7 +45,10 @@ FairDetector::FairDetector(const FairDetector& rhs)
4545
, fLogger(rhs.fLogger)
4646
{}
4747

48-
FairDetector::~FairDetector() { delete flGeoPar; }
48+
FairDetector::~FairDetector()
49+
{
50+
delete flGeoPar;
51+
}
4952

5053
FairDetector& FairDetector::operator=(const FairDetector& rhs)
5154
{
@@ -70,34 +73,12 @@ FairDetector::FairDetector()
7073

7174
// -------------------------------------------------------------------------
7275

73-
void FairDetector::DefineSensitiveVolumes()
74-
{
75-
LOG(info) << "FairDetector::DefineSensitiveVolumes";
76-
TObjArray* volumes = gGeoManager->GetListOfVolumes();
77-
TIter next(volumes);
78-
TGeoVolume* volume;
79-
while ((volume = static_cast<TGeoVolume*>(next()))) {
80-
if (IsSensitive(volume->GetName())) {
81-
LOG(debug) << "Sensitive Volume " << volume->GetName();
82-
AddSensitiveVolume(volume);
83-
}
84-
}
85-
}
86-
87-
// -------------------------------------------------------------------------
88-
8976
void FairDetector::Initialize()
9077
{
9178
// Registers hits collection in Root manager;
9279
// sets sensitive volumes.
9380
// ---
9481

95-
// Define sensitive volumes if in MT
96-
if (gMC->IsMT()) {
97-
std::cout << "Define sensitive volume " << std::endl;
98-
DefineSensitiveVolumes();
99-
}
100-
10182
Int_t NoOfEntries = svList->GetEntries();
10283
Int_t fMCid;
10384
FairGeoNode* fN;

base/sim/FairDetector.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -109,8 +109,6 @@ class FairDetector : public FairModule
109109
/** Assignment operator */
110110
FairDetector& operator=(const FairDetector&);
111111

112-
void DefineSensitiveVolumes();
113-
114112
Int_t fDetId; // Detector Id has to be set from ctr.
115113
FairLogger* fLogger; //! /// FairLogger
116114

base/sim/FairMCApplication.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ FairMCApplication::FairMCApplication(const FairMCApplication& rhs, std::unique_p
196196
auto& clone = fOwnedModules.emplace_back(module->CloneModule());
197197
fListModules.emplace_back(clone.get());
198198
fModules->Add(clone.get());
199+
for (auto sens : rhs.fMapSensitiveDetectors) {
200+
if (sens.second == module) {
201+
fMapSensitiveDetectors[sens.first] = clone.get();
202+
}
203+
}
199204
}
200205

201206
// Create and fill a list of active detectors
@@ -545,7 +550,6 @@ void FairMCApplication::Stepping()
545550
if (fRadLenMan || fRadMapMan) {
546551
Int_t copyNo;
547552
Int_t id = fMC->CurrentVolID(copyNo);
548-
id = fMC->CurrentVolID(copyNo);
549553
auto modvoliter = (fParent ? fParent : this)->fModVolMap.find(id);
550554
if (fRadLenMan) {
551555
fRadLenMan->AddPoint(fMC, modvoliter->second);
@@ -932,7 +936,6 @@ void FairMCApplication::RegisterOutput()
932936
if (detector) {
933937
// check whether detector is active
934938
if (detector->IsActive()) {
935-
detector->Initialize();
936939
detector->Register();
937940
}
938941
}
@@ -1295,8 +1298,7 @@ void FairMCApplication::ConstructSensitiveDetectors()
12951298
std::string volName = x.first; //.substr(0, x.first.find("#", 0));
12961299
if (volName.find('#') != std::string::npos) {
12971300
volName = volName.substr(0, volName.find("#", 0));
1298-
std::map<std::string, FairModule*>::iterator it;
1299-
it = cloneVolumeMap.find(volName);
1301+
auto it = cloneVolumeMap.find(volName);
13001302
LOG(debug) << "FairMCApplication::ConstructSensitiveDetectors got clone " << x.first << " " << x.second;
13011303
if (it != cloneVolumeMap.end())
13021304
continue;

base/sim/FairMCApplication.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,6 @@ class FairMCApplication : public TVirtualMCApplication
336336
/** Current state */
337337
FairMCApplicationState fState; //!
338338

339-
/** List of sensitive detectors.
340-
* To be used with TVirtualMCSensitiveDetector. */
341-
std::map<std::string, FairModule*> fMapSensitiveDetectors;
342-
343339
ClassDefOverride(FairMCApplication, 5);
344340

345341
private:
@@ -354,6 +350,12 @@ class FairMCApplication : public TVirtualMCApplication
354350
*/
355351
std::vector<FairModule*> fListModules{}; //!
356352

353+
/**
354+
* List of sensitive detectors.
355+
* To be used with TVirtualMCSensitiveDetector.
356+
*/
357+
std::map<std::string, FairModule*> fMapSensitiveDetectors;
358+
357359
/**
358360
* Owned Modules (inside the worker)
359361
*/

base/sim/FairModule.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
#include "FairLogger.h"
1616
#include "FairRun.h" // for FairRun
1717
#include "FairRuntimeDb.h" // for FairRuntimeDb
18-
#include "TVirtualMCSensitiveDetector.h"
1918

2019
#include <Rtypes.h> // for Bool_t, Int_t, etc
2120
#include <TList.h> // for TList (ptr only), TListIter
2221
#include <TNamed.h> // for TNamed
2322
#include <TObjArray.h> // for TObjArray
2423
#include <TString.h> // for TString, operator!=
24+
#include <TVirtualMCSensitiveDetector.h>
25+
2526
#include <string> // for string
2627

2728
class FairVolumeList;

examples/MQ/pixelDetector/src/Pixel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Pixel : public FairDetector
3636
/** this method is called for each step during simulation
3737
* (see FairMCApplication::Stepping())
3838
*/
39-
virtual void ProcessHits();
39+
void ProcessHits() override;
4040

4141
/** Registers the produced collections in FAIRRootManager. */
4242
void Register() override;

examples/advanced/Tutorial3/simulation/FairTestDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FairTestDetector : public FairDetector
3939
/** this method is called for each step during simulation
4040
* (see FairMCApplication::Stepping())
4141
*/
42-
virtual void ProcessHits();
42+
void ProcessHits() override;
4343

4444
/** Registers the produced collections in FAIRRootManager. */
4545
void Register() override;

examples/advanced/propagator/src/FairTutPropDet.cxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ void FairTutPropDet::ProcessHits()
110110
FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
111111
stack->AddPoint(kTutProp);
112112
}
113-
114-
return;
115113
}
116114

117115
void FairTutPropDet::EndOfEvent() { fFairTutPropPointCollection->Clear(); }

0 commit comments

Comments
 (0)