Skip to content

Commit

Permalink
Fix the double initialization of FairDetector
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
karabowi committed Jun 8, 2022
1 parent 82b4dd3 commit 2259768
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 75 deletions.
3 changes: 1 addition & 2 deletions base/sim/FairDetector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,7 +134,7 @@ void FairDetector::ProcessHits()
LOG(warning) << " Replace with void FairDetector::ProcessHits(). ";
return true;
}();
ProcessHits(FairMCApplication::Instance()->GetFairVolume());
ProcessHits(NULL);
return;
}

Expand Down
48 changes: 0 additions & 48 deletions base/sim/FairMCApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,6 @@ void FairMCApplication::InitGeometry()
if (detector) {
// check whether detector is active
if (detector->IsActive()) {
detector->Initialize();
detector->Register();
}
}
Expand Down Expand Up @@ -1359,51 +1358,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<Int_t, FairVolume*>(id, fNewV));

return fNewV;
}
return 0;
}

ClassImp(FairMCApplication)
7 changes: 1 addition & 6 deletions base/sim/FairMCApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions examples/advanced/propagator/src/FairTutPropDet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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.
Expand All @@ -112,7 +113,7 @@ Bool_t FairTutPropDet::ProcessHits(FairVolume* vol)
stack->AddPoint(kTutProp);
}

return kTRUE;
return;
}

void FairTutPropDet::EndOfEvent() { fFairTutPropPointCollection->Clear(); }
Expand Down
30 changes: 15 additions & 15 deletions examples/advanced/propagator/src/FairTutPropDet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; };

Expand All @@ -96,7 +96,7 @@ class FairTutPropDet : public FairDetector
FairTutPropDet(const FairTutPropDet&);
FairTutPropDet& operator=(const FairTutPropDet&);

ClassDef(FairTutPropDet, 1);
ClassDefOverride(FairTutPropDet, 1);
};

#endif // FAIRTUTPROPDET_H

0 comments on commit 2259768

Please sign in to comment.