File indexing completed on 2025-06-20 01:53:34
0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/stream/EDProducer.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006
0007 #include "DataFormats/L1TParticleFlow/interface/PFCluster.h"
0008 #include "L1Trigger/Phase2L1ParticleFlow/interface/corrector.h"
0009 #include "L1Trigger/Phase2L1ParticleFlow/interface/ParametricResolution.h"
0010 #include "L1Trigger/Phase2L1ParticleFlow/interface/CaloClusterer.h"
0011
0012 #include "DataFormats/L1TCalorimeterPhase2/interface/CaloCrystalCluster.h"
0013 #include "DataFormats/L1TCalorimeterPhase2/interface/DigitizedClusterCorrelator.h"
0014
0015 namespace l1tpf {
0016 class PFClusterProducerFromL1EGClusters : public edm::stream::EDProducer<> {
0017 public:
0018 explicit PFClusterProducerFromL1EGClusters(const edm::ParameterSet &);
0019 ~PFClusterProducerFromL1EGClusters() override {}
0020
0021 private:
0022 edm::EDGetTokenT<l1tp2::CaloCrystalClusterCollection> src_;
0023 edm::EDGetTokenT<l1tp2::DigitizedClusterCorrelatorCollection> digi_src_;
0024
0025 double etCut_;
0026 std::vector<double> const etaBounds_;
0027 std::vector<double> const phiBounds_;
0028 std::vector<unsigned int> const maxClustersEtaPhi_;
0029 l1tpf::corrector corrector_;
0030 l1tpf::ParametricResolution resol_;
0031
0032 void produce(edm::Event &, const edm::EventSetup &) override;
0033
0034 };
0035 }
0036
0037 l1tpf::PFClusterProducerFromL1EGClusters::PFClusterProducerFromL1EGClusters(const edm::ParameterSet &iConfig)
0038 : src_(consumes<l1tp2::CaloCrystalClusterCollection>(iConfig.getParameter<edm::InputTag>("src"))),
0039 digi_src_(consumes<l1tp2::DigitizedClusterCorrelatorCollection>(iConfig.getParameter<edm::InputTag>("digi_src"))),
0040 etCut_(iConfig.getParameter<double>("etMin")),
0041 etaBounds_(iConfig.getParameter<std::vector<double>>("etaBounds")),
0042 phiBounds_(iConfig.getParameter<std::vector<double>>("phiBounds")),
0043 maxClustersEtaPhi_(iConfig.getParameter<std::vector<unsigned int>>("maxClustersEtaPhi")),
0044 corrector_(iConfig.getParameter<std::string>("corrector"), -1),
0045 resol_(iConfig.getParameter<edm::ParameterSet>("resol")) {
0046 produces<l1t::PFClusterCollection>("all");
0047 produces<l1t::PFClusterCollection>("selected");
0048 if ((etaBounds_.size() - 1) * (phiBounds_.size() - 1) != maxClustersEtaPhi_.size()) {
0049 throw cms::Exception("Configuration")
0050 << "Size mismatch between eta/phi bounds and max clusters: " << (etaBounds_.size() - 1) << " x "
0051 << (phiBounds_.size() - 1) << " != " << maxClustersEtaPhi_.size() << "\n";
0052 }
0053 if (!std::is_sorted(etaBounds_.begin(), etaBounds_.end())) {
0054 throw cms::Exception("Configuration") << "etaBounds is not sorted\n";
0055 }
0056 if (!std::is_sorted(phiBounds_.begin(), phiBounds_.end())) {
0057 throw cms::Exception("Configuration") << "phiBounds is not sorted\n";
0058 }
0059 }
0060
0061 void l1tpf::PFClusterProducerFromL1EGClusters::produce(edm::Event &iEvent, const edm::EventSetup &) {
0062 std::unique_ptr<l1t::PFClusterCollection> out(new l1t::PFClusterCollection());
0063 std::unique_ptr<l1t::PFClusterCollection> out_sel(new l1t::PFClusterCollection());
0064 edm::Handle<l1tp2::CaloCrystalClusterCollection> clusters;
0065 edm::Handle<l1tp2::DigitizedClusterCorrelatorCollection> digi_clusters;
0066 iEvent.getByToken(src_, clusters);
0067 iEvent.getByToken(digi_src_, digi_clusters);
0068 assert(clusters->size() == digi_clusters->size());
0069
0070 l1tpf_calo::GridSelector selector = l1tpf_calo::GridSelector(etaBounds_, phiBounds_, maxClustersEtaPhi_);
0071
0072 for (unsigned int index = 0; index < clusters->size(); ++index) {
0073 const auto &cryCl = (*clusters)[index];
0074 const auto &digiCryCl = (*digi_clusters)[index];
0075
0076 if (cryCl.pt() <= etCut_)
0077 continue;
0078
0079 l1t::PFCluster cluster(cryCl.pt(),
0080 cryCl.eta(),
0081 cryCl.phi(),
0082 0.,
0083 true);
0084 if (corrector_.valid())
0085 corrector_.correctPt(cluster);
0086 cluster.setPtError(resol_(cluster.pt(), std::abs(cluster.eta())));
0087
0088
0089
0090
0091 unsigned int qual = (digiCryCl.passes_iso() && digiCryCl.passes_ss()) |
0092 ((digiCryCl.passes_looseTkiso() && digiCryCl.passes_looseTkss()) << 1) | (false << 2);
0093 cluster.setHwQual(qual);
0094
0095 out->push_back(cluster);
0096 out->back().addConstituent(edm::Ptr<l1t::L1Candidate>(clusters, index));
0097 selector.fill(cluster.pt(), cluster.eta(), cluster.phi(), index);
0098 }
0099 std::vector<unsigned int> indices = selector.returnSorted();
0100 for (unsigned int ii = 0; ii < indices.size(); ii++) {
0101 unsigned int theIndex = indices[ii];
0102 const auto &digiCryCl = (*digi_clusters)[theIndex];
0103
0104 l1t::PFCluster cluster((clusters->begin() + theIndex)->pt(),
0105 (clusters->begin() + theIndex)->eta(),
0106 (clusters->begin() + theIndex)->phi(),
0107 0.,
0108 true);
0109 if (corrector_.valid())
0110 corrector_.correctPt(cluster);
0111 cluster.setPtError(resol_(cluster.pt(), std::abs(cluster.eta())));
0112 unsigned int qual = (digiCryCl.passes_iso() && digiCryCl.passes_ss()) |
0113 ((digiCryCl.passes_looseTkiso() && digiCryCl.passes_looseTkss()) << 1) | (false << 2);
0114 cluster.setHwQual(qual);
0115
0116
0117 out_sel->push_back(cluster);
0118 out_sel->back().addConstituent(edm::Ptr<l1t::L1Candidate>(clusters, theIndex));
0119 }
0120
0121 iEvent.put(std::move(out), "all");
0122 iEvent.put(std::move(out_sel), "selected");
0123 }
0124 using l1tpf::PFClusterProducerFromL1EGClusters;
0125 DEFINE_FWK_MODULE(PFClusterProducerFromL1EGClusters);