Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:39

0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 
0003 #include "L1Trigger/L1THGCal/interface/HGCalAlgoWrapperBase.h"
0004 #include "L1Trigger/L1THGCal/interface/backend/HGCalSortingTruncationImpl_SA.h"
0005 
0006 #include "DataFormats/L1THGCal/interface/HGCalMulticluster.h"
0007 #include "L1Trigger/L1THGCal/interface/backend/HGCalMulticluster_SA.h"
0008 
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0012 #include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"
0013 
0014 class HGCalSortingTruncationWrapper : public HGCalStage2FilteringWrapperBase {
0015 public:
0016   HGCalSortingTruncationWrapper(const edm::ParameterSet& conf);
0017   ~HGCalSortingTruncationWrapper() override = default;
0018 
0019   void configure(
0020       const std::pair<const HGCalTriggerGeometryBase* const, const edm::ParameterSet&>& configuration) override;
0021 
0022   void process(const l1t::HGCalMulticlusterBxCollection&, l1t::HGCalMulticlusterBxCollection&) const override;
0023 
0024 private:
0025   void convertCMSSWInputs(const l1t::HGCalMulticlusterBxCollection& multiclusters,
0026                           l1thgcfirmware::HGCalMulticlusterSACollection& multiclusters_SA) const;
0027   void convertAlgorithmOutputs(const l1thgcfirmware::HGCalMulticlusterSACollection& multiclusters_out,
0028                                const l1t::HGCalMulticlusterBxCollection& multiclusters_original,
0029                                l1t::HGCalMulticlusterBxCollection& multiclustersBXCollection) const;
0030 
0031   void setGeometry(const HGCalTriggerGeometryBase* const geom) { triggerTools_.setGeometry(geom); }
0032 
0033   HGCalTriggerTools triggerTools_;
0034   HGCalSortingTruncationImplSA theAlgo_;
0035   l1thgcfirmware::SortingTruncationAlgoConfig theConfiguration_;
0036 };
0037 
0038 HGCalSortingTruncationWrapper::HGCalSortingTruncationWrapper(const edm::ParameterSet& conf)
0039     : HGCalStage2FilteringWrapperBase(conf), theAlgo_(), theConfiguration_(conf.getParameter<unsigned>("maxTCs")) {}
0040 
0041 void HGCalSortingTruncationWrapper::convertCMSSWInputs(
0042     const l1t::HGCalMulticlusterBxCollection& multiclusters,
0043     l1thgcfirmware::HGCalMulticlusterSACollection& multiclusters_SA) const {
0044   multiclusters_SA.reserve(multiclusters.size());
0045 
0046   for (unsigned int imulticluster = 0; imulticluster < multiclusters.size(); ++imulticluster) {
0047     bool firstConstituent = true;
0048     for (const auto& constituent : multiclusters[imulticluster].constituents()) {
0049       if (firstConstituent) {
0050         multiclusters_SA.emplace_back(l1thgcfirmware::HGCalMulticluster(
0051             l1thgcfirmware::HGCalCluster(constituent.second->centreProj().x(),
0052                                          constituent.second->centreProj().y(),
0053                                          constituent.second->centreProj().z(),
0054                                          triggerTools_.zside(constituent.second->detId()),
0055                                          triggerTools_.layerWithOffset(constituent.second->detId()),
0056                                          constituent.second->eta(),
0057                                          constituent.second->phi(),
0058                                          constituent.second->pt(),
0059                                          constituent.second->mipPt(),
0060                                          imulticluster),
0061             1.));
0062 
0063       } else {
0064         multiclusters_SA.at(imulticluster)
0065             .addConstituent(l1thgcfirmware::HGCalCluster(constituent.second->centreProj().x(),
0066                                                          constituent.second->centreProj().y(),
0067                                                          constituent.second->centreProj().z(),
0068                                                          triggerTools_.zside(constituent.second->detId()),
0069                                                          triggerTools_.layerWithOffset(constituent.second->detId()),
0070                                                          constituent.second->eta(),
0071                                                          constituent.second->phi(),
0072                                                          constituent.second->pt(),
0073                                                          constituent.second->mipPt(),
0074                                                          imulticluster),
0075                             1.);
0076       }
0077       firstConstituent = false;
0078     }
0079   }
0080 }
0081 
0082 void HGCalSortingTruncationWrapper::convertAlgorithmOutputs(
0083     const std::vector<l1thgcfirmware::HGCalMulticluster>& multiclusters_out,
0084     const l1t::HGCalMulticlusterBxCollection& multiclusters_original,
0085     l1t::HGCalMulticlusterBxCollection& multiclustersBXCollection) const {
0086   for (unsigned int imulticluster = 0; imulticluster < multiclusters_out.size(); ++imulticluster) {
0087     unsigned multicluster_id = multiclusters_out[imulticluster].constituents().at(0).index_cmssw();
0088     multiclustersBXCollection.push_back(0, multiclusters_original[multicluster_id]);
0089   }
0090 }
0091 
0092 void HGCalSortingTruncationWrapper::process(const l1t::HGCalMulticlusterBxCollection& inputMulticlusters,
0093                                             l1t::HGCalMulticlusterBxCollection& outputMulticlusters) const {
0094   l1thgcfirmware::HGCalMulticlusterSACollection multiclusters_SA;
0095   convertCMSSWInputs(inputMulticlusters, multiclusters_SA);
0096 
0097   l1thgcfirmware::HGCalMulticlusterSACollection multiclusters_finalized_SA;
0098 
0099   theAlgo_.sortAndTruncate_SA(multiclusters_SA, multiclusters_finalized_SA, theConfiguration_);
0100 
0101   convertAlgorithmOutputs(multiclusters_finalized_SA, inputMulticlusters, outputMulticlusters);
0102 }
0103 
0104 void HGCalSortingTruncationWrapper::configure(
0105     const std::pair<const HGCalTriggerGeometryBase* const, const edm::ParameterSet&>& configuration) {
0106   setGeometry(configuration.first);
0107 };
0108 
0109 DEFINE_EDM_PLUGIN(HGCalStage2FilteringWrapperBaseFactory,
0110                   HGCalSortingTruncationWrapper,
0111                   "HGCalSortingTruncationWrapper");