CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Alignment/MuonAlignment/plugins/MuonGeometrySVGTemplate.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuonGeometrySVGTemplate
00004 // Class:      MuonGeometrySVGTemplate
00005 //
00013 //
00014 // Original Author:  Jim Pivarski
00015 //         Created:  Wed Jul 14 18:31:18 CDT 2010
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <fstream>
00022 
00023 #include "FWCore/Framework/interface/Frameworkfwd.h"
00024 #include "FWCore/Framework/interface/EDAnalyzer.h"
00025 #include "FWCore/Framework/interface/EventSetup.h"
00026 #include "FWCore/Framework/interface/ESHandle.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 #include "FWCore/ParameterSet/interface/FileInPath.h"
00031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00032 
00033 #include "Alignment/MuonAlignment/interface/MuonAlignment.h"
00034 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputMethod.h"
00035 #include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
00036 #include "Alignment/CommonAlignment/interface/Alignable.h"
00037 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00038 #include "DataFormats/DetId/interface/DetId.h"
00039 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00040 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00041 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00042 
00043 //
00044 // class decleration
00045 //
00046 
00047 class MuonGeometrySVGTemplate : public edm::EDAnalyzer {
00048    public:
00049       explicit MuonGeometrySVGTemplate(const edm::ParameterSet &iConfig);
00050       ~MuonGeometrySVGTemplate();
00051 
00052    private:
00053       virtual void analyze(const edm::Event&, const edm::EventSetup &iConfig);
00054 
00055       std::string m_wheelTemplateName;
00056 //       std::string m_disk1TemplateName;
00057 //       std::string m_disk23TemplateName;
00058 //       std::string m_diskp4TemplateName;
00059 //       std::string m_diskm4TemplateName;
00060 };
00061 
00062 //
00063 // constants, enums and typedefs
00064 //
00065 
00066 //
00067 // static data member definitions
00068 //
00069 
00070 //
00071 // constructors and destructor
00072 //
00073 
00074 MuonGeometrySVGTemplate::MuonGeometrySVGTemplate(const edm::ParameterSet &iConfig)
00075    : m_wheelTemplateName(iConfig.getParameter<std::string>("wheelTemplateName"))
00076 {}
00077 
00078 MuonGeometrySVGTemplate::~MuonGeometrySVGTemplate() {}
00079 
00080 // ------------ method called to for each event  ------------
00081 void
00082 MuonGeometrySVGTemplate::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
00083    // loads ideal geometry
00084    MuonAlignmentInputMethod inputMethod;
00085    MuonAlignment muonAlignment(iSetup, inputMethod);
00086    AlignableNavigator *alignableNavigator = muonAlignment.getAlignableNavigator();
00087 
00088    edm::FileInPath fip_BEGINNING("Alignment/MuonAlignment/data/wheel_template.svg_BEGINNING");
00089    std::ifstream in_BEGINNING(fip_BEGINNING.fullPath().c_str());
00090    edm::FileInPath fip_END("Alignment/MuonAlignment/data/wheel_template.svg_END");
00091    std::ifstream in_END(fip_END.fullPath().c_str());
00092 
00093    const double height = 45.;  // assume all chambers are 45 cm tall (local z)
00094    std::ofstream out(m_wheelTemplateName.c_str());
00095 
00096    while (in_BEGINNING.good()) {
00097       char c = (char) in_BEGINNING.get();
00098       if (in_BEGINNING.good()) out << c;
00099    }
00100 
00101    for (int station = 1;  station <= 4;  station++) {
00102       int numSectors = 12;
00103       if (station == 4) numSectors = 14;
00104       for (int sector = 1;  sector <= numSectors;  sector++) {
00105          DTChamberId id(-2, station, sector);  // wheel -2 has a +1 signConvention for x
00106          Alignable *chamber = &*(alignableNavigator->alignableFromDetId(id));
00107 
00108          // different stations, sectors have different widths (*very* fortunate that Alignment software provides this)
00109          double width = chamber->surface().width();
00110          
00111          // lower-left corner of chamber in the chamber's coordinates
00112          double x = -width/2.;
00113          double y = -height/2.;
00114 
00115          // phi position of chamber
00116          align::GlobalVector direction = chamber->surface().toGlobal(LocalVector(1., 0., 0.));
00117          double phi = atan2(direction.y(), direction.x());
00118          
00119          // we'll apply a translation to put the chamber in its place
00120          double tx = chamber->surface().position().x();
00121          double ty = chamber->surface().position().y();
00122 
00123          out << "    <rect id=\"MB_" << station << "_" << sector << "\" x=\"" << x << "\" y=\"" << y << "\" width=\"" << width << "\" height=\"" << height << "\" transform=\"translate(" << tx << ", " << ty << ") rotate(" << phi*180./M_PI << ")\" style=\"fill:#e1e1e1;fill-opacity:1;stroke:#000000;stroke-width:5.0;stroke-dasharray:1, 1;stroke-dashoffset:0\" />" << std::endl;
00124       }
00125    }
00126 
00127    while (in_END.good()) {
00128       char c = (char) in_END.get();
00129       if (in_END.good()) out << c;
00130    }
00131 }
00132 
00133 //define this as a plug-in
00134 DEFINE_FWK_MODULE(MuonGeometrySVGTemplate);