CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/SimGeneral/MixingModule/plugins/MixingWorker.cc

Go to the documentation of this file.
00001 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00002 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00003 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00004 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00005 #include "SimDataFormats/CrossingFrame/interface/PCrossingFrame.h"
00006 #include "MixingWorker.h"
00007 
00008 #include "boost/shared_ptr.hpp"
00009 
00010 namespace edm {
00011   template <>
00012   void MixingWorker<PSimHit>::addPileups(const int bcr, const EventPrincipal &ep,unsigned int eventNr,int vertexoffset)
00013   {
00014     if (!mixProdStep2_){ 
00015       //    default version changed for high/low treatment
00016       boost::shared_ptr<Wrapper<std::vector<PSimHit> > const> shPtr = getProductByTag<std::vector<PSimHit> >(ep, tag_);
00017         if (shPtr) {
00018           LogDebug("MixingModule") <<shPtr->product()->size()<<"  pileup objects  added, eventNr "<<eventNr;
00019           crFrame_->setPileupPtr(shPtr);
00020           crFrame_->addPileups(bcr,const_cast< std::vector<PSimHit> * > (shPtr->product()),eventNr);
00021         }
00022       } else{ // In case mixProdStep2_=true
00023         boost::shared_ptr<Wrapper<PCrossingFrame<PSimHit> > const> shPtr = getProductByTag<PCrossingFrame<PSimHit> >(ep, tag_);
00024         if (shPtr) { 
00025           crFrame_->setPileupPtr(shPtr);
00026           secSourceCF_ = const_cast<PCrossingFrame<PSimHit> * >(shPtr->product());
00027           LogDebug("MixingModule") << "Add PCrossingFrame<PSimHit>,  eventNr " << secSourceCF_->getEventID();
00028           copyPCrossingFrame(secSourceCF_);       
00029         } 
00030         else 
00031           LogDebug("MixingModule") << "Could not get the PCrossingFrame<PSimHit>!";
00032     }//else mixProd2    
00033   }
00034 
00035 
00036   template <>
00037   void  MixingWorker<SimTrack>::addPileups(const int bcr, const EventPrincipal &ep,unsigned int eventNr,int vertexoffset)
00038   { 
00039     if (!mixProdStep2_){ 
00040       // default version changed to transmit vertexoffset
00041       boost::shared_ptr<Wrapper<std::vector<SimTrack> > const> shPtr = getProductByTag<std::vector<SimTrack> >(ep, tag_);
00042       
00043       if (shPtr) {
00044         LogDebug("MixingModule") <<shPtr->product()->size()<<"  pileup objects  added, eventNr "<<eventNr;
00045         crFrame_->setPileupPtr(shPtr);
00046         crFrame_->addPileups(bcr,const_cast< std::vector<SimTrack> * > (shPtr->product()),eventNr,vertexoffset);
00047       }
00048     }
00049     else
00050     { // In case mixProdStep2_=true     
00051         boost::shared_ptr<Wrapper<PCrossingFrame<SimTrack> > const> shPtr = getProductByTag<PCrossingFrame<SimTrack> >(ep, tag_);
00052 
00053         if (shPtr){
00054           crFrame_->setPileupPtr(shPtr);
00055           secSourceCF_ = const_cast<PCrossingFrame<SimTrack> * >(shPtr->product());
00056           LogDebug("MixingModule") << "Add PCrossingFrame<SimTrack>,  eventNr " << secSourceCF_->getEventID();
00057                 
00058           // Get PCrossingFrame data members values from the mixed secondary sources file
00059           copyPCrossingFrame(secSourceCF_);
00060         }
00061         else 
00062           LogDebug("MixingModule") << "Could not get the PCrossingFrame<SimTrack>!";
00063     }
00064   }
00065 
00066 
00067   template <>
00068   void MixingWorker<SimVertex>::addPileups(const int bcr, const EventPrincipal &ep,unsigned int eventNr,int vertexoffset)
00069   {
00070   
00071     if (!mixProdStep2_){ 
00072       // default version changed to take care of vertexoffset
00073       boost::shared_ptr<Wrapper<std::vector<SimVertex> > const> shPtr = getProductByTag<std::vector<SimVertex> >(ep, tag_);
00074         
00075       if (shPtr) {
00076         LogDebug("MixingModule") <<shPtr->product()->size()<<"  pileup objects  added, eventNr "<<eventNr;
00077         vertexoffset+=shPtr->product()->size();
00078         crFrame_->setPileupPtr(shPtr);
00079         crFrame_->addPileups(bcr,const_cast< std::vector<SimVertex> * > (shPtr->product()),eventNr);
00080       }
00081     }
00082     else {
00083       
00084       boost::shared_ptr<Wrapper<PCrossingFrame<SimVertex> > const> shPtr = getProductByTag<PCrossingFrame<SimVertex> >(ep, tag_);
00085       
00086       if (shPtr){
00087         crFrame_->setPileupPtr(shPtr);          
00088         secSourceCF_ = const_cast<PCrossingFrame<SimVertex> * >(shPtr->product());
00089         LogDebug("MixingModule") << "Add PCrossingFrame<SimVertex>,  eventNr " << secSourceCF_->getEventID();    
00090         
00091         copyPCrossingFrame(secSourceCF_);      
00092       }
00093       else
00094         LogDebug("MixingModule") << "Could not get the PCrossingFrame<SimVertex>!";             
00095     }
00096   }
00097 
00098   template <>
00099   void MixingWorker<HepMCProduct>::addPileups(const int bcr, const EventPrincipal& ep,unsigned int eventNr,int vertexoffset)
00100   {
00101     if (!mixProdStep2_){ 
00102       // default version
00103       // HepMCProduct does not come as a vector....
00104       boost::shared_ptr<Wrapper<HepMCProduct> const> shPtr = getProductByTag<HepMCProduct>(ep, tag_);
00105         if (shPtr) {
00106           LogDebug("MixingModule") <<"HepMC pileup objects  added, eventNr "<<eventNr;
00107             crFrame_->setPileupPtr(shPtr);
00108             crFrame_->addPileups(bcr,const_cast<HepMCProduct*> (shPtr->product()),eventNr);
00109         }
00110     }
00111     else {
00112       // Mixproduction version: step2
00113       boost::shared_ptr<Wrapper<PCrossingFrame<HepMCProduct> > const> shPtr = getProductByTag<PCrossingFrame<HepMCProduct> >(ep, tag_);
00114 
00115       if (shPtr){       
00116         crFrame_->setPileupPtr(shPtr);
00117         secSourceCF_ = const_cast<PCrossingFrame<HepMCProduct> * >(shPtr->product());
00118         LogDebug("MixingModule") << "Add PCrossingFrame<HepMCProduct>,  eventNr " << secSourceCF_->getEventID();
00119         
00120         copyPCrossingFrame(secSourceCF_);
00121       }
00122       else
00123         LogDebug("MixingModule") << "Could not get the PCrossingFrame<HepMCProduct>!";
00124     }
00125   }
00126 
00127   template <>
00128   void MixingWorker<HepMCProduct>::addSignals(const Event &e)
00129   { 
00130     if (mixProdStep2_){
00131       //HepMC - here the interface is different!!!
00132       Handle<HepMCProduct>  result_t;
00133       bool got = e.getByLabel(tagSignal_,result_t);
00134       if (got) {
00135         LogDebug("MixingModule") <<" adding HepMCProduct from signal event  with "<<tagSignal_;
00136         crFrame_->addSignals(result_t.product(),e.id());  
00137       }
00138       else LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for HepMCProduct with "<<tagSignal_;
00139     }
00140     else{
00141       //HepMC - here the interface is different!!!
00142       Handle<HepMCProduct>  result_t;
00143       bool got = e.getByLabel(tag_,result_t);
00144       if (got) {
00145         LogDebug("MixingModule") <<" adding HepMCProduct from signal event  with "<<tag_;
00146         crFrame_->addSignals(result_t.product(),e.id());  
00147       }
00148       else LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for HepMCProduct with "<<tag_;
00149 
00150     }
00151       
00152   }
00153   
00154   template <>
00155   bool MixingWorker<HepMCProduct>::checkSignal(const Event &e)
00156       {   
00157           bool got;
00158           InputTag t;
00159           
00160           Handle<HepMCProduct>  result_t;
00161           if (mixProdStep2_){
00162              got = e.getByLabel(tagSignal_,result_t);
00163              t = InputTag(tagSignal_.label(),tagSignal_.instance());   
00164           }
00165           else{      
00166              got = e.getByLabel(tag_,result_t);
00167              t = InputTag(tag_.label(),tag_.instance());
00168           }
00169           
00170           if (got)
00171                LogInfo("MixingModule") <<" Will create a CrossingFrame for HepMCProduct with "
00172                                        << " with InputTag= "<< t.encode();
00173                                        
00174           return got;
00175   }
00176       
00177 }//namespace edm