CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 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.

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

create a map from text file mapfile

Definition at line 72 of file PFResolutionMap.cc.

References ReadMapFile().

72  {
73  SetTitle(name);
74  GetXaxis()->SetTitle("#eta");
75  GetYaxis()->SetTitle("E");
76  if( ! ReadMapFile(mapfile) ) {
77  string err = "PFResolutionMap::PFResolutionMap : cannot read file ";
78  err += mapfile;
79  throw invalid_argument(err);
80  }
81 }
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 16 of file PFResolutionMap.cc.

20  : TH2D(name, name, nbinseta, mineta, maxeta, nbinse, mine, maxe) {
21  // fNbinsEta(nbinseta), fMinEta(mineta), fMaxEta(maxeta),
22  // fNbinsE(nbinse), fMinE(mine), fMaxE(maxe) {
23 
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 
37 }
PFResolutionMap::PFResolutionMap ( const TH2D &  h)
inline

create a map from a 2d histogram

Definition at line 34 of file PFResolutionMap.h.

34 : TH2D(h) {}
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

Member Function Documentation

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

Definition at line 307 of file PFResolutionMap.cc.

References gather_cfg::cout, i, contentValuesFiles::m, M_PI, minimum(), and pi.

Referenced by IsInAPhiCrack().

307  {
308 
309  static double pi= M_PI;// 3.14159265358979323846;
310 
311  //Location of the 18 phi-cracks
312  static std::vector<double> cPhi;
313  cPhi.resize(18,0);
314  cPhi[0]=2.97025;
315  for(unsigned i=1;i<=17;i++) cPhi[i]=cPhi[0]-2*i*pi/18;
316 
317  //Shift of this location if eta<0
318  static double delta_cPhi=0.00638;
319 
320  double m; //the result
321 
322  //the location is shifted
323  if(eta<0){
324  phi +=delta_cPhi;
325  if(phi>pi) phi-=2*pi;
326  }
327  if (phi>=-pi && phi<=pi){
328 
329  //the problem of the extrema
330  if (phi<cPhi[17] || phi>=cPhi[0]){
331  if (phi<0) phi+= 2*pi;
332  m = minimum(phi -cPhi[0],phi-cPhi[17]-2*pi);
333  }
334 
335  //between these extrema...
336  else{
337  bool OK = false;
338  unsigned i=16;
339  while(!OK){
340  if (phi<cPhi[i]){
341  m=minimum(phi-cPhi[i+1],phi-cPhi[i]);
342  OK=true;
343  }
344  else i-=1;
345  }
346  }
347  }
348  else{
349  m=0.; //if there is a problem, we assum that we are in a crack
350  std::cout<<"Problem in dminphi"<<std::endl;
351  }
352  if(eta<0) m=-m; //because of the disymetry
353  return m;
354 }
int i
Definition: DBlmapReader.cc:9
double minimum(double a, double b)
#define M_PI
T eta() const
const Double_t pi
std::pair< int, edm::FunctionWithDict > OK
Definition: findMethod.cc:136
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
int PFResolutionMap::FindBin ( double  eta,
double  e 
)

extrapolation requires overloading of this function

Definition at line 257 of file PFResolutionMap.cc.

Referenced by getRes().

257  {
258  if(e >= GetYaxis()->GetXmax() )
259  e = GetYaxis()->GetXmax() - 0.001;
260 
261  return TH2D::FindBin(eta,e);
262 }
T eta() const
const char* PFResolutionMap::GetMapFile ( ) const
inline

Definition at line 49 of file PFResolutionMap.h.

References mapFile_.

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

Definition at line 231 of file PFResolutionMap.cc.

References Abs(), newFWLiteAna::bin, FindBin(), and IsInAPhiCrack().

231  {
232  static double fMinEta = -2.95;
233  static double fMaxEta = 2.95;
234  static double fMinE=0;
235  static double fMaxE=100;
236 
237  if( eta<fMinEta ) eta = fMinEta+0.001;
238  if( eta>fMaxEta ) eta = fMaxEta-0.001;
239 
240  if( e<fMinE ) e = fMinE+0.001;
241  if( e>fMaxE ) e = fMaxE-0.001;
242 
243  unsigned bin = FindBin(TMath::Abs(eta),e);
244 
245  double res= GetBinContent(bin);
246  if(MapEta>-1){
247  if((eta<1.48) && IsInAPhiCrack(phi,eta)) {
248  if(MapEta==1) res *= 1.88;
249  else res *= 1.65;
250  }
251  }
252  return res;
253 }
int FindBin(double eta, double e)
extrapolation requires overloading of this function
T eta() const
T Abs(T a)
Definition: MathUtil.h:49
bool IsInAPhiCrack(double phi, double eta)
Definition: DDAxes.h:10
bool PFResolutionMap::IsInAPhiCrack ( double  phi,
double  eta 
)
private

Definition at line 289 of file PFResolutionMap.cc.

References Abs(), and dCrackPhi().

Referenced by getRes().

289  {
290  double dminPhi = dCrackPhi(phi,eta);
291  bool Is = (TMath::Abs(dminPhi)<0.005);
292  return Is;
293 }
double dCrackPhi(double phi, double eta)
T eta() const
T Abs(T a)
Definition: MathUtil.h:49
Definition: DDAxes.h:10
double PFResolutionMap::minimum ( double  a,
double  b 
)
private

Definition at line 296 of file PFResolutionMap.cc.

References a, Abs(), and b.

Referenced by dCrackPhi().

296  {
297  if(TMath::Abs(b)<TMath::Abs(a)) a=b;
298  return a;
299 }
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 110 of file PFResolutionMap.cc.

References relativeConstraints::empty, i, EcalCondDB::inf, j, lineSize_, mapFile_, and alignCSCRings::s.

Referenced by PFResolutionMap().

110  {
111 
112  // open the file
113 
114  std::ifstream inf(mapfile);
115  if( !inf.good() ) {
116  // cout<<"PFResolutionMap::Read : cannot open file "<<mapfile<<endl;
117  return false;
118  }
119 
120  // first data describes the map
121 
122  int nbinseta=0;
123  double mineta=0;
124  double maxeta=0;
125 
126  int nbinse=0;
127  double mine=0;
128  double maxe=0;
129 
130  inf>>nbinseta;
131  inf>>mineta;
132  inf>>maxeta;
133 
134  inf>>nbinse;
135  inf>>mine;
136  inf>>maxe;
137 
138  SetBins(nbinseta, mineta, maxeta, nbinse, mine, maxe);
139 
140  // Init(fNbinsEta,fMinEta,fMaxEta,fNbinsE,fMinE,fMaxE);
141 
142  // char data[lineSize_];
143  char s[lineSize_];
144  int pos=inf.tellg();
145 
146  // parse map data
147  int i=1;
148  do {
149  inf.seekg(pos);
150  inf.getline(s,lineSize_);
151 
152  pos = inf.tellg();
153 
154  if(string(s).empty()) {
155  continue; // remove empty lines
156  }
157 
158  istringstream lin(s);
159 
160  double dataw;
161  int j=1;
162  do {
163  lin>>dataw;
164  SetBinContent(j, i, dataw);
165  j++;
166  } while (lin.good() );
167  i++;
168  } while(inf.good());
169 
170  if(inf.eof()) {
171  mapFile_ = mapfile;
172  return true;
173  }
174  else {
175  // cout<<"error"<<endl;
176  return false;
177  }
178 
179  mapFile_ = mapfile;
180  return true;
181 }
int i
Definition: DBlmapReader.cc:9
static const unsigned lineSize_
std::string mapFile_
string inf
Definition: EcalCondDB.py:94
int j
Definition: DBlmapReader.cc:9
bool PFResolutionMap::WriteMapFile ( const char *  mapfile)

write text file is not const because mapFile_ will be updated

Definition at line 84 of file PFResolutionMap.cc.

References dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, and mapFile_.

84  {
85 
86  // assert(fData.size() == fNbinsEta*fNbinsE);
87 
88 
89  // open the file
90 
91  std::ofstream outf(mapfile);
92  if( !outf.good() ) {
93  cout<<"PFResolutionMap::Write : cannot open file "<<mapfile<<endl;
94  return false;
95  }
96 
97  outf<<(*this)<<endl;
98  if(!outf.good() ) {
99  cerr<<"PFResolutionMap::Write : corrupted file "<<mapfile<<endl;
100  return false;
101  }
102  else {
103  mapFile_ = mapfile;
104  return true;
105  }
106 }
std::string mapFile_
tuple cout
Definition: gather_cfg.py:121

Friends And Related Function Documentation

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

print this map

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().