00001 #include "PhysicsTools/JetMCAlgos/plugins/TauGenJetProducer.h"
00002
00003
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009
00010 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00011 #include "DataFormats/JetReco/interface/GenJetCollection.h"
00012 #include "DataFormats/JetReco/interface/GenJet.h"
00013 #include "DataFormats/Common/interface/RefToPtr.h"
00014
00015 #include "PhysicsTools/HepMCCandAlgos/interface/GenParticlesHelper.h"
00016
00017
00018 using namespace std;
00019 using namespace edm;
00020 using namespace reco;
00021
00022 TauGenJetProducer::TauGenJetProducer(const edm::ParameterSet& iConfig) {
00023
00024
00025 inputTagGenParticles_
00026 = iConfig.getParameter<InputTag>("GenParticles");
00027
00028 includeNeutrinos_
00029 = iConfig.getParameter<bool>("includeNeutrinos");
00030
00031 verbose_ =
00032 iConfig.getUntrackedParameter<bool>("verbose",false);
00033
00034
00035
00036 produces<GenJetCollection>();
00037 }
00038
00039
00040
00041 TauGenJetProducer::~TauGenJetProducer() { }
00042
00043
00044
00045 void TauGenJetProducer::beginJob(const edm::EventSetup & es) { }
00046
00047
00048 void TauGenJetProducer::produce(Event& iEvent,
00049 const EventSetup& iSetup) {
00050
00051 Handle<GenParticleCollection> genParticles;
00052
00053 bool found = iEvent.getByLabel( inputTagGenParticles_, genParticles);
00054
00055 if(!found ) {
00056 std::ostringstream err;
00057 err<<" cannot get collection: "
00058 <<inputTagGenParticles_<<std::endl;
00059 edm::LogError("TauGenJetProducer")<<err.str();
00060 throw cms::Exception( "MissingProduct", err.str());
00061 }
00062
00063 std::auto_ptr<GenJetCollection>
00064 pOutVisTaus(new GenJetCollection() );
00065
00066
00067 using namespace GenParticlesHelper;
00068
00069 GenParticleRefVector allStatus2Taus;
00070 findParticles( *genParticles,
00071 allStatus2Taus, 15, 2);
00072
00073 for( IGR iTau=allStatus2Taus.begin(); iTau!=allStatus2Taus.end(); ++iTau) {
00074
00075
00076 GenParticleRefVector descendents;
00077 findDescendents( *iTau, descendents, 1);
00078
00079
00080 math::XYZTLorentzVector sumVisMom;
00081 Particle::Charge charge = 0;
00082 Jet::Constituents constituents;
00083
00084 if(verbose_)
00085 cout<<"tau "<<(*iTau)<<endl;
00086
00087
00088 for(IGR igr = descendents.begin();
00089 igr!= descendents.end(); ++igr ) {
00090
00091 int absPdgId = abs( (*igr)->pdgId());
00092
00093
00094 if(!includeNeutrinos_ ) {
00095 if( absPdgId == 12 ||
00096 absPdgId == 14 ||
00097 absPdgId == 16 )
00098 continue;
00099 }
00100
00101 if(verbose_)
00102 cout<<"\t"<<(*igr)<<endl;
00103
00104 charge += (*igr)->charge();
00105 sumVisMom += (*igr)->p4();
00106
00107
00108
00109 constituents.push_back( refToPtr( *igr) );
00110 }
00111
00112 math::XYZPoint vertex;
00113 GenJet::Specific specific;
00114
00115 GenJet jet( sumVisMom, vertex, specific, constituents);
00116 pOutVisTaus->push_back( jet );
00117
00118 }
00119 iEvent.put( pOutVisTaus );
00120 }
00121
00122
00123 DEFINE_FWK_MODULE( TauGenJetProducer );