CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/Geometry/EcalTestBeam/src/EcalTBCrystalMap.cc

Go to the documentation of this file.
00001 #include "Geometry/EcalTestBeam/interface/EcalTBCrystalMap.h"
00002 
00003 EcalTBCrystalMap::EcalTBCrystalMap(std::string const & MapFileName) {
00004                                                                                                                                           
00005   // check if File exists
00006   std::ifstream * input= new std::ifstream(MapFileName.c_str(), std::ios::in);
00007   if(! (*input))
00008     {
00009       throw cms::Exception("FileNotFound", "Ecal TB Crystal map file not found") 
00010         <<  "\n" << MapFileName << " could not be opened.\n";
00011    }
00012   if (input){
00013 
00014     int nCrysCount = 0;
00015 
00016     while (nCrysCount <= NCRYSTAL ) {
00017       
00018       (*input) >> crysIndex >> crysEta >>  crysPhi;
00019       map_[std::pair<double,double>(crysEta,crysPhi)] = crysIndex;
00020 
00021       nCrysCount++;
00022       
00023     }
00024 
00025     input->close();
00026   }
00027 
00028 }
00029 
00030 EcalTBCrystalMap::~EcalTBCrystalMap() {
00031 }
00032 
00033 int EcalTBCrystalMap::CrystalIndex(double thisEta, double thisPhi) {
00034 
00035   int thisCrysIndex = 0;
00036 
00037   CrystalTBIndexMap::const_iterator mapItr = map_.find(std::make_pair(thisEta,thisPhi));
00038   if ( mapItr != map_.end() ) {
00039     thisCrysIndex = mapItr->second;
00040   }
00041 
00042   return thisCrysIndex;
00043 
00044 }
00045 
00046 void EcalTBCrystalMap::findCrystalAngles(const int thisCrysIndex, double & thisEta, double & thisPhi) {
00047   
00048   thisEta = thisPhi = 0.;
00049 
00050   if ( thisCrysIndex < 1 || thisCrysIndex > NCRYSTAL ) {
00051     edm::LogError("OutOfBounds") << "Required crystal number " << thisCrysIndex << " outside range";
00052     return;
00053   }
00054 
00055   for ( CrystalTBIndexMap::const_iterator mapItr = map_.begin() ; mapItr != map_.end() ; ++mapItr) {
00056     int theCrysIndex = mapItr->second;
00057     if ( theCrysIndex == thisCrysIndex ) {
00058       thisEta = (mapItr->first).first;
00059       thisPhi = (mapItr->first).second;
00060       return;
00061     }
00062   }
00063 
00064 }