File indexing completed on 2024-04-06 12:30:53
0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0004 #include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h"
0005 #include "DataFormats/CTPPSDetId/interface/TotemRPDetId.h"
0006 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0007 #include "SimPPS/RPDigiProducer/plugins/RPDisplacementGenerator.h"
0008
0009 #include <Math/RotationZYX.h>
0010 #include <Math/Rotation3D.h>
0011
0012 using namespace std;
0013 using namespace edm;
0014
0015 RPDisplacementGenerator::RPDisplacementGenerator(bool iIsOn,
0016 RPDetId _detId,
0017 const CTPPSRPAlignmentCorrectionsData *alignments,
0018 const CTPPSGeometry &geom)
0019 : detId_(_detId) {
0020 isOn_ = iIsOn;
0021
0022 unsigned int decId = rawToDecId(detId_);
0023
0024 math::XYZVectorD S_m;
0025 RotationMatrix R_m;
0026
0027 if (alignments) {
0028 const CTPPSRPAlignmentCorrectionData &ac = alignments->getFullSensorCorrection(decId);
0029 S_m = ac.getTranslation();
0030 R_m = ac.getRotationMatrix();
0031 } else
0032 isOn_ = false;
0033
0034
0035 const DetGeomDesc *g = geom.sensor(detId_);
0036 const RotationMatrix &R_l = g->rotation();
0037 rotation_ = R_l.Inverse() * R_m.Inverse() * R_l;
0038 shift_ = R_l.Inverse() * R_m.Inverse() * S_m;
0039
0040 LogDebug("RPDisplacementGenerator").log([&](auto &log) {
0041 log << " det id = " << decId << ", isOn = " << isOn_ << "\n";
0042 if (isOn_) {
0043 log << " shift = " << shift_ << "\n";
0044 log << " rotation = " << rotation_ << "\n";
0045 }
0046 });
0047 }
0048
0049 Local3DPoint RPDisplacementGenerator::displacePoint(const Local3DPoint &p) {
0050
0051
0052 Translation v(p.x(), p.y(), p.z());
0053 v = rotation_ * v - shift_;
0054
0055 return Local3DPoint(v.x(), v.y(), v.z());
0056 }
0057
0058 PSimHit RPDisplacementGenerator::displace(const PSimHit &input) {
0059 if (!isOn_)
0060 return input;
0061
0062 const Local3DPoint &ep = input.entryPoint(), &xp = input.exitPoint();
0063 const Local3DPoint &dep = displacePoint(ep), &dxp = displacePoint(xp);
0064
0065 LogDebug("RPDisplacementGenerator::displace\n") << " entry point: " << ep << " -> " << dep << "\n"
0066 << " exit point : " << xp << " -> " << dxp << "\n";
0067
0068 return PSimHit(dep,
0069 dxp,
0070 input.pabs(),
0071 input.tof(),
0072 input.energyLoss(),
0073 input.particleType(),
0074 input.detUnitId(),
0075 input.trackId(),
0076 input.thetaAtEntry(),
0077 input.phiAtEntry(),
0078 input.processType());
0079 }
0080
0081 uint32_t RPDisplacementGenerator::rawToDecId(uint32_t raw) {
0082 return ((raw >> CTPPSDetId::startArmBit) & CTPPSDetId::maskArm) * 1000 +
0083 ((raw >> CTPPSDetId::startStationBit) & CTPPSDetId::maskStation) * 100 +
0084 ((raw >> CTPPSDetId::startRPBit) & CTPPSDetId::maskRP) * 10 +
0085 ((raw >> TotemRPDetId::startPlaneBit) & TotemRPDetId::maskPlane);
0086 }