CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondTools/RPC/src/RPCDBSimSetUp.cc

Go to the documentation of this file.
00001 #include "CondTools/RPC/interface/RPCDBSimSetUp.h"
00002 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00003 
00004 #include <cmath>
00005 #include <math.h>
00006 #include <fstream>
00007 #include <sstream>
00008 #include <iostream>
00009 #include<cstring>
00010 #include<string>
00011 #include<vector>
00012 #include<stdlib.h>
00013 #include <utility>
00014 #include <map>
00015 
00016 using namespace std;
00017 
00018 RPCDBSimSetUp::RPCDBSimSetUp(const edm::ParameterSet& ps) {
00019   
00020   _mapDetIdNoise.clear();
00021   _mapDetIdEff.clear();
00022   _bxmap.clear();
00023 
00024     //------------------------ Noise Reading ----------------------------
00025     
00026   edm::FileInPath fp1 = ps.getParameter<edm::FileInPath>("noisemapfile");
00027   std::ifstream _infile1(fp1.fullPath().c_str(), std::ios::in);
00028   
00029   std::vector<float>  vnoise;
00030 
00031   int rpcdetid = 0;
00032   std::string buff;
00033   
00034   std::vector< std::string > words;
00035 
00036   int count = 0;
00037   while( getline(_infile1, buff, '\n') ){
00038     
00039     words.clear();
00040     vnoise.clear();
00041     
00042     stringstream ss;
00043     std::string chname;
00044     ss<<buff;
00045     ss>>chname>>rpcdetid;
00046 
00047     std::string::size_type pos = 0, prev_pos = 0;
00048 
00049     while ( (pos = buff.find("  ",pos)) != string::npos){
00050       
00051       words.push_back(buff.substr(prev_pos, pos - prev_pos));
00052       prev_pos = ++pos;
00053     }
00054     words.push_back(buff.substr(prev_pos, pos - prev_pos));
00055     
00056     for(unsigned int i = 2; i < words.size(); ++i){
00057       float value = atof( ((words)[i]).c_str() );
00058       vnoise.push_back(value);
00059     }
00060     
00061     _mapDetIdNoise.insert(make_pair(static_cast<uint32_t>(rpcdetid),vnoise));
00062     
00063     count++;
00064   }
00065    _infile1.close();
00066 
00067 
00068   //------------------------ Eff Reading ----------------------------
00069   
00070   edm::FileInPath fp2 = ps.getParameter<edm::FileInPath>("effmapfile");
00071   _infile2 = new ifstream(fp2.fullPath().c_str(), std::ios::in);
00072   
00073   std::vector<float> veff ;
00074   rpcdetid = 0;
00075   
00076   while( getline(*_infile2, buff, '\n') ){
00077     
00078     words.clear();
00079     veff.clear();
00080     
00081     stringstream ss;
00082     std::string chname;
00083     ss<<buff;
00084     ss>>chname>>rpcdetid;
00085     
00086     std::string::size_type pos = 0, prev_pos = 0;
00087     while ( (pos = buff.find("  ",pos)) != string::npos){
00088       
00089       words.push_back(buff.substr(prev_pos, pos - prev_pos));
00090       prev_pos = ++pos;
00091     }
00092     words.push_back(buff.substr(prev_pos, pos - prev_pos));
00093     
00094     for(unsigned int i = 2; i < words.size(); ++i){
00095       float value = atof(((words)[i]).c_str());
00096       veff.push_back(value);
00097     }
00098     _mapDetIdEff.insert(make_pair(static_cast<uint32_t>(rpcdetid),veff));
00099   }
00100   _infile2->close();
00101 
00102   //---------------------- Timing reading ------------------------------------
00103 
00104   edm::FileInPath fp3 = ps.getParameter<edm::FileInPath>("timingMap");
00105   _infile3 = new ifstream(fp3.fullPath().c_str(), std::ios::in);
00106 
00107   uint32_t detUnit = 0;
00108   float timing = 0.;
00109   while(!_infile3->eof()){
00110     *_infile3>>detUnit>>timing;
00111     _bxmap[RPCDetId(detUnit)] = timing;
00112   }
00113   _infile3->close();
00114 
00115   //---------------------- Cluster size --------------------------------------
00116 
00117   edm::FileInPath fp4 = ps.getParameter<edm::FileInPath>("clsmapfile");
00118   _infile4 = new ifstream(fp4.fullPath().c_str(), ios::in);
00119 
00120   string buffer;
00121   double sum = 0;
00122   unsigned int counter = 1;
00123   unsigned int row = 1;
00124   std::vector<double> sum_clsize;
00125 
00126   while ( *_infile4 >> buffer ) {
00127     const char *buffer1 = buffer.c_str();
00128     double dato = atof(buffer1);
00129     sum += dato;
00130     sum_clsize.push_back(sum);
00131 
00132     if(counter == row*20) {
00133       _clsMap[row] = sum_clsize;
00134       row++;
00135       sum = 0;
00136       sum_clsize.clear();
00137     }
00138     counter++;
00139   }
00140   _infile4->close();
00141 }
00142 
00143 std::vector<float> RPCDBSimSetUp::getNoise(uint32_t id)
00144 {
00145   map<uint32_t,std::vector<float> >::iterator iter = _mapDetIdNoise.find(id);
00146   return (iter->second);
00147 }
00148 
00149 std::vector<float> RPCDBSimSetUp::getEff(uint32_t id)
00150 {
00151   map<uint32_t,std::vector<float> >::iterator iter = _mapDetIdEff.find(id);
00152   return iter->second;
00153 }
00154 
00155 float RPCDBSimSetUp::getTime(uint32_t id)
00156 {
00157   RPCDetId rpcid(id);
00158   std::map<RPCDetId, float>::iterator iter = _bxmap.find(rpcid);
00159   return iter->second;
00160 }
00161 
00162 std::map< int, std::vector<double> > RPCDBSimSetUp::getClsMap()
00163 {
00164   return _clsMap;
00165 }
00166 
00167 RPCDBSimSetUp::~RPCDBSimSetUp(){
00168   delete _infile1;
00169   delete _infile2;
00170   delete _infile3;
00171   delete _infile4;
00172 }