Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-09 03:15:14

0001 #include "L1Trigger/L1THGCal/interface/concentrator/HGCalConcentratorSuperTriggerCellImpl.h"
0002 
0003 HGCalConcentratorSuperTriggerCellImpl::HGCalConcentratorSuperTriggerCellImpl(const edm::ParameterSet& conf)
0004     : fixedDataSizePerHGCROC_(conf.getParameter<bool>("fixedDataSizePerHGCROC")),
0005       coarsenTriggerCells_(conf.getParameter<std::vector<unsigned>>("coarsenTriggerCells")),
0006       coarseTCmapping_(conf.getParameter<std::vector<unsigned>>("ctcSize")),
0007       superTCmapping_(conf.getParameter<std::vector<unsigned>>("stcSize")),
0008       calibrationEE_(conf.getParameterSet("superTCCalibration_ee")),
0009       calibrationHEsi_(conf.getParameterSet("superTCCalibration_hesi")),
0010       calibrationHEsc_(conf.getParameterSet("superTCCalibration_hesc")),
0011       calibrationNose_(conf.getParameterSet("superTCCalibration_nose")),
0012       vfeCompression_(conf.getParameterSet("superTCCompression")) {
0013   std::string energyType(conf.getParameter<string>("type_energy_division"));
0014 
0015   if (energyType == "superTriggerCell") {
0016     energyDivisionType_ = superTriggerCell;
0017   } else if (energyType == "oneBitFraction") {
0018     energyDivisionType_ = oneBitFraction;
0019 
0020     oneBitFractionThreshold_ = conf.getParameter<double>("oneBitFractionThreshold");
0021     oneBitFractionLowValue_ = conf.getParameter<double>("oneBitFractionLowValue");
0022     oneBitFractionHighValue_ = conf.getParameter<double>("oneBitFractionHighValue");
0023 
0024   } else if (energyType == "equalShare") {
0025     energyDivisionType_ = equalShare;
0026 
0027   } else {
0028     energyDivisionType_ = superTriggerCell;
0029   }
0030 }
0031 
0032 uint32_t HGCalConcentratorSuperTriggerCellImpl::getCompressedSTCEnergy(const SuperTriggerCell& stc) const {
0033   uint32_t code(0);
0034   uint32_t compressed_value(0);
0035   vfeCompression_.compressSingle(stc.getSumHwPt(), code, compressed_value);
0036   return compressed_value;
0037 }
0038 
0039 void HGCalConcentratorSuperTriggerCellImpl::createAllTriggerCells(
0040     std::unordered_map<unsigned, SuperTriggerCell>& STCs, std::vector<l1t::HGCalTriggerCell>& trigCellVecOutput) const {
0041   for (auto& s : STCs) {
0042     std::vector<uint32_t> output_ids = superTCmapping_.getConstituentTriggerCells(s.second.getSTCId());
0043     if (output_ids.empty())
0044       continue;
0045 
0046     HGCalTriggerTools::SubDetectorType subdet = triggerTools_.getSubDetectorType(output_ids.at(0));
0047     int thickness = (!output_ids.empty() ? triggerTools_.thicknessIndex(output_ids.at(0)) : 0);
0048 
0049     for (const auto& id : output_ids) {
0050       if (((fixedDataSizePerHGCROC_ && thickness > kHighDensityThickness_) || coarsenTriggerCells_[subdet]) &&
0051           (id != coarseTCmapping_.getRepresentativeDetId(id))) {
0052         continue;
0053       }
0054 
0055       if (!triggerTools_.getTriggerGeometry()->validTriggerCell(id)) {
0056         continue;
0057       }
0058 
0059       l1t::HGCalTriggerCell triggerCell;
0060       triggerCell.setDetId(id);
0061       if (energyDivisionType_ == superTriggerCell && id != s.second.getMaxId()) {
0062         continue;
0063       }
0064 
0065       DetId tc_Id(id);
0066 
0067       if (superTCmapping_.getCoarseTriggerCellId(id) != s.second.getSTCId()) {
0068         throw cms::Exception("NonExistingCoarseTC")
0069             << "The coarse trigger cell correponsing to the nominal trigger cell does not exist";
0070       }
0071       trigCellVecOutput.push_back(triggerCell);
0072       if (energyDivisionType_ == oneBitFraction) {  //Get the 1 bit fractions
0073 
0074         if (id != s.second.getMaxId()) {
0075           float tc_fraction = getTriggerCellOneBitFraction(s.second.getTCpt(id), s.second.getSumPt());
0076           s.second.addToFractionSum(tc_fraction);
0077         }
0078       }
0079     }
0080   }
0081   // assign energy
0082   for (l1t::HGCalTriggerCell& tc : trigCellVecOutput) {
0083     const auto& stc = STCs[superTCmapping_.getCoarseTriggerCellId(tc.detId())];
0084     assignSuperTriggerCellEnergyAndPosition(tc, stc);
0085   }
0086 }
0087 
0088 void HGCalConcentratorSuperTriggerCellImpl::assignSuperTriggerCellEnergyAndPosition(l1t::HGCalTriggerCell& c,
0089                                                                                     const SuperTriggerCell& stc) const {
0090   //Compress and recalibrate STC energy
0091   uint32_t compressed_value = getCompressedSTCEnergy(stc);
0092 
0093   HGCalTriggerTools::SubDetectorType subdet = triggerTools_.getSubDetectorType(c.detId());
0094   int thickness = triggerTools_.thicknessIndex(c.detId());
0095 
0096   bool isSilicon = triggerTools_.isSilicon(c.detId());
0097   bool isEM = triggerTools_.isEm(c.detId());
0098   bool isNose = triggerTools_.isNose(c.detId());
0099 
0100   GlobalPoint point;
0101   if ((fixedDataSizePerHGCROC_ && thickness > kHighDensityThickness_) || coarsenTriggerCells_[subdet]) {
0102     point = coarseTCmapping_.getCoarseTriggerCellPosition(coarseTCmapping_.getCoarseTriggerCellId(c.detId()));
0103   } else {
0104     point = triggerTools_.getTCPosition(c.detId());
0105   }
0106   c.setPosition(point);
0107 
0108   math::PtEtaPhiMLorentzVector p4(c.pt(), point.eta(), point.phi(), 0.);
0109   c.setP4(p4);
0110 
0111   if (energyDivisionType_ == superTriggerCell) {
0112     if (c.detId() == stc.getMaxId()) {
0113       c.setHwPt(compressed_value);
0114     } else {
0115       throw cms::Exception("NonMaxIdSuperTriggerCell")
0116           << "Trigger Cell with detId not equal to the maximum of the superTriggerCell found";
0117     }
0118   } else if (energyDivisionType_ == equalShare) {
0119     double coarseTriggerCellSize =
0120         coarsenTriggerCells_[subdet]
0121             ? double(
0122                   coarseTCmapping_.getConstituentTriggerCells(coarseTCmapping_.getCoarseTriggerCellId(stc.getMaxId()))
0123                       .size())
0124             : 1.;
0125 
0126     double denominator =
0127         fixedDataSizePerHGCROC_
0128             ? double(kTriggerCellsForDivision_)
0129             : double(superTCmapping_.getConstituentTriggerCells(stc.getSTCId()).size()) / coarseTriggerCellSize;
0130 
0131     c.setHwPt(std::round(compressed_value / denominator));
0132 
0133   } else if (energyDivisionType_ == oneBitFraction) {
0134     double frac = 0;
0135 
0136     if (c.detId() != stc.getMaxId()) {
0137       frac = getTriggerCellOneBitFraction(stc.getTCpt(c.detId()), stc.getSumPt());
0138     } else {
0139       frac = 1 - stc.getFractionSum();
0140     }
0141 
0142     c.setHwPt(std::round(compressed_value * frac));
0143   }
0144   // calibration
0145   if (isNose) {
0146     calibrationNose_.calibrateInGeV(c);
0147   } else if (isSilicon) {
0148     if (isEM) {
0149       calibrationEE_.calibrateInGeV(c);
0150     } else {
0151       calibrationHEsi_.calibrateInGeV(c);
0152     }
0153   } else {
0154     calibrationHEsc_.calibrateInGeV(c);
0155   }
0156 }
0157 
0158 float HGCalConcentratorSuperTriggerCellImpl::getTriggerCellOneBitFraction(float tcPt, float sumPt) const {
0159   double f = tcPt / sumPt;
0160   double frac = 0;
0161   if (f < oneBitFractionThreshold_) {
0162     frac = oneBitFractionLowValue_;
0163   } else {
0164     frac = oneBitFractionHighValue_;
0165   }
0166 
0167   return frac;
0168 }
0169 
0170 void HGCalConcentratorSuperTriggerCellImpl::select(const std::vector<l1t::HGCalTriggerCell>& trigCellVecInput,
0171                                                    std::vector<l1t::HGCalTriggerCell>& trigCellVecOutput) {
0172   std::unordered_map<unsigned, SuperTriggerCell> STCs;
0173   // first pass, fill the "coarse" trigger cells
0174   for (const l1t::HGCalTriggerCell& tc : trigCellVecInput) {
0175     uint32_t stcid = superTCmapping_.getCoarseTriggerCellId(tc.detId());
0176     STCs[stcid].add(tc, stcid);
0177   }
0178 
0179   createAllTriggerCells(STCs, trigCellVecOutput);
0180 }