Skip to content

Commit

Permalink
Merge pull request #23590 from slava77/patch-37
Browse files Browse the repository at this point in the history
 cleanup static variables in PFResolutionMap.cc
  • Loading branch information
cmsbuild committed Jun 19, 2018
2 parents 84df0b0 + 2a51552 commit e0bee14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 98 deletions.
1 change: 1 addition & 0 deletions RecoParticleFlow/PFClusterTools/BuildFile.xml
@@ -1,3 +1,4 @@
<use name="FWCore/MessageLogger"/>
<use name="CondFormats/PhysicsToolsObjects"/>
<use name="DataFormats/ParticleFlowReco"/>
<use name="DataFormats/Math"/>
Expand Down
120 changes: 22 additions & 98 deletions RecoParticleFlow/PFClusterTools/src/PFResolutionMap.cc
Expand Up @@ -8,6 +8,7 @@
#include <TMath.h>
#include <vector>
using namespace std;
#include "FWCore/MessageLogger/interface/MessageLogger.h"


const unsigned PFResolutionMap::lineSize_ = 10000;
Expand All @@ -18,8 +19,6 @@ PFResolutionMap::PFResolutionMap(const char* name, unsigned nbinseta,
unsigned nbinse,
double mine, double maxe, double value)
: TH2D(name, name, nbinseta, mineta, maxeta, nbinse, mine, maxe) {
// fNbinsEta(nbinseta), fMinEta(mineta), fMaxEta(maxeta),
// fNbinsE(nbinse), fMinE(mine), fMaxE(maxe) {

GetXaxis()->SetTitle("#eta");
GetYaxis()->SetTitle("E");
Expand All @@ -36,38 +35,6 @@ PFResolutionMap::PFResolutionMap(const char* name, unsigned nbinseta,

}

// void PFResolutionMap::Init(unsigned nbinseta,
// double mineta, double maxeta,
// unsigned nbinse,
// double mine, double maxe) {
// assert(mineta<maxeta);
// assert(mine<maxe);

// unsigned nbins = nbinseta*nbinse;
// fData.reserve( nbins );
// for(unsigned i=0; i<nbins; i++) {
// fData.push_back(-1);
// }

// // calculate lower bound of eta and e bins
// double binsize = (fMaxEta - fMinEta)/fNbinsEta;
// double lb = fMinEta;
// // cout<<"eta bins lower bounds : "<<endl;
// for(unsigned i=0; i<nbinseta; i++) {
// fEtaBinsLowerBounds[lb] = i;
// // cout<<i<<" "<<lb<<endl;
// lb += binsize;
// }

// binsize = (fMaxE - fMinE)/fNbinsE;
// lb = fMinE;
// // cout<<"E bins lower bounds : "<<endl;
// for(unsigned i=0; i<nbinse; i++) {
// fEBinsLowerBounds[lb] = i;
// // cout<<i<<" "<<lb<<endl;
// lb += binsize;
// }
// }

PFResolutionMap::PFResolutionMap(const char* name, const char* mapfile) {
SetTitle(name);
Expand All @@ -90,13 +57,13 @@ bool PFResolutionMap::WriteMapFile(const char* mapfile) {

std::ofstream outf(mapfile);
if( !outf.good() ) {
cout<<"PFResolutionMap::Write : cannot open file "<<mapfile<<endl;
edm::LogWarning("PFResolutionMap::Write")<<" : cannot open file "<<mapfile;
return false;
}

outf<<(*this)<<endl;
if(!outf.good() ) {
cerr<<"PFResolutionMap::Write : corrupted file "<<mapfile<<endl;
edm::LogError("PFResolutionMap::Write")<<" : corrupted file "<<mapfile;
return false;
}
else {
Expand Down Expand Up @@ -137,9 +104,6 @@ bool PFResolutionMap::ReadMapFile(const char* mapfile) {

SetBins(nbinseta, mineta, maxeta, nbinse, mine, maxe);

// Init(fNbinsEta,fMinEta,fMaxEta,fNbinsE,fMinE,fMaxE);

// char data[lineSize_];
char s[lineSize_];
int pos=inf.tellg();

Expand Down Expand Up @@ -182,57 +146,12 @@ bool PFResolutionMap::ReadMapFile(const char* mapfile) {



// int PFResolutionMap::FindBin(double eta, double e) const {

// if(eta<fMinEta || eta>=fMaxEta) {
// cout<<"PFResolutionMap::FindBin "<<eta<<" out of eta bounds "<<fMinEta<<" "<<fMaxEta<<endl;
// return -1;
// }
// if(e<fMinE || e>=fMaxE) {
// cout<<"PFResolutionMap::FindBin "<<e<<" out of e bounds "<<fMinE<<" "<<fMaxE<<endl;
// return -1;
// }

// map<double,unsigned >::const_iterator iteta =
// fEtaBinsLowerBounds.upper_bound( eta );
// iteta--;

// // if( iteta != fEtaBinsLowerBounds.end() ) {
// // cout<<"eta lower bound "<<iteta->first<<" "<<iteta->second<<endl;
// // }
// // else return -1;

// map<double,unsigned>::const_iterator ite =
// fEBinsLowerBounds.upper_bound( e );
// ite--;
// // if( ite != fEBinsLowerBounds.end() ) {
// // cout<<"e lower bound "<<ite->first<<" "<<ite->second<<endl;
// // }
// // else return -1;

// // cout<<"returning "<<ite->second * fNbinsEta + iteta->second<<endl;
// // cout<<"returning "<<ite->second<<" "<<iteta->second<<endl;

// return ite->second * fNbinsEta + iteta->second;
// }

// void PFResolutionMap::Fill(double eta, double e, double res) {

// unsigned bin = FindBin(eta, e);
// if( bin<0 || bin>fData.size() ) {
// // cout<<"PFResolutionMap::Fill : out of range " <<bin<<endl;
// return;
// }

// fData[bin] = res;
// }


double PFResolutionMap::getRes(double eta, double phi, double e, int MapEta){
static double fMinEta = -2.95;
static double fMaxEta = 2.95;
static double fMinE=0;
static double fMaxE=100;
constexpr double fMinEta = -2.95;
constexpr double fMaxEta = 2.95;
constexpr double fMinE=0;
constexpr double fMaxE=100;

if( eta<fMinEta ) eta = fMinEta+0.001;
if( eta>fMaxEta ) eta = fMaxEta-0.001;
Expand Down Expand Up @@ -306,30 +225,35 @@ double PFResolutionMap::minimum(double a,double b){
//compute the unsigned distance to the closest phi-crack in the barrel
double PFResolutionMap::dCrackPhi(double phi, double eta){

static double pi= M_PI;// 3.14159265358979323846;
constexpr double pi= M_PI;// 3.14159265358979323846;
constexpr double twopi= 2.*pi;
constexpr double twopiO18= pi/9;

//Location of the 18 phi-cracks
static std::vector<double> cPhi;
cPhi.resize(18,0);
cPhi[0]=2.97025;
for(unsigned i=1;i<=17;i++) cPhi[i]=cPhi[0]-2*i*pi/18;
constexpr double c0 = 2.97025;
constexpr std::array<double,18> cPhi {{c0,
c0-twopiO18, c0-2*twopiO18, c0-3*twopiO18, c0-4*twopiO18,
c0-5*twopiO18, c0-6*twopiO18, c0-7*twopiO18, c0-8*twopiO18,
c0-9*twopiO18, c0-10*twopiO18, c0-11*twopiO18, c0-12*twopiO18,
c0-13*twopiO18, c0-14*twopiO18, c0-15*twopiO18, c0-16*twopiO18,
c0-17*twopiO18}};

//Shift of this location if eta<0
static double delta_cPhi=0.00638;
constexpr double delta_cPhi=0.00638;

double m; //the result

//the location is shifted
if(eta<0){
phi +=delta_cPhi;
if(phi>pi) phi-=2*pi;
if(phi>pi) phi-=twopi;
}
if (phi>=-pi && phi<=pi){

//the problem of the extrema
if (phi<cPhi[17] || phi>=cPhi[0]){
if (phi<0) phi+= 2*pi;
m = minimum(phi -cPhi[0],phi-cPhi[17]-2*pi);
if (phi<0) phi+= twopi;
m = minimum(phi -cPhi[0],phi-cPhi[17]-twopi);
}

//between these extrema...
Expand All @@ -347,7 +271,7 @@ double PFResolutionMap::dCrackPhi(double phi, double eta){
}
else{
m=0.; //if there is a problem, we assum that we are in a crack
std::cout<<"Problem in dminphi"<<std::endl;
edm::LogWarning("PFResolutionMap:Problem")<<"Problem in dminphi";
}
if(eta<0) m=-m; //because of the disymetry
return m;
Expand Down

0 comments on commit e0bee14

Please sign in to comment.