Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-18 08:23:36

0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 
0003 #include "L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h"
0004 #include "L1Trigger/L1THGCal/interface/backend/HGCalHistoClusteringImpl_SA.h"
0005 
0006 #include "DataFormats/L1THGCal/interface/HGCalCluster.h"
0007 #include "DataFormats/L1THGCal/interface/HGCalMulticluster.h"
0008 
0009 #include "L1Trigger/L1THGCal/interface/backend/HGCalCluster_SA.h"
0010 #include "L1Trigger/L1THGCal/interface/backend/HGCalSeed_SA.h"
0011 #include "L1Trigger/L1THGCal/interface/backend/HGCalMulticluster_SA.h"
0012 
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 
0015 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0016 #include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"
0017 
0018 class HGCalHistoClusteringWrapper : public HGCalHistoClusteringWrapperBase {
0019 public:
0020   HGCalHistoClusteringWrapper(const edm::ParameterSet& conf);
0021   ~HGCalHistoClusteringWrapper() override {}
0022 
0023   void configure(
0024       const std::pair<const HGCalTriggerGeometryBase* const, const edm::ParameterSet&>& configuration) override;
0025 
0026   void process(const std::pair<const std::vector<edm::Ptr<l1t::HGCalCluster>>,
0027                                const std::vector<std::pair<GlobalPoint, double>>>& inputClustersAndSeeds,
0028                std::pair<l1t::HGCalMulticlusterBxCollection&, l1t::HGCalClusterBxCollection&>&
0029                    outputMulticlustersAndRejectedClusters) const override;
0030 
0031 private:
0032   void convertCMSSWInputs(const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
0033                           l1thgcfirmware::HGCalClusterSACollection& clusters_SA,
0034                           const std::vector<std::pair<GlobalPoint, double>>& seeds,
0035                           l1thgcfirmware::HGCalSeedSACollection& seeds_SA) const;
0036   void convertAlgorithmOutputs(const l1thgcfirmware::HGCalMulticlusterSACollection& multiclusters_out,
0037                                const l1thgcfirmware::HGCalClusterSACollection& rejected_clusters_out,
0038                                const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
0039                                l1t::HGCalMulticlusterBxCollection& multiclusters,
0040                                l1t::HGCalClusterBxCollection& rejected_clusters) const;
0041 
0042   void clusterizeHisto(const l1thgcfirmware::HGCalClusterSACollection& inputClusters,
0043                        const l1thgcfirmware::HGCalSeedSACollection& inputSeeds,
0044                        l1thgcfirmware::HGCalMulticlusterSACollection& outputMulticlusters,
0045                        l1thgcfirmware::HGCalClusterSACollection& outputRejectedClusters) const;
0046 
0047   void setGeometry(const HGCalTriggerGeometryBase* const geom) { triggerTools_.setGeometry(geom); }
0048 
0049   HGCalTriggerTools triggerTools_;
0050 
0051   HGCalHistoClusteringImplSA theAlgo_;
0052 
0053   l1thgcfirmware::ClusterAlgoConfig theConfiguration_;
0054 
0055   static constexpr double kMidRadius_ = 2.3;
0056 };
0057 
0058 HGCalHistoClusteringWrapper::HGCalHistoClusteringWrapper(const edm::ParameterSet& conf)
0059     : HGCalHistoClusteringWrapperBase(conf),
0060       theAlgo_(),
0061       theConfiguration_(kMidRadius_,
0062                         conf.getParameter<double>("dR_multicluster"),
0063                         conf.existsAs<std::vector<double>>("dR_multicluster_byLayer_coefficientA")
0064                             ? conf.getParameter<std::vector<double>>("dR_multicluster_byLayer_coefficientA")
0065                             : std::vector<double>(),
0066                         conf.existsAs<std::vector<double>>("dR_multicluster_byLayer_coefficientB")
0067                             ? conf.getParameter<std::vector<double>>("dR_multicluster_byLayer_coefficientB")
0068                             : std::vector<double>(),
0069                         conf.getParameter<double>("minPt_multicluster")) {}
0070 
0071 void HGCalHistoClusteringWrapper::convertCMSSWInputs(const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
0072                                                      std::vector<l1thgcfirmware::HGCalCluster>& clusters_SA,
0073                                                      const std::vector<std::pair<GlobalPoint, double>>& seeds,
0074                                                      std::vector<l1thgcfirmware::HGCalSeed>& seeds_SA) const {
0075   clusters_SA.clear();
0076   clusters_SA.reserve(clustersPtrs.size());
0077   unsigned int clusterIndex = 0;
0078   for (const auto& cluster : clustersPtrs) {
0079     clusters_SA.emplace_back(cluster->centreProj().x(),
0080                              cluster->centreProj().y(),
0081                              cluster->centre().z(),
0082                              triggerTools_.zside(cluster->detId()),
0083                              triggerTools_.layerWithOffset(cluster->detId()),
0084                              cluster->eta(),
0085                              cluster->phi(),
0086                              cluster->pt(),
0087                              cluster->mipPt(),
0088                              clusterIndex);
0089     ++clusterIndex;
0090   }
0091 
0092   seeds_SA.clear();
0093   seeds_SA.reserve(seeds.size());
0094   for (const auto& seed : seeds) {
0095     seeds_SA.emplace_back(seed.first.x(), seed.first.y(), seed.first.z(), seed.second);
0096   }
0097 }
0098 
0099 void HGCalHistoClusteringWrapper::convertAlgorithmOutputs(
0100     const std::vector<l1thgcfirmware::HGCalMulticluster>& multiclusters_out,
0101     const std::vector<l1thgcfirmware::HGCalCluster>& rejected_clusters_out,
0102     const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
0103     l1t::HGCalMulticlusterBxCollection& multiclustersBXCollection,
0104     l1t::HGCalClusterBxCollection& rejected_clusters) const {
0105   // Not doing completely the correct thing here
0106   // Taking the multiclusters from the stand alone emulation
0107   // Getting their consistuent clusters (stand alone objects)
0108   // Linking back to the original CMSSW-type cluster
0109   // And creating a CMSSW-type multicluster based from these clusters
0110   // So the output multiclusters will not be storing bit accurate quantities (or whatever was derived by the stand along emulation)
0111   // As these inherit from L1Candidate, could set their HW quantities to the bit accurate ones
0112   for (const auto& rejected_cluster : rejected_clusters_out) {
0113     rejected_clusters.push_back(0, *clustersPtrs.at(rejected_cluster.index_cmssw()));
0114   }
0115 
0116   std::vector<l1t::HGCalMulticluster> multiclusters;
0117   multiclusters.reserve(multiclusters_out.size());
0118   for (unsigned int imulticluster = 0; imulticluster < multiclusters_out.size(); ++imulticluster) {
0119     bool firstConstituent = true;
0120     for (const auto& constituent : multiclusters_out[imulticluster].constituents()) {
0121       if (firstConstituent) {
0122         multiclusters.emplace_back(clustersPtrs.at(constituent.index_cmssw()), 1.);
0123       } else {
0124         multiclusters.at(imulticluster).addConstituent(clustersPtrs.at(constituent.index_cmssw()), 1.);
0125       }
0126       firstConstituent = false;
0127     }
0128   }
0129 
0130   for (const auto& multicluster : multiclusters) {
0131     multiclustersBXCollection.push_back(0, multicluster);
0132   }
0133 }
0134 
0135 void HGCalHistoClusteringWrapper::process(
0136     const std::pair<const std::vector<edm::Ptr<l1t::HGCalCluster>>, const std::vector<std::pair<GlobalPoint, double>>>&
0137         inputClustersAndSeeds,
0138     std::pair<l1t::HGCalMulticlusterBxCollection&, l1t::HGCalClusterBxCollection&>&
0139         outputMulticlustersAndRejectedClusters) const {
0140   l1thgcfirmware::HGCalClusterSACollection clusters_SA;
0141   l1thgcfirmware::HGCalSeedSACollection seeds_SA;
0142   convertCMSSWInputs(inputClustersAndSeeds.first, clusters_SA, inputClustersAndSeeds.second, seeds_SA);
0143 
0144   l1thgcfirmware::HGCalClusterSACollection rejected_clusters_finalized_SA;
0145   l1thgcfirmware::HGCalMulticlusterSACollection multiclusters_finalized_SA;
0146   clusterizeHisto(clusters_SA, seeds_SA, multiclusters_finalized_SA, rejected_clusters_finalized_SA);
0147 
0148   convertAlgorithmOutputs(multiclusters_finalized_SA,
0149                           rejected_clusters_finalized_SA,
0150                           inputClustersAndSeeds.first,
0151                           outputMulticlustersAndRejectedClusters.first,
0152                           outputMulticlustersAndRejectedClusters.second);
0153 }
0154 
0155 void HGCalHistoClusteringWrapper::clusterizeHisto(
0156     const l1thgcfirmware::HGCalClusterSACollection& inputClusters,
0157     const l1thgcfirmware::HGCalSeedSACollection& inputSeeds,
0158     l1thgcfirmware::HGCalMulticlusterSACollection& outputMulticlusters,
0159     l1thgcfirmware::HGCalClusterSACollection& outputRejectedClusters) const {
0160   // Call SA clustering
0161   std::vector<l1thgcfirmware::HGCalCluster> rejected_clusters_vec_SA;
0162   std::vector<l1thgcfirmware::HGCalMulticluster> multiclusters_vec_SA =
0163       theAlgo_.clusterSeedMulticluster_SA(inputClusters, inputSeeds, rejected_clusters_vec_SA, theConfiguration_);
0164 
0165   theAlgo_.finalizeClusters_SA(
0166       multiclusters_vec_SA, rejected_clusters_vec_SA, outputMulticlusters, outputRejectedClusters, theConfiguration_);
0167 }
0168 
0169 void HGCalHistoClusteringWrapper::configure(
0170     const std::pair<const HGCalTriggerGeometryBase* const, const edm::ParameterSet&>& configuration) {
0171   setGeometry(configuration.first);
0172 
0173   // theConfiguration_.setParameters( ... );
0174 
0175   if ((!theConfiguration_.dr_byLayer_coefficientA().empty() &&
0176        (theConfiguration_.dr_byLayer_coefficientA().size() - 1) < triggerTools_.lastLayerBH()) ||
0177       (!theConfiguration_.dr_byLayer_coefficientB().empty() &&
0178        (theConfiguration_.dr_byLayer_coefficientB().size() - 1) < triggerTools_.lastLayerBH())) {
0179     throw cms::Exception("Configuration")
0180         << "The per-layer dR values go up to " << (theConfiguration_.dr_byLayer_coefficientA().size() - 1) << "(A) and "
0181         << (theConfiguration_.dr_byLayer_coefficientB().size() - 1) << "(B), while layers go up to "
0182         << triggerTools_.lastLayerBH() << "\n";
0183   }
0184 };
0185 
0186 DEFINE_EDM_PLUGIN(HGCalHistoClusteringWrapperBaseFactory, HGCalHistoClusteringWrapper, "HGCalHistoClusteringWrapper");