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 DebugLog
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::unique_ptr<AlCaIsolatedBunch::Counters>(new 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::LogInfo("AlCaIsoBunch") << "Input tag for trigger results " << theTriggerResultsLabel_ << " with trigger name "
80  << trigName_ << " and process " << processName_ << std::endl;
81 }
82 
84 
85 //
86 // member functions
87 //
88 
89 // ------------ method called on each new Event ------------
91  bool accept(false);
92  ++nAll_;
93 #ifdef DebugLog
94  edm::LogInfo("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
95  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
96 #endif
97  //Step1: Find if the event passes the chosen trigger
99  iEvent.getByToken(tok_trigRes_, triggerResults);
100  if (triggerResults.isValid()) {
101  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
102  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
103  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
104  int hlt = triggerResults->accept(iHLT);
105  if (triggerNames_[iHLT].find(trigName_) != std::string::npos) {
106  if (hlt > 0) {
107  accept = true;
108 #ifdef DebugLog
109  edm::LogInfo("AlCaIsoBunch") << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << accept
110  << std::endl;
111 #endif
112  break;
113  }
114  }
115  }
116  }
117 
118  // Step 2: Return the acceptance flag
119  if (accept)
120  ++nGood_;
121  return accept;
122 
123 } // AlCaIsolatedBunchSelector::filter
124 // ------------ method called once each job just after ending the event loop ------------
126  globalCache()->nAll_ += nAll_;
127  globalCache()->nGood_ += nGood_;
128 }
129 
131  edm::LogInfo("AlCaIsoBunch") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events" << std::endl;
132 }
133 
134 // ------------ method called when starting to processes a run ------------
136  bool changed(false);
137  edm::LogInfo("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
138  << hltConfig_.init(iRun, iSetup, processName_, changed) << std::endl;
139 }
140 // ------------ method called when ending the processing of a run ------------
142  ++nRun_;
143  edm::LogInfo("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
144 }
145 
146 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
149  desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
150  desc.add<std::string>("processName", "HLT");
151  desc.add<std::string>("triggerName", "HLT_HcalIsolatedBunch");
152  descriptions.add("alcaIsolatedBunchSelector", desc);
153 }
154 
155 //define this as a plug-in
ConfigurationDescriptions.h
AlCaIsolatedBunchSelector::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaIsolatedBunchSelector.cc:135
AlCaIsolatedBunchSelector::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaIsolatedBunchSelector.cc:141
Handle.h
AlCaIsolatedBunchSelector::trigName_
std::string trigName_
Definition: AlCaIsolatedBunchSelector.cc:58
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
AlCaIsolatedBunchSelector::endStream
void endStream() override
Definition: AlCaIsolatedBunchSelector.cc:125
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
edm::LogInfo
Definition: MessageLogger.h:254
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:83
AlCaIsolatedBunchSelector
Definition: AlCaIsolatedBunchSelector.cc:38
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
AlCaIsolatedBunch::Counters::Counters
Counters()
Definition: AlCaIsolatedBunchSelector.cc:33
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
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:147
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
HLTConfigProvider
Definition: HLTConfigProvider.h:28
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
AlCaIsolatedBunchSelector::globalEndJob
static void globalEndJob(const AlCaIsolatedBunch::Counters *counters)
Definition: AlCaIsolatedBunchSelector.cc:130
edm::TriggerNames
Definition: TriggerNames.h:55
AlCaIsolatedBunchSelector::nAll_
unsigned int nAll_
Definition: AlCaIsolatedBunchSelector.cc:61
AlCaIsolatedBunchSelector::filter
bool filter(edm::Event &, edm::EventSetup const &) override
Definition: AlCaIsolatedBunchSelector.cc:90
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