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
PhotonEnergyCalibratorRun2.h
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
ESHandle.h
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Photon.h
EDProducer.h
CalibratedPhotonProducerRun2T::theSemiDeterministicRng
std::unique_ptr< TRandom > theSemiDeterministicRng
Definition: CalibratedPhotonProducersRun2.cc:29
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
edm::Handle
Definition: AssociativeIterator.h:50
dqmdumpme.first
first
Definition: dqmdumpme.py:55
MakerMacros.h
Photon.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CalibratedPhotonProducerRun2T::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CalibratedPhotonProducersRun2.cc:49
PhotonEnergyCalibratorRun2
Definition: PhotonEnergyCalibratorRun2.h:11
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
recoMuon::in
Definition: RecoMuonEnumerators.h:6
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:50
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
CalibratedPhotonProducerRun2T::~CalibratedPhotonProducerRun2T
~CalibratedPhotonProducerRun2T() override
Definition: CalibratedPhotonProducersRun2.cc:46
CalibratedPhotonProducerRun2T
Definition: CalibratedPhotonProducersRun2.cc:20
CalibratedPhotonProducerRun2T::theEnCorrectorRun2
PhotonEnergyCalibratorRun2 theEnCorrectorRun2
Definition: CalibratedPhotonProducersRun2.cc:28
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
T
long double T
Definition: Basic3DVectorLD.h:48
EventSetup.h
CalibratedPhotonProducerRun2
CalibratedPhotonProducerRun2T< reco::Photon > CalibratedPhotonProducerRun2
Definition: CalibratedPhotonProducersRun2.cc:80
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterSet.h
CalibratedPhotonProducerRun2T::CalibratedPhotonProducerRun2T
CalibratedPhotonProducerRun2T(const edm::ParameterSet &)
Definition: CalibratedPhotonProducersRun2.cc:33
edm::Event
Definition: Event.h:73
CalibratedPhotonProducerRun2T::thePhotonToken
edm::EDGetTokenT< edm::View< T > > thePhotonToken
Definition: CalibratedPhotonProducersRun2.cc:27
PhotonEnergyCalibratorRun2::initPrivateRng
void initPrivateRng(TRandom *rnd)
Definition: PhotonEnergyCalibratorRun2.cc:24
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
CalibratedPatPhotonProducerRun2
CalibratedPhotonProducerRun2T< pat::Photon > CalibratedPatPhotonProducerRun2
Definition: CalibratedPhotonProducersRun2.cc:81