File indexing completed on 2023-03-17 13:02:56
0001 #include "Geometry/EcalTestBeam/interface/EcalTBCrystalMap.h"
0002
0003 EcalTBCrystalMap::EcalTBCrystalMap(std::string const& MapFileName) {
0004
0005 std::ifstream* input = new std::ifstream(MapFileName.c_str(), std::ios::in);
0006 if (!(*input)) {
0007 throw cms::Exception("FileNotFound", "Ecal TB Crystal map file not found")
0008 << "\n"
0009 << MapFileName << " could not be opened.\n";
0010 }
0011 if (input) {
0012 int nCrysCount = 0;
0013
0014 while (nCrysCount <= NCRYSTAL) {
0015 (*input) >> crysIndex >> crysEta >> crysPhi;
0016 map_[std::pair<double, double>(crysEta, crysPhi)] = crysIndex;
0017
0018 nCrysCount++;
0019 }
0020
0021 input->close();
0022 }
0023 }
0024
0025 EcalTBCrystalMap::~EcalTBCrystalMap() {}
0026
0027 int EcalTBCrystalMap::CrystalIndex(double thisEta, double thisPhi) {
0028 int thisCrysIndex = 0;
0029
0030 CrystalTBIndexMap::const_iterator mapItr = map_.find(std::make_pair(thisEta, thisPhi));
0031 if (mapItr != map_.end()) {
0032 thisCrysIndex = mapItr->second;
0033 }
0034
0035 return thisCrysIndex;
0036 }
0037
0038 void EcalTBCrystalMap::findCrystalAngles(const int thisCrysIndex, double& thisEta, double& thisPhi) {
0039 thisEta = thisPhi = 0.;
0040
0041 if (thisCrysIndex < 1 || thisCrysIndex > NCRYSTAL) {
0042 edm::LogError("OutOfBounds") << "Required crystal number " << thisCrysIndex << " outside range";
0043 return;
0044 }
0045
0046 for (CrystalTBIndexMap::const_iterator mapItr = map_.begin(); mapItr != map_.end(); ++mapItr) {
0047 int theCrysIndex = mapItr->second;
0048 if (theCrysIndex == thisCrysIndex) {
0049 thisEta = (mapItr->first).first;
0050 thisPhi = (mapItr->first).second;
0051 return;
0052 }
0053 }
0054 }