-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44941 from fabiocos/fc-mtdpremix20240429
MTD simulation: add support for pre-mixing in pileup management of MtdSimLayerCluster
- Loading branch information
Showing
12 changed files
with
227 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
...astTiming/MtdAssociatorProducers/python/mtdRecoClusterToSimLayerClusterAssociation_cfi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
11 changes: 6 additions & 5 deletions
11
SimFastTiming/MtdAssociatorProducers/python/mtdSimLayerClusterToTPAssociation_cfi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
83
SimGeneral/CaloAnalysis/plugins/PreMixingMtdTruthWorker.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters