Skip to content

Commit

Permalink
style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arizzi committed Jun 7, 2018
1 parent 669a16b commit 8f87b7a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 67 deletions.
72 changes: 36 additions & 36 deletions PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,62 +55,62 @@ class BJetEnergyRegressionMVA : public BaseMVAValueMapProducer<pat::Jet> {

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);
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;
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;
emFractionEnergyRings[icone] += candEnergy;
} else if ( pdgid == 13 ) {
MuFractionEnergyRings[icone] += candEnergy;
muFractionEnergyRings[icone] += candEnergy;
} else if ( d->charge() != 0 ) {
ChFractionEnergyRings[icone] += candEnergy;
chFractionEnergyRings[icone] += candEnergy;
} else {
NeFractionEnergyRings[icone] += candEnergy;
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_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_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_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_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);

Expand Down
18 changes: 6 additions & 12 deletions PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionVarProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "FWCore/Utilities/interface/StreamID.h"


#include "DataFormats/Math/interface/deltaR.h"

#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
#include "DataFormats/PatCandidates/interface/Jet.h"
Expand Down Expand Up @@ -76,16 +78,14 @@ class BJetEnergyRegressionVarProducer : public edm::global::EDProducer<> {
public:
explicit BJetEnergyRegressionVarProducer(const edm::ParameterSet &iConfig):
srcJet_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("src"))),
// srcMu_(consumes<edm::View<pat::Muon>>(iConfig.getParameter<edm::InputTag>("musrc"))),
// srcEle_(consumes<edm::View<pat::Electron>>(iConfig.getParameter<edm::InputTag>("elesrc"))),
srcVtx_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvsrc"))),
srcSV_(consumes<edm::View<reco::VertexCompositePtrCandidate>>(iConfig.getParameter<edm::InputTag>("svsrc"))),
srcGP_(consumes<std::vector<reco::GenParticle>>(iConfig.getParameter<edm::InputTag>("gpsrc")))
{
//un prodotto da copiare
produces<edm::ValueMap<float>>("leptonPtRel");
produces<edm::ValueMap<float>>("leptonPtRatio");
produces<edm::ValueMap<float>>("leptonPtRelInv");//una variabile sbagliata?
produces<edm::ValueMap<float>>("leptonPtRelInv");//wrong variable?
produces<edm::ValueMap<float>>("leptonPtRelv0");
produces<edm::ValueMap<float>>("leptonPtRatiov0");
produces<edm::ValueMap<float>>("leptonPtRelInvv0");//v0 ~ heppy?
Expand Down Expand Up @@ -116,8 +116,6 @@ class BJetEnergyRegressionVarProducer : public edm::global::EDProducer<> {
// ----------member data ---------------------------

edm::EDGetTokenT<edm::View<pat::Jet>> srcJet_;
// edm::EDGetTokenT<edm::View<pat::Electron>> srcEle_;
// edm::EDGetTokenT<edm::View<pat::Muon>> srcMu_;
edm::EDGetTokenT<std::vector<reco::Vertex>> srcVtx_;
edm::EDGetTokenT<edm::View<reco::VertexCompositePtrCandidate>> srcSV_;
edm::EDGetTokenT<std::vector<reco::GenParticle>> srcGP_;
Expand All @@ -143,10 +141,6 @@ BJetEnergyRegressionVarProducer<T>::produce(edm::StreamID streamID, edm::Event&

edm::Handle<edm::View<pat::Jet>> srcJet;
iEvent.getByToken(srcJet_, srcJet);
// edm::Handle<edm::View<pat::Muon>> srcMu;
// iEvent.getByToken(srcMu_, srcMu);
// edm::Handle<edm::View<pat::Electron>> srcEle;
// iEvent.getByToken(srcEle_, srcEle);
edm::Handle<std::vector<reco::Vertex>> srcVtx;
iEvent.getByToken(srcVtx_, srcVtx);
edm::Handle<edm::View<reco::VertexCompositePtrCandidate>> srcSV;
Expand Down Expand Up @@ -186,7 +180,7 @@ BJetEnergyRegressionVarProducer<T>::produce(edm::StreamID streamID, edm::Event&
auto gep4wNu = genp4;
for(const auto & gp : *srcGP){
if((abs(gp.pdgId())==12 || abs(gp.pdgId())==14 || abs(gp.pdgId())==16) && gp.status()==1){
if (Geom::deltaR( genp4, gp.p4() )<0.4) {
if (reco::deltaR( genp4, gp.p4() )<0.4) {
// std::cout<<" from "<<gep4wNu.pt()<<std::endl;
gep4wNu=gep4wNu+gp.p4();
// std::cout<<" to "<<gep4wNu.pt()<<std::endl;
Expand Down Expand Up @@ -227,7 +221,7 @@ BJetEnergyRegressionVarProducer<T>::produce(edm::StreamID streamID, edm::Event&
leptonPtRel_v0[ij] = std::get<1>(res2);
leptonPtRelInv_v0[ij] = std::get<2>(res2);
leptonPdgId[ij] = d->pdgId();
leptonDeltaR[ij]=Geom::deltaR( jet->p4(), d->p4() );
leptonDeltaR[ij]=reco::deltaR( jet->p4(), d->p4() );
leptonPt[ij] = d->pt();
maxLepPt = d->pt();

Expand All @@ -249,7 +243,7 @@ BJetEnergyRegressionVarProducer<T>::produce(edm::StreamID streamID, edm::Event&
for(const auto &sv: *srcSV){
GlobalVector flightDir(sv.vertex().x() - pv.x(), sv.vertex().y() - pv.y(),sv.vertex().z() - pv.z());
GlobalVector jetDir(jet->px(),jet->py(),jet->pz());
if( Geom::deltaR2( flightDir, jetDir ) < 0.09 ){
if( reco::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();
Expand Down
7 changes: 4 additions & 3 deletions PhysicsTools/NanoAOD/plugins/BTagSFProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class BTagSFProducer : public edm::stream::EDProducer<> {
readers.push_back(reader);

// report
std::cout << "Loaded "+discShortNames_[iDisc]+" SFs from weight file "+weightFiles_[iDisc]+" with\noperating point: "+opname+",\nmeasurement type: B="+measurementTypesB_[iDisc]+", C="+measurementTypesC_[iDisc]+", UDSG="+measurementTypesUDSG_[iDisc]+",\nsystematic type: "+sysTypes_[iDisc]+".\n" << std::endl;
edm::LogInfo("BTagSFProducer") << "Loaded "+discShortNames_[iDisc]+" SFs from weight file "+weightFiles_[iDisc]+" with\noperating point: "+opname+",\nmeasurement type: B="+measurementTypesB_[iDisc]+", C="+measurementTypesC_[iDisc]+", UDSG="+measurementTypesUDSG_[iDisc]+",\nsystematic type: "+sysTypes_[iDisc]+".\n" << std::endl;

// find if multiple MiniAOD branches need to be summed up (e.g., DeepCSV b+bb) and separate them using '+' delimiter from config
std::stringstream dName(discNames_[iDisc]);
Expand All @@ -112,7 +112,7 @@ class BTagSFProducer : public edm::stream::EDProducer<> {
inBranchNames.push_back(branches);

// report
std::cout << "Skipped loading BTagCalibration for "+discShortNames_[iDisc]+" as it was marked as unavailable in the configuration file. Event weights will not be stored.\n" << std::endl;
edm::LogWarning("BTagSFProducer") << "Skipped loading BTagCalibration for "+discShortNames_[iDisc]+" as it was marked as unavailable in the configuration file. Event weights will not be stored.\n" << std::endl;
}
}
}
Expand Down Expand Up @@ -215,7 +215,8 @@ BTagSFProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)


if (SF==0.) { // default value of SF is set to 1 in case BTagCalibration returns 0
cout << discShortNames_[iDisc]+" SF not found for jet with pT="+to_string(pt)+", eta="+to_string(eta)+", discValue="+to_string(bdisc)+", flavour="+to_string(flavour) +". Setting SF to 1." << endl;
//no need to log this as could be pretty common, leaving the cout commented in case this is needed by the author for simple debugging
//cout << discShortNames_[iDisc]+" SF not found for jet with pT="+to_string(pt)+", eta="+to_string(eta)+", discValue="+to_string(bdisc)+", flavour="+to_string(flavour) +". Setting SF to 1." << endl;
SF=1.;
}

Expand Down
14 changes: 7 additions & 7 deletions PhysicsTools/NanoAOD/python/jets_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,20 @@
isClassifier = cms.bool(False),
variablesOrder = cms.vstring(["Jet_pt","nPVs","Jet_eta","Jet_mt","Jet_leadTrackPt","Jet_leptonPtRel","Jet_leptonPt","Jet_leptonDeltaR","Jet_neHEF","Jet_neEmEF","Jet_vtxPt","Jet_vtxMass","Jet_vtx3dL","Jet_vtxNtrk","Jet_vtx3deL"]),
variables = cms.PSet(
Jet_pt = cms.string("pt"),
Jet_eta = cms.string("eta"),
Jet_mt = cms.string("mt"),
Jet_pt = cms.string("pt"),
Jet_eta = cms.string("eta"),
Jet_mt = cms.string("mt"),
Jet_leadTrackPt = cms.string("userFloat('leadTrackPt')"),
Jet_vtxNtrk = cms.string("userInt('vtxNtrk')"),
Jet_vtxMass = cms.string("userFloat('vtxMass')"),
Jet_vtx3dL = cms.string("userFloat('vtx3dL')"),
Jet_vtx3deL = cms.string("userFloat('vtx3deL')"),
Jet_vtxPt = cms.string("userFloat('vtxPt')"),
Jet_leptonPtRel = cms.string("userFloat('leptonPtRelv0')"),
Jet_leptonPt = cms.string("?overlaps('muons').size()>0?overlaps('muons')[0].pt():(?overlaps('electrons').size()>0?overlaps('electrons')[0].pt():0)"),
Jet_neHEF = cms.string("neutralHadronEnergy()/energy()"),
Jet_neEmEF = cms.string("neutralEmEnergy()/energy()"),
Jet_leptonDeltaR = cms.string('''?overlaps('muons').size()>0?deltaR(eta,phi,overlaps('muons')[0].eta,overlaps('muons')[0].phi):
Jet_leptonPt = cms.string("?overlaps('muons').size()>0?overlaps('muons')[0].pt():(?overlaps('electrons').size()>0?overlaps('electrons')[0].pt():0)"),
Jet_neHEF = cms.string("neutralHadronEnergy()/energy()"),
Jet_neEmEF = cms.string("neutralEmEnergy()/energy()"),
Jet_leptonDeltaR = cms.string('''?overlaps('muons').size()>0?deltaR(eta,phi,overlaps('muons')[0].eta,overlaps('muons')[0].phi):
(?overlaps('electrons').size()>0?deltaR(eta,phi,overlaps('electrons')[0].eta,overlaps('electrons')[0].phi):
0)'''),
)
Expand Down
2 changes: 0 additions & 2 deletions PhysicsTools/NanoAOD/python/nano_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def nanoAOD_addDeepBTagFor80X(process):
process.additionalendpath = cms.EndPath(patAlgosToolsTask)
return process

from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
def nanoAOD_customizeCommon(process):
run2_miniAOD_80XLegacy.toModify(process, nanoAOD_addDeepBTagFor80X)
return process
Expand All @@ -172,7 +171,6 @@ def nanoAOD_customizeMC(process):
return process

### Era dependent customization
from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
_80x_sequence = nanoSequence.copy()
#remove stuff
_80x_sequence.remove(isoTrackTable)
Expand Down
8 changes: 1 addition & 7 deletions PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class BaseMVAValueMapProducer : public edm::stream::EDProducer<> {
session_ = tensorflow::createSession(graph_, sessionOptions);

} else {
//FIXME: throw config error
throw cms::Exception("ConfigError") << "Only 'TF' and 'TMVA' backends are supported\n";
}
if(tmva_) produces<edm::ValueMap<float>>();
else {
Expand All @@ -106,10 +106,6 @@ class BaseMVAValueMapProducer : public edm::stream::EDProducer<> {
void setValue(const std::string var,float val) {
if(positions_.find(var)!=positions_.end())
values_[positions_[var]]=val;
else {
// edm::LogWarning("MVAUnexpectedVariable") << "Variable not expected: " << var ;
// std::cout << "Variable not expected: " << var << std::endl;
}
}

static edm::ParameterSetDescription getDescription();
Expand Down Expand Up @@ -177,10 +173,8 @@ BaseMVAValueMapProducer<T>::produce(edm::Event& iEvent, const edm::EventSetup& i
std::vector<tensorflow::Tensor> outputs;
std::vector<std::string> names; names.push_back(outputTensorName_);
tensorflow::run(session_, input_tensors, names, &outputs);
// for(size_t k=0;k<output_names_.size();k++) mvaOut[k].push_back(outputs.at(0).matrix<float>()(0, k));
std::vector<float> tmpOut;
for(int k=0;k<outputs.at(0).matrix<float>().dimension(1);k++) tmpOut.push_back(outputs.at(0).matrix<float>()(0, k));
//StringObjectFunction<std::vector<float>> ss("at(0)");
for(size_t k=0;k<output_names_.size();k++) mvaOut[k].push_back(output_formulas_[k](tmpOut));

}
Expand Down

0 comments on commit 8f87b7a

Please sign in to comment.