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 
7 
9 
13 
15 
16 
20 
21 
22 
23 #include <string>
24 #include "TMath.h"
25 using namespace std;
26 using namespace edm;
27 
28 // Uncomment to DEBUG
29 //#define DEBUG
30 
32  parameters = pSet;
33 
34  ParameterSet muonparms = parameters.getParameter<edm::ParameterSet>("SingleMuonTrigger");
35  ParameterSet dimuonparms = parameters.getParameter<edm::ParameterSet>("DoubleMuonTrigger");
37  _DoubleMuonEventFlag = new GenericTriggerEventFlag( dimuonparms );
38 
39  // Trigger Expresions in case de connection to the DB fails
40  singlemuonExpr_ = muonparms.getParameter<std::vector<std::string> >("hltPaths");
41  doublemuonExpr_ = dimuonparms.getParameter<std::vector<std::string> >("hltPaths");
42 }
43 
44 
46  delete _SingleMuonEventFlag;
47  delete _DoubleMuonEventFlag;
48 }
50 #ifdef DEBUG
51  cout << "[MuonRecoOneHLT] beginJob " << endl;
52 #endif
53  dbe->setCurrentFolder("Muons/MuonRecoOneHLT");
54 
58 
59 
60  muReco = dbe->book1D("Muon_Reco", "Muon Reconstructed Tracks", 6, 1, 7);
61  muReco->setBinLabel(1,"glb+tk+sta");
62  muReco->setBinLabel(2,"glb+sta");
63  muReco->setBinLabel(3,"tk+sta");
64  muReco->setBinLabel(4,"tk");
65  muReco->setBinLabel(5,"sta");
66  muReco->setBinLabel(6,"calo");
67 
68  // monitoring of eta parameter
69  etaBin = parameters.getParameter<int>("etaBin");
70  etaMin = parameters.getParameter<double>("etaMin");
71  etaMax = parameters.getParameter<double>("etaMax");
72 
73  std::string histname = "GlbMuon_";
74  etaGlbTrack.push_back(dbe->book1D(histname+"Glb_eta", "#eta_{GLB}", etaBin, etaMin, etaMax));
75  etaGlbTrack.push_back(dbe->book1D(histname+"Tk_eta", "#eta_{TKfromGLB}", etaBin, etaMin, etaMax));
76  etaGlbTrack.push_back(dbe->book1D(histname+"Sta_eta", "#eta_{STAfromGLB}", etaBin, etaMin, etaMax));
77  etaTight = dbe->book1D("TightMuon_eta", "#eta_{GLB}", etaBin, etaMin, etaMax);
78  etaTrack = dbe->book1D("TkMuon_eta", "#eta_{TK}", etaBin, etaMin, etaMax);
79  etaStaTrack = dbe->book1D("StaMuon_eta", "#eta_{STA}", etaBin, etaMin, etaMax);
80 
81  // monitoring of phi paramater
82  phiBin = parameters.getParameter<int>("phiBin");
83  phiMin = parameters.getParameter<double>("phiMin");
84  phiMax = parameters.getParameter<double>("phiMax");
85  phiGlbTrack.push_back(dbe->book1D(histname+"Glb_phi", "#phi_{GLB}", phiBin, phiMin, phiMax));
86  phiGlbTrack[0]->setAxisTitle("rad");
87  phiGlbTrack.push_back(dbe->book1D(histname+"Tk_phi", "#phi_{TKfromGLB}", phiBin, phiMin, phiMax));
88  phiGlbTrack[1]->setAxisTitle("rad");
89  phiGlbTrack.push_back(dbe->book1D(histname+"Sta_phi", "#phi_{STAfromGLB}", phiBin, phiMin, phiMax));
90  phiGlbTrack[2]->setAxisTitle("rad");
91  phiTight = dbe->book1D("TightMuon_phi", "#phi_{GLB}", phiBin, phiMin, phiMax);
92  phiTrack = dbe->book1D("TkMuon_phi", "#phi_{TK}", phiBin, phiMin, phiMax);
93  phiTrack->setAxisTitle("rad");
94  phiStaTrack = dbe->book1D("StaMuon_phi", "#phi_{STA}", phiBin, phiMin, phiMax);
95  phiStaTrack->setAxisTitle("rad");
96 
97  // monitoring of the chi2 parameter
98  chi2Bin = parameters.getParameter<int>("chi2Bin");
99  chi2Min = parameters.getParameter<double>("chi2Min");
100  chi2Max = parameters.getParameter<double>("chi2Max");
101  chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Glb_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max));
102  chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Tk_chi2OverDf", "#chi_{2}OverDF_{TKfromGLB}", phiBin, chi2Min, chi2Max));
103  chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Sta_chi2OverDf", "#chi_{2}OverDF_{STAfromGLB}", chi2Bin, chi2Min, chi2Max));
104  chi2OvDFTight = dbe->book1D("TightMuon_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max);
105  chi2OvDFTrack = dbe->book1D("TkMuon_chi2OverDf", "#chi_{2}OverDF_{TK}", chi2Bin, chi2Min, chi2Max);
106  chi2OvDFStaTrack = dbe->book1D("StaMuon_chi2OverDf", "#chi_{2}OverDF_{STA}", chi2Bin, chi2Min, chi2Max);
107 
108  // monitoring of the transverse momentum
109  ptBin = parameters.getParameter<int>("ptBin");
110  ptMin = parameters.getParameter<double>("ptMin");
111  ptMax = parameters.getParameter<double>("ptMax");
112  ptGlbTrack.push_back(dbe->book1D(histname+"Glb_pt", "pt_{GLB}", ptBin, ptMin, ptMax));
113  ptGlbTrack[0]->setAxisTitle("GeV");
114  ptGlbTrack.push_back(dbe->book1D(histname+"Tk_pt", "pt_{TKfromGLB}", ptBin, ptMin, ptMax));
115  ptGlbTrack[1]->setAxisTitle("GeV");
116  ptGlbTrack.push_back(dbe->book1D(histname+"Sta_pt", "pt_{STAfromGLB}", ptBin, ptMin, ptMax));
117  ptGlbTrack[2]->setAxisTitle("GeV");
118  ptTight = dbe->book1D("TightMuon_pt", "pt_{GLB}", ptBin, ptMin, ptMax);
119  ptTight->setAxisTitle("GeV");
120  ptTrack = dbe->book1D("TkMuon_pt", "pt_{TK}", ptBin, ptMin, ptMax);
121  ptTrack->setAxisTitle("GeV");
122  ptStaTrack = dbe->book1D("StaMuon_pt", "pt_{STA}", ptBin, ptMin, ptMax);
123  ptStaTrack->setAxisTitle("GeV");
124 }
125 
126 void MuonRecoOneHLT::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
127 #ifdef DEBUG
128  cout << "[MuonRecoOneHLT] beginRun " << endl;
129  cout << "[MuonRecoOneHLT] Is MuonEventFlag On? "<< _SignleMuonEventFlag->on() << endl;
130 #endif
131  if ( _SingleMuonEventFlag->on() ) _SingleMuonEventFlag->initRun( iRun, iSetup );
132  if ( _DoubleMuonEventFlag->on() ) _DoubleMuonEventFlag->initRun( iRun, iSetup );
133 
138 }
140  // const reco::Muon& recoMu,
142 #ifdef DEBUG
143  cout << "[MuonRecoOneHLT] analyze "<< endl;
144 #endif
145 
146 
147  // ==========================================================
148  // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
149 
150  reco::Vertex::Point posVtx;
151  reco::Vertex::Error errVtx;
152 
153  unsigned int theIndexOfThePrimaryVertex = 999.;
154 
156  iEvent.getByLabel(vertexTag, vertex);
157 
158  if ( vertex.isValid() ){
159  for (unsigned int ind=0; ind<vertex->size(); ++ind) {
160  if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
161  theIndexOfThePrimaryVertex = ind;
162  break;
163  }
164  }
165  }
166  if (theIndexOfThePrimaryVertex<100) {
167  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
168  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
169  } else {
170  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
171 
172  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
173  iEvent.getByLabel(bsTag,recoBeamSpotHandle);
174 
175  reco::BeamSpot bs = *recoBeamSpotHandle;
176 
177  posVtx = bs.position();
178  errVtx(0,0) = bs.BeamWidthX();
179  errVtx(1,1) = bs.BeamWidthY();
180  errVtx(2,2) = bs.sigmaZ();
181  }
182  const reco::Vertex thePrimaryVertex(posVtx,errVtx);
183 
184  // ==========================================================
185 
186 
187 
188 
189  // TEST FOR ONLY TAKE HIGHEST PT MUON
191  iEvent.getByLabel(theMuonCollectionLabel,muons);
192 
193 
194  std::map<float,reco::Muon> muonMap;
195  for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu!=muons->end(); ++recoMu){
196  muonMap[recoMu->pt()] = *recoMu;
197  }
198  std::vector<reco::Muon> LeadingMuon;
199  for( std::map<float,reco::Muon>::reverse_iterator rit=muonMap.rbegin(); rit!=muonMap.rend(); ++rit){
200  LeadingMuon.push_back( (*rit).second );
201  }
202 
204  Handle<reco::BeamSpot> beamSpotHandle;
205  iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
206  beamSpot = *beamSpotHandle;
207 
208  const edm::TriggerNames& triggerNames = iEvent.triggerNames(triggerResults);
209  const unsigned int nTrig(triggerNames.size());
210  bool _trig_SingleMu = false;
211  bool _trig_DoubleMu = false;
212  for (unsigned int i=0;i<nTrig;++i){
213  if (triggerNames.triggerName(i).find(singlemuonExpr_[0].substr(0,singlemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
214  _trig_SingleMu = true;
215  if (triggerNames.triggerName(i).find(doublemuonExpr_[0].substr(0,doublemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
216  _trig_DoubleMu = true;
217  }
218 #ifdef DEBUG
219  cout << "[MuonRecoOneHLT] Trigger Fired ? "<< _trig_SingleMu << endl;
220 #endif
221 
222  if (!_trig_SingleMu && !_trig_DoubleMu) return;
223  if (LeadingMuon.size() == 0) return;
224  // if (_MuonEventFlag->on() && !(_MuonEventFlag->accept(iEvent,iSetup))) return;
225 
226  // Check if Muon is Global
227  if(LeadingMuon[0].isGlobalMuon()) {
228  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is global - filling the histos";
229  if(LeadingMuon[0].isTrackerMuon() && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(1);
230  if(!(LeadingMuon[0].isTrackerMuon()) && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(2);
231  if(!LeadingMuon[0].isStandAloneMuon())
232  LogTrace(metname)<<"[MuonRecoOneHLT] ERROR: the mu is global but not standalone!";
233 
234  // get the track combinig the information from both the Tracker and the Spectrometer
235  reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
236  // get the track using only the tracker data
237  reco::TrackRef recoTkGlbTrack = LeadingMuon[0].track();
238  // get the track using only the mu spectrometer data
239  reco::TrackRef recoStaGlbTrack = LeadingMuon[0].standAloneMuon();
240 
241  etaGlbTrack[0]->Fill(recoCombinedGlbTrack->eta());
242  etaGlbTrack[1]->Fill(recoTkGlbTrack->eta());
243  etaGlbTrack[2]->Fill(recoStaGlbTrack->eta());
244 
245  phiGlbTrack[0]->Fill(recoCombinedGlbTrack->phi());
246  phiGlbTrack[1]->Fill(recoTkGlbTrack->phi());
247  phiGlbTrack[2]->Fill(recoStaGlbTrack->phi());
248 
249  chi2OvDFGlbTrack[0]->Fill(recoCombinedGlbTrack->normalizedChi2());
250  chi2OvDFGlbTrack[1]->Fill(recoTkGlbTrack->normalizedChi2());
251  chi2OvDFGlbTrack[2]->Fill(recoStaGlbTrack->normalizedChi2());
252 
253  ptGlbTrack[0]->Fill(recoCombinedGlbTrack->pt());
254  ptGlbTrack[1]->Fill(recoTkGlbTrack->pt());
255  ptGlbTrack[2]->Fill(recoStaGlbTrack->pt());
256  }
257  // Check if Muon is Tight
258  if (muon::isTightMuon(LeadingMuon[0], thePrimaryVertex) ) {
259 
260  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
261 
262  reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
263 
264  etaTight->Fill(recoCombinedGlbTrack->eta());
265  phiTight->Fill(recoCombinedGlbTrack->phi());
266  chi2OvDFTight->Fill(recoCombinedGlbTrack->normalizedChi2());
267  ptTight->Fill(recoCombinedGlbTrack->pt());
268  }
269 
270  // Check if Muon is Tracker but NOT Global
271  if(LeadingMuon[0].isTrackerMuon() && !(LeadingMuon[0].isGlobalMuon())) {
272  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
273  if(LeadingMuon[0].isStandAloneMuon()) muReco->Fill(3);
274  if(!(LeadingMuon[0].isStandAloneMuon())) muReco->Fill(4);
275 
276  // get the track using only the tracker data
277  reco::TrackRef recoTrack = LeadingMuon[0].track();
278 
279  etaTrack->Fill(recoTrack->eta());
280  phiTrack->Fill(recoTrack->phi());
281  chi2OvDFTrack->Fill(recoTrack->normalizedChi2());
282  ptTrack->Fill(recoTrack->pt());
283  }
284 
285  // Check if Muon is STA but NOT Global
286  if(LeadingMuon[0].isStandAloneMuon() && !(LeadingMuon[0].isGlobalMuon())) {
287  LogTrace(metname)<<"[MuonRecoOneHLT] The mu is STA only - filling the histos";
288  if(!(LeadingMuon[0].isTrackerMuon())) muReco->Fill(5);
289 
290  // get the track using only the mu spectrometer data
291  reco::TrackRef recoStaTrack = LeadingMuon[0].standAloneMuon();
292 
293  etaStaTrack->Fill(recoStaTrack->eta());
294  phiStaTrack->Fill(recoStaTrack->phi());
295  chi2OvDFStaTrack->Fill(recoStaTrack->normalizedChi2());
296  ptStaTrack->Fill(recoStaTrack->pt());
297  }
298  // Check if Muon is Only CaloMuon
299  if(LeadingMuon[0].isCaloMuon() && !(LeadingMuon[0].isGlobalMuon()) && !(LeadingMuon[0].isTrackerMuon()) && !(LeadingMuon[0].isStandAloneMuon()))
300  muReco->Fill(6);
301 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::ParameterSet parameters
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:207
void beginJob(DQMStore *dbe)
Inizialize parameters for histo binning.
MonitorElement * phiTight
MonitorElement * ptTrack
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
edm::InputTag vertexTag
GenericTriggerEventFlag * _DoubleMuonEventFlag
MonitorElement * chi2OvDFTrack
bool accept() const
Has at least one path accepted the event?
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
GenericTriggerEventFlag * _SingleMuonEventFlag
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
edm::InputTag bsTag
MonitorElement * etaTight
MonitorElement * etaStaTrack
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
std::string metname
std::vector< std::string > doublemuonExpr_
void Fill(long long x)
std::vector< std::string > expressionsFromDB(const std::string &key, const edm::EventSetup &setup)
Reads and returns logical expressions from DB.
int iEvent
Definition: GenABIO.cc:243
MonitorElement * chi2OvDFStaTrack
edm::InputTag theMuonCollectionLabel
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:87
std::vector< MonitorElement * > phiGlbTrack
MonitorElement * ptStaTrack
std::vector< std::string > singlemuonExpr_
std::vector< MonitorElement * > ptGlbTrack
bool isValid() const
Definition: HandleBase.h:76
MonitorElement * etaTrack
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual ~MuonRecoOneHLT()
Destructor.
#define LogTrace(id)
std::vector< MonitorElement * > etaGlbTrack
MonitorElement * phiTrack
MonitorElement * ptTight
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
double sigmaZ() const
sigma z
Definition: BeamSpot.h:81
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:89
tuple muons
Definition: patZpeak.py:38
MonitorElement * phiStaTrack
tuple cout
Definition: gather_cfg.py:121
const Point & position() const
position
Definition: BeamSpot.h:63
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
void analyze(const edm::Event &, const edm::EventSetup &, const edm::TriggerResults &)
Get the analysis.
MonitorElement * muReco
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup)
MuonRecoOneHLT(const edm::ParameterSet &, MuonServiceProxy *theService)
Constructor.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Definition: Run.h:36
MonitorElement * chi2OvDFTight
std::vector< MonitorElement * > chi2OvDFGlbTrack