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