Go to the documentation of this file.00001 #ifndef Mixing_Base_PileUp_h
00002 #define Mixing_Base_PileUp_h
00003
00004 #include <memory>
00005 #include <string>
00006 #include <vector>
00007 #include <boost/bind.hpp>
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/Sources/interface/VectorInputSource.h"
00010 #include "DataFormats/Provenance/interface/EventID.h"
00011 #include "FWCore/Framework/interface/EventPrincipal.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013
00014 #include "CLHEP/Random/RandPoissonQ.h"
00015 #include "CLHEP/Random/RandFlat.h"
00016
00017 #include "TRandom.h"
00018 #include "TFile.h"
00019 #include "TH1F.h"
00020
00021 class TFile;
00022 class TH1F;
00023
00024 namespace CLHEP {
00025 class RandPoissonQ;
00026 class RandPoisson;
00027 }
00028
00029
00030
00031 namespace edm {
00032 class PileUp {
00033 public:
00034 explicit PileUp(ParameterSet const& pset, double averageNumber, TH1F* const histo, const bool playback);
00035 ~PileUp();
00036
00037 template<typename T>
00038 void readPileUp(edm::EventID const & signal, std::vector<edm::EventID> &ids, T eventOperator, const int NumPU );
00039
00040 template<typename T>
00041 void playPileUp(const std::vector<edm::EventID> &ids, T eventOperator);
00042
00043 double averageNumber() const {return averageNumber_;}
00044 bool poisson() const {return poisson_;}
00045 bool doPileUp() {return none_ ? false : averageNumber_>0.;}
00046 void dropUnwantedBranches(std::vector<std::string> const& wantedBranches) {
00047 input_->dropUnwantedBranches(wantedBranches);
00048 }
00049 void endJob () {
00050 input_->doEndJob();
00051 }
00052
00053 void reload(const edm::EventSetup & setup);
00054
00055 void CalculatePileup(int MinBunch, int MaxBunch, std::vector<int>& PileupSelection, std::vector<float>& TrueNumInteractions);
00056
00057
00058
00059
00060
00061 const unsigned int & input()const{return inputType_;}
00062 void input(unsigned int s){inputType_=s;}
00063
00064 private:
00065 unsigned int inputType_;
00066 std::string type_;
00067 double averageNumber_;
00068 int const intAverage_;
00069 TH1F* histo_;
00070 bool histoDistribution_;
00071 bool probFunctionDistribution_;
00072 bool poisson_;
00073 bool fixed_;
00074 bool none_;
00075 bool manage_OOT_;
00076 bool poisson_OOT_;
00077 bool fixed_OOT_;
00078
00079 bool PU_Study_;
00080 std::string Study_type_;
00081
00082 int intFixed_OOT_;
00083 int intFixed_ITPU_;
00084
00085 std::unique_ptr<ProductRegistry> productRegistry_;
00086 std::unique_ptr<VectorInputSource> const input_;
00087 std::unique_ptr<ProcessConfiguration> processConfiguration_;
00088 std::unique_ptr<EventPrincipal> eventPrincipal_;
00089 std::unique_ptr<CLHEP::RandPoissonQ> poissonDistribution_;
00090 std::unique_ptr<CLHEP::RandPoisson> poissonDistr_OOT_;
00091
00092
00093 TH1F *h1f;
00094 TH1F *hprobFunction;
00095 TFile *probFileHisto;
00096
00097
00098 bool playback_;
00099
00100
00101 bool sequential_;
00102
00103
00104 bool samelumi_;
00105
00106
00107 int seed_;
00108 };
00109
00110
00111
00112 template<typename T>
00113 class RecordEventID
00114 {
00115 private:
00116 std::vector<edm::EventID>& ids_;
00117 T& eventOperator_;
00118 int eventCount ;
00119 public:
00120 RecordEventID(std::vector<edm::EventID>& ids, T& eventOperator)
00121 : ids_(ids), eventOperator_(eventOperator), eventCount( 0 ) {}
00122 void operator()(EventPrincipal const& eventPrincipal) {
00123 ids_.push_back(eventPrincipal.id());
00124 eventOperator_(eventPrincipal, ++eventCount);
00125 }
00126 };
00127
00128
00139 template<typename T>
00140 void
00141 PileUp::readPileUp(edm::EventID const & signal, std::vector<edm::EventID> &ids, T eventOperator, const int pileEventCnt) {
00142
00143
00144
00145 ids.reserve(pileEventCnt);
00146 RecordEventID<T> recorder(ids,eventOperator);
00147 int read;
00148 if (samelumi_) {
00149 const edm::LuminosityBlockID lumi(signal.run(), signal.luminosityBlock());
00150 if (sequential_)
00151 read = input_->loopSequentialWithID(*eventPrincipal_, lumi, pileEventCnt, recorder);
00152 else
00153 read = input_->loopRandomWithID(*eventPrincipal_, lumi, pileEventCnt, recorder);
00154 } else {
00155 if (sequential_) {
00156
00157
00158
00159
00160 read = input_->loopSequential(*eventPrincipal_, pileEventCnt, recorder);
00161
00162
00163
00164
00165
00166 } else {
00167 read = input_->loopRandom(*eventPrincipal_, pileEventCnt, recorder);
00168
00169
00170
00171
00172 }
00173 }
00174 if (read != pileEventCnt)
00175 edm::LogWarning("PileUp") << "Could not read enough pileup events: only " << read << " out of " << pileEventCnt << " requested.";
00176 }
00177
00178
00179
00180 template<typename T>
00181 void
00182 PileUp::playPileUp(const std::vector<edm::EventID> &ids, T eventOperator) {
00183
00184 input_->loopSpecified(*eventPrincipal_,ids,eventOperator);
00185 }
00186
00187
00188
00191
00192
00193
00194
00195
00196
00197
00198
00199 }
00200
00201
00202 #endif