CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CommonTools/CandAlgos/src/GenJetParticleSelector.cc

Go to the documentation of this file.
00001 #include "CommonTools/CandAlgos/interface/GenJetParticleSelector.h"
00002 #include "DataFormats/Candidate/interface/Candidate.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "SimGeneral/HepPDTRecord/interface/PdtEntry.h"
00005 #include "FWCore/Utilities/interface/EDMException.h"
00006 #include <algorithm>
00007 using namespace std;
00008 using namespace edm;
00009 
00010 GenJetParticleSelector::GenJetParticleSelector(const ParameterSet& cfg) :
00011   stableOnly_(cfg.getParameter<bool>("stableOnly")),
00012   partons_(false), bInclude_(false) {
00013   const string excludeString("excludeList");
00014   const string includeString("includeList");
00015   vpdt includeList, excludeList;
00016   vector<string> vPdtParams = cfg.getParameterNamesForType<vpdt>();
00017   bool found = std::find(vPdtParams.begin(), vPdtParams.end(), includeString) != vPdtParams.end();
00018   if(found) includeList = cfg.getParameter<vpdt>(includeString);
00019   found = find(vPdtParams.begin(), vPdtParams.end(), excludeString) != vPdtParams.end();
00020   if(found) excludeList = cfg.getParameter<vpdt>(excludeString);
00021   const string partonsString("partons");
00022   vector<string> vBoolParams = cfg.getParameterNamesForType<bool>();
00023   found = find(vBoolParams.begin(), vBoolParams.end(), partonsString) != vBoolParams.end();
00024   if(found) partons_ = cfg.getParameter<bool>(partonsString);
00025   bool bExclude = false;
00026   if (includeList.size() > 0) bInclude_ = true;
00027   if (excludeList.size() > 0) bExclude = true;
00028 
00029   if (bInclude_ && bExclude) {
00030     throw cms::Exception("ConfigError", "not allowed to use both includeList and excludeList at the same time\n");
00031   }
00032   else if (bInclude_) {
00033     pdtList_ = includeList;
00034   }
00035   else {
00036     pdtList_ = excludeList;
00037   }
00038   if(stableOnly_ && partons_) {
00039     throw cms::Exception("ConfigError", "not allowed to have both stableOnly and partons true at the same time\n");
00040   }
00041 }
00042 
00043 bool GenJetParticleSelector::operator()(const reco::Candidate& p) {
00044   int status = p.status();
00045   int id = abs(p.pdgId());
00046   if((!stableOnly_ || status == 1) && !partons_ &&
00047      ( (pIds_.find(id) == pIds_.end()) ^ bInclude_))
00048     return true;
00049   else if(partons_ &&
00050           (p.numberOfDaughters() > 0 && (p.daughter(0)->pdgId() == 91 || p.daughter(0)->pdgId() == 92)) &&
00051           ( ((pIds_.find(id) == pIds_.end()) ^ bInclude_)))
00052     return true;
00053   else
00054     return false;
00055 }
00056 
00057 void GenJetParticleSelector::init(const edm::EventSetup& es) {
00058   for(vpdt::iterator i = pdtList_.begin(); i != pdtList_.end(); ++i )
00059     i->setup(es);
00060 }
00061