From 2ab950ffe5da0ece4ede1807cf8419175fbe5a01 Mon Sep 17 00:00:00 2001 From: Radoslaw Karabowicz Date: Wed, 8 Jun 2022 10:02:20 +0200 Subject: [PATCH] Fix the double initialization of FairDetector Since VMC is initializing TVirtualMCSensitiveDetector, removed detector->Initialize() from FairMCApplication. Removed the GetFairVolume function used by FairDetector::ProcessHits(). It now calls the deprecated function with NULL argument. Changed the propagator example to use the new ProcessHits(). --- base/sim/FairDetector.cxx | 3 +- base/sim/FairMCApplication.cxx | 48 ------------------- base/sim/FairMCApplication.h | 7 +-- .../propagator/src/FairTutPropDet.cxx | 9 ++-- .../advanced/propagator/src/FairTutPropDet.h | 30 ++++++------ 5 files changed, 22 insertions(+), 75 deletions(-) diff --git a/base/sim/FairDetector.cxx b/base/sim/FairDetector.cxx index 12fb8bcc0b..234f6f2631 100644 --- a/base/sim/FairDetector.cxx +++ b/base/sim/FairDetector.cxx @@ -14,7 +14,6 @@ #include "FairGeoNode.h" // for FairGeoNode #include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN -#include "FairMCApplication.h" // TEMPORARY until the depracated Bool_t ProcessHits() in use #include "FairModule.h" // for FairModule::svList, etc #include "FairRootManager.h" #include "FairVolume.h" // for FairVolume @@ -135,7 +134,7 @@ void FairDetector::ProcessHits() LOG(warning) << " Replace with void FairDetector::ProcessHits(). "; return true; }(); - ProcessHits(FairMCApplication::Instance()->GetFairVolume()); + ProcessHits(NULL); return; } diff --git a/base/sim/FairMCApplication.cxx b/base/sim/FairMCApplication.cxx index 2999f702d6..b21cb254c3 100644 --- a/base/sim/FairMCApplication.cxx +++ b/base/sim/FairMCApplication.cxx @@ -880,7 +880,6 @@ void FairMCApplication::InitGeometry() if (detector) { // check whether detector is active if (detector->IsActive()) { - detector->Initialize(); detector->Register(); } } @@ -1339,51 +1338,4 @@ void FairMCApplication::AddSensitiveModule(std::string volName, FairModule* modu { fMapSensitiveDetectors[volName] = module; } - -FairVolume* FairMCApplication::GetFairVolume() -{ - // 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); - fDisVol = 0; - Int_t fCopyNo = 0; - fVolIter = fVolMap.find(id); - - if (fVolIter != fVolMap.end()) { - - // Call Process hits for FairVolume with this id, copyNo - do { - fDisVol = fVolIter->second; - fCopyNo = fDisVol->getCopyNo(); - if (copyNo == fCopyNo) { - return fDisVol; - } - ++fVolIter; - } while (fVolIter != fVolMap.upper_bound(id)); - - // 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 (?) - // cout << "Volume not in map; fDisVol ? " << fDisVol << endl - FairVolume* fNewV = new FairVolume(fMC->CurrentVolName(), id); - fNewV->setMCid(id); - fNewV->setModId(fDisVol->getModId()); - fNewV->SetModule(fDisVol->GetModule()); - fNewV->setCopyNo(copyNo); - fVolMap.insert(pair(id, fNewV)); - - return fNewV; - } - return 0; -} - ClassImp(FairMCApplication) diff --git a/base/sim/FairMCApplication.h b/base/sim/FairMCApplication.h index eb3998684f..cd1c9145fb 100644 --- a/base/sim/FairMCApplication.h +++ b/base/sim/FairMCApplication.h @@ -221,17 +221,12 @@ class FairMCApplication : public TVirtualMCApplication * Add module to the list of sensitive detectors. */ void AddSensitiveModule(std::string volName, FairModule* module); - + /** * Return non-owning pointer to FairRadGridManager */ auto GetRadGridMan() { return fRadGridMan.get(); } - /** - * 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; diff --git a/examples/advanced/propagator/src/FairTutPropDet.cxx b/examples/advanced/propagator/src/FairTutPropDet.cxx index 81a458c1aa..8c604bdd32 100644 --- a/examples/advanced/propagator/src/FairTutPropDet.cxx +++ b/examples/advanced/propagator/src/FairTutPropDet.cxx @@ -64,7 +64,7 @@ FairTutPropDet::~FairTutPropDet() void FairTutPropDet::Initialize() { FairDetector::Initialize(); } -Bool_t FairTutPropDet::ProcessHits(FairVolume* vol) +void FairTutPropDet::ProcessHits() { /** This method is called from the MC stepping */ @@ -84,10 +84,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. @@ -112,7 +113,7 @@ Bool_t FairTutPropDet::ProcessHits(FairVolume* vol) stack->AddPoint(kTutProp); } - return kTRUE; + return; } void FairTutPropDet::EndOfEvent() { fFairTutPropPointCollection->Clear(); } diff --git a/examples/advanced/propagator/src/FairTutPropDet.h b/examples/advanced/propagator/src/FairTutPropDet.h index 8b9b5a36b0..d595b07221 100644 --- a/examples/advanced/propagator/src/FairTutPropDet.h +++ b/examples/advanced/propagator/src/FairTutPropDet.h @@ -33,24 +33,24 @@ class FairTutPropDet : public FairDetector virtual ~FairTutPropDet(); /** Initialization of the detector is done here */ - virtual void Initialize(); + void Initialize() override; /** this method is called for each step during simulation * (see FairMCApplication::Stepping()) */ - virtual Bool_t ProcessHits(FairVolume* v = 0); + void ProcessHits() override; /** Registers the produced collections in FAIRRootManager. */ - virtual void Register(); + void Register() override; /** Gets the produced collections */ - virtual TClonesArray* GetCollection(Int_t iColl) const; + TClonesArray* GetCollection(Int_t iColl) const override; /** has to be called after each event to reset the containers */ - virtual void Reset(); + void Reset() override; /** Create the detector geometry */ - void ConstructGeometry(); + void ConstructGeometry() override; /** This method is an example of how to add your own point * of type FairTutPropDetPoint to the clones array @@ -64,14 +64,14 @@ class FairTutPropDet : public FairDetector // virtual void CopyClones( TClonesArray* cl1, TClonesArray* cl2 , // Int_t offset) {;} - virtual void SetSpecialPhysicsCuts() { ; } - virtual void EndOfEvent(); - virtual void FinishPrimary() { ; } - virtual void FinishRun() { ; } - virtual void BeginPrimary() { ; } - virtual void PostTrack() { ; } - virtual void PreTrack() { ; } - virtual void BeginEvent() { ; } + void SetSpecialPhysicsCuts() override { ; } + void EndOfEvent() override; + void FinishPrimary() override { ; } + void FinishRun() override { ; } + void BeginPrimary() override { ; } + void PostTrack() override { ; } + void PreTrack() override { ; } + void BeginEvent() override { ; } void SetPointsArrayName(const std::string& tempName) { fPointsArrayName = tempName; }; @@ -96,7 +96,7 @@ class FairTutPropDet : public FairDetector FairTutPropDet(const FairTutPropDet&); FairTutPropDet& operator=(const FairTutPropDet&); - ClassDef(FairTutPropDet, 1); + ClassDefOverride(FairTutPropDet, 1); }; #endif // FAIRTUTPROPDET_H