CMS 3D CMS Logo

JVFJetIdProducer.cc
Go to the documentation of this file.
2 
5 
18 
20 
22  srcJets_ = consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcJets"));
23 
24  srcPFCandidates_ = consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates"));
26  consumes<PFCandToVertexAssMap>(cfg.getParameter<edm::InputTag>("srcPFCandToVertexAssociations"));
27  srcHardScatterVertex_ = consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("srcHardScatterVertex"));
28  minTrackPt_ = cfg.getParameter<double>("minTrackPt");
29  dZcut_ = cfg.getParameter<double>("dZcut");
30 
31  JVFcut_ = cfg.getParameter<double>("JVFcut");
32 
33  std::string neutralJetOption_string = cfg.getParameter<std::string>("neutralJetOption");
34  if (neutralJetOption_string == "PU")
36  else if (neutralJetOption_string == "noPU")
38  else
39  throw cms::Exception("JVFJetIdProducer")
40  << "Invalid Configuration Parameter 'neutralJetOption' = " << neutralJetOption_string << " !!\n";
41 
42  verbosity_ = (cfg.exists("verbosity")) ? cfg.getParameter<int>("verbosity") : 0;
43 
44  produces<edm::ValueMap<double>>("Discriminant");
45  produces<edm::ValueMap<int>>("Id");
46 }
47 
49  // nothing to be done yet...
50 }
51 
52 namespace {
53  double computeJVF(const reco::PFJet& jet,
54  const PFCandToVertexAssMap& pfCandToVertexAssociations,
56  double dZ,
57  double minTrackPt,
58  int verbosity) {
59  LogDebug("computeJVF") << "<computeJVF>:" << std::endl
60  << " jet: Pt = " << jet.pt() << ", eta = " << jet.eta() << ", phi = " << jet.phi()
61  << std::endl;
62 
63  double trackSum_isVtxAssociated = 0.;
64  double trackSum_isNotVtxAssociated = 0.;
65 
66  std::vector<reco::PFCandidatePtr> pfConsts = jet.getPFConstituents();
67  for (std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = pfConsts.begin();
68  jetConstituent != pfConsts.end();
69  ++jetConstituent) {
70  if ((*jetConstituent)->charge() == 0)
71  continue;
72 
73  double trackPt = 0.;
74  if ((*jetConstituent)->gsfTrackRef().isNonnull() && (*jetConstituent)->gsfTrackRef().isAvailable())
75  trackPt = (*jetConstituent)->gsfTrackRef()->pt();
76  else if ((*jetConstituent)->trackRef().isNonnull() && (*jetConstituent)->trackRef().isAvailable())
77  trackPt = (*jetConstituent)->trackRef()->pt();
78  else
79  trackPt = (*jetConstituent)->pt();
80 
81  if (trackPt > minTrackPt) {
82  int jetConstituent_vtxAssociationType =
83  noPuUtils::isVertexAssociated((*jetConstituent), pfCandToVertexAssociations, vertices, dZ);
84  //isVertexAssociated_fast(pfCandidateRef, pfCandToVertexAssociations_reversed, *hardScatterVertex, dZcut_, numWarnings_, maxWarnings_);
85  bool jetConstituent_isVtxAssociated = (jetConstituent_vtxAssociationType == noPuUtils::kChHSAssoc);
86  double jetConstituentPt = (*jetConstituent)->pt();
87  if (jetConstituent_isVtxAssociated) {
88  LogDebug("computeJVF") << "associated track: Pt = " << (*jetConstituent)->pt()
89  << ", eta = " << (*jetConstituent)->eta() << ", phi = " << (*jetConstituent)->phi()
90  << std::endl
91  << " (vtxAssociationType = " << jetConstituent_vtxAssociationType << ")" << std::endl;
92 
93  trackSum_isVtxAssociated += jetConstituentPt;
94  } else {
95  LogDebug("computeJVF") << "unassociated track: Pt = " << (*jetConstituent)->pt()
96  << ", eta = " << (*jetConstituent)->eta() << ", phi = " << (*jetConstituent)->phi()
97  << std::endl
98  << " (vtxAssociationType = " << jetConstituent_vtxAssociationType << ")" << std::endl;
99 
100  trackSum_isNotVtxAssociated += jetConstituentPt;
101  }
102  }
103  }
104 
105  double trackSum = trackSum_isVtxAssociated + trackSum_isNotVtxAssociated;
106 
107  double jvf = -1.;
108  if (std::abs(jet.eta()) < 2.5 && trackSum > 5.) {
109  jvf = trackSum_isVtxAssociated / trackSum;
110  }
111 
112  LogDebug("computeJVF") << "trackSum: associated = " << trackSum_isVtxAssociated
113  << ", unassociated = " << trackSum_isNotVtxAssociated << std::endl
114  << " --> JVF = " << jvf << std::endl;
115 
116  return jvf;
117  }
118 } // namespace
119 
121  // get jets
123  evt.getByToken(srcJets_, jets);
124 
125  // get PFCandidates
128 
129  // get PFCandidate-to-vertex associations and "the" hard-scatter vertex
130  edm::Handle<PFCandToVertexAssMap> pfCandToVertexAssociations;
131  evt.getByToken(srcPFCandToVertexAssociations_, pfCandToVertexAssociations);
132 
133  edm::Handle<reco::VertexCollection> hardScatterVertex;
134  evt.getByToken(srcHardScatterVertex_, hardScatterVertex);
135 
136  std::vector<double> jetIdDiscriminants;
137  std::vector<int> jetIdFlags;
138 
139  size_t numJets = jets->size();
140  for (size_t iJet = 0; iJet < numJets; ++iJet) {
141  reco::PFJetRef jet(jets, iJet);
142 
143  double jetJVF = computeJVF(
144  *jet, *pfCandToVertexAssociations, *hardScatterVertex, dZcut_, minTrackPt_, verbosity_ && jet->pt() > 20.);
145  jetIdDiscriminants.push_back(jetJVF);
146 
147  int jetIdFlag = 0;
148  if (jetJVF > JVFcut_)
149  jetIdFlag = 255;
150  else if (jetJVF < -0.5 && neutralJetOption_ == kNeutralJetNoPU)
151  jetIdFlag = 255;
152  jetIdFlags.push_back(jetIdFlag);
153  }
154 
155  auto jetIdDiscriminants_ptr = std::make_unique<edm::ValueMap<double>>();
156  edm::ValueMap<double>::Filler jetIdDiscriminantFiller(*jetIdDiscriminants_ptr);
157  jetIdDiscriminantFiller.insert(jets, jetIdDiscriminants.begin(), jetIdDiscriminants.end());
158  jetIdDiscriminantFiller.fill();
159 
160  auto jetIdFlags_ptr = std::make_unique<edm::ValueMap<int>>();
161  edm::ValueMap<int>::Filler jetIdFlagFiller(*jetIdFlags_ptr);
162  jetIdFlagFiller.insert(jets, jetIdFlags.begin(), jetIdFlags.end());
163  jetIdFlagFiller.fill();
164 
165  evt.put(std::move(jetIdDiscriminants_ptr), "Discriminant");
166  evt.put(std::move(jetIdFlags_ptr), "Id");
167 }
168 
170 
edm::EDGetTokenT< reco::PFJetCollection > srcJets_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
Jets made from PFObjects.
Definition: PFJet.h:20
edm::EDGetTokenT< PFCandToVertexAssMap > srcPFCandToVertexAssociations_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidates_
JVFJetIdProducer(const edm::ParameterSet &)
~JVFJetIdProducer() override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const int verbosity
int isVertexAssociated(const reco::PFCandidatePtr &, const PFCandToVertexAssMap &, const reco::VertexCollection &, double)
edm::EDGetTokenT< reco::VertexCollection > srcHardScatterVertex_
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)