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
19 
21 //Triggers
24 //
25 // class declaration
26 //
27 
28 //#define EDM_ML_DEBUG
29 
31  struct Counters {
32  Counters() : nAll_(0), nGood_(0) {}
33  mutable std::atomic<unsigned int> nAll_, nGood_;
34  };
35 } // namespace alCaIsolatedBunchSelector
36 
37 class AlCaIsolatedBunchSelector : public edm::stream::EDFilter<edm::GlobalCache<alCaIsolatedBunchSelector::Counters> > {
38 public:
40  ~AlCaIsolatedBunchSelector() override = default;
41 
42  static std::unique_ptr<alCaIsolatedBunchSelector::Counters> initializeGlobalCache(edm::ParameterSet const& iConfig) {
43  return std::make_unique<alCaIsolatedBunchSelector::Counters>();
44  }
45 
46  bool filter(edm::Event&, edm::EventSetup const&) override;
47  void endStream() override;
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51 private:
52  void beginRun(edm::Run const&, edm::EventSetup const&) override;
53  void endRun(edm::Run const&, edm::EventSetup const&) override;
54 
55  // ----------member data ---------------------------
57  unsigned int nRun_, nAll_, nGood_;
62 };
63 
64 //
65 // constructors and destructor
66 //
69  : nRun_(0),
70  nAll_(0),
71  nGood_(0),
72  trigName_(iConfig.getParameter<std::string>("triggerName")),
73  processName_(iConfig.getParameter<std::string>("processName")),
74  theTriggerResultsLabel_(iConfig.getParameter<edm::InputTag>("triggerResultLabel")),
75  tok_trigRes_(consumes<edm::TriggerResults>(theTriggerResultsLabel_)) {
76  edm::LogVerbatim("AlCaIsoBunch") << "Input tag for trigger results " << theTriggerResultsLabel_
77  << " with trigger name " << trigName_ << " and process " << processName_
78  << std::endl;
79 }
80 
81 //
82 // member functions
83 //
84 
85 // ------------ method called on each new Event ------------
87  bool accept(false);
88  ++nAll_;
89 #ifdef EDM_ML_DEBUG
90  edm::LogVerbatim("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
91  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
92 #endif
93  if (trigName_.empty()) {
94  accept = true;
95  } else {
96  //Step1: Find if the event passes the chosen trigger
97  auto const& triggerResults = iEvent.getHandle(tok_trigRes_);
98  if (triggerResults.isValid()) {
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  if (triggerNames_[iHLT].find(trigName_) != std::string::npos) {
104  if (hlt > 0) {
105  accept = true;
106 #ifdef EDM_ML_DEBUG
107  edm::LogVerbatim("AlCaIsoBunch")
108  << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << accept << std::endl;
109 #endif
110  break;
111  }
112  }
113  }
114  }
115  }
116 
117  // Step 2: Return the acceptance flag
118  if (accept)
119  ++nGood_;
120  return accept;
121 
122 } // AlCaIsolatedBunchSelector::filter
123 // ------------ method called once each job just after ending the event loop ------------
125  globalCache()->nAll_ += nAll_;
126  globalCache()->nGood_ += nGood_;
127 }
128 
130  edm::LogVerbatim("AlCaIsoBunch") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events" << std::endl;
131 }
132 
133 // ------------ method called when starting to processes a run ------------
135  bool changed(false);
136  edm::LogVerbatim("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
137  << hltConfig_.init(iRun, iSetup, processName_, changed) << std::endl;
138 }
139 // ------------ method called when ending the processing of a run ------------
141  ++nRun_;
142  edm::LogVerbatim("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
143 }
144 
145 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
148  desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
149  desc.add<std::string>("processName", "HLT");
150  desc.add<std::string>("triggerName", "");
151  descriptions.add("alcaIsolatedBunchSelector", desc);
152 }
153 
154 //define this as a plug-in
Log< level::Info, true > LogVerbatim
~AlCaIsolatedBunchSelector() override=default
bool filter(edm::Event &, edm::EventSetup const &) override
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t uint32_t CAHitNtupletGeneratorKernelsGPU::Counters * counters
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
AlCaIsolatedBunchSelector(edm::ParameterSet const &, const alCaIsolatedBunchSelector::Counters *count)
const edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
static std::unique_ptr< alCaIsolatedBunchSelector::Counters > initializeGlobalCache(edm::ParameterSet const &iConfig)
void beginRun(edm::Run const &, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static std::string const triggerResults
Definition: EdmProvDump.cc:47
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)
const edm::InputTag theTriggerResultsLabel_
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void globalEndJob(const alCaIsolatedBunchSelector::Counters *counters)
Definition: Run.h:45