Skip to content

Commit

Permalink
Merge pull request cms-sw#100 from mastrolorenzo/clustering2D_NN_910pre1
Browse files Browse the repository at this point in the history
Nearest neighbor 2D clustering
  • Loading branch information
jbsauvan authored Apr 10, 2017
2 parents 6f6d206 + 047ea1d commit 76785bc
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 29 deletions.
16 changes: 10 additions & 6 deletions DataFormats/L1THGCal/interface/HGCalCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,27 @@ namespace l1t {
edm::PtrVector<l1t::HGCalTriggerCell>::const_iterator triggercells_end() const {
return triggercells_.end();
}
const edm::Ptr<l1t::HGCalTriggerCell> seedTriggerCell() const {
return *triggercells_begin();
}

unsigned triggercellsSize() const { return triggercells_.size(); }

/* helpers */
void addTriggerCell( const edm::Ptr<l1t::HGCalTriggerCell> &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_; }

double distance( const l1t::HGCalTriggerCell &tc ) const; /* return distance in 'cm' */

const GlobalPoint& centre() const { return centre_; }
Expand All @@ -84,7 +85,7 @@ namespace l1t {

/* seed detId */
uint32_t seedDetId_;

/* Centre weighted with energy */
GlobalPoint centre_;

Expand All @@ -95,6 +96,9 @@ namespace l1t {
double mipPt_;
double seedMipPt_;

/* Flag dedicated to merging procedure */
bool isComplete_;

/* HGC specific information */
uint32_t module_;

Expand Down
2 changes: 2 additions & 0 deletions DataFormats/L1THGCal/src/HGCalCluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void HGCalCluster::addTriggerCell( const edm::Ptr<l1t::HGCalTriggerCell > &tc )
this->setP4( p4 );

triggercells_.push_back( tc );

}


Expand Down Expand Up @@ -105,6 +106,7 @@ int32_t HGCalCluster::zside() const
}



bool HGCalCluster::operator<(const HGCalCluster& cl) const
{

Expand Down
26 changes: 24 additions & 2 deletions L1Trigger/L1THGCal/interface/be_algorithms/HGCalClusteringImpl.h
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
#ifndef __L1Trigger_L1THGCal_HGCalClusteringImpl_h__
#define __L1Trigger_L1THGCal_HGCalClusteringImpl_h__

#include <array>
#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{

public:

HGCalClusteringImpl( const edm::ParameterSet & conf);


/* dR-algorithms */
bool isPertinent( const l1t::HGCalTriggerCell & tc,
const l1t::HGCalCluster & clu,
double distXY) const;

void clusterize( const edm::PtrVector<l1t::HGCalTriggerCell> & triggerCellsPtrs,
void clusterizeDR( const edm::PtrVector<l1t::HGCalTriggerCell> & triggerCellsPtrs,
l1t::HGCalClusterBxCollection & clusters
);

/* NN-algorithms */
void mergeClusters( l1t::HGCalCluster & main_cluster,
const l1t::HGCalCluster & secondary_cluster ) const;

void NNKernel( const std::vector<edm::Ptr<l1t::HGCalTriggerCell>> &reshuffledTriggerCells,
l1t::HGCalClusterBxCollection & clusters,
const HGCalTriggerGeometryBase & triggerGeometry
);

void clusterizeNN( const edm::PtrVector<l1t::HGCalTriggerCell> & triggerCellsPtrs,
l1t::HGCalClusterBxCollection & clusters,
const HGCalTriggerGeometryBase & triggerGeometry
);


private:

double seedThreshold_;
double triggerCellThreshold_;
double dr_;
std::string clusteringAlgorithmType_;
void triggerCellReshuffling( const edm::PtrVector<l1t::HGCalTriggerCell> & triggerCellsPtrs,
std::array<std::array<std::vector<edm::Ptr<l1t::HGCalTriggerCell>>,40>,2> & reshuffledTriggerCells );


};

Expand Down
27 changes: 20 additions & 7 deletions L1Trigger/L1THGCal/plugins/be_algorithms/HGCClusterAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,7 +32,8 @@ class HGCClusterAlgo : public Algorithm<FECODEC>
HGCalHESiliconSensitive_( conf.getParameter<std::string>("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<std::string>("clusterType"))
{

}
Expand Down Expand Up @@ -59,6 +61,7 @@ class HGCClusterAlgo : public Algorithm<FECODEC>
cluster_product_.reset( new l1t::HGCalClusterBxCollection );
multicluster_product_.reset( new l1t::HGCalMulticlusterBxCollection );
}


private:

Expand All @@ -74,12 +77,15 @@ class HGCClusterAlgo : public Algorithm<FECODEC>
/* handles to the detector topologies */
edm::ESHandle<HGCalTopology> hgceeTopoHandle_;
edm::ESHandle<HGCalTopology> hgchefTopoHandle_;

edm::ESHandle<HGCalTriggerGeometryBase> triggerGeometry_;

/* algorithms instances */
HGCalTriggerCellCalibration calibration_;
HGCalClusteringImpl clustering_;
HGCalMulticlusteringImpl multiclustering_;

/* algorithm type */
std::string clusteringAlgorithmType_;
};


Expand All @@ -91,6 +97,7 @@ void HGCClusterAlgo<FECODEC,DATA>::run(const l1t::HGCFETriggerDigiCollection & c

es.get<IdealGeometryRecord>().get( HGCalEESensitive_, hgceeTopoHandle_ );
es.get<IdealGeometryRecord>().get( HGCalHESiliconSensitive_, hgchefTopoHandle_ );
es.get<IdealGeometryRecord>().get("", triggerGeometry_);

for( const auto& digi : coll ){

Expand Down Expand Up @@ -123,7 +130,8 @@ void HGCClusterAlgo<FECODEC,DATA>::run(const l1t::HGCFETriggerDigiCollection & c
l1t::HGCalTriggerCell calibratedtriggercell( triggercell );
calibration_.calibrateInGeV( calibratedtriggercell, cellThickness );
trgcell_product_->push_back( 0, calibratedtriggercell );
}

}

}

Expand All @@ -143,9 +151,14 @@ void HGCClusterAlgo<FECODEC,DATA>::run(const l1t::HGCFETriggerDigiCollection & c
edm::Ptr<l1t::HGCalTriggerCell> ptr(triggerCellsHandle,i);
triggerCellsPtrs.push_back(ptr);
}

/* call to clustering */
clustering_.clusterize( triggerCellsPtrs, *cluster_product_);

/* call to C2d clustering */
if(clusteringAlgorithmType_=="dRC2d"){
clustering_.clusterizeDR( triggerCellsPtrs, *cluster_product_);
}
else if(clusteringAlgorithmType_=="NNC2d"){
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
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
clusterType = cms.string('NNC2d') # clustering type: dRC2d--> Geometric-dR clustering; NNC2d-->Nearest Neighbors clustering
)

C3d_parValues = cms.PSet( dR_multicluster = cms.double(0.01) )
Expand Down
Loading

0 comments on commit 76785bc

Please sign in to comment.