CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaHBHEMuonFilter.cc
Go to the documentation of this file.
1 // system include files
2 #include <atomic>
3 #include <memory>
4 #include <cmath>
5 #include <iostream>
6 #include <sstream>
7 #include <fstream>
8 
9 // user include files
21 
28 
31 
36 
37 //#define DebugLog
38 //
39 // class declaration
40 //
41 
42 namespace AlCaHBHEMuons {
43  struct Counters {
44  Counters() : nAll_(0), nGood_(0) {}
45  mutable std::atomic<unsigned int> nAll_, nGood_;
46  };
47 }
48 
49 class AlCaHBHEMuonFilter : public edm::stream::EDFilter<edm::GlobalCache<AlCaHBHEMuons::Counters> > {
50 public:
53 
54  static std::unique_ptr<AlCaHBHEMuons::Counters> initializeGlobalCache(edm::ParameterSet const&) {
55  return std::unique_ptr<AlCaHBHEMuons::Counters>(new AlCaHBHEMuons::Counters());
56  }
57 
58  virtual bool filter(edm::Event&, edm::EventSetup const&) override;
59  virtual void endStream() override;
60  static void globalEndJob(const AlCaHBHEMuons::Counters* counters);
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63 private:
64 
65  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
66  virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
67 
68  // ----------member data ---------------------------
70  std::vector<std::string> trigNames_, HLTNames_;
72  unsigned int nRun_, nAll_, nGood_;
77 };
78 
79 //
80 // constants, enums and typedefs
81 //
82 
83 //
84 // static data member definitions
85 //
86 
87 //
88 // constructors and destructor
89 //
91  nRun_(0), nAll_(0), nGood_(0) {
92  //now do what ever initialization is needed
93  trigNames_ = iConfig.getParameter<std::vector<std::string> >("Triggers");
94  processName_ = iConfig.getParameter<std::string>("ProcessName");
95  triggerResults_ = iConfig.getParameter<edm::InputTag>("TriggerResultLabel");
96  labelMuon_ = iConfig.getParameter<edm::InputTag>("MuonLabel");
97 
98  // define tokens for access
99  tok_trigRes_ = consumes<edm::TriggerResults>(triggerResults_);
100  tok_Muon_ = consumes<reco::MuonCollection>(labelMuon_);
101  edm::LogInfo("HcalHBHEMuon") << "Parameters read from config file \n"
102  << "Process " << processName_;
103  for (unsigned int k=0; k<trigNames_.size(); ++k)
104  edm::LogInfo("HcalHBHEMuon") << "Trigger[" << k << "] " << trigNames_[k];
105 } // AlCaHBHEMuonFilter::AlCaHBHEMuonFilter constructor
106 
107 
109 
110 //
111 // member functions
112 //
113 
114 // ------------ method called on each new Event ------------
116  bool accept(false);
117  ++nAll_;
118 #ifdef DebugLog
119  edm::LogInfo("HcalHBHEMuon") << "AlCaHBHEMuonFilter::Run "
120  << iEvent.id().run() << " Event "
121  << iEvent.id().event() << " Luminosity "
122  << iEvent.luminosityBlock() << " Bunch "
123  << iEvent.bunchCrossing();
124 #endif
125  //Step1: Find if the event passes one of the chosen triggers
128  iEvent.getByToken(tok_trigRes_, triggerResults);
129  if (triggerResults.isValid()) {
130  bool ok(false);
131  std::vector<std::string> modules;
132  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
133  const std::vector<std::string> & triggerNames_ = triggerNames.triggerNames();
134  for (unsigned int iHLT=0; iHLT<triggerResults->size(); iHLT++) {
135  int hlt = triggerResults->accept(iHLT);
136  for (unsigned int i=0; i<trigNames_.size(); ++i) {
137  if (triggerNames_[iHLT].find(trigNames_[i].c_str())!=std::string::npos){
138  if (hlt > 0) {
139  ok = true;
140  }
141 #ifdef DebugLog
142  edm::LogInfo("HcalHBHEMuon") << "AlCaHBHEMuonFilter::Trigger "
143  << triggerNames_[iHLT] << " Flag "
144  << hlt << ":" << ok;
145 #endif
146  }
147  }
148  }
149  if (ok) {
150  //Step2: Get geometry/B-field information
151  //Get magnetic field
153  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
154  const MagneticField *bField = bFieldH.product();
155  // get handles to calogeometry
157  iSetup.get<CaloGeometryRecord>().get(pG);
158  const CaloGeometry* geo = pG.product();
159 
160  // Relevant blocks from iEvent
162  iEvent.getByToken(tok_Muon_, _Muon);
163 #ifdef DebugLog
164  edm::LogInfo("HcalHBHEMuon") << "AlCaHBHEMuonFilter::Muon Handle "
165  << _Muon.isValid();
166 #endif
167  if (_Muon.isValid()) {
168  for (reco::MuonCollection::const_iterator RecMuon = _Muon->begin();
169  RecMuon!= _Muon->end(); ++RecMuon) {
170 #ifdef DebugLog
171  edm::LogInfo("HcalHBHEMuon") << "AlCaHBHEMuonFilter::Muon:Track " << RecMuon->track().isNonnull() << " innerTrack " << RecMuon->innerTrack().isNonnull() << " outerTrack " << RecMuon->outerTrack().isNonnull() << " globalTrack " << RecMuon->globalTrack().isNonnull();
172 #endif
173  if ((RecMuon->track().isNonnull()) &&
174  (RecMuon->innerTrack().isNonnull()) &&
175  (RecMuon->outerTrack().isNonnull()) &&
176  (RecMuon->globalTrack().isNonnull())) {
177  const reco::Track* pTrack = (RecMuon->innerTrack()).get();
178  spr::propagatedTrackID trackID = spr::propagateCALO(pTrack, geo, bField, false);
179 #ifdef DebugLog
180  edm::LogInfo("HcalHBHEMuon")<<"AlCaHBHEMuonFilter::Propagate: ECAL "
181  << trackID.okECAL << " to HCAL "
182  << trackID.okHCAL;
183 #endif
184  if ((trackID.okECAL) && (trackID.okHCAL)) {
185  accept = true;
186  break;
187  }
188  }
189  }
190  }
191  }
192  }
193  // Step 4: Return the acceptance flag
194  if (accept) ++nGood_;
195  return accept;
196 
197 } // AlCaHBHEMuonFilter::filter
198 
199 // ------------ method called once each job just after ending the event loop ------------
201  globalCache()->nAll_ += nAll_;
202  globalCache()->nGood_ += nGood_;
203 }
204 
206  edm::LogInfo("HcalHBHEMuon") << "Selects " << count->nGood_ << " in "
207  << count->nAll_ << " events";
208 }
209 
210 
211 // ------------ method called when starting to processes a run ------------
212 void AlCaHBHEMuonFilter::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
213  bool changed(false);
214  bool flag = hltConfig_.init(iRun, iSetup, processName_, changed);
215  edm::LogInfo("HcalHBHEMuon") << "Run[" << nRun_ << "] " << iRun.run()
216  << " hltconfig.init " << flag;
217 }
218 
219 // ------------ method called when ending the processing of a run ------------
221  edm::LogInfo("HcalHBHEMuon") << "endRun[" << nRun_ << "] " << iRun.run();
222  nRun_++;
223 }
224 
225 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
226 void
228  //The following says we do not know what parameters are allowed so do no validation
229  // Please change this to state exactly what you do use, even if it is no parameters
231  desc.setUnknown();
232  descriptions.addDefault(desc);
233 }
234 
235 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:220
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, std::string &theTrackQuality, bool debug=false)
RunNumber_t run() const
Definition: RunBase.h:42
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
virtual void endStream() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag labelMuon_
edm::EDGetTokenT< reco::MuonCollection > tok_Muon_
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:24
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
static void globalEndJob(const AlCaHBHEMuons::Counters *counters)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
AlCaHBHEMuonFilter(edm::ParameterSet const &, const AlCaHBHEMuons::Counters *count)
edm::InputTag triggerResults_
static std::string const triggerResults
Definition: EdmProvDump.cc:40
bool isValid() const
Definition: HandleBase.h:75
std::vector< std::string > HLTNames_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
std::atomic< unsigned int > nGood_
static std::unique_ptr< AlCaHBHEMuons::Counters > initializeGlobalCache(edm::ParameterSet const &)
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
edm::EventID id() const
Definition: EventBase.h:60
std::atomic< unsigned int > nAll_
virtual bool filter(edm::Event &, edm::EventSetup const &) override
std::vector< std::string > trigNames_
HLTConfigProvider hltConfig_
edm::EDGetTokenT< edm::TriggerResults > tok_trigRes_
Definition: Run.h:43
edm::EDGetTokenT< trigger::TriggerEvent > tok_trigEvt