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 
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 
36 
37 //
38 // class declaration
39 //
40 
42 public:
43  explicit AlCaHBHEMuonProducer(const edm::ParameterSet&);
45 
46  virtual void produce(edm::Event &, const edm::EventSetup&);
47 
48 private:
49 
50  virtual void beginJob() ;
51  virtual void endJob() ;
52  virtual void beginRun(edm::Run const&, edm::EventSetup const&);
53  virtual void endRun(edm::Run const&, edm::EventSetup const&);
54  bool select(const reco::MuonCollection &);
55 
56  // ----------member data ---------------------------
57  int nRun, nAll, nGood;
60  double pMuonMin_;
61 
69 };
70 
71 
73  nRun(0), nAll(0), nGood(0) {
74  //Get the run parameters
75  labelTriggerResults_ = iConfig.getParameter<edm::InputTag>("TriggerResultLabel");
76  labelBS_ = iConfig.getParameter<edm::InputTag>("BeamSpotLabel");
77  labelVtx_ = iConfig.getParameter<edm::InputTag>("VertexLabel");
78  labelEB_ = iConfig.getParameter<edm::InputTag>("EBRecHitLabel");
79  labelEE_ = iConfig.getParameter<edm::InputTag>("EERecHitLabel");
80  labelHBHE_ = iConfig.getParameter<edm::InputTag>("HBHERecHitLabel");
81  labelMuon_ = iConfig.getParameter<edm::InputTag>("MuonLabel");
82  pMuonMin_ = iConfig.getParameter<double>("MinimumMuonP");
83 
84  // define tokens for access
85  tok_trigRes_ = consumes<edm::TriggerResults>(labelTriggerResults_);
86  tok_Vtx_ = consumes<reco::VertexCollection>(labelVtx_);
87  tok_BS_ = consumes<reco::BeamSpot>(labelBS_);
88  tok_EB_ = consumes<EcalRecHitCollection>(labelEB_);
89  tok_EE_ = consumes<EcalRecHitCollection>(labelEE_);
90  tok_HBHE_ = consumes<HBHERecHitCollection>(labelHBHE_);
91  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
92 
93  edm::LogInfo("HcalIsoTrack") <<"Parameters read from config file \n"
94  <<"\t minP of muon " << pMuonMin_
95  <<"\t input labels " << labelTriggerResults_
96  <<" " << labelBS_ << " " << labelVtx_
97  <<" " << labelEB_ << " " << labelEE_
98  <<" " << labelHBHE_ << " " << labelMuon_;
99 
100  //saves the following collections
101  produces<edm::TriggerResults>(labelTriggerResults_.encode());
102  produces<reco::BeamSpot>(labelBS_.encode());
103  produces<reco::VertexCollection>(labelVtx_.encode());
104  produces<EcalRecHitCollection>(labelEB_.encode());
105  produces<EcalRecHitCollection>(labelEE_.encode());
106  produces<HBHERecHitCollection>(labelHBHE_.encode());
107  produces<reco::MuonCollection>(labelMuon_.encode());
108 
109 }
110 
112 
114 
115  nAll++;
116  LogDebug("HcalHBHEMuon") << "Run " << iEvent.id().run() << " Event "
117  << iEvent.id().event() << " Luminosity "
118  << iEvent.luminosityBlock() << " Bunch "
119  << iEvent.bunchCrossing();
120 
121  //Step1: Get all the relevant containers
123  iEvent.getByToken(tok_trigRes_, triggerResults);
124  if (!triggerResults.isValid()) {
125  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelTriggerResults_;
126  return;
127  }
128  const edm::TriggerResults trigres = *(triggerResults.product());
129 
131  iEvent.getByToken(tok_BS_, bmspot);
132  if (!bmspot.isValid()){
133  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelBS_;
134  return;
135  }
136  const reco::BeamSpot beam = *(bmspot.product());
137 
139  iEvent.getByToken(tok_Vtx_, vt);
140  if (!vt.isValid()) {
141  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelVtx_;
142  return ;
143  }
144  const reco::VertexCollection vtx = *(vt.product());
145 
146  edm::Handle<EcalRecHitCollection> barrelRecHitsHandle;
147  iEvent.getByToken(tok_EB_, barrelRecHitsHandle);
148  if (!barrelRecHitsHandle.isValid()) {
149  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEB_;
150  return ;
151  }
152  const EcalRecHitCollection ebcoll = *(barrelRecHitsHandle.product());
153 
154  edm::Handle<EcalRecHitCollection> endcapRecHitsHandle;
155  iEvent.getByToken(tok_EE_, endcapRecHitsHandle);
156  if (!endcapRecHitsHandle.isValid()) {
157  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelEE_;
158  return ;
159  }
160  const EcalRecHitCollection eecoll = *(endcapRecHitsHandle.product());
161 
163  iEvent.getByToken(tok_HBHE_, hbhe);
164  if (!hbhe.isValid()) {
165  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelHBHE_;
166  return ;
167  }
168  const HBHERecHitCollection hbhecoll = *(hbhe.product());
169 
171  iEvent.getByToken(tok_Muon_, muonhandle);
172  if (!muonhandle.isValid()) {
173  edm::LogWarning("HcalHBHEMuon") << "AlCaHBHEMuonProducer: Error! can't get product " << labelMuon_;
174  return ;
175  }
176  const reco::MuonCollection muons = *(muonhandle.product());
177 
178  LogDebug("HcalHBHEMuon") << "Has obtained all the collections";
179 
180  //For accepted events
181  bool accept = select(muons);
182  if (accept) {
183  nGood++;
184 
185  std::auto_ptr<edm::TriggerResults> outputTriggerResults(new edm::TriggerResults);
186  *outputTriggerResults = trigres;
187 
188  std::auto_ptr<reco::BeamSpot> outputBeamSpot(new reco::BeamSpot(beam.position(),beam.sigmaZ(),
189  beam.dxdz(),beam.dydz(),beam.BeamWidthX(),
190  beam.covariance(),beam.type()));
191 
192  std::auto_ptr<reco::VertexCollection> outputVColl(new reco::VertexCollection);
193  for (reco::VertexCollection::const_iterator vtr=vtx.begin(); vtr!=vtx.end(); ++vtr)
194  outputVColl->push_back(*vtr);
195 
196  std::auto_ptr<EBRecHitCollection> outputEBColl(new EBRecHitCollection);
197  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit=ebcoll.begin(); ehit!=ebcoll.end(); ++ehit)
198  outputEBColl->push_back(*ehit);
199 
200  std::auto_ptr<EERecHitCollection> outputEEColl(new EERecHitCollection);
201  for (edm::SortedCollection<EcalRecHit>::const_iterator ehit=eecoll.begin(); ehit!=eecoll.end(); ++ehit)
202  outputEEColl->push_back(*ehit);
203 
204  std::auto_ptr<HBHERecHitCollection> outputHBHEColl(new HBHERecHitCollection);
205  for (std::vector<HBHERecHit>::const_iterator hhit=hbhecoll.begin(); hhit!=hbhecoll.end(); ++hhit)
206  outputHBHEColl->push_back(*hhit);
207 
208 
209  std::auto_ptr<reco::MuonCollection> outputMColl(new reco::MuonCollection);
210  for (reco::MuonCollection::const_iterator muon=muons.begin(); muon!=muons.end(); ++muon)
211  outputMColl->push_back(*muon);
212 
213  iEvent.put(outputTriggerResults, labelTriggerResults_.encode());
214  iEvent.put(outputBeamSpot, labelBS_.encode());
215  iEvent.put(outputVColl, labelVtx_.encode());
216  iEvent.put(outputEBColl, labelEB_.encode());
217  iEvent.put(outputEEColl, labelEE_.encode());
218  iEvent.put(outputHBHEColl, labelHBHE_.encode());
219  iEvent.put(outputMColl, labelMuon_.encode());
220  }
221 }
222 
224 
226  edm::LogInfo("HcalHBHEMuon") << "Finds " << nGood << " good tracks in "
227  << nAll << " events from " << nRun << " runs";
228 }
229 
230 void AlCaHBHEMuonProducer::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
231  edm::LogInfo("HcalHBHEMuon") << "Run[" << nRun << "] " << iRun.run();
232 }
233 
235  nRun++;
236  edm::LogInfo("HcalHBHEMuon") << "endRun[" << nRun << "] " << iRun.run();
237 }
238 
240 
241  bool ok = (muons.size() > 0) ? (muons[0].p() > pMuonMin_) : false;
242  return ok;
243 }
244 
246 
#define LogDebug(id)
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::InputTag labelTriggerResults_
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:25
std::string encode() const
Definition: InputTag.cc:164
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
static std::string const triggerResults
Definition: EdmProvDump.cc:40
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_
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
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 &)