CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/SimGeneral/DataMixingModule/plugins/DataMixingGeneralTrackWorker.cc

Go to the documentation of this file.
00001 // File: DataMixingGeneralTrackWorker.cc
00002 // Description:  see DataMixingGeneralTrackWorker.h
00003 // Author:  Mike Hildreth, University of Notre Dame
00004 //
00005 //--------------------------------------------
00006 
00007 #include <map>
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "FWCore/Utilities/interface/EDMException.h"
00010 #include "FWCore/Framework/interface/ConstProductRegistry.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "DataFormats/Provenance/interface/Provenance.h"
00014 #include "DataFormats/Provenance/interface/BranchDescription.h"
00015 //
00016 //
00017 #include "DataMixingGeneralTrackWorker.h"
00018 
00019 using namespace std;
00020 
00021 namespace edm
00022 {
00023 
00024   // Virtual constructor
00025 
00026   DataMixingGeneralTrackWorker::DataMixingGeneralTrackWorker() { }
00027 
00028   // Constructor 
00029   DataMixingGeneralTrackWorker::DataMixingGeneralTrackWorker(const edm::ParameterSet& ps)
00030   {                                                         
00031 
00032     // get the subdetector names
00033     //    this->getSubdetectorNames();  //something like this may be useful to check what we are supposed to do...
00034 
00035     // declare the products to produce
00036 
00037     GeneralTrackLabelSig_  = ps.getParameter<edm::InputTag>("GeneralTrackLabelSig");
00038 
00039     GeneralTrackPileInputTag_ = ps.getParameter<edm::InputTag>("GeneralTrackPileInputTag");
00040 
00041     GeneralTrackCollectionDM_  = ps.getParameter<std::string>("GeneralTrackDigiCollectionDM");
00042 
00043   }
00044                
00045 
00046   // Virtual destructor needed.
00047   DataMixingGeneralTrackWorker::~DataMixingGeneralTrackWorker() { 
00048   }  
00049 
00050 
00051 
00052   void DataMixingGeneralTrackWorker::addGeneralTrackSignals(const edm::Event &e) { 
00053 
00054     // Create new track list; Rely on the fact that addSignals gets called first...
00055 
00056     NewTrackList_ = std::auto_ptr<reco::TrackCollection>(new reco::TrackCollection());
00057 
00058     // grab tracks, store copy
00059 
00060     //edm::Handle<reco::TrackCollection> generalTrkHandle;
00061     //e.getByLabel("generalTracks", generalTrkHandle);
00062     edm::Handle<reco::TrackCollection> tracks;
00063     e.getByLabel(GeneralTrackLabelSig_, tracks);
00064 
00065     if (tracks.isValid()) {
00066       for (reco::TrackCollection::const_iterator track = tracks->begin();  track != tracks->end();  ++track) {
00067         NewTrackList_->push_back(*track);
00068       }
00069       
00070     }
00071 
00072   } // end of addGeneralTrackSignals
00073 
00074 
00075 
00076   void DataMixingGeneralTrackWorker::addGeneralTrackPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
00077     LogDebug("DataMixingGeneralTrackWorker") <<"\n===============> adding pileups from event  "<<ep->id()<<" for bunchcrossing "<<bcr;
00078 
00079 
00080     boost::shared_ptr<Wrapper<reco::TrackCollection >  const> inputPTR =
00081       getProductByTag<reco::TrackCollection >(*ep, GeneralTrackPileInputTag_ );
00082 
00083     if(inputPTR ) {
00084 
00085       const reco::TrackCollection  *tracks = const_cast< reco::TrackCollection * >(inputPTR->product());
00086 
00087     // grab tracks, store copy
00088 
00089 
00090       for (reco::TrackCollection::const_iterator track = tracks->begin();  track != tracks->end();  ++track) {
00091         NewTrackList_->push_back(*track);
00092       }
00093       
00094     }
00095 
00096   }
00097 
00098 
00099  
00100   void DataMixingGeneralTrackWorker::putGeneralTrack(edm::Event &e) {
00101 
00102     // collection of Tracks to put in the event
00103 
00104     // put the collection of digis in the event   
00105     LogInfo("DataMixingGeneralTrackWorker") << "total # Merged Tracks: " << NewTrackList_->size() ;
00106 
00107     // put collection
00108 
00109     e.put( NewTrackList_, GeneralTrackCollectionDM_ );
00110 
00111     // clear local storage for this event
00112     //NewTrackList_.clear();
00113   }
00114 
00115 } //edm