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