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 ---------------------------
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 
82 
83 //
84 // member functions
85 //
86 
87 // ------------ method called on each new Event ------------
89  bool accept(false);
90  ++nAll_;
91 #ifdef EDM_ML_DEBUG
92  edm::LogVerbatim("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
93  << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
94 #endif
95  //Step1: Find if the event passes the chosen trigger
96  auto const& triggerResults = iEvent.getHandle(tok_trigRes_);
97  if (triggerResults.isValid()) {
99  const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
100  for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
101  int hlt = triggerResults->accept(iHLT);
102  if (triggerNames_[iHLT].find(trigName_) != std::string::npos) {
103  if (hlt > 0) {
104  accept = true;
105 #ifdef EDM_ML_DEBUG
106  edm::LogVerbatim("AlCaIsoBunch")
107  << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << accept << std::endl;
108 #endif
109  break;
110  }
111  }
112  }
113  }
114 
115  // Step 2: Return the acceptance flag
116  if (accept)
117  ++nGood_;
118  return accept;
119 
120 } // AlCaIsolatedBunchSelector::filter
121 // ------------ method called once each job just after ending the event loop ------------
123  globalCache()->nAll_ += nAll_;
124  globalCache()->nGood_ += nGood_;
125 }
126 
128  edm::LogVerbatim("AlCaIsoBunch") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events" << std::endl;
129 }
130 
131 // ------------ method called when starting to processes a run ------------
133  bool changed(false);
134  edm::LogVerbatim("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
135  << hltConfig_.init(iRun, iSetup, processName_, changed) << std::endl;
136 }
137 // ------------ method called when ending the processing of a run ------------
139  ++nRun_;
140  edm::LogVerbatim("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
141 }
142 
143 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
146  desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
147  desc.add<std::string>("processName", "HLT");
148  desc.add<std::string>("triggerName", "HLT_HcalIsolatedBunch");
149  descriptions.add("alcaIsolatedBunchSelector", desc);
150 }
151 
152 //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
const edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
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
void endRun(edm::Run const &, edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::InputTag theTriggerResultsLabel_
edm::EventID id() const
Definition: EventBase.h:59
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
AlCaIsolatedBunchSelector(edm::ParameterSet const &, const AlCaIsolatedBunch::Counters *count)
Definition: Run.h:45