Go to the documentation of this file.00001 #include "DataFormats/HepMCCandidate/interface/FlavorHistoryEvent.h"
00002 #include "TLorentzVector.h"
00003
00004 #include <iostream>
00005
00006 using namespace reco;
00007 using namespace std;
00008
00009
00010
00011 void FlavorHistoryEvent::cache()
00012 {
00013
00014 bool verbose = false;
00015
00016 if ( verbose ) cout << "----- Caching Flavor History Event -----" << endl;
00017
00018 cached_ = false;
00019 nb_ = nc_ = 0;
00020 highestFlavor_ = 0;
00021 dR_ = 0.0;
00022 flavorSource_ = FlavorHistory::FLAVOR_NULL;
00023
00024
00025
00026 vector<helpers::FlavorHistoryEventHelper> classification;
00027
00028
00029 const_iterator i = histories_.begin(),
00030 ibegin = histories_.begin(),
00031 iend = histories_.end();
00032
00033
00034 for ( ; i != iend; ++i ) {
00035 FlavorHistory const & flavHist = *i;
00036 if ( verbose ) cout << " Processing flavor history: " << i - ibegin << " = " << endl << flavHist << endl;
00037 CandidatePtr const & parton = flavHist.parton();
00038 flavor_type flavorSource = flavHist.flavorSource();
00039
00040
00041 int pdgId = -1;
00042 if ( parton.isNonnull() ) pdgId = abs(parton->pdgId());
00043 ShallowClonePtrCandidate const & matchedJet = flavHist.matchedJet();
00044
00045 if ( matchedJet.masterClonePtr().isNonnull() ) {
00046 TLorentzVector p41 ( matchedJet.px(), matchedJet.py(), matchedJet.pz(), matchedJet.energy() );
00047 if ( pdgId == 5 ) nb_++;
00048 if ( pdgId == 4 ) nc_++;
00049
00050
00051 ShallowClonePtrCandidate const & sisterJet = i->sisterJet();
00052 TLorentzVector p42 ( sisterJet.px(), sisterJet.py(), sisterJet.pz(), sisterJet.energy() );
00053
00054
00055
00056 double dR = -1;
00057 if ( sisterJet.masterClonePtr().isNonnull() ) {
00058 dR = p41.DeltaR( p42 );
00059 }
00060
00061 if ( verbose ) cout << "Adding classification: pdgId = " << pdgId << ", flavorSource = " << flavorSource << ", dR = " << dR << endl;
00062 classification.push_back( helpers::FlavorHistoryEventHelper ( pdgId, flavorSource, dR ) );
00063 } else{
00064 if ( verbose ) cout << "No matched jet found, not adding to classification list" << endl;
00065 }
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 if ( classification.size() > 0 ) {
00081
00082
00083 std::sort( classification.begin(), classification.end() );
00084
00085 if ( verbose ){ cout << "Writing out list of classifications" << endl;
00086 copy(classification.begin(), classification.end(),
00087 ostream_iterator<helpers::FlavorHistoryEventHelper>(cout, ""));
00088 }
00089
00090 helpers::FlavorHistoryEventHelper const & best = *(classification.rbegin());
00091 dR_ = best.dR;
00092 highestFlavor_ = best.flavor;
00093 flavorSource_ = best.flavorSource;
00094 }
00095 else {
00096 dR_ = -1.0;
00097 highestFlavor_ = 0;
00098 flavorSource_ = FlavorHistory::FLAVOR_NULL;
00099 }
00100
00101
00102 cached_ = true;
00103 }
00104
00105
00106