Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:29:26

0001 #include "SimCalorimetry/EcalSimAlgos/interface/EcalSignalGenerator.h"
0002 
0003 template <>
0004 CaloSamples EcalSignalGenerator<EBDigitizerTraits>::samplesInPE(const DIGI &digi) {
0005   // calibration, for future reference:  (same block for all Ecal types)
0006   //EcalDetId cell = digi.id();
0007   //         const EcalCalibrations& calibrations=conditions->getEcalCalibrations(cell);
0008   //const EcalQIECoder* channelCoder = theConditions->getEcalCoder (cell);
0009   //const EcalQIEShape* channelShape = theConditions->getEcalShape (cell);
0010   //EcalCoderDb coder (*channelCoder, *channelShape);
0011   //CaloSamples result;
0012   //coder.adc2fC(digi, result);
0013   //fC2pe(result);
0014 
0015   DetId detId = digi.id();
0016 
0017   double Emax = fullScaleEnergy(detId);
0018   double LSB[NGAINS + 1];
0019 
0020   //double icalconst = findIntercalibConstant( detId );
0021 
0022   double icalconst = 1.;  // find the correct value.
0023 
0024   const EcalIntercalibConstantMCMap &icalMap = ical->getMap();
0025   EcalIntercalibConstantMCMap::const_iterator icalit = icalMap.find(detId);
0026   if (icalit != icalMap.end()) {
0027     icalconst = (*icalit);
0028   }
0029 
0030   double peToA = peToAConversion(detId);
0031 
0032   const std::vector<float> gainRatios = GetGainRatios(detId);
0033 
0034   for (unsigned int igain(0); igain <= NGAINS; ++igain) {
0035     LSB[igain] = 0.;
0036     if (igain > 0)
0037       LSB[igain] = Emax / (MAXADC * gainRatios[igain]);
0038   }
0039 
0040   //    std::cout << " intercal, LSBs, egains " << icalconst << " " << LSB[0] << " " << LSB[1] << " " << gainRatios[0] << " " << gainRatios[1] << " " << Emax << std::endl;
0041 
0042   CaloSamples result(detId, digi.size());
0043 
0044   // correction factor for premixed sample: ratio of laser corrections
0045   double correction_factor_for_premixed_sample_transparency = 1.0;
0046   double value_LC = 1.;
0047   if (m_timeDependent) {
0048     if (detId.subdetId() != EcalSubdetector::EcalPreshower) {
0049       auto cache = m_valueLCCache_LC.find(detId);
0050       if (cache != m_valueLCCache_LC.end()) {
0051         value_LC = cache->second;
0052       } else {
0053         value_LC = findLaserConstant_LC(detId);
0054         m_valueLCCache_LC.emplace(detId, value_LC);
0055       }
0056     }
0057   }
0058 
0059   double value_LC_prime = 1.;
0060 
0061   if (m_timeDependent) {
0062     if (detId.subdetId() != EcalSubdetector::EcalPreshower) {
0063       auto cache = m_valueLCCache_LC_prime.find(detId);
0064       if (cache != m_valueLCCache_LC_prime.end()) {
0065         value_LC_prime = cache->second;
0066       } else {
0067         value_LC_prime = findLaserConstant_LC_prime(detId);
0068         m_valueLCCache_LC_prime.emplace(detId, value_LC_prime);
0069       }
0070     }
0071   }
0072 
0073   correction_factor_for_premixed_sample_transparency = value_LC_prime / value_LC;
0074   //
0075   // LC' /  LC  (see formula)
0076   //
0077 
0078   for (int isample = 0; isample < digi.size(); ++isample) {
0079     int gainId = digi[isample].gainId();
0080     //int gainId = 1;
0081 
0082     if (gainId == 1) {
0083       result[isample] = float(digi[isample].adc()) / 1000. / peToA *
0084                         correction_factor_for_premixed_sample_transparency;  // special coding, save low level info
0085     } else if (gainId > 1) {
0086       result[isample] =
0087           float(digi[isample].adc()) * LSB[gainId - 1] * icalconst / peToA *
0088           correction_factor_for_premixed_sample_transparency;  // bet that no pileup hit has an energy over Emax/2
0089     }                                                          // gain = 0
0090     else {
0091       result[isample] =
0092           float(digi[isample].adc()) * LSB[gainId] * icalconst / peToA *
0093           correction_factor_for_premixed_sample_transparency;  //not sure we ever get here at gain=0, but hit wil be saturated anyway
0094       // in EcalCoder.cc it is actually "LSB[3]" -> grrr
0095     }
0096 
0097     // old version:
0098     //result[isample] = float(digi[isample].adc())*LSB[gainId]*icalconst/peToA;
0099   }
0100 
0101   //std::cout << " EcalSignalGenerator:EB noise input " << digi << std::endl;
0102 
0103   //std::cout << " converted noise sample " << std::endl;
0104   //for(int isample = 0; isample<digi.size(); ++isample){
0105   //  std::cout << " " << result[isample] ;
0106   //}
0107   //std::cout << std::endl;
0108 
0109   return result;
0110 }
0111 
0112 template <>
0113 CaloSamples EcalSignalGenerator<EEDigitizerTraits>::samplesInPE(const DIGI &digi) {
0114   // calibration, for future reference:  (same block for all Ecal types)
0115   //EcalDetId cell = digi.id();
0116   //         const EcalCalibrations& calibrations=conditions->getEcalCalibrations(cell);
0117   //const EcalQIECoder* channelCoder = theConditions->getEcalCoder (cell);
0118   //const EcalQIEShape* channelShape = theConditions->getEcalShape (cell);
0119   //EcalCoderDb coder (*channelCoder, *channelShape);
0120   //CaloSamples result;
0121   //coder.adc2fC(digi, result);
0122   //fC2pe(result);
0123 
0124   DetId detId = digi.id();
0125 
0126   double Emax = fullScaleEnergy(detId);
0127   double LSB[NGAINS + 1];
0128 
0129   double icalconst = 1.;  //findIntercalibConstant( detId );
0130 
0131   const EcalIntercalibConstantMCMap &icalMap = ical->getMap();
0132   EcalIntercalibConstantMCMap::const_iterator icalit = icalMap.find(detId);
0133   if (icalit != icalMap.end()) {
0134     icalconst = (*icalit);
0135   }
0136 
0137   double peToA = peToAConversion(detId);
0138 
0139   const std::vector<float> gainRatios = GetGainRatios(detId);
0140 
0141   for (unsigned int igain(0); igain <= NGAINS; ++igain) {
0142     LSB[igain] = 0.;
0143     if (igain > 0)
0144       LSB[igain] = Emax / (MAXADC * gainRatios[igain]);
0145   }
0146 
0147   //    std::cout << " intercal, LSBs, egains " << icalconst << " " << LSB[0] << " " << LSB[1] << " " << gainRatios[0] << " " << gainRatios[1] << " " << Emax << std::endl;
0148 
0149   CaloSamples result(detId, digi.size());
0150 
0151   // correction facotr for premixed sample: ratio of laser corrections
0152   double correction_factor_for_premixed_sample_transparency = 1.0;
0153   double value_LC = 1.;
0154 
0155   if (m_timeDependent) {
0156     if (detId.subdetId() != EcalSubdetector::EcalPreshower) {
0157       auto cache = m_valueLCCache_LC.find(detId);
0158       if (cache != m_valueLCCache_LC.end()) {
0159         value_LC = cache->second;
0160       } else {
0161         value_LC = findLaserConstant_LC(detId);
0162         m_valueLCCache_LC.emplace(detId, value_LC);
0163       }
0164     }
0165   }
0166 
0167   double value_LC_prime = 1.;
0168   if (m_timeDependent) {
0169     if (detId.subdetId() != EcalSubdetector::EcalPreshower) {
0170       auto cache = m_valueLCCache_LC_prime.find(detId);
0171       if (cache != m_valueLCCache_LC_prime.end()) {
0172         value_LC_prime = cache->second;
0173       } else {
0174         value_LC_prime = findLaserConstant_LC_prime(detId);
0175         m_valueLCCache_LC_prime.emplace(detId, value_LC_prime);
0176       }
0177     }
0178   }
0179 
0180   correction_factor_for_premixed_sample_transparency = value_LC_prime / value_LC;
0181   //
0182   // LC' /  LC  (see formula)
0183   //
0184 
0185   for (int isample = 0; isample < digi.size(); ++isample) {
0186     int gainId = digi[isample].gainId();
0187     //int gainId = 1;
0188 
0189     if (gainId == 1) {
0190       result[isample] = float(digi[isample].adc()) / 1000. / peToA *
0191                         correction_factor_for_premixed_sample_transparency;  // special coding
0192     } else if (gainId > 1) {
0193       result[isample] = float(digi[isample].adc()) * LSB[gainId - 1] * icalconst / peToA *
0194                         correction_factor_for_premixed_sample_transparency;
0195     }  // gain = 0
0196     else {
0197       result[isample] = float(digi[isample].adc()) * LSB[gainId] * icalconst / peToA *
0198                         correction_factor_for_premixed_sample_transparency;
0199     }
0200 
0201     // old version
0202     //result[isample] = float(digi[isample].adc())*LSB[gainId]*icalconst/peToA;
0203   }
0204 
0205   //std::cout << " EcalSignalGenerator:EE noise input " << digi << std::endl;
0206 
0207   //std::cout << " converted noise sample " << std::endl;
0208   //for(int isample = 0; isample<digi.size(); ++isample){
0209   //  std::cout << " " << result[isample] ;
0210   // }
0211   //std::cout << std::endl;
0212 
0213   return result;
0214 }
0215 
0216 template <>
0217 CaloSamples EcalSignalGenerator<ESDigitizerTraits>::samplesInPE(const DIGI &digi) {
0218   // calibration, for future reference:  (same block for all Ecal types)
0219   //EcalDetId cell = digi.id();
0220   //         const EcalCalibrations& calibrations=conditions->getEcalCalibrations(cell);
0221   //const EcalQIECoder* channelCoder = theConditions->getEcalCoder (cell);
0222   //const EcalQIEShape* channelShape = theConditions->getEcalShape (cell);
0223   //EcalCoderDb coder (*channelCoder, *channelShape);
0224   //CaloSamples result;
0225   //coder.adc2fC(digi, result);
0226   //fC2pe(result);
0227 
0228   DetId detId = digi.id();
0229 
0230   double icalconst = 1.;  //findIntercalibConstant( detId );
0231 
0232   const ESIntercalibConstantMap &icalMap = esmips->getMap();
0233   ESIntercalibConstantMap::const_iterator icalit = icalMap.find(detId);
0234   if (icalit != icalMap.end()) {
0235     icalconst = double(*icalit);
0236   }
0237 
0238   CaloSamples result(detId, digi.size());
0239 
0240   for (int isample = 0; isample < digi.size(); ++isample) {
0241     result[isample] = float(digi[isample].adc()) / icalconst * ESMIPToGeV;
0242   }
0243 
0244   //std::cout << " EcalSignalGenerator:ES noise input " << digi << std::endl;
0245 
0246   //std::cout << " converted noise sample " << std::endl;
0247   //for(int isample = 0; isample<digi.size(); ++isample){
0248   //  std::cout << " " << result[isample] ;
0249   //}
0250   //std::cout << std::endl;
0251 
0252   return result;
0253 }