Go to the documentation of this file.00001 #ifndef Base_PileUp_h
00002 #define Base_PileUp_h
00003
00004 #include <string>
00005 #include <vector>
00006 #include <boost/bind.hpp>
00007 #include "FWCore/Framework/interface/Frameworkfwd.h"
00008 #include "FWCore/Sources/interface/VectorInputSource.h"
00009 #include "DataFormats/Provenance/interface/EventID.h"
00010 #include "FWCore/Framework/interface/EventPrincipal.h"
00011
00012 #include "CLHEP/Random/RandPoissonQ.h"
00013 #include "CLHEP/Random/RandFlat.h"
00014
00015 #include "TRandom.h"
00016 #include "TFile.h"
00017 #include "TH1F.h"
00018
00019 class TFile;
00020 class TH1F;
00021
00022 namespace CLHEP {
00023 class RandPoissonQ;
00024 class RandPoisson;
00025 }
00026
00027
00028
00029 namespace edm {
00030 class PileUp {
00031 public:
00032 explicit PileUp(ParameterSet const& pset, double averageNumber, TH1F* const histo, const bool playback);
00033 ~PileUp();
00034
00035 template<typename T>
00036 void readPileUp(std::vector<edm::EventID> &ids, T eventOperator, const int NumPU );
00037
00038 template<typename T>
00039 void playPileUp(const std::vector<edm::EventID> &ids, T eventOperator);
00040
00041 double averageNumber() const {return averageNumber_;}
00042 bool poisson() const {return poisson_;}
00043 bool doPileUp() {return none_ ? false : averageNumber_>0.;}
00044 void dropUnwantedBranches(std::vector<std::string> const& wantedBranches) {
00045 input_->dropUnwantedBranches(wantedBranches);
00046 }
00047 void endJob () {
00048 input_->doEndJob();
00049 }
00050
00051 void CalculatePileup(int MinBunch, int MaxBunch, std::vector<int>& PileupSelection, std::vector<float>& TrueNumInteractions);
00052
00053
00054
00055
00056
00057 private:
00058 std::string const type_;
00059 double const averageNumber_;
00060 int const intAverage_;
00061 TH1F* const histo_;
00062 bool const histoDistribution_;
00063 bool const probFunctionDistribution_;
00064 bool const poisson_;
00065 bool const fixed_;
00066 bool const none_;
00067 bool manage_OOT_;
00068 bool poisson_OOT_;
00069 bool fixed_OOT_;
00070 int intFixed_OOT_;
00071
00072 VectorInputSource * const input_;
00073 CLHEP::RandPoissonQ *poissonDistribution_;
00074 CLHEP::RandPoisson *poissonDistr_OOT_;
00075
00076
00077 TH1F *h1f;
00078 TH1F *hprobFunction;
00079 TFile *probFileHisto;
00080
00081
00082 bool playback_;
00083
00084
00085 bool sequential_;
00086
00087
00088 int seed_;
00089 };
00090
00091
00092
00093 template<typename T>
00094 class RecordEventID
00095 {
00096 private:
00097 std::vector<edm::EventID>& ids_;
00098 T& eventOperator_;
00099 int eventCount ;
00100 public:
00101 RecordEventID(std::vector<edm::EventID>& ids, T& eventOperator)
00102 : ids_(ids), eventOperator_(eventOperator), eventCount( 0 ) {}
00103 void operator()(EventPrincipal const& eventPrincipal) {
00104 ids_.push_back(eventPrincipal.id());
00105 eventOperator_(eventPrincipal, ++eventCount);
00106 }
00107 };
00108
00109
00117 template<typename T>
00118 void
00119 PileUp::readPileUp(std::vector<edm::EventID> &ids, T eventOperator, const int pileEventCnt) {
00120
00121
00122
00123 ids.reserve(pileEventCnt);
00124 RecordEventID<T> recorder(ids,eventOperator);
00125 if (sequential_) {
00126
00127
00128
00129
00130 input_->loopSequential(pileEventCnt, recorder);
00131
00132
00133
00134
00135
00136 } else {
00137 input_->loopRandom(pileEventCnt, recorder);
00138
00139
00140
00141
00142 }
00143 }
00144
00145
00146
00147 template<typename T>
00148 void
00149 PileUp::playPileUp(const std::vector<edm::EventID> &ids, T eventOperator) {
00150
00151 input_->loopSpecified(ids,eventOperator);
00152 }
00153
00154
00155
00158
00159
00160
00161
00162
00163
00164
00165
00166 }
00167
00168
00169 #endif