Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <iostream>
0002 #include <cstdlib>
0003 #include <cstdint>
0004 
0005 #include "UCTCard.hh"
0006 #include "UCTRegion.hh"
0007 #include "UCTGeometry.hh"
0008 #include "UCTLogging.hh"
0009 
0010 UCTCard::UCTCard(uint32_t crt, uint32_t crd, int fwv) : crate(crt), card(crd), cardSummary(0), fwVersion(fwv) {
0011   UCTGeometry g;
0012   regions.reserve(2 * g.getNRegions());
0013   for (uint32_t rgn = 0; rgn < g.getNRegions(); rgn++) {
0014     // Negative eta side
0015     regions.push_back(new UCTRegion(crate, card, true, rgn, fwVersion));
0016     // Positive eta side
0017     regions.push_back(new UCTRegion(crate, card, false, rgn, fwVersion));
0018   }
0019 }
0020 
0021 UCTCard::~UCTCard() {
0022   for (uint32_t i = 0; i < regions.size(); i++) {
0023     if (regions[i] != nullptr)
0024       delete regions[i];
0025   }
0026 }
0027 
0028 bool UCTCard::process() {
0029   cardSummary = 0;
0030   for (uint32_t i = 0; i < regions.size(); i++) {
0031     if (regions[i] != nullptr)
0032       regions[i]->process();
0033     cardSummary += regions[i]->et();
0034   }
0035   return true;
0036 }
0037 
0038 bool UCTCard::clearEvent() {
0039   cardSummary = 0;
0040   for (uint32_t i = 0; i < regions.size(); i++) {
0041     if (!regions[i]->clearEvent())
0042       return false;
0043   }
0044   return true;
0045 }
0046 
0047 bool UCTCard::setECALData(UCTTowerIndex t, bool ecalFG, uint32_t ecalET) {
0048   UCTGeometry g;
0049   uint32_t absCaloEta = std::abs(t.first);
0050   uint32_t absCaloPhi = std::abs(t.second);
0051   bool negativeEta = false;
0052   if (t.first < 0)
0053     negativeEta = true;
0054   uint32_t i = g.getRegion(absCaloEta, absCaloPhi) * 2;
0055   if (!negativeEta)
0056     i++;
0057   if (i > regions.size()) {
0058     LOG_ERROR << "UCTCard: Incorrect region requested -- bailing" << std::endl;
0059     exit(1);
0060   }
0061   return regions[i]->setECALData(t, ecalFG, ecalET);
0062 }
0063 
0064 bool UCTCard::setHCALData(UCTTowerIndex t, uint32_t hcalFB, uint32_t hcalET) {
0065   UCTGeometry g;
0066   uint32_t absCaloEta = std::abs(t.first);
0067   uint32_t absCaloPhi = std::abs(t.second);
0068   bool negativeEta = false;
0069   if (t.first < 0)
0070     negativeEta = true;
0071   uint32_t i = g.getRegion(absCaloEta, absCaloPhi) * 2;
0072   if (!negativeEta)
0073     i++;
0074   if (i > regions.size()) {
0075     LOG_ERROR << "UCTCard: Incorrect region requested -- bailing" << std::endl;
0076     exit(1);
0077   }
0078   return regions[i]->setHCALData(t, hcalFB, hcalET);
0079 }
0080 
0081 const UCTRegion* UCTCard::getRegion(UCTRegionIndex r) const {
0082   UCTGeometry g;
0083   UCTTowerIndex t = g.getUCTTowerIndex(r);
0084   uint32_t absCaloEta = std::abs(t.first);
0085   uint32_t absCaloPhi = std::abs(t.second);
0086   bool negativeEta = false;
0087   if (t.first < 0)
0088     negativeEta = true;
0089   return getRegion(negativeEta, absCaloEta, absCaloPhi);
0090 }
0091 
0092 const UCTRegion* UCTCard::getRegion(bool nE, uint32_t cEta, uint32_t cPhi) const {
0093   UCTGeometry g;
0094   uint32_t i = g.getRegion(cEta, cPhi) * 2;
0095   if (!nE)
0096     i++;
0097   if (i > regions.size()) {
0098     LOG_ERROR << "UCTCard: Incorrect region requested -- bailing" << std::endl;
0099     exit(1);
0100   }
0101   return regions[i];
0102 }
0103 
0104 std::ostream& operator<<(std::ostream& os, const UCTCard& c) {
0105   if (c.cardSummary > 0)
0106     os << "UCTCard: card = " << c.card << "; Summary = " << c.cardSummary << std::endl;
0107   return os;
0108 }