CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/L1Trigger/RegionalCaloTrigger/src/L1RCTJetSummaryCard.cc

Go to the documentation of this file.
00001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTJetSummaryCard.h"
00002 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h" 
00003 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
00004 
00005 #include <iostream>
00006 using std::cout;
00007 using std::endl;
00008 #include <vector>
00009 using std::vector;
00010 #include <bitset>
00011 using std::bitset;
00012 
00013 L1RCTJetSummaryCard::L1RCTJetSummaryCard(int crtNo, const L1RCTLookupTables* rctLookupTables) : 
00014   crtNo(crtNo),
00015   rctLookupTables_(rctLookupTables),
00016   isolatedEGObjects(4),
00017   nonisolatedEGObjects(4),
00018   jetRegions(22),
00019   HFRegions(8),
00020   barrelRegions(14),
00021   mipBits(0),
00022   quietBits(0),
00023   tauBits(0),
00024   overFlowBits(0),
00025   hfFineGrainBits(8)
00026   //quietThreshold(3)
00027 {
00028 }
00029 
00030 void L1RCTJetSummaryCard::fillHFRegionSums(std::vector<unsigned short> hfRegionSums){
00031   //std::cout << "JSC.fillHFRegionSums() entered" << std::endl;
00032   for(int i=0;i<8;i++){
00033     //std::cout << "filling hf region at " << i << std::endl;
00034     HFRegions.at(i) = rctLookupTables_->lookup( (hfRegionSums.at(i)/2), crtNo, 999, i);
00035     //std::cout << "hf region " << i << " et filled" << std::endl;
00036     hfFineGrainBits.at(i) = (hfRegionSums.at(i)&1);
00037     //std::cout << "hf region " << i << " fine grain bit filled" << std::endl;
00038   }
00039 }
00040 
00041 void L1RCTJetSummaryCard::fillJetRegions(){
00042   if(crtNo<9){
00043     for(int i = 0; i<4;i++){
00044       jetRegions.at(i) = HFRegions.at(i);
00045       jetRegions.at(i+11) = HFRegions.at(i+4);
00046     }
00047     jetRegions.at(4) = barrelRegions.at(12);
00048     jetRegions.at(5) = barrelRegions.at(9);
00049     jetRegions.at(6) = barrelRegions.at(8);
00050     jetRegions.at(7) = barrelRegions.at(5);
00051     jetRegions.at(8) = barrelRegions.at(4);
00052     jetRegions.at(9) = barrelRegions.at(1);
00053     jetRegions.at(10) = barrelRegions.at(0);
00054 
00055     jetRegions.at(15) = barrelRegions.at(13);
00056     jetRegions.at(16) = barrelRegions.at(11);
00057     jetRegions.at(17) = barrelRegions.at(10);
00058     jetRegions.at(18) = barrelRegions.at(7);
00059     jetRegions.at(19) = barrelRegions.at(6);
00060     jetRegions.at(20) = barrelRegions.at(3);
00061     jetRegions.at(21) = barrelRegions.at(2);
00062   }
00063   if(crtNo>=9){
00064     jetRegions.at(0) = barrelRegions.at(0);
00065     jetRegions.at(1) = barrelRegions.at(1);
00066     jetRegions.at(2) = barrelRegions.at(4);
00067     jetRegions.at(3) = barrelRegions.at(5);
00068     jetRegions.at(4) = barrelRegions.at(8);
00069     jetRegions.at(5) = barrelRegions.at(9);
00070     jetRegions.at(6) = barrelRegions.at(12);
00071     
00072     jetRegions.at(11) = barrelRegions.at(2);
00073     jetRegions.at(12) = barrelRegions.at(3);
00074     jetRegions.at(13) = barrelRegions.at(6);
00075     jetRegions.at(14) = barrelRegions.at(7);
00076     jetRegions.at(15) = barrelRegions.at(10);
00077     jetRegions.at(16) = barrelRegions.at(11);
00078     jetRegions.at(17) = barrelRegions.at(13);
00079     for(int i = 0; i<4;i++){
00080       jetRegions.at(i+7) = HFRegions.at(i);
00081       jetRegions.at(i+18) = HFRegions.at(i+4);
00082     }
00083   }
00084 }
00085 
00086 void L1RCTJetSummaryCard::fillIsolatedEGObjects(std::vector<unsigned short> isoElectrons){
00087   //sort(isoElectrons.begin(),isoElectrons.end());
00088   //reverse(isoElectrons.begin(),isoElectrons.end());
00089 
00090   std::vector<unsigned short> isoCards03(8);
00091   std::vector<unsigned short> isoCards46(8);
00092   std::vector<unsigned short> sortIso(8);
00093 
00094   for (int i = 0; i < 8; i++){
00095     isoCards03.at(i) = isoElectrons.at(i);
00096   }
00097   for (int i = 0; i < 6; i++){
00098     isoCards46.at(i) = isoElectrons.at(i+8);
00099   }
00100   isoCards46.at(6) = 0;
00101   isoCards46.at(7) = 0;
00102 
00103   asicSort(isoCards03);
00104   asicSort(isoCards46);
00105 
00106   sortIso.at(0) = isoCards03.at(0);
00107   sortIso.at(2) = isoCards03.at(2);
00108   sortIso.at(4) = isoCards03.at(4);
00109   sortIso.at(6) = isoCards03.at(6);
00110   sortIso.at(1) = isoCards46.at(0);
00111   sortIso.at(3) = isoCards46.at(2);
00112   sortIso.at(5) = isoCards46.at(4);
00113   sortIso.at(7) = isoCards46.at(6);
00114 
00115   asicSort(sortIso);
00116 
00117   //for(int i = 0; i<4; i++){
00118     //isolatedEGObjects.at(i) = isoElectrons.at(i);
00119     //isolatedEGObjects.at(i) = sortIso.at(2*i);
00120   //}
00121   isolatedEGObjects.at(0) = sortIso.at(4);
00122   isolatedEGObjects.at(1) = sortIso.at(6);
00123   isolatedEGObjects.at(2) = sortIso.at(0);
00124   isolatedEGObjects.at(3) = sortIso.at(2);
00125 }
00126 
00127 void L1RCTJetSummaryCard::fillNonIsolatedEGObjects(std::vector<unsigned short> nonIsoElectrons){
00128   //sort(nonIsoElectrons.begin(),nonIsoElectrons.end());
00129   //reverse(nonIsoElectrons.begin(),nonIsoElectrons.end());
00130 
00131   std::vector<unsigned short> nonIsoCards03(8);
00132   std::vector<unsigned short> nonIsoCards46(8);
00133   std::vector<unsigned short> sortNonIso(8);
00134 
00135   for (int i = 0; i < 8; i++){
00136     nonIsoCards03.at(i) = nonIsoElectrons.at(i);
00137   }
00138   for (int i = 0; i < 6; i++){
00139     nonIsoCards46.at(i) = nonIsoElectrons.at(i+8);
00140   }
00141   nonIsoCards46.at(6) = 0;
00142   nonIsoCards46.at(7) = 0;
00143 
00144   asicSort(nonIsoCards03);
00145   asicSort(nonIsoCards46);
00146 
00147   sortNonIso.at(0) = nonIsoCards03.at(0);
00148   sortNonIso.at(2) = nonIsoCards03.at(2);
00149   sortNonIso.at(4) = nonIsoCards03.at(4);
00150   sortNonIso.at(6) = nonIsoCards03.at(6);
00151   sortNonIso.at(1) = nonIsoCards46.at(0);
00152   sortNonIso.at(3) = nonIsoCards46.at(2);
00153   sortNonIso.at(5) = nonIsoCards46.at(4);
00154   sortNonIso.at(7) = nonIsoCards46.at(6);
00155 
00156   asicSort(sortNonIso);
00157 
00158   //for(int i = 0; i<4; i++){
00159     //nonisolatedEGObjects.at(i) = nonIsoElectrons.at(i);
00160     //nonisolatedEGObjects.at(i) = sortNonIso.at(2*i);
00161   //}
00162   nonisolatedEGObjects.at(0) = sortNonIso.at(4);
00163   nonisolatedEGObjects.at(1) = sortNonIso.at(6);
00164   nonisolatedEGObjects.at(2) = sortNonIso.at(0);
00165   nonisolatedEGObjects.at(3) = sortNonIso.at(2);
00166 }
00167 
00168 void L1RCTJetSummaryCard::fillMIPBits(std::vector<unsigned short> mip){
00169   bitset<14> mips;
00170   for(int i = 0; i<14; i++)
00171     mips[i] = mip.at(i);
00172   mipBits = mips.to_ulong();
00173 }
00174 
00175 void L1RCTJetSummaryCard::fillTauBits(std::vector<unsigned short> tau){
00176   bitset<14> taus;
00177   for(int i = 0; i<14; i++)
00178     taus[i] = tau.at(i);
00179   tauBits = taus.to_ulong();
00180 }
00181 
00182 void L1RCTJetSummaryCard::fillOverFlowBits(std::vector<unsigned short> overflow){
00183   bitset<14> overflows;
00184   for(int i = 0; i<14; i++)
00185     overflows[i] = overflow.at(i);
00186   overFlowBits = overflows.to_ulong();
00187 }
00188 
00189 void L1RCTJetSummaryCard::fillQuietBits(){
00190   bitset<14> quiet;
00191 
00192   quietThresholdBarrel = rctLookupTables_->rctParameters()->jscQuietThresholdBarrel();
00193   quietThresholdEndcap = rctLookupTables_->rctParameters()->jscQuietThresholdEndcap();
00194 
00195   // use one threshold for barrel regions (first 8 in list, cards 0-3)
00196   for(int i = 0; i<8; i++){
00197     if((barrelRegions.at(i))>quietThresholdBarrel)
00198       quiet[i] = 0;  //switched 0 and 1
00199     else
00200       quiet[i] = 1;
00201   }
00202   // use second for endcap regions (last 6 in list, cards 4-6)
00203   for(int i = 8; i<14; i++){
00204     if((barrelRegions.at(i))>quietThresholdEndcap)
00205       quiet[i] = 0;  //switched 0 and 1
00206     else
00207       quiet[i] = 1;
00208   }
00209 
00210   quietBits = quiet.to_ulong();
00211 }
00212 
00213 // Sorts the egamma candidates with the algorithm used in the ASIC
00214 void L1RCTJetSummaryCard::asicSort(std::vector<unsigned short>& electrons)
00215 {
00216   unsigned short temp, temp2;
00217 
00218   asicCompare(electrons);
00219 
00220   // Rotate items prior to next compare
00221 
00222   temp = electrons.at(7);
00223   electrons.at(7) = electrons.at(5);
00224   electrons.at(5) = electrons.at(3);
00225   electrons.at(3) = electrons.at(1);
00226   electrons.at(1) = temp;
00227 
00228   // Second compare
00229 
00230   asicCompare(electrons);
00231 
00232   // Second rotate, different order this time
00233 
00234   temp = electrons.at(7);
00235   temp2 = electrons.at(5);
00236   electrons.at(7) = electrons.at(3);
00237   electrons.at(5) = electrons.at(1);
00238   electrons.at(3) = temp;
00239   electrons.at(1) = temp2;
00240 
00241   // Third compare
00242 
00243   asicCompare(electrons);
00244 
00245   // Third rotate, different again
00246 
00247   temp = electrons.at(1);
00248   electrons.at(1) = electrons.at(3);
00249   electrons.at(3) = electrons.at(5);
00250   electrons.at(5) = electrons.at(7);
00251   electrons.at(7) = temp;
00252 
00253   // Fourth compare
00254 
00255   asicCompare(electrons);
00256 
00257 }
00258 
00259 // Used in ASIC sort algorithm
00260 void L1RCTJetSummaryCard::asicCompare(std::vector<unsigned short>& array)
00261 {
00262   int i;
00263   unsigned short temp;
00264   for (i = 0; i < 4; i++)
00265     {
00266 
00267       unsigned short rank1 = rctLookupTables_->emRank(array.at(2 * i)>>4);
00268       unsigned short rank2 = rctLookupTables_->emRank(array.at(2 * i + 1)>>4);
00269 
00270       if (rank1 < rank2) // currently bottom 3 bits are rgn,crd
00271         {
00272           temp = array.at(2 * i);
00273           array.at(2 * i) = array.at((2 * i) + 1);
00274           array.at((2 * i) + 1) = temp;
00275         }
00276     }
00277 }
00278 
00279 
00280 void L1RCTJetSummaryCard::print(){
00281   std::cout << "tauBits " << tauBits << std::endl;
00282   std::cout << "MIPBits " << mipBits << std::endl;
00283   std::cout << "QuietBits " << quietBits << std::endl;
00284   for(int i=0; i<4;i++) {
00285     std::cout << "isoElectron " << i << " " << isolatedEGObjects.at(i) << std::endl;;
00286     std::cout << "nonIsoElectron " << i <<" "<< nonisolatedEGObjects.at(i) << std::endl;
00287   }
00288   std::cout << "Jets ";
00289   for(int i=0; i<22;i++)
00290     std::cout << jetRegions.at(i) << " ";
00291   std::cout << std::endl;
00292 }