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>
98 lepsToken_(consumes<LeptonCollection>(
cfg.getParameter<
edm::
InputTag>(
"leps"))),
101 useOnlyMatch_(
cfg.getParameter<
bool>(
"useOnlyMatch")),
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")) {
126 bResolutions_ =
cfg.getParameter<std::vector<edm::ParameterSet>>(
"bResolutions");
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());
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;
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) {