CMS 3D CMS Logo

TtFullHadKinFitProducer.cc
Go to the documentation of this file.
2 
3 static const unsigned int nPartons = 6;
4 
7  : jetsToken_(consumes<std::vector<pat::Jet> >(cfg.getParameter<edm::InputTag>("jets"))),
8  matchToken_(mayConsume<std::vector<std::vector<int> > >(cfg.getParameter<edm::InputTag>("match"))),
9  useOnlyMatch_(cfg.getParameter<bool>("useOnlyMatch")),
10  bTagAlgo_(cfg.getParameter<std::string>("bTagAlgo")),
11  minBTagValueBJet_(cfg.getParameter<double>("minBTagValueBJet")),
12  maxBTagValueNonBJet_(cfg.getParameter<double>("maxBTagValueNonBJet")),
13  useBTagging_(cfg.getParameter<bool>("useBTagging")),
14  bTags_(cfg.getParameter<unsigned int>("bTags")),
15  jetCorrectionLevel_(cfg.getParameter<std::string>("jetCorrectionLevel")),
16  maxNJets_(cfg.getParameter<int>("maxNJets")),
17  maxNComb_(cfg.getParameter<int>("maxNComb")),
18  maxNrIter_(cfg.getParameter<unsigned int>("maxNrIter")),
19  maxDeltaS_(cfg.getParameter<double>("maxDeltaS")),
20  maxF_(cfg.getParameter<double>("maxF")),
21  jetParam_(cfg.getParameter<unsigned>("jetParametrisation")),
22  constraints_(cfg.getParameter<std::vector<unsigned> >("constraints")),
23  mW_(cfg.getParameter<double>("mW")),
24  mTop_(cfg.getParameter<double>("mTop")),
25  jetEnergyResolutionScaleFactors_(cfg.getParameter<std::vector<double> >("jetEnergyResolutionScaleFactors")),
26  jetEnergyResolutionEtaBinning_(cfg.getParameter<std::vector<double> >("jetEnergyResolutionEtaBinning")) {
27  if (cfg.exists("udscResolutions") && cfg.exists("bResolutions")) {
28  udscResolutions_ = cfg.getParameter<std::vector<edm::ParameterSet> >("udscResolutions");
29  bResolutions_ = cfg.getParameter<std::vector<edm::ParameterSet> >("bResolutions");
30  } else if (cfg.exists("udscResolutions") || cfg.exists("bResolutions")) {
31  if (cfg.exists("udscResolutions"))
32  throw cms::Exception("Configuration")
33  << "Parameter 'bResolutions' is needed if parameter 'udscResolutions' is defined!\n";
34  else
35  throw cms::Exception("Configuration")
36  << "Parameter 'udscResolutions' is needed if parameter 'bResolutions' is defined!\n";
37  }
38 
39  // define kinematic fit interface
41  bTags_,
42  bTagAlgo_,
50  maxNJets_,
51  maxNComb_,
52  maxNrIter_,
53  maxDeltaS_,
54  maxF_,
55  jetParam_,
57  mW_,
58  mTop_);
59 
60  // produces the following collections
61  produces<std::vector<pat::Particle> >("PartonsB");
62  produces<std::vector<pat::Particle> >("PartonsBBar");
63  produces<std::vector<pat::Particle> >("PartonsLightQ");
64  produces<std::vector<pat::Particle> >("PartonsLightQBar");
65  produces<std::vector<pat::Particle> >("PartonsLightP");
66  produces<std::vector<pat::Particle> >("PartonsLightPBar");
67 
68  produces<std::vector<std::vector<int> > >();
69  produces<std::vector<double> >("Chi2");
70  produces<std::vector<double> >("Prob");
71  produces<std::vector<int> >("Status");
72 }
73 
76 
79  // get jet collection
81  event.getByToken(jetsToken_, jets);
82 
83  // get match in case that useOnlyMatch_ is true
84  std::vector<int> match;
85  bool invalidMatch = false;
86  if (useOnlyMatch_) {
88  // in case that only a ceratin match should be used, get match here
90  event.getByToken(matchToken_, matches);
91  match = *(matches->begin());
92  // check if match is valid
93  if (match.size() != nPartons) {
94  invalidMatch = true;
95  } else {
96  for (unsigned int idx = 0; idx < match.size(); ++idx) {
97  if (match[idx] < 0 || match[idx] >= (int)jets->size()) {
98  invalidMatch = true;
99  break;
100  }
101  }
102  }
104  kinFitter->setMatch(match);
105  }
106 
108  kinFitter->setMatchInvalidity(invalidMatch);
109 
110  std::list<TtFullHadKinFitter::KinFitResult> fitResults = kinFitter->fit(*jets);
111 
112  // pointer for output collections
113  std::unique_ptr<std::vector<pat::Particle> > pPartonsB(new std::vector<pat::Particle>);
114  std::unique_ptr<std::vector<pat::Particle> > pPartonsBBar(new std::vector<pat::Particle>);
115  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightQ(new std::vector<pat::Particle>);
116  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightQBar(new std::vector<pat::Particle>);
117  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightP(new std::vector<pat::Particle>);
118  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightPBar(new std::vector<pat::Particle>);
119  // pointer for meta information
120  std::unique_ptr<std::vector<std::vector<int> > > pCombi(new std::vector<std::vector<int> >);
121  std::unique_ptr<std::vector<double> > pChi2(new std::vector<double>);
122  std::unique_ptr<std::vector<double> > pProb(new std::vector<double>);
123  std::unique_ptr<std::vector<int> > pStatus(new std::vector<int>);
124 
125  unsigned int iComb = 0;
126  for (std::list<TtFullHadKinFitter::KinFitResult>::const_iterator res = fitResults.begin(); res != fitResults.end();
127  ++res) {
128  if (maxNComb_ >= 1 && iComb == (unsigned int)maxNComb_) {
129  break;
130  }
131  ++iComb;
132 
133  pPartonsB->push_back(res->B);
134  pPartonsBBar->push_back(res->BBar);
135  pPartonsLightQ->push_back(res->LightQ);
136  pPartonsLightQBar->push_back(res->LightQBar);
137  pPartonsLightP->push_back(res->LightP);
138  pPartonsLightPBar->push_back(res->LightPBar);
139 
140  pCombi->push_back(res->JetCombi);
141  pChi2->push_back(res->Chi2);
142  pProb->push_back(res->Prob);
143  pStatus->push_back(res->Status);
144  }
145 
146  event.put(std::move(pCombi));
147  event.put(std::move(pPartonsB), "PartonsB");
148  event.put(std::move(pPartonsBBar), "PartonsBBar");
149  event.put(std::move(pPartonsLightQ), "PartonsLightQ");
150  event.put(std::move(pPartonsLightQBar), "PartonsLightQBar");
151  event.put(std::move(pPartonsLightP), "PartonsLightP");
152  event.put(std::move(pPartonsLightPBar), "PartonsLightPBar");
153  event.put(std::move(pChi2), "Chi2");
154  event.put(std::move(pProb), "Prob");
155  event.put(std::move(pStatus), "Status");
156 }
157 
T getParameter(std::string const &) const
static const unsigned int nPartons
TtFullHadKinFitter::KinFit * kinFitter
kinematic fit interface
edm::EDGetTokenT< std::vector< std::vector< int > > > matchToken_
input tag for matches (in case the fit should be performed on certain matches)
void produce(edm::Event &event, const edm::EventSetup &setup) override
produce fitted object collections and meta data describing fit quality
void setUseOnlyMatch(bool useOnlyMatch)
set useOnlyMatch
bool exists(std::string const &parameterName) const
checks if a parameter exists
unsigned int jetParam_
numbering of different possible jet parametrizations
double mTop_
top mass value used for constraints
std::vector< unsigned > constraints_
numbering of different possible kinematic constraints
double mW_
W mass value used for constraints.
std::list< TtFullHadKinFitter::KinFitResult > fit(const std::vector< pat::Jet > &jets)
do the fitting and return fit result
Definition: Electron.h:6
std::vector< edm::ParameterSet > udscResolutions_
store the resolutions for the jets
class that does the fitting
Definition: HeavyIon.h:7
bool useBTagging_
switch to tell whether to use b-tagging or not
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setMatch(const std::vector< int > &match)
set match to be used
std::vector< edm::ParameterSet > bResolutions_
Definition: Jet.py:1
~TtFullHadKinFitProducer() override
default destructor
int maxNComb_
maximal number of combinations to be written to the event
std::string jetCorrectionLevel_
correction level for jets
double maxF_
maximal deviation for contstraints
double maxDeltaS_
maximal chi2 equivalent
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
input tag for jets
HLT enums.
unsigned int maxNrIter_
maximal number of iterations to be performed for the fit
std::string bTagAlgo_
input tag for b-tagging algorithm
std::vector< double > jetEnergyResolutionScaleFactors_
scale factors for jet energy resolution
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
int maxNJets_
maximal number of jets (-1 possible to indicate &#39;all&#39;)
double maxBTagValueNonBJet_
max value of bTag for a non-b-jet
unsigned int bTags_
minimal number of b-jets
std::vector< double > jetEnergyResolutionEtaBinning_
double minBTagValueBJet_
min value of bTag for a b-jet
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
TtFullHadKinFitProducer(const edm::ParameterSet &cfg)
default constructor
void setMatchInvalidity(bool invalidMatch)
set the validity of a match