CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

edm::MixingModule Class Reference

#include <MixingModule.h>

Inheritance diagram for edm::MixingModule:
edm::BMixingModule edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Types

typedef std::vector
< DigiAccumulatorMixMod * > 
Accumulators

Public Member Functions

void accumulateEvent (Event const &event, EventSetup const &setup)
void accumulateEvent (PileUpEventPrincipal const &event, EventSetup const &setup)
virtual void beginJob ()
virtual void beginLuminosityBlock (LuminosityBlock &l1, EventSetup const &c)
virtual void beginRun (Run &r1, EventSetup const &c)
virtual void endLuminosityBlock (LuminosityBlock &l1, EventSetup const &c)
virtual void endRun (Run &r1, EventSetup const &c)
void finalizeEvent (Event &event, EventSetup const &setup)
void initializeEvent (Event const &event, EventSetup const &setup)
 MixingModule (const edm::ParameterSet &ps)
virtual void reload (const edm::EventSetup &)
virtual ~MixingModule ()

Private Member Functions

virtual void addSignals (const edm::Event &e, const edm::EventSetup &es)
virtual void branchesActivate (const std::string &friendlyName, const std::string &subdet, InputTag &tag, std::string &label)
virtual void checkSignal (const edm::Event &e)
void createDigiAccumulators (const edm::ParameterSet &mixingPSet)
virtual void createnewEDProduct ()
virtual void doPileUp (edm::Event &e, const edm::EventSetup &es)
void pileAllWorkers (EventPrincipal const &ep, int bcr, int id, int &offset, const edm::EventSetup &setup)
virtual void put (edm::Event &e, const edm::EventSetup &es)

Private Attributes

Accumulators digiAccumulators_
InputTag inputTagPlayback_
bool mixProdStep1_
bool mixProdStep2_
CrossingFramePlaybackInfoExtendedplaybackInfo_
bool useCurrentProcessOnly_
std::vector< std::string > wantedBranches_
std::vector< MixingWorkerBase * > workers_
std::vector< MixingWorkerBase * > workersObjects_

Detailed Description

Definition at line 43 of file MixingModule.h.


Member Typedef Documentation

Definition at line 45 of file MixingModule.h.


Constructor & Destructor Documentation

data refman pasoursint CMSSW_6_1_1 src SimGeneral MixingModule plugins MixingModule cc data refman pasoursint CMSSW_6_1_1 src SimGeneral MixingModule plugins MixingModule cc MixingModule::MixingModule ( const edm::ParameterSet ps) [explicit]

standard constructor

Definition at line 32 of file MixingModule.cc.

References edm::binary_search_all(), edm::InputTag::encode(), edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), edm::ParameterSet::getUntrackedParameter(), edm::InputTag::instance(), diffTwoXMLs::label, LogDebug, cscdqm::h::names, edm::sort_all(), AlCaHLTBitMon_QueryRunRegistry::string, subdets, GlobalPosition_Frontier_DevDB_cff::tag, and o2o::tags.

  {
    if (!mixProdStep1_ && !mixProdStep2_) LogInfo("MixingModule") << " The MixingModule was run in the Standard mode.";
    if (mixProdStep1_) LogInfo("MixingModule") << " The MixingModule was run in the Step1 mode. It produces a mixed secondary source.";
    if (mixProdStep2_) LogInfo("MixingModule") << " The MixingModule was run in the Step2 mode. It uses a mixed secondary source.";

    useCurrentProcessOnly_=false;
    if (ps_mix.exists("useCurrentProcessOnly")) {
      useCurrentProcessOnly_=ps_mix.getParameter<bool>("useCurrentProcessOnly");
      LogInfo("MixingModule") <<" using given Parameter 'useCurrentProcessOnly' ="<<useCurrentProcessOnly_;
    }
    std::string labelPlayback;    
    if (ps_mix.exists("LabelPlayback")) {
      labelPlayback = ps_mix.getParameter<std::string>("LabelPlayback");
    }
    if (labelPlayback.empty()) {
      labelPlayback = ps_mix.getParameter<std::string>("@module_label");
    }
    inputTagPlayback_ = InputTag(labelPlayback, "");

    ParameterSet ps=ps_mix.getParameter<ParameterSet>("mixObjects");
    std::vector<std::string> names = ps.getParameterNames();
    for(std::vector<std::string>::iterator it=names.begin();it!= names.end();++it) {
      ParameterSet pset=ps.getParameter<ParameterSet>((*it));
      if (!pset.exists("type")) continue; //to allow replacement by empty pset
      std::string object = pset.getParameter<std::string>("type");
      std::vector<InputTag> tags=pset.getParameter<std::vector<InputTag> >("input");

      //if (!mixProdStep2_) {

          InputTag tagCF = InputTag();
          std::string labelCF = " ";

          //SimTracks
          if (object=="SimTrack") {
            InputTag tag;
            if (tags.size()>0) tag=tags[0];
            std::string label;

            branchesActivate(TypeID(typeid(std::vector<SimTrack>)).friendlyClassName(),std::string(""),tag,label);
            bool makeCrossingFrame = pset.getUntrackedParameter<bool>("makeCrossingFrame", false);
            if(makeCrossingFrame) {
              workersObjects_.push_back(new MixingWorker<SimTrack>(minBunch_,maxBunch_,bunchSpace_,std::string(""),label,labelCF,maxNbSources_,tag,tagCF));
              produces<CrossingFrame<SimTrack> >(label);
            }

            LogInfo("MixingModule") <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
            //            std::cout <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label<<std::endl;


          } else if (object=="SimVertex") {
            InputTag tag;
            if (tags.size()>0) tag=tags[0];
            std::string label;

            branchesActivate(TypeID(typeid(std::vector<SimVertex>)).friendlyClassName(),std::string(""),tag,label);
            bool makeCrossingFrame = pset.getUntrackedParameter<bool>("makeCrossingFrame", false);
            if(makeCrossingFrame) {
              workersObjects_.push_back(new MixingWorker<SimVertex>(minBunch_,maxBunch_,bunchSpace_,std::string(""),label,labelCF,maxNbSources_,tag,tagCF));
              produces<CrossingFrame<SimVertex> >(label);
            }

            LogInfo("MixingModule") <<"Will mix "<<object<<"s with InputTag "<<tag.encode()<<", label will be "<<label;
            //            std::cout <<"Will mix "<<object<<"s with InputTag "<<tag.encode()<<", label will be "<<label<<std::endl;

          } else if (object=="HepMCProduct") {
            InputTag tag;
            if (tags.size()>0) tag=tags[0];
            std::string label;

            branchesActivate(TypeID(typeid(HepMCProduct)).friendlyClassName(),std::string(""),tag,label);
            bool makeCrossingFrame = pset.getUntrackedParameter<bool>("makeCrossingFrame", false);
            if(makeCrossingFrame) {
              workersObjects_.push_back(new MixingWorker<HepMCProduct>(minBunch_,maxBunch_,bunchSpace_,std::string(""),label,labelCF,maxNbSources_,tag,tagCF));
              produces<CrossingFrame<HepMCProduct> >(label);
            }

            LogInfo("MixingModule") <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
            //            std::cout <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label<<std::endl;

          } else if (object=="PCaloHit") {
            std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
            std::vector<std::string> crossingFrames=pset.getUntrackedParameter<std::vector<std::string> >("crossingFrames", std::vector<std::string>());
            sort_all(crossingFrames);
            for (unsigned int ii=0;ii<subdets.size();++ii) {
              InputTag tag;
              if (tags.size()==1) tag=tags[0];
              else if(tags.size()>1) tag=tags[ii];
              std::string label;

              branchesActivate(TypeID(typeid(std::vector<PCaloHit>)).friendlyClassName(),subdets[ii],tag,label);
              if(binary_search_all(crossingFrames, tag.instance())) {
                workersObjects_.push_back(new MixingWorker<PCaloHit>(minBunch_,maxBunch_,bunchSpace_,subdets[ii],label,labelCF,maxNbSources_,tag,tagCF));
                produces<CrossingFrame<PCaloHit> >(label);
              }

              LogInfo("MixingModule") <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
              //              std::cout <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label<<std::endl;

            }

          } else if (object=="PSimHit") {
            std::vector<std::string> subdets=pset.getParameter<std::vector<std::string> >("subdets");
            std::vector<std::string> crossingFrames=pset.getUntrackedParameter<std::vector<std::string> >("crossingFrames", std::vector<std::string>());
            sort_all(crossingFrames);
            for (unsigned int ii=0;ii<subdets.size();++ii) {
              InputTag tag;
              if (tags.size()==1) tag=tags[0];
              else if(tags.size()>1) tag=tags[ii];
              std::string label;

              branchesActivate(TypeID(typeid(std::vector<PSimHit>)).friendlyClassName(),subdets[ii],tag,label);
              if(binary_search_all(crossingFrames, tag.instance())) {
                workersObjects_.push_back(new MixingWorker<PSimHit>(minBunch_,maxBunch_,bunchSpace_,subdets[ii],label,labelCF,maxNbSources_,tag,tagCF));
                produces<CrossingFrame<PSimHit> >(label);
              }

              LogInfo("MixingModule") <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label;
              //              std::cout <<"Will mix "<<object<<"s with InputTag= "<<tag.encode()<<", label will be "<<label<<std::endl;
            }
          } else {
            LogWarning("MixingModule") <<"You have asked to mix an unknown type of object("<<object<<").\n If you want to include it in mixing, please contact the authors of the MixingModule!";
          }
      //} //if for mixProdStep2
    }//while over the mixObjects parameters

    sort_all(wantedBranches_);
    for (unsigned int branch=0;branch<wantedBranches_.size();++branch) LogDebug("MixingModule")<<"Will keep branch "<<wantedBranches_[branch]<<" for mixing ";
dropUnwantedBranches(wantedBranches_);

    produces<PileupMixingContent>();

    produces<CrossingFramePlaybackInfoExtended>();

    // Create and configure digitizers
    createDigiAccumulators(ps_mix);
  }


MixingModule::~MixingModule ( ) [virtual]

Default destructor

Definition at line 236 of file MixingModule.cc.

                                       {
        delete *accItr;
    }
  }

  void MixingModule::addSignals(const edm::Event &e, const edm::EventSetup& setup) {

Member Function Documentation

void MixingModule::accumulateEvent ( edm::Event const &  event,
edm::EventSetup const &  setup 
)

Definition at line 440 of file MixingModule.cc.

Referenced by pileAllWorkers().

void MixingModule::accumulateEvent ( PileUpEventPrincipal const &  event,
edm::EventSetup const &  setup 
)

Definition at line 447 of file MixingModule.cc.

void MixingModule::addSignals ( const edm::Event e,
const edm::EventSetup es 
) [private, virtual]

Reimplemented from edm::BMixingModule.

Definition at line 248 of file MixingModule.cc.

                                                    {
      workers_[ii]->addSignals(e);
    }
  }

  void MixingModule::pileAllWorkers(EventPrincipal const& eventPrincipal,
virtual void edm::MixingModule::beginJob ( void  ) [inline, virtual]

Reimplemented from edm::EDProducer.

Definition at line 53 of file MixingModule.h.

{}
void MixingModule::beginLuminosityBlock ( edm::LuminosityBlock lumi,
edm::EventSetup const &  setup 
) [virtual]

Reimplemented from edm::BMixingModule.

Definition at line 420 of file MixingModule.cc.

                                                                                            {
void MixingModule::beginRun ( edm::Run run,
edm::EventSetup const &  setup 
) [virtual]

Reimplemented from edm::BMixingModule.

Definition at line 408 of file MixingModule.cc.

                                                                   {
void MixingModule::branchesActivate ( const std::string &  friendlyName,
const std::string &  subdet,
InputTag tag,
std::string &  label 
) [private, virtual]

Definition at line 202 of file MixingModule.cc.

References EgammaHLTValidationUtils::getProcessName(), and AlCaHLTBitMon_QueryRunRegistry::string.

                                {
      const std::string processName = edm::Service<edm::service::TriggerNamesService>()->getProcessName();
      tag = InputTag(tag.label(),tag.instance(),processName);
    }
  }

  void MixingModule::checkSignal(const edm::Event &e){
void MixingModule::checkSignal ( const edm::Event e) [private, virtual]

Reimplemented from edm::BMixingModule.

Definition at line 216 of file MixingModule.cc.

References workers_, and workersObjects_.

                                                            {
        if (workersObjects_[ii]->checkSignal(e)){
          workers_.push_back(workersObjects_[ii]);
        }
      }
    }
  }

  void MixingModule::createnewEDProduct() {
void MixingModule::createDigiAccumulators ( const edm::ParameterSet mixingPSet) [private]

Definition at line 176 of file MixingModule.cc.

References digiAccumulators_, reco::get(), and edm::ParameterSet::getParameterSet().

                             : digiNames) {
        ParameterSet const& pset = digiPSet.getParameterSet(digiName);
        std::auto_ptr<DigiAccumulatorMixMod> accumulator = std::auto_ptr<DigiAccumulatorMixMod>(DigiAccumulatorMixModFactory::get()->makeDigiAccumulator(pset, *this));
        // Create appropriate DigiAccumulator
        if(accumulator.get() != 0) {
          digiAccumulators_.push_back(accumulator.release());
        }
    }
  }

  void MixingModule::reload(const edm::EventSetup & setup){
void MixingModule::createnewEDProduct ( ) [private, virtual]

Reimplemented from edm::BMixingModule.

Definition at line 226 of file MixingModule.cc.

                                                   {
      workers_[ii]->createnewEDProduct();
    }
  }

  // Virtual destructor needed.
void MixingModule::doPileUp ( edm::Event e,
const edm::EventSetup es 
) [private, virtual]

Reimplemented from edm::BMixingModule.

Definition at line 274 of file MixingModule.cc.

References Exception, edm::Event::getByLabel(), and inputTagPlayback_.

                   {
      bool got = e.getByLabel(inputTagPlayback_, playbackInfo_H);
      if (!got) {
        throw cms::Exception("MixingProductNotFound") << " No "
          "CrossingFramePlaybackInfoExtended on the input file, but playback "
          "option set!!!!! Please change the input file if you really want "
          "playback!!!!!!"  << std::endl;
      }
    }

    // source[0] is "real" pileup.  Check to see that this is what we are doing.

    std::vector<int> PileupList;
    PileupList.clear();
    TrueNumInteractions_.clear();

    boost::shared_ptr<PileUp> source0 = inputSources_[0];

    if((source0 && source0->doPileUp() ) && !playback_) {
      //    if((!inputSources_[0] || !inputSources_[0]->doPileUp()) && !playback_ ) 

      // Pre-calculate all pileup distributions before we go fishing for events

      source0->CalculatePileup(minBunch_, maxBunch_, PileupList, TrueNumInteractions_);

    }

    //    for (int bunchIdx = minBunch_; bunchIdx <= maxBunch_; ++bunchIdx) {
    //  std::cout << " bunch ID, Pileup, True " << bunchIdx << " " << PileupList[bunchIdx-minBunch_] << " " <<  TrueNumInteractions_[bunchIdx-minBunch_] << std::endl;
    //}

    for (int bunchIdx = minBunch_; bunchIdx <= maxBunch_; ++bunchIdx) {
      for (size_t setBcrIdx=0; setBcrIdx<workers_.size(); ++setBcrIdx) {
        workers_[setBcrIdx]->setBcrOffset();
      }
      for(Accumulators::const_iterator accItr = digiAccumulators_.begin(), accEnd = digiAccumulators_.end(); accItr != accEnd; ++accItr) {
        (*accItr)->initializeBunchCrossing(e, setup, bunchIdx);
      }

      for (size_t readSrcIdx=0; readSrcIdx<maxNbSources_; ++readSrcIdx) {
        boost::shared_ptr<PileUp> source = inputSources_[readSrcIdx];   // this looks like we create
                                                                        // new PileUp objects for each
                                                                        // source for each event?
                                                                        // Why?
        for (size_t setSrcIdx=0; setSrcIdx<workers_.size(); ++setSrcIdx) {
          workers_[setSrcIdx]->setSourceOffset(readSrcIdx);
        }

        if (!source || !source->doPileUp()) continue;

        int NumPU_Events = 0;

        if(readSrcIdx ==0 && !playback_) {
           NumPU_Events = PileupList[bunchIdx - minBunch_];
        } else {
           NumPU_Events = 1;
        }  // non-minbias pileup only gets one event for now. Fix later if desired.

        //        int eventId = 0;
        int vertexOffset = 0;

        if (!playback_) {
          inputSources_[readSrcIdx]->readPileUp(e.id(), recordEventID,
            boost::bind(&MixingModule::pileAllWorkers, boost::ref(*this), _1, bunchIdx,
                        _2, vertexOffset, boost::ref(setup)), NumPU_Events
            );
          playbackInfo_->setStartEventId(recordEventID, readSrcIdx, bunchIdx);
        } else {
          int dummyId = 0;
          const std::vector<edm::EventID>& playEventID =
            playbackInfo_H->getStartEventId(readSrcIdx, bunchIdx);
          if(readSrcIdx == 0) {
            PileupList.push_back(playEventID.size());
            TrueNumInteractions_.push_back(playEventID.size());
          }
          inputSources_[readSrcIdx]->playPileUp(
            playEventID,
            boost::bind(&MixingModule::pileAllWorkers, boost::ref(*this), _1, bunchIdx,
                        dummyId, vertexOffset, boost::ref(setup))
            );
        }
      }
      for(Accumulators::const_iterator accItr = digiAccumulators_.begin(), accEnd = digiAccumulators_.end(); accItr != accEnd; ++accItr) {
        (*accItr)->finalizeBunchCrossing(e, setup, bunchIdx);
      }
    }

    // Keep track of pileup accounting...

    std::auto_ptr<PileupMixingContent> PileupMixing_;

    std::vector<int> numInteractionList;
    std::vector<int> bunchCrossingList;
    std::vector<float> TrueInteractionList;

    //Makin' a list: Basically, we don't care about the "other" sources at this point.
    for (int bunchCrossing=minBunch_;bunchCrossing<=maxBunch_;++bunchCrossing) {
      bunchCrossingList.push_back(bunchCrossing);
      if(!inputSources_[0] || !inputSources_[0]->doPileUp()) {
        numInteractionList.push_back(0);
        TrueInteractionList.push_back(0);
      }
      else {
        numInteractionList.push_back(PileupList[bunchCrossing-minBunch_]);
        TrueInteractionList.push_back((TrueNumInteractions_)[bunchCrossing-minBunch_]);
      }
    }


    PileupMixing_ = std::auto_ptr<PileupMixingContent>(new PileupMixingContent(bunchCrossingList,
                                                                               numInteractionList,
                                                                               TrueInteractionList));

    e.put(PileupMixing_);

    // we have to do the ToF transformation for PSimHits once all pileup has been added
    for (unsigned int ii=0;ii<workers_.size();++ii) {
        workers_[ii]->setTof();
      workers_[ii]->put(e);
    }
 }

  void MixingModule::put(edm::Event &e, const edm::EventSetup& setup) {
void MixingModule::endLuminosityBlock ( edm::LuminosityBlock lumi,
edm::EventSetup const &  setup 
) [virtual]

Reimplemented from edm::BMixingModule.

Definition at line 426 of file MixingModule.cc.

void MixingModule::endRun ( edm::Run run,
edm::EventSetup const &  setup 
) [virtual]

Reimplemented from edm::BMixingModule.

Definition at line 414 of file MixingModule.cc.

                                                                                              {
void MixingModule::finalizeEvent ( edm::Event event,
edm::EventSetup const &  setup 
) [virtual]

Reimplemented from edm::BMixingModule.

Definition at line 454 of file MixingModule.cc.

void MixingModule::initializeEvent ( edm::Event const &  event,
edm::EventSetup const &  setup 
) [virtual]

Reimplemented from edm::BMixingModule.

Definition at line 433 of file MixingModule.cc.

void MixingModule::pileAllWorkers ( EventPrincipal const &  ep,
int  bcr,
int  id,
int &  offset,
const edm::EventSetup setup 
) [private]

Definition at line 259 of file MixingModule.cc.

References accumulateEvent(), edm::BMixingModule::bunchSpace_, LogDebug, edm::BMixingModule::vertexoffset, and workers_.

                                                                {
    PileUpEventPrincipal pep(eventPrincipal, bunchCrossing, bunchSpace_, eventId, vertexOffset);
    accumulateEvent(pep, setup);

    for (unsigned int ii=0;ii<workers_.size();++ii) {
      LogDebug("MixingModule") <<" merging Event:  id " << eventPrincipal.id();
      //      std::cout <<"PILEALLWORKERS merging Event:  id " << eventPrincipal.id() << std::endl;

        workers_[ii]->addPileups(bunchCrossing,eventPrincipal, eventId, vertexoffset);
    }
  }

  void MixingModule::doPileUp(edm::Event &e, const edm::EventSetup& setup) {
void MixingModule::put ( edm::Event e,
const edm::EventSetup es 
) [private, virtual]

Reimplemented from edm::BMixingModule.

Definition at line 400 of file MixingModule.cc.

References playbackInfo_, and edm::Event::put().

                       {
      std::auto_ptr<CrossingFramePlaybackInfoExtended> pOut(playbackInfo_);
      e.put(pOut);
    }
  }

  void MixingModule::beginRun(edm::Run& run, edm::EventSetup const& setup) {
void MixingModule::reload ( const edm::EventSetup setup) [virtual]

Reimplemented from edm::BMixingModule.

Definition at line 189 of file MixingModule.cc.

                                                          {
      workersObjects_[ii]->reload(setup);
    }
  }

  void MixingModule::branchesActivate(const std::string &friendlyName, const std::string &subdet, InputTag &tag, std::string &label) {

Member Data Documentation

Definition at line 95 of file MixingModule.h.

Referenced by createDigiAccumulators().

Definition at line 84 of file MixingModule.h.

Referenced by doPileUp().

Reimplemented from edm::BMixingModule.

Definition at line 86 of file MixingModule.h.

Reimplemented from edm::BMixingModule.

Definition at line 85 of file MixingModule.h.

Definition at line 87 of file MixingModule.h.

Referenced by put().

Definition at line 92 of file MixingModule.h.

std::vector<std::string> edm::MixingModule::wantedBranches_ [private]

Definition at line 91 of file MixingModule.h.

Definition at line 89 of file MixingModule.h.

Referenced by checkSignal(), and pileAllWorkers().

Definition at line 90 of file MixingModule.h.

Referenced by checkSignal().