Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/ForwardDetId/interface/HFNoseDetId.h"
0002 #include "DataFormats/ForwardDetId/interface/HFNoseTriggerDetId.h"
0003 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0004 #include "DataFormats/ForwardDetId/interface/HFNoseDetIdToModule.h"
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 
0007 #include <cmath>
0008 #include <iomanip>
0009 #include <iostream>
0010 #include <map>
0011 #include <string>
0012 
0013 void testCell(int type) {
0014   int N = (type == 0) ? HFNoseDetId::HFNoseFineN : HFNoseDetId::HFNoseCoarseN;
0015   const int waferu(0), waferv(0), layer(1), zside(1);
0016   std::map<std::pair<int, int>, int> triggers;
0017   int ntot(0);
0018   for (int u = 0; u < 2 * N; ++u) {
0019     for (int v = 0; v < 2 * N; ++v) {
0020       if (((v - u) < N) && (u - v) <= N) {
0021         HFNoseDetId id(zside, type, layer, waferu, waferv, u, v);
0022         std::cout << "ID " << std::hex << id.rawId() << std::dec << " " << id << " Trigger: " << id.triggerCellU()
0023                   << ":" << id.triggerCellV() << std::endl;
0024         std::pair<int, int> trig = id.triggerCellUV();
0025         std::map<std::pair<int, int>, int>::iterator itr = triggers.find(trig);
0026         if (itr == triggers.end()) {
0027           triggers[trig] = 0;
0028           itr = triggers.find(trig);
0029         }
0030         ++(itr->second);
0031         ++ntot;
0032       }
0033     }
0034   }
0035   std::cout << "Total of " << ntot << " cells in type " << type << " with " << triggers.size() << " trigger cells"
0036             << std::endl;
0037   int k(0);
0038   for (auto itr : triggers) {
0039     std::cout << "Trigger[" << k << "]  (" << (itr.first).first << ":" << (itr.first).second << ")  " << itr.second
0040               << std::endl;
0041     ++k;
0042   }
0043 }
0044 
0045 void testWafer(int layer, double rin, double rout) {
0046   const double waferSize(167.4408);
0047   const double rMaxFine(750.0), rMaxMiddle(1200.0);
0048   const int zside(1), cellu(0), cellv(0);
0049   const std::string waferType[2] = {"Virtual", "Real   "};
0050   double r = 0.5 * waferSize;
0051   double R = 2.0 * r / std::sqrt(3.0);
0052   double dy = 0.75 * R;
0053   double xc[6], yc[6];
0054   int N = (int)(0.5 * rout / r) + 2;
0055   int nreal(0), nvirtual(0);
0056   int ntype[3] = {0, 0, 0};
0057   for (int v = -N; v <= N; ++v) {
0058     for (int u = -N; u <= N; ++u) {
0059       int nr = 2 * v;
0060       int nc = -2 * u + v;
0061       double xpos = nc * r;
0062       double ypos = nr * dy;
0063       xc[0] = xpos + r;
0064       yc[0] = ypos + 0.5 * R;
0065       xc[1] = xpos;
0066       yc[1] = ypos + R;
0067       xc[2] = xpos - r;
0068       yc[2] = ypos + 0.5 * R;
0069       xc[3] = xpos - r;
0070       yc[3] = ypos - 0.5 * R;
0071       xc[4] = xpos;
0072       yc[4] = ypos - R;
0073       xc[5] = xpos + r;
0074       yc[5] = ypos - 0.5 * R;
0075       int cornerOne(0), cornerAll(1);
0076       for (int k = 0; k < 6; ++k) {
0077         double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
0078         if (rpos >= rin && rpos <= rout)
0079           cornerOne = 1;
0080         else
0081           cornerAll = 0;
0082       }
0083       if (cornerOne > 0) {
0084         double rr = std::sqrt(xpos * xpos + ypos * ypos);
0085         int type = (rr < rMaxFine) ? 0 : ((rr < rMaxMiddle) ? 1 : 2);
0086         HFNoseDetId id(zside, type, layer, u, v, cellu, cellv);
0087         std::cout << waferType[cornerAll] << " Wafer " << id << std::endl;
0088         if (cornerAll == 1) {
0089           ++nreal;
0090           ++ntype[type];
0091         } else {
0092           ++nvirtual;
0093         }
0094       }
0095     }
0096   }
0097   std::cout << nreal << " full wafers of type 0:" << ntype[0] << " 1:" << ntype[1] << " 2:" << ntype[2] << " and "
0098             << nvirtual << " partial wafers for r-range " << rin << ":" << rout << std::endl;
0099 }
0100 
0101 void testTriggerCell(int type) {
0102   int N = (type == 0) ? HFNoseDetId::HFNoseFineN : HFNoseDetId::HFNoseCoarseN;
0103   const int waferu(0), waferv(0), layer(1);
0104   std::string error[2] = {"ERROR", "OK"};
0105   int ntot(0), nerror(0);
0106   for (int iz = 0; iz <= 1; ++iz) {
0107     int zside = 2 * iz - 1;
0108     for (int u = 0; u < 2 * N; ++u) {
0109       for (int v = 0; v < 2 * N; ++v) {
0110         if (((v - u) < N) && (u - v) <= N) {
0111           HFNoseDetId id(zside, type, layer, waferu, waferv, u, v);
0112           HFNoseTriggerDetId idt((int)(HFNoseTrigger),
0113                                  id.zside(),
0114                                  id.type(),
0115                                  id.layer(),
0116                                  id.waferU(),
0117                                  id.waferV(),
0118                                  id.triggerCellU(),
0119                                  id.triggerCellV());
0120           std::cout << "ID " << std::hex << id.rawId() << std::dec << " " << id << " Trigger: " << id.triggerCellU()
0121                     << ":" << id.triggerCellV() << " Trigger " << idt << std::endl;
0122           int ok(0);
0123           std::vector<std::pair<int, int> > uvs = idt.cellUV();
0124           for (auto const& uv : uvs) {
0125             HFNoseDetId idn(idt.zside(), idt.type(), idt.layer(), idt.waferU(), idt.waferV(), uv.first, uv.second);
0126             if (idn == id) {
0127               ok = 1;
0128               break;
0129             }
0130           }
0131           std::cout << "Trigger Cell: " << idt << " obtained from cell (" << error[ok] << ")" << std::endl;
0132           std::cout << "Check " << idt << " from rawId " << HGCalTriggerDetId(idt.rawId()) << " from DetId "
0133                     << HGCalTriggerDetId(DetId(idt.rawId())) << std::endl;
0134           ++ntot;
0135           if (ok == 0)
0136             ++nerror;
0137         }
0138       }
0139     }
0140   }
0141   std::cout << "Total of " << ntot << " cells in type " << type << " with " << nerror << " errors for trigger cells"
0142             << std::endl;
0143 }
0144 
0145 void testModule(HFNoseDetId const& id) {
0146   HFNoseDetIdToModule hfn;
0147   HFNoseDetId module = hfn.getModule(id);
0148   std::vector<HFNoseDetId> ids = hfn.getDetIds(module);
0149   std::string ok = "***** ERROR *****";
0150   for (auto const& id0 : ids) {
0151     if (id0 == id) {
0152       ok = "";
0153       break;
0154     }
0155   }
0156   std::cout << "Module ID of " << id << " is " << module << " which has " << ids.size() << " cells " << ok << std::endl;
0157   for (unsigned int k = 0; k < ids.size(); ++k)
0158     std::cout << "ID[" << k << "] " << ids[k] << std::endl;
0159 }
0160 
0161 int main() {
0162   testCell(0);
0163   testWafer(1, 299.47, 1041.45);
0164   testWafer(8, 312.55, 1086.97);
0165   testTriggerCell(0);
0166   testModule(HFNoseDetId(1, 0, 1, 3, 3, 0, 5));
0167   testModule(HFNoseDetId(-1, 0, 5, 2, -2, 7, 5));
0168   return 0;
0169 }