Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-23 04:29:05

0001 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0002 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0003 #include "Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.h"
0004 #include "Geometry/MTDNumberingBuilder/plugins/ExtractStringFromDD.h"
0005 
0006 #include "DataFormats/ForwardDetId/interface/BTLDetId.h"
0007 #include "DataFormats/ForwardDetId/interface/ETLDetId.h"
0008 #include "Geometry/MTDCommonData/interface/MTDBaseNumber.h"
0009 
0010 #include "DataFormats/Math/interface/deltaPhi.h"
0011 
0012 //#define EDM_ML_DEBUG
0013 
0014 template <class FilteredView>
0015 CmsMTDConstruction<FilteredView>::CmsMTDConstruction() : etlScheme_(), baseNumber_() {}
0016 
0017 template <class FilteredView>
0018 bool CmsMTDConstruction<FilteredView>::mtdOrderZ(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0019   bool order = (a->translation().z() == b->translation().z()) ? a->translation().rho() < b->translation().rho()
0020                                                               : a->translation().z() < b->translation().z();
0021   return order;
0022 }
0023 
0024 template <class FilteredView>
0025 bool CmsMTDConstruction<FilteredView>::mtdOrderRR(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0026   MTDDetId id1(a->geographicalId());
0027   MTDDetId id2(b->geographicalId());
0028   return id1.mtdRR() < id2.mtdRR();
0029 }
0030 
0031 template <class FilteredView>
0032 bool CmsMTDConstruction<FilteredView>::mtdOrderPhi(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0033   MTDDetId id1(a->geographicalId());
0034   MTDDetId id2(b->geographicalId());
0035   return (id1.mtdRR() == id2.mtdRR()) && (angle0to2pi::make0To2pi(a->phi()) < angle0to2pi::make0To2pi(b->phi()));
0036 }
0037 
0038 template <>
0039 void CmsMTDConstruction<DDFilteredView>::buildBTLModule(DDFilteredView& fv, GeometricTimingDet* mother) {
0040   std::string nodeName(fv.name());
0041   GeometricTimingDet* det =
0042       new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0043 
0044   const auto& copyNumbers = fv.copyNumbers();
0045   auto module_number = copyNumbers[copyNumbers.size() - 2];
0046 
0047   constexpr char positive[] = "PositiveZ";
0048   constexpr char negative[] = "NegativeZ";
0049 
0050   const std::string modname(fv.name());
0051   size_t delim1 = modname.find("BModule");
0052   size_t delim2 = modname.find("Layer");
0053   module_number += atoi(modname.substr(delim1 + CmsMTDStringToEnum::kModStrLen, delim2).c_str()) - 1;
0054 
0055 #ifdef EDM_ML_DEBUG
0056   edm::LogVerbatim("MTDNumbering") << "BTLModule = " << modname << " " << copyNumbers[copyNumbers.size() - 3] << " "
0057                                    << module_number;
0058 #endif
0059 
0060   if (modname.find(positive) != std::string::npos) {
0061     det->setGeographicalID(BTLDetId(1, copyNumbers[copyNumbers.size() - 3], module_number, 0, 1));
0062   } else if (modname.find(negative) != std::string::npos) {
0063     det->setGeographicalID(BTLDetId(0, copyNumbers[copyNumbers.size() - 3], module_number, 0, 1));
0064   } else {
0065     throw cms::Exception("CmsMTDConstruction::buildBTLModule")
0066         << "BTL Module " << module_number << " is neither positive nor negative in Z!";
0067   }
0068 
0069   mother->addComponent(det);
0070 }
0071 
0072 template <>
0073 void CmsMTDConstruction<cms::DDFilteredView>::buildBTLModule(cms::DDFilteredView& fv, GeometricTimingDet* mother) {
0074   std::string nodeName(fv.name());
0075   GeometricTimingDet* det =
0076       new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0077 
0078   const auto& copyNumbers = fv.copyNumbers();
0079   auto module_number = copyNumbers[1];
0080 
0081   constexpr char positive[] = "PositiveZ";
0082   constexpr char negative[] = "NegativeZ";
0083 
0084   const std::string modname(fv.name());
0085   size_t delim1 = modname.find("BModule");
0086   size_t delim2 = modname.find("Layer");
0087   module_number += atoi(modname.substr(delim1 + CmsMTDStringToEnum::kModStrLen, delim2).c_str()) - 1;
0088 
0089 #ifdef EDM_ML_DEBUG
0090   edm::LogVerbatim("MTDNumbering") << fv.path() << "\nBTLModule = " << modname << " " << copyNumbers[2] << " "
0091                                    << module_number;
0092 #endif
0093 
0094   if (modname.find(positive) != std::string::npos) {
0095     det->setGeographicalID(BTLDetId(1, copyNumbers[2], module_number, 0, 1));
0096   } else if (modname.find(negative) != std::string::npos) {
0097     det->setGeographicalID(BTLDetId(0, copyNumbers[2], module_number, 0, 1));
0098   } else {
0099     throw cms::Exception("CmsMTDConstruction::buildBTLModule")
0100         << "BTL Module " << module_number << " is neither positive nor negative in Z!";
0101   }
0102 
0103   mother->addComponent(det);
0104 }
0105 
0106 template <>
0107 void CmsMTDConstruction<DDFilteredView>::buildETLModule(DDFilteredView& fv, GeometricTimingDet* mother) {
0108   std::string nodeName(fv.name());
0109   GeometricTimingDet* det =
0110       new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0111 
0112   if (isETLtdr(fv)) {
0113     //
0114     // For the TDR ETL geometry
0115     // in principle this method works also for the new geometry, if the main loop points to "Timingactive"
0116     // but backward compatibility is kept in order to avoid change in volume name and number of siblings
0117     //
0118 
0119     auto& gh = fv.geoHistory();
0120 
0121     baseNumber_.reset();
0122     baseNumber_.setSize(gh.size());
0123 
0124     for (uint i = gh.size(); i-- > 0;) {
0125       baseNumber_.addLevel(gh[i].logicalPart().name().name(), gh[i].copyno());
0126 #ifdef EDM_ML_DEBUG
0127       edm::LogVerbatim("CmsMTDConstruction") << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
0128 #endif
0129     }
0130 
0131     det->setGeographicalID(ETLDetId(etlScheme_.getUnitID(baseNumber_)));
0132 
0133   } else {
0134     const auto& copyNumbers = fv.copyNumbers();
0135     auto module_number = copyNumbers[copyNumbers.size() - 2];
0136 
0137     size_t delim_ring = det->name().find("EModule");
0138     size_t delim_disc = det->name().find("Disc");
0139 
0140     std::string ringN = det->name().substr(delim_ring + CmsMTDStringToEnum::kModStrLen, delim_disc);
0141 
0142     const uint32_t side = det->translation().z() > 0 ? 1 : 0;
0143 
0144     // label geographic detid is front or back (even though it is one module per entry here)
0145     det->setGeographicalID(ETLDetId(side, atoi(ringN.c_str()), module_number, 0));
0146   }
0147 
0148   mother->addComponent(det);
0149 }
0150 
0151 template <>
0152 void CmsMTDConstruction<cms::DDFilteredView>::buildETLModule(cms::DDFilteredView& fv, GeometricTimingDet* mother) {
0153   std::string nodeName(fv.name());
0154   GeometricTimingDet* det =
0155       new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0156 
0157   baseNumber_.reset();
0158   baseNumber_.setSize(fv.copyNos().size());
0159 
0160   for (uint i = 0; i < fv.copyNos().size(); i++) {
0161     std::string_view name((fv.geoHistory()[i])->GetName());
0162     size_t ipos = name.rfind('_');
0163     baseNumber_.addLevel(name.substr(0, ipos), fv.copyNos()[i]);
0164 #ifdef EDM_ML_DEBUG
0165     edm::LogVerbatim("CmsMTDConstruction") << name.substr(0, ipos) << " " << fv.copyNos()[i];
0166 #endif
0167   }
0168 
0169   det->setGeographicalID(ETLDetId(etlScheme_.getUnitID(baseNumber_)));
0170 
0171   mother->addComponent(det);
0172 }
0173 
0174 template <class FilteredView>
0175 GeometricTimingDet* CmsMTDConstruction<FilteredView>::buildSubdet(FilteredView& fv) {
0176   std::string nodeName(fv.name());
0177   auto thisDet = theCmsMTDStringToEnum.type(nodeName);
0178   GeometricTimingDet* subdet = new GeometricTimingDet(&fv, thisDet);
0179 
0180   if (thisDet == GeometricTimingDet::BTL) {
0181     subdet->setGeographicalID(BTLDetId(0, 0, 0, 0, 0));
0182   } else if (thisDet == GeometricTimingDet::ETL) {
0183     const uint32_t side = subdet->translation().z() > 0 ? 1 : 0;
0184     subdet->setGeographicalID(ETLDetId(side, 0, 0, 0));
0185   } else {
0186     throw cms::Exception("CmsMTDConstruction") << " ERROR - I was expecting a SubDet, I got a " << fv.name();
0187   }
0188 
0189   return subdet;
0190 }
0191 
0192 template <class FilteredView>
0193 GeometricTimingDet* CmsMTDConstruction<FilteredView>::buildLayer(FilteredView& fv) {
0194   std::string nodeName(fv.name());
0195   auto thisDet = theCmsMTDStringToEnum.type(nodeName);
0196   GeometricTimingDet* layer = new GeometricTimingDet(&fv, thisDet);
0197 
0198   if (thisDet != GeometricTimingDet::BTLLayer && thisDet != GeometricTimingDet::ETLDisc) {
0199     throw cms::Exception("CmsMTDConstruction") << " ERROR - I was expecting a SubDet, I got a " << fv.name();
0200   }
0201 
0202   uint32_t nLayer;
0203   if (thisDet == GeometricTimingDet::BTLLayer) {
0204     //
0205     // only one layer in BTL
0206     //
0207     nLayer = 1;
0208     layer->setGeographicalID(nLayer);
0209   } else if (thisDet == GeometricTimingDet::ETLDisc) {
0210     //
0211     // no change for pre TDR scenarios, otherwise identifiy layer with disc
0212     //
0213     nLayer = (fv.name().find("Disc1") != std::string::npos) ? 1 : 2;
0214     layer->setGeographicalID(nLayer);
0215   }
0216 
0217   return layer;
0218 }
0219 
0220 template <class FilteredView>
0221 bool CmsMTDConstruction<FilteredView>::isETLtdr(FilteredView& fv) {
0222   return (fv.name() == "EModule_Timingactive");
0223 }
0224 
0225 template class CmsMTDConstruction<DDFilteredView>;
0226 template class CmsMTDConstruction<cms::DDFilteredView>;