94 void endJob()
override;
101 double match_trigger(std::vector<int> &trigIndices,
145 maxMuon_ = iConfig.
getParameter<
unsigned int>(
"maxMuon");
146 isoTriggerNames_ = iConfig.
getParameter<std::vector<std::string>>(
"isoTriggerNames");
150 VtxToken_ = consumes<reco::VertexCollection>(
153 TriggerResultsToken_ = consumes<edm::TriggerResults>(
155 triggerSummaryLabelToken_ = consumes<trigger::TriggerEvent>(
163 muon_data = muon->getData();
165 tree_ = fs_->make<TTree>(
"Muon2RecoTree",
"Muon2RecoTree");
166 tree_->Branch(
"Muon",
"L1Analysis::L1AnalysisRecoMuon2DataFormat", &muon_data, 32000, 3);
168 triggerMaxDeltaR_ = iConfig.
getParameter<
double>(
"triggerMaxDeltaR");
171 isoTriggerNames_ = iConfig.
getParameter<std::vector<std::string>>(
"isoTriggerNames");
172 triggerNames_ = iConfig.
getParameter<std::vector<std::string>>(
"triggerNames");
201 iEvent.
getByToken(TriggerResultsToken_, triggerResults);
204 iEvent.
getByToken(triggerSummaryLabelToken_, triggerSummaryLabel_);
214 for (reco::PFMETCollection::const_iterator imet = metLabel_->begin();
215 imet != metLabel_->end() && (unsigned)counter_met < 1;
222 muon->SetMuon(iEvent, iSetup, recoMuons, vertices, METx, METy, maxMuon_);
227 for (reco::MuonCollection::const_iterator imu = recoMuons->begin();
228 imu != recoMuons->end() && (unsigned)counter_mu < maxMuon_;
234 if (triggerMatching_) {
235 double isoMatchDeltaR = 9999.;
236 double matchDeltaR = 9999.;
237 int hasIsoTriggered = 0;
238 int hasTriggered = 0;
240 int passesSingleMuonFlag = 0;
243 if (triggerResults.
isValid()) {
244 if (triggerSummaryLabel_.
isValid()) {
251 for (UInt_t iPath = 0; iPath < isoTriggerNames_.size(); ++iPath) {
252 if (passesSingleMuonFlag == 1)
265 passesSingleMuonFlag = 1;
268 if (triggerSummaryLabel_.
isValid()) {
272 matchDeltaR = match_trigger(triggerIndices_, triggerObjects, triggerSummaryLabel_, (*imu));
273 if (matchDeltaR < triggerMaxDeltaR_)
280 isoMatchDeltaR = match_trigger(isoTriggerIndices_, triggerObjects, triggerSummaryLabel_, (*imu));
281 if (isoMatchDeltaR < triggerMaxDeltaR_)
291 muon_data->hlt_isomu.push_back(hasIsoTriggered);
292 muon_data->hlt_mu.push_back(hasTriggered);
293 muon_data->hlt_isoDeltaR.push_back(isoMatchDeltaR);
294 muon_data->hlt_deltaR.push_back(matchDeltaR);
295 muon_data->passesSingleMuon.push_back(passesSingleMuonFlag);
312 muon_data->hlt_isomu.push_back(-9999);
313 muon_data->hlt_mu.push_back(-9999);
314 muon_data->hlt_isoDeltaR.push_back(-9999);
315 muon_data->hlt_deltaR.push_back(-9999);
322 double matchDeltaR = 9999;
324 for (
size_t iTrigIndex = 0; iTrigIndex < trigIndices.size(); ++iTrigIndex) {
325 int triggerIndex = trigIndices[iTrigIndex];
326 const std::vector<std::string> moduleLabels(hltConfig_.moduleLabels(triggerIndex));
328 const unsigned moduleIndex = hltConfig_.size(triggerIndex) - 2;
330 const unsigned hltFilterIndex =
333 if (hltFilterIndex < triggerEvent->sizeFilters()) {
337 const unsigned nTriggers = triggerVids.size();
338 for (
size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
342 double dRtmp =
deltaR(mu, trigObject);
344 if (dRtmp < matchDeltaR) {
358 if (triggerMatching_) {
360 if (!hltConfig_.init(run, eventSetup, triggerProcessLabel_, changed)) {
362 std::cout <<
"Error: didn't find process" << triggerProcessLabel_ << std::endl;
366 bool enableWildcard =
true;
367 for (
size_t iTrig = 0; iTrig < triggerNames_.size(); ++iTrig) {
369 TString tNameTmp = TString(triggerNames_[iTrig]);
370 TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
373 for (
unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
375 TString tmpName = TString(hltConfig_.triggerName(ipath));
376 if (tmpName.Contains(tNamePattern)) {
378 triggerIndices_.push_back(tIndex);
382 std::cout <<
"Warning: Could not find trigger" << triggerNames_[iTrig] << std::endl;
386 for (
size_t iTrig = 0; iTrig < isoTriggerNames_.size(); ++iTrig) {
388 TString tNameTmp = TString(isoTriggerNames_[iTrig]);
389 TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
392 for (
unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
394 TString tmpName = TString(hltConfig_.triggerName(ipath));
395 if (tmpName.Contains(tNamePattern)) {
397 isoTriggerIndices_.push_back(tIndex);
401 std::cout <<
"Warning: Could not find trigger" << isoTriggerNames_[iTrig] << std::endl;
407 muon->init(eventSetup);
L1Analysis::L1AnalysisRecoMuon2DataFormat * muon_data
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool accept() const
Has at least one path accepted the event?
const Keys & filterKeys(trigger::size_type index) const
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
~L1Muon2RecoTreeProducer() override
Strings::size_type size() const
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginRun(const edm::Run &, const edm::EventSetup &) override
Single trigger physics object (e.g., an isolated muon)
double match_trigger(std::vector< int > &trigIndices, const trigger::TriggerObjectCollection &trigObjs, edm::Handle< trigger::TriggerEvent > &triggerEvent, const reco::Muon &mu)
const Vids & filterIds(trigger::size_type index) const
edm::EDGetTokenT< reco::MuonCollection > MuonToken_
#define DEFINE_FWK_MODULE(type)
edm::Service< TFileService > fs_
unsigned int triggerIndex(std::string const &name) const
const TriggerObjectCollection & getObjects() const
static std::string const triggerResults
HLTConfigProvider hltConfig_
edm::Handle< edm::TriggerResults > isoTriggerToken_
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
static const char *const trigNames[]
std::vector< size_type > Keys
L1Muon2RecoTreeProducer(const edm::ParameterSet &)
std::string triggerProcessLabel_
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< edm::TriggerResults > TriggerResultsToken_
void beginJob(void) override
edm::EDGetTokenT< reco::VertexCollection > VtxToken_
edm::Handle< std::vector< std::string > > isoTriggerNamesToken_
L1Analysis::L1AnalysisRecoMuon2 * muon
std::vector< int > triggerIndices_
std::vector< int > isoTriggerIndices_
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryLabelToken_
std::vector< std::string > triggerNames_
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
edm::EDGetTokenT< reco::PFMETCollection > metToken_
bool passTrig(const float objEta, float objPhi, const trigger::TriggerEvent &trigEvt, const std::string &filterName, const std::string &processName)
std::vector< std::string > isoTriggerNames_