File indexing completed on 2025-04-06 22:42:59
0001
0002
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "FWCore/Framework/interface/ModuleFactory.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/ESProducer.h"
0009 #include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h"
0010 #include "Geometry/MTDCommonData/interface/MTDTopologyMode.h"
0011 #include "Geometry/Records/interface/MTDTopologyRcd.h"
0012 #include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
0013 #include "Geometry/Records/interface/PMTDParametersRcd.h"
0014 #include "Geometry/MTDGeometryBuilder/interface/MTDGeometry.h"
0015 #include "Geometry/Records/interface/MTDDigiGeometryRecord.h"
0016
0017 #include <memory>
0018
0019 class MTDTopologyEP : public edm::ESProducer {
0020 public:
0021 MTDTopologyEP(const edm::ParameterSet&);
0022
0023 using ReturnType = std::unique_ptr<MTDTopology>;
0024
0025 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0026
0027 ReturnType produce(const MTDTopologyRcd&);
0028
0029 private:
0030 void fillBTLtopology(const MTDGeometry&, MTDTopology::BTLValues&);
0031 void fillETLtopology(const PMTDParameters&, int& mtdTopologyMode, MTDTopology::ETLValues&);
0032
0033 edm::ESGetToken<MTDGeometry, MTDDigiGeometryRecord> mtdgeoToken_;
0034 edm::ESGetToken<PMTDParameters, PMTDParametersRcd> mtdparToken_;
0035 };
0036
0037 MTDTopologyEP::MTDTopologyEP(const edm::ParameterSet& conf) {
0038 auto cc = setWhatProduced(this);
0039 mtdgeoToken_ = cc.consumesFrom<MTDGeometry, MTDDigiGeometryRecord>(edm::ESInputTag());
0040 mtdparToken_ = cc.consumesFrom<PMTDParameters, PMTDParametersRcd>(edm::ESInputTag());
0041 }
0042
0043 void MTDTopologyEP::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0044 edm::ParameterSetDescription ttc;
0045 descriptions.add("mtdTopology", ttc);
0046 }
0047
0048 MTDTopologyEP::ReturnType MTDTopologyEP::produce(const MTDTopologyRcd& iRecord) {
0049 int mtdTopologyMode;
0050 MTDTopology::BTLValues btlVals;
0051 MTDTopology::ETLValues etlVals;
0052
0053
0054
0055 fillBTLtopology(iRecord.get(mtdgeoToken_), btlVals);
0056
0057
0058
0059 fillETLtopology(iRecord.get(mtdparToken_), mtdTopologyMode, etlVals);
0060
0061 return std::make_unique<MTDTopology>(mtdTopologyMode, btlVals, etlVals);
0062 }
0063
0064 void MTDTopologyEP::fillBTLtopology(const MTDGeometry& mtdgeo, MTDTopology::BTLValues& btlVals) {
0065 MTDTopology::BTLLayout tmpLayout;
0066 uint32_t index(0), iphi(1), ieta(0);
0067 if (mtdgeo.detsBTL().size() != tmpLayout.nBTLmodules_) {
0068 throw cms::Exception("MTDTopologyEP") << "Inconsistent size of BTL structure arrays";
0069 }
0070 for (const auto& det : mtdgeo.detsBTL()) {
0071 ieta++;
0072
0073 tmpLayout.btlDetId_[index] = det->geographicalId().rawId();
0074 tmpLayout.btlPhi_[index] = iphi;
0075 tmpLayout.btlEta_[index] = ieta;
0076 #ifdef EDM_ML_DEBUG
0077 edm::LogVerbatim("MTDTopologyEP") << "MTDTopology BTL# " << index << " id= " << det->geographicalId().rawId()
0078 << " iphi/ieta= " << iphi << " / " << ieta;
0079 #endif
0080 if (ieta == tmpLayout.nBTLeta_) {
0081 iphi++;
0082 ieta = 0;
0083 }
0084 index++;
0085 }
0086 btlVals = tmpLayout;
0087 }
0088
0089 void MTDTopologyEP::fillETLtopology(const PMTDParameters& ptp, int& mtdTopologyMode, MTDTopology::ETLValues& etlVals) {
0090 mtdTopologyMode = ptp.topologyMode_;
0091
0092
0093
0094 for (size_t it = 3; it <= 9; it++) {
0095 bool exception = ((MTDTopologyMode::etlLayoutFromTopoMode(mtdTopologyMode) == MTDTopologyMode::EtlLayout::v10) &&
0096 (it == 5 || it == 9));
0097 if (ptp.vitems_[it].vpars_.size() != ptp.vitems_[2].vpars_.size()) {
0098 if (!exception) {
0099 throw cms::Exception("MTDTopologyEP") << "Inconsistent size of ETL structure arrays";
0100 } else {
0101 LogDebug("MTDTopologyEP") << "Building ETL topology for scenario 1.7";
0102 }
0103 }
0104 }
0105
0106 MTDTopology::ETLfaceLayout tmpFace;
0107
0108 if (static_cast<int>(MTDTopologyMode::etlLayoutFromTopoMode(mtdTopologyMode)) <=
0109 static_cast<int>(MTDTopologyMode::EtlLayout::v8)) {
0110
0111
0112 tmpFace.idDiscSide_ = 0;
0113 tmpFace.idDetType1_ = 2;
0114
0115 tmpFace.start_copy_[0] = ptp.vitems_[3].vpars_;
0116 tmpFace.start_copy_[1] = ptp.vitems_[2].vpars_;
0117 tmpFace.offset_[0] = ptp.vitems_[7].vpars_;
0118 tmpFace.offset_[1] = ptp.vitems_[6].vpars_;
0119
0120 etlVals.emplace_back(tmpFace);
0121
0122
0123
0124 tmpFace.idDiscSide_ = 1;
0125 tmpFace.idDetType1_ = 1;
0126
0127 tmpFace.start_copy_[0] = ptp.vitems_[4].vpars_;
0128 tmpFace.start_copy_[1] = ptp.vitems_[5].vpars_;
0129 tmpFace.offset_[0] = ptp.vitems_[8].vpars_;
0130 tmpFace.offset_[1] = ptp.vitems_[9].vpars_;
0131
0132 etlVals.emplace_back(tmpFace);
0133
0134
0135
0136 tmpFace.idDiscSide_ = 2;
0137 tmpFace.idDetType1_ = 2;
0138
0139 tmpFace.start_copy_[0] = ptp.vitems_[3].vpars_;
0140 tmpFace.start_copy_[1] = ptp.vitems_[2].vpars_;
0141 tmpFace.offset_[0] = ptp.vitems_[7].vpars_;
0142 tmpFace.offset_[1] = ptp.vitems_[6].vpars_;
0143
0144 etlVals.emplace_back(tmpFace);
0145
0146
0147
0148 tmpFace.idDiscSide_ = 3;
0149 tmpFace.idDetType1_ = 1;
0150
0151 tmpFace.start_copy_[0] = ptp.vitems_[4].vpars_;
0152 tmpFace.start_copy_[1] = ptp.vitems_[5].vpars_;
0153 tmpFace.offset_[0] = ptp.vitems_[8].vpars_;
0154 tmpFace.offset_[1] = ptp.vitems_[9].vpars_;
0155
0156 etlVals.emplace_back(tmpFace);
0157
0158 } else if (static_cast<int>(MTDTopologyMode::etlLayoutFromTopoMode(mtdTopologyMode)) >
0159 static_cast<int>(MTDTopologyMode::EtlLayout::v8)) {
0160
0161
0162 tmpFace.idDiscSide_ = 0;
0163 tmpFace.idDetType1_ = 2;
0164
0165 tmpFace.start_copy_[0] = ptp.vitems_[2].vpars_;
0166 tmpFace.start_copy_[1] = ptp.vitems_[2].vpars_;
0167 tmpFace.offset_[0] = ptp.vitems_[6].vpars_;
0168 tmpFace.offset_[1] = ptp.vitems_[6].vpars_;
0169
0170 etlVals.emplace_back(tmpFace);
0171
0172
0173
0174 tmpFace.idDiscSide_ = 1;
0175 tmpFace.idDetType1_ = 2;
0176
0177 tmpFace.start_copy_[0] = ptp.vitems_[3].vpars_;
0178 tmpFace.start_copy_[1] = ptp.vitems_[3].vpars_;
0179 tmpFace.offset_[0] = ptp.vitems_[7].vpars_;
0180 tmpFace.offset_[1] = ptp.vitems_[7].vpars_;
0181
0182 etlVals.emplace_back(tmpFace);
0183
0184
0185
0186 tmpFace.idDiscSide_ = 2;
0187 tmpFace.idDetType1_ = 2;
0188
0189 tmpFace.start_copy_[0] = ptp.vitems_[4].vpars_;
0190 tmpFace.start_copy_[1] = ptp.vitems_[4].vpars_;
0191 tmpFace.offset_[0] = ptp.vitems_[8].vpars_;
0192 tmpFace.offset_[1] = ptp.vitems_[8].vpars_;
0193
0194 etlVals.emplace_back(tmpFace);
0195
0196
0197
0198 tmpFace.idDiscSide_ = 3;
0199 tmpFace.idDetType1_ = 2;
0200
0201 tmpFace.start_copy_[0] = ptp.vitems_[5].vpars_;
0202 tmpFace.start_copy_[1] = ptp.vitems_[5].vpars_;
0203 tmpFace.offset_[0] = ptp.vitems_[9].vpars_;
0204 tmpFace.offset_[1] = ptp.vitems_[9].vpars_;
0205
0206 etlVals.emplace_back(tmpFace);
0207 }
0208
0209 #ifdef EDM_ML_DEBUG
0210 edm::LogVerbatim("MTDTopologyEP") << " Topology mode = " << mtdTopologyMode << "\n";
0211 auto print_array = [&](std::vector<int> vector) {
0212 std::stringstream ss;
0213 for (auto const& elem : vector) {
0214 ss << " " << elem;
0215 }
0216 ss << "\n";
0217 return ss.str();
0218 };
0219
0220 for (auto const& ilay : etlVals) {
0221 edm::LogVerbatim("MTDTopologyEP") << " disc face = " << ilay.idDiscSide_ << " start det type = " << ilay.idDetType1_
0222 << "\n start_copy[0]= " << print_array(ilay.start_copy_[0])
0223 << "\n start_copy[1]= " << print_array(ilay.start_copy_[1])
0224 << "\n offset[0]= " << print_array(ilay.offset_[0])
0225 << "\n offset[1]= " << print_array(ilay.offset_[1]);
0226 }
0227
0228 #endif
0229 }
0230
0231 DEFINE_FWK_EVENTSETUP_MODULE(MTDTopologyEP);