CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/RecoMuon/MuonSeedGenerator/src/RPCSeedGenerator.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    RPCSeedGenerator
00004 // Class:      RPCSeedGenerator
00005 // 
00013 //
00014 // Original Author:  Haiyun Teng
00015 //         Created:  Wed Oct 29 17:24:36 CET 2008
00016 // $Id: RPCSeedGenerator.cc,v 1.7 2010/02/16 17:08:43 wmtan Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 // user include files
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDProducer.h"
00026 #include "FWCore/Framework/interface/Event.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00029 // special include files
00030 #include "FWCore/Utilities/interface/InputTag.h"
00031 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00032 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00033 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00034 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00035 #include <vector>
00036 // Using other classes
00037 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedPattern.h"
00038 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedFinder.h"
00039 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedrecHitFinder.h"
00040 #include "RecoMuon/MuonSeedGenerator/src/RPCCosmicSeedrecHitFinder.h"
00041 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedLayerFinder.h"
00042 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedOverlapper.h"
00043 // Geometry
00044 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00045 #include "RecoMuon/MeasurementDet/interface/MuonDetLayerMeasurements.h"
00046 #include "RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h"
00047 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
00048 // Framework
00049 #include "FWCore/Framework/interface/EventSetup.h"
00050 #include "FWCore/Framework/interface/ESHandle.h"
00051 // Math
00052 #include "math.h"
00053 // C++
00054 #include <vector>
00055 
00056 //
00057 // constants, enums and typedefs
00058 //
00059 using namespace std;
00060 using namespace edm;
00061 
00062 typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer;
00063 typedef MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer;
00064 typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer;
00065 typedef MuonTransientTrackingRecHit::ConstMuonRecHitContainer ConstMuonRecHitContainer;
00066 typedef RPCSeedPattern::weightedTrajectorySeed weightedTrajectorySeed;
00067 
00068 #ifndef RPCLayerNumber
00069 #define RPCLayerNumber 12
00070 #endif
00071 
00072 #ifndef BarrelLayerNumber
00073 #define BarrelLayerNumber 6
00074 #endif
00075 
00076 #ifndef EachEndcapLayerNumber
00077 #define EachEndcapLayerNumber 3
00078 #endif
00079 
00080 //
00081 // class decleration
00082 //
00083 
00084 class RPCSeedFinder;
00085 
00086 class RPCSeedGenerator : public edm::EDProducer {
00087     public:
00088         explicit RPCSeedGenerator(const edm::ParameterSet& iConfig);
00089         ~RPCSeedGenerator();
00090 
00091     private:
00092         virtual void beginJob();
00093         virtual void beginRun(const edm::Run&, const edm::EventSetup& iSetup);
00094         virtual void produce(edm::Event& iEvent, const edm::EventSetup& iSetup);
00095         virtual void endJob();
00096 
00097         // ----------member data ---------------------------
00098         RPCSeedFinder Finder;
00099         RPCSeedrecHitFinder recHitFinder;
00100         RPCCosmicSeedrecHitFinder CosmicrecHitFinder;
00101         RPCSeedLayerFinder LayerFinder;
00102         RPCSeedOverlapper Overlapper;
00103         std::vector<weightedTrajectorySeed> candidateweightedSeeds;
00104         std::vector<weightedTrajectorySeed> goodweightedSeeds;
00105         edm::InputTag theRPCRecHits;
00106 };
00107 
00108 
00109 //
00110 // constants, enums and typedefs
00111 //
00112 
00113 
00114 //
00115 // static data member definitions
00116 //
00117 
00118 //
00119 // constructors and destructor
00120 //
00121 RPCSeedGenerator::RPCSeedGenerator(const edm::ParameterSet& iConfig)
00122 {
00123     //register your products
00124     /* Examples
00125        produces<ExampleData2>();
00126 
00127     //if do put with a label
00128     produces<ExampleData2>("label");
00129     */
00130 
00131     // Now do what ever other initialization is needed
00132     // Configure other modules
00133     Finder.configure(iConfig);
00134     recHitFinder.configure(iConfig);
00135     CosmicrecHitFinder.configure(iConfig);
00136     LayerFinder.configure(iConfig);
00137     Overlapper.configure(iConfig);
00138     // Register the production
00139     produces<TrajectorySeedCollection>("goodSeeds");
00140     produces<TrajectorySeedCollection>("candidateSeeds");
00141     // Get event data Tag
00142     theRPCRecHits = iConfig.getParameter<edm::InputTag>("RPCRecHitsLabel");
00143     
00144     cout << endl << "[RPCSeedGenerator] --> Constructor called" << endl;
00145 }
00146 
00147 
00148 RPCSeedGenerator::~RPCSeedGenerator()
00149 {
00150     // do anything here that needs to be done at desctruction time
00151     // (e.g. close files, deallocate resources etc.)
00152     cout << "[RPCSeedGenerator] --> Destructor called" << endl;
00153 }
00154 
00155 
00156 //
00157 // member functions
00158 //
00159 
00160 // ------------ method called to produce the data  ------------
00161     void
00162 RPCSeedGenerator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00163 {
00164     using namespace edm;
00165     /* This is an event example
00166     //Read 'ExampleData' from the Event
00167     Handle<ExampleData> pIn;
00168     iEvent.getByLabel("example",pIn);
00169 
00170     //Use the ExampleData to create an ExampleData2 which 
00171     // is put into the Event
00172     std::auto_ptr<ExampleData2> pOut(new ExampleData2(*pIn));
00173     iEvent.put(pOut);
00174     */
00175 
00176     /* this is an EventSetup example
00177     //Read SetupData from the SetupRecord in the EventSetup
00178     ESHandle<SetupData> pSetup;
00179     iSetup.get<SetupRecord>().get(pSetup);
00180     */
00181 
00182     // clear weighted Seeds from last reconstruction  
00183     goodweightedSeeds.clear();
00184     candidateweightedSeeds.clear();
00185 
00186     // Create the pointer to the Seed container
00187     auto_ptr<TrajectorySeedCollection> goodCollection(new TrajectorySeedCollection());
00188     auto_ptr<TrajectorySeedCollection> candidateCollection(new TrajectorySeedCollection());
00189 
00190     // Muon Geometry - DT, CSC and RPC 
00191     edm::ESHandle<MuonDetLayerGeometry> muonLayers;
00192     iSetup.get<MuonRecoGeometryRecord>().get(muonLayers);
00193 
00194     // Get the RPC layers
00195     vector<DetLayer*> RPCBarrelLayers = muonLayers->barrelRPCLayers();
00196     const DetLayer* RB4L  = RPCBarrelLayers[5];
00197     const DetLayer* RB3L  = RPCBarrelLayers[4];
00198     const DetLayer* RB22L = RPCBarrelLayers[3];
00199     const DetLayer* RB21L = RPCBarrelLayers[2];
00200     const DetLayer* RB12L = RPCBarrelLayers[1];
00201     const DetLayer* RB11L = RPCBarrelLayers[0];
00202     vector<DetLayer*> RPCEndcapLayers = muonLayers->endcapRPCLayers();
00203     const DetLayer* REM3L = RPCEndcapLayers[0];
00204     const DetLayer* REM2L = RPCEndcapLayers[1];
00205     const DetLayer* REM1L = RPCEndcapLayers[2];
00206     const DetLayer* REP1L = RPCEndcapLayers[3];
00207     const DetLayer* REP2L = RPCEndcapLayers[4];
00208     const DetLayer* REP3L = RPCEndcapLayers[5];
00209 
00210     // Get RPC recHits by MuonDetLayerMeasurements, while CSC and DT is set to false and with empty InputTag
00211     MuonDetLayerMeasurements muonMeasurements(edm::InputTag(), edm::InputTag(), theRPCRecHits, false, false, true);
00212 
00213     // Dispatch RPC recHits to the corresponding DetLayer, 6 layers for barrel and 3 layers for each endcap
00214     MuonRecHitContainer recHitsRPC[RPCLayerNumber];
00215     recHitsRPC[0] = muonMeasurements.recHits(RB11L, iEvent);
00216     recHitsRPC[1] = muonMeasurements.recHits(RB12L, iEvent);
00217     recHitsRPC[2] = muonMeasurements.recHits(RB21L, iEvent);
00218     recHitsRPC[3] = muonMeasurements.recHits(RB22L, iEvent);
00219     recHitsRPC[4] = muonMeasurements.recHits(RB3L, iEvent);
00220     recHitsRPC[5] = muonMeasurements.recHits(RB4L, iEvent); 
00221     recHitsRPC[6] = muonMeasurements.recHits(REM1L, iEvent);
00222     recHitsRPC[7] = muonMeasurements.recHits(REM2L, iEvent);
00223     recHitsRPC[8] = muonMeasurements.recHits(REM3L, iEvent);
00224     recHitsRPC[9] = muonMeasurements.recHits(REP1L, iEvent);
00225     recHitsRPC[10] = muonMeasurements.recHits(REP2L, iEvent);
00226     recHitsRPC[11] = muonMeasurements.recHits(REP3L, iEvent);
00227 
00228     // Print the size of recHits in each DetLayer
00229     cout << "RB1in "  << recHitsRPC[0].size()  << " recHits" << endl;
00230     cout << "RB1out " << recHitsRPC[1].size()  << " recHits" << endl;
00231     cout << "RB2in "  << recHitsRPC[2].size()  << " recHits" << endl;
00232     cout << "RB2out " << recHitsRPC[3].size()  << " recHits" << endl;
00233     cout << "RB3 "    << recHitsRPC[4].size()  << " recHits" << endl;
00234     cout << "RB4 "    << recHitsRPC[5].size()  << " recHits" << endl;
00235     cout << "REM1 "   << recHitsRPC[6].size()  << " recHits" << endl;
00236     cout << "REM2 "   << recHitsRPC[7].size()  << " recHits" << endl;
00237     cout << "REM3 "   << recHitsRPC[8].size()  << " recHits" << endl;
00238     cout << "REP1 "   << recHitsRPC[9].size()  << " recHits" << endl;
00239     cout << "REP2 "   << recHitsRPC[10].size() << " recHits" << endl;
00240     cout << "REP3 "   << recHitsRPC[11].size() << " recHits" << endl;
00241 
00242     // Set Input of RPCSeedFinder, PCSeedrecHitFinder, CosmicrecHitFinder, RPCSeedLayerFinder
00243     recHitFinder.setInput(recHitsRPC);
00244     CosmicrecHitFinder.setInput(recHitsRPC);
00245     LayerFinder.setInput(recHitsRPC);
00246     
00247     // Set Magnetic Field EventSetup of RPCSeedFinder
00248     Finder.setEventSetup(iSetup);
00249 
00250     // Start from filling layers to filling seeds
00251     LayerFinder.fill();
00252     Overlapper.run();
00253 
00254     // Save seeds to event
00255     for(vector<weightedTrajectorySeed>::iterator weightedseed = goodweightedSeeds.begin(); weightedseed != goodweightedSeeds.end(); ++weightedseed)
00256         goodCollection->push_back((*weightedseed).first);
00257     for(vector<weightedTrajectorySeed>::iterator weightedseed = candidateweightedSeeds.begin(); weightedseed != candidateweightedSeeds.end(); ++weightedseed)
00258         candidateCollection->push_back((*weightedseed).first);
00259 
00260     // Put the seed to event
00261     iEvent.put(goodCollection, "goodSeeds");
00262     iEvent.put(candidateCollection, "candidateSeeds");
00263 
00264     // Unset the input of RPCSeedFinder, PCSeedrecHitFinder, RPCSeedLayerFinder
00265     recHitFinder.unsetInput();
00266     CosmicrecHitFinder.unsetInput();
00267     LayerFinder.unsetInput();
00268     
00269 }
00270 
00271 void RPCSeedGenerator::beginJob() {
00272 
00273     // Set link and EventSetup of RPCSeedFinder, PCSeedrecHitFinder, CosmicrecHitFinder, RPCSeedLayerFinder
00274     cout << "set link and Geometry EventSetup of RPCSeedFinder, RPCSeedrecHitFinder, RPCCosmicSeedrecHitFinder, RPCSeedLayerFinder and RPCSeedOverlapper" << endl;
00275     
00276     Finder.setOutput(&goodweightedSeeds, &candidateweightedSeeds);
00277     recHitFinder.setOutput(&Finder);
00278     CosmicrecHitFinder.setOutput(&Finder);
00279     LayerFinder.setOutput(&recHitFinder, &CosmicrecHitFinder);
00280 }
00281 void RPCSeedGenerator::beginRun(const edm::Run&, const edm::EventSetup& iSetup){
00282     CosmicrecHitFinder.setEdge(iSetup);
00283     Overlapper.setEventSetup(iSetup);
00284     Overlapper.setIO(&goodweightedSeeds, &candidateweightedSeeds);
00285 }
00286 
00287 void RPCSeedGenerator::endJob() {
00288 
00289     cout << "All jobs completed" << endl;
00290 }
00291 
00292 //define this as a plug-in
00293 DEFINE_FWK_MODULE(RPCSeedGenerator);