CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronIDValueMapProducer.cc
Go to the documentation of this file.
3 
6 
8 
11 
14 
17 
18 #include <memory>
19 #include <vector>
20 
22 
23  public:
24 
27 
28  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
29 
30  private:
31 
32  virtual void produce(edm::Event&, const edm::EventSetup&) override;
33 
36  const std::vector<float> & values,
37  const std::string & label) const ;
38 
40 
41  // for AOD case
46 
47  // for miniAOD case
52 
53  constexpr static char eleFull5x5SigmaIEtaIEta_[] = "eleFull5x5SigmaIEtaIEta";
54  constexpr static char eleFull5x5SigmaIEtaIPhi_[] = "eleFull5x5SigmaIEtaIPhi";
55  constexpr static char eleFull5x5E1x5_[] = "eleFull5x5E1x5";
56  constexpr static char eleFull5x5E2x5_[] = "eleFull5x5E2x5";
57  constexpr static char eleFull5x5E5x5_[] = "eleFull5x5E5x5";
58  constexpr static char eleFull5x5R9_[] = "eleFull5x5R9";
59  constexpr static char eleFull5x5Circularity_[] = "eleFull5x5Circularity";
60 };
61 
69 
71 
72  //
73  // Declare consummables, handle both AOD and miniAOD case
74  //
75  ebReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
76  ("ebReducedRecHitCollection"));
77  ebReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
78  ("ebReducedRecHitCollectionMiniAOD"));
79 
80  eeReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
81  ("eeReducedRecHitCollection"));
82  eeReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
83  ("eeReducedRecHitCollectionMiniAOD"));
84 
85  esReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
86  ("esReducedRecHitCollection"));
87  esReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
88  ("esReducedRecHitCollectionMiniAOD"));
89 
90  src_ = mayConsume<edm::View<reco::GsfElectron> >(iConfig.getParameter<edm::InputTag>("src"));
91  srcMiniAOD_ = mayConsume<edm::View<reco::GsfElectron> >(iConfig.getParameter<edm::InputTag>("srcMiniAOD"));
92 
93  produces<edm::ValueMap<float> >(eleFull5x5SigmaIEtaIEta_);
94  produces<edm::ValueMap<float> >(eleFull5x5SigmaIEtaIPhi_);
95  produces<edm::ValueMap<float> >(eleFull5x5E1x5_);
96  produces<edm::ValueMap<float> >(eleFull5x5E2x5_);
97  produces<edm::ValueMap<float> >(eleFull5x5E5x5_);
98  produces<edm::ValueMap<float> >(eleFull5x5R9_);
99  produces<edm::ValueMap<float> >(eleFull5x5Circularity_);
100 
101 }
102 
104 }
105 
107 
108  using namespace edm;
109 
111 
112  // Retrieve the collection of electrons from the event.
113  // If we fail to retrieve the collection with the standard AOD
114  // name, we next look for the one with the stndard miniAOD name.
115  bool isAOD = true;
116  iEvent.getByToken(src_, src);
117 
118  if( !src.isValid() ){
119  isAOD = false;
120  iEvent.getByToken(srcMiniAOD_,src);
121  }
122 
123  if( isAOD )
124  lazyToolnoZS = new noZS::EcalClusterLazyTools(iEvent, iSetup,
128  else
129  lazyToolnoZS = new noZS::EcalClusterLazyTools(iEvent, iSetup,
133 
134  // size_t n = src->size();
135  std::vector<float> eleFull5x5SigmaIEtaIEta, eleFull5x5SigmaIEtaIPhi;
136  std::vector<float> eleFull5x5R9, eleFull5x5Circularity;
137  std::vector<float> eleFull5x5E1x5,eleFull5x5E2x5,eleFull5x5E5x5;
138 
139  // reco::GsfElectron::superCluster() is virtual so we can exploit polymorphism
140  for (size_t i = 0; i < src->size(); ++i){
141  auto iEle = src->ptrAt(i);
142  const auto& theseed = *(iEle->superCluster()->seed());
143 
144  std::vector<float> vCov = lazyToolnoZS->localCovariances( theseed );
145  const float see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0]));
146  const float sep = vCov[1];
147  eleFull5x5SigmaIEtaIEta.push_back(see);
148  eleFull5x5SigmaIEtaIPhi.push_back(sep);
149  eleFull5x5R9.push_back(lazyToolnoZS->e3x3( theseed ) / iEle->superCluster()->rawEnergy() );
150 
151  const float e1x5 = lazyToolnoZS->e1x5( theseed );
152  const float e2x5 = lazyToolnoZS->e2x5Max( theseed );
153  const float e5x5 = lazyToolnoZS->e5x5( theseed );
154  const float circularity = (e5x5 != 0.) ? 1.-e1x5/e5x5 : -1;
155 
156  eleFull5x5E1x5.push_back(e1x5);
157  eleFull5x5E2x5.push_back(e2x5);
158  eleFull5x5E5x5.push_back(e5x5);
159  eleFull5x5Circularity.push_back(circularity);
160  }
161 
162  writeValueMap(iEvent, src, eleFull5x5SigmaIEtaIEta, eleFull5x5SigmaIEtaIEta_);
163  writeValueMap(iEvent, src, eleFull5x5SigmaIEtaIPhi, eleFull5x5SigmaIEtaIPhi_);
164  writeValueMap(iEvent, src, eleFull5x5R9, eleFull5x5R9_);
165  writeValueMap(iEvent, src, eleFull5x5E1x5, eleFull5x5E1x5_);
166  writeValueMap(iEvent, src, eleFull5x5E2x5, eleFull5x5E2x5_);
167  writeValueMap(iEvent, src, eleFull5x5E5x5, eleFull5x5E5x5_);
168  writeValueMap(iEvent, src, eleFull5x5Circularity, eleFull5x5Circularity_);
169 
170  delete lazyToolnoZS;
171 }
172 
175  const std::vector<float> & values,
176  const std::string & label) const
177 {
178  using namespace edm;
179  using namespace std;
180  auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
181  edm::ValueMap<float>::Filler filler(*valMap);
182  filler.insert(handle, values.begin(), values.end());
183  filler.fill();
184  iEvent.put(valMap, label);
185 }
186 
188  //The following says we do not know what parameters are allowed so do no validation
189  // Please change this to state exactly what you do use, even if it is no parameters
191  desc.setUnknown();
192  descriptions.addDefault(desc);
193 }
194 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float e5x5(const reco::BasicCluster &cluster)
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollection_
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
float e3x3(const reco::BasicCluster &cluster)
EcalClusterLazyToolsT< noZS::EcalClusterTools > EcalClusterLazyTools
#define constexpr
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
bool isnan(float x)
Definition: math.h:13
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollectionMiniAOD_
T sqrt(T t)
Definition: SSEVec.h:18
tuple handle
Definition: patZpeak.py:22
float e2x5Max(const reco::BasicCluster &cluster)
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollectionMiniAOD_
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
ElectronIDValueMapProducer(const edm::ParameterSet &)
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollectionMiniAOD_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollection_
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollection_
float e1x5(const reco::BasicCluster &cluster)
noZS::EcalClusterLazyTools * lazyToolnoZS
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::GsfElectron > > &handle, const std::vector< float > &values, const std::string &label) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)