CMS 3D CMS Logo

AlCaIsolatedBunchFilter.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 AlCaIsolatedBunchFilter : public edm::stream::EDFilter<edm::GlobalCache<AlCaIsolatedBunch::Counters> > {
39 public:
41  ~AlCaIsolatedBunchFilter() 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 ---------------------------
58  std::vector<std::string> trigJetNames_, trigIsoBunchNames_;
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  trigJetNames_ = iConfig.getParameter<std::vector<std::string> >("triggerJet");
73  trigIsoBunchNames_ = iConfig.getParameter<std::vector<std::string> >("triggerIsoBunch");
74  processName_ = iConfig.getParameter<std::string>("processName");
75  theTriggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("triggerResultLabel");
76 
77  // define tokens for access
78  tok_trigRes_ = consumes<edm::TriggerResults>(theTriggerResultsLabel_);
79 
80  edm::LogInfo("AlCaIsoBunch") << "Input tag for trigger results " << theTriggerResultsLabel_ << " with "
81  << trigIsoBunchNames_.size() << ":" << trigJetNames_.size() << " trigger names and"
82  << " process " << processName_ << std::endl;
83  for (unsigned int k = 0; k < trigIsoBunchNames_.size(); ++k)
84  edm::LogInfo("AlCaIsoBunch") << "Isolated Bunch[" << k << "] " << trigIsoBunchNames_[k] << std::endl;
85  for (unsigned int k = 0; k < trigJetNames_.size(); ++k)
86  edm::LogInfo("AlCaIsoBunch") << "Jet Trigger[" << k << "] " << trigJetNames_[k] << std::endl;
87 }
88 
90 
91 //
92 // member functions
93 //
94 
95 // ------------ method called on each new Event ------------
97  bool accept(false);
98  ++nAll_;
99 #ifdef DebugLog
100  edm::LogInfo("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
101  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
102 #endif
103  //Step1: Find if the event passes one of the chosen triggers
104  if ((trigIsoBunchNames_.empty()) && (trigJetNames_.empty())) {
105  accept = true;
106  } else {
109  iEvent.getByToken(tok_trigRes_, triggerResults);
110  if (triggerResults.isValid()) {
111  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
112  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
113  bool jet(false), isobunch(false);
114  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
115  int hlt = triggerResults->accept(iHLT);
116  if (!jet) {
117  for (unsigned int i = 0; i < trigJetNames_.size(); ++i) {
118  if (triggerNames_[iHLT].find(trigJetNames_[i]) != std::string::npos) {
119  if (hlt > 0)
120  jet = true;
121  if (jet) {
122 #ifdef DebugLog
123  edm::LogInfo("AlCaIsoBunch")
124  << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << jet << ":" << isobunch << std::endl;
125 #endif
126  break;
127  }
128  }
129  }
130  }
131  if (!isobunch) {
132  for (unsigned int i = 0; i < trigIsoBunchNames_.size(); ++i) {
133  if (triggerNames_[iHLT].find(trigIsoBunchNames_[i]) != std::string::npos) {
134  if (hlt > 0)
135  isobunch = true;
136  if (isobunch) {
137 #ifdef DebugLog
138  edm::LogInfo("AlCaIsoBunch")
139  << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << jet << ":" << isobunch << std::endl;
140 #endif
141  break;
142  }
143  }
144  }
145  }
146  if (jet && isobunch) {
147  accept = true;
148  break;
149  }
150  }
151  }
152  }
153 
154  // Step 2: Return the acceptance flag
155  if (accept)
156  ++nGood_;
157  return accept;
158 
159 } // AlCaIsolatedBunchFilter::filter
160 // ------------ method called once each job just after ending the event loop ------------
162  globalCache()->nAll_ += nAll_;
163  globalCache()->nGood_ += nGood_;
164 }
165 
167  edm::LogInfo("AlCaIsoBunch") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events" << std::endl;
168 }
169 
170 // ------------ method called when starting to processes a run ------------
172  bool changed(false);
173  edm::LogInfo("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
174  << hltConfig_.init(iRun, iSetup, processName_, changed) << std::endl;
175 }
176 // ------------ method called when ending the processing of a run ------------
178  ++nRun_;
179  edm::LogInfo("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
180 }
181 
182 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
185  desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
186  desc.add<std::string>("processName", "HLT");
187  std::vector<std::string> isobunch = {"HLT_ZeroBias_IsolatedBunches"};
188  desc.add<std::vector<std::string> >("triggerIsoBunch", isobunch);
189  std::vector<std::string> triggers = {"HLT_AK8PFJet",
190  "HLT_AK8PFHT",
191  "HLT_CaloJet",
192  "HLT_HT",
193  "HLT_JetE",
194  "HLT_PFHT",
195  "HLT_DiPFJet",
196  "HLT_PFJet",
197  "HLT_DiCentralPFJet",
198  "HLT_QuadPFJet",
199  "HLT_L1_TripleJet_VBF",
200  "HLT_QuadJet",
201  "HLT_DoubleJet",
202  "HLT_AK8DiPFJet",
203  "HLT_AK4CaloJet",
204  "HLT_AK4PFJet"};
205  desc.add<std::vector<std::string> >("triggerJet", triggers);
206  descriptions.add("alcaIsolatedBunchFilter", desc);
207 }
208 
209 //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
std::vector< std::string > trigIsoBunchNames_
void beginRun(edm::Run const &, edm::EventSetup const &) override
static std::unique_ptr< AlCaIsolatedBunch::Counters > initializeGlobalCache(edm::ParameterSet const &iConfig)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool accept() const
Has at least one path accepted the event?
int bunchCrossing() const
Definition: EventBase.h:64
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
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
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned int size() const
Get number of paths stored.
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
static void globalEndJob(const AlCaIsolatedBunch::Counters *counters)
bool filter(edm::Event &, edm::EventSetup const &) override
int k[5][pyjets_maxn]
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 add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:59
AlCaIsolatedBunchFilter(edm::ParameterSet const &, const AlCaIsolatedBunch::Counters *count)
void endRun(edm::Run const &, edm::EventSetup const &) override
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:256
Definition: Run.h:45
std::vector< std::string > trigJetNames_