Skip to content

Commit

Permalink
Merged master-cmsswmaster from repository cms-nanoAOD with cms-merge-…
Browse files Browse the repository at this point in the history
…topic
  • Loading branch information
peruzzim committed May 8, 2019
2 parents c458253 + 359c364 commit f92240c
Show file tree
Hide file tree
Showing 22 changed files with 814 additions and 275 deletions.
19 changes: 18 additions & 1 deletion JetMETCorrections/Type1MET/interface/JetCleanerForType1METT.h
Expand Up @@ -104,7 +104,10 @@ class JetCleanerForType1METT : public edm::stream::EDProducer<>
skipMuonSelection_.reset( new StringCutObjectSelector<reco::Candidate>(skipMuonSelection_string,true) ) ;
}

calcMuonSubtrRawPtAsValueMap_ = cfg.getParameter<bool>("calcMuonSubtrRawPtAsValueMap");

produces<std::vector<T> >();
if (calcMuonSubtrRawPtAsValueMap_) produces<edm::ValueMap<float>>("MuonSubtrRawPt");
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand All @@ -120,6 +123,7 @@ class JetCleanerForType1METT : public edm::stream::EDProducer<>
desc.add<double>("skipEMfractionThreshold");
desc.add<bool>("skipMuons");
desc.add<std::string>("skipMuonSelection");
desc.add<bool>("calcMuonSubtrRawPtAsValueMap",false)->setComment("calculate muon-subtracted raw pt as a ValueMap for the input collection (only for selected jets, zero for others)");
descriptions.addDefault(desc);
}

Expand All @@ -145,6 +149,8 @@ class JetCleanerForType1METT : public edm::stream::EDProducer<>
std::unique_ptr< std::vector<T> > cleanedJets( new std::vector<T>() );

int numJets = jets->size();
std::vector<float> muonSubtrRawPt(numJets,0);

for(int jetIndex=0;jetIndex<numJets; ++jetIndex ) {
const T& jet = jets->at(jetIndex);

Expand Down Expand Up @@ -182,9 +188,20 @@ class JetCleanerForType1METT : public edm::stream::EDProducer<>
if(corrJetP4.pt()<type1JetPtThreshold_) continue;

cleanedJets->push_back(jet);
if (calcMuonSubtrRawPtAsValueMap_) muonSubtrRawPt[jetIndex]=rawJetP4.Pt();

}

evt.put(std::move(cleanedJets));

if (calcMuonSubtrRawPtAsValueMap_) {
std::unique_ptr<edm::ValueMap<float>> muonSubtrRawPtV(new edm::ValueMap<float>());
edm::ValueMap<float>::Filler fillerMuonSubtrRawPt(*muonSubtrRawPtV);
fillerMuonSubtrRawPt.insert(jets,muonSubtrRawPt.begin(),muonSubtrRawPt.end());
fillerMuonSubtrRawPt.fill();
evt.put(std::move(muonSubtrRawPtV),"MuonSubtrRawPt");
}

}


Expand Down Expand Up @@ -215,7 +232,7 @@ class JetCleanerForType1METT : public edm::stream::EDProducer<>
// from jet energy before compute JECs/propagating JECs to Type 1 + 2 MET corrections
std::unique_ptr<StringCutObjectSelector< reco::Candidate> > skipMuonSelection_;

bool calcMuonSubtrRawPtAsValueMap_; // calculate muon-subtracted raw pt as a ValueMap for the input collection (only for selected jets, zero for others)
};

#endif
Expand Down
Expand Up @@ -222,16 +222,3 @@ class FirstObjectSimpleFlatTableProducer : public SimpleFlatTableProducerBase<T,
}
};

#include "DataFormats/Candidate/interface/Candidate.h"
typedef SimpleFlatTableProducer<reco::Candidate> SimpleCandidateFlatTableProducer;

#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
typedef EventSingletonSimpleFlatTableProducer<GenEventInfoProduct> SimpleGenEventFlatTableProducer;

#include "SimDataFormats/HTXS/interface/HiggsTemplateCrossSections.h"
typedef EventSingletonSimpleFlatTableProducer<HTXS::HiggsClassification> SimpleHTXSFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer);
DEFINE_FWK_MODULE(SimpleHTXSFlatTableProducer);
4 changes: 2 additions & 2 deletions PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc
Expand Up @@ -90,8 +90,8 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {
break;
case MTau:
// CV: assignment of status codes according to https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsToTauTauWorking2016#MC_Matching
if ( match.isNonnull() && match->isPromptFinalState() && abs(match->pdgId()) == 11 ) flav[i] = 1;
else if ( match.isNonnull() && match->isPromptFinalState() && abs(match->pdgId()) == 13 ) flav[i] = 2;
if ( match.isNonnull() && match->statusFlags().isPrompt() && abs(match->pdgId()) == 11 ) flav[i] = 1;
else if ( match.isNonnull() && match->statusFlags().isPrompt() && abs(match->pdgId()) == 13 ) flav[i] = 2;
else if ( match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 11 ) flav[i] = 3;
else if ( match.isNonnull() && match->isDirectPromptTauDecayProductFinalState() && abs(match->pdgId()) == 13 ) flav[i] = 4;
else if ( matchVisTau.isNonnull() ) flav[i] = 5;
Expand Down
124 changes: 124 additions & 0 deletions PhysicsTools/NanoAOD/plugins/EGMSeedGainProducer.cc
@@ -0,0 +1,124 @@
// -*- C++ -*-
//
// Package: PhysicsTools/NanoAOD
// Class: EGMSeedGainProducer
//
/**\class EGMSeedGainProducer EGMSeedGainProducer.cc PhysicsTools/NanoAOD/plugins/EGMSeedGainProducer.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/


// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/StreamID.h"

#include "DataFormats/PatCandidates/interface/Electron.h"
#include "DataFormats/PatCandidates/interface/Photon.h"

#include "DataFormats/Common/interface/View.h"


//
// class declaration
//

template <typename T>
class EGMSeedGainProducer : public edm::global::EDProducer<> {
public:
explicit EGMSeedGainProducer(const edm::ParameterSet &iConfig):
src_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("src"))),
recHitsEB_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEB"))),
recHitsEE_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("recHitsEE")))
{
produces<edm::ValueMap<int>>();
}
~EGMSeedGainProducer() override {};

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

// ----------member data ---------------------------

edm::EDGetTokenT<edm::View<T>> src_;
edm::EDGetTokenT<EcalRecHitCollection> recHitsEB_;
edm::EDGetTokenT<EcalRecHitCollection> recHitsEE_;
};

//
// constants, enums and typedefs
//


//
// static data member definitions
//

//
// member functions
//

// ------------ method called to produce the data ------------
template <typename T>
void
EGMSeedGainProducer<T>::produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const
{
edm::Handle<edm::View<T>> src;
iEvent.getByToken(src_, src);
edm::Handle<EcalRecHitCollection> recHitsEB;
iEvent.getByToken(recHitsEB_, recHitsEB);
edm::Handle<EcalRecHitCollection> recHitsEE;
iEvent.getByToken(recHitsEB_, recHitsEE);

unsigned nSrc = src->size();
std::vector<int> gainSeed(nSrc,12);

// determine gain of seed crystal as in RecoEgamma/EgammaTools/src/PhotonEnergyCalibrator.cc
for (unsigned i = 0; i<nSrc; i++){
auto obj = src->ptrAt(i);
auto detid = obj->superCluster()->seed()->seed();
auto coll = obj->isEB() ? recHitsEB.product() : recHitsEE.product();
auto seed = coll->find(detid);
if (seed != coll->end()) {
if (seed->checkFlag(EcalRecHit::kHasSwitchToGain6)) gainSeed[i]=6;
if (seed->checkFlag(EcalRecHit::kHasSwitchToGain1)) gainSeed[i]=1;
}
}

std::unique_ptr<edm::ValueMap<int>> gainSeedV(new edm::ValueMap<int>());
edm::ValueMap<int>::Filler fillerCorr(*gainSeedV);
fillerCorr.insert(src,gainSeed.begin(),gainSeed.end());
fillerCorr.fill();
iEvent.put(std::move(gainSeedV));

}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
template <typename T>
void
EGMSeedGainProducer<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src")->setComment("input physics object collection");
desc.add<edm::InputTag>("recHitsEB",edm::InputTag("reducedEgamma","reducedEBRecHits"))->setComment("EB rechit collection");
desc.add<edm::InputTag>("recHitsEE",edm::InputTag("reducedEgamma","reducedEERecHits"))->setComment("EE rechit collection");
descriptions.addDefault(desc);
}

typedef EGMSeedGainProducer<pat::Electron> ElectronSeedGainProducer;
typedef EGMSeedGainProducer<pat::Photon> PhotonSeedGainProducer;

//define this as a plug-in
DEFINE_FWK_MODULE(ElectronSeedGainProducer);
DEFINE_FWK_MODULE(PhotonSeedGainProducer);

0 comments on commit f92240c

Please sign in to comment.