Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:05:05

0001 #include "SimTracker/SiStripDigitizer/interface/SiTrivialDigitalConverter.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 SiTrivialDigitalConverter::SiTrivialDigitalConverter(float in, bool PreMix)
0006     : ADCperElectron(1.f / in), PreMixing_(PreMix) {
0007   _temp.reserve(800);
0008   _tempRaw.reserve(800);
0009 }
0010 
0011 SiDigitalConverter::DigitalVecType const& SiTrivialDigitalConverter::convert(const std::vector<float>& analogSignal,
0012                                                                              const SiStripGain* gain,
0013                                                                              unsigned int detid) {
0014   _temp.clear();
0015 
0016   if (PreMixing_) {
0017     for (size_t i = 0; i < analogSignal.size(); i++) {
0018       if (analogSignal[i] <= 0)
0019         continue;
0020       // convert analog amplitude to digital - special algorithm for PreMixing.
0021       // Need to keep all hits, including those at very low pulse heights.
0022       int adc = truncate(std::sqrt(9.0f * analogSignal[i]));
0023       if (adc > 0)
0024         _temp.push_back(SiStripDigi(i, adc));
0025     }
0026   } else if (gain) {
0027     SiStripApvGain::Range detGainRange = gain->getRange(detid);
0028     for (size_t i = 0; i < analogSignal.size(); i++) {
0029       if (analogSignal[i] <= 0)
0030         continue;
0031       // convert analog amplitude to digital
0032       int adc = convert((gain->getStripGain(i, detGainRange)) * (analogSignal[i]));
0033       if (adc > 0)
0034         _temp.push_back(SiStripDigi(i, adc));
0035     }
0036   } else {
0037     for (size_t i = 0; i < analogSignal.size(); i++) {
0038       if (analogSignal[i] <= 0)
0039         continue;
0040       // convert analog amplitude to digital
0041       int adc = convert(analogSignal[i]);
0042       if (adc > 0)
0043         _temp.push_back(SiStripDigi(i, adc));
0044     }
0045   }
0046   return _temp;
0047 }
0048 
0049 SiDigitalConverter::DigitalRawVecType const& SiTrivialDigitalConverter::convertRaw(
0050     const std::vector<float>& analogSignal, const SiStripGain* gain, unsigned int detid) {
0051   _tempRaw.clear();
0052 
0053   if (gain) {
0054     SiStripApvGain::Range detGainRange = gain->getRange(detid);
0055     for (size_t i = 0; i < analogSignal.size(); i++) {
0056       if (analogSignal[i] <= 0) {
0057         _tempRaw.push_back(SiStripRawDigi(0));
0058         continue;
0059       }
0060       // convert analog amplitude to digital
0061       int adc = convertRaw((gain->getStripGain(i, detGainRange)) * (analogSignal[i]));
0062       _tempRaw.push_back(SiStripRawDigi(adc));
0063     }
0064   } else {
0065     for (size_t i = 0; i < analogSignal.size(); i++) {
0066       if (analogSignal[i] <= 0) {
0067         _tempRaw.push_back(SiStripRawDigi(0));
0068         continue;
0069       }
0070       // convert analog amplitude to digital
0071       int adc = convertRaw(analogSignal[i]);
0072       _tempRaw.push_back(SiStripRawDigi(adc));
0073     }
0074   }
0075   return _tempRaw;
0076 }
0077 
0078 int SiTrivialDigitalConverter::truncate(float in_adc) const {
0079   //Rounding the ADC number instead of truncating it
0080   int adc = int(in_adc + 0.5f);
0081   /*
0082     254 ADC: 254  <= raw charge < 1023
0083     255 ADC: raw charge >= 1023
0084   */
0085   if (PreMixing_) {
0086     if (adc > 2047)
0087       return 1023;
0088     if (adc > 1022)
0089       return 1022;
0090   } else {
0091     if (adc > 1022)
0092       return 255;
0093     if (adc > 253)
0094       return 254;
0095   }
0096   //Protection
0097   if (adc < 0)
0098     return 0;
0099   return adc;
0100 }
0101 
0102 int SiTrivialDigitalConverter::truncateRaw(float in_adc) const {
0103   //Rounding the ADC number
0104   int adc = int(in_adc + 0.5f);
0105   if (adc > 1023)
0106     return 1023;
0107   //Protection
0108   if (adc < 0)
0109     return 0;
0110   return adc;
0111 }