CMS 3D CMS Logo

HGCalMulticlusteringImpl.cc
Go to the documentation of this file.
1 
2 
6 
7 
9  dr_(conf.getParameter<double>("dR_multicluster")),
10  ptC3dThreshold_(conf.getParameter<double>("minPt_multicluster")),
11  multiclusterAlgoType_(conf.getParameter<string>("type_multicluster")),
12  distDbscan_(conf.getParameter<double>("dist_dbscan_multicluster")),
13  minNDbscan_(conf.getParameter<unsigned>("minN_dbscan_multicluster"))
14 {
15  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster dR for Near Neighbour search: " << dr_;
16  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster minimum transverse-momentum: " << ptC3dThreshold_;
17  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster DBSCAN Clustering distance: " << distDbscan_;
18  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster clustering min number of subclusters: " << minNDbscan_;
19  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster type of multiclustering algortihm: " << multiclusterAlgoType_;
20  id_.reset( HGCalTriggerClusterIdentificationFactory::get()->create("HGCalTriggerClusterIdentificationBDT") );
21  id_->initialize(conf.getParameter<edm::ParameterSet>("EGIdentification"));
22 }
23 
24 
26  const l1t::HGCalMulticluster & mclu,
27  double dR ) const
28 {
29  HGCalDetId cluDetId( clu.detId() );
30  HGCalDetId firstClusterDetId( mclu.detId() );
31 
32  if( cluDetId.zside() != firstClusterDetId.zside() ){
33  return false;
34  }
35  if( ( mclu.centreProj() - clu.centreProj() ).mag() < dR ){
36  return true;
37  }
38  return false;
39 
40 }
41 
42 
43 void HGCalMulticlusteringImpl::findNeighbor( const std::vector<std::pair<unsigned int,double>>& rankedList,
44  unsigned int searchInd,
45  const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
46  std::vector<unsigned int>& neighbors
47  ){
48 
49  if(clustersPtrs.size() <= searchInd || clustersPtrs.size() < rankedList.size()){
50  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
51  }
52 
53  for(unsigned int ind = searchInd+1; ind < rankedList.size() && fabs(rankedList.at(ind).second - rankedList.at(searchInd).second) < distDbscan_ ; ind++){
54 
55  if(clustersPtrs.size() <= rankedList.at(ind).first){
56  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
57 
58  } else if(((*(clustersPtrs[rankedList.at(ind).first])).centreProj() - (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj()).mag() < distDbscan_){
59  neighbors.push_back(ind);
60  }
61  }
62 
63  for(unsigned int ind = 0; ind < searchInd && fabs(rankedList.at(searchInd).second - rankedList.at(ind).second) < distDbscan_ ; ind++){
64 
65  if(clustersPtrs.size() <= rankedList.at(ind).first){
66  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
67 
68  } else if(((*(clustersPtrs[rankedList.at(ind).first])).centreProj() - (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj()).mag() < distDbscan_){
69  neighbors.push_back(ind);
70  }
71  }
72 }
73 
74 
76  l1t::HGCalMulticlusterBxCollection & multiclusters,
77  const HGCalTriggerGeometryBase & triggerGeometry)
78 {
79 
80  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
81 
82  int iclu = 0;
83  for(std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end(); ++clu, ++iclu){
84 
85  int imclu=0;
86  vector<int> tcPertinentMulticlusters;
87  for( const auto& mclu : multiclustersTmp ){
88  if( this->isPertinent(**clu, mclu, dr_) ){
89  tcPertinentMulticlusters.push_back(imclu);
90  }
91  ++imclu;
92  }
93  if( tcPertinentMulticlusters.empty() ){
94  multiclustersTmp.emplace_back( *clu );
95  }
96  else{
97  unsigned minDist = 1;
98  unsigned targetMulticlu = 0;
99  for( int imclu : tcPertinentMulticlusters ){
100  double d = ( multiclustersTmp.at(imclu).centreProj() - (*clu)->centreProj() ).mag() ;
101  if( d < minDist ){
102  minDist = d;
103  targetMulticlu = imclu;
104  }
105  }
106 
107  multiclustersTmp.at( targetMulticlu ).addConstituent( *clu );
108 
109  }
110  }
111 
112  /* making the collection of multiclusters */
113  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
114 
115 }
117  l1t::HGCalMulticlusterBxCollection & multiclusters,
118  const HGCalTriggerGeometryBase & triggerGeometry)
119 {
120 
121  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
122  l1t::HGCalMulticluster mcluTmp;
123  std::vector<bool> visited(clustersPtrs.size(),false);
124  std::vector<bool> merged (clustersPtrs.size(),false);
125  std::vector<std::pair<unsigned int,double>> rankedList;
126  rankedList.reserve(clustersPtrs.size());
127  std::vector<std::vector<unsigned int>> neighborList;
128  neighborList.reserve(clustersPtrs.size());
129 
130  int iclu = 0, imclu = 0, neighNo;
131  double dist = 0.;
132 
133  for(std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end(); ++clu, ++iclu){
134  dist = (*clu)->centreProj().mag()*HGCalDetId((*clu)->detId()).zside();
135  rankedList.push_back(std::make_pair(iclu,dist));
136  }
137  iclu = 0;
138  std::sort(rankedList.begin(), rankedList.end(), [](auto &left, auto &right) {
139  return left.second < right.second;
140  });
141 
142  for(const auto& cluRanked: rankedList){
143  std::vector<unsigned int> neighbors;
144 
145  if(!visited.at(iclu)){
146  visited.at(iclu) = true;
147  findNeighbor(rankedList, iclu, clustersPtrs, neighbors);
148  neighborList.push_back(std::move(neighbors));
149 
150  if(neighborList.at(iclu).size() >= minNDbscan_) {
151  multiclustersTmp.emplace_back( clustersPtrs[cluRanked.first] );
152  merged.at(iclu) = true;
153  /* dynamic range loop: range-based loop syntax cannot be employed */
154  for(unsigned int neighInd = 0; neighInd < neighborList.at(iclu).size(); neighInd++){
155  neighNo = neighborList.at(iclu).at(neighInd);
156  /* This condition also ensures merging of clusters visited by other clusters but not merged. */
157  if(!merged.at(neighNo) ){
158  merged.at(neighNo) = true;
159  multiclustersTmp.at(imclu).addConstituent( clustersPtrs[rankedList.at(neighNo).first] );
160 
161  if(!visited.at(neighNo)){
162  visited.at(neighNo) = true;
163  std::vector<unsigned int> secNeighbors;
164  findNeighbor(rankedList, neighNo,clustersPtrs, secNeighbors);
165 
166  if(secNeighbors.size() >= minNDbscan_){
167  neighborList.at(iclu).insert(neighborList.at(iclu).end(), secNeighbors.begin(), secNeighbors.end());
168  }
169  }
170  }
171  }
172  imclu++;
173  }
174  }
175  else neighborList.push_back(std::move(neighbors));
176  iclu++;
177  }
178  /* making the collection of multiclusters */
179  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
180 }
181 
182 
183 void
185 finalizeClusters(std::vector<l1t::HGCalMulticluster>& multiclusters_in,
186  l1t::HGCalMulticlusterBxCollection& multiclusters_out,
187  const HGCalTriggerGeometryBase& triggerGeometry) {
188  for(auto& multicluster : multiclusters_in) {
189  // compute the eta, phi from its barycenter
190  // + pT as scalar sum of pT of constituents
191  double sumPt=0.;
192  const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalCluster>>& clusters = multicluster.constituents();
193  for(const auto& id_cluster : clusters) sumPt += id_cluster.second->pt();
194 
195  math::PtEtaPhiMLorentzVector multiclusterP4( sumPt,
196  multicluster.centre().eta(),
197  multicluster.centre().phi(),
198  0. );
199  multicluster.setP4( multiclusterP4 );
200 
201  if( multicluster.pt() > ptC3dThreshold_ ){
202  //compute shower shapes
203  multicluster.showerLength(shape_.showerLength(multicluster));
204  multicluster.coreShowerLength(shape_.coreShowerLength(multicluster, triggerGeometry));
205  multicluster.firstLayer(shape_.firstLayer(multicluster));
206  multicluster.maxLayer(shape_.maxLayer(multicluster));
207  multicluster.sigmaEtaEtaTot(shape_.sigmaEtaEtaTot(multicluster));
208  multicluster.sigmaEtaEtaMax(shape_.sigmaEtaEtaMax(multicluster));
209  multicluster.sigmaPhiPhiTot(shape_.sigmaPhiPhiTot(multicluster));
210  multicluster.sigmaPhiPhiMax(shape_.sigmaPhiPhiMax(multicluster));
211  multicluster.sigmaZZ(shape_.sigmaZZ(multicluster));
212  multicluster.sigmaRRTot(shape_.sigmaRRTot(multicluster));
213  multicluster.sigmaRRMax(shape_.sigmaRRMax(multicluster));
214  multicluster.sigmaRRMean(shape_.sigmaRRMean(multicluster));
215  multicluster.eMax(shape_.eMax(multicluster));
216  // fill quality flag
217  multicluster.setHwQual(id_->decision(multicluster));
218 
219  multiclusters_out.push_back( 0, multicluster);
220  }
221  }
222 }
float sigmaRRMax(const l1t::HGCalMulticluster &c3d) const
T getParameter(std::string const &) const
HGCalMulticlusteringImpl(const edm::ParameterSet &conf)
def create(alignables, pedeDump, additionalData, outputFile, config)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
int coreShowerLength(const l1t::HGCalMulticluster &c3d, const HGCalTriggerGeometryBase &triggerGeometry) const
float sigmaRRTot(const l1t::HGCalMulticluster &c3d) const
float sigmaPhiPhiTot(const l1t::HGCalMulticluster &c3d) const
int firstLayer(const l1t::HGCalMulticluster &c3d) const
int zside(DetId const &)
const GlobalPoint & centreProj() const
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
float sigmaRRMean(const l1t::HGCalMulticluster &c3d, float radius=5.) const
float sigmaEtaEtaMax(const l1t::HGCalMulticluster &c3d) const
std::unique_ptr< HGCalTriggerClusterIdentificationBase > id_
void findNeighbor(const std::vector< std::pair< unsigned int, double >> &rankedList, unsigned int searchInd, const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, std::vector< unsigned int > &neigbors)
uint32_t detId() const
bool isPertinent(const l1t::HGCalCluster &clu, const l1t::HGCalMulticluster &mclu, double dR) const
void clusterizeDR(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)
void finalizeClusters(std::vector< l1t::HGCalMulticluster > &, l1t::HGCalMulticlusterBxCollection &, const HGCalTriggerGeometryBase &)
int showerLength(const l1t::HGCalMulticluster &c3d) const
float sigmaZZ(const l1t::HGCalMulticluster &c3d) const
float sigmaPhiPhiMax(const l1t::HGCalMulticluster &c3d) const
int maxLayer(const l1t::HGCalMulticluster &c3d) const
float eMax(const l1t::HGCalMulticluster &c3d) const
float sigmaEtaEtaTot(const l1t::HGCalMulticluster &c3d) const
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55
void push_back(int bx, T object)
void clusterizeDBSCAN(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)