CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoLocalMuon/DTSegment/src/DTRecSegment2DProducer.cc

Go to the documentation of this file.
00001 
00009 /* This Class Header */
00010 #include "RecoLocalMuon/DTSegment/src/DTRecSegment2DProducer.h"
00011 
00012 /* Collaborating Class Header */
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016 using namespace edm;
00017 
00018 #include "Geometry/DTGeometry/interface/DTLayer.h"
00019 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 
00022 #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h"
00023 #include "DataFormats/DTRecHit/interface/DTRecHit1D.h"
00024 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
00025 #include "DataFormats/DTRecHit/interface/DTSLRecSegment2D.h"
00026 #include "DataFormats/DTRecHit/interface/DTRecSegment2DCollection.h"
00027 #include "DataFormats/DTRecHit/interface/DTRangeMapAccessor.h"
00028 
00029 #include "RecoLocalMuon/DTSegment/src/DTRecSegment2DAlgoFactory.h"
00030 
00031 /* C++ Headers */
00032 #include <string>
00033 using namespace std;
00034 
00035 /* ====================================================================== */
00036 
00038 DTRecSegment2DProducer::DTRecSegment2DProducer(const edm::ParameterSet& pset) {
00039   // Set verbose output
00040   debug = pset.getUntrackedParameter<bool>("debug"); 
00041 
00042   // the name of the 1D rec hits collection
00043   theRecHits1DLabel = pset.getParameter<InputTag>("recHits1DLabel");
00044 
00045   if(debug)
00046     cout << "[DTRecSegment2DProducer] Constructor called" << endl;
00047 
00048   produces<DTRecSegment2DCollection>();
00049 
00050   // Get the concrete reconstruction algo from the factory
00051   string theAlgoName = pset.getParameter<string>("Reco2DAlgoName");
00052   if(debug) cout << "the Reco2D AlgoName is " << theAlgoName << endl;
00053   theAlgo = DTRecSegment2DAlgoFactory::get()->create(theAlgoName,
00054                                                      pset.getParameter<ParameterSet>("Reco2DAlgoConfig"));
00055 }
00056 
00058 DTRecSegment2DProducer::~DTRecSegment2DProducer() {
00059   if(debug)
00060     cout << "[DTRecSegment2DProducer] Destructor called" << endl;
00061   delete theAlgo;
00062 }
00063 
00064 /* Operations */ 
00065 void DTRecSegment2DProducer::produce(edm::Event& event, const
00066                                      edm::EventSetup& setup) {
00067   if(debug)
00068     cout << "[DTRecSegment2DProducer] produce called" << endl;
00069   // Get the DT Geometry
00070   ESHandle<DTGeometry> dtGeom;
00071   setup.get<MuonGeometryRecord>().get(dtGeom);
00072 
00073   theAlgo->setES(setup);
00074   
00075   // Get the 1D rechits from the event
00076   Handle<DTRecHitCollection> allHits; 
00077   event.getByLabel(theRecHits1DLabel, allHits);
00078 
00079   // Create the pointer to the collection which will store the rechits
00080   auto_ptr<DTRecSegment2DCollection> segments(new DTRecSegment2DCollection());
00081 
00082   // Iterate through all hit collections ordered by LayerId
00083   DTRecHitCollection::id_iterator dtLayerIt;
00084   DTSuperLayerId oldSlId;
00085   for (dtLayerIt = allHits->id_begin(); dtLayerIt != allHits->id_end(); ++dtLayerIt){
00086     // The layerId
00087     DTLayerId layerId = (*dtLayerIt);
00088     const DTSuperLayerId SLId = layerId.superlayerId();
00089     if (SLId==oldSlId) continue; // I'm on the same SL as before
00090     oldSlId = SLId;
00091 
00092     if(debug) cout <<"Reconstructing the 2D segments in "<< SLId << endl;
00093 
00094     const DTSuperLayer* sl = dtGeom->superLayer(SLId);
00095 
00096     // Get all the rec hit in the same superLayer in which layerId relies 
00097     DTRecHitCollection::range range =
00098       allHits->get(DTRangeMapAccessor::layersBySuperLayer(SLId));
00099 
00100     // Fill the vector with the 1D RecHit
00101     vector<DTRecHit1DPair> pairs(range.first,range.second);
00102 
00103     if(debug) cout << "Number of 1D-RecHit pairs " << pairs.size() << endl;
00104 
00105     if(debug) cout << "Start the 2D-segments Reco "<< endl;
00106     OwnVector<DTSLRecSegment2D> segs = theAlgo->reconstruct(sl, pairs);
00107     if(debug) cout << "Number of Reconstructed segments: " << segs.size() << endl;
00108 
00109     if (segs.size() > 0 )
00110       segments->put(SLId, segs.begin(),segs.end());
00111   }
00112   event.put(segments);
00113 }
00114 
00115