Skip to content

Commit

Permalink
Merge pull request #23446 from arizzi/nanoAODrebasedMasterWithoutData…
Browse files Browse the repository at this point in the history
…10XY

NanoAOD update 10XY version (master version of #23445)
  • Loading branch information
cmsbuild authored Jul 9, 2018
2 parents 4d160db + 355f35c commit 2fd4547
Show file tree
Hide file tree
Showing 15 changed files with 1,350 additions and 121 deletions.
123 changes: 77 additions & 46 deletions PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class BJetEnergyRegressionMVA : public BaseMVAValueMapProducer<pat::Jet> {
explicit BJetEnergyRegressionMVA(const edm::ParameterSet &iConfig):
BaseMVAValueMapProducer<pat::Jet>(iConfig),
pvsrc_(edm::stream::EDProducer<>::consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvsrc"))),
svsrc_(edm::stream::EDProducer<>::consumes<edm::View<reco::VertexCompositePtrCandidate>> (iConfig.getParameter<edm::InputTag>("svsrc")))
svsrc_(edm::stream::EDProducer<>::consumes<edm::View<reco::VertexCompositePtrCandidate>> (iConfig.getParameter<edm::InputTag>("svsrc"))),
rhosrc_(edm::stream::EDProducer<>::consumes<double> (iConfig.getParameter<edm::InputTag>("rhosrc")))

{

Expand All @@ -42,65 +43,95 @@ class BJetEnergyRegressionMVA : public BaseMVAValueMapProducer<pat::Jet> {
void readAdditionalCollections(edm::Event&iEvent, const edm::EventSetup&) override {
iEvent.getByToken(pvsrc_, pvs_);
iEvent.getByToken(svsrc_, svs_);
}

void fillAdditionalVariables(const pat::Jet&j) override {
this->setValue("nPVs",pvs_->size());
BaseMVAValueMapProducer<pat::Jet>::setValue("Jet_leptonPtRel",0);

if(!j.overlaps("muons").empty()) {
const auto *lep=dynamic_cast<const pat::Muon *>(&*j.overlaps("muons")[0]);
if(lep!=nullptr) {BaseMVAValueMapProducer<pat::Jet>::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));}
}
else if(!j.overlaps("electrons").empty()) {
const auto *lep=dynamic_cast<const pat::Electron *>(&*j.overlaps("electrons")[0]);
if(lep!=nullptr) {BaseMVAValueMapProducer<pat::Jet>::setValue("Jet_leptonPtRel",lep->userFloat("ptRel"));}
}

float ptMax=0;
for(const auto & d : j.daughterPtrVector()){if(d->pt()>ptMax) ptMax=d->pt();}
BaseMVAValueMapProducer<pat::Jet>::setValue("Jet_leadTrackPt",ptMax);

//Fill vertex properties
VertexDistance3D vdist;
float maxFoundSignificance=0;
const auto & pv = (*pvs_)[0];
this->setValue("Jet_vtxPt",0);
this->setValue("Jet_vtxMass",0);
this->setValue("Jet_vtx3dL",0);
this->setValue("Jet_vtx3deL",0);
this->setValue("Jet_vtxNtrk",0);

for(const auto &sv: *svs_){
GlobalVector flightDir(sv.vertex().x() - pv.x(), sv.vertex().y() - pv.y(),sv.vertex().z() - pv.z());
GlobalVector jetDir(j.px(),j.py(),j.pz());
if( Geom::deltaR2( flightDir, jetDir ) < 0.09 ){
Measurement1D dl= vdist.distance(pv,VertexState(RecoVertex::convertPos(sv.position()),RecoVertex::convertError(sv.error())));
if(dl.significance() > maxFoundSignificance){
maxFoundSignificance=dl.significance();
this->setValue("Jet_vtxPt",sv.pt());
this->setValue("Jet_vtxMass",sv.p4().M());
this->setValue("Jet_vtx3dL",dl.value());
this->setValue("Jet_vtx3deL",dl.error());
this->setValue("Jet_vtxNtrk",sv.numberOfSourceCandidatePtrs());
}
}
}
iEvent.getByToken(rhosrc_,rho_);

}

void fillAdditionalVariables(const pat::Jet&j) override {

this->setValue("nPVs",pvs_->size());
this->setValue("rho",*(rho_.product()));


float cone_boundaries[] = { 0.05, 0.1, 0.2, 0.3,0.4 };
size_t ncone_boundaries = sizeof(cone_boundaries)/sizeof(float);
std::vector<float> emFractionEnergyRings(ncone_boundaries+1);
std::vector<float> chFractionEnergyRings(ncone_boundaries+1);
std::vector<float> neFractionEnergyRings(ncone_boundaries+1);
std::vector<float> muFractionEnergyRings(ncone_boundaries+1);
float jetRawEnergy=j.p4().E()*j.jecFactor("Uncorrected");
int numDaughtersPt03=0;
for (unsigned int ijcone = 0; ijcone<ncone_boundaries; ijcone++){
emFractionEnergyRings[ijcone] = 0;
muFractionEnergyRings[ijcone] = 0;
chFractionEnergyRings[ijcone] = 0;
neFractionEnergyRings[ijcone] = 0;
}
for(const auto & d : j.daughterPtrVector()){
float candDr = Geom::deltaR(d->p4(),j.p4());
size_t icone = std::lower_bound(&cone_boundaries[0],&cone_boundaries[ncone_boundaries],candDr) - &cone_boundaries[0];
float candEnergy = d->energy()/jetRawEnergy;
int pdgid = abs(d->pdgId()) ;
if( pdgid == 22 || pdgid == 11 ) {
emFractionEnergyRings[icone] += candEnergy;
} else if ( pdgid == 13 ) {
muFractionEnergyRings[icone] += candEnergy;
} else if ( d->charge() != 0 ) {
chFractionEnergyRings[icone] += candEnergy;
} else {
neFractionEnergyRings[icone] += candEnergy;
}
if(d->pt()>0.3) numDaughtersPt03+=1;
} // end of jet daughters loop

this->setValue("Jet_energyRing_dR0_em_Jet_rawEnergy", emFractionEnergyRings[0]);
this->setValue("Jet_energyRing_dR1_em_Jet_rawEnergy", emFractionEnergyRings[1]);
this->setValue("Jet_energyRing_dR2_em_Jet_rawEnergy", emFractionEnergyRings[2]);
this->setValue("Jet_energyRing_dR3_em_Jet_rawEnergy", emFractionEnergyRings[3]);
this->setValue("Jet_energyRing_dR4_em_Jet_rawEnergy", emFractionEnergyRings[4]);
// this->setValue("Jet_energyRing_dR5_em_Jet_rawEnergy", emFractionEnergyRings[5]);

this->setValue("Jet_energyRing_dR0_ch_Jet_rawEnergy", chFractionEnergyRings[0]);
this->setValue("Jet_energyRing_dR1_ch_Jet_rawEnergy", chFractionEnergyRings[1]);
this->setValue("Jet_energyRing_dR2_ch_Jet_rawEnergy", chFractionEnergyRings[2]);
this->setValue("Jet_energyRing_dR3_ch_Jet_rawEnergy", chFractionEnergyRings[3]);
this->setValue("Jet_energyRing_dR4_ch_Jet_rawEnergy", chFractionEnergyRings[4]);
// this->setValue("Jet_energyRing_dR5_ch_Jet_rawEnergy", chFractionEnergyRings[5]);

this->setValue("Jet_energyRing_dR0_mu_Jet_rawEnergy", muFractionEnergyRings[0]);
this->setValue("Jet_energyRing_dR1_mu_Jet_rawEnergy", muFractionEnergyRings[1]);
this->setValue("Jet_energyRing_dR2_mu_Jet_rawEnergy", muFractionEnergyRings[2]);
this->setValue("Jet_energyRing_dR3_mu_Jet_rawEnergy", muFractionEnergyRings[3]);
this->setValue("Jet_energyRing_dR4_mu_Jet_rawEnergy", muFractionEnergyRings[4]);
// this->setValue("Jet_energyRing_dR5_mu_Jet_rawEnergy", muFractionEnergyRings[5]);

this->setValue("Jet_energyRing_dR0_neut_Jet_rawEnergy", neFractionEnergyRings[0]);
this->setValue("Jet_energyRing_dR1_neut_Jet_rawEnergy", neFractionEnergyRings[1]);
this->setValue("Jet_energyRing_dR2_neut_Jet_rawEnergy", neFractionEnergyRings[2]);
this->setValue("Jet_energyRing_dR3_neut_Jet_rawEnergy", neFractionEnergyRings[3]);
this->setValue("Jet_energyRing_dR4_neut_Jet_rawEnergy", neFractionEnergyRings[4]);
// this->setValue("Jet_energyRing_dR5_neut_Jet_rawEnergy", neFractionEnergyRings[5]);

this->setValue("Jet_numDaughters_pt03",numDaughtersPt03);

}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc = BaseMVAValueMapProducer<pat::Jet>::getDescription();
desc.add<edm::InputTag>("pvsrc")->setComment("primary vertices input collection");
desc.add<edm::InputTag>("svsrc")->setComment("secondary vertices input collection");
desc.add<edm::InputTag>("rhosrc")->setComment("rho input collection");
descriptions.add("BJetEnergyRegressionMVA",desc);
}

private:
const edm::EDGetTokenT<std::vector<reco::Vertex>> pvsrc_;
edm::Handle<std::vector<reco::Vertex>> pvs_;
const edm::EDGetTokenT<edm::View<reco::VertexCompositePtrCandidate> > svsrc_;
const edm::EDGetTokenT<edm::View<reco::VertexCompositePtrCandidate> > svsrc_;
edm::Handle<edm::View<reco::VertexCompositePtrCandidate>> svs_;
edm::EDGetTokenT<double> rhosrc_;
edm::Handle<double> rho_;


};

Expand Down
Loading

0 comments on commit 2fd4547

Please sign in to comment.