#include <PileUp.h>
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_ |
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_.
{ delete poissonDistribution_; delete poissonDistr_OOT_ ; }
double edm::PileUp::averageNumber | ( | ) | const [inline] |
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(); }
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] |
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)) // ); } }
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] |
TH1F* edm::PileUp::h1f [private] |
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] |
VectorInputSource* const edm::PileUp::input_ [private] |
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().
int edm::PileUp::intFixed_OOT_ [private] |
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] |
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] |
bool const edm::PileUp::probFunctionDistribution_ [private] |
Definition at line 63 of file PileUp.h.
Referenced by CalculatePileup(), and PileUp().
int edm::PileUp::seed_ [private] |
bool edm::PileUp::sequential_ [private] |
Definition at line 85 of file PileUp.h.
Referenced by readPileUp().
std::string const edm::PileUp::type_ [private] |