1 #ifndef TtSemiLepHitFitProducer_h
2 #define TtSemiLepHitFitProducer_h
19 template <
typename LeptonCollection>
98 template <
typename LeptonCollection>
101 lepsToken_(consumes<LeptonCollection>(
cfg.getParameter<
edm::
InputTag>(
"leps"))),
103 maxNJets_(
cfg.getParameter<
int>(
"maxNJets")),
104 maxNComb_(
cfg.getParameter<
int>(
"maxNComb")),
106 minBTagValueBJet_(
cfg.getParameter<double>(
"minBDiscBJets")),
107 maxBTagValueNonBJet_(
cfg.getParameter<double>(
"maxBDiscLightJets")),
108 useBTag_(
cfg.getParameter<
bool>(
"useBTagging")),
109 mW_(
cfg.getParameter<double>(
"mW")),
110 mTop_(
cfg.getParameter<double>(
"mTop")),
111 jetCorrectionLevel_(
cfg.getParameter<
std::
string>(
"jetCorrectionLevel")),
112 jes_(
cfg.getParameter<double>(
"jes")),
113 jesB_(
cfg.getParameter<double>(
"jesB")),
117 hitfitDefault_(
cfg.getUntrackedParameter<
edm::FileInPath>(
119 edm::FileInPath(
std::
string(
"TopQuarkAnalysis/TopHitFit/data/setting/RunHitFitConfiguration.txt")))),
120 hitfitElectronResolution_(
cfg.getUntrackedParameter<
edm::FileInPath>(
122 edm::FileInPath(
std::
string(
"TopQuarkAnalysis/TopHitFit/data/resolution/tqafElectronResolution.txt")))),
123 hitfitMuonResolution_(
cfg.getUntrackedParameter<
edm::FileInPath>(
125 edm::FileInPath(
std::
string(
"TopQuarkAnalysis/TopHitFit/data/resolution/tqafMuonResolution.txt")))),
126 hitfitUdscJetResolution_(
cfg.getUntrackedParameter<
edm::FileInPath>(
128 edm::FileInPath(
std::
string(
"TopQuarkAnalysis/TopHitFit/data/resolution/tqafUdscJetResolution.txt")))),
129 hitfitBJetResolution_(
cfg.getUntrackedParameter<
edm::FileInPath>(
131 edm::FileInPath(
std::
string(
"TopQuarkAnalysis/TopHitFit/data/resolution/tqafBJetResolution.txt")))),
132 hitfitMETResolution_(
cfg.getUntrackedParameter<
edm::FileInPath>(
134 edm::FileInPath(
std::
string(
"TopQuarkAnalysis/TopHitFit/data/resolution/tqafKtResolution.txt")))),
138 electronTranslator_(hitfitElectronResolution_.
fullPath()),
139 muonTranslator_(hitfitMuonResolution_.
fullPath()),
141 hitfitUdscJetResolution_.
fullPath(), hitfitBJetResolution_.
fullPath(), jetCorrectionLevel_, jes_, jesB_),
142 metTranslator_(hitfitMETResolution_.
fullPath())
154 <<
"+++++++++++ TtSemiLepHitFitProducer ++++++++++++ \n"
155 <<
" Due to the eta ranges for which resolutions \n"
156 <<
" are provided in \n"
157 <<
" TopQuarkAnalysis/TopHitFit/data/resolution/ \n"
158 <<
" so far, the following cuts are currently \n"
159 <<
" implemented in the TtSemiLepHitFitProducer: \n"
160 <<
" |eta(muons )| <= " <<
maxEtaMu_ <<
" \n"
161 <<
" |eta(electrons)| <= " <<
maxEtaEle_ <<
" \n"
163 <<
"++++++++++++++++++++++++++++++++++++++++++++++++ \n";
165 produces<std::vector<pat::Particle> >(
"PartonsHadP");
166 produces<std::vector<pat::Particle> >(
"PartonsHadQ");
167 produces<std::vector<pat::Particle> >(
"PartonsHadB");
168 produces<std::vector<pat::Particle> >(
"PartonsLepB");
169 produces<std::vector<pat::Particle> >(
"Leptons");
170 produces<std::vector<pat::Particle> >(
"Neutrinos");
172 produces<std::vector<std::vector<int> > >();
173 produces<std::vector<double> >(
"Chi2");
174 produces<std::vector<double> >(
"Prob");
175 produces<std::vector<double> >(
"MT");
176 produces<std::vector<double> >(
"SigMT");
177 produces<std::vector<int> >(
"Status");
178 produces<int>(
"NumberOfConsideredJets");
181 template <
typename LeptonCollection>
186 template <
typename LeptonCollection>
188 std::unique_ptr<std::vector<pat::Particle> > pPartonsHadP(
new std::vector<pat::Particle>);
189 std::unique_ptr<std::vector<pat::Particle> > pPartonsHadQ(
new std::vector<pat::Particle>);
190 std::unique_ptr<std::vector<pat::Particle> > pPartonsHadB(
new std::vector<pat::Particle>);
191 std::unique_ptr<std::vector<pat::Particle> > pPartonsLepB(
new std::vector<pat::Particle>);
192 std::unique_ptr<std::vector<pat::Particle> > pLeptons(
new std::vector<pat::Particle>);
193 std::unique_ptr<std::vector<pat::Particle> > pNeutrinos(
new std::vector<pat::Particle>);
195 std::unique_ptr<std::vector<std::vector<int> > > pCombi(
new std::vector<std::vector<int> >);
196 std::unique_ptr<std::vector<double> > pChi2(
new std::vector<double>);
197 std::unique_ptr<std::vector<double> > pProb(
new std::vector<double>);
198 std::unique_ptr<std::vector<double> > pMT(
new std::vector<double>);
199 std::unique_ptr<std::vector<double> > pSigMT(
new std::vector<double>);
200 std::unique_ptr<std::vector<int> > pStatus(
new std::vector<int>);
201 std::unique_ptr<int> pJetsConsidered(
new int);
223 bool foundLepton =
false;
224 if (!
leps->empty()) {
225 double maxEtaLep = maxEtaMu_;
226 if (!dynamic_cast<const reco::Muon*>(&((*
leps)[0])))
227 maxEtaLep = maxEtaEle_;
228 for (
unsigned iLep = 0; iLep < (*leps).size() && !foundLepton; ++iLep) {
230 HitFit->AddLepton((*
leps)[iLep]);
237 unsigned int nJetsFound = 0;
238 for (
unsigned iJet = 0; iJet < (*jets).size() && (
int)nJetsFound != maxNJets_; ++iJet) {
239 double jet_eta = (*jets)[iJet].eta();
240 if ((*
jets)[iJet].isCaloJet()) {
241 jet_eta = ((
reco::CaloJet*)((*
jets)[iJet]).originalObject())->detectorP4().eta();
243 if (
std::abs(jet_eta) <= maxEtaJet_) {
244 HitFit->AddJet((*
jets)[iJet]);
248 *pJetsConsidered = nJetsFound;
252 HitFit->SetMet((*
mets)[0]);
254 if (!foundLepton ||
mets->empty() || nJetsFound <
nPartons) {
263 std::vector<int> invalidCombi;
265 invalidCombi.push_back(-1);
266 pCombi->push_back(invalidCombi);
268 pChi2->push_back(-1.);
270 pProb->push_back(-1.);
273 pSigMT->push_back(-1.);
275 pStatus->push_back(-1);
289 evt.
put(
std::move(pJetsConsidered),
"NumberOfConsideredJets");
293 std::list<FitResult> FitResultList;
306 size_t nHitFitJet = 0;
309 std::vector<hitfit::Fit_Result> hitFitResult;
317 nHitFit = HitFit->FitAllPermutation();
324 nHitFitJet = HitFit->GetUnfittedEvent()[0].njets();
327 hitFitResult = HitFit->GetFitAllPermutation();
330 for (
size_t fit = 0;
fit != nHitFit; ++
fit) {
341 std::vector<int> hitCombi(4);
342 for (
size_t jet = 0;
jet != nHitFitJet; ++
jet) {
380 if (hitFitResult[
fit].chisq() > 0
390 result.Prob =
exp(-1.0 * (hitFitResult[
fit].chisq()) / 2.0);
392 result.SigMT = hitFitResult[
fit].sigmt();
406 fittedEvent.
met().x(), fittedEvent.
met().y(), fittedEvent.
met().z(), fittedEvent.
met().t()),
408 result.JetCombi = hitCombi;
410 FitResultList.push_back(
result);
415 FitResultList.sort();
422 if (((
unsigned)FitResultList.size()) < 1) {
430 std::vector<int> invalidCombi;
432 invalidCombi.push_back(-1);
433 pCombi->push_back(invalidCombi);
435 pChi2->push_back(-1.);
437 pProb->push_back(-1.);
440 pSigMT->push_back(-1.);
442 pStatus->push_back(-1);
444 unsigned int iComb = 0;
445 for (
typename std::list<FitResult>::const_iterator
result = FitResultList.begin();
result != FitResultList.end();
447 if (maxNComb_ >= 1 && iComb == (
unsigned int)maxNComb_)
451 pPartonsHadP->push_back(
result->HadP);
452 pPartonsHadQ->push_back(
result->HadQ);
453 pPartonsHadB->push_back(
result->HadB);
454 pPartonsLepB->push_back(
result->LepB);
456 pLeptons->push_back(
result->LepL);
458 pNeutrinos->push_back(
result->LepN);
460 pCombi->push_back(
result->JetCombi);
462 pChi2->push_back(
result->Chi2);
464 pProb->push_back(
result->Prob);
466 pMT->push_back(
result->MT);
467 pSigMT->push_back(
result->SigMT);
469 pStatus->push_back(
result->Status);
484 evt.
put(
std::move(pJetsConsidered),
"NumberOfConsideredJets");