1
1
#include " FWCore/Framework/interface/Event.h"
2
+ #include " FWCore/Framework/interface/LuminosityBlock.h"
2
3
#include " FWCore/Framework/interface/MakerMacros.h"
3
4
#include " FWCore/ServiceRegistry/interface/Service.h"
5
+ #include " FWCore/Utilities/interface/Exception.h"
4
6
#include " FWCore/Utilities/interface/RandomNumberGenerator.h"
5
7
6
8
#include " SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
24
26
#include < sys/stat.h>
25
27
#include < cmath>
26
28
27
- PileUpProducer::PileUpProducer (edm::ParameterSet const & p) : hprob(0 )
29
+ PileUpProducer::PileUpProducer (edm::ParameterSet const & p) : hprob(0 ), currentValuesWereSet( false )
28
30
{
29
31
30
32
// This producer produces an object PileupMixingContent, needed by PileupSummaryInfo
@@ -138,14 +140,11 @@ PileUpProducer::~PileUpProducer() {
138
140
139
141
void PileUpProducer::beginRun (edm::Run const &, edm::EventSetup const &)
140
142
{
141
-
142
- gROOT ->cd ();
143
-
144
143
std::string fullPath;
145
144
146
145
// Read the information from a previous run (to keep reproducibility)
147
- bool input = this ->read (inputFile);
148
- if ( input )
146
+ currentValuesWereSet = this ->read (inputFile);
147
+ if ( currentValuesWereSet )
149
148
std::cout << " ***WARNING*** You are reading pile-up information from the file "
150
149
<< inputFile << " created in an earlier run."
151
150
<< std::endl;
@@ -181,37 +180,36 @@ void PileUpProducer::beginRun(edm::Run const&, edm::EventSetup const&)
181
180
theBranches[file]->SetAddress (&thePUEvents[file]);
182
181
//
183
182
theNumberOfEntries[file] = theTrees[file]->GetEntries ();
184
- // RANDOM_NUMBER_ERROR
185
- // Random numbers should only be generated in the beginLuminosityBlock method
186
- // or event methods of a module
187
- RandomEngineAndDistribution random ;
188
- // Add some randomness (if there was no input file)
189
- if ( !input )
190
- theCurrentEntry[file]
191
- = (unsigned ) (theNumberOfEntries[file] * random .flatShoot ());
192
-
193
- theTrees[file]->GetEntry (theCurrentEntry[file]);
194
- unsigned NMinBias = thePUEvents[file]->nMinBias ();
195
- theNumberOfMinBiasEvts[file] = NMinBias;
196
- // Add some randomness (if there was no input file)
197
- if ( !input )
198
- theCurrentMinBiasEvt[file] =
199
- (unsigned ) (theNumberOfMinBiasEvts[file] * random .flatShoot ());
200
-
201
- /*
202
- std::cout << "File " << theFileNames[file]
203
- << " is opened with " << theNumberOfEntries[file]
204
- << " entries and will be read from Entry/Event "
205
- << theCurrentEntry[file] << "/" << theCurrentMinBiasEvt[file]
206
- << std::endl;
207
- */
183
+
184
+ if ( currentValuesWereSet ) {
185
+ theTrees[file]->GetEntry (theCurrentEntry[file]);
186
+ unsigned NMinBias = thePUEvents[file]->nMinBias ();
187
+ theNumberOfMinBiasEvts[file] = NMinBias;
188
+ }
208
189
}
209
-
210
- // Return Loot in the same state as it was when entering.
211
190
gROOT ->cd ();
212
-
213
191
}
214
-
192
+
193
+ void PileUpProducer::beginLuminosityBlock (edm::LuminosityBlock const & lumi, edm::EventSetup const &) {
194
+ if ( !currentValuesWereSet ) {
195
+ currentValuesWereSet = true ;
196
+
197
+ RandomEngineAndDistribution random (lumi.index ());
198
+
199
+ for ( unsigned file=0 ; file < theNumberOfFiles; ++file ) {
200
+ theCurrentEntry[file] =
201
+ (unsigned ) (theNumberOfEntries[file] * random .flatShoot ());
202
+
203
+ theTrees[file]->GetEntry (theCurrentEntry[file]);
204
+ unsigned NMinBias = thePUEvents[file]->nMinBias ();
205
+ theNumberOfMinBiasEvts[file] = NMinBias;
206
+
207
+ theCurrentMinBiasEvt[file] =
208
+ (unsigned ) (theNumberOfMinBiasEvts[file] * random .flatShoot ());
209
+ }
210
+ }
211
+ }
212
+
215
213
void PileUpProducer::endRun (edm::Run const &, edm::EventSetup const &)
216
214
{
217
215
// Close all local files
@@ -226,10 +224,6 @@ void PileUpProducer::endRun(edm::Run const&, edm::EventSetup const&)
226
224
227
225
// Close the output file
228
226
myOutputFile.close ();
229
-
230
- // And return Loot in the same state as it was when entering.
231
- gROOT ->cd ();
232
-
233
227
}
234
228
235
229
void PileUpProducer::produce (edm::Event & iEvent, const edm::EventSetup & es)
@@ -383,7 +377,11 @@ void PileUpProducer::produce(edm::Event & iEvent, const edm::EventSetup & es)
383
377
384
378
}
385
379
// End of particle loop
386
-
380
+
381
+ // ERROR The way this loops through the pileup events breaks
382
+ // replay. Which events are retrieved for pileup depends on
383
+ // which previous events were processed.
384
+
387
385
// Increment for next time
388
386
++theCurrentMinBiasEvt[file];
389
387
0 commit comments