Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:28

0001 #include "Geometry/EcalAlgo/interface/WriteESAlignments.h"
0002 
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0008 
0009 #include "CondCore/CondDB/interface/Serialization.h"
0010 
0011 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
0012 
0013 typedef WriteESAlignments WEA;
0014 
0015 const unsigned int WEA::k_nA = EcalPreshowerGeometry::numberOfAlignments();
0016 
0017 WEA::WriteESAlignments(edm::ConsumesCollector&& cc)
0018     : geometryToken_{cc.esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{})},
0019       alignmentToken_{cc.esConsumes<Alignments, ESAlignmentRcd>(edm::ESInputTag{})} {}
0020 
0021 void WEA::writeAlignments(const edm::EventSetup& eventSetup,
0022                           const WEA::DVec& alphaVec,
0023                           const WEA::DVec& betaVec,
0024                           const WEA::DVec& gammaVec,
0025                           const WEA::DVec& xtranslVec,
0026                           const WEA::DVec& ytranslVec,
0027                           const WEA::DVec& ztranslVec) {
0028   assert(alphaVec.size() == k_nA);
0029   assert(betaVec.size() == k_nA);
0030   assert(gammaVec.size() == k_nA);
0031   assert(xtranslVec.size() == k_nA);
0032   assert(ytranslVec.size() == k_nA);
0033   assert(ztranslVec.size() == k_nA);
0034 
0035   Alignments ali;
0036   AliVec& vali(ali.m_align);
0037 
0038   convert(eventSetup, alphaVec, betaVec, gammaVec, xtranslVec, ytranslVec, ztranslVec, vali);
0039 
0040   write(ali);
0041 }
0042 
0043 void WEA::write(const Alignments& ali) {
0044   edm::LogVerbatim("WriteESAlignments") << "Uploading ES alignments to the database";
0045 
0046   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0047 
0048   if (!poolDbService.isAvailable())
0049     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0050 
0051   poolDbService->writeOneIOV<Alignments>(ali, poolDbService->currentTime(), "ESAlignmentRcd");
0052 }
0053 
0054 void WEA::convert(const edm::EventSetup& eS,
0055                   const WEA::DVec& a,
0056                   const WEA::DVec& b,
0057                   const WEA::DVec& g,
0058                   const WEA::DVec& x,
0059                   const WEA::DVec& y,
0060                   const WEA::DVec& z,
0061                   WEA::AliVec& va) {
0062   const auto& pG = eS.getData(geometryToken_);
0063 
0064   const CaloSubdetectorGeometry* geom(pG.getSubdetectorGeometry(DetId::Ecal, EcalPreshower));
0065 
0066   const auto& pA = eS.getData(alignmentToken_);
0067   const AliVec& vaPrev(pA.m_align);
0068 
0069   va.reserve(k_nA);
0070   for (unsigned int i(0); i != k_nA; ++i) {
0071     // ordering of i is: left, right, left, right,...
0072     // starting at ES- rear, then ES- front,
0073     // then ES+ front, then ES+ rear
0074 
0075     const ESDetId id(EcalPreshowerGeometry::detIdFromLocalAlignmentIndex(i));
0076 
0077     double zPlanePrev(geom->getGeometry(id)->getPosition().z());
0078     const double zAlignPrev(vaPrev[i].translation().z());
0079     const Trl q_I(0, 0, zPlanePrev - zAlignPrev);
0080     const Trl& s_p(vaPrev[i].translation());
0081     const Trl t_n(x[i], y[i], z[i]);
0082     const Rot G_p(vaPrev[i].rotation());
0083     const double gamma(g[i]);
0084     const double alpha(a[i]);
0085     const double beta(b[i]);
0086 
0087     const Rot L_n(  // New rotation in local frame!
0088         Rot(Rot(Rot().rotateZ(-gamma)).rotateX(-alpha)).rotateY(-beta));
0089 
0090     const Rot InvL_n(L_n.inverse());
0091 
0092     const Rot G_n(InvL_n * G_p);
0093 
0094     const Trl s_n(t_n + s_p + q_I - InvL_n * q_I);
0095 
0096     edm::LogVerbatim("WriteESAlignments") << "For i = " << i << ", q_I=" << q_I;
0097     edm::LogVerbatim("WriteESAlignments") << "For i = " << i << ", s_p=" << s_p;
0098     edm::LogVerbatim("WriteESAlignments") << "For i = " << i << ", alpha = " << 1000. * alpha << " mr";
0099     edm::LogVerbatim("WriteESAlignments") << "For i = " << i << ", beta  = " << 1000. * beta << " mr";
0100     edm::LogVerbatim("WriteESAlignments") << "For i = " << i << ", gamma = " << 1000. * gamma << " mr";
0101     edm::LogVerbatim("WriteESAlignments")
0102         << " For i = " << i << ", L_n = " << L_n << "   Euler angles=" << InvL_n.eulerAngles() << "\n";
0103     edm::LogVerbatim("WriteESAlignments") << "For i = " << i << ", t_n=" << t_n;
0104     edm::LogVerbatim("WriteESAlignments")
0105         << "For i = " << i << ", G_p=" << G_p << "   Euler angles=" << G_p.eulerAngles() << "\n";
0106     edm::LogVerbatim("WriteESAlignments")
0107         << " For i = " << i << ", InvL_n = " << InvL_n << "   Euler angles=" << InvL_n.eulerAngles() << "\n";
0108     edm::LogVerbatim("WriteESAlignments")
0109         << " For i =" << i << ", G_n = " << G_n << "    Euler angles=" << G_n.eulerAngles() << "\n";
0110     edm::LogVerbatim("WriteESAlignments") << " For i =" << i << ", s_n = " << s_n;
0111     edm::LogVerbatim("WriteESAlignments") << "++++++++++++++++++++++++++\n\n";
0112 
0113     va.emplace_back(AlignTransform(s_n, G_n, id));
0114   }
0115 }