File indexing completed on 2024-04-06 12:15:29
0001 #include "Geometry/TrackerNumberingBuilder/plugins/DDDCmsTrackerContruction.h"
0002
0003 #include <deque>
0004 #include <fstream>
0005 #include <utility>
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0008 #include "DetectorDescription/Core/interface/DDCompactView.h"
0009 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0010 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0011 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0012 #include "Geometry/TrackerNumberingBuilder/plugins/ExtractStringFromDDD.h"
0013 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerBuilder.h"
0014 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerDetIdBuilder.h"
0015
0016 #define DEBUG false
0017
0018 std::unique_ptr<GeometricDet> DDDCmsTrackerContruction::construct(const DDCompactView& cpv,
0019 std::vector<int> const& detidShifts) {
0020 std::string attribute = "TkDDDStructure";
0021 DDSpecificsHasNamedValueFilter filter{attribute};
0022
0023 DDFilteredView fv(cpv, filter);
0024
0025 CmsTrackerStringToEnum theCmsTrackerStringToEnum;
0026 if (theCmsTrackerStringToEnum.type(ExtractStringFromDDD<DDFilteredView>::getString(attribute, &fv)) !=
0027 GeometricDet::Tracker) {
0028 fv.firstChild();
0029 if (theCmsTrackerStringToEnum.type(ExtractStringFromDDD<DDFilteredView>::getString(attribute, &fv)) !=
0030 GeometricDet::Tracker) {
0031 throw cms::Exception("Configuration") << " The first child of the DDFilteredView is not what is expected \n"
0032 << ExtractStringFromDDD<DDFilteredView>::getString(attribute, &fv) << "\n";
0033 }
0034 }
0035
0036 auto tracker = std::make_unique<GeometricDet>(&fv, GeometricDet::Tracker);
0037
0038 edm::LogVerbatim("DDDCmsTrackerContruction") << "DDDCmsTrackerContruction::construct: Call Tracker builder.";
0039 CmsTrackerBuilder<DDFilteredView> theCmsTrackerBuilder;
0040 theCmsTrackerBuilder.build(fv, tracker.get(), attribute);
0041
0042 edm::LogVerbatim("DDDCmsTrackerContruction") << "Assign DetIds";
0043 CmsTrackerDetIdBuilder theCmsTrackerDetIdBuilder(detidShifts);
0044 theCmsTrackerDetIdBuilder.buildId(*tracker);
0045
0046 if (DEBUG) {
0047 printAllTrackerGeometricDets(tracker.get());
0048 }
0049
0050 fv.parent();
0051
0052
0053
0054
0055
0056
0057
0058
0059 return tracker;
0060 }
0061
0062 std::unique_ptr<GeometricDet> DDDCmsTrackerContruction::construct(const cms::DDCompactView& cpv,
0063 std::vector<int> const& detidShifts) {
0064 std::string attribute("TkDDDStructure");
0065 cms::DDFilteredView fv(cpv, cms::DDFilter(attribute));
0066 fv.firstChild();
0067
0068 CmsTrackerStringToEnum theCmsTrackerStringToEnum;
0069 if (theCmsTrackerStringToEnum.type(ExtractStringFromDDD<cms::DDFilteredView>::getString("TkDDDStructure", &fv)) !=
0070 GeometricDet::Tracker) {
0071 fv.firstChild();
0072 if (theCmsTrackerStringToEnum.type(ExtractStringFromDDD<cms::DDFilteredView>::getString(attribute, &fv)) !=
0073 GeometricDet::Tracker) {
0074 throw cms::Exception("Configuration")
0075 << " The first child of the DDFilteredView is not what is expected \n"
0076 << ExtractStringFromDDD<cms::DDFilteredView>::getString(attribute, &fv) << "\n";
0077 }
0078 }
0079
0080 auto tracker = std::make_unique<GeometricDet>(&fv, GeometricDet::Tracker);
0081
0082 edm::LogVerbatim("DDDCmsTrackerContruction") << "DDDCmsTrackerContruction::construct: Call Tracker builder.";
0083 CmsTrackerBuilder<cms::DDFilteredView> theCmsTrackerBuilder;
0084 theCmsTrackerBuilder.build(fv, tracker.get(), attribute);
0085
0086 edm::LogVerbatim("DDDCmsTrackerContruction") << "Assign DetIds";
0087 CmsTrackerDetIdBuilder theCmsTrackerDetIdBuilder(detidShifts);
0088 theCmsTrackerDetIdBuilder.buildId(*tracker);
0089
0090 if (DEBUG) {
0091 printAllTrackerGeometricDets(tracker.get());
0092 }
0093
0094 return tracker;
0095 }
0096
0097
0098
0099
0100
0101
0102
0103 void DDDCmsTrackerContruction::printAllTrackerGeometricDets(const GeometricDet* tracker) {
0104 std::ofstream outputFile("All_Tracker_GeometricDets_before_DetId_building.log", std::ios::out);
0105
0106
0107
0108 std::deque<const GeometricDet*> queue;
0109 queue.emplace_back(tracker);
0110
0111 while (!queue.empty()) {
0112 const GeometricDet* myDet = queue.front();
0113 queue.pop_front();
0114
0115 for (auto& child : myDet->components()) {
0116 queue.emplace_back(child);
0117 }
0118
0119 outputFile << " " << std::endl;
0120 outputFile << " " << std::endl;
0121 outputFile << "............................." << std::endl;
0122 outputFile << "myDet->geographicalID() = " << myDet->geographicalId() << std::endl;
0123 outputFile << "myDet->name() = " << myDet->name() << std::endl;
0124 outputFile << "myDet->module->type() = " << std::fixed << std::setprecision(7) << myDet->type() << std::endl;
0125 outputFile << "myDet->module->translation() = " << std::fixed << std::setprecision(7) << myDet->translation()
0126 << std::endl;
0127 outputFile << "myDet->module->rho() = " << std::fixed << std::setprecision(7) << myDet->rho() << std::endl;
0128 if (fabs(myDet->rho()) > 0.00001) {
0129 outputFile << "myDet->module->phi() = " << std::fixed << std::setprecision(7) << myDet->phi() << std::endl;
0130 }
0131 outputFile << "myDet->module->rotation() = " << std::fixed << std::setprecision(7) << myDet->rotation()
0132 << std::endl;
0133 outputFile << "myDet->module->shape() = " << std::fixed << std::setprecision(7) << myDet->shape() << std::endl;
0134 if (myDet->shape_dd4hep() == cms::DDSolidShape::ddbox || myDet->shape_dd4hep() == cms::DDSolidShape::ddtrap ||
0135 myDet->shape_dd4hep() == cms::DDSolidShape::ddtubs) {
0136 outputFile << "myDet->params() = " << std::fixed << std::setprecision(7);
0137 for (const auto& para : myDet->params()) {
0138 outputFile << para << " ";
0139 }
0140 outputFile << " " << std::endl;
0141 }
0142 outputFile << "myDet->radLength() = " << myDet->radLength() << std::endl;
0143 outputFile << "myDet->xi() = " << myDet->xi() << std::endl;
0144 outputFile << "myDet->pixROCRows() = " << myDet->pixROCRows() << std::endl;
0145 outputFile << "myDet->pixROCCols() = " << myDet->pixROCCols() << std::endl;
0146 outputFile << "myDet->pixROCx() = " << myDet->pixROCx() << std::endl;
0147 outputFile << "myDet->pixROCy() = " << myDet->pixROCy() << std::endl;
0148 outputFile << "myDet->stereo() = " << myDet->stereo() << std::endl;
0149 outputFile << "myDet->isLowerSensor() = " << myDet->isLowerSensor() << std::endl;
0150 outputFile << "myDet->isUpperSensor() = " << myDet->isUpperSensor() << std::endl;
0151 outputFile << "myDet->isFirstSensor() = " << myDet->isFirstSensor() << std::endl;
0152 outputFile << "myDet->isSecondSensor() = " << myDet->isSecondSensor() << std::endl;
0153 outputFile << "myDet->siliconAPVNum() = " << myDet->siliconAPVNum() << std::endl;
0154 }
0155 }