From c777bf460344e99a675162c0e25d27bcebe1a56a Mon Sep 17 00:00:00 2001 From: Luca Mastrolorenzo Date: Thu, 30 Mar 2017 16:13:37 +0200 Subject: [PATCH 1/9] Based on 900pre6: creation of clusterizeNN function with a basic NN-algorithm (to be updated soon with the IC NN-algorithm) + ordering of trigger-cells in phi --- .../be_algorithms/HGCalClusteringImpl.h | 11 +- .../plugins/be_algorithms/HGCClusterAlgo.cc | 14 ++- .../src/be_algorithms/HGCalClusteringImpl.cc | 115 +++++++++++++++++- 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h index 1c7b1129e04b7..02b39827d2d9f 100644 --- a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h +++ b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h @@ -2,11 +2,11 @@ #define __L1Trigger_L1THGCal_HGCalClusteringImpl_h__ #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h" #include "DataFormats/ForwardDetId/interface/HGCalDetId.h" #include "DataFormats/L1THGCal/interface/HGCalCluster.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "DataFormats/Common/interface/Ref.h" class HGCalClusteringImpl{ @@ -18,10 +18,19 @@ class HGCalClusteringImpl{ const l1t::HGCalCluster & clu, double distXY) const; + bool isPertinentNN( const l1t::HGCalTriggerCell & tc, + const l1t::HGCalCluster & clu, + edm::ESHandle triggerGeometry ) const; + void clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ); + void clusterizeNN( const edm::PtrVector & triggerCellsPtrs, + l1t::HGCalClusterBxCollection & clusters, + edm::ESHandle triggerGeometry + ); + private: double seedThreshold_; diff --git a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc index 8d85438a6d7d1..7bebb7128ce5d 100644 --- a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc +++ b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc @@ -2,12 +2,13 @@ #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h" #include "DataFormats/L1THGCal/interface/HGCalCluster.h" #include "DataFormats/L1THGCal/interface/HGCalMulticluster.h" +#include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" #include "L1Trigger/L1THGCal/interface/HGCalTriggerBackendAlgorithmBase.h" #include "L1Trigger/L1THGCal/interface/fe_codecs/HGCalTriggerCellBestChoiceCodec.h" #include "L1Trigger/L1THGCal/interface/fe_codecs/HGCalTriggerCellThresholdCodec.h" #include "L1Trigger/L1THGCal/interface/be_algorithms/HGCalTriggerCellCalibration.h" #include "L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h" -#include "L1Trigger/L1THGCal/interface/be_algorithms/HGCalMulticlusteringImpl.h" +#include "L1Trigger/L1THGCal/interface/be_algorithms/HGCalMulticlusteringImpl.h" using namespace HGCalTriggerBackend; @@ -59,6 +60,7 @@ class HGCClusterAlgo : public Algorithm cluster_product_.reset( new l1t::HGCalClusterBxCollection ); multicluster_product_.reset( new l1t::HGCalMulticlusterBxCollection ); } + private: @@ -74,7 +76,8 @@ class HGCClusterAlgo : public Algorithm /* handles to the detector topologies */ edm::ESHandle hgceeTopoHandle_; edm::ESHandle hgchefTopoHandle_; - + edm::ESHandle triggerGeometry_; + /* algorithms instances */ HGCalTriggerCellCalibration calibration_; HGCalClusteringImpl clustering_; @@ -91,6 +94,7 @@ void HGCClusterAlgo::run(const l1t::HGCFETriggerDigiCollection & c es.get().get( HGCalEESensitive_, hgceeTopoHandle_ ); es.get().get( HGCalHESiliconSensitive_, hgchefTopoHandle_ ); + es.get().get("", triggerGeometry_); for( const auto& digi : coll ){ @@ -123,7 +127,8 @@ void HGCClusterAlgo::run(const l1t::HGCFETriggerDigiCollection & c l1t::HGCalTriggerCell calibratedtriggercell( triggercell ); calibration_.calibrateInGeV( calibratedtriggercell, cellThickness ); trgcell_product_->push_back( 0, calibratedtriggercell ); - } + + } } @@ -145,7 +150,8 @@ void HGCClusterAlgo::run(const l1t::HGCFETriggerDigiCollection & c } /* call to clustering */ - clustering_.clusterize( triggerCellsPtrs, *cluster_product_); + //clustering_.clusterize( triggerCellsPtrs, *cluster_product_); + clustering_.clusterizeNN( triggerCellsPtrs, *cluster_product_, triggerGeometry_ ); /* retrieve the orphan handle to the clusters collection and put the collection in the event */ clustersHandle = evt.put( std::move( cluster_product_ ), "cluster2D"); diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index eef2bd0482085..08c56b0c448d4 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -34,11 +34,45 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } +bool HGCalClusteringImpl::isPertinentNN( const l1t::HGCalTriggerCell & tc, + const l1t::HGCalCluster & clu, + edm::ESHandle triggerGeometry ) const +{ + + HGCalDetId tcDetId( tc.detId() ); + HGCalDetId cluDetId( clu.seedDetId() ); + if( (tcDetId.layer() != cluDetId.layer()) || + (tcDetId.subdetId() != cluDetId.subdetId()) || + (tcDetId.zside() != cluDetId.zside()) ){ + return false; + } + + const edm::PtrVector pertinentTC = clu.triggercells(); + for( edm::PtrVector::const_iterator it_tc=pertinentTC.begin(); it_tcdetId() ); + std::cout << "tc in clu " << clu.seedDetId() << " " <getNeighborsFromTriggerCell( tcInCluDetId ); + if( !( neighbors.find(tcDetId) == neighbors.end() ) ){ + std::cout << " ---> it is taken " << tcDetId << std::endl; + return true; + } + } + + return false; + +} + +bool phiOrder( const edm::Ptr A, const edm::Ptr B) +{ + return (*A).p4().Phi() > (*B).p4().Phi(); +} + void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ){ - + /* sort in phi the trigger-cell collection */ + bool isSeed[triggerCellsPtrs.size()]; /* search for cluster seeds */ @@ -93,3 +127,82 @@ void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, + l1t::HGCalClusterBxCollection & clusters, + edm::ESHandle triggerGeometry + ){ + + /* sort the TCs by phi */ + std::vector< edm::Ptr > TriggerCellPhiOrdered; + for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc){ + TriggerCellPhiOrdered.emplace_back(*tc); + } + + std::sort( TriggerCellPhiOrdered.begin(), TriggerCellPhiOrdered.end(), phiOrder ); + + edm::PtrVector triggerCellsPhiOrdPtrs; + for( std::vector< edm::Ptr >::const_iterator tcOrd = TriggerCellPhiOrdered.begin(); tcOrd != TriggerCellPhiOrdered.end(); ++tcOrd) { + triggerCellsPhiOrdPtrs.push_back(*tcOrd); + } + + bool isSeed[triggerCellsPhiOrdPtrs.size()]; + + /* search for cluster seeds */ + int itc=0; + for( edm::PtrVector::const_iterator tc = triggerCellsPhiOrdPtrs.begin(); tc != triggerCellsPhiOrdPtrs.end(); ++tc, ++itc ){ + HGCalDetId det( (*tc)->detId() ); + std::cout << det << " x,y = " << (*tc)->position().x() + <<", " << (*tc)->position().y() + <<" eta,phi = " << (*tc)->position().eta() + <<", " << (*tc)->position().phi() << std::endl; + + isSeed[itc] = ( (*tc)->mipPt() > seedThreshold_) ? true : false; + } + + /* clustering the TCs */ + std::vector clustersTmp; + + itc=0; + for( edm::PtrVector::const_iterator tc = triggerCellsPhiOrdPtrs.begin(); tc != triggerCellsPhiOrdPtrs.end(); ++tc,++itc ){ + + if( (*tc)->mipPt() < triggerCellThreshold_ ){ + continue; + } + + /* searching for TC near the center of the cluster */ + int iclu=0; + vector tcPertinentClusters; + for( std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu,++iclu ){ + if( this->isPertinentNN(**tc, *clu, triggerGeometry) ){ + tcPertinentClusters.push_back(iclu); + } + } + if( tcPertinentClusters.size() == 0 && isSeed[itc] ){ + clustersTmp.emplace_back( *tc ); + } + else if ( tcPertinentClusters.size() > 0 ){ + + unsigned minDist = 300; + unsigned targetClu = 0; + + for( std::vector::const_iterator iclu = tcPertinentClusters.begin(); iclu != tcPertinentClusters.end(); ++iclu ){ + double d = clustersTmp.at(*iclu).distance(**tc); + if( d < minDist ){ + minDist = d; + targetClu = *iclu; + } + } + + clustersTmp.at(targetClu).addTriggerCell( *tc ); + + } + } + + /* making the collection of clusters */ + for( unsigned i(0); i Date: Thu, 30 Mar 2017 16:24:01 +0200 Subject: [PATCH 2/9] cleaning --- .../L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index 08c56b0c448d4..b2745e1c26ed9 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -34,6 +34,7 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } + bool HGCalClusteringImpl::isPertinentNN( const l1t::HGCalTriggerCell & tc, const l1t::HGCalCluster & clu, edm::ESHandle triggerGeometry ) const @@ -50,10 +51,8 @@ bool HGCalClusteringImpl::isPertinentNN( const l1t::HGCalTriggerCell & tc, const edm::PtrVector pertinentTC = clu.triggercells(); for( edm::PtrVector::const_iterator it_tc=pertinentTC.begin(); it_tcdetId() ); - std::cout << "tc in clu " << clu.seedDetId() << " " <getNeighborsFromTriggerCell( tcInCluDetId ); if( !( neighbors.find(tcDetId) == neighbors.end() ) ){ - std::cout << " ---> it is taken " << tcDetId << std::endl; return true; } } @@ -62,6 +61,7 @@ bool HGCalClusteringImpl::isPertinentNN( const l1t::HGCalTriggerCell & tc, } + bool phiOrder( const edm::Ptr A, const edm::Ptr B) { return (*A).p4().Phi() > (*B).p4().Phi(); @@ -71,7 +71,6 @@ bool phiOrder( const edm::Ptr A, const edm::Ptr & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ){ - /* sort in phi the trigger-cell collection */ bool isSeed[triggerCellsPtrs.size()]; @@ -151,12 +150,6 @@ void HGCalClusteringImpl::clusterizeNN( const edm::PtrVector::const_iterator tc = triggerCellsPhiOrdPtrs.begin(); tc != triggerCellsPhiOrdPtrs.end(); ++tc, ++itc ){ - HGCalDetId det( (*tc)->detId() ); - std::cout << det << " x,y = " << (*tc)->position().x() - <<", " << (*tc)->position().y() - <<" eta,phi = " << (*tc)->position().eta() - <<", " << (*tc)->position().phi() << std::endl; - isSeed[itc] = ( (*tc)->mipPt() > seedThreshold_) ? true : false; } From 4f2229d6e639a436edee6d03f43ec8726f5e3fca Mon Sep 17 00:00:00 2001 From: Luca Mastrolorenzo Date: Thu, 30 Mar 2017 16:46:02 +0200 Subject: [PATCH 3/9] start importing IC-NNC2d in CMSSW --- .../interface/be_algorithms/HGCalClusteringImpl.h | 12 +++++++----- .../plugins/be_algorithms/HGCClusterAlgo.cc | 2 +- .../src/be_algorithms/HGCalClusteringImpl.cc | 14 +++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h index 02b39827d2d9f..133b138e41afb 100644 --- a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h +++ b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h @@ -14,19 +14,21 @@ class HGCalClusteringImpl{ HGCalClusteringImpl( const edm::ParameterSet & conf); + /* dR-algorithms */ bool isPertinent( const l1t::HGCalTriggerCell & tc, const l1t::HGCalCluster & clu, double distXY) const; - bool isPertinentNN( const l1t::HGCalTriggerCell & tc, - const l1t::HGCalCluster & clu, - edm::ESHandle triggerGeometry ) const; - void clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ); - void clusterizeNN( const edm::PtrVector & triggerCellsPtrs, + /* NN-algorithms */ + bool isPertinent( const l1t::HGCalTriggerCell & tc, + const l1t::HGCalCluster & clu, + edm::ESHandle triggerGeometry ) const; + + void clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, edm::ESHandle triggerGeometry ); diff --git a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc index 7bebb7128ce5d..54f50d694124b 100644 --- a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc +++ b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc @@ -151,7 +151,7 @@ void HGCClusterAlgo::run(const l1t::HGCFETriggerDigiCollection & c /* call to clustering */ //clustering_.clusterize( triggerCellsPtrs, *cluster_product_); - clustering_.clusterizeNN( triggerCellsPtrs, *cluster_product_, triggerGeometry_ ); + clustering_.clusterize( triggerCellsPtrs, *cluster_product_, triggerGeometry_ ); /* retrieve the orphan handle to the clusters collection and put the collection in the event */ clustersHandle = evt.put( std::move( cluster_product_ ), "cluster2D"); diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index b2745e1c26ed9..8933fbae33444 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -15,6 +15,7 @@ HGCalClusteringImpl::HGCalClusteringImpl(const edm::ParameterSet & conf): } +/* dR-algorithms */ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, const l1t::HGCalCluster & clu, double distXY ) const @@ -35,9 +36,10 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } -bool HGCalClusteringImpl::isPertinentNN( const l1t::HGCalTriggerCell & tc, - const l1t::HGCalCluster & clu, - edm::ESHandle triggerGeometry ) const +/* NN-algorithm */ +bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, + const l1t::HGCalCluster & clu, + edm::ESHandle triggerGeometry ) const { HGCalDetId tcDetId( tc.detId() ); @@ -68,6 +70,7 @@ bool phiOrder( const edm::Ptr A, const edm::Ptr & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ){ @@ -127,7 +130,8 @@ void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, +/* NN-algorithms */ +void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, edm::ESHandle triggerGeometry ){ @@ -167,7 +171,7 @@ void HGCalClusteringImpl::clusterizeNN( const edm::PtrVector tcPertinentClusters; for( std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu,++iclu ){ - if( this->isPertinentNN(**tc, *clu, triggerGeometry) ){ + if( this->isPertinent(**tc, *clu, triggerGeometry) ){ tcPertinentClusters.push_back(iclu); } } From 0992533e8c09c626768eaa701aa6d442cfd04e09 Mon Sep 17 00:00:00 2001 From: Luca Mastrolorenzo Date: Thu, 30 Mar 2017 19:39:44 +0200 Subject: [PATCH 4/9] first complete version of IC-NNC2d --- DataFormats/L1THGCal/interface/HGCalCluster.h | 9 ++ .../be_algorithms/HGCalClusteringImpl.h | 13 ++ .../src/be_algorithms/HGCalClusteringImpl.cc | 149 +++++++++++++----- 3 files changed, 129 insertions(+), 42 deletions(-) diff --git a/DataFormats/L1THGCal/interface/HGCalCluster.h b/DataFormats/L1THGCal/interface/HGCalCluster.h index 98ccdb75b7699..99f3ff12d354c 100644 --- a/DataFormats/L1THGCal/interface/HGCalCluster.h +++ b/DataFormats/L1THGCal/interface/HGCalCluster.h @@ -59,6 +59,15 @@ namespace l1t { double seedMipPt() const { return seedMipPt_; } uint32_t seedDetId() const { return seedDetId_; } + bool containsSeed(double seedThr_MipT){ + for(edm::PtrVector::const_iterator tc = triggercells_.begin(); tc != triggercells_.end(); ++tc){ + if( (*tc)->mipPt() > seedThr_MipT ){ + return true; + } + } + return false; + } + double distance( const l1t::HGCalTriggerCell &tc ) const; /* return distance in 'cm' */ const GlobalPoint& centre() const { return centre_; } diff --git a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h index 133b138e41afb..2985e0674eef3 100644 --- a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h +++ b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h @@ -14,6 +14,7 @@ class HGCalClusteringImpl{ HGCalClusteringImpl( const edm::ParameterSet & conf); + /* dR-algorithms */ bool isPertinent( const l1t::HGCalTriggerCell & tc, const l1t::HGCalCluster & clu, @@ -24,15 +25,27 @@ class HGCalClusteringImpl{ ); /* NN-algorithms */ + bool isPertinent( const l1t::HGCalTriggerCell & tc1, + const l1t::HGCalTriggerCell & tc2, + edm::ESHandle triggerGeometry ) const; + bool isPertinent( const l1t::HGCalTriggerCell & tc, const l1t::HGCalCluster & clu, edm::ESHandle triggerGeometry ) const; + bool isPertinent( const l1t::HGCalCluster & clu1, + const l1t::HGCalCluster & clu2, + edm::ESHandle triggerGeometry ) const; + + void mergeClusters( l1t::HGCalCluster & main_cluster, + l1t::HGCalCluster & secondary_cluster ) const; + void clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, edm::ESHandle triggerGeometry ); + private: double seedThreshold_; diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index 8933fbae33444..df3230019a714 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -36,7 +36,37 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } -/* NN-algorithm */ +/* NN-algorithms */ + +/* tc-tc */ +bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc1, + const l1t::HGCalTriggerCell & tc2, + edm::ESHandle triggerGeometry ) const +{ + HGCalDetId detId_tc1( tc1.detId() ); + HGCalDetId detId_tc2( tc2.detId() ); + if( (detId_tc1.layer() != detId_tc2.layer()) || + (detId_tc1.subdetId() != detId_tc2.subdetId()) || + (detId_tc1.zside() != detId_tc2.zside()) ){ + return false; + } + + const auto neighbors_tc1 = triggerGeometry->getNeighborsFromTriggerCell( detId_tc1 ); + const auto neighbors_tc2 = triggerGeometry->getNeighborsFromTriggerCell( detId_tc2 ); + + for(const auto neighbor_tc2 : neighbors_tc2) + { + if( !( neighbors_tc1.find( neighbor_tc2 ) == neighbors_tc1.end() ) ){ + return true; + } + } + + return false; + +} + + +/* tc-clu */ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, const l1t::HGCalCluster & clu, edm::ESHandle triggerGeometry ) const @@ -64,6 +94,47 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } +/* clu-clu */ +bool HGCalClusteringImpl::isPertinent( const l1t::HGCalCluster & clu1, + const l1t::HGCalCluster & clu2, + edm::ESHandle triggerGeometry ) const +{ + HGCalDetId detId_clu1( clu1.seedDetId() ); + HGCalDetId detId_clu2( clu2.seedDetId() ); + + if( (detId_clu1.layer() != detId_clu2.layer()) || + (detId_clu1.subdetId() != detId_clu2.subdetId()) || + (detId_clu1.zside() != detId_clu2.zside()) ){ + return false; + } + + const edm::PtrVector pertinentTC_clu1 = clu1.triggercells(); + const edm::PtrVector pertinentTC_clu2 = clu2.triggercells(); + + for( edm::PtrVector::const_iterator tc1 = pertinentTC_clu1.begin(); tc1 != pertinentTC_clu1.begin(); ++tc1 ){ + for( edm::PtrVector::const_iterator tc2 = pertinentTC_clu2.begin(); tc2 != pertinentTC_clu2.begin(); ++tc2 ){ + if( this->isPertinent( *tc1, *tc2, triggerGeometry ) ){ + return true; + } + } + } + + return false; + +} + +void HGCalClusteringImpl::mergeClusters( l1t::HGCalCluster & main_cluster, + l1t::HGCalCluster & secondary_cluster ) const +{ + + const edm::PtrVector pertinentTC = secondary_cluster.triggercells(); + for( edm::PtrVector::iterator tc = pertinentTC.begin(); tc != pertinentTC.end(); ++tc ){ + main_cluster.addTriggerCell(*tc); + } + +} + + bool phiOrder( const edm::Ptr A, const edm::Ptr B) { return (*A).p4().Phi() > (*B).p4().Phi(); @@ -149,57 +220,51 @@ void HGCalClusteringImpl::clusterize( const edm::PtrVector::const_iterator tc = triggerCellsPhiOrdPtrs.begin(); tc != triggerCellsPhiOrdPtrs.end(); ++tc, ++itc ){ - isSeed[itc] = ( (*tc)->mipPt() > seedThreshold_) ? true : false; - } - - /* clustering the TCs */ + /* declaring the clusters vector */ std::vector clustersTmp; - itc=0; - for( edm::PtrVector::const_iterator tc = triggerCellsPhiOrdPtrs.begin(); tc != triggerCellsPhiOrdPtrs.end(); ++tc,++itc ){ - - if( (*tc)->mipPt() < triggerCellThreshold_ ){ - continue; - } - - /* searching for TC near the center of the cluster */ - int iclu=0; - vector tcPertinentClusters; - for( std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu,++iclu ){ - if( this->isPertinent(**tc, *clu, triggerGeometry) ){ - tcPertinentClusters.push_back(iclu); - } + /* LOOP OVER THE TRIGGER-CELLS */ + for( edm::PtrVector::const_iterator tc = triggerCellsPhiOrdPtrs.begin(); tc != triggerCellsPhiOrdPtrs.end(); ++tc ){ + + bool createNewC2d = true; + int i_clu=0; + for(std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu, ++i_clu ){ + if( this->isPertinent( **tc, *clu, triggerGeometry ) ){ + clustersTmp.at(i_clu).addTriggerCell( *tc ); + createNewC2d = false; + break; + } } - if( tcPertinentClusters.size() == 0 && isSeed[itc] ){ - clustersTmp.emplace_back( *tc ); + + if( createNewC2d ){ + clustersTmp.emplace_back(*tc); } - else if ( tcPertinentClusters.size() > 0 ){ - - unsigned minDist = 300; - unsigned targetClu = 0; - - for( std::vector::const_iterator iclu = tcPertinentClusters.begin(); iclu != tcPertinentClusters.end(); ++iclu ){ - double d = clustersTmp.at(*iclu).distance(**tc); - if( d < minDist ){ - minDist = d; - targetClu = *iclu; - } - } - clustersTmp.at(targetClu).addTriggerCell( *tc ); + } + /* declaring the vector with possible clusters merged */ + std::vector idx_cluToRm; + + for(std::vector::iterator clu1 = clustersTmp.begin(); clu1 != clustersTmp.end(); ++clu1){ + int i_clu2=0; + for(std::vector::iterator clu2 = clustersTmp.begin(); clu2 != clustersTmp.end(); ++clu2, ++i_clu2){ + if( this->isPertinent( *clu1, *clu2, triggerGeometry ) ){ + this->mergeClusters( *clu1, *clu2 ); + idx_cluToRm.emplace_back( i_clu2 ); + } + } + for(std::vector::const_iterator idx = idx_cluToRm.begin(); idx != idx_cluToRm.end(); ++idx){ + clustersTmp.erase( clustersTmp.begin() + (*idx) ); } } - + /* making the collection of clusters */ for( unsigned i(0); i Date: Tue, 4 Apr 2017 16:44:40 +0200 Subject: [PATCH 5/9] update of the NNC2d with the merging of two cluster that have common neighbors --- DataFormats/L1THGCal/src/HGCalCluster.cc | 4 +- .../be_algorithms/HGCalClusteringImpl.h | 13 + .../plugins/be_algorithms/HGCClusterAlgo.cc | 4 +- .../src/be_algorithms/HGCalClusteringImpl.cc | 270 +++++++++++------- 4 files changed, 181 insertions(+), 110 deletions(-) diff --git a/DataFormats/L1THGCal/src/HGCalCluster.cc b/DataFormats/L1THGCal/src/HGCalCluster.cc index 6f8b085fa5ccd..829994467b9f8 100644 --- a/DataFormats/L1THGCal/src/HGCalCluster.cc +++ b/DataFormats/L1THGCal/src/HGCalCluster.cc @@ -63,7 +63,8 @@ void HGCalCluster::addTriggerCell( const edm::Ptr &tc ) p4 += tc->p4(); this->setP4( p4 ); - triggercells_.push_back( tc ); + triggercells_.push_back( tc ); + } @@ -105,6 +106,7 @@ int32_t HGCalCluster::zside() const } + bool HGCalCluster::operator<(const HGCalCluster& cl) const { diff --git a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h index 2985e0674eef3..2f009d512014f 100644 --- a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h +++ b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h @@ -40,6 +40,15 @@ class HGCalClusteringImpl{ void mergeClusters( l1t::HGCalCluster & main_cluster, l1t::HGCalCluster & secondary_cluster ) const; + void NNKernel( std::vector> ( &reshuffledTriggerCells )[2][40], + l1t::HGCalClusterBxCollection & clusters, + edm::ESHandle triggerGeometry, + int endcap, + int layer + ); + + + void clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, edm::ESHandle triggerGeometry @@ -51,6 +60,10 @@ class HGCalClusteringImpl{ double seedThreshold_; double triggerCellThreshold_; double dr_; + void triggerCellReshuffling_( const edm::PtrVector & triggerCellsPtrs, + std::vector> ( &reshuffledTriggerCells )[2][40] ); + + }; diff --git a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc index 54f50d694124b..f9efd732b6976 100644 --- a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc +++ b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc @@ -149,8 +149,10 @@ void HGCClusterAlgo::run(const l1t::HGCFETriggerDigiCollection & c triggerCellsPtrs.push_back(ptr); } - /* call to clustering */ + /* call to dR-C2d clustering */ //clustering_.clusterize( triggerCellsPtrs, *cluster_product_); + + /* call to NN-C2d clustering */ clustering_.clusterize( triggerCellsPtrs, *cluster_product_, triggerGeometry_ ); /* retrieve the orphan handle to the clusters collection and put the collection in the event */ diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index df3230019a714..9dd1e4991a83e 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -36,6 +36,67 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } +/* dR-algorithms */ +void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, + l1t::HGCalClusterBxCollection & clusters + ){ + + bool isSeed[triggerCellsPtrs.size()]; + + /* search for cluster seeds */ + int itc=0; + for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc,++itc ){ + isSeed[itc] = ( (*tc)->mipPt() > seedThreshold_) ? true : false; + } + + /* clustering the TCs */ + std::vector clustersTmp; + + itc=0; + for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc,++itc ){ + + if( (*tc)->mipPt() < triggerCellThreshold_ ){ + continue; + } + + /* searching for TC near the center of the cluster */ + int iclu=0; + vector tcPertinentClusters; + for( std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu,++iclu ){ + if( this->isPertinent(**tc, *clu, dr_) ){ + tcPertinentClusters.push_back(iclu); + } + } + if( tcPertinentClusters.size() == 0 && isSeed[itc] ){ + clustersTmp.emplace_back( *tc ); + } + else if ( tcPertinentClusters.size() > 0 ){ + + unsigned minDist = 300; + unsigned targetClu = 0; + + for( std::vector::const_iterator iclu = tcPertinentClusters.begin(); iclu != tcPertinentClusters.end(); ++iclu ){ + double d = clustersTmp.at(*iclu).distance(**tc); + if( d < minDist ){ + minDist = d; + targetClu = *iclu; + } + } + + clustersTmp.at(targetClu).addTriggerCell( *tc ); + + } + } + + /* store clusters in the persistent collection */ + for( unsigned i(0); igetNeighborsFromTriggerCell( detId_tc2 ); for(const auto neighbor_tc2 : neighbors_tc2) - { + { if( !( neighbors_tc1.find( neighbor_tc2 ) == neighbors_tc1.end() ) ){ return true; - } - } + } + } return false; - + } @@ -81,7 +142,7 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } const edm::PtrVector pertinentTC = clu.triggercells(); - for( edm::PtrVector::const_iterator it_tc=pertinentTC.begin(); it_tc::const_iterator it_tc = pertinentTC.begin(); it_tc!= pertinentTC.end(); ++it_tc){ HGCalDetId tcInCluDetId( (*it_tc)->detId() ); const auto neighbors = triggerGeometry->getNeighborsFromTriggerCell( tcInCluDetId ); if( !( neighbors.find(tcDetId) == neighbors.end() ) ){ @@ -108,163 +169,156 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalCluster & clu1, return false; } + if( clu1.seedDetId() == clu2.seedDetId() ){ + return false; + } + const edm::PtrVector pertinentTC_clu1 = clu1.triggercells(); const edm::PtrVector pertinentTC_clu2 = clu2.triggercells(); + + int Ntc_clu1 = pertinentTC_clu1.size(); + int Ntc_clu2 = pertinentTC_clu2.size(); + + /* assume 1.06cm^2 cells */ + double maxTClength = 3.84; + double r_max = (Ntc_clu1 + Ntc_clu2) * maxTClength; + double distance = ( clu1.centre() - clu2.centre() ).mag(); - for( edm::PtrVector::const_iterator tc1 = pertinentTC_clu1.begin(); tc1 != pertinentTC_clu1.begin(); ++tc1 ){ - for( edm::PtrVector::const_iterator tc2 = pertinentTC_clu2.begin(); tc2 != pertinentTC_clu2.begin(); ++tc2 ){ - if( this->isPertinent( *tc1, *tc2, triggerGeometry ) ){ - return true; + if( distance < r_max){ + for( edm::PtrVector::const_iterator tc1 = pertinentTC_clu1.begin(); tc1 != pertinentTC_clu1.end(); ++tc1 ){ + for( edm::PtrVector::const_iterator tc2 = pertinentTC_clu2.begin(); tc2 != pertinentTC_clu2.end(); ++tc2 ){ + if( this->isPertinent( **tc1, **tc2, triggerGeometry ) ){ + return true; + } } } } - + return false; } + +/* merge clusters that have common neighbors */ void HGCalClusteringImpl::mergeClusters( l1t::HGCalCluster & main_cluster, l1t::HGCalCluster & secondary_cluster ) const { const edm::PtrVector pertinentTC = secondary_cluster.triggercells(); + for( edm::PtrVector::iterator tc = pertinentTC.begin(); tc != pertinentTC.end(); ++tc ){ main_cluster.addTriggerCell(*tc); } - + } -bool phiOrder( const edm::Ptr A, const edm::Ptr B) -{ - return (*A).p4().Phi() > (*B).p4().Phi(); +void HGCalClusteringImpl::triggerCellReshuffling_( const edm::PtrVector & triggerCellsPtrs, + std::vector> (&reshuffledTriggerCells)[2][40] + ){ + + for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc){ + int endcap = (*tc)->zside() == -1 ? 0 : 1 ; + HGCalDetId tcDetId( (*tc)->detId() ); + int subdet = tcDetId.subdetId(); + int layer = -1; + if(subdet==3){ + layer = (*tc)->layer(); + } + else if(subdet==4){ + layer = (*tc)->layer() + 28; + } + + reshuffledTriggerCells[endcap][layer-1].emplace_back(*tc); + + } + } -/* dR-algorithms */ -void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, - l1t::HGCalClusterBxCollection & clusters +void HGCalClusteringImpl::NNKernel( std::vector> (&reshuffledTriggerCells)[2][40], + l1t::HGCalClusterBxCollection & clusters, + edm::ESHandle triggerGeometry, + int endcap, + int layer ){ - - bool isSeed[triggerCellsPtrs.size()]; - - /* search for cluster seeds */ - int itc=0; - for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc,++itc ){ - isSeed[itc] = ( (*tc)->mipPt() > seedThreshold_) ? true : false; - } - - /* clustering the TCs */ + + /* declaring the clusters vector */ std::vector clustersTmp; - itc=0; - for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc,++itc ){ - + /* loop over the trigger-cells */ + for( std::vector>::iterator tc=reshuffledTriggerCells[endcap][layer].begin(); tc!=reshuffledTriggerCells[endcap][layer].end(); tc++ ){ + if( (*tc)->mipPt() < triggerCellThreshold_ ){ continue; } - /* searching for TC near the center of the cluster */ - int iclu=0; - vector tcPertinentClusters; - for( std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu,++iclu ){ - if( this->isPertinent(**tc, *clu, dr_) ){ - tcPertinentClusters.push_back(iclu); - } + bool createNewC2d = true; + int i_clu=0; + + for(std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu, ++i_clu ){ + if( this->isPertinent( **tc, *clu, triggerGeometry ) ){ + clustersTmp.at( i_clu ).addTriggerCell( *tc ); + createNewC2d = false; + break; + } } - if( tcPertinentClusters.size() == 0 && isSeed[itc] ){ + + if( createNewC2d ){ clustersTmp.emplace_back( *tc ); } - else if ( tcPertinentClusters.size() > 0 ){ - - unsigned minDist = 300; - unsigned targetClu = 0; - - for( std::vector::const_iterator iclu = tcPertinentClusters.begin(); iclu != tcPertinentClusters.end(); ++iclu ){ - double d = clustersTmp.at(*iclu).distance(**tc); - if( d < minDist ){ - minDist = d; - targetClu = *iclu; - } - } + } + + /* declaring the vector with possible clusters merged */ - clustersTmp.at(targetClu).addTriggerCell( *tc ); + for(unsigned i_clu1 = 0; i_clu1 < clustersTmp.size(); ++i_clu1){ + + std::vector idx_cluToRm; + for(unsigned i_clu2 = 0; i_clu2 < clustersTmp.size(); ++i_clu2){ + if( this->isPertinent( clustersTmp.at(i_clu1), clustersTmp.at(i_clu2), triggerGeometry ) ){ + this->mergeClusters( clustersTmp.at(i_clu1), clustersTmp.at(i_clu2) ); + idx_cluToRm.push_back( i_clu2 ); + } + } + + /* erase all the clusters that has been added */ + std::sort( idx_cluToRm.begin(), idx_cluToRm.end() ); + std::reverse( idx_cluToRm.begin(), idx_cluToRm.end() ); + for(unsigned idx = 0; idx < idx_cluToRm.size(); ++idx){ + clustersTmp.erase( clustersTmp.begin() + idx_cluToRm.at(idx) ); } + } - /* making the collection of clusters */ + /* store clusters in the persistent collection */ for( unsigned i(0); i & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, edm::ESHandle triggerGeometry ){ - /* sort the TCs by phi */ - std::vector< edm::Ptr > TriggerCellPhiOrdered; - for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc){ - TriggerCellPhiOrdered.emplace_back(*tc); - } - - std::sort( TriggerCellPhiOrdered.begin(), TriggerCellPhiOrdered.end(), phiOrder ); + std::vector> reshuffledTriggerCells[2][40]; + triggerCellReshuffling_( triggerCellsPtrs, reshuffledTriggerCells ); - edm::PtrVector triggerCellsPhiOrdPtrs; - for( std::vector< edm::Ptr >::const_iterator tcOrd = TriggerCellPhiOrdered.begin(); tcOrd != TriggerCellPhiOrdered.end(); ++tcOrd) { - triggerCellsPhiOrdPtrs.push_back(*tcOrd); - } + for(int iec=0; iec<2; ++iec){ + for(int il=0; il<40; ++il){ - /* declaring the clusters vector */ - std::vector clustersTmp; - - /* LOOP OVER THE TRIGGER-CELLS */ - for( edm::PtrVector::const_iterator tc = triggerCellsPhiOrdPtrs.begin(); tc != triggerCellsPhiOrdPtrs.end(); ++tc ){ - - bool createNewC2d = true; - int i_clu=0; - for(std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu, ++i_clu ){ - if( this->isPertinent( **tc, *clu, triggerGeometry ) ){ - clustersTmp.at(i_clu).addTriggerCell( *tc ); - createNewC2d = false; - break; - } - } - - if( createNewC2d ){ - clustersTmp.emplace_back(*tc); + NNKernel( reshuffledTriggerCells, clusters, triggerGeometry, iec, il ); + } - } - /* declaring the vector with possible clusters merged */ - std::vector idx_cluToRm; - - for(std::vector::iterator clu1 = clustersTmp.begin(); clu1 != clustersTmp.end(); ++clu1){ - int i_clu2=0; - for(std::vector::iterator clu2 = clustersTmp.begin(); clu2 != clustersTmp.end(); ++clu2, ++i_clu2){ - if( this->isPertinent( *clu1, *clu2, triggerGeometry ) ){ - this->mergeClusters( *clu1, *clu2 ); - idx_cluToRm.emplace_back( i_clu2 ); - } - } - for(std::vector::const_iterator idx = idx_cluToRm.begin(); idx != idx_cluToRm.end(); ++idx){ - clustersTmp.erase( clustersTmp.begin() + (*idx) ); - } - } - - /* making the collection of clusters */ - for( unsigned i(0); i Date: Sat, 8 Apr 2017 17:42:59 +0200 Subject: [PATCH 6/9] upgrade of the NNC2d using where possible unorderd_map/set to reduce computing time + the clustering type is now a configurable parameter of the config file --- DataFormats/L1THGCal/interface/HGCalCluster.h | 23 +- .../be_algorithms/HGCalClusteringImpl.h | 38 +-- .../plugins/be_algorithms/HGCClusterAlgo.cc | 17 +- .../hgcalTriggerPrimitiveDigiProducer_cfi.py | 6 +- .../src/be_algorithms/HGCalClusteringImpl.cc | 254 +++++++----------- L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py | 12 +- 6 files changed, 140 insertions(+), 210 deletions(-) diff --git a/DataFormats/L1THGCal/interface/HGCalCluster.h b/DataFormats/L1THGCal/interface/HGCalCluster.h index 99f3ff12d354c..bbbc9d9696603 100644 --- a/DataFormats/L1THGCal/interface/HGCalCluster.h +++ b/DataFormats/L1THGCal/interface/HGCalCluster.h @@ -39,34 +39,26 @@ namespace l1t { edm::PtrVector::const_iterator triggercells_end() const { return triggercells_.end(); } - const edm::Ptr seedTriggerCell() const { - return *triggercells_begin(); - } + unsigned triggercellsSize() const { return triggercells_.size(); } /* helpers */ void addTriggerCell( const edm::Ptr &tc); /* set info */ - void setModule (uint32_t value) { module_ = value; } + void setModule (uint32_t value) { module_ = value; } /* get info */ bool isValid() const { if(triggercells_.size() > 0 ) return true; else return false; } + void setIsComplete (bool isCompleteValue) { isComplete_ = isCompleteValue; } + bool isComplete(){ return isComplete_; } + double mipPt() const { return mipPt_; } double seedMipPt() const { return seedMipPt_; } uint32_t seedDetId() const { return seedDetId_; } - - bool containsSeed(double seedThr_MipT){ - for(edm::PtrVector::const_iterator tc = triggercells_.begin(); tc != triggercells_.end(); ++tc){ - if( (*tc)->mipPt() > seedThr_MipT ){ - return true; - } - } - return false; - } double distance( const l1t::HGCalTriggerCell &tc ) const; /* return distance in 'cm' */ @@ -93,7 +85,7 @@ namespace l1t { /* seed detId */ uint32_t seedDetId_; - + /* Centre weighted with energy */ GlobalPoint centre_; @@ -104,6 +96,9 @@ namespace l1t { double mipPt_; double seedMipPt_; + /* Flag dedicated to merging procedure */ + bool isComplete_; + /* HGC specific information */ uint32_t module_; diff --git a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h index 2f009d512014f..a05e01ecda448 100644 --- a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h +++ b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h @@ -1,6 +1,9 @@ #ifndef __L1Trigger_L1THGCal_HGCalClusteringImpl_h__ #define __L1Trigger_L1THGCal_HGCalClusteringImpl_h__ +#include +#include +#include #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h" @@ -24,34 +27,18 @@ class HGCalClusteringImpl{ l1t::HGCalClusterBxCollection & clusters ); - /* NN-algorithms */ - bool isPertinent( const l1t::HGCalTriggerCell & tc1, - const l1t::HGCalTriggerCell & tc2, - edm::ESHandle triggerGeometry ) const; - - bool isPertinent( const l1t::HGCalTriggerCell & tc, - const l1t::HGCalCluster & clu, - edm::ESHandle triggerGeometry ) const; - - bool isPertinent( const l1t::HGCalCluster & clu1, - const l1t::HGCalCluster & clu2, - edm::ESHandle triggerGeometry ) const; - + /* NN-algorithms */ void mergeClusters( l1t::HGCalCluster & main_cluster, - l1t::HGCalCluster & secondary_cluster ) const; + const l1t::HGCalCluster & secondary_cluster ) const; - void NNKernel( std::vector> ( &reshuffledTriggerCells )[2][40], + void NNKernel( std::vector> &reshuffledTriggerCells, l1t::HGCalClusterBxCollection & clusters, - edm::ESHandle triggerGeometry, - int endcap, - int layer + const HGCalTriggerGeometryBase & triggerGeometry ); - - void clusterize( const edm::PtrVector & triggerCellsPtrs, - l1t::HGCalClusterBxCollection & clusters, - edm::ESHandle triggerGeometry + l1t::HGCalClusterBxCollection & clusters, + const HGCalTriggerGeometryBase & triggerGeometry ); @@ -60,9 +47,10 @@ class HGCalClusteringImpl{ double seedThreshold_; double triggerCellThreshold_; double dr_; - void triggerCellReshuffling_( const edm::PtrVector & triggerCellsPtrs, - std::vector> ( &reshuffledTriggerCells )[2][40] ); - + double maxTClenght_; + string clusteringAlgorithmType_; + void triggerCellReshuffling( const edm::PtrVector & triggerCellsPtrs, + std::array>,40>,2> & reshuffledTriggerCells ); }; diff --git a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc index f9efd732b6976..9c5b6f4321cd8 100644 --- a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc +++ b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc @@ -32,7 +32,8 @@ class HGCClusterAlgo : public Algorithm HGCalHESiliconSensitive_( conf.getParameter("HGCalHESiliconSensitive_tag") ), calibration_( conf.getParameterSet("calib_parameters") ), clustering_( conf.getParameterSet("C2d_parameters") ), - multiclustering_( conf.getParameterSet("C3d_parameters" ) ) + multiclustering_( conf.getParameterSet("C3d_parameters" ) ), + clusteringAlgorithmType_(conf.getParameterSet("C2d_parameters").getParameter("clusterType")) { } @@ -83,6 +84,8 @@ class HGCClusterAlgo : public Algorithm HGCalClusteringImpl clustering_; HGCalMulticlusteringImpl multiclustering_; + /* algorithm type */ + std::string clusteringAlgorithmType_; }; @@ -148,12 +151,14 @@ void HGCClusterAlgo::run(const l1t::HGCFETriggerDigiCollection & c edm::Ptr ptr(triggerCellsHandle,i); triggerCellsPtrs.push_back(ptr); } - - /* call to dR-C2d clustering */ - //clustering_.clusterize( triggerCellsPtrs, *cluster_product_); - /* call to NN-C2d clustering */ - clustering_.clusterize( triggerCellsPtrs, *cluster_product_, triggerGeometry_ ); + /* call to C2d clustering */ + if(clusteringAlgorithmType_=="dRC2d"){ + clustering_.clusterize( triggerCellsPtrs, *cluster_product_); + } + else if(clusteringAlgorithmType_=="NNC2d"){ + clustering_.clusterize( triggerCellsPtrs, *cluster_product_, *triggerGeometry_ ); + } /* retrieve the orphan handle to the clusters collection and put the collection in the event */ clustersHandle = evt.put( std::move( cluster_product_ ), "cluster2D"); diff --git a/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py b/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py index 01422bc718adb..dc814c6dfb858 100644 --- a/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py +++ b/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py @@ -25,9 +25,11 @@ dEdXweights = recocalibparam.HGCalRecHit.layerWeights, thickCorr = recocalibparam.HGCalRecHit.thicknessCorrection ) -C2d_parValues = cms.PSet( seeding_threshold = cms.double(4), # MipT +C2d_parValues = cms.PSet( seeding_threshold = cms.double(5), # MipT clustering_threshold = cms.double(2), # MipT - dR_cluster = cms.double(3.) # in cm + dR_cluster = cms.double(3.), # in cm + maxTClength = cms.double(3.84), # in cm (for cells of 1.06cm^2) + clusterType = cms.string('NNC2d') # clustering type: dRC2d--> Geometric-dR clustering; NNC2d-->Nearest Neighbors clustering ) C3d_parValues = cms.PSet( dR_multicluster = cms.double(0.01) ) diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index 9dd1e4991a83e..dd2e318d3af2c 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -6,9 +6,11 @@ HGCalClusteringImpl::HGCalClusteringImpl(const edm::ParameterSet & conf): seedThreshold_(conf.getParameter("seeding_threshold")), triggerCellThreshold_(conf.getParameter("clustering_threshold")), - dr_(conf.getParameter("dR_cluster")) + dr_(conf.getParameter("dR_cluster")), + maxTClenght_(conf.getParameter("maxTClength")), + clusteringAlgorithmType_(conf.getParameter("clusterType")) { - + edm::LogInfo("HGCalClusterParameters") << "C2d Clustering Algorithm selected : " << clusteringAlgorithmType_ ; edm::LogInfo("HGCalClusterParameters") << "C2d seeding Thr: " << seedThreshold_ ; edm::LogInfo("HGCalClusterParameters") << "C2d clustering Thr: " << triggerCellThreshold_ ; @@ -36,7 +38,6 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } -/* dR-algorithms */ void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ){ @@ -44,7 +45,7 @@ void HGCalClusteringImpl::clusterize( const edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc,++itc ){ isSeed[itc] = ( (*tc)->mipPt() > seedThreshold_) ? true : false; } @@ -72,8 +73,8 @@ void HGCalClusteringImpl::clusterize( const edm::PtrVector 0 ){ - unsigned minDist = 300; - unsigned targetClu = 0; + unsigned minDist(300); + unsigned targetClu(0); for( std::vector::const_iterator iclu = tcPertinentClusters.begin(); iclu != tcPertinentClusters.end(); ++iclu ){ double d = clustersTmp.at(*iclu).distance(**tc); @@ -99,109 +100,37 @@ void HGCalClusteringImpl::clusterize( const edm::PtrVector triggerGeometry ) const -{ - HGCalDetId detId_tc1( tc1.detId() ); - HGCalDetId detId_tc2( tc2.detId() ); - if( (detId_tc1.layer() != detId_tc2.layer()) || - (detId_tc1.subdetId() != detId_tc2.subdetId()) || - (detId_tc1.zside() != detId_tc2.zside()) ){ - return false; - } - - const auto neighbors_tc1 = triggerGeometry->getNeighborsFromTriggerCell( detId_tc1 ); - const auto neighbors_tc2 = triggerGeometry->getNeighborsFromTriggerCell( detId_tc2 ); - - for(const auto neighbor_tc2 : neighbors_tc2) - { - if( !( neighbors_tc1.find( neighbor_tc2 ) == neighbors_tc1.end() ) ){ - return true; - } - } - - return false; - -} - +/* storing trigger cells into vector per layer and per endcap */ +void HGCalClusteringImpl::triggerCellReshuffling( const edm::PtrVector & triggerCellsPtrs, + std::array< std::array>,40>,2> & reshuffledTriggerCells + ){ -/* tc-clu */ -bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, - const l1t::HGCalCluster & clu, - edm::ESHandle triggerGeometry ) const -{ + for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc){ + int endcap = (*tc)->zside() == -1 ? 0 : 1 ; + HGCalDetId tcDetId( (*tc)->detId() ); + int subdet = tcDetId.subdetId(); + int layer = -1; - HGCalDetId tcDetId( tc.detId() ); - HGCalDetId cluDetId( clu.seedDetId() ); - if( (tcDetId.layer() != cluDetId.layer()) || - (tcDetId.subdetId() != cluDetId.subdetId()) || - (tcDetId.zside() != cluDetId.zside()) ){ - return false; - } - - const edm::PtrVector pertinentTC = clu.triggercells(); - for( edm::PtrVector::const_iterator it_tc = pertinentTC.begin(); it_tc!= pertinentTC.end(); ++it_tc){ - HGCalDetId tcInCluDetId( (*it_tc)->detId() ); - const auto neighbors = triggerGeometry->getNeighborsFromTriggerCell( tcInCluDetId ); - if( !( neighbors.find(tcDetId) == neighbors.end() ) ){ - return true; + if( subdet == HGCEE ){ + layer = (*tc)->layer(); } - } - - return false; - -} - - -/* clu-clu */ -bool HGCalClusteringImpl::isPertinent( const l1t::HGCalCluster & clu1, - const l1t::HGCalCluster & clu2, - edm::ESHandle triggerGeometry ) const -{ - HGCalDetId detId_clu1( clu1.seedDetId() ); - HGCalDetId detId_clu2( clu2.seedDetId() ); - - if( (detId_clu1.layer() != detId_clu2.layer()) || - (detId_clu1.subdetId() != detId_clu2.subdetId()) || - (detId_clu1.zside() != detId_clu2.zside()) ){ - return false; - } - - if( clu1.seedDetId() == clu2.seedDetId() ){ - return false; - } - - const edm::PtrVector pertinentTC_clu1 = clu1.triggercells(); - const edm::PtrVector pertinentTC_clu2 = clu2.triggercells(); - - int Ntc_clu1 = pertinentTC_clu1.size(); - int Ntc_clu2 = pertinentTC_clu2.size(); - - /* assume 1.06cm^2 cells */ - double maxTClength = 3.84; - double r_max = (Ntc_clu1 + Ntc_clu2) * maxTClength; - double distance = ( clu1.centre() - clu2.centre() ).mag(); - - if( distance < r_max){ - for( edm::PtrVector::const_iterator tc1 = pertinentTC_clu1.begin(); tc1 != pertinentTC_clu1.end(); ++tc1 ){ - for( edm::PtrVector::const_iterator tc2 = pertinentTC_clu2.begin(); tc2 != pertinentTC_clu2.end(); ++tc2 ){ - if( this->isPertinent( **tc1, **tc2, triggerGeometry ) ){ - return true; - } - } + else if( subdet == HGCHEF ){ + layer = (*tc)->layer() + 28; } + else if( subdet == HGCHEB ){ + edm::LogWarning("DataNotFound") << "WARNING: the BH trgCells are not yet implemented"; + } + + reshuffledTriggerCells[endcap][layer-1].emplace_back(*tc); + } - return false; - } /* merge clusters that have common neighbors */ void HGCalClusteringImpl::mergeClusters( l1t::HGCalCluster & main_cluster, - l1t::HGCalCluster & secondary_cluster ) const + const l1t::HGCalCluster & secondary_cluster ) const { const edm::PtrVector pertinentTC = secondary_cluster.triggercells(); @@ -213,110 +142,115 @@ void HGCalClusteringImpl::mergeClusters( l1t::HGCalCluster & main_cluster, } -void HGCalClusteringImpl::triggerCellReshuffling_( const edm::PtrVector & triggerCellsPtrs, - std::vector> (&reshuffledTriggerCells)[2][40] - ){ - - for( edm::PtrVector::const_iterator tc = triggerCellsPtrs.begin(); tc != triggerCellsPtrs.end(); ++tc){ - int endcap = (*tc)->zside() == -1 ? 0 : 1 ; - HGCalDetId tcDetId( (*tc)->detId() ); - int subdet = tcDetId.subdetId(); - int layer = -1; - if(subdet==3){ - layer = (*tc)->layer(); - } - else if(subdet==4){ - layer = (*tc)->layer() + 28; - } - - reshuffledTriggerCells[endcap][layer-1].emplace_back(*tc); - - } - -} - - -void HGCalClusteringImpl::NNKernel( std::vector> (&reshuffledTriggerCells)[2][40], +void HGCalClusteringImpl::NNKernel( std::vector> & reshuffledTriggerCells, l1t::HGCalClusterBxCollection & clusters, - edm::ESHandle triggerGeometry, - int endcap, - int layer + const HGCalTriggerGeometryBase & triggerGeometry ){ /* declaring the clusters vector */ std::vector clustersTmp; + std::unordered_map cluNNmap; + int i_clu(0); + /* loop over the trigger-cells */ - for( std::vector>::iterator tc=reshuffledTriggerCells[endcap][layer].begin(); tc!=reshuffledTriggerCells[endcap][layer].end(); tc++ ){ + for( std::vector>::iterator tc=reshuffledTriggerCells.begin(); tc!=reshuffledTriggerCells.end(); tc++ ){ if( (*tc)->mipPt() < triggerCellThreshold_ ){ continue; } - bool createNewC2d = true; - int i_clu=0; - - for(std::vector::iterator clu = clustersTmp.begin(); clu != clustersTmp.end(); ++clu, ++i_clu ){ - if( this->isPertinent( **tc, *clu, triggerGeometry ) ){ - clustersTmp.at( i_clu ).addTriggerCell( *tc ); + bool createNewC2d(true); + + for( auto it : cluNNmap ){ + HGCalDetId nnDetId( it.first ); + const auto neighbors = triggerGeometry.getNeighborsFromTriggerCell( nnDetId ); + + if( !( neighbors.find( (*tc)->detId() ) == neighbors.end() ) ) + { + clustersTmp.at( it.second ).addTriggerCell( *tc ); + cluNNmap.insert(std::make_pair( (*tc)->detId(), it.second ) ); + clustersTmp.at( it.second ).setIsComplete(true); createNewC2d = false; break; - } + } } - + if( createNewC2d ){ clustersTmp.emplace_back( *tc ); + cluNNmap.insert(std::make_pair( (*tc)->detId(), i_clu ) ); + clustersTmp.at( i_clu ).setIsComplete(true); + ++i_clu; } } /* declaring the vector with possible clusters merged */ - for(unsigned i_clu1 = 0; i_clu1 < clustersTmp.size(); ++i_clu1){ - - std::vector idx_cluToRm; - for(unsigned i_clu2 = 0; i_clu2 < clustersTmp.size(); ++i_clu2){ - if( this->isPertinent( clustersTmp.at(i_clu1), clustersTmp.at(i_clu2), triggerGeometry ) ){ - this->mergeClusters( clustersTmp.at(i_clu1), clustersTmp.at(i_clu2) ); - idx_cluToRm.push_back( i_clu2 ); - } - } + std::unordered_set cluTcSet; + + const edm::PtrVector pertinentTC_clu1 = clustersTmp.at(i_clu1).triggercells(); - /* erase all the clusters that has been added */ - std::sort( idx_cluToRm.begin(), idx_cluToRm.end() ); - std::reverse( idx_cluToRm.begin(), idx_cluToRm.end() ); + for(edm::PtrVector::const_iterator tc_clu1 = pertinentTC_clu1.begin(); tc_clu1 != pertinentTC_clu1.end(); ++tc_clu1 ){ + cluTcSet.insert( (*tc_clu1)->detId() ); + HGCalDetId tcInClu1DetId( (*tc_clu1)->detId() ); + const auto neighbors = triggerGeometry.getNeighborsFromTriggerCell( tcInClu1DetId ); + for(const auto neighbor : neighbors) + { + if( !( cluTcSet.find( neighbor ) == cluTcSet.end() ) ) + { + cluTcSet.insert( neighbor ); + } + } + } + + for(unsigned i_clu2(i_clu1+1); i_clu2 < clustersTmp.size(); ++i_clu2){ - for(unsigned idx = 0; idx < idx_cluToRm.size(); ++idx){ - clustersTmp.erase( clustersTmp.begin() + idx_cluToRm.at(idx) ); + const edm::PtrVector pertinentTC_clu2 = clustersTmp.at(i_clu2).triggercells(); + for(edm::PtrVector::const_iterator tc_clu2 = pertinentTC_clu2.begin(); tc_clu2 != pertinentTC_clu2.end(); ++tc_clu2 ){ + + if( !( cluTcSet.find( (*tc_clu2)->detId() ) == cluTcSet.end() ) && clustersTmp.at(i_clu2).isComplete()==true ) + { + this->mergeClusters( clustersTmp.at(i_clu1), clustersTmp.at(i_clu2) ); + clustersTmp.at(i_clu1).setIsComplete(false); + } + } } } /* store clusters in the persistent collection */ for( unsigned i(0); i pertinentTC = clustersTmp.at(i).triggercells(); + + for(edm::PtrVector::const_iterator tc = pertinentTC.begin(); tc != pertinentTC.end(); ++tc ){ + /* threshold in transverse-mip */ + if( (*tc)->mipPt() > seedThreshold_ ){ + saveInCollection = true; + } + } + if(saveInCollection){ clusters.push_back( 0, clustersTmp.at(i) ); } + } - clustersTmp.clear(); - } void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, - edm::ESHandle triggerGeometry + const HGCalTriggerGeometryBase & triggerGeometry ){ - - std::vector> reshuffledTriggerCells[2][40]; - triggerCellReshuffling_( triggerCellsPtrs, reshuffledTriggerCells ); - + + std::array< std::array< std::vector >,40>,2> reshuffledTriggerCells; + triggerCellReshuffling( triggerCellsPtrs, reshuffledTriggerCells ); + for(int iec=0; iec<2; ++iec){ for(int il=0; il<40; ++il){ - - NNKernel( reshuffledTriggerCells, clusters, triggerGeometry, iec, il ); - + std::vector> oneLayerTriggerCell( reshuffledTriggerCells[iec][il] ); + NNKernel( oneLayerTriggerCell, clusters, triggerGeometry ); } } diff --git a/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py b/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py index a7947c0f8453f..1e1355b8c783c 100644 --- a/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py +++ b/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py @@ -25,7 +25,7 @@ process.load('L1Trigger.L1THGCal.hgcalTriggerPrimitives_cff') process.maxEvents = cms.untracked.PSet( - input = cms.untracked.int32(-1) + input = cms.untracked.int32(20) ) # Input source @@ -33,7 +33,6 @@ secondaryFileNames = cms.untracked.vstring(), fileNames = cms.untracked.vstring('root://cms-xrd-global.cern.ch//store/mc/PhaseIIFall16DR82/MinBias_200PU_TuneCUETP8M1_14TeV-pythia8/GEN-SIM-RECO/PU200_90X_upgrade2023_realistic_v1-v1/60000/0047077C-B4ED-E611-8B36-FA163E78D122.root') ) - # Additional output definition process.TFileService = cms.Service( "TFileService", @@ -54,7 +53,14 @@ 2 ** process.hgcalTriggerPrimitiveDigiProducer.FECodec.triggerCellTruncationBits.value() ) -# Adjust the max-dR for 2D-clustering +#chose the C2d-algorithm to run [NNC2d or dRC2d] +process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.clusterType = cms.string('NNC2d') +# Adjust C2d thresholds +process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.seeding_threshold = cms.double(5) +process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.clustering_threshold = cms.double(2) +# Adjust the maxTC-length for NNC2d-clustering +process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.maxTClength = cms.double(3.84) +# Adjust the max-dR for geometric dRC2d-clustering process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.dR_cluster = cms.double(3.) trgCells_algo_all = cms.PSet( AlgorithmName = cms.string('SingleCellClusterAlgoBestChoice'), From 831588559708a2142ea01e39159c8d43c1ea1b0a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Sauvan Date: Sun, 9 Apr 2017 15:39:31 +0200 Subject: [PATCH 7/9] Update 2D clustering --- .../src/be_algorithms/HGCalClusteringImpl.cc | 109 +++++++++--------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index dd2e318d3af2c..3b6679f4c8db3 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -150,92 +150,93 @@ void HGCalClusteringImpl::NNKernel( std::vector> /* declaring the clusters vector */ std::vector clustersTmp; + // map TC id -> cluster index in clustersTmp std::unordered_map cluNNmap; - int i_clu(0); /* loop over the trigger-cells */ - for( std::vector>::iterator tc=reshuffledTriggerCells.begin(); tc!=reshuffledTriggerCells.end(); tc++ ){ + for( const auto& tc_ptr : reshuffledTriggerCells ){ - if( (*tc)->mipPt() < triggerCellThreshold_ ){ + if( tc_ptr->mipPt() < triggerCellThreshold_ ){ continue; } + // Check if the neighbors of that TC are already included in a cluster + // If this is the case, add the TC to the first (arbitrary) neighbor cluster + // Otherwise create a new cluster bool createNewC2d(true); - - for( auto it : cluNNmap ){ - HGCalDetId nnDetId( it.first ); - const auto neighbors = triggerGeometry.getNeighborsFromTriggerCell( nnDetId ); - - if( !( neighbors.find( (*tc)->detId() ) == neighbors.end() ) ) - { - clustersTmp.at( it.second ).addTriggerCell( *tc ); - cluNNmap.insert(std::make_pair( (*tc)->detId(), it.second ) ); - clustersTmp.at( it.second ).setIsComplete(true); + const auto neighbors = triggerGeometry.getNeighborsFromTriggerCell(tc_ptr->detId()); + for( const auto neighbor : neighbors ){ + auto tc_cluster_itr = cluNNmap.find(neighbor); + if(tc_cluster_itr!=cluNNmap.end()){ createNewC2d = false; + try{ + clustersTmp.at(tc_cluster_itr->second).addTriggerCell(tc_ptr); + // map TC id to the existing cluster + cluNNmap.emplace(tc_ptr->detId(), tc_cluster_itr->second); + } + catch(const std::out_of_range& e){ + throw cms::Exception("HGCTriggerUnexpected") + << "Trying to access a non-existing cluster. But it should exist...\n"; + } break; - } + } } - - if( createNewC2d ){ - clustersTmp.emplace_back( *tc ); - cluNNmap.insert(std::make_pair( (*tc)->detId(), i_clu ) ); - clustersTmp.at( i_clu ).setIsComplete(true); - ++i_clu; + if(createNewC2d){ + clustersTmp.emplace_back(tc_ptr); + clustersTmp.back().setIsComplete(true); + // map TC id to the cluster index (size - 1) + cluNNmap.emplace(tc_ptr->detId(), clustersTmp.size()-1); } } /* declaring the vector with possible clusters merged */ + // Merge neighbor clusters together for(unsigned i_clu1 = 0; i_clu1 < clustersTmp.size(); ++i_clu1){ + l1t::HGCalCluster& cluster1 = clustersTmp.at(i_clu1); + // If the cluster has been merged into another one, skip it + if(!cluster1.isComplete()) continue; + // Fill a set containing all TC included in the clusters + // as well as all neighbor TC std::unordered_set cluTcSet; - - const edm::PtrVector pertinentTC_clu1 = clustersTmp.at(i_clu1).triggercells(); - - for(edm::PtrVector::const_iterator tc_clu1 = pertinentTC_clu1.begin(); tc_clu1 != pertinentTC_clu1.end(); ++tc_clu1 ){ - cluTcSet.insert( (*tc_clu1)->detId() ); - HGCalDetId tcInClu1DetId( (*tc_clu1)->detId() ); - const auto neighbors = triggerGeometry.getNeighborsFromTriggerCell( tcInClu1DetId ); - for(const auto neighbor : neighbors) - { - if( !( cluTcSet.find( neighbor ) == cluTcSet.end() ) ) - { - cluTcSet.insert( neighbor ); - } + for(const auto& tc_clu1 : cluster1.triggercells()){ + cluTcSet.insert( tc_clu1->detId() ); + const auto neighbors = triggerGeometry.getNeighborsFromTriggerCell( tc_clu1->detId() ); + for(const auto neighbor : neighbors){ + cluTcSet.insert( neighbor ); } } - for(unsigned i_clu2(i_clu1+1); i_clu2 < clustersTmp.size(); ++i_clu2){ - - const edm::PtrVector pertinentTC_clu2 = clustersTmp.at(i_clu2).triggercells(); - for(edm::PtrVector::const_iterator tc_clu2 = pertinentTC_clu2.begin(); tc_clu2 != pertinentTC_clu2.end(); ++tc_clu2 ){ - - if( !( cluTcSet.find( (*tc_clu2)->detId() ) == cluTcSet.end() ) && clustersTmp.at(i_clu2).isComplete()==true ) - { - this->mergeClusters( clustersTmp.at(i_clu1), clustersTmp.at(i_clu2) ); - clustersTmp.at(i_clu1).setIsComplete(false); - } - } + for(unsigned i_clu2 = i_clu1+1; i_clu2 < clustersTmp.size(); ++i_clu2){ + l1t::HGCalCluster& cluster2 = clustersTmp.at(i_clu2); + // If the cluster has been merged into another one, skip it + if(!cluster2.isComplete()) continue; + // Check if the TC in clu2 are in clu1 or its neighbors + // If yes, merge the second cluster into the first one + for(const auto& tc_clu2 : cluster2.triggercells()){ + if( cluTcSet.find(tc_clu2->detId())!=cluTcSet.end() ){ + mergeClusters( cluster1, cluster2 ); + cluster2.setIsComplete(false); + break; + } + } } - } /* store clusters in the persistent collection */ - for( unsigned i(0); i pertinentTC = clustersTmp.at(i).triggercells(); - - for(edm::PtrVector::const_iterator tc = pertinentTC.begin(); tc != pertinentTC.end(); ++tc ){ + for( const auto& tc_ptr : cluster.triggercells() ){ /* threshold in transverse-mip */ - if( (*tc)->mipPt() > seedThreshold_ ){ + if( tc_ptr->mipPt() > seedThreshold_ ){ saveInCollection = true; + break; } } if(saveInCollection){ - clusters.push_back( 0, clustersTmp.at(i) ); + clusters.push_back( 0, cluster ); } - } - } From 1980482244c8fedd925890322b68baacfdedcef7 Mon Sep 17 00:00:00 2001 From: Luca Mastrolorenzo Date: Mon, 10 Apr 2017 19:22:09 +0200 Subject: [PATCH 8/9] NNC2d update + cleaning --- DataFormats/L1THGCal/src/HGCalCluster.cc | 2 +- .../be_algorithms/HGCalClusteringImpl.h | 14 +++----- .../plugins/be_algorithms/HGCClusterAlgo.cc | 6 ++-- .../hgcalTriggerPrimitiveDigiProducer_cfi.py | 1 - .../src/be_algorithms/HGCalClusteringImpl.cc | 34 ++++++++++++------- L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py | 5 ++- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/DataFormats/L1THGCal/src/HGCalCluster.cc b/DataFormats/L1THGCal/src/HGCalCluster.cc index 829994467b9f8..9088d8670b512 100644 --- a/DataFormats/L1THGCal/src/HGCalCluster.cc +++ b/DataFormats/L1THGCal/src/HGCalCluster.cc @@ -63,7 +63,7 @@ void HGCalCluster::addTriggerCell( const edm::Ptr &tc ) p4 += tc->p4(); this->setP4( p4 ); - triggercells_.push_back( tc ); + triggercells_.push_back( tc ); } diff --git a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h index a05e01ecda448..4da16d4feff9c 100644 --- a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h +++ b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h @@ -1,9 +1,6 @@ #ifndef __L1Trigger_L1THGCal_HGCalClusteringImpl_h__ #define __L1Trigger_L1THGCal_HGCalClusteringImpl_h__ -#include -#include -#include #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h" @@ -23,20 +20,20 @@ class HGCalClusteringImpl{ const l1t::HGCalCluster & clu, double distXY) const; - void clusterize( const edm::PtrVector & triggerCellsPtrs, + void clusterizeDR( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ); /* NN-algorithms */ void mergeClusters( l1t::HGCalCluster & main_cluster, - const l1t::HGCalCluster & secondary_cluster ) const; + l1t::HGCalCluster & secondary_cluster ) const; - void NNKernel( std::vector> &reshuffledTriggerCells, + void NNKernel( const std::vector> &reshuffledTriggerCells, l1t::HGCalClusterBxCollection & clusters, const HGCalTriggerGeometryBase & triggerGeometry ); - void clusterize( const edm::PtrVector & triggerCellsPtrs, + void clusterizeNN( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, const HGCalTriggerGeometryBase & triggerGeometry ); @@ -47,8 +44,7 @@ class HGCalClusteringImpl{ double seedThreshold_; double triggerCellThreshold_; double dr_; - double maxTClenght_; - string clusteringAlgorithmType_; + std::string clusteringAlgorithmType_; void triggerCellReshuffling( const edm::PtrVector & triggerCellsPtrs, std::array>,40>,2> & reshuffledTriggerCells ); diff --git a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc index 9c5b6f4321cd8..df076a5ebb687 100644 --- a/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc +++ b/L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc @@ -33,7 +33,7 @@ class HGCClusterAlgo : public Algorithm calibration_( conf.getParameterSet("calib_parameters") ), clustering_( conf.getParameterSet("C2d_parameters") ), multiclustering_( conf.getParameterSet("C3d_parameters" ) ), - clusteringAlgorithmType_(conf.getParameterSet("C2d_parameters").getParameter("clusterType")) + clusteringAlgorithmType_(conf.getParameterSet("C2d_parameters").getParameter("clusterType")) { } @@ -154,10 +154,10 @@ void HGCClusterAlgo::run(const l1t::HGCFETriggerDigiCollection & c /* call to C2d clustering */ if(clusteringAlgorithmType_=="dRC2d"){ - clustering_.clusterize( triggerCellsPtrs, *cluster_product_); + clustering_.clusterizeDR( triggerCellsPtrs, *cluster_product_); } else if(clusteringAlgorithmType_=="NNC2d"){ - clustering_.clusterize( triggerCellsPtrs, *cluster_product_, *triggerGeometry_ ); + clustering_.clusterizeNN( triggerCellsPtrs, *cluster_product_, *triggerGeometry_ ); } /* retrieve the orphan handle to the clusters collection and put the collection in the event */ diff --git a/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py b/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py index dc814c6dfb858..8e1be896b7408 100644 --- a/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py +++ b/L1Trigger/L1THGCal/python/hgcalTriggerPrimitiveDigiProducer_cfi.py @@ -28,7 +28,6 @@ C2d_parValues = cms.PSet( seeding_threshold = cms.double(5), # MipT clustering_threshold = cms.double(2), # MipT dR_cluster = cms.double(3.), # in cm - maxTClength = cms.double(3.84), # in cm (for cells of 1.06cm^2) clusterType = cms.string('NNC2d') # clustering type: dRC2d--> Geometric-dR clustering; NNC2d-->Nearest Neighbors clustering ) diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index 3b6679f4c8db3..5cc2a823da019 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -1,3 +1,6 @@ +#include +#include +#include #include "L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h" #include "DataFormats/Common/interface/PtrVector.h" #include "DataFormats/Common/interface/OrphanHandle.h" @@ -7,7 +10,6 @@ HGCalClusteringImpl::HGCalClusteringImpl(const edm::ParameterSet & conf): seedThreshold_(conf.getParameter("seeding_threshold")), triggerCellThreshold_(conf.getParameter("clustering_threshold")), dr_(conf.getParameter("dR_cluster")), - maxTClenght_(conf.getParameter("maxTClength")), clusteringAlgorithmType_(conf.getParameter("clusterType")) { edm::LogInfo("HGCalClusterParameters") << "C2d Clustering Algorithm selected : " << clusteringAlgorithmType_ ; @@ -38,7 +40,7 @@ bool HGCalClusteringImpl::isPertinent( const l1t::HGCalTriggerCell & tc, } -void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, +void HGCalClusteringImpl::clusterizeDR( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters ){ @@ -130,19 +132,19 @@ void HGCalClusteringImpl::triggerCellReshuffling( const edm::PtrVector pertinentTC = secondary_cluster.triggercells(); + const edm::PtrVector& pertinentTC = secondary_cluster.triggercells(); for( edm::PtrVector::iterator tc = pertinentTC.begin(); tc != pertinentTC.end(); ++tc ){ main_cluster.addTriggerCell(*tc); } - + } -void HGCalClusteringImpl::NNKernel( std::vector> & reshuffledTriggerCells, +void HGCalClusteringImpl::NNKernel( const std::vector> & reshuffledTriggerCells, l1t::HGCalClusterBxCollection & clusters, const HGCalTriggerGeometryBase & triggerGeometry ){ @@ -194,7 +196,7 @@ void HGCalClusteringImpl::NNKernel( std::vector> for(unsigned i_clu1 = 0; i_clu1 < clustersTmp.size(); ++i_clu1){ l1t::HGCalCluster& cluster1 = clustersTmp.at(i_clu1); // If the cluster has been merged into another one, skip it - if(!cluster1.isComplete()) continue; + if( !cluster1.isComplete() ) continue; // Fill a set containing all TC included in the clusters // as well as all neighbor TC std::unordered_set cluTcSet; @@ -206,15 +208,21 @@ void HGCalClusteringImpl::NNKernel( std::vector> } } - for(unsigned i_clu2 = i_clu1+1; i_clu2 < clustersTmp.size(); ++i_clu2){ + for(unsigned i_clu2 = 0; i_clu2 < clustersTmp.size(); ++i_clu2){ l1t::HGCalCluster& cluster2 = clustersTmp.at(i_clu2); // If the cluster has been merged into another one, skip it - if(!cluster2.isComplete()) continue; + if( cluster1.seedDetId()==cluster2.seedDetId() ) continue; + if( !cluster2.isComplete() ) continue; // Check if the TC in clu2 are in clu1 or its neighbors // If yes, merge the second cluster into the first one for(const auto& tc_clu2 : cluster2.triggercells()){ if( cluTcSet.find(tc_clu2->detId())!=cluTcSet.end() ){ - mergeClusters( cluster1, cluster2 ); + mergeClusters( cluster1, cluster2 ); + cluTcSet.insert( tc_clu2->detId() ); + const auto neighbors = triggerGeometry.getNeighborsFromTriggerCell( tc_clu2->detId() ); + for(const auto neighbor : neighbors){ + cluTcSet.insert( neighbor ); + } cluster2.setIsComplete(false); break; } @@ -225,6 +233,7 @@ void HGCalClusteringImpl::NNKernel( std::vector> /* store clusters in the persistent collection */ // only if the cluster contain a TC above the seed threshold for( auto& cluster : clustersTmp ){ + if( !cluster.isComplete() ) continue; bool saveInCollection(false); for( const auto& tc_ptr : cluster.triggercells() ){ /* threshold in transverse-mip */ @@ -240,7 +249,7 @@ void HGCalClusteringImpl::NNKernel( std::vector> } -void HGCalClusteringImpl::clusterize( const edm::PtrVector & triggerCellsPtrs, +void HGCalClusteringImpl::clusterizeNN( const edm::PtrVector & triggerCellsPtrs, l1t::HGCalClusterBxCollection & clusters, const HGCalTriggerGeometryBase & triggerGeometry ){ @@ -250,8 +259,7 @@ void HGCalClusteringImpl::clusterize( const edm::PtrVector> oneLayerTriggerCell( reshuffledTriggerCells[iec][il] ); - NNKernel( oneLayerTriggerCell, clusters, triggerGeometry ); + NNKernel( reshuffledTriggerCells[iec][il], clusters, triggerGeometry ); } } diff --git a/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py b/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py index 1e1355b8c783c..e59b49920b37a 100644 --- a/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py +++ b/L1Trigger/L1THGCal/test/testNtuplyzer_cfg.py @@ -31,7 +31,8 @@ # Input source process.source = cms.Source("PoolSource", secondaryFileNames = cms.untracked.vstring(), - fileNames = cms.untracked.vstring('root://cms-xrd-global.cern.ch//store/mc/PhaseIIFall16DR82/MinBias_200PU_TuneCUETP8M1_14TeV-pythia8/GEN-SIM-RECO/PU200_90X_upgrade2023_realistic_v1-v1/60000/0047077C-B4ED-E611-8B36-FA163E78D122.root') +# fileNames = cms.untracked.vstring('root://cms-xrd-global.cern.ch//store/mc/PhaseIIFall16DR82/MinBias_200PU_TuneCUETP8M1_14TeV-pythia8/GEN-SIM-RECO/PU200_90X_upgrade2023_realistic_v1-v1/60000/0047077C-B4ED-E611-8B36-FA163E78D122.root') + fileNames = cms.untracked.vstring('root://cms-xrd-global.cern.ch//store/relval/CMSSW_9_0_0_pre4/RelValTTbar_14TeV/GEN-SIM-RECO/PU25ns_90X_upgrade2023_realistic_v3_D4TPU200c2-v1/10000/28524D8F-20F0-E611-B999-0CC47A7C354C.root') ) # Additional output definition process.TFileService = cms.Service( @@ -58,8 +59,6 @@ # Adjust C2d thresholds process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.seeding_threshold = cms.double(5) process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.clustering_threshold = cms.double(2) -# Adjust the maxTC-length for NNC2d-clustering -process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.maxTClength = cms.double(3.84) # Adjust the max-dR for geometric dRC2d-clustering process.hgcalTriggerPrimitiveDigiProducer.BEConfiguration.algorithms[0].C2d_parameters.dR_cluster = cms.double(3.) From 047ea1d4c23215a6194d483f6bf66d1d339a527b Mon Sep 17 00:00:00 2001 From: Luca Mastrolorenzo Date: Mon, 10 Apr 2017 22:42:02 +0200 Subject: [PATCH 9/9] fixes in HGCalClusteringImpl --- .../L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h | 3 ++- L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h index 4da16d4feff9c..a8c04a35b44b0 100644 --- a/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h +++ b/L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h @@ -1,6 +1,7 @@ #ifndef __L1Trigger_L1THGCal_HGCalClusteringImpl_h__ #define __L1Trigger_L1THGCal_HGCalClusteringImpl_h__ +#include #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h" #include "DataFormats/L1THGCal/interface/HGCalTriggerCell.h" @@ -26,7 +27,7 @@ class HGCalClusteringImpl{ /* NN-algorithms */ void mergeClusters( l1t::HGCalCluster & main_cluster, - l1t::HGCalCluster & secondary_cluster ) const; + const l1t::HGCalCluster & secondary_cluster ) const; void NNKernel( const std::vector> &reshuffledTriggerCells, l1t::HGCalClusterBxCollection & clusters, diff --git a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc index 5cc2a823da019..6c82e76fa8733 100644 --- a/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc +++ b/L1Trigger/L1THGCal/src/be_algorithms/HGCalClusteringImpl.cc @@ -1,4 +1,3 @@ -#include #include #include #include "L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h" @@ -132,7 +131,7 @@ void HGCalClusteringImpl::triggerCellReshuffling( const edm::PtrVector& pertinentTC = secondary_cluster.triggercells();