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 
42  struct Counters {
43  Counters() : nAll_(0), nGood_(0) {}
44  mutable std::atomic<unsigned int> nAll_, nGood_;
45  };
46 } // namespace alCaHBHEMuonProducer
47 
48 class AlCaHBHEMuonProducer : public edm::stream::EDProducer<edm::GlobalCache<alCaHBHEMuonProducer::Counters> > {
49 public:
51  ~AlCaHBHEMuonProducer() override;
52 
53  static std::unique_ptr<alCaHBHEMuonProducer::Counters> initializeGlobalCache(edm::ParameterSet const&) {
54  return std::make_unique<alCaHBHEMuonProducer::Counters>();
55  }
56 
57  void produce(edm::Event&, const edm::EventSetup&) override;
58  void endStream() override;
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
63  bool select(const reco::MuonCollection&);
64 
65  // ----------member data ---------------------------
66  unsigned int nAll_, nGood_;
69  const double pMuonMin_;
70 
77 };
78 
81  : nAll_(0),
82  nGood_(0),
83  labelBS_(iConfig.getParameter<edm::InputTag>("BeamSpotLabel")),
84  labelVtx_(iConfig.getParameter<edm::InputTag>("VertexLabel")),
85  labelEB_(iConfig.getParameter<edm::InputTag>("EBRecHitLabel")),
86  labelEE_(iConfig.getParameter<edm::InputTag>("EERecHitLabel")),
87  labelHBHE_(iConfig.getParameter<edm::InputTag>("HBHERecHitLabel")),
88  labelMuon_(iConfig.getParameter<edm::InputTag>("MuonLabel")),
89  pMuonMin_(iConfig.getParameter<double>("MinimumMuonP")) {
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
124  auto bmspot = iEvent.getHandle(tok_BS_);
125  if (!bmspot.isValid()) {
126  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelBS_;
127  valid = false;
128  }
129 
130  auto vt = iEvent.getHandle(tok_Vtx_);
131  if (!vt.isValid()) {
132  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelVtx_;
133  valid = false;
134  }
135 
136  auto barrelRecHitsHandle = iEvent.getHandle(tok_EB_);
137  if (!barrelRecHitsHandle.isValid()) {
138  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEB_;
139  valid = false;
140  }
141 
142  auto endcapRecHitsHandle = iEvent.getHandle(tok_EE_);
143  if (!endcapRecHitsHandle.isValid()) {
144  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEE_;
145  valid = false;
146  }
147 
148  auto hbhe = iEvent.getHandle(tok_HBHE_);
149  if (!hbhe.isValid()) {
150  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelHBHE_;
151  valid = false;
152  }
153 
154  auto muonhandle = iEvent.getHandle(tok_Muon_);
155  if (!muonhandle.isValid()) {
156  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelMuon_;
157  valid = false;
158  }
159 
160 #ifdef EDM_ML_DEBUG
161  edm::LogVerbatim("HcalHBHEMuon") << "AlCaHBHEMuonProducer::obtained the collections with validity flag " << valid;
162 #endif
163 
164  //For accepted events
165  auto outputBeamSpot = std::make_unique<reco::BeamSpot>();
166  auto outputVColl = std::make_unique<reco::VertexCollection>();
167  auto outputEBColl = std::make_unique<EBRecHitCollection>();
168  auto outputEEColl = std::make_unique<EERecHitCollection>();
169  auto outputHBHEColl = std::make_unique<HBHERecHitCollection>();
170  auto outputMColl = std::make_unique<reco::MuonCollection>();
171 
172  if (valid) {
173  const reco::BeamSpot beam = *(bmspot.product());
174  outputBeamSpot = std::make_unique<reco::BeamSpot>(
175  beam.position(), beam.sigmaZ(), beam.dxdz(), beam.dydz(), beam.BeamWidthX(), beam.covariance(), beam.type());
176  const reco::VertexCollection vtx = *(vt.product());
177  const EcalRecHitCollection ebcoll = *(barrelRecHitsHandle.product());
178  const EcalRecHitCollection eecoll = *(endcapRecHitsHandle.product());
179  const HBHERecHitCollection hbhecoll = *(hbhe.product());
180  const reco::MuonCollection muons = *(muonhandle.product());
181 
182  bool accept = select(muons);
183 
184  if (accept) {
185  ++nGood_;
186 
187  for (reco::VertexCollection::const_iterator vtr = vtx.begin(); vtr != vtx.end(); ++vtr)
188  outputVColl->push_back(*vtr);
189 
190  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit = ebcoll.begin(); ehit != ebcoll.end(); ++ehit)
191  outputEBColl->push_back(*ehit);
192 
193  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit = eecoll.begin(); ehit != eecoll.end(); ++ehit)
194  outputEEColl->push_back(*ehit);
195 
196  for (std::vector<HBHERecHit>::const_iterator hhit = hbhecoll.begin(); hhit != hbhecoll.end(); ++hhit)
197  outputHBHEColl->push_back(*hhit);
198 
199  for (reco::MuonCollection::const_iterator muon = muons.begin(); muon != muons.end(); ++muon)
200  outputMColl->push_back(*muon);
201  }
202  }
203 
204  iEvent.put(std::move(outputBeamSpot), labelBS_.label());
205  iEvent.put(std::move(outputVColl), labelVtx_.label());
206  iEvent.put(std::move(outputEBColl), labelEB_.instance());
207  iEvent.put(std::move(outputEEColl), labelEE_.instance());
208  iEvent.put(std::move(outputHBHEColl), labelHBHE_.label());
209  iEvent.put(std::move(outputMColl), labelMuon_.label());
210 }
211 
213  globalCache()->nAll_ += nAll_;
214  globalCache()->nGood_ += nGood_;
215 }
216 
218  edm::LogVerbatim("HcalHBHEMuon") << "Finds " << count->nGood_ << " good tracks in " << count->nAll_ << " events";
219 }
220 
222  //The following says we do not know what parameters are allowed so do no validation
223  // Please change this to state exactly what you do use, even if it is no parameters
225  desc.add<edm::InputTag>("BeamSpotLabel", edm::InputTag("offlineBeamSpot"));
226  desc.add<edm::InputTag>("VertexLabel", edm::InputTag("offlinePrimaryVertices"));
227  desc.add<edm::InputTag>("EBRecHitLabel", edm::InputTag("ecalRecHit", "EcalRecHitsEB"));
228  desc.add<edm::InputTag>("EERecHitLabel", edm::InputTag("ecalRecHit", "EcalRecHitsEE"));
229  desc.add<edm::InputTag>("HBHERecHitLabel", edm::InputTag("hbhereco"));
230  desc.add<edm::InputTag>("MuonLabel", edm::InputTag("muons"));
231  desc.add<double>("MinimumMuonP", 5.0);
232  descriptions.add("alcaHBHEMuonProducer", desc);
233 }
234 
236  bool ok(false);
237  for (unsigned int k = 0; k < muons.size(); ++k) {
238  if (muons[k].p() > pMuonMin_) {
239  ok = true;
240  break;
241  }
242  }
243  return ok;
244 }
245 
247 
Log< level::Info, true > LogVerbatim
bool select(const reco::MuonCollection &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::string const & instance() const
Definition: InputTag.h:37
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
const edm::InputTag labelEE_
std::vector< T >::const_iterator const_iterator
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_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
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
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ CellNeighborsVector< TrackerTraits > const CellTracksVector< TrackerTraits > const OuterHitOfCell< TrackerTraits > const int32_t uint32_t Counters * counters
int iEvent
Definition: GenABIO.cc:224
const edm::InputTag labelEB_
edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
std::atomic< unsigned int > nAll_
const edm::InputTag labelVtx_
const edm::InputTag labelMuon_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
AlCaHBHEMuonProducer(edm::ParameterSet const &, const alCaHBHEMuonProducer::Counters *count)
const_iterator end() const
std::atomic< unsigned int > nGood_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
edm::EDGetTokenT< reco::BeamSpot > tok_BS_
static std::unique_ptr< alCaHBHEMuonProducer::Counters > initializeGlobalCache(edm::ParameterSet const &)
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 alCaHBHEMuonProducer::Counters *counters)
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_