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
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
RunNumber_t run() const
Definition: RunBase.h:40
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static std::unique_ptr< AlCaIsolatedBunch::Counters > initializeGlobalCache(edm::ParameterSet const &iConfig)
bool accept() const
Has at least one path accepted the event?
bool filter(edm::Event &, edm::EventSetup const &) override
int bunchCrossing() const
Definition: EventBase.h:64
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
Strings const & triggerNames() const
Definition: TriggerNames.cc:20
static void globalEndJob(const AlCaIsolatedBunch::Counters *counters)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int size() const
Get number of paths stored.
void beginRun(edm::Run const &, edm::EventSetup const &) override
static std::string const triggerResults
Definition: EdmProvDump.cc:45
std::atomic< unsigned int > nGood_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
std::atomic< unsigned int > nAll_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
void endRun(edm::Run const &, edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:59
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
AlCaIsolatedBunchSelector(edm::ParameterSet const &, const AlCaIsolatedBunch::Counters *count)
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:256
Definition: Run.h:45