Skip to content

Commit bd19c48

Browse files
committed
Add support for TVirtualMCSensitiveDetector.
1 parent d899d32 commit bd19c48

File tree

23 files changed

+143
-136
lines changed

23 files changed

+143
-136
lines changed

base/sim/FairDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FairDetector : public FairModule
4747
/**
4848
this method is called for each step during simulation (see FairMCApplication::Stepping())
4949
*/
50-
virtual Bool_t ProcessHits(FairVolume* v = 0) = 0;
50+
virtual void ProcessHits()=0;
5151
/**
5252
this is called at the end of an event after the call to tree fill in the FairRootManager
5353
*/

base/sim/FairMCApplication.cxx

Lines changed: 47 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -651,75 +651,39 @@ void FairMCApplication::FinishRunOnWorker()
651651
//_____________________________________________________________________________
652652
void FairMCApplication::Stepping()
653653
{
654-
// User actions at each step
655-
// ---
656-
657-
// Work around for Fluka VMC, which does not call
658-
// MCApplication::PreTrack()
659-
static Int_t TrackId = 0;
660-
if (fMcVersion == 2 || fMC->GetStack()->GetCurrentTrackNumber() != TrackId) {
661-
PreTrack();
662-
TrackId = fMC->GetStack()->GetCurrentTrackNumber();
663-
}
664-
665-
// Check if the volume with id is in the volume multimap.
666-
// If it is not in the map the volume is not a sensitive volume
667-
// and we do not call nay of our ProcessHits functions.
668-
669-
// If the volume is in the multimap, check in second step if the current
670-
// copy is alredy inside the multimap.
671-
// If the volume is not in the multimap add the copy of the volume to the
672-
// multimap.
673-
// In any case call the ProcessHits function for this specific detector.
674-
Int_t copyNo;
675-
Int_t id = fMC->CurrentVolID(copyNo);
676-
Bool_t InMap = kFALSE;
677-
fDisVol = 0;
678-
fDisDet = 0;
679-
Int_t fCopyNo = 0;
680-
fVolIter = fVolMap.find(id);
681-
682-
if (fVolIter != fVolMap.end()) {
683-
684-
// Call Process hits for FairVolume with this id, copyNo
685-
do {
686-
fDisVol = fVolIter->second;
687-
fCopyNo = fDisVol->getCopyNo();
688-
if (copyNo == fCopyNo) {
689-
fDisDet = fDisVol->GetDetector();
690-
if (fDisDet) {
691-
fDisDet->ProcessHits(fDisVol);
692-
}
693-
InMap = kTRUE;
694-
break;
695-
}
696-
++fVolIter;
697-
} while (fVolIter != fVolMap.upper_bound(id));
698-
699-
// if (fDisVol && !InMap) { // fDisVolume is set previously, no check needed
700-
701-
// Create new FairVolume with this id, copyNo.
702-
// Use the FairVolume with the same id found in the map to get
703-
// the link to the detector.
704-
// Seems that this never happens (?)
705-
if (!InMap) {
706-
// cout << "Volume not in map; fDisVol ? " << fDisVol << endl
707-
FairVolume* fNewV = new FairVolume(fMC->CurrentVolName(), id);
708-
fNewV->setMCid(id);
709-
fNewV->setModId(fDisVol->getModId());
710-
fNewV->SetModule(fDisVol->GetModule());
711-
fNewV->setCopyNo(copyNo);
712-
fVolMap.insert(pair<Int_t, FairVolume*>(id, fNewV));
713-
fDisDet = fDisVol->GetDetector();
714-
715-
// LOG(info) << "FairMCApplication::Stepping: new fair volume"
716-
// << id << " " << copyNo << " " << fDisDet;
717-
if (fDisDet) {
718-
fDisDet->ProcessHits(fNewV);
719-
}
654+
Int_t copyNo = 0;
655+
Int_t id = 0;
656+
657+
// If information about the tracks should be stored the information as to be
658+
// stored for any step.
659+
// Information about each single step has also to be stored for the other
660+
// special run modes of the simulation which are used to store information
661+
// about
662+
// 1.) Radiation length in each volume
663+
// 2.) Energy deposition in each volume
664+
// 3.) Fluence of particles through a defined plane which can be anywhere
665+
// in the geometry. This plane has not to be correlated with any real
666+
// volume
667+
if(fTrajAccepted) {
668+
if(fMC->TrackStep() > fTrajFilter->GetStepSizeCut()) {
669+
fMC->TrackPosition(fTrkPos);
670+
fTrajFilter->GetCurrentTrk()->AddPoint(fTrkPos.X(), fTrkPos.Y(), fTrkPos.Z(), fTrkPos.T());
720671
}
721672
}
722-
673+
if(fRadLenMan) {
674+
id = fMC->CurrentVolID(copyNo);
675+
fModVolIter = fgMasterInstance->fModVolMap.find(id);
676+
fRadLenMan->AddPoint(fModVolIter->second);
677+
}
678+
if(fRadMapMan) {
679+
id = fMC->CurrentVolID(copyNo);
680+
fModVolIter = fgMasterInstance->fModVolMap.find(id);
681+
fRadMapMan->AddPoint(fModVolIter->second);
682+
}
683+
if(fRadGridMan) {
684+
fRadGridMan->FillMeshList();
685+
}
686+
723687
// If information about the tracks should be stored the information as to be
724688
// stored for any step.
725689
// Information about each single step has also to be stored for the other
@@ -827,11 +791,6 @@ void FairMCApplication::FinishEvent()
827791
} else {
828792
fSaveCurrentEvent = kTRUE;
829793
}
830-
831-
for (auto detectorPtr : listActiveDetectors) {
832-
detectorPtr->EndOfEvent();
833-
}
834-
835794
fStack->Reset();
836795
if (nullptr != fTrajFilter) {
837796
fTrajFilter->Reset();
@@ -1480,4 +1439,19 @@ void FairMCApplication::UndoGeometryModifications()
14801439
gGeoManager->ClearPhysicalNodes(kFALSE);
14811440
}
14821441

1483-
ClassImp(FairMCApplication);
1442+
void FairMCApplication::ConstructSensitiveDetectors()
1443+
{
1444+
for(auto const& x : fMapSensitiveDetectors)
1445+
{
1446+
LOG(debug) << "FairMCApplication::ConstructSensitiveDetectors "
1447+
<< x.first << " " << x.second;
1448+
TVirtualMC::GetMC()->SetSensitiveDetector(x.first, x.second);
1449+
}
1450+
}
1451+
1452+
void FairMCApplication::AddSensitiveModule(std::string volName, FairModule* module)
1453+
{
1454+
fMapSensitiveDetectors[volName] = module;
1455+
}
1456+
1457+
ClassImp(FairMCApplication)

base/sim/FairMCApplication.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class FairRootManager;
3535
class FairTask;
3636
class FairTrajFilter;
3737
class FairVolume;
38+
class FairModule;
3839
class FairRunSim;
3940
class TChain;
4041
class TIterator;
@@ -96,6 +97,9 @@ class FairMCApplication : public TVirtualMCApplication
9697
virtual Bool_t MisalignGeometry();
9798
/** Define parameters for optical processes (optional) */
9899
virtual void ConstructOpGeometry(); // MC Application
100+
101+
virtual void ConstructSensitiveDetectors();
102+
99103
/** Define actions at the end of event */
100104
virtual void FinishEvent(); // MC Application
101105
/** Define actions at the end of primary track */
@@ -208,6 +212,11 @@ class FairMCApplication : public TVirtualMCApplication
208212
* Get the current application state.
209213
*/
210214
FairMCApplicationState GetState() const { return fState; }
215+
216+
/**
217+
* Add module to the list of sensitive detectors.
218+
*/
219+
void AddSensitiveModule(std::string volName, FairModule* module);
211220

212221
private:
213222
// methods
@@ -301,6 +310,10 @@ class FairMCApplication : public TVirtualMCApplication
301310

302311
/** Current state */
303312
FairMCApplicationState fState; //!
313+
314+
/** List of sensitive detectors.
315+
* To be used with TVirtualMCSensitiveDetector. */
316+
std::map<std::string, FairModule*> fMapSensitiveDetectors;
304317

305318
ClassDef(FairMCApplication, 4);
306319

base/sim/FairModule.cxx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void FairModule::ConstructOpGeometry()
7272
FairModule::~FairModule() {}
7373

7474
FairModule::FairModule(const char* Name, const char* title, Bool_t Active)
75-
: TNamed(Name, title)
75+
: TVirtualMCSensitiveDetector(Name, title)
7676
, fMotherVolumeName("")
7777
, fgeoVer("Not defined")
7878
, fgeoName("Not defined")
@@ -93,7 +93,7 @@ FairModule::FairModule(const char* Name, const char* title, Bool_t Active)
9393
}
9494

9595
FairModule::FairModule(const FairModule& rhs)
96-
: TNamed(rhs)
96+
: TVirtualMCSensitiveDetector(rhs)
9797
, fMotherVolumeName(rhs.fMotherVolumeName)
9898
, fgeoVer(rhs.fgeoVer)
9999
, fgeoName(rhs.fgeoName)
@@ -133,7 +133,7 @@ FairModule::FairModule(const FairModule& rhs)
133133
}
134134

135135
FairModule::FairModule()
136-
: TNamed()
136+
: TVirtualMCSensitiveDetector()
137137
, fMotherVolumeName("")
138138
, fgeoVer("Not defined")
139139
, fgeoName("Not defined")
@@ -153,7 +153,7 @@ FairModule& FairModule::operator=(const FairModule& rhs)
153153
return *this;
154154

155155
// base class assignment
156-
TNamed::operator=(rhs);
156+
TVirtualMCSensitiveDetector::operator=(rhs);
157157

158158
// assignment operator
159159
fMotherVolumeName = rhs.fMotherVolumeName;
@@ -181,7 +181,7 @@ FairModule& FairModule::operator=(const FairModule& rhs)
181181

182182
void FairModule::Streamer(TBuffer& b)
183183
{
184-
TNamed::Streamer(b);
184+
TVirtualMCSensitiveDetector::Streamer(b);
185185

186186
if (b.IsReading()) {
187187
fgeoVer.Streamer(b);
@@ -281,6 +281,9 @@ void FairModule::ProcessNodes(TList* aList)
281281
FairGeoVolume* aVol = nullptr;
282282

283283
if (node->isSensitive() && fActive) {
284+
285+
FairMCApplication::Instance()->AddSensitiveModule(volume->GetName(), this);
286+
284287
volume->setModId(fModId);
285288
volume->SetModule(this);
286289
svList->Add(volume);
@@ -293,9 +296,10 @@ void FairModule::ProcessNodes(TList* aList)
293296

294297
void FairModule::AddSensitiveVolume(TGeoVolume* v)
295298
{
296-
297299
LOG(debug2) << "AddSensitiveVolume " << v->GetName();
298300

301+
FairMCApplication::Instance()->AddSensitiveModule(v->GetName(), this);
302+
299303
// Only register volumes which are not already registered
300304
// Otherwise the stepping will be slowed down
301305
if (!vList->findObject(v->GetName())) {

base/sim/FairModule.h

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

1920
#include <Rtypes.h> // for Bool_t, Int_t, etc
2021
#include <TList.h> // for TList (ptr only), TListIter
@@ -43,7 +44,7 @@ class TVirtualMC;
4344
* Changelog: 29.02.2012 [O.Merle] Fixed missing material assignment for top volume.
4445
* ... and please - add some documentation to your code.
4546
*/
46-
class FairModule : public TNamed
47+
class FairModule : public TVirtualMCSensitiveDetector
4748
{
4849
public:
4950
/**default ctor*/
@@ -141,6 +142,17 @@ class FairModule : public TNamed
141142
FairVolume* getFairVolume(FairGeoNode* fNode);
142143
void AddSensitiveVolume(TGeoVolume* v);
143144

145+
static thread_local TArrayI* volNumber; //!
146+
TString fMotherVolumeName; //!
147+
FairVolume* getFairVolume(FairGeoNode* fNode);
148+
void AddSensitiveVolume(TGeoVolume* v);
149+
150+
virtual void EndOfEvent() {}
151+
152+
virtual void Initialize() {}
153+
154+
virtual void ProcessHits() {}
155+
144156
private:
145157
/** Re-implimented from ROOT: TGeoMatrix::SetDefaultName() */
146158
void SetDefaultMatrixName(TGeoMatrix* matrix);

base/sim/fastsim/FairFastSimDetector.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ void FairFastSimDetector::ConstructGeometry()
5959
}
6060
}
6161

62-
Bool_t FairFastSimDetector::ProcessHits(FairVolume*)
62+
void FairFastSimDetector::ProcessHits()
6363
{
6464
FastSimProcessParticle();
65-
66-
return kTRUE;
6765
}
6866

6967
ClassImp(FairFastSimDetector);

base/sim/fastsim/FairFastSimDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FairFastSimDetector : public FairDetector
2727

2828
virtual void Initialize() = 0;
2929

30-
virtual Bool_t ProcessHits(FairVolume* vol = 0) final;
30+
virtual void ProcessHits() final;
3131

3232
virtual void EndOfEvent() {}
3333

examples/MQ/pixelDetector/src/Pixel.cxx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ Pixel::~Pixel()
7575

7676
void Pixel::Initialize() { FairDetector::Initialize(); }
7777

78-
Bool_t Pixel::ProcessHits(FairVolume* vol)
78+
void Pixel::ProcessHits()
7979
{
80+
8081
/** This method is called from the MC stepping */
8182
// Set parameters at entrance of volume. Reset ELoss.
8283
if (TVirtualMC::GetMC()->IsTrackEntering()) {
@@ -94,10 +95,11 @@ Bool_t Pixel::ProcessHits(FairVolume* vol)
9495
if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
9596
|| TVirtualMC::GetMC()->IsTrackDisappeared()) {
9697
fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
97-
fVolumeID = vol->getMCid();
98+
Int_t copyNo = 0;
99+
fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo);
98100

99101
if (fELoss == 0.) {
100-
return kFALSE;
102+
return;
101103
}
102104

103105
// Taking stationNr and sectorNr from string is almost effortless.
@@ -126,6 +128,12 @@ Bool_t Pixel::ProcessHits(FairVolume* vol)
126128
FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
127129
stack->AddPoint(kPixel);
128130
}
131+
}
132+
133+
void Pixel::EndOfEvent()
134+
{
135+
136+
fPixelPointCollection->Clear();
129137

130138
return kTRUE;
131139
}

examples/MQ/pixelDetector/src/Pixel.h

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

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

examples/advanced/Tutorial3/simulation/FairTestDetector.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void FairTestDetector::Initialize()
6767
rtdb->getContainer("FairTestDetectorGeoPar");
6868
}
6969

70-
Bool_t FairTestDetector::ProcessHits(FairVolume* vol)
70+
void FairTestDetector::ProcessHits()
7171
{
7272
/** This method is called from the MC stepping */
7373

@@ -87,11 +87,12 @@ Bool_t FairTestDetector::ProcessHits(FairVolume* vol)
8787
if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop()
8888
|| TVirtualMC::GetMC()->IsTrackDisappeared()) {
8989
fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
90-
fVolumeID = vol->getMCid();
90+
Int_t copyNo = 0;
91+
fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo);
9192
TVirtualMC::GetMC()->TrackPosition(fPosOut);
9293
TVirtualMC::GetMC()->TrackMomentum(fMomOut);
9394
if (fELoss == 0.) {
94-
return kFALSE;
95+
return;
9596
}
9697
AddHit(fTrackID,
9798
fVolumeID,
@@ -107,8 +108,6 @@ Bool_t FairTestDetector::ProcessHits(FairVolume* vol)
107108
FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
108109
stack->AddPoint(kTutDet);
109110
}
110-
111-
return kTRUE;
112111
}
113112

114113
void FairTestDetector::EndOfEvent()

0 commit comments

Comments
 (0)