Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:17:50

0001 #ifndef RecoEgamma_EgammaTools_EgammaRandomSeeds_h
0002 #define RecoEgamma_EgammaTools_EgammaRandomSeeds_h
0003 
0004 //author: Sam Harper (RAL)
0005 //description:
0006 //  provides a seed for a random number generator based on object / event properties
0007 //  the supercluster method is prefered as it will be the same for electrons & photons
0008 //  the SC is based on seed ID and #crystals in SC, the #crystals in SC is for added
0009 //  entropy although this means any re-recos will change the returned number as #crystals
0010 //  will likely change with any re-reco while seed ID is fairly stable
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0014 
0015 #include <random>
0016 
0017 namespace egamma {
0018 
0019   uint32_t getRandomSeedFromSC(const edm::Event& iEvent, const reco::SuperClusterRef scRef);
0020   template <typename T>
0021   uint32_t getRandomSeedFromObj(const edm::Event& iEvent, const T& obj, size_t nrObjs, size_t objNr) {
0022     std::seed_seq seeder = {int(iEvent.id().event()),
0023                             int(iEvent.id().luminosityBlock()),
0024                             int(iEvent.id().run()),
0025                             int(nrObjs),
0026                             int(std::numeric_limits<int>::max() * obj.phi() / M_PI) & 0xFFF,
0027                             int(objNr)};
0028     uint32_t seed = 0, tries = 10;
0029     do {
0030       seeder.generate(&seed, &seed + 1);
0031       tries++;
0032     } while (seed == 0 && tries < 10);
0033     return seed ? seed : iEvent.id().event() + 10000 * objNr;
0034   }
0035 }  // namespace egamma
0036 
0037 #endif