Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. #include "L1TElectronMatchProducer.h"
  2.  
  3. #include <DataFormats/Common/interface/ValueMap.h>
  4. #include <DataFormats/Math/interface/deltaR.h>
  5. #include <FWCore/Framework/interface/MakerMacros.h>
  6.  
  7. #include <limits>
  8. #include <vector>
  9.  
  10.  
  11.  
  12. L1TElectronMatchProducer::L1TElectronMatchProducer(edm::ParameterSet const &cfg):
  13. maxAbsEta(cfg.getParameter<double>("maxAbsEta")),
  14. minIso(cfg.getParameter<int>("minIso")),
  15. useNominalBXOnly(cfg.getParameter<bool>("useNominalBXOnly"))
  16. {
  17. electronToken =
  18. consumes<std::vector<pat::Electron>>(cfg.getParameter<edm::InputTag>("electrons"));
  19. l1egammaToken = consumes<BXVector<l1t::EGamma>>(cfg.getParameter<edm::InputTag>("l1egamma"));
  20.  
  21. double const maxDR = cfg.getParameter<double>("maxDR");
  22. maxDR2 = maxDR * maxDR;
  23.  
  24.  
  25. produces<edm::ValueMap<float>>("Et");
  26. produces<edm::ValueMap<float>>("dR");
  27. }
  28.  
  29.  
  30. void L1TElectronMatchProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions)
  31. {
  32. edm::ParameterSetDescription desc;
  33. desc.add<edm::InputTag>("electrons")->
  34. setComment("Electrons to be matched to L1T objects.");
  35. desc.add<edm::InputTag>("l1egamma", edm::InputTag("caloStage2Digis", "EGamma"))->
  36. setComment("L1T egamma objects.");
  37. desc.add<double>("maxDR", 0.3)->setComment("Maximal anglular distance for matching.");
  38. desc.add<double>("maxAbsEta", std::numeric_limits<double>::infinity())->
  39. setComment("Maximal |eta| to select L1T objects.");
  40. desc.add<int>("minIso", 0)->setComment("Minimal (hardware) isolation to select L1T objets.");
  41. desc.add<bool>("useNominalBXOnly", true)->
  42. setComment("Use L1T objects from the nominal bunch crossing only.");
  43.  
  44. descriptions.add("firstVertexFilter", desc);
  45. }
  46.  
  47.  
  48. void L1TElectronMatchProducer::produce(edm::Event &event, edm::EventSetup const &eventSetup)
  49. {
  50. // Read electrons and L1T egamma objects
  51. edm::Handle<std::vector<pat::Electron>> electrons;
  52. event.getByToken(electronToken, electrons);
  53.  
  54. edm::Handle<BXVector<l1t::EGamma>> l1egammaBX;
  55. event.getByToken(l1egammaToken, l1egammaBX);
  56.  
  57. #if 0
  58. std::cout << "Processing event " << event.id().run() << ":" << event.id().luminosityBlock() <<
  59. ":" << event.id().event() << '\n';
  60. std::cout << " First BX: " << l1egammaBX->getFirstBX() << ", last BX: " <<
  61. l1egammaBX->getLastBX() << '\n';
  62.  
  63. for (int bx = l1egammaBX->getFirstBX(); bx <= l1egammaBX->getLastBX(); ++bx)
  64. {
  65. std::cout << " Egamma objects in BX " << bx << " (et, eta, phi, hwIso):\n";
  66.  
  67. for (auto l1objIt = l1egammaBX->begin(bx); l1objIt != l1egammaBX->end(bx); ++l1objIt)
  68. {
  69. std::cout << " " << l1objIt->et() << ", " << l1objIt->eta() << ", " <<
  70. l1objIt->phi() << ", " << l1objIt->hwIso() << '\n';
  71. }
  72. }
  73.  
  74. std::cout << std::endl;
  75. #endif
  76.  
  77.  
  78. // Buffers for ValueMaps that will be written into the event
  79. std::vector<float> bufferDR, bufferEt;
  80. bufferDR.reserve(electrons->size());
  81. bufferEt.reserve(electrons->size());
  82.  
  83.  
  84. // Loop over reconstructed electrons
  85. for (auto const &electron: *electrons)
  86. {
  87. float matchedDR2 = std::numeric_limits<float>::infinity();
  88. float matchedEt = 0.;
  89.  
  90. for (int bx = l1egammaBX->getFirstBX(); bx <= l1egammaBX->getLastBX(); ++bx)
  91. {
  92. // If requested to consider only the nominal bunch crossing, skip others
  93. if (useNominalBXOnly and bx != 0)
  94. continue;
  95.  
  96. for (auto l1objIt = l1egammaBX->begin(bx); l1objIt != l1egammaBX->end(bx); ++l1objIt)
  97. {
  98. // Skip L1T objects that fail the selection
  99. if (std::abs(l1objIt->eta()) >= maxAbsEta or l1objIt->hwIso() < minIso)
  100. continue;
  101.  
  102. float const dR2 = reco::deltaR2(l1objIt->eta(), l1objIt->phi(),
  103. electron.superCluster()->eta(), electron.superCluster()->phi());
  104.  
  105.  
  106. // If the L1T object is within the predefined distance, update Et and dR of the
  107. //matched object. Give priority to higher Et.
  108. if (dR2 < maxDR2 and l1objIt->et() > matchedEt)
  109. {
  110. matchedDR2 = dR2;
  111. matchedEt = l1objIt->et();
  112. }
  113. }
  114. }
  115.  
  116. bufferDR.emplace_back(std::sqrt(matchedDR2));
  117. bufferEt.emplace_back(matchedEt);
  118. }
  119.  
  120.  
  121. // Create the maps and write them to the event
  122. std::unique_ptr<edm::ValueMap<float>> valueMapDR(new edm::ValueMap<float>());
  123. edm::ValueMap<float>::Filler valueMapDRFiller(*valueMapDR);
  124. valueMapDRFiller.insert(electrons, bufferDR.begin(), bufferDR.end());
  125. valueMapDRFiller.fill();
  126. event.put(std::move(valueMapDR), "dR");
  127.  
  128. std::unique_ptr<edm::ValueMap<float>> valueMapEt(new edm::ValueMap<float>());
  129. edm::ValueMap<float>::Filler valueMapEtFiller(*valueMapEt);
  130. valueMapEtFiller.insert(electrons, bufferEt.begin(), bufferEt.end());
  131. valueMapEtFiller.fill();
  132. event.put(std::move(valueMapEt), "Et");
  133. }
  134.  
  135.  
  136. DEFINE_FWK_MODULE(L1TElectronMatchProducer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement