Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:20

0001 #include "CondTools/RPC/interface/RPCDBSimSetUp.h"
0002 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0003 
0004 #include <cmath>
0005 #include <cmath>
0006 #include <fstream>
0007 #include <sstream>
0008 #include <iostream>
0009 #include <cstring>
0010 #include <string>
0011 #include <vector>
0012 #include <cstdlib>
0013 #include <utility>
0014 #include <map>
0015 
0016 using namespace std;
0017 
0018 RPCDBSimSetUp::RPCDBSimSetUp(const edm::ParameterSet& ps) {
0019   _mapDetIdNoise.clear();
0020   _mapDetIdEff.clear();
0021   _bxmap.clear();
0022 
0023   //------------------------ Noise Reading ----------------------------
0024 
0025   edm::FileInPath fp1 = ps.getParameter<edm::FileInPath>("noisemapfile");
0026   std::ifstream _infile1(fp1.fullPath().c_str(), std::ios::in);
0027 
0028   std::vector<float> vnoise;
0029 
0030   int rpcdetid = 0;
0031   std::string buff;
0032 
0033   std::vector<std::string> words;
0034 
0035   int count = 0;
0036   while (getline(_infile1, buff, '\n')) {
0037     words.clear();
0038     vnoise.clear();
0039 
0040     stringstream ss;
0041     std::string chname;
0042     ss << buff;
0043     ss >> chname >> rpcdetid;
0044 
0045     std::string::size_type pos = 0, prev_pos = 0;
0046 
0047     while ((pos = buff.find("  ", pos)) != string::npos) {
0048       words.push_back(buff.substr(prev_pos, pos - prev_pos));
0049       prev_pos = ++pos;
0050     }
0051     words.push_back(buff.substr(prev_pos, pos - prev_pos));
0052 
0053     for (unsigned int i = 2; i < words.size(); ++i) {
0054       float value = atof(((words)[i]).c_str());
0055       vnoise.push_back(value);
0056     }
0057 
0058     _mapDetIdNoise.insert(make_pair(static_cast<uint32_t>(rpcdetid), vnoise));
0059 
0060     count++;
0061   }
0062   _infile1.close();
0063 
0064   //------------------------ Eff Reading ----------------------------
0065 
0066   edm::FileInPath fp2 = ps.getParameter<edm::FileInPath>("effmapfile");
0067   _infile2 = new ifstream(fp2.fullPath().c_str(), std::ios::in);
0068 
0069   std::vector<float> veff;
0070   rpcdetid = 0;
0071 
0072   while (getline(*_infile2, buff, '\n')) {
0073     words.clear();
0074     veff.clear();
0075 
0076     stringstream ss;
0077     std::string chname;
0078     ss << buff;
0079     ss >> chname >> rpcdetid;
0080 
0081     std::string::size_type pos = 0, prev_pos = 0;
0082     while ((pos = buff.find("  ", pos)) != string::npos) {
0083       words.push_back(buff.substr(prev_pos, pos - prev_pos));
0084       prev_pos = ++pos;
0085     }
0086     words.push_back(buff.substr(prev_pos, pos - prev_pos));
0087 
0088     for (unsigned int i = 2; i < words.size(); ++i) {
0089       float value = atof(((words)[i]).c_str());
0090       veff.push_back(value);
0091     }
0092     _mapDetIdEff.insert(make_pair(static_cast<uint32_t>(rpcdetid), veff));
0093   }
0094   _infile2->close();
0095 
0096   //---------------------- Timing reading ------------------------------------
0097 
0098   edm::FileInPath fp3 = ps.getParameter<edm::FileInPath>("timingMap");
0099   _infile3 = new ifstream(fp3.fullPath().c_str(), std::ios::in);
0100 
0101   uint32_t detUnit = 0;
0102   float timing = 0.;
0103   while (!_infile3->eof()) {
0104     *_infile3 >> detUnit >> timing;
0105     _bxmap[RPCDetId(detUnit)] = timing;
0106   }
0107   _infile3->close();
0108 
0109   //---------------------- Cluster size --------------------------------------
0110 
0111   edm::FileInPath fp4 = ps.getParameter<edm::FileInPath>("clsmapfile");
0112   _infile4 = new ifstream(fp4.fullPath().c_str(), ios::in);
0113 
0114   string buffer;
0115   double sum = 0;
0116   unsigned int counter = 1;
0117   unsigned int row = 1;
0118   std::vector<double> sum_clsize;
0119 
0120   while (*_infile4 >> buffer) {
0121     const char* buffer1 = buffer.c_str();
0122     double dato = atof(buffer1);
0123     sum += dato;
0124     sum_clsize.push_back(sum);
0125 
0126     if (counter == row * 20) {
0127       _clsMap[row] = sum_clsize;
0128       row++;
0129       sum = 0;
0130       sum_clsize.clear();
0131     }
0132     counter++;
0133   }
0134   _infile4->close();
0135 }
0136 
0137 std::vector<float> RPCDBSimSetUp::getNoise(uint32_t id) {
0138   map<uint32_t, std::vector<float> >::iterator iter = _mapDetIdNoise.find(id);
0139   return (iter->second);
0140 }
0141 
0142 std::vector<float> RPCDBSimSetUp::getEff(uint32_t id) {
0143   map<uint32_t, std::vector<float> >::iterator iter = _mapDetIdEff.find(id);
0144   return iter->second;
0145 }
0146 
0147 float RPCDBSimSetUp::getTime(uint32_t id) {
0148   RPCDetId rpcid(id);
0149   std::map<RPCDetId, float>::iterator iter = _bxmap.find(rpcid);
0150   return iter->second;
0151 }
0152 
0153 std::map<int, std::vector<double> > RPCDBSimSetUp::getClsMap() { return _clsMap; }
0154 
0155 RPCDBSimSetUp::~RPCDBSimSetUp() {
0156   delete _infile1;
0157   delete _infile2;
0158   delete _infile3;
0159   delete _infile4;
0160 }