Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:09

0001 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0002 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0003 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0004 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetIdToModule.h"
0005 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetIdToROC.h"
0006 #include "DataFormats/DetId/interface/DetId.h"
0007 
0008 #include <cmath>
0009 #include <iomanip>
0010 #include <iostream>
0011 #include <map>
0012 #include <string>
0013 
0014 void testCell(int type) {
0015   int N = (type == 0) ? HGCSiliconDetId::HGCalHighDensityN : HGCSiliconDetId::HGCalLowDensityN;
0016   const int waferu(0), waferv(0), layer(1), zside(1);
0017   std::map<std::pair<int, int>, int> triggers;
0018   int ntot(0);
0019   for (int u = 0; u < 2 * N; ++u) {
0020     for (int v = 0; v < 2 * N; ++v) {
0021       if (((v - u) < N) && (u - v) <= N) {
0022         HGCSiliconDetId id(DetId::HGCalEE, zside, type, layer, waferu, waferv, u, v);
0023         std::cout << "ID " << std::hex << id.rawId() << std::dec << " " << id << " Trigger: " << id.triggerCellU()
0024                   << ":" << id.triggerCellV() << std::endl;
0025         std::pair<int, int> trig = id.triggerCellUV();
0026         std::map<std::pair<int, int>, int>::iterator itr = triggers.find(trig);
0027         if (itr == triggers.end()) {
0028           triggers[trig] = 0;
0029           itr = triggers.find(trig);
0030         }
0031         ++(itr->second);
0032         ++ntot;
0033       }
0034     }
0035   }
0036   std::cout << "Total of " << ntot << " cells in type " << type << " with " << triggers.size() << " trigger cells"
0037             << std::endl;
0038   int k(0);
0039   for (auto itr : triggers) {
0040     std::cout << "Trigger[" << k << "]  (" << (itr.first).first << ":" << (itr.first).second << ")  " << itr.second
0041               << std::endl;
0042     ++k;
0043   }
0044 }
0045 
0046 void testWafer(int layer, double rin, double rout) {
0047   const double waferSize(167.4408);
0048   const double rMaxFine(750.0), rMaxMiddle(1200.0);
0049   const int zside(1), cellu(0), cellv(0);
0050   const std::string waferType[2] = {"Virtual", "Real   "};
0051   double r = 0.5 * waferSize;
0052   double R = 2.0 * r / std::sqrt(3.0);
0053   double dy = 0.75 * R;
0054   double xc[6], yc[6];
0055   int N = (int)(0.5 * rout / r) + 2;
0056   int nreal(0), nvirtual(0);
0057   int ntype[3] = {0, 0, 0};
0058   for (int v = -N; v <= N; ++v) {
0059     for (int u = -N; u <= N; ++u) {
0060       int nr = 2 * v;
0061       int nc = -2 * u + v;
0062       double xpos = nc * r;
0063       double ypos = nr * dy;
0064       xc[0] = xpos + r;
0065       yc[0] = ypos + 0.5 * R;
0066       xc[1] = xpos;
0067       yc[1] = ypos + R;
0068       xc[2] = xpos - r;
0069       yc[2] = ypos + 0.5 * R;
0070       xc[3] = xpos - r;
0071       yc[3] = ypos - 0.5 * R;
0072       xc[4] = xpos;
0073       yc[4] = ypos - R;
0074       xc[5] = xpos + r;
0075       yc[5] = ypos - 0.5 * R;
0076       int cornerOne(0), cornerAll(1);
0077       for (int k = 0; k < 6; ++k) {
0078         double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
0079         if (rpos >= rin && rpos <= rout)
0080           cornerOne = 1;
0081         else
0082           cornerAll = 0;
0083       }
0084       if (cornerOne > 0) {
0085         double rr = std::sqrt(xpos * xpos + ypos * ypos);
0086         int type = (rr < rMaxFine) ? 0 : ((rr < rMaxMiddle) ? 1 : 2);
0087         HGCSiliconDetId id(DetId::HGCalEE, zside, type, layer, u, v, cellu, cellv);
0088         std::cout << waferType[cornerAll] << " Wafer " << id << std::endl;
0089         if (cornerAll == 1) {
0090           ++nreal;
0091           ++ntype[type];
0092         } else {
0093           ++nvirtual;
0094         }
0095       }
0096     }
0097   }
0098   std::cout << nreal << " full wafers of type 0:" << ntype[0] << " 1:" << ntype[1] << " 2:" << ntype[2] << " and "
0099             << nvirtual << " partial wafers for r-range " << rin << ":" << rout << std::endl;
0100 }
0101 
0102 void testScint(int layer) {
0103   int type = ((layer <= 8) ? 0 : ((layer <= 17) ? 1 : 2));
0104   int phimax = (type == 0) ? 360 : 288;
0105   int irmin = ((layer <= 12) ? 10 : ((layer <= 14) ? 14 : ((layer <= 18) ? 7 : 1)));
0106   int irmax = ((layer <= 12) ? 33 : ((layer <= 14) ? 37 : 42));
0107   int sipm = (layer <= 17) ? 0 : 1;
0108   for (int ring = irmin; ring <= irmax; ++ring) {
0109     for (int phi = 1; phi <= phimax; ++phi) {
0110       for (int zp = 0; zp < 2; ++zp) {
0111         int radius = (2 * zp - 1) * ring;
0112         HGCScintillatorDetId id(type, layer, radius, phi, false, sipm);
0113         std::cout << "Input " << type << ":" << layer << ":" << radius << ":" << phi << ":" << sipm << " ID "
0114                   << std::hex << id << std::dec;
0115         if ((id.iradius() != radius) || (id.iphi() != phi) || (id.layer() != layer) || (id.type() != type) ||
0116             (id.sipm() != sipm))
0117           std::cout << " ***** ERROR *****" << std::endl;
0118         else
0119           std::cout << std::endl;
0120       }
0121       phi += 9;
0122     }
0123     ring += 3;
0124   }
0125 }
0126 
0127 void testTriggerCell(int type) {
0128   int N = (type == 0) ? HGCSiliconDetId::HGCalHighDensityN : HGCSiliconDetId::HGCalLowDensityN;
0129   const int waferu(0), waferv(0), layer(1);
0130   std::string error[2] = {"ERROR", "OK"};
0131   int ntot(0), nerror(0);
0132   for (int iz = 0; iz < 2; ++iz) {
0133     int zside = 2 * iz - 1;
0134     for (int u = 0; u < 2 * N; ++u) {
0135       for (int v = 0; v < 2 * N; ++v) {
0136         if (((v - u) < N) && (u - v) <= N) {
0137           HGCSiliconDetId id(DetId::HGCalEE, zside, type, layer, waferu, waferv, u, v);
0138           std::cout << "ID " << std::hex << id.rawId() << std::dec << " " << id << " Trigger: " << id.triggerCellU()
0139                     << ":" << id.triggerCellV() << std::endl;
0140           HGCalTriggerDetId idt((int)(HGCalEETrigger),
0141                                 id.zside(),
0142                                 id.type(),
0143                                 id.layer(),
0144                                 id.waferU(),
0145                                 id.waferV(),
0146                                 id.triggerCellU(),
0147                                 id.triggerCellV());
0148           int ok(0);
0149           std::vector<std::pair<int, int> > uvs = idt.cellUV();
0150           for (auto const& uv : uvs) {
0151             HGCSiliconDetId idn(
0152                 DetId::HGCalEE, idt.zside(), idt.type(), idt.layer(), idt.waferU(), idt.waferV(), uv.first, uv.second);
0153             if (idn == id) {
0154               ok = 1;
0155               break;
0156             }
0157           }
0158           std::cout << "Trigger Cell: " << idt << " obtained from cell (" << error[ok] << ")" << std::endl;
0159           ++ntot;
0160           if (ok == 0)
0161             ++nerror;
0162         }
0163       }
0164     }
0165   }
0166   std::cout << "Total of " << ntot << " cells in type " << type << " with " << nerror << " errors for trigger cells"
0167             << std::endl;
0168 }
0169 
0170 void testROC() {
0171   HGCSiliconDetIdToROC idToROC;
0172   idToROC.print();
0173   for (int type = 0; type < 2; ++type) {
0174     int kmax = (type == 0) ? 6 : 3;
0175     for (int k = 1; k <= kmax; ++k) {
0176       auto cells = idToROC.getTriggerId(k, type);
0177       bool error(false);
0178       std::cout << "ROC " << type << ":" << k << " has " << cells.size() << " trigger cells:";
0179       unsigned int i(0);
0180       for (auto cell : cells) {
0181         int k0 = idToROC.getROCNumber(cell.first, cell.second, type);
0182         std::cout << " [" << i << "] (" << cell.first << "," << cell.second << "):" << k0;
0183         ++i;
0184         if (k0 != k)
0185           error = true;
0186       }
0187       if (error)
0188         std::cout << " ***** ERROR *****" << std::endl;
0189       else
0190         std::cout << std::endl;
0191     }
0192   }
0193 }
0194 
0195 void testModule(HGCSiliconDetId const& id) {
0196   HGCSiliconDetIdToModule hgc;
0197   HGCSiliconDetId module = hgc.getModule(id);
0198   std::vector<HGCSiliconDetId> ids = hgc.getDetIds(module);
0199   std::string ok = "***** ERROR *****";
0200   for (auto const& id0 : ids) {
0201     if (id0 == id) {
0202       ok = "";
0203       break;
0204     }
0205   }
0206   std::cout << "Module ID of " << id << " is " << module << " which has " << ids.size() << " cells " << ok << std::endl;
0207   for (unsigned int k = 0; k < ids.size(); ++k)
0208     std::cout << "ID[" << k << "] " << ids[k] << std::endl;
0209 }
0210 
0211 int main() {
0212   testCell(0);
0213   testCell(1);
0214   testWafer(1, 319.80, 1544.30);
0215   testWafer(28, 352.46, 1658.68);
0216   testScint(10);
0217   testScint(22);
0218   testTriggerCell(0);
0219   testTriggerCell(1);
0220   testROC();
0221   testModule(HGCSiliconDetId(DetId::HGCalEE, 1, 0, 1, 5, 4, 0, 10));
0222   testModule(HGCSiliconDetId(DetId::HGCalHSi, -1, 1, 30, -6, -4, 5, 5));
0223   return 0;
0224 }