Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:30

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 "DataFormats/L1Trigger/interface/EGamma.h"
0011 #include "L1Trigger/Phase2L1ParticleFlow/interface/CaloClusterer.h"
0012 
0013 namespace l1tpf {
0014   class PFClusterProducerFromL1EGClusters : public edm::stream::EDProducer<> {
0015   public:
0016     explicit PFClusterProducerFromL1EGClusters(const edm::ParameterSet &);
0017     ~PFClusterProducerFromL1EGClusters() override {}
0018 
0019   private:
0020     edm::EDGetTokenT<BXVector<l1t::EGamma>> src_;
0021     double etCut_;
0022     std::vector<double> const etaBounds_;
0023     std::vector<double> const phiBounds_;
0024     std::vector<unsigned int> const maxClustersEtaPhi_;
0025     l1tpf::corrector corrector_;
0026     l1tpf::ParametricResolution resol_;
0027 
0028     void produce(edm::Event &, const edm::EventSetup &) override;
0029 
0030   };  // class
0031 }  // namespace l1tpf
0032 
0033 l1tpf::PFClusterProducerFromL1EGClusters::PFClusterProducerFromL1EGClusters(const edm::ParameterSet &iConfig)
0034     : src_(consumes<BXVector<l1t::EGamma>>(iConfig.getParameter<edm::InputTag>("src"))),
0035       etCut_(iConfig.getParameter<double>("etMin")),
0036       etaBounds_(iConfig.getParameter<std::vector<double>>("etaBounds")),
0037       phiBounds_(iConfig.getParameter<std::vector<double>>("phiBounds")),
0038       maxClustersEtaPhi_(iConfig.getParameter<std::vector<unsigned int>>("maxClustersEtaPhi")),
0039       corrector_(iConfig.getParameter<std::string>("corrector"), -1),
0040       resol_(iConfig.getParameter<edm::ParameterSet>("resol")) {
0041   produces<l1t::PFClusterCollection>("all");
0042   produces<l1t::PFClusterCollection>("selected");
0043   if ((etaBounds_.size() - 1) * (phiBounds_.size() - 1) != maxClustersEtaPhi_.size()) {
0044     throw cms::Exception("Configuration")
0045         << "Size mismatch between eta/phi bounds and max clusters: " << (etaBounds_.size() - 1) << " x "
0046         << (phiBounds_.size() - 1) << " != " << maxClustersEtaPhi_.size() << "\n";
0047   }
0048   if (!std::is_sorted(etaBounds_.begin(), etaBounds_.end())) {
0049     throw cms::Exception("Configuration") << "etaBounds is not sorted\n";
0050   }
0051   if (!std::is_sorted(phiBounds_.begin(), phiBounds_.end())) {
0052     throw cms::Exception("Configuration") << "phiBounds is not sorted\n";
0053   }
0054 }
0055 
0056 void l1tpf::PFClusterProducerFromL1EGClusters::produce(edm::Event &iEvent, const edm::EventSetup &) {
0057   std::unique_ptr<l1t::PFClusterCollection> out(new l1t::PFClusterCollection());
0058   std::unique_ptr<l1t::PFClusterCollection> out_sel(new l1t::PFClusterCollection());
0059   edm::Handle<BXVector<l1t::EGamma>> clusters;
0060   iEvent.getByToken(src_, clusters);
0061 
0062   l1tpf_calo::GridSelector selector = l1tpf_calo::GridSelector(etaBounds_, phiBounds_, maxClustersEtaPhi_);
0063 
0064   unsigned int index = 0;
0065   for (auto it = clusters->begin(), ed = clusters->end(); it != ed; ++it, ++index) {
0066     if (it->pt() <= etCut_)
0067       continue;
0068 
0069     l1t::PFCluster cluster(
0070         it->pt(), it->eta(), it->phi(), /*hOverE=*/0., /*isEM=*/true);  // it->hovere() seems to return random values
0071     if (corrector_.valid())
0072       corrector_.correctPt(cluster);
0073     cluster.setPtError(resol_(cluster.pt(), std::abs(cluster.eta())));
0074     cluster.setHwQual(it->hwQual());
0075     out->push_back(cluster);
0076     out->back().addConstituent(edm::Ptr<l1t::L1Candidate>(clusters, index));
0077     selector.fill(cluster.pt(), cluster.eta(), cluster.phi(), index);
0078   }
0079   std::vector<unsigned int> indices = selector.returnSorted();
0080   for (unsigned int ii = 0; ii < indices.size(); ii++) {
0081     unsigned int theIndex = indices[ii];
0082     l1t::PFCluster cluster((clusters->begin() + theIndex)->pt(),
0083                            (clusters->begin() + theIndex)->eta(),
0084                            (clusters->begin() + theIndex)->phi(),
0085                            /*hOverE=*/0.,
0086                            /*isEM=*/true);  // it->hovere() seems to return random values
0087     if (corrector_.valid())
0088       corrector_.correctPt(cluster);
0089     cluster.setPtError(resol_(cluster.pt(), std::abs(cluster.eta())));
0090     cluster.setHwQual((clusters->begin() + theIndex)->hwQual());
0091     out_sel->push_back(cluster);
0092     out_sel->back().addConstituent(edm::Ptr<l1t::L1Candidate>(clusters, theIndex));
0093   }
0094 
0095   iEvent.put(std::move(out), "all");
0096   iEvent.put(std::move(out_sel), "selected");
0097 }
0098 using l1tpf::PFClusterProducerFromL1EGClusters;
0099 DEFINE_FWK_MODULE(PFClusterProducerFromL1EGClusters);