Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:31

0001 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
0002 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTJetSummaryCard.h"
0003 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h"
0004 
0005 #include <iostream>
0006 using std::cout;
0007 using std::endl;
0008 #include <vector>
0009 using std::vector;
0010 #include <bitset>
0011 using std::bitset;
0012 
0013 L1RCTJetSummaryCard::L1RCTJetSummaryCard(int crtNo, const L1RCTLookupTables *rctLookupTables)
0014     : crtNo(crtNo),
0015       rctLookupTables_(rctLookupTables),
0016       isolatedEGObjects(4),
0017       nonisolatedEGObjects(4),
0018       jetRegions(22),
0019       HFRegions(8),
0020       barrelRegions(14),
0021       mipBits(0),
0022       quietBits(0),
0023       tauBits(0),
0024       overFlowBits(0),
0025       hfFineGrainBits(8)
0026 // quietThreshold(3)
0027 {}
0028 
0029 void L1RCTJetSummaryCard::fillHFRegionSums(const std::vector<unsigned short> &hfRegionSums) {
0030   // std::cout << "JSC.fillHFRegionSums() entered" << std::endl;
0031   for (int i = 0; i < 8; i++) {
0032     // std::cout << "filling hf region at " << i << std::endl;
0033     HFRegions.at(i) = rctLookupTables_->lookup((hfRegionSums.at(i) / 2), crtNo, 999, i);
0034     // std::cout << "hf region " << i << " et filled" << std::endl;
0035     hfFineGrainBits.at(i) = (hfRegionSums.at(i) & 1);
0036     // std::cout << "hf region " << i << " fine grain bit filled" << std::endl;
0037   }
0038 }
0039 
0040 void L1RCTJetSummaryCard::fillJetRegions() {
0041   if (crtNo < 9) {
0042     for (int i = 0; i < 4; i++) {
0043       jetRegions.at(i) = HFRegions.at(i);
0044       jetRegions.at(i + 11) = HFRegions.at(i + 4);
0045     }
0046     jetRegions.at(4) = barrelRegions.at(12);
0047     jetRegions.at(5) = barrelRegions.at(9);
0048     jetRegions.at(6) = barrelRegions.at(8);
0049     jetRegions.at(7) = barrelRegions.at(5);
0050     jetRegions.at(8) = barrelRegions.at(4);
0051     jetRegions.at(9) = barrelRegions.at(1);
0052     jetRegions.at(10) = barrelRegions.at(0);
0053 
0054     jetRegions.at(15) = barrelRegions.at(13);
0055     jetRegions.at(16) = barrelRegions.at(11);
0056     jetRegions.at(17) = barrelRegions.at(10);
0057     jetRegions.at(18) = barrelRegions.at(7);
0058     jetRegions.at(19) = barrelRegions.at(6);
0059     jetRegions.at(20) = barrelRegions.at(3);
0060     jetRegions.at(21) = barrelRegions.at(2);
0061   }
0062   if (crtNo >= 9) {
0063     jetRegions.at(0) = barrelRegions.at(0);
0064     jetRegions.at(1) = barrelRegions.at(1);
0065     jetRegions.at(2) = barrelRegions.at(4);
0066     jetRegions.at(3) = barrelRegions.at(5);
0067     jetRegions.at(4) = barrelRegions.at(8);
0068     jetRegions.at(5) = barrelRegions.at(9);
0069     jetRegions.at(6) = barrelRegions.at(12);
0070 
0071     jetRegions.at(11) = barrelRegions.at(2);
0072     jetRegions.at(12) = barrelRegions.at(3);
0073     jetRegions.at(13) = barrelRegions.at(6);
0074     jetRegions.at(14) = barrelRegions.at(7);
0075     jetRegions.at(15) = barrelRegions.at(10);
0076     jetRegions.at(16) = barrelRegions.at(11);
0077     jetRegions.at(17) = barrelRegions.at(13);
0078     for (int i = 0; i < 4; i++) {
0079       jetRegions.at(i + 7) = HFRegions.at(i);
0080       jetRegions.at(i + 18) = HFRegions.at(i + 4);
0081     }
0082   }
0083 }
0084 
0085 void L1RCTJetSummaryCard::fillIsolatedEGObjects(const std::vector<unsigned short> &isoElectrons) {
0086   // sort(isoElectrons.begin(),isoElectrons.end());
0087   // reverse(isoElectrons.begin(),isoElectrons.end());
0088 
0089   std::vector<unsigned short> isoCards03(8);
0090   std::vector<unsigned short> isoCards46(8);
0091   std::vector<unsigned short> sortIso(8);
0092 
0093   for (int i = 0; i < 8; i++) {
0094     isoCards03.at(i) = isoElectrons.at(i);
0095   }
0096   for (int i = 0; i < 6; i++) {
0097     isoCards46.at(i) = isoElectrons.at(i + 8);
0098   }
0099   isoCards46.at(6) = 0;
0100   isoCards46.at(7) = 0;
0101 
0102   asicSort(isoCards03);
0103   asicSort(isoCards46);
0104 
0105   sortIso.at(0) = isoCards03.at(0);
0106   sortIso.at(2) = isoCards03.at(2);
0107   sortIso.at(4) = isoCards03.at(4);
0108   sortIso.at(6) = isoCards03.at(6);
0109   sortIso.at(1) = isoCards46.at(0);
0110   sortIso.at(3) = isoCards46.at(2);
0111   sortIso.at(5) = isoCards46.at(4);
0112   sortIso.at(7) = isoCards46.at(6);
0113 
0114   asicSort(sortIso);
0115 
0116   // for(int i = 0; i<4; i++){
0117   // isolatedEGObjects.at(i) = isoElectrons.at(i);
0118   // isolatedEGObjects.at(i) = sortIso.at(2*i);
0119   //}
0120   isolatedEGObjects.at(0) = sortIso.at(4);
0121   isolatedEGObjects.at(1) = sortIso.at(6);
0122   isolatedEGObjects.at(2) = sortIso.at(0);
0123   isolatedEGObjects.at(3) = sortIso.at(2);
0124 }
0125 
0126 void L1RCTJetSummaryCard::fillNonIsolatedEGObjects(const std::vector<unsigned short> &nonIsoElectrons) {
0127   // sort(nonIsoElectrons.begin(),nonIsoElectrons.end());
0128   // reverse(nonIsoElectrons.begin(),nonIsoElectrons.end());
0129 
0130   std::vector<unsigned short> nonIsoCards03(8);
0131   std::vector<unsigned short> nonIsoCards46(8);
0132   std::vector<unsigned short> sortNonIso(8);
0133 
0134   for (int i = 0; i < 8; i++) {
0135     nonIsoCards03.at(i) = nonIsoElectrons.at(i);
0136   }
0137   for (int i = 0; i < 6; i++) {
0138     nonIsoCards46.at(i) = nonIsoElectrons.at(i + 8);
0139   }
0140   nonIsoCards46.at(6) = 0;
0141   nonIsoCards46.at(7) = 0;
0142 
0143   asicSort(nonIsoCards03);
0144   asicSort(nonIsoCards46);
0145 
0146   sortNonIso.at(0) = nonIsoCards03.at(0);
0147   sortNonIso.at(2) = nonIsoCards03.at(2);
0148   sortNonIso.at(4) = nonIsoCards03.at(4);
0149   sortNonIso.at(6) = nonIsoCards03.at(6);
0150   sortNonIso.at(1) = nonIsoCards46.at(0);
0151   sortNonIso.at(3) = nonIsoCards46.at(2);
0152   sortNonIso.at(5) = nonIsoCards46.at(4);
0153   sortNonIso.at(7) = nonIsoCards46.at(6);
0154 
0155   asicSort(sortNonIso);
0156 
0157   // for(int i = 0; i<4; i++){
0158   // nonisolatedEGObjects.at(i) = nonIsoElectrons.at(i);
0159   // nonisolatedEGObjects.at(i) = sortNonIso.at(2*i);
0160   //}
0161   nonisolatedEGObjects.at(0) = sortNonIso.at(4);
0162   nonisolatedEGObjects.at(1) = sortNonIso.at(6);
0163   nonisolatedEGObjects.at(2) = sortNonIso.at(0);
0164   nonisolatedEGObjects.at(3) = sortNonIso.at(2);
0165 }
0166 
0167 void L1RCTJetSummaryCard::fillMIPBits(const std::vector<unsigned short> &mip) {
0168   bitset<14> mips;
0169   for (int i = 0; i < 14; i++)
0170     mips[i] = mip.at(i);
0171   mipBits = mips.to_ulong();
0172 }
0173 
0174 void L1RCTJetSummaryCard::fillTauBits(const std::vector<unsigned short> &tau) {
0175   bitset<14> taus;
0176   for (int i = 0; i < 14; i++)
0177     taus[i] = tau.at(i);
0178   tauBits = taus.to_ulong();
0179 }
0180 
0181 void L1RCTJetSummaryCard::fillOverFlowBits(const std::vector<unsigned short> &overflow) {
0182   bitset<14> overflows;
0183   for (int i = 0; i < 14; i++)
0184     overflows[i] = overflow.at(i);
0185   overFlowBits = overflows.to_ulong();
0186 }
0187 
0188 void L1RCTJetSummaryCard::fillQuietBits() {
0189   bitset<14> quiet;
0190 
0191   quietThresholdBarrel = rctLookupTables_->rctParameters()->jscQuietThresholdBarrel();
0192   quietThresholdEndcap = rctLookupTables_->rctParameters()->jscQuietThresholdEndcap();
0193 
0194   // use one threshold for barrel regions (first 8 in list, cards 0-3)
0195   for (int i = 0; i < 8; i++) {
0196     if ((barrelRegions.at(i)) > quietThresholdBarrel)
0197       quiet[i] = false;  // switched 0 and 1
0198     else
0199       quiet[i] = true;
0200   }
0201   // use second for endcap regions (last 6 in list, cards 4-6)
0202   for (int i = 8; i < 14; i++) {
0203     if ((barrelRegions.at(i)) > quietThresholdEndcap)
0204       quiet[i] = false;  // switched 0 and 1
0205     else
0206       quiet[i] = true;
0207   }
0208 
0209   quietBits = quiet.to_ulong();
0210 }
0211 
0212 // Sorts the egamma candidates with the algorithm used in the ASIC
0213 void L1RCTJetSummaryCard::asicSort(std::vector<unsigned short> &electrons) {
0214   unsigned short temp, temp2;
0215 
0216   asicCompare(electrons);
0217 
0218   // Rotate items prior to next compare
0219 
0220   temp = electrons.at(7);
0221   electrons.at(7) = electrons.at(5);
0222   electrons.at(5) = electrons.at(3);
0223   electrons.at(3) = electrons.at(1);
0224   electrons.at(1) = temp;
0225 
0226   // Second compare
0227 
0228   asicCompare(electrons);
0229 
0230   // Second rotate, different order this time
0231 
0232   temp = electrons.at(7);
0233   temp2 = electrons.at(5);
0234   electrons.at(7) = electrons.at(3);
0235   electrons.at(5) = electrons.at(1);
0236   electrons.at(3) = temp;
0237   electrons.at(1) = temp2;
0238 
0239   // Third compare
0240 
0241   asicCompare(electrons);
0242 
0243   // Third rotate, different again
0244 
0245   temp = electrons.at(1);
0246   electrons.at(1) = electrons.at(3);
0247   electrons.at(3) = electrons.at(5);
0248   electrons.at(5) = electrons.at(7);
0249   electrons.at(7) = temp;
0250 
0251   // Fourth compare
0252 
0253   asicCompare(electrons);
0254 }
0255 
0256 // Used in ASIC sort algorithm
0257 void L1RCTJetSummaryCard::asicCompare(std::vector<unsigned short> &array) {
0258   int i;
0259   unsigned short temp;
0260   for (i = 0; i < 4; i++) {
0261     unsigned short rank1 = rctLookupTables_->emRank(array.at(2 * i) >> 4);
0262     unsigned short rank2 = rctLookupTables_->emRank(array.at(2 * i + 1) >> 4);
0263 
0264     if (rank1 < rank2)  // currently bottom 3 bits are rgn,crd
0265     {
0266       temp = array.at(2 * i);
0267       array.at(2 * i) = array.at((2 * i) + 1);
0268       array.at((2 * i) + 1) = temp;
0269     }
0270   }
0271 }
0272 
0273 void L1RCTJetSummaryCard::print() {
0274   std::cout << "tauBits " << tauBits << std::endl;
0275   std::cout << "MIPBits " << mipBits << std::endl;
0276   std::cout << "QuietBits " << quietBits << std::endl;
0277   for (int i = 0; i < 4; i++) {
0278     std::cout << "isoElectron " << i << " " << isolatedEGObjects.at(i) << std::endl;
0279     ;
0280     std::cout << "nonIsoElectron " << i << " " << nonisolatedEGObjects.at(i) << std::endl;
0281   }
0282   std::cout << "Jets ";
0283   for (int i = 0; i < 22; i++)
0284     std::cout << jetRegions.at(i) << " ";
0285   std::cout << std::endl;
0286 }