Skip to content

Commit

Permalink
Merge pull request #2 from cms-tau-pog/CMSSW_5_3_X_HighPt
Browse files Browse the repository at this point in the history
Merging highPt fixes into boostedTaus
  • Loading branch information
jpavel committed Nov 27, 2013
2 parents 749413d + 341f80e commit 15ab5e2
Show file tree
Hide file tree
Showing 39 changed files with 2,432 additions and 104 deletions.
59 changes: 31 additions & 28 deletions PhysicsTools/PatAlgos/python/tools/pfTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,21 @@ def reconfigurePF2PATTaus(process,
% (tauType, pf2patSelection)

#get baseSequence
baseSequence = getattr(process,"pfTausBaseSequence"+postfix)
#clean baseSequence from old modules
for oldBaseModuleName in baseSequence.moduleNames():
oldBaseModule = getattr(process,oldBaseModuleName)
baseSequence.remove(oldBaseModule)
# baseSequence = getattr(process,"pfTausBaseSequence"+postfix)
# #clean baseSequence from old modules
# for oldBaseModuleName in baseSequence.moduleNames():
# oldBaseModule = getattr(process,oldBaseModuleName)
# baseSequence.remove(oldBaseModule)

# Get the prototype of tau producer to make, i.e. fixedConePFTauProducer
producerName = producerFromType(tauType)
# Set as the source for the pf2pat taus (pfTaus) selector
applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
# applyPostfix(process,"pfTaus", postfix).src = producerName+postfix
# Start our pf2pat taus base sequence
oldTauSansRefs = getattr(process,'pfTausProducerSansRefs'+postfix)
oldTau = getattr(process,'pfTausProducer'+postfix)
## copy tau and setup it properly
newTauSansRefs = None
# newTauSansRefs = None
newTau = getattr(process,producerName).clone()
## adapted to new structure in RecoTauProducers PLEASE CHECK!!!
if tauType=='shrinkingConePFTau':
Expand All @@ -221,15 +221,18 @@ def reconfigurePF2PATTaus(process,
elif tauType=='fixedConePFTau':
newTau.piZeroSrc = "pfJetsLegacyTaNCPiZeros"+postfix
elif tauType=='hpsPFTau':
newTau = process.combinatoricRecoTaus.clone()
newTau = getattr(process,'combinatoricRecoTaus').clone()
newTau.piZeroSrc="pfJetsLegacyHPSPiZeros"+postfix
newTau.jetRegionSrc="pfTauPFJets08Region"+postfix
newTau.chargedHadronSrc='pfTauPFJetsRecoTauChargedHadrons'+postfix
newTau.modifiers[3] = cms.PSet(
pfTauTagInfoSrc = cms.InputTag("pfTauTagInfoProducer"+postfix),
name = cms.string('pfTauTTIworkaround'+postfix),
plugin = cms.string('RecoTauTagInfoWorkaroundModifer')
)
from PhysicsTools.PatAlgos.tools.helpers import cloneProcessingSnippet
cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
# cloneProcessingSnippet(process, process.produceHPSPFTaus, postfix)
setattr(process,'produceHPSPFTaus'+postfix,cms.Sequence(applyPostfix(process,'hpsSelectionDiscriminator',postfix)+applyPostfix(process,'hpsPFTauProducerSansRefs',postfix)+applyPostfix(process,'hpsPFTauProducer',postfix)))
massSearchReplaceParam(getattr(process,"produceHPSPFTaus"+postfix),
"PFTauProducer",
cms.InputTag("combinatoricRecoTaus"),
Expand All @@ -239,19 +242,19 @@ def reconfigurePF2PATTaus(process,
cms.InputTag("combinatoricRecoTaus"),
cms.InputTag("pfTausBase"+postfix) )

newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
newTau.jetRegionSrc = oldTau.jetRegionSrc
newTau.jetSrc = oldTau.jetSrc
# newTau.builders[0].pfCandSrc = oldTau.builders[0].pfCandSrc
# newTau.jetRegionSrc = oldTau.jetRegionSrc
# newTau.jetSrc = oldTau.jetSrc

# replace old tau producer by new one put it into baseSequence
setattr(process,"pfTausBase"+postfix,newTau)
if tauType=='shrinkingConePFTau':
setattr(process,"pfTausBaseSansRefs"+postfix,newTauSansRefs)
getattr(process,"pfTausBase"+postfix).src = "pfTausBaseSansRefs"+postfix
baseSequence += getattr(process,"pfTausBaseSansRefs"+postfix)
baseSequence += getattr(process,"pfTausBase"+postfix)
if tauType=='hpsPFTau':
baseSequence += getattr(process,"produceHPSPFTaus"+postfix)
# baseSequence += getattr(process,"pfTausBase"+postfix)
# if tauType=='hpsPFTau':
# baseSequence += getattr(process,"produceHPSPFTaus"+postfix)
#make custom mapper to take postfix into account (could have gone with lambda of lambda but... )
def producerIsTauTypeMapperWithPostfix(tauProducer):
return lambda x: producerIsTauTypeMapper(tauProducer)+x.group(1)+postfix
Expand All @@ -267,7 +270,7 @@ def recoTauTypeMapperWithGroup(tauProducer):
clonedDisc = getattr(process, originalName).clone()
# Register in our process
setattr(process, clonedName, clonedDisc)
baseSequence += getattr(process, clonedName)
# baseSequence += getattr(process, clonedName)

tauCollectionToSelect = None
if tauType != 'hpsPFTau' :
Expand All @@ -283,7 +286,7 @@ def recoTauTypeMapperWithGroup(tauProducer):
clonedDisc.PFTauProducer = tauCollectionToSelect

# Reconfigure the pf2pat PFTau selector discrimination sources
applyPostfix(process,"pfTaus", postfix).discriminators = cms.VPSet()
# applyPostfix(process,"pfTaus", postfix).discriminators = cms.VPSet()
for selection in pf2patSelection:
# Get our discriminator that will be used to select pfTaus
originalName = tauType+selection
Expand All @@ -305,17 +308,17 @@ def recoTauTypeMapperWithGroup(tauProducer):
newTauTypeMapper=producerIsTauTypeMapperWithPostfix,
preservePFTauProducer=True)
clonedDisc.PFTauProducer = tauCollectionToSelect
baseSequence += clonedDisc
# baseSequence += clonedDisc
# Add this selection to our pfTau selectors
applyPostfix(process,"pfTaus", postfix).discriminators.append(cms.PSet(
discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
# applyPostfix(process,"pfTaus", postfix).discriminators.append(cms.PSet(
# discriminator=cms.InputTag(clonedName), selectionCut=cms.double(0.5)))
# Set the input of the final selector.
if tauType != 'hpsPFTau':
applyPostfix(process,"pfTaus", postfix).src = "pfTausBase"+postfix
else:
# If we are using HPS taus, we need to take the output of the clenaed
# collection
applyPostfix(process,"pfTaus", postfix).src = "hpsPFTauProducer"+postfix
# if tauType != 'hpsPFTau':
# applyPostfix(process,"pfTaus", postfix).src = "pfTausBase"+postfix
# else:
# # If we are using HPS taus, we need to take the output of the clenaed
# # collection
# applyPostfix(process,"pfTaus", postfix).src = "hpsPFTauProducer"+postfix



Expand All @@ -332,7 +335,7 @@ def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
if tauType != 'hpsPFTau' :
applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausBase"+postfix)
else:
applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("hpsPFTauProducer"+postfix)
applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTausProducer"+postfix)
# to use preselected collection (old default) uncomment line below
#applyPostfix(process,"patTaus", postfix).tauSource = cms.InputTag("pfTaus"+postfix)

Expand All @@ -346,7 +349,6 @@ def adaptPFTaus(process,tauType = 'shrinkingConePFTau', postfix = ""):
pfTauLabelNew=applyPostfix(process,"patTaus", postfix).tauSource,
pfTauLabelOld=cms.InputTag(tauType+'Producer'),
postfix=postfix)

applyPostfix(process,"makePatTaus", postfix).remove(
applyPostfix(process,"patPFCandidateIsoDepositSelection", postfix)
)
Expand Down Expand Up @@ -636,3 +638,4 @@ def usePF2PAT(process, runPF2PAT=True, jetAlgo='AK5', runOnMC=True, postfix="",
removeMCMatchingPF2PAT(process,postfix=postfix,outputModules=outputModules)

print "Done: PF2PAT interfaced to PAT, postfix=", postfix

21 changes: 12 additions & 9 deletions PhysicsTools/PatAlgos/python/tools/tauTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def redoPFTauDiscriminators(process,
else:
# remove producers
for iname in process.patHPSPFTauDiscrimination.moduleNames():
if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1 or iname.find("kt6PFJetsForRhoComputationVoronoi")>-1):
if not (iname.find("DiscriminationBy")>-1 or iname.find("DiscriminationAgainst")>-1 or iname.find("kt6PFJetsForRhoComputationVoronoi")>-1 or iname.find("PtSum")>-1 or iname.find("ImpactParameters")>-1 or iname.find("VertexProducer")>-1):
process.patHPSPFTauDiscrimination.remove(getattr(process,iname) )
tauDiscriminationSequence = cloneProcessingSnippet(process, process.patHPSPFTauDiscrimination, postfix)

Expand Down Expand Up @@ -66,11 +66,11 @@ def redoPFTauDiscriminators(process,
else:
raise StandardError, "Unkown tauType: '%s'"%tauType

##if not hasattr(process,"updateHPSPFTaus"+postfix):
## applyPostfix(process,"patDefaultSequence",postfix).replace(
## applyPostfix(process,"patTaus",postfix),
## tauDiscriminationSequence*applyPostfix(process,"patTaus",postfix)
## )
if not hasattr(process,"updateHPSPFTaus"+postfix):
applyPostfix(process,"patDefaultSequence",postfix).replace(
applyPostfix(process,"patTaus",postfix),
tauDiscriminationSequence*applyPostfix(process,"patTaus",postfix)
)

massSearchReplaceParam(tauDiscriminationSequence, tauSrc, oldPFTauLabel, newPFTauLabel)

Expand Down Expand Up @@ -137,7 +137,6 @@ def _switchToPFTau(process,
postfix = ""):
"""internal auxiliary function to switch to **any** PFTau collection"""
print ' Taus: ', pfTauLabelOld, '->', pfTauLabelNew

applyPostfix(process, "tauMatch" + patTauLabel, postfix).src = pfTauLabelNew
applyPostfix(process, "tauGenJetMatch" + patTauLabel, postfix).src = pfTauLabelNew

Expand Down Expand Up @@ -350,15 +349,19 @@ def switchToPFTauHPS(process,
patTauLabel = "",
jecLevels = [],
postfix = ""):

hpsTauJECpayloadMapping = pfTauJECpayloadMapping

_switchToPFTau(process, pfTauLabelOld, pfTauLabelNew, 'hpsPFTau', hpsTauIDSources,
jecLevels, hpsTauJECpayloadMapping,
patTauLabel = patTauLabel, postfix = postfix)

# CV: enable tau lifetime information for HPS PFTaus
applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = pfTauLabelNew.value().replace("Producer", "TransverseImpactParameters")
applyPostfix(process, "patTaus" + patTauLabel, postfix).tauTransverseImpactParameterSource = pfTauLabelOld.value().replace("Producer", "TransverseImpactParameters")+patTauLabel+postfix
applyPostfix(process, "hpsPFTauPrimaryVertexProducer"+ patTauLabel, postfix).PFTauTag = pfTauLabelNew
applyPostfix(process, "hpsPFTauSecondaryVertexProducer" + patTauLabel, postfix).PFTauTag = pfTauLabelNew
applyPostfix(process, "hpsPFTauTransverseImpactParameters" +patTauLabel, postfix).PFTauTag = pfTauLabelNew
applyPostfix(process, "hpsPFTauTransverseImpactParameters" +patTauLabel, postfix).PFTauPVATag = "hpsPFTauPrimaryVertexProducer"+patTauLabel+postfix
applyPostfix(process, "hpsPFTauTransverseImpactParameters" +patTauLabel, postfix).PFTauSVATag = "hpsPFTauSecondaryVertexProducer"+patTauLabel+postfix

## adapt cleanPatTaus
if hasattr(process, "cleanPatTaus" + patTauLabel + postfix):
Expand Down
3 changes: 2 additions & 1 deletion RecoTauTag/ImpactParameter/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<use name="root"/>
<use name="RecoBTag/BTagTools"/>
<use name="TrackingTools/TransientTrack"/>
<flags EDM_PLUGIN="1"/>
<use name="rootcore"/>
<use name="rootminuit2"/>
<export>
<lib name="1"/>
</export>
26 changes: 26 additions & 0 deletions RecoTauTag/ImpactParameter/interface/Chi2VertexFitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* From SimpleFits Package
* Designed an written by
* author: Ian M. Nugent
* Humboldt Foundations
*/

#ifndef Chi2VertexFitter_h
#define Chi2VertexFitter_h

#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/FCNBase.h"
#include "RecoTauTag/ImpactParameter/interface/TrackHelixVertexFitter.h"

class Chi2VertexFitter : public TrackHelixVertexFitter {
public:
Chi2VertexFitter(std::vector<TrackParticle> &particles,TVector3 vguess,double nsigma_=4.0):TrackHelixVertexFitter(particles,vguess),nsigma(nsigma_){};
virtual ~Chi2VertexFitter(){};

virtual bool Fit();

private:
double nsigma;
};
#endif


30 changes: 30 additions & 0 deletions RecoTauTag/ImpactParameter/interface/ChiSquareFunctionUpdator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* From SimpleFits Package
* Designed an written by
* author: Ian M. Nugent
* Humboldt Foundations
*/
#ifndef ChiSquareFunctionUpdator_h
#define ChiSquareFunctionUpdator_h

#include "Minuit2/FCNBase.h"
#include "TMatrixT.h"
#include "RecoTauTag/ImpactParameter/interface/TrackHelixVertexFitter.h"

class ChiSquareFunctionUpdator : public ROOT::Minuit2::FCNBase {
public:
ChiSquareFunctionUpdator(TrackHelixVertexFitter *VF_){VF=VF_;}
virtual ~ChiSquareFunctionUpdator(){};

virtual double operator() (const std::vector<double> & x)const{
TMatrixT<double> X(x.size(),1);
for(unsigned int i=0; i<x.size();i++){X(i,0)=x.at(i);}
return VF->UpdateChisquare(X);
}
virtual double Up()const{return 1.0;}// Error definiton for Chi^2

private:
TrackHelixVertexFitter *VF;

};
#endif

20 changes: 20 additions & 0 deletions RecoTauTag/ImpactParameter/interface/ErrorMatrixPropagator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* From SimpleFits Package
* Designed an written by
* author: Ian M. Nugent
* Humboldt Foundations
*/
#ifndef ErrorMatrixPropagator_h
#define ErrorMatrixPropagator_h

#include "TMatrixT.h"
#include "TMatrixTSym.h"

class ErrorMatrixPropagator {
public:
ErrorMatrixPropagator(){};
virtual ~ErrorMatrixPropagator(){};
static TMatrixTSym<double> PropogateError(TMatrixT<double> (*f)(TMatrixT<double> &par),TMatrixT<double> inPar,TMatrixTSym<double> inCov, double epsilon=0.001, double errorEpsilonRatio=1000);
};
#endif


27 changes: 0 additions & 27 deletions RecoTauTag/ImpactParameter/interface/ImpactParameter.h

This file was deleted.

76 changes: 76 additions & 0 deletions RecoTauTag/ImpactParameter/interface/LagrangeMultipliersFitter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* From SimpleFits Package
* Designed an written by
* author: Ian M. Nugent
* Humboldt Foundations
*/
#ifndef LagrangeMultipliersFitter_H
#define LagrangeMultipliersFitter_H

#include "RecoTauTag/ImpactParameter/interface/LorentzVectorParticle.h"
#include "TMatrixT.h"
#include "TVectorT.h"
#include "TMatrixTSym.h"
#include <vector>

class LagrangeMultipliersFitter{
public:
enum Position{pos_x=0,pos_y,pos_z,nposdim};
enum Parameters{par_vx=0,par_vy,par_vz,par_px,par_py,par_pz,par_m,npardim};
enum ConvergeProc{ConstraintMin=0,Chi2Min,Chi2AndConstaintMin};

LagrangeMultipliersFitter();
virtual ~LagrangeMultipliersFitter(){};

virtual void SetWeight(double weight){weight_=weight;}
virtual void SetMaxDelta(double MaxDelta){MaxDelta_=MaxDelta;}
virtual void SetNIterMax(int Nitermax){nitermax_=Nitermax;}

virtual bool Fit();
virtual bool isConverged();
virtual bool isConfigured(){return isconfigured;}
virtual double ChiSquare(){return chi2;}
virtual double CSum(){return delta;};
virtual double NIter(){return niter;};
virtual double NConstraints()=0;
virtual double NDF()=0;
virtual int NDaughters()=0;

virtual std::vector<LorentzVectorParticle> GetReFitDaughters()=0;
virtual LorentzVectorParticle GetMother()=0;

static TVectorT<double> convertToVector(TMatrixT<double> M);
static TMatrixT<double> convertToMatrix(TVectorT<double> V);

protected:
virtual TVectorD Value(TVectorD &v)=0;

TVectorD par_0; // parameter values for linearization point
TVectorD par; // current parameter values
TMatrixTSym<double> cov_0; //covariance matrix for linearization point (corresponding to par_0)
TMatrixTSym<double> cov; // current covariance matrix (corresponding to par)
bool isconfigured;
bool isFit;

private:
bool ApplyLagrangianConstraints();
TMatrixT<double> Derivative();
double ChiSquare(TMatrixT<double> delta_alpha,TMatrixT<double> lambda,TMatrixT<double> D,TMatrixT<double> d);
double ChiSquareUsingInitalPoint(TMatrixT<double> alpha,TMatrixT<double> lambda);
double ConstraintDelta(TVectorT<double> par);
TMatrixT<double> ComputeVariance();

// Configuration parameters
double epsilon_,weight_,MaxDelta_,nitermax_;

// Fit variables
double chi2,chi2prev,delta,niter;

// covariances and derivatives info
TMatrixTSym<double> V_alpha0_inv;
TMatrixT<double> D;
TMatrixTSym<double> V_D;
double ScaleFactor;
TMatrixT<double> V_corr_prev;

};
#endif
Loading

0 comments on commit 15ab5e2

Please sign in to comment.