19 #include "HepMC/GenEvent.h"
33 produces<PileupMixingContent>();
34 produces<PileupVertexContent>();
36 produces<edm::HepMCProduct>(
"PileUpEvents");
40 if ( ! rng.isAvailable() ) {
42 <<
"PileUpProducer requires the RandomGeneratorService\n"
43 "which is not present in the configuration file.\n"
44 "You must add the service in the configuration file\n"
45 "or remove the module that requires it";
55 gRandom->SetSeed(rng->mySeed());
62 std::cout <<
" FastSimulation/PileUpProducer -> poissonian distribution" << std::endl;
63 averageNumber_ = pu.
getParameter<
double>(
"averageNumber");
72 std::cout <<
" FastSimulation/PileUpProducer -> distribution from configuration file " << std::endl;
74 for (
int i=0;
i<(varSize -
probSize);
i++) dataProb.push_back(0);
75 edm::LogWarning(
"") <<
" The probability function data will be completed with "
76 << (varSize -
probSize) <<
" values `0';"
77 <<
" the number of the P(x) data set after adding those 0's is " << dataProb.size();
84 std::cout <<
" FastSimulation/PileUpProducer -> An histogram will be created with " << numBins
85 <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
86 hprob =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
87 LogDebug(
"") <<
" FastSimulation/PileUpProducer -> Filling histogram with the following data:";
88 for (
int j=0;
j < numBins ;
j++){
94 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;
97 averageNumber_ =
hprob->GetMean();
114 if ( vtxType ==
"Gaussian" )
116 else if ( vtxType ==
"Flat" )
118 else if ( vtxType ==
"BetaFunc" )
125 if (averageNumber_ > 0.)
127 std::cout <<
" FastSimulation/PileUpProducer -> MinBias events taken from " <<
theFileNames[0] <<
" et al., " ;
128 std::cout <<
" with an average number of events of " << averageNumber_ << std::endl;
130 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."
234 HepMC::GenEvent* evt =
new HepMC::GenEvent();
239 int PUevts;
float truePUevts;
252 float d = (float)
hprob->GetRandom();
253 PUevts = (int)
random.poissonShoot(d);
263 std::auto_ptr< PileupMixingContent > PileupMixing_;
264 std::auto_ptr< PileupVertexContent > PileupVertexing_;
266 std::vector<int> bunchCrossingList;
267 bunchCrossingList.push_back(0);
269 std::vector<int> numInteractionList;
270 numInteractionList.push_back(PUevts);
272 std::vector<float> trueInteractionList;
273 trueInteractionList.push_back(truePUevts);
275 std::vector<edm::EventID> eventInfoList;
277 std::vector<float> pThatList;
278 std::vector<float> zposList;
282 eventInfoList.push_back(Fake);
283 pThatList.push_back(0.);
284 zposList.push_back(0.);
287 PileupMixing_ = std::auto_ptr< PileupMixingContent >(
new PileupMixingContent(bunchCrossingList,numInteractionList,trueInteractionList,eventInfoList,450));
288 iEvent.
put(PileupMixing_);
290 PileupVertexing_ = std::auto_ptr< PileupVertexContent >(
new PileupVertexContent(pThatList, zposList));
292 iEvent.
put(PileupVertexing_);
296 for (
int ievt=0; ievt<PUevts; ++ievt ) {
308 HepMC::FourVector smearedVertex =
313 HepMC::GenVertex* aVertex =
new HepMC::GenVertex(smearedVertex);
314 evt->add_vertex(aVertex);
317 double theAngle =
random.flatShoot() * 2. * 3.14159265358979323;
363 unsigned firstTrack = aMinBiasEvt.
first;
364 unsigned trackSize = firstTrack + aMinBiasEvt.
size;
371 for (
unsigned iTrack=firstTrack; iTrack<trackSize; ++iTrack ) {
388 + aParticle.
py*aParticle.
py
389 + aParticle.
pz*aParticle.
pz
392 HepMC::FourVector myPart(cAngle * aParticle.
px + sAngle * aParticle.
py,
393 -sAngle * aParticle.
px + cAngle * aParticle.
py,
394 aParticle.
pz, energy);
398 aVertex->add_particle_out(aGenParticle);
417 pu_product->addHepMCData( evt );
420 if ( boost ) pu_product->boostToLab(boost,
"momentum");
424 iEvent.
put(pu_product,
"PileUpEvents");
457 std::ifstream myInputFile;
465 myInputFile.open (inputFile.c_str());
466 if ( myInputFile.is_open() ) {
469 if ( stat(inputFile.c_str(), &
results) == 0 ) size = results.st_size;
473 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