Skip to content

Commit

Permalink
Merge pull request CERN-PH-CMG#208 from cms-l1t-offline/nsmith-layer1…
Browse files Browse the repository at this point in the history
…-style

@mulhearn this one applies to 80X cmssw PR, same as the 81X version from earlier
  • Loading branch information
nsmith- committed Mar 31, 2016
2 parents d29872b + 3eb7182 commit 0913af8
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 183 deletions.
21 changes: 11 additions & 10 deletions L1Trigger/L1TCaloLayer1/plugins/L1TCaloLayer1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "L1Trigger/L1TCaloLayer1/src/UCTTower.hh"

#include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh"
#include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh"

#include "DataFormats/L1TCalorimeter/interface/CaloTower.h"

Expand Down Expand Up @@ -163,7 +164,7 @@ L1TCaloLayer1::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)

uint32_t expectedTotalET = 0;
if(!layer1->clearEvent()) {
std::cerr << "UCT: Failed to clear event" << std::endl;
LOG_ERROR << "UCT: Failed to clear event" << std::endl;
return;
}

Expand All @@ -175,7 +176,7 @@ L1TCaloLayer1::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
if(et != 0) {
UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
if(!layer1->setECALData(t,fgVeto,et)) {
std::cerr << "UCT: Failed loading an ECAL tower" << std::endl;
LOG_ERROR << "UCT: Failed loading an ECAL tower" << std::endl;
return;
}
expectedTotalET += et;
Expand Down Expand Up @@ -203,27 +204,27 @@ L1TCaloLayer1::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
uint32_t featureBits = 0;
if(fg) featureBits = 0x1F; // Set all five feature bits for the moment - they are not defined in HW / FW yet!
if(!layer1->setHCALData(t, featureBits, et)) {
std::cerr << "caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
std::cerr << "UCT: Failed loading an HCAL tower" << std::endl;
LOG_ERROR << "caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
LOG_ERROR << "UCT: Failed loading an HCAL tower" << std::endl;
return;

}
expectedTotalET += et;
}
}
else {
std::cerr << "Illegal Tower: caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
}
}
else {
std::cerr << "Illegal Tower: caloEta = " << caloEta << std::endl;
LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << std::endl;
}
}


//Process
if(!layer1->process()) {
std::cerr << "UCT: Failed to process layer 1" << std::endl;
LOG_ERROR << "UCT: Failed to process layer 1" << std::endl;
}


Expand Down Expand Up @@ -278,10 +279,10 @@ void
L1TCaloLayer1::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
{
if(!L1TCaloLayer1FetchLUTs(iSetup, ecalLUT, hcalLUT, useLSB, useECALLUT, useHCALLUT)) {
std::cerr << "L1TCaloLayer1::beginRun: failed to fetch LUTS - using unity" << std::endl;
LOG_ERROR << "L1TCaloLayer1::beginRun: failed to fetch LUTS - using unity" << std::endl;
}
if(!makeHFLUTs()) {
std::cerr << "L1TCaloLayer1::beginRun: failed to make HF LUTs - using unity" << std::endl;
LOG_ERROR << "L1TCaloLayer1::beginRun: failed to make HF LUTs - using unity" << std::endl;
}
vector<UCTCrate*> crates = layer1->getCrates();
for(uint32_t crt = 0; crt < crates.size(); crt++) {
Expand All @@ -291,7 +292,7 @@ L1TCaloLayer1::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
for(uint32_t rgn = 0; rgn < regions.size(); rgn++) {
vector<UCTTower*> towers = regions[rgn]->getTowers();
for(uint32_t twr = 0; twr < towers.size(); twr++) {
if(rgn < NRegionsInCard) {
if(rgn < l1tcalo::NRegionsInCard) {
towers[twr]->setECALLUT(&ecalLUT);
towers[twr]->setHCALLUT(&hcalLUT);
}
Expand Down
5 changes: 3 additions & 2 deletions L1Trigger/L1TCaloLayer1/src/L1TCaloLayer1FetchLUTs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CondFormats/DataRecord/interface/L1EmEtScaleRcd.h"

#include "L1TCaloLayer1FetchLUTs.hh"
#include "UCTLogging.hh"

bool L1TCaloLayer1FetchLUTs(const edm::EventSetup& iSetup,
std::vector< std::vector< std::vector < uint32_t > > > &eLUT,
Expand Down Expand Up @@ -55,7 +56,7 @@ bool L1TCaloLayer1FetchLUTs(const edm::EventSetup& iSetup,
if(useECALLUT) {
double linearizedECalInput = e->et(ecalInput, absCaloEta, 1);
if(linearizedECalInput != (e->et(ecalInput, absCaloEta, -1))) {
std::cerr << "L1TCaloLayer1FetchLUTs - ecal scale factors are different for positive and negative eta ! :(" << std::endl;
LOG_ERROR << "L1TCaloLayer1FetchLUTs - ecal scale factors are different for positive and negative eta ! :(" << std::endl;
}
// Use hcal = 0 to get ecal only energy but in RCT JetMET scale - should be 8-bit max
double calibratedECalInput = linearizedECalInput;
Expand Down Expand Up @@ -86,7 +87,7 @@ bool L1TCaloLayer1FetchLUTs(const edm::EventSetup& iSetup,
if(useHCALLUT) {
double linearizedHcalInput = h->et(hcalInput, absCaloEta, 1);
if(linearizedHcalInput != (h->et(hcalInput, absCaloEta, -1))) {
std::cerr << "L1TCaloLayer1FetchLUTs - hcal scale factors are different for positive and negative eta ! :(" << std::endl;
LOG_ERROR << "L1TCaloLayer1FetchLUTs - hcal scale factors are different for positive and negative eta ! :(" << std::endl;
}
// Use ecal = 0 to get hcal only energy but in RCT JetMET scale - should be 8-bit max
double calibratedHcalInput = linearizedHcalInput;
Expand Down
12 changes: 7 additions & 5 deletions L1Trigger/L1TCaloLayer1/src/UCTCard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#include "UCTCard.hh"
#include "UCTRegion.hh"
#include "UCTGeometry.hh"
#include "UCTLogging.hh"

UCTCard::UCTCard(uint32_t crt, uint32_t crd) :
crate(crt),
card(crd),
cardSummary(0) {
UCTGeometry g;
regions.reserve(2*g.getNRegions());
for(uint32_t rgn = 0; rgn < g.getNRegions(); rgn++) {
// Negative eta side
regions.push_back(new UCTRegion(crate, card, true, rgn));
Expand Down Expand Up @@ -51,7 +53,7 @@ bool UCTCard::setECALData(UCTTowerIndex t, bool ecalFG, uint32_t ecalET) {
uint32_t i = g.getRegion(absCaloEta, absCaloPhi) * 2;
if(!negativeEta) i++;
if(i > regions.size()) {
std::cerr << "UCTCard: Incorrect region requested -- bailing" << std::endl;
LOG_ERROR << "UCTCard: Incorrect region requested -- bailing" << std::endl;
exit(1);
}
return regions[i]->setECALData(t, ecalFG, ecalET);
Expand All @@ -66,7 +68,7 @@ bool UCTCard::setHCALData(UCTTowerIndex t, uint32_t hcalFB, uint32_t hcalET) {
uint32_t i = g.getRegion(absCaloEta, absCaloPhi) * 2;
if(!negativeEta) i++;
if(i > regions.size()) {
std::cerr << "UCTCard: Incorrect region requested -- bailing" << std::endl;
LOG_ERROR << "UCTCard: Incorrect region requested -- bailing" << std::endl;
exit(1);
}
return regions[i]->setHCALData(t, hcalFB, hcalET);
Expand All @@ -75,8 +77,8 @@ bool UCTCard::setHCALData(UCTTowerIndex t, uint32_t hcalFB, uint32_t hcalET) {
const UCTRegion* UCTCard::getRegion(UCTRegionIndex r) const {
UCTGeometry g;
UCTTowerIndex t = g.getUCTTowerIndex(r);
uint32_t absCaloEta = abs(t.first);
uint32_t absCaloPhi = abs(t.second);
uint32_t absCaloEta = std::abs(t.first);
uint32_t absCaloPhi = std::abs(t.second);
bool negativeEta = false;
if(t.first < 0) negativeEta = true;
return getRegion(negativeEta, absCaloEta, absCaloPhi);
Expand All @@ -87,7 +89,7 @@ const UCTRegion* UCTCard::getRegion(bool nE, uint32_t cEta, uint32_t cPhi) const
uint32_t i = g.getRegion(cEta, cPhi) * 2;
if(!nE) i++;
if(i > regions.size()) {
std::cerr << "UCTCard: Incorrect region requested -- bailing" << std::endl;
LOG_ERROR << "UCTCard: Incorrect region requested -- bailing" << std::endl;
exit(1);
}
return regions[i];
Expand Down
7 changes: 4 additions & 3 deletions L1Trigger/L1TCaloLayer1/src/UCTCrate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "UCTCrate.hh"
#include "UCTCard.hh"
#include "UCTGeometry.hh"
#include "UCTLogging.hh"

UCTCrate::UCTCrate(uint32_t crt) :
crate(crt),
Expand Down Expand Up @@ -44,7 +45,7 @@ bool UCTCrate::setECALData(UCTTowerIndex t, bool ecalFG, uint32_t ecalET) {
UCTGeometry g;
uint32_t i = g.getCard(t.first, t.second);
if(i > cards.size()) {
std::cerr << "UCTCrate: Incorrect (caloEta, caloPhi) -- bailing" << std::endl;
LOG_ERROR << "UCTCrate: Incorrect (caloEta, caloPhi) -- bailing" << std::endl;
exit(1);
}
return cards[i]->setECALData(t, ecalFG, ecalET);
Expand All @@ -54,7 +55,7 @@ bool UCTCrate::setHCALData(UCTTowerIndex t, uint32_t hcalFB, uint32_t hcalET) {
UCTGeometry g;
uint32_t i = g.getCard(t.first, t.second);
if(i > cards.size()) {
std::cerr << "UCTCrate: Incorrect (caloEta, caloPhi) -- bailing" << std::endl;
LOG_ERROR << "UCTCrate: Incorrect (caloEta, caloPhi) -- bailing" << std::endl;
exit(1);
}
return cards[i]->setHCALData(t, hcalFB, hcalET);
Expand All @@ -64,7 +65,7 @@ const UCTCard* UCTCrate::getCard(UCTTowerIndex t) const {
UCTGeometry g;
uint32_t i = g.getCard(t.first, t.second);
if(i > cards.size()) {
std::cerr << "UCTCrate: Incorrect (caloEta, caloPhi) -- bailing" << std::endl;
LOG_ERROR << "UCTCrate: Incorrect (caloEta, caloPhi) -- bailing" << std::endl;
exit(1);
}
return cards[i];
Expand Down
89 changes: 44 additions & 45 deletions L1Trigger/L1TCaloLayer1/src/UCTGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,70 @@
#include <stdint.h>

#include "UCTGeometry.hh"
#include "UCTLogging.hh"

UCTGeometry::UCTGeometry() {
twrEtaValues[0] = 0;
for(unsigned int i = 0; i < 20; i++) {
twrEtaValues[i + 1] = 0.0436 + i * 0.0872;
}
twrEtaValues[21] = 1.785;
twrEtaValues[22] = 1.880;
twrEtaValues[23] = 1.9865;
twrEtaValues[24] = 2.1075;
twrEtaValues[25] = 2.247;
twrEtaValues[26] = 2.411;
twrEtaValues[27] = 2.575;
twrEtaValues[28] = 2.825;
}

uint32_t UCTGeometry::getLinkNumber(bool negativeEta, uint32_t region,
uint32_t iEta, uint32_t iPhi) {
if(checkRegion(region)) {
std::cerr << "Invalid region number: region = " << region << std::endl;
LOG_ERROR << "Invalid region number: region = " << region << std::endl;
exit(1);
}
if(checkEtaIndex(region, iEta)) {
std::cerr << "Invalid eta index: iEta = " << iEta << std::endl;
LOG_ERROR << "Invalid eta index: iEta = " << iEta << std::endl;
exit(1);
}
if(checkPhiIndex(region, iPhi)) {
std::cerr << "Invalid eta index: iPhi = " << iPhi << std::endl;
LOG_ERROR << "Invalid eta index: iPhi = " << iPhi << std::endl;
exit(1);
}
uint32_t linkNumber = 0xDEADBEEF;
if(region < MaxRegionNumber) {
if(iEta < NEtaInRegion / 2) {
if(region < l1tcalo::MaxRegionNumber) {
if(iEta < l1tcalo::NEtaInRegion / 2) {
linkNumber = region * 2;
}
else {
linkNumber = region * 2 + 1;
}
}
else {
linkNumber = NRegionsInCard * 2 + iPhi;
linkNumber = l1tcalo::NRegionsInCard * 2 + iPhi;
}

if(!negativeEta) {
linkNumber += NRegionsInCard * 2 + 2;
linkNumber += l1tcalo::NRegionsInCard * 2 + 2;
}
return linkNumber;
}

int UCTGeometry::getCaloEtaIndex(bool negativeSide, uint32_t region, uint32_t iEta) {

if(checkRegion(region)) {
std::cerr << "Invalid region number: region = " << region << std::endl;
LOG_ERROR << "Invalid region number: region = " << region << std::endl;
exit(1);
}
if(checkEtaIndex(region, iEta)) {
std::cerr << "Invalid eta index: iEta = " << iEta << std::endl;
LOG_ERROR << "Invalid eta index: iEta = " << iEta << std::endl;
exit(1);
}

int caloEtaIndex = region * NEtaInRegion + iEta + 1;
int caloEtaIndex = region * l1tcalo::NEtaInRegion + iEta + 1;
if(region > 6) {
caloEtaIndex = (region - 7) * NHFEtaInRegion + iEta + 30;
caloEtaIndex = (region - 7) * l1tcalo::NHFEtaInRegion + iEta + 30;
}

if(negativeSide) return -caloEtaIndex;
Expand All @@ -61,15 +77,15 @@ int UCTGeometry::getCaloEtaIndex(bool negativeSide, uint32_t region, uint32_t iE
int UCTGeometry::getCaloPhiIndex(uint32_t crate, uint32_t card,
uint32_t region, uint32_t iPhi) {
if(checkCrate(crate)) {
std::cerr << "Invalid crate number: crate = " << crate << std::endl;
LOG_ERROR << "Invalid crate number: crate = " << crate << std::endl;
exit(1);
}
if(checkCard(card)) {
std::cerr << "Invalid card number: card = " << card << std::endl;
LOG_ERROR << "Invalid card number: card = " << card << std::endl;
exit(1);
}
if(checkPhiIndex(region, iPhi)) {
std::cerr << "Invalid phi index: iPhi = " << iPhi << std::endl;
LOG_ERROR << "Invalid phi index: iPhi = " << iPhi << std::endl;
exit(1);
}
int caloPhiIndex = 0xDEADBEEF;
Expand All @@ -88,11 +104,11 @@ int UCTGeometry::getCaloPhiIndex(uint32_t crate, uint32_t card,

uint32_t UCTGeometry::getUCTRegionPhiIndex(uint32_t crate, uint32_t card) {
if(checkCrate(crate)) {
std::cerr << "Invalid crate number: crate = " << crate << std::endl;
LOG_ERROR << "Invalid crate number: crate = " << crate << std::endl;
exit(1);
}
if(checkCard(card)) {
std::cerr << "Invalid card number: card = " << card << std::endl;
LOG_ERROR << "Invalid card number: card = " << card << std::endl;
exit(1);
}
uint32_t uctRegionPhiIndex = 0xDEADBEEF;
Expand Down Expand Up @@ -142,37 +158,37 @@ uint32_t UCTGeometry::getCard(int caloEta, int caloPhi) {

uint32_t UCTGeometry::getRegion(int caloEta, int caloPhi) {
uint32_t absCEta = abs(caloEta);
if((absCEta - 1) < (NRegionsInCard * NEtaInRegion))
return (absCEta - 1) / NEtaInRegion;
if((absCEta - 1) < (l1tcalo::NRegionsInCard * l1tcalo::NEtaInRegion))
return (absCEta - 1) / l1tcalo::NEtaInRegion;
else
return NRegionsInCard + ((absCEta - 2 - (NRegionsInCard * NEtaInRegion)) / NHFEtaInRegion);
return l1tcalo::NRegionsInCard + ((absCEta - 2 - (l1tcalo::NRegionsInCard * l1tcalo::NEtaInRegion)) / l1tcalo::NHFEtaInRegion);
}

uint32_t UCTGeometry::getiEta(int caloEta) {
uint32_t absCEta = abs(caloEta);
if((absCEta - 1) < (NRegionsInCard * NEtaInRegion))
return (absCEta - 1) % NEtaInRegion;
if((absCEta - 1) < (l1tcalo::NRegionsInCard * l1tcalo::NEtaInRegion))
return (absCEta - 1) % l1tcalo::NEtaInRegion;
else
return absCEta % NHFEtaInRegion; // To account for missing tower 29
return absCEta % l1tcalo::NHFEtaInRegion; // To account for missing tower 29
}

uint32_t UCTGeometry::getiPhi(int caloPhi) {
return (caloPhi + 1) % NPhiInCard;
return (caloPhi + 1) % l1tcalo::NPhiInCard;
}

uint32_t UCTGeometry::getNEta(uint32_t region) {
uint32_t nEta = 0xDEADBEEF;
if(region < CaloHFRegionStart) {
nEta = NEtaInRegion;
if(region < l1tcalo::CaloHFRegionStart) {
nEta = l1tcalo::NEtaInRegion;
}
else {
nEta = NHFEtaInRegion;
nEta = l1tcalo::NHFEtaInRegion;
}
return nEta;
}

uint32_t UCTGeometry::getNPhi(uint32_t region) {
return NPhiInRegion;
return l1tcalo::NPhiInRegion;
}

UCTRegionIndex UCTGeometry::getUCTRegionIndex(int caloEta, int caloPhi) {
Expand All @@ -188,7 +204,7 @@ UCTRegionIndex UCTGeometry::getUCTRegionIndex(bool negativeSide, uint32_t crate,
}

UCTTowerIndex UCTGeometry::getUCTTowerIndex(UCTRegionIndex region, uint32_t iEta, uint32_t iPhi) {
if(iPhi >= NPhiInRegion || iEta >= NEtaInRegion) {
if(iPhi >= l1tcalo::NPhiInRegion || iEta >= l1tcalo::NEtaInRegion) {
return UCTTowerIndex(0, 0); // Illegal values
}
int regionEta = region.first;
Expand All @@ -200,23 +216,6 @@ UCTTowerIndex UCTGeometry::getUCTTowerIndex(UCTRegionIndex region, uint32_t iEta
}

double UCTGeometry::getUCTTowerEta(int caloEta) {
static bool first = true;
static double twrEtaValues[29];
if(first) {
twrEtaValues[0] = 0;
for(unsigned int i = 0; i < 20; i++) {
twrEtaValues[i + 1] = 0.0436 + i * 0.0872;
}
twrEtaValues[21] = 1.785;
twrEtaValues[22] = 1.880;
twrEtaValues[23] = 1.9865;
twrEtaValues[24] = 2.1075;
twrEtaValues[25] = 2.247;
twrEtaValues[26] = 2.411;
twrEtaValues[27] = 2.575;
twrEtaValues[28] = 2.825;
first = false;
}
uint32_t absCaloEta = abs(caloEta);
if(absCaloEta <= 28) return twrEtaValues[absCaloEta];
else return -999.;
Expand Down
Loading

0 comments on commit 0913af8

Please sign in to comment.