CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 // This file was removed but it should not have been.
00002 // This comment is to restore it. 
00003 
00004 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistoryFilter.h"
00005 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistoryProducer.h"
00006 
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "DataFormats/Math/interface/deltaR.h"
00010 
00011 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistorySelectorUtil.h"
00012 
00013 #include <vector>
00014 
00015 using namespace edm;
00016 using namespace reco;
00017 using namespace std;
00018 
00019 
00020 //
00021 // constants, enums and typedefs
00022 //
00023 
00024 //
00025 // static data member definitions
00026 //
00027 
00028 //
00029 // constructors and destructor
00030 //
00031 FlavorHistoryFilter::FlavorHistoryFilter(const edm::ParameterSet& iConfig) :
00032   bsrc_           ( iConfig.getParameter<edm::InputTag>("bsrc" ) ),
00033   csrc_           ( iConfig.getParameter<edm::InputTag>("csrc" ) )
00034 {
00035   if ( iConfig.exists("pathToSelect") )
00036     pathToSelect_ =        iConfig.getParameter<int>    ("pathToSelect");
00037   else
00038     pathToSelect_ = -1;
00039 
00040   // This is the "interface" delta R with which to decide
00041   // where to take the event from
00042   dr_                =  iConfig.getParameter<double> ("dr" ) ;
00043   bool verbose        ( iConfig.getParameter<bool>   ("verbose") );
00044 
00045   // Set up the boundaries.
00046   // dr0 = 0.0
00047   // dr1 = set by user
00048   // dr2 = infinity
00049   double dr0 = 0.0;
00050   double dr1 = dr_;
00051   double dr2 = 99999.0;
00052   
00053 
00054   // These are the processes that can come from the matrix element calculation
00055   std::vector<int> me_ids;
00056   me_ids.push_back(2);   // flavor excitation
00057   me_ids.push_back(3);   // flavor creation
00058   
00059   // These are the processes that can come from the parton shower calculation
00060   std::vector<int> ps_ids;
00061   ps_ids.push_back(1);   // gluon splitting
00062 
00063 
00064   // To select bb->2 events from matrix element... Path 1 
00065   bb_me_ = new FlavorHistorySelectorUtil( 5,
00066                                           2,
00067                                           me_ids,
00068                                           dr1,
00069                                           dr2,
00070                                           verbose );
00071 
00072   // To select  b->1 events from matrix element... Path 2 
00073   b_me_  = new FlavorHistorySelectorUtil( 5,
00074                                           1,
00075                                           me_ids,
00076                                           dr0,
00077                                           dr0,
00078                                           verbose );
00079 
00080 
00081   // To select cc->2 events from matrix element... Path 3
00082   cc_me_ = new FlavorHistorySelectorUtil( 4,
00083                                           2,
00084                                           me_ids,
00085                                           dr1,
00086                                           dr2,
00087                                           verbose );
00088 
00089   // To select  c->1 events from matrix element... Path 4
00090   c_me_  = new FlavorHistorySelectorUtil( 4,
00091                                           1,
00092                                           me_ids,
00093                                           dr0,
00094                                           dr0,
00095                                           verbose );
00096 
00097   // To select bb->2 events from parton shower ... Path 5 
00098   b_ps_  = new FlavorHistorySelectorUtil( 5,
00099                                           1,
00100                                           ps_ids,
00101                                           dr0,
00102                                           dr1,
00103                                           verbose );
00104 
00105   
00106   // To select cc->2 events from parton shower ... Path 6 
00107   c_ps_  = new FlavorHistorySelectorUtil( 4,
00108                                           1,
00109                                           ps_ids,
00110                                           dr0,
00111                                           dr1,
00112                                           verbose );  
00113 
00114   // To select bb->1 events from matrix element... Path 7
00115   bb_me_comp_ = new FlavorHistorySelectorUtil( 5,
00116                                                2,
00117                                                me_ids,
00118                                                dr0,
00119                                                dr1,
00120                                                verbose );
00121 
00122   // To select cc->1 events from matrix element... Path 8 
00123   cc_me_comp_ = new FlavorHistorySelectorUtil( 4,
00124                                                2,
00125                                                me_ids,
00126                                                dr0,
00127                                                dr1,
00128                                                verbose );
00129 
00130   // To select bb->2 events from parton shower ... Path 9 
00131   b_ps_comp_  = new FlavorHistorySelectorUtil( 5,
00132                                                2,
00133                                                ps_ids,
00134                                                dr1,
00135                                                dr2,
00136                                                verbose );
00137 
00138   // To select cc->1 events from parton shower ... Path 10
00139   c_ps_comp_  = new FlavorHistorySelectorUtil( 4,
00140                                                2,
00141                                                ps_ids,
00142                                                dr1,
00143                                                dr2,
00144                                                verbose );
00145 
00146   // The veto of all of these is               ... Path 11
00147   
00148 
00149   // This will write 1-11 (the path number), or 0 if error. 
00150   produces<unsigned int>();
00151 }
00152 
00153 
00154 FlavorHistoryFilter::~FlavorHistoryFilter()
00155 {
00156  
00157   if ( bb_me_ ) delete bb_me_; 
00158   if (  b_me_ ) delete b_me_;
00159   if ( cc_me_ ) delete cc_me_; 
00160   if (  c_me_ ) delete c_me_;  
00161   if (  b_ps_ ) delete b_ps_; 
00162   if (  c_ps_ ) delete c_ps_; 
00163 
00164   if ( bb_me_comp_ ) delete bb_me_comp_; 
00165   if ( cc_me_comp_ ) delete cc_me_comp_; 
00166   if (  b_ps_comp_ ) delete b_ps_comp_; 
00167   if (  c_ps_comp_ ) delete c_ps_comp_;
00168 
00169 
00170 
00171  
00172 }
00173 
00174 
00175 
00176 bool
00177 FlavorHistoryFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00178 {
00179 
00180   // Get the flavor history
00181   Handle<FlavorHistoryEvent > bFlavorHistoryEvent;
00182   iEvent.getByLabel(bsrc_,bFlavorHistoryEvent);
00183 
00184   Handle<FlavorHistoryEvent > cFlavorHistoryEvent;
00185   iEvent.getByLabel(csrc_,cFlavorHistoryEvent);
00186 
00187   std::auto_ptr<unsigned int> selection ( new unsigned int() );
00188 
00189   // Get the number of matched b-jets in the event
00190   unsigned int nb = bFlavorHistoryEvent->nb();
00191   // Get the number of matched c-jets in the event
00192   unsigned int nc = cFlavorHistoryEvent->nc();
00193   // Get the two flavor sources. The highest takes precedence
00194   // over the rest. 
00195   FlavorHistory::FLAVOR_T bFlavorSource = bFlavorHistoryEvent->flavorSource();
00196   FlavorHistory::FLAVOR_T cFlavorSource = cFlavorHistoryEvent->flavorSource();
00197   FlavorHistory::FLAVOR_T flavorSource = FlavorHistory::FLAVOR_NULL;
00198   // Get the highest flavor in the event
00199   unsigned int highestFlavor = 0;  
00200   // Get the delta r between the two heavy flavor matched jets.
00201   double dr = -1;
00202 
00203   // Preference is in increasing priority:
00204   //  1: gluon splitting
00205   //  2: flavor excitation
00206   //  3: flavor creation (matrix element)
00207   //  4: flavor decay
00208   if ( bFlavorSource >= cFlavorSource ) {    
00209     flavorSource = bFlavorHistoryEvent->flavorSource();
00210     highestFlavor = bFlavorHistoryEvent->highestFlavor();
00211     dr = bFlavorHistoryEvent->deltaR();    
00212   }
00213   else {
00214     flavorSource = cFlavorHistoryEvent->flavorSource();
00215     highestFlavor = cFlavorHistoryEvent->highestFlavor();
00216     dr = cFlavorHistoryEvent->deltaR();
00217   }
00218 
00219   
00220   *selection = 0;
00221   // Now make hierarchical determination
00222   if      ( bb_me_     ->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 1;
00223   else if (  b_me_     ->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 2;
00224   else if ( cc_me_     ->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 3;
00225   else if (  c_me_     ->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 4;
00226   else if (  b_ps_     ->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 5;
00227   else if (  c_ps_     ->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 6;
00228   else if ( bb_me_comp_->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 7;
00229   else if ( cc_me_comp_->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 8;
00230   else if (  b_ps_comp_->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 9;
00231   else if (  c_ps_comp_->select( nb, nc, highestFlavor, flavorSource, dr ) ) *selection = 10;
00232   else *selection = 11;
00233 
00234   bool pass = false;
00235   if ( pathToSelect_ > 0 ) {
00236     pass = (*selection > 0 && *selection == static_cast<unsigned int>(pathToSelect_ ) );
00237   } else {
00238     pass = true;
00239   }
00240 
00241   iEvent.put( selection );
00242 
00243   return pass; 
00244 
00245 }
00246 
00247 // ------------ method called once each job just after ending the event loop  ------------
00248 void 
00249 FlavorHistoryFilter::endJob() {
00250 }
00251 
00252 //define this as a plug-in
00253 DEFINE_FWK_MODULE(FlavorHistoryFilter);