Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:54

0001 #include "Calibration/EcalAlCaRecoProducers/plugins/AlCaElectronTracksReducer.h"
0002 #include "DataFormats/TrackReco/interface/Track.h"
0003 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0004 
0005 AlCaElectronTracksReducer::AlCaElectronTracksReducer(const edm::ParameterSet& iConfig) {
0006   generalTracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("generalTracksLabel"));
0007   generalTracksExtraToken_ =
0008       consumes<reco::TrackExtraCollection>(iConfig.getParameter<edm::InputTag>("generalTracksExtraLabel"));
0009   electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronLabel"));
0010 
0011   // name of the output collection
0012   alcaTrackExtraCollection_ = iConfig.getParameter<std::string>("alcaTrackExtraCollection");
0013 
0014   //register your products
0015   produces<reco::TrackCollection>(alcaTrackCollection_);
0016   produces<reco::TrackExtraCollection>(alcaTrackExtraCollection_);
0017 }
0018 
0019 // ------------ method called to produce the data  ------------
0020 void AlCaElectronTracksReducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0021   using namespace edm;
0022   using namespace std;
0023   using namespace reco;
0024 
0025   // Get GSFElectrons
0026   Handle<reco::GsfElectronCollection> pElectrons;
0027   iEvent.getByToken(electronToken_, pElectrons);
0028 
0029   const reco::GsfElectronCollection* electronCollection = pElectrons.product();
0030 
0031   Handle<TrackCollection> generalTracksHandle;
0032   iEvent.getByToken(generalTracksToken_, generalTracksHandle);
0033 
0034   Handle<TrackExtraCollection> generalTracksExtraHandle;
0035   iEvent.getByToken(generalTracksExtraToken_, generalTracksExtraHandle);
0036 
0037   //Create empty output collections
0038   auto redGeneralTracksCollection = std::make_unique<TrackCollection>();
0039   auto redGeneralTracksExtraCollection = std::make_unique<TrackExtraCollection>();
0040 
0041   reco::GsfElectronCollection::const_iterator eleIt;
0042 
0043   for (eleIt = electronCollection->begin(); eleIt != electronCollection->end(); eleIt++) {
0044     // barrel
0045     TrackRef track = (eleIt->closestCtfTrackRef());
0046     if (track.isNull()) {
0047       //      edm::LogError("track") << "Track Ref not found " << eleIt->energy() << "\t" << eleIt->eta();
0048       continue;
0049     }
0050     redGeneralTracksCollection->push_back(*track);
0051     if (generalTracksExtraHandle.isValid())
0052       redGeneralTracksExtraCollection->push_back(*(track->extra()));
0053   }
0054 
0055   //Put selected information in the event
0056   iEvent.put(std::move(redGeneralTracksCollection), alcaTrackCollection_);
0057   iEvent.put(std::move(redGeneralTracksExtraCollection), alcaTrackExtraCollection_);
0058 }
0059 
0060 DEFINE_FWK_MODULE(AlCaElectronTracksReducer);