Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-01 06:57:36

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) : electronperADC(in), PreMixing_(PreMix) {
0006   _temp.reserve(800);
0007   _tempRaw.reserve(800);
0008 }
0009 
0010 SiDigitalConverter::DigitalVecType SiTrivialDigitalConverter::convert(const std::vector<float>& analogSignal,
0011                                                                       const SiStripGain* gain,
0012                                                                       unsigned int detid) {
0013   _temp.clear();
0014 
0015   if (PreMixing_) {
0016     for (size_t i = 0; i < analogSignal.size(); i++) {
0017       if (analogSignal[i] <= 0)
0018         continue;
0019       // convert analog amplitude to digital - special algorithm for PreMixing.
0020       // Need to keep all hits, including those at very low pulse heights.
0021       int adc = truncate(sqrt(9.0 * analogSignal[i]));
0022       if (adc > 0)
0023         _temp.push_back(SiStripDigi(i, adc));
0024     }
0025   } else if (gain) {
0026     SiStripApvGain::Range detGainRange = gain->getRange(detid);
0027     for (size_t i = 0; i < analogSignal.size(); i++) {
0028       if (analogSignal[i] <= 0)
0029         continue;
0030       // convert analog amplitude to digital
0031       int adc = convert((gain->getStripGain(i, detGainRange)) * (analogSignal[i]));
0032       if (adc > 0)
0033         _temp.push_back(SiStripDigi(i, adc));
0034     }
0035   } else {
0036     for (size_t i = 0; i < analogSignal.size(); i++) {
0037       if (analogSignal[i] <= 0)
0038         continue;
0039       // convert analog amplitude to digital
0040       int adc = convert(analogSignal[i]);
0041       if (adc > 0)
0042         _temp.push_back(SiStripDigi(i, adc));
0043     }
0044   }
0045   return _temp;
0046 }
0047 
0048 SiDigitalConverter::DigitalRawVecType SiTrivialDigitalConverter::convertRaw(const std::vector<float>& analogSignal,
0049                                                                             const SiStripGain* gain,
0050                                                                             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.5);
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.5);
0105   if (adc > 1023)
0106     return 1023;
0107   //Protection
0108   if (adc < 0)
0109     return 0;
0110   return adc;
0111 }