Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:25

0001 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistorySelectorUtil.h"
0002 
0003 #include <iostream>
0004 
0005 using namespace std;
0006 using namespace reco;
0007 
0008 FlavorHistorySelectorUtil::FlavorHistorySelectorUtil(unsigned int flavor,
0009                                                      unsigned int noutput,
0010                                                      flavor_vector const& flavorSource,
0011                                                      double minDR,
0012                                                      double maxDR,
0013                                                      bool verbose)
0014     : flavor_(flavor), noutput_(noutput), flavorSource_(flavorSource), minDR_(minDR), maxDR_(maxDR), verbose_(verbose) {
0015   // Deal with the case if minDR == maxDR, just increment maxDR by epsilon
0016   if (maxDR_ - minDR_ <= 0.001)
0017     maxDR_ += 0.001;
0018 }
0019 
0020 bool FlavorHistorySelectorUtil::select(unsigned int nb,
0021                                        unsigned int nc,
0022                                        unsigned int highestFlavor,
0023                                        FlavorHistory::FLAVOR_T flavorSource,
0024                                        double dr) const {
0025   // Print out some information about this event
0026   if (verbose_) {
0027     cout << "Looking at flavor history event: " << endl;
0028     cout << "source   = " << flavorSource << endl;
0029     cout << "nbjet    = " << nb << endl;
0030     cout << "ncjet    = " << nc << endl;
0031     cout << "flavor   = " << highestFlavor << endl;
0032     cout << "dr       = " << dr << endl;
0033   }
0034 
0035   // First check that the highest flavor in the event is what this
0036   // filter is checking. Otherwise we need to fail the event,
0037   // since it should be handled by another filter
0038   if (highestFlavor > static_cast<unsigned int>(flavor_)) {
0039     if (verbose_)
0040       cout << "Rejecting event, highest flavor is " << highestFlavor << endl;
0041     return false;
0042   }
0043 
0044   // Next check that the flavor source is one of the desired ones
0045   vector<int>::const_iterator iflavorSource =
0046       find(flavorSource_.begin(), flavorSource_.end(), static_cast<int>(flavorSource));
0047   if (iflavorSource == flavorSource_.end()) {
0048     if (verbose_)
0049       cout << "Rejecting event, didn't find flavor source " << static_cast<int>(flavorSource) << endl;
0050     return false;
0051   }
0052 
0053   // If we are examining b quarks
0054   if (flavor_ == reco::FlavorHistory::bQuarkId) {
0055     // if we have no b quarks, return false
0056     if (nb <= 0) {
0057       if (verbose_)
0058         cout << "Rejecting event, nb = " << nb << endl;
0059       return false;
0060     }
0061     // here, nb > 0
0062     else {
0063       // if we want 1 b, require nb == 1
0064       if (noutput_ == 1 && nb == 1) {
0065         if (verbose_)
0066           cout << "Accepting event" << endl;
0067         return true;
0068       }
0069       // if we want 2 b, then look at delta R
0070       else if (noutput_ > 1 && nb > 1) {
0071         // If dr is within the range we want, pass.
0072         // Otherwise, fail.
0073         if (verbose_)
0074           cout << "Want multiples, dr = " << dr << endl;
0075         return (dr >= minDR_ && dr < maxDR_);
0076       }
0077       // otherwise return false
0078       else {
0079         if (verbose_)
0080           cout << "Rejecting event, isn't output = 1 + nb = 1, or output > 0 and delta R in proper range" << endl;
0081         return false;
0082       }
0083     }  // end if nb > 0
0084 
0085   }  // end if flavor is b quark
0086 
0087   // If we are examining c quarks
0088   else if (flavor_ == reco::FlavorHistory::cQuarkId) {
0089     // make sure there are no b quarks in the event.
0090     // If there are, another filter should handle it.
0091     if (nb > 0)
0092       return false;
0093 
0094     // if we have no c quarks, return false
0095     if (nc <= 0)
0096       return false;
0097     // here, nc > 0
0098     else {
0099       // if we want 1 c, require nc == 1
0100       if (noutput_ == 1 && nc == 1) {
0101         return true;
0102       }
0103       // if we want 2 c, then look at delta R
0104       else if (noutput_ > 1 && nc > 1) {
0105         // If dr is within the range we want, pass.
0106         // Otherwise, fail.
0107         return (dr >= minDR_ && dr < maxDR_);
0108       }
0109       // otherwise return false
0110       else {
0111         return false;
0112       }
0113     }  // end if nc > 0
0114 
0115   }
0116   // Otherwise return false
0117   else {
0118     if (verbose_)
0119       cout << "Something is weird, flavor is " << flavor_ << endl;
0120     return false;
0121   }
0122 }