Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-13 01:43:57

0001 /** \file GEMCSCSegmentProducer.cc
0002  *
0003  */
0004 
0005 #include <RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.h>
0006 #include <RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentBuilder.h>
0007 
0008 #include <DataFormats/Common/interface/Handle.h>
0009 #include <FWCore/Framework/interface/ESHandle.h>
0010 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0011 
0012 #include <DataFormats/GEMRecHit/interface/GEMRecHitCollection.h>
0013 #include <DataFormats/GEMRecHit/interface/GEMCSCSegmentCollection.h>
0014 #include <DataFormats/GEMRecHit/interface/GEMCSCSegment.h>
0015 
0016 #include <DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h>
0017 #include <DataFormats/CSCRecHit/interface/CSCSegmentCollection.h>
0018 #include <DataFormats/CSCRecHit/interface/CSCSegment.h>
0019 
0020 GEMCSCSegmentProducer::GEMCSCSegmentProducer(const edm::ParameterSet& pas)
0021     : kCSCGeometryToken_(esConsumes<CSCGeometry, MuonGeometryRecord>()),
0022       kGEMGeometryToken_(esConsumes<GEMGeometry, MuonGeometryRecord>()),
0023       kCSCSegmentCollectionToken_(consumes<CSCSegmentCollection>(pas.getParameter<edm::InputTag>("inputObjectsCSC"))),
0024       kGEMRecHitCollectionToken_(consumes<GEMRecHitCollection>(pas.getParameter<edm::InputTag>("inputObjectsGEM"))),
0025       iev(0) {
0026   segmentBuilder_ = new GEMCSCSegmentBuilder(pas);  // pass on the parameterset
0027 
0028   // register what this produces
0029   produces<GEMCSCSegmentCollection>();
0030 }
0031 
0032 GEMCSCSegmentProducer::~GEMCSCSegmentProducer() {
0033   LogDebug("GEMCSCSegment") << "deleting GEMCSCSegmentBuilder after " << iev << " events w/ gem and csc data.";
0034   delete segmentBuilder_;
0035 }
0036 
0037 void GEMCSCSegmentProducer::produce(edm::Event& ev, const edm::EventSetup& setup) {
0038   LogDebug("GEMCSCSegment") << "start producing segments for " << ++iev << "th event w/ gem and csc data";
0039 
0040   // find the geometry (& conditions?) for this event & cache it in the builder
0041   const auto cscg = setup.getHandle(kCSCGeometryToken_);
0042   if (not cscg.isValid()) {
0043     edm::LogError("GEMCSCSegment") << "invalid CSCGeometry";
0044     return;
0045   }
0046   const CSCGeometry* cgeom = &*cscg;
0047 
0048   const auto gemg = setup.getHandle(kGEMGeometryToken_);
0049   if (not gemg.isValid()) {
0050     edm::LogError("GEMCSCSegment") << "invalid GEMGeometry";
0051     return;
0052   }
0053   const GEMGeometry* ggeom = &*gemg;
0054 
0055   // cache the geometry in the builder
0056   segmentBuilder_->setGeometry(ggeom, cgeom);
0057 
0058   // fill the map with matches between GEM and CSC chambers
0059   segmentBuilder_->LinkGEMRollsToCSCChamberIndex(ggeom, cgeom);
0060 
0061   // get the collection of CSCSegment and GEMRecHits
0062   const auto cscSegment = ev.getHandle(kCSCSegmentCollectionToken_);
0063   if (not cscSegment.isValid()) {
0064     edm::LogError("GEMCSCSegment") << "invalid CSCSegmentCollection";
0065     return;
0066   }
0067 
0068   const auto gemRecHits = ev.getHandle(kGEMRecHitCollectionToken_);
0069   if (not gemRecHits.isValid()) {
0070     edm::LogError("GEMCSCSegment") << "invalid GEMRecHitCollection";
0071     return;
0072   }
0073 
0074   // create empty collection of GEMCSC Segments
0075   auto oc = std::make_unique<GEMCSCSegmentCollection>();
0076 
0077   // pass the empty collection of GEMCSC Segments and fill it
0078   segmentBuilder_->build(gemRecHits.product(), cscSegment.product(), *oc);  //@@ FILL oc
0079 
0080   // put the filled collection in event
0081   ev.put(std::move(oc));
0082 }