diff --git a/base/sim/FairDetector.cxx b/base/sim/FairDetector.cxx index 71542f29ac..f4e61daa0b 100644 --- a/base/sim/FairDetector.cxx +++ b/base/sim/FairDetector.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -45,7 +45,10 @@ FairDetector::FairDetector(const FairDetector& rhs) , fLogger(rhs.fLogger) {} -FairDetector::~FairDetector() { delete flGeoPar; } +FairDetector::~FairDetector() +{ + delete flGeoPar; +} FairDetector& FairDetector::operator=(const FairDetector& rhs) { @@ -70,34 +73,12 @@ FairDetector::FairDetector() // ------------------------------------------------------------------------- -void FairDetector::DefineSensitiveVolumes() -{ - LOG(info) << "FairDetector::DefineSensitiveVolumes"; - TObjArray* volumes = gGeoManager->GetListOfVolumes(); - TIter next(volumes); - TGeoVolume* volume; - while ((volume = static_cast(next()))) { - if (IsSensitive(volume->GetName())) { - LOG(debug) << "Sensitive Volume " << volume->GetName(); - AddSensitiveVolume(volume); - } - } -} - -// ------------------------------------------------------------------------- - void FairDetector::Initialize() { // Registers hits collection in Root manager; // sets sensitive volumes. // --- - // Define sensitive volumes if in MT - if (gMC->IsMT()) { - std::cout << "Define sensitive volume " << std::endl; - DefineSensitiveVolumes(); - } - Int_t NoOfEntries = svList->GetEntries(); Int_t fMCid; FairGeoNode* fN; @@ -124,6 +105,23 @@ void FairDetector::Initialize() fMC = TVirtualMC::GetMC(); } +// ------------------------------------------------------------------------- + +void FairDetector::ProcessHits() +{ + static const auto printOnce = [this] { + LOG(warning) << "Calling depracated Bool_t FairDetector::ProcessHits(FairVolume* vol = 0) for \"" << GetName() + << "\"."; + LOG(warning) << " Replace with void FairDetector::ProcessHits(). "; + return true; + }(); + (void)printOnce; + ProcessHits(NULL); + return; +} + +// ------------------------------------------------------------------------- + void FairDetector::SaveGeoParams() { if (!fGeoSaved) { diff --git a/base/sim/FairDetector.h b/base/sim/FairDetector.h index b89fa8ab79..6ddbc9266c 100644 --- a/base/sim/FairDetector.h +++ b/base/sim/FairDetector.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -45,9 +45,13 @@ class FairDetector : public FairModule */ virtual void Initialize(); /** - this method is called for each step during simulation (see FairMCApplication::Stepping()) + this method is called for each step during simulation by the VMC */ - virtual Bool_t ProcessHits(FairVolume* v = 0) = 0; + virtual void ProcessHits(); + /** + DEPRACTED method, currently called by void FairDetector::ProcessHits() + */ + virtual Bool_t ProcessHits(FairVolume* v = 0) { return false; } /** this is called at the end of an event after the call to tree fill in the FairRootManager */ @@ -105,8 +109,6 @@ class FairDetector : public FairModule /** Assignment operator */ FairDetector& operator=(const FairDetector&); - void DefineSensitiveVolumes(); - Int_t fDetId; // Detector Id has to be set from ctr. FairLogger* fLogger; //! /// FairLogger diff --git a/base/sim/FairMCApplication.cxx b/base/sim/FairMCApplication.cxx index d5a0552c9c..f704eea809 100644 --- a/base/sim/FairMCApplication.cxx +++ b/base/sim/FairMCApplication.cxx @@ -196,6 +196,11 @@ FairMCApplication::FairMCApplication(const FairMCApplication& rhs, std::unique_p auto& clone = fOwnedModules.emplace_back(module->CloneModule()); fListModules.emplace_back(clone.get()); fModules->Add(clone.get()); + for (auto sens : rhs.fMapSensitiveDetectors) { + if (sens.second == module) { + fMapSensitiveDetectors[sens.first] = clone.get(); + } + } } // Create and fill a list of active detectors @@ -526,62 +531,6 @@ void FairMCApplication::Stepping() TrackId = fMC->GetStack()->GetCurrentTrackNumber(); } - // Check if the volume with id is in the volume multimap. - // If it is not in the map the volume is not a sensitive volume - // and we do not call nay of our ProcessHits functions. - - // If the volume is in the multimap, check in second step if the current - // copy is alredy inside the multimap. - // If the volume is not in the multimap add the copy of the volume to the - // multimap. - // In any case call the ProcessHits function for this specific detector. - Int_t copyNo; - Int_t id = fMC->CurrentVolID(copyNo); - auto voliter = fVolMap.find(id); - - if (voliter != fVolMap.end()) { - Bool_t InMap = kFALSE; - FairVolume* disvol = nullptr; - FairDetector* disdet = nullptr; - - // Call Process hits for FairVolume with this id, copyNo - do { - disvol = voliter->second; - if (copyNo == disvol->getCopyNo()) { - disdet = disvol->GetDetector(); - if (disdet) { - disdet->ProcessHits(disvol); - } - InMap = kTRUE; - break; - } - ++voliter; - } while (voliter != fVolMap.upper_bound(id)); - - // if (disvol && !InMap) { // fDisVolume is set previously, no check needed - - // Create new FairVolume with this id, copyNo. - // Use the FairVolume with the same id found in the map to get - // the link to the detector. - // Seems that this never happens (?) - if (!InMap) { - // cout << "Volume not in map; disvol ? " << disvol << endl - FairVolume* fNewV = new FairVolume(fMC->CurrentVolName(), id); - fNewV->setMCid(id); - fNewV->setModId(disvol->getModId()); - fNewV->SetModule(disvol->GetModule()); - fNewV->setCopyNo(copyNo); - fVolMap.insert(pair(id, fNewV)); - disdet = disvol->GetDetector(); - - // LOG(info) << "FairMCApplication::Stepping: new fair volume" - // << id << " " << copyNo << " " << disdet; - if (disdet) { - disdet->ProcessHits(fNewV); - } - } - } - // If information about the tracks should be stored the information as to be // stored for any step. // Information about each single step has also to be stored for the other @@ -599,7 +548,8 @@ void FairMCApplication::Stepping() } } if (fRadLenMan || fRadMapMan) { - id = fMC->CurrentVolID(copyNo); + Int_t copyNo; + Int_t id = fMC->CurrentVolID(copyNo); auto modvoliter = (fParent ? fParent : this)->fModVolMap.find(id); if (fRadLenMan) { fRadLenMan->AddPoint(fMC, modvoliter->second); @@ -656,13 +606,10 @@ void FairMCApplication::StopMCRun() } //_____________________________________________________________________________ -void FairMCApplication::FinishEvent() +void FairMCApplication::EndOfEvent() { - // User actions after finishing of an event + // User actions just before finishing of an event // --- - LOG(debug) << "[" << fRootManager->GetInstanceId() - << " FairMCMCApplication::FinishEvent: " << fMCEventHeader->GetEventID() << " (MC " - << gMC->CurrentEvent() << ")"; if (gMC->IsMT() && fRun->GetSink()->GetSinkType() == kONLINESINK) { // fix the rare case when running G4 multithreaded on MQ fMCEventHeader->SetEventID(gMC->CurrentEvent() + 1); @@ -680,18 +627,24 @@ void FairMCApplication::FinishEvent() fFairTaskList->FinishEvent(); } - for (auto detectorPtr : listActiveDetectors) { - detectorPtr->FinishEvent(); - } - if (fRootManager && fSaveCurrentEvent) { fRootManager->Fill(); } else { fSaveCurrentEvent = kTRUE; } +} + +//_____________________________________________________________________________ +void FairMCApplication::FinishEvent() +{ + // User actions after finishing of an event + // --- + LOG(debug) << "[" << fRootManager->GetInstanceId() + << " FairMCMCApplication::FinishEvent: " << fMCEventHeader->GetEventID() << " (MC " + << gMC->CurrentEvent() << ")"; for (auto detectorPtr : listActiveDetectors) { - detectorPtr->EndOfEvent(); + detectorPtr->FinishEvent(); } fStack->Reset(); @@ -983,7 +936,6 @@ void FairMCApplication::RegisterOutput() if (detector) { // check whether detector is active if (detector->IsActive()) { - detector->Initialize(); detector->Register(); } } @@ -1338,4 +1290,28 @@ void FairMCApplication::UndoGeometryModifications() gGeoManager->ClearPhysicalNodes(kFALSE); } -ClassImp(FairMCApplication); +void FairMCApplication::ConstructSensitiveDetectors() +{ + std::map cloneVolumeMap; + + for (auto const& x : fMapSensitiveDetectors) { + std::string volName = x.first; //.substr(0, x.first.find("#", 0)); + if (volName.find('#') != std::string::npos) { + volName = volName.substr(0, volName.find("#", 0)); + auto it = cloneVolumeMap.find(volName); + LOG(debug) << "FairMCApplication::ConstructSensitiveDetectors got clone " << x.first << " " << x.second; + if (it != cloneVolumeMap.end()) + continue; + cloneVolumeMap[volName] = x.second; + LOG(debug) << "FairMCApplication::ConstructSensitiveDetectors really do " << volName; + } + LOG(debug) << "FairMCApplication::ConstructSensitiveDetectors really do " << volName; + TVirtualMC::GetMC()->SetSensitiveDetector(volName, x.second); + } +} + +void FairMCApplication::AddSensitiveModule(std::string volName, FairModule* module) +{ + fMapSensitiveDetectors[volName] = module; +} +ClassImp(FairMCApplication) diff --git a/base/sim/FairMCApplication.h b/base/sim/FairMCApplication.h index d90cdabf1f..df87e75db7 100644 --- a/base/sim/FairMCApplication.h +++ b/base/sim/FairMCApplication.h @@ -39,6 +39,7 @@ class FairRootManager; class FairTask; class FairTrajFilter; class FairVolume; +class FairModule; class FairRunSim; class TChain; class TIterator; @@ -105,6 +106,12 @@ class FairMCApplication : public TVirtualMCApplication Bool_t MisalignGeometry() override; /** Define parameters for optical processes (optional) */ void ConstructOpGeometry() override; // MC Application + + /** set sensitive detectors following TVirtualMCSensitiveDetector logic */ + void ConstructSensitiveDetectors() override; // MC Application + + /** Define actions just before sensitive->EndOfEvent */ + void EndOfEvent() override; // MC Application /** Define actions at the end of event */ void FinishEvent() override; // MC Application /** Define actions at the end of primary track */ @@ -222,6 +229,11 @@ class FairMCApplication : public TVirtualMCApplication */ FairMCApplicationState GetState() const { return fState; } + /** + * Add module to the list of sensitive detectors. + */ + void AddSensitiveModule(std::string volName, FairModule* module); + /** * Return non-owning pointer to FairRadGridManager */ @@ -232,6 +244,11 @@ class FairMCApplication : public TVirtualMCApplication */ auto GetIsMT() { return fMC ? fMC->IsMT() : false; } + /** + * Method introduced temporarily. It should go awway with DEPRACATED Bool_t FairDetector::ProcessHits() + */ + FairVolume* GetFairVolume(); + private: // methods Int_t GetIonPdg(Int_t z, Int_t a) const; @@ -333,6 +350,12 @@ class FairMCApplication : public TVirtualMCApplication */ std::vector fListModules{}; //! + /** + * List of sensitive detectors. + * To be used with TVirtualMCSensitiveDetector. + */ + std::map fMapSensitiveDetectors; + /** * Owned Modules (inside the worker) */ diff --git a/base/sim/FairModule.cxx b/base/sim/FairModule.cxx index 57207c0e9e..8bc66c0e76 100644 --- a/base/sim/FairModule.cxx +++ b/base/sim/FairModule.cxx @@ -73,7 +73,7 @@ void FairModule::ConstructOpGeometry() FairModule::~FairModule() {} FairModule::FairModule(const char* Name, const char* title, Bool_t Active) - : TNamed(Name, title) + : TVirtualMCSensitiveDetector(Name, title) , fMotherVolumeName("") , fgeoVer("Not defined") , fgeoName("Not defined") @@ -94,7 +94,7 @@ FairModule::FairModule(const char* Name, const char* title, Bool_t Active) } FairModule::FairModule(const FairModule& rhs) - : TNamed(rhs) + : TVirtualMCSensitiveDetector(rhs) , fMotherVolumeName(rhs.fMotherVolumeName) , fgeoVer(rhs.fgeoVer) , fgeoName(rhs.fgeoName) @@ -134,7 +134,7 @@ FairModule::FairModule(const FairModule& rhs) } FairModule::FairModule() - : TNamed() + : TVirtualMCSensitiveDetector() , fMotherVolumeName("") , fgeoVer("Not defined") , fgeoName("Not defined") @@ -154,7 +154,7 @@ FairModule& FairModule::operator=(const FairModule& rhs) return *this; // base class assignment - TNamed::operator=(rhs); + TVirtualMCSensitiveDetector::operator=(rhs); // assignment operator fMotherVolumeName = rhs.fMotherVolumeName; @@ -182,7 +182,7 @@ FairModule& FairModule::operator=(const FairModule& rhs) void FairModule::Streamer(TBuffer& b) { - TNamed::Streamer(b); + TVirtualMCSensitiveDetector::Streamer(b); if (b.IsReading()) { fgeoVer.Streamer(b); @@ -282,6 +282,9 @@ void FairModule::ProcessNodes(TList* aList) FairGeoVolume* aVol = nullptr; if (node->isSensitive() && fActive) { + + FairMCApplication::Instance()->AddSensitiveModule(volume->GetName(), this); + volume->setModId(fModId); volume->SetModule(this); svList->Add(volume); @@ -294,9 +297,10 @@ void FairModule::ProcessNodes(TList* aList) void FairModule::AddSensitiveVolume(TGeoVolume* v) { - LOG(debug2) << "AddSensitiveVolume " << v->GetName(); + FairMCApplication::Instance()->AddSensitiveModule(v->GetName(), this); + // Only register volumes which are not already registered // Otherwise the stepping will be slowed down if (!vList->findObject(v->GetName())) { diff --git a/base/sim/FairModule.h b/base/sim/FairModule.h index 409d2340d2..046a7e193f 100644 --- a/base/sim/FairModule.h +++ b/base/sim/FairModule.h @@ -21,6 +21,8 @@ #include // for TNamed #include // for TObjArray #include // for TString, operator!= +#include + #include // for string class FairVolumeList; @@ -43,7 +45,7 @@ class TVirtualMC; * Changelog: 29.02.2012 [O.Merle] Fixed missing material assignment for top volume. * ... and please - add some documentation to your code. */ -class FairModule : public TNamed +class FairModule : public TVirtualMCSensitiveDetector { public: /**default ctor*/ @@ -148,6 +150,12 @@ class FairModule : public TNamed FairVolume* getFairVolume(FairGeoNode* fNode); void AddSensitiveVolume(TGeoVolume* v); + void EndOfEvent() override {} + + void Initialize() override {} + + void ProcessHits() override {} + private: /** Re-implimented from ROOT: TGeoMatrix::SetDefaultName() */ void SetDefaultMatrixName(TGeoMatrix* matrix); diff --git a/base/sim/fastsim/FairFastSimDetector.cxx b/base/sim/fastsim/FairFastSimDetector.cxx index f574d92e77..a48e0f4c07 100644 --- a/base/sim/fastsim/FairFastSimDetector.cxx +++ b/base/sim/fastsim/FairFastSimDetector.cxx @@ -59,11 +59,9 @@ void FairFastSimDetector::ConstructGeometry() } } -Bool_t FairFastSimDetector::ProcessHits(FairVolume*) +void FairFastSimDetector::ProcessHits() { FastSimProcessParticle(); - - return kTRUE; } ClassImp(FairFastSimDetector); diff --git a/base/sim/fastsim/FairFastSimDetector.h b/base/sim/fastsim/FairFastSimDetector.h index 187c48b9d5..5867640dbb 100644 --- a/base/sim/fastsim/FairFastSimDetector.h +++ b/base/sim/fastsim/FairFastSimDetector.h @@ -25,7 +25,7 @@ class FairFastSimDetector : public FairDetector ~FairFastSimDetector() override; - Bool_t ProcessHits(FairVolume* vol = 0) override final; + void ProcessHits() override final; void EndOfEvent() override {} diff --git a/examples/MQ/pixelDetector/src/Pixel.cxx b/examples/MQ/pixelDetector/src/Pixel.cxx index f61d6d1602..fe96881113 100644 --- a/examples/MQ/pixelDetector/src/Pixel.cxx +++ b/examples/MQ/pixelDetector/src/Pixel.cxx @@ -73,8 +73,9 @@ Pixel::~Pixel() } } -Bool_t Pixel::ProcessHits(FairVolume* vol) +void Pixel::ProcessHits() { + /** This method is called from the MC stepping */ // Set parameters at entrance of volume. Reset ELoss. if (TVirtualMC::GetMC()->IsTrackEntering()) { @@ -92,10 +93,11 @@ Bool_t Pixel::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - fVolumeID = vol->getMCid(); + Int_t copyNo = 0; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); if (fELoss == 0.) { - return kFALSE; + return; } // Taking stationNr and sectorNr from string is almost effortless. @@ -124,8 +126,6 @@ Bool_t Pixel::ProcessHits(FairVolume* vol) FairStack* stack = static_cast(TVirtualMC::GetMC()->GetStack()); stack->AddPoint(kPixel); } - - return kTRUE; } void Pixel::EndOfEvent() { fPixelPointCollection->Clear(); } diff --git a/examples/MQ/pixelDetector/src/Pixel.h b/examples/MQ/pixelDetector/src/Pixel.h index 38c13e5303..9fd65d7475 100644 --- a/examples/MQ/pixelDetector/src/Pixel.h +++ b/examples/MQ/pixelDetector/src/Pixel.h @@ -36,7 +36,7 @@ class Pixel : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - Bool_t ProcessHits(FairVolume* v = 0) override; + void ProcessHits() override; /** Registers the produced collections in FAIRRootManager. */ void Register() override; diff --git a/examples/advanced/Tutorial3/simulation/FairTestDetector.cxx b/examples/advanced/Tutorial3/simulation/FairTestDetector.cxx index 98ba6c1d29..bef9b8c454 100644 --- a/examples/advanced/Tutorial3/simulation/FairTestDetector.cxx +++ b/examples/advanced/Tutorial3/simulation/FairTestDetector.cxx @@ -67,7 +67,7 @@ void FairTestDetector::Initialize() rtdb->getContainer("FairTestDetectorGeoPar"); } -Bool_t FairTestDetector::ProcessHits(FairVolume* vol) +void FairTestDetector::ProcessHits() { /** This method is called from the MC stepping */ @@ -87,11 +87,12 @@ Bool_t FairTestDetector::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - fVolumeID = vol->getMCid(); + Int_t copyNo = 0; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); TVirtualMC::GetMC()->TrackPosition(fPosOut); TVirtualMC::GetMC()->TrackMomentum(fMomOut); if (fELoss == 0.) { - return kFALSE; + return; } AddHit(fTrackID, fVolumeID, @@ -107,8 +108,6 @@ Bool_t FairTestDetector::ProcessHits(FairVolume* vol) FairStack* stack = static_cast(TVirtualMC::GetMC()->GetStack()); stack->AddPoint(kTutDet); } - - return kTRUE; } void FairTestDetector::EndOfEvent() diff --git a/examples/advanced/Tutorial3/simulation/FairTestDetector.h b/examples/advanced/Tutorial3/simulation/FairTestDetector.h index 767231c411..1cb47bc4d5 100644 --- a/examples/advanced/Tutorial3/simulation/FairTestDetector.h +++ b/examples/advanced/Tutorial3/simulation/FairTestDetector.h @@ -39,7 +39,7 @@ class FairTestDetector : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - Bool_t ProcessHits(FairVolume* v = 0) override; + void ProcessHits() override; /** Registers the produced collections in FAIRRootManager. */ void Register() override; diff --git a/examples/advanced/propagator/src/FairTutPropDet.cxx b/examples/advanced/propagator/src/FairTutPropDet.cxx index a4a0e8e985..e3ff4a7c85 100644 --- a/examples/advanced/propagator/src/FairTutPropDet.cxx +++ b/examples/advanced/propagator/src/FairTutPropDet.cxx @@ -62,7 +62,7 @@ FairTutPropDet::~FairTutPropDet() } } -Bool_t FairTutPropDet::ProcessHits(FairVolume* vol) +void FairTutPropDet::ProcessHits() { /** This method is called from the MC stepping */ @@ -82,10 +82,11 @@ Bool_t FairTutPropDet::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - fVolumeID = vol->getMCid(); + Int_t copyNo; + fVolumeID = fMC->CurrentVolID(copyNo); if (fELoss == 0.) { - return kFALSE; + return; } // Taking stationNr from string is almost effortless. @@ -109,8 +110,6 @@ Bool_t FairTutPropDet::ProcessHits(FairVolume* vol) FairStack* stack = static_cast(TVirtualMC::GetMC()->GetStack()); stack->AddPoint(kTutProp); } - - return kTRUE; } void FairTutPropDet::EndOfEvent() { fFairTutPropPointCollection->Clear(); } diff --git a/examples/advanced/propagator/src/FairTutPropDet.h b/examples/advanced/propagator/src/FairTutPropDet.h index 0f5f3bb183..d8321dd6dc 100644 --- a/examples/advanced/propagator/src/FairTutPropDet.h +++ b/examples/advanced/propagator/src/FairTutPropDet.h @@ -35,7 +35,7 @@ class FairTutPropDet : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - Bool_t ProcessHits(FairVolume* v = nullptr) override; + void ProcessHits() override; /** Registers the produced collections in FAIRRootManager. */ void Register() override; diff --git a/examples/simulation/Tutorial1/macros/CMakeLists.txt b/examples/simulation/Tutorial1/macros/CMakeLists.txt index 65c1eec79b..32c489dff3 100644 --- a/examples/simulation/Tutorial1/macros/CMakeLists.txt +++ b/examples/simulation/Tutorial1/macros/CMakeLists.txt @@ -1,5 +1,5 @@ ################################################################################ -# Copyright (C) 2014-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # # # # This software is distributed under the terms of the # # GNU Lesser General Public Licence (LGPL) version 3, # @@ -52,7 +52,7 @@ foreach(mcEngine IN LISTS mcEngine_list) endforeach() add_test(NAME ex_tutorial1_Geant4MT - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_tutorial1.sh 10 \"TGeant4\" true false) + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/run_tutorial1.sh 20 \"TGeant4\" true false) set_tests_properties(ex_tutorial1_Geant4MT PROPERTIES TIMEOUT ${maxTestTime} PASS_REGULAR_EXPRESSION "Simulation successful." diff --git a/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx b/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx index 7f0727abf1..59b485f996 100644 --- a/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx +++ b/examples/simulation/Tutorial1/src/FairTutorialDet1.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -7,8 +7,8 @@ ********************************************************************************/ #include "FairTutorialDet1.h" -#include "FairDetectorList.h" // for DetectorId::kTutDet -#include "FairLogger.h" // for logging +#include "FairDetectorList.h" // for DetectorId::kTutDet +#include "FairLogger.h" #include "FairRootManager.h" // for FairRootManager #include "FairStack.h" // for FairStack #include "FairTutorialDet1Geo.h" // for FairTutorialDet1Geo @@ -50,7 +50,7 @@ void FairTutorialDet1::Initialize() fIsInitialised = true; } -Bool_t FairTutorialDet1::ProcessHits(FairVolume* vol) +void FairTutorialDet1::ProcessHits() { /** This method is called from the MC stepping */ @@ -71,9 +71,11 @@ Bool_t FairTutorialDet1::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { auto trackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - auto volumeID = vol->getMCid(); + auto copyNo = 0; + auto volumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); + if (fELoss == 0.) { - return kFALSE; + return; } AddHit(trackID, volumeID, @@ -87,11 +89,15 @@ Bool_t FairTutorialDet1::ProcessHits(FairVolume* vol) auto stack = static_cast(TVirtualMC::GetMC()->GetStack()); stack->AddPoint(kTutDet); } - - return kTRUE; } -void FairTutorialDet1::EndOfEvent() { fFairTutorialDet1PointCollection->Clear(); } +void FairTutorialDet1::EndOfEvent() +{ + + LOG(info) << "FairTutorialDet1 : " << fFairTutorialDet1PointCollection->GetEntriesFast() << " points registered."; + + fFairTutorialDet1PointCollection->Clear(); +} void FairTutorialDet1::Register() { @@ -114,18 +120,16 @@ TClonesArray* FairTutorialDet1::GetCollection(Int_t iColl) const } } -void FairTutorialDet1::Reset() { fFairTutorialDet1PointCollection->Clear(); } - -Bool_t FairTutorialDet1::IsSensitive(const std::string& name) +void FairTutorialDet1::Reset() { - return name.find("tutdet") != std::string::npos; + fFairTutorialDet1PointCollection->Clear(); } void FairTutorialDet1::ConstructGeometry() { /** If you are using the standard ASCII input for the geometry - just copy this and use it for your detector, otherwise you can - implement here you own way of constructing the geometry. */ + just copy this and use it for your detector, otherwise you can + implement here you own way of constructing the geometry. */ ConstructASCIIGeometry("FairTutorialDet1GeoPar"); } @@ -143,6 +147,9 @@ FairTutorialDet1Point* FairTutorialDet1::AddHit(Int_t trackID, return new (clref[size]) FairTutorialDet1Point(trackID, detID, pos, mom, time, length, eLoss); } -FairModule* FairTutorialDet1::CloneModule() const { return new FairTutorialDet1(*this); } +FairModule* FairTutorialDet1::CloneModule() const +{ + return new FairTutorialDet1(*this); +} ClassImp(FairTutorialDet1); diff --git a/examples/simulation/Tutorial1/src/FairTutorialDet1.h b/examples/simulation/Tutorial1/src/FairTutorialDet1.h index d9a640fe5e..957ee38455 100644 --- a/examples/simulation/Tutorial1/src/FairTutorialDet1.h +++ b/examples/simulation/Tutorial1/src/FairTutorialDet1.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -42,7 +42,7 @@ class FairTutorialDet1 : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - Bool_t ProcessHits(FairVolume* v = nullptr) override; + void ProcessHits() override; /** Registers the produced collections in FAIRRootManager. */ void Register() override; @@ -79,8 +79,6 @@ class FairTutorialDet1 : public FairDetector FairModule* CloneModule() const override; - Bool_t IsSensitive(const std::string& name) override; - private: /** Track information to be stored until the track leaves the active volume. diff --git a/examples/simulation/Tutorial2/src/FairTutorialDet2.cxx b/examples/simulation/Tutorial2/src/FairTutorialDet2.cxx index ea386449da..332efc4598 100644 --- a/examples/simulation/Tutorial2/src/FairTutorialDet2.cxx +++ b/examples/simulation/Tutorial2/src/FairTutorialDet2.cxx @@ -70,7 +70,7 @@ FairTutorialDet2::~FairTutorialDet2() } } -Bool_t FairTutorialDet2::ProcessHits(FairVolume* vol) +void FairTutorialDet2::ProcessHits() { /** This method is called from the MC stepping */ @@ -90,9 +90,10 @@ Bool_t FairTutorialDet2::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - fVolumeID = vol->getMCid(); + Int_t copyNo = 0; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); if (fELoss == 0.) { - return kFALSE; + return; } AddHit(fTrackID, fVolumeID, @@ -106,8 +107,6 @@ Bool_t FairTutorialDet2::ProcessHits(FairVolume* vol) FairStack* stack = static_cast(TVirtualMC::GetMC()->GetStack()); stack->AddPoint(kTutDet); } - - return kTRUE; } void FairTutorialDet2::EndOfEvent() { Reset(); } diff --git a/examples/simulation/Tutorial2/src/FairTutorialDet2.h b/examples/simulation/Tutorial2/src/FairTutorialDet2.h index 8e1a405cb9..6cced14876 100644 --- a/examples/simulation/Tutorial2/src/FairTutorialDet2.h +++ b/examples/simulation/Tutorial2/src/FairTutorialDet2.h @@ -39,7 +39,7 @@ class FairTutorialDet2 : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - virtual Bool_t ProcessHits(FairVolume* v = 0); + virtual void ProcessHits(); /** Registers the produced collections in FAIRRootManager. */ virtual void Register(); diff --git a/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.cxx b/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.cxx index 65821aa8b0..f0fb44cb1e 100644 --- a/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.cxx +++ b/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.cxx @@ -152,7 +152,7 @@ void FairTutorialDet4::InitParContainers() fRotZ = fMisalignPar->GetRotZ(); } -Bool_t FairTutorialDet4::ProcessHits(FairVolume* /*vol*/) +void FairTutorialDet4::ProcessHits() { /** This method is called from the MC stepping */ @@ -172,10 +172,10 @@ Bool_t FairTutorialDet4::ProcessHits(FairVolume* /*vol*/) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - // fVolumeID = vol->getMCid(); + // fVolumeID = vol->getMCid(); fVolumeID = fGeoHandler->GetUniqueDetectorId(); if (fELoss == 0.) { - return kFALSE; + return; } if (!fGlobalCoordinates) { @@ -206,8 +206,6 @@ Bool_t FairTutorialDet4::ProcessHits(FairVolume* /*vol*/) FairStack* stack = static_cast(TVirtualMC::GetMC()->GetStack()); stack->AddPoint(kTutDet); } - - return kTRUE; } void FairTutorialDet4::EndOfEvent() { fFairTutorialDet4PointCollection->Clear(); } diff --git a/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.h b/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.h index 4dcff9236c..a0df52f082 100644 --- a/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.h +++ b/examples/simulation/Tutorial4/src/mc/FairTutorialDet4.h @@ -50,7 +50,7 @@ class FairTutorialDet4 : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - virtual Bool_t ProcessHits(FairVolume* v = 0); + virtual void ProcessHits(); /** Registers the produced collections in FAIRRootManager. */ virtual void Register(); diff --git a/examples/simulation/rutherford/src/FairRutherford.cxx b/examples/simulation/rutherford/src/FairRutherford.cxx index ccd2d097b4..25fbbc8164 100644 --- a/examples/simulation/rutherford/src/FairRutherford.cxx +++ b/examples/simulation/rutherford/src/FairRutherford.cxx @@ -42,7 +42,7 @@ FairRutherford::~FairRutherford() } } -Bool_t FairRutherford::ProcessHits(FairVolume* vol) +void FairRutherford::ProcessHits() { /** This method is called from the MC stepping */ @@ -62,9 +62,10 @@ Bool_t FairRutherford::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - fVolumeID = vol->getMCid(); + Int_t copyNo = 0; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); if (fELoss == 0.) { - return kFALSE; + return; } AddHit(fTrackID, fVolumeID, @@ -78,8 +79,6 @@ Bool_t FairRutherford::ProcessHits(FairVolume* vol) auto stack = static_cast(TVirtualMC::GetMC()->GetStack()); stack->AddPoint(kFairRutherford); } - - return kTRUE; } void FairRutherford::EndOfEvent() { fFairRutherfordPointCollection->Clear(); } diff --git a/examples/simulation/rutherford/src/FairRutherford.h b/examples/simulation/rutherford/src/FairRutherford.h index 218881d8bf..697774015e 100644 --- a/examples/simulation/rutherford/src/FairRutherford.h +++ b/examples/simulation/rutherford/src/FairRutherford.h @@ -36,9 +36,9 @@ class FairRutherford : public FairDetector ~FairRutherford() override; /** this method is called for each step during simulation - * (see FairMCApplication::Stepping()) + * (by the VMC) */ - Bool_t ProcessHits(FairVolume* v = nullptr) override; + void ProcessHits() override; /** Registers the produced collections in FAIRRootManager. */ void Register() override; diff --git a/templates/project_root_containers/NewDetector/NewDetector.cxx b/templates/project_root_containers/NewDetector/NewDetector.cxx index 1454fd5715..cc5139843b 100644 --- a/templates/project_root_containers/NewDetector/NewDetector.cxx +++ b/templates/project_root_containers/NewDetector/NewDetector.cxx @@ -92,7 +92,7 @@ void NewDetector::Initialize() (void)par; // stop warning about unused variable } -Bool_t NewDetector::ProcessHits(FairVolume* vol) +void NewDetector::ProcessHits() { /** This method is called from the MC stepping */ @@ -112,9 +112,10 @@ Bool_t NewDetector::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - fVolumeID = vol->getMCid(); + Int_t copyNo = 0; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); if (fELoss == 0.) { - return kFALSE; + return; } AddHit(fTrackID, fVolumeID, @@ -128,8 +129,6 @@ Bool_t NewDetector::ProcessHits(FairVolume* vol) MyProjStack* stack = (MyProjStack*)TVirtualMC::GetMC()->GetStack(); stack->AddPoint(kNewDetector); } - - return kTRUE; } void NewDetector::EndOfEvent() diff --git a/templates/project_root_containers/NewDetector/NewDetector.h b/templates/project_root_containers/NewDetector/NewDetector.h index e02458f704..a0f16208c7 100644 --- a/templates/project_root_containers/NewDetector/NewDetector.h +++ b/templates/project_root_containers/NewDetector/NewDetector.h @@ -39,7 +39,7 @@ class NewDetector : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - virtual Bool_t ProcessHits(FairVolume* v = 0); + virtual void ProcessHits(); /** Registers the produced collections in FAIRRootManager. */ virtual void Register(); diff --git a/templates/project_stl_containers/NewDetector/NewDetector.cxx b/templates/project_stl_containers/NewDetector/NewDetector.cxx index fdb28440d7..7d99e8d3d3 100644 --- a/templates/project_stl_containers/NewDetector/NewDetector.cxx +++ b/templates/project_stl_containers/NewDetector/NewDetector.cxx @@ -91,7 +91,7 @@ void NewDetector::Initialize() (void)par; // stop warning about unused variable } -Bool_t NewDetector::ProcessHits(FairVolume* vol) +void NewDetector::ProcessHits() { /** This method is called from the MC stepping */ @@ -111,9 +111,10 @@ Bool_t NewDetector::ProcessHits(FairVolume* vol) if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() || TVirtualMC::GetMC()->IsTrackDisappeared()) { fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); - fVolumeID = vol->getMCid(); + Int_t copyNo = 0; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); if (fELoss == 0.) { - return kFALSE; + return; } AddHit(fTrackID, fVolumeID, @@ -127,8 +128,6 @@ Bool_t NewDetector::ProcessHits(FairVolume* vol) MyProjStack* stack = (MyProjStack*)TVirtualMC::GetMC()->GetStack(); stack->AddPoint(kNewDetector); } - - return kTRUE; } void NewDetector::EndOfEvent() diff --git a/templates/project_stl_containers/NewDetector/NewDetector.h b/templates/project_stl_containers/NewDetector/NewDetector.h index 347f5ada58..78e337fd58 100644 --- a/templates/project_stl_containers/NewDetector/NewDetector.h +++ b/templates/project_stl_containers/NewDetector/NewDetector.h @@ -39,7 +39,7 @@ class NewDetector : public FairDetector /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - virtual Bool_t ProcessHits(FairVolume* v = 0); + virtual void ProcessHits(); /** Registers the produced collections in FAIRRootManager. */ virtual void Register();