CMS 3D CMS Logo

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

#include <TtSemiLepJetCombMaxSumPtWMass.h>

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

Public Member Functions

 TtSemiLepJetCombMaxSumPtWMass (const edm::ParameterSet &)
 
 ~TtSemiLepJetCombMaxSumPtWMass () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
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)
 
 ~ProducerBase () 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
 
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 9 of file TtSemiLepJetCombMaxSumPtWMass.h.

Constructor & Destructor Documentation

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

Definition at line 7 of file TtSemiLepJetCombMaxSumPtWMass.cc.

References Exception, and maxNJets_.

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

Definition at line 26 of file TtSemiLepJetCombMaxSumPtWMass.cc.

27 {
28 }

Member Function Documentation

void TtSemiLepJetCombMaxSumPtWMass::beginJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 18 of file TtSemiLepJetCombMaxSumPtWMass.h.

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

18 {};
void TtSemiLepJetCombMaxSumPtWMass::endJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 20 of file TtSemiLepJetCombMaxSumPtWMass.h.

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

Definition at line 31 of file TtSemiLepJetCombMaxSumPtWMass.cc.

References bTagAlgorithm_, spr::find(), 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().

32 {
33  std::unique_ptr<std::vector<std::vector<int> > > pOut(new std::vector<std::vector<int> >);
34  std::unique_ptr<int> pJetsConsidered(new int);
35 
36  std::vector<int> match;
37  for(unsigned int i = 0; i < 4; ++i)
38  match.push_back( -1 );
39 
40  // get jets
42  evt.getByToken(jetsToken_, jets);
43 
44  // get leptons
46  evt.getByToken(lepsToken_, leps);
47 
48 
49  // skip events without lepton candidate or less than 4 jets or no MET
50  if(leps->empty() || jets->size() < 4){
51  pOut->push_back( match );
52  evt.put(std::move(pOut));
53  *pJetsConsidered = jets->size();
54  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
55  return;
56  }
57 
58  unsigned maxNJets = maxNJets_;
59  if(maxNJets_ == -1 || (int)jets->size() < maxNJets_) maxNJets = jets->size();
60  *pJetsConsidered = maxNJets;
61  evt.put(std::move(pJetsConsidered), "NumberOfConsideredJets");
62 
63  std::vector<bool> isBJet;
64  std::vector<bool> isLJet;
65  int cntBJets = 0;
66  if(useBTagging_) {
67  for(unsigned int idx=0; idx<maxNJets; ++idx) {
68  isBJet.push_back( ((*jets)[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_ ) );
69  isLJet.push_back( ((*jets)[idx].bDiscriminator(bTagAlgorithm_) < maxBDiscLightJets_) );
70  if((*jets)[idx].bDiscriminator(bTagAlgorithm_) > minBDiscBJets_ )cntBJets++;
71  }
72  }
73 
74  // -----------------------------------------------------
75  // associate those jets with maximum pt of the vectorial
76  // sum to the hadronic decay chain
77  // -----------------------------------------------------
78  double maxPt=-1.;
79  std::vector<int> maxPtIndices;
80  maxPtIndices.push_back(-1);
81  maxPtIndices.push_back(-1);
82  maxPtIndices.push_back(-1);
83  for(unsigned idx=0; idx<maxNJets; ++idx){
84  if(useBTagging_ && (!isLJet[idx] || (cntBJets<=2 && isBJet[idx]))) continue;
85  for(unsigned jdx=(idx+1); jdx<maxNJets; ++jdx){
86  if(jdx==idx || (useBTagging_ && (!isLJet[jdx] || (cntBJets<=2 && isBJet[jdx]) || (cntBJets==3 && isBJet[idx] && isBJet[jdx])))) continue;
87  for(unsigned kdx=0; kdx<maxNJets; ++kdx){
88  if(kdx==idx || kdx==jdx || (useBTagging_ && !isBJet[kdx])) continue;
90  (*jets)[idx].p4()+
91  (*jets)[jdx].p4()+
92  (*jets)[kdx].p4();
93  if( maxPt<0. || maxPt<sum.pt() ){
94  maxPt=sum.pt();
95  maxPtIndices.clear();
96  maxPtIndices.push_back(idx);
97  maxPtIndices.push_back(jdx);
98  maxPtIndices.push_back(kdx);
99  }
100  }
101  }
102  }
103 
104  // -----------------------------------------------------
105  // associate those jets that get closest to the W mass
106  // with their invariant mass to the W boson
107  // -----------------------------------------------------
108  double wDist =-1.;
109  std::vector<int> closestToWMassIndices;
110  closestToWMassIndices.push_back(-1);
111  closestToWMassIndices.push_back(-1);
112  if( isValid(maxPtIndices[0], jets) && isValid(maxPtIndices[1], jets) && isValid(maxPtIndices[2], jets)) {
113  for(unsigned idx=0; idx<maxPtIndices.size(); ++idx){
114  for(unsigned jdx=0; jdx<maxPtIndices.size(); ++jdx){
115  if( jdx==idx || maxPtIndices[idx]>maxPtIndices[jdx] || (useBTagging_ && (!isLJet[maxPtIndices[idx]] || !isLJet[maxPtIndices[jdx]] || (cntBJets<=2 && isBJet[maxPtIndices[idx]]) || (cntBJets<=2 && isBJet[maxPtIndices[jdx]]) || (cntBJets==3 && isBJet[maxPtIndices[idx]] && isBJet[maxPtIndices[jdx]])))) continue;
117  (*jets)[maxPtIndices[idx]].p4()+
118  (*jets)[maxPtIndices[jdx]].p4();
119  if( wDist<0. || wDist>fabs(sum.mass()-wMass_) ){
120  wDist=fabs(sum.mass()-wMass_);
121  closestToWMassIndices.clear();
122  closestToWMassIndices.push_back(maxPtIndices[idx]);
123  closestToWMassIndices.push_back(maxPtIndices[jdx]);
124  }
125  }
126  }
127  }
128  int hadB=-1;
129  for(unsigned idx=0; idx<maxPtIndices.size(); ++idx){
130  // if this idx is not yet contained in the list of W mass candidates...
131  if( std::find( closestToWMassIndices.begin(), closestToWMassIndices.end(), maxPtIndices[idx]) == closestToWMassIndices.end() ){
132  hadB = maxPtIndices[idx];
133  break; // there should be no other cadidates!
134  }
135  }
136 
137  // -----------------------------------------------------
138  // associate the remaining jet with maximum pt of the
139  // vectorial sum with the leading lepton with the
140  // leptonic decay chain
141  // -----------------------------------------------------
142  maxPt=-1.;
143  int lepB=-1;
144  for(unsigned idx=0; idx<maxNJets; ++idx){
145  if(useBTagging_ && !isBJet[idx]) continue;
146  // make sure it's not used up already from the hadronic decay chain
147  if( std::find(maxPtIndices.begin(), maxPtIndices.end(), idx) == maxPtIndices.end() ){
149  (*jets)[idx].p4()+(*leps)[ 0 ].p4();
150  if( maxPt<0. || maxPt<sum.pt() ){
151  maxPt=sum.pt();
152  lepB=idx;
153  }
154  }
155  }
156 
157  match[TtSemiLepEvtPartons::LightQ ] = closestToWMassIndices[0];
158  match[TtSemiLepEvtPartons::LightQBar] = closestToWMassIndices[1];
159  match[TtSemiLepEvtPartons::HadB ] = hadB;
160  match[TtSemiLepEvtPartons::LepB ] = lepB;
161 
162  pOut->push_back( match );
163  evt.put(std::move(pOut));
164 }
bool isValid(const int &idx, const edm::Handle< std::vector< pat::Jet > > &jets)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
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_
edm::EDGetTokenT< edm::View< reco::RecoCandidate > > lepsToken_
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 TtSemiLepJetCombMaxSumPtWMass::bTagAlgorithm_
private

Definition at line 29 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce().

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

Definition at line 22 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce().

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

Definition at line 25 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce().

double TtSemiLepJetCombMaxSumPtWMass::maxBDiscLightJets_
private

Definition at line 31 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce().

int TtSemiLepJetCombMaxSumPtWMass::maxNJets_
private

Definition at line 26 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce(), and TtSemiLepJetCombMaxSumPtWMass().

double TtSemiLepJetCombMaxSumPtWMass::minBDiscBJets_
private

Definition at line 30 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce().

bool TtSemiLepJetCombMaxSumPtWMass::useBTagging_
private

Definition at line 28 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce().

double TtSemiLepJetCombMaxSumPtWMass::wMass_
private

Definition at line 27 of file TtSemiLepJetCombMaxSumPtWMass.h.

Referenced by produce().