File indexing completed on 2023-03-17 10:50:06
0001 #include "DataFormats/HepMCCandidate/interface/FlavorHistoryEvent.h"
0002 #include "TLorentzVector.h"
0003
0004 #include <iostream>
0005
0006 using namespace reco;
0007 using namespace std;
0008
0009
0010
0011 void FlavorHistoryEvent::cache() {
0012 bool verbose = false;
0013
0014 if (verbose)
0015 cout << "----- Caching Flavor History Event -----" << endl;
0016
0017 cached_ = false;
0018 nb_ = nc_ = 0;
0019 highestFlavor_ = 0;
0020 dR_ = 0.0;
0021 flavorSource_ = FlavorHistory::FLAVOR_NULL;
0022
0023
0024
0025 vector<helpers::FlavorHistoryEventHelper> classification;
0026
0027
0028 const_iterator i = histories_.begin(), ibegin = histories_.begin(), iend = histories_.end();
0029
0030
0031 for (; i != iend; ++i) {
0032 FlavorHistory const& flavHist = *i;
0033 if (verbose)
0034 cout << " Processing flavor history: " << i - ibegin << " = " << endl << flavHist << endl;
0035 CandidatePtr const& parton = flavHist.parton();
0036 flavor_type flavorSource = flavHist.flavorSource();
0037
0038
0039 int pdgId = -1;
0040 if (parton.isNonnull())
0041 pdgId = abs(parton->pdgId());
0042 ShallowClonePtrCandidate const& matchedJet = flavHist.matchedJet();
0043
0044 if (matchedJet.masterClonePtr().isNonnull()) {
0045 TLorentzVector p41(matchedJet.px(), matchedJet.py(), matchedJet.pz(), matchedJet.energy());
0046 if (pdgId == 5)
0047 nb_++;
0048 if (pdgId == 4)
0049 nc_++;
0050
0051
0052 ShallowClonePtrCandidate const& sisterJet = i->sisterJet();
0053 TLorentzVector p42(sisterJet.px(), sisterJet.py(), sisterJet.pz(), sisterJet.energy());
0054
0055
0056 double dR = -1;
0057 if (sisterJet.masterClonePtr().isNonnull()) {
0058 dR = p41.DeltaR(p42);
0059 }
0060
0061 if (verbose)
0062 cout << "Adding classification: pdgId = " << pdgId << ", flavorSource = " << flavorSource << ", dR = " << dR
0063 << endl;
0064 classification.push_back(helpers::FlavorHistoryEventHelper(pdgId, flavorSource, dR));
0065 } else {
0066 if (verbose)
0067 cout << "No matched jet found, not adding to classification list" << endl;
0068 }
0069 }
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 if (!classification.empty()) {
0083 std::sort(classification.begin(), classification.end());
0084
0085 if (verbose) {
0086 cout << "Writing out list of classifications" << endl;
0087 copy(classification.begin(), classification.end(), ostream_iterator<helpers::FlavorHistoryEventHelper>(cout, ""));
0088 }
0089
0090 helpers::FlavorHistoryEventHelper const& best = *(classification.rbegin());
0091 dR_ = best.dR;
0092 highestFlavor_ = best.flavor;
0093 flavorSource_ = best.flavorSource;
0094 } else {
0095 dR_ = -1.0;
0096 highestFlavor_ = 0;
0097 flavorSource_ = FlavorHistory::FLAVOR_NULL;
0098 }
0099
0100
0101 cached_ = true;
0102 }