CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
TtSemiLepJetCombMaxSumPtWMass Class Reference
Inheritance diagram for TtSemiLepJetCombMaxSumPtWMass:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 TtSemiLepJetCombMaxSumPtWMass (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::global::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
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector
< edm::ProductResolverIndex >
const & 
indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector
< edm::ProductResolverIndex >
const & 
putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex >
const & 
esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector
< ProductResolverIndexAndSkipBit >
const & 
itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

bool isValid (const int &idx, const std::vector< pat::Jet > &jets) const
 
void produce (edm::StreamID, edm::Event &evt, const edm::EventSetup &setup) const override
 

Private Attributes

std::string bTagAlgorithm_
 
edm::EDGetTokenT< std::vector
< pat::Jet > > 
jetsToken_
 
edm::EDGetTokenT< edm::View
< reco::RecoCandidate > > 
lepsToken_
 
double maxBDiscLightJets_
 
int maxNJets_
 
double minBDiscBJets_
 
bool useBTagging_
 
double wMass_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 8 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Constructor & Destructor Documentation

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

Definition at line 29 of file TtSemiLepJetCombMaxSumPtWMass.cc.

References Exception, and maxNJets_.

30  : jetsToken_(consumes<std::vector<pat::Jet>>(cfg.getParameter<edm::InputTag>("jets"))),
32  maxNJets_(cfg.getParameter<int>("maxNJets")),
33  wMass_(cfg.getParameter<double>("wMass")),
34  useBTagging_(cfg.getParameter<bool>("useBTagging")),
35  bTagAlgorithm_(cfg.getParameter<std::string>("bTagAlgorithm")),
36  minBDiscBJets_(cfg.getParameter<double>("minBDiscBJets")),
37  maxBDiscLightJets_(cfg.getParameter<double>("maxBDiscLightJets")) {
38  if (maxNJets_ < 4 && maxNJets_ != -1)
39  throw cms::Exception("WrongConfig") << "Parameter maxNJets can not be set to " << maxNJets_ << ". \n"
40  << "It has to be larger than 4 or can be set to -1 to take all jets.";
41 
42  produces<std::vector<std::vector<int>>>();
43  produces<int>("NumberOfConsideredJets");
44 }
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303

Member Function Documentation

bool TtSemiLepJetCombMaxSumPtWMass::isValid ( const int &  idx,
const std::vector< pat::Jet > &  jets 
) const
inlineprivate

Definition at line 15 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by ntupleDataFormat._Object::_checkIsValid(), produce(), and core.AutoHandle.AutoHandle::ReallyLoad().

15  {
16  return (0 <= idx && idx < (int)jets.size());
17  };
vector< PseudoJet > jets
void TtSemiLepJetCombMaxSumPtWMass::produce ( edm::StreamID  ,
edm::Event evt,
const edm::EventSetup setup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 46 of file TtSemiLepJetCombMaxSumPtWMass.cc.

References bTagAlgorithm_, spr::find(), edm::Event::get(), TtSemiLepEvtPartons::HadB, mps_fire::i, isValid(), fwrapper::jets, jetsToken_, TtSemiLepEvtPartons::LepB, lepsToken_, TtSemiLepEvtPartons::LightQ, TtSemiLepEvtPartons::LightQBar, match(), maxBDiscLightJets_, maxNJets_, minBDiscBJets_, eostools::move(), edm::Event::put(), useBTagging_, and wMass_.

46  {
47  auto pOut = std::make_unique<std::vector<std::vector<int>>>();
48  auto pJetsConsidered = std::make_unique<int>(0);
49 
50  std::vector<int> match;
51  for (unsigned int i = 0; i < 4; ++i)
52  match.push_back(-1);
53 
54  // get jets
55  const auto& jets = evt.get(jetsToken_);
56 
57  // get leptons
58  const auto& leps = evt.get(lepsToken_);
59 
60  // skip events without lepton candidate or less than 4 jets or no MET
61  if (leps.empty() || jets.size() < 4) {
62  pOut->push_back(match);
63  evt.put(std::move(pOut));
64  *pJetsConsidered = jets.size();
65  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
66  return;
67  }
68 
69  unsigned maxNJets = maxNJets_;
70  if (maxNJets_ == -1 || (int)jets.size() < maxNJets_)
71  maxNJets = jets.size();
72  *pJetsConsidered = maxNJets;
73  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
74 
75  std::vector<bool> isBJet;
76  std::vector<bool> isLJet;
77  int cntBJets = 0;
78  if (useBTagging_) {
79  for (unsigned int idx = 0; idx < maxNJets; ++idx) {
80  isBJet.push_back((jets[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_));
81  isLJet.push_back((jets[idx].bDiscriminator(bTagAlgorithm_) < maxBDiscLightJets_));
82  if (jets[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_)
83  cntBJets++;
84  }
85  }
86 
87  // -----------------------------------------------------
88  // associate those jets with maximum pt of the vectorial
89  // sum to the hadronic decay chain
90  // -----------------------------------------------------
91  double maxPt = -1.;
92  std::vector<int> maxPtIndices;
93  maxPtIndices.push_back(-1);
94  maxPtIndices.push_back(-1);
95  maxPtIndices.push_back(-1);
96  for (unsigned idx = 0; idx < maxNJets; ++idx) {
97  if (useBTagging_ && (!isLJet[idx] || (cntBJets <= 2 && isBJet[idx])))
98  continue;
99  for (unsigned jdx = (idx + 1); jdx < maxNJets; ++jdx) {
100  if (jdx == idx || (useBTagging_ && (!isLJet[jdx] || (cntBJets <= 2 && isBJet[jdx]) ||
101  (cntBJets == 3 && isBJet[idx] && isBJet[jdx]))))
102  continue;
103  for (unsigned kdx = 0; kdx < maxNJets; ++kdx) {
104  if (kdx == idx || kdx == jdx || (useBTagging_ && !isBJet[kdx]))
105  continue;
106  reco::Particle::LorentzVector sum = jets[idx].p4() + jets[jdx].p4() + jets[kdx].p4();
107  if (maxPt < 0. || maxPt < sum.pt()) {
108  maxPt = sum.pt();
109  maxPtIndices.clear();
110  maxPtIndices.push_back(idx);
111  maxPtIndices.push_back(jdx);
112  maxPtIndices.push_back(kdx);
113  }
114  }
115  }
116  }
117 
118  // -----------------------------------------------------
119  // associate those jets that get closest to the W mass
120  // with their invariant mass to the W boson
121  // -----------------------------------------------------
122  double wDist = -1.;
123  std::vector<int> closestToWMassIndices;
124  closestToWMassIndices.push_back(-1);
125  closestToWMassIndices.push_back(-1);
126  if (isValid(maxPtIndices[0], jets) && isValid(maxPtIndices[1], jets) && isValid(maxPtIndices[2], jets)) {
127  for (unsigned idx = 0; idx < maxPtIndices.size(); ++idx) {
128  for (unsigned jdx = 0; jdx < maxPtIndices.size(); ++jdx) {
129  if (jdx == idx || maxPtIndices[idx] > maxPtIndices[jdx] ||
130  (useBTagging_ &&
131  (!isLJet[maxPtIndices[idx]] || !isLJet[maxPtIndices[jdx]] ||
132  (cntBJets <= 2 && isBJet[maxPtIndices[idx]]) || (cntBJets <= 2 && isBJet[maxPtIndices[jdx]]) ||
133  (cntBJets == 3 && isBJet[maxPtIndices[idx]] && isBJet[maxPtIndices[jdx]]))))
134  continue;
135  reco::Particle::LorentzVector sum = jets[maxPtIndices[idx]].p4() + jets[maxPtIndices[jdx]].p4();
136  if (wDist < 0. || wDist > fabs(sum.mass() - wMass_)) {
137  wDist = fabs(sum.mass() - wMass_);
138  closestToWMassIndices.clear();
139  closestToWMassIndices.push_back(maxPtIndices[idx]);
140  closestToWMassIndices.push_back(maxPtIndices[jdx]);
141  }
142  }
143  }
144  }
145  int hadB = -1;
146  for (unsigned idx = 0; idx < maxPtIndices.size(); ++idx) {
147  // if this idx is not yet contained in the list of W mass candidates...
148  if (std::find(closestToWMassIndices.begin(), closestToWMassIndices.end(), maxPtIndices[idx]) ==
149  closestToWMassIndices.end()) {
150  hadB = maxPtIndices[idx];
151  break; // there should be no other cadidates!
152  }
153  }
154 
155  // -----------------------------------------------------
156  // associate the remaining jet with maximum pt of the
157  // vectorial sum with the leading lepton with the
158  // leptonic decay chain
159  // -----------------------------------------------------
160  maxPt = -1.;
161  int lepB = -1;
162  for (unsigned idx = 0; idx < maxNJets; ++idx) {
163  if (useBTagging_ && !isBJet[idx])
164  continue;
165  // make sure it's not used up already from the hadronic decay chain
166  if (std::find(maxPtIndices.begin(), maxPtIndices.end(), idx) == maxPtIndices.end()) {
167  reco::Particle::LorentzVector sum = jets[idx].p4() + leps[0].p4();
168  if (maxPt < 0. || maxPt < sum.pt()) {
169  maxPt = sum.pt();
170  lepB = idx;
171  }
172  }
173  }
174 
175  match[TtSemiLepEvtPartons::LightQ] = closestToWMassIndices[0];
176  match[TtSemiLepEvtPartons::LightQBar] = closestToWMassIndices[1];
177  match[TtSemiLepEvtPartons::HadB] = hadB;
178  match[TtSemiLepEvtPartons::LepB] = lepB;
179 
180  pOut->push_back(match);
181  evt.put(std::move(pOut));
182 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool isValid(const int &idx, const std::vector< pat::Jet > &jets) const
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
vector< PseudoJet > jets
def move
Definition: eostools.py:511
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21

Member Data Documentation

std::string TtSemiLepJetCombMaxSumPtWMass::bTagAlgorithm_
private

Definition at line 24 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce().

edm::EDGetTokenT<std::vector<pat::Jet> > TtSemiLepJetCombMaxSumPtWMass::jetsToken_
private

Definition at line 17 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce().

edm::EDGetTokenT<edm::View<reco::RecoCandidate> > TtSemiLepJetCombMaxSumPtWMass::lepsToken_
private

Definition at line 20 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce().

double TtSemiLepJetCombMaxSumPtWMass::maxBDiscLightJets_
private

Definition at line 26 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce().

int TtSemiLepJetCombMaxSumPtWMass::maxNJets_
private

Definition at line 21 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce(), and TtSemiLepJetCombMaxSumPtWMass().

double TtSemiLepJetCombMaxSumPtWMass::minBDiscBJets_
private

Definition at line 25 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce().

bool TtSemiLepJetCombMaxSumPtWMass::useBTagging_
private

Definition at line 23 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce().

double TtSemiLepJetCombMaxSumPtWMass::wMass_
private

Definition at line 22 of file TtSemiLepJetCombMaxSumPtWMass.cc.

Referenced by produce().