Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Tag&Probe in 7.4.X (and later) #8801

Closed
wants to merge 8 commits into from
6 changes: 3 additions & 3 deletions DataFormats/PatCandidates/interface/Electron.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ namespace pat {
// ---- embed various impact parameters with errors ----
typedef enum IPTYPE { PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, IpTypeSize = 4 } IpType;
/// Impact parameter wrt primary vertex or beamspot
double dB(IpType type) const;
double dB(IPTYPE type) const;
/// Uncertainty on the corresponding impact parameter
double edB(IpType type) const;
double edB(IPTYPE type) const;
/// the version without arguments returns PD2D, but with an absolute value (for backwards compatibility)
double dB() const { return std::abs(dB(PV2D)); }
/// the version without arguments returns PD2D, but with an absolute value (for backwards compatibility)
double edB() const { return std::abs(edB(PV2D)); }
/// Set impact parameter of a certain type and its uncertainty
void setDB(double dB, double edB, IpType type);
void setDB(double dB, double edB, IPTYPE type);

// ---- Momentum estimate specific methods ----
const LorentzVector & ecalDrivenMomentum() const {return ecalDrivenMomentum_;}
Expand Down
6 changes: 3 additions & 3 deletions DataFormats/PatCandidates/interface/Muon.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ namespace pat {
PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, IpTypeSize = 4
} IpType;
void initImpactParameters(void); // init IP defaults in a constructor
double dB(IpType type) const;
double edB(IpType type) const;
double dB(IPTYPE type) const;
double edB(IPTYPE type) const;

/// the version without arguments returns PD2D, but with an absolute value (for backwards compatibility)
double dB() const { return std::abs(dB(PV2D)); }
/// the version without arguments returns PD2D, but with an absolute value (for backwards compatibility)
double edB() const { return std::abs(edB(PV2D)); }

void setDB ( double dB, double edB, IpType type = PV2D ) {
void setDB ( double dB, double edB, IPTYPE type = PV2D ) {
ip_[type] = dB; eip_[type] = edB; cachedIP_ |= (1 << int(type));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// $Id: TriggerObjectFilterByCollection.cc,v 1.1 2012/08/02 14:34:28 gpetrucc Exp $
//

/**
\class TriggerObjectFilterByCollection.h "MuonAnalysis/TagAndProbe/plugins/TriggerObjectFilterByCollection.h"
\brief Creates a filtered list of TriggerObjectStandAlone objects selecting by collection label
Inputs are:
- a list of TriggerObjectStandAlone (param. "src")
- a list of collections (param. "collections")
Outputs are:
- a list of TriggerObjectStandAlone

\author Giovanni Petrucciani
\version $Id: TriggerObjectFilterByCollection.cc,v 1.1 2012/08/02 14:34:28 gpetrucc Exp $
*/

#include <cstring>
#include <string>
#include <vector>
#include <algorithm>

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"


class TriggerObjectFilterByCollection : public edm::EDProducer {
public:
explicit TriggerObjectFilterByCollection(const edm::ParameterSet & iConfig);
virtual ~TriggerObjectFilterByCollection() { }

virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);

private:
edm::InputTag src_;
std::vector<std::string> collections_;
};

TriggerObjectFilterByCollection::TriggerObjectFilterByCollection(const edm::ParameterSet & iConfig) :
src_(iConfig.getParameter<edm::InputTag>("src")),
collections_(iConfig.getParameter<std::vector<std::string> >("collections"))
{
produces<std::vector<pat::TriggerObjectStandAlone> >();
for (unsigned int i = 0, n = collections_.size(); i < n; ++i) {
std::string &c = collections_[i];
int numsc = std::count(c.begin(), c.end(), ':');
if (numsc == 1) c.push_back(':');
else if (numsc == 2) c.append("::");
}
}

void
TriggerObjectFilterByCollection::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
using namespace edm;

Handle<std::vector<pat::TriggerObjectStandAlone> > src;
iEvent.getByLabel(src_, src);

std::auto_ptr<std::vector<pat::TriggerObjectStandAlone> > out(new std::vector<pat::TriggerObjectStandAlone>());
out->reserve(src->size());
for (std::vector<pat::TriggerObjectStandAlone>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
const std::string &coll = it->collection();
bool found = false;
for (std::vector<std::string>::const_iterator ic = collections_.begin(), ec = collections_.end(); ic != ec; ++ic) {
if (strncmp(coll.c_str(), ic->c_str(), ic->size()) == 0) { found = true; break; }
}
if (found) out->push_back(*it);
}

iEvent.put(out);
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(TriggerObjectFilterByCollection);
28 changes: 23 additions & 5 deletions MuonAnalysis/MuonAssociators/python/patMuonsWithTrigger_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
embedPFCandidate = False,
embedCaloMETMuonCorrs = cms.bool(False),
embedTcMETMuonCorrs = cms.bool(False),
embedPfEcalEnergy = cms.bool(False),
# then switch off some features we don't need
#addTeVRefits = False, ## <<--- this doesn't work. PAT bug ??
embedPickyMuon = False,
Expand Down Expand Up @@ -68,10 +69,14 @@ def addL1UserData(patMuonProducer, l1ModuleLabel = "muonL1Info"):
### ==== Unpack trigger, and match ====
from PhysicsTools.PatAlgos.triggerLayer1.triggerProducer_cfi import patTrigger as patTriggerFull
patTriggerFull.onlyStandAlone = True
patTrigger = cms.EDFilter("PATTriggerObjectStandAloneSelector",
patTrigger = cms.EDProducer("TriggerObjectFilterByCollection",
src = cms.InputTag("patTriggerFull"),
cut = cms.string('coll("hltL1extraParticles") || coll("hltL2MuonCandidates") || coll("hltL3MuonCandidates") || coll("hltGlbTrkMuonCands") || coll("hltMuTrackJpsiCtfTrackCands") || coll("hltMuTrackJpsiEffCtfTrackCands") || coll("hltMuTkMuJpsiTrackerMuonCands")'),
collections = cms.vstring("hltL1extraParticles", "hltL2MuonCandidates", "hltL3MuonCandidates", "hltGlbTrkMuonCands", "hltMuTrackJpsiCtfTrackCands", "hltMuTrackJpsiEffCtfTrackCands", "hltMuTkMuJpsiTrackerMuonCands"),
)
#patTrigger = cms.EDFilter("PATTriggerObjectStandAloneSelector",
# src = cms.InputTag("patTriggerFull"),
# cut = cms.string('coll("hltL1extraParticles") || coll("hltL2MuonCandidates") || coll("hltL3MuonCandidates") || coll("hltGlbTrkMuonCands") || coll("hltMuTrackJpsiCtfTrackCands") || coll("hltMuTrackJpsiEffCtfTrackCands") || coll("hltMuTkMuJpsiTrackerMuonCands")'),
#)

### ==== Then perform a match for all HLT triggers of interest
muonTriggerMatchHLT = cms.EDProducer( "PATTriggerMatcherDRDPtLessByR",
Expand Down Expand Up @@ -107,14 +112,14 @@ def addL1UserData(patMuonProducer, l1ModuleLabel = "muonL1Info"):
muonMatchHLTTrackMu = muonTriggerMatchHLT.clone(matchedCuts = cms.string('coll("hltMuTkMuJpsiTrackerMuonCands")'), maxDeltaR = 0.1, maxDPtRel = 10.0) #maxDeltaR Changed accordingly to Zoltan tuning.

patTriggerMatchers1Mu = cms.Sequence(
muonMatchHLTL1 +
#muonMatchHLTL1 + # keep off by default, since it is slow and usually not needed
muonMatchHLTL2 +
muonMatchHLTL3 +
muonMatchHLTL3T
)
patTriggerMatchers1MuInputTags = [
cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
cms.InputTag('muonMatchHLTL1'),
#cms.InputTag('muonMatchHLTL1','propagatedReco'), # fake, will match if and only if he muon did propagate to station 2
#cms.InputTag('muonMatchHLTL1'),
cms.InputTag('muonMatchHLTL2'),
cms.InputTag('muonMatchHLTL3'),
cms.InputTag('muonMatchHLTL3T'),
Expand Down Expand Up @@ -201,6 +206,19 @@ def addMCinfo(process):
def addDiMuonTriggers(process):
print "[MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff] Di-muon triggers are already enabled by default"

def addHLTL1Passthrough(process, embedder="patMuonsWithTrigger"):
process.patMuonsWithTriggerSequence.replace(process.muonMatchHLTL3, process.muonMatchHLTL1 + process.muonMatchHLTL3)
getattr(process,embedder).matches += [ cms.InputTag('muonMatchHLTL1'), cms.InputTag('muonMatchHLTL1','propagatedReco') ]

def useExtendedL1Match(process, patMuonProd="patMuonsWithoutTrigger", byWhat=["ByQ"]):
process.load("MuonAnalysis.MuonAssociators.muonL1MultiMatch_cfi")
process.globalReplace('muonL1Info', process.muonL1MultiMatch.clone(src = process.muonL1Info.src.value()))
pmp = getattr(process, patMuonProd)
for X in byWhat:
pmp.userData.userInts.src += [ cms.InputTag('muonL1Info', "quality"+X) ]
pmp.userData.userFloats.src += [ cms.InputTag('muonL1Info', "deltaR"+X) ]
pmp.userData.userCands.src += [ cms.InputTag('muonL1Info', X) ]

def useL1MatchingWindowForSinglets(process):
"Change the L1 trigger matching window to be suitable also for CSC single triggers"
if hasattr(process, 'muonL1Info'):
Expand Down
9 changes: 9 additions & 0 deletions PhysicsTools/TagAndProbe/interface/BaseTreeFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class BaseTreeFiller : boost::noncopyable {
/// Write a string dump of this PSet into the TTree header.
/// see macro in test directory for how to retrieve it from the output root file
void writeProvenance(const edm::ParameterSet &pset) const ;

//get the pileup weight informations
bool storePUweight() const {return storePUweight_;};

protected:

std::vector<ProbeVariable> vars_;
Expand All @@ -167,6 +171,7 @@ class BaseTreeFiller : boost::noncopyable {
enum WeightMode { None, Fixed, External };
WeightMode weightMode_;
edm::EDGetTokenT<double> weightSrcToken_;
edm::EDGetTokenT<double> PUweightSrcToken_;
edm::EDGetTokenT<reco::VertexCollection> recVtxsToken_;
edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
edm::EDGetTokenT<reco::CaloMETCollection> metToken_;
Expand All @@ -179,6 +184,9 @@ class BaseTreeFiller : boost::noncopyable {
/// Add branches with run and lumisection number
bool addRunLumiInfo_;

/// Store Pileup weight when running over Monte Carlo
bool storePUweight_;

/// Add branches with event variables: met, sum ET, .. etc.
bool addEventVariablesInfo_;

Expand All @@ -187,6 +195,7 @@ class BaseTreeFiller : boost::noncopyable {
//implementation notice: these two are 'mutable' because we will fill them from a 'const' method
mutable TTree * tree_;
mutable float weight_;
mutable float PUweight_;
mutable uint32_t run_, lumi_, mNPV_;
mutable uint64_t event_;

Expand Down
6 changes: 4 additions & 2 deletions PhysicsTools/TagAndProbe/interface/TPTreeFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class TPTreeFiller : public BaseTreeFiller {

// We declare 'const' the methods which don't change the configuration
void init(const edm::Event &iEvent) const ;
void fill(const reco::CandidateBaseRef &probe, double mass, bool mcTrue=false) const ;

void fill(const reco::CandidateBaseRef &probe, double mass, bool mcTrue=false, float mcMass=0.0) const ;
protected:
/// extra branch for the mass
mutable float mass_;
/// extra branch for the mc truth
mutable int32_t mcTrue_;
/// extra branch for the mc-truth mass
mutable float mcMass_;
};
}

Expand Down
12 changes: 9 additions & 3 deletions PhysicsTools/TagAndProbe/interface/TagProbeFitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class TagProbeFitter {
/// set number of bins to use when making the plots; 0 = automatic
void setBinsForMassPlots(int bins) ;

//// turn on or off the saving of distribution plots)
void setSaveDistributionsPlot(bool saveDistributionsPlot_) { doSaveDistributionsPlot = saveDistributionsPlot_; }

/// set a variable to be used as weight for a dataset. empty string means no weights.
void setWeightVar(const std::string &weight);

Expand All @@ -69,6 +72,9 @@ class TagProbeFitter {
///number of CPUs to use for the fit
int numCPU;

///save distribution plots
bool doSaveDistributionsPlot;

///the default option wether to save the workspace for each bin
bool saveWorkspace;

Expand Down Expand Up @@ -142,10 +148,10 @@ class TagProbeFitter {
void saveEfficiencyPlots(RooDataSet& eff, const TString& effName, RooArgSet& binnedVariables, RooArgSet& mappedCategories);

///makes the 1D plot
void makeEfficiencyPlot1D(RooDataSet& eff, RooRealVar& v, const TString& plotName, const TString& plotTitle, const TString& effName);

void makeEfficiencyPlot1D(RooDataSet& eff, RooRealVar& v, const TString& plotName, const TString& plotTitle, const TString& effName, const char *catName = 0, int catIndex = -1);
///makes the 2D plot
void makeEfficiencyPlot2D(RooDataSet& eff, RooRealVar& v1, RooRealVar& v2, const TString& plotName, const TString& plotTitle, const TString& effName);
void makeEfficiencyPlot2D(RooDataSet& eff, RooRealVar& v1, RooRealVar& v2, const TString& plotName, const TString& plotTitle, const TString& effName, const char *catName = 0, int catIndex = -1);

};

Expand Down
4 changes: 4 additions & 0 deletions PhysicsTools/TagAndProbe/interface/TagProbePairMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ namespace tnp {
double arbitrationMass_;
void arbitrate(TagProbePairs &pairs) const ;
TRandom2* randGen_;

// SCZ
bool phiCutForTwoLeg_;
void phiCutByEventNumber(TagProbePairs &pairs, int eventNumber) const ;
};
}

Expand Down
5 changes: 5 additions & 0 deletions PhysicsTools/TagAndProbe/interface/TriggerCandProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ class TriggerCandProducer : public edm::EDProducer
std::vector<edm::InputTag> hltTags_;
edm::InputTag theRightHLTTag_;
double delRMatchingCut_;
double objEtMin_;
double objEtaMax_;
std::string filterName_;
bool storeRefCollection_;
bool antiSelect_;
bool isTriggerOR_;
bool isFilter_;
bool noHltFiring_;
bool printIndex_;
bool changed_;
HLTConfigProvider hltConfig_;
Expand Down
95 changes: 95 additions & 0 deletions PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "PhysicsTools/TagAndProbe/plugins/AnythingToValueMap.h"
#include "DataFormats/Common/interface/AssociationVector.h"
#include "DataFormats/Common/interface/AssociationMap.h"
#include "DataFormats/Common/interface/OneToValue.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

namespace pat { namespace helper {
class AnyNumberAssociationAdaptor {
public:
typedef float value_type;
typedef edm::View<reco::Candidate> Collection;
template<typename T> struct AssoVec { typedef typename edm::AssociationVector<reco::CandidateBaseRefProd, typename std::vector<T> > type; };

AnyNumberAssociationAdaptor(const edm::InputTag &in, const edm::ParameterSet & iConfig, edm::ConsumesCollector && iC) :
type_(Uninitialized), in_(in), label_(in.label() + in.instance()),
tokenVMd_(iC.consumes<edm::ValueMap<double> >(in)),
tokenVMf_(iC.consumes<edm::ValueMap<float> >(in)),
tokenVMi_(iC.consumes<edm::ValueMap<int> >(in)),
tokenVMb_(iC.consumes<edm::ValueMap<bool> >(in)),
tokenAVd_(iC.consumes<AssoVec<double>::type >(in)),
tokenAVf_(iC.consumes<AssoVec<float>::type >(in)),
tokenAVi_(iC.consumes<AssoVec<int>::type >(in)),
tokenAVb_(iC.consumes<AssoVec<bool>::type >(in))
{ }

const std::string & label() { return label_; }

bool run(const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) {
switch (type_) {
case Uninitialized:
if (run_<edm::ValueMap<double> >(tokenVMd_, iEvent, coll, ret)) { type_ = ValueMapDouble; return true; }
if (run_<edm::ValueMap<float> >(tokenVMf_, iEvent, coll, ret)) { type_ = ValueMapFloat; return true; }
if (run_<edm::ValueMap<int> >(tokenVMi_, iEvent, coll, ret)) { type_ = ValueMapInt; return true; }
if (run_<edm::ValueMap<bool> >(tokenVMb_, iEvent, coll, ret)) { type_ = ValueMapBool; return true; }
if (run_<AssoVec<double>::type >(tokenAVd_, iEvent, coll, ret)) { type_ = AssoVecDouble; return true; }
if (run_<AssoVec<float>::type >(tokenAVf_, iEvent, coll, ret)) { type_ = AssoVecFloat; return true; }
if (run_<AssoVec<int>::type >(tokenAVi_, iEvent, coll, ret)) { type_ = AssoVecInt; return true; }
if (run_<AssoVec<bool>::type >(tokenAVb_, iEvent, coll, ret)) { type_ = AssoVecBool; return true; }
type_ = Nothing; return false;
break;
case ValueMapDouble : return run_<edm::ValueMap<double> >(tokenVMd_, iEvent, coll, ret);
case ValueMapFloat : return run_<edm::ValueMap<float> >(tokenVMf_, iEvent, coll, ret);
case ValueMapInt : return run_<edm::ValueMap<int> >(tokenVMi_, iEvent, coll, ret);
case ValueMapBool : return run_<edm::ValueMap<bool> >(tokenVMb_, iEvent, coll, ret);
case AssoVecDouble : return run_<AssoVec<double>::type >(tokenAVd_, iEvent, coll, ret);
case AssoVecFloat : return run_<AssoVec<float>::type >(tokenAVf_, iEvent, coll, ret);
case AssoVecInt : return run_<AssoVec<int>::type >(tokenAVi_, iEvent, coll, ret);
case AssoVecBool : return run_<AssoVec<bool>::type >(tokenAVb_, iEvent, coll, ret);
case Nothing : return false;
}
return false;
}
private:
enum Type { Uninitialized = 0,
ValueMapDouble, ValueMapFloat, ValueMapInt, ValueMapBool,
AssoVecDouble , AssoVecFloat, AssoVecInt, AssoVecBool,
Nothing };
template<typename T> bool run_(const edm::EDGetTokenT<T> & token, const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) ;
Type type_;
edm::InputTag in_;
std::string label_;
edm::EDGetTokenT<edm::ValueMap<double> > tokenVMd_;
edm::EDGetTokenT<edm::ValueMap<float> > tokenVMf_;
edm::EDGetTokenT<edm::ValueMap<int> > tokenVMi_;
edm::EDGetTokenT<edm::ValueMap<bool> > tokenVMb_;
edm::EDGetTokenT<AssoVec<double>::type > tokenAVd_;
edm::EDGetTokenT<AssoVec<float>::type > tokenAVf_;
edm::EDGetTokenT<AssoVec<int>::type > tokenAVi_;
edm::EDGetTokenT<AssoVec<bool>::type > tokenAVb_;

};

template<typename T>
bool AnyNumberAssociationAdaptor::run_(const edm::EDGetTokenT<T> & token, const edm::Event &iEvent, const Collection &coll, std::vector<value_type> &ret) {
edm::Handle<T> handle;
iEvent.getByToken(token, handle);
if (handle.failedToGet()) return false;

for (size_t i = 0, n = coll.size(); i < n; ++i) {
reco::CandidateBaseRef ref = coll.refAt(i);
ret.push_back( (*handle)[ref] );
}
return true;
}

typedef ManyThingsToValueMaps<AnyNumberAssociationAdaptor> AnyNumbersToValueMaps;

}} // namespaces


#include "FWCore/Framework/interface/MakerMacros.h"
using namespace pat::helper;
DEFINE_FWK_MODULE(AnyNumbersToValueMaps);