CMS 3D CMS Logo

AlCaIsolatedBunchSelector.cc
Go to the documentation of this file.
1 // system include files
2 #include <atomic>
3 #include <memory>
4 #include <cmath>
5 #include <iostream>
6 #include <sstream>
7 #include <fstream>
8 
9 // user include files
20 
22 //Triggers
25 //
26 // class declaration
27 //
28 
29 //#define EDM_ML_DEBUG
30 
31 namespace AlCaIsolatedBunch {
32  struct Counters {
33  Counters() : nAll_(0), nGood_(0) {}
34  mutable std::atomic<unsigned int> nAll_, nGood_;
35  };
36 } // namespace AlCaIsolatedBunch
37 
38 class AlCaIsolatedBunchSelector : public edm::stream::EDFilter<edm::GlobalCache<AlCaIsolatedBunch::Counters> > {
39 public:
41  ~AlCaIsolatedBunchSelector() override;
42 
43  static std::unique_ptr<AlCaIsolatedBunch::Counters> initializeGlobalCache(edm::ParameterSet const& iConfig) {
44  return std::make_unique<AlCaIsolatedBunch::Counters>();
45  }
46 
47  bool filter(edm::Event&, edm::EventSetup const&) override;
48  void endStream() override;
49  static void globalEndJob(const AlCaIsolatedBunch::Counters* counters);
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52 private:
53  void beginRun(edm::Run const&, edm::EventSetup const&) override;
54  void endRun(edm::Run const&, edm::EventSetup const&) override;
55 
56  // ----------member data ---------------------------
61  unsigned int nRun_, nAll_, nGood_;
63 };
64 
65 //
66 // constructors and destructor
67 //
70  : nRun_(0), nAll_(0), nGood_(0) {
71  //now do what ever initialization is needed
72  trigName_ = iConfig.getParameter<std::string>("triggerName");
73  processName_ = iConfig.getParameter<std::string>("processName");
74  theTriggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("triggerResultLabel");
75 
76  // define tokens for access
77  tok_trigRes_ = consumes<edm::TriggerResults>(theTriggerResultsLabel_);
78 
79  edm::LogVerbatim("AlCaIsoBunch") << "Input tag for trigger results " << theTriggerResultsLabel_
80  << " with trigger name " << trigName_ << " and process " << processName_
81  << std::endl;
82 }
83 
85 
86 //
87 // member functions
88 //
89 
90 // ------------ method called on each new Event ------------
92  bool accept(false);
93  ++nAll_;
94 #ifdef EDM_ML_DEBUG
95  edm::LogVerbatim("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
96  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
97 #endif
98  //Step1: Find if the event passes the chosen trigger
100  iEvent.getByToken(tok_trigRes_, triggerResults);
101  if (triggerResults.isValid()) {
102  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
103  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
104  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
105  int hlt = triggerResults->accept(iHLT);
106  if (triggerNames_[iHLT].find(trigName_) != std::string::npos) {
107  if (hlt > 0) {
108  accept = true;
109 #ifdef EDM_ML_DEBUG
110  edm::LogVerbatim("AlCaIsoBunch")
111  << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << accept << std::endl;
112 #endif
113  break;
114  }
115  }
116  }
117  }
118 
119  // Step 2: Return the acceptance flag
120  if (accept)
121  ++nGood_;
122  return accept;
123 
124 } // AlCaIsolatedBunchSelector::filter
125 // ------------ method called once each job just after ending the event loop ------------
127  globalCache()->nAll_ += nAll_;
128  globalCache()->nGood_ += nGood_;
129 }
130 
132  edm::LogVerbatim("AlCaIsoBunch") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events" << std::endl;
133 }
134 
135 // ------------ method called when starting to processes a run ------------
137  bool changed(false);
138  edm::LogVerbatim("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
139  << hltConfig_.init(iRun, iSetup, processName_, changed) << std::endl;
140 }
141 // ------------ method called when ending the processing of a run ------------
143  ++nRun_;
144  edm::LogVerbatim("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
145 }
146 
147 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
150  desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
151  desc.add<std::string>("processName", "HLT");
152  desc.add<std::string>("triggerName", "HLT_HcalIsolatedBunch");
153  descriptions.add("alcaIsolatedBunchSelector", desc);
154 }
155 
156 //define this as a plug-in
ConfigurationDescriptions.h
AlCaIsolatedBunchSelector::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaIsolatedBunchSelector.cc:136
AlCaIsolatedBunchSelector::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaIsolatedBunchSelector.cc:142
Handle.h
AlCaIsolatedBunchSelector::trigName_
std::string trigName_
Definition: AlCaIsolatedBunchSelector.cc:58
AlCaIsolatedBunchSelector::endStream
void endStream() override
Definition: AlCaIsolatedBunchSelector.cc:126
AlCaIsolatedBunchSelector::theTriggerResultsLabel_
edm::InputTag theTriggerResultsLabel_
Definition: AlCaIsolatedBunchSelector.cc:59
AlCaIsolatedBunchSelector::tok_trigRes_
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
Definition: AlCaIsolatedBunchSelector.cc:62
MessageLogger.h
ESHandle.h
TriggerResults.h
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< edm::TriggerResults >
LuminosityBlock.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
AlCaIsolatedBunchSelector::nRun_
unsigned int nRun_
Definition: AlCaIsolatedBunchSelector.cc:61
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle< edm::TriggerResults >
edm::RunBase::run
RunNumber_t run() const
Definition: RunBase.h:40
AlCaIsolatedBunchSelector::processName_
std::string processName_
Definition: AlCaIsolatedBunchSelector.cc:60
accept
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
L1TEGammaOffline_cfi.triggerNames
triggerNames
Definition: L1TEGammaOffline_cfi.py:40
Run.h
AlCaIsolatedBunchSelector::~AlCaIsolatedBunchSelector
~AlCaIsolatedBunchSelector() override
Definition: AlCaIsolatedBunchSelector.cc:84
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
AlCaIsolatedBunchSelector
Definition: AlCaIsolatedBunchSelector.cc:38
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
AlCaIsolatedBunch::Counters::Counters
Counters()
Definition: AlCaIsolatedBunchSelector.cc:33
AlCaIsolatedBunchSelector::hltConfig_
HLTConfigProvider hltConfig_
Definition: AlCaIsolatedBunchSelector.cc:57
AlCaIsolatedBunch::Counters::nAll_
std::atomic< unsigned int > nAll_
Definition: AlCaIsolatedBunchFilter.cc:34
TriggerNames.h
iEvent
int iEvent
Definition: GenABIO.cc:224
AlCaIsolatedBunchSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: AlCaIsolatedBunchSelector.cc:148
edm::EventSetup
Definition: EventSetup.h:57
AlCaIsolatedBunch::Counters
Definition: AlCaIsolatedBunchFilter.cc:32
AlCaIsolatedBunch
Definition: AlCaIsolatedBunchFilter.cc:31
HLTConfigProvider.h
AlCaIsolatedBunchSelector::AlCaIsolatedBunchSelector
AlCaIsolatedBunchSelector(edm::ParameterSet const &, const AlCaIsolatedBunch::Counters *count)
Definition: AlCaIsolatedBunchSelector.cc:68
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HLTConfigProvider
Definition: HLTConfigProvider.h:29
HLTConfigProvider::init
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d'tor
Definition: HLTConfigProvider.cc:36
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
AlCaIsolatedBunchSelector::globalEndJob
static void globalEndJob(const AlCaIsolatedBunch::Counters *counters)
Definition: AlCaIsolatedBunchSelector.cc:131
edm::TriggerNames
Definition: TriggerNames.h:55
AlCaIsolatedBunchSelector::nAll_
unsigned int nAll_
Definition: AlCaIsolatedBunchSelector.cc:61
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
AlCaIsolatedBunchSelector::filter
bool filter(edm::Event &, edm::EventSetup const &) override
Definition: AlCaIsolatedBunchSelector.cc:91
EDFilter.h
AlCaIsolatedBunch::Counters::nGood_
std::atomic< unsigned int > nGood_
Definition: AlCaIsolatedBunchFilter.cc:34
ParameterSet.h
edm::stream::EDFilter
Definition: EDFilter.h:38
edm::Event
Definition: Event.h:73
AlCaIsolatedBunchSelector::nGood_
unsigned int nGood_
Definition: AlCaIsolatedBunchSelector.cc:61
AlCaIsolatedBunchSelector::initializeGlobalCache
static std::unique_ptr< AlCaIsolatedBunch::Counters > initializeGlobalCache(edm::ParameterSet const &iConfig)
Definition: AlCaIsolatedBunchSelector.cc:43
edm::InputTag
Definition: InputTag.h:15
ValidationMatrix.hlt
hlt
Definition: ValidationMatrix.py:459