CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EGGainSwitchFlagProducer.cc
Go to the documentation of this file.
3 
7 
9 
12 
17 
22 
26 
28 
29 #include <memory>
30 #include <vector>
31 
32 namespace {
33  template<typename T>
35  getHandle(const edm::Event& iEvent, const edm::EDGetTokenT<T>& token)
36  {
38  iEvent.getByToken(token, handle);
39  return handle;
40  }
41 }
42 
44 
45 template<typename C>
47 
48 public:
49 
52 
53  void produce(edm::Event&, const edm::EventSetup&) override;
55  edm::EventSetup const&) override;
56 
57  template<typename T>
59  auto tag(pset.getParameter<edm::InputTag>(label));
60  if (!instance.empty())
61  tag = edm::InputTag(tag.label(), instance, tag.process());
62 
63  token = consumes<T>(tag);
64  }
65 
66 private:
67 
72 
73 };
74 
75 template<typename C>
77  hasGainSwitchFlag_("hasGainSwitchFlag")
78 
79 {
80 
81  getToken(ebRecHitsToken_,iConfig,"ebRecHits");
82  getToken(objectsToken_,iConfig,"src");
83 
84  produces<intMap>(hasGainSwitchFlag_);
85 
86 }
87 
88 template<typename C>
90 }
91 
92 template<typename C>
94 
95 
96  auto ebRecHits = *getHandle(iEvent, ebRecHitsToken_);
97  auto objects = getHandle(iEvent, objectsToken_);
98 
99  std::vector<int> objectFlags;
100 
101  for(auto& object : *objects){
102 
103  if (GainSwitchTools::hasEBGainSwitchIn5x5(*object.superCluster(), &ebRecHits, topology_)) {
104  objectFlags.emplace_back(1);
105  } else {
106  objectFlags.emplace_back(0);
107  }
108 
109  }
110 
111  std::unique_ptr<intMap> bRefMap(new intMap);
112  intMap::Filler intMapFiller(*bRefMap);
113  intMapFiller.insert(objects, objectFlags.begin(), objectFlags.end());
114  intMapFiller.fill();
115  iEvent.put(std::move(bRefMap),hasGainSwitchFlag_);
116 
117 }
118 
119 template<typename C>
121  edm::EventSetup const& es) {
122  edm::ESHandle<CaloTopology> caloTopo ;
123  es.get<CaloTopologyRecord>().get(caloTopo);
124  topology_ = caloTopo.product();
125 }
126 
129 //using PhotonGainSwitchFlagProducer=EGGainSwitchFlagProducer<edm::View<pat::Photon > >;
130 //using ElectronGainSwitchFlagProducer=EGGainSwitchFlagProducer<edm::View<pat::Electron > >;
131 
T getParameter(std::string const &) const
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
edm::EDGetTokenT< C > objectsToken_
void getToken(edm::EDGetTokenT< T > &token, const edm::ParameterSet &pset, const std::string &label, const std::string &instance="")
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
def move
Definition: eostools.py:510
tuple handle
Definition: patZpeak.py:22
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
edm::ValueMap< int > intMap
edm::EDGetTokenT< EcalRecHitCollection > ebRecHitsToken_
EGGainSwitchFlagProducer(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
static bool hasEBGainSwitchIn5x5(const reco::SuperCluster &superClus, const EcalRecHitCollection *recHits, const CaloTopology *topology)
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override