CMS 3D CMS Logo

AlCaHBHEMuonProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //#define EDM_ML_DEBUG
3 
4 // system include files
5 #include <atomic>
6 #include <memory>
7 #include <string>
8 #include <cmath>
9 #include <iostream>
10 #include <sstream>
11 #include <fstream>
12 #include <vector>
13 #include <boost/regex.hpp>
14 
15 // user include files
25 
35 
36 //#define EDM_ML_DEBUG
37 //
38 // class declaration
39 //
40 
41 namespace AlCaHBHEMuons {
42  struct Counters {
43  Counters() : nAll_(0), nGood_(0) {}
44  mutable std::atomic<unsigned int> nAll_, nGood_;
45  };
46 } // namespace AlCaHBHEMuons
47 
48 class AlCaHBHEMuonProducer : public edm::stream::EDProducer<edm::GlobalCache<AlCaHBHEMuons::Counters> > {
49 public:
51  ~AlCaHBHEMuonProducer() override;
52 
53  static std::unique_ptr<AlCaHBHEMuons::Counters> initializeGlobalCache(edm::ParameterSet const&) {
54  return std::make_unique<AlCaHBHEMuons::Counters>();
55  }
56 
57  void produce(edm::Event&, const edm::EventSetup&) override;
58  void endStream() override;
59  static void globalEndJob(const AlCaHBHEMuons::Counters* counters);
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
63  void beginRun(edm::Run const&, edm::EventSetup const&) override;
64  void endRun(edm::Run const&, edm::EventSetup const&) override;
65  bool select(const reco::MuonCollection&);
66 
67  // ----------member data ---------------------------
68  unsigned int nRun_, nAll_, nGood_;
71  const double pMuonMin_;
72 
79 };
80 
82  : nRun_(0),
83  nAll_(0),
84  nGood_(0),
85  labelBS_(iConfig.getParameter<edm::InputTag>("BeamSpotLabel")),
86  labelVtx_(iConfig.getParameter<edm::InputTag>("VertexLabel")),
87  labelEB_(iConfig.getParameter<edm::InputTag>("EBRecHitLabel")),
88  labelEE_(iConfig.getParameter<edm::InputTag>("EERecHitLabel")),
89  labelHBHE_(iConfig.getParameter<edm::InputTag>("HBHERecHitLabel")),
90  labelMuon_(iConfig.getParameter<edm::InputTag>("MuonLabel")),
91  pMuonMin_(iConfig.getParameter<double>("MinimumMuonP")) {
92  // define tokens for access
93  tok_Vtx_ = consumes<reco::VertexCollection>(labelVtx_);
94  tok_BS_ = consumes<reco::BeamSpot>(labelBS_);
95  tok_EB_ = consumes<EcalRecHitCollection>(labelEB_);
96  tok_EE_ = consumes<EcalRecHitCollection>(labelEE_);
97  tok_HBHE_ = consumes<HBHERecHitCollection>(labelHBHE_);
98  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
99 
100  edm::LogVerbatim("HcalHBHEMuon") << "Parameters read from config file \n"
101  << "\t minP of muon " << pMuonMin_ << "\t input labels " << labelBS_ << " "
102  << labelVtx_ << " " << labelEB_ << " " << labelEE_ << " " << labelHBHE_ << " "
103  << labelMuon_;
104 
105  //saves the following collections
106  produces<reco::BeamSpot>(labelBS_.label());
107  produces<reco::VertexCollection>(labelVtx_.label());
108  produces<EcalRecHitCollection>(labelEB_.instance());
109  produces<EcalRecHitCollection>(labelEE_.instance());
110  produces<HBHERecHitCollection>(labelHBHE_.label());
111  produces<reco::MuonCollection>(labelMuon_.label());
112 }
113 
115 
117  ++nAll_;
118  bool valid(true);
119 #ifdef EDM_ML_DEBUG
120  edm::LogVerbatim("HcalHBHEMuon") << "AlCaHBHEMuonProducer::Run " << iEvent.id().run() << " Event "
121  << iEvent.id().event() << " Luminosity " << iEvent.luminosityBlock() << " Bunch "
122  << iEvent.bunchCrossing();
123 #endif
124 
125  //Step1: Get all the relevant containers
126  auto bmspot = iEvent.getHandle(tok_BS_);
127  if (!bmspot.isValid()) {
128  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelBS_;
129  valid = false;
130  }
131 
132  auto vt = iEvent.getHandle(tok_Vtx_);
133  if (!vt.isValid()) {
134  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelVtx_;
135  valid = false;
136  }
137 
138  auto barrelRecHitsHandle = iEvent.getHandle(tok_EB_);
139  if (!barrelRecHitsHandle.isValid()) {
140  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEB_;
141  valid = false;
142  }
143 
144  auto endcapRecHitsHandle = iEvent.getHandle(tok_EE_);
145  if (!endcapRecHitsHandle.isValid()) {
146  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEE_;
147  valid = false;
148  }
149 
150  auto hbhe = iEvent.getHandle(tok_HBHE_);
151  if (!hbhe.isValid()) {
152  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelHBHE_;
153  valid = false;
154  }
155 
156  auto muonhandle = iEvent.getHandle(tok_Muon_);
157  if (!muonhandle.isValid()) {
158  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelMuon_;
159  valid = false;
160  }
161 
162 #ifdef EDM_ML_DEBUG
163  edm::LogVerbatim("HcalHBHEMuon") << "AlCaHBHEMuonProducer::obtained the collections with validity flag " << valid;
164 #endif
165 
166  //For accepted events
167  auto outputBeamSpot = std::make_unique<reco::BeamSpot>();
168  auto outputVColl = std::make_unique<reco::VertexCollection>();
169  auto outputEBColl = std::make_unique<EBRecHitCollection>();
170  auto outputEEColl = std::make_unique<EERecHitCollection>();
171  auto outputHBHEColl = std::make_unique<HBHERecHitCollection>();
172  auto outputMColl = std::make_unique<reco::MuonCollection>();
173 
174  if (valid) {
175  const reco::BeamSpot beam = *(bmspot.product());
176  outputBeamSpot = std::make_unique<reco::BeamSpot>(
177  beam.position(), beam.sigmaZ(), beam.dxdz(), beam.dydz(), beam.BeamWidthX(), beam.covariance(), beam.type());
178  const reco::VertexCollection vtx = *(vt.product());
179  const EcalRecHitCollection ebcoll = *(barrelRecHitsHandle.product());
180  const EcalRecHitCollection eecoll = *(endcapRecHitsHandle.product());
181  const HBHERecHitCollection hbhecoll = *(hbhe.product());
182  const reco::MuonCollection muons = *(muonhandle.product());
183 
184  bool accept = select(muons);
185 
186  if (accept) {
187  ++nGood_;
188 
189  for (reco::VertexCollection::const_iterator vtr = vtx.begin(); vtr != vtx.end(); ++vtr)
190  outputVColl->push_back(*vtr);
191 
192  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit = ebcoll.begin(); ehit != ebcoll.end(); ++ehit)
193  outputEBColl->push_back(*ehit);
194 
195  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit = eecoll.begin(); ehit != eecoll.end(); ++ehit)
196  outputEEColl->push_back(*ehit);
197 
198  for (std::vector<HBHERecHit>::const_iterator hhit = hbhecoll.begin(); hhit != hbhecoll.end(); ++hhit)
199  outputHBHEColl->push_back(*hhit);
200 
201  for (reco::MuonCollection::const_iterator muon = muons.begin(); muon != muons.end(); ++muon)
202  outputMColl->push_back(*muon);
203  }
204  }
205 
206  iEvent.put(std::move(outputBeamSpot), labelBS_.label());
207  iEvent.put(std::move(outputVColl), labelVtx_.label());
208  iEvent.put(std::move(outputEBColl), labelEB_.instance());
209  iEvent.put(std::move(outputEEColl), labelEE_.instance());
210  iEvent.put(std::move(outputHBHEColl), labelHBHE_.label());
211  iEvent.put(std::move(outputMColl), labelMuon_.label());
212 }
213 
215  globalCache()->nAll_ += nAll_;
216  globalCache()->nGood_ += nGood_;
217 }
218 
220  edm::LogVerbatim("HcalHBHEMuon") << "Finds " << count->nGood_ << " good tracks in " << count->nAll_ << " events";
221 }
222 
224  //The following says we do not know what parameters are allowed so do no validation
225  // Please change this to state exactly what you do use, even if it is no parameters
227  desc.add<edm::InputTag>("BeamSpotLabel", edm::InputTag("offlineBeamSpot"));
228  desc.add<edm::InputTag>("VertexLabel", edm::InputTag("offlinePrimaryVertices"));
229  desc.add<edm::InputTag>("EBRecHitLabel", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
230  desc.add<edm::InputTag>("EERecHitLabel", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
231  desc.add<edm::InputTag>("HBHERecHitLabel", edm::InputTag("hbhereco"));
232  desc.add<edm::InputTag>("MuonLabel", edm::InputTag("muons"));
233  desc.add<double>("MinimumMuonP", 10.0);
234  descriptions.add("alcaHBHEMuonProducer", desc);
235 }
236 
237 void AlCaHBHEMuonProducer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
238  edm::LogVerbatim("HcalHBHEMuon") << "Run[" << nRun_ << "] " << iRun.run();
239 }
240 
242  ++nRun_;
243  edm::LogVerbatim("HcalHBHEMuon") << "endRun[" << nRun_ << "] " << iRun.run();
244 }
245 
247  bool ok(false);
248  for (unsigned int k = 0; k < muons.size(); ++k) {
249  if (muons[k].p() > pMuonMin_) {
250  ok = true;
251  break;
252  }
253  }
254  return ok;
255 }
256 
258 
std::atomic< unsigned int > nGood_
Log< level::Info, true > LogVerbatim
bool select(const reco::MuonCollection &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static std::unique_ptr< AlCaHBHEMuons::Counters > initializeGlobalCache(edm::ParameterSet const &)
std::string const & instance() const
Definition: InputTag.h:37
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
std::atomic< unsigned int > nAll_
const edm::InputTag labelEE_
void beginRun(edm::Run const &, edm::EventSetup const &) override
std::vector< T >::const_iterator const_iterator
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
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
std::string const & label() const
Definition: InputTag.h:36
const edm::InputTag labelHBHE_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
const edm::InputTag labelBS_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
void endRun(edm::Run const &, edm::EventSetup const &) override
AlCaHBHEMuonProducer(edm::ParameterSet const &, const AlCaHBHEMuons::Counters *count)
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
const edm::InputTag labelEB_
edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
const edm::InputTag labelVtx_
const edm::InputTag labelMuon_
const_iterator begin() const
const_iterator end() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
edm::EDGetTokenT< reco::BeamSpot > tok_BS_
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::VertexCollection > tok_Vtx_
Log< level::Warning, false > LogWarning
static void globalEndJob(const AlCaHBHEMuons::Counters *counters)
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
Definition: Run.h:45