17 #include "HepMC/GenEvent.h"
31 produces<PileupMixingContent>();
33 produces<edm::HepMCProduct>(
"PileUpEvents");
37 if ( ! rng.isAvailable() ) {
39 <<
"PileUpProducer requires the RandomGeneratorService\n"
40 "which is not present in the configuration file.\n"
41 "You must add the service in the configuration file\n"
42 "or remove the module that requires it";
52 gRandom->SetSeed(rng->mySeed());
59 std::cout <<
" FastSimulation/PileUpProducer -> poissonian distribution" << std::endl;
60 averageNumber_ = pu.
getParameter<
double>(
"averageNumber");
69 std::cout <<
" FastSimulation/PileUpProducer -> distribution from configuration file " << std::endl;
71 for (
int i=0;
i<(varSize -
probSize);
i++) dataProb.push_back(0);
72 edm::LogWarning(
"") <<
" The probability function data will be completed with "
73 << (varSize -
probSize) <<
" values `0';"
74 <<
" the number of the P(x) data set after adding those 0's is " << dataProb.size();
81 std::cout <<
" FastSimulation/PileUpProducer -> An histogram will be created with " << numBins
82 <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
83 hprob =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
84 LogDebug(
"") <<
" FastSimulation/PileUpProducer -> Filling histogram with the following data:";
85 for (
int j=0;
j < numBins ;
j++){
91 if (((
hprob->Integral() - 1) > 1.0
e-02) && ((
hprob->Integral() - 1) < -1.0
e-02))
throw cms::Exception(
"BadHistoDistribution") <<
"The histogram should be normalized!" << std::endl;
94 averageNumber_ =
hprob->GetMean();
111 if ( vtxType ==
"Gaussian" )
113 else if ( vtxType ==
"Flat" )
115 else if ( vtxType ==
"BetaFunc" )
122 if (averageNumber_ > 0.)
124 std::cout <<
" FastSimulation/PileUpProducer -> MinBias events taken from " <<
theFileNames[0] <<
" et al., " ;
125 std::cout <<
" with an average number of events of " << averageNumber_ << std::endl;
127 else std::cout <<
" FastSimulation/PileUpProducer -> No pileup " << std::endl;
149 std::cout <<
"***WARNING*** You are reading pile-up information from the file "
150 <<
inputFile <<
" created in an earlier run."
239 HepMC::GenEvent* evt =
new HepMC::GenEvent();
244 int PUevts;
float truePUevts;
257 float d = (float)
hprob->GetRandom();
265 std::auto_ptr< PileupMixingContent > PileupMixing_;
267 std::vector<int> bunchCrossingList;
268 bunchCrossingList.push_back(0);
270 std::vector<int> numInteractionList;
271 numInteractionList.push_back(PUevts);
273 std::vector<float> trueInteractionList;
274 trueInteractionList.push_back(truePUevts);
276 PileupMixing_ = std::auto_ptr< PileupMixingContent >(
new PileupMixingContent(bunchCrossingList,numInteractionList,trueInteractionList));
277 iEvent.
put(PileupMixing_);
280 for (
int ievt=0; ievt<PUevts; ++ievt ) {
292 HepMC::FourVector smearedVertex =
297 HepMC::GenVertex* aVertex =
new HepMC::GenVertex(smearedVertex);
298 evt->add_vertex(aVertex);
301 double theAngle =
random.flatShoot() * 2. * 3.14159265358979323;
347 unsigned firstTrack = aMinBiasEvt.
first;
348 unsigned trackSize = firstTrack + aMinBiasEvt.
size;
355 for (
unsigned iTrack=firstTrack; iTrack<trackSize; ++iTrack ) {
372 + aParticle.
py*aParticle.
py
373 + aParticle.
pz*aParticle.
pz
376 HepMC::FourVector myPart(cAngle * aParticle.
px + sAngle * aParticle.
py,
377 -sAngle * aParticle.
px + cAngle * aParticle.
py,
378 aParticle.
pz, energy);
382 aVertex->add_particle_out(aGenParticle);
397 pu_product->addHepMCData( evt );
400 if ( boost ) pu_product->boostToLab(boost,
"momentum");
404 iEvent.
put(pu_product,
"PileUpEvents");
437 std::ifstream myInputFile;
445 myInputFile.open (inputFile.c_str());
446 if ( myInputFile.is_open() ) {
449 if ( stat(inputFile.c_str(), &
results) == 0 ) size = results.st_size;
453 myInputFile.seekg(size-size1-size2);
PileUpProducer(edm::ParameterSet const &p)
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< unsigned > theNumberOfMinBiasEvts
std::vector< std::string > theFileNames
double flatShoot(double xmin=0.0, double xmax=1.0) const
#define DEFINE_FWK_MODULE(type)
Sin< T >::type sin(const T &t)
bool read(std::string inputFile)
Read former minbias configuration (from previous run)
std::vector< int > dataProbFunctionVar
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< unsigned > theNumberOfEntries
virtual void generate(RandomEngineAndDistribution const *)=0
Generation process (to be implemented)
PrimaryVertexGenerator * theVertexGenerator
static std::string const input
std::ofstream myOutputFile
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Cos< T >::type cos(const T &t)
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
std::vector< unsigned > theCurrentMinBiasEvt
std::vector< PUEvent * > thePUEvents
std::vector< double > dataProb
std::vector< unsigned > theCurrentEntry
std::vector< TTree * > theTrees
virtual ~PileUpProducer()
StreamID streamID() const
std::string fullPath() const
unsigned theNumberOfFiles
tuple size
Write out results.
std::vector< TFile * > theFiles
void save()
Save current minbias configuration (for later use)
std::vector< TBranch * > theBranches