CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
JetTagProducer Class Reference

#include <RecoBTag/JetTagProducer/src/JetTagProducer.cc>

Inheritance diagram for JetTagProducer:
edm::stream::EDProducer<>

Public Member Functions

 JetTagProducer (const edm::ParameterSet &)
 
 ~JetTagProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::string m_jetTagComputer
 
unsigned int nTagInfos
 
edm::ESWatcher< JetTagComputerRecordrecordWatcher_
 
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > token_tagInfos
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Description: Uses a JetTagComputer to produce JetTags from TagInfos

Implementation: <Notes on="" implementation>="">

Definition at line 22 of file JetTagProducer.h.

Constructor & Destructor Documentation

JetTagProducer::JetTagProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 51 of file JetTagProducer.cc.

References edm::ParameterSet::getParameter(), mps_fire::i, nTagInfos, and token_tagInfos.

51  :
52  m_jetTagComputer(iConfig.getParameter<string>("jetTagComputer"))
53 {
54  std::vector<edm::InputTag> m_tagInfos = iConfig.getParameter< vector<InputTag> >("tagInfos");
55  nTagInfos = m_tagInfos.size();
56  for(unsigned int i = 0; i < nTagInfos; i++) {
57  token_tagInfos.push_back( consumes<View<BaseTagInfo> >(m_tagInfos[i]) );
58  }
59 
60  produces<JetTagCollection>();
61 }
T getParameter(std::string const &) const
std::string m_jetTagComputer
unsigned int nTagInfos
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > token_tagInfos
JetTagProducer::~JetTagProducer ( )
override

Definition at line 63 of file JetTagProducer.cc.

References edm::RefToBase< T >::id(), and edm::RefToBase< T >::key().

64 {
65 }

Member Function Documentation

void JetTagProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 155 of file JetTagProducer.cc.

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addDefault(), DEFINE_FWK_MODULE, AlCaHLTBitMon_QueryRunRegistry::string, and combinedMVAV2BJetTags_cfi::tagInfos.

155  {
156 
158  desc.add<std::string>("jetTagComputer","combinedMVAComputer");
159  {
160  std::vector<edm::InputTag> tagInfos;
161  tagInfos.push_back(edm::InputTag("impactParameterTagInfos"));
162  tagInfos.push_back(edm::InputTag("inclusiveSecondaryVertexFinderTagInfos"));
163  tagInfos.push_back(edm::InputTag("softPFMuonsTagInfos"));
164  tagInfos.push_back(edm::InputTag("softPFElectronsTagInfos"));
165  desc.add<std::vector<edm::InputTag> >("tagInfos",tagInfos);
166  }
167  descriptions.addDefault(desc);
168 }
void addDefault(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void JetTagProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 82 of file JetTagProducer.cc.

References edm::ESWatcher< T >::check(), caloDeepCSVTagInfos_cfi::computer, edm::errors::Configuration, mvaPFMET_leptons_cfi::discriminator, Exception, edm::EventSetup::get(), edm::Event::getByToken(), JetTagComputer::getInputLabels(), mps_fire::i, findQualityFiles::jj, m_jetTagComputer, edm::makeRefToBaseProdFrom(), eostools::move(), nTagInfos, edm::Handle< T >::product(), edm::Event::put(), recordWatcher_, AlCaHLTBitMon_QueryRunRegistry::string, combinedMVAV2BJetTags_cfi::tagInfos, and token_tagInfos.

83 {
85  iSetup.get<JetTagComputerRecord>().get( m_jetTagComputer, computer );
86 
87  if (recordWatcher_.check(iSetup) ) {
88  unsigned int nLabels = computer->getInputLabels().size();
89  if (nLabels == 0) ++nLabels;
90  if (nTagInfos != nLabels) {
91 
92  vector<string> inputLabels(computer->getInputLabels());
93  // backward compatible case, use default tagInfo
94  if (inputLabels.empty())
95  inputLabels.push_back("tagInfo");
96  std::string message("VInputTag size mismatch - the following taginfo "
97  "labels are needed:\n");
98  for(vector<string>::const_iterator iter = inputLabels.begin();
99  iter != inputLabels.end(); ++iter)
100  message += "\"" + *iter + "\"\n";
101  throw edm::Exception(errors::Configuration) << message;
102  }
103  }
104 
105  // now comes the tricky part:
106  // we need to collect all requested TagInfos belonging to the same jet
107 
108  typedef vector<const BaseTagInfo*> TagInfoPtrs;
109  typedef RefToBase<Jet> JetRef;
110  typedef map<JetRef, TagInfoPtrs, JetRefCompare> JetToTagInfoMap;
111 
112  JetToTagInfoMap jetToTagInfos;
113 
114  // retrieve all requested TagInfos
115  vector< Handle< View<BaseTagInfo> > > tagInfoHandles(nTagInfos);
116  for(unsigned int i = 0; i < nTagInfos; i++) {
117  Handle< View<BaseTagInfo> > &tagInfoHandle = tagInfoHandles[i];
118  iEvent.getByToken(token_tagInfos[i], tagInfoHandle);
119 
120  for(View<BaseTagInfo>::const_iterator iter = tagInfoHandle->begin();
121  iter != tagInfoHandle->end(); iter++) {
122  TagInfoPtrs &tagInfos = jetToTagInfos[iter->jet()];
123  if (tagInfos.empty())
124  tagInfos.resize(nTagInfos);
125 
126  tagInfos[i] = &*iter;
127  }
128  }
129 
130  // take first tagInfo
131  Handle< View<BaseTagInfo> > &tagInfoHandle = tagInfoHandles[0];
132  std::unique_ptr<JetTagCollection> jetTagCollection;
133  if (!tagInfoHandle.product()->empty()) {
134  RefToBase<Jet> jj = tagInfoHandle->begin()->jet();
135  jetTagCollection = std::make_unique<JetTagCollection>(edm::makeRefToBaseProdFrom(jj, iEvent));
136  } else
137  jetTagCollection = std::make_unique<JetTagCollection>();
138 
139  // now loop over the map and compute all JetTags
140  for(JetToTagInfoMap::const_iterator iter = jetToTagInfos.begin();
141  iter != jetToTagInfos.end(); iter++) {
142  const TagInfoPtrs &tagInfoPtrs = iter->second;
143 
145  float discriminator = (*computer)(helper);
146 
147  (*jetTagCollection)[iter->first] = discriminator;
148  }
149 
150  iEvent.put(std::move(jetTagCollection));
151 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
Definition: helper.py:1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::string m_jetTagComputer
unsigned int nTagInfos
edm::Ref< JetBxCollection > JetRef
Definition: Jet.h:13
const std::vector< std::string > & getInputLabels() const
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > token_tagInfos
T const * product() const
Definition: Handle.h:74
edm::ESWatcher< JetTagComputerRecord > recordWatcher_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
T get() const
Definition: EventSetup.h:71
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

std::string JetTagProducer::m_jetTagComputer
private

Definition at line 31 of file JetTagProducer.h.

Referenced by produce().

unsigned int JetTagProducer::nTagInfos
private

Definition at line 33 of file JetTagProducer.h.

Referenced by JetTagProducer(), and produce().

edm::ESWatcher<JetTagComputerRecord> JetTagProducer::recordWatcher_
private

Definition at line 34 of file JetTagProducer.h.

Referenced by produce().

std::vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo> > > JetTagProducer::token_tagInfos
private

Definition at line 32 of file JetTagProducer.h.

Referenced by JetTagProducer(), and produce().