test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTPFNeutralIsolationProducer.cc
Go to the documentation of this file.
1 
8 #include <iostream>
9 #include <vector>
10 #include <memory>
11 
13 
14 // Framework
20 
23 
25 
27 
28  pfCandidateProducer_ = consumes<reco::PFCandidateCollection>(config.getParameter<edm::InputTag>("pfCandidatesProducer"));
29 
30  useSCRefs_ = config.getParameter<bool>("useSCRefs");
31 
32  drMax_ = config.getParameter<double>("drMax");
33  drVetoBarrel_ = config.getParameter<double>("drVetoBarrel");
34  drVetoEndcap_ = config.getParameter<double>("drVetoEndcap");
35  etaStripBarrel_ = config.getParameter<double>("etaStripBarrel");
36  etaStripEndcap_ = config.getParameter<double>("etaStripEndcap");
37  energyBarrel_ = config.getParameter<double>("energyBarrel");
38  energyEndcap_ = config.getParameter<double>("energyEndcap");
39  pfToUse_ = config.getParameter<int>("pfCandidateType");
40 
41  doRhoCorrection_ = config.getParameter<bool>("doRhoCorrection");
42  if (doRhoCorrection_)
43  rhoProducer_ = consumes<double>(config.getParameter<edm::InputTag>("rhoProducer"));
44 
45  rhoMax_ = config.getParameter<double>("rhoMax");
46  rhoScale_ = config.getParameter<double>("rhoScale");
47  effectiveAreaBarrel_ = config.getParameter<double>("effectiveAreaBarrel");
48  effectiveAreaEndcap_ = config.getParameter<double>("effectiveAreaEndcap");
49 
50  if(useSCRefs_) {
51  produces < reco::RecoEcalCandidateIsolationMap >();
52  recoEcalCandidateProducer_ = consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"));
53  } else {
54  produces < reco::ElectronIsolationMap >();
55  electronProducer_ = consumes<reco::ElectronCollection>(config.getParameter<edm::InputTag>("electronProducer"));
56  }
57 }
58 
61  desc.add<edm::InputTag>("electronProducer", edm::InputTag("hltEle27WP80PixelMatchElectronsL1SeededPF"));
62  desc.add<edm::InputTag>("recoEcalCandidateProducer", edm::InputTag("hltL1SeededRecoEcalCandidatePF"));
63  desc.add<edm::InputTag>("pfCandidatesProducer", edm::InputTag("hltParticleFlowReg"));
64  desc.add<edm::InputTag>("rhoProducer", edm::InputTag("fixedGridRhoFastjetAllCalo"));
65  desc.add<bool>("doRhoCorrection", false);
66  desc.add<double>("rhoMax", 9.9999999E7);
67  desc.add<double>("rhoScale", 1.0);
68  desc.add<double>("effectiveAreaBarrel", 0.101);
69  desc.add<double>("effectiveAreaEndcap", 0.046);
70  desc.add<bool>("useSCRefs", false);
71  desc.add<double>("drMax", 0.3);
72  desc.add<double>("drVetoBarrel", 0.0);
73  desc.add<double>("drVetoEndcap", 0.0);
74  desc.add<double>("etaStripBarrel", 0.0);
75  desc.add<double>("etaStripEndcap", 0.0);
76  desc.add<double>("energyBarrel", 0.0);
77  desc.add<double>("energyEndcap", 0.0);
78  desc.add<int>("pfCandidateType", 5);
79  descriptions.add(("hltEgammaHLTPFNeutralIsolationProducer"), desc);
80 }
81 
83 
84  edm::Handle<double> rhoHandle;
85  double rho = 0.0;
86  if (doRhoCorrection_) {
87  iEvent.getByToken(rhoProducer_, rhoHandle);
88  rho = *(rhoHandle.product());
89  }
90 
91  if (rho > rhoMax_)
92  rho = rhoMax_;
93 
94  rho = rho*rhoScale_;
95 
99 
100  iEvent.getByToken(pfCandidateProducer_, pfHandle);
101  const reco::PFCandidateCollection* forIsolation = pfHandle.product();
102 
103  if(useSCRefs_) {
104 
105  iEvent.getByToken(recoEcalCandidateProducer_,recoecalcandHandle);
106  reco::RecoEcalCandidateIsolationMap recoEcalCandMap(recoecalcandHandle);
107 
108  float dRVeto = -1.;
109  float etaStrip = -1;
110 
111  for (unsigned int iReco = 0; iReco < recoecalcandHandle->size(); iReco++) {
112  reco::RecoEcalCandidateRef candRef(recoecalcandHandle, iReco);
113 
114  if (fabs(candRef->eta()) < 1.479) {
115  dRVeto = drVetoBarrel_;
116  etaStrip = etaStripBarrel_;
117  } else {
118  dRVeto = drVetoEndcap_;
119  etaStrip = etaStripEndcap_;
120  }
121 
122  float sum = 0;
123 
124  // Loop over the PFCandidates
125  for(unsigned i=0; i<forIsolation->size(); i++) {
126  const reco::PFCandidate& pfc = (*forIsolation)[i];
127 
128  //require that the PFCandidate is a neutral hadron
129  if (pfc.particleId() == pfToUse_) {
130 
131  if (fabs(candRef->eta()) < 1.479) {
132  if (fabs(pfc.pt()) < energyBarrel_)
133  continue;
134  } else {
135  if (fabs(pfc.energy()) < energyEndcap_)
136  continue;
137  }
138 
139  // Shift the RecoEcalCandidate direction vector according to the PF vertex
140  math::XYZPoint pfvtx = pfc.vertex();
141  math::XYZVector candDirectionWrtVtx(candRef->superCluster()->x() - pfvtx.x(),
142  candRef->superCluster()->y() - pfvtx.y(),
143  candRef->superCluster()->z() - pfvtx.z());
144 
145  float dEta = fabs(candDirectionWrtVtx.Eta() - pfc.momentum().Eta());
146  if(dEta < etaStrip) continue;
147 
148  float dR = deltaR(candDirectionWrtVtx.Eta(), candDirectionWrtVtx.Phi(), pfc.momentum().Eta(), pfc.momentum().Phi());
149  if(dR > drMax_ || dR < dRVeto) continue;
150 
151  sum += pfc.pt();
152  }
153  }
154 
155  if (doRhoCorrection_) {
156  if (fabs(candRef->eta()) < 1.479)
157  sum = sum - rho*effectiveAreaBarrel_;
158  else
159  sum = sum - rho*effectiveAreaEndcap_;
160  }
161 
162  recoEcalCandMap.insert(candRef, sum);
163  }
164  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> mapForEvent(new reco::RecoEcalCandidateIsolationMap(recoEcalCandMap));
165  iEvent.put(mapForEvent);
166 
167  } else {
168 
169  iEvent.getByToken(electronProducer_,electronHandle);
170  reco::ElectronIsolationMap eleMap(electronHandle);
171 
172  float dRVeto = -1.;
173  float etaStrip = -1;
174 
175  for(unsigned int iEl=0; iEl<electronHandle->size(); iEl++) {
176  reco::ElectronRef eleRef(electronHandle, iEl);
177 
178  if (fabs(eleRef->eta()) < 1.479) {
179  dRVeto = drVetoBarrel_;
180  etaStrip = etaStripBarrel_;
181  } else {
182  dRVeto = drVetoEndcap_;
183  etaStrip = etaStripEndcap_;
184  }
185 
186  float sum = 0;
187 
188  // Loop over the PFCandidates
189  for(unsigned i=0; i<forIsolation->size(); i++) {
190  const reco::PFCandidate& pfc = (*forIsolation)[i];
191 
192  //require that the PFCandidate is a neutral hadron
193  if (pfc.particleId() == pfToUse_) {
194 
195  if (fabs(eleRef->eta()) < 1.479) {
196  if (fabs(pfc.pt()) < energyBarrel_)
197  continue;
198  } else {
199  if (fabs(pfc.energy()) < energyEndcap_)
200  continue;
201  }
202 
203  float dEta = fabs(eleRef->eta() - pfc.momentum().Eta());
204  if(dEta < etaStrip) continue;
205 
206  float dR = deltaR(eleRef->eta(), eleRef->phi(), pfc.momentum().Eta(), pfc.momentum().Phi());
207  if(dR > drMax_ || dR < dRVeto) continue;
208 
209  sum += pfc.pt();
210  }
211  }
212 
213  if (doRhoCorrection_) {
214  if (fabs(eleRef->superCluster()->eta()) < 1.479)
215  sum = sum - rho*effectiveAreaBarrel_;
216  else
217  sum = sum - rho*effectiveAreaEndcap_;
218  }
219 
220  eleMap.insert(eleRef, sum);
221  }
222  std::auto_ptr<reco::ElectronIsolationMap> mapForEvent(new reco::ElectronIsolationMap(eleMap));
223  iEvent.put(mapForEvent);
224  }
225 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual double energy() const final
energy
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateProducer_
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidateProducer_
edm::EDGetTokenT< reco::ElectronCollection > electronProducer_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
virtual const Point & vertex() const
vertex position (overwritten by PF...)
Definition: PFCandidate.cc:647
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual Vector momentum() const final
spatial momentum vector
void produce(edm::Event &, const edm::EventSetup &) override
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
virtual ParticleType particleId() const
Definition: PFCandidate.h:373
virtual double pt() const final
transverse momentum