test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TtSemiLepKinFitter.cc
Go to the documentation of this file.
8 
11 
13 
16  TopKinFitter(),
17  hadB_(0), hadP_(0), hadQ_(0), lepB_(0), lepton_(0), neutrino_(0),
18  udscResolutions_(0), bResolutions_(0), lepResolutions_(0), metResolutions_(0),
19  jetEnergyResolutionScaleFactors_(0), jetEnergyResolutionEtaBinning_(0),
20  jetParam_(kEMom), lepParam_(kEMom), metParam_(kEMom)
21 {
22  setupFitter();
23 }
24 
26  int maxNrIter, double maxDeltaS, double maxF,
27  const std::vector<Constraint>& constraints, double mW, double mTop,
28  const std::vector<edm::ParameterSet>* udscResolutions,
29  const std::vector<edm::ParameterSet>* bResolutions,
30  const std::vector<edm::ParameterSet>* lepResolutions,
31  const std::vector<edm::ParameterSet>* metResolutions,
32  const std::vector<double>* jetEnergyResolutionScaleFactors,
33  const std::vector<double>* jetEnergyResolutionEtaBinning):
34  TopKinFitter(maxNrIter, maxDeltaS, maxF, mW, mTop),
35  hadB_(0), hadP_(0), hadQ_(0), lepB_(0), lepton_(0), neutrino_(0),
36  udscResolutions_(udscResolutions), bResolutions_(bResolutions), lepResolutions_(lepResolutions), metResolutions_(metResolutions),
37  jetEnergyResolutionScaleFactors_(jetEnergyResolutionScaleFactors), jetEnergyResolutionEtaBinning_(jetEnergyResolutionEtaBinning),
38  jetParam_(jetParam), lepParam_(lepParam), metParam_(metParam), constrList_(constraints)
39 {
40  setupFitter();
41 }
42 
44 {
45  delete hadB_;
46  delete hadP_;
47  delete hadQ_;
48  delete lepB_;
49  delete lepton_;
50  delete neutrino_;
51  delete covM_;
52  for(std::map<Constraint, TFitConstraintM*>::iterator it = massConstr_.begin(); it != massConstr_.end(); ++it)
53  delete it->second;
54  delete sumPxConstr_;
55  delete sumPyConstr_;
56 }
57 
59 {
60  std::stringstream constr;
61  for(unsigned int i=0; i<constrList_.size(); ++i){
62  switch(constrList_[i]){
63  case kWHadMass : constr << " * hadronic W-mass (" << mW_ << " GeV) \n"; break;
64  case kWLepMass : constr << " * leptonic W-mass (" << mW_ << " GeV) \n"; break;
65  case kTopHadMass : constr << " * hadronic t-mass (" << mTop_ << " GeV) \n"; break;
66  case kTopLepMass : constr << " * leptonic t-mass (" << mTop_ << " GeV) \n"; break;
67  case kNeutrinoMass : constr << " * neutrino mass (0 GeV) \n"; break;
68  case kEqualTopMasses : constr << " * equal t-masses \n"; break;
69  case kSumPt : constr << " * summed transverse momentum \n"; break;
70  }
71  }
72  edm::LogVerbatim( "TtSemiLepKinFitter" )
73  << "\n"
74  << "+++++++++++ TtSemiLepKinFitter Setup ++++++++++++ \n"
75  << " Parametrization: \n"
76  << " * jet : " << param(jetParam_) << "\n"
77  << " * lep : " << param(lepParam_) << "\n"
78  << " * met : " << param(metParam_) << "\n"
79  << " Constraints: \n"
80  << constr.str()
81  << " Max(No iterations): " << maxNrIter_ << "\n"
82  << " Max(deltaS) : " << maxDeltaS_ << "\n"
83  << " Max(F) : " << maxF_ << "\n"
84  << "+++++++++++++++++++++++++++++++++++++++++++++++++ \n";
85 }
86 
88 {
89  TMatrixD empty3x3(3,3);
90  TMatrixD empty4x4(4,4);
91  switch(jetParam_){ // setup jets according to parameterization
92  case kEMom :
93  hadB_= new TFitParticleEMomDev ("Jet1", "Jet1", 0, &empty4x4);
94  hadP_= new TFitParticleEMomDev ("Jet2", "Jet2", 0, &empty4x4);
95  hadQ_= new TFitParticleEMomDev ("Jet3", "Jet3", 0, &empty4x4);
96  lepB_= new TFitParticleEMomDev ("Jet4", "Jet4", 0, &empty4x4);
97  break;
98  case kEtEtaPhi :
99  hadB_= new TFitParticleEtEtaPhi ("Jet1", "Jet1", 0, &empty3x3);
100  hadP_= new TFitParticleEtEtaPhi ("Jet2", "Jet2", 0, &empty3x3);
101  hadQ_= new TFitParticleEtEtaPhi ("Jet3", "Jet3", 0, &empty3x3);
102  lepB_= new TFitParticleEtEtaPhi ("Jet4", "Jet4", 0, &empty3x3);
103  break;
104  case kEtThetaPhi :
105  hadB_= new TFitParticleEtThetaPhi("Jet1", "Jet1", 0, &empty3x3);
106  hadP_= new TFitParticleEtThetaPhi("Jet2", "Jet2", 0, &empty3x3);
107  hadQ_= new TFitParticleEtThetaPhi("Jet3", "Jet3", 0, &empty3x3);
108  lepB_= new TFitParticleEtThetaPhi("Jet4", "Jet4", 0, &empty3x3);
109  break;
110  }
111 }
112 
114 {
115  TMatrixD empty3x3(3,3);
116  switch(lepParam_){ // setup lepton according to parameterization
117  case kEMom : lepton_ = new TFitParticleEScaledMomDev("Lepton", "Lepton", 0, &empty3x3); break;
118  case kEtEtaPhi : lepton_ = new TFitParticleEtEtaPhi ("Lepton", "Lepton", 0, &empty3x3); break;
119  case kEtThetaPhi : lepton_ = new TFitParticleEtThetaPhi ("Lepton", "Lepton", 0, &empty3x3); break;
120  }
121  switch(metParam_){ // setup neutrino according to parameterization
122  case kEMom : neutrino_= new TFitParticleEScaledMomDev("Neutrino", "Neutrino", 0, &empty3x3); break;
123  case kEtEtaPhi : neutrino_= new TFitParticleEtEtaPhi ("Neutrino", "Neutrino", 0, &empty3x3); break;
124  case kEtThetaPhi : neutrino_= new TFitParticleEtThetaPhi ("Neutrino", "Neutrino", 0, &empty3x3); break;
125  }
126 }
127 
129 {
130  massConstr_[kWHadMass ] = new TFitConstraintM("WMassHad", "WMassHad", 0, 0, mW_ );
131  massConstr_[kWLepMass ] = new TFitConstraintM("WMassLep", "WMassLep", 0, 0, mW_ );
132  massConstr_[kTopHadMass ] = new TFitConstraintM("TopMassHad", "TopMassHad", 0, 0, mTop_);
133  massConstr_[kTopLepMass ] = new TFitConstraintM("TopMassLep", "TopMassLep", 0, 0, mTop_);
134  massConstr_[kNeutrinoMass ] = new TFitConstraintM("NeutrinoMass", "NeutrinoMass", 0, 0, 0.);
135  massConstr_[kEqualTopMasses] = new TFitConstraintM("EqualTopMasses","EqualTopMasses",0, 0, 0.);
136  sumPxConstr_ = new TFitConstraintEp("SumPx", "SumPx", 0, TFitConstraintEp::pX, 0.);
137  sumPyConstr_ = new TFitConstraintEp("SumPy", "SumPy", 0, TFitConstraintEp::pY, 0.);
138 
139  massConstr_[kWHadMass ]->addParticles1(hadP_, hadQ_ );
140  massConstr_[kWLepMass ]->addParticles1(lepton_, neutrino_);
141  massConstr_[kTopHadMass ]->addParticles1(hadP_, hadQ_, hadB_);
142  massConstr_[kTopLepMass ]->addParticles1(lepton_, neutrino_, lepB_);
143  massConstr_[kNeutrinoMass ]->addParticle1 (neutrino_);
144  massConstr_[kEqualTopMasses]->addParticles1(hadP_, hadQ_, hadB_);
148 
149  if(std::find(constrList_.begin(), constrList_.end(), kSumPt)!=constrList_.end())
150  constrainSumPt_ = true;
151  constrainSumPt_ = false;
152 }
153 
155 {
156  printSetup();
157 
158  setupJets();
159  setupLeptons();
161 
162  // add measured particles
169 
170  // add constraints
171  for(unsigned int i=0; i<constrList_.size(); i++){
172  if(constrList_[i]!=kSumPt)
174  }
175  if(constrainSumPt_) {
178  }
179 
180  // initialize helper class used to bring the resolutions into covariance matrices
181  if(udscResolutions_->size() && bResolutions_->size() && lepResolutions_->size() && metResolutions_->size())
184  else
185  covM_ = new CovarianceMatrix();
186 }
187 
188 int TtSemiLepKinFitter::fit(const TLorentzVector& p4HadP, const TLorentzVector& p4HadQ, const TLorentzVector& p4HadB, const TLorentzVector& p4LepB,
189  const TLorentzVector& p4Lepton, const TLorentzVector& p4Neutrino, const int leptonCharge, const CovarianceMatrix::ObjectType leptonType)
190 {
191  // initialize covariance matrices
192  TMatrixD covHadP = covM_->setupMatrix(p4HadP, CovarianceMatrix::kUdscJet, jetParam_);
193  TMatrixD covHadQ = covM_->setupMatrix(p4HadQ, CovarianceMatrix::kUdscJet, jetParam_);
194  TMatrixD covHadB = covM_->setupMatrix(p4HadB, CovarianceMatrix::kBJet, jetParam_);
195  TMatrixD covLepB = covM_->setupMatrix(p4LepB, CovarianceMatrix::kBJet, jetParam_);
196  TMatrixD covLepton = covM_->setupMatrix(p4Lepton , leptonType , lepParam_);
197  TMatrixD covNeutrino = covM_->setupMatrix(p4Neutrino, CovarianceMatrix::kMet , metParam_);
198 
199  // now do the part that is fully independent of PAT features
200  return fit(p4HadP, p4HadQ, p4HadB, p4LepB, p4Lepton, p4Neutrino,
201  covHadP, covHadQ, covHadB, covLepB, covLepton, covNeutrino,
202  leptonCharge);
203 }
204 
205 int TtSemiLepKinFitter::fit(const TLorentzVector& p4HadP, const TLorentzVector& p4HadQ, const TLorentzVector& p4HadB, const TLorentzVector& p4LepB,
206  const TLorentzVector& p4Lepton, const TLorentzVector& p4Neutrino,
207  const TMatrixD& covHadP, const TMatrixD& covHadQ, const TMatrixD& covHadB, const TMatrixD& covLepB,
208  const TMatrixD& covLepton, const TMatrixD& covNeutrino, const int leptonCharge)
209 {
210  // set the kinematics of the objects to be fitted
211  hadP_->setIni4Vec( &p4HadP );
212  hadQ_->setIni4Vec( &p4HadQ );
213  hadB_->setIni4Vec( &p4HadB );
214  lepB_->setIni4Vec( &p4LepB );
215  lepton_->setIni4Vec( &p4Lepton );
216  neutrino_->setIni4Vec( &p4Neutrino );
217 
218  hadP_->setCovMatrix( &covHadP );
219  hadQ_->setCovMatrix( &covHadQ );
220  hadB_->setCovMatrix( &covHadB );
221  lepB_->setCovMatrix( &covLepB );
222  lepton_ ->setCovMatrix( &covLepton );
223  neutrino_->setCovMatrix( &covNeutrino );
224 
225  if(constrainSumPt_){
226  // setup Px and Py constraint for curent event configuration so that sum Pt will be conserved
227  sumPxConstr_->setConstraint( p4HadP.Px() + p4HadQ.Px() + p4HadB.Px() + p4LepB.Px() + p4Lepton.Px() + p4Neutrino.Px() );
228  sumPyConstr_->setConstraint( p4HadP.Py() + p4HadQ.Py() + p4HadB.Py() + p4LepB.Py() + p4Lepton.Py() + p4Neutrino.Py() );
229  }
230 
231  // now do the fit
232  fitter_->fit();
233 
234  // read back the resulting particles if the fit converged
235  if(fitter_->getStatus()==0){
236  // read back jet kinematics
238  hadP_->getCurr4Vec()->Y(), hadP_->getCurr4Vec()->Z(), hadP_->getCurr4Vec()->E()), math::XYZPoint()));
240  hadQ_->getCurr4Vec()->Y(), hadQ_->getCurr4Vec()->Z(), hadQ_->getCurr4Vec()->E()), math::XYZPoint()));
242  hadB_->getCurr4Vec()->Y(), hadB_->getCurr4Vec()->Z(), hadB_->getCurr4Vec()->E()), math::XYZPoint()));
244  lepB_->getCurr4Vec()->Y(), lepB_->getCurr4Vec()->Z(), lepB_->getCurr4Vec()->E()), math::XYZPoint()));
245 
246  // read back lepton kinematics
248  lepton_->getCurr4Vec()->Y(), lepton_->getCurr4Vec()->Z(), lepton_->getCurr4Vec()->E()), math::XYZPoint()));
249 
250  // read back the MET kinematics
253 
254  }
255  return fitter_->getStatus();
256 }
257 
259 {
260 
261  TtSemiEvtSolution fitsol(*asol);
262 
263  std::vector<pat::Jet> jets;
264  jets.resize(4);
265  jets[TtSemiLepEvtPartons::LightQ ] = fitsol.getCalHadp();
267  jets[TtSemiLepEvtPartons::HadB ] = fitsol.getCalHadb();
268  jets[TtSemiLepEvtPartons::LepB ] = fitsol.getCalLepb();
269 
270  // perform the fit, either using the electron or the muon
271  if(fitsol.getDecay() == "electron") fit( jets, fitsol.getCalLepe(), fitsol.getCalLepn() );
272  if(fitsol.getDecay() == "muon" ) fit( jets, fitsol.getCalLepm(), fitsol.getCalLepn() );
273 
274  // add fitted information to the solution
275  if (fitter_->getStatus() == 0) {
276  // fill the fitted particles
277  fitsol.setFitHadb( fittedHadB() );
278  fitsol.setFitHadp( fittedHadP() );
279  fitsol.setFitHadq( fittedHadQ() );
280  fitsol.setFitLepb( fittedLepB() );
281  fitsol.setFitLepl( fittedLepton() );
282  fitsol.setFitLepn( fittedNeutrino() );
283  // store the fit's chi2 probability
284  fitsol.setProbChi2( fitProb() );
285  }
286  return fitsol;
287 }
void setFitHadq(const pat::Particle &aFitHadq)
const pat::Particle fittedHadP() const
return hadronic light quark candidate
int i
Definition: DBlmapReader.cc:9
void addParticles(TAbsFitParticle *p1, TAbsFitParticle *p2=0, TAbsFitParticle *p3=0, TAbsFitParticle *p4=0, TAbsFitParticle *p5=0, TAbsFitParticle *p6=0, TAbsFitParticle *p7=0, TAbsFitParticle *p8=0, TAbsFitParticle *p9=0, TAbsFitParticle *p10=0)
void setFitHadb(const pat::Particle &aFitHadb)
TAbsFitParticle * hadB_
input particles
const std::vector< edm::ParameterSet > * udscResolutions_
resolutions
TAbsFitParticle * neutrino_
Int_t fit()
Definition: TKinFitter.cc:309
const pat::Particle fittedNeutrino() const
return neutrino candidate
const pat::Particle fittedLepB() const
return leptonic b quark candidate
TAbsFitParticle * hadQ_
pat::Jet getCalHadq() const
virtual void setIni4Vec(const TLorentzVector *pini)=0
bool constrainSumPt_
internally use simple boolean for this constraint to reduce the per-event computing time ...
std::string param(const Param &param) const
convert Param to human readable form
Definition: TopKinFitter.cc:23
pat::MET getCalLepn() const
TMatrixD setupMatrix(const pat::PATObject< T > &object, const TopKinFitter::Param param, const std::string &resolutionProvider="")
return covariance matrix for a PAT object
std::string getDecay() const
TFitConstraintEp * sumPyConstr_
math::Error< 5 >::type CovarianceMatrix
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int maxNrIter_
maximal allowed number of iterations to be used for the fit
Definition: TopKinFitter.h:48
pat::Particle fittedHadP_
double fitProb() const
return fit probability
Definition: TopKinFitter.h:36
pat::Particle fittedLepB_
Param lepParam_
lepton parametrization
pat::Particle fittedHadB_
output particles
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
pat::Electron getCalLepe() const
const std::vector< edm::ParameterSet > * bResolutions_
TAbsFitParticle * lepton_
int fit(const std::vector< pat::Jet > &jets, const pat::Lepton< LeptonType > &leps, const pat::MET &met)
kinematic fit interface for PAT objects
void setupJets()
initialize jet inputs
const std::vector< edm::ParameterSet > * lepResolutions_
void printSetup() const
print fitter setup
void setFitLepb(const pat::Particle &aFitLepb)
pat::Particle fittedLepton_
void addConstraint(TAbsFitConstraint *constraint)
Definition: TKinFitter.cc:281
TAbsFitParticle * hadP_
vector< PseudoJet > jets
void setFitHadp(const pat::Particle &aFitHadp)
const std::vector< double > * jetEnergyResolutionScaleFactors_
scale factors for the jet energy resolution
Int_t getStatus()
Definition: TKinFitter.h:41
virtual void setCovMatrix(const TMatrixD *theCovMatrix)
Param jetParam_
jet parametrization
const pat::Particle fittedHadB() const
return hadronic b quark candidate
double mW_
W mass value used for constraints.
Definition: TopKinFitter.h:54
void addMeasParticle(TAbsFitParticle *particle)
Definition: TKinFitter.cc:209
TtSemiLepKinFitter()
default constructor
std::map< Constraint, TFitConstraintM * > massConstr_
supported constraints
Param metParam_
met parametrization
CovarianceMatrix * covM_
object used to construct the covariance matrices for the individual particles
pat::Particle fittedHadQ_
pat::Muon getCalLepm() const
void setConstraint(Double_t constraint)
double maxDeltaS_
maximal allowed chi2 (not normalized to degrees of freedom)
Definition: TopKinFitter.h:50
pat::Jet getCalHadb() const
TtSemiEvtSolution addKinFitInfo(TtSemiEvtSolution *asol)
add kin fit information to the old event solution (in for legacy reasons)
~TtSemiLepKinFitter()
default destructor
void setupConstraints()
initialize constraints
std::vector< Constraint > constrList_
vector of constraints to be used
void setupLeptons()
initialize lepton inputs
TFitConstraintEp * sumPxConstr_
void setFitLepn(const pat::Particle &aFitLepn)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Analysis-level particle class.
Definition: Particle.h:32
const pat::Particle fittedHadQ() const
return hadronic light quark candidate
const TLorentzVector * getCurr4Vec()
const pat::Particle fittedLepton() const
return lepton candidate
void setProbChi2(double c)
pat::Jet getCalLepb() const
void setupFitter()
setup fitter
pat::Particle fittedNeutrino_
const std::vector< double > * jetEnergyResolutionEtaBinning_
TKinFitter * fitter_
kinematic fitter
Definition: TopKinFitter.h:46
tuple leptonType
LEPTON
Definition: autophobj.py:48
void setFitLepl(const pat::Particle &aFitLepl)
double mTop_
top mass value used for constraints
Definition: TopKinFitter.h:56
TAbsFitParticle * lepB_
double maxF_
maximal allowed distance from constraints
Definition: TopKinFitter.h:52
pat::Jet getCalHadp() const
const std::vector< edm::ParameterSet > * metResolutions_