Skip to content

Commit c6ffc2e

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

File tree

23 files changed

+530
-561
lines changed

23 files changed

+530
-561
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: 95 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -651,74 +651,38 @@ 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-
}
720-
}
721-
}
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());
671+
}
672+
}
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+
}
722686

723687
// If information about the tracks should be stored the information as to be
724688
// stored for any step.
@@ -796,61 +760,53 @@ void FairMCApplication::StopMCRun()
796760
//_____________________________________________________________________________
797761
void FairMCApplication::FinishEvent()
798762
{
799-
// User actions after finishing of an event
800-
// ---
801-
LOG(debug) << "[" << fRootManager->GetInstanceId()
802-
<< " FairMCMCApplication::FinishEvent: " << fMCEventHeader->GetEventID() << " (MC "
803-
<< gMC->CurrentEvent() << ")";
804-
if (gMC->IsMT()
805-
&& fRun->GetSink()->GetSinkType() == kONLINESINK) { // fix the rare case when running G4 multithreaded on MQ
806-
fMCEventHeader->SetEventID(gMC->CurrentEvent() + 1);
807-
}
808-
809-
// --> Fill the stack output array
810-
fStack->FillTrackArray();
811-
// --> Update track indizes in MCTracks and MCPoints
812-
fStack->UpdateTrackIndex(fActiveDetectors);
813-
// --> Screen output of stack
814-
// fStack->Print();
815-
816-
if (fFairTaskList) {
817-
fFairTaskList->ExecuteTask("");
818-
fFairTaskList->FinishEvent();
819-
}
820-
821-
for (auto detectorPtr : listActiveDetectors) {
822-
detectorPtr->FinishEvent();
823-
}
824-
825-
if (fRootManager && fSaveCurrentEvent) {
826-
fRootManager->Fill();
827-
} else {
828-
fSaveCurrentEvent = kTRUE;
829-
}
830-
831-
for (auto detectorPtr : listActiveDetectors) {
832-
detectorPtr->EndOfEvent();
833-
}
834-
835-
fStack->Reset();
836-
if (nullptr != fTrajFilter) {
837-
fTrajFilter->Reset();
838-
// TObjArray* fListOfTracks=gGeoManager->GetListOfTracks();
839-
// fListOfTracks->Delete();
840-
gGeoManager->GetListOfTracks()->Delete();
841-
}
842-
if (nullptr != fRadLenMan) {
843-
fRadLenMan->Reset();
844-
}
845-
if (nullptr != fRadMapMan) {
846-
fRadMapMan->Reset();
847-
}
848-
849-
// Store information about runtime for one event and memory consuption
850-
// for later usage.
851-
if ((FairRunSim::Instance()->IsRunInfoGenerated()) && !gMC->IsMT()) {
852-
fRunInfo.StoreInfo();
853-
}
763+
// User actions after finishing of an event
764+
// ---
765+
LOG(debug) << "FairMCMCApplication::FinishEvent: "
766+
<< fRootManager->GetInstanceId();
767+
768+
// --> Fill the stack output array
769+
fStack->FillTrackArray();
770+
// --> Update track indizes in MCTracks and MCPoints
771+
fStack->UpdateTrackIndex(fActiveDetectors);
772+
// --> Screen output of stack
773+
// fStack->Print();
774+
775+
if (fFairTaskList) {
776+
fFairTaskList->ExecuteTask("");
777+
fFairTaskList->FinishEvent();
778+
}
779+
780+
for (auto detectorPtr : listActiveDetectors)
781+
{
782+
detectorPtr->FinishEvent();
783+
}
784+
785+
if (fRootManager && fSaveCurrentEvent) {
786+
fRootManager->Fill();
787+
} else {
788+
fSaveCurrentEvent = kTRUE;
789+
}
790+
791+
fStack->Reset();
792+
if(nullptr != fTrajFilter) {
793+
fTrajFilter->Reset();
794+
// TObjArray* fListOfTracks=gGeoManager->GetListOfTracks();
795+
// fListOfTracks->Delete();
796+
gGeoManager->GetListOfTracks()->Delete();
797+
}
798+
if(nullptr !=fRadLenMan) {
799+
fRadLenMan->Reset();
800+
}
801+
if(nullptr !=fRadMapMan) {
802+
fRadMapMan->Reset();
803+
}
804+
805+
// Store information about runtime for one event and memory consuption
806+
// for later usage.
807+
if ( (FairRunSim::Instance()->IsRunInfoGenerated()) && ! gMC->IsMT() ) {
808+
fRunInfo.StoreInfo();
809+
}
854810
}
855811
//_____________________________________________________________________________
856812
Double_t FairMCApplication::TrackingRmax() const
@@ -1480,4 +1436,19 @@ void FairMCApplication::UndoGeometryModifications()
14801436
gGeoManager->ClearPhysicalNodes(kFALSE);
14811437
}
14821438

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

base/sim/FairMCApplication.h

Lines changed: 15 additions & 2 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;
@@ -95,7 +96,10 @@ class FairMCApplication : public TVirtualMCApplication
9596
/** Align or misalign geometry before actual run */
9697
virtual Bool_t MisalignGeometry();
9798
/** Define parameters for optical processes (optional) */
98-
virtual void ConstructOpGeometry(); // MC Application
99+
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
@@ -300,7 +309,11 @@ class FairMCApplication : public TVirtualMCApplication
300309
Bool_t fSaveCurrentEvent;
301310

302311
/** Current state */
303-
FairMCApplicationState fState; //!
312+
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

0 commit comments

Comments
 (0)