File indexing completed on 2024-04-06 12:14:46
0001 #include "Geometry/HcalCommonData/interface/CaloSimParametersFromDD.h"
0002 #include "CondFormats/GeometryObjects/interface/CaloSimulationParameters.h"
0003 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0004 #include "DetectorDescription/Core/interface/DDFilter.h"
0005 #include "DetectorDescription/Core/interface/DDValue.h"
0006 #include "DetectorDescription/Core/interface/DDutils.h"
0007 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0008
0009
0010
0011 template <typename T>
0012 void myPrint(std::string value, const std::vector<T>& vec) {
0013 edm::LogVerbatim("HCalGeom") << "CaloSimParametersFromDD: " << vec.size() << " entries for " << value << ":";
0014 unsigned int i(0);
0015 for (const auto& e : vec) {
0016 edm::LogVerbatim("HCalGeom") << " (" << i << ") " << e;
0017 ++i;
0018 }
0019 }
0020
0021 bool CaloSimParametersFromDD::build(const DDCompactView* cpv, CaloSimulationParameters& php) {
0022 #ifdef EDM_ML_DEBUG
0023 edm::LogVerbatim("HCalGeom")
0024 << "Inside CaloSimParametersFromDD::build(const DDCompactView*, CaloSimulationParameters&)";
0025 #endif
0026
0027 std::string attribute = "ReadOutName";
0028 std::string name = "CaloHitsTk";
0029 DDSpecificsMatchesValueFilter filter{DDValue(attribute, name, 0)};
0030 DDFilteredView fv(*cpv, filter);
0031 fv.firstChild();
0032 DDsvalues_type sv(fv.mergedSpecifics());
0033 edm::LogVerbatim("HCalGeom") << "Filtered view " << &fv << " after filter with " << sv.size() << " contents";
0034
0035 php.caloNames_ = getNames("Calorimeter", sv, false);
0036 php.levels_ = getNumbers("Levels", sv, false);
0037 php.neighbours_ = getNumbers("Neighbours", sv, false);
0038 php.insideNames_ = getNames("Inside", sv, false);
0039 php.insideLevel_ = getNumbers("InsideLevel", sv, false);
0040 php.fCaloNames_ = getNames("FineCalorimeter", sv, true);
0041 php.fLevels_ = getNumbers("FineLevels", sv, true);
0042
0043 return this->buildParameters(php);
0044 }
0045
0046 bool CaloSimParametersFromDD::build(const cms::DDCompactView* cpv, CaloSimulationParameters& php) {
0047 #ifdef EDM_ML_DEBUG
0048 edm::LogVerbatim("HCalGeom")
0049 << "Inside CaloSimParametersFromDD::build(const cms::DDCompactView*, CaloSimulationParameters&)";
0050 #endif
0051
0052 cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume());
0053 php.caloNames_ = fv.get<std::vector<std::string> >("calo", "Calorimeter");
0054 php.levels_ = dbl_to_int(fv.get<std::vector<double> >("calo", "Levels"));
0055 php.neighbours_ = dbl_to_int(fv.get<std::vector<double> >("calo", "Neighbours"));
0056 php.insideNames_ = fv.get<std::vector<std::string> >("calo", "Inside");
0057 php.insideLevel_ = dbl_to_int(fv.get<std::vector<double> >("calo", "InsideLevel"));
0058 php.fCaloNames_ = fv.get<std::vector<std::string> >("calo", "FineCalorimeter");
0059 php.fLevels_ = dbl_to_int(fv.get<std::vector<double> >("calo", "FineLevels"));
0060
0061 return this->buildParameters(php);
0062 }
0063
0064 bool CaloSimParametersFromDD::buildParameters(const CaloSimulationParameters& php) {
0065 #ifdef EDM_ML_DEBUG
0066 myPrint("Calorimeter", php.caloNames_);
0067 myPrint("Levels", php.levels_);
0068 myPrint("Neighbours", php.neighbours_);
0069 myPrint("Inside", php.insideNames_);
0070 myPrint("InsideLevel", php.insideLevel_);
0071 myPrint("FineCalorimeter", php.fCaloNames_);
0072 myPrint("FineLevels", php.fLevels_);
0073 #endif
0074
0075 if (php.caloNames_.size() < php.neighbours_.size()) {
0076 edm::LogError("HCalGeom") << "CaloSimParametersFromDD: # of Calorimeter bins " << php.caloNames_.size()
0077 << " does not match with " << php.neighbours_.size() << " ==> illegal ";
0078 throw cms::Exception("Unknown", "CaloSimParametersFromDD")
0079 << "Calorimeter array size does not match with size of neighbours\n";
0080 }
0081
0082 return true;
0083 }
0084
0085 std::vector<std::string> CaloSimParametersFromDD::getNames(const std::string& str,
0086 const DDsvalues_type& sv,
0087 bool ignore) {
0088 #ifdef EDM_ML_DEBUG
0089 edm::LogVerbatim("HCalGeom") << "CaloSimParametersFromDD::getNames called for " << str;
0090 #endif
0091 DDValue value(str);
0092 if (DDfetch(&sv, value)) {
0093 #ifdef EDM_ML_DEBUG
0094 edm::LogVerbatim("HCalGeom") << value;
0095 #endif
0096 const std::vector<std::string>& fvec = value.strings();
0097 int nval = fvec.size();
0098 if ((nval < 1) && (!ignore)) {
0099 edm::LogError("HCalGeom") << "CaloSimParametersFromDD: # of " << str << " bins " << nval << " < 1 ==> illegal ";
0100 throw cms::Exception("Unknown", "CaloSimParametersFromDD") << "nval < 1 for array " << str << "\n";
0101 }
0102
0103 return fvec;
0104 } else if (ignore) {
0105 std::vector<std::string> fvec;
0106 return fvec;
0107 } else {
0108 edm::LogError("HCalGeom") << "CaloSimParametersFromDD: cannot get array " << str;
0109 throw cms::Exception("Unknown", "CaloSimParametersFromDD") << "cannot get array " << str << "\n";
0110 }
0111 }
0112
0113 std::vector<int> CaloSimParametersFromDD::getNumbers(const std::string& str, const DDsvalues_type& sv, bool ignore) {
0114 #ifdef EDM_ML_DEBUG
0115 edm::LogVerbatim("HCalGeom") << "CaloSimParametersFromDD::getNumbers called for " << str;
0116 #endif
0117 DDValue value(str);
0118 if (DDfetch(&sv, value)) {
0119 #ifdef EDM_ML_DEBUG
0120 edm::LogVerbatim("HCalGeom") << value;
0121 #endif
0122 const std::vector<double>& fvec = value.doubles();
0123 int nval = fvec.size();
0124 if ((nval < 1) && (!ignore)) {
0125 edm::LogError("HCalGeom") << "CaloSimParametersFromDD: # of " << str << " bins " << nval << " < 1 ==> illegal ";
0126 throw cms::Exception("Unknown", "CaloSimParametersFromDD") << "nval < 2 for array " << str << "\n";
0127 }
0128 return dbl_to_int(fvec);
0129 } else if (ignore) {
0130 std::vector<int> fvec;
0131 return fvec;
0132 } else {
0133 edm::LogError("HCalGeom") << "CaloSimParametersFromDD: cannot get array " << str;
0134 throw cms::Exception("Unknown", "CaloSimParametersFromDD") << "cannot get array " << str << "\n";
0135 }
0136 }