Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9512 from gpetruc/TnP-75X-Bare
Fixes for Tag&Probe in 7.5.X (fix of #8801)
- Loading branch information
Showing
26 changed files
with
884 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
MuonAnalysis/MuonAssociators/plugins/TriggerObjectFilterByCollection.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.