Skip to content

Commit

Permalink
Merge pull request #2436 from wddgit/migrateToNewRandomServiceInterface2
Browse files Browse the repository at this point in the history
Multithreading fixes -- Migrate to New Random Service Interface
  • Loading branch information
ktf committed Feb 14, 2014
2 parents 5337ffa + edf3874 commit 668322a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
9 changes: 5 additions & 4 deletions RecoHI/HiEgammaAlgos/interface/TxCalculator.h
Expand Up @@ -19,11 +19,12 @@
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"

#include "CLHEP/Random/RandFlat.h"


#define PI 3.141592653

namespace CLHEP {
class HepRandomEngine;
}

class TxCalculator
{
public:
Expand All @@ -41,7 +42,7 @@ class TxCalculator
private:

edm::Handle<reco::TrackCollection> recCollection;
CLHEP::RandFlat *theDice;
CLHEP::HepRandomEngine *theDice;

double dRDistance(double eta1,double phi1,double eta2,double phi2)
{
Expand Down
10 changes: 5 additions & 5 deletions RecoHI/HiEgammaAlgos/src/TxCalculator.cc
Expand Up @@ -15,6 +15,8 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"

#include "CLHEP/Random/RandomEngine.h"

using namespace edm;
using namespace reco;
using namespace std;
Expand All @@ -31,9 +33,7 @@ TxCalculator::TxCalculator (const edm::Event &iEvent, const edm::EventSetup &iSe
"which is not present in the configuration file. You must add the service\n"
"in the configuration file or remove the modules that require it.";
}
CLHEP::HepRandomEngine& engine = rng->getEngine();
theDice = new CLHEP::RandFlat(engine, 0, 1);

theDice = &rng->getEngine(iEvent.streamID());
}


Expand Down Expand Up @@ -98,7 +98,7 @@ double TxCalculator::getTx(const reco::Photon& cluster, double x, double thresho
for(reco::TrackCollection::const_iterator
recTrack = recCollection->begin(); recTrack!= recCollection->end(); recTrack++)
{
double diceNum = theDice->fire();
double diceNum = theDice->flat();
if ( (effRatio < 1 ) && ( diceNum > effRatio))
continue;

Expand Down Expand Up @@ -135,7 +135,7 @@ double TxCalculator::getCTx(const reco::Photon& cluster, double x, double thresh
for(reco::TrackCollection::const_iterator
recTrack = recCollection->begin(); recTrack!= recCollection->end(); recTrack++)
{
double diceNum = theDice->fire();
double diceNum = theDice->flat();
if ( (effRatio < 1 ) && ( diceNum > effRatio))
continue;

Expand Down
30 changes: 13 additions & 17 deletions RecoJets/FFTJetProducers/plugins/FFTJetVertexAdder.cc
Expand Up @@ -81,8 +81,6 @@ class FFTJetVertexAdder : public edm::EDProducer
const double errZ;

const unsigned nVerticesToMake;

CLHEP::RandGauss* rGauss_;
};

//
Expand All @@ -105,23 +103,24 @@ FFTJetVertexAdder::FFTJetVertexAdder(const edm::ParameterSet& ps)
init_param(double, errX),
init_param(double, errY),
init_param(double, errZ),
init_param(unsigned, nVerticesToMake),
rGauss_(0)
init_param(unsigned, nVerticesToMake)
{
produces<reco::VertexCollection>(outputLabel);
}


FFTJetVertexAdder::~FFTJetVertexAdder()
{
delete rGauss_;
}


// ------------ method called to produce the data ------------
void FFTJetVertexAdder::produce(
edm::Event& iEvent, const edm::EventSetup& iSetup)
{
edm::Service<edm::RandomNumberGenerator> rng;
CLHEP::RandGauss rGauss(rng->getEngine(iEvent.streamID()));

// get PFCandidates
std::auto_ptr<reco::VertexCollection> pOutput(new reco::VertexCollection);

Expand Down Expand Up @@ -162,9 +161,9 @@ void FFTJetVertexAdder::produce(

for (unsigned iv=0; iv<nVerticesToMake; ++iv)
{
const double x0 = (*rGauss_)(xmean, xwidth);
const double y0 = (*rGauss_)(ymean, ywidth);
const double z0 = (*rGauss_)(zmean, zwidth);
const double x0 = rGauss(xmean, xwidth);
const double y0 = rGauss(ymean, ywidth);
const double z0 = rGauss(zmean, zwidth);
const reco::Vertex::Point position(x0, y0, z0);
pOutput->push_back(reco::Vertex(position, err, chi2, nDof, 0));
}
Expand Down Expand Up @@ -193,15 +192,12 @@ void FFTJetVertexAdder::produce(
// ------------ method called once each job just before starting event loop
void FFTJetVertexAdder::beginJob()
{
if (!rGauss_)
{
edm::Service<edm::RandomNumberGenerator> rng;
if ( !rng.isAvailable() )
throw cms::Exception("FFTJetBadConfig")
<< "ERROR in FFTJetVertexAdder:"
" failed to initialize the random number generator"
<< std::endl;
rGauss_ = new CLHEP::RandGauss(rng->getEngine());
edm::Service<edm::RandomNumberGenerator> rng;
if ( !rng.isAvailable() ) {
throw cms::Exception("FFTJetBadConfig")
<< "ERROR in FFTJetVertexAdder:"
" failed to initialize the random number generator"
<< std::endl;
}
}

Expand Down

0 comments on commit 668322a

Please sign in to comment.