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 //
37 // class declaration
38 //
39 
40 namespace AlCaHBHEMuons {
41  struct Counters {
42  Counters() : nAll_(0), nGood_(0) {}
43  mutable std::atomic<unsigned int> nAll_, nGood_;
44  };
45 } // namespace AlCaHBHEMuons
46 
47 class AlCaHBHEMuonProducer : public edm::stream::EDProducer<edm::GlobalCache<AlCaHBHEMuons::Counters> > {
48 public:
50  ~AlCaHBHEMuonProducer() override;
51 
52  static std::unique_ptr<AlCaHBHEMuons::Counters> initializeGlobalCache(edm::ParameterSet const&) {
53  return std::make_unique<AlCaHBHEMuons::Counters>();
54  }
55 
56  void produce(edm::Event&, const edm::EventSetup&) override;
57  void endStream() override;
58  static void globalEndJob(const AlCaHBHEMuons::Counters* counters);
59 
60 private:
61  void beginRun(edm::Run const&, edm::EventSetup const&) override;
62  void endRun(edm::Run const&, edm::EventSetup const&) override;
63  bool select(const reco::MuonCollection&);
64 
65  // ----------member data ---------------------------
66  unsigned int nRun_, nAll_, nGood_;
69  double pMuonMin_;
70 
77 };
78 
80  : nRun_(0), nAll_(0), nGood_(0) {
81  //Get the run parameters
82  labelBS_ = iConfig.getParameter<edm::InputTag>("BeamSpotLabel");
83  labelVtx_ = iConfig.getParameter<edm::InputTag>("VertexLabel");
84  labelEB_ = iConfig.getParameter<edm::InputTag>("EBRecHitLabel");
85  labelEE_ = iConfig.getParameter<edm::InputTag>("EERecHitLabel");
86  labelHBHE_ = iConfig.getParameter<edm::InputTag>("HBHERecHitLabel");
87  labelMuon_ = iConfig.getParameter<edm::InputTag>("MuonLabel");
88  pMuonMin_ = iConfig.getParameter<double>("MinimumMuonP");
89 
90  // define tokens for access
91  tok_Vtx_ = consumes<reco::VertexCollection>(labelVtx_);
92  tok_BS_ = consumes<reco::BeamSpot>(labelBS_);
93  tok_EB_ = consumes<EcalRecHitCollection>(labelEB_);
94  tok_EE_ = consumes<EcalRecHitCollection>(labelEE_);
95  tok_HBHE_ = consumes<HBHERecHitCollection>(labelHBHE_);
96  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
97 
98  edm::LogVerbatim("HcalHBHEMuon") << "Parameters read from config file \n"
99  << "\t minP of muon " << pMuonMin_ << "\t input labels " << labelBS_ << " "
100  << labelVtx_ << " " << labelEB_ << " " << labelEE_ << " " << labelHBHE_ << " "
101  << labelMuon_;
102 
103  //saves the following collections
104  produces<reco::BeamSpot>(labelBS_.label());
105  produces<reco::VertexCollection>(labelVtx_.label());
106  produces<EcalRecHitCollection>(labelEB_.instance());
107  produces<EcalRecHitCollection>(labelEE_.instance());
108  produces<HBHERecHitCollection>(labelHBHE_.label());
109  produces<reco::MuonCollection>(labelMuon_.label());
110 }
111 
113 
115  ++nAll_;
116  bool valid(true);
117 #ifdef EDM_ML_DEBUG
118  edm::LogVerbatim("HcalHBHEMuon") << "AlCaHBHEMuonProducer::Run " << iEvent.id().run() << " Event "
119  << iEvent.id().event() << " Luminosity " << iEvent.luminosityBlock() << " Bunch "
120  << iEvent.bunchCrossing();
121 #endif
122 
123  //Step1: Get all the relevant containers
125  iEvent.getByToken(tok_BS_, bmspot);
126  if (!bmspot.isValid()) {
127  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelBS_;
128  valid = false;
129  }
130 
132  iEvent.getByToken(tok_Vtx_, vt);
133  if (!vt.isValid()) {
134  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelVtx_;
135  valid = false;
136  }
137 
138  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
139  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
140  if (!barrelRecHitsHandle.isValid()) {
141  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEB_;
142  valid = false;
143  }
144 
145  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
146  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
147  if (!endcapRecHitsHandle.isValid()) {
148  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEE_;
149  valid = false;
150  }
151 
153  iEvent.getByToken(tok_HBHE_, hbhe);
154  if (!hbhe.isValid()) {
155  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelHBHE_;
156  valid = false;
157  }
158 
160  iEvent.getByToken(tok_Muon_, muonhandle);
161  if (!muonhandle.isValid()) {
162  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelMuon_;
163  valid = false;
164  }
165 
166 #ifdef EDM_ML_DEBUG
167  edm::LogVerbatim("HcalHBHEMuon") << "AlCaHBHEMuonProducer::obtained the collections with validity flag " << valid;
168 #endif
169 
170  //For accepted events
171  auto outputBeamSpot = std::make_unique<reco::BeamSpot>();
172  auto outputVColl = std::make_unique<reco::VertexCollection>();
173  auto outputEBColl = std::make_unique<EBRecHitCollection>();
174  auto outputEEColl = std::make_unique<EERecHitCollection>();
175  auto outputHBHEColl = std::make_unique<HBHERecHitCollection>();
176  auto outputMColl = std::make_unique<reco::MuonCollection>();
177 
178  if (valid) {
179  const reco::BeamSpot beam = *(bmspot.product());
180  outputBeamSpot = std::make_unique<reco::BeamSpot>(
181  beam.position(), beam.sigmaZ(), beam.dxdz(), beam.dydz(), beam.BeamWidthX(), beam.covariance(), beam.type());
182  const reco::VertexCollection vtx = *(vt.product());
183  const EcalRecHitCollection ebcoll = *(barrelRecHitsHandle.product());
184  const EcalRecHitCollection eecoll = *(endcapRecHitsHandle.product());
185  const HBHERecHitCollection hbhecoll = *(hbhe.product());
186  const reco::MuonCollection muons = *(muonhandle.product());
187 
188  bool accept = select(muons);
189 
190  if (accept) {
191  ++nGood_;
192 
193  for (reco::VertexCollection::const_iterator vtr = vtx.begin(); vtr != vtx.end(); ++vtr)
194  outputVColl->push_back(*vtr);
195 
196  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit = ebcoll.begin(); ehit != ebcoll.end(); ++ehit)
197  outputEBColl->push_back(*ehit);
198 
199  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit = eecoll.begin(); ehit != eecoll.end(); ++ehit)
200  outputEEColl->push_back(*ehit);
201 
202  for (std::vector<HBHERecHit>::const_iterator hhit = hbhecoll.begin(); hhit != hbhecoll.end(); ++hhit)
203  outputHBHEColl->push_back(*hhit);
204 
205  for (reco::MuonCollection::const_iterator muon = muons.begin(); muon != muons.end(); ++muon)
206  outputMColl->push_back(*muon);
207  }
208  }
209 
210  iEvent.put(std::move(outputBeamSpot), labelBS_.label());
211  iEvent.put(std::move(outputVColl), labelVtx_.label());
212  iEvent.put(std::move(outputEBColl), labelEB_.instance());
213  iEvent.put(std::move(outputEEColl), labelEE_.instance());
214  iEvent.put(std::move(outputHBHEColl), labelHBHE_.label());
215  iEvent.put(std::move(outputMColl), labelMuon_.label());
216 }
217 
219  globalCache()->nAll_ += nAll_;
220  globalCache()->nGood_ += nGood_;
221 }
222 
224  edm::LogVerbatim("HcalHBHEMuon") << "Finds " << count->nGood_ << " good tracks in " << count->nAll_ << " events";
225 }
226 
227 void AlCaHBHEMuonProducer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
228  edm::LogVerbatim("HcalHBHEMuon") << "Run[" << nRun_ << "] " << iRun.run();
229 }
230 
232  ++nRun_;
233  edm::LogVerbatim("HcalHBHEMuon") << "endRun[" << nRun_ << "] " << iRun.run();
234 }
235 
237  bool ok(false);
238  for (unsigned int k = 0; k < muons.size(); ++k) {
239  if (muons[k].p() > pMuonMin_) {
240  ok = true;
241  break;
242  }
243  }
244  return ok;
245 }
246 
248 
ConfigurationDescriptions.h
AlCaHBHEMuonProducer::globalEndJob
static void globalEndJob(const AlCaHBHEMuons::Counters *counters)
Definition: AlCaHBHEMuonProducer.cc:223
AlCaHBHEMuonProducer::endStream
void endStream() override
Definition: AlCaHBHEMuonProducer.cc:218
AlCaHBHEMuonProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: AlCaHBHEMuonProducer.cc:114
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
Handle.h
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
Muon.h
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
AlCaHBHEMuonProducer::labelBS_
edm::InputTag labelBS_
Definition: AlCaHBHEMuonProducer.cc:67
edm::InputTag::instance
std::string const & instance() const
Definition: InputTag.h:37
muon
Definition: MuonCocktails.h:17
AlCaHBHEMuonProducer::labelHBHE_
edm::InputTag labelHBHE_
Definition: AlCaHBHEMuonProducer.cc:68
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< reco::BeamSpot >
AlCaHBHEMuonProducer::tok_Vtx_
edm::EDGetTokenT< reco::VertexCollection > tok_Vtx_
Definition: AlCaHBHEMuonProducer.cc:72
AlCaHBHEMuonProducer::select
bool select(const reco::MuonCollection &)
Definition: AlCaHBHEMuonProducer.cc:236
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
AlCaHBHEMuonProducer::labelVtx_
edm::InputTag labelVtx_
Definition: AlCaHBHEMuonProducer.cc:67
AlCaHBHEMuonProducer::tok_BS_
edm::EDGetTokenT< reco::BeamSpot > tok_BS_
Definition: AlCaHBHEMuonProducer.cc:71
EDProducer.h
edm::SortedCollection< EcalRecHit >
AlCaHBHEMuonProducer::tok_Muon_
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
Definition: AlCaHBHEMuonProducer.cc:76
AlCaHBHEMuonProducer::tok_EE_
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
Definition: AlCaHBHEMuonProducer.cc:74
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle< reco::BeamSpot >
edm::RunBase::run
RunNumber_t run() const
Definition: RunBase.h:40
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
EcalRecHitCollections.h
AlCaHBHEMuons::Counters
Definition: AlCaHBHEMuonFilter.cc:42
AlCaHBHEMuonProducer::~AlCaHBHEMuonProducer
~AlCaHBHEMuonProducer() override
Definition: AlCaHBHEMuonProducer.cc:112
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
AlCaHBHEMuonProducer::nGood_
unsigned int nGood_
Definition: AlCaHBHEMuonProducer.cc:66
accept
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
MakerMacros.h
counters
const caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple cms::cuda::AtomicPairCounter const GPUCACell *__restrict__ const uint32_t *__restrict__ const gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell *__restrict__ int32_t uint32_t CAHitNtupletGeneratorKernelsGPU::Counters * counters
Definition: CAHitNtupletGeneratorKernelsImpl.h:53
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11725
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
MuonFwd.h
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
AlCaHBHEMuonProducer::labelMuon_
edm::InputTag labelMuon_
Definition: AlCaHBHEMuonProducer.cc:68
reco::BeamSpot
Definition: BeamSpot.h:21
Run.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
EcalCondDBWriter_cfi.beam
beam
Definition: EcalCondDBWriter_cfi.py:45
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHBHEMuonProducer::labelEE_
edm::InputTag labelEE_
Definition: AlCaHBHEMuonProducer.cc:68
AlCaHBHEMuonProducer::nRun_
unsigned int nRun_
Definition: AlCaHBHEMuonProducer.cc:66
AlCaHBHEMuonProducer::initializeGlobalCache
static std::unique_ptr< AlCaHBHEMuons::Counters > initializeGlobalCache(edm::ParameterSet const &)
Definition: AlCaHBHEMuonProducer.cc:52
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHBHEMuonProducer::pMuonMin_
double pMuonMin_
Definition: AlCaHBHEMuonProducer.cc:69
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
AlCaHBHEMuons::Counters::Counters
Counters()
Definition: AlCaHBHEMuonProducer.cc:42
Event.h
AlCaHBHEMuonProducer
Definition: AlCaHBHEMuonProducer.cc:47
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
AlCaHBHEMuonProducer::AlCaHBHEMuonProducer
AlCaHBHEMuonProducer(edm::ParameterSet const &, const AlCaHBHEMuons::Counters *count)
Definition: AlCaHBHEMuonProducer.cc:79
AlCaHBHEMuons::Counters::nGood_
std::atomic< unsigned int > nGood_
Definition: AlCaHBHEMuonFilter.cc:44
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
AlCaHBHEMuons::Counters::nAll_
std::atomic< unsigned int > nAll_
Definition: AlCaHBHEMuonFilter.cc:44
AlCaHBHEMuons
Definition: AlCaHBHEMuonFilter.cc:41
photonIsolationHIProducer_cfi.hbhe
hbhe
Definition: photonIsolationHIProducer_cfi.py:8
VertexFwd.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
Ref.h
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:19
AlCaHBHEMuonProducer::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaHBHEMuonProducer.cc:227
Vertex.h
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HcalRecHitCollections.h
Exception.h
AlCaHBHEMuonProducer::labelEB_
edm::InputTag labelEB_
Definition: AlCaHBHEMuonProducer.cc:68
AlCaHBHEMuonProducer::nAll_
unsigned int nAll_
Definition: AlCaHBHEMuonProducer.cc:66
RunInfoPI::valid
Definition: RunInfoPayloadInspectoHelper.h:16
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
AlCaHBHEMuonProducer::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaHBHEMuonProducer.cc:231
edm::Event
Definition: Event.h:73
AlCaHBHEMuonProducer::tok_HBHE_
edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
Definition: AlCaHBHEMuonProducer.cc:75
AlCaHBHEMuonProducer::tok_EB_
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
Definition: AlCaHBHEMuonProducer.cc:73
edm::InputTag
Definition: InputTag.h:15