CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/L1Trigger/RegionalCaloTrigger/src/L1RCTElectronIsolationCard.cc

Go to the documentation of this file.
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.push_back(L1RCTRegion());
00016   regions.push_back(L1RCTRegion());
00017 }
00018 
00019 L1RCTElectronIsolationCard::~L1RCTElectronIsolationCard()
00020 {
00021   regions.clear();
00022 }
00023 
00024 
00025 void L1RCTElectronIsolationCard::fillElectronCandidates(){
00026   std::vector<unsigned short> region0Electrons = calcElectronCandidates(regions.at(0),0);
00027   std::vector<unsigned short> region1Electrons = calcElectronCandidates(regions.at(1),1);
00028   isoElectrons.at(0) = region0Electrons.at(0);
00029   isoElectrons.at(1) = region1Electrons.at(0);
00030   nonIsoElectrons.at(0) = region0Electrons.at(1);
00031   nonIsoElectrons.at(1) = region1Electrons.at(1);
00032 
00033 
00034 }
00035 
00036 
00037 //This method is the bulk of this class.  It finds the electrons given a pointer to
00038 //a region.  It will return the largest nonIsoElectron candidate and the largest
00039 //isoElectron candidate.  A deposit is an electron candidate if the h/e||fg bit is
00040 //not on and it is higher energy than it's direct four neighbors.
00041 //An electron candidate is *always* a non-isolated electron.
00042 //If it also passes the neighbor cuts then it is an isolated electron as well.
00043 std::vector<unsigned short>
00044 L1RCTElectronIsolationCard::calcElectronCandidates(const L1RCTRegion& region, int regionNum){
00045   
00046   unsigned short nonIsoElectron = 0;
00047   unsigned short isoElectron = 0;
00048   
00049   //i is row and j is column
00050   for(int i = 0; i<4; i++){
00051     for(int j = 0; j<4; j++){
00052 
00053       unsigned short primaryEt = region.getEtIn7Bits(i,j);
00054       unsigned short primaryHE_FG = region.getHE_FGBit(i,j); 
00055       
00056       unsigned short northEt = region.getEtIn7Bits(i-1,  j);
00057       unsigned short southEt = region.getEtIn7Bits(i+1,  j);
00058       unsigned short westEt  = region.getEtIn7Bits(  i,j-1);
00059       unsigned short eastEt  = region.getEtIn7Bits(  i,j+1);
00060       unsigned short neEt    = region.getEtIn7Bits(i-1,j+1);
00061       unsigned short nwEt    = region.getEtIn7Bits(i-1,j-1);
00062       unsigned short seEt    = region.getEtIn7Bits(i+1,j+1);
00063       unsigned short swEt    = region.getEtIn7Bits(i+1,j-1);
00064 
00065       unsigned short northHE_FG = region.getHE_FGBit(i-1,  j);
00066       unsigned short southHE_FG = region.getHE_FGBit(i+1,  j);
00067       unsigned short westHE_FG  = region.getHE_FGBit(  i,j-1);
00068       unsigned short eastHE_FG  = region.getHE_FGBit(  i,j+1);
00069       unsigned short neHE_FG    = region.getHE_FGBit(i-1,j+1);
00070       unsigned short nwHE_FG    = region.getHE_FGBit(i-1,j-1);
00071       unsigned short seHE_FG    = region.getHE_FGBit(i+1,j+1);
00072       unsigned short swHE_FG    = region.getHE_FGBit(i+1,j-1);
00073 
00074       bool top = false;
00075 
00076       int nCrate = crateNumber();
00077       int nCard = cardNumber();
00078       int nRegion = regionNum;
00079 
00080       // top row of crate
00081       if (nCard == 0 || nCard == 2 || nCard == 4 || (nCard == 6 && nRegion == 0))
00082         {
00083           top = true;
00084         }
00085       // bottom row of crate
00086       else if (nCard == 1 || nCard == 3 || nCard == 5 || (nCard == 6 && nRegion == 1))
00087         {} // top already false
00088       else
00089         {
00090           std::cerr << "Error! EIC top assignment" << std::endl;  // this shouldn't happen!
00091         }
00092 
00093       // The following values are used for zeroing and determining whether or
00094       // not a tower is a "candidate".  The original primaryEt, northEt, neEt, etc.
00095       // are used to calculate vetoes and must not be zeroed.
00096 
00097       unsigned short primaryTowerEt = primaryEt;
00098       unsigned short northTowerEt = northEt;
00099       unsigned short southTowerEt = southEt;
00100       unsigned short eastTowerEt = eastEt;
00101       unsigned short westTowerEt = westEt;
00102 
00103       // In order to ensure proper selection of candidate tower and neighbor,
00104       // if two neighbor energies are equal, one is set to zero (in the
00105       // appropriate regions, those for which tp_lf bit is set to 0 in
00106       // Pam's JCCTest/EGWithShare.cc). 
00107 
00108       if (primaryEt > 0)  // this value should maybe be customizable?
00109         {
00110           if (nCard != 6)  // all cards except 6
00111             {
00112               if(top && nCrate >= 9)  // top row of regions in positive-eta crate
00113                 {
00114                   if(westTowerEt == eastTowerEt) westTowerEt=0;
00115                   if(southTowerEt == northTowerEt) southTowerEt=0;
00116                   if(southTowerEt == eastTowerEt) southTowerEt=0;
00117                   if(westTowerEt == northTowerEt) westTowerEt=0;
00118                 }
00119               else if((!top) && nCrate < 9) // bottom row of regions in negative-eta crate
00120                 {
00121                   if(eastTowerEt == westTowerEt) eastTowerEt=0;
00122                   if(northTowerEt == southTowerEt) northTowerEt=0;
00123                   if(northTowerEt == westTowerEt) northTowerEt=0;
00124                   if(eastTowerEt == southTowerEt) eastTowerEt=0;
00125                 }
00126             }
00127           else  // card 6                                            
00128             {
00129               // only +eta card 6 needs to have zeroing.  Pam sez.  
00130               // -eta card 6 does what it's supposed to even w/o zeroing.
00131               if(nRegion == 0 && nCrate >=9)
00132                 {
00133                   if(westTowerEt == eastTowerEt) westTowerEt=0;
00134                   if(southTowerEt == northTowerEt) southTowerEt=0;
00135                   if(southTowerEt == eastTowerEt) southTowerEt=0;
00136                   if(westTowerEt == northTowerEt) westTowerEt=0;
00137                 }
00138             }
00139         }
00140       
00141       // This section compares the energies in the primary tower with the
00142       // surrounding towers to determine whether or not the primary tower
00143       // should be considered a "candidate".  
00144 
00145       bool candidate = false;
00146 
00147       // for case where primary tower et greater than all neighbors -> candidate
00148       if (primaryEt > northEt && primaryEt > southEt && primaryEt > eastEt
00149           && primaryEt > westEt && !primaryHE_FG)
00150         {
00151           candidate = true;
00152         }
00153 
00154       // if primary et less than any neighbors (or HE_FG veto set) NOT a candidate!
00155       else if (primaryEt < northEt || primaryEt < southEt || primaryEt < eastEt
00156           || primaryEt < westEt || primaryHE_FG)
00157         {} // candidate already false
00158 
00159       else // Case of primary tower et being equal to any of its neighbors.
00160         // This section determines which tower gets the candidate.
00161         // See AboutTP.pdf document, figure on p. 4, for clarification.
00162         // Zeroed values are used in this calculation.
00163         {
00164           if (primaryEt > 0)
00165             {
00166               if (nCrate >=9)  // positive eta
00167                 {
00168                   if (top) // top row of regions in crate.  tp_lf == 0
00169                     // priority order: east < south < north < west
00170                     {
00171                       if (westTowerEt == primaryTowerEt)
00172                         candidate = true;
00173                       else if (northTowerEt == primaryTowerEt)
00174                         candidate = false;
00175                       else if (southTowerEt == primaryTowerEt)
00176                         candidate = true;
00177                       else if (eastTowerEt == primaryTowerEt)
00178                         candidate = false;
00179                     }
00180 
00181                   else // bottom row of regions in crate.  tp_lf == 1
00182                     // priority order: west < north < south < east
00183                     {
00184                       if (eastTowerEt == primaryTowerEt)
00185                         candidate = true;
00186                       else if (southTowerEt == primaryTowerEt)
00187                         candidate = true;
00188                       else if (northTowerEt == primaryTowerEt)
00189                         candidate = false;
00190                       else if (westTowerEt == primaryTowerEt)
00191                         candidate = false;
00192                       if (nCard == 6)  // card 6. tp_lf == 1
00193                         {
00194                           // priority order: east < north < south < west
00195                           if (westTowerEt == primaryTowerEt)
00196                             candidate = true;
00197                           else if (southTowerEt == primaryTowerEt)
00198                             candidate = true;
00199                           else if (northTowerEt == primaryTowerEt)
00200                             candidate = false;
00201                           else if (eastTowerEt == primaryTowerEt)
00202                             candidate = false;
00203                         }
00204                     }
00205                 }
00206               else // negative eta
00207                 {
00208                   if (top) // top row of regions in crate.  tp_lf == 1  
00209                     // priority order: east < south < north < west
00210                     {
00211                       if (westTowerEt == primaryTowerEt)
00212                         candidate = true;
00213                       else if (northTowerEt == primaryTowerEt)
00214                         candidate = true;
00215                       else if (southTowerEt == primaryTowerEt)
00216                         candidate = false;
00217                       else if (eastTowerEt == primaryTowerEt)
00218                         candidate = false;
00219                       if (nCard == 6)  // card 6.  tp_lf == 0
00220                         // east < south < north < west
00221                         {
00222                           if (westTowerEt == primaryTowerEt)
00223                             candidate = false;
00224                           else if (northTowerEt == primaryTowerEt)
00225                             candidate = false;
00226                           else if (southTowerEt == primaryTowerEt)
00227                             candidate = true;
00228                           else if (eastTowerEt == primaryTowerEt)
00229                             candidate = true;
00230                         }
00231                     }
00232                   else // bottom row of regions.  tp_lf == 0
00233                     // west < north < south < east
00234                     {
00235                       if (eastTowerEt == primaryTowerEt)
00236                         candidate = true;
00237                       else if (southTowerEt == primaryTowerEt)
00238                         candidate = false;
00239                       else if (northTowerEt == primaryTowerEt)
00240                         candidate = true;
00241                       else if (westTowerEt == primaryTowerEt)
00242                         candidate = false;
00243                       
00244                       if (nCard == 6) // card 6.  tp_lf == 1
00245                         // west < north < south < east
00246                         {
00247                           if (eastTowerEt == primaryTowerEt)
00248                             candidate = true;
00249                           else if (southTowerEt == primaryTowerEt)
00250                             candidate = true;
00251                           else if (northTowerEt == primaryTowerEt)
00252                             candidate = false;
00253                           else if (westTowerEt == primaryTowerEt)
00254                             candidate = false;
00255                         }
00256                     }
00257                 }
00258             }
00259         } // end of if (primary == neighbors)
00260       
00261       if (candidate) {
00262         
00263         // Either zeroed or non-zeroed set of values can be used here --
00264         // neighbor tower only zeroed if another neighbor tower of same
00265         // energy.  Max sum calculated from primary and only one neighbor
00266         // tower, and always one neighbor tower left over, so value of sum
00267         // is not affected.  Currently using non-zeroed.
00268         unsigned short candidateEt = calcMaxSum(primaryEt,northEt,southEt,
00269                                                 eastEt,westEt);
00270         
00271         // neighbor HE_FG veto true if neighbor has HE_FG set
00272         bool neighborVeto = (nwHE_FG || northHE_FG || neHE_FG || westHE_FG ||
00273                              eastHE_FG || swHE_FG || southHE_FG || seHE_FG); 
00274         
00275         // threshold for five-tower corner quiet veto
00276         //int quietThreshold = 3;   // 3 - loose isolation 0 - very tight isolation
00277         //int quietThreshold = 7; // ECALGREN
00278         //int quietThreshold = 0; // HCALGREN
00279         unsigned quietThreshold = rctLookupTables_->rctParameters()->eicIsolationThreshold();
00280         
00281         bool nw = false;
00282         bool ne = false;
00283         bool sw = false;
00284         bool se = false;
00285         bool n = false;
00286         bool w = false;
00287         bool s = false;
00288         bool e = false;
00289 
00290         // individual neighbor vetoes set if neighbor is over threshold
00291         if (nwEt >= quietThreshold) nw = true;
00292         if (neEt >= quietThreshold) ne = true;
00293         if (swEt >= quietThreshold) sw = true;
00294         if (seEt >= quietThreshold) se = true;
00295         if (northEt >= quietThreshold) n = true;
00296         if (southEt >= quietThreshold) s = true;
00297         if (westEt >= quietThreshold) w = true;
00298         if (eastEt >= quietThreshold) e = true;
00299 
00300         // veto TRUE for each corner set if any individual tower in each set is over threshold
00301         bool nwC = (sw || w || nw || n || ne);
00302         bool neC = (nw || n || ne || e || se);
00303         bool seC = (ne || e || se || s || sw);
00304         bool swC = (se || s || sw || w || nw);
00305 
00306         // overall quiet veto TRUE only if NO corner sets are quiet 
00307         // (all are "loud") -> non-isolated
00308         bool quietVeto = (nwC && neC && seC && swC);
00309 
00310         // only isolated if both vetoes are false
00311         // Note: quietThreshold = 0 forces all candidates to be non-iso
00312         if(!(quietVeto || neighborVeto)){
00313           if(candidateEt > isoElectron)
00314             isoElectron = candidateEt;
00315         }
00316         // otherwise, non-isolated
00317         else if(candidateEt > nonIsoElectron)
00318           nonIsoElectron = candidateEt;
00319 
00320       }
00321     }
00322   }
00323 
00324   
00325   std::vector<unsigned short> candidates;
00326   unsigned short fullIsoElectron = isoElectron*16 + cardNo*2;  // leaves room for last bit -- region number, added in Crate.cc
00327   candidates.push_back(fullIsoElectron);
00328   unsigned short fullNonIsoElectron = nonIsoElectron*16 + cardNo*2;  // leaves room for region info in last bit
00329   candidates.push_back(fullNonIsoElectron);
00330 
00331   return candidates;
00332 }
00333 
00334 unsigned short 
00335 L1RCTElectronIsolationCard::calcMaxSum(unsigned short primaryEt,unsigned short northEt,
00336                                         unsigned short southEt,unsigned short eastEt,
00337                                         unsigned short westEt){
00338   unsigned short cardinals[4] = {northEt,southEt,eastEt,westEt};
00339   unsigned short max = 0;
00340   for(int i = 0; i<4;i++){
00341     unsigned short test = primaryEt+cardinals[i];
00342     if(test > max)
00343       max = test;
00344   }
00345    return max;
00346 }
00347 
00348 void L1RCTElectronIsolationCard::print() {
00349   std::cout << "Electron isolation card " << cardNo << std::endl;
00350   std::cout << "Region 0 Information" << std::endl;
00351   regions.at(0).print();
00352 
00353   std::cout << "IsoElectron Candidate " << isoElectrons.at(0) << std::endl;
00354   std::cout << "NonIsoElectron Candidate " << nonIsoElectrons.at(0) << std::endl << std::endl;
00355 
00356   std::cout << "Region 1 Information" << std::endl;
00357   regions.at(1).print();
00358 
00359   std::cout << "IsoElectron Candidate " << isoElectrons.at(1) << std::endl;
00360   std::cout << "NonIsoElectron Candidate " << nonIsoElectrons.at(1) << std::endl;
00361 }