CMS 3D CMS Logo

EffectiveAreas.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 #include <fstream>
6 #include <string>
7 #include <sstream>
8 
10  filename_(filename)
11 {
12 
13  // Open the file with the effective area constants
14  std::ifstream inputFile;
15  inputFile.open(filename_.c_str());
16  if( !inputFile.is_open() )
17  throw cms::Exception("EffectiveAreas config failure")
18  << "failed to open the file " << filename_ << std::endl;
19 
20  // Read file line by line
22  const float undef = -999;
23  while( getline(inputFile, line) ){
24  if(line[0]=='#') continue; // skip the comments lines
25  float etaMin = undef, etaMax = undef, effArea = undef;
26  std::stringstream ss(line);
27  ss >> etaMin >> etaMax >> effArea;
28  // In case if the format is messed up, there are letters
29  // instead of numbers, or not exactly three numbers in the line,
30  // it is likely that one or more of these vars never changed
31  // the original "undef" value:
32  if( etaMin==undef || etaMax==undef || effArea==undef )
33  throw cms::Exception("EffectiveAreas config failure")
34  << "wrong file format, file name " << filename_ << std::endl;
35 
36  absEtaMin_ .push_back( etaMin );
37  absEtaMax_ .push_back( etaMax );
38  effectiveAreaValues_.push_back( effArea );
39  }
40 
41  // Extra consistency checks are in the function below.
42  // If any of them fail, an exception is thrown.
44 }
45 
47 }
48 
49 // Return effective area for given eta
50 const float EffectiveAreas::getEffectiveArea(float eta) const{
51 
52  float effArea = 0;
53  uint nEtaBins = absEtaMin_.size();
54  for(uint iEta = 0; iEta<nEtaBins; iEta++){
55  if( std::abs(eta) >= absEtaMin_[iEta]
56  && std::abs(eta) < absEtaMax_[iEta] ){
57  effArea = effectiveAreaValues_[iEta];
58  break;
59  }
60  }
61 
62  return effArea;
63 }
64 
66 
67  printf("EffectiveAreas: source file %s\n", filename_.c_str());
68  printf(" eta_min eta_max effective area\n");
69  uint nEtaBins = absEtaMin_.size();
70  for(uint iEta = 0; iEta<nEtaBins; iEta++){
71  printf(" %8.4f %8.4f %8.5f\n",
72  absEtaMin_[iEta], absEtaMax_[iEta],
73  effectiveAreaValues_[iEta]);
74  }
75 
76 }
77 
78 // Basic common sense checks
80 
81  // There should be at least one eta range with one constant
82  if( effectiveAreaValues_.size() == 0 )
83  throw cms::Exception("EffectiveAreas config failure")
84  << "found no effective area constans in the file "
85  << filename_ << std::endl;
86 
87  uint nEtaBins = absEtaMin_.size();
88  for(uint iEta = 0; iEta<nEtaBins; iEta++){
89 
90  // The low limit should be lower than the upper limit
91  if( !( absEtaMin_[iEta] < absEtaMax_[iEta] ) )
92  throw cms::Exception("EffectiveAreas config failure")
93  << "eta ranges improperly defined (min>max) in the file"
94  << filename_ << std::endl;
95 
96  // The low limit of the next range should be (near) equal to the
97  // upper limit of the previous range
98  if( iEta != nEtaBins-1 ) // don't do the check for the last bin
99  if( !( absEtaMin_[iEta+1] - absEtaMax_[iEta] < 0.0001 ) )
100  throw cms::Exception("EffectiveAreas config failure")
101  << "eta ranges improperly defined (disjointed) in the file "
102  << filename_ << std::endl;
103 
104  // The effective area should be non-negative number,
105  // and should be less than the whole calorimeter area
106  // eta range -2.5 to 2.5, phi 0 to 2pi => Amax = 5*2*pi ~= 31.4
107  if( !( effectiveAreaValues_[iEta] >= 0
108  && effectiveAreaValues_[iEta] < 31.4 ) )
109  throw cms::Exception("EffectiveAreas config failure")
110  << "effective area values are too large or negative in the file"
111  << filename_ << std::endl;
112  }
113 
114 }
const float getEffectiveArea(float eta) const
EffectiveAreas(const std::string &filename)
std::vector< float > absEtaMax_
std::vector< float > effectiveAreaValues_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< float > absEtaMin_
void checkConsistency() const
void printEffectiveAreas() const
const std::string filename_