CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaHBHEMuonProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //#define DebugLog
3 
4 // system include files
5 #include <memory>
6 #include <string>
7 #include <cmath>
8 #include <iostream>
9 #include <sstream>
10 #include <fstream>
11 #include <vector>
12 #include <boost/regex.hpp>
13 
14 // user include files
25 
35 
36 //
37 // class declaration
38 //
39 
41 public:
42  explicit AlCaHBHEMuonProducer(const edm::ParameterSet&);
44 
45  virtual void produce(edm::Event &, const edm::EventSetup&);
46 
47 private:
48 
49  virtual void beginJob() ;
50  virtual void endJob() ;
51  virtual void beginRun(edm::Run const&, edm::EventSetup const&);
52  virtual void endRun(edm::Run const&, edm::EventSetup const&);
53  bool select(const reco::MuonCollection &);
54 
55  // ----------member data ---------------------------
56  int nRun, nAll, nGood;
59  double pMuonMin_;
60 
67 };
68 
69 
71  nRun(0), nAll(0), nGood(0) {
72  //Get the run parameters
73  labelBS_ = iConfig.getParameter<edm::InputTag>("BeamSpotLabel");
74  labelVtx_ = iConfig.getParameter<edm::InputTag>("VertexLabel");
75  labelEB_ = iConfig.getParameter<edm::InputTag>("EBRecHitLabel");
76  labelEE_ = iConfig.getParameter<edm::InputTag>("EERecHitLabel");
77  labelHBHE_ = iConfig.getParameter<edm::InputTag>("HBHERecHitLabel");
78  labelMuon_ = iConfig.getParameter<edm::InputTag>("MuonLabel");
79  pMuonMin_ = iConfig.getParameter<double>("MinimumMuonP");
80 
81  // define tokens for access
82  tok_Vtx_ = consumes<reco::VertexCollection>(labelVtx_);
83  tok_BS_ = consumes<reco::BeamSpot>(labelBS_);
84  tok_EB_ = consumes<EcalRecHitCollection>(labelEB_);
85  tok_EE_ = consumes<EcalRecHitCollection>(labelEE_);
86  tok_HBHE_ = consumes<HBHERecHitCollection>(labelHBHE_);
87  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
88 
89  edm::LogInfo("HcalIsoTrack") << "Parameters read from config file \n"
90  << "\t minP of muon " << pMuonMin_
91  << "\t input labels " << labelBS_ << " "
92  << labelVtx_ <<" " << labelEB_ << " " << labelEE_
93  <<" " << labelHBHE_ << " " << labelMuon_;
94 
95  //saves the following collections
96  produces<reco::BeamSpot>(labelBS_.label());
97  produces<reco::VertexCollection>(labelVtx_.label());
98  produces<EcalRecHitCollection>(labelEB_.instance());
99  produces<EcalRecHitCollection>(labelEE_.instance());
100  produces<HBHERecHitCollection>(labelHBHE_.label());
101  produces<reco::MuonCollection>(labelMuon_.label());
102 }
103 
105 
107 
108  nAll++;
109 #ifdef DebugLog
110  edm::LogInfo("HcalHBHEMuon") << "AlCaHBHEMuonProducer::Run "
111  << iEvent.id().run() << " Event "
112  << iEvent.id().event() << " Luminosity "
113  << iEvent.luminosityBlock() << " Bunch "
114  << iEvent.bunchCrossing();
115 #endif
116 
117  //Step1: Get all the relevant containers
119  iEvent.getByToken(tok_BS_, bmspot);
120  if (!bmspot.isValid()){
121  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelBS_;
122  return;
123  }
124  const reco::BeamSpot beam = *(bmspot.product());
125 
126 
128  iEvent.getByToken(tok_Vtx_, vt);
129  if (!vt.isValid()) {
130  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelVtx_;
131  return ;
132  }
133  const reco::VertexCollection vtx = *(vt.product());
134 
135  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
136  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
137  if (!barrelRecHitsHandle.isValid()) {
138  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEB_;
139  return ;
140  }
141  const EcalRecHitCollection ebcoll = *(barrelRecHitsHandle.product());
142 
143  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
144  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
145  if (!endcapRecHitsHandle.isValid()) {
146  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEE_;
147  return ;
148  }
149  const EcalRecHitCollection eecoll = *(endcapRecHitsHandle.product());
150 
152  iEvent.getByToken(tok_HBHE_, hbhe);
153  if (!hbhe.isValid()) {
154  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelHBHE_;
155  return ;
156  }
157  const HBHERecHitCollection hbhecoll = *(hbhe.product());
158 
160  iEvent.getByToken(tok_Muon_, muonhandle);
161  if (!muonhandle.isValid()) {
162  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelMuon_;
163  return ;
164  }
165  const reco::MuonCollection muons = *(muonhandle.product());
166 
167 #ifdef DebugLog
168  edm::LogInfo("HcalHBHEMuon") << "AlCaHBHEMuonProducer::Has obtained all the collections";
169 #endif
170 
171  //For accepted events
172  bool accept = select(muons);
173  std::auto_ptr<reco::BeamSpot> outputBeamSpot(new reco::BeamSpot(beam.position(),beam.sigmaZ(),
174  beam.dxdz(),beam.dydz(),beam.BeamWidthX(),
175  beam.covariance(),beam.type()));
176  std::auto_ptr<reco::VertexCollection> outputVColl(new reco::VertexCollection);
177  std::auto_ptr<EBRecHitCollection> outputEBColl(new EBRecHitCollection);
178  std::auto_ptr<EERecHitCollection> outputEEColl(new EERecHitCollection);
179  std::auto_ptr<HBHERecHitCollection> outputHBHEColl(new HBHERecHitCollection);
180  std::auto_ptr<reco::MuonCollection> outputMColl(new reco::MuonCollection);
181  if (accept) {
182  nGood++;
183 
184  for (reco::VertexCollection::const_iterator vtr=vtx.begin(); vtr!=vtx.end(); ++vtr)
185  outputVColl->push_back(*vtr);
186 
187  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit=ebcoll.begin(); ehit!=ebcoll.end(); ++ehit)
188  outputEBColl->push_back(*ehit);
189 
190  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit=eecoll.begin(); ehit!=eecoll.end(); ++ehit)
191  outputEEColl->push_back(*ehit);
192 
193  for (std::vector<HBHERecHit>::const_iterator hhit=hbhecoll.begin(); hhit!=hbhecoll.end(); ++hhit)
194  outputHBHEColl->push_back(*hhit);
195 
196  for (reco::MuonCollection::const_iterator muon=muons.begin(); muon!=muons.end(); ++muon)
197  outputMColl->push_back(*muon);
198  }
199 
200  iEvent.put(outputBeamSpot, labelBS_.label());
201  iEvent.put(outputVColl, labelVtx_.label());
202  iEvent.put(outputEBColl, labelEB_.instance());
203  iEvent.put(outputEEColl, labelEE_.instance());
204  iEvent.put(outputHBHEColl, labelHBHE_.label());
205  iEvent.put(outputMColl, labelMuon_.label());
206 }
207 
209 
211  edm::LogInfo("HcalHBHEMuon") << "Finds " << nGood << " good tracks in "
212  << nAll << " events from " << nRun << " runs";
213 }
214 
215 void AlCaHBHEMuonProducer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
216  edm::LogInfo("HcalHBHEMuon") << "Run[" << nRun << "] " << iRun.run();
217 }
218 
220  nRun++;
221  edm::LogInfo("HcalHBHEMuon") << "endRun[" << nRun << "] " << iRun.run();
222 }
223 
225 
226  bool ok(false);
227  for (unsigned int k=0; k<muons.size(); ++k) {
228  if (muons[k].p() > pMuonMin_) {
229  ok = true; break;
230  }
231  }
232  return ok;
233 }
234 
236 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
bool select(const reco::MuonCollection &)
AlCaHBHEMuonProducer(const edm::ParameterSet &)
RunNumber_t run() const
Definition: RunBase.h:42
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< EcalRecHitCollection > tok_EE_
std::vector< T >::const_iterator const_iterator
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:25
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
return((rh^lh)&mask)
double dydz() const
dydz slope
Definition: BeamSpot.h:84
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetTokenT< HBHERecHitCollection > tok_HBHE_
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
bool isValid() const
Definition: HandleBase.h:75
double dxdz() const
dxdz slope
Definition: BeamSpot.h:82
const_iterator end() const
T const * product() const
Definition: Handle.h:81
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
edm::EDGetTokenT< EcalRecHitCollection > tok_EB_
edm::EDGetTokenT< reco::BeamSpot > tok_BS_
std::string const & label() const
Definition: InputTag.h:42
double covariance(int i, int j) const
(i,j)-th element of error matrix
Definition: BeamSpot.h:112
edm::EventID id() const
Definition: EventBase.h:60
tuple muons
Definition: patZpeak.py:38
edm::EDGetTokenT< reco::VertexCollection > tok_Vtx_
const Point & position() const
position
Definition: BeamSpot.h:62
std::string const & instance() const
Definition: InputTag.h:43
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
const_iterator begin() const
Definition: Run.h:41
BeamType type() const
return beam type
Definition: BeamSpot.h:129
virtual void endRun(edm::Run const &, edm::EventSetup const &)