Skip to content
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

Geant4 sensitive detectors clean-up 6 #23480

Merged
merged 6 commits into from Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion SimG4CMS/Calo/interface/CaloHitID.h
Expand Up @@ -5,7 +5,7 @@
// HitID class for storing unique identifier of a Calorimetric Hit
///////////////////////////////////////////////////////////////////////////////

#include <boost/cstdint.hpp>
#include <cstdint>
#include <iostream>

class CaloHitID {
Expand Down
3 changes: 0 additions & 3 deletions SimG4CMS/Calo/interface/CaloSD.h
Expand Up @@ -26,9 +26,6 @@
#include "G4Track.hh"
#include "G4VGFlashSensitiveDetector.hh"

#include <cstdint>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>

Expand Down
2 changes: 1 addition & 1 deletion SimG4CMS/Calo/interface/HcalNumberingScheme.h
Expand Up @@ -8,7 +8,7 @@
#include "Geometry/CaloGeometry/interface/CaloNumberingScheme.h"
#include "Geometry/HcalCommonData/interface/HcalNumberingFromDDD.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <boost/cstdint.hpp>
#include <cstdint>

class HcalNumberingScheme : public CaloNumberingScheme {

Expand Down
15 changes: 9 additions & 6 deletions SimG4CMS/Calo/src/CaloSD.cc
Expand Up @@ -20,6 +20,9 @@
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"

#include <iostream>
#include <fstream>

//#define DebugLog

CaloSD::CaloSD(const std::string& name, const DDCompactView & cpv,
Expand Down Expand Up @@ -402,7 +405,7 @@ CaloG4Hit* CaloSD::createNewHit(const G4Step* aStep) {
<< " save: " << (etrack >= energyCut || forceSave);
#endif
if (etrack >= energyCut || forceSave) {
TrackInformation* trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
TrackInformation* trkInfo = cmsTrackInformation(theTrack);
trkInfo->storeTrack(true);
trkInfo->putInHistory();
}
Expand Down Expand Up @@ -492,7 +495,7 @@ void CaloSD::update(const BeginOfEvent *) {

void CaloSD::update(const EndOfTrack * trk) {
int id = (*trk)()->GetTrackID();
TrackInformation *trkI =(TrackInformation *)((*trk)()->GetUserInformation());
TrackInformation *trkI = cmsTrackInformation((*trk)());
int lastTrackID = -1;
if (trkI) lastTrackID = trkI->getIDonCaloSurface();
if (id == lastTrackID) {
Expand Down Expand Up @@ -591,7 +594,7 @@ int CaloSD::getTrackID(const G4Track* aTrack) {

int primaryID = 0;
forceSave = false;
TrackInformation* trkInfo=(TrackInformation *)(aTrack->GetUserInformation());
TrackInformation* trkInfo = cmsTrackInformation(aTrack);
if (trkInfo) {
primaryID = trkInfo->getIDonCaloSurface();
#ifdef DebugLog
Expand All @@ -612,7 +615,7 @@ int CaloSD::getTrackID(const G4Track* aTrack) {
int CaloSD::setTrackID(const G4Step* aStep) {

auto const theTrack = aStep->GetTrack();
TrackInformation * trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
TrackInformation * trkInfo = cmsTrackInformation(theTrack);
int primaryID = trkInfo->getIDonCaloSurface();
if (primaryID == 0) { primaryID = theTrack->GetTrackID(); }

Expand Down Expand Up @@ -643,7 +646,7 @@ bool CaloSD::filterHit(CaloG4Hit* hit, double time) {
double CaloSD::getResponseWt(const G4Track* aTrack) {
double wt = 1.0;
if (meanResponse.get()) {
TrackInformation * trkInfo = (TrackInformation *)(aTrack->GetUserInformation());
TrackInformation * trkInfo = cmsTrackInformation(aTrack);
wt = meanResponse.get()->getWeight(trkInfo->genParticlePID(), trkInfo->genParticleP());
}
return wt;
Expand Down Expand Up @@ -697,7 +700,7 @@ bool CaloSD::saveHit(CaloG4Hit* aHit) {

void CaloSD::update(const BeginOfTrack * trk) {
int primary = -1;
TrackInformation * trkInfo = (TrackInformation *)((*trk)()->GetUserInformation());
TrackInformation * trkInfo = cmsTrackInformation((*trk)());
if ( trkInfo->isPrimary() ) primary = (*trk)()->GetTrackID();

#ifdef DebugLog
Expand Down
1 change: 0 additions & 1 deletion SimG4CMS/Calo/src/HCalSD.cc
Expand Up @@ -561,7 +561,6 @@ void HCalSD::update(const BeginOfJob * job) {
}

void HCalSD::initRun() {
edm::LogWarning("HcalSim") << "InitRun for HFFFFF ";
if (showerLibrary.get()) showerLibrary.get()->initRun(nullptr, hcalConstants);
if (showerParam.get()) showerParam.get()->initRun(hcalConstants);
if (hfshower.get()) hfshower.get()->initRun(hcalConstants);
Expand Down
7 changes: 4 additions & 3 deletions SimG4CMS/Muon/BuildFile.xml
@@ -1,8 +1,9 @@
<use name="SimG4Core/SensitiveDetector"/>
<use name="SimG4Core/Notification"/>
<use name="boost"/>
<use name="geant4core"/>
<use name="SimG4Core/Physics"/>
<use name="SimDataFormats/SimHitMaker"/>
<use name="SimG4Core/Application"/>
<use name="Geometry/MuonNumbering"/>
<use name="boost"/>
<use name="geant4core"/>
<use name="hepmc"/>
<flags EDM_PLUGIN="1"/>
11 changes: 4 additions & 7 deletions SimG4CMS/Muon/interface/MuonFrameRotation.h
Expand Up @@ -10,19 +10,16 @@
* Make it base class of each detector FrameRotation
*/

#include "G4Step.hh"
#include "DataFormats/GeometryVector/interface/LocalPoint.h"

class MuonSubDetector;
class DDCompactView;
class G4Step;

class MuonFrameRotation {
public:
MuonFrameRotation( ) { };
virtual ~MuonFrameRotation(){};
virtual Local3DPoint transformPoint(const Local3DPoint &,const G4Step *) const = 0;
MuonFrameRotation() {};
virtual ~MuonFrameRotation() {};
virtual Local3DPoint transformPoint(const Local3DPoint &,const G4Step *) const;

private:
};

#endif
3 changes: 1 addition & 2 deletions SimG4CMS/Muon/interface/MuonGEMFrameRotation.h
Expand Up @@ -14,9 +14,8 @@
#include "SimG4CMS/Muon/interface/MuonFrameRotation.h"
#include "SimG4CMS/Muon/interface/MuonG4Numbering.h"

#include "G4Step.hh"

class MuonDDDConstants;
class G4Step;

class MuonGEMFrameRotation : public MuonFrameRotation {

Expand Down
69 changes: 26 additions & 43 deletions SimG4CMS/Muon/interface/MuonSensitiveDetector.h
Expand Up @@ -15,18 +15,11 @@
* Add SimTracks selection
*/

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "SimG4Core/Notification/interface/Observer.h"
#include "SimG4Core/Notification/interface/BeginOfEvent.h"
#include "SimG4Core/Notification/interface/EndOfEvent.h"
#include "SimG4Core/SensitiveDetector/interface/SensitiveTkDetector.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "DataFormats/GeometryVector/interface/LocalPoint.h"

#include "G4Step.hh"
#include "G4StepPoint.hh"
#include "G4Track.hh"

#include <string>

class MuonSlaveSD;
Expand All @@ -36,22 +29,18 @@ class UpdatablePSimHit;
class MuonSubDetector;
class MuonG4Numbering;
class SimHitPrinter;
class TrackInformation;
class G4Track;
class G4Step;
class G4ProcessTypeEnumerator;
class G4TrackToParticleID;
class SimTrackManager;

class MuonSensitiveDetector :
public SensitiveTkDetector,
public Observer<const BeginOfEvent*>,
public Observer<const EndOfEvent*>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@civanch there is no action in the EndOfEvent, this is the reason to remove this line, am I correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if methods will not be empty, they may be returned back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiocos , one of the goals of this clean-up is to take out methods/code which doing nothing but is copy/paste from one SD class to another.

{

public:
MuonSensitiveDetector(const std::string&, const DDCompactView &,
const SensitiveDetectorCatalog &, edm::ParameterSet const &,
const SimTrackManager*);
public Observer<const BeginOfEvent*>
{
public:
explicit MuonSensitiveDetector(const std::string&, const DDCompactView &,
const SensitiveDetectorCatalog &, edm::ParameterSet const &,
const SimTrackManager*);
~MuonSensitiveDetector() override;
G4bool ProcessHits(G4Step *,G4TouchableHistory *) override;
uint32_t setDetUnitId(const G4Step *) override;
Expand All @@ -60,58 +49,52 @@ public Observer<const EndOfEvent*>
void fillHits(edm::PSimHitContainer&, const std::string&) override;
void clearHits() override;

std::string type();

const MuonSlaveSD* GetSlaveMuon() const {
return slaveMuon; }

private:
void update(const BeginOfEvent *) override;
void update(const ::EndOfEvent *) override;

Local3DPoint toOrcaRef(Local3DPoint in ,G4Step *);
Local3DPoint toOrcaUnits(const Local3DPoint&);
Global3DPoint toOrcaUnits(const Global3DPoint&);
protected:

void update(const BeginOfEvent *) override;

private:

TrackInformation* getOrCreateTrackInformation( const G4Track* theTrack );
inline Local3DPoint cmsUnits(const Local3DPoint& v)
{ return Local3DPoint(v.x()*0.1, v.y()*0.1, v.z()*0.1); }

private:
MuonSlaveSD* slaveMuon;
MuonSimHitNumberingScheme* numbering;
MuonSubDetector* detector;
MuonFrameRotation* theRotation;
MuonG4Numbering* g4numbering;

void storeVolumeAndTrack(const G4Step *);
bool newHit(G4Step *);
void createHit(G4Step *);
void updateHit(G4Step *);
bool newHit(const G4Step *);
void createHit(const G4Step *);
void updateHit(const G4Step *);
void saveHit();

/**
* Transform from local coordinates of a volume to local coordinates of a parent volume
* one or more levels up the volume hierarchy: e.g. levelsUp = 1 for immediate parent. <BR>
* one or more levels up the volume hierarchy: e.g. levelsUp = 1 for immediate parent.
* This is done by moving from local_1 -> global -> local_2.
*/
Local3DPoint InitialStepPositionVsParent(G4Step * currentStep, G4int levelsUp);
Local3DPoint FinalStepPositionVsParent(G4Step * currentStep, G4int levelsUp);
Local3DPoint InitialStepPositionVsParent(const G4Step * currentStep, G4int levelsUp);
Local3DPoint FinalStepPositionVsParent(const G4Step * currentStep, G4int levelsUp);

G4VPhysicalVolume * thePV;
const G4VPhysicalVolume* thePV;
UpdatablePSimHit* theHit;
uint32_t theDetUnitId;
unsigned int theTrackID;
uint32_t theDetUnitId;
uint32_t newDetUnitId;
int theTrackID;

bool printHits;
SimHitPrinter* thePrinter;
Global3DPoint theGlobalEntry;

//--- SimTracks cuts
double STenergyPersistentCut;
bool STallMuonsPersistent;
float ePersistentCutGeV;
bool allMuonsPersistent;

G4ProcessTypeEnumerator* theG4ProcessTypeEnumerator;

G4TrackToParticleID* myG4TrackToParticleID;
const SimTrackManager* theManager;
};

Expand Down
19 changes: 7 additions & 12 deletions SimG4CMS/Muon/src/MuonEndcapFrameRotation.cc
@@ -1,22 +1,17 @@
#include "SimG4CMS/Muon/interface/MuonEndcapFrameRotation.h"
#include "SimG4Core/SensitiveDetector/interface/FrameRotation.h"

#include "G4Step.hh"
#include "G4StepPoint.hh"
#include "G4TouchableHistory.hh"

Local3DPoint MuonEndcapFrameRotation::transformPoint(const Local3DPoint & point,const G4Step * s=nullptr) const {
if (!s)
return Local3DPoint(0.,0.,0.);
Local3DPoint MuonEndcapFrameRotation::transformPoint(const Local3DPoint& point,const G4Step* step) const {

const G4StepPoint * preStepPoint = s->GetPreStepPoint();
const G4StepPoint * preStepPoint = step->GetPreStepPoint();
const G4TouchableHistory * theTouchable = (const G4TouchableHistory *)preStepPoint->GetTouchable();
const G4ThreeVector& trans=theTouchable->GetTranslation();

if (trans.z()<0) {
// return Local3DPoint(point.x(),-point.z(),point.y());
// return Local3DPoint(-point.x(),point.z(),-point.y());
return Local3DPoint(-point.x(),-point.z(),-point.y());
} else {
// return Local3DPoint(point.x(),point.z(),-point.y());
return Local3DPoint(point.x(),point.z(),-point.y());
}
return (trans.z()<0)
? Local3DPoint(-point.x(),-point.z(),-point.y())
: Local3DPoint(point.x(),point.z(),-point.y());
}
6 changes: 6 additions & 0 deletions SimG4CMS/Muon/src/MuonFrameRotation.cc
@@ -0,0 +1,6 @@
#include "SimG4CMS/Muon/interface/MuonFrameRotation.h"
#include "G4Step.hh"

Local3DPoint MuonFrameRotation::transformPoint(const Local3DPoint& point,const G4Step*) const {
return point;
}
17 changes: 5 additions & 12 deletions SimG4CMS/Muon/src/MuonGEMFrameRotation.cc
Expand Up @@ -2,27 +2,20 @@
#include "Geometry/MuonNumbering/interface/MuonDDDConstants.h"
#include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"

#include "G4StepPoint.hh"
#include "G4TouchableHistory.hh"
#include "G4Step.hh"

//#define LOCAL_DEBUG

MuonGEMFrameRotation::MuonGEMFrameRotation(const MuonDDDConstants& muonConstants) : MuonFrameRotation::MuonFrameRotation() {
MuonGEMFrameRotation::MuonGEMFrameRotation(const MuonDDDConstants& muonConstants)
: MuonFrameRotation::MuonFrameRotation() {
g4numbering = new MuonG4Numbering(muonConstants);
int theLevelPart= muonConstants.getValue("level");
theSectorLevel = muonConstants.getValue("mg_sector")/theLevelPart;
#ifdef LOCAL_DEBUG
std::cout << "MuonGEMFrameRotation: theSectorLevel " << theSectorLevel
<< std::endl;
#endif
}

MuonGEMFrameRotation::~MuonGEMFrameRotation() {
delete g4numbering;
}

Local3DPoint MuonGEMFrameRotation::transformPoint(const Local3DPoint & point,const G4Step * aStep=nullptr) const {
if (!aStep) return Local3DPoint(0.,0.,0.);

Local3DPoint MuonGEMFrameRotation::transformPoint(const Local3DPoint & point,const G4Step *) const {
//---VI: theSectorLevel and g4numbering are not used
return Local3DPoint(point.x(),point.z(),-point.y());
}
22 changes: 8 additions & 14 deletions SimG4CMS/Muon/src/MuonME0FrameRotation.cc
Expand Up @@ -3,29 +3,23 @@
#include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "G4StepPoint.hh"
#include "G4TouchableHistory.hh"
#include "G4Step.hh"

//#define LOCAL_DEBUG

MuonME0FrameRotation::MuonME0FrameRotation(const MuonDDDConstants& muonConstants) : MuonFrameRotation::MuonFrameRotation() {
MuonME0FrameRotation::MuonME0FrameRotation(const MuonDDDConstants& muonConstants)
: MuonFrameRotation::MuonFrameRotation() {
g4numbering = new MuonG4Numbering(muonConstants);
int theLevelPart= muonConstants.getValue("level");
theSectorLevel = muonConstants.getValue("mg_sector")/theLevelPart;
#ifdef LOCAL_DEBUG
std::cout << "MuonME0FrameRotation: theSectorLevel " << theSectorLevel
<< std::endl;
#endif
edm::LogVerbatim("MuonME0FrameRotation")<<"MuonME0FrameRotation: theSectorLevel " << theSectorLevel;
edm::LogVerbatim("MuonME0FrameRotation")
<<"MuonME0FrameRotation: theSectorLevel " << theSectorLevel;
}

MuonME0FrameRotation::~MuonME0FrameRotation() {
delete g4numbering;
}

Local3DPoint MuonME0FrameRotation::transformPoint(const Local3DPoint & point,const G4Step * aStep=nullptr) const {
if (!aStep) return Local3DPoint(0.,0.,0.);

edm::LogVerbatim("MuonME0FrameRotation")<<"MuonME0FrameRotation transformPoint :: Local3DPoint (" <<point.x()<<","<<point.z()<<","<<-point.y()<<")" ;
Local3DPoint
MuonME0FrameRotation::transformPoint(const Local3DPoint& point,const G4Step *) const {
//---VI: sector level and g4numbering are not used
return Local3DPoint(point.x(),point.z(),-point.y());
}