Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:27

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