Back to home page

Project CMSSW displayed by LXR

 
 

    


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