CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Attributes
edm::PileUp Class Reference

#include <PileUp.h>

Public Types

typedef
VectorInputSource::EventPrincipalVector 
EventPrincipalVector
 

Public Member Functions

double averageNumber () const
 
bool doPileup ()
 
void dropUnwantedBranches (std::vector< std::string > const &wantedBranches)
 
void endJob ()
 
 PileUp (ParameterSet const &pset, int const minb, int const maxb, double averageNumber, TH1F *const histo, const bool playback)
 
bool poisson () const
 
void readPileUp (std::vector< EventPrincipalVector > &result, std::vector< std::vector< edm::EventID > > &ids)
 
 ~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_
 
int const maxBunch_
 
int const minBunch_
 
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 22 of file PileUp.h.

Member Typedef Documentation

Definition at line 24 of file PileUp.h.

Constructor & Destructor Documentation

edm::PileUp::PileUp ( ParameterSet const &  pset,
int const  minb,
int const  maxb,
double  averageNumber,
TH1F *const  histo,
const bool  playback 
)
explicit

Definition at line 22 of file PileUp.cc.

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

22  :
23  type_(pset.getParameter<std::string>("type")),
24  minBunch_(minb),
25  maxBunch_(maxb),
27  intAverage_(static_cast<int>(averageNumber)),
28  histo_(histo),
29  histoDistribution_(type_ == "histo"),
30  probFunctionDistribution_(type_ == "probFunction"),
31  poisson_(type_ == "poisson"),
32  fixed_(type_ == "fixed"),
33  none_(type_ == "none"),
34  input_(VectorInputSourceFactory::get()->makeVectorInputSource(pset, InputSourceDescription()).release()),
37  sequential_(pset.getUntrackedParameter<bool>("sequential", false)),
38  seed_(pset.getParameter<edm::ParameterSet>("nbPileupEvents").getUntrackedParameter<int>("seed",1234))
39  {
40 
41 
43  if (!rng.isAvailable()) {
44  throw cms::Exception("Configuration")
45  << "PileUp requires the RandomNumberGeneratorService\n"
46  "which is not present in the configuration file. You must add the service\n"
47  "in the configuration file or remove the modules that require it.";
48  }
49 
50  CLHEP::HepRandomEngine& engine = rng->getEngine();
51  poissonDistribution_ = new CLHEP::RandPoissonQ(engine, averageNumber_);
52 
53  // Get seed for the case when using user histogram or probability function
55  gRandom->SetSeed(seed_);
56  LogInfo("MixingModule") << " Change seed for " << type_ << " mode. The seed is set to " << seed_;
57  }
58 
59 
61  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
62  << "'type' parameter (a string) has a value of '" << type_ << "'.\n"
63  << "Legal values are 'poisson', 'fixed', or 'none'\n";
64  }
65 
66  manage_OOT_ = pset.getUntrackedParameter<bool>("manage_OOT", false);
67 
68  if(manage_OOT_) { // figure out what the parameters are
69 
70  if (playback_) throw cms::Exception("Illegal parameter clash","PileUp::PileUp(ParameterSet const& pset)")
71  << " manage_OOT option not allowed with playback ";
72 
73  std::string OOT_type = pset.getUntrackedParameter<std::string>("OOT_type");
74 
75  if(OOT_type == "Poisson" || OOT_type == "poisson") {
76  poisson_OOT_ = true;
77  poissonDistr_OOT_ = new CLHEP::RandPoisson(engine);
78  }
79  else if(OOT_type == "Fixed" || OOT_type == "fixed") {
80  fixed_OOT_ = true;
81  // read back the fixed number requested out-of-time
82  intFixed_OOT_ = pset.getUntrackedParameter<int>("intFixed_OOT", -1);
83  if(intFixed_OOT_ < 0) {
84  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
85  << " Fixed out-of-time pileup requested, but no fixed value given ";
86  }
87  }
88  else {
89  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
90  << "'OOT_type' parameter (a string) has a value of '" << OOT_type << "'.\n"
91  << "Legal values are 'poisson' or 'fixed'\n";
92  }
93  edm::LogInfo("MixingModule") <<" Out-of-time pileup will be generated with a " << OOT_type << " distribution. " ;
94  }
95 
96  }
bool manage_OOT_
Definition: PileUp.h:52
int const maxBunch_
Definition: PileUp.h:43
T getUntrackedParameter(std::string const &, T const &) const
bool const histoDistribution_
Definition: PileUp.h:47
bool const none_
Definition: PileUp.h:51
tuple histo
Definition: trackerHits.py:12
VectorInputSource *const input_
Definition: PileUp.h:57
bool const probFunctionDistribution_
Definition: PileUp.h:48
int const intAverage_
Definition: PileUp.h:45
double averageNumber() const
Definition: PileUp.h:30
bool playback_
Definition: PileUp.h:67
bool poisson_OOT_
Definition: PileUp.h:53
bool isAvailable() const
Definition: Service.h:47
bool const poisson_
Definition: PileUp.h:49
tuple pset
Definition: CrabTask.py:85
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
bool fixed_OOT_
Definition: PileUp.h:54
CLHEP::RandPoisson * poissonDistr_OOT_
Definition: PileUp.h:59
bool const fixed_
Definition: PileUp.h:50
static VectorInputSourceFactory * get()
double const averageNumber_
Definition: PileUp.h:44
TH1F *const histo_
Definition: PileUp.h:46
bool sequential_
Definition: PileUp.h:70
std::string const type_
Definition: PileUp.h:41
int seed_
Definition: PileUp.h:73
tuple playback
Definition: Playback_cff.py:20
int intFixed_OOT_
Definition: PileUp.h:55
CLHEP::RandPoissonQ * poissonDistribution_
Definition: PileUp.h:58
int const minBunch_
Definition: PileUp.h:42
edm::PileUp::~PileUp ( )

Definition at line 98 of file PileUp.cc.

References poissonDistribution_.

98  {
99  delete poissonDistribution_;
100  }
CLHEP::RandPoissonQ * poissonDistribution_
Definition: PileUp.h:58

Member Function Documentation

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

Definition at line 30 of file PileUp.h.

References averageNumber_.

30 {return averageNumber_;}
double const averageNumber_
Definition: PileUp.h:44
bool edm::PileUp::doPileup ( )
inline

Definition at line 32 of file PileUp.h.

References averageNumber_, and none_.

32 {return none_ ? false : averageNumber_>0.;}
bool const none_
Definition: PileUp.h:51
double const averageNumber_
Definition: PileUp.h:44
void edm::PileUp::dropUnwantedBranches ( std::vector< std::string > const &  wantedBranches)
inline

Definition at line 33 of file PileUp.h.

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

33  {
34  input_->dropUnwantedBranches(wantedBranches);
35  }
void dropUnwantedBranches(std::vector< std::string > const &wantedBranches)
VectorInputSource *const input_
Definition: PileUp.h:57
void edm::PileUp::endJob ( void  )
inline

Definition at line 36 of file PileUp.h.

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

36  {
37  input_->doEndJob();
38  }
VectorInputSource *const input_
Definition: PileUp.h:57
void doEndJob()
Called by framework at end of job.
Definition: InputSource.cc:237
bool edm::PileUp::poisson ( ) const
inline

Definition at line 31 of file PileUp.h.

References poisson_.

31 {return poisson_;}
bool const poisson_
Definition: PileUp.h:49
void edm::PileUp::readPileUp ( std::vector< EventPrincipalVector > &  result,
std::vector< std::vector< edm::EventID > > &  ids 
)

Definition at line 103 of file PileUp.cc.

References filterCSVwithJSON::copy, dbtoweb::file, fixed_, histo_, histoDistribution_, i, input_, intAverage_, intFixed_OOT_, j, LogDebug, manage_OOT_, maxBunch_, minBunch_, n, nint(), none_, playback_, poisson_, poisson_OOT_, poissonDistr_OOT_, poissonDistribution_, probFunctionDistribution_, edm::VectorInputSource::readManyRandom(), edm::VectorInputSource::readManySequential(), edm::VectorInputSource::readManySpecified(), sequential_, and findQualityFiles::size.

103  {
104 
105  // set up vector of event counts for each bunch crossing ahead of time, so that we can
106  // allow for an arbitrary distribution for out-of-time vs. in-time pileup
107 
108  std::vector<int> nint;
109 
110  // if we are managing the distribution of out-of-time pileup separately, select the distribution for bunch
111  // crossing zero first, save it for later.
112 
113  int nzero_crossing = -1;
114 
115  if(manage_OOT_) {
116  if (none_){
117  nzero_crossing = 0;
118  }else if (poisson_){
119  nzero_crossing = poissonDistribution_->fire() ;
120  }else if (fixed_){
121  nzero_crossing = intAverage_ ;
123  double d = histo_->GetRandom();
124  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
125  nzero_crossing = int(d);
126  }
127  }
128 
129  for (int i = minBunch_; i <= maxBunch_; ++i) {
130 
131  if (playback_){
132  nint.push_back( ids[i-minBunch_].size() );
133  //} else if (sequential_) { // just read many sequentially... why specify?
134  // For now, the use case for sequential read reads only one event at a time.
135  // nint.push_back( 1 );
136  }
137  else if(manage_OOT_) {
138  if(i==0 && !poisson_OOT_) nint.push_back(nzero_crossing);
139  else{
140  if(poisson_OOT_) {
141  nint.push_back( poissonDistr_OOT_->fire(float(nzero_crossing)) );
142  }
143  else {
144  nint.push_back( intFixed_OOT_ );
145  }
146  }
147  }
148  else {
149  if (none_){
150  nint.push_back(0);
151  }else if (poisson_){
152  nint.push_back( poissonDistribution_->fire() );
153  }else if (fixed_){
154  nint.push_back( intAverage_ );
156  double d = histo_->GetRandom();
157  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
158  nint.push_back( int(d) );
159  }
160 
161  }
162  }
163 
164  int n=0;
165 
166  for (int i = minBunch_; i <= maxBunch_; ++i) {
167  EventPrincipalVector eventVector;
168 
169  n = nint[i-minBunch_];
170 
171  eventVector.reserve(n);
172  while (n > 0) {
173  EventPrincipalVector oneResult;
174  oneResult.reserve(n);
175  std::vector<edm::EventID> oneResultPlayback;
176  oneResultPlayback.reserve(n);
177  if (playback_) {
178  input_->readManySpecified(ids[i-minBunch_],oneResult); // playback
179  } else if (sequential_) {
180  unsigned int file;
181  input_->readManySequential(n, oneResult, file); // sequential
182  for (int j=0;j<(int)oneResult.size();j++){
183  oneResultPlayback.push_back(oneResult[j]->id());
184  }
185  ids[i-minBunch_] = oneResultPlayback;
186  } else {
187  unsigned int file; //FIXME: need unsigned filenr?
188  input_->readManyRandom(n, oneResult,file); //no playback
189  for (int j=0;j<(int)oneResult.size();j++){
190  oneResultPlayback.push_back(oneResult[j]->id());
191  }
192  ids[i-minBunch_] = oneResultPlayback;
193  }
194  LogDebug("readPileup") << "READ: " << oneResult.size();
195  std::copy(oneResult.begin(), oneResult.end(), std::back_inserter(eventVector));
196  n -= oneResult.size();
197  }
198  result.push_back(eventVector);
199  }
200  }
#define LogDebug(id)
bool manage_OOT_
Definition: PileUp.h:52
int const maxBunch_
Definition: PileUp.h:43
int i
Definition: DBlmapReader.cc:9
bool const histoDistribution_
Definition: PileUp.h:47
list file
Definition: dbtoweb.py:253
bool const none_
Definition: PileUp.h:51
VectorInputSource *const input_
Definition: PileUp.h:57
bool const probFunctionDistribution_
Definition: PileUp.h:48
void readManyRandom(int number, EventPrincipalVector &result, unsigned int &fileSeqNumber)
int const intAverage_
Definition: PileUp.h:45
bool playback_
Definition: PileUp.h:67
bool poisson_OOT_
Definition: PileUp.h:53
VectorInputSource::EventPrincipalVector EventPrincipalVector
Definition: PileUp.h:24
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
bool const poisson_
Definition: PileUp.h:49
void readManySequential(int number, EventPrincipalVector &result, unsigned int &fileSeqNumber)
CLHEP::RandPoisson * poissonDistr_OOT_
Definition: PileUp.h:59
int nint(float a)
Return the nearest integer - analogous to the FORTRAN intrinsic NINT.
Definition: nint.h:8
bool const fixed_
Definition: PileUp.h:50
TH1F *const histo_
Definition: PileUp.h:46
bool sequential_
Definition: PileUp.h:70
int intFixed_OOT_
Definition: PileUp.h:55
CLHEP::RandPoissonQ * poissonDistribution_
Definition: PileUp.h:58
tuple size
Write out results.
void readManySpecified(std::vector< EventID > const &events, EventPrincipalVector &result)
int const minBunch_
Definition: PileUp.h:42

Member Data Documentation

double const edm::PileUp::averageNumber_
private

Definition at line 44 of file PileUp.h.

Referenced by averageNumber(), doPileup(), and PileUp().

bool const edm::PileUp::fixed_
private

Definition at line 50 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

bool edm::PileUp::fixed_OOT_
private

Definition at line 54 of file PileUp.h.

Referenced by PileUp().

TH1F* edm::PileUp::h1f
private

Definition at line 62 of file PileUp.h.

TH1F* const edm::PileUp::histo_
private

Definition at line 46 of file PileUp.h.

Referenced by readPileUp().

bool const edm::PileUp::histoDistribution_
private

Definition at line 47 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

TH1F* edm::PileUp::hprobFunction
private

Definition at line 63 of file PileUp.h.

VectorInputSource* const edm::PileUp::input_
private

Definition at line 57 of file PileUp.h.

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

int const edm::PileUp::intAverage_
private

Definition at line 45 of file PileUp.h.

Referenced by readPileUp().

int edm::PileUp::intFixed_OOT_
private

Definition at line 55 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

bool edm::PileUp::manage_OOT_
private

Definition at line 52 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

int const edm::PileUp::maxBunch_
private

Definition at line 43 of file PileUp.h.

Referenced by readPileUp().

int const edm::PileUp::minBunch_
private

Definition at line 42 of file PileUp.h.

Referenced by readPileUp().

bool const edm::PileUp::none_
private

Definition at line 51 of file PileUp.h.

Referenced by doPileup(), PileUp(), and readPileUp().

bool edm::PileUp::playback_
private

Definition at line 67 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

bool const edm::PileUp::poisson_
private

Definition at line 49 of file PileUp.h.

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

bool edm::PileUp::poisson_OOT_
private

Definition at line 53 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

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

Definition at line 59 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

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

Definition at line 58 of file PileUp.h.

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

TFile* edm::PileUp::probFileHisto
private

Definition at line 64 of file PileUp.h.

bool const edm::PileUp::probFunctionDistribution_
private

Definition at line 48 of file PileUp.h.

Referenced by PileUp(), and readPileUp().

int edm::PileUp::seed_
private

Definition at line 73 of file PileUp.h.

Referenced by PileUp().

bool edm::PileUp::sequential_
private

Definition at line 70 of file PileUp.h.

Referenced by readPileUp().

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