1 #ifndef TtSemiLepKinFitProducer_h
2 #define TtSemiLepKinFitProducer_h
12 template <
typename LeptonCollection>
29 std::vector<TtSemiLepKinFitter::Constraint>
constraints(std::vector<unsigned>&);
93 template<
typename LeptonCollection>
95 jetsToken_ (consumes<std::vector<pat::
Jet> >(cfg.getParameter<edm::
InputTag>(
"jets"))),
96 lepsToken_ (consumes<LeptonCollection>(cfg.getParameter<edm::
InputTag>(
"leps"))),
97 metsToken_ (consumes<std::vector<pat::
MET> >(cfg.getParameter<edm::
InputTag>(
"mets"))),
98 matchToken_ (mayConsume<std::vector<std::vector<int> > >(cfg.getParameter<edm::
InputTag>(
"match"))),
99 useOnlyMatch_ (cfg.getParameter<bool> (
"useOnlyMatch" )),
100 bTagAlgo_ (cfg.getParameter<std::
string> (
"bTagAlgo" )),
101 minBTagValueBJet_ (cfg.getParameter<double> (
"minBDiscBJets" )),
102 maxBTagValueNonBJet_ (cfg.getParameter<double> (
"maxBDiscLightJets" )),
103 useBTag_ (cfg.getParameter<bool> (
"useBTagging" )),
104 maxNJets_ (cfg.getParameter<int> (
"maxNJets" )),
105 maxNComb_ (cfg.getParameter<int> (
"maxNComb" )),
106 maxNrIter_ (cfg.getParameter<unsigned> (
"maxNrIter" )),
107 maxDeltaS_ (cfg.getParameter<double> (
"maxDeltaS" )),
108 maxF_ (cfg.getParameter<double> (
"maxF" )),
109 jetParam_ (cfg.getParameter<unsigned> (
"jetParametrisation" )),
110 lepParam_ (cfg.getParameter<unsigned> (
"lepParametrisation" )),
111 metParam_ (cfg.getParameter<unsigned> (
"metParametrisation" )),
112 constraints_ (cfg.getParameter<std::vector<unsigned> >(
"constraints")),
113 mW_ (cfg.getParameter<double> (
"mW" )),
114 mTop_ (cfg.getParameter<double> (
"mTop" )),
115 jetEnergyResolutionScaleFactors_(cfg.getParameter<std::vector<double> >(
"jetEnergyResolutionScaleFactors")),
116 jetEnergyResolutionEtaBinning_ (cfg.getParameter<std::vector<double> >(
"jetEnergyResolutionEtaBinning")),
117 udscResolutions_(0), bResolutions_(0), lepResolutions_(0), metResolutions_(0)
119 if(cfg.
exists(
"udscResolutions") && cfg.
exists(
"bResolutions") && cfg.
exists(
"lepResolutions") && cfg.
exists(
"metResolutions")){
125 else if(cfg.
exists(
"udscResolutions") || cfg.
exists(
"bResolutions") || cfg.
exists(
"lepResolutions") || cfg.
exists(
"metResolutions") ){
126 throw cms::Exception(
"Configuration") <<
"Parameters 'udscResolutions', 'bResolutions', 'lepResolutions', 'metResolutions' should be used together.\n";
133 produces< std::vector<pat::Particle> >(
"PartonsHadP");
134 produces< std::vector<pat::Particle> >(
"PartonsHadQ");
135 produces< std::vector<pat::Particle> >(
"PartonsHadB");
136 produces< std::vector<pat::Particle> >(
"PartonsLepB");
137 produces< std::vector<pat::Particle> >(
"Leptons");
138 produces< std::vector<pat::Particle> >(
"Neutrinos");
140 produces< std::vector<std::vector<int> > >();
141 produces< std::vector<double> >(
"Chi2");
142 produces< std::vector<double> >(
"Prob");
143 produces< std::vector<int> >(
"Status");
145 produces<int>(
"NumberOfConsideredJets");
148 template<
typename LeptonCollection>
154 template<
typename LeptonCollection>
156 std::string& bTagAlgo_,
double& minBTagValueBJet_,
double& maxBTagValueNonBJet_){
173 template<
typename LeptonCollection>
176 std::auto_ptr< std::vector<pat::Particle> > pPartonsHadP(
new std::vector<pat::Particle> );
177 std::auto_ptr< std::vector<pat::Particle> > pPartonsHadQ(
new std::vector<pat::Particle> );
178 std::auto_ptr< std::vector<pat::Particle> > pPartonsHadB(
new std::vector<pat::Particle> );
179 std::auto_ptr< std::vector<pat::Particle> > pPartonsLepB(
new std::vector<pat::Particle> );
180 std::auto_ptr< std::vector<pat::Particle> > pLeptons (
new std::vector<pat::Particle> );
181 std::auto_ptr< std::vector<pat::Particle> > pNeutrinos (
new std::vector<pat::Particle> );
183 std::auto_ptr< std::vector<std::vector<int> > > pCombi (
new std::vector<std::vector<int> > );
184 std::auto_ptr< std::vector<double> > pChi2 (
new std::vector<double> );
185 std::auto_ptr< std::vector<double> > pProb (
new std::vector<double> );
186 std::auto_ptr< std::vector<int> > pStatus(
new std::vector<int> );
188 std::auto_ptr<int> pJetsConsidered(
new int);
201 std::vector<int>
match;
202 bool invalidMatch =
false;
207 match = *(matchHandle->begin());
209 if(match.size()!=
nPartons) invalidMatch=
true;
211 for(
unsigned int idx=0;
idx<match.size(); ++
idx) {
212 if(match[
idx]<0 || match[
idx]>=(
int)jets->size()) {
225 if( leps->empty() || mets->empty() || jets->size()<nPartons || invalidMatch ) {
227 pPartonsHadP->push_back( fitter->fittedHadP() );
228 pPartonsHadQ->push_back( fitter->fittedHadQ() );
229 pPartonsHadB->push_back( fitter->fittedHadB() );
230 pPartonsLepB->push_back( fitter->fittedLepB() );
231 pLeptons ->push_back( fitter->fittedLepton() );
232 pNeutrinos ->push_back( fitter->fittedNeutrino() );
234 std::vector<int> invalidCombi;
236 invalidCombi.push_back( -1 );
237 pCombi->push_back( invalidCombi );
239 pChi2->push_back( -1. );
241 pProb->push_back( -1. );
243 pStatus->push_back( -1 );
245 *pJetsConsidered = jets->size();
248 evt.
put(pPartonsHadP,
"PartonsHadP");
249 evt.
put(pPartonsHadQ,
"PartonsHadQ");
250 evt.
put(pPartonsHadB,
"PartonsHadB");
251 evt.
put(pPartonsLepB,
"PartonsLepB");
252 evt.
put(pLeptons ,
"Leptons" );
253 evt.
put(pNeutrinos ,
"Neutrinos" );
254 evt.
put(pChi2 ,
"Chi2" );
255 evt.
put(pProb ,
"Prob" );
256 evt.
put(pStatus ,
"Status" );
257 evt.
put(pJetsConsidered,
"NumberOfConsideredJets");
266 std::vector<int> jetIndices;
268 for(
unsigned int i=0;
i<jets->size(); ++
i){
269 if(maxNJets_ >= (
int) nPartons && maxNJets_ == (int)
i) {
270 *pJetsConsidered =
i;
273 jetIndices.push_back(
i);
277 std::vector<int> combi;
279 if(useOnlyMatch_) combi.push_back( match[
i] );
280 else combi.push_back(i);
283 std::list<KinFitResult> FitResultList;
286 for(
int cnt = 0; cnt < TMath::Factorial( combi.size() ); ++cnt){
290 || useOnlyMatch_ ) && doBTagging(useBTag_, jets, combi, bTagAlgo_, minBTagValueBJet_, maxBTagValueNonBJet_) ){
292 std::vector<pat::Jet> jetCombi;
293 jetCombi.resize(nPartons);
300 const int status = fitter->fit(jetCombi, (*leps)[0], (*mets)[0]);
305 result.
Chi2 = fitter->fitS();
306 result.
Prob = fitter->fitProb();
307 result.
HadB = fitter->fittedHadB();
308 result.
HadP = fitter->fittedHadP();
309 result.
HadQ = fitter->fittedHadQ();
310 result.
LepB = fitter->fittedLepB();
311 result.
LepL = fitter->fittedLepton();
312 result.
LepN = fitter->fittedNeutrino();
315 FitResultList.push_back(result);
319 if(useOnlyMatch_)
break;
320 next_permutation( combi.begin(), combi.end() );
322 if(useOnlyMatch_)
break;
327 FitResultList.sort();
334 if( (
unsigned)FitResultList.size() < 1 ) {
335 pPartonsHadP->push_back( fitter->fittedHadP() );
336 pPartonsHadQ->push_back( fitter->fittedHadQ() );
337 pPartonsHadB->push_back( fitter->fittedHadB() );
338 pPartonsLepB->push_back( fitter->fittedLepB() );
339 pLeptons ->push_back( fitter->fittedLepton() );
340 pNeutrinos ->push_back( fitter->fittedNeutrino() );
342 std::vector<int> invalidCombi;
344 invalidCombi.push_back( -1 );
345 pCombi->push_back( invalidCombi );
347 pChi2->push_back( -1. );
349 pProb->push_back( -1. );
351 pStatus->push_back( -1 );
354 unsigned int iComb = 0;
355 for(
typename std::list<KinFitResult>::const_iterator
result = FitResultList.begin();
result != FitResultList.end(); ++
result) {
356 if(maxNComb_ >= 1 && iComb == (
unsigned int) maxNComb_)
break;
359 pPartonsHadP->push_back(
result->HadP );
360 pPartonsHadQ->push_back(
result->HadQ );
361 pPartonsHadB->push_back(
result->HadB );
362 pPartonsLepB->push_back(
result->LepB );
364 pLeptons->push_back(
result->LepL );
366 pNeutrinos->push_back(
result->LepN );
368 pCombi->push_back(
result->JetCombi );
370 pChi2->push_back(
result->Chi2 );
372 pProb->push_back(
result->Prob );
374 pStatus->push_back(
result->Status );
378 evt.
put(pPartonsHadP,
"PartonsHadP");
379 evt.
put(pPartonsHadQ,
"PartonsHadQ");
380 evt.
put(pPartonsHadB,
"PartonsHadB");
381 evt.
put(pPartonsLepB,
"PartonsLepB");
382 evt.
put(pLeptons ,
"Leptons" );
383 evt.
put(pNeutrinos ,
"Neutrinos" );
384 evt.
put(pChi2 ,
"Chi2" );
385 evt.
put(pProb ,
"Prob" );
386 evt.
put(pStatus ,
"Status" );
387 evt.
put(pJetsConsidered,
"NumberOfConsideredJets");
390 template<
typename LeptonCollection>
400 <<
"Chosen jet parametrization is not supported: " << val <<
"\n";
406 template<
typename LeptonCollection>
420 <<
"Chosen fit constraint is not supported: " << val <<
"\n";
426 template<
typename LeptonCollection>
429 std::vector<TtSemiLepKinFitter::Constraint>
result;
430 for(
unsigned i=0;
i<val.size(); ++
i){
std::vector< edm::ParameterSet > bResolutions_
std::vector< double > jetEnergyResolutionScaleFactors_
scale factors for jet energy resolution
T getParameter(std::string const &) const
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
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
virtual void produce(edm::Event &, const edm::EventSetup &)
int maxNJets_
maximal number of jets (-1 possible to indicate 'all')
std::vector< double > jetEnergyResolutionEtaBinning_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
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
bool doBTagging(bool &useBTag_, edm::Handle< std::vector< pat::Jet > > &jets, std::vector< int > &combi, std::string &bTagAlgo_, double &minBTagValueBJets_, double &maxBTagValueNonBJets_)
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_
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
Analysis-level particle class.
~TtSemiLepKinFitProducer()
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_
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Constraint
supported constraints