CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/SimTracker/SiStripDigitizer/src/SiTrivialDigitalConverter.cc

Go to the documentation of this file.
00001 #include "SimTracker/SiStripDigitizer/interface/SiTrivialDigitalConverter.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 SiTrivialDigitalConverter::SiTrivialDigitalConverter(float in){
00006   electronperADC = in;
00007   _temp.reserve(800);
00008   _tempRaw.reserve(800);
00009 }
00010 
00011 SiDigitalConverter::DigitalVecType
00012 SiTrivialDigitalConverter::convert(const std::vector<double>& analogSignal, edm::ESHandle<SiStripGain> & gainHandle, unsigned int detid){
00013   
00014   _temp.clear();
00015   
00016   if(gainHandle.isValid()) {
00017     SiStripApvGain::Range detGainRange = gainHandle->getRange(detid);
00018     for ( size_t i=0; i<analogSignal.size(); i++) {
00019       if (analogSignal[i]<=0) continue;
00020       // convert analog amplitude to digital
00021       int adc = convert( (gainHandle->getStripGain(i, detGainRange))*(analogSignal[i]) );
00022       if ( adc > 0) _temp.push_back(SiStripDigi(i, adc));
00023     }
00024   } else {
00025     for ( size_t i=0; i<analogSignal.size(); i++) {
00026       if (analogSignal[i]<=0) continue;
00027       // convert analog amplitude to digital
00028       int adc = convert( analogSignal[i] );
00029       if ( adc > 0) _temp.push_back(SiStripDigi(i, adc));
00030     }
00031   }
00032   return _temp;
00033 }
00034 
00035 SiDigitalConverter::DigitalRawVecType
00036 SiTrivialDigitalConverter::convertRaw(const std::vector<double>& analogSignal, edm::ESHandle<SiStripGain> & gainHandle, unsigned int detid){
00037   
00038   _tempRaw.clear();
00039 
00040   if(gainHandle.isValid()) {
00041     SiStripApvGain::Range detGainRange = gainHandle->getRange(detid);
00042     for ( size_t i=0; i<analogSignal.size(); i++) {
00043       if (analogSignal[i]<=0) { _tempRaw.push_back(SiStripRawDigi(0)); continue; }
00044       // convert analog amplitude to digital
00045       int adc = convertRaw( (gainHandle->getStripGain(i, detGainRange))*(analogSignal[i]));
00046       _tempRaw.push_back(SiStripRawDigi(adc));
00047     }
00048   } else {
00049     for ( size_t i=0; i<analogSignal.size(); i++) {
00050       if (analogSignal[i]<=0) { _tempRaw.push_back(SiStripRawDigi(0)); continue; }
00051       // convert analog amplitude to digital
00052       int adc = convertRaw( analogSignal[i] );
00053       _tempRaw.push_back(SiStripRawDigi(adc));
00054     }
00055   }
00056   return _tempRaw;
00057 }
00058 
00059 int SiTrivialDigitalConverter::truncate(float in_adc) {
00060   //Rounding the ADC number instead of truncating it
00061   int adc = int(in_adc+0.5);
00062   /*
00063     254 ADC: 254  <= raw charge < 1023
00064     255 ADC: raw charge >= 1023
00065   */
00066   if (adc > 1022 ) return 255;
00067   if (adc > 253) return 254;
00068   //Protection
00069   if (adc < 0) return 0;
00070   return adc;
00071 }
00072 
00073 int SiTrivialDigitalConverter::truncateRaw(float in_adc) {
00074   //Rounding the ADC number
00075   int adc = int(in_adc+0.5);
00076   if (adc > 1023 ) return 1023;
00077   //Protection
00078   if (adc < 0) return 0;
00079   return adc;
00080 }
00081