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"
52 std::ostringstream
os;
53 os <<
"\nAlignment x = (" << initialAlignment.getTranslation().x() /
CLHEP::micrometer <<
") micron\n";
54 os <<
"Alignment y = (" << initialAlignment.getTranslation().y() /
CLHEP::micrometer <<
") micron\n";
55 os <<
"Alignment z = (" << initialAlignment.getTranslation().z() /
CLHEP::micrometer <<
") micron\n";
56 os <<
"Alignment x phi = (" << initialAlignment.getRotation().phiX() /
CLHEP::deg <<
") degree\n";
57 os <<
"Alignment x Theta = (" << initialAlignment.getRotation().thetaX() /
CLHEP::deg <<
") degree\n";
58 os <<
"Alignment y phi = (" << initialAlignment.getRotation().phiY() /
CLHEP::deg <<
") degree\n";
59 os <<
"Alignment y Theta = (" << initialAlignment.getRotation().thetaY() /
CLHEP::deg <<
") degree\n";
60 os <<
"Alignment z phi = (" << initialAlignment.getRotation().phiZ() /
CLHEP::deg <<
") degree\n";
61 os <<
"Alignment z Theta = (" << initialAlignment.getRotation().thetaZ() /
CLHEP::deg <<
") degree\n";
73 m_pixelIdHelper(nullptr),
74 m_sctIdHelper(nullptr),
75 m_trtIdHelper(nullptr),
76 m_IDAlignDBTool(
"InDetAlignDBTool",this),
77 m_trtaligndbservice(
"TRT_AlignDbSvc",
name),
78 m_asciiFileNameBase(
"MisalignmentSet"),
79 m_SQLiteTag(
"test_tag"),
81 m_createFreshDB(true),
82 m_MisalignmentMode(0),
86 m_local_translation{0., 0., 0.},
87 m_local_rotation{0., 0., 0.},
93 m_IBLBowingTshift(0.),
94 m_ScalePixelBarrel(1.),
95 m_ScalePixelEndcap(1.),
100 m_VisualizationLookupTree(
nullptr),
101 m_AthenaHashedID(-1),
102 m_HumanReadableID(-1),
107 declareProperty(
"ASCIIFilenameBase" , m_asciiFileNameBase);
108 declareProperty(
"SQLiteTag" , m_SQLiteTag);
109 declareProperty(
"MisalignMode" , m_MisalignmentMode);
110 declareProperty(
"Translation" , m_translation);
111 declareProperty(
"Rotation" , m_rotation);
112 declareProperty(
"Local_Translation" , m_local_translation);
113 declareProperty(
"Local_Rotation" , m_local_rotation);
114 declareProperty(
"Index" , m_index);
115 declareProperty(
"MaxShift" , m_Misalign_maxShift);
116 declareProperty(
"MaxShiftInner" , m_Misalign_maxShift_Inner);
117 declareProperty(
"CreateFreshDB" , m_createFreshDB);
118 declareProperty(
"IDAlignDBTool" , m_IDAlignDBTool);
119 declareProperty(
"TRTAlignDBService" , m_trtaligndbservice);
120 declareProperty(
"ScalePixelIBL" , m_ScalePixelIBL);
121 declareProperty(
"ScalePixelDBM" , m_ScalePixelDBM);
122 declareProperty(
"IBLBowingTshift" , m_IBLBowingTshift);
123 declareProperty(
"ScalePixelBarrel" , m_ScalePixelBarrel);
124 declareProperty(
"ScalePixelEndcap" , m_ScalePixelEndcap);
125 declareProperty(
"ScaleSCTBarrel" , m_ScaleSCTBarrel);
126 declareProperty(
"ScaleSCTEndcap" , m_ScaleSCTEndcap);
127 declareProperty(
"ScaleTRTBarrel" , m_ScaleTRTBarrel);
128 declareProperty(
"ScaleTRTEndcap" , m_ScaleTRTEndcap);
168 SmartIF<ITHistSvc> hist_svc{Gaudi::svcLocator()->service(
"THistSvc")};
177 NTupleFilePtr file1(
ntupleSvc(),
"/NTUPLES/CREATEMISALIGN");
179 NTuplePtr
nt(
ntupleSvc(),
"/NTUPLES/CREATEMISALIGN/InitialAlignment");
181 nt =
ntupleSvc()->book(
"/NTUPLES/CREATEMISALIGN/InitialAlignment", CLID_ColumnWiseTuple,
"InitialAlignment");
203 msg(MSG::ERROR) <<
"Failed to book InitialAlignment ntuple." <<
endmsg;
220 ATH_MSG_INFO(
"Dry run, no misalignment will be generated." );
223 return StatusCode::SUCCESS;
255 return StatusCode::FAILURE;
261 return StatusCode::SUCCESS;
271 return StatusCode::SUCCESS;
280 if (not sctDetEleHandle.
isValid() or elements==
nullptr) {
317 msg() << commonAlignmentOutput(InitialAlignment);
330 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
336 const Identifier Pixel_ModuleID = element->identify();
366 msg() << commonAlignmentOutput(InitialAlignment);
381 std::map< Identifier, std::vector<double> > trtModulesWithCOG;
386 if (not trtDetEleHandle.
isValid() or elements==
nullptr) {
394 const Identifier TRTID_orig = element->identify();
396 bool insertSuccess{};
397 std::tie(
std::ignore, insertSuccess) = trtModulesWithCOG.insert({TRTID,std::vector<double>(4,0.)});
398 if (not insertSuccess){
399 ATH_MSG_VERBOSE(
"No insert was performed, identifier was already in the trtModulesWithCOG map");
402 unsigned int nStraws = element->nStraws();
403 for (
unsigned int l = 0;
l<nStraws;
l++) {
405 trtModulesWithCOG[TRTID].at(0) += strawcenter.x();
406 trtModulesWithCOG[TRTID].at(1) += strawcenter.y();
407 trtModulesWithCOG[TRTID].at(2) += strawcenter.z();
408 trtModulesWithCOG[TRTID].at(3) += 1.;
412 ATH_MSG_DEBUG(
"this strawlayer has " << nStraws <<
" straws." );
413 ATH_MSG_DEBUG(
"strawcount of this module: " << trtModulesWithCOG[TRTID].at(3) );
418 std::map< Identifier, std::vector<double> >::const_iterator iter2;
419 for (iter2 = trtModulesWithCOG.begin(); iter2!=trtModulesWithCOG.end(); ++iter2) {
421 double nStraws = iter2->second.at(3);
424 m_ModuleList[TRTID] = HepGeom::Point3D<double>(iter2->second.at(0)/nStraws, iter2->second.at(1)/nStraws,iter2->second.at(2)/nStraws);
433 msg() << commonAlignmentOutput(InitialAlignment);
449 SmartIF<IRndmGenSvc> randsvc{Gaudi::svcLocator()->service(
"RndmGenSvc")};
495 pixelElements = *pixelDetEleHandle;
496 if (not pixelDetEleHandle.
isValid() or pixelElements==
nullptr) {
498 return StatusCode::FAILURE;
504 sctElements = *sctDetEleHandle;
505 if (not sctDetEleHandle.
isValid() or sctElements==
nullptr) {
507 return StatusCode::FAILURE;
520 else ATH_MSG_WARNING(
"Trying to access a Pixel module when running with no Pixel!");
525 else ATH_MSG_WARNING(
"Trying to access an SCT/Strop module when running with no SCT/Strip!");
531 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
546 ATH_MSG_WARNING(
"Apparently in a silicon detector, but SiModule is a null pointer");
549 const HepGeom::Point3D<double> center =
iter->second;
552 double r = center.rho();
553 double phi = center.phi();
554 double z = center.z();
561 double ScaleFactor = 1.;
596 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
607 msg() <<
"localToGlobal transformation:" <<
endmsg;
610 msg() << localToGlobal.xx() <<
" " << localToGlobal.xy() <<
" " << localToGlobal.xz() <<
endmsg;
611 msg() << localToGlobal.yx() <<
" " << localToGlobal.yy() <<
" " << localToGlobal.yz() <<
endmsg;
612 msg() << localToGlobal.zx() <<
" " << localToGlobal.zy() <<
" " << localToGlobal.zz() <<
endmsg;
625 CLHEP::HepRotation rot;
628 if (ScaleFactor == 0.0) {
646 double randMisX = RandMisX();
647 double randMisY = RandMisY();
648 double randMisZ = RandMisZ();
650 double randMisaplha = RandMisalpha();
651 double randMisbeta = RandMisbeta();
652 double randMisgamma = RandMisgamma();
654 CLHEP::HepRotation rot;
655 HepGeom::Vector3D<double> shift;
658 if (ScaleFactor == 0.0) {
662 shift = HepGeom::Vector3D<double>(randMisX, randMisY, randMisZ);
663 rot = CLHEP::HepRotationX(randMisaplha) * CLHEP::HepRotationY(randMisbeta) * CLHEP::HepRotationZ(randMisgamma);
666 shift = HepGeom::Vector3D<double>(0, 0, 0);
667 rot = CLHEP::HepRotationX(randMisaplha) * CLHEP::HepRotationY(randMisbeta) * CLHEP::HepRotationZ(randMisgamma);
670 shift = HepGeom::Vector3D<double>(randMisX, randMisY, randMisZ);
671 rot = CLHEP::HepRotationX(0) * CLHEP::HepRotationY(0) * CLHEP::HepRotationZ(0);
673 else { shift = HepGeom::Vector3D<double>(0, 0, 0);
674 rot = CLHEP::HepRotationX(0) * CLHEP::HepRotationY(0) * CLHEP::HepRotationZ(0);
690 ATH_MSG_DEBUG(
"will not move this module for IBL temp distortion " );
694 parameterizedTrafo = HepGeom::Translate3D(
deltaX,0,0);
705 HepGeom::Vector3D<double> shift(0, 0, 0);
711 CLHEP::HepRotation rot = CLHEP::HepRotationX(0) * CLHEP::HepRotationY(0) * CLHEP::HepRotationZ(0);
731 ATH_MSG_DEBUG(
"will not move TRT endcap for radial distortion " );
734 deltaR =
r/maxRadius * maxDeltaR;
741 ATH_MSG_DEBUG(
"will not move TRT endcap for elliptical distortion " );
744 deltaR =
cos ( 2*phi ) *
r/maxRadius * maxDeltaR;
751 ATH_MSG_DEBUG(
"will not move TRT endcap for funnel distortion " );
754 deltaR = 2. *
z/maxLength * maxDeltaR;
757 ATH_MSG_DEBUG(
"Wrong misalignment mode entered, doing nothing." );
770 deltaPhi =
r/maxRadius * maxAngle + minRadius/
r * maxAngleInner;
777 ATH_MSG_DEBUG(
"will not move TRT endcap for clamshell distortion " );
792 parameterizedTrafo = HepGeom::RotateZ3D(
deltaPhi);
800 deltaZ =
r/maxRadius * maxDeltaZ;
806 ATH_MSG_DEBUG(
"will not move TRT endcap for skew distortion " );
814 deltaZ = 2. *
z/maxLength * maxDeltaZ;
821 parameterizedTrafo = HepGeom::Translate3D(0,0,
deltaZ);
834 ATH_MSG_DEBUG(
"additional rotation for TRT barrel module!" );
835 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
838 alignmentTrafo = parameterizedTrafo * realLocalToGlobalTRT * parameterizedTrafo * realLocalToGlobalTRT.inverse();
841 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
842 double deltaAlpha = (-2.) *
r * maxAngle/maxLength;
845 CLHEP::HepRotation twistForTRTRotation(HepGeom::Vector3D<double>(center.x(),center.y(),center.z()), deltaAlpha );
849 alignmentTrafo = realLocalToGlobalTRT * twistForTRT * realLocalToGlobalTRT.inverse();
852 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
853 double deltaAlpha = (-2.) * maxDeltaR/maxLength;
857 HepGeom::Vector3D<double> normalVector(center.x(),center.y(),center.z());
858 HepGeom::Vector3D<double> beamVector(0.,0.,1.);
859 HepGeom::Vector3D<double> rotationAxis = normalVector.cross(beamVector);
860 CLHEP::HepRotation twistForTRTRotation(rotationAxis, deltaAlpha );
863 alignmentTrafo = realLocalToGlobalTRT * twistForTRT * realLocalToGlobalTRT.inverse();
869 alignmentTrafo = parameterizedTrafo;
873 alignmentTrafo = localToGlobal.inverse() * parameterizedTrafo * localToGlobal;
880 msg() <<
"Align Transformation x phi = (" << alignmentTrafo.getRotation().phiX() /
CLHEP::deg <<
")" <<
endmsg;
881 msg() <<
"Align Transformation x Theta = (" << alignmentTrafo.getRotation().thetaX() /
CLHEP::deg <<
")" <<
endmsg;
882 msg() <<
"Align Transformation y phi = (" << alignmentTrafo.getRotation().phiY() /
CLHEP::deg <<
")" <<
endmsg;
883 msg() <<
"Align Transformation y Theta = (" << alignmentTrafo.getRotation().thetaY() /
CLHEP::deg <<
")" <<
endmsg;
884 msg() <<
"Align Transformation z phi = (" << alignmentTrafo.getRotation().phiZ() /
CLHEP::deg <<
")" <<
endmsg;
885 msg() <<
"Align Transformation z Theta = (" << alignmentTrafo.getRotation().thetaZ() /
CLHEP::deg <<
")" <<
endmsg;
889 if ( std::abs(alignmentTrafo.getTranslation().x()) < 1
e-10) {
890 HepGeom::Vector3D<double>
891 zeroSuppressedTranslation(0,alignmentTrafo.getTranslation().y(),alignmentTrafo.
892 getTranslation().
z());
896 if ( std::abs(alignmentTrafo.getTranslation().y()) < 1
e-10) {
897 HepGeom::Vector3D<double>
898 zeroSuppressedTranslation(alignmentTrafo.getTranslation().x(),0,alignmentTrafo.
899 getTranslation().
z());
903 if ( std::abs(alignmentTrafo.getTranslation().z()) < 1
e-10) {
904 HepGeom::Vector3D<double>
905 zeroSuppressedTranslation(alignmentTrafo.getTranslation().x(),alignmentTrafo.getTranslation().y(),0);
909 if ( std::abs(alignmentTrafo.getRotation().getDelta()) < 1
e-10) {
910 CLHEP::HepRotation zeroSuppressedRotation(alignmentTrafo.getRotation());
911 zeroSuppressedRotation.setDelta(0.);
938 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
963 HepGeom::Point3D<double> alignedPosGlobal = LocalaGlobal * alignedPosLocal;
971 double radialShift_x = SCT_Center[0];
972 double radialShift_y = SCT_Center[1];
975 HepGeom::Point3D<double> SCT_endcap_alignedPosGlobal = LocalaaGlobal * alignedPosLocal;
1020 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
1024 if (StatusCode::SUCCESS!=
ntupleSvc()->writeRecord(
"NTUPLES/CREATEMISALIGN/InitialAlignment")) {
1025 ATH_MSG_ERROR(
"Could not write InitialAlignment ntuple." );
1040 ATH_MSG_INFO(
"Writing IoV information to mysql file" );
1047 ATH_MSG_ERROR(
"Write of AlignableTransforms (TRT) failed" );
1049 ATH_MSG_INFO(
"AlignableTransforms for TRT were written" );
1054 ATH_MSG_INFO(
"Writing IoV information for TRT to mysql file" );
1055 if ( StatusCode::SUCCESS
1062 return StatusCode::SUCCESS;
1069 HepGeom::Vector3D<double> AlignShift(AlignParams[0],AlignParams[1],AlignParams[2]);
1070 CLHEP::HepRotation AlignRot;
1072 AlignRot = CLHEP::HepRotationX(AlignParams[3]) * CLHEP::HepRotationY(AlignParams[4]) * CLHEP::HepRotationZ(AlignParams[5]);
1075 return AlignTransform;
1087 if (barrel_ec==1) barrel_ec=-1;
1121 double T = 15 + temp_shift;
1122 return 1.53e-12 - 1.02e-13*T;