CMS 3D CMS Logo

CalibratedElectronProducersRun2.cc
Go to the documentation of this file.
1 #ifndef CalibratedElectronProducerRun2_h
2 #define CalibratedElectronProducerRun2_h
3 
10 
13 
18 
19 #include <memory>
20 
21 #include <TRandom2.h>
22 #include <random>
23 #include <vector>
24 
25 template <typename T>
27 public:
30  void produce(edm::Event &, const edm::EventSetup &) override;
31 
32 private:
35 
38  std::unique_ptr<TRandom> theSemiDeterministicRng;
39 
41 };
42 
43 template <typename T>
45  : theElectronToken(consumes<edm::View<T> >(conf.getParameter<edm::InputTag>("electrons"))),
46  theGBRForestName(conf.getParameter<std::string>("gbrForestName")),
47  theEpCombinationTool(),
48  theEnCorrectorRun2(theEpCombinationTool,
49  conf.getParameter<bool>("isMC"),
50  conf.getParameter<bool>("isSynchronization"),
51  conf.getParameter<std::string>("correctionFile")) {
52  if (conf.existsAs<bool>("semiDeterministic") && conf.getParameter<bool>("semiDeterministic")) {
53  theSemiDeterministicRng = std::make_unique<TRandom2>();
55  }
57  produces<std::vector<T> >();
58 }
59 
60 template <typename T>
62 
63 template <typename T>
65  const GBRForest *theGBRForest = &iSetup.getData(gbrforestToken_);
66  theEpCombinationTool.init(theGBRForest);
67 
69  iEvent.getByToken(theElectronToken, in);
70 
71  std::unique_ptr<std::vector<T> > out(new std::vector<T>());
72  out->reserve(in->size());
73 
74  if (theSemiDeterministicRng && !in->empty()) { // no need to set a seed if in is empty
75  const auto &first = in->front();
76  std::seed_seq seeder = {int(iEvent.id().event()),
77  int(iEvent.id().luminosityBlock()),
78  int(iEvent.id().run()),
79  int(in->size()),
80  int(std::numeric_limits<int>::max() * first.phi() / M_PI) & 0xFFF,
81  int(first.pdgId())};
82  uint32_t seed = 0, tries = 10;
83  do {
84  seeder.generate(&seed, &seed + 1);
85  tries++;
86  } while (seed == 0 && tries < 10);
87  theSemiDeterministicRng->SetSeed(seed ? seed : iEvent.id().event());
88  }
89 
90  for (const T &ele : *in) {
91  out->push_back(ele);
92  theEnCorrectorRun2.calibrate(out->back(), iEvent.id().run(), iEvent.streamID());
93  }
94 
95  iEvent.put(std::move(out));
96 }
97 
100 
102 
105 
106 #endif
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CalibratedElectronProducerRun2T< reco::GsfElectron > CalibratedElectronProducerRun2
edm::EDGetTokenT< edm::View< T > > theElectronToken
CalibratedElectronProducerRun2T(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
void produce(edm::Event &, const edm::EventSetup &) override
edm::ESGetToken< GBRForest, GBRWrapperRcd > gbrforestToken_
int iEvent
Definition: GenABIO.cc:224
bool getData(T &iHolder) const
Definition: EventSetup.h:122
CalibratedElectronProducerRun2T< pat::Electron > CalibratedPatElectronProducerRun2
#define M_PI
std::unique_ptr< TRandom > theSemiDeterministicRng
HLT enums.
long double T
ElectronEnergyCalibratorRun2 theEnCorrectorRun2
def move(src, dest)
Definition: eostools.py:511