Skip to content

Commit a8061f4

Browse files
authored
Merge pull request #15295 from fwyzard/backport_13448+14344_80x
backport of #13448: small performance improvement in Tracking, and #14344: avoid redundant computations in StripCPE
2 parents b09c233 + ba6640b commit a8061f4

File tree

20 files changed

+368
-262
lines changed

20 files changed

+368
-262
lines changed

DataFormats/Common/interface/DetSetNew.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ namespace edmNew {
9696
return edm::Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>( handle.id(), ci, ci - &(container().front()) );
9797
}
9898

99+
unsigned int makeKeyOf(const_iterator ci) const {
100+
return ci - &(container().front());
101+
}
99102

100103
private:
101104

DataFormats/SiStripCluster/interface/SiStripClusterTools.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,31 @@ namespace siStripClusterTools {
2222
else return 1.f/0.027f;
2323
}
2424

25+
2526
template<typename Iter>
26-
float chargePerCM(DetId detid, Iter a, Iter b) {
27+
inline float chargePerCM(DetId detid, Iter a, Iter b) {
2728
return float(std::accumulate(a,b,int(0)))*sensorThicknessInverse(detid);
2829
}
2930

3031
template<typename Clus>
31-
float chargePerCM(DetId detid, Clus const & cl) {
32+
inline float chargePerCM(DetId detid, Clus const & cl) {
3233
return cl.charge()*sensorThicknessInverse(detid);
3334
}
3435

3536

3637
template<typename Clus>
37-
float chargePerCM(DetId detid, Clus const & cl, LocalTrajectoryParameters const & tp) {
38+
inline float chargePerCM(DetId detid, Clus const & cl, LocalTrajectoryParameters const & tp) {
3839
return chargePerCM(detid,cl)*tp.absdz();
3940
}
4041

4142
template<typename Clus>
42-
float chargePerCM(DetId detid, Clus const & cl, const LocalVector & ldir) {
43+
inline float chargePerCM(Clus const & cl, LocalTrajectoryParameters const & tp, float invThick) {
44+
return cl.charge()*invThick*tp.absdz();
45+
}
46+
47+
48+
template<typename Clus>
49+
inline float chargePerCM(DetId detid, Clus const & cl, const LocalVector & ldir) {
4350
return chargePerCM(detid,cl)*std::abs(ldir.z())/ldir.mag();
4451
}
4552

DataFormats/SiStripDetId/interface/SiStripDetId.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,7 @@ class SiStripDetId : public DetId {
112112
// ---------- inline methods ----------
113113

114114
SiStripDetId::SubDetector SiStripDetId::subDetector() const {
115-
SiStripDetId::SubDetector result;
116-
if ( det() == DetId::Tracker) {
117-
if ( subdetId() == static_cast<int>(SiStripDetId::TEC) ) {
118-
result = SiStripDetId::TEC;
119-
} else if ( subdetId() == static_cast<int>(SiStripDetId::TID) ) {
120-
result = SiStripDetId::TID;
121-
} else if ( subdetId() == static_cast<int>(SiStripDetId::TOB) ) {
122-
result = SiStripDetId::TOB;
123-
} else if ( subdetId() == static_cast<int>(SiStripDetId::TIB) ) {
124-
result = SiStripDetId::TIB;
125-
} else {
126-
result = SiStripDetId::UNKNOWN;
127-
}
128-
} else {
129-
result = SiStripDetId::UNKNOWN;
130-
}
131-
return result;
115+
return static_cast<SiStripDetId::SubDetector>(subdetId());
132116
}
133117

134118
SiStripDetId::ModuleGeometry SiStripDetId::moduleGeometry() const {

RecoLocalTracker/ClusterParameterEstimator/interface/StripClusterParameterEstimator.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
1414
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
1515

16+
#include "CommonTools/Utils/interface/DynArray.h"
1617
#include "FWCore/Utilities/interface/Exception.h"
1718

1819

@@ -25,9 +26,15 @@
2526
class StripClusterParameterEstimator
2627
{
2728
public:
28-
typedef std::pair<LocalPoint,LocalError> LocalValues;
29+
using LocalValues = std::pair<LocalPoint,LocalError>;
30+
using ALocalValues = DynArray<LocalValues>;
31+
using AClusters = DynArray<SiStripCluster const *>;
2932
typedef std::vector<LocalValues> VLocalValues;
3033

34+
virtual void localParameters(AClusters const & clusters, ALocalValues & retValues, const GeomDetUnit& gd, const LocalTrajectoryParameters & ltp) const {
35+
}
36+
37+
3138
virtual LocalValues localParameters( const SiStripCluster&,const GeomDetUnit&) const {
3239
return std::make_pair(LocalPoint(), LocalError());
3340
}

RecoLocalTracker/SiPixelRecHits/interface/SiPixelTemplateReco.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,36 @@
6161
#define N2D 500
6262

6363
#include <vector>
64-
#include "boost/multi_array.hpp"
6564

6665

67-
namespace SiPixelTemplateReco
68-
{
69-
70-
typedef boost::multi_array<float, 2> array_2d;
66+
namespace SiPixelTemplateReco {
7167

72-
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, array_2d& cluster,
73-
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
68+
struct ClusMatrix {
69+
float & operator()(int x, int y) { return matrix[mcol*x+y];}
70+
float operator()(int x, int y) const { return matrix[mcol*x+y];}
71+
float * matrix;
72+
bool const * xdouble;
73+
bool const * ydouble;
74+
int mrow, mcol;
75+
};
76+
77+
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, ClusMatrix & cluster,
7478
SiPixelTemplate& templ,
75-
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed, bool deadpix, std::vector<std::pair<int, int> >& zeropix,
79+
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed, bool deadpix,
80+
std::vector<std::pair<int, int> >& zeropix,
7681
float& probQ);
7782

78-
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, array_2d& cluster,
79-
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
83+
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, ClusMatrix & cluster,
8084
SiPixelTemplate& templ,
8185
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed,
8286
float& probQ);
8387

84-
int PixelTempReco2D(int id, float cotalpha, float cotbeta, array_2d& cluster,
85-
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
88+
int PixelTempReco2D(int id, float cotalpha, float cotbeta, ClusMatrix & cluster,
8689
SiPixelTemplate& templ,
8790
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed,
8891
float& probQ);
8992

90-
int PixelTempReco2D(int id, float cotalpha, float cotbeta, array_2d& cluster,
91-
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
93+
int PixelTempReco2D(int id, float cotalpha, float cotbeta, ClusMatrix & cluster,
9294
SiPixelTemplate& templ,
9395
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed);
9496
}

RecoLocalTracker/SiPixelRecHits/src/PixelCPETemplateReco.cc

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
137137

138138
SiPixelTemplate templ(thePixelTemp_);
139139

140-
// Make from cluster (a SiPixelCluster) a boost multi_array_2d called
141-
// clust_array_2d.
142-
boost::multi_array<float, 2> clust_array_2d(boost::extents[cluster_matrix_size_x][cluster_matrix_size_y]);
143-
144140
// Preparing to retrieve ADC counts from the SiPixeltheClusterParam.theCluster-> In the cluster,
145141
// we have the following:
146142
// int minPixelRow(); // Minimum pixel index in the x direction (low edge).
@@ -176,37 +172,48 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
176172
lp = theDetParam.theTopol->localPosition( MeasurementPoint(tmp_x, tmp_y) );
177173
}
178174

179-
// Copy clust's pixels (calibrated in electrons) into clust_array_2d;
180-
for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
175+
// first compute matrix size
176+
int mrow=0, mcol=0;
177+
for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
178+
{
179+
auto pix = theClusterParam.theCluster->pixel(i);
180+
int irow = int(pix.x);
181+
int icol = int(pix.y);
182+
mrow = std::max(mrow,irow);
183+
mcol = std::max(mcol,icol);
184+
}
185+
mrow -= row_offset; mrow+=1; mrow = std::min(mrow,cluster_matrix_size_x);
186+
mcol -= col_offset; mcol+=1; mcol = std::min(mcol,cluster_matrix_size_y);
187+
assert(mrow>0); assert(mcol>0);
188+
189+
float clustMatrix[mrow][mcol];
190+
memset(clustMatrix,0,sizeof(float)*mrow*mcol);
191+
192+
// Copy clust's pixels (calibrated in electrons) into clusMatrix;
193+
for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
181194
{
182195
auto pix = theClusterParam.theCluster->pixel(i);
183-
// *pixIter dereferences to Pixel struct, with public vars x, y, adc (all float)
184-
// 02/13/2008 [email protected]: type of x, y and adc has been changed to unsigned char, unsigned short, unsigned short
185-
// in DataFormats/SiPixelCluster/interface/SiPixeltheClusterParam.theCluster->h so the type cast to int is redundant. Leave it there, it
186-
// won't hurt.
187-
int irow = int(pix.x) - row_offset; // &&& do we need +0.5 ???
188-
int icol = int(pix.y) - col_offset; // &&& do we need +0.5 ???
196+
int irow = int(pix.x) - row_offset;
197+
int icol = int(pix.y) - col_offset;
189198

190-
// Gavril : what do we do here if the row/column is larger than cluster_matrix_size_x/cluster_matrix_size_y = 7/21 ?
199+
// Gavril : what do we do here if the row/column is larger than cluster_matrix_size_x/cluster_matrix_size_y ?
191200
// Ignore them for the moment...
192-
if ( irow<cluster_matrix_size_x && icol<cluster_matrix_size_y )
193-
// 02/13/2008 [email protected] typecast pixIter->adc to float
194-
clust_array_2d[irow][icol] = (float)pix.adc;
201+
if ( (irow<mrow) & (icol<mcol) ) clustMatrix[irow][icol] = float(pix.adc);
202+
195203
}
196204

205+
197206
// Make and fill the bool arrays flagging double pixels
198-
std::vector<bool> ydouble(cluster_matrix_size_y), xdouble(cluster_matrix_size_x);
207+
bool xdouble[mrow], ydouble[mcol];
199208
// x directions (shorter), rows
200-
for (int irow = 0; irow < cluster_matrix_size_x; ++irow)
201-
{
209+
for (int irow = 0; irow < mrow; ++irow)
202210
xdouble[irow] = theDetParam.theRecTopol->isItBigPixelInX( irow+row_offset );
203-
}
204-
205-
// y directions (longer), columns
206-
for (int icol = 0; icol < cluster_matrix_size_y; ++icol)
207-
{
211+
212+
// y directions (longer), columns
213+
for (int icol = 0; icol < mcol; ++icol)
208214
ydouble[icol] = theDetParam.theRecTopol->isItBigPixelInY( icol+col_offset );
209-
}
215+
216+
SiPixelTemplateReco::ClusMatrix clusterPayload{&clustMatrix[0][0], xdouble, ydouble, mrow,mcol};
210217

211218
// Output:
212219
float nonsense = -99999.9f; // nonsense init value
@@ -231,7 +238,7 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
231238
theClusterParam.ierr =
232239
PixelTempReco2D( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
233240
locBz,
234-
clust_array_2d, ydouble, xdouble,
241+
clusterPayload,
235242
templ,
236243
theClusterParam.templYrec_, theClusterParam.templSigmaY_, theClusterParam.templProbY_,
237244
theClusterParam.templXrec_, theClusterParam.templSigmaX_, theClusterParam.templProbX_,
@@ -286,14 +293,15 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
286293
// templQbin_ );
287294

288295

289-
float dchisq;
290-
float templProbQ_;
291296
std::vector< SiPixelTemplateStore2D > thePixelTemp2D_;
292297
SiPixelTemplate2D::pushfile(ID, thePixelTemp2D_);
293298
SiPixelTemplate2D templ2D_(thePixelTemp2D_);
294299

295-
theClusterParam.ierr =
296-
SiPixelTemplateSplit::PixelTempSplit( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
300+
theClusterParam.ierr = -123;
301+
/*
302+
float dchisq;
303+
float templProbQ_;
304+
SiPixelTemplateSplit::PixelTempSplit( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
297305
clust_array_2d,
298306
ydouble, xdouble,
299307
templ,
@@ -305,7 +313,7 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
305313
dchisq,
306314
templ2D_ );
307315
308-
316+
*/
309317
if ( theClusterParam.ierr != 0 )
310318
{
311319
LogDebug("PixelCPETemplateReco::localPosition") <<

0 commit comments

Comments
 (0)