Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-22 06:26:43

0001 // -*- C++ -*-
0002 //
0003 // Package:    TestTrackerHierarchy
0004 // Class:      TestTrackerHierarchy
0005 //
0006 //
0007 // Description: Module to test the Alignment software
0008 //
0009 //
0010 // Original Author:  Frederic Ronga
0011 //         Created:  March 16, 2006
0012 //         $Id: TestTrackerHierarchy.cpp,v 1.6 2012/06/30 08:59:35 eulisse Exp $
0013 
0014 // system include files
0015 #include <sstream>
0016 #include <iomanip>
0017 #include <memory>
0018 
0019 // user include files
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/ESHandle.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 
0026 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0027 
0028 #include "CondFormats/Alignment/interface/AlignTransform.h"
0029 #include "CondFormats/Alignment/interface/Alignments.h"
0030 
0031 #include "Alignment/TrackerAlignment/interface/AlignableTracker.h"
0032 #include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
0033 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
0034 
0035 static const int kLEAD_WIDTH = 40;  // First field width
0036 
0037 //
0038 //
0039 // class declaration
0040 //
0041 
0042 class TestTrackerHierarchy : public edm::one::EDAnalyzer<> {
0043 public:
0044   explicit TestTrackerHierarchy(const edm::ParameterSet& pSet)
0045       : tTopoToken_(esConsumes()),
0046         tkGeomToken_(esConsumes()),
0047         aliToken_(esConsumes()),
0048         aliErrToken_(esConsumes()),
0049         dumpAlignments_(pSet.getUntrackedParameter<bool>("dumpAlignments")) {}
0050 
0051   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0052 
0053 private:
0054   // ----------member data ---------------------------
0055   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0056   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0057   const edm::ESGetToken<Alignments, TrackerAlignmentRcd> aliToken_;
0058   const edm::ESGetToken<AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd> aliErrToken_;
0059 
0060   void dumpAlignable(const Alignable*, unsigned int, unsigned int);
0061   void printInfo(const Alignable*, unsigned int);
0062   void dumpAlignments(const edm::EventSetup& setup, AlignableTracker* aliTracker) const;
0063 
0064   std::string leaders_, blank_, filled_;
0065 
0066   const bool dumpAlignments_;
0067   std::unique_ptr<AlignableTracker> alignableTracker_;
0068 };
0069 
0070 void TestTrackerHierarchy::analyze(const edm::Event&, const edm::EventSetup& setup) {
0071   //Retrieve tracker topology from geometry
0072   const TrackerTopology* const tTopo = &setup.getData(tTopoToken_);
0073   edm::LogInfo("TrackerHierarchy") << "Starting!";
0074 
0075   const TrackerGeometry* trackerGeometry = &setup.getData(tkGeomToken_);
0076   alignableTracker_ = std::make_unique<AlignableTracker>(&(*trackerGeometry), tTopo);
0077 
0078   leaders_ = "";
0079   blank_ = "   ";   // These two...
0080   filled_ = "|  ";  // ... must have the same length
0081 
0082   // Now dump mother of each alignable
0083   //const Alignable* alignable = (&(*theAlignableTracker))->pixelHalfBarrels()[0];
0084   this->dumpAlignable(alignableTracker_.get(), 1, 1);
0085 
0086   edm::LogInfo("TrackerHierarchy") << "Done!";
0087 
0088   if (dumpAlignments_) {
0089     this->dumpAlignments(setup, alignableTracker_.get());
0090   }
0091 }
0092 
0093 //__________________________________________________________________________________________________
0094 // Recursive loop on alignable hierarchy
0095 void TestTrackerHierarchy::dumpAlignable(const Alignable* alignable, unsigned int idau, unsigned int ndau) {
0096   printInfo(alignable, idau);
0097 
0098   if (ndau != idau)
0099     leaders_ += filled_;
0100   else
0101     leaders_ += blank_;
0102 
0103   const align::Alignables& comps = alignable->components();
0104   if (unsigned int ndau = comps.size()) {
0105     unsigned int idau = 0;
0106     for (align::Alignables::const_iterator iter = comps.begin(); iter != comps.end(); ++iter)
0107       dumpAlignable(*iter, ++idau, ndau);
0108   }
0109 
0110   leaders_ = leaders_.substr(0, leaders_.length() - blank_.length());
0111 }
0112 
0113 //__________________________________________________________________________________________________
0114 // Do the actual printout
0115 void TestTrackerHierarchy::printInfo(const Alignable* alignable, unsigned int idau) {
0116   int width = kLEAD_WIDTH - leaders_.length();
0117 
0118   std::ostringstream name, pos, rot;
0119 
0120   name << alignableTracker_->objectIdProvider().idToString(alignable->alignableObjectId()) << idau;
0121 
0122   // Position
0123   pos.setf(std::ios::fixed);
0124   pos << "(" << std::right << std::setw(8) << std::setprecision(4) << alignable->globalPosition().x() << ","
0125       << std::setw(8) << std::setprecision(4) << alignable->globalPosition().y() << "," << std::setw(8)
0126       << std::setprecision(4) << alignable->globalPosition().z() << ")";
0127 
0128   edm::LogVerbatim("DumpAlignable") << leaders_ << "+-> " << std::setw(width) << std::left << name.str() << " | "
0129                                     << std::setw(3) << std::left << alignable->components().size() << " | "
0130                                     << std::setw(11) << std::left << alignable->id() << " | " << pos.str();
0131 }
0132 
0133 //__________________________________________________________________________________________________
0134 void TestTrackerHierarchy::dumpAlignments(const edm::EventSetup& setup, AlignableTracker* aliTracker) const {
0135   const Alignments* alignments = &setup.getData(aliToken_);
0136   if (alignments->empty()) {
0137     edm::LogWarning("TrackerAlignment") << "@SUB=dumpAlignments"
0138                                         << "No TrackerAlignmentRcd.";
0139   } else {
0140     AlignableNavigator navi(aliTracker);
0141     edm::LogInfo("TrackerAlignment") << "@SUB=dumpAlignments"
0142                                      << "Start dumping alignments.";
0143     unsigned int nProblems = 0;
0144     for (std::vector<AlignTransform>::const_iterator iAlign = alignments->m_align.begin(),
0145                                                      iEnd = alignments->m_align.end();
0146          iAlign != iEnd;
0147          ++iAlign) {
0148       const align::ID id = (*iAlign).rawId();
0149       const AlignTransform::Translation pos((*iAlign).translation());
0150       edm::LogVerbatim("DumpAlignable") << (*iAlign).rawId() << "  |  " << pos;
0151 
0152       AlignableDetOrUnitPtr aliPtr = navi.alignableFromDetId(id);
0153       if (!aliPtr.isNull()) {
0154         const Alignable::PositionType& aliPos = aliPtr->globalPosition();
0155         double dR = aliPos.perp() - pos.perp();
0156         double dRphi = (aliPos.phi() - pos.phi()) * pos.perp();
0157         double dZ = aliPos.z() - pos.z();
0158         if (dR * dR + dRphi * dRphi + dZ * dZ) {
0159           ++nProblems;
0160           edm::LogWarning("Alignment") << "@SUB=analyze"
0161                                        << "Delta r,rphi,z: " << dR << " " << dRphi << " " << dZ
0162                                        << "\nPos r,phi,z: " << pos.perp() << " " << pos.phi() << " " << pos.z();
0163         }
0164       } else {
0165         ++nProblems;
0166         edm::LogWarning("Alignment") << "@SUB=dumpAlignments"
0167                                      << "No Alignable for Id " << id;
0168       }
0169     }  // ending loop
0170 
0171     if (nProblems) {
0172       edm::LogWarning("TrackerAlignment") << "@SUB=dumpAlignments"
0173                                           << "Ending: " << nProblems << " Alignments with problems.";
0174     } else {
0175       edm::LogInfo("TrackerAlignment") << "@SUB=dumpAlignments"
0176                                        << "Ending without problem.";
0177     }
0178   }
0179 }
0180 
0181 //define this as a plug-in
0182 DEFINE_FWK_MODULE(TestTrackerHierarchy);