1 |
#include "UserCode/L1RpcTriggerAnalysis/interface/BestMuonFinder.h"
|
2 |
|
3 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
4 |
#include "FWCore/Framework/interface/Event.h"
|
5 |
#include "FWCore/Framework/interface/EventSetup.h"
|
6 |
#include "FWCore/Framework/interface/ESHandle.h"
|
7 |
#include "DataFormats/Common/interface/Handle.h"
|
8 |
|
9 |
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
|
10 |
#include "DataFormats/MuonReco/interface/Muon.h"
|
11 |
#include "DataFormats/MuonReco/interface/MuonFwd.h"
|
12 |
#include "DataFormats/TrackReco/interface/TrackFwd.h"
|
13 |
#include "DataFormats/TrackReco/interface/Track.h"
|
14 |
|
15 |
#include "UserCode/L1RpcTriggerAnalysis/interface/Utilities.h"
|
16 |
#include "DataFormats/Math/interface/deltaR.h"
|
17 |
#include "DataFormats/Math/interface/deltaPhi.h"
|
18 |
#include "TObjArray.h"
|
19 |
#include "TH1D.h"
|
20 |
#include "TH2D.h"
|
21 |
|
22 |
//TH2D* hMuHitsCSCvsEta;
|
23 |
|
24 |
BestMuonFinder::BestMuonFinder(const edm::ParameterSet& cfg)
|
25 |
: lastEvent(0), lastRun(0), theConfig(cfg), theUnique(true), theAllMuons(0), theMuon(0),
|
26 |
theTrackerHits(0), theRPCHits(0), theDTHits(0), theCSCHits(0),
|
27 |
hMuChi2Tk(0), hMuChi2Gl(0), hMuNHitsTk(0),
|
28 |
hMuPtVsEta(0), hMuHitsRPCvsCSC(0), hMuHitsRPCvsDT(0),
|
29 |
hMuonPt_BMF(0),hMuonEta_BMF (0),hMuonPhi_BMF(0)
|
30 |
{}
|
31 |
|
32 |
bool BestMuonFinder::run(const edm::Event &ev, const edm::EventSetup &es)
|
33 |
{
|
34 |
|
35 |
if (lastEvent==ev.id().event() && lastRun==ev.run()) return false;
|
36 |
lastEvent = ev.id().event() ;
|
37 |
lastRun = ev.run();
|
38 |
theMuon = 0;
|
39 |
theUnique = true;
|
40 |
|
41 |
|
42 |
//getBeamSpot
|
43 |
math::XYZPoint reference(0.,0.,0.);
|
44 |
edm::InputTag beamSpot = theConfig.getParameter<edm::InputTag>("beamSpot");
|
45 |
edm::Handle<reco::BeamSpot> bsHandle;
|
46 |
ev.getByLabel( beamSpot, bsHandle);
|
47 |
if (bsHandle.isValid()) reference = math::XYZPoint(bsHandle->x0(), bsHandle->y0(), bsHandle->z0());
|
48 |
|
49 |
//get Muon
|
50 |
edm::Handle<reco::MuonCollection> muons;
|
51 |
static std::string muonCollName = theConfig.getParameter<std::string>("muonColl");
|
52 |
static bool warnNoColl = theConfig.getUntrackedParameter<bool>("warnNoColl", true);
|
53 |
ev.getByLabel( muonCollName, muons);
|
54 |
if (!muons.isValid()) {
|
55 |
if (warnNoColl) std::cout <<"** WARNING - no collection labeled: "<<muonCollName<<std::endl;
|
56 |
return false;
|
57 |
}
|
58 |
theAllMuons = muons->size();
|
59 |
|
60 |
for (reco::MuonCollection::const_iterator im = muons->begin(); im != muons->end(); ++im) {
|
61 |
|
62 |
/*
|
63 |
if (ev.id().event() == 352597514) {
|
64 |
std::cout << "HERE Muon: matched stations:"<<im->numberOfMatchedStations() <<std::endl;
|
65 |
if (im->isGlobalMuon()) {
|
66 |
std::cout <<" GlobalMuon: "
|
67 |
<<" pt="<<im->combinedMuon()->pt()
|
68 |
<<" eta="<<im->combinedMuon()->eta()
|
69 |
<<" phi="<<im->combinedMuon()->phi()
|
70 |
<<" chi2: "<<im->combinedMuon()->normalizedChi2()<<std::endl;
|
71 |
}
|
72 |
if (im->isTrackerMuon() && im->innerTrack().isNonnull()) {
|
73 |
std::cout <<" TrackerMuon: "
|
74 |
<<" pt="<<im->innerTrack()->pt()
|
75 |
<<" eta="<<im->innerTrack()->eta()
|
76 |
<<" phi="<<im->innerTrack()->phi()
|
77 |
<< std::endl;
|
78 |
}
|
79 |
if (im->isStandAloneMuon()) std::cout <<" StandaloneMuon"<<std::endl;
|
80 |
}
|
81 |
*/
|
82 |
if (im->bestTrack()->eta() > theConfig.getParameter<double>("maxEta")) continue;
|
83 |
if (im->bestTrack()->pt() < theConfig.getParameter<double>("minPt")) continue;
|
84 |
if (im->numberOfMatchedStations() < theConfig.getParameter<int>("minNumberOfMatchedStations")) continue;
|
85 |
|
86 |
if ( theConfig.getParameter<bool>("requireInnerTrack")) {
|
87 |
if (!im->isTrackerMuon() || !im->innerTrack().isNonnull()) continue;
|
88 |
if (im->innerTrack()->dxy(reference) > theConfig.getParameter<double>("maxTIP")) continue;
|
89 |
if (im->innerTrack()->normalizedChi2() > theConfig.getParameter<double>("maxChi2Tk")) continue;
|
90 |
if (hMuonPt_BMF) hMuonPt_BMF->Fill( im->innerTrack()->pt());
|
91 |
if (hMuonEta_BMF) hMuonEta_BMF->Fill( im->innerTrack()->eta());
|
92 |
if (hMuonPhi_BMF) hMuonPhi_BMF->Fill( im->innerTrack()->phi());
|
93 |
if (hMuChi2Tk) hMuChi2Tk->Fill(im->innerTrack()->normalizedChi2());
|
94 |
if (hMuPtVsEta) hMuPtVsEta->Fill(im->innerTrack()->eta(), im->innerTrack()->pt());
|
95 |
}
|
96 |
if ( theConfig.getParameter<bool>("requireOuterTrack")){
|
97 |
if(!im->isStandAloneMuon() || !im->outerTrack().isNonnull())continue;
|
98 |
if(im->standAloneMuon()->normalizedChi2() > theConfig.getParameter<double>("maxChi2Sa")) continue;
|
99 |
}
|
100 |
if ( theConfig.getParameter<bool>("requireGlobalTrack")) {
|
101 |
if(!im->isGlobalMuon() || !im->globalTrack().isNonnull()) continue;
|
102 |
if(im->combinedMuon()->normalizedChi2() > theConfig.getParameter<double>("maxChi2Mu")) continue;
|
103 |
}
|
104 |
|
105 |
if (hMuChi2Gl && im->isGlobalMuon()) hMuChi2Gl->Fill(im->combinedMuon()->normalizedChi2());
|
106 |
|
107 |
//
|
108 |
// TMP TIGHT SELECTION FOR IVAN
|
109 |
// if (! im->isGlobalMuon()) continue;
|
110 |
// if (! (im->globalTrack()->normalizedChi2() < 10)) continue;
|
111 |
// if (! (im->globalTrack()->hitPattern().numberOfValidMuonHits() > 0)) continue;
|
112 |
// if (! (im->numberOfMatchedStations() > 1)) continue;
|
113 |
// if (! (fabs(im->innerTrack()->dxy(reference)) < 0.2)) continue;
|
114 |
// if (! (im->track()->hitPattern().numberOfValidPixelHits() > 0)) continue;
|
115 |
// if (! (im->track()->hitPattern().numberOfValidTrackerHits() > 10)) continue;
|
116 |
// TMP END OF TIGHT MUON SELECTION FROM IVAN
|
117 |
|
118 |
//remove muons without valid hits in tk and mu system
|
119 |
int nTrackerHits =0;
|
120 |
int nRPCHits =0;
|
121 |
int nDTHits =0;
|
122 |
int nCSCHits =0;
|
123 |
|
124 |
if (im->isGlobalMuon()) {
|
125 |
const reco::HitPattern& hp = (im->combinedMuon())->hitPattern();
|
126 |
nTrackerHits = hp.numberOfValidTrackerHits();
|
127 |
nRPCHits = hp.numberOfValidMuonRPCHits();
|
128 |
nDTHits = hp.numberOfValidMuonDTHits();
|
129 |
nCSCHits = hp.numberOfValidMuonCSCHits();
|
130 |
if (hMuNHitsTk) hMuNHitsTk->Fill(fabs(nTrackerHits)+1.e-3);
|
131 |
if (nDTHits==0 && hMuHitsRPCvsCSC) hMuHitsRPCvsCSC->Fill(nCSCHits,nRPCHits);
|
132 |
if (nCSCHits==0 && hMuHitsRPCvsDT) hMuHitsRPCvsDT->Fill(nDTHits,nRPCHits);
|
133 |
} else {
|
134 |
if(im->isTrackerMuon()) {
|
135 |
const reco::HitPattern& hp = (im->innerTrack())->hitPattern();
|
136 |
nTrackerHits = hp.numberOfValidTrackerHits();
|
137 |
}
|
138 |
if (im->isStandAloneMuon()) {
|
139 |
const reco::HitPattern& hp = (im->standAloneMuon())->hitPattern();
|
140 |
nRPCHits = hp.numberOfValidMuonRPCHits();
|
141 |
nDTHits = hp.numberOfValidMuonDTHits();
|
142 |
nCSCHits = hp.numberOfValidMuonCSCHits();
|
143 |
}
|
144 |
}
|
145 |
|
146 |
if (nTrackerHits< theConfig.getParameter<int>("minNumberTrackerHits")) continue;
|
147 |
if ( nRPCHits < theConfig.getParameter<int>("minNumberRpcHits")) continue;
|
148 |
if ( nDTHits + nCSCHits < theConfig.getParameter<int>("minNumberDtCscHits") ) continue;
|
149 |
|
150 |
if (!theMuon || (im->bestTrack()->pt() > theMuon->bestTrack()->pt()) ) {
|
151 |
theMuon = &(*im);
|
152 |
theTrackerHits = nTrackerHits;
|
153 |
theRPCHits = nRPCHits;
|
154 |
theDTHits = nDTHits;
|
155 |
theCSCHits = nCSCHits;
|
156 |
}
|
157 |
}
|
158 |
|
159 |
//
|
160 |
// check if muon is unigue
|
161 |
//
|
162 |
if (theMuon) {
|
163 |
double muonEta = theMuon->bestTrack()->eta();
|
164 |
double muonPhi = theMuon->bestTrack()->phi();
|
165 |
for (reco::MuonCollection::const_iterator im = muons->begin(); im != muons->end(); ++im) {
|
166 |
if (&(*im) == theMuon) continue;
|
167 |
if ( fabs(reco::deltaPhi(muonPhi, im->bestTrack()->phi())) > theConfig.getParameter<double>("deltaPhiUnique")) continue;
|
168 |
if ( fabs(muonEta-im->bestTrack()->eta()) > theConfig.getParameter<double>("deltaEtaUnique")) continue;
|
169 |
theUnique = false;
|
170 |
}
|
171 |
}
|
172 |
return true;
|
173 |
}
|
174 |
|
175 |
void BestMuonFinder::initHistos( TObjArray & histos)
|
176 |
{
|
177 |
hMuChi2Tk = new TH1D("hMuChi2Tk","hMuChi2Tk",100.,0.,10.); histos.Add(hMuChi2Tk);
|
178 |
hMuChi2Gl = new TH1D("hMuChi2Gl","hMuChi2Gl",100.,0.,10.); histos.Add(hMuChi2Gl);
|
179 |
hMuNHitsTk = new TH1D("hMuNHitsTk","hMuNHitsTk",30,0.,30.); histos.Add(hMuNHitsTk);
|
180 |
hMuPtVsEta = new TH2D("hMuPtVsEta","hMuPtVsEta", L1RpcEtaScale::nEtaBins, L1RpcEtaScale::etaBins, L1PtScale::nPtBins, L1PtScale::ptBins); histos.Add(hMuPtVsEta);
|
181 |
hMuHitsRPCvsCSC = new TH2D("hMuHitsRPCvsCSC","hMuHitsRPCvsCSC", 40,0.,40., 6,0.,6.); histos.Add(hMuHitsRPCvsCSC);
|
182 |
hMuHitsRPCvsDT = new TH2D("hMuHitsRPCvsDT","hMuHitsRPCvsDT", 30,0.,60., 6,0.,6.); histos.Add(hMuHitsRPCvsDT);
|
183 |
// hMuHitsCSCvsEta = new TH2D("hMuHitsCSCvsEta","hMuHitsCSCvsEta",17, 0.8,2.5, 40,0.,40); histos.Add(hMuHitsCSCvsEta);
|
184 |
hMuonPt_BMF = new TH1D("hMuonPt_BMF","All global muons Pt;Glb.muon p_{T} [GeV];Muons / bin",L1PtScale::nPtBins,L1PtScale::ptBins); histos.Add(hMuonPt_BMF);
|
185 |
hMuonEta_BMF = new TH1D("hMuonEta_BMF","All global muons Eta;Glb.muon #eta;Muons / bin",84, -2.1, 2.1); histos.Add(hMuonEta_BMF);
|
186 |
hMuonPhi_BMF = new TH1D("hMuonPhi_BMF","All global muons Phi;Glb.muon #phi [rad];Muons / bin",90,-M_PI,M_PI); histos.Add(hMuonPhi_BMF);
|
187 |
|
188 |
}
|