CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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 "FWCore/Framework/interface/ESHandle.h"
00021 #include "FWCore/Framework/interface/EventSetup.h"
00022 #include "CondFormats/DataRecord/interface/MixingRcd.h"
00023 #include "CondFormats/RunInfo/interface/MixingModuleConfig.h"
00024 
00025 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00026 #include "SimDataFormats/CrossingFrame/interface/PCrossingFrame.h"
00027 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00028 #include "FWCore/Utilities/interface/InputTag.h" 
00029 
00030 #include <vector>
00031 #include <string>
00032 #include <typeinfo>
00033 #include "MixingWorkerBase.h"
00034 
00035 class SimTrack;
00036 class SimVertex;
00037 namespace edm
00038 {
00039   template <class T> 
00040     class MixingWorker: public MixingWorkerBase 
00041     {
00042     public:
00043 
00045       explicit MixingWorker() :
00046         minBunch_(-5),
00047         maxBunch_(3),
00048         bunchSpace_(75),
00049         subdet_(std::string(" ")),
00050         label_(std::string(" ")),
00051         labelCF_(std::string(" ")),
00052         maxNbSources_(5) {
00053             tag_=InputTag();
00054             tagSignal_=InputTag();
00055         }
00056 
00057       /*Normal constructor*/ 
00058       MixingWorker(int minBunch,int maxBunch, int bunchSpace,
00059                    std::string subdet,std::string label,
00060                    std::string labelCF,int maxNbSources, InputTag& tag,
00061                    InputTag& tagCF):
00062         MixingWorkerBase(),
00063         minBunch_(minBunch),
00064         maxBunch_(maxBunch),
00065         bunchSpace_(bunchSpace),
00066         subdet_(subdet),
00067         label_(label),
00068         labelCF_(labelCF),
00069         maxNbSources_(maxNbSources),
00070         tag_(tag),
00071         tagSignal_(tagCF)
00072         {
00073         }
00074 
00076       virtual ~MixingWorker() {;}
00077 
00078     public:
00079 
00080       virtual void reload(const edm::EventSetup & setup){
00081         //get the required parameters from DB.
00082         // watch the label/tag
00083         edm::ESHandle<MixingModuleConfig> config;
00084         setup.get<MixingRcd>().get(config);
00085         minBunch_=config->minBunch();
00086         maxBunch_=config->maxBunch();
00087         bunchSpace_=config->bunchSpace();
00088       }
00089 
00090       virtual bool checkSignal(const edm::Event &e){
00091           bool got;
00092           InputTag t;
00093           edm::Handle<std::vector<T> >  result_t;
00094           got = e.getByLabel(tag_,result_t);
00095           t = InputTag(tag_.label(),tag_.instance());
00096           
00097           if (got)
00098                LogInfo("MixingModule") <<" Will create a CrossingFrame for "<< typeid(T).name() 
00099                                        << " with InputTag= "<< t.encode();
00100                                        
00101           return got;
00102       }
00103       
00104       
00105       virtual void createnewEDProduct(){        
00106           crFrame_=new CrossingFrame<T>(minBunch_,maxBunch_,bunchSpace_,subdet_,maxNbSources_);
00107       }
00108            
00109       virtual void addSignals(const edm::Event &e){
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         } else {
00116           LogInfo("MixingModule") <<"!!!!!!! Did not get any signal data for "<<typeid(T).name()<<", with "<<tag_;
00117         }
00118       }
00119 
00120       virtual void addPileups(const EventPrincipal &ep, unsigned int eventNr);
00121 
00122       virtual void setBcrOffset() {crFrame_->setBcrOffset();}
00123       virtual void setSourceOffset(const unsigned int s) {crFrame_->setSourceOffset(s);}
00124 
00125       void setTof();
00126 
00127       virtual void put(edm::Event &e) { 
00128         std::auto_ptr<CrossingFrame<T> > pOut(crFrame_);
00129         e.put(pOut,label_);
00130         LogDebug("MixingModule") <<" CF was put for type "<<typeid(T).name()<<" with "<<label_;
00131       }
00132 
00133 
00134       // When using mixed secondary source 
00135       // Copy the data from the PCrossingFrame to the CrossingFrame
00136       virtual void copyPCrossingFrame(const PCrossingFrame<T> *PCF);
00137       
00138     private:
00139       int minBunch_;
00140       int maxBunch_;
00141       int bunchSpace_;
00142       std::string const subdet_;
00143       std::string const label_;
00144       std::string const labelCF_;
00145       unsigned int const maxNbSources_;
00146       InputTag tag_;
00147       InputTag tagSignal_;
00148 
00149       CrossingFrame<T> * crFrame_;
00150       PCrossingFrame<T> * secSourceCF_;
00151     };
00152 
00153   template <typename T>
00154   void  MixingWorker<T>::addPileups(const EventPrincipal &ep, unsigned int eventNr) {
00155     boost::shared_ptr<Wrapper<std::vector<T> > const> shPtr = getProductByTag<std::vector<T> >(ep, tag_);
00156     if (shPtr) {
00157       LogDebug("MixingModule") << shPtr->product()->size() << "  pileup objects  added, eventNr " << eventNr;
00158       crFrame_->setPileupPtr(shPtr);
00159       crFrame_->addPileups(*shPtr->product());
00160     }
00161   }
00162 
00163 //=============== template specializations ====================================================================================
00164 template <>
00165     void MixingWorker<HepMCProduct>::addPileups(const EventPrincipal &ep, unsigned int eventNr);
00166     
00167 template <class T>
00168     void MixingWorker<T>::setTof() {;}
00169 
00170 template <class T>
00171     void MixingWorker<T>::copyPCrossingFrame(const PCrossingFrame<T> *PCF)
00172     { 
00173       crFrame_->setBunchRange(PCF->getBunchRange()); 
00174       crFrame_->setBunchSpace(PCF->getBunchSpace());
00175       crFrame_->setMaxNbSources(PCF->getMaxNbSources());
00176       crFrame_->setSubDet(PCF->getSubDet());
00177       crFrame_->setPileupOffsetsBcr(PCF->getPileupOffsetsBcr());
00178       crFrame_->setPileupOffsetsSource(PCF->getPileupOffsetsSource());
00179       crFrame_->setPileups(PCF->getPileups());
00180       
00181       // For playback option
00182       crFrame_->setPileupFileNr(PCF->getPileupFileNr());
00183       crFrame_->setIdFirstPileup(PCF->getIdFirstPileup());
00184     }
00185       
00186 }//edm
00187 
00188 #endif