CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DataFormats/HepMCCandidate/src/FlavorHistoryEvent.cc

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 // Loop over flavor histories, count number of genjets with
00010 // flavor b, c, or l
00011 void FlavorHistoryEvent::cache()
00012 {
00013 
00014   bool verbose = false;
00015   
00016   if ( verbose ) cout << "----- Caching Flavor History Event  -----" << endl;
00017   // Set cached to false
00018   cached_ = false;
00019   nb_ = nc_ = 0;
00020   highestFlavor_ = 0;
00021   dR_ = 0.0;
00022   flavorSource_ = FlavorHistory::FLAVOR_NULL;
00023 
00024   // get list of flavor --> type --> dR.
00025   // Will sort this later to determine event classification
00026   vector<helpers::FlavorHistoryEventHelper> classification;
00027 
00028   // get iterators to the history vector
00029   const_iterator i = histories_.begin(),
00030     ibegin = histories_.begin(),
00031     iend = histories_.end();
00032   // loop over the history vector and count the number of 
00033   // partons of flavors "b" and "c" that have a matched genjet.
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     // Now examine the matched jets to see what the classification should be.
00041     int pdgId = -1;
00042     if ( parton.isNonnull() ) pdgId = abs(parton->pdgId());
00043     ShallowClonePtrCandidate const & matchedJet = flavHist.matchedJet();
00044     // Only count events with a matched genjet
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       // Get the sister genjet
00051       ShallowClonePtrCandidate const & sisterJet = i->sisterJet();
00052       TLorentzVector p42 ( sisterJet.px(), sisterJet.py(), sisterJet.pz(), sisterJet.energy() );
00053 
00054 
00055       // Now check the source.
00056       double dR = -1;
00057       if ( sisterJet.masterClonePtr().isNonnull() ) {
00058         dR = p41.DeltaR( p42 );
00059       }
00060       // Add to the vector to be sorted later
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   // Sort by priority
00070   
00071   // Priority is:
00072   // 
00073   //  1. flavor (5 > 4)
00074   //  2. type:
00075   //      2a. Flavor decay
00076   //      2b. Matrix element
00077   //      2c. Flavor excitation
00078   //      2d. Gluon splitting
00079   //  3. delta R (if applicable)
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   // now we're cached, can return values quickly
00102   cached_ = true;
00103 }
00104 
00105 
00106