#include <CMGTools/PileupJetIdProducer/src/PileupJetIdProducer.cc>
Description: [one line class summary]
Implementation: [Notes on implementation]
Definition at line 48 of file PileupJetIdProducer.cc.
PileupJetIdProducer::PileupJetIdProducer | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 79 of file PileupJetIdProducer.cc.
References algos_, applyJec_, edm::ParameterSet::getParameter(), inputIsCorrected_, jec_, jecCor_, jetids_, jets_, diffTwoXMLs::label, produceJetIds_, residualsFromTxt_, residualsTxt_, rho_, runMvas_, AlCaHLTBitMon_QueryRunRegistry::string, and vertexes_.
{ runMvas_ = iConfig.getParameter<bool>("runMvas"); produceJetIds_ = iConfig.getParameter<bool>("produceJetIds"); jets_ = iConfig.getParameter<edm::InputTag>("jets"); vertexes_ = iConfig.getParameter<edm::InputTag>("vertexes"); jetids_ = iConfig.getParameter<edm::InputTag>("jetids"); inputIsCorrected_ = iConfig.getParameter<bool>("inputIsCorrected"); applyJec_ = iConfig.getParameter<bool>("applyJec"); jec_ = iConfig.getParameter<std::string>("jec"); rho_ = iConfig.getParameter<edm::InputTag>("rho"); residualsFromTxt_ = iConfig.getParameter<bool>("residualsFromTxt"); residualsTxt_ = iConfig.getParameter<edm::FileInPath>("residualsTxt"); std::vector<edm::ParameterSet> algos = iConfig.getParameter<std::vector<edm::ParameterSet> >("algos"); jecCor_ = 0; if( ! runMvas_ ) assert( algos.size() == 1 ); if( produceJetIds_ ) { produces<edm::ValueMap<StoredPileupJetIdentifier> > (""); } for(std::vector<edm::ParameterSet>::iterator it=algos.begin(); it!=algos.end(); ++it) { std::string label = it->getParameter<std::string>("label"); algos_.push_back( std::make_pair(label,new PileupJetIdAlgo(*it)) ); if( runMvas_ ) { produces<edm::ValueMap<float> > (label+"Discriminant"); produces<edm::ValueMap<int> > (label+"Id"); } } }
PileupJetIdProducer::~PileupJetIdProducer | ( | ) |
Definition at line 114 of file PileupJetIdProducer.cc.
{ }
void PileupJetIdProducer::beginJob | ( | void | ) | [private, virtual] |
void PileupJetIdProducer::beginLuminosityBlock | ( | edm::LuminosityBlock & | , |
edm::EventSetup const & | |||
) | [private, virtual] |
void PileupJetIdProducer::beginRun | ( | edm::Run & | , |
edm::EventSetup const & | |||
) | [private, virtual] |
void PileupJetIdProducer::endJob | ( | void | ) | [private, virtual] |
void PileupJetIdProducer::endLuminosityBlock | ( | edm::LuminosityBlock & | , |
edm::EventSetup const & | |||
) | [private, virtual] |
void PileupJetIdProducer::endRun | ( | edm::Run & | , |
edm::EventSetup const & | |||
) | [private, virtual] |
void PileupJetIdProducer::fillDescriptions | ( | edm::ConfigurationDescriptions & | descriptions | ) | [static] |
Reimplemented from edm::EDProducer.
Definition at line 308 of file PileupJetIdProducer.cc.
References edm::ConfigurationDescriptions::addDefault(), and edm::ParameterSetDescription::setUnknown().
{ //The following says we do not know what parameters are allowed so do no validation // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); }
void PileupJetIdProducer::initJetEnergyCorrector | ( | const edm::EventSetup & | iSetup, |
bool | isData | ||
) | [private] |
Definition at line 319 of file PileupJetIdProducer.cc.
References edm::FileInPath::fullPath(), edm::EventSetup::get(), jec_, jecCor_, jetCorPars_, Parameters::parameters, residualsFromTxt_, and residualsTxt_.
Referenced by produce().
{ //jet energy correction levels to apply on raw jet std::vector<std::string> jecLevels; jecLevels.push_back("L1FastJet"); jecLevels.push_back("L2Relative"); jecLevels.push_back("L3Absolute"); if(isData && ! residualsFromTxt_ ) jecLevels.push_back("L2L3Residual"); //check the corrector parameters needed according to the correction levels edm::ESHandle<JetCorrectorParametersCollection> parameters; iSetup.get<JetCorrectionsRecord>().get(jec_,parameters); for(std::vector<std::string>::const_iterator ll = jecLevels.begin(); ll != jecLevels.end(); ++ll) { const JetCorrectorParameters& ip = (*parameters)[*ll]; jetCorPars_.push_back(ip); } if( isData && residualsFromTxt_ ) { jetCorPars_.push_back(JetCorrectorParameters(residualsTxt_.fullPath())); } //instantiate the jet corrector jecCor_ = new FactorizedJetCorrector(jetCorPars_); }
void PileupJetIdProducer::produce | ( | edm::Event & | iEvent, |
const edm::EventSetup & | iSetup | ||
) | [private, virtual] |
Implements edm::EDProducer.
Definition at line 121 of file PileupJetIdProducer.cc.
References algos_, applyJec_, reco::CompositePtrCandidate::clone(), PileupJetIdAlgo::computeIdVariables(), PileupJetIdAlgo::computeMva(), reco::LeafCandidate::eta(), edm::helper::Filler< Map >::fill(), edm::Event::getByLabel(), FactorizedJetCorrector::getCorrection(), i, initJetEnergyCorrector(), inputIsCorrected_, edm::helper::Filler< Map >::insert(), edm::EventBase::isRealData(), patTestJEC_cfi::jec, jecCor_, metsig::jet, reco::Jet::jetArea(), jetids_, analyzePatCleaning_cfg::jets, jets_, reco::LeafCandidate::phi(), produceJetIds_, reco::LeafCandidate::pt(), edm::Event::put(), dt_dqm_sourceclient_common_cff::reco, rho, rho_, runMvas_, pileupReCalc_HLTpaths::scale, reco::Jet::scaleEnergy(), PileupJetIdAlgo::set(), FactorizedJetCorrector::setJetA(), FactorizedJetCorrector::setJetEta(), FactorizedJetCorrector::setJetPt(), FactorizedJetCorrector::setRho(), and vertexes_.
{ using namespace edm; using namespace std; using namespace reco; // Input jets Handle<View<Jet> > jetHandle; iEvent.getByLabel(jets_,jetHandle); const View<Jet> & jets = *jetHandle; // vertexes Handle<VertexCollection> vertexHandle; if( produceJetIds_ ) { iEvent.getByLabel(vertexes_, vertexHandle); } const VertexCollection & vertexes = *(vertexHandle.product()); // input variables Handle<ValueMap<StoredPileupJetIdentifier> > vmap; if( ! produceJetIds_ ) { iEvent.getByLabel(jetids_, vmap); } // rho edm::Handle< double > rhoH; double rho = 0.; // products vector<StoredPileupJetIdentifier> ids; map<string, vector<float> > mvas; map<string, vector<int> > idflags; VertexCollection::const_iterator vtx; if( produceJetIds_ ) { // require basic quality cuts on the vertexes vtx = vertexes.begin(); while( vtx != vertexes.end() && ( vtx->isFake() || vtx->ndof() < 4 ) ) { ++vtx; } if( vtx == vertexes.end() ) { vtx = vertexes.begin(); } } // Loop over input jets for ( unsigned int i=0; i<jets.size(); ++i ) { // Pick the first algo to compute the input variables vector<pair<string,PileupJetIdAlgo *> >::iterator algoi = algos_.begin(); PileupJetIdAlgo * ialgo = algoi->second; const Jet & jet = jets.at(i); //const pat::Jet * patjet = dynamic_cast<const pat::Jet *>(&jet); //bool ispat = patjet != 0; // Get jet energy correction float jec = 0.; if( applyJec_ ) { // If haven't done it get rho from the event if( rho == 0. ) { iEvent.getByLabel(rho_,rhoH); rho = *rhoH; } // jet corrector if( jecCor_ == 0 ) { initJetEnergyCorrector( iSetup, iEvent.isRealData() ); } //if( ispat ) { // jecCor_->setJetPt(patjet->correctedJet(0).pt()); //} else { jecCor_->setJetPt(jet.pt()); //} jecCor_->setJetEta(jet.eta()); jecCor_->setJetA(jet.jetArea()); jecCor_->setRho(rho); jec = jecCor_->getCorrection(); } // If it was requested or the input is an uncorrected jet apply the JEC bool applyJec = applyJec_ || !inputIsCorrected_; //( ! ispat && ! inputIsCorrected_ ); reco::Jet * corrJet = 0; if( applyJec ) { float scale = jec; //if( ispat ) { // corrJet = new pat::Jet(patjet->correctedJet(0)) ; //} else { corrJet = dynamic_cast<reco::Jet *>( jet.clone() ); //} corrJet->scaleEnergy(scale); } const reco::Jet * theJet = ( applyJec ? corrJet : &jet ); PileupJetIdentifier puIdentifier; if( produceJetIds_ ) { // Compute the input variables puIdentifier = ialgo->computeIdVariables(theJet, jec, &(*vtx), vertexes, runMvas_); ids.push_back( puIdentifier ); } else { // Or read it from the value map puIdentifier = (*vmap)[jets.refAt(i)]; puIdentifier.jetPt(theJet->pt()); // make sure JEC is applied when computing the MVA puIdentifier.jetEta(theJet->eta()); puIdentifier.jetPhi(theJet->phi()); ialgo->set(puIdentifier); puIdentifier = ialgo->computeMva(); } if( runMvas_ ) { // Compute the MVA and WP mvas[algoi->first].push_back( puIdentifier.mva() ); idflags[algoi->first].push_back( puIdentifier.idFlag() ); for( ++algoi; algoi!=algos_.end(); ++algoi) { ialgo = algoi->second; ialgo->set(puIdentifier); PileupJetIdentifier id = ialgo->computeMva(); mvas[algoi->first].push_back( id.mva() ); idflags[algoi->first].push_back( id.idFlag() ); } } // cleanup if( corrJet ) { delete corrJet; } } // Produce the output value maps if( runMvas_ ) { for(vector<pair<string,PileupJetIdAlgo *> >::iterator ialgo = algos_.begin(); ialgo!=algos_.end(); ++ialgo) { // MVA vector<float> & mva = mvas[ialgo->first]; auto_ptr<ValueMap<float> > mvaout(new ValueMap<float>()); ValueMap<float>::Filler mvafiller(*mvaout); mvafiller.insert(jetHandle,mva.begin(),mva.end()); mvafiller.fill(); iEvent.put(mvaout,ialgo->first+"Discriminant"); // WP vector<int> & idflag = idflags[ialgo->first]; auto_ptr<ValueMap<int> > idflagout(new ValueMap<int>()); ValueMap<int>::Filler idflagfiller(*idflagout); idflagfiller.insert(jetHandle,idflag.begin(),idflag.end()); idflagfiller.fill(); iEvent.put(idflagout,ialgo->first+"Id"); } } // input variables if( produceJetIds_ ) { assert( jetHandle->size() == ids.size() ); auto_ptr<ValueMap<StoredPileupJetIdentifier> > idsout(new ValueMap<StoredPileupJetIdentifier>()); ValueMap<StoredPileupJetIdentifier>::Filler idsfiller(*idsout); idsfiller.insert(jetHandle,ids.begin(),ids.end()); idsfiller.fill(); iEvent.put(idsout); } }
std::vector<std::pair<std::string, PileupJetIdAlgo *> > PileupJetIdProducer::algos_ [private] |
Definition at line 70 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
bool PileupJetIdProducer::applyJec_ [private] |
Definition at line 69 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
bool PileupJetIdProducer::inputIsCorrected_ [private] |
Definition at line 69 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
std::string PileupJetIdProducer::jec_ [private] |
Definition at line 68 of file PileupJetIdProducer.cc.
Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().
Definition at line 74 of file PileupJetIdProducer.cc.
Referenced by initJetEnergyCorrector(), PileupJetIdProducer(), and produce().
std::vector<JetCorrectorParameters> PileupJetIdProducer::jetCorPars_ [private] |
Definition at line 75 of file PileupJetIdProducer.cc.
Referenced by initJetEnergyCorrector().
edm::InputTag PileupJetIdProducer::jetids_ [private] |
Definition at line 67 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
edm::InputTag PileupJetIdProducer::jets_ [private] |
Definition at line 67 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
bool PileupJetIdProducer::produceJetIds_ [private] |
Definition at line 69 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
bool PileupJetIdProducer::residualsFromTxt_ [private] |
Definition at line 72 of file PileupJetIdProducer.cc.
Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().
Definition at line 73 of file PileupJetIdProducer.cc.
Referenced by initJetEnergyCorrector(), and PileupJetIdProducer().
edm::InputTag PileupJetIdProducer::rho_ [private] |
Definition at line 67 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
bool PileupJetIdProducer::runMvas_ [private] |
Definition at line 69 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().
edm::InputTag PileupJetIdProducer::vertexes_ [private] |
Definition at line 67 of file PileupJetIdProducer.cc.
Referenced by PileupJetIdProducer(), and produce().