From 7995cc3f70925d016a38a1778493b11a1f2ec753 Mon Sep 17 00:00:00 2001 From: gk199 Date: Tue, 20 Jul 2021 22:34:08 +0200 Subject: [PATCH 1/2] fine grain bits for timing and depth LLP trigger set, aligned with uHTR 2.5.0 fw implementation --- .../interface/HcalFinegrainBit.h | 37 +++++++++- .../interface/HcalTriggerPrimitiveAlgo.h | 7 ++ .../HcalTrigPrimAlgos/src/HcalFinegrainBit.cc | 69 ++++++++++++++++--- .../src/HcalTriggerPrimitiveAlgo.cc | 28 +++++++- 4 files changed, 131 insertions(+), 10 deletions(-) diff --git a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h index e17151cb09cce..319bf34459387 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h +++ b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h @@ -3,16 +3,20 @@ #include #include +#include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h" class HcalFinegrainBit { public: // see the const definitions below for the meaning of the bit towers. // Each bit is replicated for each depth level typedef std::array, 2> Tower; + // Each pair contains energy and TDC of the cell in that depth of the trigger tower + typedef std::array, 7> TowerTDC; HcalFinegrainBit(int version) : version_(version){}; - std::bitset<4> compute(const Tower&) const; + std::bitset<2> compute(const Tower&) const; + std::bitset<6> compute(const TowerTDC&, const HcalTrigTowerDetId&) const; private: // define the two bits in the tower @@ -20,6 +24,37 @@ class HcalFinegrainBit { const int is_above_mip = 1; int version_; + + // define prompt-delayed TDC range. Note this is offset from depth and ieta by 1 + const int tdc_HE[29][7] = {{8, 14, 15, 17, 0, 0, 0}, + {8, 14, 15, 17, 0, 0, 0}, + {8, 14, 14, 17, 0, 0, 0}, + {8, 14, 14, 17, 0, 0, 0}, + {8, 13, 14, 16, 0, 0, 0}, + {8, 13, 14, 16, 0, 0, 0}, + {8, 12, 14, 15, 0, 0, 0}, + {8, 12, 14, 15, 0, 0, 0}, + {7, 12, 13, 15, 0, 0, 0}, + {7, 12, 13, 15, 0, 0, 0}, + {7, 12, 13, 15, 0, 0, 0}, + {7, 12, 13, 15, 0, 0, 0}, + {7, 11, 12, 14, 0, 0, 0}, + {7, 11, 12, 14, 0, 0, 0}, + {7, 11, 12, 14, 0, 0, 0}, + {7, 11, 12, 7, 0, 0, 0}, + {0, 12, 10, 0, 0, 0, 0}, + {0, 9, 10, 9, 10, 0, 0}, + {16, 9, 9, 9, 11, 10, 0}, + {17, 8, 9, 8, 9, 10, 0}, + {9, 7, 7, 7, 9, 6, 0}, + {8, 7, 7, 6, 6, 6, 0}, + {8, 6, 6, 6, 7, 7, 0}, + {7, 6, 6, 6, 7, 6, 0}, + {7, 6, 6, 6, 6, 6, 0}, + {6, 6, 6, 6, 6, 6, 0}, + {6, 5, 6, 6, 6, 7, 10}, + {9, 9, 9, 5, 5, 6, 6}, + {0, 0, 0, 0, 0, 0, 0}}; }; #endif diff --git a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h index 025b052d8b5d9..b050a2f32a899 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h +++ b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalTriggerPrimitiveAlgo.h @@ -101,6 +101,7 @@ class HcalTriggerPrimitiveAlgo { void addSignal(const IntegerCaloSamples& samples); void addFG(const HcalTrigTowerDetId& id, std::vector& msb); void addUpgradeFG(const HcalTrigTowerDetId& id, int depth, const std::vector>& bits); + void addUpgradeTDCFG(const HcalTrigTowerDetId& id, const QIE11DataFrame& frame); bool passTDC(const QIE10DataFrame& digi, int ts) const; bool validUpgradeFG(const HcalTrigTowerDetId& id, int depth) const; @@ -213,6 +214,10 @@ class HcalTriggerPrimitiveAlgo { typedef std::map FGUpgradeMap; FGUpgradeMap fgUpgradeMap_; + typedef std::vector FGUpgradeTDCContainer; + typedef std::map FGUpgradeTDCMap; + FGUpgradeTDCMap fgUpgradeTDCMap_; + bool upgrade_hb_ = false; bool upgrade_he_ = false; bool upgrade_hf_ = false; @@ -264,6 +269,7 @@ void HcalTriggerPrimitiveAlgo::run(const HcalTPGCoder* incoder, HF_Veto.clear(); fgMap_.clear(); fgUpgradeMap_.clear(); + fgUpgradeTDCMap_.clear(); theHFDetailMap.clear(); theHFUpgradeDetailMap.clear(); @@ -319,6 +325,7 @@ void HcalTriggerPrimitiveAlgo::run(const HcalTPGCoder* incoder, HF_Veto.clear(); fgMap_.clear(); fgUpgradeMap_.clear(); + fgUpgradeTDCMap_.clear(); theHFDetailMap.clear(); theHFUpgradeDetailMap.clear(); diff --git a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc index 4ba753bad376e..ca25f7741838b 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc +++ b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc @@ -2,9 +2,9 @@ #include -std::bitset<4> HcalFinegrainBit::compute(const HcalFinegrainBit::Tower& tower) const { +std::bitset<2> HcalFinegrainBit::compute(const HcalFinegrainBit::Tower& tower) const { if (version_ == 0) { - std::bitset<4> result; + std::bitset<2> result; // First layer consistent with a MIP result[0] = tower[is_mip][0]; @@ -14,28 +14,81 @@ std::bitset<4> HcalFinegrainBit::compute(const HcalFinegrainBit::Tower& tower) c result[1] = result[0] & (tower[is_above_mip].count() > 0); // There layers consistent with a MIP - result[2] = tower[is_mip].count() >= 3; + // result[2] = tower[is_mip].count() >= 3; // Unset - result[3] = false; + // result[3] = false; return result; } if (version_ == 1) { - std::bitset<4> result; + std::bitset<2> result; // All algorithms the same for testing purposes - result[0] = result[1] = result[2] = result[3] = tower[is_mip][0]; + result[0] = result[1] = tower[is_mip][0]; return result; } if (version_ == 2) { - std::bitset<4> result; + std::bitset<2> result; // All algorithms the same for testing purposes - result[0] = result[1] = result[2] = result[3] = true; + result[0] = result[1] = true; return result; } return 0; } + +// timing/depth LLP bit setting +std::bitset<6> HcalFinegrainBit::compute(const HcalFinegrainBit::TowerTDC& tower, const HcalTrigTowerDetId& id) const { + std::bitset<6> result; + + int tp_ieta = id.ieta(); + + int Ndelayed = 0; + int NveryDelayed = 0; + int Nprompt = 0; + const int MinE = 64; + + int DeepEnergy = 0; + int EarlyEnergy = 0; + const int deepLayerMinE = 80; + const int earlyLayerMaxE = 16; + + for(size_t i=0; i<7; i++){ + int ADC = tower[i].first; + int TDC = tower[i].second; + + // timing bits + if (TDC < 50) { // exclude error code for TDC in HE (unpacked) + if (abs(tp_ieta) <= 16) { // in HB, TDC values are compressed. 01 = first delayed range, 10 = second delayed range + if (TDC == 1 && ADC >= MinE ) Ndelayed += 1; + if (TDC == 2 && ADC >= MinE ) NveryDelayed +=1; + if (TDC == 0 && ADC >= MinE ) Nprompt += 1; + } + if (abs(tp_ieta) > 16 && i >= 1) { // in HE, TDC values are uncompressed (0-49). Exclude depth 1 in HE due to backgrounds + if (TDC > tdc_HE[abs(tp_ieta)-1][i] && TDC <= tdc_HE[abs(tp_ieta)-1][i]+2 && ADC >= MinE) Ndelayed += 1; + if (TDC > tdc_HE[abs(tp_ieta)-1][i]+2 && ADC >= MinE) NveryDelayed += 1; + if (TDC <= tdc_HE[abs(tp_ieta)-1][i] && TDC >= 0 && ADC >= MinE) Nprompt += 1; + } + } + + // depth bit + if (i <= 1 && ADC >= earlyLayerMaxE) EarlyEnergy += 1; // early layers, depth 1 and 2 + if (i >= 2 && ADC >= deepLayerMinE) DeepEnergy += 1; // deep layers, 3+ + } + + // very delayed (100000), slightly delayed (010000), prompt (001000), 2 reserved bits (000110), depth flag (000001) + if (DeepEnergy > 0 && EarlyEnergy == 0) result[0] = true; // 000001 + else result[0] = false; + if (Nprompt > 0) result[3] = true; // 001000 + else result[3] = false; + if (Ndelayed > 0) result[4] = true; // 010000 + else result[4] = false; + if (NveryDelayed > 0) result[5] = true; // 100000 + else result[5] = false; + result[1] = result[2] = false; // 000110 in HcalTriggerPrimitiveAlgo.cc, set to MIP bits from above + + return result; +} diff --git a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc index 878ba4e6005fe..8ee2a4a996e11 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc +++ b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc @@ -272,9 +272,11 @@ void HcalTriggerPrimitiveAlgo::addSignal(const QIE11DataFrame& frame) { samples2.setPresamples(frame.presamples()); addSignal(samples2); addUpgradeFG(ids[1], detId.depth(), msb); + addUpgradeTDCFG(ids[1], frame); } addSignal(samples1); addUpgradeFG(ids[0], detId.depth(), msb); + addUpgradeTDCFG(ids[0], frame); } void HcalTriggerPrimitiveAlgo::addSignal(const IntegerCaloSamples& samples) { @@ -422,6 +424,7 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples, unsigned int shrink = filterSamples - 1; auto& msb = fgUpgradeMap_[samples.id()]; + auto& timingTDC = fgUpgradeTDCMap_[samples.id()]; IntegerCaloSamples sum(samples.id(), samples.size()); std::vector ids = theTrigTowerGeometry->towerIds(detId); @@ -496,7 +499,8 @@ void HcalTriggerPrimitiveAlgo::analyzeQIE11(IntegerCaloSamples& samples, output[ibin] = 0; } // peak-finding is not applied for FG bits - finegrain[ibin] = fg_algo.compute(msb[idx]).to_ulong(); + // compute(msb) returns two bits (MIP). compute(timingTDC,ids) returns 6 bits (1 depth, 2 reserved, 1 prompt, 1 delayed 01, 1 delayed 10) + finegrain[ibin] = fg_algo.compute(timingTDC[idx], ids[0]).to_ulong() | fg_algo.compute(msb[idx]).to_ulong() << 1; } outcoder_->compress(output, finegrain, result); } @@ -899,6 +903,28 @@ void HcalTriggerPrimitiveAlgo::addUpgradeFG(const HcalTrigTowerDetId& id, } } +void HcalTriggerPrimitiveAlgo::addUpgradeTDCFG(const HcalTrigTowerDetId& id, const QIE11DataFrame& frame) { + HcalDetId detId(frame.id()); + if (detId.subdet() != HcalEndcap && detId.subdet() != HcalBarrel) + return; + + std::vector ids = theTrigTowerGeometry->towerIds(detId); + assert(ids.size() == 1 || ids.size() == 2); + IntegerCaloSamples samples1(ids[0], int(frame.samples())); + samples1.setPresamples(frame.presamples()); + incoder_->adc2Linear(frame, samples1); // use linearization LUT + + auto it = fgUpgradeTDCMap_.find(id); + if (it == fgUpgradeTDCMap_.end()) { + FGUpgradeTDCContainer element; + element.resize(frame.samples()); + it = fgUpgradeTDCMap_.insert(std::make_pair(id, element)).first; + } + for(int i=0; isecond[i][detId.depth()-1] = std::make_pair(samples1[i], frame[i].tdc()); + } +} + void HcalTriggerPrimitiveAlgo::setWeightsQIE11(const edm::ParameterSet& weightsQIE11) { // Names are just abs(ieta) for HBHE std::vector ietaStrs = weightsQIE11.getParameterNames(); From e1a78f6f840cbd0bf7ca473b998c7d43e10a2003 Mon Sep 17 00:00:00 2001 From: gk199 Date: Thu, 22 Jul 2021 23:53:34 +0200 Subject: [PATCH 2/2] fixing code format changes recommended by cmsbuild after PR --- .../interface/HcalFinegrainBit.h | 38 +++--------- .../HcalTrigPrimAlgos/src/HcalFinegrainBit.cc | 62 ++++++++++++------- .../src/HcalTriggerPrimitiveAlgo.cc | 6 +- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h index 319bf34459387..82ad95b296141 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h +++ b/SimCalorimetry/HcalTrigPrimAlgos/interface/HcalFinegrainBit.h @@ -26,35 +26,15 @@ class HcalFinegrainBit { int version_; // define prompt-delayed TDC range. Note this is offset from depth and ieta by 1 - const int tdc_HE[29][7] = {{8, 14, 15, 17, 0, 0, 0}, - {8, 14, 15, 17, 0, 0, 0}, - {8, 14, 14, 17, 0, 0, 0}, - {8, 14, 14, 17, 0, 0, 0}, - {8, 13, 14, 16, 0, 0, 0}, - {8, 13, 14, 16, 0, 0, 0}, - {8, 12, 14, 15, 0, 0, 0}, - {8, 12, 14, 15, 0, 0, 0}, - {7, 12, 13, 15, 0, 0, 0}, - {7, 12, 13, 15, 0, 0, 0}, - {7, 12, 13, 15, 0, 0, 0}, - {7, 12, 13, 15, 0, 0, 0}, - {7, 11, 12, 14, 0, 0, 0}, - {7, 11, 12, 14, 0, 0, 0}, - {7, 11, 12, 14, 0, 0, 0}, - {7, 11, 12, 7, 0, 0, 0}, - {0, 12, 10, 0, 0, 0, 0}, - {0, 9, 10, 9, 10, 0, 0}, - {16, 9, 9, 9, 11, 10, 0}, - {17, 8, 9, 8, 9, 10, 0}, - {9, 7, 7, 7, 9, 6, 0}, - {8, 7, 7, 6, 6, 6, 0}, - {8, 6, 6, 6, 7, 7, 0}, - {7, 6, 6, 6, 7, 6, 0}, - {7, 6, 6, 6, 6, 6, 0}, - {6, 6, 6, 6, 6, 6, 0}, - {6, 5, 6, 6, 6, 7, 10}, - {9, 9, 9, 5, 5, 6, 6}, - {0, 0, 0, 0, 0, 0, 0}}; + const int tdc_HE[29][7] = { + {8, 14, 15, 17, 0, 0, 0}, {8, 14, 15, 17, 0, 0, 0}, {8, 14, 14, 17, 0, 0, 0}, {8, 14, 14, 17, 0, 0, 0}, + {8, 13, 14, 16, 0, 0, 0}, {8, 13, 14, 16, 0, 0, 0}, {8, 12, 14, 15, 0, 0, 0}, {8, 12, 14, 15, 0, 0, 0}, + {7, 12, 13, 15, 0, 0, 0}, {7, 12, 13, 15, 0, 0, 0}, {7, 12, 13, 15, 0, 0, 0}, {7, 12, 13, 15, 0, 0, 0}, + {7, 11, 12, 14, 0, 0, 0}, {7, 11, 12, 14, 0, 0, 0}, {7, 11, 12, 14, 0, 0, 0}, {7, 11, 12, 7, 0, 0, 0}, + {0, 12, 10, 0, 0, 0, 0}, {0, 9, 10, 9, 10, 0, 0}, {16, 9, 9, 9, 11, 10, 0}, {17, 8, 9, 8, 9, 10, 0}, + {9, 7, 7, 7, 9, 6, 0}, {8, 7, 7, 6, 6, 6, 0}, {8, 6, 6, 6, 7, 7, 0}, {7, 6, 6, 6, 7, 6, 0}, + {7, 6, 6, 6, 6, 6, 0}, {6, 6, 6, 6, 6, 6, 0}, {6, 5, 6, 6, 6, 7, 10}, {9, 9, 9, 5, 5, 6, 6}, + {0, 0, 0, 0, 0, 0, 0}}; }; #endif diff --git a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc index ca25f7741838b..875158b507e2a 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc +++ b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalFinegrainBit.cc @@ -56,39 +56,57 @@ std::bitset<6> HcalFinegrainBit::compute(const HcalFinegrainBit::TowerTDC& tower const int deepLayerMinE = 80; const int earlyLayerMaxE = 16; - for(size_t i=0; i<7; i++){ + for (size_t i = 0; i < 7; i++) { int ADC = tower[i].first; int TDC = tower[i].second; // timing bits - if (TDC < 50) { // exclude error code for TDC in HE (unpacked) - if (abs(tp_ieta) <= 16) { // in HB, TDC values are compressed. 01 = first delayed range, 10 = second delayed range - if (TDC == 1 && ADC >= MinE ) Ndelayed += 1; - if (TDC == 2 && ADC >= MinE ) NveryDelayed +=1; - if (TDC == 0 && ADC >= MinE ) Nprompt += 1; + if (TDC < 50) { // exclude error code for TDC in HE (unpacked) + if (abs(tp_ieta) <= + 16) { // in HB, TDC values are compressed. 01 = first delayed range, 10 = second delayed range + if (TDC == 1 && ADC >= MinE) + Ndelayed += 1; + if (TDC == 2 && ADC >= MinE) + NveryDelayed += 1; + if (TDC == 0 && ADC >= MinE) + Nprompt += 1; } - if (abs(tp_ieta) > 16 && i >= 1) { // in HE, TDC values are uncompressed (0-49). Exclude depth 1 in HE due to backgrounds - if (TDC > tdc_HE[abs(tp_ieta)-1][i] && TDC <= tdc_HE[abs(tp_ieta)-1][i]+2 && ADC >= MinE) Ndelayed += 1; - if (TDC > tdc_HE[abs(tp_ieta)-1][i]+2 && ADC >= MinE) NveryDelayed += 1; - if (TDC <= tdc_HE[abs(tp_ieta)-1][i] && TDC >= 0 && ADC >= MinE) Nprompt += 1; + if (abs(tp_ieta) > 16 && + i >= 1) { // in HE, TDC values are uncompressed (0-49). Exclude depth 1 in HE due to backgrounds + if (TDC > tdc_HE[abs(tp_ieta) - 1][i] && TDC <= tdc_HE[abs(tp_ieta) - 1][i] + 2 && ADC >= MinE) + Ndelayed += 1; + if (TDC > tdc_HE[abs(tp_ieta) - 1][i] + 2 && ADC >= MinE) + NveryDelayed += 1; + if (TDC <= tdc_HE[abs(tp_ieta) - 1][i] && TDC >= 0 && ADC >= MinE) + Nprompt += 1; } } - + // depth bit - if (i <= 1 && ADC >= earlyLayerMaxE) EarlyEnergy += 1; // early layers, depth 1 and 2 - if (i >= 2 && ADC >= deepLayerMinE) DeepEnergy += 1; // deep layers, 3+ + if (i <= 1 && ADC >= earlyLayerMaxE) + EarlyEnergy += 1; // early layers, depth 1 and 2 + if (i >= 2 && ADC >= deepLayerMinE) + DeepEnergy += 1; // deep layers, 3+ } // very delayed (100000), slightly delayed (010000), prompt (001000), 2 reserved bits (000110), depth flag (000001) - if (DeepEnergy > 0 && EarlyEnergy == 0) result[0] = true; // 000001 - else result[0] = false; - if (Nprompt > 0) result[3] = true; // 001000 - else result[3] = false; - if (Ndelayed > 0) result[4] = true; // 010000 - else result[4] = false; - if (NveryDelayed > 0) result[5] = true; // 100000 - else result[5] = false; - result[1] = result[2] = false; // 000110 in HcalTriggerPrimitiveAlgo.cc, set to MIP bits from above + if (DeepEnergy > 0 && EarlyEnergy == 0) + result[0] = true; // 000001 + else + result[0] = false; + if (Nprompt > 0) + result[3] = true; // 001000 + else + result[3] = false; + if (Ndelayed > 0) + result[4] = true; // 010000 + else + result[4] = false; + if (NveryDelayed > 0) + result[5] = true; // 100000 + else + result[5] = false; + result[1] = result[2] = false; // 000110 in HcalTriggerPrimitiveAlgo.cc, set to MIP bits from above return result; } diff --git a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc index 8ee2a4a996e11..d4df6d7521bd4 100644 --- a/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc +++ b/SimCalorimetry/HcalTrigPrimAlgos/src/HcalTriggerPrimitiveAlgo.cc @@ -912,7 +912,7 @@ void HcalTriggerPrimitiveAlgo::addUpgradeTDCFG(const HcalTrigTowerDetId& id, con assert(ids.size() == 1 || ids.size() == 2); IntegerCaloSamples samples1(ids[0], int(frame.samples())); samples1.setPresamples(frame.presamples()); - incoder_->adc2Linear(frame, samples1); // use linearization LUT + incoder_->adc2Linear(frame, samples1); // use linearization LUT auto it = fgUpgradeTDCMap_.find(id); if (it == fgUpgradeTDCMap_.end()) { @@ -920,8 +920,8 @@ void HcalTriggerPrimitiveAlgo::addUpgradeTDCFG(const HcalTrigTowerDetId& id, con element.resize(frame.samples()); it = fgUpgradeTDCMap_.insert(std::make_pair(id, element)).first; } - for(int i=0; isecond[i][detId.depth()-1] = std::make_pair(samples1[i], frame[i].tdc()); + for (int i = 0; i < frame.samples(); i++) { + it->second[i][detId.depth() - 1] = std::make_pair(samples1[i], frame[i].tdc()); } }