diff --git a/RecoLocalCalo/HcalRecProducers/BuildFile.xml b/RecoLocalCalo/HcalRecProducers/BuildFile.xml index c3ae589a0c0a7..9c4b594ab430e 100644 --- a/RecoLocalCalo/HcalRecProducers/BuildFile.xml +++ b/RecoLocalCalo/HcalRecProducers/BuildFile.xml @@ -6,3 +6,5 @@ + + diff --git a/RecoLocalCalo/HcalRecProducers/src/FacileHcalReconstructor.cc b/RecoLocalCalo/HcalRecProducers/src/FacileHcalReconstructor.cc new file mode 100644 index 0000000000000..b43243c3ab735 --- /dev/null +++ b/RecoLocalCalo/HcalRecProducers/src/FacileHcalReconstructor.cc @@ -0,0 +1,98 @@ +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" +#include "HeterogeneousCore/SonicTriton/interface/TritonClient.h" +#include "HeterogeneousCore/SonicCore/interface/SonicEDProducer.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "DataFormats/HcalRecHit/interface/HBHERecHit.h" +#include "Geometry/CaloTopology/interface/HcalTopology.h" +#include "Geometry/Records/interface/HcalRecNumberingRecord.h" + +class FacileHcalReconstructor : public SonicEDProducer { +public: + explicit FacileHcalReconstructor(edm::ParameterSet const& cfg) + : SonicEDProducer(cfg), + fChannelInfoName_(cfg.getParameter("ChannelInfoName")), + fTokChannelInfo_(consumes(fChannelInfoName_)), + htopoToken_(esConsumes()) { + produces(); + setDebugName("FacileHcalReconstructor"); + } + + void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) override { + edm::Handle hChannelInfo; + iEvent.getByToken(fTokChannelInfo_, hChannelInfo); + + const HcalTopology* htopo = &iSetup.getData(htopoToken_); + + auto& input1 = iInput.begin()->second; + auto data1 = std::make_shared>(); + data1->reserve(hChannelInfo->size()); + client_.setBatchSize(hChannelInfo->size()); + + hcalIds_.clear(); + + for (const auto& pChannel : *hChannelInfo) { + std::vector input; + const HcalDetId pDetId = pChannel.id(); + hcalIds_.push_back(pDetId); + + //inputs for Facile: iphi, gain, raw[8], depth (categorical), ieta (categorical) + input.push_back(pDetId.iphi()); + input.push_back(pChannel.tsGain(0.)); + for (unsigned int itTS = 0; itTS < pChannel.nSamples(); ++itTS) { + input.push_back(pChannel.tsRawCharge(itTS)); + } + + for (int itDepth = 1; itDepth <= htopo->maxDepth(); itDepth++) { + input.push_back(pDetId.depth() == itDepth); + } + + for (int itIeta = 0; itIeta <= htopo->lastHERing(); itIeta++) { + input.push_back(pDetId.ietaAbs() == itIeta); + } + + data1->push_back(input); + } + + input1.toServer(data1); + } + + void produce(edm::Event& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) override { + std::unique_ptr out; + out = std::make_unique(); + out->reserve(hcalIds_.size()); + + const auto& output1 = iOutput.begin()->second; + const auto& outputs = output1.fromServer(); + + for (std::size_t iB = 0; iB < hcalIds_.size(); iB++) { + float rhE = outputs[iB][0]; + if (rhE < 0. or std::isnan(rhE) or std::isinf(rhE)) + rhE = 0; + + HBHERecHit rh = HBHERecHit(hcalIds_[iB], rhE, 0.f, 0.f); + out->push_back(rh); + } + iEvent.put(std::move(out)); + } + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + TritonClient::fillPSetDescription(desc); + desc.add("ChannelInfoName"); + descriptions.add("FacileHcalReconstructor", desc); + } + +private: + edm::InputTag fChannelInfoName_; + edm::EDGetTokenT fTokChannelInfo_; + std::vector hcalIds_; + edm::ESGetToken htopoToken_; +}; + +DEFINE_FWK_MODULE(FacileHcalReconstructor); diff --git a/RecoLocalCalo/HcalRecProducers/test/sonic_hlt_test.py b/RecoLocalCalo/HcalRecProducers/test/sonic_hlt_test.py new file mode 100644 index 0000000000000..a7f50c0c3bc47 --- /dev/null +++ b/RecoLocalCalo/HcalRecProducers/test/sonic_hlt_test.py @@ -0,0 +1,32 @@ +import FWCore.ParameterSet.Config as cms +import os,sys + +sys.path = sys.path + [os.path.expandvars("$CMSSW_BASE/src/HLTrigger/Configuration/test/"), os.path.expandvars("$CMSSW_RELEASE_BASE/src/HLTrigger/Configuration/test/")] + +from OnLine_HLT_GRun import process + +process.hltHbherecopre = process.hltHbhereco.clone( + makeRecHits = cms.bool(False), + saveInfos = cms.bool(True), +) + +process.hltHbhereco = cms.EDProducer("FacileHcalReconstructor", + Client = cms.PSet( + batchSize = cms.untracked.uint32(16000), + address = cms.untracked.string("0.0.0.0"), + port = cms.untracked.uint32(8001), + timeout = cms.untracked.uint32(300), + modelName = cms.string("facile_all_v2"), + mode = cms.string("Async"), + modelVersion = cms.int32(-1), + verbose = cms.untracked.bool(False), + allowedTries = cms.untracked.uint32(5), + outputs = cms.untracked.vstring("output/BiasAdd"), + ), + ChannelInfoName = cms.InputTag("hltHbherecopre") +) + +process.HLTDoLocalHcalSequence = cms.Sequence( process.hltHcalDigis + process.hltHbherecopre + process.hltHbhereco + process.hltHfprereco + process.hltHfreco + process.hltHoreco ) +process.HLTStoppedHSCPLocalHcalReco = cms.Sequence( process.hltHcalDigis + process.hltHbherecopre + process.hltHbhereco) + +process.source.fileNames = cms.untracked.vstring("file:RelVal_Raw_GRun_MC.root")