17 #include "GaudiKernel/ITHistSvc.h"
18 #include "GaudiKernel/SmartDataPtr.h"
19 #include "GaudiKernel/RndmGenerators.h"
20 #include "GaudiKernel/IRndmGenSvc.h"
23 #include "Identifier/Identifier.h"
54 std::ostringstream
os;
55 os <<
"\nAlignment x = (" << initialAlignment.getTranslation().x() /
CLHEP::micrometer <<
") micron\n";
56 os <<
"Alignment y = (" << initialAlignment.getTranslation().y() /
CLHEP::micrometer <<
") micron\n";
57 os <<
"Alignment z = (" << initialAlignment.getTranslation().z() /
CLHEP::micrometer <<
") micron\n";
58 os <<
"Alignment x phi = (" << initialAlignment.getRotation().phiX() /
CLHEP::deg <<
") degree\n";
59 os <<
"Alignment x Theta = (" << initialAlignment.getRotation().thetaX() /
CLHEP::deg <<
") degree\n";
60 os <<
"Alignment y phi = (" << initialAlignment.getRotation().phiY() /
CLHEP::deg <<
") degree\n";
61 os <<
"Alignment y Theta = (" << initialAlignment.getRotation().thetaY() /
CLHEP::deg <<
") degree\n";
62 os <<
"Alignment z phi = (" << initialAlignment.getRotation().phiZ() /
CLHEP::deg <<
") degree\n";
63 os <<
"Alignment z Theta = (" << initialAlignment.getRotation().thetaZ() /
CLHEP::deg <<
") degree\n";
75 m_pixelIdHelper(nullptr),
76 m_sctIdHelper(nullptr),
77 m_trtIdHelper(nullptr),
78 m_IDAlignDBTool(
"InDetAlignDBTool",this),
79 m_trtaligndbservice(
"TRT_AlignDbSvc",
name),
80 m_asciiFileNameBase(
"MisalignmentSet"),
81 m_SQLiteTag(
"test_tag"),
83 m_createFreshDB(true),
84 m_MisalignmentMode(0),
86 m_translation{0.1, 0.1, 0.1},
87 m_rotation{0.1, 0.1, 0.1},
88 m_local_translation{0., 0., 0.},
89 m_local_rotation{0., 0., 0.},
95 m_IBLBowingTshift(0.),
96 m_ScalePixelBarrel(1.),
97 m_ScalePixelEndcap(1.),
100 m_ScaleTRTBarrel(1.),
101 m_ScaleTRTEndcap(1.),
102 m_VisualizationLookupTree(
nullptr),
103 m_AthenaHashedID(-1),
104 m_HumanReadableID(-1),
109 declareProperty(
"ASCIIFilenameBase" , m_asciiFileNameBase);
110 declareProperty(
"SQLiteTag" , m_SQLiteTag);
111 declareProperty(
"MisalignMode" , m_MisalignmentMode);
112 declareProperty(
"Translation_Scale" , m_translation);
113 declareProperty(
"Rotation_Scale" , m_rotation);
114 declareProperty(
"Local_Translation" , m_local_translation);
115 declareProperty(
"Local_Rotation" , m_local_rotation);
116 declareProperty(
"Index" , m_index);
117 declareProperty(
"MaxShift" , m_Misalign_maxShift);
118 declareProperty(
"MaxShiftInner" , m_Misalign_maxShift_Inner);
119 declareProperty(
"CreateFreshDB" , m_createFreshDB);
120 declareProperty(
"IDAlignDBTool" , m_IDAlignDBTool);
121 declareProperty(
"TRTAlignDBService" , m_trtaligndbservice);
122 declareProperty(
"ScalePixelIBL" , m_ScalePixelIBL);
123 declareProperty(
"ScalePixelDBM" , m_ScalePixelDBM);
124 declareProperty(
"IBLBowingTshift" , m_IBLBowingTshift);
125 declareProperty(
"ScalePixelBarrel" , m_ScalePixelBarrel);
126 declareProperty(
"ScalePixelEndcap" , m_ScalePixelEndcap);
127 declareProperty(
"ScaleSCTBarrel" , m_ScaleSCTBarrel);
128 declareProperty(
"ScaleSCTEndcap" , m_ScaleSCTEndcap);
129 declareProperty(
"ScaleTRTBarrel" , m_ScaleTRTBarrel);
130 declareProperty(
"ScaleTRTEndcap" , m_ScaleTRTEndcap);
170 SmartIF<ITHistSvc> hist_svc{Gaudi::svcLocator()->service(
"THistSvc")};
179 NTupleFilePtr file1(
ntupleSvc(),
"/NTUPLES/CREATEMISALIGN");
181 NTuplePtr
nt(
ntupleSvc(),
"/NTUPLES/CREATEMISALIGN/InitialAlignment");
183 nt =
ntupleSvc()->book(
"/NTUPLES/CREATEMISALIGN/InitialAlignment", CLID_ColumnWiseTuple,
"InitialAlignment");
205 msg(MSG::ERROR) <<
"Failed to book InitialAlignment ntuple." <<
endmsg;
222 ATH_MSG_INFO(
"Dry run, no misalignment will be generated." );
225 return StatusCode::SUCCESS;
257 return StatusCode::FAILURE;
263 return StatusCode::SUCCESS;
273 return StatusCode::SUCCESS;
282 if (not sctDetEleHandle.
isValid() or elements==
nullptr) {
319 msg() << commonAlignmentOutput(InitialAlignment);
332 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
338 const Identifier Pixel_ModuleID = element->identify();
368 msg() << commonAlignmentOutput(InitialAlignment);
383 std::map< Identifier, std::vector<double> > trtModulesWithCOG;
388 if (not trtDetEleHandle.
isValid() or elements==
nullptr) {
396 const Identifier TRTID_orig = element->identify();
398 bool insertSuccess{};
399 std::tie(
std::ignore, insertSuccess) = trtModulesWithCOG.insert({TRTID,std::vector<double>(4,0.)});
400 if (not insertSuccess){
401 ATH_MSG_VERBOSE(
"No insert was performed, identifier was already in the trtModulesWithCOG map");
404 unsigned int nStraws = element->nStraws();
405 for (
unsigned int l = 0;
l<nStraws;
l++) {
407 trtModulesWithCOG[TRTID].at(0) += strawcenter.x();
408 trtModulesWithCOG[TRTID].at(1) += strawcenter.y();
409 trtModulesWithCOG[TRTID].at(2) += strawcenter.z();
410 trtModulesWithCOG[TRTID].at(3) += 1.;
414 ATH_MSG_DEBUG(
"this strawlayer has " << nStraws <<
" straws." );
415 ATH_MSG_DEBUG(
"strawcount of this module: " << trtModulesWithCOG[TRTID].at(3) );
420 std::map< Identifier, std::vector<double> >::const_iterator iter2;
421 for (iter2 = trtModulesWithCOG.begin(); iter2!=trtModulesWithCOG.end(); ++iter2) {
423 double nStraws = iter2->second.at(3);
426 m_ModuleList[TRTID] = HepGeom::Point3D<double>(iter2->second.at(0)/nStraws, iter2->second.at(1)/nStraws,iter2->second.at(2)/nStraws);
435 msg() << commonAlignmentOutput(InitialAlignment);
451 SmartIF<IRndmGenSvc> randsvc{Gaudi::svcLocator()->service(
"RndmGenSvc")};
497 pixelElements = *pixelDetEleHandle;
498 if (not pixelDetEleHandle.
isValid() or pixelElements==
nullptr) {
500 return StatusCode::FAILURE;
506 sctElements = *sctDetEleHandle;
507 if (not sctDetEleHandle.
isValid() or sctElements==
nullptr) {
509 return StatusCode::FAILURE;
522 else ATH_MSG_WARNING(
"Trying to access a Pixel module when running with no Pixel!");
527 else ATH_MSG_WARNING(
"Trying to access an SCT/Strop module when running with no SCT/Strip!");
533 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
548 ATH_MSG_WARNING(
"Apparently in a silicon detector, but SiModule is a null pointer");
551 const HepGeom::Point3D<double> center =
iter->second;
554 double r = center.rho();
555 double phi = center.phi();
556 double z = center.z();
563 double ScaleFactor = 1.;
598 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
609 msg() <<
"localToGlobal transformation:" <<
endmsg;
612 msg() << localToGlobal.xx() <<
" " << localToGlobal.xy() <<
" " << localToGlobal.xz() <<
endmsg;
613 msg() << localToGlobal.yx() <<
" " << localToGlobal.yy() <<
" " << localToGlobal.yz() <<
endmsg;
614 msg() << localToGlobal.zx() <<
" " << localToGlobal.zy() <<
" " << localToGlobal.zz() <<
endmsg;
627 CLHEP::HepRotation rot;
630 if (ScaleFactor == 0.0) {
654 double randMisX = RandMisX();
655 double randMisY = RandMisY();
656 double randMisZ = RandMisZ();
658 double randMisaplha = RandMisalpha();
659 double randMisbeta = RandMisbeta();
660 double randMisgamma = RandMisgamma();
662 CLHEP::HepRotation rot;
663 HepGeom::Vector3D<double> shift;
666 if (ScaleFactor == 0.0) {
669 shift = HepGeom::Vector3D<double>(randMisX, randMisY, randMisZ);
670 rot = CLHEP::HepRotationX(randMisaplha) * CLHEP::HepRotationY(randMisbeta) * CLHEP::HepRotationZ(randMisgamma);
685 ATH_MSG_DEBUG(
"will not move this module for IBL temp distortion " );
689 parameterizedTrafo = HepGeom::Translate3D(
deltaX,0,0);
700 HepGeom::Vector3D<double> shift(0, 0, 0);
706 CLHEP::HepRotation rot = CLHEP::HepRotationX(0) * CLHEP::HepRotationY(0) * CLHEP::HepRotationZ(0);
726 ATH_MSG_DEBUG(
"will not move TRT endcap for radial distortion " );
729 deltaR =
r/maxRadius * maxDeltaR;
736 ATH_MSG_DEBUG(
"will not move TRT endcap for elliptical distortion " );
746 ATH_MSG_DEBUG(
"will not move TRT endcap for funnel distortion " );
749 deltaR = 2. *
z/maxLength * maxDeltaR;
752 ATH_MSG_DEBUG(
"Wrong misalignment mode entered, doing nothing." );
765 deltaPhi =
r/maxRadius * maxAngle + minRadius/
r * maxAngleInner;
772 ATH_MSG_DEBUG(
"will not move TRT endcap for clamshell distortion " );
787 parameterizedTrafo = HepGeom::RotateZ3D(
deltaPhi);
795 deltaZ =
r/maxRadius * maxDeltaZ;
801 ATH_MSG_DEBUG(
"will not move TRT endcap for skew distortion " );
809 deltaZ = 2. *
z/maxLength * maxDeltaZ;
816 parameterizedTrafo = HepGeom::Translate3D(0,0,
deltaZ);
829 ATH_MSG_DEBUG(
"additional rotation for TRT barrel module!" );
830 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
833 alignmentTrafo = parameterizedTrafo * realLocalToGlobalTRT * parameterizedTrafo * realLocalToGlobalTRT.inverse();
836 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
837 double deltaAlpha = (-2.) *
r * maxAngle/maxLength;
840 CLHEP::HepRotation twistForTRTRotation(HepGeom::Vector3D<double>(center.x(),center.y(),center.z()), deltaAlpha );
844 alignmentTrafo = realLocalToGlobalTRT * twistForTRT * realLocalToGlobalTRT.inverse();
847 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
848 double deltaAlpha = (-2.) * maxDeltaR/maxLength;
852 HepGeom::Vector3D<double> normalVector(center.x(),center.y(),center.z());
853 HepGeom::Vector3D<double> beamVector(0.,0.,1.);
854 HepGeom::Vector3D<double> rotationAxis = normalVector.cross(beamVector);
855 CLHEP::HepRotation twistForTRTRotation(rotationAxis, deltaAlpha );
858 alignmentTrafo = realLocalToGlobalTRT * twistForTRT * realLocalToGlobalTRT.inverse();
864 alignmentTrafo = parameterizedTrafo;
868 alignmentTrafo = localToGlobal.inverse() * parameterizedTrafo * localToGlobal;
875 msg() <<
"Align Transformation x phi = (" << alignmentTrafo.getRotation().phiX() /
CLHEP::deg <<
")" <<
endmsg;
876 msg() <<
"Align Transformation x Theta = (" << alignmentTrafo.getRotation().thetaX() /
CLHEP::deg <<
")" <<
endmsg;
877 msg() <<
"Align Transformation y phi = (" << alignmentTrafo.getRotation().phiY() /
CLHEP::deg <<
")" <<
endmsg;
878 msg() <<
"Align Transformation y Theta = (" << alignmentTrafo.getRotation().thetaY() /
CLHEP::deg <<
")" <<
endmsg;
879 msg() <<
"Align Transformation z phi = (" << alignmentTrafo.getRotation().phiZ() /
CLHEP::deg <<
")" <<
endmsg;
880 msg() <<
"Align Transformation z Theta = (" << alignmentTrafo.getRotation().thetaZ() /
CLHEP::deg <<
")" <<
endmsg;
884 if ( std::abs(alignmentTrafo.getTranslation().x()) < 1
e-10) {
885 HepGeom::Vector3D<double>
886 zeroSuppressedTranslation(0,alignmentTrafo.getTranslation().y(),alignmentTrafo.
887 getTranslation().
z());
891 if ( std::abs(alignmentTrafo.getTranslation().y()) < 1
e-10) {
892 HepGeom::Vector3D<double>
893 zeroSuppressedTranslation(alignmentTrafo.getTranslation().x(),0,alignmentTrafo.
894 getTranslation().
z());
898 if ( std::abs(alignmentTrafo.getTranslation().z()) < 1
e-10) {
899 HepGeom::Vector3D<double>
900 zeroSuppressedTranslation(alignmentTrafo.getTranslation().x(),alignmentTrafo.getTranslation().y(),0);
904 if ( std::abs(alignmentTrafo.getRotation().getDelta()) < 1
e-10) {
905 CLHEP::HepRotation zeroSuppressedRotation(alignmentTrafo.getRotation());
906 zeroSuppressedRotation.setDelta(0.);
933 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
958 HepGeom::Point3D<double> alignedPosGlobal = LocalaGlobal * alignedPosLocal;
966 double radialShift_x = SCT_Center[0];
967 double radialShift_y = SCT_Center[1];
970 HepGeom::Point3D<double> SCT_endcap_alignedPosGlobal = LocalaaGlobal * alignedPosLocal;
1015 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
1019 if (StatusCode::SUCCESS!=
ntupleSvc()->writeRecord(
"NTUPLES/CREATEMISALIGN/InitialAlignment")) {
1020 ATH_MSG_ERROR(
"Could not write InitialAlignment ntuple." );
1035 ATH_MSG_INFO(
"Writing IoV information to mysql file" );
1042 ATH_MSG_ERROR(
"Write of AlignableTransforms (TRT) failed" );
1044 ATH_MSG_INFO(
"AlignableTransforms for TRT were written" );
1049 ATH_MSG_INFO(
"Writing IoV information for TRT to mysql file" );
1050 if ( StatusCode::SUCCESS
1057 return StatusCode::SUCCESS;
1064 HepGeom::Vector3D<double> AlignShift(AlignParams[0],AlignParams[1],AlignParams[2]);
1065 CLHEP::HepRotation AlignRot;
1067 AlignRot = CLHEP::HepRotationX(AlignParams[3]) * CLHEP::HepRotationY(AlignParams[4]) * CLHEP::HepRotationZ(AlignParams[5]);
1070 return AlignTransform;
1082 if (barrel_ec==1) barrel_ec=-1;
1116 double T = 15 + temp_shift;
1117 return 1.53e-12 - 1.02e-13*T;