CMS 3D CMS Logo

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