CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFRecoTauChargedHadronFromTrackPlugin.cc
Go to the documentation of this file.
1 /*
2  * PFRecoTauChargedHadronFromTrackPlugin
3  *
4  * Build PFRecoTauChargedHadron objects
5  * using charged PFCandidates as input
6  *
7  * Author: Christian Veelken, LLR
8  *
9  */
10 
12 
14 
18 
30 
33 
38 
39 #include <TMath.h>
40 
41 #include <memory>
42 #include <math.h>
43 
44 namespace reco { namespace tau {
45 
47 {
48  public:
51  // Return type is auto_ptr<ChargedHadronVector>
52  return_type operator()(const reco::PFJet&) const;
53  // Hook to update PV information
54  virtual void beginEvent();
55 
56  private:
57  typedef std::vector<reco::PFCandidatePtr> PFCandPtrs;
58 
60 
62 
65  double dRcone_;
67 
70 
72 
73  mutable int numWarnings_;
75 
77 };
78 
81  vertexAssociator_(pset.getParameter<edm::ParameterSet>("qualityCuts"),std::move(iC)),
82  qcuts_(0)
83 {
84  edm::ParameterSet qcuts_pset = pset.getParameterSet("qualityCuts").getParameterSet("signalQualityCuts");
85  qcuts_ = new RecoTauQualityCuts(qcuts_pset);
86 
87  srcTracks_ = pset.getParameter<edm::InputTag>("srcTracks");
89  dRcone_ = pset.getParameter<double>("dRcone");
90  dRconeLimitedToJetArea_ = pset.getParameter<bool>("dRconeLimitedToJetArea");
91 
92  dRmergeNeutralHadron_ = pset.getParameter<double>("dRmergeNeutralHadron");
93  dRmergePhoton_ = pset.getParameter<double>("dRmergePhoton");
94 
95  numWarnings_ = 0;
96  maxWarnings_ = 3;
97 
98  verbosity_ = ( pset.exists("verbosity") ) ?
99  pset.getParameter<int>("verbosity") : 0;
100 }
101 
103 {
104  delete qcuts_;
105 }
106 
107 // Update the primary vertex
109 {
110  vertexAssociator_.setEvent(*this->evt());
111 
113  evtSetup()->get<IdealMagneticFieldRecord>().get(magneticField);
114  magneticFieldStrength_ = magneticField->inTesla(GlobalPoint(0.,0.,0.));
115 }
116 
117 namespace
118 {
119  struct PFCandidate_withDistance
120  {
122  double distance_;
123  };
124 
125  bool isSmallerDistance(const PFCandidate_withDistance& cand1, const PFCandidate_withDistance& cand2)
126  {
127  return (cand1.distance_ < cand2.distance_);
128  }
129 }
130 
132 {
133  if ( verbosity_ ) {
134  edm::LogPrint("TauChHFromTrack") << "<PFRecoTauChargedHadronFromTrackPlugin::operator()>:" ;
135  edm::LogPrint("TauChHFromTrack") << " pluginName = " << name() ;
136  }
137 
139 
140  const edm::Event& evt = (*this->evt());
141 
143  evt.getByToken(Tracks_token, tracks);
144 
146  float jEta=jet.eta();
147  float jPhi=jet.phi();
148  size_t numTracks = tracks->size();
149  for ( size_t iTrack = 0; iTrack < numTracks; ++iTrack ) {
150  reco::TrackRef track(tracks, iTrack);
151 
152  // consider tracks in vicinity of tau-jet candidate only
153  double dR = deltaR(track->eta(), track->phi(), jEta,jPhi);
154  double dRmatch = dRcone_;
155  if ( dRconeLimitedToJetArea_ ) {
156  double jetArea = jet.jetArea();
157  if ( jetArea > 0. ) {
158  dRmatch = TMath::Min(dRmatch, TMath::Sqrt(jetArea/TMath::Pi()));
159  } else {
160  if ( numWarnings_ < maxWarnings_ ) {
161  edm::LogInfo("PFRecoTauChargedHadronFromTrackPlugin::operator()")
162  << "Jet: Pt = " << jet.pt() << ", eta = " << jet.eta() << ", phi = " << jet.phi() << " has area = " << jetArea << " !!" << std::endl;
163  ++numWarnings_;
164  }
165  dRmatch = 0.1;
166  }
167  }
168  if ( dR > dRmatch ) continue;
169 
170  // ignore tracks which fail quality cuts
171  if ( !qcuts_->filterTrack(track) ) continue;
172 
173  reco::Candidate::Charge trackCharge_int = 0;
174  if ( track->charge() > 0. ) trackCharge_int = +1;
175  else if ( track->charge() < 0. ) trackCharge_int = -1;
176 
177  const double chargedPionMass = 0.13957; // GeV
178  double chargedPionP = track->p();
179  double chargedPionEn = TMath::Sqrt(chargedPionP*chargedPionP + chargedPionMass*chargedPionMass);
180  reco::Candidate::LorentzVector chargedPionP4(track->px(), track->py(), track->pz(), chargedPionEn);
181 
182  reco::Vertex::Point vtx(0.,0.,0.);
184 
185  std::auto_ptr<PFRecoTauChargedHadron> chargedHadron(new PFRecoTauChargedHadron(trackCharge_int, chargedPionP4, vtx, 0, true, PFRecoTauChargedHadron::kTrack));
186  chargedHadron->track_ = edm::Ptr<reco::Track>(tracks, iTrack);
187 
188  // CV: Take code for propagating track to ECAL entrance
189  // from RecoParticleFlow/PFTracking/src/PFTrackTransformer.cc
190  // to make sure propagation is done in the same way as for charged PFCandidates.
191  //
192  // The following replacements need to be made
193  // outerMomentum -> momentum
194  // outerPosition -> referencePoint
195  // in order to run on AOD input
196  // (outerMomentum and outerPosition require access to reco::TrackExtra objects, which are available in RECO only)
197  //
198  XYZTLorentzVector chargedPionPos(track->referencePoint().x(), track->referencePoint().y(), track->referencePoint().z(), 0.);
199  BaseParticlePropagator trackPropagator(RawParticle(chargedPionP4, chargedPionPos), 0., 0., magneticFieldStrength_.z());
200  trackPropagator.setCharge(track->charge());
201  trackPropagator.propagateToEcalEntrance(false);
202  if ( trackPropagator.getSuccess() != 0 ) {
203  chargedHadron->positionAtECALEntrance_ = trackPropagator.vertex();
204  } else {
205  if ( chargedPionP4.pt() > 2. ) {
206  edm::LogWarning("PFRecoTauChargedHadronFromTrackPlugin::operator()")
207  << "Failed to propagate track: Pt = " << track->pt() << ", eta = " << track->eta() << ", phi = " << track->phi() << " to ECAL entrance !!" << std::endl;
208  }
209  chargedHadron->positionAtECALEntrance_ = math::XYZPointF(0.,0.,0.);
210  }
211 
212  std::vector<PFCandidate_withDistance> neutralJetConstituents_withDistance;
213  std::vector<reco::PFCandidatePtr> jetConstituents = jet.getPFConstituents();
214  for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = jetConstituents.begin();
215  jetConstituent != jetConstituents.end(); ++jetConstituent ) {
216  reco::PFCandidate::ParticleType jetConstituentType = (*jetConstituent)->particleId();
217  if ( !(jetConstituentType == reco::PFCandidate::h0 || jetConstituentType == reco::PFCandidate::gamma) ) continue;
218  double dR = deltaR((*jetConstituent)->positionAtECALEntrance(), chargedHadron->positionAtECALEntrance_);
219  double dRmerge = -1.;
220  if ( jetConstituentType == reco::PFCandidate::h0 ) dRmerge = dRmergeNeutralHadron_;
221  else if ( jetConstituentType == reco::PFCandidate::gamma ) dRmerge = dRmergePhoton_;
222  if ( dR < dRmerge ) {
223  PFCandidate_withDistance jetConstituent_withDistance;
224  jetConstituent_withDistance.pfCandidate_ = (*jetConstituent);
225  jetConstituent_withDistance.distance_ = dR;
226  neutralJetConstituents_withDistance.push_back(jetConstituent_withDistance);
227  chargedHadron->addDaughter(*jetConstituent);
228  }
229  }
230  std::sort(neutralJetConstituents_withDistance.begin(), neutralJetConstituents_withDistance.end(), isSmallerDistance);
231 
232  const double caloResolutionCoeff = 1.0; // CV: approximate ECAL + HCAL calorimeter resolution for hadrons by 100%*sqrt(E)
233  double resolutionTrackP = track->p()*(track->ptError()/track->pt());
234  double neutralEnSum = 0.;
235  for ( std::vector<PFCandidate_withDistance>::const_iterator nextNeutral = neutralJetConstituents_withDistance.begin();
236  nextNeutral != neutralJetConstituents_withDistance.end(); ++nextNeutral ) {
237  double nextNeutralEn = nextNeutral->pfCandidate_->energy();
238  double resolutionCaloEn = caloResolutionCoeff*sqrt(neutralEnSum + nextNeutralEn);
239  double resolution = sqrt(resolutionTrackP*resolutionTrackP + resolutionCaloEn*resolutionCaloEn);
240  if ( (neutralEnSum + nextNeutralEn) < (track->p() + 2.*resolution) ) {
241  chargedHadron->neutralPFCandidates_.push_back(nextNeutral->pfCandidate_);
242  neutralEnSum += nextNeutralEn;
243  } else {
244  break;
245  }
246  }
247 
248  setChargedHadronP4(*chargedHadron);
249 
250  if ( verbosity_ ) {
251  edm::LogPrint("TauChHFromTrack") << *chargedHadron;
252  }
253 
254  output.push_back(chargedHadron);
255  }
256 
257  return output.release();
258 }
259 
260 }} // end namespace reco::tau
261 
263 
const double Pi
void setCharge(float q)
set the MEASURED charge
Definition: RawParticle.cc:139
T getParameter(std::string const &) const
int Charge
electric charge type
Definition: Candidate.h:35
return_type operator()(const reco::PFJet &) const
Build a collection of chargedHadrons from objects in the input jet.
ParticleType
particle types
Definition: PFCandidate.h:44
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
PFRecoTauChargedHadronFromTrackPlugin(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
reco::PFCandidatePtr pfCandidate_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
reco::VertexRef associatedVertex(const PFJet &jet) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual double phi() const final
momentum azimuthal angle
void setEvent(const edm::Event &evt)
Load the vertices from the event.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
T Min(T a, T b)
Definition: MathUtil.h:39
virtual void beginEvent()
Hook called at the beginning of the event.
boost::ptr_vector< PFRecoTauChargedHadron > ChargedHadronVector
Jets made from PFObjects.
Definition: PFJet.h:21
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void setPV(const reco::VertexRef &vtx) const
Update the primary vertex.
T sqrt(T t)
Definition: SSEVec.h:18
def move
Definition: eostools.py:510
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
const edm::EventSetup * evtSetup() const
ParameterSet const & getParameterSet(std::string const &) const
tuple tracks
Definition: testEve_cfg.py:39
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
const T & get() const
Definition: EventSetup.h:56
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
virtual float jetArea() const
get jet area
Definition: Jet.h:105
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
Definition: PFJet.cc:52
#define DEFINE_EDM_PLUGIN(factory, type, name)
virtual double eta() const final
momentum pseudorapidity
const std::string & name() const
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
bool filterTrack(const reco::TrackBaseRef &track) const
Filter a single Track.
virtual double pt() const final
transverse momentum