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"), conf.getParameter<bool>("isSynchronization"), conf.getParameter<std::string >("correctionFile")) {
36 
37  if (conf.existsAs<bool>("semiDeterministic") && conf.getParameter<bool>("semiDeterministic")) {
38  theSemiDeterministicRng.reset(new TRandom2());
40  }
41  produces<std::vector<T> >();
42 }
43 
44 template<typename T>
46 {}
47 
48 template<typename T>
49 void
51 
53  iEvent.getByToken(thePhotonToken, in);
54 
55  if (theSemiDeterministicRng && !in->empty()) { // no need to set a seed if in is empty
56  const auto & first = in->front();
57  std::seed_seq seeder = {int(iEvent.id().event()), int(iEvent.id().luminosityBlock()), int(iEvent.id().run()),
58  int(in->size()), int(std::numeric_limits<int>::max()*first.phi()/M_PI) & 0xFFF, int(first.pdgId())};
59  uint32_t seed = 0, tries = 10;
60  do {
61  seeder.generate(&seed,&seed+1); tries++;
62  } while (seed == 0 && tries < 10);
63  theSemiDeterministicRng->SetSeed(seed ? seed : iEvent.id().event());
64  }
65 
66  std::unique_ptr<std::vector<T> > out(new std::vector<T>());
67  out->reserve(in->size());
68 
69  for (const T &ele : *in) {
70  out->push_back(ele);
71  theEnCorrectorRun2.calibrate(out->back(), iEvent.id().run(), iEvent.streamID());
72  }
73 
74  iEvent.put(std::move(out));
75 }
76 
79 
81 
84 
85 #endif
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
CalibratedPhotonProducerRun2T(const edm::ParameterSet &)
edm::EDGetTokenT< edm::View< T > > thePhotonToken
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
CalibratedPhotonProducerRun2T< reco::Photon > CalibratedPhotonProducerRun2
int iEvent
Definition: GenABIO.cc:230
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:60
HLT enums.
StreamID streamID() const
Definition: Event.h:86
long double T
def move(src, dest)
Definition: eostools.py:510
std::unique_ptr< TRandom > theSemiDeterministicRng