Skip to content

Commit 3cd6899

Browse files
committed
Add support for TVirtualMCSensitiveDetector.
1 parent 25bd3f5 commit 3cd6899

File tree

23 files changed

+102
-146
lines changed

23 files changed

+102
-146
lines changed

base/sim/FairDetector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FairDetector : public FairModule
4949
/**
5050
this method is called for each step during simulation (see FairMCApplication::Stepping())
5151
*/
52-
virtual Bool_t ProcessHits( FairVolume* v=0)=0;
52+
virtual void ProcessHits()=0;
5353
/**
5454
this is called at the end of an event
5555
*/

base/sim/FairMCApplication.cxx

Lines changed: 20 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -661,76 +661,9 @@ void FairMCApplication::FinishRunOnWorker()
661661
//_____________________________________________________________________________
662662
void FairMCApplication::Stepping()
663663
{
664-
// User actions at each step
665-
// ---
666-
667-
// Work around for Fluka VMC, which does not call
668-
// MCApplication::PreTrack()
669-
static Int_t TrackId = 0;
670-
if ( fMcVersion ==2 && fMC->GetStack()->GetCurrentTrackNumber() != TrackId ) {
671-
PreTrack();
672-
TrackId = fMC->GetStack()->GetCurrentTrackNumber();
673-
}
674-
675-
// Check if the volume with id is in the volume multimap.
676-
// If it is not in the map the volume is not a sensitive volume
677-
// and we do not call nay of our ProcessHits functions.
678-
679-
// If the volume is in the multimap, check in second step if the current
680-
// copy is alredy inside the multimap.
681-
// If the volume is not in the multimap add the copy of the volume to the
682-
// multimap.
683-
// In any case call the ProcessHits function for this specific detector.
684-
Int_t copyNo;
685-
Int_t id = fMC->CurrentVolID(copyNo);
686-
Bool_t InMap =kFALSE;
687-
fDisVol=0;
688-
fDisDet=0;
689-
Int_t fCopyNo=0;
690-
fVolIter =fVolMap.find(id);
691-
692-
if (fVolIter!=fVolMap.end()) {
693-
694-
// Call Process hits for FairVolume with this id, copyNo
695-
do {
696-
fDisVol=fVolIter->second;
697-
fCopyNo=fDisVol->getCopyNo();
698-
if(copyNo==fCopyNo) {
699-
fDisDet=fDisVol->GetDetector();
700-
if (fDisDet) {
701-
fDisDet->ProcessHits(fDisVol);
702-
}
703-
InMap=kTRUE;
704-
break;
705-
}
706-
fVolIter++;
707-
}
708-
while(fVolIter!=fVolMap.upper_bound(id));
709-
710-
// if(fDisVol && !InMap) { // fDisVolume is set previously, no check needed
711-
712-
// Create new FairVolume with this id, copyNo.
713-
// Use the FairVolume with the same id found in the map to get
714-
// the link to the detector.
715-
// Seems that this never happens (?)
716-
if(!InMap) {
717-
// cout << "Volume not in map; fDisVol ? " << fDisVol << endl
718-
FairVolume* fNewV=new FairVolume( fMC->CurrentVolName(), id);
719-
fNewV->setMCid(id);
720-
fNewV->setModId(fDisVol->getModId());
721-
fNewV->SetModule(fDisVol->GetModule());
722-
fNewV->setCopyNo(copyNo);
723-
fVolMap.insert(pair<Int_t, FairVolume* >(id, fNewV));
724-
fDisDet=fDisVol->GetDetector();
725-
726-
// LOG(info) << "FairMCApplication::Stepping: new fair volume"
727-
// << id << " " << copyNo << " " << fDisDet;
728-
if ( fDisDet) {
729-
fDisDet->ProcessHits(fNewV);
730-
}
731-
}
732-
}
733-
664+
Int_t copyNo = 0;
665+
Int_t id = 0;
666+
734667
// If information about the tracks should be stored the information as to be
735668
// stored for any step.
736669
// Information about each single step has also to be stored for the other
@@ -838,11 +771,6 @@ void FairMCApplication::FinishEvent()
838771
fSaveCurrentEvent = kTRUE;
839772
}
840773

841-
for (auto detectorPtr : listActiveDetectors)
842-
{
843-
detectorPtr->EndOfEvent();
844-
}
845-
846774
fStack->Reset();
847775
if(NULL != fTrajFilter) {
848776
fTrajFilter->Reset();
@@ -1504,4 +1432,21 @@ void FairMCApplication::UndoGeometryModifications()
15041432

15051433
}
15061434

1435+
void FairMCApplication::ConstructSensitiveDetectors()
1436+
{
1437+
LOG(info) << "############ ?????????? Construct sensitive detectors";
1438+
1439+
for(auto const& x : fMapSensitiveDetectors)
1440+
{
1441+
LOG(debug) << "FairMCApplication::ConstructSensitiveDetectors "
1442+
<< x.first << " " << x.second;
1443+
TVirtualMC::GetMC()->SetSensitiveDetector(x.first, x.second);
1444+
}
1445+
}
1446+
1447+
void FairMCApplication::AddSensitiveModule(std::string volName, FairModule* module)
1448+
{
1449+
fMapSensitiveDetectors[volName] = module;
1450+
}
1451+
15071452
ClassImp(FairMCApplication)

base/sim/FairMCApplication.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class FairRootManager;
3737
class FairTask;
3838
class FairTrajFilter;
3939
class FairVolume;
40+
class FairModule;
4041
class FairRunSim;
4142
class TChain;
4243
class TIterator;
@@ -93,6 +94,9 @@ class FairMCApplication : public TVirtualMCApplication
9394
virtual Bool_t MisalignGeometry();
9495
/** Define parameters for optical processes (optional) */
9596
virtual void ConstructOpGeometry(); // MC Application
97+
98+
virtual void ConstructSensitiveDetectors();
99+
96100
/** Define actions at the end of event */
97101
virtual void FinishEvent(); // MC Application
98102
/** Define actions at the end of primary track */
@@ -203,6 +207,11 @@ class FairMCApplication : public TVirtualMCApplication
203207
* Get the current application state.
204208
*/
205209
FairMCApplicationState GetState() const { return fState; }
210+
211+
/**
212+
* Add module to the list of sensitive detectors.
213+
*/
214+
void AddSensitiveModule(std::string volName, FairModule* module);
206215

207216
private:
208217
// methods
@@ -296,6 +305,10 @@ class FairMCApplication : public TVirtualMCApplication
296305

297306
/** Current state */
298307
FairMCApplicationState fState; //!
308+
309+
/** List of sensitive detectors.
310+
* To be used with TVirtualMCSensitiveDetector. */
311+
std::map<std::string, FairModule*> fMapSensitiveDetectors;
299312

300313
ClassDef(FairMCApplication,4) //Interface to MonteCarlo application
301314

base/sim/FairModule.cxx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ FairModule::~FairModule()
7777
}
7878
//__________________________________________________________________________
7979
FairModule::FairModule(const char* Name, const char* title ,Bool_t Active)
80-
:TNamed(Name, title),
80+
:TVirtualMCSensitiveDetector(Name, title),
8181
fMotherVolumeName(""),
8282
fgeoVer("Not defined"),
8383
fgeoName("Not defined"),
@@ -96,7 +96,7 @@ FairModule::FairModule(const char* Name, const char* title ,Bool_t Active)
9696

9797
//__________________________________________________________________________
9898
FairModule::FairModule(const FairModule& rhs)
99-
:TNamed(rhs),
99+
:TVirtualMCSensitiveDetector(rhs),
100100
fMotherVolumeName(rhs.fMotherVolumeName),
101101
fgeoVer(rhs.fgeoVer),
102102
fgeoName(rhs.fgeoName),
@@ -139,8 +139,7 @@ FairModule::FairModule(const FairModule& rhs)
139139
//__________________________________________________________________________
140140

141141
FairModule::FairModule()
142-
: TNamed(),
143-
fMotherVolumeName(""),
142+
: fMotherVolumeName(""),
144143
fgeoVer("Not defined"),
145144
fgeoName("Not defined"),
146145
fModId(-1),
@@ -160,7 +159,7 @@ FairModule& FairModule::operator= (const FairModule& rhs)
160159
if (this == &rhs) return *this;
161160

162161
// base class assignment
163-
TNamed::operator=(rhs);
162+
TVirtualMCSensitiveDetector::operator=(rhs);
164163

165164
// assignment operator
166165
fMotherVolumeName = rhs.fMotherVolumeName;
@@ -188,7 +187,7 @@ FairModule& FairModule::operator= (const FairModule& rhs)
188187
//__________________________________________________________________________
189188
void FairModule::Streamer(TBuffer& b)
190189
{
191-
TNamed::Streamer(b);
190+
TVirtualMCSensitiveDetector::Streamer(b);
192191

193192

194193
if (b.IsReading()) {
@@ -294,6 +293,9 @@ void FairModule::ProcessNodes(TList* aList)
294293
FairGeoVolume* aVol=NULL;
295294

296295
if ( node->isSensitive() && fActive ) {
296+
297+
FairMCApplication::Instance()->AddSensitiveModule(volume->GetName(), this);
298+
297299
volume->setModId(fModId);
298300
volume->SetModule(this);
299301
svList->Add(volume);
@@ -306,9 +308,10 @@ void FairModule::ProcessNodes(TList* aList)
306308
//__________________________________________________________________________
307309
void FairModule::AddSensitiveVolume(TGeoVolume* v)
308310
{
309-
310311
LOG(debug2)<<"AddSensitiveVolume " << v->GetName();
311312

313+
FairMCApplication::Instance()->AddSensitiveModule(v->GetName(), this);
314+
312315
// Only register volumes which are not already registered
313316
// Otherwise the stepping will be slowed down
314317
if( ! vList->findObject(v->GetName() ) ) {
@@ -321,8 +324,6 @@ void FairModule::AddSensitiveVolume(TGeoVolume* v)
321324
fNbOfSensitiveVol++;
322325
}
323326
}
324-
325-
326327
//__________________________________________________________________________
327328
FairVolume* FairModule::getFairVolume(FairGeoNode* fN)
328329
{

base/sim/FairModule.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef FAIRMODULE_H
99
#define FAIRMODULE_H
1010

11-
#include "TNamed.h" // for TNamed
11+
#include "TVirtualMCSensitiveDetector.h"
1212

1313
#include "FairGeoInterface.h" // for FairGeoInterface
1414
#include "FairGeoLoader.h" // for FairGeoLoader
@@ -47,7 +47,7 @@ class TVirtualMC;
4747
* Changelog: 29.02.2012 [O.Merle] Fixed missing material assignment for top volume.
4848
* ... and please - add some documentation to your code.
4949
*/
50-
class FairModule: public TNamed
50+
class FairModule: public TVirtualMCSensitiveDetector
5151
{
5252
public:
5353
/**default ctor*/
@@ -136,6 +136,13 @@ class FairModule: public TNamed
136136
TString fMotherVolumeName; //!
137137
FairVolume* getFairVolume(FairGeoNode* fNode);
138138
void AddSensitiveVolume(TGeoVolume* v);
139+
140+
virtual void EndOfEvent() {}
141+
142+
virtual void Initialize() {}
143+
144+
virtual void ProcessHits() {}
145+
139146
private:
140147
/** Re-implimented from ROOT: TGeoMatrix::SetDefaultName() */
141148
void SetDefaultMatrixName(TGeoMatrix* matrix);

base/sim/fastsim/FairFastSimDetector.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ void FairFastSimDetector::ConstructGeometry()
6363
}
6464
}
6565

66-
Bool_t FairFastSimDetector::ProcessHits(FairVolume*)
66+
void FairFastSimDetector::ProcessHits()
6767
{
6868
FastSimProcessParticle();
69-
70-
return kTRUE;
7169
}
7270

7371
ClassImp(FairFastSimDetector)

base/sim/fastsim/FairFastSimDetector.h

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

2424
virtual void Initialize() = 0;
2525

26-
virtual Bool_t ProcessHits(FairVolume* vol = 0) final;
26+
virtual void ProcessHits() final;
2727

2828
virtual void EndOfEvent() {}
2929

examples/MQ/pixelDetector/src/Pixel.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void Pixel::Initialize()
8787
FairDetector::Initialize();
8888
}
8989

90-
Bool_t Pixel::ProcessHits(FairVolume* vol)
90+
void Pixel::ProcessHits()
9191
{
9292

9393
/** This method is called from the MC stepping */
@@ -108,10 +108,11 @@ Bool_t Pixel::ProcessHits(FairVolume* vol)
108108
TVirtualMC::GetMC()->IsTrackStop() ||
109109
TVirtualMC::GetMC()->IsTrackDisappeared() ) {
110110
fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
111-
fVolumeID = vol->getMCid();
111+
Int_t copyNo = 0;
112+
fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo);
112113

113114

114-
if (fELoss == 0. ) { return kFALSE; }
115+
if (fELoss == 0. ) { return; }
115116

116117
// Taking stationNr and sectorNr from string is almost effortless.
117118
// Simulation of 100k events with 5 pions without magnetic field takes:
@@ -135,8 +136,6 @@ Bool_t Pixel::ProcessHits(FairVolume* vol)
135136
FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
136137
stack->AddPoint(kPixel);
137138
}
138-
139-
return kTRUE;
140139
}
141140

142141
void Pixel::EndOfEvent()

examples/MQ/pixelDetector/src/Pixel.h

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

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

examples/advanced/Tutorial3/simulation/FairTestDetector.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void FairTestDetector::Initialize()
7878
rtdb->getContainer("FairTestDetectorGeoPar");
7979
}
8080

81-
Bool_t FairTestDetector::ProcessHits(FairVolume* vol)
81+
void FairTestDetector::ProcessHits()
8282
{
8383
/** This method is called from the MC stepping */
8484

@@ -99,12 +99,13 @@ Bool_t FairTestDetector::ProcessHits(FairVolume* vol)
9999
if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared())
100100
{
101101
fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
102-
fVolumeID = vol->getMCid();
102+
Int_t copyNo = 0;
103+
fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo);
103104
TVirtualMC::GetMC()->TrackPosition(fPosOut);
104105
TVirtualMC::GetMC()->TrackMomentum(fMomOut);
105106
if (fELoss == 0.)
106107
{
107-
return kFALSE;
108+
return;
108109
}
109110
AddHit(fTrackID,
110111
fVolumeID,
@@ -120,8 +121,6 @@ Bool_t FairTestDetector::ProcessHits(FairVolume* vol)
120121
FairStack* stack = static_cast<FairStack*>(TVirtualMC::GetMC()->GetStack());
121122
stack->AddPoint(kTutDet);
122123
}
123-
124-
return kTRUE;
125124
}
126125

127126
void FairTestDetector::EndOfEvent()

0 commit comments

Comments
 (0)