Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Significant reduction of memory footprint for 2D templates, etc. #23263

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 35 additions & 47 deletions RecoLocalTracker/SiPixelRecHits/interface/SiPixelTemplate2D.h
@@ -1,5 +1,5 @@
//
// SiPixelTemplate2D.h (v2.35)
// SiPixelTemplate2D.h (v2.61a)
//
// Full 2-D templates for cluster splitting, simulated cluster reweighting, and improved cluster probability
//
Expand All @@ -14,7 +14,11 @@
// v2.25 - Resize template store to accommodate FPix Templates
// v2.30 - Fix bug found by P. Shuetze that compromises sqlite file loading
// v2.35 - Add directory path selection to the ascii pushfile method
// V2.36 - Move templateStore to the heap, fix variable name in pushfile()
// v2.50 - Change template storage to dynamically allocated 2D arrays of SiPixelTemplateEntry2D structs
// v2.51 - Ensure that the derivative arrays are correctly zeroed between calls
// v2.52 - Improve cosmetics for increased style points from judges
// v2.60 - Fix FPix multiframe lookup problem [takes +-cotalpha and +-cotbeta]
// v2.61a - Code 2.60 fix correctly
//

// Build the template storage structure from several pieces
Expand Down Expand Up @@ -48,7 +52,7 @@ struct SiPixelTemplateEntry2D { //!< Basic template entry corresponding to a sin
int jxmax; //!< the maximum nonzero pixel xindex in template (saves time during interpolation)
float xypar[2][5]; //!< pixel uncertainty parameterization
float lanpar[2][5]; //!< pixel landau distribution parameters
float xytemp[7][7][T2YSIZE][T2XSIZE]; //!< templates for y-reconstruction (binned over 1 central pixel)
short int xytemp[7][7][T2YSIZE][T2XSIZE]; //!< templates for y-reconstruction (binned over 1 central pixel)
float chi2ppix; //!< average chi^2 per pixel
float chi2scale; //!< scale factor for the chi2 distribution
float chi2avgone; //!< average y chi^2 for 1 pixel clusters
Expand Down Expand Up @@ -101,14 +105,16 @@ struct SiPixelTemplateHeader2D { //!< template header structure

struct SiPixelTemplateStore2D { //!< template storage structure
SiPixelTemplateHeader2D head;
#ifndef SI_PIXEL_TEMPLATE_USE_BOOST
SiPixelTemplateEntry2D entry[73][7]; //!< use 2d entry to store [47][5] barrel entries or [5][9] fpix
#else
boost::multi_array<SiPixelTemplateEntry2D,2> entry; //!< use 2d entry to store [47][5] barrel entries or [5][9] fpix entries
#endif
} ;
SiPixelTemplateEntry2D** entry = nullptr; //!< use 2d entry to store BPix and FPix entries [dynamically allocated]
void destroy() { // deletes arrays created by pushfile method of SiPixelTemplate
if (entry!=nullptr) {
delete[] entry[0];
delete[] entry;
}

}

} ;



Expand Down Expand Up @@ -175,41 +181,11 @@ class SiPixelTemplate2D {
float qscale() {return qscale_;} //!< charge scaling factor
float s50() {return s50_;} //!< 1/2 of the pixel threshold signal in adc units
float sxymax() {return sxymax_;} //!< max pixel signal for pixel error calculation
float scalex(int i) {
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
if(i < 0 || i > 3) {throw cms::Exception("DataCorrupt") << "SiPixelTemplate2D::scalex called with illegal index = " << i << std::endl;}
#else
assert(i>=0 && i<4);
#endif
return scalex_[i];} //!< x-error scale factor in 4 charge bins
float scaley(int i) {
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
if(i < 0 || i > 3) {throw cms::Exception("DataCorrupt") << "SiPixelTemplate2D::scaley called with illegal index = " << i << std::endl;}
#else
assert(i>=0 && i<4);
#endif
return scaley_[i];} //!<x-error scale factor in 4 charge bins
float offsetx(int i) {
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
if(i < 0 || i > 3) {throw cms::Exception("DataCorrupt") << "SiPixelTemplate2D::scaley called with illegal index = " << i << std::endl;}
#else
assert(i>=0 && i<4);
#endif
return offsetx_[i];} //!< x-offset in 4 charge bins
float offsety(int i) {
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
if(i < 0 || i > 3) {throw cms::Exception("DataCorrupt") << "SiPixelTemplate2D::scaley called with illegal index = " << i << std::endl;}
#else
assert(i>=0 && i<4);
#endif
return offsety_[i];} //!< x-offset in 4 charge bins
float fbin(int i) {
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
if(i < 0 || i > 2) {throw cms::Exception("DataCorrupt") << "SiPixelTemplate2D::fbin called with illegal index = " << i << std::endl;}
#else
assert(i>=0 && i<3);
#endif
return fbin_[i];} //!< Return lower bound of Qbin definition
float scalex(int i) {if(checkIllegalIndex("scalex",3,i)) {return scalex_[i];} else {return 0.f;}} //!< x-error scale factor in 4 charge bins
float scaley(int i) {if(checkIllegalIndex("scaley",3,i)) {return scaley_[i];} else {return 0.f;}} //!< y-error scale factor in 4 charge bins
float offsetx(int i) {if(checkIllegalIndex("offsetx",3,i)) {return offsetx_[i];} else {return 0.f;}} //!< x-offset in 4 charge bins
float offsety(int i) {if(checkIllegalIndex("offsety",3,i)) {return offsety_[i];} else {return 0.f;}} //!< y-offset in 4 charge bins
float fbin(int i) {if(checkIllegalIndex("fbin",2,i)) {return fbin_[i];} else {return 0.f;}} //!< Return lower bound of Qbin definition
float sizex() {return clslenx_;} //!< return x size of template cluster
float sizey() {return clsleny_;} //!< return y size of template cluster
float chi2ppix() {return chi2ppix_;} //!< average chi^2 per struck pixel
Expand All @@ -233,6 +209,18 @@ class SiPixelTemplate2D {
int storesize() {return (int)thePixelTemp_.size();} //!< return the size of the template store (the number of stored IDs

private:

bool checkIllegalIndex(const std::string whichMethod, int indMax, int i)
{
#ifndef SI_PIXEL_TEMPLATE_STANDALONE
if(i < 0 || i > indMax) {throw cms::Exception("DataCorrupt") << "SiPixelTemplate2D::"<< whichMethod <<" called with illegal index = " << i << std::endl;}
#else
assert(i>=0 && i<indMax+1);

#endif
return true;
}


// Keep current template interpolaion parameters

Expand Down Expand Up @@ -301,9 +289,9 @@ class SiPixelTemplate2D {
float ysize_; //!< Pixel y-size
float zsize_; //!< Pixel z-size (thickness)
float fbin_[3]; //!< The QBin definitions in Q_clus/Q_avg
const SiPixelTemplateEntry2D* entry00_; // Pointer to presently interpolated point
const SiPixelTemplateEntry2D* entry10_; // Pointer to presently interpolated point [iy+1]
const SiPixelTemplateEntry2D* entry01_; // Pointer to presently interpolated point [ix+1]
const SiPixelTemplateEntry2D* entry00_; // Pointer to presently interpolated point [iy,ix]
const SiPixelTemplateEntry2D* entry10_; // Pointer to presently interpolated point [iy+1,ix]
const SiPixelTemplateEntry2D* entry01_; // Pointer to presently interpolated point [iy,ix+1]

// The actual template store is a std::vector container

Expand Down
@@ -1,10 +1,15 @@
//
// SiPixelTemplateReco2D.cc (Version 2.20)
// SiPixelTemplateReco2D.cc (Version 2.60)
// Updated to work with the 2D template generation code
// 2.10 - Add y-lorentz drift to estimate starting point [for FPix]
// 2.10 - Remove >1 pixel requirement
// 2.20 - Fix major bug, change chi2 scan to 9x5 [YxX]

// 2.30 - Allow one pixel clusters, improve cosmetics for increased style points from judges
// 2.50 - Add variable cluster shifting to make the position parameter space more symmetric,
// also fix potential problems with variable size input clusters and double pixel flags
// 2.55 - Fix another double pixel flag problem and a small pseudopixel problem in the edgegflagy = 3 case.
// 2.60 - Modify the algorithm to return the point with the best chi2 from the starting point scan when
// the iterative procedure does not converge [eg 1 pixel clusters]

//
//
Expand Down
4 changes: 2 additions & 2 deletions RecoLocalTracker/SiPixelRecHits/src/PixelCPEClusterRepair.cc
Expand Up @@ -107,8 +107,8 @@ PixelCPEClusterRepair::PixelCPEClusterRepair(edm::ParameterSet const & conf,
//-----------------------------------------------------------------------------
PixelCPEClusterRepair::~PixelCPEClusterRepair()
{
for(auto x : thePixelTemp_) x.destroy();
// Note: this is not needed for Template 2D
for (auto x : thePixelTemp_) x.destroy();
for (auto x : thePixelTemp2D_) x.destroy();
}

PixelCPEBase::ClusterParam* PixelCPEClusterRepair::createClusterParam(const SiPixelCluster & cl) const
Expand Down
4 changes: 2 additions & 2 deletions RecoLocalTracker/SiPixelRecHits/src/SiPixelTemplate.cc
Expand Up @@ -2818,7 +2818,7 @@ void SiPixelTemplate::temperrors(int id, float cotalpha, float cotbeta, int qBin
// Interpolate the absolute value of cot(beta)

acotb = fabs((double)cotbeta);
cotb = cotbeta;
// cotb = cotbeta; // &&& check with Morris, we reassign it below.

// for some cosmics, the ususal gymnastics are incorrect

Expand Down Expand Up @@ -3005,7 +3005,7 @@ void SiPixelTemplate::qbin_dist(int id, float cotalpha, float cotbeta, float qbi
// Interpolate the absolute value of cot(beta)

acotb = fabs((double)cotbeta);
cotb = cotbeta;
// cotb = cotbeta; // &&& check with Morris, we reassign it below.


// for some cosmics, the ususal gymnastics are incorrect
Expand Down