Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-24 02:13:02

0001 // -*- C++ -*-
0002 //
0003 // Package:    NavigationSchoolAnalyzer
0004 // Class:      NavigationSchoolAnalyzer
0005 //
0006 /**\class NavigationSchoolAnalyzer NavigationSchoolAnalyzer.cc RecoTracker/NavigationSchoolAnalyzer/src/NavigationSchoolAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jean-Roch Vlimant
0015 //         Created:  Fri Mar 16 13:19:20 CDT 2007
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "DataFormats/ForwardDetId/interface/BTLDetId.h"
0024 #include "DataFormats/ForwardDetId/interface/ETLDetId.h"
0025 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0026 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0027 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0028 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0035 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
0036 #include "TrackingTools/DetLayers/interface/DetLayer.h"
0037 #include "TrackingTools/DetLayers/interface/NavigationSchool.h"
0038 
0039 // class definition
0040 class NavigationSchoolAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0041 public:
0042   explicit NavigationSchoolAnalyzer(const edm::ParameterSet&);
0043   ~NavigationSchoolAnalyzer() override = default;
0044 
0045 private:
0046   virtual void beginRun(edm::Run const& run, const edm::EventSetup&) override;
0047   virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
0048   virtual void endRun(edm::Run const& run, const edm::EventSetup&) override{};
0049 
0050   const std::string theNavigationSchoolName_;
0051   const edm::ESGetToken<NavigationSchool, NavigationSchoolRecord> navSchoolToken_;
0052   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoTokenBR_;
0053   const edm::ESGetToken<NavigationSchool, NavigationSchoolRecord> navSchoolTokenBR_;
0054 
0055   const TrackerTopology* tTopo;
0056   void print(std::ostream& os, const DetLayer* dl);
0057   void print(std::ostream& os, const NavigationSchool::StateType& layers);
0058   void print(std::ostream& os, const NavigationSchool* nav);
0059   void printUsingGeom(std::ostream& os, const NavigationSchool& nav);
0060 };
0061 
0062 //navigation printouts
0063 void NavigationSchoolAnalyzer::print(std::ostream& os, const DetLayer* dl) {
0064   const std::vector<const GeomDet*>& bComponents = dl->basicComponents();
0065 
0066   if (bComponents.empty()) { /* t'es pas dans la merde */
0067     return;
0068   }
0069 
0070   const GeomDet* tag = bComponents.front();
0071   unsigned int LorW = 0;
0072   unsigned int side = 0;
0073 
0074   if (GeomDetEnumerators::isTracker(dl->subDetector())) {
0075     LorW = tTopo->layer(tag->geographicalId());
0076     side = tTopo->side(tag->geographicalId());
0077   } else if (dl->subDetector() == GeomDetEnumerators::TimingEndcap) {
0078     ETLDetId id(dl->basicComponents().front()->geographicalId().rawId());
0079     LorW = id.nDisc();
0080     //The MTD side returns 0 for the negative side and 1 for the positive side
0081     //In order to be comp
0082     side = id.mtdSide() + 1;
0083   } else {
0084     switch (dl->subDetector()) {
0085       case GeomDetEnumerators::DT:
0086         LorW = DTChamberId(tag->geographicalId().rawId()).station();
0087         break;
0088       case GeomDetEnumerators::RPCEndcap:
0089         side = (unsigned int)((RPCDetId(tag->geographicalId().rawId()).region() / 2. + 1) * 2.);
0090         [[fallthrough]];
0091       case GeomDetEnumerators::RPCBarrel:
0092         LorW = RPCDetId(tag->geographicalId().rawId()).station();
0093         break;
0094 
0095       case GeomDetEnumerators::CSC:
0096         LorW = CSCDetId(tag->geographicalId().rawId()).layer();
0097         side = CSCDetId(tag->geographicalId().rawId()).endcap();
0098         break;
0099       case GeomDetEnumerators::invalidDet:  // make gcc happy
0100         // edm::LogError("InvalidDet") << "At " << __FILE__ << ", line " << __LINE__ << "\n";
0101         break;
0102       default:
0103         break;
0104     }
0105   }
0106 
0107   switch (dl->location()) {
0108     case GeomDetEnumerators::barrel:
0109       os << "barrel subDetector: " << dl->subDetector() << "\n"
0110          << "layer: " << LorW << "\n";
0111       break;
0112     case GeomDetEnumerators::endcap:
0113       os << "endcap subDetector: " << dl->subDetector() << "\n"
0114          << "wheel: " << LorW << "\n"
0115          << "side: " << ((side == 1) ? "Minus" : "Plus") << "\n";
0116       break;
0117     case GeomDetEnumerators::invalidLoc:  // make gcc happy
0118       // edm::LogError("InvalidLoc") << "At " << __FILE__ << ", line " << __LINE__ << "\n";
0119       break;
0120   }
0121   os << (void*)dl << "\n";
0122   return;
0123 }
0124 
0125 void NavigationSchoolAnalyzer::print(std::ostream& os, const NavigationSchool::StateType& layers) {
0126   for (NavigationSchool::StateType::const_iterator l = layers.begin(); l != layers.end(); ++l) {
0127     std::vector<const DetLayer*> displayThose;
0128 
0129     os << "####################\n"
0130        << "Layer: \n";
0131     print(os, (*l)->detLayer());
0132 
0133     displayThose = (*l)->nextLayers(insideOut);
0134     if (displayThose.empty()) {
0135       os << "*** no INsideOUT connection ***\n";
0136     } else {
0137       os << "*** INsideOUT CONNECTED TO ***\n";
0138       for (std::vector<const DetLayer*>::iterator nl = displayThose.begin(); nl != displayThose.end(); ++nl) {
0139         print(os, *nl);
0140         os << "-----------------\n";
0141       }
0142     }
0143 
0144     displayThose = (*l)->nextLayers(outsideIn);
0145     if (displayThose.empty()) {
0146       os << "*** no OUTsideIN connection ***\n";
0147     } else {
0148       os << "*** OUTsideIN CONNECTED TO ***\n";
0149       for (std::vector<const DetLayer*>::iterator nl = displayThose.begin(); nl != displayThose.end(); ++nl) {
0150         print(os, *nl);
0151         os << "-----------------\n";
0152       }
0153     }
0154   }
0155   os << "\n";
0156   return;
0157 }
0158 
0159 void NavigationSchoolAnalyzer::print(std::ostream& os, const NavigationSchool* nav) {
0160   NavigationSchool::StateType layer = const_cast<NavigationSchool*>(nav)->navigableLayers();
0161   print(os, layer);
0162   return;
0163 }
0164 
0165 void NavigationSchoolAnalyzer::printUsingGeom(std::ostream& os, const NavigationSchool& nav) {
0166   auto dls = nav.allLayersInSystem();  // ok let's' keep it for debug
0167   for (auto dl : dls) {
0168     os << "####################\n"
0169        << "Layer: \n";
0170     print(os, dl);
0171 
0172     auto displayThose = nav.nextLayers(*dl, insideOut);
0173     if (displayThose.empty()) {
0174       os << "*** no INsideOUT connection ***\n";
0175     } else {
0176       os << "*** INsideOUT CONNECTED TO ***\n";
0177       for (std::vector<const DetLayer*>::iterator nl = displayThose.begin(); nl != displayThose.end(); ++nl) {
0178         print(os, *nl);
0179         os << "-----------------\n";
0180       }
0181     }
0182 
0183     displayThose = nav.nextLayers(*dl, outsideIn);
0184     if (displayThose.empty()) {
0185       os << "*** no OUTsideIN connection ***\n";
0186     } else {
0187       os << "*** OUTsideIN CONNECTED TO ***\n";
0188       for (std::vector<const DetLayer*>::iterator nl = displayThose.begin(); nl != displayThose.end(); ++nl) {
0189         print(os, *nl);
0190         os << "-----------------\n";
0191       }
0192     }
0193   }
0194   os << "\n";
0195 }
0196 
0197 void printOldStyle(std::ostream& os, const NavigationSchool& nav) {
0198   /*
0199   NavigationSetter setter(nav);
0200 
0201   auto dls = nav.allLayersInSystem(); // ok let's' keep it for debug
0202   for ( auto dl : dls) {
0203      os<<"####################\n"    
0204     << "Layer: \n"
0205        << (dl);
0206       
0207      auto displayThose=  dl->nextLayers(insideOut);
0208       if (displayThose.empty())
0209         {os<<"*** no INsideOUT connection ***\n";}
0210       else{
0211     os<<"*** INsideOUT CONNECTED TO ***\n";
0212     for(std::vector<const DetLayer*>::iterator nl =displayThose.begin();nl!=displayThose.end();++nl)
0213       {os<<(*nl)<<"-----------------\n";}}
0214 
0215       displayThose = dl->nextLayers(outsideIn);
0216       if (displayThose.empty())
0217     {os<<"*** no OUTsideIN connection ***\n";}
0218       else{
0219     os<<"*** OUTsideIN CONNECTED TO ***\n";
0220     for(std::vector<const DetLayer*>::iterator nl =displayThose.begin();nl!=displayThose.end();++nl)
0221       {os<<(*nl)<<"-----------------\n";}}
0222   }
0223   os<<"\n";
0224 */
0225 }
0226 
0227 // the analyzer itself
0228 NavigationSchoolAnalyzer::NavigationSchoolAnalyzer(const edm::ParameterSet& iConfig)
0229     : theNavigationSchoolName_(iConfig.getParameter<std::string>("navigationSchoolName")),
0230       navSchoolToken_(esConsumes(edm::ESInputTag("", theNavigationSchoolName_))),
0231       tTopoTokenBR_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", theNavigationSchoolName_))),
0232       navSchoolTokenBR_(esConsumes<edm::Transition::BeginRun>()) {}
0233 
0234 #include <sstream>
0235 #include <fstream>
0236 
0237 void NavigationSchoolAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0238   std::ostringstream byNav;
0239   std::ostringstream byGeom;
0240   std::ostringstream oldStyle;
0241 
0242   std::ofstream ByNavFile(theNavigationSchoolName_ + "_ByNav.log");
0243   std::ofstream ByGeomFile(theNavigationSchoolName_ + "_ByGeom.log");
0244   std::ofstream oldStyleFile(theNavigationSchoolName_ + "_oldStyle.log");
0245 
0246   //get the navigation school
0247   const NavigationSchool* nav = &iSetup.getData(navSchoolToken_);
0248   print(byNav, nav);
0249   printUsingGeom(byGeom, *nav);
0250   printOldStyle(oldStyle, *nav);
0251 
0252   ByNavFile << byNav.str() << std::endl;
0253   ByGeomFile << byGeom.str() << std::endl;
0254   oldStyleFile << oldStyle.str() << std::endl;
0255 
0256   if (oldStyle.str() != byGeom.str())
0257     edm::LogPrint("NavigationSchoolAnalyzer")
0258         << "Error: Navigation by Geom is not consistent with old Style Navigation in " << theNavigationSchoolName_
0259         << "\n";
0260 
0261   // NavigationSetter setter(*nav);
0262   edm::LogPrint("NavigationSchoolAnalyzer") << "NavigationSchoolAnalyzer "
0263                                             << "hello at event";
0264   edm::LogPrint("NavigationSchoolAnalyzer") << "NavigationSchoolAnalyzer "
0265                                             << "NavigationSchool display of: " << theNavigationSchoolName_ << "\n"
0266                                             << byNav.str();
0267 
0268   edm::LogPrint("NavigationSchoolAnalyzer") << "\n\nNavigationSchoolAnalyzer "
0269                                             << "NavigationSchool display using Geometry";
0270   edm::LogPrint("NavigationSchoolAnalyzer") << byGeom.str();
0271 }
0272 
0273 void NavigationSchoolAnalyzer::beginRun(edm::Run const& run, const edm::EventSetup& iSetup) {
0274   tTopo = &iSetup.getData(tTopoTokenBR_);
0275 
0276   //get the navigation school
0277   const NavigationSchool* nav = &iSetup.getData(navSchoolTokenBR_);
0278   // NavigationSetter setter(*nav.product());
0279   edm::LogInfo("NavigationSchoolAnalyzer") << "NavigationSchool display of: " << theNavigationSchoolName_ << "\n";
0280   print(std::cout, nav);
0281 }
0282 
0283 //define this as a plug-in
0284 DEFINE_FWK_MODULE(NavigationSchoolAnalyzer);