Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-16 03:24:09

0001 /** \file
0002  *
0003  * \author Stefano Lacaprara - INFN Legnaro <stefano.lacaprara@pd.infn.it>
0004  * \author Riccardo Bellan - INFN TO <riccardo.bellan@cern.ch>
0005  */
0006 
0007 /* This Class Header */
0008 #include "RecoLocalMuon/DTSegment/src/DTRecSegment2DProducer.h"
0009 
0010 /* Collaborating Class Header */
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 using namespace edm;
0016 
0017 #include "Geometry/DTGeometry/interface/DTLayer.h"
0018 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0020 
0021 #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h"
0022 #include "DataFormats/DTRecHit/interface/DTRecHit1D.h"
0023 #include "DataFormats/DTRecHit/interface/DTSLRecSegment2D.h"
0024 #include "DataFormats/DTRecHit/interface/DTRecSegment2DCollection.h"
0025 #include "DataFormats/DTRecHit/interface/DTRangeMapAccessor.h"
0026 
0027 #include "RecoLocalMuon/DTSegment/src/DTRecSegment2DAlgoFactory.h"
0028 
0029 /* C++ Headers */
0030 #include <string>
0031 using namespace std;
0032 
0033 /* ====================================================================== */
0034 
0035 /// Constructor
0036 DTRecSegment2DProducer::DTRecSegment2DProducer(const edm::ParameterSet& pset)
0037     : theAlgo{DTRecSegment2DAlgoFactory::get()->create(pset.getParameter<string>("Reco2DAlgoName"),
0038                                                        pset.getParameter<ParameterSet>("Reco2DAlgoConfig"),
0039                                                        consumesCollector())},
0040       dtGeomToken_{esConsumes()} {
0041   // Set verbose output
0042   debug = pset.getUntrackedParameter<bool>("debug");
0043 
0044   // the name of the 1D rec hits collection
0045   recHits1DToken_ = consumes<DTRecHitCollection>(pset.getParameter<InputTag>("recHits1DLabel"));
0046 
0047   if (debug)
0048     cout << "[DTRecSegment2DProducer] Constructor called" << endl;
0049 
0050   produces<DTRecSegment2DCollection>();
0051 
0052   // Get the concrete reconstruction algo from the factory
0053   if (debug)
0054     cout << "the Reco2D AlgoName is " << pset.getParameter<string>("Reco2DAlgoName") << endl;
0055 }
0056 
0057 /// Destructor
0058 DTRecSegment2DProducer::~DTRecSegment2DProducer() {
0059   if (debug)
0060     cout << "[DTRecSegment2DProducer] Destructor called" << endl;
0061 }
0062 
0063 /* Operations */
0064 void DTRecSegment2DProducer::produce(edm::Event& event, const edm::EventSetup& setup) {
0065   if (debug)
0066     cout << "[DTRecSegment2DProducer] produce called" << endl;
0067   // Get the DT Geometry
0068   DTGeometry const& dtGeom = setup.getData(dtGeomToken_);
0069 
0070   theAlgo->setES(setup);
0071 
0072   // Get the 1D rechits from the event
0073   Handle<DTRecHitCollection> allHits;
0074   event.getByToken(recHits1DToken_, allHits);
0075 
0076   // Create the pointer to the collection which will store the rechits
0077   auto segments = std::make_unique<DTRecSegment2DCollection>();
0078 
0079   // Iterate through all hit collections ordered by LayerId
0080   DTRecHitCollection::id_iterator dtLayerIt;
0081   DTSuperLayerId oldSlId;
0082   for (dtLayerIt = allHits->id_begin(); dtLayerIt != allHits->id_end(); ++dtLayerIt) {
0083     // The layerId
0084     DTLayerId layerId = (*dtLayerIt);
0085     const DTSuperLayerId SLId = layerId.superlayerId();
0086     if (SLId == oldSlId)
0087       continue;  // I'm on the same SL as before
0088     oldSlId = SLId;
0089 
0090     if (debug)
0091       cout << "Reconstructing the 2D segments in " << SLId << endl;
0092 
0093     const DTSuperLayer* sl = dtGeom.superLayer(SLId);
0094 
0095     // Get all the rec hit in the same superLayer in which layerId relies
0096     DTRecHitCollection::range range = allHits->get(DTRangeMapAccessor::layersBySuperLayer(SLId));
0097 
0098     // Fill the vector with the 1D RecHit
0099     vector<DTRecHit1DPair> pairs(range.first, range.second);
0100 
0101     if (debug)
0102       cout << "Number of 1D-RecHit pairs " << pairs.size() << endl;
0103 
0104     if (debug)
0105       cout << "Start the 2D-segments Reco " << endl;
0106     OwnVector<DTSLRecSegment2D> segs = theAlgo->reconstruct(sl, pairs);
0107     if (debug)
0108       cout << "Number of Reconstructed segments: " << segs.size() << endl;
0109 
0110     if (!segs.empty())
0111       segments->put(SLId, segs.begin(), segs.end());
0112   }
0113   event.put(std::move(segments));
0114 }