CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
PFResolutionMap Class Reference

Resolution Map (resolution as a function of eta and E) More...

#include <PFResolutionMap.h>

Inheritance diagram for PFResolutionMap:

Public Member Functions

int FindBin (double eta, double e, double z=0) override
 extrapolation requires overloading of this function More...
 
const char * GetMapFile () const
 
double getRes (double eta, double phi, double e, int MapEta=-1)
 
 PFResolutionMap ()
 default constructor More...
 
 PFResolutionMap (const char *name, const char *mapfile)
 create a map from text file mapfile More...
 
 PFResolutionMap (const char *name, unsigned nbinseta, double mineta, double maxeta, unsigned nbinse, double mine, double maxe, double value=-1)
 create an empty map and initialize it More...
 
 PFResolutionMap (const TH2D &h)
 create a map from a 2d histogram More...
 
bool ReadMapFile (const char *mapfile)
 read text file More...
 
bool WriteMapFile (const char *mapfile)
 

Private Member Functions

double dCrackPhi (double phi, double eta)
 
bool IsInAPhiCrack (double phi, double eta)
 
double minimum (double a, double b)
 

Private Attributes

std::string mapFile_
 

Static Private Attributes

static const unsigned lineSize_ = 10000
 

Friends

std::ostream & operator<< (std::ostream &out, const PFResolutionMap &rm)
 print this map More...
 

Detailed Description

Resolution Map (resolution as a function of eta and E)

Basically just a TH2D with text I/O

Author
Colin Bernet
Date
January 2006

Definition at line 16 of file PFResolutionMap.h.

Constructor & Destructor Documentation

◆ PFResolutionMap() [1/4]

PFResolutionMap::PFResolutionMap ( )
inline

default constructor

Definition at line 19 of file PFResolutionMap.h.

19 : TH2D() {}

◆ PFResolutionMap() [2/4]

PFResolutionMap::PFResolutionMap ( const char *  name,
const char *  mapfile 
)

create a map from text file mapfile

Definition at line 38 of file PFResolutionMap.cc.

38  {
39  SetTitle(name);
40  GetXaxis()->SetTitle("#eta");
41  GetYaxis()->SetTitle("E");
42  if (!ReadMapFile(mapfile)) {
43  string err = "PFResolutionMap::PFResolutionMap : cannot read file ";
44  err += mapfile;
45  throw invalid_argument(err);
46  }
47 }

References submitPVResolutionJobs::err, Skims_PA_cff::name, and ReadMapFile().

◆ PFResolutionMap() [3/4]

PFResolutionMap::PFResolutionMap ( const char *  name,
unsigned  nbinseta,
double  mineta,
double  maxeta,
unsigned  nbinse,
double  mine,
double  maxe,
double  value = -1 
)

create an empty map and initialize it

Definition at line 15 of file PFResolutionMap.cc.

23  : TH2D(name, name, nbinseta, mineta, maxeta, nbinse, mine, maxe) {
24  GetXaxis()->SetTitle("#eta");
25  GetYaxis()->SetTitle("E");
26 
27  if (value > 0) {
28  for (int ie = 1; ie <= GetNbinsY(); ie++) {
29  for (int ieta = 1; ieta <= GetNbinsX(); ieta++) {
30  SetBinContent(ieta, ie, value);
31  }
32  }
33  }
34  // cout<<"creating resolution map "<<endl;
35  // Print("all");
36 }

References LEDCalibrationChannels::ieta.

◆ PFResolutionMap() [4/4]

PFResolutionMap::PFResolutionMap ( const TH2D &  h)
inline

create a map from a 2d histogram

Definition at line 35 of file PFResolutionMap.h.

35 : TH2D(h) {}

Member Function Documentation

◆ dCrackPhi()

double PFResolutionMap::dCrackPhi ( double  phi,
double  eta 
)
private

Definition at line 216 of file PFResolutionMap.cc.

216  {
217  constexpr double pi = M_PI; // 3.14159265358979323846;
218  constexpr double twopi = 2. * pi;
219  constexpr double twopiO18 = pi / 9;
220 
221  //Location of the 18 phi-cracks
222  constexpr double c0 = 2.97025;
223  constexpr std::array<double, 18> cPhi{{c0,
224  c0 - twopiO18,
225  c0 - 2 * twopiO18,
226  c0 - 3 * twopiO18,
227  c0 - 4 * twopiO18,
228  c0 - 5 * twopiO18,
229  c0 - 6 * twopiO18,
230  c0 - 7 * twopiO18,
231  c0 - 8 * twopiO18,
232  c0 - 9 * twopiO18,
233  c0 - 10 * twopiO18,
234  c0 - 11 * twopiO18,
235  c0 - 12 * twopiO18,
236  c0 - 13 * twopiO18,
237  c0 - 14 * twopiO18,
238  c0 - 15 * twopiO18,
239  c0 - 16 * twopiO18,
240  c0 - 17 * twopiO18}};
241 
242  //Shift of this location if eta<0
243  constexpr double delta_cPhi = 0.00638;
244 
245  double m; //the result
246 
247  //the location is shifted
248  if (eta < 0) {
249  phi += delta_cPhi;
250  if (phi > pi)
251  phi -= twopi;
252  }
253  if (phi >= -pi && phi <= pi) {
254  //the problem of the extrema
255  if (phi < cPhi[17] || phi >= cPhi[0]) {
256  if (phi < 0)
257  phi += twopi;
258  m = minimum(phi - cPhi[0], phi - cPhi[17] - twopi);
259  }
260 
261  //between these extrema...
262  else {
263  bool OK = false;
264  unsigned i = 16;
265  while (!OK) {
266  if (phi < cPhi[i]) {
267  m = minimum(phi - cPhi[i + 1], phi - cPhi[i]);
268  OK = true;
269  } else
270  i -= 1;
271  }
272  }
273  } else {
274  m = 0.; //if there is a problem, we assum that we are in a crack
275  edm::LogWarning("PFResolutionMap:Problem") << "Problem in dminphi";
276  }
277  if (eta < 0)
278  m = -m; //because of the disymetry
279  return m;
280 }

References fftjetpileupestimator_calo_uncalib_cfi::c0, PVValHelper::eta, mps_fire::i, visualization-live-secondInstance_cfg::m, M_PI, minimum(), phi, and pi.

Referenced by IsInAPhiCrack().

◆ FindBin()

int PFResolutionMap::FindBin ( double  eta,
double  e,
double  z = 0 
)
override

extrapolation requires overloading of this function

Definition at line 168 of file PFResolutionMap.cc.

168  {
169  if (e >= GetYaxis()->GetXmax())
170  e = GetYaxis()->GetXmax() - 0.001;
171 
172  return TH2D::FindBin(eta, e);
173 }

References MillePedeFileConverter_cfg::e, and PVValHelper::eta.

Referenced by getRes().

◆ GetMapFile()

const char* PFResolutionMap::GetMapFile ( ) const
inline

Definition at line 49 of file PFResolutionMap.h.

49 { return mapFile_.c_str(); }

References mapFile_.

◆ getRes()

double PFResolutionMap::getRes ( double  eta,
double  phi,
double  e,
int  MapEta = -1 
)

Definition at line 138 of file PFResolutionMap.cc.

138  {
139  constexpr double fMinEta = -2.95;
140  constexpr double fMaxEta = 2.95;
141  constexpr double fMinE = 0;
142  constexpr double fMaxE = 100;
143 
144  if (eta < fMinEta)
145  eta = fMinEta + 0.001;
146  if (eta > fMaxEta)
147  eta = fMaxEta - 0.001;
148 
149  if (e < fMinE)
150  e = fMinE + 0.001;
151  if (e > fMaxE)
152  e = fMaxE - 0.001;
153 
154  unsigned bin = FindBin(TMath::Abs(eta), e);
155 
156  double res = GetBinContent(bin);
157  if (MapEta > -1) {
158  if ((eta < 1.48) && IsInAPhiCrack(phi, eta)) {
159  if (MapEta == 1)
160  res *= 1.88;
161  else
162  res *= 1.65;
163  }
164  }
165  return res;
166 }

References Abs(), newFWLiteAna::bin, MillePedeFileConverter_cfg::e, PVValHelper::eta, FindBin(), IsInAPhiCrack(), and phi.

◆ IsInAPhiCrack()

bool PFResolutionMap::IsInAPhiCrack ( double  phi,
double  eta 
)
private

Definition at line 198 of file PFResolutionMap.cc.

198  {
199  double dminPhi = dCrackPhi(phi, eta);
200  bool Is = (TMath::Abs(dminPhi) < 0.005);
201  return Is;
202 }

References Abs(), dCrackPhi(), PVValHelper::eta, and phi.

Referenced by getRes().

◆ minimum()

double PFResolutionMap::minimum ( double  a,
double  b 
)
private

Definition at line 205 of file PFResolutionMap.cc.

205  {
206  if (TMath::Abs(b) < TMath::Abs(a))
207  a = b;
208  return a;
209 }

References a, Abs(), and b.

Referenced by dCrackPhi().

◆ ReadMapFile()

bool PFResolutionMap::ReadMapFile ( const char *  mapfile)

read text file

Definition at line 70 of file PFResolutionMap.cc.

70  {
71  // open the file
72 
73  std::ifstream inf(mapfile);
74  if (!inf.good()) {
75  // cout<<"PFResolutionMap::Read : cannot open file "<<mapfile<<endl;
76  return false;
77  }
78 
79  // first data describes the map
80 
81  int nbinseta = 0;
82  double mineta = 0;
83  double maxeta = 0;
84 
85  int nbinse = 0;
86  double mine = 0;
87  double maxe = 0;
88 
89  inf >> nbinseta;
90  inf >> mineta;
91  inf >> maxeta;
92 
93  inf >> nbinse;
94  inf >> mine;
95  inf >> maxe;
96 
97  SetBins(nbinseta, mineta, maxeta, nbinse, mine, maxe);
98 
99  char s[lineSize_];
100  int pos = inf.tellg();
101 
102  // parse map data
103  int i = 1;
104  do {
105  inf.seekg(pos);
106  inf.getline(s, lineSize_);
107 
108  pos = inf.tellg();
109 
110  if (string(s).empty()) {
111  continue; // remove empty lines
112  }
113 
114  istringstream lin(s);
115 
116  double dataw;
117  int j = 1;
118  do {
119  lin >> dataw;
120  SetBinContent(j, i, dataw);
121  j++;
122  } while (lin.good());
123  i++;
124  } while (inf.good());
125 
126  if (inf.eof()) {
127  mapFile_ = mapfile;
128  return true;
129  } else {
130  // cout<<"error"<<endl;
131  return false;
132  }
133 
134  mapFile_ = mapfile;
135  return true;
136 }

References relativeConstraints::empty, mps_fire::i, dqmiodatasetharvest::inf, dqmiolumiharvest::j, lineSize_, mapFile_, and alignCSCRings::s.

Referenced by PFResolutionMap().

◆ WriteMapFile()

bool PFResolutionMap::WriteMapFile ( const char *  mapfile)

write text file is not const because mapFile_ will be updated

Definition at line 49 of file PFResolutionMap.cc.

49  {
50  // assert(fData.size() == fNbinsEta*fNbinsE);
51 
52  // open the file
53 
54  std::ofstream outf(mapfile);
55  if (!outf.good()) {
56  edm::LogWarning("PFResolutionMap::Write") << " : cannot open file " << mapfile;
57  return false;
58  }
59 
60  outf << (*this) << endl;
61  if (!outf.good()) {
62  edm::LogError("PFResolutionMap::Write") << " : corrupted file " << mapfile;
63  return false;
64  } else {
65  mapFile_ = mapfile;
66  return true;
67  }
68 }

References mapFile_.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const PFResolutionMap rm 
)
friend

print this map

Member Data Documentation

◆ lineSize_

const unsigned PFResolutionMap::lineSize_ = 10000
staticprivate

Definition at line 58 of file PFResolutionMap.h.

Referenced by ReadMapFile().

◆ mapFile_

std::string PFResolutionMap::mapFile_
private

Definition at line 59 of file PFResolutionMap.h.

Referenced by GetMapFile(), ReadMapFile(), and WriteMapFile().

mps_fire.i
i
Definition: mps_fire.py:428
PFResolutionMap::mapFile_
std::string mapFile_
Definition: PFResolutionMap.h:59
PFResolutionMap::dCrackPhi
double dCrackPhi(double phi, double eta)
Definition: PFResolutionMap.cc:216
pos
Definition: PixelAliasList.h:18
PFResolutionMap::ReadMapFile
bool ReadMapFile(const char *mapfile)
read text file
Definition: PFResolutionMap.cc:70
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
reco::OK
std::pair< int, edm::FunctionWithDict > OK
Definition: findMethod.cc:126
PFResolutionMap::lineSize_
static const unsigned lineSize_
Definition: PFResolutionMap.h:58
PFResolutionMap::minimum
double minimum(double a, double b)
Definition: PFResolutionMap.cc:205
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Abs
T Abs(T a)
Definition: MathUtil.h:49
PVValHelper::eta
Definition: PVValidationHelpers.h:69
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
h
b
double b
Definition: hdecay.h:118
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
a
double a
Definition: hdecay.h:119
value
Definition: value.py:1
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
res
Definition: Electron.h:6
PFResolutionMap::FindBin
int FindBin(double eta, double e, double z=0) override
extrapolation requires overloading of this function
Definition: PFResolutionMap.cc:168
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
DDAxes::phi
dqmiodatasetharvest.inf
inf
Definition: dqmiodatasetharvest.py:38
M_PI
#define M_PI
Definition: PFResolutionMap.cc:212
PFResolutionMap::IsInAPhiCrack
bool IsInAPhiCrack(double phi, double eta)
Definition: PFResolutionMap.cc:198
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
fftjetpileupestimator_calo_uncalib_cfi.c0
c0
Definition: fftjetpileupestimator_calo_uncalib_cfi.py:8
pi
const Double_t pi
Definition: trackSplitPlot.h:36
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37