00001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTElectronIsolationCard.h"
00002 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h"
00003 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
00004
00005 #include <iostream>
00006 #include <iomanip>
00007
00008 L1RCTElectronIsolationCard::L1RCTElectronIsolationCard(int crateNumber,
00009 int cardNumber,
00010 const L1RCTLookupTables* rctLookupTables) :
00011 crtNo(crateNumber),cardNo(cardNumber),
00012 rctLookupTables_(rctLookupTables),
00013 isoElectrons(2),nonIsoElectrons(2), regions(2)
00014 {
00015 regions.at(0) = new L1RCTRegion();
00016 regions.at(1) = new L1RCTRegion();
00017 }
00018
00019 L1RCTElectronIsolationCard::~L1RCTElectronIsolationCard(){}
00020
00021
00022 void L1RCTElectronIsolationCard::fillElectronCandidates(){
00023 std::vector<unsigned short> region0Electrons = calcElectronCandidates(regions.at(0),0);
00024 std::vector<unsigned short> region1Electrons = calcElectronCandidates(regions.at(1),1);
00025 isoElectrons.at(0) = region0Electrons.at(0);
00026 isoElectrons.at(1) = region1Electrons.at(0);
00027 nonIsoElectrons.at(0) = region0Electrons.at(1);
00028 nonIsoElectrons.at(1) = region1Electrons.at(1);
00029 }
00030
00031
00032
00033
00034
00035
00036
00037
00038 std::vector<unsigned short>
00039 L1RCTElectronIsolationCard::calcElectronCandidates(L1RCTRegion* region, int regionNum){
00040
00041 unsigned short nonIsoElectron = 0;
00042 unsigned short isoElectron = 0;
00043
00044
00045 for(int i = 0; i<4; i++){
00046 for(int j = 0; j<4; j++){
00047
00048 unsigned short primaryEt = region->getEtIn7Bits(i,j);
00049 unsigned short primaryHE_FG = region->getHE_FGBit(i,j);
00050
00051 unsigned short northEt = region->getEtIn7Bits(i-1, j);
00052 unsigned short southEt = region->getEtIn7Bits(i+1, j);
00053 unsigned short westEt = region->getEtIn7Bits( i,j-1);
00054 unsigned short eastEt = region->getEtIn7Bits( i,j+1);
00055 unsigned short neEt = region->getEtIn7Bits(i-1,j+1);
00056 unsigned short nwEt = region->getEtIn7Bits(i-1,j-1);
00057 unsigned short seEt = region->getEtIn7Bits(i+1,j+1);
00058 unsigned short swEt = region->getEtIn7Bits(i+1,j-1);
00059
00060 unsigned short northHE_FG = region->getHE_FGBit(i-1, j);
00061 unsigned short southHE_FG = region->getHE_FGBit(i+1, j);
00062 unsigned short westHE_FG = region->getHE_FGBit( i,j-1);
00063 unsigned short eastHE_FG = region->getHE_FGBit( i,j+1);
00064 unsigned short neHE_FG = region->getHE_FGBit(i-1,j+1);
00065 unsigned short nwHE_FG = region->getHE_FGBit(i-1,j-1);
00066 unsigned short seHE_FG = region->getHE_FGBit(i+1,j+1);
00067 unsigned short swHE_FG = region->getHE_FGBit(i+1,j-1);
00068
00069 bool top = false;
00070
00071 int nCrate = crateNumber();
00072 int nCard = cardNumber();
00073 int nRegion = regionNum;
00074
00075
00076 if (nCard == 0 || nCard == 2 || nCard == 4 || (nCard == 6 && nRegion == 0))
00077 {
00078 top = true;
00079 }
00080
00081 else if (nCard == 1 || nCard == 3 || nCard == 5 || (nCard == 6 && nRegion == 1))
00082 {}
00083 else
00084 {
00085 std::cerr << "Error! EIC top assignment" << std::endl;
00086 }
00087
00088
00089
00090
00091
00092 unsigned short primaryTowerEt = primaryEt;
00093 unsigned short northTowerEt = northEt;
00094 unsigned short southTowerEt = southEt;
00095 unsigned short eastTowerEt = eastEt;
00096 unsigned short westTowerEt = westEt;
00097
00098
00099
00100
00101
00102
00103 if (primaryEt > 0)
00104 {
00105 if (nCard != 6)
00106 {
00107 if(top && nCrate >= 9)
00108 {
00109 if(westTowerEt == eastTowerEt) westTowerEt=0;
00110 if(southTowerEt == northTowerEt) southTowerEt=0;
00111 if(southTowerEt == eastTowerEt) southTowerEt=0;
00112 if(westTowerEt == northTowerEt) westTowerEt=0;
00113 }
00114 else if((!top) && nCrate < 9)
00115 {
00116 if(eastTowerEt == westTowerEt) eastTowerEt=0;
00117 if(northTowerEt == southTowerEt) northTowerEt=0;
00118 if(northTowerEt == westTowerEt) northTowerEt=0;
00119 if(eastTowerEt == southTowerEt) eastTowerEt=0;
00120 }
00121 }
00122 else
00123 {
00124
00125
00126 if(nRegion == 0 && nCrate >=9)
00127 {
00128 if(westTowerEt == eastTowerEt) westTowerEt=0;
00129 if(southTowerEt == northTowerEt) southTowerEt=0;
00130 if(southTowerEt == eastTowerEt) southTowerEt=0;
00131 if(westTowerEt == northTowerEt) westTowerEt=0;
00132 }
00133 }
00134 }
00135
00136
00137
00138
00139
00140 bool candidate = false;
00141
00142
00143 if (primaryEt > northEt && primaryEt > southEt && primaryEt > eastEt
00144 && primaryEt > westEt && !primaryHE_FG)
00145 {
00146 candidate = true;
00147 }
00148
00149
00150 else if (primaryEt < northEt || primaryEt < southEt || primaryEt < eastEt
00151 || primaryEt < westEt || primaryHE_FG)
00152 {}
00153
00154 else
00155
00156
00157
00158 {
00159 if (primaryEt > 0)
00160 {
00161 if (nCrate >=9)
00162 {
00163 if (top)
00164
00165 {
00166 if (westTowerEt == primaryTowerEt)
00167 candidate = true;
00168 else if (northTowerEt == primaryTowerEt)
00169 candidate = false;
00170 else if (southTowerEt == primaryTowerEt)
00171 candidate = true;
00172 else if (eastTowerEt == primaryTowerEt)
00173 candidate = false;
00174 }
00175
00176 else
00177
00178 {
00179 if (eastTowerEt == primaryTowerEt)
00180 candidate = true;
00181 else if (southTowerEt == primaryTowerEt)
00182 candidate = true;
00183 else if (northTowerEt == primaryTowerEt)
00184 candidate = false;
00185 else if (westTowerEt == primaryTowerEt)
00186 candidate = false;
00187 if (nCard == 6)
00188 {
00189
00190 if (westTowerEt == primaryTowerEt)
00191 candidate = true;
00192 else if (southTowerEt == primaryTowerEt)
00193 candidate = true;
00194 else if (northTowerEt == primaryTowerEt)
00195 candidate = false;
00196 else if (eastTowerEt == primaryTowerEt)
00197 candidate = false;
00198 }
00199 }
00200 }
00201 else
00202 {
00203 if (top)
00204
00205 {
00206 if (westTowerEt == primaryTowerEt)
00207 candidate = true;
00208 else if (northTowerEt == primaryTowerEt)
00209 candidate = true;
00210 else if (southTowerEt == primaryTowerEt)
00211 candidate = false;
00212 else if (eastTowerEt == primaryTowerEt)
00213 candidate = false;
00214 if (nCard == 6)
00215
00216 {
00217 if (westTowerEt == primaryTowerEt)
00218 candidate = false;
00219 else if (northTowerEt == primaryTowerEt)
00220 candidate = false;
00221 else if (southTowerEt == primaryTowerEt)
00222 candidate = true;
00223 else if (eastTowerEt == primaryTowerEt)
00224 candidate = true;
00225 }
00226 }
00227 else
00228
00229 {
00230 if (eastTowerEt == primaryTowerEt)
00231 candidate = true;
00232 else if (southTowerEt == primaryTowerEt)
00233 candidate = false;
00234 else if (northTowerEt == primaryTowerEt)
00235 candidate = true;
00236 else if (westTowerEt == primaryTowerEt)
00237 candidate = false;
00238
00239 if (nCard == 6)
00240
00241 {
00242 if (eastTowerEt == primaryTowerEt)
00243 candidate = true;
00244 else if (southTowerEt == primaryTowerEt)
00245 candidate = true;
00246 else if (northTowerEt == primaryTowerEt)
00247 candidate = false;
00248 else if (westTowerEt == primaryTowerEt)
00249 candidate = false;
00250 }
00251 }
00252 }
00253 }
00254 }
00255
00256 if (candidate) {
00257
00258
00259
00260
00261
00262
00263 unsigned short candidateEt = calcMaxSum(primaryEt,northEt,southEt,
00264 eastEt,westEt);
00265
00266
00267 bool neighborVeto = (nwHE_FG || northHE_FG || neHE_FG || westHE_FG ||
00268 eastHE_FG || swHE_FG || southHE_FG || seHE_FG);
00269
00270
00271
00272
00273
00274 unsigned quietThreshold = rctLookupTables_->rctParameters()->eicIsolationThreshold();
00275
00276 bool nw = false;
00277 bool ne = false;
00278 bool sw = false;
00279 bool se = false;
00280 bool n = false;
00281 bool w = false;
00282 bool s = false;
00283 bool e = false;
00284
00285
00286 if (nwEt >= quietThreshold) nw = true;
00287 if (neEt >= quietThreshold) ne = true;
00288 if (swEt >= quietThreshold) sw = true;
00289 if (seEt >= quietThreshold) se = true;
00290 if (northEt >= quietThreshold) n = true;
00291 if (southEt >= quietThreshold) s = true;
00292 if (westEt >= quietThreshold) w = true;
00293 if (eastEt >= quietThreshold) e = true;
00294
00295
00296 bool nwC = (sw || w || nw || n || ne);
00297 bool neC = (nw || n || ne || e || se);
00298 bool seC = (ne || e || se || s || sw);
00299 bool swC = (se || s || sw || w || nw);
00300
00301
00302
00303 bool quietVeto = (nwC && neC && seC && swC);
00304
00305
00306
00307 if(!(quietVeto || neighborVeto)){
00308 if(candidateEt > isoElectron)
00309 isoElectron = candidateEt;
00310 }
00311
00312 else if(candidateEt > nonIsoElectron)
00313 nonIsoElectron = candidateEt;
00314
00315 }
00316 }
00317 }
00318
00319
00320 std::vector<unsigned short> candidates;
00321 unsigned short fullIsoElectron = isoElectron*16 + cardNo*2;
00322 candidates.push_back(fullIsoElectron);
00323 unsigned short fullNonIsoElectron = nonIsoElectron*16 + cardNo*2;
00324 candidates.push_back(fullNonIsoElectron);
00325
00326 return candidates;
00327 }
00328
00329 unsigned short
00330 L1RCTElectronIsolationCard::calcMaxSum(unsigned short primaryEt,unsigned short northEt,
00331 unsigned short southEt,unsigned short eastEt,
00332 unsigned short westEt){
00333 unsigned short cardinals[4] = {northEt,southEt,eastEt,westEt};
00334 unsigned short max = 0;
00335 for(int i = 0; i<4;i++){
00336 unsigned short test = primaryEt+cardinals[i];
00337 if(test > max)
00338 max = test;
00339 }
00340 return max;
00341 }
00342
00343 void L1RCTElectronIsolationCard::print() {
00344 std::cout << "Electron isolation card " << cardNo << std::endl;
00345 std::cout << "Region 0 Information" << std::endl;
00346 regions.at(0)->print();
00347
00348 std::cout << "IsoElectron Candidate " << isoElectrons.at(0) << std::endl;
00349 std::cout << "NonIsoElectron Candidate " << nonIsoElectrons.at(0) << std::endl << std::endl;
00350
00351 std::cout << "Region 1 Information" << std::endl;
00352 regions.at(1)->print();
00353
00354 std::cout << "IsoElectron Candidate " << isoElectrons.at(1) << std::endl;
00355 std::cout << "NonIsoElectron Candidate " << nonIsoElectrons.at(1) << std::endl;
00356 }