CMS 3D CMS Logo

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

#include <TtSemiLepJetCombWMassMaxSumPt.h>

Inheritance diagram for TtSemiLepJetCombWMassMaxSumPt:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 TtSemiLepJetCombWMassMaxSumPt (const edm::ParameterSet &)
 
 ~TtSemiLepJetCombWMassMaxSumPt () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () 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)
 
virtual ~ProducerBase () noexcept(false)
 
- 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
 
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::vector< ModuleDescription const * > &modules, 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
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void beginJob () override
 
void endJob () override
 
bool isValid (const int &idx, const edm::Handle< std::vector< pat::Jet > > &jets)
 
void produce (edm::Event &evt, const edm::EventSetup &setup) 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::EDProducer
typedef EDProducer 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::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
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 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)
 

Detailed Description

Definition at line 10 of file TtSemiLepJetCombWMassMaxSumPt.h.

Constructor & Destructor Documentation

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

Definition at line 5 of file TtSemiLepJetCombWMassMaxSumPt.cc.

References Exception, and maxNJets_.

5  :
6  jetsToken_ (consumes< std::vector<pat::Jet> >(cfg.getParameter<edm::InputTag>("jets" ))),
8  maxNJets_ (cfg.getParameter<int> ("maxNJets" )),
9  wMass_ (cfg.getParameter<double> ("wMass" )),
10  useBTagging_ (cfg.getParameter<bool> ("useBTagging" )),
11  bTagAlgorithm_ (cfg.getParameter<std::string> ("bTagAlgorithm" )),
12  minBDiscBJets_ (cfg.getParameter<double> ("minBDiscBJets" )),
13  maxBDiscLightJets_(cfg.getParameter<double> ("maxBDiscLightJets"))
14 {
15  if(maxNJets_<4 && maxNJets_!=-1)
16  throw cms::Exception("WrongConfig")
17  << "Parameter maxNJets can not be set to " << maxNJets_ << ". \n"
18  << "It has to be larger than 4 or can be set to -1 to take all jets.";
19 
20  produces<std::vector<std::vector<int> > >();
21  produces<int>("NumberOfConsideredJets");
22 }
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
TtSemiLepJetCombWMassMaxSumPt::~TtSemiLepJetCombWMassMaxSumPt ( )
override

Definition at line 24 of file TtSemiLepJetCombWMassMaxSumPt.cc.

25 {
26 }

Member Function Documentation

void TtSemiLepJetCombWMassMaxSumPt::beginJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 19 of file TtSemiLepJetCombWMassMaxSumPt.h.

References produce(), and GeneralSetup::setup().

19 {};
void TtSemiLepJetCombWMassMaxSumPt::endJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 21 of file TtSemiLepJetCombWMassMaxSumPt.h.

21 {};
bool TtSemiLepJetCombWMassMaxSumPt::isValid ( const int &  idx,
const edm::Handle< std::vector< pat::Jet > > &  jets 
)
inlineprivate
void TtSemiLepJetCombWMassMaxSumPt::produce ( edm::Event evt,
const edm::EventSetup setup 
)
overrideprivate

Definition at line 29 of file TtSemiLepJetCombWMassMaxSumPt.cc.

References bTagAlgorithm_, edm::Event::getByToken(), TtSemiLepEvtPartons::HadB, mps_fire::i, training_settings::idx, isValid(), fwrapper::jets, jetsToken_, TtSemiLepEvtPartons::LepB, TtSemiLepHitFitProducer_Electrons_cfi::leps, lepsToken_, TtSemiLepEvtPartons::LightQ, TtSemiLepEvtPartons::LightQBar, match(), maxBDiscLightJets_, TtFullLepEvtBuilder_cfi::maxNJets, maxNJets_, MuonErrorMatrixAnalyzer_cfi::maxPt, minBDiscBJets_, eostools::move(), edm::Event::put(), useBTagging_, and wMass_.

Referenced by beginJob().

30 {
31  std::unique_ptr<std::vector<std::vector<int> > > pOut(new std::vector<std::vector<int> >);
32  std::unique_ptr<int> pJetsConsidered(new int);
33 
34  std::vector<int> match;
35  for(unsigned int i = 0; i < 4; ++i)
36  match.push_back( -1 );
37 
38  // get jets
40  evt.getByToken(jetsToken_, jets);
41 
42  // get leptons
44  evt.getByToken(lepsToken_, leps);
45 
46 
47  // skip events without lepton candidate or less than 4 jets or no MET
48  if(leps->empty() || jets->size() < 4){
49  pOut->push_back( match );
50  evt.put(std::move(pOut));
51  *pJetsConsidered = jets->size();
52  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
53  return;
54  }
55 
56  unsigned maxNJets = maxNJets_;
57  if(maxNJets_ == -1 || (int)jets->size() < maxNJets_) maxNJets = jets->size();
58  *pJetsConsidered = maxNJets;
59  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
60 
61  std::vector<bool> isBJet;
62  std::vector<bool> isLJet;
63  int cntBJets = 0;
64  if(useBTagging_) {
65  for(unsigned int idx=0; idx<maxNJets; ++idx) {
66  isBJet.push_back( ((*jets)[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_ ) );
67  isLJet.push_back( ((*jets)[idx].bDiscriminator(bTagAlgorithm_) < maxBDiscLightJets_) );
68  if((*jets)[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_ )cntBJets++;
69  }
70  }
71 
72  // -----------------------------------------------------
73  // associate those jets that get closest to the W mass
74  // with their invariant mass to the hadronic W boson
75  // -----------------------------------------------------
76  double wDist =-1.;
77  std::vector<int> closestToWMassIndices;
78  closestToWMassIndices.push_back(-1);
79  closestToWMassIndices.push_back(-1);
80  for(unsigned idx=0; idx<maxNJets; ++idx){
81  if(useBTagging_ && (!isLJet[idx] || (cntBJets<=2 && isBJet[idx]))) continue;
82  for(unsigned jdx=(idx+1); jdx<maxNJets; ++jdx){
83  if(useBTagging_ && (!isLJet[jdx] || (cntBJets<=2 && isBJet[jdx]) || (cntBJets==3 && isBJet[idx] && isBJet[jdx]))) continue;
85  (*jets)[idx].p4()+
86  (*jets)[jdx].p4();
87  if( wDist<0. || wDist>fabs(sum.mass()-wMass_) ){
88  wDist=fabs(sum.mass()-wMass_);
89  closestToWMassIndices.clear();
90  closestToWMassIndices.push_back(idx);
91  closestToWMassIndices.push_back(jdx);
92  }
93  }
94  }
95 
96  // -----------------------------------------------------
97  // associate those jets with maximum pt of the vectorial
98  // sum to the hadronic decay chain
99  // -----------------------------------------------------
100  double maxPt=-1.;
101  int hadB=-1;
102  if( isValid(closestToWMassIndices[0], jets) && isValid(closestToWMassIndices[1], jets)) {
103  for(unsigned idx=0; idx<maxNJets; ++idx){
104  if(useBTagging_ && !isBJet[idx]) continue;
105  // make sure it's not used up already from the hadronic W
106  if( (int)idx!=closestToWMassIndices[0] && (int)idx!=closestToWMassIndices[1] ){
108  (*jets)[closestToWMassIndices[0]].p4()+
109  (*jets)[closestToWMassIndices[1]].p4()+
110  (*jets)[idx].p4();
111  if( maxPt<0. || maxPt<sum.pt() ){
112  maxPt=sum.pt();
113  hadB=idx;
114  }
115  }
116  }
117  }
118 
119  // -----------------------------------------------------
120  // associate the remaining jet with maximum pt of the
121  // vectorial sum with the leading lepton with the
122  // leptonic b quark
123  // -----------------------------------------------------
124  maxPt=-1.;
125  int lepB=-1;
126  for(unsigned idx=0; idx<maxNJets; ++idx){
127  if(useBTagging_ && !isBJet[idx]) continue;
128  // make sure it's not used up already from the hadronic decay chain
129  if( (int)idx!=closestToWMassIndices[0] && (int)idx!=closestToWMassIndices[1] && (int)idx!=hadB) {
131  (*jets)[idx].p4()+(*leps)[ 0 ].p4();
132  if( maxPt<0. || maxPt<sum.pt() ){
133  maxPt=sum.pt();
134  lepB=idx;
135  }
136  }
137  }
138 
139  match[TtSemiLepEvtPartons::LightQ ] = closestToWMassIndices[0];
140  match[TtSemiLepEvtPartons::LightQBar] = closestToWMassIndices[1];
141  match[TtSemiLepEvtPartons::HadB ] = hadB;
142  match[TtSemiLepEvtPartons::LepB ] = lepB;
143 
144  pOut->push_back( match );
145  evt.put(std::move(pOut));
146 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool isValid(const int &idx, const edm::Handle< std::vector< pat::Jet > > &jets)
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
vector< PseudoJet > jets
maxNJets
maximum number of jets taken into account per event for each hypothesis (this parameter is used in th...
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
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
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

std::string TtSemiLepJetCombWMassMaxSumPt::bTagAlgorithm_
private

Definition at line 30 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce().

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

Definition at line 23 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce().

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

Definition at line 26 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce().

double TtSemiLepJetCombWMassMaxSumPt::maxBDiscLightJets_
private

Definition at line 32 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce().

int TtSemiLepJetCombWMassMaxSumPt::maxNJets_
private

Definition at line 27 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce(), and TtSemiLepJetCombWMassMaxSumPt().

double TtSemiLepJetCombWMassMaxSumPt::minBDiscBJets_
private

Definition at line 31 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce().

bool TtSemiLepJetCombWMassMaxSumPt::useBTagging_
private

Definition at line 29 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce().

double TtSemiLepJetCombWMassMaxSumPt::wMass_
private

Definition at line 28 of file TtSemiLepJetCombWMassMaxSumPt.h.

Referenced by produce().