CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CalibMuon/RPCCalibration/src/RPCCalibSetUp.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDProducer.h"
00002 #include "DataFormats/Common/interface/Handle.h"
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "CalibMuon/RPCCalibration/interface/RPCCalibSetUp.h"
00012 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00013 
00014 #include <cmath>
00015 #include <math.h>
00016 #include <fstream>
00017 #include <sstream>
00018 #include <iostream>
00019 #include<cstring>
00020 #include<string>
00021 #include<vector>
00022 #include<stdlib.h>
00023 #include <utility>
00024 #include <map>
00025 
00026 using namespace std;
00027 
00028 RPCCalibSetUp::RPCCalibSetUp(const edm::ParameterSet& ps) {
00029   
00030   _mapDetIdNoise.clear();
00031   _mapDetIdEff.clear();
00032   _bxmap.clear();
00033   _mapDetClsMap.clear();
00034 
00035     //------------------------ Noise Reading ----------------------------
00036     
00037   edm::FileInPath fp1 = ps.getParameter<edm::FileInPath>("noisemapfile");
00038   std::ifstream _infile1(fp1.fullPath().c_str(), std::ios::in);
00039   
00040   std::vector<float>  vnoise;
00041 
00042   int rpcdetid = 0;
00043   std::string buff;
00044   
00045   std::vector< std::string > words;
00046 
00047   int count = 0;
00048   while( getline(_infile1, buff, '\n') ){
00049     
00050     words.clear();
00051     vnoise.clear();
00052     
00053     stringstream ss;
00054     std::string chname;
00055     ss<<buff;
00056     ss>>chname>>rpcdetid;
00057 
00058     std::string::size_type pos = 0, prev_pos = 0;
00059 
00060     while ( (pos = buff.find("  ",pos)) != string::npos){
00061       
00062       words.push_back(buff.substr(prev_pos, pos - prev_pos));
00063       prev_pos = ++pos;
00064     }
00065     words.push_back(buff.substr(prev_pos, pos - prev_pos));
00066     
00067     for(unsigned int i = 2; i < words.size(); ++i){
00068       float value = atof( ((words)[i]).c_str() );
00069       vnoise.push_back(value);
00070     }
00071     
00072     _mapDetIdNoise.insert(make_pair(static_cast<uint32_t>(rpcdetid),vnoise));
00073     
00074     count++;
00075   }
00076    _infile1.close();
00077 
00078   //------------------------ Eff Reading ----------------------------
00079   
00080   edm::FileInPath fp2 = ps.getParameter<edm::FileInPath>("effmapfile");
00081   std::ifstream _infile2(fp2.fullPath().c_str(), std::ios::in);
00082 
00083   std::vector<float> veff ;
00084   rpcdetid = 0;
00085   
00086   while( getline(_infile2, buff, '\n') ){
00087 
00088     words.clear();
00089     veff.clear();
00090     
00091     stringstream ss;
00092     std::string chname;
00093     ss<<buff;
00094     ss>>chname>>rpcdetid;
00095     
00096     std::string::size_type pos = 0, prev_pos = 0;
00097     while ( (pos = buff.find("  ",pos)) != string::npos){
00098       
00099       words.push_back(buff.substr(prev_pos, pos - prev_pos));
00100       prev_pos = ++pos;
00101     }
00102     words.push_back(buff.substr(prev_pos, pos - prev_pos));
00103 
00104     for(unsigned int i = 2; i < words.size(); ++i){
00105       float value = atof(((words)[i]).c_str());
00106       veff.push_back(value);
00107     }
00108     _mapDetIdEff.insert(make_pair(static_cast<uint32_t>(rpcdetid),veff));
00109   }
00110   _infile2.close();
00111 
00112   //---------------------- Timing reading ------------------------------------
00113 
00114   edm::FileInPath fp3 = ps.getParameter<edm::FileInPath>("timingMap");
00115   std::ifstream _infile3(fp3.fullPath().c_str(), std::ios::in);
00116 
00117   uint32_t detUnit = 0;
00118   float timing = 0.;
00119   while(!_infile3.eof()){
00120     _infile3>>detUnit>>timing;
00121     _bxmap[RPCDetId(detUnit)] = timing;
00122   }
00123   _infile3.close();
00124 
00125   //---------------------- Cluster size --------------------------------------
00126 
00127   edm::FileInPath fp4 = ps.getParameter<edm::FileInPath>("clsmapfile");
00128   std::ifstream _infile4(fp4.fullPath().c_str(), ios::in);
00129 
00130   string buffer;
00131   double sum = 0;
00132   unsigned int counter = 1;
00133   unsigned int row = 1;
00134   std::vector<double> sum_clsize;
00135 
00136   while ( _infile4 >> buffer ) {
00137     const char *buffer1 = buffer.c_str();
00138     double dato = atof(buffer1);
00139     sum += dato;
00140     sum_clsize.push_back(sum);
00141 
00142     if(counter == row*20) {
00143       _clsMap[row] = sum_clsize;
00144       row++;
00145       sum = 0;
00146       sum_clsize.clear();
00147     }
00148     counter++;
00149   }
00150   _infile4.close();
00151 
00152   //---------------------- Cluster size Chamber by Chamber -------------------
00153 
00154   edm::FileInPath fp5 = ps.getParameter<edm::FileInPath>("clsidmapfile");
00155   std::ifstream _infile5(fp5.fullPath().c_str(), ios::in);
00156   
00157   std::vector<double> vClsDistrib ;
00158   rpcdetid = 0;
00159 
00160   while( getline(_infile5, buff, '\n') ){
00161 
00162     words.clear();
00163     vClsDistrib.clear();
00164     
00165     stringstream ss1;
00166     ss1<<buff;
00167     ss1>>rpcdetid;
00168     
00169     std::string::size_type pos = 0, prev_pos = 0;
00170     while ( (pos = buff.find("  ",pos)) != string::npos){
00171       
00172       words.push_back(buff.substr(prev_pos, pos - prev_pos));
00173       prev_pos = ++pos;
00174     }
00175     words.push_back(buff.substr(prev_pos, pos - prev_pos));
00176     
00177     float clusterSizeSumData(0.);
00178 
00179     for(unsigned int i = 1; i < words.size(); ++i){
00180       float value = atof(((words)[i]).c_str());
00181       
00182       clusterSizeSumData+=value;
00183           vClsDistrib.push_back(clusterSizeSumData);
00184           if(!(i%20)){ 
00185             clusterSizeSumData=0.;
00186           }
00187     }
00188     if(vClsDistrib.size()!=100){
00189       throw cms::Exception("DataCorrupt") 
00190         << "Exception comming from RPCCalibSetUp - cluster size - a wrong format "<< std::endl;
00191     }
00192     _mapDetClsMap.insert(make_pair(static_cast<uint32_t>(rpcdetid),vClsDistrib));
00193     std::cout<<"_mapDetClsMap.size()\t"<<_mapDetClsMap.size()<<std::endl;
00194   }
00195 
00196   
00197   _infile5.close();
00198   
00199 }
00200 
00201 std::vector<float> RPCCalibSetUp::getNoise(uint32_t id)
00202 {
00203   map<uint32_t,std::vector<float> >::iterator iter = _mapDetIdNoise.find(id);
00204   if(iter == _mapDetIdNoise.end()){
00205     throw cms::Exception("DataCorrupt") 
00206       << "Exception comming from RPCCalibSetUp - no noise information for DetId\t"<<id<< std::endl;
00207   }
00208   return (iter->second);
00209 }
00210 
00211 std::vector<float> RPCCalibSetUp::getEff(uint32_t id)
00212 {
00213   map<uint32_t,std::vector<float> >::iterator iter = _mapDetIdEff.find(id);
00214   if(iter == _mapDetIdEff.end()){
00215     throw cms::Exception("DataCorrupt") 
00216       << "Exception comming from RPCCalibSetUp - no efficiency information for DetId\t"<<id<< std::endl;
00217   }
00218   if((iter->second).size() != 96){
00219     throw cms::Exception("DataCorrupt") 
00220       << "Exception comming from RPCCalibSetUp - efficiency information in a wrong format for DetId\t"<<id<< std::endl;
00221   }
00222   return iter->second;
00223 }
00224 
00225 float RPCCalibSetUp::getTime(uint32_t id)
00226 {
00227   RPCDetId rpcid(id);
00228 
00229   std::map<RPCDetId, float>::iterator iter = _bxmap.find(rpcid);
00230   if(iter == _bxmap.end()){
00231     throw cms::Exception("DataCorrupt") 
00232       << "Exception comming from RPCCalibSetUp - no timing information for rpcid.rawId()\t"<<rpcid.rawId()<< std::endl;
00233   }
00234   return iter->second;
00235 }
00236 
00237 std::map< int, std::vector<double> > RPCCalibSetUp::getClsMap()
00238 {
00239   if(_clsMap.size()!=5){
00240     throw cms::Exception("DataCorrupt") 
00241       << "Exception comming from RPCCalibSetUp - cluster size - a wrong format "<< std::endl;
00242   }
00243   return _clsMap;
00244 }
00245 
00246 std::vector<double> RPCCalibSetUp::getCls(uint32_t id){
00247   std::map<uint32_t,std::vector<double> >::iterator iter = _mapDetClsMap.find(id);
00248   if(iter == _mapDetClsMap.end()){
00249     throw cms::Exception("DataCorrupt") 
00250       << "Exception comming from RPCCalibSetUp - no cluster size information for DetId\t"<<id<< std::endl;
00251   }
00252   if((iter->second).size() != 100){
00253     throw cms::Exception("DataCorrupt") 
00254       << "Exception comming from RPCCalibSetUp - cluster size information in a wrong format for DetId\t"<<id<< std::endl;
00255   }
00256   return iter->second; 
00257 }
00258 
00259 RPCCalibSetUp::~RPCCalibSetUp(){}