New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup Geant4 sensitive detectors #19939
Changes from 6 commits
a996c0d
24b53ba
11b9b63
2e296d9
d54d821
fc6048c
f26db6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,21 +19,26 @@ | |
#include "G4SystemOfUnits.hh" | ||
#include "G4PhysicalConstants.hh" | ||
|
||
//#define DebugLog | ||
// #define DebugLog | ||
|
||
CaloSD::CaloSD(G4String name, const DDCompactView & cpv, | ||
const SensitiveDetectorCatalog & clg, | ||
edm::ParameterSet const & p, const SimTrackManager* manager, | ||
float timeSliceUnit, bool ignoreTkID) : | ||
SensitiveCaloDetector(name, cpv, clg, p), | ||
G4VGFlashSensitiveDetector(), theTrack(0), preStepPoint(0), eminHit(0), | ||
eminHitD(0), m_trackManager(manager), currentHit(0), runInit(false), | ||
timeSlice(timeSliceUnit), ignoreTrackID(ignoreTkID), hcID(-1), theHC(0), | ||
meanResponse(0) { | ||
//Add Hcal Sentitive Detector Names | ||
G4VGFlashSensitiveDetector(), theTrack(nullptr), theTouchableHistory(nullptr), | ||
preStepPoint(nullptr), eminHit(0.0), eminHitD(0.0), m_trackManager(manager), | ||
currentHit(nullptr), runInit(false), timeSlice(timeSliceUnit), | ||
ignoreTrackID(ignoreTkID), hcID(-1), theHC(nullptr), meanResponse(nullptr) { | ||
|
||
//Add Hcal Sentitive Detector Names | ||
collectionName.insert(name); | ||
|
||
// initialisation | ||
incidentEnergy = edepositEM = edepositHAD = 0.0f; | ||
primIDSaved = -99; | ||
emPDG = epPDG = gammaPDG = 0; | ||
|
||
//Parameters | ||
edm::ParameterSet m_CaloSD = p.getParameter<edm::ParameterSet>("CaloSD"); | ||
energyCut = m_CaloSD.getParameter<double>("EminTrack")*GeV; | ||
|
@@ -111,43 +116,38 @@ CaloSD::CaloSD(G4String name, const DDCompactView & cpv, | |
} | ||
|
||
CaloSD::~CaloSD() { | ||
if (slave) delete slave; | ||
if (theHC) delete theHC; | ||
if (meanResponse) delete meanResponse; | ||
delete slave; | ||
delete theHC; | ||
delete meanResponse; | ||
} | ||
|
||
bool CaloSD::ProcessHits(G4Step * aStep, G4TouchableHistory * ) { | ||
bool CaloSD::ProcessHits(G4Step * aStep, G4TouchableHistory * tHistory) { | ||
|
||
NaNTrap( aStep ) ; | ||
|
||
if (aStep == NULL) { | ||
return true; | ||
} else { | ||
if (getStepInfo(aStep)) { | ||
if (hitExists() == false && edepositEM+edepositHAD>0.) | ||
currentHit = createNewHit(); | ||
} | ||
NaNTrap(aStep); | ||
theTouchableHistory = tHistory; | ||
if(getStepInfo(aStep) && !hitExists() && edepositEM+edepositHAD>0.f) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hi @civanch - so no need to protect against aStep=nullptr now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was never needed and likely is left in many SD classes due to historical reasons. There is also NaNTrap - I am not sure how it is useful, I personally prefer if FPE arithmetic checks are enabled on compiler level in jenkins tests and RelVal tests, home made NaNTrap looks strange, however, in this PR it is simplified, so cost much less than before. |
||
currentHit = createNewHit(); | ||
} | ||
return true; | ||
} | ||
|
||
bool CaloSD::ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) { | ||
|
||
if (aSpot != NULL) { | ||
if (aSpot != nullptr) { | ||
theTrack = const_cast<G4Track *>(aSpot->GetOriginatorTrack()->GetPrimaryTrack()); | ||
G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding(); | ||
|
||
if (particleCode == emPDG || | ||
particleCode == epPDG || | ||
particleCode == gammaPDG ) { | ||
edepositEM = aSpot->GetEnergySpot()->GetEnergy(); | ||
edepositHAD = 0.; | ||
edepositHAD = 0.f; | ||
} else { | ||
edepositEM = 0.; | ||
edepositHAD = 0.; | ||
edepositEM = 0.f; | ||
edepositHAD = 0.f; | ||
} | ||
|
||
if (edepositEM>0.) { | ||
if (edepositEM>0.f) { | ||
G4Step * fFakeStep = new G4Step(); | ||
preStepPoint = fFakeStep->GetPreStepPoint(); | ||
G4StepPoint * fFakePostStepPoint = fFakeStep->GetPostStepPoint(); | ||
|
@@ -224,10 +224,9 @@ void CaloSD::EndOfEvent(G4HCofThisEvent* ) { | |
|
||
cleanHitCollection(); | ||
|
||
#ifdef DebugLog | ||
edm::LogInfo("CaloSim") << "CaloSD: EndofEvent entered with " << theHC->entries() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @civanch - it may bring some extra output which was turned off with #ifdef DebugLog |
||
<< " entries"; | ||
#endif | ||
|
||
// TimeMe("CaloSD:sortAndMergeHits",false); | ||
} | ||
|
||
|
@@ -252,30 +251,27 @@ bool CaloSD::getStepInfo(G4Step* aStep) { | |
preStepPoint = aStep->GetPreStepPoint(); | ||
theTrack = aStep->GetTrack(); | ||
|
||
double time = (aStep->GetPostStepPoint()->GetGlobalTime())/nanosecond; | ||
unsigned int unitID= setDetUnitId(aStep); | ||
uint16_t depth = getDepth(aStep); | ||
int primaryID = getTrackID(theTrack); | ||
|
||
bool flag = (unitID > 0); | ||
if (flag) { | ||
double time = theTrack->GetGlobalTime()/CLHEP::nanosecond; | ||
uint16_t depth = getDepth(aStep); | ||
int primaryID = getTrackID(theTrack); | ||
currentID.setID(unitID, time, primaryID, depth); | ||
|
||
#ifdef DebugLog | ||
G4TouchableHistory* touch =(G4TouchableHistory*)(theTrack->GetTouchable()); | ||
edm::LogInfo("CaloSim") << "CaloSD:: GetStepInfo for" | ||
<< " PV " << touch->GetVolume(0)->GetName() | ||
<< " PVid = " << touch->GetReplicaNumber(0) | ||
<< " MVid = " << touch->GetReplicaNumber(1) | ||
<< " PV " << theTouchableHistory->GetVolume(0)->GetName() | ||
<< " PVid = " << theTouchableHistory->GetReplicaNumber(0) | ||
<< " MVid = " << theTouchableHistory->GetReplicaNumber(1) | ||
<< " Unit " << currentID.unitID() | ||
<< " Edeposit = " << edepositEM << " " << edepositHAD; | ||
<< " Edeposit = " << aStep->GetTotalEnergyDeposit(); | ||
} else { | ||
G4TouchableHistory* touch =(G4TouchableHistory*)(theTrack->GetTouchable()); | ||
edm::LogInfo("CaloSim") << "CaloSD:: GetStepInfo for" | ||
<< " PV " << touch->GetVolume(0)->GetName() | ||
<< " PVid = " << touch->GetReplicaNumber(0) | ||
<< " MVid = " << touch->GetReplicaNumber(1) | ||
<< " Unit " << std::hex << unitID << std::dec | ||
<< " Edeposit = " << edepositEM << " " << edepositHAD; | ||
<< " PV " << theTouchableHistory->GetVolume(0)->GetName() | ||
<< " PVid = " << theTouchableHistory->GetReplicaNumber(0) | ||
<< " MVid = " << theTouchableHistory->GetReplicaNumber(1) | ||
<< " Unit " << std::hex << unitID << std::dec; | ||
#endif | ||
} | ||
|
||
|
@@ -284,9 +280,9 @@ bool CaloSD::getStepInfo(G4Step* aStep) { | |
particleCode == epPDG || | ||
particleCode == gammaPDG ) { | ||
edepositEM = getEnergyDeposit(aStep); | ||
edepositHAD = 0.; | ||
edepositHAD = 0.f; | ||
} else { | ||
edepositEM = 0.; | ||
edepositEM = 0.f; | ||
edepositHAD = getEnergyDeposit(aStep); | ||
} | ||
|
||
|
@@ -433,7 +429,7 @@ CaloG4Hit* CaloSD::createNewHit() { | |
} | ||
} | ||
primIDSaved = currentID.trackID(); | ||
if (useMap) totalHits++; | ||
if (useMap) ++totalHits; | ||
return aHit; | ||
} | ||
|
||
|
@@ -490,10 +486,8 @@ void CaloSD::update(const BeginOfRun *) { | |
emPDG = theParticleTable->FindParticle(particleName="e-")->GetPDGEncoding(); | ||
epPDG = theParticleTable->FindParticle(particleName="e+")->GetPDGEncoding(); | ||
gammaPDG = theParticleTable->FindParticle(particleName="gamma")->GetPDGEncoding(); | ||
#ifdef DebugLog | ||
edm::LogInfo("CaloSim") << "CaloSD: Particle code for e- = " << emPDG | ||
<< " for e+ = " << epPDG << " for gamma = " << gammaPDG; | ||
#endif | ||
initRun(); | ||
runInit = true; | ||
} | ||
|
@@ -615,7 +609,7 @@ double CaloSD::getResponseWt(G4Track* aTrack) { | |
|
||
void CaloSD::storeHit(CaloG4Hit* hit) { | ||
if (previousID.trackID()<0) return; | ||
if (hit == 0) { | ||
if (hit == nullptr) { | ||
edm::LogWarning("CaloSim") << "CaloSD: hit to be stored is NULL !!"; | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -522,7 +522,7 @@ bool DreamSD::setPbWO2MaterialProperties_( G4Material* aMaterial ) { | |
// Calculate Cherenkov angle integrals: | ||
// This is an ad-hoc solution (we hold it in the class, not in the material) | ||
chAngleIntegrals_ = | ||
std::auto_ptr<G4PhysicsOrderedFreeVector>( new G4PhysicsOrderedFreeVector() ); | ||
std::unique_ptr<G4PhysicsOrderedFreeVector>( new G4PhysicsOrderedFreeVector() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @civanch - it is better to use std::make_unique |
||
|
||
int index = 0; | ||
double currentRI = RefractiveIndex[index]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ DDDWorld::DDDWorld(const DDCompactView* cpv, | |
SensitiveDetectorCatalog & catalog, | ||
bool check) { | ||
|
||
std::auto_ptr<DDG4Builder> theBuilder(new DDG4Builder(cpv, check)); | ||
std::unique_ptr<DDG4Builder> theBuilder(new DDG4Builder(cpv, check)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto theBuilder = std::make_unique(cpv, check); |
||
|
||
DDGeometryReturnType ret = theBuilder->BuildGeometry(); | ||
G4LogicalVolume * world = ret.logicalVolume(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,8 +53,8 @@ class GeometryProducer : public edm::one::EDProducer<edm::one::SharedResources, | |
SimActivityRegistry m_registry; | ||
std::vector<std::shared_ptr<SimWatcher> > m_watchers; | ||
std::vector<std::shared_ptr<SimProducer> > m_producers; | ||
std::auto_ptr<sim::FieldBuilder> m_fieldBuilder; | ||
std::auto_ptr<SimTrackManager> m_trackManager; | ||
std::unique_ptr<sim::FieldBuilder> m_fieldBuilder; | ||
std::unique_ptr<SimTrackManager> m_trackManager; | ||
AttachSD * m_attach; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this is a raw pointer? |
||
std::vector<SensitiveTkDetector*> m_sensTkDets; | ||
std::vector<SensitiveCaloDetector*> m_sensCaloDets; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,8 +134,8 @@ void GeometryProducer::produce(edm::Event & e, const edm::EventSetup & es) | |
{ | ||
edm::LogInfo("GeometryProducer") << " instantiating sensitive detectors "; | ||
// instantiate and attach the sensitive detectors | ||
m_trackManager = std::auto_ptr<SimTrackManager>(new SimTrackManager); | ||
if (m_attach==0) m_attach = new AttachSD; | ||
m_trackManager = std::unique_ptr<SimTrackManager>(new SimTrackManager); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::make_unique |
||
if (m_attach == nullptr) m_attach = new AttachSD; | ||
{ | ||
std::pair< std::vector<SensitiveTkDetector*>, | ||
std::vector<SensitiveCaloDetector*> > | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,22 +34,25 @@ class SensitiveDetector : public G4VSensitiveDetector | |
virtual void AssignSD(const std::string & vname); | ||
virtual void EndOfEvent(G4HCofThisEvent * eventHC); | ||
enum coordinates {WorldCoordinates, LocalCoordinates}; | ||
Local3DPoint InitialStepPosition(G4Step * s, coordinates); | ||
Local3DPoint FinalStepPosition(G4Step * s, coordinates); | ||
Local3DPoint ConvertToLocal3DPoint(const G4ThreeVector& point); | ||
std::string nameOfSD() { return name; } | ||
Local3DPoint InitialStepPosition(G4Step * step, coordinates); | ||
Local3DPoint FinalStepPosition(G4Step * step, coordinates); | ||
inline Local3DPoint ConvertToLocal3DPoint(const G4ThreeVector& point) | ||
{ | ||
Local3DPoint res(point.x(),point.y(),point.z()); | ||
return std::move(res); | ||
} | ||
inline std::string& nameOfSD() { return name; } | ||
virtual std::vector<std::string> getNames() | ||
{ | ||
std::vector<std::string> temp; | ||
temp.push_back(nameOfSD()); | ||
temp.push_back(name); | ||
return temp; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::vectorstd::string getNames() { return std::vectorstd::string{name}; }; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the second iteration likely this method should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moreover, this methods are not used... Will be removed in the next iteration. |
||
} | ||
|
||
void NaNTrap( G4Step* step ) ; | ||
|
||
private: | ||
std::string name; | ||
G4Step * currentStep; | ||
}; | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,10 @@ class SensitiveDetectorMaker : public SensitiveDetectorMakerBase | |
const edm::ParameterSet& p, | ||
const SimTrackManager* m, | ||
SimActivityRegistry& reg, | ||
std::auto_ptr<SensitiveTkDetector>& oTK, | ||
std::auto_ptr<SensitiveCaloDetector>& oCalo) const | ||
std::unique_ptr<SensitiveTkDetector>& oTK, | ||
std::unique_ptr<SensitiveCaloDetector>& oCalo) const | ||
{ | ||
std::auto_ptr<T> returnValue(new T(iname, cpv, clg, p, m)); | ||
std::unique_ptr<T> returnValue(new T(iname, cpv, clg, p, m)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::make_unique |
||
SimActivityRegistryEnroller::enroll(reg, returnValue.get()); | ||
|
||
this->convertTo(returnValue.get(), oTK,oCalo); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,8 @@ class SensitiveDetectorMakerBase | |
const edm::ParameterSet& p, | ||
const SimTrackManager* m, | ||
SimActivityRegistry& reg, | ||
std::auto_ptr<SensitiveTkDetector>& oTK, | ||
std::auto_ptr<SensitiveCaloDetector>& oCalo) const =0; | ||
std::unique_ptr<SensitiveTkDetector>& oTK, | ||
std::unique_ptr<SensitiveCaloDetector>& oCalo) const =0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. passing a reference to a unique pointer without transferring ownership may cause trouble if an owner decides to reset it. Would a shared_ptr be safer here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is used only at initialisation and it is its only function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have the same concern - so these functions do not keep this pointer around internally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class does not create unique_ptr but only use them as input to check, if the SD class is tracker or calo. |
||
|
||
// ---------- static member functions -------------------- | ||
|
||
|
@@ -57,14 +57,14 @@ class SensitiveDetectorMakerBase | |
protected: | ||
//used to identify which type of Sensitive Detector we have | ||
void convertTo( SensitiveTkDetector* iFrom, | ||
std::auto_ptr<SensitiveTkDetector>& oTo, | ||
std::auto_ptr<SensitiveCaloDetector>&) const{ | ||
oTo= std::auto_ptr<SensitiveTkDetector>(iFrom); | ||
std::unique_ptr<SensitiveTkDetector>& oTo, | ||
std::unique_ptr<SensitiveCaloDetector>&) const{ | ||
oTo= std::unique_ptr<SensitiveTkDetector>(iFrom); | ||
} | ||
void convertTo( SensitiveCaloDetector* iFrom, | ||
std::auto_ptr<SensitiveTkDetector>&, | ||
std::auto_ptr<SensitiveCaloDetector>& oTo) const{ | ||
oTo=std::auto_ptr<SensitiveCaloDetector>(iFrom); | ||
std::unique_ptr<SensitiveTkDetector>&, | ||
std::unique_ptr<SensitiveCaloDetector>& oTo) const{ | ||
oTo=std::unique_ptr<SensitiveCaloDetector>(iFrom); | ||
} | ||
|
||
private: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@civanch - I'd add a space before aSpot