Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:15

0001 #include <iostream>
0002 #include <iomanip>
0003 #include <cstdlib>
0004 #include <cstdint>
0005 
0006 #include "UCTLayer1.hh"
0007 
0008 #include "UCTCrate.hh"
0009 #include "UCTCard.hh"
0010 #include "UCTRegion.hh"
0011 #include "UCTTower.hh"
0012 
0013 #include "UCTGeometry.hh"
0014 #include "UCTLogging.hh"
0015 
0016 using namespace l1tcalo;
0017 
0018 UCTLayer1::UCTLayer1(int fwv) : uctSummary(0), fwVersion(fwv) {
0019   UCTGeometry g;
0020   crates.reserve(g.getNCrates());
0021   for (uint32_t crate = 0; crate < g.getNCrates(); crate++) {
0022     crates.push_back(new UCTCrate(crate, fwVersion));
0023   }
0024 }
0025 
0026 UCTLayer1::~UCTLayer1() {
0027   for (uint32_t i = 0; i < crates.size(); i++) {
0028     if (crates[i] != nullptr)
0029       delete crates[i];
0030   }
0031 }
0032 
0033 bool UCTLayer1::clearEvent() {
0034   for (uint32_t i = 0; i < crates.size(); i++) {
0035     if (crates[i] != nullptr)
0036       crates[i]->clearEvent();
0037   }
0038   return true;
0039 }
0040 
0041 const UCTRegion* UCTLayer1::getRegion(int regionEtaIndex, uint32_t regionPhiIndex) const {
0042   if (regionEtaIndex == 0 || (uint32_t)std::abs(regionEtaIndex) > (NRegionsInCard + NHFRegionsInCard) ||
0043       regionPhiIndex >= MaxUCTRegionsPhi) {
0044     return nullptr;
0045   }
0046   // Get (0,0) tower region information
0047   UCTGeometry g;
0048   UCTRegionIndex r = UCTRegionIndex(regionEtaIndex, regionPhiIndex);
0049   UCTTowerIndex t = g.getUCTTowerIndex(r);
0050   uint32_t absCaloEta = std::abs(t.first);
0051   uint32_t absCaloPhi = std::abs(t.second);
0052   uint32_t crt = g.getCrate(absCaloEta, absCaloPhi);
0053   if (crt >= crates.size()) {
0054     LOG_ERROR << "UCTLayer1::getRegion - Crate number is wrong - " << std::hex << crt << std::dec << " (rEta,rPhi)=("
0055               << regionEtaIndex << "," << regionPhiIndex << ")"
0056               << " (eta,phi)=(" << absCaloEta << "," << absCaloPhi << ")" << std::endl;
0057     exit(1);
0058   }
0059   const UCTCrate* crate = crates[crt];
0060   const UCTCard* card = crate->getCard(t);
0061   const UCTRegion* region = card->getRegion(r);
0062   return region;
0063 }
0064 
0065 const UCTTower* UCTLayer1::getTower(int caloEta, int caloPhi) const {
0066   if (caloPhi < 0) {
0067     LOG_ERROR << "UCT::getTower - Negative caloPhi is unacceptable -- bailing" << std::endl;
0068     exit(1);
0069   }
0070   UCTGeometry g;
0071   UCTTowerIndex twr = UCTTowerIndex(caloEta, caloPhi);
0072   const UCTRegionIndex rgn = g.getUCTRegionIndex(twr);
0073   const UCTRegion* region = getRegion(rgn);
0074   const UCTTower* tower = region->getTower(twr);
0075   return tower;
0076 }
0077 
0078 bool UCTLayer1::setECALData(UCTTowerIndex t, bool ecalFG, uint32_t ecalET) {
0079   uint32_t absCaloEta = std::abs(t.first);
0080   uint32_t absCaloPhi = std::abs(t.second);
0081   UCTGeometry g;
0082   uint32_t crt = g.getCrate(absCaloEta, absCaloPhi);
0083   if (crt >= crates.size()) {
0084     LOG_ERROR << "UCTLayer1::setECALData - Crate number is wrong - " << std::hex << crt << std::dec << " (eta,phi)=("
0085               << absCaloEta << "," << absCaloPhi << ")" << std::endl;
0086     exit(1);
0087   }
0088   UCTCrate* crate = crates[crt];
0089   return crate->setECALData(t, ecalFG, ecalET);
0090 }
0091 
0092 bool UCTLayer1::setHCALData(UCTTowerIndex t, uint32_t hcalFB, uint32_t hcalET) {
0093   uint32_t absCaloEta = std::abs(t.first);
0094   uint32_t absCaloPhi = std::abs(t.second);
0095   UCTGeometry g;
0096   uint32_t crt = g.getCrate(absCaloEta, absCaloPhi);
0097   if (crt >= crates.size()) {
0098     LOG_ERROR << "UCTLayer1::setHCALData - Crate number is wrong - " << std::hex << crt << std::dec << " (eta,phi)=("
0099               << absCaloEta << "," << absCaloPhi << ")" << std::endl;
0100     exit(1);
0101   }
0102   UCTCrate* crate = crates[crt];
0103   return crate->setHCALData(t, hcalFB, hcalET);
0104 }
0105 
0106 bool UCTLayer1::process() {
0107   uctSummary = 0;
0108   for (uint32_t i = 0; i < crates.size(); i++) {
0109     if (crates[i] != nullptr) {
0110       crates[i]->process();
0111       uctSummary += crates[i]->et();
0112     }
0113   }
0114 
0115   return true;
0116 }
0117 
0118 std::ostream& operator<<(std::ostream& os, const UCTLayer1& l) {
0119   os << "UCTLayer1: Summary " << l.uctSummary << std::endl;
0120   return os;
0121 }