CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
30 namespace AlCaIsolatedBunch {
31  struct Counters {
32  Counters() : nAll_(0), nGood_(0) {}
33  mutable std::atomic<unsigned int> nAll_, nGood_;
34  };
35 } // namespace AlCaIsolatedBunch
36 
37 class AlCaIsolatedBunchSelector : public edm::stream::EDFilter<edm::GlobalCache<AlCaIsolatedBunch::Counters> > {
38 public:
40  ~AlCaIsolatedBunchSelector() override;
41 
42  static std::unique_ptr<AlCaIsolatedBunch::Counters> initializeGlobalCache(edm::ParameterSet const& iConfig) {
43  return std::make_unique<AlCaIsolatedBunch::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 ---------------------------
60  unsigned int nRun_, nAll_, nGood_;
62 };
63 
64 //
65 // constructors and destructor
66 //
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::LogVerbatim("AlCaIsoBunch") << "Input tag for trigger results " << theTriggerResultsLabel_
79  << " with trigger name " << trigName_ << " and process " << processName_
80  << 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 EDM_ML_DEBUG
94  edm::LogVerbatim("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
98  auto const& triggerResults = iEvent.getHandle(tok_trigRes_);
99  if (triggerResults.isValid()) {
101  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
102  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
103  int hlt = triggerResults->accept(iHLT);
104  if (triggerNames_[iHLT].find(trigName_) != std::string::npos) {
105  if (hlt > 0) {
106  accept = true;
107 #ifdef EDM_ML_DEBUG
108  edm::LogVerbatim("AlCaIsoBunch")
109  << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << accept << std::endl;
110 #endif
111  break;
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", "HLT_HcalIsolatedBunch");
151  descriptions.add("alcaIsolatedBunchSelector", desc);
152 }
153 
154 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:38
Log< level::Info, true > LogVerbatim
EventNumber_t event() const
Definition: EventID.h:40
RunNumber_t run() const
Definition: RunBase.h:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static std::unique_ptr< AlCaIsolatedBunch::Counters > initializeGlobalCache(edm::ParameterSet const &iConfig)
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:19
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
Strings const & triggerNames() const
Definition: TriggerNames.cc:48
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:275
static void globalEndJob(const AlCaIsolatedBunch::Counters *counters)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
int iEvent
Definition: GenABIO.cc:224
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 beginRun(edm::Run const &, edm::EventSetup const &) override
static std::string const triggerResults
Definition: EdmProvDump.cc:44
std::atomic< unsigned int > nGood_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::atomic< unsigned int > nAll_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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_
Definition: Run.h:45