Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:39

0001 /** \class HLTJetTag
0002  *
0003  *  This class is an HLTFilter (a spcialized EDFilter) implementing
0004  *  tagged multi-jet trigger for b and tau.
0005  *  It should be run after the normal multi-jet trigger.
0006  *
0007  *
0008  *  \author Arnaud Gay, Ian Tomalin
0009  *  \maintainer Andrea Bocci
0010  *
0011  */
0012 
0013 #include <vector>
0014 #include <string>
0015 
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "DataFormats/Common/interface/Handle.h"
0018 #include "DataFormats/Common/interface/RefToBase.h"
0019 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0020 #include "DataFormats/BTauReco/interface/JetTag.h"
0021 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0022 #include "HLTrigger/HLTcore/interface/HLTFilter.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0026 
0027 #include "HLTJetTag.h"
0028 
0029 //
0030 // constructors and destructor
0031 //
0032 
0033 template <typename T>
0034 HLTJetTag<T>::HLTJetTag(const edm::ParameterSet& config)
0035     : HLTFilter(config),
0036       m_Jets(config.getParameter<edm::InputTag>("Jets")),
0037       m_JetTags(config.getParameter<edm::InputTag>("JetTags")),
0038       m_MinTag(config.getParameter<double>("MinTag")),
0039       m_MaxTag(config.getParameter<double>("MaxTag")),
0040       m_MinJets(config.getParameter<int>("MinJets")),
0041       m_TriggerType(config.getParameter<int>("TriggerType")) {
0042   m_JetsToken = consumes<std::vector<T>>(m_Jets), m_JetTagsToken = consumes<reco::JetTagCollection>(m_JetTags),
0043 
0044   edm::LogInfo("") << " (HLTJetTag) trigger cuts: " << std::endl
0045                    << "\ttype of        jets used: " << m_Jets.encode() << std::endl
0046                    << "\ttype of tagged jets used: " << m_JetTags.encode() << std::endl
0047                    << "\tmin/max tag value: [" << m_MinTag << ".." << m_MaxTag << "]" << std::endl
0048                    << "\tmin no. tagged jets: " << m_MinJets << "\tTriggerType: " << m_TriggerType << std::endl;
0049 }
0050 
0051 template <typename T>
0052 HLTJetTag<T>::~HLTJetTag() = default;
0053 
0054 template <typename T>
0055 void HLTJetTag<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0056   edm::ParameterSetDescription desc;
0057   makeHLTFilterDescription(desc);
0058   desc.add<edm::InputTag>("Jets", edm::InputTag("hltJetCollection"));
0059   desc.add<edm::InputTag>("JetTags", edm::InputTag("hltJetTagCollection"));
0060   desc.add<double>("MinTag", 2.0);
0061   desc.add<double>("MaxTag", 999999.0);
0062   desc.add<int>("MinJets", 1);
0063   desc.add<int>("TriggerType", 0);
0064   descriptions.add(defaultModuleLabel<HLTJetTag<T>>(), desc);
0065 }
0066 
0067 //
0068 // member functions
0069 //
0070 
0071 // ------------ method called to produce the data  ------------
0072 template <typename T>
0073 bool HLTJetTag<T>::hltFilter(edm::Event& event,
0074                              const edm::EventSetup& setup,
0075                              trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0076   using namespace std;
0077   using namespace edm;
0078   using namespace reco;
0079 
0080   typedef vector<T> TCollection;
0081   typedef Ref<TCollection> TRef;
0082 
0083   edm::Handle<TCollection> h_Jets;
0084   event.getByToken(m_JetsToken, h_Jets);
0085   if (saveTags())
0086     filterproduct.addCollectionTag(m_Jets);
0087 
0088   edm::Handle<JetTagCollection> h_JetTags;
0089   event.getByToken(m_JetTagsToken, h_JetTags);
0090 
0091   // check if the product this one depends on is available
0092   auto const& handle = h_JetTags;
0093   auto const& dependent = handle->keyProduct();
0094   if (not dependent.isNull() and not dependent.hasCache()) {
0095     // only an empty AssociationVector can have a invalid dependent collection
0096     edm::StableProvenance const& dependent_provenance = event.getStableProvenance(dependent.id());
0097     if (dependent_provenance.branchDescription().dropped())
0098       // FIXME the error message should be made prettier
0099       throw edm::Exception(edm::errors::ProductNotFound)
0100           << "Product " << handle.provenance()->branchName() << " requires product "
0101           << dependent_provenance.branchName() << ", which has been dropped";
0102   }
0103 
0104   TRef jetRef;
0105 
0106   // Look at all jets in decreasing order of Et.
0107   int nJet = 0;
0108   int nTag = 0;
0109   for (auto const& jet : *h_JetTags) {
0110     jetRef = TRef(h_Jets, jet.first.key());
0111     LogTrace("") << "Jet " << nJet << " : Et = " << jet.first->et() << " , tag value = " << jet.second;
0112     ++nJet;
0113     // Check if jet is tagged.
0114     if ((m_MinTag <= jet.second) and (jet.second <= m_MaxTag)) {
0115       ++nTag;
0116 
0117       // Store a reference to the jets which passed tagging cuts
0118       filterproduct.addObject(m_TriggerType, jetRef);
0119     }
0120   }
0121 
0122   // filter decision
0123   bool accept = (nTag >= m_MinJets);
0124 
0125   edm::LogInfo("") << " trigger accept ? = " << accept << " nTag/nJet = " << nTag << "/" << nJet << std::endl;
0126 
0127   return accept;
0128 }