CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/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     // create input selector
00036     //    if (label_.size()>0){
00037     //  sel_=new Selector( ModuleLabelSelector(label_));
00038     // }
00039     //else {
00040     //  sel_=new Selector( MatchAllSelector());
00041 
00042     // declare the products to produce
00043 
00044     GeneralTrackLabelSig_  = ps.getParameter<edm::InputTag>("GeneralTrackLabelSig");
00045 
00046     GeneralTrackPileInputTag_ = ps.getParameter<edm::InputTag>("GeneralTrackPileInputTag");
00047 
00048     GeneralTrackCollectionDM_  = ps.getParameter<std::string>("GeneralTrackDigiCollectionDM");
00049 
00050   }
00051                
00052 
00053   // Virtual destructor needed.
00054   DataMixingGeneralTrackWorker::~DataMixingGeneralTrackWorker() { 
00055   }  
00056 
00057 
00058 
00059   void DataMixingGeneralTrackWorker::addGeneralTrackSignals(const edm::Event &e) { 
00060 
00061     // Create new track list; Rely on the fact that addSignals gets called first...
00062 
00063     NewTrackList_ = std::auto_ptr<reco::TrackCollection>(new reco::TrackCollection());
00064 
00065     // grab tracks, store copy
00066 
00067     //edm::Handle<reco::TrackCollection> generalTrkHandle;
00068     //e.getByLabel("generalTracks", generalTrkHandle);
00069     edm::Handle<reco::TrackCollection> tracks;
00070     e.getByLabel(GeneralTrackLabelSig_, tracks);
00071 
00072     if (tracks.isValid()) {
00073       for (reco::TrackCollection::const_iterator track = tracks->begin();  track != tracks->end();  ++track) {
00074         NewTrackList_->push_back(*track);
00075       }
00076       
00077     }
00078 
00079   } // end of addGeneralTrackSignals
00080 
00081 
00082 
00083   void DataMixingGeneralTrackWorker::addGeneralTrackPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
00084     LogDebug("DataMixingGeneralTrackWorker") <<"\n===============> adding pileups from event  "<<ep->id()<<" for bunchcrossing "<<bcr;
00085 
00086 
00087     boost::shared_ptr<Wrapper<reco::TrackCollection >  const> inputPTR =
00088       getProductByTag<reco::TrackCollection >(*ep, GeneralTrackPileInputTag_ );
00089 
00090     if(inputPTR ) {
00091 
00092       const reco::TrackCollection  *tracks = const_cast< reco::TrackCollection * >(inputPTR->product());
00093 
00094     // grab tracks, store copy
00095 
00096 
00097       for (reco::TrackCollection::const_iterator track = tracks->begin();  track != tracks->end();  ++track) {
00098         NewTrackList_->push_back(*track);
00099       }
00100       
00101     }
00102 
00103   }
00104 
00105 
00106  
00107   void DataMixingGeneralTrackWorker::putGeneralTrack(edm::Event &e) {
00108 
00109     // collection of Tracks to put in the event
00110 
00111     // put the collection of digis in the event   
00112     LogInfo("DataMixingGeneralTrackWorker") << "total # Merged Tracks: " << NewTrackList_->size() ;
00113 
00114     // put collection
00115 
00116     e.put( NewTrackList_, GeneralTrackCollectionDM_ );
00117 
00118     // clear local storage for this event
00119     //NewTrackList_.clear();
00120   }
00121 
00122 } //edm