CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
MultShiftMETcorrDBInputProducer Class Reference

#include <MultShiftMETcorrDBInputProducer.h>

Inheritance diagram for MultShiftMETcorrDBInputProducer:
edm::stream::EDProducer<>

Public Member Functions

 MultShiftMETcorrDBInputProducer (const edm::ParameterSet &)
 
 ~MultShiftMETcorrDBInputProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

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

Static Private Member Functions

static int translateTypeToAbsPdgId (reco::PFCandidate::ParticleType type)
 

Private Attributes

std::vector< edm::ParameterSetcfgCorrParameters_
 
int counts_
 
std::vector< double > etaMax_
 
std::vector< double > etaMin_
 
std::unique_ptr< TF1 > formula_x_
 
std::unique_ptr< TF1 > formula_y_
 
bool mIsData
 
edm::ESGetToken< MEtXYcorrectParametersCollection, MEtXYcorrectRecordmMEtXYcorParaColl_
 
std::string moduleLabel_
 
std::string mPayloadName
 
std::string mSampleType
 
edm::EDGetTokenT< edm::View< reco::Candidate > > pflow_
 
double sumPt_
 
edm::EDGetTokenT< edm::View< reco::Vertex > > vertices_
 
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Compute MET correction to compensate systematic shift of MET in x/y-direction (cf. https://indico.cern.ch/getFile.py/access?contribId=1&resId=0&materialId=slides&confId=174318 )

Authors
SangEun Lee,
Robert Schoefbeck, Vienna

Definition at line 36 of file MultShiftMETcorrDBInputProducer.h.

Constructor & Destructor Documentation

◆ MultShiftMETcorrDBInputProducer()

MultShiftMETcorrDBInputProducer::MultShiftMETcorrDBInputProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 38 of file MultShiftMETcorrDBInputProducer.cc.

References looper::cfg, etaMax_, etaMin_, mIsData, mMEtXYcorParaColl_, mPayloadName, mSampleType, pflow_, HLT_2022v15_cff::srcWeights, AlCaHLTBitMon_QueryRunRegistry::string, vertices_, and weightsToken_.

39  : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
40  mPayloadName = cfg.getParameter<std::string>("payloadName");
41  mSampleType = (cfg.exists("sampleType")) ? cfg.getParameter<std::string>("sampleType") : "MC";
42  mIsData = cfg.getParameter<bool>("isData");
43 
44  pflow_ = consumes<edm::View<reco::Candidate>>(cfg.getParameter<edm::InputTag>("srcPFlow"));
45  vertices_ = consumes<edm::View<reco::Vertex>>(cfg.getParameter<edm::InputTag>("vertexCollection"));
47  esConsumes<MEtXYcorrectParametersCollection, MEtXYcorrectRecord>(edm::ESInputTag("", mPayloadName));
48 
49  edm::InputTag srcWeights = cfg.getParameter<edm::InputTag>("srcWeights");
50  if (!srcWeights.label().empty())
52 
53  etaMin_.clear();
54  etaMax_.clear();
55 
56  produces<CorrMETData>();
57 }
edm::EDGetTokenT< edm::View< reco::Candidate > > pflow_
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
edm::EDGetTokenT< edm::View< reco::Vertex > > vertices_
edm::ESGetToken< MEtXYcorrectParametersCollection, MEtXYcorrectRecord > mMEtXYcorParaColl_

◆ ~MultShiftMETcorrDBInputProducer()

MultShiftMETcorrDBInputProducer::~MultShiftMETcorrDBInputProducer ( )
override

Definition at line 59 of file MultShiftMETcorrDBInputProducer.cc.

59 {}

Member Function Documentation

◆ produce()

void MultShiftMETcorrDBInputProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
overrideprivate

Definition at line 61 of file MultShiftMETcorrDBInputProducer.cc.

References funct::abs(), HltBtagPostValidation_cff::c, counts_, MEtXYcorrectParameters::definitions(), Exception, MEtXYcorrectParametersCollection::findLabel(), MEtXYcorrectParameters::Definitions::formula(), formula_x_, formula_y_, edm::Event::getByToken(), edm::EventSetup::getHandle(), metFilters_cff::goodVertices, mps_fire::i, MEtXYcorrectParametersCollection::isShiftData(), MEtXYcorrectParametersCollection::isShiftDY(), MEtXYcorrectParametersCollection::isShiftMC(), MEtXYcorrectParametersCollection::isShiftTTJets(), MEtXYcorrectParametersCollection::isShiftWJets(), edm::EDGetTokenT< T >::isUninitialized(), edm::HandleBase::isValid(), relativeConstraints::keys, mIsData, mMEtXYcorParaColl_, eostools::move(), mSampleType, MEtXYcorrectParameters::Record::nParameters(), MEtXYcorrectParameters::Record::parameter(), pfLinker_cff::particleFlow, MEtXYcorrectParameters::Definitions::parVar(), pflow_, position, MEtXYcorrectParameters::Definitions::PtclType(), edm::Event::put(), MEtXYcorrectParameters::record(), rho, AlCaHLTBitMon_QueryRunRegistry::string, sumPt_, translateTypeToAbsPdgId(), heppy_batch::val, MEtXYcorrectParametersCollection::validKeys(), vertices_, mps_merge::weight, hltDeepSecondaryVertexTagInfosPFPuppi_cfi::weights, weightsToken_, MEtXYcorrectParameters::Record::xMax(), MEtXYcorrectParameters::Record::xMin(), and z.

61  {
62  // Get para.s from DB
64 
65  // get the sections from Collection (pair of section and METCorr.Par class)
66  std::vector<MEtXYcorrectParametersCollection::key_type> keys;
67  // save level to keys for each METParameter in METParameter collection
68  MEtXYcorParaColl->validKeys(keys);
69 
70  //get primary vertices
72  evt.getByToken(vertices_, hpv);
73  if (!hpv.isValid()) {
74  edm::LogError("MultShiftMETcorrDBInputProducer::produce") << "could not find vertex collection ";
75  }
76  std::vector<reco::Vertex> goodVertices;
77  for (unsigned i = 0; i < hpv->size(); i++) {
78  if ((*hpv)[i].ndof() > 4 && (fabs((*hpv)[i].z()) <= 24.) && (fabs((*hpv)[i].position().rho()) <= 2.0))
79  goodVertices.push_back((*hpv)[i]);
80  }
81  int ngoodVertices = goodVertices.size();
82 
85 
89 
90  //loop over all constituent types and sum each correction
91  //std::unique_ptr<CorrMETData> metCorr(new CorrMETData());
92  std::unique_ptr<CorrMETData> metCorr(new CorrMETData());
93 
94  double corx = 0.;
95  double cory = 0.;
96 
97  // check DB
98  for (std::vector<MEtXYcorrectParametersCollection::key_type>::const_iterator ikey = keys.begin(); ikey != keys.end();
99  ++ikey) {
100  if (mIsData) {
101  if (!MEtXYcorParaColl->isShiftData(*ikey))
102  throw cms::Exception("MultShiftMETcorrDBInputProducer::produce")
103  << "DB is not for Data. Set proper option: \"corrPfMetXYMultDB.isData\" !!\n";
104  } else {
105  if (MEtXYcorParaColl->isShiftData(*ikey))
106  throw cms::Exception("MultShiftMETcorrDBInputProducer::produce")
107  << "DB is for Data. Set proper option: \"corrPfMetXYMultDB.isData\" !!\n";
108  }
109  }
110 
111  for (std::vector<MEtXYcorrectParametersCollection::key_type>::const_iterator ikey = keys.begin(); ikey != keys.end();
112  ++ikey) {
113  if (!mIsData) {
114  if (mSampleType == "MC") {
115  if (!MEtXYcorParaColl->isShiftMC(*ikey))
116  continue;
117  } else if (mSampleType == "DY") {
118  if (!MEtXYcorParaColl->isShiftDY(*ikey))
119  continue;
120  } else if (mSampleType == "TTJets") {
121  if (!MEtXYcorParaColl->isShiftTTJets(*ikey))
122  continue;
123  } else if (mSampleType == "WJets") {
124  if (!MEtXYcorParaColl->isShiftWJets(*ikey))
125  continue;
126  } else
127  throw cms::Exception("MultShiftMETcorrDBInputProducer::produce")
128  << "SampleType: " << mSampleType << " is not reserved !!!\n";
129  }
130 
131  std::string sectionName = MEtXYcorParaColl->findLabel(*ikey);
132  MEtXYcorrectParameters const& MEtXYcorParams = (*MEtXYcorParaColl)[*ikey];
133 
134  counts_ = 0;
135  sumPt_ = 0;
136 
137  for (unsigned i = 0; i < particleFlow->size(); ++i) {
138  const reco::Candidate& c = particleFlow->at(i);
139  if (abs(c.pdgId()) ==
141  if ((c.eta() > MEtXYcorParams.record(0).xMin(0)) and (c.eta() < MEtXYcorParams.record(0).xMax(0))) {
142  float weight = (!weightsToken_.isUninitialized()) ? (*weights)[particleFlow->ptrAt(i)] : 1.0;
143  counts_ += (weight > 0);
144  sumPt_ += c.pt() * weight;
145  continue;
146  }
147  }
148  }
149  double val(0.);
150  unsigned parVar = MEtXYcorParams.definitions().parVar(0);
151 
152  if (parVar == 0) {
153  val = counts_;
154 
155  } else if (parVar == 1) {
156  val = ngoodVertices;
157 
158  } else if (parVar == 2) {
159  val = sumPt_;
160 
161  } else {
162  throw cms::Exception("MultShiftMETcorrDBInputProducer::produce")
163  << "parVar: " << parVar << " is not reserved !!!\n";
164  }
165 
166  formula_x_ = std::make_unique<TF1>("corrPx", MEtXYcorParams.definitions().formula().c_str());
167  formula_y_ = std::make_unique<TF1>("corrPy", MEtXYcorParams.definitions().formula().c_str());
168 
169  for (unsigned i(0); i < MEtXYcorParams.record(0).nParameters(); i++) {
170  formula_x_->SetParameter(i, MEtXYcorParams.record(0).parameter(i));
171  }
172  for (unsigned i(0); i < MEtXYcorParams.record(1).nParameters(); i++) {
173  formula_y_->SetParameter(i, MEtXYcorParams.record(1).parameter(i));
174  }
175 
176  corx -= formula_x_->Eval(val);
177  cory -= formula_y_->Eval(val);
178 
179  } //end loop over corrections
180 
181  metCorr->mex = corx;
182  metCorr->mey = cory;
183  evt.put(std::move(metCorr), "");
184 }
const Record & record(unsigned fBin) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
ParticleType
particle types
Definition: PFCandidate.h:44
edm::EDGetTokenT< edm::View< reco::Candidate > > pflow_
void validKeys(std::vector< key_type > &keys) const
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:104
goodVertices
The Good vertices collection needed by the tracking failure filter ________||.
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
Definition: weight.py:1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
Log< level::Error, false > LogError
std::vector< unsigned > parVar() const
static int translateTypeToAbsPdgId(reco::PFCandidate::ParticleType type)
float xMin(unsigned fVar) const
float xMax(unsigned fVar) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const Definitions & definitions() const
bool isValid() const
Definition: HandleBase.h:70
static std::string findLabel(key_type k)
a MET correction term
Definition: CorrMETData.h:14
static int position[264][3]
Definition: ReadPGInfo.cc:289
edm::EDGetTokenT< edm::View< reco::Vertex > > vertices_
edm::ESGetToken< MEtXYcorrectParametersCollection, MEtXYcorrectRecord > mMEtXYcorParaColl_
def move(src, dest)
Definition: eostools.py:511
float parameter(unsigned fIndex) const

◆ translateTypeToAbsPdgId()

int MultShiftMETcorrDBInputProducer::translateTypeToAbsPdgId ( reco::PFCandidate::ParticleType  type)
staticprivate

Definition at line 16 of file MultShiftMETcorrDBInputProducer.cc.

References MillePedeFileConverter_cfg::e, CustomPhysics_cfi::gamma, h, amptDefaultParameters_cff::mu, and X.

Referenced by produce().

16  {
17  switch (type) {
19  return 211; // pi+
21  return 11;
23  return 13;
25  return 22;
26  case reco::PFCandidate::ParticleType::h0:
27  return 130; // K_L0
28  case reco::PFCandidate::ParticleType::h_HF:
29  return 1; // dummy pdg code
30  case reco::PFCandidate::ParticleType::egamma_HF:
31  return 2; // dummy pdg code
33  default:
34  return 0;
35  }
36 }
#define X(str)
Definition: MuonsGrabber.cc:38
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

Member Data Documentation

◆ cfgCorrParameters_

std::vector<edm::ParameterSet> MultShiftMETcorrDBInputProducer::cfgCorrParameters_
private

Definition at line 54 of file MultShiftMETcorrDBInputProducer.h.

◆ counts_

int MultShiftMETcorrDBInputProducer::counts_
private

Definition at line 57 of file MultShiftMETcorrDBInputProducer.h.

Referenced by produce().

◆ etaMax_

std::vector<double> MultShiftMETcorrDBInputProducer::etaMax_
private

Definition at line 56 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer().

◆ etaMin_

std::vector<double> MultShiftMETcorrDBInputProducer::etaMin_
private

Definition at line 56 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer().

◆ formula_x_

std::unique_ptr<TF1> MultShiftMETcorrDBInputProducer::formula_x_
private

Definition at line 59 of file MultShiftMETcorrDBInputProducer.h.

Referenced by produce().

◆ formula_y_

std::unique_ptr<TF1> MultShiftMETcorrDBInputProducer::formula_y_
private

Definition at line 60 of file MultShiftMETcorrDBInputProducer.h.

Referenced by produce().

◆ mIsData

bool MultShiftMETcorrDBInputProducer::mIsData
private

Definition at line 51 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer(), and produce().

◆ mMEtXYcorParaColl_

edm::ESGetToken<MEtXYcorrectParametersCollection, MEtXYcorrectRecord> MultShiftMETcorrDBInputProducer::mMEtXYcorParaColl_
private

Definition at line 47 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer(), and produce().

◆ moduleLabel_

std::string MultShiftMETcorrDBInputProducer::moduleLabel_
private

◆ mPayloadName

std::string MultShiftMETcorrDBInputProducer::mPayloadName
private

Definition at line 49 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer().

◆ mSampleType

std::string MultShiftMETcorrDBInputProducer::mSampleType
private

Definition at line 50 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer(), and produce().

◆ pflow_

edm::EDGetTokenT<edm::View<reco::Candidate> > MultShiftMETcorrDBInputProducer::pflow_
private

Definition at line 45 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer(), and produce().

◆ sumPt_

double MultShiftMETcorrDBInputProducer::sumPt_
private

Definition at line 58 of file MultShiftMETcorrDBInputProducer.h.

Referenced by produce().

◆ vertices_

edm::EDGetTokenT<edm::View<reco::Vertex> > MultShiftMETcorrDBInputProducer::vertices_
private

Definition at line 46 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer(), and produce().

◆ weightsToken_

edm::EDGetTokenT<edm::ValueMap<float> > MultShiftMETcorrDBInputProducer::weightsToken_
private

Definition at line 52 of file MultShiftMETcorrDBInputProducer.h.

Referenced by MultShiftMETcorrDBInputProducer(), and produce().