CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 // File: DataMixingMuonWorker.cc
00002 // Description:  see DataMixingMuonWorker.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 "DataMixingMuonWorker.h"
00018 
00019 
00020 using namespace std;
00021 
00022 namespace edm
00023 {
00024 
00025   // Virtual constructor
00026 
00027   DataMixingMuonWorker::DataMixingMuonWorker() { } 
00028 
00029   // Constructor 
00030   DataMixingMuonWorker::DataMixingMuonWorker(const edm::ParameterSet& ps) : 
00031                                                             label_(ps.getParameter<std::string>("Label"))
00032 
00033   {                                                         
00034 
00035     // get the subdetector names
00036     //    this->getSubdetectorNames();  //something like this may be useful to check what we are supposed to do...
00037 
00038     // Declare the products to produce
00039 
00040     DTDigiTagSig_           = ps.getParameter<edm::InputTag>("DTDigiTagSig");
00041     RPCDigiTagSig_          = ps.getParameter<edm::InputTag>("RPCDigiTagSig");
00042 
00043     CSCstripdigi_collectionSig_   = ps.getParameter<edm::InputTag>("CSCstripdigiCollectionSig");
00044     CSCwiredigi_collectionSig_    = ps.getParameter<edm::InputTag>("CSCwiredigiCollectionSig");
00045     CSCCompdigi_collectionSig_    = ps.getParameter<edm::InputTag>("CSCCompdigiCollectionSig");
00046 
00047     DTPileInputTag_       = ps.getParameter<edm::InputTag>("DTPileInputTag");
00048     RPCPileInputTag_      = ps.getParameter<edm::InputTag>("RPCPileInputTag");
00049     CSCWirePileInputTag_  = ps.getParameter<edm::InputTag>("CSCWirePileInputTag");
00050     CSCStripPileInputTag_ = ps.getParameter<edm::InputTag>("CSCStripPileInputTag");
00051     CSCCompPileInputTag_  = ps.getParameter<edm::InputTag>("CSCCompPileInputTag");
00052 
00053     // outputs:
00054 
00055     DTDigiCollectionDM_  = ps.getParameter<std::string>("DTDigiCollectionDM");
00056     RPCDigiCollectionDM_ = ps.getParameter<std::string>("RPCDigiCollectionDM");
00057     CSCStripDigiCollectionDM_ = ps.getParameter<std::string>("CSCStripDigiCollectionDM");
00058     CSCWireDigiCollectionDM_  = ps.getParameter<std::string>("CSCWireDigiCollectionDM");
00059     CSCComparatorDigiCollectionDM_  = ps.getParameter<std::string>("CSCComparatorDigiCollectionDM");
00060 
00061 
00062   }
00063                
00064 
00065   // Virtual destructor needed.
00066   DataMixingMuonWorker::~DataMixingMuonWorker() { 
00067   }  
00068 
00069   void DataMixingMuonWorker::addMuonSignals(const edm::Event &e) { 
00070     // fill in maps of hits
00071 
00072     LogDebug("DataMixingMuonWorker")<<"===============> adding MC signals for "<<e.id();
00073 
00074     // DT
00075     // 
00076 
00077     OurDTDigis_ = new DTDigiCollection();
00078     Handle<DTDigiCollection> pDTdigis; 
00079 
00080     // Get the digis from the event
00081     if( e.getByLabel(DTDigiTagSig_, pDTdigis) ) {
00082 
00083     //    LogInfo("DataMixingMuonWorker") << "total # DT Digis: " << DTdigis->size();
00084 
00085     // Loop over digis, copying them to our own local storage
00086       const DTDigiCollection* DTdigis = pDTdigis.product();
00087       DTDigiCollection::DigiRangeIterator DLayerIt;
00088       for (DLayerIt = DTdigis->begin(); DLayerIt != DTdigis->end(); ++DLayerIt) {
00089         // The layerId
00090         const DTLayerId& layerId = (*DLayerIt).first;
00091 
00092         // Get the iterators over the digis associated with this LayerId
00093         const DTDigiCollection::Range& range = (*DLayerIt).second;
00094 
00095         OurDTDigis_->put(range, layerId);
00096       }
00097     }
00098     // RPC
00099     // 
00100 
00101     OurRPCDigis_ = new RPCDigiCollection();
00102 
00103     // Get the digis from the event
00104     Handle<RPCDigiCollection> pRPCdigis; 
00105 
00106     if( e.getByLabel(RPCDigiTagSig_, pRPCdigis) ) {
00107 
00108     // Loop over digis, copying them to our own local storage
00109 
00110       const RPCDigiCollection* RPCdigis = pRPCdigis.product();
00111       RPCDigiCollection::DigiRangeIterator RLayerIt;
00112       for (RLayerIt = RPCdigis->begin(); RLayerIt != RPCdigis->end(); ++RLayerIt) {
00113         // The layerId
00114         const RPCDetId& layerId = (*RLayerIt).first;
00115 
00116         // Get the iterators over the digis associated with this LayerId
00117         const RPCDigiCollection::Range& range = (*RLayerIt).second;
00118 
00119         OurRPCDigis_->put(range, layerId);
00120       
00121       }
00122     }
00123     // CSCStrip
00124     // 
00125 
00126     OurCSCStripDigis_ = new CSCStripDigiCollection();
00127 
00128     // Get the digis from the event
00129     Handle<CSCStripDigiCollection> pCSCStripdigis; 
00130 
00131     if( e.getByLabel(CSCstripdigi_collectionSig_, pCSCStripdigis) ) {
00132 
00133     //if(pCSCStripdigis.isValid() ) { std::cout << "Signal: have CSCStripDigis" << std::endl;}
00134     //else { std::cout << "Signal: NO CSCStripDigis" << std::endl;}
00135 
00136 
00137     // Loop over digis, copying them to our own local storage
00138 
00139       const CSCStripDigiCollection* CSCStripdigis = pCSCStripdigis.product();
00140       CSCStripDigiCollection::DigiRangeIterator CSLayerIt;
00141       for (CSLayerIt = CSCStripdigis->begin(); CSLayerIt != CSCStripdigis->end(); ++CSLayerIt) {
00142         // The layerId
00143         const CSCDetId& layerId = (*CSLayerIt).first;
00144 
00145         // Get the iterators over the digis associated with this LayerId
00146         const CSCStripDigiCollection::Range& range = (*CSLayerIt).second;
00147 
00148         OurCSCStripDigis_->put(range, layerId);
00149       }
00150     }
00151     // CSCWire
00152     // 
00153 
00154     OurCSCWireDigis_ = new CSCWireDigiCollection();
00155 
00156     // Get the digis from the event
00157     Handle<CSCWireDigiCollection> pCSCWiredigis; 
00158 
00159     if( e.getByLabel(CSCwiredigi_collectionSig_, pCSCWiredigis) ) {
00160    
00161 
00162     //if(pCSCWiredigis.isValid() ) { std::cout << "Signal: have CSCWireDigis" << std::endl;}
00163     //else { std::cout << "Signal: NO CSCWireDigis" << std::endl;}
00164     
00165     // Loop over digis, copying them to our own local storage
00166 
00167       const CSCWireDigiCollection* CSCWiredigis = pCSCWiredigis.product();
00168       CSCWireDigiCollection::DigiRangeIterator CWLayerIt;
00169       for (CWLayerIt = CSCWiredigis->begin(); CWLayerIt != CSCWiredigis->end(); ++CWLayerIt) {
00170         // The layerId
00171         const CSCDetId& layerId = (*CWLayerIt).first;
00172 
00173         // Get the iterators over the digis associated with this LayerId
00174         const CSCWireDigiCollection::Range& range = (*CWLayerIt).second;
00175 
00176         OurCSCWireDigis_->put(range, layerId);
00177       
00178       }
00179     }
00180 
00181     // CSCComparators
00182     // 
00183 
00184     OurCSCComparatorDigis_ = new CSCComparatorDigiCollection();
00185 
00186     // Get the digis from the event
00187     Handle<CSCComparatorDigiCollection> pCSCComparatordigis; 
00188 
00189     //std::cout << "CSCComp label: " << CSCDigiTagSig_.label() << " " << CSCCompdigi_collectionSig_.label() << std::endl;
00190 
00191     if( e.getByLabel(CSCCompdigi_collectionSig_, pCSCComparatordigis) ) {
00192    
00193 
00194       //if(pCSCComparatordigis.isValid() ) { std::cout << "Signal: have CSCComparatorDigis" << std::endl;}
00195       //else { std::cout << "Signal: NO CSCComparatorDigis" << std::endl;}
00196     
00197     // Loop over digis, copying them to our own local storage
00198 
00199       const CSCComparatorDigiCollection* CSCComparatordigis = pCSCComparatordigis.product();
00200       CSCComparatorDigiCollection::DigiRangeIterator CWLayerIt;
00201       for (CWLayerIt = CSCComparatordigis->begin(); CWLayerIt != CSCComparatordigis->end(); ++CWLayerIt) {
00202         // The layerId
00203         const CSCDetId& layerId = (*CWLayerIt).first;
00204 
00205         // Get the iterators over the digis associated with this LayerId
00206         const CSCComparatorDigiCollection::Range& range = (*CWLayerIt).second;
00207 
00208         OurCSCComparatorDigis_->put(range, layerId);
00209       
00210       }
00211     }
00212 
00213     
00214   } // end of addMuonSignals
00215 
00216   void DataMixingMuonWorker::addMuonPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr) {
00217   
00218     LogDebug("DataMixingMuonWorker") <<"\n===============> adding pileups from event  "<<ep->id()<<" for bunchcrossing "<<bcr;
00219 
00220     // fill in maps of hits; same code as addSignals, except now applied to the pileup events
00221 
00222     // DT
00223     // 
00224     // Get the digis from the event
00225 
00226    boost::shared_ptr<Wrapper<DTDigiCollection>  const> DTDigisPTR = 
00227           getProductByTag<DTDigiCollection>(*ep, DTPileInputTag_ );
00228  
00229    if(DTDigisPTR ) {
00230 
00231      const DTDigiCollection*  DTDigis = const_cast< DTDigiCollection * >(DTDigisPTR->product());
00232 
00233      DTDigiCollection::DigiRangeIterator DTLayerIt;
00234      for (DTLayerIt = DTDigis->begin(); DTLayerIt != DTDigis->end(); ++DTLayerIt) {
00235         // The layerId
00236         const DTLayerId& layerId = (*DTLayerIt).first;
00237 
00238         // Get the iterators over the Digis associated with this LayerId
00239         const DTDigiCollection::Range& range = (*DTLayerIt).second;
00240 
00241         OurDTDigis_->put(range, layerId);
00242       
00243       }
00244     }
00245     // RPC
00246     // 
00247 
00248     // Get the digis from the event
00249 
00250 
00251    boost::shared_ptr<Wrapper<RPCDigiCollection>  const> RPCDigisPTR = 
00252           getProductByTag<RPCDigiCollection>(*ep, RPCPileInputTag_ );
00253  
00254    if(RPCDigisPTR ) {
00255 
00256      const RPCDigiCollection*  RPCDigis = const_cast< RPCDigiCollection * >(RPCDigisPTR->product());
00257 
00258      RPCDigiCollection::DigiRangeIterator RPCLayerIt;
00259      for (RPCLayerIt = RPCDigis->begin(); RPCLayerIt != RPCDigis->end(); ++RPCLayerIt) {
00260         // The layerId
00261         const RPCDetId& layerId = (*RPCLayerIt).first;
00262 
00263         // Get the iterators over the digis associated with this LayerId
00264         const RPCDigiCollection::Range& range = (*RPCLayerIt).second;
00265 
00266         OurRPCDigis_->put(range, layerId);
00267       
00268       }
00269     }
00270 
00271     // CSCStrip
00272     // 
00273 
00274     // Get the digis from the event
00275 
00276    boost::shared_ptr<Wrapper<CSCStripDigiCollection>  const> CSCStripDigisPTR = 
00277           getProductByTag<CSCStripDigiCollection>(*ep, CSCStripPileInputTag_ );
00278  
00279    if(CSCStripDigisPTR ) {
00280 
00281      const CSCStripDigiCollection*  CSCStripDigis = const_cast< CSCStripDigiCollection * >(CSCStripDigisPTR->product());
00282 
00283      CSCStripDigiCollection::DigiRangeIterator CSCStripLayerIt;
00284      for (CSCStripLayerIt = CSCStripDigis->begin(); CSCStripLayerIt != CSCStripDigis->end(); ++CSCStripLayerIt) {
00285         // The layerId
00286         const CSCDetId& layerId = (*CSCStripLayerIt).first;
00287 
00288         // Get the iterators over the digis associated with this LayerId
00289         const CSCStripDigiCollection::Range& range = (*CSCStripLayerIt).second;
00290 
00291         OurCSCStripDigis_->put(range, layerId);
00292       
00293       }
00294     }
00295 
00296     // CSCWire
00297     // 
00298 
00299     // Get the digis from the event
00300 
00301    boost::shared_ptr<Wrapper<CSCWireDigiCollection>  const> CSCWireDigisPTR = 
00302           getProductByTag<CSCWireDigiCollection>(*ep, CSCWirePileInputTag_ );
00303  
00304    if(CSCWireDigisPTR ) {
00305 
00306      const CSCWireDigiCollection*  CSCWireDigis = const_cast< CSCWireDigiCollection * >(CSCWireDigisPTR->product());
00307 
00308      CSCWireDigiCollection::DigiRangeIterator CSCWireLayerIt;
00309      for (CSCWireLayerIt = CSCWireDigis->begin(); CSCWireLayerIt != CSCWireDigis->end(); ++CSCWireLayerIt) {
00310         // The layerId
00311         const CSCDetId& layerId = (*CSCWireLayerIt).first;
00312 
00313         // Get the iterators over the digis associated with this LayerId
00314         const CSCWireDigiCollection::Range& range = (*CSCWireLayerIt).second;
00315 
00316         OurCSCWireDigis_->put(range, layerId);
00317       
00318       }
00319     }
00320 
00321    // CSCComparators
00322    //
00323 
00324    // Get the digis from the event
00325 
00326    boost::shared_ptr<Wrapper<CSCComparatorDigiCollection>  const> CSCComparatorDigisPTR =
00327      getProductByTag<CSCComparatorDigiCollection>(*ep, CSCCompPileInputTag_ );
00328 
00329    if(CSCComparatorDigisPTR ) {
00330 
00331      const CSCComparatorDigiCollection*  CSCComparatorDigis = const_cast< CSCComparatorDigiCollection * >(CSCComparatorDigisPTR->product());
00332 
00333      CSCComparatorDigiCollection::DigiRangeIterator CSCComparatorLayerIt;
00334      for (CSCComparatorLayerIt = CSCComparatorDigis->begin(); CSCComparatorLayerIt != CSCComparatorDigis->end(); ++CSCComparatorLayerIt) {
00335        // The layerId
00336        const CSCDetId& layerId = (*CSCComparatorLayerIt).first;
00337 
00338        // Get the iterators over the digis associated with this LayerId
00339        const CSCComparatorDigiCollection::Range& range = (*CSCComparatorLayerIt).second;
00340 
00341        OurCSCComparatorDigis_->put(range, layerId);
00342 
00343      }
00344    }
00345 
00346 
00347   }
00348  
00349   void DataMixingMuonWorker::putMuon(edm::Event &e) {
00350 
00351     // collections of digis to put in the event
00352     std::auto_ptr< DTDigiCollection > DTDigiMerge( new DTDigiCollection );
00353     std::auto_ptr< RPCDigiCollection > RPCDigiMerge( new RPCDigiCollection );
00354     std::auto_ptr< CSCStripDigiCollection > CSCStripDigiMerge( new CSCStripDigiCollection );
00355     std::auto_ptr< CSCWireDigiCollection > CSCWireDigiMerge( new CSCWireDigiCollection );
00356     std::auto_ptr< CSCComparatorDigiCollection > CSCComparatorDigiMerge( new CSCComparatorDigiCollection );
00357 
00358     // Loop over DT digis, copying them from our own local storage
00359 
00360     DTDigiCollection::DigiRangeIterator DLayerIt;
00361     for (DLayerIt = OurDTDigis_->begin(); DLayerIt != OurDTDigis_->end(); ++DLayerIt) {
00362       // The layerId
00363       const DTLayerId& layerId = (*DLayerIt).first;
00364 
00365       // Get the iterators over the digis associated with this LayerId
00366       const DTDigiCollection::Range& range = (*DLayerIt).second;
00367 
00368       DTDigiMerge->put(range, layerId);
00369       
00370     }
00371 
00372     // Loop over RPC digis, copying them from our own local storage
00373 
00374     RPCDigiCollection::DigiRangeIterator RLayerIt;
00375     for (RLayerIt = OurRPCDigis_->begin(); RLayerIt != OurRPCDigis_->end(); ++RLayerIt) {
00376       // The layerId
00377       const RPCDetId& layerId = (*RLayerIt).first;
00378 
00379       // Get the iterators over the digis associated with this LayerId
00380       const RPCDigiCollection::Range& range = (*RLayerIt).second;
00381 
00382       RPCDigiMerge->put(range, layerId);
00383       
00384     }
00385     // Loop over CSCStrip digis, copying them from our own local storage
00386 
00387     CSCStripDigiCollection::DigiRangeIterator CSLayerIt;
00388     for (CSLayerIt = OurCSCStripDigis_->begin(); CSLayerIt != OurCSCStripDigis_->end(); ++CSLayerIt) {
00389       // The layerId
00390       const CSCDetId& layerId = (*CSLayerIt).first;
00391 
00392       // Get the iterators over the digis associated with this LayerId
00393       const CSCStripDigiCollection::Range& range = (*CSLayerIt).second;
00394 
00395       CSCStripDigiMerge->put(range, layerId);
00396       
00397     }
00398     // Loop over CSCStrip digis, copying them from our own local storage
00399 
00400     CSCWireDigiCollection::DigiRangeIterator CWLayerIt;
00401     for (CWLayerIt = OurCSCWireDigis_->begin(); CWLayerIt != OurCSCWireDigis_->end(); ++CWLayerIt) {
00402       // The layerId
00403       const CSCDetId& layerId = (*CWLayerIt).first;
00404 
00405       // Get the iterators over the digis associated with this LayerId
00406       const CSCWireDigiCollection::Range& range = (*CWLayerIt).second;
00407 
00408       CSCWireDigiMerge->put(range, layerId);
00409       
00410     }
00411 
00412     // Loop over CSCComparator digis, copying them from our own local storage
00413 
00414     CSCComparatorDigiCollection::DigiRangeIterator CCLayerIt;
00415     for (CCLayerIt = OurCSCComparatorDigis_->begin(); CCLayerIt != OurCSCComparatorDigis_->end(); ++CCLayerIt) {
00416       // The layerId
00417       const CSCDetId& layerId = (*CCLayerIt).first;
00418 
00419       // Get the iterators over the digis associated with this LayerId
00420       const CSCComparatorDigiCollection::Range& range = (*CCLayerIt).second;
00421 
00422       CSCComparatorDigiMerge->put(range, layerId);
00423       
00424     }
00425 
00426 
00427     // put the collection of recunstructed hits in the event   
00428     //    LogDebug("DataMixingMuonWorker") << "total # DT Merged Digis: " << DTDigiMerge->size() ;
00429     //    LogDebug("DataMixingMuonWorker") << "total # RPC Merged Digis: " << RPCDigiMerge->size() ;
00430     //    LogDebug("DataMixingMuonWorker") << "total # CSCStrip Merged Digis: " << CSCStripDigiMerge->size() ;
00431     //    LogDebug("DataMixingMuonWorker") << "total # CSCWire Merged Digis: " << CSCWireDigiMerge->size() ;
00432 
00433     e.put( DTDigiMerge );
00434     e.put( RPCDigiMerge );
00435     e.put( CSCStripDigiMerge, CSCStripDigiCollectionDM_ );
00436     e.put( CSCWireDigiMerge, CSCWireDigiCollectionDM_ );
00437     e.put( CSCComparatorDigiMerge, CSCComparatorDigiCollectionDM_ );
00438 
00439     // clear local storage for this event
00440     delete OurDTDigis_;
00441     delete OurRPCDigis_;
00442     delete OurCSCStripDigis_;
00443     delete OurCSCWireDigis_;
00444     delete OurCSCComparatorDigis_;
00445 
00446   }
00447 
00448 } //edm