Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-06 03:11:18

0001 #include "SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h"
0002 
0003 #include <cassert>
0004 
0005 std::bitset<2> HcalFinegrainBit::compute(const HcalFinegrainBit::Tower& tower) const {
0006   if (version_ == 0) {
0007     std::bitset<2> result;
0008 
0009     // First layer consistent with a MIP
0010     result[0] = tower[is_mip][0];
0011 
0012     // First layer consistent with a MIP, at least one layer with more
0013     // than MIP energy deposition
0014     result[1] = result[0] & (tower[is_above_mip].count() > 0);
0015 
0016     // There layers consistent with a MIP
0017     //    result[2] = tower[is_mip].count() >= 3;
0018 
0019     // Unset
0020     //    result[3] = false;
0021 
0022     return result;
0023   }
0024   if (version_ == 1) {
0025     std::bitset<2> result;
0026 
0027     // All algorithms the same for testing purposes
0028     result[0] = result[1] = tower[is_mip][0];
0029 
0030     return result;
0031   }
0032   if (version_ == 2) {
0033     std::bitset<2> result;
0034 
0035     // All algorithms the same for testing purposes
0036     result[0] = result[1] = true;
0037 
0038     return result;
0039   }
0040   return 0;
0041 }
0042 
0043 // timing/depth LLP bit setting
0044 std::bitset<6> HcalFinegrainBit::compute(const HcalFinegrainBit::TowerTDC& tower, const HcalTrigTowerDetId& id) const {
0045   std::bitset<6> result;
0046 
0047   int tp_ieta = id.ieta();
0048 
0049   int Ndelayed = 0;
0050   int NveryDelayed = 0;
0051   int Nprompt = 0;
0052   int EarlyEnergy = 0;
0053   int DeepEnergy = 0;
0054 
0055   for (size_t i = 0; i < 7; i++) {
0056     int bit12_15set = tower[i].first.first;
0057     bool is_compressed = tower[i].first.second;
0058     int bit12 = (bit12_15set & 0b0001);       // low depth 1,2 energy
0059     int bit13 = (bit12_15set & 0b0010) >> 1;  // high depth 3+ energy
0060     int bit14 = (bit12_15set & 0b0100) >> 2;  // prompt energy passed
0061     int bit15 = (bit12_15set & 0b1000) >> 3;  // delayed energy passed
0062     int TDC = tower[i].second.first;
0063     int ADC = tower[i].second.second;
0064 
0065     // timing bits
0066     if (TDC < 50) {  // exclude error code for TDC in HE (unpacked)
0067       if ((abs(tp_ieta) <= 16) || (i >= 1)) {
0068         // count delayed / prompt hits either in HB, or in HE (excluding depth 1 due to backgrounds in HE)
0069         // Sim packing into Raw, has uncompressed TDC values (0-49) at the trigger primitive level. Packing (compressing HB TDC 6:2) happens in packer.
0070         // Hcal digis have compressed HB TDC (0-3)
0071         if (is_compressed == 1) {
0072           if (TDC == 1 && bit15 == 1)
0073             Ndelayed += 1;
0074           if (TDC == 2 && bit15 == 1)
0075             NveryDelayed += 1;
0076           if (TDC == 0 && bit14 == 1)
0077             Nprompt += 1;
0078         } else {
0079           if (TDC > tdc_boundary[abs(tp_ieta) - 1][i] && TDC <= tdc_boundary[abs(tp_ieta) - 1][i] + 2 && bit15 == 1)
0080             Ndelayed += 1;
0081           if (TDC > tdc_boundary[abs(tp_ieta) - 1][i] + 2 && bit15 == 1)
0082             NveryDelayed += 1;
0083           if (TDC <= tdc_boundary[abs(tp_ieta) - 1][i] && TDC >= 0 && bit14 == 1)
0084             Nprompt += 1;
0085         }
0086       }
0087     }
0088 
0089     // depth bit
0090     if (ADC > 0 && bit12 == 0)
0091       EarlyEnergy +=
0092           1;  // early layers, depth 1 and 2. If bit12 = 0, too much energy in early layers. Require ADC > 0 to ensure valid hit in cell
0093     if (ADC > 0 && bit13 == 1)
0094       DeepEnergy +=
0095           1;  // deep layers, 3+. If bit13 = 1, energy in deep layers. Require ADC > 0 to ensure valid hit in cell
0096   }
0097 
0098   // very delayed (001000), slightly delayed (000100), prompt (000010), depth flag (000001), 2 reserved bits (110000)
0099   if (DeepEnergy > 0 && EarlyEnergy == 0)
0100     result[0] = true;  // 000001
0101   else
0102     result[0] = false;
0103   if (Nprompt > 0)
0104     result[1] = true;  // 000010
0105   else
0106     result[1] = false;
0107   if (Ndelayed > 0)
0108     result[2] = true;  // 000100
0109   else
0110     result[2] = false;
0111   if (NveryDelayed > 0)
0112     result[3] = true;  // 001000
0113   else
0114     result[3] = false;
0115   result[4] = result[5] = false;  // 110000 in HcalTriggerPrimitiveAlgo.cc, set to MIP bits from above
0116 
0117   return result;
0118 }