Skip to content

Commit

Permalink
Merge pull request #15295 from fwyzard/backport_13448+14344_80x
Browse files Browse the repository at this point in the history
backport of #13448: small performance improvement in Tracking, and #14344: avoid redundant computations in StripCPE
  • Loading branch information
cmsbuild committed Aug 26, 2016
2 parents b09c233 + ba6640b commit a8061f4
Show file tree
Hide file tree
Showing 20 changed files with 368 additions and 262 deletions.
3 changes: 3 additions & 0 deletions DataFormats/Common/interface/DetSetNew.h
Expand Up @@ -96,6 +96,9 @@ namespace edmNew {
return edm::Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>( handle.id(), ci, ci - &(container().front()) );
}

unsigned int makeKeyOf(const_iterator ci) const {
return ci - &(container().front());
}

private:

Expand Down
15 changes: 11 additions & 4 deletions DataFormats/SiStripCluster/interface/SiStripClusterTools.h
Expand Up @@ -22,24 +22,31 @@ namespace siStripClusterTools {
else return 1.f/0.027f;
}


template<typename Iter>
float chargePerCM(DetId detid, Iter a, Iter b) {
inline float chargePerCM(DetId detid, Iter a, Iter b) {
return float(std::accumulate(a,b,int(0)))*sensorThicknessInverse(detid);
}

template<typename Clus>
float chargePerCM(DetId detid, Clus const & cl) {
inline float chargePerCM(DetId detid, Clus const & cl) {
return cl.charge()*sensorThicknessInverse(detid);
}


template<typename Clus>
float chargePerCM(DetId detid, Clus const & cl, LocalTrajectoryParameters const & tp) {
inline float chargePerCM(DetId detid, Clus const & cl, LocalTrajectoryParameters const & tp) {
return chargePerCM(detid,cl)*tp.absdz();
}

template<typename Clus>
float chargePerCM(DetId detid, Clus const & cl, const LocalVector & ldir) {
inline float chargePerCM(Clus const & cl, LocalTrajectoryParameters const & tp, float invThick) {
return cl.charge()*invThick*tp.absdz();
}


template<typename Clus>
inline float chargePerCM(DetId detid, Clus const & cl, const LocalVector & ldir) {
return chargePerCM(detid,cl)*std::abs(ldir.z())/ldir.mag();
}

Expand Down
18 changes: 1 addition & 17 deletions DataFormats/SiStripDetId/interface/SiStripDetId.h
Expand Up @@ -112,23 +112,7 @@ class SiStripDetId : public DetId {
// ---------- inline methods ----------

SiStripDetId::SubDetector SiStripDetId::subDetector() const {
SiStripDetId::SubDetector result;
if ( det() == DetId::Tracker) {
if ( subdetId() == static_cast<int>(SiStripDetId::TEC) ) {
result = SiStripDetId::TEC;
} else if ( subdetId() == static_cast<int>(SiStripDetId::TID) ) {
result = SiStripDetId::TID;
} else if ( subdetId() == static_cast<int>(SiStripDetId::TOB) ) {
result = SiStripDetId::TOB;
} else if ( subdetId() == static_cast<int>(SiStripDetId::TIB) ) {
result = SiStripDetId::TIB;
} else {
result = SiStripDetId::UNKNOWN;
}
} else {
result = SiStripDetId::UNKNOWN;
}
return result;
return static_cast<SiStripDetId::SubDetector>(subdetId());
}

SiStripDetId::ModuleGeometry SiStripDetId::moduleGeometry() const {
Expand Down
Expand Up @@ -13,6 +13,7 @@
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"

#include "CommonTools/Utils/interface/DynArray.h"
#include "FWCore/Utilities/interface/Exception.h"


Expand All @@ -25,9 +26,15 @@
class StripClusterParameterEstimator
{
public:
typedef std::pair<LocalPoint,LocalError> LocalValues;
using LocalValues = std::pair<LocalPoint,LocalError>;
using ALocalValues = DynArray<LocalValues>;
using AClusters = DynArray<SiStripCluster const *>;
typedef std::vector<LocalValues> VLocalValues;

virtual void localParameters(AClusters const & clusters, ALocalValues & retValues, const GeomDetUnit& gd, const LocalTrajectoryParameters & ltp) const {
}


virtual LocalValues localParameters( const SiStripCluster&,const GeomDetUnit&) const {
return std::make_pair(LocalPoint(), LocalError());
}
Expand Down
30 changes: 16 additions & 14 deletions RecoLocalTracker/SiPixelRecHits/interface/SiPixelTemplateReco.h
Expand Up @@ -61,34 +61,36 @@
#define N2D 500

#include <vector>
#include "boost/multi_array.hpp"


namespace SiPixelTemplateReco
{

typedef boost::multi_array<float, 2> array_2d;
namespace SiPixelTemplateReco {

int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, array_2d& cluster,
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
struct ClusMatrix {
float & operator()(int x, int y) { return matrix[mcol*x+y];}
float operator()(int x, int y) const { return matrix[mcol*x+y];}
float * matrix;
bool const * xdouble;
bool const * ydouble;
int mrow, mcol;
};

int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, ClusMatrix & cluster,
SiPixelTemplate& templ,
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,
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,
float& probQ);

int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, array_2d& cluster,
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
int PixelTempReco2D(int id, float cotalpha, float cotbeta, float locBz, ClusMatrix & cluster,
SiPixelTemplate& templ,
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed,
float& probQ);

int PixelTempReco2D(int id, float cotalpha, float cotbeta, array_2d& cluster,
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
int PixelTempReco2D(int id, float cotalpha, float cotbeta, ClusMatrix & cluster,
SiPixelTemplate& templ,
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed,
float& probQ);

int PixelTempReco2D(int id, float cotalpha, float cotbeta, array_2d& cluster,
std::vector<bool>& ydouble, std::vector<bool>& xdouble,
int PixelTempReco2D(int id, float cotalpha, float cotbeta, ClusMatrix & cluster,
SiPixelTemplate& templ,
float& yrec, float& sigmay, float& proby, float& xrec, float& sigmax, float& probx, int& qbin, int speed);
}
Expand Down
70 changes: 39 additions & 31 deletions RecoLocalTracker/SiPixelRecHits/src/PixelCPETemplateReco.cc
Expand Up @@ -137,10 +137,6 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &

SiPixelTemplate templ(thePixelTemp_);

// Make from cluster (a SiPixelCluster) a boost multi_array_2d called
// clust_array_2d.
boost::multi_array<float, 2> clust_array_2d(boost::extents[cluster_matrix_size_x][cluster_matrix_size_y]);

// Preparing to retrieve ADC counts from the SiPixeltheClusterParam.theCluster-> In the cluster,
// we have the following:
// int minPixelRow(); // Minimum pixel index in the x direction (low edge).
Expand Down Expand Up @@ -176,37 +172,48 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
lp = theDetParam.theTopol->localPosition( MeasurementPoint(tmp_x, tmp_y) );
}

// Copy clust's pixels (calibrated in electrons) into clust_array_2d;
for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
// first compute matrix size
int mrow=0, mcol=0;
for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
{
auto pix = theClusterParam.theCluster->pixel(i);
int irow = int(pix.x);
int icol = int(pix.y);
mrow = std::max(mrow,irow);
mcol = std::max(mcol,icol);
}
mrow -= row_offset; mrow+=1; mrow = std::min(mrow,cluster_matrix_size_x);
mcol -= col_offset; mcol+=1; mcol = std::min(mcol,cluster_matrix_size_y);
assert(mrow>0); assert(mcol>0);

float clustMatrix[mrow][mcol];
memset(clustMatrix,0,sizeof(float)*mrow*mcol);

// Copy clust's pixels (calibrated in electrons) into clusMatrix;
for (int i=0 ; i!=theClusterParam.theCluster->size(); ++i )
{
auto pix = theClusterParam.theCluster->pixel(i);
// *pixIter dereferences to Pixel struct, with public vars x, y, adc (all float)
// 02/13/2008 ggiurgiu@fnal.gov: type of x, y and adc has been changed to unsigned char, unsigned short, unsigned short
// in DataFormats/SiPixelCluster/interface/SiPixeltheClusterParam.theCluster->h so the type cast to int is redundant. Leave it there, it
// won't hurt.
int irow = int(pix.x) - row_offset; // &&& do we need +0.5 ???
int icol = int(pix.y) - col_offset; // &&& do we need +0.5 ???
int irow = int(pix.x) - row_offset;
int icol = int(pix.y) - col_offset;

// Gavril : what do we do here if the row/column is larger than cluster_matrix_size_x/cluster_matrix_size_y = 7/21 ?
// Gavril : what do we do here if the row/column is larger than cluster_matrix_size_x/cluster_matrix_size_y ?
// Ignore them for the moment...
if ( irow<cluster_matrix_size_x && icol<cluster_matrix_size_y )
// 02/13/2008 ggiurgiu@fnal.gov typecast pixIter->adc to float
clust_array_2d[irow][icol] = (float)pix.adc;
if ( (irow<mrow) & (icol<mcol) ) clustMatrix[irow][icol] = float(pix.adc);

}


// Make and fill the bool arrays flagging double pixels
std::vector<bool> ydouble(cluster_matrix_size_y), xdouble(cluster_matrix_size_x);
bool xdouble[mrow], ydouble[mcol];
// x directions (shorter), rows
for (int irow = 0; irow < cluster_matrix_size_x; ++irow)
{
for (int irow = 0; irow < mrow; ++irow)
xdouble[irow] = theDetParam.theRecTopol->isItBigPixelInX( irow+row_offset );
}

// y directions (longer), columns
for (int icol = 0; icol < cluster_matrix_size_y; ++icol)
{

// y directions (longer), columns
for (int icol = 0; icol < mcol; ++icol)
ydouble[icol] = theDetParam.theRecTopol->isItBigPixelInY( icol+col_offset );
}

SiPixelTemplateReco::ClusMatrix clusterPayload{&clustMatrix[0][0], xdouble, ydouble, mrow,mcol};

// Output:
float nonsense = -99999.9f; // nonsense init value
Expand All @@ -231,7 +238,7 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
theClusterParam.ierr =
PixelTempReco2D( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
locBz,
clust_array_2d, ydouble, xdouble,
clusterPayload,
templ,
theClusterParam.templYrec_, theClusterParam.templSigmaY_, theClusterParam.templProbY_,
theClusterParam.templXrec_, theClusterParam.templSigmaX_, theClusterParam.templProbX_,
Expand Down Expand Up @@ -286,14 +293,15 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
// templQbin_ );


float dchisq;
float templProbQ_;
std::vector< SiPixelTemplateStore2D > thePixelTemp2D_;
SiPixelTemplate2D::pushfile(ID, thePixelTemp2D_);
SiPixelTemplate2D templ2D_(thePixelTemp2D_);

theClusterParam.ierr =
SiPixelTemplateSplit::PixelTempSplit( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
theClusterParam.ierr = -123;
/*
float dchisq;
float templProbQ_;
SiPixelTemplateSplit::PixelTempSplit( ID, theClusterParam.cotalpha, theClusterParam.cotbeta,
clust_array_2d,
ydouble, xdouble,
templ,
Expand All @@ -305,7 +313,7 @@ PixelCPETemplateReco::localPosition(DetParam const & theDetParam, ClusterParam &
dchisq,
templ2D_ );

*/
if ( theClusterParam.ierr != 0 )
{
LogDebug("PixelCPETemplateReco::localPosition") <<
Expand Down

0 comments on commit a8061f4

Please sign in to comment.