Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSignalGenerator.h"
0002 
0003 //specializations

0004 
0005 template <>
0006 bool HcalSignalGenerator<HcalQIE10DigitizerTraits>::validDigi(
0007     const HcalSignalGenerator<HcalQIE10DigitizerTraits>::DIGI& digi) {
0008   int DigiSum = 0;
0009   for (int id = 0; id < digi.samples(); id++) {
0010     if (digi[id].adc() > 0)
0011       ++DigiSum;
0012   }
0013   return (DigiSum > 0);
0014 }
0015 
0016 template <>
0017 CaloSamples HcalSignalGenerator<HcalQIE10DigitizerTraits>::samplesInPE(
0018     const HcalSignalGenerator<HcalQIE10DigitizerTraits>::DIGI& digi) {
0019   HcalDetId cell = digi.id();
0020   CaloSamples result = CaloSamples(cell, digi.samples());
0021 
0022   // first, check if there was an overflow in this fake digi:

0023   bool overflow = false;
0024   // find and list them

0025 
0026   for (int isample = 0; isample < digi.samples(); ++isample) {
0027     //only check error bit for non-zero ADCs

0028     if (digi[isample].adc() > 0 && !digi[isample].ok())
0029       overflow = true;
0030   }
0031 
0032   if (overflow) {  // do full conversion, go back and overwrite fake entries

0033     const HcalQIECoder* channelCoder = theConditions->getHcalCoder(cell);
0034     const HcalQIEShape* channelShape = theConditions->getHcalShape(cell);
0035     HcalCoderDb coder(*channelCoder, *channelShape);
0036     coder.adc2fC(digi, result);
0037 
0038     // overwrite with coded information

0039     for (int isample = 0; isample < digi.samples(); ++isample) {
0040       if (digi[isample].ok())
0041         result[isample] = float(digi[isample].adc()) / HcalQIE10DigitizerTraits::PreMixFactor;
0042     }
0043   } else {  // saves creating the coder, etc., every time

0044     // use coded information

0045     for (int isample = 0; isample < digi.samples(); ++isample) {
0046       result[isample] = float(digi[isample].adc()) / HcalQIE10DigitizerTraits::PreMixFactor;
0047       if (digi[isample].soi())
0048         result.setPresamples(isample);
0049     }
0050   }
0051 
0052   // translation done in fC, convert to pe:

0053   fC2pe(result);
0054 
0055   return result;
0056 }
0057 
0058 template <>
0059 void HcalSignalGenerator<HcalQIE10DigitizerTraits>::fillDigis(
0060     const HcalSignalGenerator<HcalQIE10DigitizerTraits>::COLLECTION* digis) {
0061   // loop over digis, adding these to the existing maps

0062   for (typename COLLECTION::const_iterator it = digis->begin(); it != digis->end(); ++it) {
0063     QIE10DataFrame df(*it);
0064     // for the first signal, set the starting cap id

0065     if ((it == digis->begin()) && theElectronicsSim) {
0066       int startingCapId = df[0].capid();
0067       theElectronicsSim->setStartingCapId(startingCapId);
0068     }
0069     if (validDigi(df)) {
0070       theNoiseSignals.push_back(samplesInPE(df));
0071     }
0072   }
0073 }
0074 
0075 template <>
0076 bool HcalSignalGenerator<HcalQIE11DigitizerTraits>::validDigi(
0077     const HcalSignalGenerator<HcalQIE11DigitizerTraits>::DIGI& digi) {
0078   int DigiSum = 0;
0079   for (int id = 0; id < digi.samples(); id++) {
0080     if (digi[id].adc() > 0)
0081       ++DigiSum;
0082   }
0083   return (DigiSum > 0);
0084 }
0085 
0086 template <>
0087 CaloSamples HcalSignalGenerator<HcalQIE11DigitizerTraits>::samplesInPE(
0088     const HcalSignalGenerator<HcalQIE11DigitizerTraits>::DIGI& digi) {
0089   HcalDetId cell = digi.id();
0090   CaloSamples result = CaloSamples(cell, digi.samples());
0091 
0092   // first, check if there was an overflow in this fake digi:

0093   bool overflow = false;
0094   // find and list them

0095 
0096   for (int isample = 0; isample < digi.samples(); ++isample) {
0097     if (digi[isample].tdc() == 1) {
0098       overflow = true;
0099       break;
0100     }
0101   }
0102 
0103   if (overflow) {  // do full conversion, go back and overwrite fake entries

0104     const HcalQIECoder* channelCoder = theConditions->getHcalCoder(cell);
0105     const HcalQIEShape* channelShape = theConditions->getHcalShape(cell);
0106     HcalCoderDb coder(*channelCoder, *channelShape);
0107     coder.adc2fC(digi, result);
0108 
0109     // overwrite with coded information

0110     for (int isample = 0; isample < digi.samples(); ++isample) {
0111       if (digi[isample].tdc() == 0)
0112         result[isample] = float(digi[isample].adc()) / HcalQIE11DigitizerTraits::PreMixFactor;
0113     }
0114   } else {  // saves creating the coder, etc., every time

0115     // use coded information

0116     for (int isample = 0; isample < digi.samples(); ++isample) {
0117       result[isample] = float(digi[isample].adc()) / HcalQIE11DigitizerTraits::PreMixFactor;
0118       if (digi[isample].soi())
0119         result.setPresamples(isample);
0120     }
0121   }
0122 
0123   // translation done in fC, convert to pe:

0124   fC2pe(result);
0125 
0126   return result;
0127 }
0128 
0129 template <>
0130 void HcalSignalGenerator<HcalQIE11DigitizerTraits>::fillDigis(
0131     const HcalSignalGenerator<HcalQIE11DigitizerTraits>::COLLECTION* digis) {
0132   // loop over digis, adding these to the existing maps

0133   for (typename COLLECTION::const_iterator it = digis->begin(); it != digis->end(); ++it) {
0134     QIE11DataFrame df(*it);
0135     // for the first signal, set the starting cap id

0136     if ((it == digis->begin()) && theElectronicsSim) {
0137       int startingCapId = df[0].capid();
0138       theElectronicsSim->setStartingCapId(startingCapId);
0139     }
0140     if (validDigi(df)) {
0141       theNoiseSignals.push_back(samplesInPE(df));
0142     }
0143   }
0144 }