CMS 3D CMS Logo

CalibratedPhotonProducersRun2.cc
Go to the documentation of this file.
1 #ifndef CalibratedPhotonProducer_h
2 #define CalibratedPhotonProducer_h
3 
10 
14 
15 #include <vector>
16 #include <random>
17 #include <TRandom2.h>
18 
19 template <typename T>
21 public:
24  void produce(edm::Event &, const edm::EventSetup &) override;
25 
26 private:
29  std::unique_ptr<TRandom> theSemiDeterministicRng;
30 };
31 
32 template <typename T>
34  : thePhotonToken(consumes<edm::View<T> >(conf.getParameter<edm::InputTag>("photons"))),
35  theEnCorrectorRun2(conf.getParameter<bool>("isMC"),
36  conf.getParameter<bool>("isSynchronization"),
37  conf.getParameter<std::string>("correctionFile")) {
38  if (conf.existsAs<bool>("semiDeterministic") && conf.getParameter<bool>("semiDeterministic")) {
39  theSemiDeterministicRng.reset(new TRandom2());
41  }
42  produces<std::vector<T> >();
43 }
44 
45 template <typename T>
47 
48 template <typename T>
51  iEvent.getByToken(thePhotonToken, in);
52 
53  if (theSemiDeterministicRng && !in->empty()) { // no need to set a seed if in is empty
54  const auto &first = in->front();
55  std::seed_seq seeder = {int(iEvent.id().event()),
56  int(iEvent.id().luminosityBlock()),
57  int(iEvent.id().run()),
58  int(in->size()),
59  int(std::numeric_limits<int>::max() * first.phi() / M_PI) & 0xFFF,
60  int(first.pdgId())};
61  uint32_t seed = 0, tries = 10;
62  do {
63  seeder.generate(&seed, &seed + 1);
64  tries++;
65  } while (seed == 0 && tries < 10);
66  theSemiDeterministicRng->SetSeed(seed ? seed : iEvent.id().event());
67  }
68 
69  std::unique_ptr<std::vector<T> > out(new std::vector<T>());
70  out->reserve(in->size());
71 
72  for (const T &ele : *in) {
73  out->push_back(ele);
74  theEnCorrectorRun2.calibrate(out->back(), iEvent.id().run(), iEvent.streamID());
75  }
76 
77  iEvent.put(std::move(out));
78 }
79 
82 
84 
87 
88 #endif
RunNumber_t run() const
Definition: EventID.h:38
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
CalibratedPhotonProducerRun2T(const edm::ParameterSet &)
edm::EDGetTokenT< edm::View< T > > thePhotonToken
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
CalibratedPhotonProducerRun2T< reco::Photon > CalibratedPhotonProducerRun2
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CalibratedPhotonProducerRun2T< pat::Photon > CalibratedPatPhotonProducerRun2
PhotonEnergyCalibratorRun2 theEnCorrectorRun2
void produce(edm::Event &, const edm::EventSetup &) override
#define M_PI
void calibrate(SimplePhoton &photon, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
StreamID streamID() const
Definition: Event.h:96
long double T
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< TRandom > theSemiDeterministicRng