CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CommonTools/CandAlgos/plugins/ParticleDecayProducer.cc

Go to the documentation of this file.
00001 
00007 // user include files
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009 #include "FWCore/Framework/interface/EDProducer.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Utilities/interface/InputTag.h"
00012 #include <vector>
00013 
00014 class ParticleDecayProducer : public edm::EDProducer {
00015  public:
00016   explicit ParticleDecayProducer(const edm::ParameterSet&);
00017   ~ParticleDecayProducer();
00018 
00019  private:
00020   virtual void produce(edm::Event&, const edm::EventSetup&);
00021   edm::InputTag genCandidates_;
00022   int motherPdgId_;
00023   std::vector<int> daughtersPdgId_;
00024   std::string decayChain_;
00025   std::vector<std::string> valias;
00026 };
00027 
00028 // Candidate handling
00029 #include "DataFormats/Candidate/interface/Candidate.h"
00030 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00031 #include "DataFormats/Common/interface/AssociationVector.h"
00032 #include "CommonTools/Utils/interface/PtComparator.h"
00033 #include "FWCore/Framework/interface/Event.h"
00034 #include <sstream>
00035 using namespace edm;
00036 using namespace std;
00037 using namespace reco;
00038 
00039 // constructors
00040 ParticleDecayProducer::ParticleDecayProducer(const edm::ParameterSet& iConfig) :
00041   genCandidates_(iConfig.getParameter<InputTag>("src")),
00042   motherPdgId_(iConfig.getParameter<int>("motherPdgId")),
00043   daughtersPdgId_(iConfig.getParameter<vector<int> >("daughtersPdgId")),
00044   decayChain_(iConfig.getParameter<std::string>("decayChain")) {
00045   string alias;
00046   produces<CandidateCollection >(alias = decayChain_+ "Mother").setBranchAlias(alias);
00047   for (unsigned int j = 0; j < daughtersPdgId_.size(); ++ j) {
00048     ostringstream index,collection;
00049     index << j;
00050     collection << decayChain_ << "Lepton" << index.str();
00051     valias.push_back(collection.str());
00052     produces<CandidateCollection >(valias.at(j)).setBranchAlias( valias.at(j) );
00053   }
00054 }
00055 
00056 // destructor
00057 ParticleDecayProducer::~ParticleDecayProducer() {
00058 }
00059 
00060 void ParticleDecayProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00061   // get gen particle candidates
00062   edm::Handle<CandidateCollection> genCandidatesCollection;
00063   iEvent.getByLabel(genCandidates_, genCandidatesCollection);
00064 
00065   auto_ptr<CandidateCollection> mothercands(new CandidateCollection);
00066   auto_ptr<CandidateCollection> daughterscands(new CandidateCollection);
00067   size_t daughtersize = daughtersPdgId_.size();
00068   for( CandidateCollection::const_iterator p = genCandidatesCollection->begin();p != genCandidatesCollection->end(); ++ p ) {
00069     if (p->pdgId() == motherPdgId_  && p->status() == 3){
00070       mothercands->push_back(p->clone());
00071       size_t ndau = p->numberOfDaughters();
00072       for(size_t i = 0; i < ndau; ++ i){
00073         for (size_t j = 0; j < daughtersize; ++j){
00074           if (p->daughter(i)->pdgId()==daughtersPdgId_[j] && p->daughter(i)->status()==3){
00075             daughterscands->push_back(p->daughter(i)->clone());
00076           }
00077         }
00078       }      
00079     }
00080   }
00081 
00082   iEvent.put(mothercands, decayChain_ + "Mother");
00083   daughterscands->sort(GreaterByPt<reco::Candidate>());
00084   
00085   for (unsigned int row = 0; row < daughtersize; ++ row ){
00086     auto_ptr<CandidateCollection> leptonscands_(new CandidateCollection);
00087     leptonscands_->push_back((daughterscands->begin()+row)->clone());
00088     iEvent.put(leptonscands_, valias.at(row));
00089   }
00090 }
00091 
00092 #include "FWCore/Framework/interface/MakerMacros.h"
00093 
00094 DEFINE_FWK_MODULE( ParticleDecayProducer );