Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:19

0001 /** Derived from DTSectorAnalyzer by Nicola Amapane
0002  *
0003  *  \author M. Maggi - INFN Bari
0004  */
0005 
0006 #include <memory>
0007 #include <fstream>
0008 #include <FWCore/Framework/interface/Frameworkfwd.h>
0009 
0010 #include <FWCore/Framework/interface/one/EDAnalyzer.h>
0011 #include <FWCore/Framework/interface/Event.h>
0012 #include <FWCore/Framework/interface/EventSetup.h>
0013 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0014 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0015 
0016 #include <Geometry/RPCGeometry/interface/RPCGeometry.h>
0017 #include <Geometry/RPCGeometry/interface/RPCGeomServ.h>
0018 #include <Geometry/Records/interface/MuonGeometryRecord.h>
0019 #include <Geometry/CommonTopologies/interface/RectangularStripTopology.h>
0020 #include <Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h>
0021 
0022 #include <string>
0023 #include <cmath>
0024 #include <vector>
0025 #include <iomanip>
0026 #include <set>
0027 
0028 class RPCSectorAnalyzer : public edm::one::EDAnalyzer<> {
0029 public:
0030   RPCSectorAnalyzer(const edm::ParameterSet& pset);
0031 
0032   ~RPCSectorAnalyzer() override;
0033 
0034   void beginJob() override {}
0035   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0036   void endJob() override {}
0037 
0038   const std::string& myName() { return myName_; }
0039 
0040 private:
0041   const edm::ESGetToken<RPCGeometry, MuonGeometryRecord> tokRPC_;
0042   const int dashedLineWidth_;
0043   const std::string dashedLine_;
0044   const std::string myName_;
0045   std::ofstream ofos;
0046 };
0047 
0048 RPCSectorAnalyzer::RPCSectorAnalyzer(const edm::ParameterSet& /*iConfig*/)
0049     : tokRPC_{esConsumes<RPCGeometry, MuonGeometryRecord>(edm::ESInputTag{})},
0050       dashedLineWidth_(104),
0051       dashedLine_(std::string(dashedLineWidth_, '-')),
0052       myName_("RPCSectorAnalyzer") {
0053   ofos.open("MytestOutput.out");
0054   edm::LogVerbatim("RPCGeometry") << "======================== Opening output file";
0055 }
0056 
0057 RPCSectorAnalyzer::~RPCSectorAnalyzer() {
0058   ofos.close();
0059   edm::LogVerbatim("RPCGeometry") << "======================== Closing output file";
0060 }
0061 
0062 void RPCSectorAnalyzer::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0063   const RPCGeometry* pDD = &iSetup.getData(tokRPC_);
0064 
0065   ofos << myName() << ": Analyzer..." << std::endl;
0066   ofos << "start " << dashedLine_ << std::endl;
0067 
0068   ofos << " Geometry node for RPCGeom is  " << &(*pDD) << std::endl;
0069   ofos << " I have " << pDD->detTypes().size() << " detTypes" << std::endl;
0070   ofos << " I have " << pDD->detUnits().size() << " detUnits" << std::endl;
0071   ofos << " I have " << pDD->dets().size() << " dets" << std::endl;
0072   ofos << " I have " << pDD->rolls().size() << " rolls" << std::endl;
0073   ofos << " I have " << pDD->chambers().size() << " chambers" << std::endl;
0074 
0075   ofos << myName() << ": Begin iteration over geometry..." << std::endl;
0076   ofos << "iter " << dashedLine_ << std::endl;
0077 
0078   const double dPi = 3.14159265358;
0079   const double radToDeg = 180. / dPi;  //@@ Where to get pi from?
0080 
0081   for (auto it : pDD->dets()) {
0082     //      //----------------------- RPCCHAMBER TEST -------------------------------------------------------
0083 
0084     if (dynamic_cast<const RPCChamber*>(it) != nullptr) {
0085       const RPCChamber* ch = dynamic_cast<const RPCChamber*>(it);
0086 
0087       //RPCDetId detId=ch->id();
0088 
0089       std::vector<const RPCRoll*> rolls = (ch->rolls());
0090       for (auto& roll : rolls) {
0091         if (roll->id().region() == -1 && roll->id().station() > 0)  // &&
0092         // (*r)->id().sector() == 8)
0093         {
0094           ofos << "RPCDetId = " << roll->id() << std::endl;
0095           RPCGeomServ geosvc(roll->id());
0096           LocalPoint centre(0., 0., 0.);
0097           GlobalPoint gc = roll->toGlobal(centre);
0098           double phifirs = double(roll->toGlobal(roll->centreOfStrip(1)).phi()) * radToDeg;
0099           if (phifirs < 0)
0100             phifirs = 360. + phifirs;
0101           double philast = double(roll->toGlobal(roll->centreOfStrip(roll->nstrips())).phi()) * radToDeg;
0102           if (philast < 0)
0103             philast = 360. + philast;
0104           double deltaphi = philast - phifirs;
0105           if (std::abs(deltaphi) > 180.) {
0106             if (deltaphi < 0) {
0107               deltaphi += 360.;
0108             } else if (deltaphi > 0) {
0109               deltaphi -= 360.;
0110             }
0111           }
0112 
0113           ofos << " Position " << gc << " phi=" << double(gc.phi()) * radToDeg << " strip 1 " << phifirs << " strip "
0114                << roll->nstrips() << " " << philast << std::endl;
0115           ofos << geosvc.name() << " "
0116                << "Anticlockwise ? ";
0117           if (geosvc.aclockwise()) {
0118             ofos << "yes ";
0119           } else {
0120             ofos << "no ";
0121           }
0122           if (deltaphi > 0. && geosvc.aclockwise()) {
0123             ofos << " OK ";
0124           } else if (deltaphi < 0. && !geosvc.aclockwise()) {
0125             ofos << " OK ";
0126           } else {
0127             ofos << " NOTOK ";
0128           }
0129           ofos << " /\\phi=" << deltaphi << std::endl;
0130         }
0131       }
0132     }
0133   }
0134   edm::LogVerbatim("RPCGeometry") << dashedLine_ << " end";
0135 }
0136 
0137 //define this as a plug-in
0138 #include <FWCore/Framework/interface/MakerMacros.h>
0139 DEFINE_FWK_MODULE(RPCSectorAnalyzer);