Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of the first version of muon DPG nanoAOD ntuples #38226

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions DPGAnalysis/MuonTools/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ServiceRegistry"/>
<use name="FWCore/ParameterSet"/>
<use name="CommonTools/Utils"/>
<use name="CommonTools/UtilAlgos"/>
<use name="DataFormats/NanoAOD"/>
<use name="PhysicsTools/NanoAOD"/>
<use name="CalibMuon/DTDigiSync"/>
<use name="Geometry/Records"/>
<use name="Utilities/General"/>
<use name="TrackingTools/GeomPropagators"/>
<use name="DataFormats/Common"/>
<use name="DataFormats/DTDigi"/>
<use name="DataFormats/DTRecHit"/>
<use name="DataFormats/L1DTTrackFinder"/>
<use name="Geometry/GEMGeometry"/>
<use name="Geometry/RPCGeometry"/>
<use name="DataFormats/GEMDigi"/>
<use name="DataFormats/GEMRecHit"/>
<use name="DataFormats/CSCRecHit"/>
<use name="DataFormats/CSCDigi"/>
<use name="HLTrigger/HLTcore"/>
<use name="DataFormats/MuonReco"/>
<use name="TrackingTools/TransientTrack"/>
<use name="TrackingTools/Records"/>
<use name="RecoMuon/TrackingTools"/>
<use name="DataFormats/RPCDigi"/>
<use name="DataFormats/RPCRecHit"/>
<use name="boost"/>

<export>
<lib name="1"/>
</export>

73 changes: 73 additions & 0 deletions DPGAnalysis/MuonTools/interface/MuBaseFlatTableProducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef Mu_MuBaseFlatTableProducer_h
#define Mu_MuBaseFlatTableProducer_h

/** \class MuBaseFlatTableProducer MuBaseFlatTableProducer.h DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h
*
* Helper class defining the generic interface of a FlatTableProducer
*
* \author C. Battilana (INFN BO)
*
*
*/

#include "DPGAnalysis/MuonTools/interface/MuNtupleUtils.h"

#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "DataFormats/NanoAOD/interface/FlatTable.h"

#include <string>

class MuBaseFlatTableProducer : public edm::stream::EDProducer<> {
public:
/// Constructor
explicit MuBaseFlatTableProducer(const edm::ParameterSet &);

/// Configure event setup for each run
void beginRun(const edm::Run &run, const edm::EventSetup &config) final;

/// Fill ntuples event by event
void produce(edm::Event &, const edm::EventSetup &) final;

/// Empty, needed by interface
void endRun(const edm::Run &, const edm::EventSetup &) final {}

protected:
/// The label name of the FlatTableProducer
std::string m_name;

/// Get info from the ES by run
virtual void getFromES(const edm::Run &run, const edm::EventSetup &environment) {}

/// Get info from the ES for a given event
virtual void getFromES(const edm::EventSetup &environment) {}

/// Fill ntuple
virtual void fillTable(edm::Event &ev) = 0;

/// Definition of default values for int variables
static constexpr int DEFAULT_INT_VAL{-999};

/// Definition of default values for int8 variables
static constexpr int8_t DEFAULT_INT8_VAL{-99};

/// Definition of default values for positive int variables
static constexpr int DEFAULT_INT_VAL_POS{-1};

/// Definition of default values for float variables
static constexpr double DEFAULT_DOUBLE_VAL{-999.0};

/// Definition of default values for positive float variables
static constexpr double DEFAULT_DOUBLE_VAL_POS{-1.0};

template <typename T>
void addColumn(std::unique_ptr<nanoaod::FlatTable> &table,
const std::string name,
const std::vector<T> &vec,
const std::string descr) {
table->template addColumn<T, std::vector<T>>(name, vec, descr);
}
};

#endif
118 changes: 118 additions & 0 deletions DPGAnalysis/MuonTools/interface/MuDigiBaseProducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#ifndef MuonTools_MuDigiBaseProducer_h
#define MuonTools_MuDigiBaseProducer_h

/** \class MuDigiBaseProducer MuDigiBaseProducer.h DPGAnalysis/MuonTools/src/MuDigiBaseProducer.h
*
* Helper class defining the generic interface of a muon digi Producer
*
* \author C. Battilana (INFN BO)
*
*
*/

#include "DataFormats/MuonData/interface/MuonDigiCollection.h"
#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <algorithm>
#include <list>
#include <string>

template <class DETECTOR_T, class DIGI_T>
class MuDigiBaseProducer : public SimpleFlatTableProducerBase<DIGI_T, MuonDigiCollection<DETECTOR_T, DIGI_T>> {
using COLLECTION = MuonDigiCollection<DETECTOR_T, DIGI_T>;

using IntDetVar = FuncVariable<DETECTOR_T, StringObjectFunction<DETECTOR_T>, int>;
using UIntDetVar = FuncVariable<DETECTOR_T, StringObjectFunction<DETECTOR_T>, unsigned int>;
using Int8DetVar = FuncVariable<DETECTOR_T, StringObjectFunction<DETECTOR_T>, int8_t>;
using UInt8DetVar = FuncVariable<DETECTOR_T, StringObjectFunction<DETECTOR_T>, uint8_t>;

std::vector<std::unique_ptr<Variable<DETECTOR_T>>> detIdVars_;

public:
MuDigiBaseProducer(edm::ParameterSet const &params) : SimpleFlatTableProducerBase<DIGI_T, COLLECTION>(params) {
const auto &varCfgs = params.getParameter<edm::ParameterSet>("detIdVariables");
const auto &varNames = varCfgs.getParameterNamesForType<edm::ParameterSet>();

std::transform(varNames.begin(), varNames.end(), std::back_inserter(detIdVars_), [&](const auto &name) {
const edm::ParameterSet &varCfg = varCfgs.getParameter<edm::ParameterSet>(name);
const std::string &type = varCfg.getParameter<std::string>("type");

std::unique_ptr<Variable<DETECTOR_T>> detVarPtr;

if (type == "int") {
detVarPtr = std::move(std::make_unique<IntDetVar>(name, varCfg));
} else if (type == "uint") {
detVarPtr = std::move(std::make_unique<UIntDetVar>(name, varCfg));
} else if (type == "int8") {
detVarPtr = std::move(std::make_unique<Int8DetVar>(name, varCfg));
} else if (type == "uint8") {
detVarPtr = std::move(std::make_unique<UInt8DetVar>(name, varCfg));
} else {
throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + name);
}

return detVarPtr;
});
}

~MuDigiBaseProducer() override {}

static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc = SimpleFlatTableProducerBase<DIGI_T, COLLECTION>::baseDescriptions();

edm::ParameterSetDescription variable;
edm::Comment comType{"the c++ type of the branch in the flat table"};
edm::Comment comPrecision{"the precision with which to store the value in the flat table"};

variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
variable.add<std::string>("doc")->setComment("few words description of the branch content");

variable.ifValue(edm::ParameterDescription<std::string>("type", "int", true, comType),
edm::allowedValues<std::string>("int", "uint", "int8", "uint8"));

edm::ParameterSetDescription variables;

variables.setComment("a parameters set to define all variable taken form detId to fill the flat table");

edm::ParameterWildcard<edm::ParameterSetDescription> variableWildCard{"*", edm::RequireZeroOrMore, true, variable};
variables.addNode(variableWildCard);

desc.add<edm::ParameterSetDescription>("detIdVariables", variables);

descriptions.addWithDefaultLabel(desc);
}

std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
const edm::Handle<COLLECTION> &prod) const override {
std::vector<const DIGI_T *> digis;
std::vector<const DETECTOR_T *> detIds;
std::list<DETECTOR_T> detIdObjs; // CB needed to store DetIds (they are transient)

if (prod.isValid()) {
auto detIdIt = prod->begin();
auto detIdEnd = prod->end();

for (; detIdIt != detIdEnd; ++detIdIt) {
const auto &[detId, range] = (*detIdIt);
detIdObjs.push_back(detId);
std::fill_n(std::back_inserter(detIds), range.second - range.first, &detIdObjs.back());
std::transform(range.first, range.second, std::back_inserter(digis), [](const auto &digi) { return &digi; });
}
}

auto table = std::make_unique<nanoaod::FlatTable>(digis.size(), this->name_, false, this->extension_);

for (const auto &var : this->vars_) {
var->fill(digis, *table);
}

for (const auto &var : detIdVars_) {
var->fill(detIds, *table);
}

return table;
}
};

#endif
Loading