Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "L1TElectronMatchProducer.h"
- #include <DataFormats/Common/interface/ValueMap.h>
- #include <DataFormats/Math/interface/deltaR.h>
- #include <FWCore/Framework/interface/MakerMacros.h>
- #include <limits>
- #include <vector>
- L1TElectronMatchProducer::L1TElectronMatchProducer(edm::ParameterSet const &cfg):
- maxAbsEta(cfg.getParameter<double>("maxAbsEta")),
- minIso(cfg.getParameter<int>("minIso")),
- useNominalBXOnly(cfg.getParameter<bool>("useNominalBXOnly"))
- {
- electronToken =
- consumes<std::vector<pat::Electron>>(cfg.getParameter<edm::InputTag>("electrons"));
- l1egammaToken = consumes<BXVector<l1t::EGamma>>(cfg.getParameter<edm::InputTag>("l1egamma"));
- double const maxDR = cfg.getParameter<double>("maxDR");
- maxDR2 = maxDR * maxDR;
- produces<edm::ValueMap<float>>("Et");
- produces<edm::ValueMap<float>>("dR");
- }
- void L1TElectronMatchProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions)
- {
- edm::ParameterSetDescription desc;
- desc.add<edm::InputTag>("electrons")->
- setComment("Electrons to be matched to L1T objects.");
- desc.add<edm::InputTag>("l1egamma", edm::InputTag("caloStage2Digis", "EGamma"))->
- setComment("L1T egamma objects.");
- desc.add<double>("maxDR", 0.3)->setComment("Maximal anglular distance for matching.");
- desc.add<double>("maxAbsEta", std::numeric_limits<double>::infinity())->
- setComment("Maximal |eta| to select L1T objects.");
- desc.add<int>("minIso", 0)->setComment("Minimal (hardware) isolation to select L1T objets.");
- desc.add<bool>("useNominalBXOnly", true)->
- setComment("Use L1T objects from the nominal bunch crossing only.");
- descriptions.add("firstVertexFilter", desc);
- }
- void L1TElectronMatchProducer::produce(edm::Event &event, edm::EventSetup const &eventSetup)
- {
- // Read electrons and L1T egamma objects
- edm::Handle<std::vector<pat::Electron>> electrons;
- event.getByToken(electronToken, electrons);
- edm::Handle<BXVector<l1t::EGamma>> l1egammaBX;
- event.getByToken(l1egammaToken, l1egammaBX);
- #if 0
- std::cout << "Processing event " << event.id().run() << ":" << event.id().luminosityBlock() <<
- ":" << event.id().event() << '\n';
- std::cout << " First BX: " << l1egammaBX->getFirstBX() << ", last BX: " <<
- l1egammaBX->getLastBX() << '\n';
- for (int bx = l1egammaBX->getFirstBX(); bx <= l1egammaBX->getLastBX(); ++bx)
- {
- std::cout << " Egamma objects in BX " << bx << " (et, eta, phi, hwIso):\n";
- for (auto l1objIt = l1egammaBX->begin(bx); l1objIt != l1egammaBX->end(bx); ++l1objIt)
- {
- std::cout << " " << l1objIt->et() << ", " << l1objIt->eta() << ", " <<
- l1objIt->phi() << ", " << l1objIt->hwIso() << '\n';
- }
- }
- std::cout << std::endl;
- #endif
- // Buffers for ValueMaps that will be written into the event
- std::vector<float> bufferDR, bufferEt;
- bufferDR.reserve(electrons->size());
- bufferEt.reserve(electrons->size());
- // Loop over reconstructed electrons
- for (auto const &electron: *electrons)
- {
- float matchedDR2 = std::numeric_limits<float>::infinity();
- float matchedEt = 0.;
- for (int bx = l1egammaBX->getFirstBX(); bx <= l1egammaBX->getLastBX(); ++bx)
- {
- // If requested to consider only the nominal bunch crossing, skip others
- if (useNominalBXOnly and bx != 0)
- continue;
- for (auto l1objIt = l1egammaBX->begin(bx); l1objIt != l1egammaBX->end(bx); ++l1objIt)
- {
- // Skip L1T objects that fail the selection
- if (std::abs(l1objIt->eta()) >= maxAbsEta or l1objIt->hwIso() < minIso)
- continue;
- float const dR2 = reco::deltaR2(l1objIt->eta(), l1objIt->phi(),
- electron.superCluster()->eta(), electron.superCluster()->phi());
- // If the L1T object is within the predefined distance, update Et and dR of the
- //matched object. Give priority to higher Et.
- if (dR2 < maxDR2 and l1objIt->et() > matchedEt)
- {
- matchedDR2 = dR2;
- matchedEt = l1objIt->et();
- }
- }
- }
- bufferDR.emplace_back(std::sqrt(matchedDR2));
- bufferEt.emplace_back(matchedEt);
- }
- // Create the maps and write them to the event
- std::unique_ptr<edm::ValueMap<float>> valueMapDR(new edm::ValueMap<float>());
- edm::ValueMap<float>::Filler valueMapDRFiller(*valueMapDR);
- valueMapDRFiller.insert(electrons, bufferDR.begin(), bufferDR.end());
- valueMapDRFiller.fill();
- event.put(std::move(valueMapDR), "dR");
- std::unique_ptr<edm::ValueMap<float>> valueMapEt(new edm::ValueMap<float>());
- edm::ValueMap<float>::Filler valueMapEtFiller(*valueMapEt);
- valueMapEtFiller.insert(electrons, bufferEt.begin(), bufferEt.end());
- valueMapEtFiller.fill();
- event.put(std::move(valueMapEt), "Et");
- }
- DEFINE_FWK_MODULE(L1TElectronMatchProducer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement