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);
260 std::auto_ptr< PileupMixingContent > PileupMixing_;
261 std::auto_ptr< PileupVertexContent > PileupVertexing_;
263 std::vector<int> bunchCrossingList;
264 bunchCrossingList.push_back(0);
266 std::vector<int> numInteractionList;
267 numInteractionList.push_back(PUevts);
269 std::vector<float> trueInteractionList;
270 trueInteractionList.push_back(truePUevts);
272 std::vector<edm::EventID> eventInfoList;
274 std::vector<float> pThatList;
275 std::vector<float> zposList;
281 eventInfoList.push_back(Fake);
282 pThatList.push_back(0.);
283 zposList.push_back(0.);
286 PileupMixing_ = std::auto_ptr< PileupMixingContent >(
new PileupMixingContent(bunchCrossingList,numInteractionList,trueInteractionList,eventInfoList,450));
287 iEvent.
put(PileupMixing_);
289 PileupVertexing_ = std::auto_ptr< PileupVertexContent >(
new PileupVertexContent(pThatList, zposList));
291 iEvent.
put(PileupVertexing_);
294 for (
int ievt=0; ievt<PUevts; ++ievt ) {
306 HepMC::FourVector smearedVertex =
311 HepMC::GenVertex* aVertex =
new HepMC::GenVertex(smearedVertex);
312 evt->add_vertex(aVertex);
315 double theAngle =
random.flatShoot() * 2. * 3.14159265358979323;
361 unsigned firstTrack = aMinBiasEvt.
first;
362 unsigned trackSize = firstTrack + aMinBiasEvt.
size;
369 for (
unsigned iTrack=firstTrack; iTrack<trackSize; ++iTrack ) {
386 + aParticle.
py*aParticle.
py
387 + aParticle.
pz*aParticle.
pz
390 HepMC::FourVector myPart(cAngle * aParticle.
px + sAngle * aParticle.
py,
391 -sAngle * aParticle.
px + cAngle * aParticle.
py,
392 aParticle.
pz, energy);
396 aVertex->add_particle_out(aGenParticle);
415 pu_product->addHepMCData( evt );
418 if ( boost ) pu_product->boostToLab(boost,
"momentum");
422 iEvent.
put(pu_product,
"PileUpEvents");
455 std::ifstream myInputFile;
463 myInputFile.open (inputFile.c_str());
464 if ( myInputFile.is_open() ) {
467 if ( stat(inputFile.c_str(), &
results) == 0 ) size = results.st_size;
471 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