/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
PhysicsTools/TruthInfo/plugins/RecHitFlatTableProducer.cc
102 строки
5 KB
Felice Pantaleo
TICLGeom: migrate HGCAL reco, validation and associators to ticlgeom::Tools
25 июл 2026, 22:32
25 июл 2026, 22:32
a3cfed2
Код
Авторство
О чём код?
// Original author: Felice Pantaleo (CERN) <felice.pantaleo@cern.ch> // Part of the MC-truth-graph prototype - under heavy development, not yet open // to external contributions (see PhysicsTools/TruthInfo/README.md). #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/stream/moduleAbilities.h" #include "FWCore/Utilities/interface/ESGetToken.h" #include "FWCore/Utilities/interface/ESInputTag.h" #include "FWCore/Utilities/interface/transform.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "DataFormats/NanoAOD/interface/FlatTable.h" #include "RecoLocalCalo/HGCalRecAlgos/interface/TICLGeomTools.h" #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h" #include <vector> #include <iostream> class RecHitFlatTableProducer : public edm::stream::EDProducer<edm::stream::WatchRuns> { public: RecHitFlatTableProducer(edm::ParameterSet const& params) : objName_(params.getParameter<std::string>("objName")), rechits_tokens_{ edm::vector_transform(params.getParameter<std::vector<edm::InputTag>>("label_rechits"), [this](const edm::InputTag& lab) { return consumes<HGCRecHitCollection>(lab); })}, ticlGeom_token_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", ""))), ticlGeomLookup_token_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", ""))), ticlGeomLayers_token_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", ""))) { produces<nanoaod::FlatTable>(); } ~RecHitFlatTableProducer() override {} void produce(edm::Event& event, edm::EventSetup const& iSetup) override { std::vector<uint32_t> rechit_ID; std::vector<float> rechit_energy; std::vector<float> rechit_x; std::vector<float> rechit_y; std::vector<float> rechit_z; std::vector<float> rechit_time; std::vector<float> rechit_radius; for (auto const& rh_token : rechits_tokens_) { edm::Handle<HGCRecHitCollection> rechit_handle; event.getByToken(rh_token, rechit_handle); if (!rechit_handle.isValid()) continue; for (auto const& rh : *rechit_handle) { rechit_energy.push_back(rh.energy()); auto const rhPosition = rhtools_.getPosition(rh.detid()); rechit_x.push_back(rhPosition.x()); rechit_y.push_back(rhPosition.y()); rechit_z.push_back(rhPosition.z()); rechit_ID.push_back(rh.detid().rawId()); rechit_time.push_back(rh.time()); rechit_radius.push_back(rhtools_.getRadiusToSide(rh.detid())); } } auto tab = std::make_unique<nanoaod::FlatTable>(rechit_ID.size(), objName_, false, false); tab->addColumn<uint32_t>("rechit_ID", rechit_ID, "Rechit ID"); tab->addColumn<float>("rechit_energy", rechit_energy, "Rechit energy"); tab->addColumn<float>("rechit_x", rechit_x, "Rechit X from rechittools"); tab->addColumn<float>("rechit_y", rechit_y, "Rechit Y from rechittools"); tab->addColumn<float>("rechit_z", rechit_z, "Rechit Z from rechittools"); tab->addColumn<float>("rechit_time", rechit_time, "Rechit time"); tab->addColumn<float>("rechit_radius", rechit_radius, "Rechit radius to side from rechittools"); event.put(std::move(tab)); } void beginRun(edm::Run const&, edm::EventSetup const& es) override { rhtools_.setGeometry( es.getData(ticlGeom_token_), es.getData(ticlGeomLookup_token_), es.getData(ticlGeomLayers_token_)); } static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.add<std::string>("objName", "rechits")->setComment("name of the nanoaod::FlatTable to extend with this table"); desc.add<std::vector<edm::InputTag>>("label_rechits", {edm::InputTag("HGCalRecHit", "HGCEERecHits"), edm::InputTag("HGCalRecHit", "HGCHEFRecHits"), edm::InputTag("HGCalRecHit", "HGCHEBRecHits")}); descriptions.add("recHitTable", desc); } protected: const std::string objName_; // const edm::EDGetTokenT<edm::View<pat::PackedGenParticle>> src_; const std::vector<edm::EDGetTokenT<HGCRecHitCollection>> rechits_tokens_; edm::ESGetToken<TICLGeomHost, CaloGeometryRecord> ticlGeom_token_; edm::ESGetToken<TICLGeomLookupHost, CaloGeometryRecord> ticlGeomLookup_token_; edm::ESGetToken<TICLGeomLayersHost, CaloGeometryRecord> ticlGeomLayers_token_; ticlgeom::Tools rhtools_; }; #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(RecHitFlatTableProducer);