CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JVFJetIdProducer.cc
Go to the documentation of this file.
2 
5 
17 
18 
20 
22 {
23  srcJets_ = consumes<reco::PFJetCollection>(cfg.getParameter<edm::InputTag>("srcJets"));
24 
25  srcPFCandidates_ = consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates"));
26  srcPFCandToVertexAssociations_ = 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" ) neutralJetOption_ = kNeutralJetPU;
35  else if ( neutralJetOption_string == "noPU" ) neutralJetOption_ = kNeutralJetNoPU;
36  else throw cms::Exception("JVFJetIdProducer")
37  << "Invalid Configuration Parameter 'neutralJetOption' = " << neutralJetOption_string << " !!\n";
38 
39  verbosity_ = ( cfg.exists("verbosity") ) ?
40  cfg.getParameter<int>("verbosity") : 0;
41 
42  produces<edm::ValueMap<double> >("Discriminant");
43  produces<edm::ValueMap<int> >("Id");
44 }
45 
47 {
48 // nothing to be done yet...
49 }
50 
51 namespace
52 {
53  double computeJVF(const reco::PFJet& jet,
54  const PFCandToVertexAssMap& pfCandToVertexAssociations,
55  const reco::VertexCollection& vertices, double dZ, double minTrackPt,
56  int verbosity) {
57 
58  LogDebug ("computeJVF")
59  << "<computeJVF>:" << std::endl
60  << " jet: Pt = " << jet.pt() << ", eta = " << jet.eta() << ", phi = " << jet.phi() << std::endl;
61 
62  double trackSum_isVtxAssociated = 0.;
63  double trackSum_isNotVtxAssociated = 0.;
64 
65  std::vector<reco::PFCandidatePtr> pfConsts = jet.getPFConstituents();
66  for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = pfConsts.begin(); jetConstituent != pfConsts.end(); ++jetConstituent ) {
67  // reco::PFCandidate pfc=(*jetConstituent); //using the pointer along the sequence makes the code segfaulting for no apparent reason...
68  if ( (*jetConstituent)->charge() != 0 ) {
69  double trackPt = 0.;
70  if ( (*jetConstituent)->gsfTrackRef().isNonnull() && (*jetConstituent)->gsfTrackRef().isAvailable() ) trackPt = (*jetConstituent)->gsfTrackRef()->pt();
71  else if ( (*jetConstituent)->trackRef().isNonnull() && (*jetConstituent)->trackRef().isAvailable() ) trackPt = (*jetConstituent)->trackRef()->pt();
72  else trackPt = (*jetConstituent)->pt();
73 
74  if ( trackPt > minTrackPt ) {
75  int jetConstituent_vtxAssociationType = isVertexAssociated( (*jetConstituent), pfCandToVertexAssociations, vertices, dZ);
76  bool jetConstituent_isVtxAssociated = (jetConstituent_vtxAssociationType == noPuUtils::kChHSAssoc );
77  double jetConstituentPt = (*jetConstituent)->pt();
78  if ( jetConstituent_isVtxAssociated ) {
79  LogDebug ("computeJVF")
80  << "associated track: Pt = " << (*jetConstituent)->pt() << ", eta = " << (*jetConstituent)->eta() << ", phi = " << (*jetConstituent)->phi() << std::endl
81  << " (vtxAssociationType = " << jetConstituent_vtxAssociationType << ")" << std::endl;
82 
83  trackSum_isVtxAssociated += jetConstituentPt;
84  } else {
85  LogDebug ("computeJVF")
86  << "unassociated track: Pt = " << (*jetConstituent)->pt() << ", eta = " << (*jetConstituent)->eta() << ", phi = " << (*jetConstituent)->phi() << std::endl
87  << " (vtxAssociationType = " << jetConstituent_vtxAssociationType << ")" << std::endl;
88 
89  trackSum_isNotVtxAssociated += jetConstituentPt;
90  }
91  }
92  }
93  }
94 
95  double trackSum = trackSum_isVtxAssociated + trackSum_isNotVtxAssociated;
96 
97  double jvf = -1.;
98  if ( std::abs(jet.eta()) < 2.5 && trackSum > 5. ) {
99  jvf = trackSum_isVtxAssociated/trackSum;
100  }
101 
102  LogDebug ("computeJVF")
103  << "trackSum: associated = " << trackSum_isVtxAssociated << ", unassociated = " << trackSum_isNotVtxAssociated << std::endl
104  << " --> JVF = " << jvf << std::endl;
105 
106  return jvf;
107  }
108 }
109 
111 {
112 // get jets
114  evt.getByToken(srcJets_, jets);
115 
116  // get PFCandidates
118  evt.getByToken(srcPFCandidates_, pfCandidates);
119 
120  // get PFCandidate-to-vertex associations and "the" hard-scatter vertex
121  edm::Handle<PFCandToVertexAssMap> pfCandToVertexAssociations;
122  evt.getByToken(srcPFCandToVertexAssociations_, pfCandToVertexAssociations);
123 
124  edm::Handle<reco::VertexCollection> hardScatterVertex;
125  evt.getByToken(srcHardScatterVertex_, hardScatterVertex);
126 
127  std::vector<double> jetIdDiscriminants;
128  std::vector<int> jetIdFlags;
129 
130  size_t numJets = jets->size();
131  for ( size_t iJet = 0; iJet < numJets; ++iJet ) {
132  reco::PFJetRef jet(jets, iJet);
133 
134  double jetJVF = computeJVF(*jet, *pfCandToVertexAssociations, *hardScatterVertex, dZcut_, minTrackPt_, verbosity_ && jet->pt() > 20.);
135  jetIdDiscriminants.push_back(jetJVF);
136 
137  int jetIdFlag = 0;
138  if ( jetJVF > JVFcut_ ) jetIdFlag = 255;
139  else if ( jetJVF < -0.5 && neutralJetOption_ == kNeutralJetNoPU ) jetIdFlag = 255;
140  jetIdFlags.push_back(jetIdFlag);
141  }
142 
143  std::auto_ptr<edm::ValueMap<double> > jetIdDiscriminants_ptr(new edm::ValueMap<double>());
144  edm::ValueMap<double>::Filler jetIdDiscriminantFiller(*jetIdDiscriminants_ptr);
145  jetIdDiscriminantFiller.insert(jets, jetIdDiscriminants.begin(), jetIdDiscriminants.end());
146  jetIdDiscriminantFiller.fill();
147 
148  std::auto_ptr<edm::ValueMap<int> > jetIdFlags_ptr(new edm::ValueMap<int>());
149  edm::ValueMap<int>::Filler jetIdFlagFiller(*jetIdFlags_ptr);
150  jetIdFlagFiller.insert(jets, jetIdFlags.begin(), jetIdFlags.end());
151  jetIdFlagFiller.fill();
152 
153  evt.put(jetIdDiscriminants_ptr, "Discriminant");
154  evt.put(jetIdFlags_ptr, "Id");
155 }
156 
158 
#define LogDebug(id)
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:237
virtual float pt() const
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
tuple trackPt
Definition: listHistos.py:120
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual float phi() const
momentum azimuthal angle
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Jets made from PFObjects.
Definition: PFJet.h:21
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
edm::EDGetTokenT< PFCandToVertexAssMap > srcPFCandToVertexAssociations_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidates_
tuple minTrackPt
Definition: align_cfg.py:22
virtual float eta() const
momentum pseudorapidity
JVFJetIdProducer(const edm::ParameterSet &)
vector< PseudoJet > jets
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int isVertexAssociated(const reco::PFCandidate &, const PFCandToVertexAssMap &, const reco::VertexCollection &, double)
edm::EDGetTokenT< reco::VertexCollection > srcHardScatterVertex_
edm::EDGetTokenT< reco::PFJetCollection > srcJets_
void produce(edm::Event &, const edm::EventSetup &)
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
Definition: PFJet.cc:52
tuple verbosity
Definition: mvaPFMET_cff.py:80