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

Reduce fastsim memory profile a bit #9443

Merged
merged 1 commit into from Jun 9, 2015
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
10 changes: 5 additions & 5 deletions FastSimulation/CaloGeometryTools/interface/BaseCrystal.h
Expand Up @@ -43,7 +43,7 @@ class BaseCrystal
///
void setCorners(const CaloCellGeometry::CornersVec& vec,const GlobalPoint& pos);

inline const std::vector<XYZPoint>& getCorners() const {return corners_;}
// inline const std::vector<XYZPoint>& getCorners() const {return corners_;}

/// get the i-th corner
inline const XYZPoint& getCorner(unsigned i) const { return corners_[i];};
Expand Down Expand Up @@ -108,7 +108,7 @@ class BaseCrystal
void computeBasicProperties();

private:
std::vector<XYZPoint> corners_;
XYZPoint corners_[8];
DetId cellid_;
int subdetn_;
XYZPoint center_;
Expand All @@ -117,8 +117,8 @@ class BaseCrystal
XYZVector firstedgedirection_;
XYZVector fifthedgedirection_;
XYZVector crystalaxis_;
std::vector<XYZVector> lateraldirection_;
std::vector<Plane3D> lateralPlane_;
std::vector<XYZVector> exitingNormal_;
XYZVector lateraldirection_[4];
Plane3D lateralPlane_[6];
XYZVector exitingNormal_[6];
};
#endif
Expand Up @@ -6,6 +6,7 @@
#include "FastSimulation/CaloGeometryTools/interface/BaseCrystal.h"

#include <vector>
#include <array>

class DetId;
class Crystal;
Expand Down Expand Up @@ -45,7 +46,8 @@ class CaloGeometryHelper:public Calorimeter
void initialize(double bField);

// get the <=8 neighbours
const std::vector<DetId> & getNeighbours(const DetId& det) const ;
typedef std::array<DetId,8> NeiVect;
const NeiVect& getNeighbours(const DetId& det) const ;

inline double magneticField() const {return bfield_;}

Expand All @@ -67,8 +69,8 @@ class CaloGeometryHelper:public Calorimeter
double psLayer1Z_,psLayer2Z_;

// array of neighbours the hashed index is used for the first vector
std::vector<std::vector<DetId> > barrelNeighbours_;
std::vector<std::vector<DetId> > endcapNeighbours_;
std::vector< NeiVect > barrelNeighbours_;
std::vector< NeiVect > endcapNeighbours_;

std::vector<BaseCrystal> barrelCrystals_;
std::vector<BaseCrystal> endcapCrystals_;
Expand Down
15 changes: 3 additions & 12 deletions FastSimulation/CaloGeometryTools/src/BaseCrystal.cc
Expand Up @@ -24,17 +24,13 @@ void BaseCrystal::setCorners(const CaloCellGeometry::CornersVec& vec,const Globa
{
if(pos.z()>0.)
{
corners_.clear();
corners_.resize(8);
for(unsigned ic=0;ic<8;++ic)
{
corners_[ic]=XYZPoint(vec[ic].x(),vec[ic].y(),vec[ic].z());
}
}
else
{
corners_.clear();
corners_.resize(8);
corners_[0]=XYZPoint(vec[2].x(),vec[2].y(),vec[2].z());
corners_[1]=XYZPoint(vec[3].x(),vec[3].y(),vec[3].z());
corners_[2]=XYZPoint(vec[0].x(),vec[0].y(),vec[0].z());
Expand Down Expand Up @@ -76,8 +72,6 @@ void BaseCrystal::setCorners(const CaloCellGeometry::CornersVec& vec,const Globa
offset=1;
zsign=-1;
}
corners_.clear();
corners_.resize(8);
for(unsigned ic=0;ic<4;++ic)
{
unsigned i1=(unsigned)((zsign*ic+offset)%4);
Expand All @@ -91,7 +85,7 @@ void BaseCrystal::setCorners(const CaloCellGeometry::CornersVec& vec,const Globa

void BaseCrystal::computeBasicProperties()
{
if(corners_.size()==0) return;
//if(corners_.size()==0) return;
center_=XYZPoint(0.,0.,0.);
for(unsigned ic=0;ic<8;++ic)
{
Expand All @@ -106,7 +100,6 @@ void BaseCrystal::computeBasicProperties()
crystalaxis_ = backcenter_-frontcenter_;
firstedgedirection_=-(corners_[1]-corners_[0]).Unit();
fifthedgedirection_=-(corners_[5]-corners_[4]).Unit();
lateraldirection_.resize(4);
// std::cout << " Direction laterales " << std::endl;
for(unsigned il=0;il<4;++il)
{
Expand All @@ -115,7 +108,6 @@ void BaseCrystal::computeBasicProperties()

Plane3D frontPlane((Point)corners_[0],(Point)corners_[1],(Point)corners_[2]);
Plane3D backPlane ((Point)corners_[4],(Point)corners_[5],(Point)corners_[6]);
lateralPlane_.resize(6);
for(unsigned i=0;i<4;++i)
{
lateralPlane_[i]=
Expand All @@ -126,7 +118,6 @@ void BaseCrystal::computeBasicProperties()
// Back plane i =5 (DOWN)
lateralPlane_[5] = backPlane;

exitingNormal_.resize(6);
for(unsigned i=0;i<6;++i)
{
exitingNormal_[i] =
Expand Down Expand Up @@ -281,13 +272,13 @@ void BaseCrystal::getSide(const CaloDirection& side, XYZPoint &a,XYZPoint &b,XYZ
void BaseCrystal::print() const{
std::cout << "CellID " << cellid_.rawId() << std::endl;
std::cout << " Corners " << std::endl;
for(unsigned ic=0;ic<corners_.size();++ic)
for(unsigned ic=0;ic<8;++ic)
std::cout << corners_[ic] << std::endl;
std::cout << " Center " << center_ << std::endl;
std::cout << " Front Center " << frontcenter_ << std::endl;
std::cout << " Back Center " << backcenter_ << std::endl;
std::cout << " Normales sortantes " << std::endl;
for(unsigned id=0;id<exitingNormal_.size();++id)
for(unsigned id=0;id<6;++id)
std::cout << exitingNormal_[id] << std::endl;
}

Expand Down
18 changes: 11 additions & 7 deletions FastSimulation/CaloGeometryTools/src/CaloGeometryHelper.cc
Expand Up @@ -219,21 +219,23 @@ void CaloGeometryHelper::buildNeighbourArray()

if(nneighbours==9)
{
barrelNeighbours_[hashedindex].reserve(8);
//barrelNeighbours_[hashedindex].reserve(8);
unsigned int nn=0;
for(unsigned in=0;in<nneighbours;++in)
{
// remove the centre
if(neighbours[in]!=vec[ic])
{
barrelNeighbours_[hashedindex].push_back(neighbours[in]);
barrelNeighbours_[hashedindex][nn]=(neighbours[in]);
nn++;
// std::cout << " Neighbour " << in << " " << EBDetId(neighbours[in]) << std::endl;
}
}
}
else
{
DetId central(vec[ic]);
barrelNeighbours_[hashedindex].resize(8,DetId(0));
//barrelNeighbours_[hashedindex].resize(8,DetId(0));
for(unsigned idir=0;idir<8;++idir)
{
DetId testid=central;
Expand Down Expand Up @@ -272,20 +274,22 @@ void CaloGeometryHelper::buildNeighbourArray()

if(nneighbours==9)
{
endcapNeighbours_[hashedindex].reserve(8);
//endcapNeighbours_[hashedindex].reserve(8);
unsigned int nn=0;
for(unsigned in=0;in<nneighbours;++in)
{
// remove the centre
if(neighbours[in]!=vece[ic])
{
endcapNeighbours_[hashedindex].push_back(neighbours[in]);
endcapNeighbours_[hashedindex][nn]=(neighbours[in]);
nn++;
}
}
}
else
{
DetId central(vece[ic]);
endcapNeighbours_[hashedindex].resize(8,DetId(0));
//endcapNeighbours_[hashedindex].resize(8,DetId(0));
for(unsigned idir=0;idir<8;++idir)
{
DetId testid=central;
Expand All @@ -299,7 +303,7 @@ void CaloGeometryHelper::buildNeighbourArray()
neighbourmapcalculated_ = true;
}

const std::vector<DetId>& CaloGeometryHelper::getNeighbours(const DetId& detid) const
const CaloGeometryHelper::NeiVect& CaloGeometryHelper::getNeighbours(const DetId& detid) const
{
return (detid.subdetId()==EcalBarrel)?barrelNeighbours_[EBDetId(detid).hashedIndex()]:
endcapNeighbours_[EEDetId(detid).hashedIndex()];
Expand Down
2 changes: 1 addition & 1 deletion FastSimulation/CaloGeometryTools/src/CrystalWindowMap.cc
Expand Up @@ -15,7 +15,7 @@ CrystalWindowMap::CrystalWindowMap(const CaloGeometryHelper *calo,const std::vec

for(unsigned ic=0; ic<size_; ++ic)
{
const std::vector<DetId>& neighbours=myCalorimeter_->getNeighbours(cw[ic].getDetId());
const CaloGeometryHelper::NeiVect& neighbours=myCalorimeter_->getNeighbours(cw[ic].getDetId());
myNeighbours_[ic].reserve(8);
for(unsigned in=0; in<8;++in)
{
Expand Down
Expand Up @@ -230,7 +230,7 @@ void testCaloGeometryTools::testBorderCrossing()
unsigned counter=0;
for(unsigned ic=0;ic<size;++ic)
{
std::vector<DetId> neighbours=myGeometry.getNeighbours(vec[ic]);
CaloGeometryHelper::NeiVect neighbours=myGeometry.getNeighbours(vec[ic]);
for(unsigned in=0;in<8;++in)
{
if(neighbours[in].null()) continue;
Expand All @@ -257,7 +257,7 @@ void testCaloGeometryTools::testBorderCrossing()
counter=0;
for(unsigned ic=0;ic<size;++ic)
{
std::vector<DetId> neighbours=myGeometry.getNeighbours(vec2[ic]);
CaloGeometryHelper::NeiVect neighbours=myGeometry.getNeighbours(vec2[ic]);
for(unsigned in=0;in<8;++in)
{
if(neighbours[in].null()) continue;
Expand Down
Expand Up @@ -47,6 +47,9 @@ SiPixelGaussianSmearingRecHitConverterAlgorithm::SiPixelGaussianSmearingRecHitCo
// Switch between old (ORCA) and new (CMSSW) pixel parameterization
useCMSSWPixelParameterization = pset.getParameter<bool>("UseCMSSWPixelParametrization");

thePixelResolutionFile1=0;
thePixelResolutionFile2=0;

if( thePixelPart == GeomDetEnumerators::PixelBarrel ) {
isForward = false;
thePixelResolutionFileName1 = pset_.getParameter<string>( "NewPixelBarrelResolutionFile1" );
Expand Down Expand Up @@ -82,6 +85,17 @@ SiPixelGaussianSmearingRecHitConverterAlgorithm::SiPixelGaussianSmearingRecHitCo
else
throw cms::Exception("SiPixelGaussianSmearingRecHitConverterAlgorithm :")
<<"Not a pixel detector"<<endl;

if ( thePixelResolutionFile2) {
thePixelResolutionFile2->Close();
delete thePixelResolutionFile2;
}
if ( thePixelResolutionFile1) {
thePixelResolutionFile1->Close();
delete thePixelResolutionFile1;
}
thePixelResolutionFile1=0;
thePixelResolutionFile2=0;
}

SiPixelGaussianSmearingRecHitConverterAlgorithm::~SiPixelGaussianSmearingRecHitConverterAlgorithm()
Expand Down
8 changes: 4 additions & 4 deletions FastSimulation/Utilities/interface/SimpleHistogramGenerator.h
Expand Up @@ -34,16 +34,16 @@ class SimpleHistogramGenerator
double generate(RandomEngineAndDistribution const*) const;

int binarySearch(const int& n,
const std::vector<double>& array,
const std::vector<float>& array,
const double& value) const;

private:

/// Pointer to the histogram
TH1 * myHisto;
//TH1 * myHisto;

/// the axis
TAxis * theXaxis;
//TAxis * theXaxis;

/// Number of bins
int nBins;
Expand All @@ -55,7 +55,7 @@ class SimpleHistogramGenerator
double binWidth;

/// Integral
std::vector<double> integral;
std::vector<float> integral;

/// Number of entries
double nEntries;
Expand Down
13 changes: 7 additions & 6 deletions FastSimulation/Utilities/src/SimpleHistogramGenerator.cc
Expand Up @@ -6,13 +6,14 @@
// #include <iostream>

SimpleHistogramGenerator::SimpleHistogramGenerator(TH1 * histo) :
myHisto(histo),
theXaxis(histo->GetXaxis()),
nBins(theXaxis->GetNbins()),
xMin(theXaxis->GetXmin()),
xMax(theXaxis->GetXmax()),
//myHisto(histo),
//theXaxis(histo->GetXaxis()),
nBins(histo->GetXaxis()->GetNbins()),
xMin(histo->GetXaxis()->GetXmin()),
xMax(histo->GetXaxis()->GetXmax()),
binWidth((xMax-xMin)/(float)nBins)
{
integral.reserve(nBins+2);
integral.push_back(0.);
for ( int i=1; i<=nBins; ++i )
integral.push_back(integral[i-1]+histo->GetBinContent(i));
Expand Down Expand Up @@ -41,7 +42,7 @@ SimpleHistogramGenerator::generate(RandomEngineAndDistribution const* random) co

int
SimpleHistogramGenerator::binarySearch(const int& n,
const std::vector<double>& array,
const std::vector<float>& array,
const double& value) const
{
// Binary search in an array of n values to locate value.
Expand Down