CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/PhysicsTools/RecoUtils/src/CandMassKinFitter.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/RecoUtils/interface/CandMassKinFitter.h"
00002 #include "PhysicsTools/KinFitter/interface/TKinFitter.h"
00003 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00004 #include "PhysicsTools/KinFitter/interface/TFitConstraintM.h"
00005 #include "PhysicsTools/KinFitter/interface/TFitParticleMCCart.h"
00006 #include "TMatrixD.h"
00007 #include <iostream>
00008 using namespace reco;
00009 using namespace std;
00010 
00011 FitQuality CandMassKinFitter::set( Candidate & c ) const {
00012   TKinFitter fitter("CandMassFit", "CandMassFit");
00013   TString name("dau0");
00014   size_t daus = c.numberOfDaughters();
00015   vector<TMatrixD> errors(daus, TMatrix(3,3));
00016   vector<TVector3> momenta(daus);
00017   vector<TFitParticleMCCart *> particles(daus, 0);
00018   TFitConstraintM constraint( "MassConstraint", 
00019                               "MassConstraint", 0, 0 , mass_);
00020   for ( size_t i = 0; i < daus; ++ i ) {
00021     const Candidate & dau = * c.daughter( i );
00022     Particle::LorentzVector p4 = dau.p4();
00023     TMatrixD & err = errors[i];
00024     TVector3 & mom = momenta[i];
00025     mom = TVector3( p4.px(), p4.py(), p4.pz() );
00026     TrackRef trk = dau.get<TrackRef>();
00027     // dummy errors for now...
00028     // should play with track parametrization...
00029     err.Zero();
00030     err(0,0) = 0.1;
00031     err(1,1) = 0.1;
00032     err(2,2) = 0.1;
00033     fitter.addMeasParticle( particles[i] = new TFitParticleMCCart( name, name, & mom, dau.mass(), & err ) );
00034     name[3] ++;
00035     constraint.addParticle1( particles[i] );
00036   } 
00037   fitter.addConstraint(& constraint);
00038   fitter.setMaxNbIter( 30 );
00039   fitter.setMaxDeltaS( 1e-2 );
00040   fitter.setMaxF( 1e-1 );
00041   fitter.setVerbosity( 0 );                     
00042   fitter.fit();
00043   // if (  fitter->getStatus() != 0 ) throw ...
00044   TLorentzVector sum( 0, 0, 0, 0 );
00045   for( size_t i = 0; i < daus; ++ i ) {
00046     Candidate & dau = * c.daughter( i );
00047     TFitParticleMCCart * part =  particles[i];
00048     const TLorentzVector * p4 = part->getCurr4Vec();
00049     dau.setP4( Particle::LorentzVector( p4->X(), p4->Y(), p4->Z(), p4->T() ) );
00050     sum += * p4;
00051     delete particles[i];
00052   }
00053   c.setP4( Particle::LorentzVector( sum.X(), sum.Y(), sum.Z(), sum.T() ) );
00054   return FitQuality( fitter.getS(), fitter.getNDF());
00055 }