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 }
37 
38 class AlCaIsolatedBunchSelector : public edm::stream::EDFilter<edm::GlobalCache<AlCaIsolatedBunch::Counters> > {
39 public:
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  virtual bool filter(edm::Event&, edm::EventSetup const&) override;
48  virtual void endStream() override;
49  static void globalEndJob(const AlCaIsolatedBunch::Counters* counters);
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52 private:
53  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
54  virtual 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 //
69  nRun_(0), nAll_(0), nGood_(0) {
70  //now do what ever initialization is needed
71  trigName_ = iConfig.getParameter<std::string>("TriggerName");
72  processName_ = iConfig.getParameter<std::string>("ProcessName");
73  theTriggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("TriggerResultLabel");
74 
75  // define tokens for access
76  tok_trigRes_ = consumes<edm::TriggerResults>(theTriggerResultsLabel_);
77 
78  edm::LogInfo("AlCaIsoBunch") << "Input tag for trigger results "
79  << theTriggerResultsLabel_
80  << " with trigger name " << trigName_
81  << " and process " << processName_ << std::endl;
82 }
83 
85 
86 //
87 // member functions
88 //
89 
90 // ------------ method called on each new Event ------------
92  edm::EventSetup const& iSetup) {
93  bool accept(false);
94  ++nAll_;
95 #ifdef DebugLog
96  edm::LogInfo("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event "
97  << iEvent.id().event() << " Luminosity "
98  << iEvent.luminosityBlock() << " Bunch "
99  << iEvent.bunchCrossing() << std::endl;
100 #endif
101  //Step1: Find if the event passes the chosen trigger
103  iEvent.getByToken(tok_trigRes_, triggerResults);
104  if (triggerResults.isValid()) {
105  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
106  const std::vector<std::string> & triggerNames_ = triggerNames.triggerNames();
107  for (unsigned int iHLT=0; iHLT<triggerResults->size(); iHLT++) {
108  int hlt = triggerResults->accept(iHLT);
109  if (triggerNames_[iHLT].find(trigName_.c_str())!=std::string::npos) {
110  if (hlt > 0) {
111  accept = true;
112 #ifdef DebugLog
113  edm::LogInfo("AlCaIsoBunch") << triggerNames_[iHLT]
114  << " has got HLT flag " << hlt
115  << ":" << accept << std::endl;
116 #endif
117  break;
118  }
119  }
120  }
121  }
122 
123  // Step 2: Return the acceptance flag
124  if (accept) ++nGood_;
125  return accept;
126 
127 } // AlCaIsolatedBunchSelector::filter
128 // ------------ method called once each job just after ending the event loop ------------
130  globalCache()->nAll_ += nAll_;
131  globalCache()->nGood_ += nGood_;
132 }
133 
135  edm::LogInfo("AlCaIsoBunch") << "Selects " << count->nGood_ << " in "
136  << count->nAll_ << " events" << std::endl;
137 }
138 
139 
140 // ------------ method called when starting to processes a run ------------
142  bool changed(false);
143  edm::LogInfo("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run()
144  << " hltconfig.init "
145  << hltConfig_.init(iRun,iSetup,processName_,changed)
146  << std::endl;
147 }
148 // ------------ method called when ending the processing of a run ------------
150  ++nRun_;
151  edm::LogInfo("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run()
152  << std::endl;
153 }
154 
155 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
157  //The following says we do not know what parameters are allowed so do no validation
158  // Please change this to state exactly what you do use, even if it is no parameters
160  desc.setUnknown();
161  descriptions.addDefault(desc);
162 }
163 
164 //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:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static std::unique_ptr< AlCaIsolatedBunch::Counters > initializeGlobalCache(edm::ParameterSet const &iConfig)
bool accept() const
Has at least one path accepted the event?
virtual bool filter(edm::Event &, edm::EventSetup const &) override
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
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:24
static void globalEndJob(const AlCaIsolatedBunch::Counters *counters)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
unsigned int size() const
Get number of paths stored.
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
static std::string const triggerResults
Definition: EdmProvDump.cc:41
std::atomic< unsigned int > nGood_
bool isValid() const
Definition: HandleBase.h:74
std::atomic< unsigned int > nAll_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
edm::EventID id() const
Definition: EventBase.h:60
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
AlCaIsolatedBunchSelector(edm::ParameterSet const &, const AlCaIsolatedBunch::Counters *count)
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:239
Definition: Run.h:42