File indexing completed on 2024-04-06 11:58:23
0001
0002
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include <FWCore/Framework/interface/ESHandle.h>
0005 #include <FWCore/Framework/interface/EventSetup.h>
0006 #include <FWCore/Framework/interface/MakerMacros.h>
0007 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0008 #include <memory>
0009
0010 #include <DataFormats/GeometryVector/interface/Pi.h>
0011 #include <Geometry/CSCGeometry/interface/CSCGeometry.h>
0012 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
0013 #include <Geometry/Records/interface/MuonGeometryRecord.h>
0014
0015 #include <CalibMuon/CSCCalibration/interface/CSCIndexerBase.h>
0016 #include <CalibMuon/CSCCalibration/interface/CSCIndexerRecord.h>
0017
0018 #include <cmath>
0019 #include <iomanip> // for setw() etc.
0020 #include <string>
0021 #include <vector>
0022
0023 class CSCIndexerAnalyzer2 : public edm::one::EDAnalyzer<> {
0024 public:
0025 explicit CSCIndexerAnalyzer2(const edm::ParameterSet &);
0026 ~CSCIndexerAnalyzer2() = default;
0027
0028 virtual void analyze(const edm::Event &, const edm::EventSetup &);
0029
0030 const std::string &myName() const { return myName_; }
0031 const std::string &myAlgo() const { return algoName_; }
0032
0033 private:
0034 const int dashedLineWidth_;
0035 const std::string dashedLine_;
0036 const std::string myName_;
0037
0038 std::string algoName_;
0039
0040 const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> theCSCGeometryToken_;
0041 const edm::ESGetToken<CSCIndexerBase, CSCIndexerRecord> theCSCIndexerToken_;
0042 };
0043
0044 CSCIndexerAnalyzer2::CSCIndexerAnalyzer2(const edm::ParameterSet &iConfig)
0045 : dashedLineWidth_(146),
0046 dashedLine_(std::string(dashedLineWidth_, '-')),
0047 myName_("CSCIndexerAnalyzer2"),
0048 algoName_("UNKNOWN"),
0049 theCSCGeometryToken_(esConsumes()),
0050 theCSCIndexerToken_(esConsumes()) {
0051 std::cout << dashedLine_ << std::endl;
0052 std::cout << "Welcome to " << myName_ << std::endl;
0053 std::cout << dashedLine_ << std::endl;
0054 std::cout << "At present my CSCIndexer algorithm is " << myAlgo() << std::endl;
0055 std::cout << dashedLine_ << std::endl;
0056 std::cout << "I will build the CSC geometry, then iterate over all layers." << std::endl;
0057 std::cout << "From each CSCDetId I will build the associated linear index, "
0058 "including ME1a layers."
0059 << std::endl;
0060 std::cout << "I will build this index once from the layer labels and once "
0061 "from the CSCDetId, and check they agree."
0062 << std::endl;
0063 std::cout << "I will output one line per layer, listing the CSCDetId, the "
0064 "labels, and these two indexes."
0065 << std::endl;
0066 std::cout << "I will append the strip-channel indexes for the two edge "
0067 "strips and the central strip."
0068 << std::endl;
0069 std::cout << "Finally, I will rebuild a CSCDetId from the layer index, and "
0070 "check it is the same as the original,"
0071 << std::endl;
0072 std::cout << "and rebuild a CSCDetId from the final strip-channel index, and "
0073 "check it is the same as the original."
0074 << std::endl;
0075 std::cout << "If any of these tests fail, you will see assert failure "
0076 "messages in the output."
0077 << std::endl;
0078 std::cout << "If there are no such failures then the tests passed." << std::endl;
0079 std::cout << dashedLine_ << std::endl;
0080 }
0081
0082 void CSCIndexerAnalyzer2::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0083 CSCDetId testCSCDetId;
0084
0085 const double dPi = Geom::pi();
0086 const double radToDeg = 180. / dPi;
0087
0088 std::cout << myName() << "::analyze(..) start" << std::endl;
0089 std::cout << dashedLine_ << std::endl;
0090 std::cout << "pi = " << dPi << ", radToDeg = " << radToDeg << std::endl;
0091
0092 auto const pDD = &iSetup.getData(theCSCGeometryToken_);
0093
0094 std::cout << " Geometry node for CSCGeom is " << &(*pDD) << std::endl;
0095 std::cout << " I have " << pDD->detTypes().size() << " detTypes" << std::endl;
0096 std::cout << " I have " << pDD->detUnits().size() << " detUnits" << std::endl;
0097 std::cout << " I have " << pDD->dets().size() << " dets" << std::endl;
0098 std::cout << " I have " << pDD->layers().size() << " layers" << std::endl;
0099 std::cout << " I have " << pDD->chambers().size() << " chambers" << std::endl;
0100
0101
0102 const auto theIndexer = &iSetup.getData(theCSCIndexerToken_);
0103 algoName_ = theIndexer->name();
0104
0105 std::cout << dashedLine_ << std::endl;
0106 std::cout << "Found CSCIndexer algorithm " << myAlgo() << " in EventSetup" << std::endl;
0107 std::cout << dashedLine_ << std::endl;
0108
0109 bool ganged = 1;
0110 if (myAlgo() == "CSCIndexerPostls1")
0111 ganged = 0;
0112
0113 std::cout << myName() << ": Begin iteration over geometry..." << std::endl;
0114 std::cout << dashedLine_ << std::endl;
0115
0116 std::cout << "\n # id(dec) id(oct) "
0117 "lindex lindex2 cindex label strip sindex "
0118 " strip sindex strip sindex"
0119 << std::endl;
0120
0121 int icount = 0;
0122
0123
0124 for (const auto &it : pDD->detUnits()) {
0125
0126 auto layer = dynamic_cast<const CSCLayer *>(it);
0127
0128 if (layer) {
0129
0130
0131 DetId detId = layer->geographicalId();
0132 int id = detId();
0133 CSCDetId cscDetId = layer->id();
0134
0135
0136
0137 int iw = std::cout.width();
0138 int ip = std::cout.precision();
0139
0140 short ie = CSCDetId::endcap(id);
0141 short is = CSCDetId::station(id);
0142 short ir = CSCDetId::ring(id);
0143 short ic = CSCDetId::chamber(id);
0144 short il = CSCDetId::layer(id);
0145
0146 ++icount;
0147
0148 std::cout << std::setw(4) << icount << std::setw(12) << id << std::oct << std::setw(12) << id << std::dec
0149 << std::setw(iw) << " E" << ie << " S" << is << " R" << ir << " C" << std::setw(2) << ic
0150 << std::setw(iw) << " L" << il;
0151
0152 unsigned cind = theIndexer->chamberIndex(ie, is, ir, ic);
0153 unsigned lind = theIndexer->layerIndex(ie, is, ir, ic, il);
0154 unsigned scind = theIndexer->startChamberIndexInEndcap(ie, is, ir) + ic - 1;
0155 unsigned cind2 = theIndexer->chamberIndex(cscDetId);
0156 unsigned lind2 = theIndexer->layerIndex(cscDetId);
0157
0158 std::cout << std::setw(12) << lind << std::setw(12) << lind2 << std::setw(12) << scind << std::setw(12)
0159 << theIndexer->chamberLabelFromChamberIndex(scind) << " ";
0160
0161
0162 unsigned short nchan = theIndexer->stripChannelsPerOnlineLayer(is, ir);
0163 unsigned int sc1 = theIndexer->stripChannelIndex(ie, is, ir, ic, il, 1);
0164 unsigned int scm = theIndexer->stripChannelIndex(ie, is, ir, ic, il, nchan / 2);
0165 unsigned int scn = theIndexer->stripChannelIndex(ie, is, ir, ic, il, nchan);
0166
0167 std::cout << " 1 " << std::setw(6) << sc1 << " " << std::setw(2) << nchan / 2 << " " << std::setw(6)
0168 << scm << " " << std::setw(2) << nchan << " " << std::setw(6) << scn << std::endl;
0169
0170
0171 std::cout << std::setprecision(ip) << std::setw(iw);
0172
0173
0174
0175
0176
0177
0178 assert(cind2 == cind);
0179 assert(lind2 == lind);
0180
0181
0182
0183 CSCDetId cscDetId2 = theIndexer->detIdFromLayerIndex(lind);
0184
0185 testCSCDetId = cscDetId;
0186
0187 if (ir == 4)
0188 testCSCDetId = CSCDetId(ie, is, 1, ic, il);
0189
0190 assert(cscDetId2 == testCSCDetId);
0191
0192
0193
0194
0195 std::pair<CSCDetId, unsigned short int> p = theIndexer->detIdFromStripChannelIndex(scn);
0196 CSCDetId cscDetId3 = p.first;
0197 unsigned short iscn = p.second;
0198
0199 if (ir == 4 && ganged)
0200 iscn -= 64;
0201
0202 assert(iscn == nchan);
0203
0204 if (ir == 4 && !ganged)
0205 testCSCDetId = cscDetId;
0206
0207 assert(cscDetId3 == testCSCDetId);
0208
0209
0210 const GeomDetUnit *gdu = pDD->idToDetUnit(detId);
0211 assert(gdu == layer);
0212
0213 const GeomDet *gd = pDD->idToDet(detId);
0214 assert(gd == layer);
0215 } else {
0216 std::cout << myName() << ": something wrong ... could not dynamic_cast Det* to CSCLayer* " << std::endl;
0217 }
0218 }
0219
0220 std::cout << dashedLine_ << std::endl;
0221 std::cout << myName() << " end." << std::endl;
0222 }
0223
0224
0225 DEFINE_FWK_MODULE(CSCIndexerAnalyzer2);