95 void endJob()
override;
102 double match_trigger(std::vector<int> &trigIndices,
148 maxMuon_ = iConfig.
getParameter<
unsigned int>(
"maxMuon");
149 isoTriggerNames_ = iConfig.
getParameter<std::vector<std::string>>(
"isoTriggerNames");
153 VtxToken_ = consumes<reco::VertexCollection>(
156 TriggerResultsToken_ = consumes<edm::TriggerResults>(
158 triggerSummaryLabelToken_ = consumes<trigger::TriggerEvent>(
166 muon_data =
muon->getData();
168 tree_ = fs_->make<TTree>(
"Muon2RecoTree",
"Muon2RecoTree");
169 tree_->Branch(
"Muon",
"L1Analysis::L1AnalysisRecoMuon2DataFormat", &muon_data, 32000, 3);
171 triggerMaxDeltaR_ = iConfig.
getParameter<
double>(
"triggerMaxDeltaR");
174 isoTriggerNames_ = iConfig.
getParameter<std::vector<std::string>>(
"isoTriggerNames");
175 triggerNames_ = iConfig.
getParameter<std::vector<std::string>>(
"triggerNames");
199 iEvent.getByToken(MuonToken_, recoMuons);
208 iEvent.getByToken(triggerSummaryLabelToken_, triggerSummaryLabel_);
211 iEvent.getByToken(metToken_, metLabel_);
218 for (reco::PFMETCollection::const_iterator imet = metLabel_->begin();
219 imet != metLabel_->end() && (unsigned)counter_met < 1;
231 for (reco::MuonCollection::const_iterator imu = recoMuons->begin();
232 imu != recoMuons->end() && (unsigned)counter_mu < maxMuon_;
238 if (triggerMatching_) {
239 double isoMatchDeltaR = 9999.;
240 double matchDeltaR = 9999.;
241 int hasIsoTriggered = 0;
242 int hasTriggered = 0;
244 int passesSingleMuonFlag = 0;
248 if (triggerSummaryLabel_.
isValid()) {
255 for (UInt_t iPath = 0; iPath < isoTriggerNames_.size(); ++iPath) {
256 if (passesSingleMuonFlag == 1)
269 passesSingleMuonFlag = 1;
272 if (triggerSummaryLabel_.
isValid()) {
276 matchDeltaR = match_trigger(triggerIndices_,
triggerObjects, triggerSummaryLabel_, (*imu));
277 if (matchDeltaR < triggerMaxDeltaR_)
284 isoMatchDeltaR = match_trigger(isoTriggerIndices_,
triggerObjects, triggerSummaryLabel_, (*imu));
285 if (isoMatchDeltaR < triggerMaxDeltaR_)
295 muon_data->hlt_isomu.push_back(hasIsoTriggered);
296 muon_data->hlt_mu.push_back(hasTriggered);
297 muon_data->hlt_isoDeltaR.push_back(isoMatchDeltaR);
298 muon_data->hlt_deltaR.push_back(matchDeltaR);
299 muon_data->passesSingleMuon.push_back(passesSingleMuonFlag);
316 muon_data->hlt_isomu.push_back(-9999);
317 muon_data->hlt_mu.push_back(-9999);
318 muon_data->hlt_isoDeltaR.push_back(-9999);
319 muon_data->hlt_deltaR.push_back(-9999);
326 double matchDeltaR = 9999;
328 for (
size_t iTrigIndex = 0; iTrigIndex < trigIndices.size(); ++iTrigIndex) {
329 int triggerIndex = trigIndices[iTrigIndex];
330 const std::vector<std::string> moduleLabels(hltConfig_.moduleLabels(triggerIndex));
332 const unsigned moduleIndex = hltConfig_.size(triggerIndex) - 2;
334 const unsigned hltFilterIndex =
337 if (hltFilterIndex < triggerEvent->sizeFilters()) {
341 const unsigned nTriggers = triggerVids.size();
342 for (
size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
346 double dRtmp =
deltaR(
mu, trigObject);
348 if (dRtmp < matchDeltaR) {
362 if (triggerMatching_) {
364 if (!hltConfig_.init(
run,
eventSetup, triggerProcessLabel_, changed)) {
366 std::cout <<
"Error: didn't find process" << triggerProcessLabel_ << std::endl;
370 bool enableWildcard =
true;
371 for (
size_t iTrig = 0; iTrig < triggerNames_.size(); ++iTrig) {
373 TString tNameTmp = TString(triggerNames_[iTrig]);
374 TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
377 for (
unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
379 TString tmpName = TString(hltConfig_.triggerName(ipath));
380 if (tmpName.Contains(tNamePattern)) {
382 triggerIndices_.push_back(tIndex);
386 std::cout <<
"Warning: Could not find trigger" << triggerNames_[iTrig] << std::endl;
390 for (
size_t iTrig = 0; iTrig < isoTriggerNames_.size(); ++iTrig) {
392 TString tNameTmp = TString(isoTriggerNames_[iTrig]);
393 TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
396 for (
unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
398 TString tmpName = TString(hltConfig_.triggerName(ipath));
399 if (tmpName.Contains(tNamePattern)) {
401 isoTriggerIndices_.push_back(tIndex);
405 std::cout <<
"Warning: Could not find trigger" << isoTriggerNames_[iTrig] << std::endl;
static const std::string kSharedResource
L1Analysis::L1AnalysisRecoMuon2DataFormat * muon_data
T getParameter(std::string const &) const
~L1Muon2RecoTreeProducer() override
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(edm::Run const &, edm::EventSetup const &) override
void beginRun(const edm::Run &, const edm::EventSetup &) override
T getUntrackedParameter(std::string const &, T const &) const
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)
edm::EDGetTokenT< reco::MuonCollection > MuonToken_
edm::Service< TFileService > fs_
const TriggerObjectCollection & getObjects() const
#define DEFINE_FWK_MODULE(type)
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_
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::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_