CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/HepMCCandAlgos/src/FlavorHistorySelectorUtil.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistorySelectorUtil.h"
00002 
00003 #include <iostream>
00004 
00005 using namespace std;
00006 using namespace reco;
00007 
00008 FlavorHistorySelectorUtil::FlavorHistorySelectorUtil( unsigned int flavor,
00009                                                       unsigned int noutput,
00010                                                       flavor_vector const & flavorSource,
00011                                                       double minDR,
00012                                                       double maxDR,
00013                                                       bool verbose ) :
00014   flavor_(flavor),
00015   noutput_(noutput),
00016   flavorSource_(flavorSource),
00017   minDR_(minDR),
00018   maxDR_(maxDR),
00019   verbose_(verbose)
00020 {
00021   
00022   // Deal with the case if minDR == maxDR, just increment maxDR by epsilon
00023   if ( maxDR_ - minDR_ <= 0.001 ) maxDR_ += 0.001;
00024 }
00025 
00026 bool FlavorHistorySelectorUtil::select(unsigned int nb,
00027                                        unsigned int nc,
00028                                        unsigned int highestFlavor,
00029                                        FlavorHistory::FLAVOR_T flavorSource,
00030                                        double dr ) const 
00031 {
00032   
00033   // Print out some information about this event
00034   if ( verbose_ ) {
00035     cout << "Looking at flavor history event: " << endl;
00036     cout << "source   = " << flavorSource << endl;
00037     cout << "nbjet    = " << nb << endl;
00038     cout << "ncjet    = " << nc << endl;
00039     cout << "flavor   = " << highestFlavor << endl;
00040     cout << "dr       = " << dr << endl;
00041   }
00042 
00043   // First check that the highest flavor in the event is what this
00044   // filter is checking. Otherwise we need to fail the event,
00045   // since it should be handled by another filter
00046   if ( highestFlavor > static_cast<unsigned int>(flavor_) ) {
00047     if ( verbose_ ) cout << "Rejecting event, highest flavor is " << highestFlavor << endl;
00048     return false;
00049   }
00050 
00051   // Next check that the flavor source is one of the desired ones
00052   vector<int>::const_iterator iflavorSource = find( flavorSource_.begin(), flavorSource_.end(), static_cast<int>(flavorSource) );
00053   if ( iflavorSource == flavorSource_.end() ) {
00054     if ( verbose_ ) cout << "Rejecting event, didn't find flavor source " << static_cast<int>(flavorSource) << endl;
00055     return false;
00056   }
00057   
00058   // If we are examining b quarks
00059   if ( flavor_ == reco::FlavorHistory::bQuarkId ) {
00060     // if we have no b quarks, return false
00061     if ( nb <= 0 ) {
00062       if ( verbose_ ) cout << "Rejecting event, nb = " << nb << endl;
00063       return false;
00064     }
00065     // here, nb > 0
00066     else {
00067       // if we want 1 b, require nb == 1
00068       if ( noutput_ == 1 && nb == 1 ) {
00069         if ( verbose_ ) cout << "Accepting event" << endl;
00070         return true;
00071       }
00072       // if we want 2 b, then look at delta R
00073       else if ( noutput_ > 1 && nb > 1 ) {
00074         // If dr is within the range we want, pass.
00075         // Otherwise, fail.
00076         if ( verbose_ ) cout << "Want multiples, dr = " << dr << endl;
00077         return ( dr >= minDR_ && dr < maxDR_ );
00078       }
00079       // otherwise return false
00080       else {
00081         if ( verbose_ ) cout << "Rejecting event, isn't output = 1 + nb = 1, or output > 0 and delta R in proper range" << endl;
00082         return false;
00083       }
00084     }// end if nb > 0
00085     
00086   } // end if flavor is b quark
00087 
00088   // If we are examining c quarks
00089   else if ( flavor_ == reco::FlavorHistory::cQuarkId ) {
00090     // make sure there are no b quarks in the event.
00091     // If there are, another filter should handle it.
00092     if ( nb > 0 ) return false;
00093     
00094     // if we have no c quarks, return false
00095     if ( nc <= 0 ) return false;
00096     // here, nc > 0
00097     else {
00098       // if we want 1 c, require nc == 1
00099       if ( noutput_ == 1 && nc == 1 ) {
00100         return true;
00101       }
00102       // if we want 2 c, then look at delta R
00103       else if ( noutput_ > 1 && nc > 1 ) {
00104         // If dr is within the range we want, pass.
00105         // Otherwise, fail.
00106         return ( dr >= minDR_ && dr < maxDR_ );
00107       }
00108       // otherwise return false
00109       else {
00110         return false;
00111       }
00112     }// end if nc > 0
00113     
00114   }
00115   // Otherwise return false
00116   else {
00117     if ( verbose_ ) cout << "Something is weird, flavor is " << flavor_ << endl;
00118     return false;
00119   }
00120 }