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 18 of file PFResolutionMap.h.

Constructor & Destructor Documentation

PFResolutionMap::PFResolutionMap ( )
inline

default constructor

Definition at line 23 of file PFResolutionMap.h.

References dataset::name.

23 : TH2D() {}
PFResolutionMap::PFResolutionMap ( const char *  name,
const char *  mapfile 
)

create a map from text file mapfile

Definition at line 39 of file PFResolutionMap.cc.

References ReadMapFile().

39  {
40  SetTitle(name);
41  GetXaxis()->SetTitle("#eta");
42  GetYaxis()->SetTitle("E");
43  if( ! ReadMapFile(mapfile) ) {
44  string err = "PFResolutionMap::PFResolutionMap : cannot read file ";
45  err += mapfile;
46  throw invalid_argument(err);
47  }
48 }
bool ReadMapFile(const char *mapfile)
read text file
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 17 of file PFResolutionMap.cc.

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

create a map from a 2d histogram

Definition at line 34 of file PFResolutionMap.h.

References MillePedeFileConverter_cfg::e, PVValHelper::eta, FindBin(), getRes(), phi, ReadMapFile(), WriteMapFile(), and z.

34 : TH2D(h) {}
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.

Member Function Documentation

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

Definition at line 226 of file PFResolutionMap.cc.

References fftjetpileupestimator_calo_uncalib_cfi::c0, constexpr, mps_fire::i, funct::m, M_PI, minimum(), and pi.

Referenced by GetMapFile(), and IsInAPhiCrack().

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

extrapolation requires overloading of this function

Definition at line 176 of file PFResolutionMap.cc.

Referenced by getRes(), and PFResolutionMap().

176  {
177  if(e >= GetYaxis()->GetXmax() )
178  e = GetYaxis()->GetXmax() - 0.001;
179 
180  return TH2D::FindBin(eta,e);
181 }
const char* PFResolutionMap::GetMapFile ( ) const
inline

Definition at line 49 of file PFResolutionMap.h.

References a, b, dCrackPhi(), IsInAPhiCrack(), mapFile_, minimum(), operator<<, MillePedeFileConverter_cfg::out, and submit::rm.

49 {return mapFile_.c_str();}
std::string mapFile_
double PFResolutionMap::getRes ( double  eta,
double  phi,
double  e,
int  MapEta = -1 
)

Definition at line 150 of file PFResolutionMap.cc.

References Abs(), stringResolutionProvider_cfi::bin, constexpr, FindBin(), and IsInAPhiCrack().

Referenced by PFResolutionMap().

150  {
151  constexpr double fMinEta = -2.95;
152  constexpr double fMaxEta = 2.95;
153  constexpr double fMinE=0;
154  constexpr double fMaxE=100;
155 
156  if( eta<fMinEta ) eta = fMinEta+0.001;
157  if( eta>fMaxEta ) eta = fMaxEta-0.001;
158 
159  if( e<fMinE ) e = fMinE+0.001;
160  if( e>fMaxE ) e = fMaxE-0.001;
161 
162  unsigned bin = FindBin(TMath::Abs(eta),e);
163 
164  double res= GetBinContent(bin);
165  if(MapEta>-1){
166  if((eta<1.48) && IsInAPhiCrack(phi,eta)) {
167  if(MapEta==1) res *= 1.88;
168  else res *= 1.65;
169  }
170  }
171  return res;
172 }
Definition: Electron.h:6
T Abs(T a)
Definition: MathUtil.h:49
bin
set the eta bin as selection string.
bool IsInAPhiCrack(double phi, double eta)
int FindBin(double eta, double e, double z=0) override
extrapolation requires overloading of this function
#define constexpr
bool PFResolutionMap::IsInAPhiCrack ( double  phi,
double  eta 
)
private

Definition at line 208 of file PFResolutionMap.cc.

References Abs(), and dCrackPhi().

Referenced by GetMapFile(), and getRes().

208  {
209  double dminPhi = dCrackPhi(phi,eta);
210  bool Is = (TMath::Abs(dminPhi)<0.005);
211  return Is;
212 }
double dCrackPhi(double phi, double eta)
T Abs(T a)
Definition: MathUtil.h:49
double PFResolutionMap::minimum ( double  a,
double  b 
)
private

Definition at line 215 of file PFResolutionMap.cc.

References a, Abs(), and b.

Referenced by dCrackPhi(), and GetMapFile().

215  {
216  if(TMath::Abs(b)<TMath::Abs(a)) a=b;
217  return a;
218 }
T Abs(T a)
Definition: MathUtil.h:49
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
bool PFResolutionMap::ReadMapFile ( const char *  mapfile)

read text file

Definition at line 77 of file PFResolutionMap.cc.

References relativeConstraints::empty, mps_fire::i, spu::inf(), lineSize_, mapFile_, and alignCSCRings::s.

Referenced by PFResolutionMap().

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

write text file is not const because mapFile_ will be updated

Definition at line 51 of file PFResolutionMap.cc.

References mapFile_.

Referenced by PFResolutionMap().

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

Friends And Related Function Documentation

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

print this map

Referenced by GetMapFile().

Member Data Documentation

const unsigned PFResolutionMap::lineSize_ = 10000
staticprivate

Definition at line 58 of file PFResolutionMap.h.

Referenced by ReadMapFile().

std::string PFResolutionMap::mapFile_
private

Definition at line 59 of file PFResolutionMap.h.

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