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

Run3-gex83B Convert all SD's in SimG4CMS/ShowerLibraryProducer using the new way of initiating #34510

Merged
merged 2 commits into from Jul 16, 2021
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
17 changes: 17 additions & 0 deletions SimG4CMS/ShowerLibraryProducer/data/CaloUtil.xml
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<DDDefinition>
<SpecParSection label="caloutil.xml" eval="true">
<SpecPar name="calo">
<PartSelector path="//HFWorld"/>
<Parameter name="SensitiveDetector" value="CaloTrkProcessing" eval="false"/>
<Parameter name="ReadOutName" value="CaloHitsTk" eval="false"/>
<Parameter name="Calorimeter" value="HFWedge" eval="false"/>
<Parameter name="Levels" value="2" eval="true"/>
<Parameter name="Neighbours" value="1" eval="true"/>
<Parameter name="Inside" value="NotFound" eval="false"/>
<Parameter name="InsideLevel" value="3" eval="true"/>
<Parameter name="FineCalorimeter" value="HFwedge" eval="false"/>
<Parameter name="FineLevels" value="1" eval="true"/>
</SpecPar>
</SpecParSection>
</DDDefinition>
19 changes: 9 additions & 10 deletions SimG4CMS/ShowerLibraryProducer/interface/FiberSensitiveDetector.h
Expand Up @@ -27,17 +27,17 @@ class G4Step;
class G4HCofThisEvent;

class FiberSensitiveDetector : public SensitiveCaloDetector,
public Observer<const BeginOfJob *>,
public Observer<const BeginOfRun *>,
public Observer<const BeginOfEvent *>,
public Observer<const EndOfEvent *> {
public Observer<const BeginOfJob *>,
public Observer<const BeginOfRun *>,
public Observer<const BeginOfEvent *>,
public Observer<const EndOfEvent *> {
public:
explicit FiberSensitiveDetector(const std::string &,
const HcalSimulationConstants*,
const HcalDDDSimConstants*,
const SensitiveDetectorCatalog &,
edm::ParameterSet const &,
const SimTrackManager *);
const HcalSimulationConstants *,
const HcalDDDSimConstants *,
const SensitiveDetectorCatalog &,
edm::ParameterSet const &,
const SimTrackManager *);
~FiberSensitiveDetector() override;

void Initialize(G4HCofThisEvent *HCE) override;
Expand All @@ -58,7 +58,6 @@ class FiberSensitiveDetector : public SensitiveCaloDetector,
void update(const ::EndOfEvent *) override;

private:
const SimTrackManager *m_trackManager;
HFShower *theShower;

G4int theHCID;
Expand Down
@@ -1,5 +1,5 @@
#ifndef SimG4CMS_ShowerLibraryProducer_HFChamberSD_h
#define SimG4CMS_ShowerLibraryProducer_HFChamberSD_h
#ifndef SimG4CMS_ShowerLibraryProducer_HFChamberSensitiveDetector_h
#define SimG4CMS_ShowerLibraryProducer_HFChamberSensitiveDetector_h

#include "SimG4Core/SensitiveDetector/interface/SensitiveCaloDetector.h"
#include "SimG4Core/Notification/interface/SimTrackManager.h"
Expand All @@ -18,14 +18,12 @@
class G4Step;
class G4HCofThisEvent;

class HFChamberSD : public SensitiveCaloDetector {
class HFChamberSensitiveDetector : public SensitiveCaloDetector {
public:
explicit HFChamberSD(const std::string&,
const edm::EventSetup&,
const SensitiveDetectorCatalog&,
const edm::ParameterSet&,
const SimTrackManager*);
~HFChamberSD() override;
explicit HFChamberSensitiveDetector(const std::string&,
const SensitiveDetectorCatalog&,
const SimTrackManager*);
~HFChamberSensitiveDetector() override;

void Initialize(G4HCofThisEvent* HCE) override;
G4bool ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist) override;
Expand All @@ -39,8 +37,6 @@ class HFChamberSD : public SensitiveCaloDetector {
void fillHits(edm::PCaloHitContainer&, const std::string&) override;

private:
const SimTrackManager* m_trackManager;

G4int theHCID;
HFShowerG4HitsCollection* theHC;
int theNSteps;
Expand Down
@@ -1,5 +1,5 @@
#ifndef SimG4CMS_ShowerLibraryProducer_HFWedgeSD_h
#define SimG4CMS_ShowerLibraryProducer_HFWedgeSD_h
#ifndef SimG4CMS_ShowerLibraryProducer_HFWedgeSensitiveDetector_h
#define SimG4CMS_ShowerLibraryProducer_HFWedgeSensitiveDetector_h

#include "SimG4Core/SensitiveDetector/interface/SensitiveCaloDetector.h"
#include "SimG4Core/Notification/interface/SimTrackManager.h"
Expand All @@ -17,14 +17,12 @@
class G4Step;
class G4HCofThisEvent;

class HFWedgeSD : public SensitiveCaloDetector {
class HFWedgeSensitiveDetector : public SensitiveCaloDetector {
public:
explicit HFWedgeSD(const std::string&,
const edm::EventSetup& cpv,
const SensitiveDetectorCatalog& clg,
edm::ParameterSet const& p,
const SimTrackManager*);
~HFWedgeSD() override;
explicit HFWedgeSensitiveDetector(const std::string&,
const SensitiveDetectorCatalog& clg,
const SimTrackManager*);
~HFWedgeSensitiveDetector() override;

void Initialize(G4HCofThisEvent* HCE) override;
bool ProcessHits(G4Step* step, G4TouchableHistory* tHistory) override;
Expand All @@ -43,8 +41,6 @@ class HFWedgeSD : public SensitiveCaloDetector {
void updateHit(HFShowerG4Hit*);

private:
const SimTrackManager* m_trackManager;

int hcID;
HFShowerG4HitsCollection* theHC;
std::map<int, HFShowerG4Hit*> hitMap;
Expand Down
7 changes: 0 additions & 7 deletions SimG4CMS/ShowerLibraryProducer/plugins/module.cc
@@ -1,14 +1,7 @@
#include "SimG4CMS/ShowerLibraryProducer/interface/HFWedgeSD.h"
#include "SimG4CMS/ShowerLibraryProducer/interface/HFChamberSD.h"
#include "SimG4CMS/ShowerLibraryProducer/interface/HcalForwardAnalysis.h"
#include "SimG4CMS/ShowerLibraryProducer/interface/CastorShowerLibraryMaker.h"
#include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h"
#include "SimG4Core/Watcher/interface/SimWatcherFactory.h"
#include "FWCore/PluginManager/interface/ModuleDef.h"

typedef HFWedgeSD HFWedgeSensitiveDetector;
DEFINE_SENSITIVEDETECTOR(HFWedgeSensitiveDetector);
typedef HFChamberSD HFChamberSensitiveDetector;
DEFINE_SENSITIVEDETECTOR(HFChamberSensitiveDetector);
DEFINE_SIMWATCHER(HcalForwardAnalysis);
DEFINE_SIMWATCHER(CastorShowerLibraryMaker);
Expand Up @@ -4,8 +4,9 @@
geomXMLFiles = cms.vstring('Geometry/CMSCommonData/data/materials.xml',
'Geometry/HcalCommonData/data/hcalforwardmaterial.xml',
'Geometry/HcalCommonData/data/hcalforwardshower/v2/hcalforwardshower.xml',
'SimG4CMS/ShowerLibraryProducer/data/CaloUtil.xml',
'Geometry/HcalCommonData/data/hcalSimNumbering/hfshower/v1/hcalSimNumbering.xml',
'Geometry/HcalCommonData/data/hcalRecNumbering/hfshower/v1/hcalRecNumbering.xml'),
'Geometry/HcalCommonData/data/hcalRecNumbering/hfshower/v1/hcalRecNumbering.xml'),
rootNodeName = cms.string('hcalforwardshower:HFWorld')
)

Expand Down
40 changes: 23 additions & 17 deletions SimG4CMS/ShowerLibraryProducer/src/FiberSensitiveDetector.cc
Expand Up @@ -17,13 +17,15 @@
#include "G4SDManager.hh"
#include "G4ios.hh"

//#define EDM_ML_DEBUG

FiberSensitiveDetector::FiberSensitiveDetector(const std::string& iname,
const HcalSimulationConstants* hsps,
const HcalDDDSimConstants* hdc,
const SensitiveDetectorCatalog& clg,
edm::ParameterSet const& p,
const SimTrackManager* manager)
: SensitiveCaloDetector(iname, clg), m_trackManager(manager), theShower(nullptr), theHCID(-1), theHC(nullptr) {
const HcalSimulationConstants* hsps,
const HcalDDDSimConstants* hdc,
const SensitiveDetectorCatalog& clg,
edm::ParameterSet const& p,
const SimTrackManager* manager)
: SensitiveCaloDetector(iname, clg), theShower(nullptr), theHCID(-1), theHC(nullptr) {
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector : Instantiating for " << iname;
// Get pointer to HcalDDDConstants and HcalSimulationConstants
theShower = new HFShower(iname, hdc, hsps->hcalsimpar(), p, 1);
Expand All @@ -35,13 +37,14 @@ FiberSensitiveDetector::~FiberSensitiveDetector() {
}

void FiberSensitiveDetector::Initialize(G4HCofThisEvent* HCE) {
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector : Initialize called for " << GetName() << " in collection " << HCE;
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector : Initialize called for " << GetName() << " in collection "
<< HCE;
theHC = new FiberG4HitsCollection(GetName(), collectionName[0]);
if (theHCID < 0)
theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
HCE->AddHitsCollection(theHCID, theHC);
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector : Add hit collectrion for " << collectionName[0] << ":" << theHCID << ":"
<< theHC;
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector : Add hit collectrion for " << collectionName[0] << ":"
<< theHCID << ":" << theHC;
}

G4bool FiberSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
Expand All @@ -68,22 +71,25 @@ G4bool FiberSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
//edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector :presteppoint position z " << preStepPoint->GetPosition().z();

FiberG4Hit* aHit = new FiberG4Hit(lv, detID, depth, trackID);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector :hit size " << hits.size() << " npe" << aHit->npe();
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector :pre hit position " << aHit->hitPos();
#endif
aHit->setNpe(hits.size());
aHit->setPos(theHitPos);
aHit->setTime(preStepPoint->GetGlobalTime());
aHit->setPhoton(thePE);
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector :ShowerPhoton position " << thePE[0].x() << " " << thePE[0].y() << " "
<< thePE[0].z();

edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector: Hit created at " << lv->GetName() << " DetID: " << aHit->towerId()
<< " Depth: " << aHit->depth() << " Track ID: " << aHit->trackId()
<< " Nb. of Cerenkov Photons: " << aHit->npe() << " Time: " << aHit->time() << " at "
<< aHit->hitPos();
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector :ShowerPhoton position " << thePE[0].x() << " "
<< thePE[0].y() << " " << thePE[0].z();

edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector: Hit created at " << lv->GetName()
<< " DetID: " << aHit->towerId() << " Depth: " << aHit->depth()
<< " Track ID: " << aHit->trackId() << " Nb. of Cerenkov Photons: " << aHit->npe()
<< " Time: " << aHit->time() << " at " << aHit->hitPos();
for (unsigned int i = 0; i < thePE.size(); i++)
edm::LogVerbatim("FiberSim") << "FiberSensitiveDetector: PE[" << i << "] " << thePE[i];

#endif
theHC->insert(aHit);
}
return true;
Expand Down
@@ -1,4 +1,4 @@
#include "SimG4CMS/ShowerLibraryProducer/interface/HFChamberSD.h"
#include "SimG4CMS/ShowerLibraryProducer/interface/HFChamberSensitiveDetector.h"
#include "DataFormats/Math/interface/Point3D.h"

#include "G4VPhysicalVolume.hh"
Expand All @@ -16,28 +16,27 @@
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"

HFChamberSD::HFChamberSD(const std::string& name,
const edm::EventSetup& es,
const SensitiveDetectorCatalog& clg,
edm::ParameterSet const& p,
const SimTrackManager* manager)
: SensitiveCaloDetector(name, clg), m_trackManager(manager), theHCID(-1), theHC(nullptr), theNSteps(0) {
edm::LogVerbatim("FiberSim") << "HFChamberSD : Instantiated for " << name;
//#define EDM_ML_DEBUG

HFChamberSensitiveDetector::HFChamberSensitiveDetector(const std::string& name,
const SensitiveDetectorCatalog& clg,
const SimTrackManager* manager)
: SensitiveCaloDetector(name, clg), theHCID(-1), theHC(nullptr), theNSteps(0) {
edm::LogVerbatim("FiberSim") << "HFChamberSensitiveDetector : Instantiated for " << name;
}

HFChamberSD::~HFChamberSD() { delete theHC; }
HFChamberSensitiveDetector::~HFChamberSensitiveDetector() { delete theHC; }

void HFChamberSD::Initialize(G4HCofThisEvent* HCE) {
edm::LogVerbatim("FiberSim") << "HFChamberSD : Initialize called for " << GetName() << " in collection " << HCE;
void HFChamberSensitiveDetector::Initialize(G4HCofThisEvent* HCE) {
edm::LogVerbatim("FiberSim") << "HFChamberSensitiveDetector : Initialize called for " << GetName() << " in collection " << HCE;
theHC = new HFShowerG4HitsCollection(GetName(), collectionName[0]);
if (theHCID < 0)
theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
HCE->AddHitsCollection(theHCID, theHC);
edm::LogVerbatim("FiberSim") << "HFChamberSD : Add hit collectrion for " << collectionName[0] << ":" << theHCID << ":"
<< theHC;
edm::LogVerbatim("FiberSim") << "HFChamberSensitiveDetector : Add hit collectrion for " << collectionName[0] << ":" << theHCID << ":" << theHC;
}

G4bool HFChamberSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
G4bool HFChamberSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
//do not process hits other than primary particle hits:
double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
int trackID = aStep->GetTrack()->GetTrackID();
Expand All @@ -64,31 +63,29 @@ G4bool HFChamberSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
aHit->setGlobalPos(globalPos);
aHit->setPrimMomDir(momDir);

edm::LogVerbatim("FiberSim") << "HFChamberSD: Hit created in (" << touch->GetVolume(0)->GetLogicalVolume()->GetName()
<< ") ID " << detID << " Track " << trackID << " Edep: " << edep / CLHEP::MeV
<< " MeV; Time: " << time << " ns; Position (local) " << localPos << " (global ) "
<< globalPos << " direction " << momDir;

#ifdef EDM_ML_DEBUG
edm::LogVerbatim("FiberSim") << "HFChamberSensitiveDetector: Hit created in (" << touch->GetVolume(0)->GetLogicalVolume()->GetName() << ") ID " << detID << " Track " << trackID << " Edep: " << edep / CLHEP::MeV << " MeV; Time: " << time << " ns; Position (local) " << localPos << " (global ) " << globalPos << " direction " << momDir;
#endif
theHC->insert(aHit);
return true;
}

void HFChamberSD::EndOfEvent(G4HCofThisEvent* HCE) {
edm::LogVerbatim("FiberSim") << "HFChamberSD: Finds " << theHC->entries() << " hits";
void HFChamberSensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE) {
edm::LogVerbatim("FiberSim") << "HFChamberSensitiveDetector: Finds " << theHC->entries() << " hits";
clear();
}

void HFChamberSD::clear() { theNSteps = 0; }
void HFChamberSensitiveDetector::clear() { theNSteps = 0; }

void HFChamberSD::DrawAll() {}
void HFChamberSensitiveDetector::DrawAll() {}

void HFChamberSD::PrintAll() {}
void HFChamberSensitiveDetector::PrintAll() {}

void HFChamberSD::clearHits() {}
void HFChamberSensitiveDetector::clearHits() {}

uint32_t HFChamberSD::setDetUnitId(const G4Step* aStep) {
uint32_t HFChamberSensitiveDetector::setDetUnitId(const G4Step* aStep) {
const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
return (touch->GetReplicaNumber(0));
}

void HFChamberSD::fillHits(edm::PCaloHitContainer&, const std::string&) {}
void HFChamberSensitiveDetector::fillHits(edm::PCaloHitContainer&, const std::string&) {}
@@ -0,0 +1,32 @@
// system include files

// user include files
#include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorMakerBase.h"
#include "SimG4Core/Notification/interface/SimActivityRegistryEnroller.h"
#include "SimG4Core/SensitiveDetector/interface/SensitiveDetectorPluginFactory.h"

#include "SimG4CMS/ShowerLibraryProducer/interface/HFChamberSensitiveDetector.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

class HFChamberSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
public:
explicit HFChamberSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc) {}

void beginRun(const edm::EventSetup& es) final {}
std::unique_ptr<SensitiveDetector> make(const std::string& iname,
const SensitiveDetectorCatalog& clg,
const edm::ParameterSet& p,
const SimTrackManager* man,
SimActivityRegistry& reg) const final {
auto sd = std::make_unique<HFChamberSensitiveDetector>(iname, clg, man);
SimActivityRegistryEnroller::enroll(reg, sd.get());
return sd;
}
};

DEFINE_SENSITIVEDETECTORBUILDER(HFChamberSensitiveDetectorBuilder, HFChamberSensitiveDetector);