Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:42

0001 #include "L1Trigger/L1THGCal/interface/HGCalCoarseTriggerCellMapping.h"
0002 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0003 
0004 HGCalCoarseTriggerCellMapping::HGCalCoarseTriggerCellMapping(const std::vector<unsigned>& ctcSize)
0005     : ctcSize_(!ctcSize.empty() ? ctcSize
0006                                 : std::vector<unsigned>{kNHGCalLayersMax_ * kNThicknesses_, kCTCsizeVeryFine_}) {
0007   if (ctcSize_.size() != (kNHGCalLayersMax_ + 1) * kNThicknesses_) {
0008     throw cms::Exception("HGCTriggerParameterError")
0009         << "Inconsistent size of coarse trigger cell size vector " << ctcSize_.size();
0010   }
0011 
0012   for (auto ctc : ctcSize_)
0013     checkSizeValidity(ctc);
0014 }
0015 
0016 const std::map<int, int> HGCalCoarseTriggerCellMapping::kSplit_ = {
0017     {kCTCsizeIndividual_, kSplit_Individual_},
0018     {kCTCsizeVeryFine_, kSplit_VeryFine_},
0019     {kCTCsizeFine_, kSplit_Fine_},
0020     {kCTCsizeMid_, kSplit_Mid_},
0021     {kCTCsizeCoarse_, kSplit_Coarse_},
0022 };
0023 
0024 const std::map<int, int> HGCalCoarseTriggerCellMapping::kSplit_Scin_ = {
0025     {kCTCsizeIndividual_, kSplit_Scin_Individual_},
0026     {kCTCsizeVeryFine_, kSplit_Scin_VeryFine_},
0027     {kCTCsizeFine_, kSplit_Scin_Fine_},
0028     {kCTCsizeMid_, kSplit_Scin_Mid_},
0029     {kCTCsizeCoarse_, kSplit_Scin_Coarse_},
0030 };
0031 
0032 void HGCalCoarseTriggerCellMapping::checkSizeValidity(int ctcSize) const {
0033   if (ctcSize != kCTCsizeFine_ && ctcSize != kCTCsizeCoarse_ && ctcSize != kCTCsizeMid_ &&
0034       ctcSize != kCTCsizeVeryFine_ && ctcSize != kCTCsizeIndividual_) {
0035     throw cms::Exception("HGCTriggerParameterError")
0036         << "Coarse Trigger Cell should be of size " << kCTCsizeIndividual_ << " or " << kCTCsizeVeryFine_ << " or "
0037         << kCTCsizeFine_ << " or " << kCTCsizeMid_ << " or " << kCTCsizeCoarse_;
0038   }
0039 }
0040 
0041 uint32_t HGCalCoarseTriggerCellMapping::getRepresentativeDetId(uint32_t tcid) const {
0042   uint32_t representativeid = 0;
0043   //Firstly get coarse trigger cell Id
0044   uint32_t ctcId = getCoarseTriggerCellId(tcid);
0045   //Get list of the constituent TCs, and choose (arbitrarily) the first one
0046   representativeid = getConstituentTriggerCells(ctcId).at(0);
0047   if (triggerTools_.getTriggerGeometry()->validTriggerCell(representativeid)) {
0048     return representativeid;
0049   } else {
0050     return tcid;
0051   }
0052 }
0053 
0054 uint32_t HGCalCoarseTriggerCellMapping::getCoarseTriggerCellId(uint32_t detid) const {
0055   unsigned int layer = triggerTools_.layerWithOffset(detid);
0056   int thickness = triggerTools_.thicknessIndex(detid);
0057 
0058   int ctcSize = ctcSize_.at(thickness * kNHGCalLayersMax_ + layer);
0059 
0060   DetId tc_Id(detid);
0061   if (tc_Id.det() == DetId::HGCalTrigger || tc_Id.det() == DetId::HGCalHSc) {
0062     if (triggerTools_.isScintillator(detid)) {
0063       HGCScintillatorDetId tc_Id(detid);
0064 
0065       int tcSplit = (((tc_Id.ietaAbs() - 1) << HGCScintillatorDetId::kHGCalRadiusOffset) | (tc_Id.iphi() - 1)) &
0066                     kSplit_Scin_.at(ctcSize);
0067 
0068       detid = (detid & kHGCalScinCellMaskInv_) | tcSplit;
0069 
0070       return detid;
0071 
0072     } else {
0073       HGCalTriggerDetId tc_Id(detid);
0074 
0075       int uPrime = 0;
0076       int vPrime = 0;
0077       int rocnum = detIdToROC_.getROCNumber(tc_Id.triggerCellU(), tc_Id.triggerCellV(), 1);
0078 
0079       if (rocnum == kRoc0deg_) {
0080         uPrime = tc_Id.triggerCellU();
0081         vPrime = tc_Id.triggerCellV() - tc_Id.triggerCellU();
0082 
0083       } else if (rocnum == kRoc120deg_) {
0084         uPrime = tc_Id.triggerCellU() - tc_Id.triggerCellV() - 1;
0085         vPrime = tc_Id.triggerCellV();
0086 
0087       } else if (rocnum == kRoc240deg_) {
0088         uPrime = tc_Id.triggerCellV() - kRotate4_;
0089         vPrime = kRotate7_ - tc_Id.triggerCellU();
0090       }
0091 
0092       int tcSplit = (rocnum << kRocShift_) | ((uPrime << kUShift_ | vPrime) & kSplit_.at(ctcSize));
0093       detid = (detid & kHGCalCellMaskInv_) | tcSplit;
0094       return detid;
0095     }
0096 
0097   } else {
0098     return 0;
0099   }
0100 }
0101 
0102 std::vector<uint32_t> HGCalCoarseTriggerCellMapping::getConstituentTriggerCells(uint32_t ctcId) const {
0103   int thickness = triggerTools_.thicknessIndex(ctcId);
0104   unsigned int layer = triggerTools_.layerWithOffset(ctcId);
0105   int ctcSize = ctcSize_.at(thickness * kNHGCalLayersMax_ + layer);
0106 
0107   std::vector<uint32_t> output_ids;
0108   DetId tc_Id(ctcId);
0109 
0110   if (tc_Id.det() == DetId::HGCalTrigger || tc_Id.det() == DetId::HGCalHSc) {
0111     if (triggerTools_.isScintillator(ctcId)) {
0112       int splitInv = ~(kHGCalScinCellMaskInv_ | kSplit_Scin_.at(ctcSize));
0113       for (int i = 0; i < splitInv + 1; i++) {
0114         if ((i & splitInv) != i)
0115           continue;
0116 
0117         HGCScintillatorDetId prime = (ctcId | i);
0118         unsigned outid = (ctcId & kHGCalScinCellMaskInv_) |
0119                          (((prime.iradiusAbs() + 1) << HGCScintillatorDetId::kHGCalRadiusOffset) | (prime.iphi() + 1));
0120 
0121         if (triggerTools_.getTriggerGeometry()->validTriggerCell(outid)) {
0122           output_ids.emplace_back(outid);
0123         }
0124       }
0125 
0126     } else {
0127       int splitInv = ~(kSTCidMaskInv_ | kSplit_.at(ctcSize));
0128       for (int i = 0; i < splitInv + 1; i++) {
0129         if ((i & splitInv) != i)
0130           continue;
0131         int uPrime = ((ctcId | i) >> kUShift_) & kUMask_;
0132         int vPrime = ((ctcId | i) >> kVShift_) & kVMask_;
0133         int rocnum = (ctcId >> kRocShift_) & kRocMask_;
0134 
0135         int u = 0;
0136         int v = 0;
0137 
0138         if (rocnum == kRoc0deg_) {
0139           u = uPrime;
0140           v = vPrime + u;
0141         } else if (rocnum == kRoc120deg_) {
0142           u = uPrime + vPrime + 1;
0143           v = vPrime;
0144         } else if (rocnum == kRoc240deg_) {
0145           u = kRotate7_ - vPrime;
0146           v = uPrime + kRotate4_;
0147         }
0148 
0149         uint32_t outid = ctcId & kHGCalCellMaskInv_;
0150         outid |= (((u & HGCalTriggerDetId::kHGCalCellUMask) << HGCalTriggerDetId::kHGCalCellUOffset) |
0151                   ((v & HGCalTriggerDetId::kHGCalCellVMask) << HGCalTriggerDetId::kHGCalCellVOffset));
0152 
0153         if (triggerTools_.getTriggerGeometry()->validTriggerCell(outid)) {
0154           output_ids.emplace_back(outid);
0155         }
0156       }
0157     }
0158   }
0159   return output_ids;
0160 }
0161 
0162 GlobalPoint HGCalCoarseTriggerCellMapping::getCoarseTriggerCellPosition(uint32_t ctcId) const {
0163   std::vector<uint32_t> constituentTCs = getConstituentTriggerCells(ctcId);
0164   Basic3DVector<float> average_vector(0., 0., 0.);
0165 
0166   for (const auto constituent : constituentTCs) {
0167     average_vector += triggerTools_.getTCPosition(constituent).basicVector();
0168   }
0169 
0170   GlobalPoint average_point(average_vector / constituentTCs.size());
0171   return average_point;
0172 }