Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:33

0001 /****************************************************************************
0002 * Authors: 
0003 *  Jan Kašpar (jan.kaspar@gmail.com) 
0004 ****************************************************************************/
0005 
0006 #include "FWCore/Framework/interface/stream/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/ParameterSet/interface/FileInPath.h"
0013 
0014 #include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionData.h"
0015 #include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsData.h"
0016 
0017 #include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
0018 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0019 #include "CondFormats/PPSObjects/interface/CTPPSRPAlignmentCorrectionsMethods.h"
0020 
0021 #include "CalibPPS/AlignmentRelative/interface/AlignmentTask.h"
0022 #include "CalibPPS/AlignmentRelative/interface/Utilities.h"
0023 
0024 /**
0025  *\brief Modifies the alignment modes unconstrained by the track-based alignment.
0026  **/
0027 class PPSModifySingularModes : public edm::stream::EDAnalyzer<> {
0028 public:
0029   PPSModifySingularModes(const edm::ParameterSet &ps);
0030 
0031 private:
0032   edm::ParameterSet ps_;
0033 
0034   edm::ESGetToken<CTPPSGeometry, VeryForwardRealGeometryRecord> tokenRealGeometry_;
0035 
0036   void beginRun(edm::Run const &, edm::EventSetup const &) override;
0037 
0038   void analyze(const edm::Event &e, const edm::EventSetup &es) override {}
0039 };
0040 
0041 using namespace std;
0042 using namespace edm;
0043 
0044 //----------------------------------------------------------------------------------------------------
0045 
0046 PPSModifySingularModes::PPSModifySingularModes(const ParameterSet &ps)
0047     : ps_(ps), tokenRealGeometry_(esConsumes<edm::Transition::BeginRun>()) {}
0048 
0049 //----------------------------------------------------------------------------------------------------
0050 
0051 void PPSModifySingularModes::beginRun(edm::Run const &, edm::EventSetup const &es) {
0052   // get config parameters
0053   const double z1 = ps_.getUntrackedParameter<double>("z1");
0054   const double z2 = ps_.getUntrackedParameter<double>("z2");
0055   const double de_x1 = ps_.getUntrackedParameter<double>("de_x1");
0056   const double de_x2 = ps_.getUntrackedParameter<double>("de_x2");
0057   const double de_y1 = ps_.getUntrackedParameter<double>("de_y1");
0058   const double de_y2 = ps_.getUntrackedParameter<double>("de_y2");
0059   const double de_rho1 = ps_.getUntrackedParameter<double>("de_rho1");
0060   const double de_rho2 = ps_.getUntrackedParameter<double>("de_rho2");
0061 
0062   FileInPath inputFileInPath(ps_.getUntrackedParameter<string>("inputFile"));
0063   const string inputFile = inputFileInPath.fullPath();
0064   const string outputFile = ps_.getUntrackedParameter<string>("outputFile");
0065 
0066   // validate config parameters
0067   if (z1 == z2)
0068     throw cms::Exception("PPS") << "z1 equals z2";
0069 
0070   // calculate slopes and intercepts
0071   const double a_x = (de_x2 - de_x1) / (z2 - z1), b_x = de_x1 - a_x * z1;
0072   const double a_y = (de_y2 - de_y1) / (z2 - z1), b_y = de_y1 - a_y * z1;
0073   const double a_rho = (de_rho2 - de_rho1) / (z2 - z1), b_rho = de_rho1 - a_rho * z1;
0074 
0075   // get geometry
0076   const auto &geometry = es.getData(tokenRealGeometry_);
0077 
0078   // get input alignments
0079   CTPPSRPAlignmentCorrectionsDataSequence inputSequence = CTPPSRPAlignmentCorrectionsMethods::loadFromXML(inputFile);
0080   const auto &input = inputSequence.begin()->second;
0081 
0082   // modify the singular modes
0083   CTPPSRPAlignmentCorrectionsData output = input;
0084 
0085   for (auto &it : input.getSensorMap()) {
0086     const auto &sensorId = it.first;
0087 
0088     const auto &c = geometry.sensorTranslation(sensorId);
0089 
0090     // pixels cannot be described by one single value of z, but no better approxiamtion can be made
0091     const double z = c.z();
0092 
0093     double de_ShX = a_x * z + b_x;
0094     double de_ShY = a_y * z + b_y;
0095     const double de_RotZ = a_rho * z + b_rho;
0096 
0097     // add the effect of global rotation (about origin, not sensor centre)
0098     de_ShX -= +de_RotZ * (c.y() + de_ShY);
0099     de_ShY -= -de_RotZ * (c.x() + de_ShX);
0100 
0101     CTPPSRPAlignmentCorrectionData d = it.second;
0102     d.setShX(d.getShX() + de_ShX);
0103     d.setShY(d.getShY() + de_ShY);
0104     d.setRotZ(d.getRotZ() + de_RotZ);
0105 
0106     output.setSensorCorrection(sensorId, d);
0107   }
0108 
0109   // build list of RPs
0110   vector<unsigned int> rps;
0111   unsigned int last_rp = 123456;
0112   for (auto &it : input.getSensorMap()) {
0113     CTPPSDetId senId(it.first);
0114     unsigned int rpDecId = senId.arm() * 100 + senId.station() * 10 + senId.rp();
0115 
0116     if (last_rp != rpDecId) {
0117       rps.push_back(rpDecId);
0118       last_rp = rpDecId;
0119     }
0120   }
0121 
0122   // build alignment geometry (needed for the factorisation below)
0123   AlignmentGeometry alignmentGeometry;
0124   vector<unsigned int> excludePlanes;
0125   AlignmentTask::buildGeometry(rps, excludePlanes, &geometry, 0., alignmentGeometry);
0126 
0127   // factorise output
0128   CTPPSRPAlignmentCorrectionsData outputExpanded;
0129   CTPPSRPAlignmentCorrectionsData outputFactored;
0130 
0131   const bool equalWeights = false;
0132   factorRPFromSensorCorrections(output, outputExpanded, outputFactored, alignmentGeometry, equalWeights, 1);
0133 
0134   // save output
0135   CTPPSRPAlignmentCorrectionsMethods::writeToXML(outputFactored, outputFile, false, false, true, true, true, true);
0136 }
0137 
0138 //----------------------------------------------------------------------------------------------------
0139 
0140 DEFINE_FWK_MODULE(PPSModifySingularModes);