Skip to content

Commit

Permalink
Merge pull request #44941 from fabiocos/fc-mtdpremix20240429
Browse files Browse the repository at this point in the history
MTD simulation: add support for pre-mixing in pileup management of MtdSimLayerCluster
  • Loading branch information
cmsbuild authored May 20, 2024
2 parents eb5c178 + e7f49d4 commit 411547a
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
# For phase2 premixing switch the sim digi collections to the ones including pileup
from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
premix_stage2.toModify(_phase2_hgc_extraCommands,
v = ['keep *_mixData_HGCDigisEE_*', 'keep *_mixData_HGCDigisHEfront_*', 'keep *_mixData_HGCDigisHEback_*', 'keep *_mixData_MergedCaloTruth_*', 'keep *_mix_MergedMtdTruth_*', 'keep *_mix_MergedMtdTruthLC_*', 'keep *_mix_MergedMtdTruthST_*'])
v = ['keep *_mixData_HGCDigisEE_*', 'keep *_mixData_HGCDigisHEfront_*', 'keep *_mixData_HGCDigisHEback_*', 'keep *_mixData_MergedCaloTruth_*', 'keep *_mix_MergedMtdTruth_*', 'keep *_mixData_MergedMtdTruthLC_*', 'keep *_mix_MergedMtdTruthST_*'])
phase2_hgcal.toModify( SimCalorimetryRAW, outputCommands = SimCalorimetryRAW.outputCommands + _phase2_hgc_extraCommands.v )
phase2_hgcal.toModify( SimCalorimetryFEVTDEBUG, outputCommands = SimCalorimetryFEVTDEBUG.outputCommands + _phase2_hgc_extraCommands.v )
phase2_hgcal.toModify( SimCalorimetryRECO, outputCommands = SimCalorimetryRECO.outputCommands + _phase2_hgc_extraCommands.v )
Expand Down
4 changes: 3 additions & 1 deletion SimDataFormats/CaloAnalysis/src/MtdSimLayerCluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ MtdSimLayerCluster::~MtdSimLayerCluster() {}
std::ostream &operator<<(std::ostream &s, MtdSimLayerCluster const &tp) {
s << "CP momentum, q, ID, & Event #: " << tp.p4() << " " << tp.charge() << " " << tp.pdgId() << " "
<< tp.eventId().bunchCrossing() << "." << tp.eventId().event() << std::endl;
s << " Offset " << tp.trackIdOffset() << " "
<< " LC time " << tp.simLCTime() << " LC energy " << tp.simLCEnergy() << std::endl;

for (MtdSimLayerCluster::genp_iterator hepT = tp.genParticle_begin(); hepT != tp.genParticle_end(); ++hepT) {
s << " HepMC Track Momentum " << (*hepT)->momentum().rho() << std::endl;
Expand All @@ -39,7 +41,7 @@ std::ostream &operator<<(std::ostream &s, MtdSimLayerCluster const &tp) {
s << " Mismatch b/t MtdSimLayerCluster and Geant types" << std::endl;
}
}
s << " # of cells = " << tp.hits_.size()
s << " # of cells = " << tp.mtdHits_.size()
<< ", effective cells = " << std::accumulate(tp.fractions_.begin(), tp.fractions_.end(), 0.f) << std::endl;
return s;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Unsure what to do with InitialVertices, they don't seem to be consumed downstream?
from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
premix_stage2.toModify(_phase2_timing_extraCommands,
value = [ 'keep *_mixData_FTLBarrel_*','keep *_mixData_FTLEndcap_*','keep *_mix_InitialVertices_*' ]
value = [ 'keep *_mixData_FTLBarrel_*','keep *_mixData_FTLEndcap_*','keep *_mix_InitialVertices_*', 'keep *_mtdRecoClusterToSimLayerClusterAssociation_*_*', 'keep *_mtdSimLayerClusterToTPAssociation_*_*' ]
)
from Configuration.Eras.Modifier_phase2_timing_cff import phase2_timing
phase2_timing.toModify( SimFastTimingRAW, outputCommands = SimFastTimingRAW.outputCommands + _phase2_timing_extraCommands.value )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/EDGetToken.h"

#include "SimDataFormats/Associations/interface/MtdRecoClusterToSimLayerClusterAssociator.h"
Expand All @@ -22,6 +24,8 @@ class MtdRecoClusterToSimLayerClusterAssociatorEDProducer : public edm::global::
explicit MtdRecoClusterToSimLayerClusterAssociatorEDProducer(const edm::ParameterSet &);
~MtdRecoClusterToSimLayerClusterAssociatorEDProducer() override;

static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

private:
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;

Expand Down Expand Up @@ -81,5 +85,15 @@ void MtdRecoClusterToSimLayerClusterAssociatorEDProducer::produce(edm::StreamID,
iEvent.put(std::move(s2r));
}

void MtdRecoClusterToSimLayerClusterAssociatorEDProducer::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("associator", edm::InputTag("mtdRecoClusterToSimLayerClusterAssociatorByHits"));
desc.add<edm::InputTag>("mtdSimClustersTag", edm::InputTag("mix", "MergedMtdTruthLC"));
desc.add<edm::InputTag>("btlRecoClustersTag", edm::InputTag("mtdClusters", "FTLBarrel"));
desc.add<edm::InputTag>("etlRecoClustersTag", edm::InputTag("mtdClusters", "FTLEndcap"));

cfg.add("mtdRecoClusterToSimLayerClusterAssociationDefault", desc);
}

// define this as a plug-in
DEFINE_FWK_MODULE(MtdRecoClusterToSimLayerClusterAssociatorEDProducer);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "SimDataFormats/Associations/interface/MtdSimLayerClusterToTPAssociator.h"

Expand All @@ -26,6 +28,8 @@ class MtdSimLayerClusterToTPAssociatorEDProducer : public edm::global::EDProduce
explicit MtdSimLayerClusterToTPAssociatorEDProducer(const edm::ParameterSet &);
~MtdSimLayerClusterToTPAssociatorEDProducer() override;

static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

private:
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;

Expand Down Expand Up @@ -74,5 +78,14 @@ void MtdSimLayerClusterToTPAssociatorEDProducer::produce(edm::StreamID,
iEvent.put(std::move(tp2s));
}

void MtdSimLayerClusterToTPAssociatorEDProducer::fillDescriptions(edm::ConfigurationDescriptions &cfg) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("associator", edm::InputTag("mtdSimLayerClusterToTPAssociatorByTrackId"));
desc.add<edm::InputTag>("mtdSimClustersTag", edm::InputTag("mix", "MergedMtdTruthLC"));
desc.add<edm::InputTag>("trackingParticlesTag", edm::InputTag("mix", "MergedTrackTruth"));

cfg.add("mtdSimLayerClusterToTPAssociationDefault", desc);
}

// define this as a plug-in
DEFINE_FWK_MODULE(MtdSimLayerClusterToTPAssociatorEDProducer);
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import FWCore.ParameterSet.Config as cms

mtdRecoClusterToSimLayerClusterAssociation = cms.EDProducer("MtdRecoClusterToSimLayerClusterAssociatorEDProducer",
associator = cms.InputTag('mtdRecoClusterToSimLayerClusterAssociatorByHits'),
mtdSimClustersTag = cms.InputTag('mix','MergedMtdTruthLC'),
btlRecoClustersTag = cms.InputTag('mtdClusters', 'FTLBarrel'),
etlRecoClustersTag = cms.InputTag('mtdClusters', 'FTLEndcap'),
)
from SimFastTiming.MtdAssociatorProducers.mtdRecoClusterToSimLayerClusterAssociationDefault_cfi import mtdRecoClusterToSimLayerClusterAssociationDefault as _mtdRecoClusterToSimLayerClusterAssociationDefault
mtdRecoClusterToSimLayerClusterAssociation = _mtdRecoClusterToSimLayerClusterAssociationDefault.clone()

from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
premix_stage2.toModify(mtdRecoClusterToSimLayerClusterAssociation, mtdSimClustersTag = "mixData:MergedMtdTruthLC")
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import FWCore.ParameterSet.Config as cms

mtdSimLayerClusterToTPAssociation = cms.EDProducer("MtdSimLayerClusterToTPAssociatorEDProducer",
associator = cms.InputTag('mtdSimLayerClusterToTPAssociatorByTrackId'),
mtdSimClustersTag = cms.InputTag('mix','MergedMtdTruthLC'),
trackingParticlesTag = cms.InputTag('mix', 'MergedTrackTruth')
)
from SimFastTiming.MtdAssociatorProducers.mtdSimLayerClusterToTPAssociationDefault_cfi import mtdSimLayerClusterToTPAssociationDefault as _mtdSimLayerClusterToTPAssociationDefault
mtdSimLayerClusterToTPAssociation = _mtdSimLayerClusterToTPAssociationDefault.clone()

from Configuration.ProcessModifiers.premix_stage2_cff import premix_stage2
premix_stage2.toModify(mtdSimLayerClusterToTPAssociation, mtdSimClustersTag = "mixData:MergedMtdTruthLC")
premix_stage2.toModify(mtdSimLayerClusterToTPAssociation, trackingParticlesTag = "mixData:MergedTrackTruth")
83 changes: 83 additions & 0 deletions SimGeneral/CaloAnalysis/plugins/PreMixingMtdTruthWorker.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ProducesCollector.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "SimGeneral/MixingModule/interface/PileUpEventPrincipal.h"

#include "DataFormats/Common/interface/Handle.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerCluster.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"

#include "SimGeneral/PreMixingModule/interface/PreMixingWorker.h"
#include "SimGeneral/PreMixingModule/interface/PreMixingWorkerFactory.h"

class PreMixingMtdTruthWorker : public PreMixingWorker {
public:
PreMixingMtdTruthWorker(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &&iC);
~PreMixingMtdTruthWorker() override = default;

void initializeEvent(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
void addSignals(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
void addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) override;
void put(edm::Event &iEvent,
edm::EventSetup const &iSetup,
std::vector<PileupSummaryInfo> const &ps,
int bunchSpacing) override;

private:
void add(const MtdSimLayerClusterCollection &clusters);

edm::EDGetTokenT<MtdSimLayerClusterCollection> sigClusterToken_;

edm::InputTag clusterPileInputTag_;
std::string mtdSimLCCollectionDM_;

std::unique_ptr<MtdSimLayerClusterCollection> newClusters_;
};

PreMixingMtdTruthWorker::PreMixingMtdTruthWorker(const edm::ParameterSet &ps,
edm::ProducesCollector producesCollector,
edm::ConsumesCollector &&iC)
: sigClusterToken_(iC.consumes<MtdSimLayerClusterCollection>(ps.getParameter<edm::InputTag>("labelSig"))),
clusterPileInputTag_(ps.getParameter<edm::InputTag>("pileInputTag")),
mtdSimLCCollectionDM_(ps.getParameter<std::string>("collectionDM")) {
producesCollector.produces<MtdSimLayerClusterCollection>(mtdSimLCCollectionDM_);
}

void PreMixingMtdTruthWorker::initializeEvent(edm::Event const &iEvent, edm::EventSetup const &iSetup) {
newClusters_ = std::make_unique<MtdSimLayerClusterCollection>();
}

void PreMixingMtdTruthWorker::addSignals(edm::Event const &iEvent, edm::EventSetup const &iSetup) {
edm::Handle<MtdSimLayerClusterCollection> clusters;
iEvent.getByToken(sigClusterToken_, clusters);

if (clusters.isValid()) {
add(*clusters);
}
}

void PreMixingMtdTruthWorker::addPileups(PileUpEventPrincipal const &pep, edm::EventSetup const &iSetup) {
edm::Handle<MtdSimLayerClusterCollection> clusters;
pep.getByLabel(clusterPileInputTag_, clusters);

if (clusters.isValid()) {
add(*clusters);
}
}

void PreMixingMtdTruthWorker::add(const MtdSimLayerClusterCollection &clusters) {
// Copy MtdSimLayerClusters
newClusters_->reserve(newClusters_->size() + clusters.size());
std::copy(clusters.begin(), clusters.end(), std::back_inserter(*newClusters_));
}

void PreMixingMtdTruthWorker::put(edm::Event &iEvent,
edm::EventSetup const &iSetup,
std::vector<PileupSummaryInfo> const &ps,
int bunchSpacing) {
iEvent.put(std::move(newClusters_), mtdSimLCCollectionDM_);
}

DEFINE_PREMIXING_WORKER(PreMixingMtdTruthWorker);
5 changes: 5 additions & 0 deletions SimGeneral/CaloAnalysis/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<library file="*.cc" name="SimGeneralCaloAnalysis_test">
<use name="FWCore/Framework"/>
<use name="SimDataFormats/CaloAnalysis"/>
<flags EDM_PLUGIN="1"/>
</library>
75 changes: 75 additions & 0 deletions SimGeneral/CaloAnalysis/test/MtdTruthDumper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// system include files
#include <vector>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "DataFormats/Common/interface/ValidHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerCluster.h"
#include "SimDataFormats/CaloAnalysis/interface/MtdSimLayerClusterFwd.h"

class MtdTruthDumper : public edm::one::EDAnalyzer<> {
public:
explicit MtdTruthDumper(const edm::ParameterSet&);
~MtdTruthDumper() override{};

void analyze(const edm::Event&, const edm::EventSetup&) override;
void beginJob() override{};
void endJob() override{};

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
edm::EDGetTokenT<MtdSimLayerClusterCollection> mtdSimLCToken_;
};

MtdTruthDumper::MtdTruthDumper(const edm::ParameterSet& iConfig)
: mtdSimLCToken_(
consumes<MtdSimLayerClusterCollection>(iConfig.getParameter<edm::InputTag>("moduleLabelMtdSimLC"))) {}

//
// member functions
//

// ------------ method called to produce the data ------------
void MtdTruthDumper::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
auto mtdSimLCcoll = edm::makeValid(iEvent.getHandle(mtdSimLCToken_));

edm::LogPrint("DumpMtdSimLC") << "\n MtdSimLayerCluster collection dump \n";
edm::LogPrint("DumpMtdSimLC") << " MtdSimLayerCluster in the event = " << (*mtdSimLCcoll).size();
size_t isimLC(0);

isimLC = 0;
for (const auto& mtdLC : *mtdSimLCcoll) {
edm::LogPrint("DumpMtdSimLC") << "MtdSimLayerCluster " << isimLC << " = " << mtdLC;
size_t ihit(0);
for (const auto& hit : mtdLC.detIds_and_rows()) {
edm::LogPrint("DumpMtdSimLC") << "hit # " << ihit << " DetId " << hit.first << " r/c "
<< (uint32_t)hit.second.first << " " << (uint32_t)hit.second.second;
ihit++;
}
isimLC++;
edm::LogPrint("DumpMtdSimLC") << "\n";
}

return;
}

void MtdTruthDumper::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("moduleLabelMtdSimLC", edm::InputTag("mix", "MergedMtdTruthLC"))
->setComment("Module for input MtdSimLayerCluster collection");
descriptions.add("mtdTruthDumper", desc);
}

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

//define this as a plug-in
DEFINE_FWK_MODULE(MtdTruthDumper);
15 changes: 15 additions & 0 deletions SimGeneral/CaloAnalysis/test/runMtdTruthDumper_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("tPtVDump")
process.load("FWCore.MessageLogger.MessageLogger_cfi")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(-1)
)
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('file:step3.root')
)

process.load("SimGeneral.CaloAnalysis.mtdTruthDumper_cfi")

process.p1 = cms.Path(process.mtdTruthDumper)
6 changes: 6 additions & 0 deletions SimGeneral/PreMixingModule/python/mixOne_premix_on_sim_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@
digiTagSig = cms.InputTag("mix", "FTLEndcap"),
pileInputTag = cms.InputTag("mix", "FTLEndcap"),
),
mtdTruth = cms.PSet(
workerType = cms.string("PreMixingMtdTruthWorker"),
labelSig = cms.InputTag("mix", "MergedMtdTruthLC"),
pileInputTag = cms.InputTag("mix", "MergedMtdTruthLC"),
collectionDM = cms.string("MergedMtdTruthLC"),
)
)
)
# ECAL
Expand Down

0 comments on commit 411547a

Please sign in to comment.