19 #include "HepMC/GenEvent.h"
33 produces<PileupMixingContent>();
35 produces<edm::HepMCProduct>(
"PileUpEvents");
39 if ( ! rng.isAvailable() ) {
41 <<
"PileUpProducer requires the RandomGeneratorService\n"
42 "which is not present in the configuration file.\n"
43 "You must add the service in the configuration file\n"
44 "or remove the module that requires it";
54 gRandom->SetSeed(rng->mySeed());
61 std::cout <<
" FastSimulation/PileUpProducer -> poissonian distribution" << std::endl;
62 averageNumber_ = pu.
getParameter<
double>(
"averageNumber");
71 std::cout <<
" FastSimulation/PileUpProducer -> distribution from configuration file " << std::endl;
73 for (
int i=0;
i<(varSize -
probSize);
i++) dataProb.push_back(0);
74 edm::LogWarning(
"") <<
" The probability function data will be completed with "
75 << (varSize -
probSize) <<
" values `0';"
76 <<
" the number of the P(x) data set after adding those 0's is " << dataProb.size();
83 std::cout <<
" FastSimulation/PileUpProducer -> An histogram will be created with " << numBins
84 <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
85 hprob =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
86 LogDebug(
"") <<
" FastSimulation/PileUpProducer -> Filling histogram with the following data:";
87 for (
int j=0;
j < numBins ;
j++){
93 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;
96 averageNumber_ =
hprob->GetMean();
113 if ( vtxType ==
"Gaussian" )
115 else if ( vtxType ==
"Flat" )
117 else if ( vtxType ==
"BetaFunc" )
124 if (averageNumber_ > 0.)
126 std::cout <<
" FastSimulation/PileUpProducer -> MinBias events taken from " <<
theFileNames[0] <<
" et al., " ;
127 std::cout <<
" with an average number of events of " << averageNumber_ << std::endl;
129 else std::cout <<
" FastSimulation/PileUpProducer -> No pileup " << std::endl;
148 std::cout <<
"***WARNING*** You are reading pile-up information from the file "
149 <<
inputFile <<
" created in an earlier run."
233 HepMC::GenEvent* evt =
new HepMC::GenEvent();
238 int PUevts;
float truePUevts;
251 float d = (float)
hprob->GetRandom();
259 std::auto_ptr< PileupMixingContent > PileupMixing_;
261 std::vector<int> bunchCrossingList;
262 bunchCrossingList.push_back(0);
264 std::vector<int> numInteractionList;
265 numInteractionList.push_back(PUevts);
267 std::vector<float> trueInteractionList;
268 trueInteractionList.push_back(truePUevts);
270 PileupMixing_ = std::auto_ptr< PileupMixingContent >(
new PileupMixingContent(bunchCrossingList,numInteractionList,trueInteractionList));
271 iEvent.
put(PileupMixing_);
274 for (
int ievt=0; ievt<PUevts; ++ievt ) {
286 HepMC::FourVector smearedVertex =
291 HepMC::GenVertex* aVertex =
new HepMC::GenVertex(smearedVertex);
292 evt->add_vertex(aVertex);
295 double theAngle =
random.flatShoot() * 2. * 3.14159265358979323;
341 unsigned firstTrack = aMinBiasEvt.
first;
342 unsigned trackSize = firstTrack + aMinBiasEvt.
size;
349 for (
unsigned iTrack=firstTrack; iTrack<trackSize; ++iTrack ) {
366 + aParticle.
py*aParticle.
py
367 + aParticle.
pz*aParticle.
pz
370 HepMC::FourVector myPart(cAngle * aParticle.
px + sAngle * aParticle.
py,
371 -sAngle * aParticle.
px + cAngle * aParticle.
py,
372 aParticle.
pz, energy);
376 aVertex->add_particle_out(aGenParticle);
395 pu_product->addHepMCData( evt );
398 if ( boost ) pu_product->boostToLab(boost,
"momentum");
402 iEvent.
put(pu_product,
"PileUpEvents");
435 std::ifstream myInputFile;
443 myInputFile.open (inputFile.c_str());
444 if ( myInputFile.is_open() ) {
447 if ( stat(inputFile.c_str(), &
results) == 0 ) size = results.st_size;
451 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
LuminosityBlockIndex index() 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
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.
bool currentValuesWereSet
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
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
volatile std::atomic< bool > shutdown_flag false
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