1 #include <unordered_set> 2 #include <unordered_map> 9 siliconSeedThreshold_(conf.getParameter<double>(
"seeding_threshold_silicon")),
10 siliconTriggerCellThreshold_(conf.getParameter<double>(
"clustering_threshold_silicon")),
11 scintillatorSeedThreshold_(conf.getParameter<double>(
"seeding_threshold_scintillator")),
12 scintillatorTriggerCellThreshold_(conf.getParameter<double>(
"clustering_threshold_scintillator")),
13 dr_(conf.getParameter<double>(
"dR_cluster")),
14 clusteringAlgorithmType_(conf.getParameter<
string>(
"clusterType")),
15 calibSF_(conf.getParameter<double>(
"calibSF_cluster")),
16 layerWeights_(conf.getParameter<
std::vector<double> >(
"layerWeights")),
17 applyLayerWeights_(conf.getParameter<
bool >(
"applyLayerCalibration"))
36 if( (tcDetId.layer() != cluDetId.layer()) ||
37 (tcDetId.subdetId() != cluDetId.subdetId()) ||
38 (tcDetId.zside() != cluDetId.zside()) ){
53 bool isSeed[triggerCellsPtrs.size()];
59 isSeed[itc] = ( (*tc)->mipPt() >
seedThreshold) ?
true :
false;
63 std::vector<l1t::HGCalCluster> clustersTmp;
78 vector<int> tcPertinentClusters;
79 for(
const auto& clu : clustersTmp){
81 tcPertinentClusters.push_back(iclu);
85 if( tcPertinentClusters.empty() && isSeed[itc] ){
86 clustersTmp.emplace_back( *tc );
88 else if ( !tcPertinentClusters.empty() ){
90 unsigned minDist(300);
91 unsigned targetClu(0);
93 for(
int iclu : tcPertinentClusters){
94 double d = clustersTmp.at(iclu).distance(**tc);
101 clustersTmp.at(targetClu).addConstituent( *tc );
107 clusters.
resize(0, clustersTmp.size());
108 for(
unsigned i(0);
i<clustersTmp.size(); ++
i ){
110 clusters.
set( 0,
i, clustersTmp.at(
i) );
126 for(
const auto& tc : triggerCellsPtrs ){
127 int endcap = tc->zside() == -1 ? 0 : 1 ;
131 reshuffledTriggerCells[
endcap][layer-1].emplace_back(tc);
143 const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalTriggerCell>>& pertinentTC = secondary_cluster.
constituents();
145 for(
const auto& id_tc : pertinentTC){
158 std::vector<l1t::HGCalCluster> clustersTmp;
161 std::unordered_map<uint32_t, unsigned> cluNNmap;
164 for(
const auto& tc_ptr : reshuffledTriggerCells ){
173 bool createNewC2d(
true);
175 for(
const auto neighbor : neighbors ){
176 auto tc_cluster_itr = cluNNmap.find(neighbor);
177 if(tc_cluster_itr!=cluNNmap.end()){
178 createNewC2d =
false;
179 if( tc_cluster_itr->second < clustersTmp.size()){
180 clustersTmp.at(tc_cluster_itr->second).addConstituent(tc_ptr);
182 cluNNmap.emplace(tc_ptr->detId(), tc_cluster_itr->second);
186 <<
"Trying to access a non-existing cluster. But it should exist...\n";
192 clustersTmp.emplace_back(tc_ptr);
193 clustersTmp.back().setValid(
true);
195 cluNNmap.emplace(tc_ptr->detId(), clustersTmp.size()-1);
201 for(
auto& cluster1 : clustersTmp){
203 if( !cluster1.valid() )
continue;
206 std::unordered_set<uint32_t> cluTcSet;
207 for(
const auto& tc_clu1 : cluster1.constituents()){
208 cluTcSet.insert( tc_clu1.second->detId() );
210 for(
const auto neighbor : neighbors){
211 cluTcSet.insert( neighbor );
215 for(
auto& cluster2 : clustersTmp ){
217 if( cluster1.detId()==cluster2.detId() )
continue;
218 if( !cluster2.valid() )
continue;
221 for(
const auto& tc_clu2 : cluster2.constituents()){
222 if( cluTcSet.find(tc_clu2.second->detId())!=cluTcSet.end() ){
224 cluTcSet.insert( tc_clu2.second->detId() );
226 for(
const auto neighbor : neighbors){
227 cluTcSet.insert( neighbor );
229 cluster2.setValid(
false);
238 for(
auto& cluster : clustersTmp ){
239 if( !cluster.valid() )
continue;
240 bool saveInCollection(
false);
241 for(
const auto& id_tc : cluster.constituents() ){
245 saveInCollection =
true;
249 if(saveInCollection){
262 std::array< std::vector< std::vector<edm::Ptr<l1t::HGCalTriggerCell>>>,
kNSides_> reshuffledTriggerCells;
264 for(
unsigned side=0; side<
kNSides_; side++)
266 reshuffledTriggerCells[side].resize(layers);
270 for(
unsigned iec=0; iec<
kNSides_; ++iec){
271 for(
unsigned il=0; il<
layers; ++il){
272 NNKernel( reshuffledTriggerCells[iec][il], clusters, triggerGeometry );
286 bool isSeed[triggerCellsPtrs.size()];
287 std::vector<unsigned> seedPositions;
288 seedPositions.reserve( triggerCellsPtrs.size() );
297 isSeed[itc] = ( (*tc)->mipPt() >
seedThreshold) ?
true :
false;
300 seedPositions.push_back( itc );
303 for(
auto pos : seedPositions ){
304 if( ( (*tc)->position() - triggerCellsPtrs[
pos]->position() ).
mag() <
dr_ ){
305 if( this->
areTCneighbour( (*tc)->detId(), triggerCellsPtrs[
pos]->detId(), triggerGeometry ) )
308 seedPositions.pop_back();
317 std::vector<l1t::HGCalCluster> clustersTmp;
320 for(
auto pos : seedPositions ) {
321 clustersTmp.emplace_back( triggerCellsPtrs[
pos] );
332 if( (*tc)->mipPt() <
threshold )
continue;
333 if( isSeed[itc] )
continue;
336 std::vector<unsigned> tcPertinentClusters;
339 for (
const auto& clu : clustersTmp ) {
341 tcPertinentClusters.push_back( iclu );
346 if ( tcPertinentClusters.empty() ) {
349 else if( tcPertinentClusters.size() == 1 ) {
350 clustersTmp.at( tcPertinentClusters.at(0) ).addConstituent( *tc );
356 for(
auto clu : tcPertinentClusters ){
357 totMipt += clustersTmp.at( clu ).seedMipPt();
360 for(
auto clu : tcPertinentClusters ){
361 double seedMipt = clustersTmp.at( clu ).seedMipPt();
362 clustersTmp.at( clu ).addConstituent( *tc,
true, seedMipt/totMipt );
368 clusters.
resize(0, clustersTmp.size());
369 for(
unsigned i(0);
i<clustersTmp.size(); ++
i ){
372 clusters.
set( 0,
i, clustersTmp.at(
i) );
383 if( neighbors.find( detIDb ) != neighbors.end() )
return true;
393 const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalTriggerCell>>& constituents = cluster.
constituents();
397 vector<pair<edm::Ptr<l1t::HGCalTriggerCell>,
float>> distances;
398 for(
const auto & id_tc : constituents )
411 bool toRemove[constituents.size()];
413 for(
unsigned itc=1; itc<distances.size(); itc++ ){
416 toRemove[itc] =
true;
420 for(
unsigned itc_ref=0; itc_ref<itc; itc_ref++ ){
421 if( !toRemove[itc_ref] ) {
422 if(
areTCneighbour( tcToStudy->
detId(), distances.at( itc_ref ).first->detId(), triggerGeometry ) ) {
423 toRemove[itc] =
false;
433 for(
unsigned i=0;
i<distances.size();
i++){
451 <<
"2D cluster energy forced to 0 by calibration coefficients.\n" 452 <<
"The configuration should be changed. " 453 <<
"Discarded layers should be defined in hgcalTriggerGeometryESProducer.TriggerGeometry.DisconnectedLayers and not with calibration coefficients = 0\n";
471 cluster.
setP4( calibP4 );
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
double distance(const l1t::HGCalTriggerCell &tc) const
double siliconSeedThreshold_
double eta() const final
momentum pseudorapidity
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
double scintillatorSeedThreshold_
bool distanceSorter(pair< edm::Ptr< l1t::HGCalTriggerCell >, float > i, pair< edm::Ptr< l1t::HGCalTriggerCell >, float > j)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual geom_set getNeighborsFromTriggerCell(const unsigned trigger_cell_det_id) const =0
void calibratePt(l1t::HGCalCluster &cluster)
void mergeClusters(l1t::HGCalCluster &main_cluster, const l1t::HGCalCluster &secondary_cluster) const
double pt() const final
transverse momentum
std::vector< double > layerWeights_
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
void clusterizeDRNN(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &triggerCellsPtrs, l1t::HGCalClusterBxCollection &clusters, const HGCalTriggerGeometryBase &triggerGeometry)
void removeConstituent(const edm::Ptr< C > &c, bool updateCentre=true)
bool isPertinent(const l1t::HGCalTriggerCell &tc, const l1t::HGCalCluster &clu, double distXY) const
void clusterizeNN(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &triggerCellsPtrs, l1t::HGCalClusterBxCollection &clusters, const HGCalTriggerGeometryBase &triggerGeometry)
std::string clusteringAlgorithmType_
void removeUnconnectedTCinCluster(l1t::HGCalCluster &cluster, const HGCalTriggerGeometryBase &triggerGeometry)
void triggerCellReshuffling(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &triggerCellsPtrs, std::array< std::vector< std::vector< edm::Ptr< l1t::HGCalTriggerCell >>>, kNSides_ > &reshuffledTriggerCells)
void set(int bx, unsigned i, const T &object)
static const unsigned kNSides_
HGCalTriggerTools triggerTools_
HGCalClusteringImpl(const edm::ParameterSet &conf)
void resize(int bx, unsigned size)
void NNKernel(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &reshuffledTriggerCells, l1t::HGCalClusterBxCollection &clusters, const HGCalTriggerGeometryBase &triggerGeometry)
void clusterizeDR(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &triggerCellsPtrs, l1t::HGCalClusterBxCollection &clusters)
bool areTCneighbour(uint32_t detIDa, uint32_t detIDb, const HGCalTriggerGeometryBase &triggerGeometry)
static int position[264][3]
double scintillatorTriggerCellThreshold_
double siliconTriggerCellThreshold_
double phi() const final
momentum azimuthal angle
void setP4(const LorentzVector &p4) final
set 4-momentum
void push_back(int bx, T object)
const std::unordered_map< uint32_t, edm::Ptr< C > > & constituents() const