CMS 3D CMS Logo

Public Member Functions | Private Attributes

edm::PileUp Class Reference

#include <PileUp.h>

List of all members.

Public Member Functions

double averageNumber () const
void CalculatePileup (int MinBunch, int MaxBunch, std::vector< int > &PileupSelection, std::vector< float > &TrueNumInteractions)
bool doPileUp ()
void dropUnwantedBranches (std::vector< std::string > const &wantedBranches)
void endJob ()
 PileUp (ParameterSet const &pset, double averageNumber, TH1F *const histo, const bool playback)
template<typename T >
void playPileUp (const std::vector< edm::EventID > &ids, T eventOperator)
bool poisson () const
template<typename T >
void readPileUp (std::vector< edm::EventID > &ids, T eventOperator, const int NumPU)
 ~PileUp ()

Private Attributes

double const averageNumber_
bool const fixed_
bool fixed_OOT_
TH1F * h1f
TH1F *const histo_
bool const histoDistribution_
TH1F * hprobFunction
VectorInputSource *const input_
int const intAverage_
int intFixed_OOT_
bool manage_OOT_
bool const none_
bool playback_
bool const poisson_
bool poisson_OOT_
CLHEP::RandPoisson * poissonDistr_OOT_
CLHEP::RandPoissonQ * poissonDistribution_
TFile * probFileHisto
bool const probFunctionDistribution_
int seed_
bool sequential_
std::string const type_

Detailed Description

Definition at line 30 of file PileUp.h.


Constructor & Destructor Documentation

edm::PileUp::PileUp ( ParameterSet const &  pset,
double  averageNumber,
TH1F *const  histo,
const bool  playback 
) [explicit]

Definition at line 15 of file PileUp.cc.

References averageNumber_, Exception, fixed_, fixed_OOT_, edm::ParameterSet::getUntrackedParameter(), histoDistribution_, intFixed_OOT_, edm::Service< T >::isAvailable(), manage_OOT_, none_, playback_, poisson_, poisson_OOT_, poissonDistr_OOT_, poissonDistribution_, probFunctionDistribution_, seed_, and type_.

                                                                                                        :
    type_(pset.getParameter<std::string>("type")),
    averageNumber_(averageNumber),
    intAverage_(static_cast<int>(averageNumber)),
    histo_(histo),
    histoDistribution_(type_ == "histo"),
    probFunctionDistribution_(type_ == "probFunction"),
    poisson_(type_ == "poisson"),
    fixed_(type_ == "fixed"),
    none_(type_ == "none"),
    input_(VectorInputSourceFactory::get()->makeVectorInputSource(pset, InputSourceDescription()).release()),
    poissonDistribution_(0),
    poissonDistr_OOT_(0),
    playback_(playback),
    sequential_(pset.getUntrackedParameter<bool>("sequential", false)),
    seed_(pset.getParameter<edm::ParameterSet>("nbPileupEvents").getUntrackedParameter<int>("seed",0))
   {

    
    edm::Service<edm::RandomNumberGenerator> rng;
    if (!rng.isAvailable()) {
      throw cms::Exception("Configuration")
        << "PileUp requires the RandomNumberGeneratorService\n"
        "which is not present in the configuration file.  You must add the service\n"
        "in the configuration file or remove the modules that require it.";
    }
    
    CLHEP::HepRandomEngine& engine = rng->getEngine();
    poissonDistribution_ = new CLHEP::RandPoissonQ(engine, averageNumber_);
    
    // Get seed for the case when using user histogram or probability function
    if (histoDistribution_ || probFunctionDistribution_){ 
      if(seed_ !=0) {
        gRandom->SetSeed(seed_);
        LogInfo("MixingModule") << " Change seed for " << type_ << " mode. The seed is set to " << seed_;
      }
      else {
        gRandom->SetSeed(engine.getSeed());
      }
    } 
     
        
    if (!(histoDistribution_ || probFunctionDistribution_ || poisson_ || fixed_ || none_)) {
      throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
        << "'type' parameter (a string) has a value of '" << type_ << "'.\n"
        << "Legal values are 'poisson', 'fixed', or 'none'\n";
    }

    manage_OOT_ = pset.getUntrackedParameter<bool>("manage_OOT", false);

    if(manage_OOT_) { // figure out what the parameters are

      if (playback_) throw cms::Exception("Illegal parameter clash","PileUp::PileUp(ParameterSet const& pset)")
        << " manage_OOT option not allowed with playback ";

      std::string OOT_type = pset.getUntrackedParameter<std::string>("OOT_type");

      if(OOT_type == "Poisson" || OOT_type == "poisson") {
        poisson_OOT_ = true;
        poissonDistr_OOT_ = new CLHEP::RandPoisson(engine);
      }
      else if(OOT_type == "Fixed" || OOT_type == "fixed") {
        fixed_OOT_ = true;
        // read back the fixed number requested out-of-time
        intFixed_OOT_ = pset.getUntrackedParameter<int>("intFixed_OOT", -1);
        if(intFixed_OOT_ < 0) {
          throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)") 
            << " Fixed out-of-time pileup requested, but no fixed value given ";
        }
      }
      else {
        throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
          << "'OOT_type' parameter (a string) has a value of '" << OOT_type << "'.\n"
          << "Legal values are 'poisson' or 'fixed'\n";
      }
      edm::LogInfo("MixingModule") <<" Out-of-time pileup will be generated with a " << OOT_type << " distribution. " ;
    }
    
  }
edm::PileUp::~PileUp ( )

Definition at line 95 of file PileUp.cc.

References poissonDistr_OOT_, and poissonDistribution_.


Member Function Documentation

double edm::PileUp::averageNumber ( ) const [inline]

Definition at line 41 of file PileUp.h.

References averageNumber_.

{return averageNumber_;}
void edm::PileUp::CalculatePileup ( int  MinBunch,
int  MaxBunch,
std::vector< int > &  PileupSelection,
std::vector< float > &  TrueNumInteractions 
)

Definition at line 100 of file PileUp.cc.

References averageNumber_, fixed_, histo_, histoDistribution_, intAverage_, intFixed_OOT_, manage_OOT_, none_, poisson_, poisson_OOT_, poissonDistr_OOT_, poissonDistribution_, and probFunctionDistribution_.

                                                                                                                                 {

    // if we are managing the distribution of out-of-time pileup separately, select the distribution for bunch
    // crossing zero first, save it for later.

    int nzero_crossing = -1;
    double Fnzero_crossing = -1;

    if(manage_OOT_) {
      if (none_){
        nzero_crossing = 0;
      }else if (poisson_){
        nzero_crossing =  poissonDistribution_->fire() ;
      }else if (fixed_){
        nzero_crossing =  intAverage_ ;
      }else if (histoDistribution_ || probFunctionDistribution_){
        double d = histo_->GetRandom();
        //n = (int) floor(d + 0.5);  // incorrect for bins with integer edges
        Fnzero_crossing =  d;
      }

    }

    for(int bx = MinBunch; bx < MaxBunch+1; ++bx) {

      if(manage_OOT_) {
        if(bx==0 && !poisson_OOT_) { 
          PileupSelection.push_back(nzero_crossing) ;
          TrueNumInteractions.push_back( nzero_crossing );
        }
        else{
          if(poisson_OOT_) {
            PileupSelection.push_back(poissonDistr_OOT_->fire(Fnzero_crossing)) ;
            TrueNumInteractions.push_back( Fnzero_crossing );
          }
          else {
            PileupSelection.push_back(intFixed_OOT_) ;
            TrueNumInteractions.push_back( intFixed_OOT_ );
          }  
        }
      }
      else {
        if (none_){
          PileupSelection.push_back(0);
          TrueNumInteractions.push_back( 0. );
        }else if (poisson_){
          PileupSelection.push_back(poissonDistribution_->fire());
          TrueNumInteractions.push_back( averageNumber_ );
        }else if (fixed_){
          PileupSelection.push_back(intAverage_);
          TrueNumInteractions.push_back( intAverage_ );
        }else if (histoDistribution_ || probFunctionDistribution_){
          double d = histo_->GetRandom();
          PileupSelection.push_back(int(d));
          TrueNumInteractions.push_back( d );
        }
      }
    
    }
  }
bool edm::PileUp::doPileUp ( ) [inline]

Definition at line 43 of file PileUp.h.

References averageNumber_, and none_.

{return none_ ? false :  averageNumber_>0.;}
void edm::PileUp::dropUnwantedBranches ( std::vector< std::string > const &  wantedBranches) [inline]

Definition at line 44 of file PileUp.h.

References edm::VectorInputSource::dropUnwantedBranches(), and input_.

                                                                          {
      input_->dropUnwantedBranches(wantedBranches);
    }
void edm::PileUp::endJob ( void  ) [inline]

Definition at line 47 of file PileUp.h.

References edm::InputSource::doEndJob(), and input_.

                   {
      input_->doEndJob();
    }
template<typename T >
void edm::PileUp::playPileUp ( const std::vector< edm::EventID > &  ids,
T  eventOperator 
)

Definition at line 149 of file PileUp.h.

References input_, and edm::VectorInputSource::loopSpecified().

                                                                        {
    //TrueNumInteractions.push_back( ids.size() ) ;
    input_->loopSpecified(ids,eventOperator);
  }
bool edm::PileUp::poisson ( ) const [inline]

Definition at line 42 of file PileUp.h.

References poisson_.

{return poisson_;}
template<typename T >
void edm::PileUp::readPileUp ( std::vector< edm::EventID > &  ids,
T  eventOperator,
const int  pileEventCnt 
)

Generates events from a VectorInputSource. This function decides which method of VectorInputSource to call: sequential, random, or pre-specified. The ids are either ids to read or ids to store while reading. eventOperator has a type that matches the eventOperator in VectorInputSource::loopRandom.

Definition at line 119 of file PileUp.h.

References input_, edm::VectorInputSource::loopRandom(), edm::VectorInputSource::loopSequential(), and sequential_.

                                                                                          {

    // One reason PileUp is responsible for recording event IDs is
    // that it is the one that knows how many events will be read.
    ids.reserve(pileEventCnt);
    RecordEventID<T> recorder(ids,eventOperator);
    if (sequential_) {
      // boost::bind creates a functor from recordEventForPlayback
      // so that recordEventForPlayback can insert itself before
      // the original eventOperator.

      input_->loopSequential(pileEventCnt, recorder);
      //boost::bind(&PileUp::recordEventForPlayback<T>,
      //                    boost::ref(*this), _1, boost::ref(ids),
      //                             boost::ref(eventOperator))
      //  );
        
    } else  {
      input_->loopRandom(pileEventCnt, recorder);
      //               boost::bind(&PileUp::recordEventForPlayback<T>,
      //                             boost::ref(*this), _1, boost::ref(ids),
      //                             boost::ref(eventOperator))
      //                 );
    }
  }

Member Data Documentation

double const edm::PileUp::averageNumber_ [private]

Definition at line 59 of file PileUp.h.

Referenced by averageNumber(), CalculatePileup(), doPileUp(), and PileUp().

bool const edm::PileUp::fixed_ [private]

Definition at line 65 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

bool edm::PileUp::fixed_OOT_ [private]

Definition at line 69 of file PileUp.h.

Referenced by PileUp().

TH1F* edm::PileUp::h1f [private]

Definition at line 77 of file PileUp.h.

TH1F* const edm::PileUp::histo_ [private]

Definition at line 61 of file PileUp.h.

Referenced by CalculatePileup().

bool const edm::PileUp::histoDistribution_ [private]

Definition at line 62 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

TH1F* edm::PileUp::hprobFunction [private]

Definition at line 78 of file PileUp.h.

Definition at line 72 of file PileUp.h.

Referenced by dropUnwantedBranches(), endJob(), playPileUp(), and readPileUp().

int const edm::PileUp::intAverage_ [private]

Definition at line 60 of file PileUp.h.

Referenced by CalculatePileup().

Definition at line 70 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

bool edm::PileUp::manage_OOT_ [private]

Definition at line 67 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

bool const edm::PileUp::none_ [private]

Definition at line 66 of file PileUp.h.

Referenced by CalculatePileup(), doPileUp(), and PileUp().

bool edm::PileUp::playback_ [private]

Definition at line 82 of file PileUp.h.

Referenced by PileUp().

bool const edm::PileUp::poisson_ [private]

Definition at line 64 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and poisson().

bool edm::PileUp::poisson_OOT_ [private]

Definition at line 68 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

CLHEP::RandPoisson* edm::PileUp::poissonDistr_OOT_ [private]

Definition at line 74 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and ~PileUp().

CLHEP::RandPoissonQ* edm::PileUp::poissonDistribution_ [private]

Definition at line 73 of file PileUp.h.

Referenced by CalculatePileup(), PileUp(), and ~PileUp().

TFile* edm::PileUp::probFileHisto [private]

Definition at line 79 of file PileUp.h.

Definition at line 63 of file PileUp.h.

Referenced by CalculatePileup(), and PileUp().

int edm::PileUp::seed_ [private]

Definition at line 88 of file PileUp.h.

Referenced by PileUp().

bool edm::PileUp::sequential_ [private]

Definition at line 85 of file PileUp.h.

Referenced by readPileUp().

std::string const edm::PileUp::type_ [private]

Definition at line 58 of file PileUp.h.

Referenced by PileUp().