CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTPFPhotonIsolationProducer.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <vector>
10 #include <memory>
11 
13 
14 // Framework
20 
23 
27 
29 
31 
33 
34  pfCandidateProducer_ = consumes<reco::PFCandidateCollection>(config.getParameter<edm::InputTag>("pfCandidatesProducer"));
35 
36  useSCRefs_ = config.getParameter<bool>("useSCRefs");
37 
38  drMax_ = config.getParameter<double>("drMax");
39  drVetoBarrel_ = config.getParameter<double>("drVetoBarrel");
40  drVetoEndcap_ = config.getParameter<double>("drVetoEndcap");
41  etaStripBarrel_ = config.getParameter<double>("etaStripBarrel");
42  etaStripEndcap_ = config.getParameter<double>("etaStripEndcap");
43  energyBarrel_ = config.getParameter<double>("energyBarrel");
44  energyEndcap_ = config.getParameter<double>("energyEndcap");
45  pfToUse_ = config.getParameter<int>("pfCandidateType");
46 
47  doRhoCorrection_ = config.getParameter<bool>("doRhoCorrection");
48  if (doRhoCorrection_)
49  rhoProducer_ = consumes<double>(config.getParameter<edm::InputTag>("rhoProducer"));
50 
51  rhoMax_ = config.getParameter<double>("rhoMax");
52  rhoScale_ = config.getParameter<double>("rhoScale");
53  effectiveAreaBarrel_ = config.getParameter<double>("effectiveAreaBarrel");
54  effectiveAreaEndcap_ = config.getParameter<double>("effectiveAreaEndcap");
55 
56  if(useSCRefs_) {
57  produces < reco::RecoEcalCandidateIsolationMap >();
58  recoEcalCandidateProducer_ = consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"));
59  } else {
60  produces < reco::ElectronIsolationMap >();
61  electronProducer_ = consumes<reco::ElectronCollection>(config.getParameter<edm::InputTag>("electronProducer"));
62  }
63 }
64 
67  desc.add<edm::InputTag>("electronProducer", edm::InputTag("hltEle27WP80PixelMatchElectronsL1SeededPF"));
68  desc.add<edm::InputTag>("recoEcalCandidateProducer", edm::InputTag("hltL1SeededRecoEcalCandidatePF"));
69  desc.add<edm::InputTag>("pfCandidatesProducer", edm::InputTag("hltParticleFlowReg"));
70  desc.add<edm::InputTag>("rhoProducer", edm::InputTag("fixedGridRhoFastjetAllCalo"));
71  desc.add<bool>("doRhoCorrection", false);
72  desc.add<double>("rhoMax", 9.9999999E7);
73  desc.add<double>("rhoScale", 1.0);
74  desc.add<double>("effectiveAreaBarrel", 0.101);
75  desc.add<double>("effectiveAreaEndcap", 0.046);
76  desc.add<bool>("useSCRefs", false);
77  desc.add<double>("drMax", 0.3);
78  desc.add<double>("drVetoBarrel", 0.0);
79  desc.add<double>("drVetoEndcap", 0.0);
80  desc.add<double>("etaStripBarrel", 0.0);
81  desc.add<double>("etaStripEndcap", 0.0);
82  desc.add<double>("energyBarrel", 0.0);
83  desc.add<double>("energyEndcap", 0.0);
84  desc.add<int>("pfCandidateType", 4);
85  descriptions.add(("hltEgammaHLTPFPhotonIsolationProducer"), desc);
86 }
87 
89 
90  edm::Handle<double> rhoHandle;
91  double rho = 0.0;
92  if (doRhoCorrection_) {
93  iEvent.getByToken(rhoProducer_, rhoHandle);
94  rho = *(rhoHandle.product());
95  }
96 
97  if (rho > rhoMax_)
98  rho = rhoMax_;
99 
100  rho = rho*rhoScale_;
101 
105 
106  iEvent.getByToken(pfCandidateProducer_, pfHandle);
107 
109  reco::RecoEcalCandidateIsolationMap recoEcalCandMap;
110 
111  if(useSCRefs_) {
112 
113  iEvent.getByToken(recoEcalCandidateProducer_,recoecalcandHandle);
114 
115  float dRVeto = -1.;
116  float etaStrip = -1;
117 
118  for (unsigned int iReco = 0; iReco < recoecalcandHandle->size(); iReco++) {
119  reco::RecoEcalCandidateRef candRef(recoecalcandHandle, iReco);
120 
121  if (fabs(candRef->eta()) < 1.479) {
122  dRVeto = drVetoBarrel_;
123  etaStrip = etaStripBarrel_;
124  } else {
125  dRVeto = drVetoEndcap_;
126  etaStrip = etaStripEndcap_;
127  }
128 
129  float sum = 0;
130 
131  // Loop over the PFCandidates
132  for(unsigned i=0; i<pfHandle->size(); i++) {
133  reco::PFCandidateRef pfc(pfHandle, i);
134 
135  //require that the PFCandidate is a photon
136  if (pfc->particleId() == pfToUse_) {
137 
138  if (fabs(candRef->eta()) < 1.479) {
139  if (fabs(pfc->pt()) < energyBarrel_)
140  continue;
141  } else {
142  if (fabs(pfc->energy()) < energyEndcap_)
143  continue;
144  }
145 
146  // Shift the RecoEcalCandidate direction vector according to the PF vertex
147  math::XYZPoint pfvtx = pfc->vertex();
148  math::XYZVector candDirectionWrtVtx(candRef->superCluster()->x() - pfvtx.x(),
149  candRef->superCluster()->y() - pfvtx.y(),
150  candRef->superCluster()->z() - pfvtx.z());
151 
152  float dEta = fabs(candDirectionWrtVtx.Eta() - pfc->momentum().Eta());
153  if(dEta < etaStrip) continue;
154 
155  float dR = deltaR(candDirectionWrtVtx.Eta(), candDirectionWrtVtx.Phi(), pfc->momentum().Eta(), pfc->momentum().Phi());
156  if(dR > drMax_ || dR < dRVeto) continue;
157 
158  // Exclude PF photons which clusters are part of the candidate
159  bool clusterOverlap = false;
160  for(unsigned b=0; b<pfc->elementsInBlocks().size(); b++){
161  reco::PFBlockRef blockRef = pfc->elementsInBlocks()[b].first;
162  unsigned elementIndex = pfc->elementsInBlocks()[b].second;
163  if(blockRef.isNull()) continue;
164  const edm::OwnVector< reco::PFBlockElement >& elements = blockRef->elements();
165  const reco::PFBlockElement& pfbe(elements[elementIndex]);
166  if( pfbe.type() == reco::PFBlockElement::ECAL ){
167  reco::PFClusterRef myPFClusterRef = pfbe.clusterRef();
168  if(myPFClusterRef.isNull()) continue;
169  for(reco::CaloCluster_iterator it = candRef->superCluster()->clustersBegin(); it != candRef->superCluster()->clustersEnd(); ++it){
170  if( myPFClusterRef->seed() == (*it)->seed() ){
171  clusterOverlap = true;
172  break;
173  }
174  }
175  }
176  if(clusterOverlap) break;
177  }
178  if(clusterOverlap) continue;
179 
180  sum += pfc->pt();
181  }
182  }
183 
184  if (doRhoCorrection_) {
185  if (fabs(candRef->eta()) < 1.479)
186  sum = sum - rho*effectiveAreaBarrel_;
187  else
188  sum = sum - rho*effectiveAreaEndcap_;
189  }
190 
191  recoEcalCandMap.insert(candRef, sum);
192  }
193 
194  } else {
195 
196  iEvent.getByToken(electronProducer_,electronHandle);
197 
198  float dRVeto = -1.;
199  float etaStrip = -1;
200 
201  for(unsigned int iEl=0; iEl<electronHandle->size(); iEl++) {
202  reco::ElectronRef eleRef(electronHandle, iEl);
203 
204  if (fabs(eleRef->eta()) < 1.479) {
205  dRVeto = drVetoBarrel_;
206  etaStrip = etaStripBarrel_;
207  } else {
208  dRVeto = drVetoEndcap_;
209  etaStrip = etaStripEndcap_;
210  }
211 
212  float sum = 0;
213 
214  // Loop over the PFCandidates
215  for(unsigned i=0; i<pfHandle->size(); i++) {
216  reco::PFCandidateRef pfc(pfHandle, i);
217 
218  //require that the PFCandidate is a photon
219  if (pfc->particleId() == pfToUse_) {
220 
221  if (fabs(eleRef->eta()) < 1.479) {
222  if (fabs(pfc->pt()) < energyBarrel_)
223  continue;
224  } else {
225  if (fabs(pfc->energy()) < energyEndcap_)
226  continue;
227  }
228 
229  float dEta = fabs(eleRef->eta() - pfc->momentum().Eta());
230  if(dEta < etaStrip)
231  continue;
232 
233  float dR = deltaR(eleRef->eta(), eleRef->phi(), pfc->momentum().Eta(), pfc->momentum().Phi());
234  if(dR > drMax_ || dR < dRVeto)
235  continue;
236 
237  // Exclude PF photons which clusters are part of the electron supercluster
238  bool clusterOverlap = false;
239  for(unsigned b=0; b<pfc->elementsInBlocks().size(); b++){
240  reco::PFBlockRef blockRef = pfc->elementsInBlocks()[b].first;
241  unsigned elementIndex = pfc->elementsInBlocks()[b].second;
242  if(blockRef.isNull()) continue;
243  const edm::OwnVector< reco::PFBlockElement >& elements = blockRef->elements();
244  const reco::PFBlockElement& pfbe(elements[elementIndex]);
245  if( pfbe.type() == reco::PFBlockElement::ECAL ){
246  reco::PFClusterRef myPFClusterRef = pfbe.clusterRef();
247  if(myPFClusterRef.isNull()) continue;
248  for(reco::CaloCluster_iterator it = eleRef->superCluster()->clustersBegin(); it != eleRef->superCluster()->clustersEnd(); ++it){
249  if( myPFClusterRef->seed() == (*it)->seed() ){
250  clusterOverlap = true;
251  break;
252  }
253  }
254  }
255  if(clusterOverlap) break;
256  }
257  if(clusterOverlap) continue;
258 
259  sum += pfc->pt();
260  }
261  }
262 
263  if (doRhoCorrection_) {
264  if (fabs(eleRef->eta()) < 1.479)
265  sum = sum - rho*effectiveAreaBarrel_;
266  else
267  sum = sum - rho*effectiveAreaEndcap_;
268  }
269 
270  eleMap.insert(eleRef, sum);
271  }
272 
273  }
274 
275  if(useSCRefs_){
276  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> mapForEvent(new reco::RecoEcalCandidateIsolationMap(recoEcalCandMap));
277  iEvent.put(mapForEvent);
278  }else{
279  std::auto_ptr<reco::ElectronIsolationMap> mapForEvent(new reco::ElectronIsolationMap(eleMap));
280  iEvent.put(mapForEvent);
281  }
282 }
T getParameter(std::string const &) const
Abstract base class for a PFBlock element (track, cluster...)
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual const PFClusterRef & clusterRef() const
Type type() const
Definition: DDAxes.h:10
list elements
Definition: asciidump.py:414
edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
int iEvent
Definition: GenABIO.cc:230
bool isNull() const
Checks for null.
Definition: Ref.h:247
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidateProducer_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
void insert(const key_type &k, const data_type &v)
insert an association
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
double b
Definition: hdecay.h:120
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T const * product() const
Definition: Handle.h:81
virtual void produce(edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_