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 {
26  public:
29  void produce( edm::Event &, const edm::EventSetup & ) override ;
30 
31  private:
35 
38  std::unique_ptr<TRandom> theSemiDeterministicRng;
39 
40 };
41 
42 template<typename T>
44  theElectronToken(consumes<edm::View<T> >(conf.getParameter<edm::InputTag>("electrons"))),
45  theGBRForestName(conf.getParameter<std::string>("gbrForestName")),
47  theEnCorrectorRun2(theEpCombinationTool, conf.getParameter<bool>("isMC"), conf.getParameter<bool>("isSynchronization"), conf.getParameter<std::string>("correctionFile"))
48 {
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 }
60 
61 template<typename T>
62 void
64 {
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()), int(iEvent.id().luminosityBlock()), int(iEvent.id().run()),
77  int(in->size()), int(std::numeric_limits<int>::max()*first.phi()/M_PI) & 0xFFF, int(first.pdgId())};
78  uint32_t seed = 0, tries = 10;
79  do {
80  seeder.generate(&seed,&seed+1); tries++;
81  } while (seed == 0 && tries < 10);
82  theSemiDeterministicRng->SetSeed(seed ? seed : iEvent.id().event());
83  }
84 
85  for (const T &ele : *in) {
86  out->push_back(ele);
87  theEnCorrectorRun2.calibrate(out->back(), iEvent.id().run(), iEvent.streamID());
88  }
89 
90  iEvent.put(std::move(out));
91 }
92 
95 
97 
100 
101 #endif
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
CalibratedElectronProducerRun2T< reco::GsfElectron > CalibratedElectronProducerRun2
edm::EDGetTokenT< edm::View< T > > theElectronToken
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
CalibratedElectronProducerRun2T(const edm::ParameterSet &)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool init(const GBRForest *forest)
void produce(edm::Event &, const edm::EventSetup &) override
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
void calibrate(SimpleElectron &electron, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
int iEvent
Definition: GenABIO.cc:230
CalibratedElectronProducerRun2T< pat::Electron > CalibratedPatElectronProducerRun2
#define M_PI
std::unique_ptr< TRandom > theSemiDeterministicRng
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
T get() const
Definition: EventSetup.h:62
StreamID streamID() const
Definition: Event.h:96
long double T
T const * product() const
Definition: ESHandle.h:86
ElectronEnergyCalibratorRun2 theEnCorrectorRun2
def move(src, dest)
Definition: eostools.py:511