CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoLocalMuon/DTSegment/src/DTRecSegment4DProducer.cc

Go to the documentation of this file.
00001 
00009 #include "RecoLocalMuon/DTSegment/src/DTRecSegment4DProducer.h"
00010 
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 
00016 #include "RecoLocalMuon/DTSegment/src/DTSegmentUpdator.h"
00017 #include "RecoLocalMuon/DTSegment/src/DTRecSegment4DAlgoFactory.h"
00018 
00019 #include "DataFormats/Common/interface/OwnVector.h"
00020 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
00021 #include "DataFormats/DTRecHit/interface/DTRecSegment2DCollection.h"
00022 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00023 
00024 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00025 
00026 using namespace edm;
00027 using namespace std;
00028 
00029 DTRecSegment4DProducer::DTRecSegment4DProducer(const ParameterSet& pset){
00030   produces<DTRecSegment4DCollection>();
00031   
00032   // debug parameter
00033   debug = pset.getUntrackedParameter<bool>("debug", false);
00034   
00035   if(debug)
00036     cout << "[DTRecSegment4DProducer] Constructor called" << endl;
00037   
00038   // the name of the 1D rec hits collection
00039   theRecHits1DLabel = pset.getParameter<InputTag>("recHits1DLabel");
00040   
00041   // the name of the 2D rec hits collection
00042   theRecHits2DLabel = pset.getParameter<InputTag>("recHits2DLabel");
00043   
00044   // Get the concrete 4D-segments reconstruction algo from the factory
00045   string theReco4DAlgoName = pset.getParameter<string>("Reco4DAlgoName");
00046   if(debug) cout << "the Reco4D AlgoName is " << theReco4DAlgoName << endl;
00047   the4DAlgo = DTRecSegment4DAlgoFactory::get()->create(theReco4DAlgoName,
00048                                                        pset.getParameter<ParameterSet>("Reco4DAlgoConfig"));
00049 }
00050 
00052 DTRecSegment4DProducer::~DTRecSegment4DProducer(){
00053   if(debug)
00054     cout << "[DTRecSegment4DProducer] Destructor called" << endl;
00055   delete the4DAlgo;
00056 }
00057 
00058 void DTRecSegment4DProducer::produce(Event& event, const EventSetup& setup){
00059 
00060   // Get the 1D rechits from the event
00061   Handle<DTRecHitCollection> all1DHits; 
00062   event.getByLabel(theRecHits1DLabel,all1DHits);
00063   
00064   // Get the 2D rechits from the event
00065   Handle<DTRecSegment2DCollection> all2DSegments;
00066   if(the4DAlgo->wants2DSegments())
00067     event.getByLabel(theRecHits2DLabel, all2DSegments);
00068 
00069   // Create the pointer to the collection which will store the rechits
00070   auto_ptr<DTRecSegment4DCollection> segments4DCollection(new DTRecSegment4DCollection());
00071 
00072   // get the geometry
00073   ESHandle<DTGeometry> theGeom;
00074   setup.get<MuonGeometryRecord>().get(theGeom);
00075 
00076   // Percolate the setup
00077   the4DAlgo->setES(setup);
00078 
00079   // Iterate over all hit collections ordered by layerId
00080   DTRecHitCollection::id_iterator dtLayerIt;
00081 
00082   DTChamberId oldChId;
00083 
00084   for (dtLayerIt = all1DHits->id_begin(); dtLayerIt != all1DHits->id_end(); ++dtLayerIt){
00085 
00086     // Check the DTChamberId
00087     const DTChamberId chId = (*dtLayerIt).chamberId();
00088     if (chId==oldChId) continue; // I'm on the same Chamber as before
00089     oldChId = chId;
00090     if(debug) cout << "ChamberId: "<< chId << endl;
00091     the4DAlgo->setChamber(chId);
00092 
00093     if(debug) cout<<"Take the DTRecHits1D and set them in the reconstructor"<<endl;
00094 
00095     the4DAlgo->setDTRecHit1DContainer(all1DHits);
00096 
00097     if(debug) cout<<"Take the DTRecSegments2D and set them in the reconstructor"<<endl;
00098 
00099     the4DAlgo->setDTRecSegment2DContainer(all2DSegments);
00100 
00101     if(debug) cout << "Start 4D-Segments Reco " << endl;
00102     
00103     OwnVector<DTRecSegment4D> segments4D = the4DAlgo->reconstruct();
00104     
00105     if(debug) {
00106       cout << "Number of reconstructed 4D-segments " << segments4D.size() << endl;
00107       copy(segments4D.begin(), segments4D.end(),
00108            ostream_iterator<DTRecSegment4D>(cout, "\n"));
00109     }
00110 
00111     if (segments4D.size() > 0 )
00112       // convert the OwnVector into a Collection
00113       segments4DCollection->put(chId, segments4D.begin(),segments4D.end());
00114   }
00115   // Load the output in the Event
00116   event.put(segments4DCollection);
00117 }