Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:22

0001 #include "DataFormats/ForwardDetId/interface/HFNoseTriggerDetId.h"
0002 #include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include <ostream>
0005 #include <iostream>
0006 
0007 const HFNoseTriggerDetId HFNoseTriggerDetId::Undefined(HFNoseTrigger, 0, 0, 0, 0, 0, 0, 0);
0008 
0009 HFNoseTriggerDetId::HFNoseTriggerDetId() : DetId() {}
0010 
0011 HFNoseTriggerDetId::HFNoseTriggerDetId(uint32_t rawid) : DetId(rawid) {}
0012 
0013 HFNoseTriggerDetId::HFNoseTriggerDetId(
0014     int subdet, int zp, int type, int layer, int waferU, int waferV, int cellU, int cellV)
0015     : DetId(HGCalTrigger, ForwardEmpty) {
0016   int waferUabs(std::abs(waferU)), waferVabs(std::abs(waferV));
0017   int waferUsign = (waferU >= 0) ? 0 : 1;
0018   int waferVsign = (waferV >= 0) ? 0 : 1;
0019   int zside = (zp < 0) ? 1 : 0;
0020   id_ |= (((cellU & kHFNoseCellUMask) << kHFNoseCellUOffset) | ((cellV & kHFNoseCellVMask) << kHFNoseCellVOffset) |
0021           ((waferUabs & kHFNoseWaferUMask) << kHFNoseWaferUOffset) |
0022           ((waferUsign & kHFNoseWaferUSignMask) << kHFNoseWaferUSignOffset) |
0023           ((waferVabs & kHFNoseWaferVMask) << kHFNoseWaferVOffset) |
0024           ((waferVsign & kHFNoseWaferVSignMask) << kHFNoseWaferVSignOffset) |
0025           ((layer & kHFNoseLayerMask) << kHFNoseLayerOffset) | ((zside & kHFNoseZsideMask) << kHFNoseZsideOffset) |
0026           ((type & kHFNoseTypeMask) << kHFNoseTypeOffset) | ((subdet & kHFNoseSubdetMask) << kHFNoseSubdetOffset));
0027 }
0028 
0029 HFNoseTriggerDetId::HFNoseTriggerDetId(const DetId& gen) {
0030   if (!gen.null()) {
0031     if ((gen.det() != HGCalTrigger) || ((gen.subdetId() & kHFNoseSubdetMask) != HFNoseTrigger)) {
0032       throw cms::Exception("Invalid DetId")
0033           << "Cannot initialize HFNoseTriggerDetId from " << std::hex << gen.rawId() << std::dec;
0034     }
0035   }
0036   id_ = gen.rawId();
0037 }
0038 
0039 HFNoseTriggerDetId& HFNoseTriggerDetId::operator=(const DetId& gen) {
0040   if (!gen.null()) {
0041     if ((gen.det() != HGCalTrigger) || ((gen.subdetId() & kHFNoseSubdetMask) != HFNoseTrigger)) {
0042       throw cms::Exception("Invalid DetId")
0043           << "Cannot assign HFNoseTriggerDetId from " << std::hex << gen.rawId() << std::dec;
0044     }
0045   }
0046   id_ = gen.rawId();
0047   return (*this);
0048 }
0049 
0050 int HFNoseTriggerDetId::triggerCellX() const {
0051   int nT = (type() == HFNoseDetId::HFNoseFine) ? HFNoseDetId::HFNoseFineTrigger : HFNoseDetId::HFNoseCoarseTrigger;
0052   int N = nT * HFNoseTriggerCell;
0053   std::vector<int> vc = cellV();
0054   int x(0);
0055   for (auto const& v : vc) {
0056     x += (3 * (v - N) + 2);
0057   }
0058   return (x / static_cast<int>(vc.size()));
0059 }
0060 
0061 int HFNoseTriggerDetId::triggerCellY() const {
0062   int nT = (type() == HFNoseDetId::HFNoseFine) ? HFNoseDetId::HFNoseFineTrigger : HFNoseDetId::HFNoseCoarseTrigger;
0063   int N = nT * HFNoseTriggerCell;
0064   std::vector<int> uc = cellU();
0065   std::vector<int> vc = cellV();
0066   int y(0);
0067   for (unsigned int k = 0; k < uc.size(); ++k) {
0068     y += (2 * uc[k] - (N + vc[k]));
0069   }
0070   return (y / static_cast<int>(vc.size()));
0071 }
0072 
0073 std::vector<int> HFNoseTriggerDetId::cellU() const {
0074   std::vector<int> uc;
0075   int nT = (type() == HFNoseDetId::HFNoseFine) ? HFNoseDetId::HFNoseFineTrigger : HFNoseDetId::HFNoseCoarseTrigger;
0076   if ((triggerCellU() >= HFNoseTriggerCell) && (triggerCellV() >= HFNoseTriggerCell)) {
0077     int u0 = nT * triggerCellU();
0078     for (int i = 0; i < nT; ++i) {
0079       for (int j = 0; j < nT; ++j) {
0080         uc.emplace_back(u0 + i);
0081       }
0082     }
0083   } else if ((triggerCellU() < HFNoseTriggerCell) && (triggerCellU() <= triggerCellV())) {
0084     int u0 = nT * triggerCellU();
0085     for (int i = 0; i < nT; ++i) {
0086       for (int j = 0; j < nT; ++j) {
0087         uc.emplace_back(u0 + i);
0088       }
0089     }
0090   } else {
0091     int u0 = nT * (triggerCellU() - 1) + 1;
0092     for (int i = 0; i < nT; ++i) {
0093       for (int j = 0; j < nT; ++j) {
0094         uc.emplace_back(u0 + j);
0095       }
0096       ++u0;
0097     }
0098   }
0099   return uc;
0100 }
0101 
0102 std::vector<int> HFNoseTriggerDetId::cellV() const {
0103   std::vector<int> vc;
0104   int nT = (type() == HFNoseDetId::HFNoseFine) ? HFNoseDetId::HFNoseFineTrigger : HFNoseDetId::HFNoseCoarseTrigger;
0105   if ((triggerCellU() >= HFNoseTriggerCell) && (triggerCellV() >= HFNoseTriggerCell)) {
0106     int v0 = nT * triggerCellV();
0107     for (int i = 0; i < nT; ++i) {
0108       for (int j = 0; j < nT; ++j) {
0109         vc.emplace_back(v0 + j);
0110       }
0111     }
0112   } else if ((triggerCellU() < HFNoseTriggerCell) && (triggerCellU() <= triggerCellV())) {
0113     int v0 = nT * triggerCellV();
0114     for (int i = 0; i < nT; ++i) {
0115       for (int j = 0; j < nT; ++j) {
0116         vc.emplace_back(v0 + j);
0117       }
0118       ++v0;
0119     }
0120   } else {
0121     int v0 = nT * triggerCellV();
0122     for (int i = 0; i < nT; ++i) {
0123       for (int j = 0; j < nT; ++j) {
0124         vc.emplace_back(v0 + i);
0125       }
0126     }
0127   }
0128   return vc;
0129 }
0130 
0131 std::vector<std::pair<int, int> > HFNoseTriggerDetId::cellUV() const {
0132   std::vector<int> uc = cellU();
0133   std::vector<int> vc = cellV();
0134   std::vector<std::pair<int, int> > uv;
0135   for (unsigned int k = 0; k < uc.size(); ++k) {
0136     uv.emplace_back(uc[k], vc[k]);
0137   }
0138   return uv;
0139 }
0140 
0141 std::ostream& operator<<(std::ostream& s, const HFNoseTriggerDetId& id) {
0142   return s << " EE:HSil= " << id.isEE() << ":" << id.isHSilicon() << " type= " << id.type() << " z= " << id.zside()
0143            << " layer= " << id.layer() << " wafer(u,v:x,y)= (" << id.waferU() << "," << id.waferV() << ":"
0144            << id.waferX() << "," << id.waferY() << ")"
0145            << " triggerCell(u,v:x,y)= (" << id.triggerCellU() << "," << id.triggerCellV() << ":" << id.triggerCellX()
0146            << "," << id.triggerCellY() << ")";
0147 }