CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TriggerMatchProducer< object > Class Template Reference

#include <TriggerMatchProducer.h>

Inheritance diagram for TriggerMatchProducer< object >:
edm::stream::EDProducer<>

Public Member Functions

 TriggerMatchProducer (const edm::ParameterSet &)
 
 ~TriggerMatchProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

void beginRun (edm::Run const &iRun, edm::EventSetup const &iSetup) override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

edm::InputTag _inputProducer
 
edm::EDGetTokenT< edm::View< object > > _inputProducerToken
 
bool changed_
 
double delRMatchingCut_
 
std::string filterName_
 
HLTPrescaleProvider hltPrescaleProvider_
 
std::string hltTag_
 
bool storeRefCollection_
 
edm::InputTag triggerEventTag_
 
edm::EDGetTokenT< trigger::TriggerEventtriggerEventToken_
 
edm::InputTag triggerResultsTag_
 
edm::EDGetTokenT< edm::TriggerResultstriggerResultsToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

template<class object>
class TriggerMatchProducer< object >

Definition at line 30 of file TriggerMatchProducer.h.

Constructor & Destructor Documentation

◆ TriggerMatchProducer()

template<class object >
TriggerMatchProducer< object >::TriggerMatchProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 58 of file TriggerMatchProducer.h.

References TriggerMatchProducer< object >::_inputProducer, TriggerMatchProducer< object >::_inputProducerToken, TriggerMatchProducer< object >::delRMatchingCut_, TriggerMatchProducer< object >::filterName_, edm::ParameterSet::getUntrackedParameter(), TriggerMatchProducer< object >::hltTag_, AlCaHLTBitMon_QueryRunRegistry::string, TriggerMatchProducer< object >::triggerEventTag_, TriggerMatchProducer< object >::triggerEventToken_, TriggerMatchProducer< object >::triggerResultsTag_, and TriggerMatchProducer< object >::triggerResultsToken_.

59  : hltPrescaleProvider_(iConfig, consumesCollector(), *this) {
60  _inputProducer = iConfig.template getParameter<edm::InputTag>("InputProducer");
61  _inputProducerToken = consumes<edm::View<object> >(_inputProducer);
62 
63  // **************** Trigger ******************* //
64  const edm::InputTag dTriggerEventTag("hltTriggerSummaryAOD", "", "HLT");
65  triggerEventTag_ = iConfig.getUntrackedParameter<edm::InputTag>("triggerEventTag", dTriggerEventTag);
66  triggerEventToken_ = consumes<trigger::TriggerEvent>(triggerEventTag_);
67 
68  const edm::InputTag dTriggerResults("TriggerResults", "", "HLT");
69  // By default, trigger results are labeled "TriggerResults" with process name "HLT" in the event.
70  triggerResultsTag_ = iConfig.getUntrackedParameter<edm::InputTag>("triggerResultsTag", dTriggerResults);
71  triggerResultsToken_ = consumes<edm::TriggerResults>(triggerResultsTag_);
72 
73  // const edm::InputTag dHLTTag("HLT_Ele15_LW_L1R", "","HLT8E29");
74  hltTag_ = iConfig.getUntrackedParameter<std::string>("hltTag", "HLT_Ele*");
75 
76  delRMatchingCut_ = iConfig.getUntrackedParameter<double>("triggerDelRMatch", 0.30);
77  // ******************************************** //
78  //Trigger path VS l1 trigger filter. Trigger Path is default.
79  // isFilter_ = iConfig.getUntrackedParameter<bool>("isTriggerFilter",false);
80  // printIndex_ = iConfig.getUntrackedParameter<bool>("verbose",false);
81 
82  produces<edm::PtrVector<object> >();
83  produces<edm::RefToBaseVector<object> >("R");
84 
85  filterName_ = "";
86 }
HLTPrescaleProvider hltPrescaleProvider_
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag triggerResultsTag_
edm::EDGetTokenT< edm::View< object > > _inputProducerToken
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
edm::InputTag triggerEventTag_

◆ ~TriggerMatchProducer()

template<class object >
TriggerMatchProducer< object >::~TriggerMatchProducer ( )
override

Definition at line 89 of file TriggerMatchProducer.h.

89 {}

Member Function Documentation

◆ beginRun()

template<class object >
void TriggerMatchProducer< object >::beginRun ( edm::Run const &  iRun,
edm::EventSetup const &  iSetup 
)
overrideprivate

Definition at line 241 of file TriggerMatchProducer.h.

References Exception.

241  {
242  // std::cout << "calling init(" << "iRun" << ", " << "iSetup" << ", " << triggerEventTag_.process() << ", " << "changed_" << ") in beginRun()" << std::endl;
243  if (!hltPrescaleProvider_.init(iRun, iSetup, triggerEventTag_.process(), changed_)) {
244  edm::LogError("TriggerMatchProducer") << "Error! Can't initialize HLTConfigProvider";
245  throw cms::Exception("HLTConfigProvider::init() returned non 0");
246  }
247  // HLTConfigProvider const& hltConfig = hltPrescaleProvider_.hltConfigProvider();
248  // if(printIndex_ && changed_)
249  // std::cout << "HLT configuration changed !" << std::endl;
250  // std::vector<std::string> filters = hltConfig.moduleLabels( hltTag_.label() );
251 }
HLTPrescaleProvider hltPrescaleProvider_
Log< level::Error, false > LogError
edm::InputTag triggerEventTag_
std::string const & process() const
Definition: InputTag.h:40
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)

◆ produce()

template<class object >
void TriggerMatchProducer< object >::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
overrideprivate

Definition at line 97 of file TriggerMatchProducer.h.

References edm::HLTGlobalStatus::accept(), counter, gather_cfg::cout, PbPb_ZMuSkimMuonDPG_cff::deltaR, edm::HLTGlobalStatus::error(), trigger::TriggerObject::eta(), options_cfi::eventSetup, cppFunctionSkipper::exception, ALCARECOTkAlBeamHalo_cff::filter, trigger::TriggerEvent::filterIndex(), trigger::TriggerEvent::filterKeys(), filters, trigger::TriggerEvent::getObjects(), HltComparatorCreateWorkflow::hltConfig, mps_fire::i, heavyIonCSV_trainingSettings::idx, edm::HandleBase::isValid(), dqmiolumiharvest::j, eostools::move(), trigger::TriggerObject::phi(), edm::RefToBaseVector< T >::push_back(), edm::PtrVector< T >::push_back(), trigger::TriggerEvent::sizeFilters(), and edm::HLTGlobalStatus::wasrun().

97  {
98  using namespace std;
99  using namespace edm;
100  using namespace reco;
101  using namespace trigger;
102 
104 
105  // Create the output collection
106  std::unique_ptr<edm::RefToBaseVector<object> > outColRef(new edm::RefToBaseVector<object>);
107  std::unique_ptr<edm::PtrVector<object> > outColPtr(new edm::PtrVector<object>);
108 
109  // Get the input collection
110  edm::Handle<edm::View<object> > candHandle;
111  try {
112  event.getByToken(_inputProducerToken, candHandle);
113  } catch (cms::Exception& ex) {
114  edm::LogError("TriggerMatchProducer") << "Error! Can't get collection: " << _inputProducer;
115  throw ex;
116  }
117 
118  // Trigger Info
120  event.getByToken(triggerEventToken_, trgEvent);
122  event.getByToken(triggerResultsToken_, pTrgResults);
123 
124  //gracefully choose the single appropriate HLT path from the list of desired paths
125  std::vector<std::string> activeHLTPathsInThisEvent = hltConfig.triggerNames();
126  std::map<std::string, bool> triggerInMenu;
127  std::map<std::string, bool> triggerUnprescaled;
128  // for (std::vector<edm::InputTag>::const_iterator iMyHLT = hltTags_.begin();
129  // iMyHLT != hltTags_.end(); ++iMyHLT) {
130  // if ( triggerInMenu.find((*iMyHLT).label()) == triggerInMenu.end() )
131  // triggerInMenu[(*iMyHLT).label()] = false;
132  // if ( triggerUnprescaled.find((*iMyHLT).label()) == triggerUnprescaled.end() )
133  // triggerUnprescaled[(*iMyHLT).label()] = false;
134  // }
135  for (std::vector<std::string>::const_iterator iHLT = activeHLTPathsInThisEvent.begin();
136  iHLT != activeHLTPathsInThisEvent.end();
137  ++iHLT) {
138  // cout << "######## " << *iHLT << endl;
139 
140  if (TString(*iHLT).Contains(TRegexp(hltTag_))) {
141  triggerInMenu[*iHLT] = true;
143  triggerUnprescaled[*iHLT] = true;
144  }
145  }
146 
147  // Some sanity checks
148  if (not trgEvent.isValid()) {
149  edm::LogInfo("info") << "******** Following Trigger Summary Object Not Found: " << triggerEventTag_;
150 
151  event.put(std::move(outColRef), "R");
152  event.put(std::move(outColPtr));
153  return;
154  }
155 
156  //---------------------------------------------------------------------------
157 
158  edm::InputTag filterTag;
159  // loop over these objects to see whether they match
160  const trigger::TriggerObjectCollection& TOC(trgEvent->getObjects());
161 
162  std::vector<int> index;
163  std::vector<std::string> filters;
164  // if(isFilter_){
165  //-----------------------------------------------------------------------
166  for (std::map<std::string, bool>::const_iterator iMyHLT = triggerInMenu.begin(); iMyHLT != triggerInMenu.end();
167  ++iMyHLT) {
168  if (!(iMyHLT->second && triggerUnprescaled[iMyHLT->first]))
169  continue;
170 
171  int triggerIndex = -1;
172  edm::InputTag filterTag;
173  try {
174  filters = hltConfig.moduleLabels(iMyHLT->first);
175  triggerIndex = hltConfig.triggerIndex(iMyHLT->first);
176  } catch (std::exception const&) {
177  cout << "bad trigger\n";
178  }
179  // Results from TriggerResults product
180  if (triggerIndex == -1 || !(pTrgResults->wasrun(triggerIndex)) || !(pTrgResults->accept(triggerIndex)) ||
181  (pTrgResults->error(triggerIndex))) {
182  continue;
183  }
184 
185  for (std::vector<std::string>::iterator filter = filters.begin(); filter != filters.end(); ++filter) {
186  edm::InputTag testTag(*filter, "", triggerEventTag_.process());
187  int testindex = trgEvent->filterIndex(testTag);
188  if (!(testindex >= trgEvent->sizeFilters())) {
189  filterName_ = *filter;
190  filterTag = testTag;
191  }
192  }
193 
194  //using last filter tag
195  index.push_back(trgEvent->filterIndex(filterTag));
196  // std::cout << "TrgPath" << iMyHLT->first << "hltTag_.label() " <<
197  // filterTag.label() << " filter name " <<
198  // filterName_ << " sizeFilters " <<
199  // trgEvent->sizeFilters() << std::endl;
200  }
201 
202  // Loop over the candidate collection
203  edm::PtrVector<object> ptrVect;
205  for (size_t i = 0; i < candHandle->size(); ++i) {
206  ptrVect.push_back(candHandle->ptrAt(i));
207  refs.push_back(candHandle->refAt(i));
208  }
209  // find how many objects there are
210  unsigned int counter = 0;
211  for (typename edm::View<object>::const_iterator j = candHandle->begin(); j != candHandle->end(); ++j, ++counter) {
212  bool hltTrigger = false;
213  for (unsigned int idx = 0; idx < index.size(); ++idx) {
214  if (hltTrigger)
215  continue;
216  const trigger::Keys& KEYS(trgEvent->filterKeys(index[idx]));
217  const size_type nK(KEYS.size());
218  // Get cut decision for each candidate
219  // Did this candidate cause a HLT trigger?
220 
221  for (int ipart = 0; ipart != nK; ++ipart) {
222  const trigger::TriggerObject& TO = TOC[KEYS[ipart]];
223  double dRval = deltaR(j->eta(), j->phi(), TO.eta(), TO.phi());
224  hltTrigger = dRval < delRMatchingCut_;
225  if (hltTrigger)
226  break;
227  }
228  }
229 
230  if (hltTrigger) {
231  outColRef->push_back(refs[counter]);
232  outColPtr->push_back(ptrVect[counter]);
233  }
234  }
235  event.put(std::move(outColRef), "R");
236  event.put(std::move(outColPtr));
237 }
bool accept() const
Has at least one path accepted the event?
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:118
bool error() const
Has any path encountered an error (exception)
HLTPrescaleProvider hltPrescaleProvider_
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
T prescaleValue(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
combining the two methods above
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:146
HLTConfigProvider const & hltConfigProvider() const
Log< level::Error, false > LogError
uint16_t size_type
std::vector< TPRegexp > filters
Definition: eve_filter.cc:22
bool wasrun() const
Was at least one path run?
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:101
edm::EDGetTokenT< edm::View< object > > _inputProducerToken
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
Log< level::Info, false > LogInfo
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:132
edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
std::vector< size_type > Keys
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
static std::atomic< unsigned int > counter
void push_back(const RefToBase< T > &)
edm::InputTag triggerEventTag_
std::string const & process() const
Definition: InputTag.h:40
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1

Member Data Documentation

◆ _inputProducer

template<class object >
edm::InputTag TriggerMatchProducer< object >::_inputProducer
private

◆ _inputProducerToken

template<class object >
edm::EDGetTokenT<edm::View<object> > TriggerMatchProducer< object >::_inputProducerToken
private

◆ changed_

template<class object >
bool TriggerMatchProducer< object >::changed_
private

Definition at line 53 of file TriggerMatchProducer.h.

◆ delRMatchingCut_

template<class object >
double TriggerMatchProducer< object >::delRMatchingCut_
private

◆ filterName_

template<class object >
std::string TriggerMatchProducer< object >::filterName_
private

◆ hltPrescaleProvider_

template<class object >
HLTPrescaleProvider TriggerMatchProducer< object >::hltPrescaleProvider_
private

Definition at line 54 of file TriggerMatchProducer.h.

◆ hltTag_

template<class object >
std::string TriggerMatchProducer< object >::hltTag_
private

◆ storeRefCollection_

template<class object >
bool TriggerMatchProducer< object >::storeRefCollection_
private

Definition at line 50 of file TriggerMatchProducer.h.

◆ triggerEventTag_

template<class object >
edm::InputTag TriggerMatchProducer< object >::triggerEventTag_
private

◆ triggerEventToken_

template<class object >
edm::EDGetTokenT<trigger::TriggerEvent> TriggerMatchProducer< object >::triggerEventToken_
private

◆ triggerResultsTag_

template<class object >
edm::InputTag TriggerMatchProducer< object >::triggerResultsTag_
private

◆ triggerResultsToken_

template<class object >
edm::EDGetTokenT<edm::TriggerResults> TriggerMatchProducer< object >::triggerResultsToken_
private