1 #ifndef TtSemiLepKinFitProducer_h
2 #define TtSemiLepKinFitProducer_h
12 template <
typename LeptonCollection>
27 std::vector<TtSemiLepKinFitter::Constraint>
constraints(std::vector<unsigned>&);
31 std::vector<int>& combi,
33 double& minBTagValueBJets_,
34 double& maxBTagValueNonBJets_);
95 template <
typename LeptonCollection>
97 : jetsToken_(consumes<std::
vector<pat::
Jet>>(cfg.getParameter<edm::
InputTag>(
"jets"))),
98 lepsToken_(consumes<LeptonCollection>(cfg.getParameter<edm::
InputTag>(
"leps"))),
99 metsToken_(consumes<std::
vector<pat::
MET>>(cfg.getParameter<edm::
InputTag>(
"mets"))),
100 matchToken_(mayConsume<std::
vector<std::
vector<int>>>(cfg.getParameter<edm::
InputTag>(
"match"))),
101 useOnlyMatch_(cfg.getParameter<bool>(
"useOnlyMatch")),
102 bTagAlgo_(cfg.getParameter<std::
string>(
"bTagAlgo")),
103 minBTagValueBJet_(cfg.getParameter<double>(
"minBDiscBJets")),
104 maxBTagValueNonBJet_(cfg.getParameter<double>(
"maxBDiscLightJets")),
105 useBTag_(cfg.getParameter<bool>(
"useBTagging")),
106 maxNJets_(cfg.getParameter<int>(
"maxNJets")),
107 maxNComb_(cfg.getParameter<int>(
"maxNComb")),
108 maxNrIter_(cfg.getParameter<unsigned>(
"maxNrIter")),
109 maxDeltaS_(cfg.getParameter<double>(
"maxDeltaS")),
110 maxF_(cfg.getParameter<double>(
"maxF")),
111 jetParam_(cfg.getParameter<unsigned>(
"jetParametrisation")),
112 lepParam_(cfg.getParameter<unsigned>(
"lepParametrisation")),
113 metParam_(cfg.getParameter<unsigned>(
"metParametrisation")),
114 constraints_(cfg.getParameter<std::
vector<unsigned>>(
"constraints")),
115 mW_(cfg.getParameter<double>(
"mW")),
116 mTop_(cfg.getParameter<double>(
"mTop")),
117 jetEnergyResolutionScaleFactors_(cfg.getParameter<std::
vector<double>>(
"jetEnergyResolutionScaleFactors")),
118 jetEnergyResolutionEtaBinning_(cfg.getParameter<std::
vector<double>>(
"jetEnergyResolutionEtaBinning")),
123 if (cfg.
exists(
"udscResolutions") && cfg.
exists(
"bResolutions") && cfg.
exists(
"lepResolutions") &&
124 cfg.
exists(
"metResolutions")) {
129 }
else if (cfg.
exists(
"udscResolutions") || cfg.
exists(
"bResolutions") || cfg.
exists(
"lepResolutions") ||
130 cfg.
exists(
"metResolutions")) {
131 throw cms::Exception(
"Configuration") <<
"Parameters 'udscResolutions', 'bResolutions', 'lepResolutions', "
132 "'metResolutions' should be used together.\n";
151 produces<std::vector<pat::Particle>>(
"PartonsHadP");
152 produces<std::vector<pat::Particle>>(
"PartonsHadQ");
153 produces<std::vector<pat::Particle>>(
"PartonsHadB");
154 produces<std::vector<pat::Particle>>(
"PartonsLepB");
155 produces<std::vector<pat::Particle>>(
"Leptons");
156 produces<std::vector<pat::Particle>>(
"Neutrinos");
158 produces<std::vector<std::vector<int>>>();
159 produces<std::vector<double>>(
"Chi2");
160 produces<std::vector<double>>(
"Prob");
161 produces<std::vector<int>>(
"Status");
163 produces<int>(
"NumberOfConsideredJets");
166 template <
typename LeptonCollection>
171 template <
typename LeptonCollection>
174 std::vector<int>& combi,
176 double& minBTagValueBJet_,
177 double& maxBTagValueNonBJet_) {
191 template <
typename LeptonCollection>
193 std::unique_ptr<std::vector<pat::Particle>> pPartonsHadP(
new std::vector<pat::Particle>);
194 std::unique_ptr<std::vector<pat::Particle>> pPartonsHadQ(
new std::vector<pat::Particle>);
195 std::unique_ptr<std::vector<pat::Particle>> pPartonsHadB(
new std::vector<pat::Particle>);
196 std::unique_ptr<std::vector<pat::Particle>> pPartonsLepB(
new std::vector<pat::Particle>);
197 std::unique_ptr<std::vector<pat::Particle>> pLeptons(
new std::vector<pat::Particle>);
198 std::unique_ptr<std::vector<pat::Particle>> pNeutrinos(
new std::vector<pat::Particle>);
200 std::unique_ptr<std::vector<std::vector<int>>> pCombi(
new std::vector<std::vector<int>>);
201 std::unique_ptr<std::vector<double>> pChi2(
new std::vector<double>);
202 std::unique_ptr<std::vector<double>> pProb(
new std::vector<double>);
203 std::unique_ptr<std::vector<int>> pStatus(
new std::vector<int>);
205 std::unique_ptr<int> pJetsConsidered(
new int);
218 std::vector<int>
match;
219 bool invalidMatch =
false;
224 match = *(matchHandle->begin());
229 for (
unsigned int idx = 0; idx < match.size(); ++idx) {
230 if (match[idx] < 0 || match[idx] >= (
int)jets->size()) {
243 if (leps->empty() || mets->empty() || jets->size() < nPartons || invalidMatch) {
245 pPartonsHadP->push_back(fitter->fittedHadP());
246 pPartonsHadQ->push_back(fitter->fittedHadQ());
247 pPartonsHadB->push_back(fitter->fittedHadB());
248 pPartonsLepB->push_back(fitter->fittedLepB());
249 pLeptons->push_back(fitter->fittedLepton());
250 pNeutrinos->push_back(fitter->fittedNeutrino());
252 std::vector<int> invalidCombi;
254 invalidCombi.push_back(-1);
255 pCombi->push_back(invalidCombi);
257 pChi2->push_back(-1.);
259 pProb->push_back(-1.);
261 pStatus->push_back(-1);
263 *pJetsConsidered = jets->size();
275 evt.
put(
std::move(pJetsConsidered),
"NumberOfConsideredJets");
284 std::vector<int> jetIndices;
285 if (!useOnlyMatch_) {
286 for (
unsigned int i = 0;
i < jets->size(); ++
i) {
287 if (maxNJets_ >= (
int)nPartons && maxNJets_ == (int)
i) {
288 *pJetsConsidered =
i;
291 jetIndices.push_back(
i);
295 std::vector<int> combi;
298 combi.push_back(match[
i]);
303 std::list<KinFitResult> FitResultList;
306 for (
int cnt = 0; cnt < TMath::Factorial(combi.size()); ++cnt) {
310 doBTagging(useBTag_, jets, combi, bTagAlgo_, minBTagValueBJet_, maxBTagValueNonBJet_)) {
311 std::vector<pat::Jet> jetCombi;
312 jetCombi.resize(nPartons);
319 const int status = fitter->fit(jetCombi, (*leps)[0], (*mets)[0]);
324 result.
Chi2 = fitter->fitS();
325 result.
Prob = fitter->fitProb();
326 result.
HadB = fitter->fittedHadB();
327 result.
HadP = fitter->fittedHadP();
328 result.
HadQ = fitter->fittedHadQ();
329 result.
LepB = fitter->fittedLepB();
330 result.
LepL = fitter->fittedLepton();
331 result.
LepN = fitter->fittedNeutrino();
334 FitResultList.push_back(result);
339 next_permutation(combi.begin(), combi.end());
346 FitResultList.sort();
353 if ((
unsigned)FitResultList.size() < 1) {
354 pPartonsHadP->push_back(fitter->fittedHadP());
355 pPartonsHadQ->push_back(fitter->fittedHadQ());
356 pPartonsHadB->push_back(fitter->fittedHadB());
357 pPartonsLepB->push_back(fitter->fittedLepB());
358 pLeptons->push_back(fitter->fittedLepton());
359 pNeutrinos->push_back(fitter->fittedNeutrino());
361 std::vector<int> invalidCombi;
363 invalidCombi.push_back(-1);
364 pCombi->push_back(invalidCombi);
366 pChi2->push_back(-1.);
368 pProb->push_back(-1.);
370 pStatus->push_back(-1);
372 unsigned int iComb = 0;
373 for (
typename std::list<KinFitResult>::const_iterator
result = FitResultList.begin();
result != FitResultList.end();
375 if (maxNComb_ >= 1 && iComb == (
unsigned int)maxNComb_)
379 pPartonsHadP->push_back(
result->HadP);
380 pPartonsHadQ->push_back(
result->HadQ);
381 pPartonsHadB->push_back(
result->HadB);
382 pPartonsLepB->push_back(
result->LepB);
384 pLeptons->push_back(
result->LepL);
386 pNeutrinos->push_back(
result->LepN);
388 pCombi->push_back(
result->JetCombi);
390 pChi2->push_back(
result->Chi2);
392 pProb->push_back(
result->Prob);
394 pStatus->push_back(
result->Status);
407 evt.
put(
std::move(pJetsConsidered),
"NumberOfConsideredJets");
410 template <
typename LeptonCollection>
424 throw cms::Exception(
"Configuration") <<
"Chosen jet parametrization is not supported: " << val <<
"\n";
430 template <
typename LeptonCollection>
456 throw cms::Exception(
"Configuration") <<
"Chosen fit constraint is not supported: " << val <<
"\n";
462 template <
typename LeptonCollection>
464 std::vector<unsigned>&
val) {
465 std::vector<TtSemiLepKinFitter::Constraint>
result;
466 for (
unsigned i = 0;
i < val.size(); ++
i) {
std::vector< edm::ParameterSet > bResolutions_
std::vector< double > jetEnergyResolutionScaleFactors_
scale factors for jet energy resolution
double maxBTagValueNonBJet_
max value of bTag for a non-b-jet
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
std::string bTagAlgo_
input tag for b-tagging algorithm
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
static const unsigned int nPartons
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
double minBTagValueBJet_
min value of bTag for a b-jet
Param
supported parameterizations
std::vector< int > JetCombi
std::vector< TtSemiLepKinFitter::Constraint > constraints(std::vector< unsigned > &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
~TtSemiLepKinFitProducer() override
int maxNJets_
maximal number of jets (-1 possible to indicate 'all')
bool doBTagging(bool &useBTag_, edm::Handle< std::vector< pat::Jet >> &jets, std::vector< int > &combi, std::string &bTagAlgo_, double &minBTagValueBJets_, double &maxBTagValueNonBJets_)
std::vector< double > jetEnergyResolutionEtaBinning_
edm::EDGetTokenT< std::vector< std::vector< int > > > matchToken_
TtSemiLepKinFitter * fitter
std::vector< unsigned > constraints_
constrains
unsigned int maxNrIter_
maximal number of iterations to be performed for the fit
bool operator<(const KinFitResult &rhs)
std::vector< edm::ParameterSet > udscResolutions_
config-file-based object resolutions
int maxNComb_
maximal number of combinations to be written to the event
double maxF_
maximal deviation for contstraints
edm::EDGetTokenT< LeptonCollection > lepsToken_
std::vector< edm::ParameterSet > metResolutions_
Analysis-level particle class.
T getParameter(std::string const &) const
void produce(edm::Event &, const edm::EventSetup &) override
TtSemiLepKinFitter::Constraint constraint(unsigned)
bool useOnlyMatch_
switch to use only a combination given by another hypothesis
bool useBTag_
switch to tell whether to use b-tagging or not
TtSemiLepKinFitter::Param param(unsigned)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
TtSemiLepKinFitProducer(const edm::ParameterSet &)
double maxDeltaS_
maximal chi2 equivalent
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
std::vector< edm::ParameterSet > lepResolutions_
Constraint
supported constraints