diff --git a/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser01.py b/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser01.py index 675f61f5b77cea6bc6fac3c42eb01f17bfc492b8..1939952e5914b1269d4d41d5c5c0e3ee10beaf65 100644 --- a/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser01.py +++ b/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser01.py @@ -5,7 +5,7 @@ import sys from AthenaCommon.Constants import VERBOSE, INFO from AthenaConfiguration.ComponentFactory import CompFactory -def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", **kwargs): +def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", alignmentConstants={}, **kwargs): # Initialize GeoModel from FaserGeoModel.FaserGeoModelConfig import FaserGeometryCfg @@ -32,7 +32,12 @@ def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", **kwargs): PoolContainerPrefix="ConditionsContainer", TopLevelContainerName = "<type>", SubLevelBranchName= "<key>" ) - kwargs.setdefault("AlignDbTool", CompFactory.TrackerAlignDBTool("AlignDbTool", OutputTool = outputTool, OutputLevel=VERBOSE)) + + trackerAlignDBTool = CompFactory.TrackerAlignDBTool("AlignDbTool", OutputTool = outputTool, + OutputLevel=VERBOSE, + AlignmentConstants = {}) + kwargs.setdefault("AlignDbTool", trackerAlignDBTool) + trackerAlignDBTool.AlignmentConstants = alignmentConstants a.addEventAlgo(WriteAlignmentAlg(name, **kwargs)) return a @@ -53,12 +58,23 @@ if __name__ == "__main__": ConfigFlags.IOVDb.DBConnection = "sqlite://;schema=" + ConfigFlags.GeoModel.FaserVersion + "_ALLP200.db;dbname=OFLP200" ConfigFlags.GeoModel.Align.Disable = True # Hack to avoid loading alignment when we want to create it from scratch ConfigFlags.addFlag("WriteAlignment.PoolFileName", ConfigFlags.GeoModel.FaserVersion + "_Align.pool.root") + +# Parse flags from command line and lock + ConfigFlags.addFlag("AlignDbTool.AlignmentConstants", {}) + ConfigFlags.fillFromArgs(sys.argv[1:]) ConfigFlags.lock() # Configure components from CalypsoConfiguration.MainServicesConfig import MainServicesCfg acc = MainServicesCfg(ConfigFlags) +# Set things up to create a conditions DB with neutral Tracker alignment transforms + acc.merge(WriteAlignmentCfg(ConfigFlags, alignmentConstants=ConfigFlags.AlignDbTool.AlignmentConstants, ValidRunStart=1, ValidEvtStart=0, ValidRunEnd=9999999, ValidEvtEnd=9999999, CondTag=ConfigFlags.GeoModel.FaserVersion.replace("FASER", "TRACKER-ALIGN"), )) + +# Configure components + from CalypsoConfiguration.MainServicesConfig import MainServicesCfg + acc = MainServicesCfg(ConfigFlags) + # Set things up to create a conditions DB with neutral Tracker alignment transforms acc.merge(WriteAlignmentCfg(ConfigFlags, ValidRunStart=1, ValidEvtStart=0, ValidRunEnd=9999999, ValidEvtEnd=9999999, CondTag=ConfigFlags.GeoModel.FaserVersion.replace("FASER", "TRACKER-ALIGN"))) diff --git a/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser02.py b/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser02.py index b05c15632415e873e301a08d9f63332175ebfe20..57842aabebf988a56f8b9ddfddc60c3fa06d8919 100644 --- a/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser02.py +++ b/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_Faser02.py @@ -5,7 +5,7 @@ import sys from AthenaCommon.Constants import VERBOSE, INFO from AthenaConfiguration.ComponentFactory import CompFactory -def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", **kwargs): +def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", alignmentConstants={}, **kwargs): # Initialize GeoModel from FaserGeoModel.FaserGeoModelConfig import FaserGeometryCfg @@ -32,7 +32,12 @@ def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", **kwargs): PoolContainerPrefix="ConditionsContainer", TopLevelContainerName = "<type>", SubLevelBranchName= "<key>" ) - kwargs.setdefault("AlignDbTool", CompFactory.TrackerAlignDBTool("AlignDbTool", OutputTool = outputTool, OutputLevel=VERBOSE)) + + trackerAlignDBTool = CompFactory.TrackerAlignDBTool("AlignDbTool", OutputTool = outputTool, + OutputLevel=VERBOSE, + AlignmentConstants = {}) + kwargs.setdefault("AlignDbTool", trackerAlignDBTool) + trackerAlignDBTool.AlignmentConstants = alignmentConstants a.addEventAlgo(WriteAlignmentAlg(name, **kwargs)) return a @@ -53,12 +58,23 @@ if __name__ == "__main__": ConfigFlags.IOVDb.DBConnection = "sqlite://;schema=" + ConfigFlags.GeoModel.FaserVersion + "_ALLP200.db;dbname=OFLP200" ConfigFlags.GeoModel.Align.Disable = True # Hack to avoid loading alignment when we want to create it from scratch ConfigFlags.addFlag("WriteAlignment.PoolFileName", ConfigFlags.GeoModel.FaserVersion + "_Align.pool.root") + +# Parse flags from command line and lock + ConfigFlags.addFlag("AlignDbTool.AlignmentConstants", {}) + ConfigFlags.fillFromArgs(sys.argv[1:]) ConfigFlags.lock() # Configure components from CalypsoConfiguration.MainServicesConfig import MainServicesCfg acc = MainServicesCfg(ConfigFlags) +# Set things up to create a conditions DB with neutral Tracker alignment transforms + acc.merge(WriteAlignmentCfg(ConfigFlags, alignmentConstants=ConfigFlags.AlignDbTool.AlignmentConstants, ValidRunStart=1, ValidEvtStart=0, ValidRunEnd=9999999, ValidEvtEnd=9999999, CondTag=ConfigFlags.GeoModel.FaserVersion.replace("FASER", "TRACKER-ALIGN"), )) + +# Configure components + from CalypsoConfiguration.MainServicesConfig import MainServicesCfg + acc = MainServicesCfg(ConfigFlags) + # Set things up to create a conditions DB with neutral Tracker alignment transforms acc.merge(WriteAlignmentCfg(ConfigFlags, ValidRunStart=1, ValidEvtStart=0, ValidRunEnd=9999999, ValidEvtEnd=9999999, CondTag=ConfigFlags.GeoModel.FaserVersion.replace("FASER", "TRACKER-ALIGN"))) diff --git a/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_FaserTB00.py b/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_FaserTB00.py index d57092f2dd8b8c1dcb3bd6568fdb3dac636d3cf2..84fb1b02e855907c7c525c64498b7d4d8b015f18 100644 --- a/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_FaserTB00.py +++ b/Control/CalypsoExample/WriteAlignment/python/WriteAlignmentConfig_FaserTB00.py @@ -5,7 +5,7 @@ import sys from AthenaCommon.Constants import VERBOSE, INFO from AthenaConfiguration.ComponentFactory import CompFactory -def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", **kwargs): +def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", alignmentConstants={}, **kwargs): # Initialize GeoModel from FaserGeoModel.FaserGeoModelConfig import FaserGeometryCfg @@ -32,7 +32,12 @@ def WriteAlignmentCfg(flags, name="WriteAlignmentAlg", **kwargs): PoolContainerPrefix="ConditionsContainer", TopLevelContainerName = "<type>", SubLevelBranchName= "<key>" ) - kwargs.setdefault("AlignDbTool", CompFactory.TrackerAlignDBTool("AlignDbTool", OutputTool = outputTool, OutputLevel=VERBOSE)) + + trackerAlignDBTool = CompFactory.TrackerAlignDBTool("AlignDbTool", OutputTool = outputTool, + OutputLevel=VERBOSE, + AlignmentConstants = {}) + kwargs.setdefault("AlignDbTool", trackerAlignDBTool) + trackerAlignDBTool.AlignmentConstants = alignmentConstants a.addEventAlgo(WriteAlignmentAlg(name, **kwargs)) return a @@ -53,6 +58,10 @@ if __name__ == "__main__": ConfigFlags.IOVDb.DBConnection = "sqlite://;schema=" + ConfigFlags.GeoModel.FaserVersion + "_ALLP200.db;dbname=OFLP200" ConfigFlags.GeoModel.Align.Disable = True # Hack to avoid loading alignment when we want to create it from scratch ConfigFlags.addFlag("WriteAlignment.PoolFileName", ConfigFlags.GeoModel.FaserVersion + "_Align.pool.root") + +# Parse flags from command line and lock + ConfigFlags.addFlag("AlignDbTool.AlignmentConstants", {}) + ConfigFlags.fillFromArgs(sys.argv[1:]) ConfigFlags.lock() # Configure components @@ -60,7 +69,7 @@ if __name__ == "__main__": acc = MainServicesCfg(ConfigFlags) # Set things up to create a conditions DB with neutral Tracker alignment transforms - acc.merge(WriteAlignmentCfg(ConfigFlags, ValidRunStart=1, ValidEvtStart=0, ValidRunEnd=9999999, ValidEvtEnd=9999999, CondTag=ConfigFlags.GeoModel.FaserVersion.replace("FASER", "TRACKER-ALIGN"))) + acc.merge(WriteAlignmentCfg(ConfigFlags, alignmentConstants=ConfigFlags.AlignDbTool.AlignmentConstants, ValidRunStart=1, ValidEvtStart=0, ValidRunEnd=9999999, ValidEvtEnd=9999999, CondTag=ConfigFlags.GeoModel.FaserVersion.replace("FASER", "TRACKER-ALIGN"), )) # Configure verbosity # ConfigFlags.dump() diff --git a/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.cxx b/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.cxx index 3b03712c8c79f3f07b3b6bfcd981c8dc54a43fb0..4483eb5b4cd52b31aa70cb915ba6500641297685 100644 --- a/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.cxx +++ b/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.cxx @@ -214,25 +214,27 @@ StatusCode TrackerAlignDBTool::createDB() const int iModule = iModulePhi; if (iModuleEta < 0) iModule +=4; - const auto key = [](auto iStation, auto iLayer, auto iModule, auto parameter) { + const auto buildKey = [](auto iStation, auto iLayer, auto iModule) { std::stringstream ss; - ss << iStation << "." << iLayer << "." << iModule << "-" << parameter; + ss << iStation << iLayer << iModule; return ss.str(); }; - const double x = m_alignment.value().find(key(iStation, iLayer, iModule, "x"))->second; - const double y = m_alignment.value().find(key(iStation, iLayer, iModule, "y"))->second; - const double z = m_alignment.value().find(key(iStation, iLayer, iModule, "z"))->second; - const double alpha = m_alignment.value().find(key(iStation, iLayer, iModule, "alpha"))->second; - const double beta = m_alignment.value().find(key(iStation, iLayer, iModule, "beta"))->second; - const double gamma = m_alignment.value().find(key(iStation, iLayer, iModule, "gamma"))->second; - - Amg::Translation3D newtranslation(x, y, z); - Amg::Transform3D alignment = newtranslation * Amg::RotationMatrix3D::Identity(); - alignment *= Amg::AngleAxis3D(gamma, Amg::Vector3D(0.,0.,1.)); - alignment *= Amg::AngleAxis3D(beta, Amg::Vector3D(0.,1.,0.)); - alignment *= Amg::AngleAxis3D(alpha, Amg::Vector3D(1.,0.,0.)); - - pat->add(ident, Amg::EigenTransformToCLHEP(alignment)); + + const auto key = buildKey(iStation, iLayer, iModule); + if (not (m_alignment.find(key) == m_alignment.end())) { + const std::vector<double> c = m_alignment.value().find(key)->second; + ATH_MSG_VERBOSE("Applying correction for " << key); + ATH_MSG_VERBOSE(c[0] << " " << c[1] << " " << c[2] << " " << c[3] << " " << c[4] << " " << c[5]); + Amg::Translation3D newtranslation(c[0], c[1], c[2]); + Amg::Transform3D alignment = newtranslation * Amg::RotationMatrix3D::Identity(); + alignment *= Amg::AngleAxis3D(c[5], Amg::Vector3D(0.,0.,1.)); + alignment *= Amg::AngleAxis3D(c[4], Amg::Vector3D(0.,1.,0.)); + alignment *= Amg::AngleAxis3D(c[3], Amg::Vector3D(1.,0.,0.)); + + pat->add(ident, Amg::EigenTransformToCLHEP(alignment)); + } else { + ATH_MSG_VERBOSE("No correction given for " << key); + } } else { @@ -256,25 +258,27 @@ StatusCode TrackerAlignDBTool::createDB() const auto iStation = m_sctid->station(ident); auto iLayer = m_sctid->layer(ident); - const auto key = [](auto iStation, auto iLayer, auto parameter) { + const auto buildKey = [](auto iStation, auto iLayer) { std::stringstream ss; - ss << iStation << "." << iLayer << "-" << parameter; + ss << iStation << iLayer; return ss.str(); }; - const double x = m_alignment.value().find(key(iStation, iLayer, "x"))->second; - const double y = m_alignment.value().find(key(iStation, iLayer, "y"))->second; - const double z = m_alignment.value().find(key(iStation, iLayer, "z"))->second; - const double alpha = m_alignment.value().find(key(iStation, iLayer, "alpha"))->second; - const double beta = m_alignment.value().find(key(iStation, iLayer, "beta"))->second; - const double gamma = m_alignment.value().find(key(iStation, iLayer, "gamma"))->second; - - Amg::Translation3D newtranslation(x, y, z); - Amg::Transform3D alignment = newtranslation * Amg::RotationMatrix3D::Identity(); - alignment *= Amg::AngleAxis3D(gamma, Amg::Vector3D(0.,0.,1.)); - alignment *= Amg::AngleAxis3D(beta, Amg::Vector3D(0.,1.,0.)); - alignment *= Amg::AngleAxis3D(alpha, Amg::Vector3D(1.,0.,0.)); - - pat->add(ident2, Amg::EigenTransformToCLHEP(alignment)); + + const auto key = buildKey(iStation, iLayer); + if (not (m_alignment.find(key) == m_alignment.end())) { + const std::vector<double> c = m_alignment.value().find(key)->second; + ATH_MSG_VERBOSE("Applying correction for " << key); + ATH_MSG_VERBOSE(c[0] << " " << c[1] << " " << c[2] << " " << c[3] << " " << c[4] << " " << c[5]); + Amg::Translation3D newtranslation(c[0], c[1], c[2]); + Amg::Transform3D alignment = newtranslation * Amg::RotationMatrix3D::Identity(); + alignment *= Amg::AngleAxis3D(c[5], Amg::Vector3D(0.,0.,1.)); + alignment *= Amg::AngleAxis3D(c[4], Amg::Vector3D(0.,1.,0.)); + alignment *= Amg::AngleAxis3D(c[3], Amg::Vector3D(1.,0.,0.)); + + pat->add(ident2, Amg::EigenTransformToCLHEP(alignment)); + } else { + ATH_MSG_VERBOSE("No correction given for " << key); + } } else { diff --git a/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.h b/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.h index a0502d79fac2b0465880e05dfe7da99cb5fdc255..6ee1a190427d31b683aa946fe54726e8b04079ba 100644 --- a/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.h +++ b/Tracker/TrackerAlignTools/TrackerAlignGenTools/src/TrackerAlignDBTool.h @@ -186,7 +186,7 @@ class TrackerAlignDBTool: virtual public ITrackerAlignDBTool, public AthAlgTool bool m_dynamicDB; bool m_forceUserDBConfig; std::set<int> m_stations; - Gaudi::Property<std::map<std::string, double>> m_alignment{ this, "AlignmentConstants", {}, "Alignment constants."}; + Gaudi::Property<std::map<std::string, std::vector<double>>> m_alignment{ this, "AlignmentConstants", {}, "Alignment constants."}; mutable ToolHandle<IAthenaOutputStreamTool> m_outputTool { this, "OutputTool", "AthenaOutputStreamTool/CondStream1"} ;