Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:29:58

0001 // File: DataMixingGeneralTrackWorker.cc
0002 // Description:  see DataMixingGeneralTrackWorker.h
0003 // Author:  Mike Hildreth, University of Notre Dame
0004 //
0005 //--------------------------------------------
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include <map>
0009 #include <memory>
0010 
0011 #include "DataFormats/Common/interface/Handle.h"
0012 //
0013 //
0014 #include "DataMixingGeneralTrackWorker.h"
0015 
0016 using namespace std;
0017 
0018 namespace edm {
0019 
0020   // Virtual constructor
0021 
0022   DataMixingGeneralTrackWorker::DataMixingGeneralTrackWorker() {}
0023 
0024   // Constructor
0025   DataMixingGeneralTrackWorker::DataMixingGeneralTrackWorker(const edm::ParameterSet &ps, edm::ConsumesCollector &&iC) {
0026     // get the subdetector names
0027     //    this->getSubdetectorNames();  //something like this may be useful to
0028     //    check what we are supposed to do...
0029 
0030     // declare the products to produce
0031 
0032     GeneralTrackLabelSig_ = ps.getParameter<edm::InputTag>("GeneralTrackLabelSig");
0033 
0034     GeneralTrackPileInputTag_ = ps.getParameter<edm::InputTag>("GeneralTrackPileInputTag");
0035 
0036     GeneralTrackCollectionDM_ = ps.getParameter<std::string>("GeneralTrackDigiCollectionDM");
0037 
0038     GTrackSigToken_ = iC.consumes<reco::TrackCollection>(GeneralTrackLabelSig_);
0039     GTrackPileToken_ = iC.consumes<reco::TrackCollection>(GeneralTrackPileInputTag_);
0040   }
0041 
0042   // Virtual destructor needed.
0043   DataMixingGeneralTrackWorker::~DataMixingGeneralTrackWorker() {}
0044 
0045   void DataMixingGeneralTrackWorker::addGeneralTrackSignals(const edm::Event &e) {
0046     // Create new track list; Rely on the fact that addSignals gets called
0047     // first...
0048 
0049     NewTrackList_ = std::make_unique<reco::TrackCollection>();
0050 
0051     // grab tracks, store copy
0052 
0053     // edm::Handle<reco::TrackCollection> generalTrkHandle;
0054     // e.getByLabel("generalTracks", generalTrkHandle);
0055     edm::Handle<reco::TrackCollection> tracks;
0056     e.getByToken(GTrackSigToken_, tracks);
0057 
0058     if (tracks.isValid()) {
0059       for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
0060         NewTrackList_->push_back(*track);
0061       }
0062     }
0063 
0064   }  // end of addGeneralTrackSignals
0065 
0066   void DataMixingGeneralTrackWorker::addGeneralTrackPileups(const int bcr,
0067                                                             const EventPrincipal *ep,
0068                                                             unsigned int eventNr,
0069                                                             ModuleCallingContext const *mcc) {
0070     LogDebug("DataMixingGeneralTrackWorker")
0071         << "\n===============> adding pileups from event  " << ep->id() << " for bunchcrossing " << bcr;
0072 
0073     std::shared_ptr<Wrapper<reco::TrackCollection> const> inputPTR =
0074         getProductByTag<reco::TrackCollection>(*ep, GeneralTrackPileInputTag_, mcc);
0075 
0076     if (inputPTR) {
0077       const reco::TrackCollection *tracks = const_cast<reco::TrackCollection *>(inputPTR->product());
0078 
0079       // grab tracks, store copy
0080 
0081       for (reco::TrackCollection::const_iterator track = tracks->begin(); track != tracks->end(); ++track) {
0082         NewTrackList_->push_back(*track);
0083       }
0084     }
0085   }
0086 
0087   void DataMixingGeneralTrackWorker::putGeneralTrack(edm::Event &e) {
0088     // collection of Tracks to put in the event
0089 
0090     // put the collection of digis in the event
0091     LogInfo("DataMixingGeneralTrackWorker") << "total # Merged Tracks: " << NewTrackList_->size();
0092 
0093     // put collection
0094 
0095     e.put(std::move(NewTrackList_), GeneralTrackCollectionDM_);
0096 
0097     // clear local storage for this event
0098     // NewTrackList_.clear();
0099   }
0100 
0101 }  // namespace edm