Skip to content

Commit 8b318cc

Browse files
committed
Make the DetSetVector<CTPPSPixelRecHit> more robust
The sorting of the CTPPSPixelRecHit elements in the DetSetvector is improved in two ways: - using mag2() instead of mag() avoids the square root computation; - caching the value instead of recomputing it every time makes the sorting more stable. Other minor clean ups.
1 parent b048d1e commit 8b318cc

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

DataFormats/CTPPSReco/interface/CTPPSPixelRecHit.h

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef DataFormats_CTPPSReco_interface_CTPPSPixelRecHit_h
2+
#define DataFormats_CTPPSReco_interface_CTPPSPixelRecHit_h
3+
14
/*
25
*
36
* This is a part of CTPPS offline software.
@@ -6,11 +9,11 @@
69
*
710
*/
811

9-
#ifndef DataFormats_CTPPSReco_CTPPSPixelRecHit_H
10-
#define DataFormats_CTPPSReco_CTPPSPixelRecHit_H
12+
#include <cassert>
1113

1214
#include "DataFormats/GeometrySurface/interface/LocalError.h"
1315
#include "DataFormats/GeometryVector/interface/LocalPoint.h"
16+
#include "FWCore/Utilities/interface/isFinite.h"
1417

1518
// Reconstructed hits in CTPPS Pixel detector
1619

@@ -37,19 +40,21 @@ class CTPPSPixelRecHit {
3740
clusterSizeRow_(rowsize),
3841
clusterSizeCol_(colsize) {}
3942

40-
inline LocalPoint point() const { return thePoint_; }
41-
inline LocalError error() const { return theError_; }
43+
LocalPoint point() const { return thePoint_; }
44+
LocalError error() const { return theError_; }
45+
46+
bool isOnEdge() const { return isOnEdge_; }
47+
bool hasBadPixels() const { return hasBadPixels_; }
48+
bool spanTwoRocs() const { return spanTwoRocs_; }
4249

43-
inline bool isOnEdge() const { return isOnEdge_; }
44-
inline bool hasBadPixels() const { return hasBadPixels_; }
45-
inline bool spanTwoRocs() const { return spanTwoRocs_; }
50+
unsigned int minPixelRow() const { return minPixelRow_; }
51+
unsigned int minPixelCol() const { return minPixelCol_; }
4652

47-
inline unsigned int minPixelRow() const { return minPixelRow_; }
48-
inline unsigned int minPixelCol() const { return minPixelCol_; }
53+
unsigned int clusterSize() const { return clusterSize_; }
54+
unsigned int clusterSizeRow() const { return clusterSizeRow_; }
55+
unsigned int clusterSizeCol() const { return clusterSizeCol_; }
4956

50-
inline unsigned int clusterSize() const { return clusterSize_; }
51-
inline unsigned int clusterSizeRow() const { return clusterSizeRow_; }
52-
inline unsigned int clusterSizeCol() const { return clusterSizeCol_; }
57+
float sort_key() const { return thePoint_.mag2(); }
5358

5459
private:
5560
LocalPoint thePoint_;
@@ -67,6 +72,12 @@ class CTPPSPixelRecHit {
6772
unsigned int clusterSizeCol_;
6873
};
6974

70-
inline bool operator<(CTPPSPixelRecHit& a, CTPPSPixelRecHit& b) { return (a.point().mag() < b.point().mag()); };
75+
inline bool operator<(CTPPSPixelRecHit const& a, CTPPSPixelRecHit const& b) {
76+
float a_key = a.sort_key();
77+
float b_key = b.sort_key();
78+
assert(edm::isFinite(a_key));
79+
assert(edm::isFinite(b_key));
80+
return a_key < b_key;
81+
}
7182

72-
#endif
83+
#endif // DataFormats_CTPPSReco_interface_CTPPSPixelRecHit_h

0 commit comments

Comments
 (0)