CMS 3D CMS Logo

AlCaIsoTracksProducerFilter.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 
23 //Triggers
26 
27 //
28 // class declaration
29 //
30 
32  struct Counters {
33  Counters() : nAll_(0), nGood_(0) {}
34  mutable std::atomic<unsigned int> nAll_, nGood_;
35  };
36 } // namespace AlCaIsoTracksProdFilter
37 
38 class AlCaIsoTracksProducerFilter : public edm::stream::EDFilter<edm::GlobalCache<AlCaIsoTracksProdFilter::Counters> > {
39 public:
41  ~AlCaIsoTracksProducerFilter() override;
42 
43  static std::unique_ptr<AlCaIsoTracksProdFilter::Counters> initializeGlobalCache(edm::ParameterSet const& iConfig) {
44  return std::make_unique<AlCaIsoTracksProdFilter::Counters>();
45  }
46 
47  bool filter(edm::Event&, edm::EventSetup const&) override;
48  void endStream() override;
49  static void globalEndJob(const AlCaIsoTracksProdFilter::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> trigNames_;
59  unsigned int nRun_, nAll_, nGood_;
63 };
64 
67  : nRun_(0), nAll_(0), nGood_(0) {
68  //now do what ever initialization is needed
69  trigNames_ = iConfig.getParameter<std::vector<std::string> >("triggers");
70  processName_ = iConfig.getParameter<std::string>("processName");
71  triggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("triggerResultLabel");
72 
73  // define tokens for access
74  tok_trigRes_ = consumes<edm::TriggerResults>(triggerResultsLabel_);
75 
76  edm::LogInfo("HcalIsoTrack") << "Use process name " << processName_ << " Labels " << triggerResultsLabel_
77  << " selecting " << trigNames_.size() << " triggers\n";
78  for (unsigned int k = 0; k < trigNames_.size(); ++k) {
79  edm::LogInfo("HcalIsoTrack") << "Trigger[" << k << "] " << trigNames_[k] << std::endl;
80  }
81 }
82 
84 
86  ++nAll_;
87  edm::LogInfo("HcalIsoTrack") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
88  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
89 
90  //Find if the event passes one of the chosen triggers
91  bool triggerSatisfied(false);
92  if (trigNames_.empty()) {
93  triggerSatisfied = true;
94  } else {
96  iEvent.getByToken(tok_trigRes_, triggerResults);
97  if (triggerResults.isValid()) {
98  std::vector<std::string> modules;
99  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
100  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
101  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
102  int hlt = triggerResults->accept(iHLT);
103  for (unsigned int i = 0; i < trigNames_.size(); ++i) {
104  if (triggerNames_[iHLT].find(trigNames_[i]) != std::string::npos) {
105  edm::LogInfo("HcalIsoTrack") << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":"
106  << triggerSatisfied << std::endl;
107  if (hlt > 0) {
108  triggerSatisfied = true;
109  break;
110  }
111  }
112  }
113  if (triggerSatisfied)
114  break;
115  }
116  }
117  }
118  if (triggerSatisfied)
119  ++nGood_;
120  return triggerSatisfied;
121 }
122 
124  globalCache()->nAll_ += nAll_;
125  globalCache()->nGood_ += nGood_;
126 }
127 
129  edm::LogInfo("HcalIsoTrack") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events " << std::endl;
130 }
131 
133  bool changed(false);
134  bool flag = hltConfig_.init(iRun, iSetup, processName_, changed);
135  edm::LogInfo("HcalIsoTrack") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init " << flag << std::endl;
136 }
137 
139  ++nRun_;
140  edm::LogInfo("HcalIsoTrack") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
141 }
142 
144  //The following says we do not know what parameters are allowed so do no validation
145  // Please change this to state exactly what you do use, even if it is no parameters
147  desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
148  std::vector<std::string> trigger = {"HLT_IsoTrackHB", "HLT_IsoTrackHE"};
149  desc.add<std::vector<std::string> >("triggers", trigger);
150  desc.add<std::string>("processName", "HLT");
151  descriptions.add("alcaIsoTracksProducerFilter", desc);
152 }
153 
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
bool accept() const
Has at least one path accepted the event?
int bunchCrossing() const
Definition: EventBase.h:64
static std::unique_ptr< AlCaIsoTracksProdFilter::Counters > initializeGlobalCache(edm::ParameterSet const &iConfig)
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
Strings const & triggerNames() const
Definition: TriggerNames.cc:20
void beginRun(edm::Run const &, edm::EventSetup const &) override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int size() const
Get number of paths stored.
static std::string const triggerResults
Definition: EdmProvDump.cc:45
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
int k[5][pyjets_maxn]
std::vector< std::string > trigNames_
void endRun(edm::Run const &, edm::EventSetup const &) override
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
static void globalEndJob(const AlCaIsoTracksProdFilter::Counters *counters)
AlCaIsoTracksProducerFilter(edm::ParameterSet const &, const AlCaIsoTracksProdFilter::Counters *count)
bool filter(edm::Event &, edm::EventSetup const &) override
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:256
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Run.h:45