Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:59:25

0001 // -*- C++ -*-
0002 //
0003 // Package:    RPCSeedGenerator
0004 // Class:      RPCSeedGenerator
0005 //
0006 /**\class RPCSeedGenerator RPCSeedGenerator.cc RecoMuon/MuonSeedGenerator/src/RPCSeedGenerator.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Haiyun Teng
0015 //         Created:  Wed Oct 29 17:24:36 CET 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 // user include files
0022 #include "FWCore/Framework/interface/Frameworkfwd.h"
0023 #include "FWCore/Framework/interface/stream/EDProducer.h"
0024 #include "FWCore/Framework/interface/Event.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 // special include files
0028 #include "FWCore/Utilities/interface/InputTag.h"
0029 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0030 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
0031 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
0032 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0033 #include <vector>
0034 // Using other classes
0035 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedPattern.h"
0036 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedFinder.h"
0037 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedrecHitFinder.h"
0038 #include "RecoMuon/MuonSeedGenerator/src/RPCCosmicSeedrecHitFinder.h"
0039 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedLayerFinder.h"
0040 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedOverlapper.h"
0041 // Geometry
0042 #include "TrackingTools/DetLayers/interface/DetLayer.h"
0043 #include "RecoMuon/MeasurementDet/interface/MuonDetLayerMeasurements.h"
0044 #include "RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h"
0045 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
0046 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0047 
0048 // Framework
0049 #include "FWCore/Framework/interface/EventSetup.h"
0050 #include "FWCore/Framework/interface/ESHandle.h"
0051 // Math
0052 #include <cmath>
0053 // C++
0054 #include <vector>
0055 
0056 //
0057 // constants, enums and typedefs
0058 //
0059 using namespace std;
0060 using namespace edm;
0061 
0062 typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer;
0063 typedef MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer;
0064 typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer;
0065 typedef MuonTransientTrackingRecHit::ConstMuonRecHitContainer ConstMuonRecHitContainer;
0066 typedef RPCSeedPattern::weightedTrajectorySeed weightedTrajectorySeed;
0067 
0068 #ifndef RPCLayerNumber
0069 #define RPCLayerNumber 12
0070 #endif
0071 
0072 #ifndef BarrelLayerNumber
0073 #define BarrelLayerNumber 6
0074 #endif
0075 
0076 #ifndef EachEndcapLayerNumber
0077 #define EachEndcapLayerNumber 3
0078 #endif
0079 
0080 //
0081 // class decleration
0082 //
0083 
0084 class RPCSeedFinder;
0085 
0086 class RPCSeedGenerator : public edm::stream::EDProducer<> {
0087 public:
0088   explicit RPCSeedGenerator(const edm::ParameterSet& iConfig);
0089   ~RPCSeedGenerator() override;
0090 
0091 private:
0092   void beginStream(edm::StreamID) override;
0093   void beginRun(const edm::Run&, const edm::EventSetup& iSetup) override;
0094   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0095   void endStream() override;
0096 
0097   // ----------member data ---------------------------
0098   RPCSeedFinder Finder;
0099   RPCSeedrecHitFinder recHitFinder;
0100   RPCCosmicSeedrecHitFinder CosmicrecHitFinder;
0101   RPCSeedLayerFinder LayerFinder;
0102   RPCSeedOverlapper Overlapper;
0103   std::vector<weightedTrajectorySeed> candidateweightedSeeds;
0104   std::vector<weightedTrajectorySeed> goodweightedSeeds;
0105   edm::InputTag theRPCRecHits;
0106   std::unique_ptr<MuonDetLayerMeasurements> muonMeasurements;
0107 
0108   const edm::ESGetToken<RPCGeometry, MuonGeometryRecord> brRPCGeometryToken;
0109   const edm::ESGetToken<MuonDetLayerGeometry, MuonRecoGeometryRecord> muonLayersToken;
0110   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> fieldToken;
0111   const edm::ESGetToken<RPCGeometry, MuonGeometryRecord> rpcGeometryToken;
0112 };
0113 
0114 //
0115 // constants, enums and typedefs
0116 //
0117 
0118 //
0119 // static data member definitions
0120 //
0121 
0122 //
0123 // constructors and destructor
0124 //
0125 RPCSeedGenerator::RPCSeedGenerator(const edm::ParameterSet& iConfig)
0126     : brRPCGeometryToken(esConsumes<edm::Transition::BeginRun>()),
0127       muonLayersToken(esConsumes()),
0128       fieldToken(esConsumes()),
0129       rpcGeometryToken(esConsumes()) {
0130   //register your products
0131   /* Examples
0132        produces<ExampleData2>();
0133 
0134     //if do put with a label
0135     produces<ExampleData2>("label");
0136     */
0137 
0138   // Now do what ever other initialization is needed
0139   // Configure other modules
0140   Finder.configure(iConfig);
0141   recHitFinder.configure(iConfig);
0142   CosmicrecHitFinder.configure(iConfig);
0143   LayerFinder.configure(iConfig);
0144   Overlapper.configure(iConfig);
0145   // Register the production
0146   produces<TrajectorySeedCollection>("goodSeeds");
0147   produces<TrajectorySeedCollection>("candidateSeeds");
0148   // Get event data Tag
0149   theRPCRecHits = iConfig.getParameter<edm::InputTag>("RPCRecHitsLabel");
0150 
0151   // Get RPC recHits by MuonDetLayerMeasurements, while CSC and DT is set to false and with empty InputTag
0152   edm::ConsumesCollector iC = consumesCollector();
0153 
0154   muonMeasurements = std::make_unique<MuonDetLayerMeasurements>(edm::InputTag(),
0155                                                                 edm::InputTag(),
0156                                                                 theRPCRecHits,
0157                                                                 edm::InputTag(),
0158                                                                 edm::InputTag(),
0159                                                                 iC,
0160                                                                 false,
0161                                                                 false,
0162                                                                 true,
0163                                                                 false,
0164                                                                 false);
0165 
0166   cout << endl << "[RPCSeedGenerator] --> Constructor called" << endl;
0167 }
0168 
0169 RPCSeedGenerator::~RPCSeedGenerator() {
0170   // do anything here that needs to be done at desctruction time
0171   // (e.g. close files, deallocate resources etc.)
0172   cout << "[RPCSeedGenerator] --> Destructor called" << endl;
0173 }
0174 
0175 //
0176 // member functions
0177 //
0178 
0179 // ------------ method called to produce the data  ------------
0180 void RPCSeedGenerator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0181   using namespace edm;
0182   goodweightedSeeds.clear();
0183   candidateweightedSeeds.clear();
0184 
0185   // Create the pointer to the Seed container
0186   auto goodCollection = std::make_unique<TrajectorySeedCollection>();
0187   auto candidateCollection = std::make_unique<TrajectorySeedCollection>();
0188 
0189   // Muon Geometry - DT, CSC and RPC
0190   MuonDetLayerGeometry const& muonLayers = iSetup.getData(muonLayersToken);
0191 
0192   // Get the RPC layers
0193   vector<const DetLayer*> RPCBarrelLayers = muonLayers.barrelRPCLayers();
0194   const DetLayer* RB4L = RPCBarrelLayers[5];
0195   const DetLayer* RB3L = RPCBarrelLayers[4];
0196   const DetLayer* RB22L = RPCBarrelLayers[3];
0197   const DetLayer* RB21L = RPCBarrelLayers[2];
0198   const DetLayer* RB12L = RPCBarrelLayers[1];
0199   const DetLayer* RB11L = RPCBarrelLayers[0];
0200   vector<const DetLayer*> RPCEndcapLayers = muonLayers.endcapRPCLayers();
0201   const DetLayer* REM3L = RPCEndcapLayers[0];
0202   const DetLayer* REM2L = RPCEndcapLayers[1];
0203   const DetLayer* REM1L = RPCEndcapLayers[2];
0204   const DetLayer* REP1L = RPCEndcapLayers[3];
0205   const DetLayer* REP2L = RPCEndcapLayers[4];
0206   const DetLayer* REP3L = RPCEndcapLayers[5];
0207 
0208   // Dispatch RPC recHits to the corresponding DetLayer, 6 layers for barrel and 3 layers for each endcap
0209   MuonRecHitContainer recHitsRPC[RPCLayerNumber];
0210   recHitsRPC[0] = muonMeasurements->recHits(RB11L, iEvent);
0211   recHitsRPC[1] = muonMeasurements->recHits(RB12L, iEvent);
0212   recHitsRPC[2] = muonMeasurements->recHits(RB21L, iEvent);
0213   recHitsRPC[3] = muonMeasurements->recHits(RB22L, iEvent);
0214   recHitsRPC[4] = muonMeasurements->recHits(RB3L, iEvent);
0215   recHitsRPC[5] = muonMeasurements->recHits(RB4L, iEvent);
0216   recHitsRPC[6] = muonMeasurements->recHits(REM1L, iEvent);
0217   recHitsRPC[7] = muonMeasurements->recHits(REM2L, iEvent);
0218   recHitsRPC[8] = muonMeasurements->recHits(REM3L, iEvent);
0219   recHitsRPC[9] = muonMeasurements->recHits(REP1L, iEvent);
0220   recHitsRPC[10] = muonMeasurements->recHits(REP2L, iEvent);
0221   recHitsRPC[11] = muonMeasurements->recHits(REP3L, iEvent);
0222 
0223   // Print the size of recHits in each DetLayer
0224   cout << "RB1in " << recHitsRPC[0].size() << " recHits" << endl;
0225   cout << "RB1out " << recHitsRPC[1].size() << " recHits" << endl;
0226   cout << "RB2in " << recHitsRPC[2].size() << " recHits" << endl;
0227   cout << "RB2out " << recHitsRPC[3].size() << " recHits" << endl;
0228   cout << "RB3 " << recHitsRPC[4].size() << " recHits" << endl;
0229   cout << "RB4 " << recHitsRPC[5].size() << " recHits" << endl;
0230   cout << "REM1 " << recHitsRPC[6].size() << " recHits" << endl;
0231   cout << "REM2 " << recHitsRPC[7].size() << " recHits" << endl;
0232   cout << "REM3 " << recHitsRPC[8].size() << " recHits" << endl;
0233   cout << "REP1 " << recHitsRPC[9].size() << " recHits" << endl;
0234   cout << "REP2 " << recHitsRPC[10].size() << " recHits" << endl;
0235   cout << "REP3 " << recHitsRPC[11].size() << " recHits" << endl;
0236 
0237   // Set Input of RPCSeedFinder, PCSeedrecHitFinder, CosmicrecHitFinder, RPCSeedLayerFinder
0238   recHitFinder.setInput(recHitsRPC);
0239   CosmicrecHitFinder.setInput(recHitsRPC);
0240   LayerFinder.setInput(recHitsRPC);
0241 
0242   // Set Magnetic Field EventSetup of RPCSeedFinder
0243   const MagneticField& Field = iSetup.getData(fieldToken);
0244 
0245   const RPCGeometry& rpcGeom = iSetup.getData(rpcGeometryToken);
0246   Finder.setEventSetup(Field, rpcGeom);
0247 
0248   // Start from filling layers to filling seeds
0249   LayerFinder.fill();
0250   Overlapper.run();
0251 
0252   // Save seeds to event
0253   for (vector<weightedTrajectorySeed>::iterator weightedseed = goodweightedSeeds.begin();
0254        weightedseed != goodweightedSeeds.end();
0255        ++weightedseed)
0256     goodCollection->push_back((*weightedseed).first);
0257   for (vector<weightedTrajectorySeed>::iterator weightedseed = candidateweightedSeeds.begin();
0258        weightedseed != candidateweightedSeeds.end();
0259        ++weightedseed)
0260     candidateCollection->push_back((*weightedseed).first);
0261 
0262   // Put the seed to event
0263   iEvent.put(std::move(goodCollection), "goodSeeds");
0264   iEvent.put(std::move(candidateCollection), "candidateSeeds");
0265 
0266   // Unset the input of RPCSeedFinder, PCSeedrecHitFinder, RPCSeedLayerFinder
0267   recHitFinder.unsetInput();
0268   CosmicrecHitFinder.unsetInput();
0269   LayerFinder.unsetInput();
0270 }
0271 
0272 void RPCSeedGenerator::beginStream(edm::StreamID) {
0273   // Set link and EventSetup of RPCSeedFinder, PCSeedrecHitFinder, CosmicrecHitFinder, RPCSeedLayerFinder
0274   cout << "set link and Geometry EventSetup of RPCSeedFinder, RPCSeedrecHitFinder, RPCCosmicSeedrecHitFinder, "
0275           "RPCSeedLayerFinder and RPCSeedOverlapper"
0276        << endl;
0277 
0278   Finder.setOutput(&goodweightedSeeds, &candidateweightedSeeds);
0279   recHitFinder.setOutput(&Finder);
0280   CosmicrecHitFinder.setOutput(&Finder);
0281   LayerFinder.setOutput(&recHitFinder, &CosmicrecHitFinder);
0282 }
0283 void RPCSeedGenerator::beginRun(const edm::Run&, const edm::EventSetup& iSetup) {
0284   // Get RPCGeometry
0285   RPCGeometry const& rpcGeometry = iSetup.getData(brRPCGeometryToken);
0286 
0287   CosmicrecHitFinder.setEdge(rpcGeometry);
0288   Overlapper.setGeometry(rpcGeometry);
0289   Overlapper.setIO(&goodweightedSeeds, &candidateweightedSeeds);
0290 }
0291 
0292 void RPCSeedGenerator::endStream() { cout << "All jobs completed" << endl; }
0293 
0294 //define this as a plug-in
0295 DEFINE_FWK_MODULE(RPCSeedGenerator);