CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/SimGeneral/MixingModule/plugins/MixingWorker.h

Go to the documentation of this file.
00001 #ifndef MixingWorker_h
00002 #define MixingWorker_h
00003 
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/Framework/interface/EventPrincipal.h"
00017 #include "DataFormats/Common/interface/Wrapper.h"
00018 #include "DataFormats/Common/interface/Handle.h"
00019 
00020 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00021 #include "SimDataFormats/CrossingFrame/interface/PCrossingFrame.h"
00022 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00023 #include "FWCore/Utilities/interface/InputTag.h" 
00024 
00025 #include <vector>
00026 #include <string>
00027 #include <typeinfo>
00028 #include "MixingWorkerBase.h"
00029 
00030 class SimTrack;
00031 class SimVertex;
00032 namespace edm
00033 {
00034   template <class T> 
00035     class MixingWorker: public MixingWorkerBase 
00036     {
00037     public:
00038 
00040       explicit MixingWorker() {;}
00041 
00042       /*Normal constructor*/ 
00043       MixingWorker(int minBunch,int maxBunch, int bunchSpace,std::string subdet,std::string label, std::string labelCF,int maxNbSources, InputTag& tag, InputTag& tagCF, bool mixProdStep2):
00044         MixingWorkerBase(minBunch,maxBunch,bunchSpace,subdet,label,labelCF,maxNbSources,tag,tagCF,mixProdStep2)
00045         {
00046           mixProdStep2_ = mixProdStep2;
00047         }
00048 
00050       virtual ~MixingWorker() {;}
00051 
00052     public:
00053 
00054       void setTof();
00055 
00056       virtual void put(edm::Event &e) { 
00057         std::auto_ptr<CrossingFrame<T> > pOut(crFrame_);
00058         if (!mixProdStep2_){
00059           e.put(pOut,label_);
00060           LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
00061         }
00062         else {
00063           e.put(pOut,labelCF_);
00064           LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<labelCF_;
00065         }
00066       }
00067 
00068 
00069       virtual bool checkSignal(const edm::Event &e){
00070           bool got;
00071           InputTag t;
00072           edm::Handle<std::vector<T> >  result_t;
00073           if (mixProdStep2_){   
00074              got = e.getByLabel(tagSignal_,result_t);
00075              t = InputTag(tagSignal_.label(),tagSignal_.instance());   
00076           }
00077           else{
00078              got = e.getByLabel(tag_,result_t);
00079              t = InputTag(tag_.label(),tag_.instance());
00080           }
00081           
00082           if (got)
00083                LogInfo("MixingModule") <<" Will create a CrossingFrame for "<< typeid(T).name() 
00084                                        << " with InputTag= "<< t.encode();
00085                                        
00086           return got;
00087       }
00088       
00089       
00090       virtual void createnewEDProduct(){        
00091           crFrame_=new CrossingFrame<T>(minBunch_,maxBunch_,bunchSpace_,subdet_,maxNbSources_);
00092       }
00093            
00094       virtual void setBcrOffset() {crFrame_->setBcrOffset();}
00095       virtual void setSourceOffset(const unsigned int s) {crFrame_->setSourceOffset(s);}
00096 
00097 
00098       virtual void addSignals(const edm::Event &e){
00099         if (mixProdStep2_){       
00100           edm::Handle<std::vector<T> >  result_t;
00101           bool got = e.getByLabel(tagSignal_,result_t);
00102           if (got) {
00103             LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tagSignal_;
00104             crFrame_->addSignals(result_t.product(),e.id());
00105           }
00106           else    LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tagSignal_;
00107         }
00108         else{
00109         // Default version
00110           edm::Handle<std::vector<T> >  result_t;
00111           bool got = e.getByLabel(tag_,result_t);
00112           if (got) {
00113             LogDebug("MixingModule") <<" adding " << result_t.product()->size()<<" signal objects for "<<typeid(T).name()<<" with "<<tag_;
00114             crFrame_->addSignals(result_t.product(),e.id());
00115           }
00116           else    LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tag_;
00117 
00118         }
00119         
00120       }
00121 
00122       virtual void addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
00123       // When using mixed secondary source 
00124       // Copy the data from the PCrossingFrame to the CrossingFrame
00125       virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
00126       
00127     private:
00128       CrossingFrame<T> * crFrame_;
00129       PCrossingFrame<T> * secSourceCF_;
00130 
00131       bool mixProdStep2_;
00132     };
00133 
00134 //=============== template specializations ====================================================================================
00135   template <class T>
00136     void MixingWorker<T>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset)
00137     {
00138       if (!mixProdStep2_){
00139         // default version
00140         // valid for CaloHits 
00141         boost::shared_ptr<Wrapper<std::vector<T> > const> shPtr =
00142         edm::getProductByTag<std::vector<T> >(*ep, tag_);
00143 
00144         if (shPtr) {
00145           LogDebug("MixingModule") <<shPtr->product()->size()<<"  pileup objects  added, eventNr "<<eventNr;
00146           crFrame_->addPileups(bcr,const_cast< std::vector<T> * >(shPtr->product()),eventNr);
00147         }
00148         
00149       }
00150       else
00151       {
00152         boost::shared_ptr<Wrapper<PCrossingFrame<T> > const> shPtr = getProductByTag<PCrossingFrame<T> >(*ep, tag_);
00153      
00154         if (shPtr){                     
00155           secSourceCF_ = const_cast<PCrossingFrame<T> * >(shPtr->product());
00156           LogDebug("MixingModule") << "Add PCrossingFrame<T>  eventNr " << secSourceCF_->getEventID();
00157 
00158           copyPCrossingFrame(secSourceCF_);
00159 
00160         }
00161         else
00162           LogDebug("MixingModule") << "Could not get the PCrossingFrame<T>!";
00163       }
00164     }
00165 
00166     
00167 template <>
00168     void MixingWorker<PSimHit>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
00169 
00170 template <>
00171     void MixingWorker<SimTrack>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
00172 
00173 template <>
00174     void MixingWorker<SimVertex>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
00175 
00176 template <>
00177     void MixingWorker<HepMCProduct>::addPileups(const int bcr, EventPrincipal *ep, unsigned int eventNr,int vertexoffset);
00178 
00179 template <class T>
00180     void MixingWorker<T>::setTof() {;}
00181 
00182 template <class T>
00183     void MixingWorker<T>::copyPCrossingFrame(const PCrossingFrame<T> *PCF)
00184     { 
00185       crFrame_->setBunchRange(PCF->getBunchRange()); 
00186       crFrame_->setBunchSpace(PCF->getBunchSpace());
00187       crFrame_->setMaxNbSources(PCF->getMaxNbSources());
00188       crFrame_->setSubDet(PCF->getSubDet());
00189       crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
00190       crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
00191       crFrame_->setPileups(PCF->getPileups());
00192       
00193       // For playback option
00194       crFrame_->setPileupFileNr(PCF->getPileupFileNr());
00195       crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
00196     }
00197       
00198 }//edm
00199 
00200 #endif