CMS 3D CMS Logo

EgammaTrackExtractor.cc
Go to the documentation of this file.
2 
21 
22 using namespace edm;
23 using namespace std;
24 using namespace reco;
25 using namespace egammaisolation;
27 
28 EgammaTrackExtractor::EgammaTrackExtractor(const ParameterSet& par, edm::ConsumesCollector& iC)
29  : theTrackCollectionToken(iC.consumes<View<Track> >(par.getParameter<edm::InputTag>("inputTrackCollection"))),
30  theDepositLabel(par.getUntrackedParameter<std::string>("DepositLabel")),
31  theDiff_r(par.getParameter<double>("Diff_r")),
32  theDiff_z(par.getParameter<double>("Diff_z")),
33  theDR_Max(par.getParameter<double>("DR_Max")),
34  theDR_Veto(par.getParameter<double>("DR_Veto")),
35  theBeamlineOption(par.getParameter<std::string>("BeamlineOption")),
36  theBeamSpotToken(iC.mayConsume<reco::BeamSpot>(par.getParameter<edm::InputTag>("BeamSpotLabel"))),
37  theNHits_Min(par.getParameter<unsigned int>("NHits_Min")),
38  theChi2Ndof_Max(par.getParameter<double>("Chi2Ndof_Max")),
39  theChi2Prob_Min(par.getParameter<double>("Chi2Prob_Min")),
40  thePt_Min(par.getParameter<double>("Pt_Min")),
41  dzOptionString(par.getParameter<std::string>("dzOption")) {
42  if (!dzOptionString.compare("dz"))
44  else if (!dzOptionString.compare("vz"))
46  else if (!dzOptionString.compare("bs"))
48  else if (!dzOptionString.compare("vtx"))
50  else
52 }
53 
55  const edm::EventSetup& evSetup,
56  const reco::Track& track) const {
57  reco::isodeposit::Direction dir(track.eta(), track.phi());
58  return reco::IsoDeposit::Vetos(1, veto(dir));
59 }
60 
63  result.vetoDir = dir;
64  result.dR = theDR_Veto;
65  return result;
66 }
67 
69  const EventSetup& eventSetup,
70  const Candidate& candTk) const {
71  static const std::string metname = "EgammaIsolationAlgos|EgammaTrackExtractor";
72 
74  double dzCut = 0;
75 
76  reco::TrackBase::Point beamPoint(0, 0, 0);
77  if (theBeamlineOption == "BeamSpotFromEvent") {
78  //pick beamSpot
81 
82  event.getByToken(theBeamSpotToken, beamSpotH);
83 
84  if (beamSpotH.isValid()) {
85  beamPoint = beamSpotH->position();
86  }
87  }
88 
89  Handle<View<Track> > tracksH;
90  event.getByToken(theTrackCollectionToken, tracksH);
91 
92  if (candTk.isElectron()) {
93  const reco::GsfElectron* elec = dynamic_cast<const reco::GsfElectron*>(&candTk);
94  candDir = reco::isodeposit::Direction(elec->gsfTrack()->eta(), elec->gsfTrack()->phi());
95  } else {
96  candDir = reco::isodeposit::Direction(candTk.eta(), candTk.phi());
97  }
98 
99  IsoDeposit deposit(candDir);
100  deposit.setVeto(veto(candDir));
101  deposit.addCandEnergy(candTk.et());
102 
103  View<Track>::const_iterator itrTr = tracksH->begin();
104  View<Track>::const_iterator trEnd = tracksH->end();
105  for (itrTr = tracksH->begin(); itrTr != trEnd; ++itrTr) {
106  if (candDir.deltaR(reco::isodeposit::Direction(itrTr->eta(), itrTr->phi())) > theDR_Max)
107  continue;
108 
109  if (itrTr->normalizedChi2() > theChi2Ndof_Max)
110  continue;
111 
112  if (itrTr->pt() < thePt_Min)
113  continue;
114 
115  if (theChi2Prob_Min > 0 && ChiSquaredProbability(itrTr->chi2(), itrTr->ndof()) < theChi2Prob_Min)
116  continue;
117 
118  if (theNHits_Min > 0 && itrTr->numberOfValidHits() < theNHits_Min)
119  continue;
120 
121  if (candTk.isElectron()) {
122  const reco::GsfElectron* elec = dynamic_cast<const reco::GsfElectron*>(&candTk);
123  switch (dzOption) {
125  dzCut = elec->gsfTrack()->dz() - itrTr->dz();
126  break;
128  dzCut = elec->gsfTrack()->vz() - itrTr->vz();
129  break;
131  dzCut = elec->gsfTrack()->dz(beamPoint) - itrTr->dz(beamPoint);
132  break;
134  dzCut = itrTr->dz(elec->gsfTrack()->vertex());
135  break;
136  default:
137  dzCut = elec->gsfTrack()->vz() - itrTr->vz();
138  break;
139  }
140  } else {
141  switch (dzOption) {
143  dzCut = (*itrTr).dz() - candTk.vertex().z();
144  break;
146  dzCut = (*itrTr).vz() - candTk.vertex().z();
147  break;
149  dzCut = (*itrTr).dz(beamPoint) - candTk.vertex().z();
150  break;
152  dzCut = (*itrTr).dz(candTk.vertex());
153  break;
154  default:
155  dzCut = (*itrTr).vz() - candTk.vertex().z();
156  break;
157  }
158  }
159 
160  if (fabs(dzCut) > theDiff_z)
161  continue;
162 
163  if (fabs(itrTr->dxy(beamPoint)) > theDiff_r)
164  continue;
165 
166  deposit.addDeposit(reco::isodeposit::Direction(itrTr->eta(), itrTr->phi()), itrTr->pt());
167  }
168 
169  return deposit;
170 }
double theDR_Veto
Maximum cone angle for deposits.
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
edm::EDGetTokenT< edm::View< reco::Track > > theTrackCollectionToken
std::string dzOptionString
Endcap requirements to determine if isolated for selective filling.
const std::string metname
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:614
reco::IsoDeposit::Veto veto(const reco::IsoDeposit::Direction &dir) const
bool ev
double theChi2Prob_Min
trk.normalizedChi2 < theChi2Ndof_Max
double theDiff_r
minimum candidate et
virtual double et() const =0
transverse energy
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
double thePt_Min
ChiSquaredProbability(trk.chi2,trk.ndof) > theChi2Prob_Min.
float ChiSquaredProbability(double chiSquared, double nrDOF)
virtual bool isElectron() const =0
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
bool isValid() const
Definition: HandleBase.h:70
virtual double eta() const =0
momentum pseudorapidity
double theDiff_z
transverse distance to vertex
unsigned int theNHits_Min
BeamSpot name.
virtual reco::IsoDeposit::Vetos vetos(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &track) const
std::vector< Veto > Vetos
Definition: IsoDeposit.h:65
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< reco::BeamSpot > theBeamSpotToken
double theDR_Max
z distance to vertex
virtual const Point & vertex() const =0
vertex position
const Point & position() const
position
Definition: BeamSpot.h:59
reco::IsoDeposit deposit(const edm::Event &ev, const edm::EventSetup &evSetup, const reco::Track &muon) const override
double theChi2Ndof_Max
trk.numberOfValidHits >= theNHits_Min
virtual double phi() const =0
momentum azimuthal angle
std::string theBeamlineOption
Veto cone angle.
Definition: event.py:1
double deltaR(const Direction &dir2) const