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 
108  if(useSCRefs_) {
109 
110  iEvent.getByToken(recoEcalCandidateProducer_,recoecalcandHandle);
111  reco::RecoEcalCandidateIsolationMap recoEcalCandMap(recoecalcandHandle);
112 
113  float dRVeto = -1.;
114  float etaStrip = -1;
115 
116  for (unsigned int iReco = 0; iReco < recoecalcandHandle->size(); iReco++) {
117  reco::RecoEcalCandidateRef candRef(recoecalcandHandle, iReco);
118 
119  if (fabs(candRef->eta()) < 1.479) {
120  dRVeto = drVetoBarrel_;
121  etaStrip = etaStripBarrel_;
122  } else {
123  dRVeto = drVetoEndcap_;
124  etaStrip = etaStripEndcap_;
125  }
126 
127  float sum = 0;
128 
129  // Loop over the PFCandidates
130  for(unsigned i=0; i<pfHandle->size(); i++) {
131  reco::PFCandidateRef pfc(pfHandle, i);
132 
133  //require that the PFCandidate is a photon
134  if (pfc->particleId() == pfToUse_) {
135 
136  if (fabs(candRef->eta()) < 1.479) {
137  if (fabs(pfc->pt()) < energyBarrel_)
138  continue;
139  } else {
140  if (fabs(pfc->energy()) < energyEndcap_)
141  continue;
142  }
143 
144  // Shift the RecoEcalCandidate direction vector according to the PF vertex
145  math::XYZPoint pfvtx = pfc->vertex();
146  math::XYZVector candDirectionWrtVtx(candRef->superCluster()->x() - pfvtx.x(),
147  candRef->superCluster()->y() - pfvtx.y(),
148  candRef->superCluster()->z() - pfvtx.z());
149 
150  float dEta = fabs(candDirectionWrtVtx.Eta() - pfc->momentum().Eta());
151  if(dEta < etaStrip) continue;
152 
153  float dR = deltaR(candDirectionWrtVtx.Eta(), candDirectionWrtVtx.Phi(), pfc->momentum().Eta(), pfc->momentum().Phi());
154  if(dR > drMax_ || dR < dRVeto) continue;
155 
156  // Exclude PF photons which clusters are part of the candidate
157  bool clusterOverlap = false;
158  for(unsigned b=0; b<pfc->elementsInBlocks().size(); b++){
159  reco::PFBlockRef blockRef = pfc->elementsInBlocks()[b].first;
160  unsigned elementIndex = pfc->elementsInBlocks()[b].second;
161  if(blockRef.isNull()) continue;
162  const edm::OwnVector< reco::PFBlockElement >& elements = blockRef->elements();
163  const reco::PFBlockElement& pfbe(elements[elementIndex]);
164  if( pfbe.type() == reco::PFBlockElement::ECAL ){
165  reco::PFClusterRef myPFClusterRef = pfbe.clusterRef();
166  if(myPFClusterRef.isNull()) continue;
167  for(reco::CaloCluster_iterator it = candRef->superCluster()->clustersBegin(); it != candRef->superCluster()->clustersEnd(); ++it){
168  if( myPFClusterRef->seed() == (*it)->seed() ){
169  clusterOverlap = true;
170  break;
171  }
172  }
173  }
174  if(clusterOverlap) break;
175  }
176  if(clusterOverlap) continue;
177 
178  sum += pfc->pt();
179  }
180  }
181 
182  if (doRhoCorrection_) {
183  if (fabs(candRef->eta()) < 1.479)
184  sum = sum - rho*effectiveAreaBarrel_;
185  else
186  sum = sum - rho*effectiveAreaEndcap_;
187  }
188 
189  recoEcalCandMap.insert(candRef, sum);
190  }
191  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> mapForEvent(new reco::RecoEcalCandidateIsolationMap(recoEcalCandMap));
192  iEvent.put(mapForEvent);
193 
194  } else {
195 
196  iEvent.getByToken(electronProducer_,electronHandle);
197  reco::ElectronIsolationMap eleMap(electronHandle);
198 
199  float dRVeto = -1.;
200  float etaStrip = -1;
201 
202  for(unsigned int iEl=0; iEl<electronHandle->size(); iEl++) {
203  reco::ElectronRef eleRef(electronHandle, iEl);
204 
205  if (fabs(eleRef->eta()) < 1.479) {
206  dRVeto = drVetoBarrel_;
207  etaStrip = etaStripBarrel_;
208  } else {
209  dRVeto = drVetoEndcap_;
210  etaStrip = etaStripEndcap_;
211  }
212 
213  float sum = 0;
214 
215  // Loop over the PFCandidates
216  for(unsigned i=0; i<pfHandle->size(); i++) {
217  reco::PFCandidateRef pfc(pfHandle, i);
218 
219  //require that the PFCandidate is a photon
220  if (pfc->particleId() == pfToUse_) {
221 
222  if (fabs(eleRef->eta()) < 1.479) {
223  if (fabs(pfc->pt()) < energyBarrel_)
224  continue;
225  } else {
226  if (fabs(pfc->energy()) < energyEndcap_)
227  continue;
228  }
229 
230  float dEta = fabs(eleRef->eta() - pfc->momentum().Eta());
231  if(dEta < etaStrip)
232  continue;
233 
234  float dR = deltaR(eleRef->eta(), eleRef->phi(), pfc->momentum().Eta(), pfc->momentum().Phi());
235  if(dR > drMax_ || dR < dRVeto)
236  continue;
237 
238  // Exclude PF photons which clusters are part of the electron supercluster
239  bool clusterOverlap = false;
240  for(unsigned b=0; b<pfc->elementsInBlocks().size(); b++){
241  reco::PFBlockRef blockRef = pfc->elementsInBlocks()[b].first;
242  unsigned elementIndex = pfc->elementsInBlocks()[b].second;
243  if(blockRef.isNull()) continue;
244  const edm::OwnVector< reco::PFBlockElement >& elements = blockRef->elements();
245  const reco::PFBlockElement& pfbe(elements[elementIndex]);
246  if( pfbe.type() == reco::PFBlockElement::ECAL ){
247  reco::PFClusterRef myPFClusterRef = pfbe.clusterRef();
248  if(myPFClusterRef.isNull()) continue;
249  for(reco::CaloCluster_iterator it = eleRef->superCluster()->clustersBegin(); it != eleRef->superCluster()->clustersEnd(); ++it){
250  if( myPFClusterRef->seed() == (*it)->seed() ){
251  clusterOverlap = true;
252  break;
253  }
254  }
255  }
256  if(clusterOverlap) break;
257  }
258  if(clusterOverlap) continue;
259 
260  sum += pfc->pt();
261  }
262  }
263 
264  if (doRhoCorrection_) {
265  if (fabs(eleRef->eta()) < 1.479)
266  sum = sum - rho*effectiveAreaBarrel_;
267  else
268  sum = sum - rho*effectiveAreaEndcap_;
269  }
270 
271  eleMap.insert(eleRef, sum);
272  }
273  std::auto_ptr<reco::ElectronIsolationMap> mapForEvent(new reco::ElectronIsolationMap(eleMap));
274  iEvent.put(mapForEvent);
275  }
276 }
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:462
virtual const PFClusterRef & clusterRef() const
Type type() const
edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
dictionary elements
int iEvent
Definition: GenABIO.cc:230
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidateProducer_
virtual void produce(edm::Event &, const edm::EventSetup &) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isNull() const
Checks for null.
Definition: Ref.h:249
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
T const * product() const
Definition: Handle.h:81
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)
edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_