Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:39

0001 // -*- C++ -*-
0002 //
0003 // Package:    MuonGeometrySVGTemplate
0004 // Class:      MuonGeometrySVGTemplate
0005 //
0006 /**\class MuonGeometrySVGTemplate MuonGeometrySVGTemplate.cc Alignment/MuonAlignment/plugins/MuonGeometrySVGTemplate.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jim Pivarski
0015 //         Created:  Wed Jul 14 18:31:18 CDT 2010
0016 //
0017 //
0018 
0019 // system include files
0020 #include <fstream>
0021 
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/ESHandle.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/ParameterSet/interface/FileInPath.h"
0030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0031 
0032 #include "Alignment/MuonAlignment/interface/MuonAlignment.h"
0033 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputMethod.h"
0034 #include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
0035 #include "Alignment/CommonAlignment/interface/Alignable.h"
0036 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0037 #include "DataFormats/DetId/interface/DetId.h"
0038 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0039 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0040 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0041 
0042 //
0043 // class decleration
0044 //
0045 
0046 class MuonGeometrySVGTemplate : public edm::one::EDAnalyzer<> {
0047 public:
0048   explicit MuonGeometrySVGTemplate(const edm::ParameterSet &iConfig);
0049   ~MuonGeometrySVGTemplate() override;
0050 
0051 private:
0052   void analyze(const edm::Event &, const edm::EventSetup &iConfig) override;
0053 
0054   std::string m_wheelTemplateName;
0055   //       std::string m_disk1TemplateName;
0056   //       std::string m_disk23TemplateName;
0057   //       std::string m_diskp4TemplateName;
0058   //       std::string m_diskm4TemplateName;
0059 };
0060 
0061 //
0062 // constructors and destructor
0063 //
0064 
0065 MuonGeometrySVGTemplate::MuonGeometrySVGTemplate(const edm::ParameterSet &iConfig)
0066     : m_wheelTemplateName(iConfig.getParameter<std::string>("wheelTemplateName")) {}
0067 
0068 MuonGeometrySVGTemplate::~MuonGeometrySVGTemplate() = default;
0069 
0070 // ------------ method called to for each event  ------------
0071 void MuonGeometrySVGTemplate::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0072   // loads ideal geometry
0073   MuonAlignmentInputMethod inputMethod;
0074   MuonAlignment muonAlignment(iSetup, inputMethod);
0075   AlignableNavigator *alignableNavigator = muonAlignment.getAlignableNavigator();
0076 
0077   edm::FileInPath fip_BEGINNING("Alignment/MuonAlignment/data/wheel_template.svg_BEGINNING");
0078   std::ifstream in_BEGINNING(fip_BEGINNING.fullPath().c_str());
0079   edm::FileInPath fip_END("Alignment/MuonAlignment/data/wheel_template.svg_END");
0080   std::ifstream in_END(fip_END.fullPath().c_str());
0081 
0082   const double height = 45.;  // assume all chambers are 45 cm tall (local z)
0083   std::ofstream out(m_wheelTemplateName.c_str());
0084 
0085   while (in_BEGINNING.good()) {
0086     char c = (char)in_BEGINNING.get();
0087     if (in_BEGINNING.good())
0088       out << c;
0089   }
0090 
0091   for (int station = 1; station <= 4; station++) {
0092     int numSectors = 12;
0093     if (station == 4)
0094       numSectors = 14;
0095     for (int sector = 1; sector <= numSectors; sector++) {
0096       DTChamberId id(-2, station, sector);  // wheel -2 has a +1 signConvention for x
0097       Alignable *chamber = &*(alignableNavigator->alignableFromDetId(id));
0098 
0099       // different stations, sectors have different widths (*very* fortunate that Alignment software provides this)
0100       double width = chamber->surface().width();
0101 
0102       // lower-left corner of chamber in the chamber's coordinates
0103       double x = -width / 2.;
0104       double y = -height / 2.;
0105 
0106       // phi position of chamber
0107       align::GlobalVector direction = chamber->surface().toGlobal(LocalVector(1., 0., 0.));
0108       double phi = atan2(direction.y(), direction.x());
0109 
0110       // we'll apply a translation to put the chamber in its place
0111       double tx = chamber->surface().position().x();
0112       double ty = chamber->surface().position().y();
0113 
0114       out << "    <rect id=\"MB_" << station << "_" << sector << "\" x=\"" << x << "\" y=\"" << y << "\" width=\""
0115           << width << "\" height=\"" << height << "\" transform=\"translate(" << tx << ", " << ty << ") rotate("
0116           << phi * 180. / M_PI
0117           << ")\" style=\"fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:5.0;stroke-dasharray:1, "
0118              "1;stroke-dashoffset:0\" />"
0119           << std::endl;
0120     }
0121   }
0122 
0123   while (in_END.good()) {
0124     char c = (char)in_END.get();
0125     if (in_END.good())
0126       out << c;
0127   }
0128 }
0129 
0130 //define this as a plug-in
0131 DEFINE_FWK_MODULE(MuonGeometrySVGTemplate);