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