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, std::vector< float > &TrueBXCount)
 
 ~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",0))
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  if(seed_ !=0) {
56  gRandom->SetSeed(seed_);
57  LogInfo("MixingModule") << " Change seed for " << type_ << " mode. The seed is set to " << seed_;
58  }
59  else {
60  gRandom->SetSeed(engine.getSeed());
61  }
62  }
63 
64 
66  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
67  << "'type' parameter (a string) has a value of '" << type_ << "'.\n"
68  << "Legal values are 'poisson', 'fixed', or 'none'\n";
69  }
70 
71  manage_OOT_ = pset.getUntrackedParameter<bool>("manage_OOT", false);
72 
73  if(manage_OOT_) { // figure out what the parameters are
74 
75  if (playback_) throw cms::Exception("Illegal parameter clash","PileUp::PileUp(ParameterSet const& pset)")
76  << " manage_OOT option not allowed with playback ";
77 
78  std::string OOT_type = pset.getUntrackedParameter<std::string>("OOT_type");
79 
80  if(OOT_type == "Poisson" || OOT_type == "poisson") {
81  poisson_OOT_ = true;
82  poissonDistr_OOT_ = new CLHEP::RandPoisson(engine);
83  }
84  else if(OOT_type == "Fixed" || OOT_type == "fixed") {
85  fixed_OOT_ = true;
86  // read back the fixed number requested out-of-time
87  intFixed_OOT_ = pset.getUntrackedParameter<int>("intFixed_OOT", -1);
88  if(intFixed_OOT_ < 0) {
89  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
90  << " Fixed out-of-time pileup requested, but no fixed value given ";
91  }
92  }
93  else {
94  throw cms::Exception("Illegal parameter value","PileUp::PileUp(ParameterSet const& pset)")
95  << "'OOT_type' parameter (a string) has a value of '" << OOT_type << "'.\n"
96  << "Legal values are 'poisson' or 'fixed'\n";
97  }
98  edm::LogInfo("MixingModule") <<" Out-of-time pileup will be generated with a " << OOT_type << " distribution. " ;
99  }
100 
101  }
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
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 103 of file PileUp.cc.

References poissonDistribution_.

103  {
104  delete poissonDistribution_;
105  }
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  }
void doEndJob()
Called by framework at end of job.
Definition: InputSource.cc:237
VectorInputSource *const input_
Definition: PileUp.h:57
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,
std::vector< float > &  TrueBXCount 
)

Definition at line 108 of file PileUp.cc.

References averageNumber_, filterCSVwithJSON::copy, mergeVDriftHistosByStation::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.

108  {
109 
110  // set up vector of event counts for each bunch crossing ahead of time, so that we can
111  // allow for an arbitrary distribution for out-of-time vs. in-time pileup
112 
113  std::vector<int> nint;
114 
115  // if we are managing the distribution of out-of-time pileup separately, select the distribution for bunch
116  // crossing zero first, save it for later.
117 
118  int nzero_crossing = -1;
119  double Fnzero_crossing = -1;
120 
121  if(manage_OOT_) {
122  if (none_){
123  nzero_crossing = 0;
124  }else if (poisson_){
125  nzero_crossing = poissonDistribution_->fire() ;
126  }else if (fixed_){
127  nzero_crossing = intAverage_ ;
129  double d = histo_->GetRandom();
130  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
131  Fnzero_crossing = d;
132  }
133  }
134 
135  for (int i = minBunch_; i <= maxBunch_; ++i) {
136 
137  if (playback_){
138  nint.push_back( ids[i-minBunch_].size() );
139  //} else if (sequential_) { // just read many sequentially... why specify?
140  // For now, the use case for sequential read reads only one event at a time.
141  // nint.push_back( 1 );
142  TrueNumInteractions.push_back( ids[i-minBunch_].size() );
143  }
144  else if(manage_OOT_) {
145  if(i==0 && !poisson_OOT_) {
146  nint.push_back(nzero_crossing);
147  TrueNumInteractions.push_back( nzero_crossing );
148  }
149  else{
150  if(poisson_OOT_) {
151  nint.push_back( poissonDistr_OOT_->fire(Fnzero_crossing) );
152  TrueNumInteractions.push_back( Fnzero_crossing );
153  }
154  else {
155  nint.push_back( intFixed_OOT_ );
156  TrueNumInteractions.push_back( intFixed_OOT_ );
157  }
158  }
159  }
160  else {
161  if (none_){
162  nint.push_back(0);
163  TrueNumInteractions.push_back( 0. );
164  }else if (poisson_){
165  nint.push_back( poissonDistribution_->fire() );
166  TrueNumInteractions.push_back( averageNumber_ );
167  }else if (fixed_){
168  nint.push_back( intAverage_ );
169  TrueNumInteractions.push_back( intAverage_ );
171  double d = histo_->GetRandom();
172  //n = (int) floor(d + 0.5); // incorrect for bins with integer edges
173  nint.push_back( int(d) );
174  TrueNumInteractions.push_back( d );
175  }
176 
177  }
178  }
179 
180  int n=0;
181 
182  for (int i = minBunch_; i <= maxBunch_; ++i) {
183  EventPrincipalVector eventVector;
184 
185  n = nint[i-minBunch_];
186 
187  eventVector.reserve(n);
188  while (n > 0) {
189  EventPrincipalVector oneResult;
190  oneResult.reserve(n);
191  std::vector<edm::EventID> oneResultPlayback;
192  oneResultPlayback.reserve(n);
193  if (playback_) {
194  input_->readManySpecified(ids[i-minBunch_],oneResult); // playback
195  } else if (sequential_) {
196  unsigned int file;
197  input_->readManySequential(n, oneResult, file); // sequential
198  for (int j=0;j<(int)oneResult.size();j++){
199  oneResultPlayback.push_back(oneResult[j]->id());
200  }
201  ids[i-minBunch_] = oneResultPlayback;
202  } else {
203  unsigned int file; //FIXME: need unsigned filenr?
204  input_->readManyRandom(n, oneResult,file); //no playback
205  for (int j=0;j<(int)oneResult.size();j++){
206  oneResultPlayback.push_back(oneResult[j]->id());
207  }
208  ids[i-minBunch_] = oneResultPlayback;
209  }
210  LogDebug("readPileup") << "READ: " << oneResult.size();
211  std::copy(oneResult.begin(), oneResult.end(), std::back_inserter(eventVector));
212  n -= oneResult.size();
213  }
214  result.push_back(eventVector);
215  }
216  }
#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
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
double const averageNumber_
Definition: PileUp.h:44
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(), PileUp(), and readPileUp().

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