File indexing completed on 2024-04-06 12:18:59
0001 #include "HLTriggerOffline/Tau/interface/HLTTauRefCombiner.h"
0002 #include "Math/GenVector/VectorUtil.h"
0003
0004 using namespace edm;
0005 using namespace std;
0006
0007 HLTTauRefCombiner::HLTTauRefCombiner(const edm::ParameterSet &iConfig)
0008 : matchDeltaR_{iConfig.getParameter<double>("MatchDeltaR")},
0009 outName_{iConfig.getParameter<string>("OutputCollection")} {
0010 std::vector<edm::InputTag> inputCollVector_ = iConfig.getParameter<std::vector<InputTag>>("InputCollections");
0011 for (unsigned int ii = 0; ii < inputCollVector_.size(); ++ii) {
0012 inputColl_.push_back(consumes<LorentzVectorCollection>(inputCollVector_[ii]));
0013 }
0014
0015 produces<LorentzVectorCollection>(outName_);
0016 }
0017
0018 void HLTTauRefCombiner::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iES) const {
0019 unique_ptr<LorentzVectorCollection> out_product(new LorentzVectorCollection);
0020
0021
0022 std::vector<Handle<LorentzVectorCollection>> handles;
0023
0024 bool allCollectionsExist = true;
0025
0026 for (size_t i = 0; i < inputColl_.size(); ++i) {
0027 edm::Handle<LorentzVectorCollection> tmp;
0028 if (iEvent.getByToken(inputColl_[i], tmp)) {
0029 handles.push_back(tmp);
0030 } else {
0031 allCollectionsExist = false;
0032 }
0033 }
0034
0035
0036 if (allCollectionsExist) {
0037
0038 for (size_t i = 0; i < (handles[0])->size(); ++i) {
0039 bool MatchedObj = true;
0040
0041
0042 const LorentzVector lvRef = (*(handles[0]))[i];
0043
0044
0045 for (size_t j = 1; j < handles.size(); ++j) {
0046 if (!match(lvRef, *(handles[j])))
0047 MatchedObj = false;
0048 }
0049
0050
0051 if (MatchedObj) {
0052 out_product->push_back(lvRef);
0053 }
0054 }
0055
0056
0057 iEvent.put(std::move(out_product), outName_);
0058 }
0059 }
0060
0061 bool HLTTauRefCombiner::match(const LorentzVector &lv, const LorentzVectorCollection &lvcol) const {
0062 bool matched = false;
0063
0064 if (!lvcol.empty())
0065 for (LorentzVectorCollection::const_iterator it = lvcol.begin(); it != lvcol.end(); ++it) {
0066 double delta = ROOT::Math::VectorUtil::DeltaR(lv, *it);
0067 if (delta < matchDeltaR_) {
0068 matched = true;
0069 }
0070 }
0071
0072 return matched;
0073 }