Skip to content

Commit

Permalink
Merge pull request #29 from cms-nanoAOD/nano_94X_fixes
Browse files Browse the repository at this point in the history
PR cms-sw#20626 code review + #22
  • Loading branch information
gpetruc committed Oct 2, 2017
2 parents 1eabc06 + 711bfda commit a8aba11
Show file tree
Hide file tree
Showing 42 changed files with 316 additions and 296 deletions.
2 changes: 0 additions & 2 deletions DataFormats/NanoAOD/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<use name="DataFormats/Common"/>
<use name="DataFormats/StdDictionaries"/>
<use name="boost"/>
<flags LCG_DICT_HEADER="classes.h"/>
<flags LCG_DICT_XML="classes_def.xml"/>
<export>
<lib name="1"/>
</export>
8 changes: 6 additions & 2 deletions DataFormats/NanoAOD/interface/FlatTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include <vector>
#include <string>
#include <boost/range/sub_range.hpp>
#include <FWCore/Utilities/interface/Exception.h>
#include <DataFormats/PatCandidates/interface/libminifloat.h>
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/PatCandidates/interface/libminifloat.h"

namespace nanoaod {

namespace flatTableHelper {
template<typename T> struct MaybeMantissaReduce {
Expand All @@ -21,6 +23,7 @@ namespace flatTableHelper {
inline void bulk(boost::sub_range<std::vector<float>> data) const { if (bits_ > 0) MiniFloatConverter::reduceMantissaToNbitsRounding(bits_, data.begin(), data.end(), data.begin()); }
};
}

class FlatTable {
public:
enum ColumnType { FloatColumn, IntColumn, UInt8Column, BoolColumn }; // We could have other Float types with reduced mantissa, and similar
Expand Down Expand Up @@ -155,5 +158,6 @@ template<> inline std::vector<float> & FlatTable::bigVector<float>() { retur
template<> inline std::vector<int> & FlatTable::bigVector<int>() { return ints_; }
template<> inline std::vector<uint8_t> & FlatTable::bigVector<uint8_t>() { return uint8s_; }

} // nanoaod

#endif
10 changes: 9 additions & 1 deletion DataFormats/NanoAOD/interface/MergeableCounterTable.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef DataFormats_NanoAOD_MergeableCounterTable_h
#define DataFormats_NanoAOD_MergeableCounterTable_h

#include <FWCore/Utilities/interface/Exception.h>
#include "FWCore/Utilities/interface/Exception.h"
#include <vector>
#include <string>

namespace nanoaod {

class MergeableCounterTable {
public:
MergeableCounterTable() {}
Expand All @@ -19,6 +21,8 @@ class MergeableCounterTable {
std::string name, doc;
T value;
void operator+=(const SingleColumn<T> & other) {
//// if one arrives here from tryMerge the checks are already done in the compatible() function before.
//// you may however want to enable these and remove the 'return false' in tryMerge in order to see what's incompatible between the tables.
//if (name != other.name) throw cms::Exception("LogicError", "Trying to merge "+name+" with "+other.name+"\n");
value += other.value;
}
Expand All @@ -38,6 +42,8 @@ class MergeableCounterTable {
std::string name, doc;
std::vector<T> values;
void operator+=(const VectorColumn<T> & other) {
//// if one arrives here from tryMerge the checks are already done in the compatible() function before.
//// you may however want to enable these and remove the 'return false' in tryMerge in order to see what's incompatible between the tables.
//if (name != other.name) throw cms::Exception("LogicError", "Trying to merge "+name+" with "+other.name+"\n");
//if (values.size() != other.values.size()) throw cms::Exception("LogicError", "Trying to merge "+name+" with different number of values!\n");
for (unsigned int i = 0, n = values.size(); i < n; ++i) {
Expand Down Expand Up @@ -100,4 +106,6 @@ class MergeableCounterTable {
}
};

} // namespace nanoaod

#endif
4 changes: 4 additions & 0 deletions DataFormats/NanoAOD/interface/UniqueString.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <string>

namespace nanoaod {

class UniqueString {
public:
UniqueString() {}
Expand All @@ -15,4 +17,6 @@ class UniqueString {
std::string str_;
};

} // namespace nanoaod

#endif
4 changes: 2 additions & 2 deletions DataFormats/NanoAOD/src/FlatTable.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <DataFormats/NanoAOD/interface/FlatTable.h>
#include "DataFormats/NanoAOD/interface/FlatTable.h"

int FlatTable::columnIndex(const std::string & name) const {
int nanoaod::FlatTable::columnIndex(const std::string & name) const {
for (unsigned int i = 0, n = columns_.size(); i < n; ++i) {
if (columns_[i].name == name) return i;
}
Expand Down
13 changes: 7 additions & 6 deletions DataFormats/NanoAOD/src/classes.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "Rtypes.h"

#include <DataFormats/NanoAOD/interface/FlatTable.h>
#include <DataFormats/NanoAOD/interface/MergeableCounterTable.h>
#include <DataFormats/NanoAOD/interface/UniqueString.h>
#include "DataFormats/NanoAOD/interface/FlatTable.h"
#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h"
#include "DataFormats/NanoAOD/interface/UniqueString.h"
#include "DataFormats/Common/interface/Wrapper.h"

namespace DataFormats_NanoAOD {
struct dictionary {
edm::Wrapper<FlatTable> w_table;
edm::Wrapper<MergeableCounterTable> w_mtable;
edm::Wrapper<UniqueString> w_ustr;
nanoaod::FlatTable table;
edm::Wrapper<nanoaod::FlatTable> w_table;
edm::Wrapper<nanoaod::MergeableCounterTable> w_mtable;
edm::Wrapper<nanoaod::UniqueString> w_ustr;
};
}
48 changes: 24 additions & 24 deletions DataFormats/NanoAOD/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<lcgdict>
<class name="FlatTable::Column" ClassVersion="3">
<version ClassVersion="3" checksum="3947803302"/>
<class name="nanoaod::FlatTable::Column" ClassVersion="3">
<version ClassVersion="3" checksum="3066258528"/>
</class>
<class name="std::vector<FlatTable::Column>" />
<class name="FlatTable" ClassVersion="3">
<version ClassVersion="3" checksum="3559888950"/>
<class name="std::vector<nanoaod::FlatTable::Column>" />
<class name="nanoaod::FlatTable" ClassVersion="3">
<version ClassVersion="3" checksum="2443023556"/>
</class>
<class name="edm::Wrapper<FlatTable>" />
<class name="edm::Wrapper<nanoaod::FlatTable>" />

<class name="MergeableCounterTable::FloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="2459898836"/>
<class name="nanoaod::MergeableCounterTable::FloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="828208870"/>
</class>
<class name="MergeableCounterTable::IntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="213915508"/>
<class name="nanoaod::MergeableCounterTable::IntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="1191014438"/>
</class>
<class name="MergeableCounterTable::VFloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="3802388249"/>
<class name="nanoaod::MergeableCounterTable::VFloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="719259663"/>
</class>
<class name="MergeableCounterTable::VIntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="3160379289"/>
<class name="nanoaod::MergeableCounterTable::VIntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="2535066991"/>
</class>
<class name="std::vector<MergeableCounterTable::FloatColumn>" />
<class name="std::vector<MergeableCounterTable::VFloatColumn>" />
<class name="std::vector<MergeableCounterTable::IntColumn>" />
<class name="std::vector<MergeableCounterTable::VIntColumn>" />
<class name="MergeableCounterTable" ClassVersion="3">
<version ClassVersion="3" checksum="1055793220"/>
<class name="std::vector<nanoaod::MergeableCounterTable::FloatColumn>" />
<class name="std::vector<nanoaod::MergeableCounterTable::VFloatColumn>" />
<class name="std::vector<nanoaod::MergeableCounterTable::IntColumn>" />
<class name="std::vector<nanoaod::MergeableCounterTable::VIntColumn>" />
<class name="nanoaod::MergeableCounterTable" ClassVersion="3">
<version ClassVersion="3" checksum="677965884"/>
</class>
<class name="edm::Wrapper<MergeableCounterTable>" />
<class name="UniqueString" ClassVersion="3">
<version ClassVersion="3" checksum="3967771225"/>
<class name="edm::Wrapper<nanoaod::MergeableCounterTable>" />
<class name="nanoaod::UniqueString" ClassVersion="3">
<version ClassVersion="3" checksum="2793726511"/>
</class>
<class name="edm::Wrapper<UniqueString>" />
<class name="edm::Wrapper<nanoaod::UniqueString>" />
</lcgdict>

2 changes: 0 additions & 2 deletions PhysicsTools/NanoAOD/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<use name="DataFormats/Candidate"/>
<use name="DataFormats/NanoAOD"/>
<use name="boost"/>
<flags LCG_DICT_HEADER="classes.h"/>
<flags LCG_DICT_XML="classes_def.xml"/>
<export>
<lib name="1"/>
</export>
2 changes: 1 addition & 1 deletion PhysicsTools/NanoAOD/plugins/BJetEnergyRegressionMVA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h"
#include "RecoVertex/VertexPrimitives/interface/VertexState.h"

#include "PhysicsTools/NanoAOD/plugins/BaseMVAValueMapProducer.h"
#include "PhysicsTools/PatAlgos/plugins/BaseMVAValueMapProducer.h"
#include <vector>

class BJetEnergyRegressionMVA : public BaseMVAValueMapProducer<pat::Jet> {
Expand Down
10 changes: 5 additions & 5 deletions PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {
src_(consumes<reco::CandidateView>(params.getParameter<edm::InputTag>("src"))),
candMap_(consumes<edm::Association<reco::GenParticleCollection>>(params.getParameter<edm::InputTag>("mcMap")))
{
produces<FlatTable>();
produces<nanoaod::FlatTable>();
const std::string & type = params.getParameter<std::string>("objType");
if (type == "Muon") type_ = MMuon;
else if (type == "Electron") type_ = MElectron;
Expand Down Expand Up @@ -53,7 +53,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {
iEvent.getByToken(src_, cands);
unsigned int ncand = cands->size();

auto tab = std::make_unique<FlatTable>(ncand, objName_, false, true);
auto tab = std::make_unique<nanoaod::FlatTable>(ncand, objName_, false, true);

edm::Handle<edm::Association<reco::GenParticleCollection>> map;
iEvent.getByToken(candMap_, map);
Expand Down Expand Up @@ -101,8 +101,8 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {
};
}

tab->addColumn<int>(branchName_+"Idx", key, "Index into genParticle list for "+doc_, FlatTable::IntColumn);
tab->addColumn<uint8_t>(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, FlatTable::UInt8Column);
tab->addColumn<int>(branchName_+"Idx", key, "Index into genParticle list for "+doc_, nanoaod::FlatTable::IntColumn);
tab->addColumn<uint8_t>(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, nanoaod::FlatTable::UInt8Column);

iEvent.put(std::move(tab));
}
Expand All @@ -127,7 +127,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::string>("objName")->setComment("name of the FlatTable to extend with this table");
desc.add<std::string>("objName")->setComment("name of the nanoaod::FlatTable to extend with this table");
desc.add<std::string>("branchName")->setComment("name of the column to write (the final branch in the nanoaod will be <objName>_<branchName>Idx and <objName>_<branchName>Flav");
desc.add<std::string>("docString")->setComment("documentation to forward to the output");
desc.add<edm::InputTag>("src")->setComment("physics object collection for the reconstructed objects (e.g. leptons)");
Expand Down
4 changes: 2 additions & 2 deletions PhysicsTools/NanoAOD/plugins/EGMEnergyVarProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ EGMEnergyVarProducer<T>::produce(edm::StreamID streamID, edm::Event& iEvent, con

std::vector<float> eCorr(nSrcCorr,-1);

for (uint ir = 0; ir<nSrcRaw; ir++){
for (unsigned int ir = 0; ir<nSrcRaw; ir++){
auto egm_raw = srcRaw->ptrAt(ir);
for (uint ic = 0; ic<nSrcCorr; ic++){
for (unsigned int ic = 0; ic<nSrcCorr; ic++){
auto egm_corr = srcCorr->ptrAt(ic);
if(matchByCommonParentSuperClusterRef(*egm_raw,*egm_corr)){
eCorr[ir] = egm_corr->energy()/egm_raw->energy();
Expand Down
44 changes: 22 additions & 22 deletions PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
debug_(params.getUntrackedParameter<bool>("debug",false)), debugRun_(debug_.load()),
hasIssuedWarning_(false)
{
produces<FlatTable>();
produces<FlatTable>("LHEScale");
produces<FlatTable>("LHEPdf");
produces<FlatTable>("LHENamed");
produces<MergeableCounterTable,edm::InRun>();
produces<nanoaod::FlatTable>();
produces<nanoaod::FlatTable>("LHEScale");
produces<nanoaod::FlatTable>("LHEPdf");
produces<nanoaod::FlatTable>("LHENamed");
produces<nanoaod::MergeableCounterTable,edm::InRun>();
if (namedWeightIDs_.size() != namedWeightLabels_.size()) {
throw cms::Exception("Configuration", "Size mismatch between namedWeightIDs & namedWeightLabels");
}
Expand All @@ -138,13 +138,13 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
double weight = genInfo->weight();

// table for gen info, always available
auto out = std::make_unique<FlatTable>(1, "genWeight", true);
auto out = std::make_unique<nanoaod::FlatTable>(1, "genWeight", true);
out->setDoc("generator weight");
out->addColumnValue<float>("", weight, "generator weight", FlatTable::FloatColumn);
out->addColumnValue<float>("", weight, "generator weight", nanoaod::FlatTable::FloatColumn);
iEvent.put(std::move(out));

// tables for LHE weights, may not be filled
std::unique_ptr<FlatTable> lheScaleTab, lhePdfTab, lheNamedTab;
std::unique_ptr<nanoaod::FlatTable> lheScaleTab, lhePdfTab, lheNamedTab;

edm::Handle<LHEEventProduct> lheInfo;
if (iEvent.getByToken(lheTag_, lheInfo)) {
Expand All @@ -156,9 +156,9 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
// minimal book-keeping of weights
counter->incGenOnly(weight);
// make dummy values
lheScaleTab.reset(new FlatTable(1, "LHEScaleWeights", true));
lhePdfTab.reset(new FlatTable(1, "LHEPdfWeights", true));
lheNamedTab.reset(new FlatTable(1, "LHENamedWeights", true));
lheScaleTab.reset(new nanoaod::FlatTable(1, "LHEScaleWeights", true));
lhePdfTab.reset(new nanoaod::FlatTable(1, "LHEPdfWeights", true));
lheNamedTab.reset(new nanoaod::FlatTable(1, "LHENamedWeights", true));
if (!hasIssuedWarning_.exchange(true)) {
edm::LogWarning("LHETablesProducer") << "No LHEEventProduct, so there will be no LHE Tables\n";
}
Expand All @@ -174,9 +174,9 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
const DynamicWeightChoice * weightChoice,
double genWeight,
const LHEEventProduct & lheProd,
std::unique_ptr<FlatTable> & outScale,
std::unique_ptr<FlatTable> & outPdf,
std::unique_ptr<FlatTable> & outNamed ) const
std::unique_ptr<nanoaod::FlatTable> & outScale,
std::unique_ptr<nanoaod::FlatTable> & outPdf,
std::unique_ptr<nanoaod::FlatTable> & outNamed ) const
{
bool lheDebug = debug_.exchange(false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind)

Expand All @@ -199,16 +199,16 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
if (mNamed != namedWeightIDs_.end()) wNamed[mNamed-namedWeightIDs_.begin()] = weight.wgt/w0;
}

outScale.reset(new FlatTable(wScale.size(), "LHEScaleWeight", false));
outScale->addColumn<float>("", wScale, weightChoice->scaleWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_);
outScale.reset(new nanoaod::FlatTable(wScale.size(), "LHEScaleWeight", false));
outScale->addColumn<float>("", wScale, weightChoice->scaleWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);

outPdf.reset(new FlatTable(wPDF.size(), "LHEPdfWeight", false));
outPdf->addColumn<float>("", wPDF, weightChoice->pdfWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_);
outPdf.reset(new nanoaod::FlatTable(wPDF.size(), "LHEPdfWeight", false));
outPdf->addColumn<float>("", wPDF, weightChoice->pdfWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);

outNamed.reset(new FlatTable(1, "LHEWeight", true));
outNamed->addColumnValue<float>("originalXWGTUP", lheProd.originalXWGTUP(), "Nominal event weight in the LHE file", FlatTable::FloatColumn);
outNamed.reset(new nanoaod::FlatTable(1, "LHEWeight", true));
outNamed->addColumnValue<float>("originalXWGTUP", lheProd.originalXWGTUP(), "Nominal event weight in the LHE file", nanoaod::FlatTable::FloatColumn);
for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) {
outNamed->addColumnValue<float>(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", FlatTable::FloatColumn, lheWeightPrecision_);
outNamed->addColumnValue<float>(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
}

counter->incLHE(genWeight, wScale, wPDF, wNamed);
Expand Down Expand Up @@ -355,7 +355,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
}
// write the total to the run
void globalEndRunProduce(edm::Run& iRun, edm::EventSetup const&, Counter const* runCounter) const override {
auto out = std::make_unique<MergeableCounterTable>();
auto out = std::make_unique<nanoaod::MergeableCounterTable>();
out->addInt("genEventCount", "event count", runCounter->num);
out->addFloat("genEventSumw", "sum of gen weights", runCounter->sumw);
out->addFloat("genEventSumw2", "sum of gen (weight^2)", runCounter->sumw2);
Expand Down
Loading

0 comments on commit a8aba11

Please sign in to comment.