73 #include <Math/VectorUtil.h>
79 using namespace ROOT::Math::VectorUtil;
100 std::vector<const reco::Candidate*> findCandidates(
const reco::Candidate*,
int);
101 void fillLeptons(
const std::vector<const reco::Candidate*> &,
JetFlavour::Leptons &,
int,
int);
102 static int heaviestFlavour(
int);
119 produces<JetFlavourMatchingCollection>();
120 sourceByReferToken_ = consumes<JetMatchedPartonsCollection>(iConfig.
getParameter<
InputTag>(
"srcByReference"));
121 physDefinition = iConfig.
getParameter<
bool>(
"physicsDefinition");
122 leptonInfo_ = iConfig.
exists(
"leptonInfo") ? iConfig.
getParameter<
bool>(
"leptonInfo") :
false;
127 if ( iConfig.
exists(
"definition") ) {
130 definition = NULL_DEF;
136 JetFlavourIdentifier::~JetFlavourIdentifier()
145 iEvent.
getByToken (sourceByReferToken_, theTagByRef);
149 if (!theTagByRef->empty()) {
155 auto_ptr<reco::JetFlavourMatchingCollection> jetFlavMatching(jfmc);
159 j != theTagByRef->end();
169 int thePartonFlavour = 0;
173 switch (definition) {
177 thePartonLorentzVector = aPartPhy.
get()->p4();
178 thePartonVertex = aPartPhy.
get()->vertex();
179 thePartonFlavour = aPartPhy.
get()->pdgId();
180 if (leptonInfo_) theLeptons = findLeptons(aPartPhy);
187 thePartonLorentzVector = aPartAlg.
get()->p4();
188 thePartonVertex = aPartAlg.
get()->vertex();
189 thePartonFlavour = aPartAlg.
get()->pdgId();
190 if (leptonInfo_) theLeptons = findLeptons(aPartAlg);
194 case NEAREST_STATUS2 : {
197 thePartonLorentzVector = aPartN2.
get()->p4();
198 thePartonVertex = aPartN2.
get()->vertex();
199 thePartonFlavour = aPartN2.
get()->pdgId();
200 if (leptonInfo_) theLeptons = findLeptons(aPartN2);
204 case NEAREST_STATUS3: {
207 thePartonLorentzVector = aPartN3.
get()->p4();
208 thePartonVertex = aPartN3.
get()->vertex();
209 thePartonFlavour = aPartN3.
get()->pdgId();
210 if (leptonInfo_) theLeptons = findLeptons(aPartN3);
217 thePartonLorentzVector = aPartHeaviest.
get()->p4();
218 thePartonVertex = aPartHeaviest.
get()->vertex();
219 thePartonFlavour = aPartHeaviest.
get()->pdgId();
220 if (leptonInfo_) theLeptons = findLeptons(aPartHeaviest);
226 if (physDefinition) {
229 thePartonLorentzVector = aPartPhy.
get()->p4();
230 thePartonVertex = aPartPhy.
get()->vertex();
231 thePartonFlavour = aPartPhy.
get()->pdgId();
232 if (leptonInfo_) theLeptons = findLeptons(aPartPhy);
237 thePartonLorentzVector = aPartAlg.
get()->p4();
238 thePartonVertex = aPartAlg.
get()->vertex();
239 thePartonFlavour = aPartAlg.
get()->pdgId();
240 if (leptonInfo_) theLeptons = findLeptons(aPartAlg);
249 if (thePartonFlavour == 0) {
250 if (physDefinition) {
253 thePartonLorentzVector = aPartPhy.
get()->p4();
254 thePartonVertex = aPartPhy.
get()->vertex();
255 thePartonFlavour = aPartPhy.
get()->pdgId();
256 if (leptonInfo_) theLeptons = findLeptons(aPartPhy);
261 thePartonLorentzVector = aPartAlg.
get()->p4();
262 thePartonVertex = aPartAlg.
get()->vertex();
263 thePartonFlavour = aPartAlg.
get()->pdgId();
264 if (leptonInfo_) theLeptons = findLeptons(aPartAlg);
276 (*jetFlavMatching)[(*j).first] =
JetFlavour(thePartonLorentzVector, thePartonVertex, thePartonFlavour, theLeptons);
281 iEvent.
put( jetFlavMatching );
289 thePartonLV = parton->p4();
293 int partonFlavour =
std::abs(parton->pdgId());
297 std::vector<const reco::Candidate*>
candidates = findCandidates(mcstring, partonFlavour);
302 fillLeptons(candidates, theLeptons, 1, partonFlavour);
307 std::vector<const reco::Candidate*> JetFlavourIdentifier::findCandidates(
const reco::Candidate *cand,
int partonFlavour)
309 std::vector<const reco::Candidate*> cands;
310 if(!cand)
return cands;
322 int flavour = heaviestFlavour(pdgId);
323 if (flavour == partonFlavour ||
324 (flavour >= 10 && partonFlavour >= 10)) {
326 std::vector<const reco::Candidate*> newcands = findCandidates(cand->
daughter(
i), partonFlavour);
328 std::copy(newcands.begin(), newcands.end(), std::back_inserter(cands));
330 if (partonFlavour >= 10)
336 !(partonFlavour >= 4 && partonFlavour < 10 &&
337 heaviestFlavour(cand->
pdgId()) < 4))
338 cands.push_back(cand);
345 for(
unsigned int j = 0;
j < cands.size();
j++) {
346 for(
unsigned int i = 0;
i < cands[
j]->numberOfDaughters();
i++) {
355 else if (pdgId == 14)
356 leptons.
muon += rank;
357 else if (pdgId == 16)
360 int heaviest = heaviestFlavour(pdgId);
361 int heaviest_ = heaviest < 10 ? heaviest : 0;
362 if (!heaviest || (flavour < 4 ? (heaviest_ < 4) : (heaviest >= 4))) {
363 std::vector<const reco::Candidate*> newcands = findCandidates(cands[
j]->daughter(
i), heaviest);
364 if (pdgId <= 110) newcands.push_back(cands[
j]->daughter(
i));
365 fillLeptons(newcands, leptons, rank * 10,
std::max(heaviest_, flavour));
372 int JetFlavourIdentifier::heaviestFlavour(
int pdgId)
378 while(pdgId % 10 > 0 && pdgId % 10 < 6) {
380 if (pdgId % 10 > flavour)
381 flavour = pdgId % 10;
T getParameter(std::string const &) const
Handle< JetMatchedPartonsCollection > theTagByRef
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
bool isNonnull() const
Checks for non-null.
transient_vector_type::const_iterator const_iterator
const GenParticleRef & nearest_status3() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
virtual size_type numberOfDaughters() const =0
number of daughters
const GenParticleRef & algoDefinitionParton() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Abs< T >::type abs(const T &t)
T const * get() const
Returns C++ pointer to the item.
const GenParticleRef & nearest_status2() const
virtual int pdgId() const =0
PDG identifier.
const GenParticleRef heaviest() const
XYZPointD XYZPoint
point in space with cartesian internal representation
const GenParticleRef & physicsDefinitionParton() const
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
EDGetTokenT< JetMatchedPartonsCollection > sourceByReferToken_
int flavour(const Candidate &part)
math::XYZTLorentzVector thePartonLV
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector