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 
45 
47 
48  constexpr static char eleFull5x5SigmaIEtaIEta_[] = "eleFull5x5SigmaIEtaIEta";
49  constexpr static char eleFull5x5SigmaIEtaIPhi_[] = "eleFull5x5SigmaIEtaIPhi";
50  constexpr static char eleFull5x5E1x5_[] = "eleFull5x5E1x5";
51  constexpr static char eleFull5x5E2x5_[] = "eleFull5x5E2x5";
52  constexpr static char eleFull5x5E5x5_[] = "eleFull5x5E5x5";
53  constexpr static char eleFull5x5R9_[] = "eleFull5x5R9";
54  constexpr static char eleFull5x5Circularity_[] = "eleFull5x5Circularity";
55 };
56 
64 
66 
67  ebReducedRecHitCollection_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ebReducedRecHitCollection"));
68  eeReducedRecHitCollection_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("eeReducedRecHitCollection"));
69  esReducedRecHitCollection_ = consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("esReducedRecHitCollection"));
70 
71  src_ = consumes<edm::View<reco::GsfElectron> >(iConfig.getParameter<edm::InputTag>("src"));
72 
73  dataFormat_ = iConfig.getParameter<std::string>("dataFormat");
74  if( dataFormat_ != "RECO" && dataFormat_ != "PAT") {
75  throw cms::Exception("InvalidConfiguration")
76  << "ElectronIDValueMapProducer runs in \"RECO\" or \"PAT\" mode!";
77  }
78 
79  produces<edm::ValueMap<float> >(eleFull5x5SigmaIEtaIEta_);
80  produces<edm::ValueMap<float> >(eleFull5x5SigmaIEtaIPhi_);
81  produces<edm::ValueMap<float> >(eleFull5x5E1x5_);
82  produces<edm::ValueMap<float> >(eleFull5x5E2x5_);
83  produces<edm::ValueMap<float> >(eleFull5x5E5x5_);
84  produces<edm::ValueMap<float> >(eleFull5x5R9_);
85  produces<edm::ValueMap<float> >(eleFull5x5Circularity_);
86 
87 }
88 
90 }
91 
93 
94  using namespace edm;
95 
96  lazyToolnoZS = new noZS::EcalClusterLazyTools(iEvent, iSetup, ebReducedRecHitCollection_, eeReducedRecHitCollection_); //, esReducedRecHitCollection_
97 
99  iEvent.getByToken(src_, src);
100 
101  if( dataFormat_ == "PAT" && src->size() ) {
102  edm::Ptr<pat::Electron> test(src->ptrAt(0));
103  if( test.isNull() || !test.isAvailable() ) {
104  throw cms::Exception("InvalidConfiguration")
105  <<"DataFormat set to \"PAT\" but cannot cast to pat::Electron!";
106  }
107  }
108 
109  // size_t n = src->size();
110  std::vector<float> eleFull5x5SigmaIEtaIEta, eleFull5x5SigmaIEtaIPhi;
111  std::vector<float> eleFull5x5R9, eleFull5x5Circularity;
112  std::vector<float> eleFull5x5E1x5,eleFull5x5E2x5,eleFull5x5E5x5;
113 
114  // reco::GsfElectron::superCluster() is virtual so we can exploit polymorphism
115  for (size_t i = 0; i < src->size(); ++i){
116  auto iEle = src->ptrAt(i);
117  const auto& theseed = *(iEle->superCluster()->seed());
118 
119  std::vector<float> vCov = lazyToolnoZS->localCovariances( theseed );
120  const float see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0]));
121  const float sep = vCov[1];
122  eleFull5x5SigmaIEtaIEta.push_back(see);
123  eleFull5x5SigmaIEtaIPhi.push_back(sep);
124  eleFull5x5R9.push_back(lazyToolnoZS->e3x3( theseed ) / iEle->superCluster()->rawEnergy() );
125 
126  const float e1x5 = lazyToolnoZS->e1x5( theseed );
127  const float e2x5 = lazyToolnoZS->e2x5Max( theseed );
128  const float e5x5 = lazyToolnoZS->e5x5( theseed );
129  const float circularity = (e5x5 != 0.) ? 1.-e1x5/e5x5 : -1;
130 
131  eleFull5x5E1x5.push_back(e1x5);
132  eleFull5x5E2x5.push_back(e2x5);
133  eleFull5x5E5x5.push_back(e5x5);
134  eleFull5x5Circularity.push_back(circularity);
135  }
136 
137  writeValueMap(iEvent, src, eleFull5x5SigmaIEtaIEta, eleFull5x5SigmaIEtaIEta_);
138  writeValueMap(iEvent, src, eleFull5x5SigmaIEtaIPhi, eleFull5x5SigmaIEtaIPhi_);
139  writeValueMap(iEvent, src, eleFull5x5R9, eleFull5x5R9_);
140  writeValueMap(iEvent, src, eleFull5x5E1x5, eleFull5x5E1x5_);
141  writeValueMap(iEvent, src, eleFull5x5E2x5, eleFull5x5E2x5_);
142  writeValueMap(iEvent, src, eleFull5x5E5x5, eleFull5x5E5x5_);
143  writeValueMap(iEvent, src, eleFull5x5Circularity, eleFull5x5Circularity_);
144 
145  delete lazyToolnoZS;
146 }
147 
150  const std::vector<float> & values,
151  const std::string & label) const
152 {
153  using namespace edm;
154  using namespace std;
155  auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
156  edm::ValueMap<float>::Filler filler(*valMap);
157  filler.insert(handle, values.begin(), values.end());
158  filler.fill();
159  iEvent.put(valMap, label);
160 }
161 
163  //The following says we do not know what parameters are allowed so do no validation
164  // Please change this to state exactly what you do use, even if it is no parameters
166  desc.setUnknown();
167  descriptions.addDefault(desc);
168 }
169 
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:449
#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:113
bool isnan(float x)
Definition: math.h:13
T sqrt(T t)
Definition: SSEVec.h:48
tuple handle
Definition: patZpeak.py:22
float e2x5Max(const reco::BasicCluster &cluster)
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
ElectronIDValueMapProducer(const edm::ParameterSet &)
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)