40 #include <Math/VectorUtil.h>
153 : isMC_(iConfig.getParameter<bool>(
"isMC")),
154 deltaR_(iConfig.getParameter<double>(
"deltaR")),
155 ptThreshold_(iConfig.getParameter<double>(
"ptThreshold")),
156 eleMapTags_(iConfig.getParameter<std::
vector<std::
string>>(
"eleMVAs")),
157 eleMapBranchNames_(iConfig.getParameter<std::
vector<std::
string>>(
"eleMVALabels")),
158 nEleMaps_(eleMapBranchNames_.
size()),
159 valMapTags_(iConfig.getParameter<std::
vector<std::
string>>(
"eleMVAValMaps")),
160 valMapBranchNames_(iConfig.getParameter<std::
vector<std::
string>>(
"eleMVAValMapLabels")),
161 nValMaps_(valMapBranchNames_.
size()),
162 mvaCatTags_(iConfig.getParameter<std::
vector<std::
string>>(
"eleMVACats")),
163 mvaCatBranchNames_(iConfig.getParameter<std::
vector<std::
string>>(
"eleMVACatLabels")),
164 nCats_(mvaCatBranchNames_.
size()),
165 src_(consumes<edm::
View<
reco::GsfElectron>>(iConfig.getParameter<edm::
InputTag>(
"src"))),
166 vertices_(consumes<std::
vector<
reco::Vertex>>(iConfig.getParameter<edm::
InputTag>(
"vertices"))),
172 mvaPasses_(nEleMaps_),
173 mvaValues_(nValMaps_),
175 variableHelper_(consumesCollector()),
176 mvaVarMngr_(
iConfig.getParameter<
std::string>(
"variableDefinition"), MVAVariableHelper::indexMap()),
177 nVars_(mvaVarMngr_.getNVars()),
179 doEnergyMatrix_(
iConfig.getParameter<
bool>(
"doEnergyMatrix")),
180 energyMatrixSize_(
iConfig.getParameter<
int>(
"energyMatrixSize")) {
182 for (
auto const&
tag : eleMapTags_) {
186 for (
auto const&
tag : valMapTags_) {
190 for (
auto const&
tag : mvaCatTags_) {
197 tree_ = fs->
make<TTree>(
"tree",
"tree");
199 tree_->Branch(
"nEvent", &nEvent_);
200 tree_->Branch(
"nRun", &nRun_);
201 tree_->Branch(
"nLumi", &nLumi_);
203 tree_->Branch(
"genNpu", &genNpu_);
204 tree_->Branch(
"vtxN", &vtxN_);
206 tree_->Branch(
"ele_q", &eleQ_);
207 tree_->Branch(
"ele_3q", &ele3Q_);
210 tree_->Branch(
"energyMatrix", &energyMatrix_);
213 tree_->Branch(
"matchedToGenEle", &matchedToGenEle_);
216 tree_->Branch(mvaVarMngr_.getName(
i).c_str(), &vars_[
i]);
218 tree_->Branch(
"ele_isEB", &eleIsEB_);
219 tree_->Branch(
"ele_isEE", &eleIsEE_);
220 tree_->Branch(
"ele_isEBEtaGap", &eleIsEBEtaGap_);
221 tree_->Branch(
"ele_isEBPhiGap", &eleIsEBPhiGap_);
222 tree_->Branch(
"ele_isEBEEGap", &eleIsEBEEGap_);
223 tree_->Branch(
"ele_isEEDeeGap", &eleIsEEDeeGap_);
224 tree_->Branch(
"ele_isEERingGap", &eleIsEERingGap_);
227 for (
size_t k = 0;
k < nValMaps_; ++
k) {
228 tree_->Branch(valMapBranchNames_[
k].c_str(), &mvaValues_[
k]);
231 for (
size_t k = 0;
k < nEleMaps_; ++
k) {
232 tree_->Branch(eleMapBranchNames_[
k].c_str(), &mvaPasses_[
k]);
235 for (
size_t k = 0;
k < nCats_; ++
k) {
236 tree_->Branch(mvaCatBranchNames_[
k].c_str(), &mvaCats_[
k]);
252 std::unique_ptr<noZS::EcalClusterLazyTools> lazyTools;
255 lazyTools = std::make_unique<noZS::EcalClusterLazyTools>(
267 for (
const auto& pu : *pileup) {
268 int bx = pu.getBunchCrossing();
270 genNpu_ = pu.getPU_NumInteractions();
294 std::vector<float> extraVariables =
variableHelper_.getAuxVariables(iEvent);
296 for (
auto const& ele :
src->ptrs()) {
302 const auto&
seed = *(ele->superCluster()->seed());
307 eleQ_ = ele->charge();
308 ele3Q_ = ele->chargeInfo().isGsfCtfScPixConsistent;
310 for (
int iVar = 0; iVar <
nVars_; ++iVar) {
334 for (
size_t k = 0; k <
nCats_; ++
k)
350 for (
auto const& particle : genParticles) {
352 if (
std::abs(particle.pdgId()) != 11 || particle.status() != 1)
358 closestElectron = &particle;
362 if (closestElectron ==
nullptr || dR >=
deltaR_)
385 desc.
add<
bool>(
"doEnergyMatrix",
false);
386 desc.
add<
int>(
"energyMatrixSize", 2)->setComment(
"extension of crystals in each direction away from the seed");
387 desc.
add<
bool>(
"isMC",
true);
388 desc.
add<
double>(
"deltaR", 0.1);
389 desc.
add<
double>(
"ptThreshold", 5.0);
390 desc.
add<std::vector<std::string>>(
"eleMVAs", {});
391 desc.
add<std::vector<std::string>>(
"eleMVALabels", {});
392 desc.
add<std::vector<std::string>>(
"eleMVAValMaps", {});
393 desc.
add<std::vector<std::string>>(
"eleMVAValMapLabels", {});
394 desc.
add<std::vector<std::string>>(
"eleMVACats", {});
395 desc.
add<std::vector<std::string>>(
"eleMVACatLabels", {});
static const std::string kSharedResource
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
EventNumber_t event() const
const double ptThreshold_
const LorentzVector & p4(P4Kind kind) const
std::vector< edm::EDGetTokenT< edm::ValueMap< bool > > > eleMapTokens_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const edm::EDGetTokenT< std::vector< PileupSummaryInfo > > pileup_
bool isDirectHardProcessTauDecayProductFinalState() const
#define DEFINE_FWK_MODULE(type)
edm::LuminosityBlockNumber_t luminosityBlock() const
const edm::EDGetTokenT< EcalRecHitCollection > ebRecHits_
T * make(const Args &...args) const
make new ROOT object
const bool doEnergyMatrix_
float getValue(int index, const ParticleType &particle, const std::vector< float > &auxVariables) const
std::vector< edm::EDGetTokenT< edm::ValueMap< int > > > mvaCatTokens_
const std::vector< std::string > mvaCatBranchNames_
std::vector< float > mvaValues_
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > valMapTokens_
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
const std::vector< std::string > eleMapBranchNames_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
const std::vector< std::string > valMapTags_
const std::vector< std::string > mvaCatTags_
void addDefault(ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< std::vector< reco::Vertex > > vertices_
const std::vector< std::string > valMapBranchNames_
std::vector< float > energyMatrix_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< int > mvaPasses_
const MVAVariableHelper variableHelper_
Abs< T >::type abs(const T &t)
std::vector< int > mvaCats_
ElectronMVANtuplizer(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< edm::View< reco::GsfElectron > > src_
const edm::EDGetTokenT< edm::View< reco::GenParticle > > genParticles_
bool fromHardProcessFinalState() const
const std::vector< std::string > eleMapTags_
std::vector< float > vars_
MVAVariableManager< reco::GsfElectron > mvaVarMngr_
void analyze(const edm::Event &, const edm::EventSetup &) override
int matchToTruth(reco::GsfElectron const &electron, edm::View< reco::GenParticle > const &genParticles) const
const edm::EDGetTokenT< EcalRecHitCollection > eeRecHits_
const int energyMatrixSize_
tuple size
Write out results.