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"
53 std::ostringstream
os;
54 os <<
"\nAlignment x = (" << initialAlignment.getTranslation().x() /
CLHEP::micrometer <<
") micron\n";
55 os <<
"Alignment y = (" << initialAlignment.getTranslation().y() /
CLHEP::micrometer <<
") micron\n";
56 os <<
"Alignment z = (" << initialAlignment.getTranslation().z() /
CLHEP::micrometer <<
") micron\n";
57 os <<
"Alignment x phi = (" << initialAlignment.getRotation().phiX() /
CLHEP::deg <<
") degree\n";
58 os <<
"Alignment x Theta = (" << initialAlignment.getRotation().thetaX() /
CLHEP::deg <<
") degree\n";
59 os <<
"Alignment y phi = (" << initialAlignment.getRotation().phiY() /
CLHEP::deg <<
") degree\n";
60 os <<
"Alignment y Theta = (" << initialAlignment.getRotation().thetaY() /
CLHEP::deg <<
") degree\n";
61 os <<
"Alignment z phi = (" << initialAlignment.getRotation().phiZ() /
CLHEP::deg <<
") degree\n";
62 os <<
"Alignment z Theta = (" << initialAlignment.getRotation().thetaZ() /
CLHEP::deg <<
") degree\n";
74 m_pixelIdHelper(nullptr),
75 m_sctIdHelper(nullptr),
76 m_trtIdHelper(nullptr),
77 m_IDAlignDBTool(
"InDetAlignDBTool",this),
78 m_trtaligndbservice(
"TRT_AlignDbSvc",
name),
79 m_asciiFileNameBase(
"MisalignmentSet"),
80 m_SQLiteTag(
"test_tag"),
82 m_createFreshDB(true),
83 m_MisalignmentMode(0),
85 m_Misalign_maxShift(1*
CLHEP::
mm),
89 m_IBLBowingTshift(0.),
90 m_ScalePixelBarrel(1.),
91 m_ScalePixelEndcap(1.),
96 m_VisualizationLookupTree(nullptr),
98 m_HumanReadableID(-1),
168 NTupleFilePtr file1(
ntupleSvc(),
"/NTUPLES/CREATEMISALIGN");
170 NTuplePtr
nt(
ntupleSvc(),
"/NTUPLES/CREATEMISALIGN/InitialAlignment");
172 nt =
ntupleSvc()->book(
"/NTUPLES/CREATEMISALIGN/InitialAlignment", CLID_ColumnWiseTuple,
"InitialAlignment");
194 msg(MSG::ERROR) <<
"Failed to book InitialAlignment ntuple." <<
endmsg;
211 ATH_MSG_INFO(
"Dry run, no misalignment will be generated." );
214 return StatusCode::SUCCESS;
246 return StatusCode::FAILURE;
252 return StatusCode::SUCCESS;
262 return StatusCode::SUCCESS;
271 if (not sctDetEleHandle.
isValid() or elements==
nullptr) {
308 msg() << commonAlignmentOutput(InitialAlignment);
321 if (not pixelDetEleHandle.
isValid() or elements==
nullptr) {
327 const Identifier Pixel_ModuleID = element->identify();
357 msg() << commonAlignmentOutput(InitialAlignment);
372 std::map< Identifier, std::vector<double> > trtModulesWithCOG;
377 if (not trtDetEleHandle.
isValid() or elements==
nullptr) {
385 const Identifier TRTID_orig = element->identify();
387 bool insertSuccess{};
388 std::tie(
std::ignore, insertSuccess) = trtModulesWithCOG.insert({TRTID,std::vector<double>(4,0.)});
389 if (not insertSuccess){
390 ATH_MSG_VERBOSE(
"No insert was performed, identifier was already in the trtModulesWithCOG map");
393 unsigned int nStraws = element->nStraws();
394 for (
unsigned int l = 0;
l<nStraws;
l++) {
396 trtModulesWithCOG[TRTID].at(0) += strawcenter.x();
397 trtModulesWithCOG[TRTID].at(1) += strawcenter.y();
398 trtModulesWithCOG[TRTID].at(2) += strawcenter.z();
399 trtModulesWithCOG[TRTID].at(3) += 1.;
403 ATH_MSG_DEBUG(
"this strawlayer has " << nStraws <<
" straws." );
404 ATH_MSG_DEBUG(
"strawcount of this module: " << trtModulesWithCOG[TRTID].at(3) );
409 std::map< Identifier, std::vector<double> >::const_iterator iter2;
410 for (iter2 = trtModulesWithCOG.begin(); iter2!=trtModulesWithCOG.end(); ++iter2) {
412 double nStraws = iter2->second.at(3);
415 m_ModuleList[TRTID] = HepGeom::Point3D<double>(iter2->second.at(0)/nStraws, iter2->second.at(1)/nStraws,iter2->second.at(2)/nStraws);
424 msg() << commonAlignmentOutput(InitialAlignment);
440 IRndmGenSvc* randsvc;
441 if (StatusCode::SUCCESS!=service(
"RndmGenSvc",randsvc,
true)) {
490 pixelElements = *pixelDetEleHandle;
491 if (not pixelDetEleHandle.
isValid() or pixelElements==
nullptr) {
493 return StatusCode::FAILURE;
499 sctElements = *sctDetEleHandle;
500 if (not sctDetEleHandle.
isValid() or sctElements==
nullptr) {
502 return StatusCode::FAILURE;
515 else ATH_MSG_WARNING(
"Trying to access a Pixel module when running with no Pixel!");
520 else ATH_MSG_WARNING(
"Trying to access an SCT/Strop module when running with no SCT/Strip!");
526 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
541 ATH_MSG_WARNING(
"Apparently in a silicon detector, but SiModule is a null pointer");
544 const HepGeom::Point3D<double> center = iter->second;
547 double r = center.rho();
548 double phi = center.phi();
549 double z = center.z();
556 double ScaleFactor = 1.;
591 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
602 msg() <<
"localToGlobal transformation:" <<
endmsg;
605 msg() << localToGlobal.xx() <<
" " << localToGlobal.xy() <<
" " << localToGlobal.xz() <<
endmsg;
606 msg() << localToGlobal.yx() <<
" " << localToGlobal.yy() <<
" " << localToGlobal.yz() <<
endmsg;
607 msg() << localToGlobal.zx() <<
" " << localToGlobal.zy() <<
" " << localToGlobal.zz() <<
endmsg;
620 CLHEP::HepRotation rot;
623 if (ScaleFactor == 0.0) {
641 double randMisX = RandMisX();
642 double randMisY = RandMisY();
643 double randMisZ = RandMisZ();
645 HepGeom::Vector3D<double> shift(randMisX, randMisY, randMisZ);
646 double randMisaplha = RandMisalpha();
647 double randMisbeta = RandMisbeta();
648 double randMisgamma = RandMisgamma();
650 CLHEP::HepRotation rot;
651 rot = CLHEP::HepRotationX(randMisaplha) * CLHEP::HepRotationY(randMisbeta) * CLHEP::HepRotationZ(randMisgamma);
654 if (ScaleFactor == 0.0) {
672 ATH_MSG_DEBUG(
"will not move this module for IBL temp distortion " );
676 parameterizedTrafo = HepGeom::Translate3D(
deltaX,0,0);
688 ATH_MSG_DEBUG(
"will not move TRT endcap for radial distortion " );
691 deltaR =
r/maxRadius * maxDeltaR;
698 ATH_MSG_DEBUG(
"will not move TRT endcap for elliptical distortion " );
708 ATH_MSG_DEBUG(
"will not move TRT endcap for funnel distortion " );
711 deltaR = 2. *
z/maxLength * maxDeltaR;
714 ATH_MSG_DEBUG(
"Wrong misalignment mode entered, doing nothing." );
727 deltaPhi =
r/maxRadius * maxAngle + minRadius/
r * maxAngleInner;
734 ATH_MSG_DEBUG(
"will not move TRT endcap for clamshell distortion " );
749 parameterizedTrafo = HepGeom::RotateZ3D(
deltaPhi);
757 deltaZ =
r/maxRadius * maxDeltaZ;
763 ATH_MSG_DEBUG(
"will not move TRT endcap for skew distortion " );
771 deltaZ = 2. *
z/maxLength * maxDeltaZ;
778 parameterizedTrafo = HepGeom::Translate3D(0,0,
deltaZ);
791 ATH_MSG_DEBUG(
"additional rotation for TRT barrel module!" );
792 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
795 alignmentTrafo = parameterizedTrafo * realLocalToGlobalTRT * parameterizedTrafo * realLocalToGlobalTRT.inverse();
798 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
799 double deltaAlpha = (-2.) *
r * maxAngle/maxLength;
802 CLHEP::HepRotation twistForTRTRotation(HepGeom::Vector3D<double>(center.x(),center.y(),center.z()), deltaAlpha );
806 alignmentTrafo = realLocalToGlobalTRT * twistForTRT * realLocalToGlobalTRT.inverse();
809 HepGeom::Transform3D realLocalToGlobalTRT = HepGeom::Translate3D(center.x(),center.y(),center.z());
810 double deltaAlpha = (-2.) * maxDeltaR/maxLength;
814 HepGeom::Vector3D<double> normalVector(center.x(),center.y(),center.z());
815 HepGeom::Vector3D<double> beamVector(0.,0.,1.);
816 HepGeom::Vector3D<double> rotationAxis = normalVector.cross(beamVector);
817 CLHEP::HepRotation twistForTRTRotation(rotationAxis, deltaAlpha );
820 alignmentTrafo = realLocalToGlobalTRT * twistForTRT * realLocalToGlobalTRT.inverse();
826 alignmentTrafo = parameterizedTrafo;
830 alignmentTrafo = localToGlobal.inverse() * parameterizedTrafo * localToGlobal;
837 msg() <<
"Align Transformation x phi = (" << alignmentTrafo.getRotation().phiX() /
CLHEP::deg <<
")" <<
endmsg;
838 msg() <<
"Align Transformation x Theta = (" << alignmentTrafo.getRotation().thetaX() /
CLHEP::deg <<
")" <<
endmsg;
839 msg() <<
"Align Transformation y phi = (" << alignmentTrafo.getRotation().phiY() /
CLHEP::deg <<
")" <<
endmsg;
840 msg() <<
"Align Transformation y Theta = (" << alignmentTrafo.getRotation().thetaY() /
CLHEP::deg <<
")" <<
endmsg;
841 msg() <<
"Align Transformation z phi = (" << alignmentTrafo.getRotation().phiZ() /
CLHEP::deg <<
")" <<
endmsg;
842 msg() <<
"Align Transformation z Theta = (" << alignmentTrafo.getRotation().thetaZ() /
CLHEP::deg <<
")" <<
endmsg;
846 if ( std::abs(alignmentTrafo.getTranslation().x()) < 1
e-10) {
847 HepGeom::Vector3D<double>
848 zeroSuppressedTranslation(0,alignmentTrafo.getTranslation().y(),alignmentTrafo.
849 getTranslation().
z());
853 if ( std::abs(alignmentTrafo.getTranslation().y()) < 1
e-10) {
854 HepGeom::Vector3D<double>
855 zeroSuppressedTranslation(alignmentTrafo.getTranslation().x(),0,alignmentTrafo.
856 getTranslation().
z());
860 if ( std::abs(alignmentTrafo.getTranslation().z()) < 1
e-10) {
861 HepGeom::Vector3D<double>
862 zeroSuppressedTranslation(alignmentTrafo.getTranslation().x(),alignmentTrafo.getTranslation().y(),0);
866 if ( std::abs(alignmentTrafo.getRotation().getDelta()) < 1
e-10) {
867 CLHEP::HepRotation zeroSuppressedRotation(alignmentTrafo.getRotation());
868 zeroSuppressedRotation.setDelta(0.);
895 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
920 HepGeom::Point3D<double> alignedPosGlobal = LocalaGlobal * alignedPosLocal;
928 double radialShift_x = SCT_Center[0];
929 double radialShift_y = SCT_Center[1];
932 HepGeom::Point3D<double> SCT_endcap_alignedPosGlobal = LocalaaGlobal * alignedPosLocal;
977 ATH_MSG_WARNING(
"Something fishy, identifier is neither Pixel, nor SCT or TRT!" );
981 if (StatusCode::SUCCESS!=
ntupleSvc()->writeRecord(
"NTUPLES/CREATEMISALIGN/InitialAlignment")) {
997 ATH_MSG_INFO(
"Writing IoV information to mysql file" );
1004 ATH_MSG_ERROR(
"Write of AlignableTransforms (TRT) failed" );
1006 ATH_MSG_INFO(
"AlignableTransforms for TRT were written" );
1011 ATH_MSG_INFO(
"Writing IoV information for TRT to mysql file" );
1012 if ( StatusCode::SUCCESS
1019 return StatusCode::SUCCESS;
1026 HepGeom::Vector3D<double> AlignShift(AlignParams[0],AlignParams[1],AlignParams[2]);
1027 CLHEP::HepRotation AlignRot;
1029 AlignRot = CLHEP::HepRotationX(AlignParams[3]) * CLHEP::HepRotationY(AlignParams[4]) * CLHEP::HepRotationZ(AlignParams[5]);
1032 return AlignTransform;
1044 if (barrel_ec==1) barrel_ec=-1;
1078 double T = 15 + temp_shift;
1079 return 1.53e-12 - 1.02e-13*T;
1092 double Tx = p0 - p1*(
z+p2) * (4.*p2*
pow((
z+p2),2) -
pow((
z+p2),3) -
pow((2.*p2),3));