Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:37

0001 #include "DataFormats/HcalDigi/interface/HcalTTPDigi.h"
0002 
0003 HcalTTPDigi::HcalTTPDigi() : identifier_(0), samples_(0), presamples_(0), fwVersion_(0), algorithm_(0), lPipe_(0) {
0004   for (int i = 0; i < 8; i++) {
0005     algoDepend_[i] = 0;
0006     triggerOutput_[i] = 0;
0007     for (int j = 0; j < 5; j++)
0008       triggerInputs_[j * 8 + i] = 0;
0009   }
0010 }
0011 
0012 HcalTTPDigi::HcalTTPDigi(
0013     int identifier, int samples, int presamples, unsigned int fwVersion, int algorithm, unsigned int lPipe)
0014     : identifier_(identifier),
0015       samples_(samples),
0016       presamples_(presamples),
0017       fwVersion_(fwVersion),
0018       algorithm_(algorithm),
0019       lPipe_(lPipe) {
0020   for (int i = 0; i < 8; i++) {
0021     algoDepend_[i] = 0x0;
0022     triggerOutput_[i] = 0x0;
0023     for (int j = 0; j < 5; j++)
0024       triggerInputs_[i * 5 + j] = 0x0;
0025   }
0026 }
0027 
0028 void HcalTTPDigi::setSample(int relativeSample,
0029                             const uint16_t* triggerInputs,
0030                             const uint32_t algodep,
0031                             const uint8_t outputTrigger) {
0032   int linSample = presamples_ + relativeSample;
0033   if (linSample >= 0 && linSample < samples_) {
0034     // Trigger input: 72 bits
0035     for (int i = 0; i < 4; i++)
0036       triggerInputs_[5 * linSample + i] = triggerInputs[i];
0037     triggerInputs_[5 * linSample + 4] = triggerInputs[4] & 0xFF;
0038     // Algo dependency: 20 bits
0039     algoDepend_[linSample] = algodep & 0xFFFFF;
0040     // Trigger output: 4 bits
0041     triggerOutput_[linSample] = outputTrigger & 0xF;
0042   }
0043 }
0044 
0045 std::vector<bool> HcalTTPDigi::inputPattern(int relativeSample) const {
0046   std::vector<bool> retval;
0047   int linSample = presamples_ + relativeSample;
0048   if (linSample >= 0 && linSample < samples_) {
0049     for (int i = 0; i < 72; i++) {
0050       int ioff = i / 16;
0051       retval.push_back(triggerInputs_[linSample * 5 + ioff] & (1 << (i % 16)));
0052     }
0053   }
0054   return retval;
0055 }
0056 
0057 uint8_t HcalTTPDigi::triggerOutput(int relativeSample) const {
0058   int linSample = presamples_ + relativeSample;
0059   if (linSample >= 0 && linSample < samples_)
0060     return triggerOutput_[linSample];
0061   else
0062     return 0;
0063 }
0064 
0065 uint32_t HcalTTPDigi::algorithmWord(int relativeSample) const {
0066   int linSample = presamples_ + relativeSample;
0067   if (linSample >= 0 && linSample < samples_)
0068     return algoDepend_[linSample];
0069   else
0070     return 0;
0071 }
0072 
0073 bool HcalTTPDigi::operator==(const HcalTTPDigi& digi) const {
0074   if (samples_ != digi.size() || presamples_ != digi.presamples())
0075     return false;
0076   int relativeSize = digi.size() - digi.presamples();
0077   for (int i = -this->presamples(); i < relativeSize; i++) {
0078     if (this->inputPattern(i) != digi.inputPattern(i))
0079       return false;
0080     if (this->algorithmWord(i) != digi.algorithmWord(i))
0081       return false;
0082     if (this->triggerOutput(i) != digi.triggerOutput(i))
0083       return false;
0084   }
0085   return true;
0086 }
0087 
0088 std::ostream& operator<<(std::ostream& out, const HcalTTPDigi& digi) {
0089   out << "HcalTTPDigi " << digi.id() << " with " << digi.size() << " samples, " << digi.presamples() << " presamples. "
0090       << std::endl;
0091   out << "Firmware version " << digi.fwVersion() << " and flavor/algo " << digi.algorithm();
0092   out << "; pipeline length " << digi.pipelineLength() << std::endl;
0093   int relativeSize = digi.size() - digi.presamples();
0094   for (int i = -digi.presamples(); i < relativeSize; i++) {
0095     for (unsigned int j = digi.inputPattern(i).size(); j > 0; j--) {
0096       if (!(j % 16))
0097         out << " ";
0098       out << digi.inputPattern(i).at(j - 1);
0099     }
0100     if (i < 0)
0101       out << " (PRE)";  // Indicates presamples
0102     out << std::endl;
0103     out << "ALGO: ";
0104     for (int j = 19; j >= 0; j--)
0105       out << bool((digi.algorithmWord(i)) & (1 << j));
0106 
0107     out << "  TRIG: ";
0108     for (int j = 3; j >= 0; j--)
0109       out << bool((digi.triggerOutput(i)) & (1 << j));
0110     out << std::endl;
0111   }
0112 
0113   return out;
0114 }