Skip to content

Commit

Permalink
Merge pull request #34538 from bsunanda/Run3-gex83E
Browse files Browse the repository at this point in the history
Run3-gex83E Update SD class initialization in SimG4CMS/CherenkovAnalysis
  • Loading branch information
cmsbuild committed Jul 18, 2021
2 parents 6c56f58 + 853dd89 commit dfdabd0
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 23 deletions.
12 changes: 9 additions & 3 deletions SimG4CMS/CherenkovAnalysis/interface/DreamSD.h
@@ -1,10 +1,12 @@
#ifndef SimG4CMS_DreamSD_h
#define SimG4CMS_DreamSD_h

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "SimG4CMS/Calo/interface/CaloSD.h"
#include "DetectorDescription/Core/interface/DDCompactView.h"
#include "DetectorDescription/DDCMS/interface/DDCompactView.h"

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"

#include "G4PhysicsFreeVector.hh"
Expand All @@ -20,7 +22,8 @@ class G4LogicalVolume;
class DreamSD : public CaloSD {
public:
DreamSD(const std::string &,
const edm::EventSetup &,
const DDCompactView *,
const cms::DDCompactView *,
const SensitiveDetectorCatalog &,
edm::ParameterSet const &,
const SimTrackManager *);
Expand All @@ -36,7 +39,7 @@ class DreamSD : public CaloSD {
typedef std::pair<double, double> Doubles;
typedef std::map<G4LogicalVolume *, Doubles> DimensionMap;

void initMap(const std::string &, const edm::EventSetup &);
void initMap(const std::string &);
void fillMap(const std::string &, double, double);
double curve_LY(const G4Step *, int);
double crystalLength(G4LogicalVolume *) const;
Expand All @@ -57,6 +60,9 @@ class DreamSD : public CaloSD {
static constexpr double k_ScaleFromDDDToG4 = 1.0;
static constexpr double k_ScaleFromDD4HepToG4 = 1.0 / dd4hep::mm;

const DDCompactView *cpvDDD_;
const cms::DDCompactView *cpvDD4Hep_;

bool useBirk_, doCherenkov_, readBothSide_, dd4hep_;
double birk1_, birk2_, birk3_;
double slopeLY_;
Expand Down
2 changes: 2 additions & 0 deletions SimG4CMS/CherenkovAnalysis/plugins/CherenkovAnalysis.cc
Expand Up @@ -39,6 +39,8 @@ Description: <one line class summary>
#include "FWCore/ServiceRegistry/interface/Service.h"
#include <TH1F.h>

//#define EDM_ML_DEBUG

class CherenkovAnalysis : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit CherenkovAnalysis(const edm::ParameterSet &);
Expand Down
@@ -0,0 +1,56 @@
// 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 "DetectorDescription/Core/interface/DDCompactView.h"
#include "DetectorDescription/DDCMS/interface/DDCompactView.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "SimG4CMS/CherenkovAnalysis/interface/DreamSD.h"

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

class DreamSensitiveDetectorBuilder : public SensitiveDetectorMakerBase {
public:
explicit DreamSensitiveDetectorBuilder(edm::ParameterSet const& p, edm::ConsumesCollector cc) {
fromDD4Hep_ = p.getParameter<bool>("g4GeometryDD4hepSource");
if (fromDD4Hep_)
cpvTokenDD4Hep_ = cc.esConsumes<edm::Transition::BeginRun>();
else
cpvTokenDDD_ = cc.esConsumes<edm::Transition::BeginRun>();
}

void beginRun(const edm::EventSetup& es) final {
if (fromDD4Hep_) {
cpvDD4Hep_ = &es.getData(cpvTokenDD4Hep_);
} else {
cpvDDD_ = &es.getData(cpvTokenDDD_);
}
}

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<DreamSD>(iname, cpvDDD_, cpvDD4Hep_, clg, p, man);
SimActivityRegistryEnroller::enroll(reg, sd.get());
return sd;
}

private:
bool fromDD4Hep_;
edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_;
edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4Hep_;
const DDCompactView* cpvDDD_;
const cms::DDCompactView* cpvDD4Hep_;
};

typedef DreamSD DreamSensitiveDetector;
DEFINE_SENSITIVEDETECTORBUILDER(DreamSensitiveDetectorBuilder, DreamSensitiveDetector);
2 changes: 2 additions & 0 deletions SimG4CMS/CherenkovAnalysis/plugins/XtalDedxAnalysis.cc
Expand Up @@ -31,6 +31,8 @@
#include <TH1F.h>
#include <TH1I.h>

//#define EDM_ML_DEBUG

class XtalDedxAnalysis : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit XtalDedxAnalysis(const edm::ParameterSet &);
Expand Down
6 changes: 0 additions & 6 deletions SimG4CMS/CherenkovAnalysis/plugins/module.cc

This file was deleted.

20 changes: 7 additions & 13 deletions SimG4CMS/CherenkovAnalysis/src/DreamSD.cc
@@ -1,7 +1,6 @@

#include <memory>

#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "DetectorDescription/Core/interface/DDCompactView.h"
#include "DetectorDescription/Core/interface/DDFilter.h"
#include "DetectorDescription/Core/interface/DDFilteredView.h"
Expand All @@ -19,8 +18,6 @@
#include "G4Track.hh"
#include "G4VProcess.hh"

#include "FWCore/Framework/interface/ESTransientHandle.h"

// Histogramming
#include "FWCore/ServiceRegistry/interface/Service.h"

Expand All @@ -35,11 +32,12 @@

//________________________________________________________________________________________
DreamSD::DreamSD(const std::string &name,
const edm::EventSetup &es,
const DDCompactView *cpvDDD,
const cms::DDCompactView *cpvDD4Hep,
const SensitiveDetectorCatalog &clg,
edm::ParameterSet const &p,
const SimTrackManager *manager)
: CaloSD(name, clg, p, manager) {
: CaloSD(name, clg, p, manager), cpvDDD_(cpvDDD), cpvDD4Hep_(cpvDD4Hep) {
edm::ParameterSet m_EC = p.getParameter<edm::ParameterSet>("ECalSD");
useBirk_ = m_EC.getParameter<bool>("UseBirkLaw");
doCherenkov_ = m_EC.getParameter<bool>("doCherenkov");
Expand All @@ -65,7 +63,7 @@ DreamSD::DreamSD(const std::string &name,
for (auto lvcite = lvs->begin(); lvcite != lvs->end(); ++lvcite, ++k)
edm::LogVerbatim("EcalSim") << "Volume[" << k << "] " << (*lvcite)->GetName();
#endif
initMap(name, es);
initMap(name);
}

//________________________________________________________________________________________
Expand Down Expand Up @@ -122,12 +120,10 @@ uint32_t DreamSD::setDetUnitId(const G4Step *aStep) {
}

//________________________________________________________________________________________
void DreamSD::initMap(const std::string &sd, const edm::EventSetup &es) {
void DreamSD::initMap(const std::string &sd) {
if (dd4hep_) {
edm::ESTransientHandle<cms::DDCompactView> cpv;
es.get<IdealGeometryRecord>().get(cpv);
const cms::DDFilter filter("ReadOutName", sd);
cms::DDFilteredView fv((*cpv), filter);
cms::DDFilteredView fv((*cpvDD4Hep_), filter);
while (fv.firstChild()) {
std::string name = static_cast<std::string>(dd4hep::dd::noNamespace(fv.name()));
std::vector<double> paras(fv.parameters());
Expand All @@ -142,10 +138,8 @@ void DreamSD::initMap(const std::string &sd, const edm::EventSetup &es) {
fillMap(name, length, width);
}
} else {
edm::ESTransientHandle<DDCompactView> cpv;
es.get<IdealGeometryRecord>().get(cpv);
DDSpecificsMatchesValueFilter filter{DDValue("ReadOutName", sd, 0)};
DDFilteredView fv((*cpv), filter);
DDFilteredView fv((*cpvDDD_), filter);
fv.firstChild();
bool dodet = true;
const G4LogicalVolumeStore *lvs = G4LogicalVolumeStore::GetInstance();
Expand Down
3 changes: 2 additions & 1 deletion SimG4CMS/CherenkovAnalysis/test/runSingleDREAMDD4Hep_cfg.py
@@ -1,6 +1,7 @@
import FWCore.ParameterSet.Config as cms
from Configuration.ProcessModifiers.dd4hep_cff import dd4hep

process = cms.Process("CaloTest")
process = cms.Process("CaloTest", dd4hep)
process.load("SimGeneral.HepPDTESSource.pdt_cfi")
process.load("Configuration.EventContent.EventContent_cff")
process.load('FWCore.MessageService.MessageLogger_cfi')
Expand Down

0 comments on commit dfdabd0

Please sign in to comment.