diff --git a/CommonTools/RecoAlgos/plugins/BuildFile.xml b/CommonTools/RecoAlgos/plugins/BuildFile.xml index 14976ed78b0e4..1391d81bd6a18 100644 --- a/CommonTools/RecoAlgos/plugins/BuildFile.xml +++ b/CommonTools/RecoAlgos/plugins/BuildFile.xml @@ -16,4 +16,5 @@ + diff --git a/CommonTools/RecoAlgos/plugins/RecHitToPFCandAssociationProducer.cc b/CommonTools/RecoAlgos/plugins/RecHitToPFCandAssociationProducer.cc new file mode 100644 index 0000000000000..9978035255129 --- /dev/null +++ b/CommonTools/RecoAlgos/plugins/RecHitToPFCandAssociationProducer.cc @@ -0,0 +1,136 @@ +// system include files +#include +#include + +// user include files +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/Framework/interface/ESHandle.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" +#include "SimDataFormats/CaloAnalysis/interface/SimClusterFwd.h" +#include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" +#include "DataFormats/CaloRecHit/interface/CaloRecHit.h" +#include "SimDataFormats/CaloHit/interface/PCaloHit.h" +#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h" +#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" + +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHit.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecHitFraction.h" +#include "DataFormats/ParticleFlowReco/interface/PFBlock.h" +#include "DataFormats/ParticleFlowReco/interface/PFBlockFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" + +#include "DataFormats/Common/interface/Association.h" + +#include "FWCore/Utilities/interface/transform.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include + +// +// class decleration +// +typedef std::pair IdxAndFraction; + +class RecHitToPFCandAssociationProducer : public edm::stream::EDProducer<> { +public: + explicit RecHitToPFCandAssociationProducer(const edm::ParameterSet &); + ~RecHitToPFCandAssociationProducer() override; + +private: + virtual void produce(edm::Event&, const edm::EventSetup&) override; + + std::vector caloRechitTags_; + std::vector> caloSimhitCollectionTokens_; + //std::vector> trackSimhitCollectionTokens_; + std::vector>> caloRechitCollectionTokens_; + edm::EDGetTokenT pfCollectionToken_; +}; + +RecHitToPFCandAssociationProducer::RecHitToPFCandAssociationProducer(const edm::ParameterSet &pset) + : //caloSimhitCollectionTokens_(edm::vector_transform(pset.getParameter>("caloSimHits"), + // [this](const edm::InputTag& tag) {return mayConsume(tag); })), + //trackSimhitCollectionTokens_(edm::vector_transform(pset.getParameter("trackSimHits"), + // [this](const edm::InputTag& tag) {return mayConsume(tag); }), + caloRechitTags_(pset.getParameter>("caloRecHits")), + caloRechitCollectionTokens_(edm::vector_transform(caloRechitTags_, + [this](const edm::InputTag& tag) {return mayConsume>(tag); })), + pfCollectionToken_(consumes(pset.getParameter("pfCands"))) +{ + for (auto& tag : caloRechitTags_) { + std::string label = tag.instance(); + //TODO: Can this be an edm::View? + produces>(label+"ToPFCand"); + } +} + +RecHitToPFCandAssociationProducer::~RecHitToPFCandAssociationProducer() {} + +// +// member functions +// + +// ------------ method called to produce the data ------------ +void RecHitToPFCandAssociationProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + edm::Handle pfCollection; + iEvent.getByToken(pfCollectionToken_, pfCollection); + std::unordered_map hitDetIdToIndex; + + for (size_t j = 0; j < pfCollection->size(); j++) { + const auto& pfCand = pfCollection->at(j); + const reco::PFCandidate::ElementsInBlocks& elements = pfCand.elementsInBlocks(); + for (auto& element : elements) { + const reco::PFBlockRef blockRef = element.first; + for (const auto& block : blockRef->elements()) { + if (block.type() == reco::PFBlockElement::HGCAL) { + const reco::PFClusterRef cluster = block.clusterRef(); + const std::vector& rhf = cluster->recHitFractions(); + for (const auto& hf : rhf) { + auto& hit = hf.recHitRef(); + if (!hit) + throw cms::Exception("RecHitToPFCandAssociationProducer") << "Invalid RecHit ref"; + size_t detId = hit->detId(); + auto entry = hitDetIdToIndex.find(detId); + if (entry == hitDetIdToIndex.end() || entry->second.second < hf.fraction()) + hitDetIdToIndex[detId] = {j, hf.fraction()}; + } + } + } + } + } + + for (size_t i = 0; i < caloRechitCollectionTokens_.size(); i++) { + std::string label = caloRechitTags_.at(i).instance(); + std::vector rechitIndices; + + edm::Handle> caloRechitCollection; + iEvent.getByToken(caloRechitCollectionTokens_.at(i), caloRechitCollection); + + for (size_t h = 0; h < caloRechitCollection->size(); h++) { + const CaloRecHit& caloRh = caloRechitCollection->at(h); + size_t id = caloRh.detid().rawId(); + int match = hitDetIdToIndex.find(id) == hitDetIdToIndex.end() ? -1 : hitDetIdToIndex.at(id).first; + rechitIndices.push_back(match); + } + + auto assoc = std::make_unique>(pfCollection); + edm::Association::Filler filler(*assoc); + filler.insert(caloRechitCollection, rechitIndices.begin(), rechitIndices.end()); + filler.fill(); + iEvent.put(std::move(assoc), label+"ToPFCand"); + } +} + +// define this as a plug-in +DEFINE_FWK_MODULE(RecHitToPFCandAssociationProducer); + + diff --git a/CommonTools/RecoAlgos/plugins/SimHitRecHitAssocitionProducer.cc b/CommonTools/RecoAlgos/plugins/SimHitRecHitAssocitionProducer.cc new file mode 100644 index 0000000000000..59ef9993233b8 --- /dev/null +++ b/CommonTools/RecoAlgos/plugins/SimHitRecHitAssocitionProducer.cc @@ -0,0 +1,115 @@ +// system include files +#include +#include + +// user include files +#include "FWCore/Framework/interface/stream/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/Framework/interface/ESHandle.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" +#include "SimDataFormats/CaloAnalysis/interface/SimClusterFwd.h" +#include "SimDataFormats/CaloAnalysis/interface/SimCluster.h" +#include "DataFormats/CaloRecHit/interface/CaloRecHit.h" +#include "SimDataFormats/CaloHit/interface/PCaloHit.h" +#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h" + + +#include "DataFormats/Common/interface/Association.h" + +#include "FWCore/Utilities/interface/transform.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include + +// +// class decleration +// +typedef std::pair IdxAndFraction; + +class SimHitRecHitAssociationProducer : public edm::stream::EDProducer<> { +public: + explicit SimHitRecHitAssociationProducer(const edm::ParameterSet &); + ~SimHitRecHitAssociationProducer() override; + +private: + virtual void produce(edm::Event&, const edm::EventSetup&) override; + + std::vector caloRechitTags_; + std::vector> caloSimhitCollectionTokens_; + //std::vector> trackSimhitCollectionTokens_; + std::vector>> caloRechitCollectionTokens_; + edm::EDGetTokenT scCollectionToken_; +}; + +SimHitRecHitAssociationProducer::SimHitRecHitAssociationProducer(const edm::ParameterSet &pset) + : //caloSimhitCollectionTokens_(edm::vector_transform(pset.getParameter>("caloSimHits"), + // [this](const edm::InputTag& tag) {return mayConsume(tag); })), + //trackSimhitCollectionTokens_(edm::vector_transform(pset.getParameter("trackSimHits"), + // [this](const edm::InputTag& tag) {return mayConsume(tag); }), + caloRechitTags_(pset.getParameter>("caloRecHits")), + caloRechitCollectionTokens_(edm::vector_transform(caloRechitTags_, + [this](const edm::InputTag& tag) {return mayConsume>(tag); })), + scCollectionToken_(consumes(pset.getParameter("simClusters"))) +{ + for (auto& tag : caloRechitTags_) { + std::string label = tag.instance(); + produces>(label+"ToSimClus"); + } +} + +SimHitRecHitAssociationProducer::~SimHitRecHitAssociationProducer() {} + +// +// member functions +// + +// ------------ method called to produce the data ------------ +void SimHitRecHitAssociationProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + edm::Handle scCollection; + iEvent.getByToken(scCollectionToken_, scCollection); + std::unordered_map hitDetIdToIndex; + + for (size_t s = 0; s < scCollection->size(); s++) { + const auto& sc = scCollection->at(s); + for (auto& hf : sc.hits_and_fractions()) { + auto entry = hitDetIdToIndex.find(hf.first); + // Update SimCluster assigment if detId has been found in no other SCs or if + // SC has greater fraction of energy in DetId than the SC already found + if (entry == hitDetIdToIndex.end() || entry->second.second < hf.second) + hitDetIdToIndex[hf.first] = {s, hf.second}; + } + } + + for (size_t i = 0; i < caloRechitCollectionTokens_.size(); i++) { + std::string label = caloRechitTags_.at(i).instance(); + std::vector rechitIndices; + + edm::Handle> caloRechitCollection; + iEvent.getByToken(caloRechitCollectionTokens_.at(i), caloRechitCollection); + //edm::Handle caloSimhitCollection; + //iEvent.getByToken(caloSimhitCollectionTokens_.at(i), caloSimhitCollection); + + for (size_t h = 0; h < caloRechitCollection->size(); h++) { + const CaloRecHit& caloRh = caloRechitCollection->at(h); + size_t id = caloRh.detid().rawId(); + int match = hitDetIdToIndex.find(id) == hitDetIdToIndex.end() ? -1 : hitDetIdToIndex.at(id).first; + rechitIndices.push_back(match); + } + + auto assoc = std::make_unique>(scCollection); + edm::Association::Filler filler(*assoc); + filler.insert(caloRechitCollection, rechitIndices.begin(), rechitIndices.end()); + filler.fill(); + iEvent.put(std::move(assoc), label+"ToSimClus"); + } +} + +// define this as a plug-in +DEFINE_FWK_MODULE(SimHitRecHitAssociationProducer); + diff --git a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc index 8426b258fd718..d9a92164fc366 100644 --- a/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc +++ b/PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc @@ -8,9 +8,10 @@ typedef SimpleFlatTableProducer SimpleSimClusterFlatTableProducer; #include "SimDataFormats/CaloHit/interface/PCaloHit.h" typedef SimpleFlatTableProducer SimplePCaloHitFlatTableProducer; - #include "SimDataFormats/TrackingHit/interface/PSimHit.h" typedef SimpleFlatTableProducer SimplePSimHitFlatTableProducer; +#include "DataFormats/CaloRecHit/interface/CaloRecHit.h" +typedef SimpleFlatTableProducer SimpleCaloRecHitFlatTableProducer; #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" typedef SimpleFlatTableProducer SimpleTrackingParticleFlatTableProducer; @@ -23,6 +24,8 @@ typedef SimpleFlatTableProducer SimplePFCandidateFlatTablePro #include "SimDataFormats/Track/interface/SimTrack.h" typedef SimpleFlatTableProducer SimpleSimTrackFlatTableProducer; +#include "DataFormats/TrackReco/interface/Track.h" +typedef SimpleFlatTableProducer SimpleTrackFlatTableProducer; #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" typedef EventSingletonSimpleFlatTableProducer SimpleGenEventFlatTableProducer; @@ -41,10 +44,12 @@ typedef EventSingletonSimpleFlatTableProducer SimpleXYZPointFla #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(SimplePCaloHitFlatTableProducer); +DEFINE_FWK_MODULE(SimpleCaloRecHitFlatTableProducer); DEFINE_FWK_MODULE(SimplePSimHitFlatTableProducer); DEFINE_FWK_MODULE(SimpleSimTrackFlatTableProducer); DEFINE_FWK_MODULE(SimpleSimClusterFlatTableProducer); DEFINE_FWK_MODULE(SimpleTrackingParticleFlatTableProducer); +DEFINE_FWK_MODULE(SimpleTrackFlatTableProducer); DEFINE_FWK_MODULE(SimplePFParticleFlatTableProducer); DEFINE_FWK_MODULE(SimplePFCandidateFlatTableProducer); DEFINE_FWK_MODULE(SimpleCaloParticleFlatTableProducer); diff --git a/PhysicsTools/NanoAOD/python/hgcRecHits_cff.py b/PhysicsTools/NanoAOD/python/hgcRecHits_cff.py new file mode 100644 index 0000000000000..a010dbba7825b --- /dev/null +++ b/PhysicsTools/NanoAOD/python/hgcRecHits_cff.py @@ -0,0 +1,103 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import Var,P3Vars + +hgcEERecHitsTable = cms.EDProducer("SimpleCaloRecHitFlatTableProducer", + src = cms.InputTag("HGCalRecHit:HGCEERecHits"), + cut = cms.string(""), + name = cms.string("RecHitHGCEE"), + doc = cms.string("RecHits in HGCAL Electromagnetic endcap"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the muons + variables = cms.PSet( + detId = Var('detid().rawId()', 'int', precision=-1, doc='detId'), + energy = Var('energy', 'float', precision=14, doc='energy'), + time = Var('time', 'float', precision=14, doc='hit time'), + ) +) + +hgcRecHitsToSimClusters = cms.EDProducer("SimHitRecHitAssociationProducer", + caloRecHits = cms.VInputTag("HGCalRecHit:HGCEERecHits", + "HGCalRecHit:HGCHEFRecHits", "HGCalRecHit:HGCHEBRecHits", + ), + simClusters = cms.InputTag("mix:MergedCaloTruth"), +) + +hgcEERecHitsToSimClusterTable = cms.EDProducer("CaloRecHitToSimClusterIndexTableProducer", + cut = hgcEERecHitsTable.cut, + src = hgcEERecHitsTable.src, + objName = hgcEERecHitsTable.name, + branchName = cms.string("SimCluster"), + objMap = cms.InputTag("hgcRecHitsToSimClusters:HGCEERecHitsToSimClus"), + docString = cms.string("SimCluster responsible for most sim energy in RecHit DetId") +) + +hgcRecHitsToPFCands = cms.EDProducer("RecHitToPFCandAssociationProducer", + caloRecHits = cms.VInputTag("HGCalRecHit:HGCEERecHits", + "HGCalRecHit:HGCHEFRecHits", "HGCalRecHit:HGCHEBRecHits", + ), + pfCands = cms.InputTag("particleFlow"), +) + +hgcEERecHitsToPFCandTable = cms.EDProducer("CaloRecHitToPFCandIndexTableProducer", + cut = hgcEERecHitsTable.cut, + src = hgcEERecHitsTable.src, + objName = hgcEERecHitsTable.name, + branchName = cms.string("PFCand"), + objMap = cms.InputTag("hgcRecHitsToPFCands:HGCEERecHitsToPFCand"), + docString = cms.string("PFCand with most associated energy in RecHit DetId") +) + +hgcHEfrontRecHitsTable = hgcEERecHitsTable.clone() +hgcHEfrontRecHitsTable.src = "HGCalRecHit:HGCHEFRecHits" +hgcHEfrontRecHitsTable.name = "RecHitHGCHEF" + +hgcHEfrontRecHitsToSimClusterTable = hgcEERecHitsToSimClusterTable.clone() +hgcHEfrontRecHitsToSimClusterTable.src = hgcHEfrontRecHitsTable.src +hgcHEfrontRecHitsToSimClusterTable.objName = hgcHEfrontRecHitsTable.name +hgcHEfrontRecHitsToSimClusterTable.objMap = "hgcRecHitsToSimClusters:HGCHEFRecHitsToSimClus" + +hgcHEfrontRecHitsToPFCandTable = hgcEERecHitsToPFCandTable.clone() +hgcHEfrontRecHitsToPFCandTable.src = hgcHEfrontRecHitsTable.src +hgcHEfrontRecHitsToPFCandTable.objName = hgcHEfrontRecHitsTable.name +hgcHEfrontRecHitsToPFCandTable.objMap = "hgcRecHitsToPFCands:HGCHEFRecHitsToPFCand" + +hgcHEbackRecHitsTable = hgcEERecHitsTable.clone() +hgcHEbackRecHitsTable.src = "HGCalRecHit:HGCHEBRecHits" +hgcHEbackRecHitsTable.name = "RecHitHGCHEB" + +hgcHEbackRecHitsToSimClusterTable = hgcEERecHitsToSimClusterTable.clone() +hgcHEbackRecHitsToSimClusterTable.src = hgcHEbackRecHitsTable.src +hgcHEbackRecHitsToSimClusterTable.objName = hgcHEbackRecHitsTable.name +hgcHEbackRecHitsToSimClusterTable.objMap = "hgcRecHitsToSimClusters:HGCHEBRecHitsToSimClus" + +hgcHEbackRecHitsToPFCandTable = hgcEERecHitsToPFCandTable.clone() +hgcHEbackRecHitsToPFCandTable.src = hgcHEbackRecHitsTable.src +hgcHEbackRecHitsToPFCandTable.objName = hgcHEbackRecHitsTable.name +hgcHEbackRecHitsToPFCandTable.objMap = "hgcRecHitsToPFCands:HGCHEBRecHitsToPFCand" + +hgcEERecHitsPositionTable = cms.EDProducer("HGCRecHitPositionFromDetIDTableProducer", + src = hgcEERecHitsTable.src, + cut = hgcEERecHitsTable.cut, + name = hgcEERecHitsTable.name, + doc = hgcEERecHitsTable.doc, +) +# +hgcHEfrontRecHitsPositionTable = hgcEERecHitsPositionTable.clone() +hgcHEfrontRecHitsPositionTable.name = hgcHEfrontRecHitsTable.name +hgcHEfrontRecHitsPositionTable.src = hgcHEfrontRecHitsTable.src + +hgcHEbackRecHitsPositionTable = hgcEERecHitsPositionTable.clone() +hgcHEbackRecHitsPositionTable.name = hgcHEbackRecHitsTable.name +hgcHEbackRecHitsPositionTable.src = hgcHEbackRecHitsTable.src + +hgcRecHitsSequence = cms.Sequence(hgcEERecHitsTable+hgcHEbackRecHitsTable+hgcHEfrontRecHitsTable + +hgcRecHitsToSimClusters + +hgcRecHitsToPFCands + +hgcEERecHitsToPFCandTable+hgcHEfrontRecHitsToPFCandTable+hgcHEbackRecHitsToPFCandTable + +hgcEERecHitsPositionTable + +hgcHEfrontRecHitsPositionTable + +hgcHEbackRecHitsPositionTable + +hgcEERecHitsToSimClusterTable + +hgcHEfrontRecHitsToSimClusterTable + +hgcHEbackRecHitsToSimClusterTable +) diff --git a/PhysicsTools/NanoAOD/python/hgcSimHits_cff.py b/PhysicsTools/NanoAOD/python/hgcSimHits_cff.py index 175c832641bff..c456803d77b88 100644 --- a/PhysicsTools/NanoAOD/python/hgcSimHits_cff.py +++ b/PhysicsTools/NanoAOD/python/hgcSimHits_cff.py @@ -12,7 +12,6 @@ detId = Var('id', 'int', precision=-1, doc='detId'), energy = Var('energy', 'float', precision=14, doc='energy'), trackId = Var('geantTrackId', 'int', precision=-1, doc='Geant4 track ID'), - #fineTrackId = Var('geantFineTrackId', 'int', precision=-1, doc='granular Geant4 track ID'), ) ) @@ -27,7 +26,7 @@ hgcHEfrontSimHitsTable = hgcEESimHitsTable.clone() hgcHEfrontSimHitsTable.src = "g4SimHits:HGCHitsHEfront" -hgcHEfrontSimHitsTable.name = "SimHitHGCHEfront" +hgcHEfrontSimHitsTable.name = "SimHitHGCHEF" hgcHEfrontHitsToSimClusterTable = hgcEEHitsToSimClusterTable.clone() hgcHEfrontHitsToSimClusterTable.src = hgcHEfrontSimHitsTable.src @@ -36,7 +35,7 @@ hgcHEbackSimHitsTable = hgcEESimHitsTable.clone() hgcHEbackSimHitsTable.src = "g4SimHits:HGCHitsHEback" -hgcHEbackSimHitsTable.name = "SimHitHGCHEback" +hgcHEbackSimHitsTable.name = "SimHitHGCHEB" hgcHEbackHitsToSimClusterTable = hgcEEHitsToSimClusterTable.clone() hgcHEbackHitsToSimClusterTable.src = hgcHEbackSimHitsTable.src @@ -66,3 +65,4 @@ +hgcHEfrontHitsToSimClusterTable +hgcHEbackHitsToSimClusterTable +hgcHEfrontSimHitsTable+hgcHEbackSimHitsTable) + diff --git a/PhysicsTools/NanoAOD/python/hgcSimTracks_cff.py b/PhysicsTools/NanoAOD/python/hgcSimTracks_cff.py index e5f972be25915..8a9870c44bb0c 100644 --- a/PhysicsTools/NanoAOD/python/hgcSimTracks_cff.py +++ b/PhysicsTools/NanoAOD/python/hgcSimTracks_cff.py @@ -3,30 +3,29 @@ simTrackTable = cms.EDProducer("SimpleSimTrackFlatTableProducer", src = cms.InputTag("g4SimHits"), - #cut = cms.string("abs(momentum().eta) > 1.52 || abs(getMomentumAtBoundary().eta()) > 1.52"), - cut = cms.string(""), + cut = cms.string("abs(momentum().eta) > 1.52 || abs(getMomentumAtBoundary().eta()) > 1.52"), name = cms.string("SimTrack"), doc = cms.string("Geant4 sim tracks in HGCAL Electromagnetic endcap"), singleton = cms.bool(False), # the number of entries is variable extension = cms.bool(False), # this is the main table for the muons variables = cms.PSet( + crossedBoundary = Var('crossedBoundary', 'bool', doc='track crossed boundary'), pdgId = Var('type', 'int', doc='pdgId (track type)'), charge = Var('charge', 'int', doc='ID'), trackId = Var('trackId', 'int', precision=-1, doc='ID'), - #trackIdAtBoundary = Var('getIDAtBoundary', 'int', precision=-1, doc='ID at boundary crossing'), + trackIdAtBoundary = Var('getIDAtBoundary', 'int', precision=-1, doc='ID at boundary crossing'), pt = Var('momentum().pt()', 'float', precision=14, doc='pt'), eta = Var('momentum().eta()', 'float', precision=14, doc='eta'), phi = Var('momentum().phi()', 'float', precision=14, doc='phi'), lastPos_x = Var('trackerSurfacePosition().x()', 'float', precision=14, doc='x position at HGCAL boundary'), lastPos_y = Var('trackerSurfacePosition().y()', 'float', precision=14, doc='y position at HGCAL boundary'), lastPos_z = Var('trackerSurfacePosition().z()', 'float', precision=14, doc='z position at HGCAL boundary'), - #crossedBoundary = Var('crossedBoundary', 'bool', doc='track crossed boundary'), - #boundaryPos_x = Var('getPositionAtBoundary().x()', 'float', precision=14, doc='x position at HGCAL boundary'), - #boundaryPos_y = Var('getPositionAtBoundary().y()', 'float', precision=14, doc='y position at HGCAL boundary'), - #boundaryPos_z = Var('getPositionAtBoundary().z()', 'float', precision=14, doc='z position at HGCAL boundary'), - #boundaryMomentum_pt = Var('getMomentumAtBoundary().pt()', 'float', precision=14, doc='pt at HGCAL boundary'), - #boundaryMomentum_eta = Var('getMomentumAtBoundary().eta()', 'float', precision=14, doc='eta position at HGCAL boundary'), - #boundaryMomentum_phi = Var('getMomentumAtBoundary().phi()', 'float', precision=14, doc='phi position at HGCAL boundary'), + boundaryPos_x = Var('getPositionAtBoundary().x()', 'float', precision=14, doc='x position at HGCAL boundary'), + boundaryPos_y = Var('getPositionAtBoundary().y()', 'float', precision=14, doc='y position at HGCAL boundary'), + boundaryPos_z = Var('getPositionAtBoundary().z()', 'float', precision=14, doc='z position at HGCAL boundary'), + boundaryMomentum_pt = Var('getMomentumAtBoundary().pt()', 'float', precision=14, doc='pt at HGCAL boundary'), + boundaryMomentum_eta = Var('getMomentumAtBoundary().eta()', 'float', precision=14, doc='eta position at HGCAL boundary'), + boundaryMomentum_phi = Var('getMomentumAtBoundary().phi()', 'float', precision=14, doc='phi position at HGCAL boundary'), ) ) diff --git a/PhysicsTools/NanoAOD/python/nanoHGCML_cff.py b/PhysicsTools/NanoAOD/python/nanoHGCML_cff.py index ef6f44f464fc9..1be868888a349 100644 --- a/PhysicsTools/NanoAOD/python/nanoHGCML_cff.py +++ b/PhysicsTools/NanoAOD/python/nanoHGCML_cff.py @@ -4,9 +4,11 @@ from hgcSimHits_cff import * from hgcSimTracks_cff import * from trackSimHits_cff import * +from hgcRecHits_cff import * from simClusters_cff import * from caloParticles_cff import * from trackingParticles_cff import * +from tracks_cff import * from genparticles_cff import genParticleTable from genVertex_cff import * from pfCands_cff import * @@ -21,7 +23,26 @@ genParticleTable.variables = cms.PSet(genParticleTable.variables, charge = CandVars.charge) -nanoHGCMLSequence = cms.Sequence(nanoMetadata+genVertexTables+genParticleTable+ \ - trackingParticleTable+caloParticleTable+simClusterTables+ \ - #pfCandTable+pfTICLCandTable \ +nanoHGCMLSequence = cms.Sequence(nanoMetadata+genVertexTables+genParticleTable+ + trackingParticleTable+caloParticleTable+simClusterTables+ simTrackTables+hgcSimHitsSequence+trackerSimHitTables) + +def customizeReco(process): + process.nanoHGCMLSequence.insert(1, hgcRecHitsSequence) + process.nanoHGCMLSequence.insert(2, pfCandTable) + process.nanoHGCMLSequence.insert(3, pfTICLCandTable) + process.nanoHGCMLSequence.insert(4, trackTables) + return process + +def customizeNoSimClusters(process): + process.nanoHGCMLSequence.remove(simClusterTable) + process.nanoHGCMLSequence.remove(simClusterToCaloPartTable) + process.nanoHGCMLSequence.remove(hgcEEHitsToSimClusterTable) + process.nanoHGCMLSequence.remove(hgcHEfrontHitsToSimClusterTable) + process.nanoHGCMLSequence.remove(hgcHEbackHitsToSimClusterTable) + process.nanoHGCMLSequence.remove(simTrackToSimClusterTable) + return process + +def customizeMergedSimClusters(process): + process.nanoHGCMLSequence.insert(1, mergedSimClusterTables) + return process diff --git a/PhysicsTools/NanoAOD/python/simClusters_cff.py b/PhysicsTools/NanoAOD/python/simClusters_cff.py index d6bf348eba1cb..d2d82e3bdc0f3 100644 --- a/PhysicsTools/NanoAOD/python/simClusters_cff.py +++ b/PhysicsTools/NanoAOD/python/simClusters_cff.py @@ -9,19 +9,28 @@ singleton = cms.bool(False), # the number of entries is variable extension = cms.bool(False), # this is the main table for the muons variables = cms.PSet(CandVars, - #x = Var('impactPoint().x()', 'float', precision=14, doc='x position'), - #y = Var('impactPoint().y()', 'float', precision=14, doc='y position'), - #z = Var('impactPoint().z()', 'float', precision=14, doc='z position'), - #impactPointX = Var('impactPoint().x()', 'float', precision=14, doc='x position'), - #impactPointY = Var('impactPoint().y()', 'float', precision=14, doc='y position'), - #impactPointZ = Var('impactPoint().z()', 'float', precision=14, doc='z position'), lastPos_x = Var('g4Tracks.at(0).trackerSurfacePosition().x()', 'float', precision=14, doc='track x final position'), lastPos_y = Var('g4Tracks.at(0).trackerSurfacePosition().y()', 'float', precision=14, doc='track y final position'), lastPos_z = Var('g4Tracks.at(0).trackerSurfacePosition().z()', 'float', precision=14, doc='track z final position'), - nSimHits = Var('numberOfSimHits', 'int', precision=-1, doc='total energy of simhits'), - simEnergy = Var('simEnergy', 'float', precision=14, doc='total energy of simhits'), - trackId = Var('g4Tracks().at(0).trackId()', 'int', precision=10, doc='Geant track id'), - #trackIdAtBoundary = Var('g4Tracks().at(0).getIDAtBoundary()', 'int', precision=-1, doc='Track ID at boundary'), + # NOTE: This is the cms-pepr approach, which is needed for merged simclusters + #impactPoint_x = Var('impactPoint().x()', 'float', precision=14, doc='x position'), + #impactPoint_y = Var('impactPoint().y()', 'float', precision=14, doc='y position'), + #impactPoint_z = Var('impactPoint().z()', 'float', precision=14, doc='z position'), + #impactPoint_t = Var('impactPoint().t()', 'float', precision=14, doc='Impact time'), + impactPoint_x = Var('g4Tracks().at(0).getPositionAtBoundary().x()', 'float', precision=14, doc='x position'), + impactPoint_y = Var('g4Tracks().at(0).getPositionAtBoundary().y()', 'float', precision=14, doc='y position'), + impactPoint_z = Var('g4Tracks().at(0).getPositionAtBoundary().z()', 'float', precision=14, doc='z position'), + impactPoint_t = Var('g4Tracks().at(0).getPositionAtBoundary().t()', 'float', precision=14, doc='Impact time'), + # For stupid reasons lost on me, the nsimhits_ variable is uninitialized, and hits_ (which are really simhits) + # are often referred to as rechits in the SimCluster class + nHits = Var('numberOfRecHits', 'int', precision=-1, doc='number of simhits'), + sumHitEnergy = Var('energy', 'float', precision=14, doc='total energy of simhits'), + boundaryPmag = Var('impactMomentum.P()', 'float', precision=14, doc='magnitude of the boundary 3-momentum vector'), + boundaryP4 = Var('impactMomentum.mag()', 'float', precision=14, doc='magnitude of four vector'), + boundaryEnergy = Var('impactMomentum.energy()', 'float', precision=14, doc='magnitude of four vector'), + boundaryPt = Var('impactMomentum.pt()', 'float', precision=14, doc='magnitude of four vector'), + trackId = Var('g4Tracks().at(0).trackId()', 'int', precision=-1, doc='Geant track id'), + trackIdAtBoundary = Var('g4Tracks().at(0).getIDAtBoundary()', 'int', precision=-1, doc='Track ID at boundary'), ) ) @@ -34,4 +43,21 @@ docString = cms.string("Index of CaloPart containing SimCluster") ) +hgcSimTruth = cms.EDProducer("HGCTruthProducer") + +simClusterToMergedSCTable = cms.EDProducer("SimClusterToSimClusterIndexTableProducer", + cut = simClusterTable.cut, + src = simClusterTable.src, + objName = simClusterTable.name, + branchName = cms.string("MergedSimCluster"), + objMap = cms.InputTag("hgcSimTruth"), + docString = cms.string("Index of Merged SimCluster containing SimCluster") +) + +mergedSimClusterTable = simClusterTable.clone() +mergedSimClusterTable.src = "hgcSimTruth" +mergedSimClusterTable.name = "MergedSimCluster" + simClusterTables = cms.Sequence(simClusterTable+simClusterToCaloPartTable) + +mergedSimClusterTables = cms.Sequence(hgcSimTruth+mergedSimClusterTable+simClusterToMergedSCTable) diff --git a/PhysicsTools/NanoAOD/python/trackSimHits_cff.py b/PhysicsTools/NanoAOD/python/trackSimHits_cff.py index c30c5f58066cc..7efb49957b7b6 100644 --- a/PhysicsTools/NanoAOD/python/trackSimHits_cff.py +++ b/PhysicsTools/NanoAOD/python/trackSimHits_cff.py @@ -13,6 +13,7 @@ extension = cms.bool(False), # this is the main table for the muons variables = cms.PSet( detId = Var('detUnitId', 'int', precision=-1, doc='detId'), + energy = Var('energyLoss', 'float', precision=14, doc='energy'), pMag = Var('pabs', 'float', precision=14, doc='magnitude of momentum'), trackId = Var('trackId', 'int', precision=-1, doc='Geant4 track ID'), pdgId = Var('particleType', 'int', doc='PDG ID of associated track'), diff --git a/PhysicsTools/NanoAOD/python/tracks_cff.py b/PhysicsTools/NanoAOD/python/tracks_cff.py new file mode 100644 index 0000000000000..20f2d66769761 --- /dev/null +++ b/PhysicsTools/NanoAOD/python/tracks_cff.py @@ -0,0 +1,48 @@ +import FWCore.ParameterSet.Config as cms +from PhysicsTools.NanoAOD.common_cff import P3Vars,Var + +generalTrackTable = cms.EDProducer("SimpleTrackFlatTableProducer", + src = cms.InputTag("generalTracks"), + cut = cms.string(""), + name = cms.string("Track"), + doc = cms.string("reco::Track"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the muons + variables = cms.PSet(P3Vars, + charge = Var("charge", int, doc="electric charge"), + normChiSq = Var("normalizedChi2", float, precision=14, doc="Chi^2/ndof"), + numberOfValidHits = Var('numberOfValidHits()', 'int', precision=-1, doc='Number of valid hits in track'), + numberOfLostHits = Var('numberOfLostHits()', 'int', precision=-1, doc='Number of lost hits in track'), + Vtx_x = Var('vx()', 'float', precision=14, doc='parent vertex x pos'), + Vtx_y = Var('vy()', 'float', precision=14, doc='parent vertex y pos'), + Vtx_z = Var('vz()', 'float', precision=14, doc='parent vertex z pos'), + Vtx_t = Var('t0', 'float', precision=14, doc='parent vertex time'), + # Be careful here, this isn't really a decay vertex + DecayVtx_y = Var('outerPosition().x()', 'float', precision=14, doc='x position of first decay vertex'), + DecayVtx_x = Var('outerPosition().y()', 'float', precision=14, doc='y position of first decay vertex'), + DecayVtx_z = Var('outerPosition().z()', 'float', precision=14, doc='z position of first decay vertex'), + DecayVtx_t = Var('0', 'float', precision=14, doc='DUMMY VALUE! for time of first decay vertex'), + ) +) + +trackConversionsTable = generalTrackTable.clone() +trackConversionsTable.src = "conversionStepTracks" +trackConversionsTable.name = "TrackConv" + +trackDisplacedTable = cms.EDProducer("SimpleTrackFlatTableProducer", + src = cms.InputTag("displacedTracks"), + cut = cms.string(""), + name = cms.string("TrackDisp"), + doc = cms.string("reco::Track"), + singleton = cms.bool(False), # the number of entries is variable + extension = cms.bool(False), # this is the main table for the muons + variables = cms.PSet(P3Vars, + charge = Var("charge", int, doc="electric charge"), + Vtx_x = Var('vx()', 'float', precision=14, doc='parent vertex x pos'), + Vtx_y = Var('vy()', 'float', precision=14, doc='parent vertex y pos'), + Vtx_z = Var('vz()', 'float', precision=14, doc='parent vertex z pos'), + Vtx_t = Var('t0', 'float', precision=14, doc='parent vertex time'), + ) +) + +trackTables = cms.Sequence(generalTrackTable+trackConversionsTable+trackDisplacedTable)