CMS 3D CMS Logo

EcalTBCrystalMap.cc
Go to the documentation of this file.
2 
4  // check if File exists
5  std::ifstream* input = new std::ifstream(MapFileName.c_str(), std::ios::in);
6  if (!(*input)) {
7  throw cms::Exception("FileNotFound", "Ecal TB Crystal map file not found")
8  << "\n"
9  << MapFileName << " could not be opened.\n";
10  }
11  if (input) {
12  int nCrysCount = 0;
13 
14  while (nCrysCount <= NCRYSTAL) {
15  (*input) >> crysIndex >> crysEta >> crysPhi;
16  map_[std::pair<double, double>(crysEta, crysPhi)] = crysIndex;
17 
18  nCrysCount++;
19  }
20 
21  input->close();
22  }
23 }
24 
26 
27 int EcalTBCrystalMap::CrystalIndex(double thisEta, double thisPhi) {
28  int thisCrysIndex = 0;
29 
30  CrystalTBIndexMap::const_iterator mapItr = map_.find(std::make_pair(thisEta, thisPhi));
31  if (mapItr != map_.end()) {
32  thisCrysIndex = mapItr->second;
33  }
34 
35  return thisCrysIndex;
36 }
37 
38 void EcalTBCrystalMap::findCrystalAngles(const int thisCrysIndex, double& thisEta, double& thisPhi) {
39  thisEta = thisPhi = 0.;
40 
41  if (thisCrysIndex < 1 || thisCrysIndex > NCRYSTAL) {
42  edm::LogError("OutOfBounds") << "Required crystal number " << thisCrysIndex << " outside range";
43  return;
44  }
45 
46  for (CrystalTBIndexMap::const_iterator mapItr = map_.begin(); mapItr != map_.end(); ++mapItr) {
47  int theCrysIndex = mapItr->second;
48  if (theCrysIndex == thisCrysIndex) {
49  thisEta = (mapItr->first).first;
50  thisPhi = (mapItr->first).second;
51  return;
52  }
53  }
54 }
CrystalTBIndexMap map_
static const int NCRYSTAL
Log< level::Error, false > LogError
static std::string const input
Definition: EdmProvDump.cc:47
U second(std::pair< T, U > const &p)
EcalTBCrystalMap(std::string const &MapFileName)
void findCrystalAngles(const int thisCrysIndex, double &thisEta, double &thisPhi)
int CrystalIndex(double thisEta, double thisPhi)