00001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCT.h"
00002
00003 #include <vector>
00004 using std::vector;
00005
00006 #include <fstream>
00007 #include <string>
00008
00009 #include <iostream>
00010 using std::ostream;
00011 using std::cout;
00012 using std::cerr;
00013 using std::endl;
00014
00015 #include <iomanip>
00016
00017
00018
00019 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTLookupTables.h"
00020 #include "CondFormats/L1TObjects/interface/L1RCTParameters.h"
00021 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 void L1RCT::processEvent(){
00037 for(int i=0; i<18;i++)
00038 crates.at(i).processReceiverCards();
00039 shareNeighbors();
00040 for(int i=0; i<18;i++){
00041 crates.at(i).fillElectronIsolationCards();
00042 crates.at(i).processElectronIsolationCards();
00043 crates.at(i).fillJetSummaryCard();
00044 crates.at(i).processJetSummaryCard();
00045 }
00046 }
00047
00048 void L1RCT::makeCrates()
00049 {
00050 for(int i = 0; i<18; i++){
00051 L1RCTCrate c(i, rctLookupTables_);
00052 crates.push_back(c);
00053 }
00054 }
00055
00056 L1RCT::L1RCT(const L1RCTLookupTables* rctLookupTables) :
00057 rctLookupTables_(rctLookupTables),
00058 empty(),
00059 neighborMap(),
00060 barrel(18,std::vector<std::vector<unsigned short> >(7,std::vector<unsigned short>(64))),
00061 hf(18,std::vector<unsigned short>(8))
00062 {
00063 makeCrates();
00064 }
00065
00066 void L1RCT::input()
00067 {
00068 for(int i = 0; i<18; i++){
00069 crates.at(i).input(barrel.at(i),hf.at(i));
00070 }
00071 }
00072
00073 void L1RCT::input(std::vector<std::vector<std::vector<unsigned short> > > barrelIn,
00074 std::vector<std::vector<unsigned short> > hfIn)
00075 {
00076 for(int i = 0; i<18; i++){
00077 crates.at(i).input(barrelIn.at(i),hfIn.at(i));
00078 }
00079 }
00080
00081
00082
00083
00084
00085 void L1RCT::fileInput(const char* filename){
00086 unsigned short x;
00087 std::ifstream instream(filename);
00088 if(instream){
00089 for(int i = 0; i<18;i++){
00090 for(int j = 0; j<7; j++){
00091 for(int k = 0; k<64; k++){
00092 if(instream >> x){
00093 unsigned short bit = x/256;
00094 unsigned short energy = x&255;
00095 unsigned short input = energy*2 + bit;
00096 barrel.at(i).at(j).at(k) = input;
00097 }
00098 else
00099 break;
00100 }
00101 }
00102 for(int j = 0; j<8; j++){
00103 if(instream >> x){
00104 hf.at(i).at(j) = x;
00105 }
00106 else
00107 break;
00108 }
00109 }
00110 }
00111 input();
00112 }
00113
00114
00115
00116 void L1RCT::digiInput(const EcalTrigPrimDigiCollection& ecalCollection,
00117 const HcalTrigPrimDigiCollection& hcalCollection)
00118 {
00119
00120 for (int i = 0; i < 18; i++)
00121 {
00122 for (int j = 0; j < 7; j++)
00123 {
00124 for (int k = 0; k < 64; k++)
00125 {
00126 barrel.at(i).at(j).at(k) = 0;
00127 }
00128 }
00129 for (int j = 0; j < 8; j++)
00130 {
00131 hf.at(i).at(j) = 0;
00132 }
00133 }
00134
00135 int nEcalDigi = ecalCollection.size();
00136 if (nEcalDigi>4032) {nEcalDigi=4032;}
00137 for (int i = 0; i < nEcalDigi; i++){
00138 short ieta = (short) ecalCollection[i].id().ieta();
00139
00140 unsigned short absIeta = (unsigned short) abs(ieta);
00141 unsigned short cal_iphi = (unsigned short) ecalCollection[i].id().iphi();
00142 unsigned short iphi = (72 + 18 - cal_iphi) % 72;
00143
00144
00145 unsigned short crate = 999, card = 999, tower = 999;
00146 crate = rctLookupTables_->rctParameters()->calcCrate(iphi, ieta);
00147 card = rctLookupTables_->rctParameters()->calcCard(iphi, absIeta);
00148 tower = rctLookupTables_->rctParameters()->calcTower(iphi, absIeta);
00149
00150 unsigned short energy = ecalCollection[i].compressedEt();
00151 unsigned short fineGrain = (unsigned short) ecalCollection[i].fineGrain();
00152 unsigned short ecalInput = energy*2 + fineGrain;
00153
00154
00155 if ((crate<18) && (card<7) && (tower<32)) {
00156 barrel.at(crate).at(card).at(tower) = ecalInput;
00157 }
00158 else { std::cerr << "L1RCT: ecal out of range! tower = " << tower << " iphi is " << iphi << " absieta is " << absIeta << std::endl; }
00159 }
00160
00161
00162
00163 int nHcalDigi = hcalCollection.size();
00164
00165
00166 for (int i = 0; i < nHcalDigi; i++){
00167 short ieta = (short) hcalCollection[i].id().ieta();
00168 unsigned short absIeta = (unsigned short) abs(ieta);
00169 unsigned short cal_iphi = (unsigned short) hcalCollection[i].id().iphi();
00170
00171
00172 unsigned short iphi = (72 + 18 - cal_iphi) % 72;
00173
00174
00175
00176 if (absIeta >= 29) {
00177 iphi = iphi/4;
00178 }
00179
00180
00181 unsigned short crate = 999, card = 999, tower = 999;
00182 crate = rctLookupTables_->rctParameters()->calcCrate(iphi, ieta);
00183 if (absIeta < 29){
00184 card = rctLookupTables_->rctParameters()->calcCard(iphi, absIeta);
00185 }
00186 tower = rctLookupTables_->rctParameters()->calcTower(iphi, absIeta);
00187
00188
00189 unsigned short energy = hcalCollection[i].SOI_compressedEt();
00190 unsigned short fineGrain = (unsigned short) hcalCollection[i].SOI_fineGrain();
00191 unsigned short hcalInput = energy*2 + fineGrain;
00192 if (absIeta <= 28){
00193
00194 if ((crate<18) && (card<7) && (tower<32)) {
00195 barrel.at(crate).at(card).at(tower + 32) = hcalInput;
00196 }
00197 else { std::cout << "L1RCT: hcal out of range! tower = " << tower << std::endl; }
00198 }
00199 else if ((absIeta >= 29) && (absIeta <= 32)){
00200
00201 if ((crate<18) && (tower<8)) {
00202 hf.at(crate).at(tower) = hcalInput;
00203 }
00204 else { std::cout << "L1RCT: hf out of range! region = " << tower << std::endl; }
00205 }
00206
00207 }
00208
00209 input();
00210
00211 return;
00212
00213 }
00214
00215
00216
00217 void L1RCT::randomInput()
00218 {
00219 for(int i = 0; i<18;i++){
00220 for(int j = 0; j<7;j++){
00221 for(int k = 0; k<64; k++){
00222 barrel.at(i).at(j).at(k) = rand()%511;
00223 }
00224 }
00225 for(int j = 0; j<8;j++){
00226 hf.at(i).at(j) = rand()%255;
00227 }
00228 }
00229 input();
00230 return;
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240 void L1RCT::shareNeighbors(){
00241 L1RCTRegion *north;
00242 L1RCTRegion *south;
00243 L1RCTRegion *west;
00244 L1RCTRegion *east;
00245 L1RCTRegion *se;
00246 L1RCTRegion *sw;
00247 L1RCTRegion *nw;
00248 L1RCTRegion *ne;
00249 L1RCTRegion *primary;
00250
00251
00252 for(int i = 0; i < 18; i++){
00253 for(int j = 0; j < 7; j++){
00254 for(int k = 0; k < 2; k++){
00255
00256 primary = crates.at(i).getReceiverCard(j)->getRegion(k);
00257
00258 vector<int> northIndices = neighborMap.north(i,j,k);
00259 if(northIndices.at(0) != -1)
00260 north = crates.at(northIndices.at(0)).getReceiverCard(northIndices.at(1))->getRegion(northIndices.at(2));
00261 else north = ∅
00262
00263 vector<int> southIndices = neighborMap.south(i,j,k);
00264 if(southIndices.at(0) != -1)
00265 south = crates.at(southIndices.at(0)).getReceiverCard(southIndices.at(1))->getRegion(southIndices.at(2));
00266 else south = ∅
00267
00268 vector<int> westIndices = neighborMap.west(i,j,k);
00269 if(westIndices.at(0) != -1)
00270 west = crates.at(westIndices.at(0)).getReceiverCard(westIndices.at(1))->getRegion(westIndices.at(2));
00271 else west = ∅
00272
00273 vector<int> eastIndices = neighborMap.east(i,j,k);
00274 if(eastIndices.at(0) != -1)
00275 east = crates.at(eastIndices.at(0)).getReceiverCard(eastIndices.at(1))->getRegion(eastIndices.at(2));
00276 else east = ∅
00277
00278 vector<int> seIndices = neighborMap.se(i,j,k);
00279 if(seIndices.at(0) != -1)
00280 se = crates.at(seIndices.at(0)).getReceiverCard(seIndices.at(1))->getRegion(seIndices.at(2));
00281 else se = ∅
00282
00283 vector<int> swIndices = neighborMap.sw(i,j,k);
00284 if(swIndices.at(0) != -1)
00285 sw= crates.at(swIndices.at(0)).getReceiverCard(swIndices.at(1))->getRegion(swIndices.at(2));
00286 else sw = ∅
00287
00288 vector<int> neIndices = neighborMap.ne(i,j,k);
00289 if(neIndices.at(0) != -1)
00290 ne= crates.at(neIndices.at(0)).getReceiverCard(neIndices.at(1))->getRegion(neIndices.at(2));
00291 else ne = ∅
00292
00293 vector<int> nwIndices = neighborMap.nw(i,j,k);
00294 if(nwIndices.at(0) != -1)
00295 nw= crates.at(nwIndices.at(0)).getReceiverCard(nwIndices.at(1))->getRegion(nwIndices.at(2));
00296 else nw = ∅
00297
00298 primary->setNorthEt(north->giveNorthEt());
00299 primary->setNorthHE_FG(north->giveNorthHE_FG());
00300 primary->setSouthEt(south->giveSouthEt());
00301 primary->setSouthHE_FG(south->giveSouthHE_FG());
00302 primary->setEastEt(east->giveEastEt());
00303 primary->setEastHE_FG(east->giveEastHE_FG());
00304 primary->setWestEt(west->giveWestEt());
00305 primary->setWestHE_FG(west->giveWestHE_FG());
00306 primary->setSEEt(se->giveSEEt());
00307 primary->setSEHE_FG(se->giveSEHE_FG());
00308 primary->setSWEt(sw->giveSWEt());
00309 primary->setSWHE_FG(sw->giveSWHE_FG());
00310 primary->setNWEt(nw->giveNWEt());
00311 primary->setNWHE_FG(nw->giveNWHE_FG());
00312 primary->setNEEt(ne->giveNEEt());
00313 primary->setNEHE_FG(ne->giveNEHE_FG());
00314
00315
00316
00317 }
00318 }
00319 }
00320
00321 }
00322
00323 void L1RCT::print(){
00324 for(int i = 0; i<18; i++){
00325 std::cout << "Crate " << i << std::endl;
00326 crates.at(i).print();
00327 }
00328 }
00329
00330
00331
00332 L1CaloEmCollection L1RCT::getIsolatedEGObjects(unsigned crate){
00333 std::vector<unsigned short> isoEmObjects = crates.at(crate).getIsolatedEGObjects();
00334 L1CaloEmCollection isoEmCands;
00335 for (uint16_t i = 0; i < 4; i++){
00336 unsigned rgn = ((isoEmObjects.at(i)) & 1);
00337 unsigned crd = (((isoEmObjects.at(i))/2) & 7);
00338 unsigned energy = ((isoEmObjects.at(i))/16);
00339 unsigned rank = rctLookupTables_->emRank(energy);
00340 L1CaloEmCand isoCand(rank, rgn, crd, crate, 1, i, 0);
00341 isoEmCands.push_back(isoCand);
00342 }
00343 return isoEmCands;
00344 }
00345
00346
00347
00348
00349 L1CaloEmCollection L1RCT::getNonisolatedEGObjects(unsigned crate){
00350 std::vector<unsigned short> nonIsoEmObjects = crates.at(crate).getNonisolatedEGObjects();
00351 L1CaloEmCollection nonIsoEmCands;
00352 for (uint16_t i = 0; i < 4; i++){
00353 unsigned rgn = ((nonIsoEmObjects.at(i)) & 1);
00354 unsigned crd = (((nonIsoEmObjects.at(i))/2) & 7);
00355 unsigned energy = ((nonIsoEmObjects.at(i))/16);
00356 unsigned rank = rctLookupTables_->emRank(energy);
00357 L1CaloEmCand nonIsoCand(rank, rgn, crd, crate, 0, i, 0);
00358 nonIsoEmCands.push_back(nonIsoCand);
00359 }
00360 return nonIsoEmCands;
00361 }
00362
00363 vector<L1CaloRegion> L1RCT::getRegions(unsigned crate){
00364
00365 std::bitset<14> taus( (long) crates.at(crate).getTauBits());
00366 std::bitset<14> mips( (long) crates.at(crate).getMIPBits());
00367 std::bitset<14> quiets( (long) crates.at(crate).getQuietBits());
00368 std::bitset<14> overflows( (long) crates.at(crate).getOverFlowBits());
00369 std::vector<unsigned short> barrelEnergies = crates.at(crate).getBarrelRegions();
00370 std::vector<L1CaloRegion> regionCollection;
00371 for (unsigned card = 0; card < 7; card++){
00372 for (unsigned rgn = 0; rgn < 2; rgn++){
00373 bool tau = taus[card*2+rgn];
00374 bool mip = mips[card*2+rgn];
00375 bool quiet = quiets[card*2+rgn];
00376 bool overflow = overflows[card*2+rgn];
00377 unsigned barrelEnergy = barrelEnergies.at(card*2+rgn);
00378 L1CaloRegion region(barrelEnergy, overflow, tau, mip, quiet, crate, card, rgn);
00379 regionCollection.push_back(region);
00380 }
00381 }
00382
00383
00384 std::vector<unsigned short> hfEnergies = crates.at(crate).getHFRegions();
00385
00386 std::vector<unsigned short> hfFineGrainBits = crates.at(crate).getHFFineGrainBits();
00387 for (unsigned hfRgn = 0; hfRgn<8; hfRgn++){
00388 unsigned energy = hfEnergies.at(hfRgn);
00389 bool fineGrain = hfFineGrainBits.at(hfRgn);
00390 L1CaloRegion hfRegion(energy, fineGrain, crate, hfRgn);
00391 regionCollection.push_back(hfRegion);
00392 }
00393 return regionCollection;
00394 }