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

Try to fix GeometryProducer and G4e examples #38864

Merged
merged 6 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SimG4Core/GeometryProducer/interface/GeometryProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class GeometryProducer : public edm::one::EDProducer<edm::one::SharedResources,
private:
void updateMagneticField(edm::EventSetup const &es);

void makeGeom(const edm::EventSetup &c);

G4RunManagerKernel *m_kernel;
edm::ParameterSet m_pField;
SimActivityRegistry m_registry;
Expand Down
17 changes: 12 additions & 5 deletions SimG4Core/GeometryProducer/src/GeometryProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ GeometryProducer::GeometryProducer(edm::ParameterSet const &p)
m_pGeoFromDD4hep(false) {
// Look for an outside SimActivityRegistry
// this is used by the visualization code

edm::Service<SimActivityRegistry> otherRegistry;
if (otherRegistry)
m_registry.connect(*otherRegistry);
createWatchers(m_p, m_registry, m_watchers, m_producers);

m_sdMakers = sim::sensitiveDetectorMakers(m_p, consumesCollector(), std::vector<std::string>());
if (m_pUseSensitiveDetectors)
m_sdMakers = sim::sensitiveDetectorMakers(m_p, consumesCollector(), std::vector<std::string>());

tokMF_ = esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>();
if (m_pGeoFromDD4hep) {
tokDD4hep_ = esConsumes<cms::DDCompactView, IdealGeometryRecord, edm::Transition::BeginRun>();
Expand Down Expand Up @@ -103,6 +106,7 @@ void GeometryProducer::beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSe
}

void GeometryProducer::beginRun(const edm::Run &run, const edm::EventSetup &es) {
makeGeom(es);
updateMagneticField(es);
for (auto &maker : m_sdMakers) {
maker.second->beginRun(es);
Expand All @@ -115,6 +119,13 @@ void GeometryProducer::produce(edm::Event &e, const edm::EventSetup &es) {
if (!m_firstRun)
return;
m_firstRun = false;
for (Producers::iterator itProd = m_producers.begin(); itProd != m_producers.end(); ++itProd) {
(*itProd)->produce(e, es);
}
}
void GeometryProducer::makeGeom(const edm::EventSetup &es) {
if (!m_firstRun)
return;

edm::LogVerbatim("GeometryProducer") << "Producing G4 Geom";

Expand Down Expand Up @@ -156,10 +167,6 @@ void GeometryProducer::produce(edm::Event &e, const edm::EventSetup &es) {
edm::LogInfo("GeometryProducer") << " Sensitive Detector building finished; found " << m_sensTkDets.size()
<< " Tk type Producers, and " << m_sensCaloDets.size() << " Calo type producers ";
}

for (Producers::iterator itProd = m_producers.begin(); itProd != m_producers.end(); ++itProd) {
(*itProd)->produce(e, es);
}
}

DEFINE_FWK_MODULE(GeometryProducer);
56 changes: 35 additions & 21 deletions TrackPropagation/Geant4e/python/geantRefit_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,41 @@
UseMagneticField = cms.bool(True),
UseSensitiveDetectors = cms.bool(False),
MagneticField = cms.PSet(
UseLocalMagFieldManager = cms.bool(False),
Verbosity = cms.untracked.bool(False),
ConfGlobalMFM = cms.PSet(
Volume = cms.string('OCMS'),
OCMS = cms.PSet(
Stepper = cms.string('G4ClassicalRK4'),
Type = cms.string('CMSIMField'),
StepperParam = cms.PSet(
MaximumEpsilonStep = cms.untracked.double(0.01), ## in mm
DeltaOneStep = cms.double(1e-4),## in mm
MaximumLoopCounts = cms.untracked.double(1000.0),
DeltaChord = cms.double(0.001), ## in mm
MinStep = cms.double(0.1), ## in mm
DeltaIntersectionAndOneStep = cms.untracked.double(-1.0),
DeltaIntersection = cms.double(1e-6), ## in mm
MinimumEpsilonStep = cms.untracked.double(1e-05) ## in mm
)
)
),
delta = cms.double(1.0)
)
UseLocalMagFieldManager = cms.bool(False),
Verbosity = cms.bool(False),
ConfGlobalMFM = cms.PSet(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this PSet be taken from somewhere else, so that we can avoid staying in synch manually?

Volume = cms.string('OCMS'),
OCMS = cms.PSet(
Stepper = cms.string('G4TDormandPrince45'),
Type = cms.string('CMSIMField'),
StepperParam = cms.PSet(
VacRegions = cms.vstring(),
# VacRegions = cms.vstring('DefaultRegionForTheWorld','BeamPipeVacuum','BeamPipeOutside'),
EnergyThTracker = cms.double(0.2), ## in GeV
RmaxTracker = cms.double(8000), ## in mm
ZmaxTracker = cms.double(11000), ## in mm
MaximumEpsilonStep = cms.untracked.double(0.01),
DeltaOneStep = cms.double(0.001), ## in mm
DeltaOneStepTracker = cms.double(1e-4),## in mm
MaximumLoopCounts = cms.untracked.double(1000.0),
DeltaChord = cms.double(0.002), ## in mm
DeltaChordTracker = cms.double(0.001), ## in mm
MinStep = cms.double(0.1), ## in mm
DeltaIntersectionAndOneStep = cms.untracked.double(-1.0),
DeltaIntersection = cms.double(0.0001), ## in mm
DeltaIntersectionTracker = cms.double(1e-6),## in mm
MaxStep = cms.double(150.), ## in cm
MinimumEpsilonStep = cms.untracked.double(1e-05),
EnergyThSimple = cms.double(0.015), ## in GeV
DeltaChordSimple = cms.double(0.1), ## in mm
DeltaOneStepSimple = cms.double(0.1), ## in mm
DeltaIntersectionSimple = cms.double(0.01), ## in mm
MaxStepSimple = cms.double(50.), ## in cm
)
)
),
delta = cms.double(1.0)
),
)

# load this to do a track refit
Expand Down
2 changes: 2 additions & 0 deletions TrackPropagation/Geant4e/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
<library file="Geant4ePropagatorAnalyzer.cc" name="Geant4ePropagatorAnalyzer">
<flags EDM_PLUGIN="1"/>
</library>

<test name="testG4Refitter" command="cmsRun ${LOCALTOP}/src/TrackPropagation/Geant4e/test/Geant4e_example_cfg.py"/>
12 changes: 7 additions & 5 deletions TrackPropagation/Geant4e/test/Geant4ePropagatorAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,20 @@ void Geant4ePropagatorAnalyzer::analyze(const edm::Event &iEvent, const edm::Eve
///////////////////////////////////////
// Get the sim tracks & vertices
Handle<SimTrackContainer> simTracks;
iEvent.getByLabel<SimTrackContainer>(G4TrkSrc_, simTracks);
iEvent.getByLabel<SimTrackContainer>("g4SimHits", "", simTracks);
if (!simTracks.isValid()) {
LogWarning("Geant4e") << "No tracks found" << std::endl;
return;
// return;
}
LogDebug("Geant4e") << "G4e -- Got simTracks of size " << simTracks->size();
std::cout << "Geant4e "
<< "G4e -- Got simTracks of size " << simTracks->size() << std::endl;

Handle<SimVertexContainer> simVertices;
iEvent.getByLabel<SimVertexContainer>(G4VtxSrc_, simVertices);
iEvent.getByLabel<SimVertexContainer>("g4SimHits", simVertices);
if (!simVertices.isValid()) {
LogWarning("Geant4e") << "No tracks found" << std::endl;
return;
LogWarning("Geant4e") << "No verticess found" << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for spotting.
Once we find how to get the products will fix this as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably unrelated, but about

the test does not find products (getByLabel broken?)

Shouldn't be tokens used instead? https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideEDMGetDataFromEvent#get_ByToken

AFAIK getByLabel is deprecated, but I would have expected a different error message.

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAIK getByLabel is deprecated, but I would have expected a different error message.

Correct, and I would have expected too to see a different exception (complaining about missing consumes() calls).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deprecated should not mean not working... (or message should indeed say something different)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does one really has to consume each single product used?
and create tokens etc just for a single very stupid analyzer?
One cannot just say I consume everything in the input file?
I understand products to be produced, but for those in the input file is a bit abusive to ask all those boilerplate....

is there a script that generate the boilerplate?
I will not write it by hand!

Copy link
Contributor

Choose a reason for hiding this comment

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

Does one really has to consume each single product used?

Yes.

and create tokens etc just for a single very stupid analyzer?

Yes.

One cannot just say I consume everything in the input file?

No.

I understand products to be produced, but for those in the input file is a bit abusive to ask all those boilerplate....

The consumes information is used also for input file to read in only those branches that are actually needed by the module.

is there a script that generate the boilerplate?

I'm not aware of any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added

@@ -147,6 +147,9 @@ Geant4ePropagatorAnalyzer::Geant4ePropagatorAnalyzer(const edm::ParameterSet &iC
       thePropagator(nullptr),
       G4VtxSrc_(iConfig.getParameter<edm::InputTag>("G4VtxSrc")),
       G4TrkSrc_(iConfig.getParameter<edm::InputTag>("G4TrkSrc")) {
+
+      consumes(G4TrkSrc_);
+

in the constructor.

getByLabel still produces the very same error as above

Copy link
Contributor

Choose a reason for hiding this comment

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

The point of the migration is to use getByToken instead of getByLabel

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to note that the exception message has been improved for this particular corner case in #38875.

About

@@ -147,6 +147,9 @@ Geant4ePropagatorAnalyzer::Geant4ePropagatorAnalyzer(const edm::ParameterSet &iC
       thePropagator(nullptr),
       G4VtxSrc_(iConfig.getParameter<edm::InputTag>("G4VtxSrc")),
       G4TrkSrc_(iConfig.getParameter<edm::InputTag>("G4TrkSrc")) {
+
+      consumes(G4TrkSrc_);
+

in this case the consumes() call would need an explicit type (because it can't infer it from anywhere) along

@@ -147,6 +147,9 @@ Geant4ePropagatorAnalyzer::Geant4ePropagatorAnalyzer(const edm::ParameterSet &iC
       thePropagator(nullptr),
       G4VtxSrc_(iConfig.getParameter<edm::InputTag>("G4VtxSrc")),
       G4TrkSrc_(iConfig.getParameter<edm::InputTag>("G4TrkSrc")) {
+
+      consumes<std::vector<SimTrack>>(G4TrkSrc_);
+

In that case the getByLabel() should still work (even if getByToken() is strongly favored). The consumes() call itself has been required since 2016.

// return;
}
LogDebug("Geant4e") << "Got simVertices of size " << simVertices->size();

Expand Down
7 changes: 3 additions & 4 deletions TrackPropagation/Geant4e/test/Geant4e_example_cfg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FWCore.ParameterSet.Config
import FWCore.ParameterSet.Config as cms

process = cms.Process("G4eRefit")

Expand All @@ -13,7 +13,7 @@


from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '')
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2022_realistic', '')

process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.default = cms.untracked.PSet(ERROR = cms.untracked.PSet(limit = cms.untracked.int32(5)))
Expand All @@ -23,8 +23,7 @@

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
'/store/relval/CMSSW_7_4_0_pre6/RelValSingleMuPt10_UP15/GEN-SIM-RECO/MCRUN2_74_V1-v1/00000/4C6BF9BF-95A9-E411-ADA9-0025905A60FE.root',
'/store/relval/CMSSW_7_4_0_pre6/RelValSingleMuPt10_UP15/GEN-SIM-RECO/MCRUN2_74_V1-v1/00000/DE6B164D-9FA9-E411-9BAF-0025905B85D0.root'
'/store/relval/CMSSW_12_5_0_pre3/RelValSingleMuPt10/GEN-SIM-RECO/124X_mcRun3_2022_realistic_v8-v2/10000/6a6528c0-9d66-4358-bacc-158c40b439cf.root'
),
)

Expand Down
65 changes: 0 additions & 65 deletions TrackPropagation/Geant4e/test/testPropagatorAnalyzer.cfg

This file was deleted.

120 changes: 120 additions & 0 deletions TrackPropagation/Geant4e/test/testPropagatorAnalyzer_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("PROPAGATORTEST")



#####################################################################
# Message Logger ####################################################
#
process.load("FWCore.MessageService.MessageLogger_cfi")
process.load('Configuration.StandardSequences.Services_cff')
process.load('Configuration.StandardSequences.GeometryDB_cff')
process.load("Configuration.EventContent.EventContent_cff")
process.load("Configuration.StandardSequences.Reconstruction_cff")
process.load('Configuration.StandardSequences.MagneticField_38T_cff')
process.load('Configuration.StandardSequences.EndOfProcess_cff')
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")

from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run1_mc', '')
# process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2022_realistic', '')

process.load("FWCore.MessageService.MessageLogger_cfi")

# MessageLogger customizations
process.MessageLogger.cerr.enable = False
process.MessageLogger.cout.enable = True
labels = ["propAna", "geopro"] # Python module's label
messageLogger = dict()
for category in labels:
main_key = '%sMessageLogger'%(category)
category_key = 'Geant4e' # C++ EDProducer type
messageLogger[main_key] = dict(
filename = '%s_%s.log' % ("debugG4e", category),
threshold = 'DEBUG',
default = dict(limit=0)
)
messageLogger[main_key][category_key] = dict(limit=-1)
# First create defaults
setattr(process.MessageLogger.files, category, dict())
# Then modify them
setattr(process.MessageLogger.files, category, messageLogger[main_key])


#####################################################################
# Pool Source #######################################################
#
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring("file:step1.root")
# '/store/relval/CMSSW_12_5_0_pre3/RelValSingleMuPt10/GEN-SIM-RECO/124X_mcRun3_2022_realistic_v8-v2/10000/6a6528c0-9d66-4358-bacc-158c40b439cf.root'
)

process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(20) )

## Load propagator
from TrackPropagation.Geant4e.Geant4ePropagator_cfi import *


from TrackingTools.TrackRefitter.TracksToTrajectories_cff import *

## Set up geometry
process.geopro = cms.EDProducer("GeometryProducer",
UseMagneticField = cms.bool(True),
UseSensitiveDetectors = cms.bool(False),
MagneticField = cms.PSet(
UseLocalMagFieldManager = cms.bool(False),
Verbosity = cms.bool(False),
ConfGlobalMFM = cms.PSet(
Volume = cms.string('OCMS'),
OCMS = cms.PSet(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Stepper = cms.string('G4TDormandPrince45'),
Type = cms.string('CMSIMField'),
StepperParam = cms.PSet(
VacRegions = cms.vstring(),
# VacRegions = cms.vstring('DefaultRegionForTheWorld','BeamPipeVacuum','BeamPipeOutside'),
EnergyThTracker = cms.double(0.2), ## in GeV
RmaxTracker = cms.double(8000), ## in mm
ZmaxTracker = cms.double(11000), ## in mm
MaximumEpsilonStep = cms.untracked.double(0.01),
DeltaOneStep = cms.double(0.001), ## in mm
DeltaOneStepTracker = cms.double(1e-4),## in mm
MaximumLoopCounts = cms.untracked.double(1000.0),
DeltaChord = cms.double(0.002), ## in mm
DeltaChordTracker = cms.double(0.001), ## in mm
MinStep = cms.double(0.1), ## in mm
DeltaIntersectionAndOneStep = cms.untracked.double(-1.0),
DeltaIntersection = cms.double(0.0001), ## in mm
DeltaIntersectionTracker = cms.double(1e-6),## in mm
MaxStep = cms.double(150.), ## in cm
MinimumEpsilonStep = cms.untracked.double(1e-05),
EnergyThSimple = cms.double(0.015), ## in GeV
DeltaChordSimple = cms.double(0.1), ## in mm
DeltaOneStepSimple = cms.double(0.1), ## in mm
DeltaIntersectionSimple = cms.double(0.01), ## in mm
MaxStepSimple = cms.double(50.), ## in cm
)
)
),
delta = cms.double(1.0)
),
)




#####################################################################
# Extrapolator ######################################################
#
process.propAna = cms.EDAnalyzer("Geant4ePropagatorAnalyzer",
G4VtxSrc = cms.InputTag("g4SimHits"),
G4TrkSrc = cms.InputTag("g4SimHits"),
RootFile = cms.string("Geant4e.root"),
BeamCenter = cms.double(0), #degrees
BeamInterval = cms.double(20), #degrees
StudyStation = cms.int32(-1) #Station that we want to study. -1 for all.
)


process.g4AnalPath = cms.Path( process.geopro*process.propAna )
process.schedule = cms.Schedule( process.g4AnalPath )