Skip to content

Commit

Permalink
Removed use of static for temporary variable in TauA1NuConstrainedFitter
Browse files Browse the repository at this point in the history
The threaded framework was failing becuase multiple DQM modules were calling
TauA1NuConstrainedFitter at the same time and the class was using a static
to hold temporary data. I changed the code so now one passes the value as an
argument of the function which uses the value. This also required changed
ErrorMatrixPropagator which was formerly taking a pointer to a function but
now sometimes the function being called needed an additional argument. Changing
ErrorMatrixPropagator to use a std::function<> instead of a pointer to a function
as the argument fixed that problem.
  • Loading branch information
Dr15Jones committed Mar 28, 2014
1 parent 8f4573b commit 93d4101
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
3 changes: 2 additions & 1 deletion RecoTauTag/ImpactParameter/interface/ErrorMatrixPropagator.h
Expand Up @@ -6,6 +6,7 @@
* author: Ian M. Nugent
* Humboldt Foundations
*/
#include <functional>

#include "TMatrixT.h"
#include "TMatrixTSym.h"
Expand All @@ -17,7 +18,7 @@ class ErrorMatrixPropagator {
public:
ErrorMatrixPropagator(){};
virtual ~ErrorMatrixPropagator(){};
static TMatrixTSym<double> propagateError(TVectorT<double> (*f)(const TVectorT<double> &par), const TVectorT<double>& inPar, TMatrixTSym<double>& inCov, double epsilon=0.001, double errorEpsilonRatio=1000);
static TMatrixTSym<double> propagateError(std::function<TVectorT<double>(const TVectorT<double>&)> f, const TVectorT<double>& inPar, TMatrixTSym<double>& inCov, double epsilon=0.001, double errorEpsilonRatio=1000);
};

}
Expand Down
Expand Up @@ -39,8 +39,8 @@ class TauA1NuConstrainedFitter : public MultiProngTauSolver{
static TVectorT<double> ComputeNuLorentzVectorPar(const TVectorT<double> &inpar);
static TVectorT<double> ComputeA1LorentzVectorPar(const TVectorT<double> &inpar);
static TVectorT<double> ComputeMotherLorentzVectorPar(const TVectorT<double> &inpar);
static TVectorT<double> SolveAmbiguityAnalytically(const TVectorT<double> &inpar);
static TVectorT<double> SolveAmbiguityAnalyticallywithRot(const TVectorT<double> &inpar);
static TVectorT<double> SolveAmbiguityAnalytically(const TVectorT<double> &inpar, unsigned int ambiguity);
static TVectorT<double> SolveAmbiguityAnalyticallywithRot(const TVectorT<double> &inpar, unsigned int ambiguity);
static TVectorT<double> TauRot(const TVectorT<double> &inpar);

void UpdateExpandedPar();
Expand Down
2 changes: 1 addition & 1 deletion RecoTauTag/ImpactParameter/src/ErrorMatrixPropagator.cc
Expand Up @@ -9,7 +9,7 @@

using namespace tauImpactParameter;

TMatrixTSym<double> ErrorMatrixPropagator::propagateError(TVectorT<double> (*f)(const TVectorT<double>& par),
TMatrixTSym<double> ErrorMatrixPropagator::propagateError( std::function<TVectorT<double>(const TVectorT<double>&)> f,
const TVectorT<double>& inPar, TMatrixTSym<double>& inCov, double epsilon, double errorEpsilonRatio){
TVectorT<double> v=f(inPar);
TMatrixT<double> Jacobian(inPar.GetNrows(),v.GetNrows());
Expand Down
20 changes: 9 additions & 11 deletions RecoTauTag/ImpactParameter/src/TauA1NuConstrainedFitter.cc
Expand Up @@ -3,15 +3,14 @@
* author: Ian M. Nugent
* Humboldt Foundations
*/
#include <functional>
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "RecoTauTag/ImpactParameter/interface/TauA1NuConstrainedFitter.h"
#include "RecoTauTag/ImpactParameter/interface/PDGInfo.h"
#include <iostream>

using namespace tauImpactParameter;

unsigned int TauA1NuConstrainedFitter::static_amb;

TauA1NuConstrainedFitter::TauA1NuConstrainedFitter(unsigned int ambiguity,const LorentzVectorParticle& A1,const TVector3& PVertex, const TMatrixTSym<double>& VertexCov):
MultiProngTauSolver(),
ambiguity_(ambiguity)
Expand Down Expand Up @@ -198,7 +197,6 @@ bool TauA1NuConstrainedFitter::fit(){
TVector3 TauDir(cos(phi)*sin(theta),sin(phi)*sin(theta),cos(theta));
bool isReal;
solveByRotation(TauDir,a1,Tau_plus,Tau_minus,nu_plus,nu_minus,isReal);
static_amb=ambiguity_;

//check that the do product of the a1 and tau is positive, otherwise there is no information for tau direction -> use zero solution
if(TauDir.Dot(a1.Vect())<0){
Expand All @@ -208,22 +206,22 @@ bool TauA1NuConstrainedFitter::fit(){
//case 1: is real then solve analytically
if(isReal && (ambiguity_==plus || ambiguity_==minus)){
// popogate errors
TVectorT<double> par_tmp=TauA1NuConstrainedFitter::SolveAmbiguityAnalytically(par);
cov=ErrorMatrixPropagator::propagateError(&TauA1NuConstrainedFitter::SolveAmbiguityAnalytically,par,cov_0);
TVectorT<double> par_tmp=TauA1NuConstrainedFitter::SolveAmbiguityAnalytically(par,ambiguity_);
cov=ErrorMatrixPropagator::propagateError(std::bind(TauA1NuConstrainedFitter::SolveAmbiguityAnalytically,std::placeholders::_1,ambiguity_),par,cov_0);
for(int i=0; i<npar;i++) par(i)=par_tmp(i);
return true;
}
// case 2 is in unphsyical region - rotate and substitue \theta_{GJ} with \theta_{GJ}^{Max} and then solve analytically
else if(!isReal && ambiguity_==zero){
TVectorT<double> par_tmp=TauA1NuConstrainedFitter::SolveAmbiguityAnalyticallywithRot(par);
cov=ErrorMatrixPropagator::propagateError(&TauA1NuConstrainedFitter::SolveAmbiguityAnalyticallywithRot,par,cov_0);
TVectorT<double> par_tmp=TauA1NuConstrainedFitter::SolveAmbiguityAnalyticallywithRot(par,ambiguity_);
cov=ErrorMatrixPropagator::propagateError(std::bind(TauA1NuConstrainedFitter::SolveAmbiguityAnalyticallywithRot,std::placeholders::_1,ambiguity_),par,cov_0);
for(int i=0; i<npar;i++) par(i)=par_tmp(i);
return true;
}
return false;
}

TVectorT<double> TauA1NuConstrainedFitter::SolveAmbiguityAnalytically(const TVectorT<double>& inpar){
TVectorT<double> TauA1NuConstrainedFitter::SolveAmbiguityAnalytically(const TVectorT<double>& inpar, unsigned int amb){
// Solve equation quadratic equation
TVectorT<double> outpar(inpar.GetNrows());
TLorentzVector a1,nu;
Expand All @@ -235,7 +233,7 @@ TVectorT<double> TauA1NuConstrainedFitter::SolveAmbiguityAnalytically(const TVec
TLorentzVector Tau_plus,Tau_minus,nu_plus,nu_minus;
bool isReal;
solveByRotation(TauDir,a1_d,Tau_plus,Tau_minus,nu_plus,nu_minus,isReal,true);
if(static_amb==plus)nu=nu_plus;
if(amb==plus)nu=nu_plus;
else nu=nu_minus;
for(int i=0; i<outpar.GetNrows();i++){ outpar(i)=inpar(i);}
outpar(nu_px)=nu.Px();
Expand All @@ -244,7 +242,7 @@ TVectorT<double> TauA1NuConstrainedFitter::SolveAmbiguityAnalytically(const TVec
return outpar;
}

TVectorT<double> TauA1NuConstrainedFitter::SolveAmbiguityAnalyticallywithRot(const TVectorT<double>& inpar){
TVectorT<double> TauA1NuConstrainedFitter::SolveAmbiguityAnalyticallywithRot(const TVectorT<double>& inpar, unsigned int ambiguity){
// Rotate and subsitute \theta_{GJ} with \theta_{GJ}^{Max} - assumes uncertianty on thata and phi of the a1 or small compared to the tau direction.
TVectorT<double> outpar(inpar.GetNrows());
TLorentzVector a1,nu;
Expand All @@ -261,7 +259,7 @@ TVectorT<double> TauA1NuConstrainedFitter::SolveAmbiguityAnalyticallywithRot(con
for(int i=0; i<outpar.GetNrows();i++) outpar(i)=inpar(i);
outpar(tau_phi)=TauDir.Phi();
outpar(tau_theta)=TauDir.Theta();
return SolveAmbiguityAnalytically(outpar);
return SolveAmbiguityAnalytically(outpar,ambiguity);
}

// Return the significance of the rotation when the tau direction is in the unphysical region
Expand Down

0 comments on commit 93d4101

Please sign in to comment.