CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonRecoOneHLT.cc
Go to the documentation of this file.
2 
4 
5 #include <string>
6 #include "TMath.h"
7 using namespace std;
8 using namespace edm;
9 
10 // Uncomment to DEBUG
11 //#define DEBUG
12 
13 MuonRecoOneHLT::MuonRecoOneHLT(const edm::ParameterSet& pSet) { //, MuonServiceProxy *theService) :MuonAnalyzerBase(theService) {
14  parameters = pSet;
15 
16  // the services
17  theService = new MuonServiceProxy(parameters.getParameter<ParameterSet>("ServiceParameters"));
18 
19 
20  ParameterSet muonparms = parameters.getParameter<edm::ParameterSet>("SingleMuonTrigger");
21  ParameterSet dimuonparms = parameters.getParameter<edm::ParameterSet>("DoubleMuonTrigger");
22  _SingleMuonEventFlag = new GenericTriggerEventFlag( muonparms, consumesCollector() );
23  _DoubleMuonEventFlag = new GenericTriggerEventFlag( dimuonparms, consumesCollector() );
24 
25  // Trigger Expresions in case de connection to the DB fails
26  singlemuonExpr_ = muonparms.getParameter<std::vector<std::string> >("hltPaths");
27  doublemuonExpr_ = dimuonparms.getParameter<std::vector<std::string> >("hltPaths");
28 
29  theMuonCollectionLabel_ = consumes<reco::MuonCollection>(parameters.getParameter<edm::InputTag>("MuonCollection"));
30  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
31  theBeamSpotLabel_ = mayConsume<reco::BeamSpot>(parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
32  theTriggerResultsLabel_ = consumes<TriggerResults>(parameters.getParameter<InputTag>("TriggerResultsLabel"));
33 
34  // Parameters
35  etaBin = parameters.getParameter<int>("etaBin");
36  etaMin = parameters.getParameter<double>("etaMin");
37  etaMax = parameters.getParameter<double>("etaMax");
38  ptBin = parameters.getParameter<int>("ptBin");
39  ptMin = parameters.getParameter<double>("ptMin");
40  ptMax = parameters.getParameter<double>("ptMax");
41  chi2Bin = parameters.getParameter<int>("chi2Bin");
42  chi2Min = parameters.getParameter<double>("chi2Min");
43  chi2Max = parameters.getParameter<double>("chi2Max");
44  phiBin = parameters.getParameter<int>("phiBin");
45  phiMin = parameters.getParameter<double>("phiMin");
46  phiMax = parameters.getParameter<double>("phiMax");
47 }
49  delete _SingleMuonEventFlag;
50  delete _DoubleMuonEventFlag;
51 }
53  edm::Run const & iRun,
54  edm::EventSetup const & iSetup) {
55 #ifdef DEBUG
56  cout << "[MuonRecoOneHLT] beginRun " << endl;
57  cout << "[MuonRecoOneHLT] Is MuonEventFlag On? "<< _SingleMuonEventFlag->on() << endl;
58 #endif
59 
60  ibooker.cd();
61  ibooker.setCurrentFolder("Muons/MuonRecoOneHLT");
62 
63  muReco = ibooker.book1D("Muon_Reco", "Muon Reconstructed Tracks", 6, 1, 7);
64  muReco->setBinLabel(1,"glb+tk+sta");
65  muReco->setBinLabel(2,"glb+sta");
66  muReco->setBinLabel(3,"tk+sta");
67  muReco->setBinLabel(4,"tk");
68  muReco->setBinLabel(5,"sta");
69  muReco->setBinLabel(6,"calo");
70 
71  // monitoring of eta parameter
72  std::string histname = "GlbMuon_";
73  etaGlbTrack.push_back(ibooker.book1D(histname+"Glb_eta", "#eta_{GLB}", etaBin, etaMin, etaMax));
74  etaGlbTrack.push_back(ibooker.book1D(histname+"Tk_eta", "#eta_{TKfromGLB}", etaBin, etaMin, etaMax));
75  etaGlbTrack.push_back(ibooker.book1D(histname+"Sta_eta", "#eta_{STAfromGLB}", etaBin, etaMin, etaMax));
76  etaTight = ibooker.book1D("TightMuon_eta", "#eta_{GLB}", etaBin, etaMin, etaMax);
77  etaTrack = ibooker.book1D("TkMuon_eta", "#eta_{TK}", etaBin, etaMin, etaMax);
78  etaStaTrack = ibooker.book1D("StaMuon_eta", "#eta_{STA}", etaBin, etaMin, etaMax);
79 
80  // monitoring of phi paramater
81  phiGlbTrack.push_back(ibooker.book1D(histname+"Glb_phi", "#phi_{GLB}", phiBin, phiMin, phiMax));
82  phiGlbTrack[0]->setAxisTitle("rad");
83  phiGlbTrack.push_back(ibooker.book1D(histname+"Tk_phi", "#phi_{TKfromGLB}", phiBin, phiMin, phiMax));
84  phiGlbTrack[1]->setAxisTitle("rad");
85  phiGlbTrack.push_back(ibooker.book1D(histname+"Sta_phi", "#phi_{STAfromGLB}", phiBin, phiMin, phiMax));
86  phiGlbTrack[2]->setAxisTitle("rad");
87  phiTight = ibooker.book1D("TightMuon_phi", "#phi_{GLB}", phiBin, phiMin, phiMax);
88  phiTrack = ibooker.book1D("TkMuon_phi", "#phi_{TK}", phiBin, phiMin, phiMax);
89  phiTrack->setAxisTitle("rad");
90  phiStaTrack = ibooker.book1D("StaMuon_phi", "#phi_{STA}", phiBin, phiMin, phiMax);
91  phiStaTrack->setAxisTitle("rad");
92 
93  // monitoring of the chi2 parameter
94  chi2OvDFGlbTrack.push_back(ibooker.book1D(histname+"Glb_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max));
95  chi2OvDFGlbTrack.push_back(ibooker.book1D(histname+"Tk_chi2OverDf", "#chi_{2}OverDF_{TKfromGLB}", phiBin, chi2Min, chi2Max));
96  chi2OvDFGlbTrack.push_back(ibooker.book1D(histname+"Sta_chi2OverDf", "#chi_{2}OverDF_{STAfromGLB}", chi2Bin, chi2Min, chi2Max));
97  chi2OvDFTight = ibooker.book1D("TightMuon_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max);
98  chi2OvDFTrack = ibooker.book1D("TkMuon_chi2OverDf", "#chi_{2}OverDF_{TK}", chi2Bin, chi2Min, chi2Max);
99  chi2OvDFStaTrack = ibooker.book1D("StaMuon_chi2OverDf", "#chi_{2}OverDF_{STA}", chi2Bin, chi2Min, chi2Max);
100 
101  // monitoring of the transverse momentum
102  ptGlbTrack.push_back(ibooker.book1D(histname+"Glb_pt", "pt_{GLB}", ptBin, ptMin, ptMax));
103  ptGlbTrack[0]->setAxisTitle("GeV");
104  ptGlbTrack.push_back(ibooker.book1D(histname+"Tk_pt", "pt_{TKfromGLB}", ptBin, ptMin, ptMax));
105  ptGlbTrack[1]->setAxisTitle("GeV");
106  ptGlbTrack.push_back(ibooker.book1D(histname+"Sta_pt", "pt_{STAfromGLB}", ptBin, ptMin, ptMax));
107  ptGlbTrack[2]->setAxisTitle("GeV");
108  ptTight = ibooker.book1D("TightMuon_pt", "pt_{GLB}", ptBin, ptMin, ptMax);
109  ptTight->setAxisTitle("GeV");
110  ptTrack = ibooker.book1D("TkMuon_pt", "pt_{TK}", ptBin, ptMin, ptMax);
111  ptTrack->setAxisTitle("GeV");
112  ptStaTrack = ibooker.book1D("StaMuon_pt", "pt_{STA}", ptBin, ptMin, ptMax);
113  ptStaTrack->setAxisTitle("GeV");
114 
115  if ( _SingleMuonEventFlag->on() ) _SingleMuonEventFlag->initRun( iRun, iSetup );
116  if ( _DoubleMuonEventFlag->on() ) _DoubleMuonEventFlag->initRun( iRun, iSetup );
117 
118  if (_SingleMuonEventFlag->on() && _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
119  singlemuonExpr_ = _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(),iSetup);
120  if (_DoubleMuonEventFlag->on() && _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
121  singlemuonExpr_ = _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(),iSetup);
122 }
124  theService->update(iSetup);
125 
126  // =================================================================================
127  // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
128  reco::Vertex::Point posVtx;
129  reco::Vertex::Error errVtx;
130  unsigned int theIndexOfThePrimaryVertex = 999.;
131 
133  iEvent.getByToken(theVertexLabel_, vertex);
134  if (vertex.isValid()){
135  for (unsigned int ind=0; ind<vertex->size(); ++ind) {
136  if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
137  theIndexOfThePrimaryVertex = ind;
138  break;
139  }
140  }
141  }
142 
143  if (theIndexOfThePrimaryVertex<100) {
144  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
145  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
146  }
147  else {
148  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
149 
150  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
151  iEvent.getByToken(theBeamSpotLabel_,recoBeamSpotHandle);
152  reco::BeamSpot bs = *recoBeamSpotHandle;
153 
154  posVtx = bs.position();
155  errVtx(0,0) = bs.BeamWidthX();
156  errVtx(1,1) = bs.BeamWidthY();
157  errVtx(2,2) = bs.sigmaZ();
158  }
159 
160  const reco::Vertex vtx(posVtx,errVtx);
161 
162 
163  // ==========================================================
164  // READ DATA:
166  iEvent.getByToken(theMuonCollectionLabel_,muons);
167 
169  iEvent.getByToken(theTriggerResultsLabel_, triggerResults);
170 
171  // check if muon collection is valid
172  if(!muons.isValid()) return;
173 
174  // Pick the leading lepton.
175  std::map<float,reco::Muon> muonMap;
176  for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu!=muons->end(); ++recoMu){
177  muonMap[recoMu->pt()] = *recoMu;
178  }
179  std::vector<reco::Muon> LeadingMuon;
180  for( std::map<float,reco::Muon>::reverse_iterator rit=muonMap.rbegin(); rit!=muonMap.rend(); ++rit){
181  LeadingMuon.push_back( (*rit).second );
182  }
183 
184  // Pick Trigger information.
185  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
186  const unsigned int nTrig(triggerNames.size());
187  bool _trig_SingleMu = false;
188  bool _trig_DoubleMu = false;
189  for (unsigned int i=0;i<nTrig;++i){
190  if (triggerNames.triggerName(i).find(singlemuonExpr_[0].substr(0,singlemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults->accept(i))
191  _trig_SingleMu = true;
192  if (triggerNames.triggerName(i).find(doublemuonExpr_[0].substr(0,doublemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults->accept(i))
193  _trig_DoubleMu = true;
194  }
195 #ifdef DEBUG
196  cout << "[MuonRecoOneHLT] Trigger Fired ? "<< (_trig_SingleMu || _trig_DoubleMu) << endl;
197 #endif
198 
199  if (!_trig_SingleMu && !_trig_DoubleMu) return;
200  if (LeadingMuon.size() == 0) return;
201  // if (_MuonEventFlag->on() && !(_MuonEventFlag->accept(iEvent,iSetup))) return;
202 
203  // Check if Muon is Global
204  if(LeadingMuon[0].isGlobalMuon()) {
205  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is global - filling the histos";
206  if(LeadingMuon[0].isTrackerMuon() && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(1);
207  if(!(LeadingMuon[0].isTrackerMuon()) && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(2);
208  if(!LeadingMuon[0].isStandAloneMuon())
209  LogTrace(metname)<<"[MuonRecoOneHLT] ERROR: the mu is global but not standalone!";
210 
211  // get the track combinig the information from both the Tracker and the Spectrometer
212  reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
213  // get the track using only the tracker data
214  reco::TrackRef recoTkGlbTrack = LeadingMuon[0].track();
215  // get the track using only the mu spectrometer data
216  reco::TrackRef recoStaGlbTrack = LeadingMuon[0].standAloneMuon();
217 
218  etaGlbTrack[0]->Fill(recoCombinedGlbTrack->eta());
219  etaGlbTrack[1]->Fill(recoTkGlbTrack->eta());
220  etaGlbTrack[2]->Fill(recoStaGlbTrack->eta());
221 
222  phiGlbTrack[0]->Fill(recoCombinedGlbTrack->phi());
223  phiGlbTrack[1]->Fill(recoTkGlbTrack->phi());
224  phiGlbTrack[2]->Fill(recoStaGlbTrack->phi());
225 
226  chi2OvDFGlbTrack[0]->Fill(recoCombinedGlbTrack->normalizedChi2());
227  chi2OvDFGlbTrack[1]->Fill(recoTkGlbTrack->normalizedChi2());
228  chi2OvDFGlbTrack[2]->Fill(recoStaGlbTrack->normalizedChi2());
229 
230  ptGlbTrack[0]->Fill(recoCombinedGlbTrack->pt());
231  ptGlbTrack[1]->Fill(recoTkGlbTrack->pt());
232  ptGlbTrack[2]->Fill(recoStaGlbTrack->pt());
233  }
234  // Check if Muon is Tight
235  if (muon::isTightMuon(LeadingMuon[0], vtx) ) {
236 
237  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
238 
239  reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
240 
241  etaTight->Fill(recoCombinedGlbTrack->eta());
242  phiTight->Fill(recoCombinedGlbTrack->phi());
243  chi2OvDFTight->Fill(recoCombinedGlbTrack->normalizedChi2());
244  ptTight->Fill(recoCombinedGlbTrack->pt());
245  }
246 
247  // Check if Muon is Tracker but NOT Global
248  if(LeadingMuon[0].isTrackerMuon() && !(LeadingMuon[0].isGlobalMuon())) {
249  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
250  if(LeadingMuon[0].isStandAloneMuon()) muReco->Fill(3);
251  if(!(LeadingMuon[0].isStandAloneMuon())) muReco->Fill(4);
252 
253  // get the track using only the tracker data
254  reco::TrackRef recoTrack = LeadingMuon[0].track();
255 
256  etaTrack->Fill(recoTrack->eta());
257  phiTrack->Fill(recoTrack->phi());
258  chi2OvDFTrack->Fill(recoTrack->normalizedChi2());
259  ptTrack->Fill(recoTrack->pt());
260  }
261 
262  // Check if Muon is STA but NOT Global
263  if(LeadingMuon[0].isStandAloneMuon() && !(LeadingMuon[0].isGlobalMuon())) {
264  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is STA only - filling the histos";
265  if(!(LeadingMuon[0].isTrackerMuon())) muReco->Fill(5);
266 
267  // get the track using only the mu spectrometer data
268  reco::TrackRef recoStaTrack = LeadingMuon[0].standAloneMuon();
269 
270  etaStaTrack->Fill(recoStaTrack->eta());
271  phiStaTrack->Fill(recoStaTrack->phi());
272  chi2OvDFStaTrack->Fill(recoStaTrack->normalizedChi2());
273  ptStaTrack->Fill(recoStaTrack->pt());
274  }
275  // Check if Muon is Only CaloMuon
276  if(LeadingMuon[0].isCaloMuon() && !(LeadingMuon[0].isGlobalMuon()) && !(LeadingMuon[0].isTrackerMuon()) && !(LeadingMuon[0].isStandAloneMuon()))
277  muReco->Fill(6);
278 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:208
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
const std::string metname
void cd(void)
Definition: DQMStore.cc:266
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void analyze(const edm::Event &, const edm::EventSetup &)
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
Strings::size_type size() const
Definition: TriggerNames.cc:39
int iEvent
Definition: GenABIO.cc:230
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
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
~MuonRecoOneHLT()
Destructor.
#define LogTrace(id)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MuonRecoOneHLT(const edm::ParameterSet &)
Constructor.
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
tuple muons
Definition: patZpeak.py:38
static int position[264][3]
Definition: ReadPGInfo.cc:509
tuple cout
Definition: gather_cfg.py:121
const Point & position() const
position
Definition: BeamSpot.h:62
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Definition: Run.h:41