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