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 <vector>
20 #include <random>
21 #include <TRandom2.h>
22 
23 template <typename T>
25 public:
28  void produce(edm::Event &, const edm::EventSetup &) override;
29 
30 private:
34 
37  std::unique_ptr<TRandom> theSemiDeterministicRng;
38 };
39 
40 template <typename T>
42  : theElectronToken(consumes<edm::View<T> >(conf.getParameter<edm::InputTag>("electrons"))),
43  theGBRForestName(conf.getParameter<std::string>("gbrForestName")),
44  theEpCombinationTool(),
45  theEnCorrectorRun2(theEpCombinationTool,
46  conf.getParameter<bool>("isMC"),
47  conf.getParameter<bool>("isSynchronization"),
48  conf.getParameter<std::string>("correctionFile")) {
49  if (conf.existsAs<bool>("semiDeterministic") && conf.getParameter<bool>("semiDeterministic")) {
50  theSemiDeterministicRng.reset(new TRandom2());
52  }
53  produces<std::vector<T> >();
54 }
55 
56 template <typename T>
58 
59 template <typename T>
61  iSetup.get<GBRWrapperRcd>().get(theGBRForestName, theGBRForestHandle);
62  theEpCombinationTool.init(theGBRForestHandle.product());
63 
65  iEvent.getByToken(theElectronToken, in);
66 
67  std::unique_ptr<std::vector<T> > out(new std::vector<T>());
68  out->reserve(in->size());
69 
70  if (theSemiDeterministicRng && !in->empty()) { // no need to set a seed if in is empty
71  const auto &first = in->front();
72  std::seed_seq seeder = {int(iEvent.id().event()),
73  int(iEvent.id().luminosityBlock()),
74  int(iEvent.id().run()),
75  int(in->size()),
76  int(std::numeric_limits<int>::max() * first.phi() / M_PI) & 0xFFF,
77  int(first.pdgId())};
78  uint32_t seed = 0, tries = 10;
79  do {
80  seeder.generate(&seed, &seed + 1);
81  tries++;
82  } while (seed == 0 && tries < 10);
83  theSemiDeterministicRng->SetSeed(seed ? seed : iEvent.id().event());
84  }
85 
86  for (const T &ele : *in) {
87  out->push_back(ele);
88  theEnCorrectorRun2.calibrate(out->back(), iEvent.id().run(), iEvent.streamID());
89  }
90 
91  iEvent.put(std::move(out));
92 }
93 
96 
98 
101 
102 #endif
EpCombinationTool.h
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
CalibratedElectronProducerRun2T::theGBRForestName
std::string theGBRForestName
Definition: CalibratedElectronProducersRun2.cc:32
CalibratedPatElectronProducerRun2
CalibratedElectronProducerRun2T< pat::Electron > CalibratedPatElectronProducerRun2
Definition: CalibratedElectronProducersRun2.cc:95
CalibratedElectronProducerRun2T::theGBRForestHandle
edm::ESHandle< GBRForest > theGBRForestHandle
Definition: CalibratedElectronProducersRun2.cc:33
ESHandle.h
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
GBRWrapperRcd.h
EDProducer.h
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
GBRForest.h
edm::Handle
Definition: AssociativeIterator.h:50
dqmdumpme.first
first
Definition: dqmdumpme.py:55
MakerMacros.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CalibratedElectronProducerRun2T::theSemiDeterministicRng
std::unique_ptr< TRandom > theSemiDeterministicRng
Definition: CalibratedElectronProducersRun2.cc:37
ElectronEnergyCalibratorRun2
Definition: ElectronEnergyCalibratorRun2.h:12
edm::ESHandle< GBRForest >
ElectronEnergyCalibratorRun2.h
GsfElectron.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CalibratedElectronProducerRun2T::theEpCombinationTool
EpCombinationTool theEpCombinationTool
Definition: CalibratedElectronProducersRun2.cc:35
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
CalibratedElectronProducerRun2T::theElectronToken
edm::EDGetTokenT< edm::View< T > > theElectronToken
Definition: CalibratedElectronProducersRun2.cc:31
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
CalibratedElectronProducerRun2T::~CalibratedElectronProducerRun2T
~CalibratedElectronProducerRun2T() override
Definition: CalibratedElectronProducersRun2.cc:57
recoMuon::in
Definition: RecoMuonEnumerators.h:6
CalibratedElectronProducerRun2T::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CalibratedElectronProducersRun2.cc:60
ElectronEnergyCalibratorRun2::initPrivateRng
void initPrivateRng(TRandom *rnd)
Definition: ElectronEnergyCalibratorRun2.cc:28
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
get
#define get
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
GBRWrapperRcd
Definition: GBRWrapperRcd.h:24
CalibratedElectronProducerRun2T::CalibratedElectronProducerRun2T
CalibratedElectronProducerRun2T(const edm::ParameterSet &)
Definition: CalibratedElectronProducersRun2.cc:41
EventSetup.h
Electron.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterSet.h
CalibratedElectronProducerRun2T
Definition: CalibratedElectronProducersRun2.cc:24
edm::Event
Definition: Event.h:73
CalibratedElectronProducerRun2
CalibratedElectronProducerRun2T< reco::GsfElectron > CalibratedElectronProducerRun2
Definition: CalibratedElectronProducersRun2.cc:94
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
EpCombinationTool
Definition: EpCombinationTool.h:10
CalibratedElectronProducerRun2T::theEnCorrectorRun2
ElectronEnergyCalibratorRun2 theEnCorrectorRun2
Definition: CalibratedElectronProducersRun2.cc:36