54 template <
class TrackClass>
55 class PFRecoTauChargedHadronFromGenericTrackPlugin :
public PFRecoTauChargedHadronBuilderPlugin {
91 template <
class TrackClass>
94 template <
class TrackClass>
98 vertexAssociator_(pset.getParameter<edm::
ParameterSet>(
"qualityCuts"), std::
move(iC)),
115 template <
class TrackClass>
121 template <
class TrackClass>
123 vertexAssociator_.setEvent(*this->evt());
125 magneticFieldStrength_ = evtSetup()->getData(magneticFieldToken_).inTesla(
GlobalPoint(0., 0., 0.));
133 return qcuts_->filterTrack(trackRef);
138 const edm::Handle<std::vector<pat::PackedCandidate> >&
tracks,
size_t iTrack)
const {
144 return qcuts_->filterChargedCand(cand);
167 double trackPtError =
170 if (
track !=
nullptr) {
171 trackPtError =
track->ptError();
174 trackPtError = 0.025;
194 struct Candidate_withDistance {
199 bool isSmallerDistance(
const Candidate_withDistance& cand1,
const Candidate_withDistance& cand2) {
200 return (cand1.distance_ < cand2.distance_);
204 template <
class TrackClass>
205 typename PFRecoTauChargedHadronFromGenericTrackPlugin<TrackClass>::return_type
208 edm::LogPrint(
"TauChHFromTrack") <<
"<PFRecoTauChargedHadronFromGenericTrackPlugin::operator()>:";
219 qcuts_->setPV(vertexAssociator_.associatedVertex(jet));
220 float jEta = jet.
eta();
221 float jPhi = jet.
phi();
222 size_t numTracks = tracks->size();
223 for (
size_t iTrack = 0; iTrack < numTracks; ++iTrack) {
227 double dR =
deltaR(track.eta(), track.phi(), jEta, jPhi);
228 double dRmatch = dRcone_;
229 if (dRconeLimitedToJetArea_) {
230 double jetArea = jet.
jetArea();
234 if (numWarnings_ < maxWarnings_) {
235 edm::LogInfo(
"PFRecoTauChargedHadronFromGenericTrackPlugin::operator()")
236 <<
"Jet: Pt = " << jet.
pt() <<
", eta = " << jet.
eta() <<
", phi = " << jet.
phi()
237 <<
" has area = " << jetArea <<
" !!" << std::endl;
246 if (!this->filterTrack(tracks, iTrack))
250 if (track.charge() > 0.)
251 trackCharge_int = +1;
252 else if (track.charge() < 0.)
253 trackCharge_int = -1;
255 const double chargedPionMass = 0.13957;
256 double chargedPionP = track.p();
257 double chargedPionEn = TMath::Sqrt(chargedPionP * chargedPionP + chargedPionMass * chargedPionMass);
261 if (vertexAssociator_.associatedVertex(jet).isNonnull())
262 vtx = vertexAssociator_.associatedVertex(jet)->position();
264 std::unique_ptr<PFRecoTauChargedHadron> chargedHadron(
284 if (trackPropagator.getSuccess() != 0) {
285 chargedHadron->positionAtECALEntrance_ = trackPropagator.particle().vertex();
287 if (chargedPionP4.pt() > 2. and
std::abs(chargedPionP4.eta()) < 3.) {
288 edm::LogWarning(
"PFRecoTauChargedHadronFromGenericTrackPlugin::operator()")
289 <<
"Failed to propagate track: Pt = " << track.pt() <<
", eta = " << track.eta()
290 <<
", phi = " << track.phi() <<
" to ECAL entrance !!" << std::endl;
295 std::vector<Candidate_withDistance> neutralJetConstituents_withDistance;
297 int pdgId = jetConstituent->pdgId();
298 if (!(pdgId == 130 || pdgId == 22))
301 chargedHadron->positionAtECALEntrance_);
302 double dRmerge = -1.;
304 dRmerge = dRmergeNeutralHadron_;
305 else if (pdgId == 22)
306 dRmerge = dRmergePhoton_;
308 Candidate_withDistance jetConstituent_withDistance;
309 jetConstituent_withDistance.pfCandidate_ = jetConstituent;
310 jetConstituent_withDistance.distance_ = dR;
311 neutralJetConstituents_withDistance.push_back(jetConstituent_withDistance);
312 chargedHadron->addDaughter(jetConstituent);
316 neutralJetConstituents_withDistance.begin(), neutralJetConstituents_withDistance.end(), isSmallerDistance);
318 const double caloResolutionCoeff =
320 double resolutionTrackP = track.p() * (getTrackPtError(track) / track.pt());
321 double neutralEnSum = 0.;
322 for (std::vector<Candidate_withDistance>::const_iterator nextNeutral =
323 neutralJetConstituents_withDistance.begin();
324 nextNeutral != neutralJetConstituents_withDistance.end();
326 double nextNeutralEn = nextNeutral->pfCandidate_->energy();
327 double resolutionCaloEn = caloResolutionCoeff *
sqrt(neutralEnSum + nextNeutralEn);
328 double resolution =
sqrt(resolutionTrackP * resolutionTrackP + resolutionCaloEn * resolutionCaloEn);
329 if ((neutralEnSum + nextNeutralEn) < (track.p() + 2. *
resolution)) {
330 chargedHadron->neutralPFCandidates_.push_back(nextNeutral->pfCandidate_);
331 neutralEnSum += nextNeutralEn;
343 output.push_back(
std::move(chargedHadron));
359 "PFRecoTauChargedHadronFromTrackPlugin");
362 "PFRecoTauChargedHadronFromLostTrackPlugin");
CandidatePtr lostTrackCandidate_
void setCharge(float q)
set the MEASURED charge
int Charge
electric charge type
const Point & referencePoint() const
Reference point on the track.
const Point & vertex() const override
vertex position
static constexpr unsigned int maxWarnings_
std::vector< std::unique_ptr< PFRecoTauChargedHadron > > ChargedHadronVector
math::XYZPointF atECALEntrance(const reco::Candidate *part, double bField)
double pt() const final
transverse momentum
RecoTauQualityCuts * qcuts_
bool dRconeLimitedToJetArea_
int charge() const override
electric charge
bool getByToken(EDGetToken token, Handle< PROD > &result) const
ChargedHadronVector return_type
reco::CandidatePtr pfCandidate_
double z() const
z of vertex
Base class for all types of Jets.
Global3DPoint GlobalPoint
PFRecoTauChargedHadronFromGenericTrackPlugin(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
auto const & tracks
cannot be loose
~PFRecoTauChargedHadronFromGenericTrackPlugin() override
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
void beginEvent() override
Hook called at the beginning of the event.
virtual const daughters & daughterPtrVector() const
references to daughtes
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
double eta() const override
momentum pseudorapidity
double getTrackPtError(const TrackClass &track) const
XYZTLorentzVector getTrackPos(const TrackClass &track) const
static std::atomic< unsigned int > numWarnings_
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Abs< T >::type abs(const T &t)
return_type operator()(const reco::Jet &) const override
Build a collection of chargedHadrons from objects in the input jet.
math::XYZPoint Point
point in the space
edm::EDGetTokenT< std::vector< TrackClass > > Tracks_token
Log< level::Warning, true > LogPrint
bool propagateToEcalEntrance(bool first=true)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
Log< level::Info, false > LogInfo
ParameterSet const & getParameterSet(std::string const &) const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
PFRecoTauChargedHadronFromGenericTrackPlugin< reco::Track > PFRecoTauChargedHadronFromTrackPlugin
T getParameter(std::string const &) const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
virtual float jetArea() const
get jet area
RecoTauVertexAssociator vertexAssociator_
#define DEFINE_EDM_PLUGIN(factory, type, name)
PFRecoTauChargedHadronFromGenericTrackPlugin< pat::PackedCandidate > PFRecoTauChargedHadronFromLostTrackPlugin
math::XYZVector magneticFieldStrength_
Log< level::Warning, false > LogWarning
double dRmergeNeutralHadron_
void setChargedHadronTrack(PFRecoTauChargedHadron &chargedHadron, const edm::Ptr< TrackClass > &track) const
void setChargedHadronP4(reco::PFRecoTauChargedHadron &chargedHadron, double scaleFactor_neutralPFCands=1.0)
double phi() const final
momentum azimuthal angle
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
bool filterTrack(const edm::Handle< std::vector< TrackClass > > &, size_t iTrack) const
math::XYZTLorentzVector XYZTLorentzVector
double eta() const final
momentum pseudorapidity