CMS 3D CMS Logo

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