CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/PhysicsTools/JetMCAlgos/plugins/PartonSelector.cc

Go to the documentation of this file.
00001 //
00002 // Select the partons status 2 and 3 for MC Jet Flavour 
00003 // Author: Attilio
00004 // Date: 10.10.2007
00005 //
00006     
00007 //=======================================================================
00008 
00009 // user include files
00010 #include "FWCore/Framework/interface/EDProducer.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "FWCore/Utilities/interface/InputTag.h"
00013 
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "FWCore/Framework/interface/MakerMacros.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 #include "DataFormats/Common/interface/Handle.h"
00021 #include "DataFormats/Common/interface/Ref.h"  
00022 //#include "DataFormats/Candidate/interface/CandidateFwd.h"
00023 //#include "DataFormats/HepMCCandidate/interface/GenParticleCandidate.h"
00024 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00025 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
00026       
00027 #include <memory>
00028 #include <string>
00029 #include <iostream>
00030 #include <vector>
00031          
00032 using namespace std;
00033 using namespace reco;
00034 using namespace edm;
00035 
00036 class PartonSelector : public edm::EDProducer 
00037 {
00038   public:
00039     PartonSelector( const edm::ParameterSet & );
00040     ~PartonSelector();
00041 
00042   private:
00043 
00044     virtual void produce(edm::Event&, const edm::EventSetup& ); 
00045     bool withLeptons;  // Optionally specify leptons
00046     bool withTop;      // Optionally include top quarks in the list 
00047     edm::InputTag   inputTagGenParticles_; // input collection
00048 };
00049 //=========================================================================
00050 
00051 PartonSelector::PartonSelector( const edm::ParameterSet& iConfig )
00052 { 
00053     produces<reco::GenParticleRefVector>();
00054     withLeptons           = iConfig.getParameter<bool>("withLeptons"); 
00055     inputTagGenParticles_ = iConfig.getParameter<edm::InputTag>("src");
00056     if ( iConfig.exists("withTop") ) {
00057       withTop = iConfig.getParameter<bool>("withTop");
00058     } else {
00059       withTop = false;
00060     }
00061 }
00062 
00063 //=========================================================================
00064 
00065 PartonSelector::~PartonSelector()
00066 {
00067 }
00068 
00069 // ------------ method called to produce the data  ------------
00070 
00071 void PartonSelector::produce( Event& iEvent, const EventSetup& iEs )
00072 {
00073   
00074   //edm::Handle <reco::CandidateView> particles;
00075   edm::Handle <reco::GenParticleCollection> particles;
00076   iEvent.getByLabel (inputTagGenParticles_, particles );  
00077   edm::LogVerbatim("PartonSelector") << "=== GenParticle size:" << particles->size();
00078   int nPart=0; 
00079 
00080   auto_ptr<GenParticleRefVector> thePartons ( new GenParticleRefVector);  
00081   
00082   for (size_t m = 0; m < particles->size(); m++) {
00083     
00084     // Don't take into account first 6 particles in generator list
00085     if (m<6) continue;    
00086 
00087     const GenParticle & aParticle = (*particles)[ m ];
00088 
00089     bool isAParton = false;
00090     bool isALepton = false;
00091     int flavour = abs(aParticle.pdgId());
00092     if(flavour == 1 ||
00093        flavour == 2 ||
00094        flavour == 3 ||
00095        flavour == 4 ||
00096        flavour == 5 ||  
00097        (flavour == 6 && withTop) ||
00098        flavour == 21 ) isAParton = true;
00099     if(flavour == 11 ||
00100        flavour == 12 ||
00101        flavour == 13 ||
00102        flavour == 14 ||
00103        flavour == 15 ||
00104        flavour == 16 ) isALepton = true;
00105 
00106 
00107     //Add Partons status 3
00108     if( aParticle.status() == 3 && isAParton ) {
00109       thePartons->push_back( GenParticleRef( particles, m ) );
00110       nPart++;
00111     }
00112 
00113     //Add Partons status 2
00114     int nparton_daughters = 0;
00115     if( aParticle.numberOfDaughters() > 0 && isAParton ) {
00116       
00117       for (unsigned int i=0; i < aParticle.numberOfDaughters(); i++){
00118         
00119         int daughterFlavour = abs(aParticle.daughter(i)->pdgId());
00120         if( (daughterFlavour == 1 || daughterFlavour == 2 || daughterFlavour == 3 || 
00121              daughterFlavour == 4 || daughterFlavour == 5 || daughterFlavour == 6 || daughterFlavour == 21)) {
00122           nparton_daughters++;
00123         }
00124 
00125       }
00126       if(nparton_daughters == 0){
00127           nPart++;
00128           thePartons->push_back( GenParticleRef( particles, m ) );
00129       }
00130 
00131     }
00132 
00133     //Add Leptons
00134     // Here you have to decide what to do with taus....
00135     // Now all leptons, including e and mu from leptonic tau decays, are added
00136     if( withLeptons && aParticle.status() == 3 && isALepton ) {
00137       thePartons->push_back( GenParticleRef( particles, m ) );
00138       nPart++;
00139     }
00140   }
00141   
00142   edm::LogVerbatim("PartonSelector") << "=== GenParticle selected:" << nPart;  
00143   iEvent.put( thePartons );
00144 
00145 }
00146 
00147 DEFINE_FWK_MODULE(PartonSelector);
00148