CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTPFChargedIsolationProducer.cc
Go to the documentation of this file.
1 
9 
10 // Framework
19 
22 
26 
29 
32 
34 
36 
37  electronProducer_ = config.getParameter<edm::InputTag>("electronProducer");
38  pfCandidateProducer_ = config.getParameter<edm::InputTag>("pfCandidatesProducer");
39  recoEcalCandidateProducer_ = config.getParameter<edm::InputTag>("recoEcalCandidateProducer");
40  beamSpotProducer_ = config.getParameter<edm::InputTag>("beamSpotProducer");
41 
42  useGsfTrack_ = config.getParameter<bool>("useGsfTrack");
43  useSCRefs_ = config.getParameter<bool>("useSCRefs");
44 
45  drMax_ = config.getParameter<double>("drMax");
46  drVetoBarrel_ = config.getParameter<double>("drVetoBarrel");
47  drVetoEndcap_ = config.getParameter<double>("drVetoEndcap");
48  ptMin_ = config.getParameter<double>("ptMin");
49  dzMax_ = config.getParameter<double>("dzMax");
50  dxyMax_ = config.getParameter<double>("dxyMax");
51  pfToUse_ = config.getParameter<int>("pfCandidateType");
52 
53  //register your products
54  if(useSCRefs_)
55  produces < reco::RecoEcalCandidateIsolationMap >();
56  else
57  produces < reco::ElectronIsolationMap >();
58 }
59 
60 
62 {}
63 
66  desc.add<edm::InputTag>("pfCandidatesProducer", edm::InputTag("hltParticleFlowReg"));
67  desc.add<edm::InputTag>("recoEcalCandidateProducer", edm::InputTag("hltL1SeededRecoEcalCandidatePF"));
68  desc.add<edm::InputTag>("electronProducer", edm::InputTag("hltEle27WP80PixelMatchElectronsL1SeededPF"));
69  desc.add<edm::InputTag>("beamSpotProducer", edm::InputTag("hltOnlineBeamSpot"));
70  desc.add<bool>("useGsfTrack", false);
71  desc.add<bool>("useSCRefs", false);
72  desc.add<double>("drMax", 0.3);
73  desc.add<double>("drVetoBarrel", 0.02);
74  desc.add<double>("drVetoEndcap", 0.02);
75  desc.add<double>("ptMin", 0.0);
76  desc.add<double>("dzMax", 0.2);
77  desc.add<double>("dxyMax", 0.1);
78  desc.add<int>("pfCandidateType", 1);
79  descriptions.add(("hltEgammaHLTPFChargedIsolationProducer"), desc);
80 }
81 
83 
85  iEvent.getByLabel(electronProducer_,electronHandle);
86 
87  // Get the general tracks
89  iEvent.getByLabel(pfCandidateProducer_, pfHandle);
90 
93 
94  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
95 
96  if(useSCRefs_) {
98  iEvent.getByLabel(recoEcalCandidateProducer_, recoEcalCandHandle);
99 
100  iEvent.getByLabel(beamSpotProducer_, recoBeamSpotHandle);
101  const reco::BeamSpot::Point& beamSpotPosition = recoBeamSpotHandle->position();
102 
103  for(unsigned int iReco=0; iReco<recoEcalCandHandle->size(); iReco++) {
104 
105  reco::RecoEcalCandidateRef candRef(recoEcalCandHandle, iReco);
106 
107  float dRveto = -1;
108  if (fabs(candRef->eta())<1.479)
109  dRveto = drVetoBarrel_;
110  else
111  dRveto = drVetoEndcap_;
112 
113  const reco::PFCandidateCollection* forIsolation = pfHandle.product();
114 
115  // Shift the photon according to the vertex
116  math::XYZVector photon_directionWrtVtx(candRef->superCluster()->x() - beamSpotPosition.x(),
117  candRef->superCluster()->y() - beamSpotPosition.y(),
118  candRef->superCluster()->z() - beamSpotPosition.z());
119 
120  float sum = 0;
121  // Loop over the PFCandidates
122  for(unsigned i=0; i<forIsolation->size(); i++) {
123 
124  const reco::PFCandidate& pfc = (*forIsolation)[i];
125 
126  //require that PFCandidate is a charged hadron
127  if (pfc.particleId() == pfToUse_) {
128  if (pfc.pt() < ptMin_)
129  continue;
130 
131  float dz = fabs(pfc.trackRef()->dz(beamSpotPosition));
132  if (dz > dzMax_) continue;
133 
134  float dxy = fabs(pfc.trackRef()->dxy(beamSpotPosition));
135  if(fabs(dxy) > dxyMax_) continue;
136 
137  float dR = deltaR(photon_directionWrtVtx.Eta(), photon_directionWrtVtx.Phi(), pfc.momentum().Eta(), pfc.momentum().Phi());
138  if(dR > drMax_ || dR < dRveto) continue;
139 
140  sum += pfc.pt();
141  }
142  }
143 
144  recoEcalCandMap.insert(candRef, sum);
145  }
146  } else {
147  for(unsigned int iEl=0; iEl<electronHandle->size(); iEl++) {
148  reco::ElectronRef eleRef(electronHandle, iEl);
149 
150  //const reco::Track* eleTrk = useGsfTrack_ ? &*eleRef->gsfTrack() : &*eleRef->track();
151  float dRveto = -1;
152  if (fabs(eleRef->eta())<1.479)
153  dRveto = drVetoBarrel_;
154  else
155  dRveto = drVetoEndcap_;
156 
157  const reco::PFCandidateCollection* forIsolation = pfHandle.product();
158 
159  float sum = 0;
160  // Loop over the PFCandidates
161  for(unsigned i=0; i<forIsolation->size(); i++) {
162 
163  const reco::PFCandidate& pfc = (*forIsolation)[i];
164 
165  // FIXME Rimuovi la traccia dell'elettrone esplicitamente
166  //require that PFCandidate is a charged hadron
167  if (pfc.particleId() == pfToUse_) {
168  if (pfc.pt() < ptMin_)
169  continue;
170 
171  float dz = fabs(pfc.trackRef()->dz(eleRef->vertex()));
172  if (dz > dzMax_) continue;
173 
174  float dxy = fabs(pfc.trackRef()->dxy(eleRef->vertex()));
175  if(fabs(dxy) > dxyMax_) continue;
176 
177  float dR = deltaR(eleRef->eta(), eleRef->phi(), pfc.momentum().Eta(), pfc.momentum().Phi());
178  if(dR > drMax_ || dR < dRveto) continue;
179 
180  sum += pfc.pt();
181  }
182  }
183 
184  eleMap.insert(eleRef, sum);
185  }
186  }
187 
188  if(useSCRefs_){
189  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> mapForEvent(new reco::RecoEcalCandidateIsolationMap(recoEcalCandMap));
190  iEvent.put(mapForEvent);
191  }else{
192  std::auto_ptr<reco::ElectronIsolationMap> mapForEvent(new reco::ElectronIsolationMap(eleMap));
193  iEvent.put(mapForEvent);
194  }
195 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:429
int iEvent
Definition: GenABIO.cc:243
virtual void produce(edm::Event &, const edm::EventSetup &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
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
virtual Vector momentum() const GCC11_FINAL
spatial momentum vector
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
T const * product() const
Definition: Handle.h:81
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:38
virtual ParticleType particleId() const
Definition: PFCandidate.h:355
virtual float pt() const GCC11_FINAL
transverse momentum