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";
45 gRandom->SetSeed(rng->mySeed());
52 std::cout <<
" FastSimulation/PileUpProducer -> poissonian distribution" << std::endl;
53 averageNumber_ = pu.
getParameter<
double>(
"averageNumber");
62 std::cout <<
" FastSimulation/PileUpProducer -> distribution from configuration file " << std::endl;
64 for (
int i=0;
i<(varSize -
probSize);
i++) dataProb.push_back(0);
65 edm::LogWarning(
"") <<
" The probability function data will be completed with "
66 << (varSize -
probSize) <<
" values `0';"
67 <<
" the number of the P(x) data set after adding those 0's is " << dataProb.size();
74 std::cout <<
" FastSimulation/PileUpProducer -> An histogram will be created with " << numBins
75 <<
" bins in the range ("<< xmin <<
"," << xmax <<
")." << std::endl;
76 hprob =
new TH1F(
"h",
"Histo from the user's probability function",numBins,xmin,xmax);
77 LogDebug(
"") <<
" FastSimulation/PileUpProducer -> Filling histogram with the following data:";
78 for (
int j=0;
j < numBins ;
j++){
84 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;
87 averageNumber_ =
hprob->GetMean();
103 std::string vtxType = vtx.
getParameter<std::string>(
"type");
104 if ( vtxType ==
"Gaussian" )
106 else if ( vtxType ==
"Flat" )
108 else if ( vtxType ==
"BetaFunc" )
115 if (averageNumber_ > 0.)
117 std::cout <<
" FastSimulation/PileUpProducer -> MinBias events taken from " <<
theFileNames[0] <<
" et al., " ;
118 std::cout <<
" with an average number of events of " << averageNumber_ << std::endl;
120 else std::cout <<
" FastSimulation/PileUpProducer -> No pileup " << std::endl;
137 std::string fullPath;
142 std::cout <<
"***WARNING*** You are reading pile-up information from the file "
143 <<
inputFile <<
" created in an earlier run."
229 HepMC::GenEvent* evt =
new HepMC::GenEvent();
232 int PUevts;
float truePUevts;
238 float d = (float)
hprob->GetRandom();
246 std::auto_ptr< PileupMixingContent > PileupMixing_;
248 std::vector<int> bunchCrossingList;
249 bunchCrossingList.push_back(0);
251 std::vector<int> numInteractionList;
252 numInteractionList.push_back(PUevts);
254 std::vector<float> trueInteractionList;
255 trueInteractionList.push_back(truePUevts);
257 PileupMixing_ = std::auto_ptr< PileupMixingContent >(
new PileupMixingContent(bunchCrossingList,numInteractionList,trueInteractionList));
258 iEvent.
put(PileupMixing_);
261 for (
int ievt=0; ievt<PUevts; ++ievt ) {
273 HepMC::FourVector smearedVertex =
278 HepMC::GenVertex* aVertex =
new HepMC::GenVertex(smearedVertex);
279 evt->add_vertex(aVertex);
328 unsigned firstTrack = aMinBiasEvt.
first;
329 unsigned trackSize = firstTrack + aMinBiasEvt.
size;
336 for (
unsigned iTrack=firstTrack; iTrack<trackSize; ++iTrack ) {
353 + aParticle.
py*aParticle.
py
354 + aParticle.
pz*aParticle.
pz
357 HepMC::FourVector myPart(cAngle * aParticle.
px + sAngle * aParticle.
py,
358 -sAngle * aParticle.
px + cAngle * aParticle.
py,
359 aParticle.
pz, energy);
363 aVertex->add_particle_out(aGenParticle);
378 pu_product->addHepMCData( evt );
381 if ( boost ) pu_product->boostToLab(boost,
"momentum");
385 iEvent.
put(pu_product,
"PileUpEvents");
418 ifstream myInputFile;
426 myInputFile.open (inputFile.c_str());
427 if ( myInputFile.is_open() ) {
430 if ( stat(inputFile.c_str(), &
results) == 0 ) size = results.st_size;
434 myInputFile.seekg(size-size1-size2);
PileUpProducer(edm::ParameterSet const &p)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< unsigned > theNumberOfMinBiasEvts
std::vector< std::string > theFileNames
#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
PrimaryVertexGenerator * theVertexGenerator
std::ofstream myOutputFile
virtual void produce(edm::Event &e, const edm::EventSetup &c)
virtual void beginRun(edm::Run &, edm::EventSetup const &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
unsigned int poissonShoot(double mean) const
const RandomEngine * random
Cos< T >::type cos(const T &t)
std::vector< unsigned > theCurrentMinBiasEvt
std::vector< PUEvent * > thePUEvents
virtual void generate()=0
Generation process (to be implemented)
std::vector< double > dataProb
double flatShoot(double xmin=0.0, double xmax=1.0) const
std::vector< unsigned > theCurrentEntry
std::vector< TTree * > theTrees
virtual ~PileUpProducer()
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