40 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Initializing configuration from parameterset.\n";
42 theGenLabel_ = consumes<GenParticleCollection>(pSet.
getParameter<
InputTag>(
"inputTagGenParticles"));
47 theHighPtTh = pSet.
getParameter<
double>(
"highPtThreshold");
48 theRecoGenR = pSet.
getParameter<
double>(
"recoGenDeltaR");
54 theMuonKinds.push_back(
"");
55 theMuonKinds.push_back(
"Tight");
56 theMuonKinds.push_back(
"TightIso");
79 event.getByToken(theRecoLabel_, muons);
82 event.getByToken(theGenLabel_, genMuons);
85 event.getByToken(theBeamSpotLabel_, beamSpot);
88 event.getByToken(theVertexLabel_, vertex);
92 recoToGenMatch(muons, genMuons);
94 RecoGenCollection::const_iterator recoGenIt = theRecoGen.begin();
95 RecoGenCollection::const_iterator recoGenEnd = theRecoGen.end();
97 for (; recoGenIt != recoGenEnd; ++recoGenIt) {
103 vector<string>::const_iterator kindIt = theMuonKinds.begin();
104 vector<string>::const_iterator kindEnd = theMuonKinds.end();
106 for (; kindIt != kindEnd; ++kindIt) {
107 const string &
kind = (*kindIt);
109 if (kind.find(
"Tight") != string::npos && !
muon::isTightMuon((*muon), primaryVertex))
112 if (kind.find(
"Iso") != string::npos && combRelIso(muon) > theIsoCut)
117 if (!tunePTrack.
isNull()) {
120 float pt = tunePTrack->pt();
121 float phi = tunePTrack->phi();
122 float eta = tunePTrack->eta();
125 float genPhi = genMuon->
p4().phi();
126 float genEta = genMuon->
p4().eta();
128 float dPtOverPt = (pt /
genPt) - 1;
130 if (pt < theHighPtTh) {
131 fillInRange(getPlot(group,
"code"), 1, muonTrackType(muon,
false));
132 fillInRange(getPlot(group,
"deltaPtOverPt"), 1, dPtOverPt);
134 fillInRange(getPlot(group,
"codeHighPt"), 1, muonTrackType(muon,
false));
135 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"), 1, dPtOverPt);
138 fillInRange(getPlot(group,
"deltaPt"), 1, (pt - genPt));
139 fillInRange(getPlot(group,
"deltaPhi"), 1, fDeltaPhi(genPhi, phi));
140 fillInRange(getPlot(group,
"deltaEta"), 1, genEta - eta);
147 float pt = muon->
pt();
148 float phi = muon->
p4().phi();
149 float eta = muon->
p4().eta();
152 float genPhi = genMuon->
p4().phi();
153 float genEta = genMuon->
p4().eta();
155 float dPtOverPt = (pt /
genPt) - 1;
157 if (pt < theHighPtTh) {
158 fillInRange(getPlot(group,
"code"), 1, muonTrackType(muon,
true));
159 fillInRange(getPlot(group,
"deltaPtOverPt"), 1, dPtOverPt);
161 fillInRange(getPlot(group,
"codeHighPt"), 1, muonTrackType(muon,
true));
162 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"), 1, dPtOverPt);
165 fillInRange(getPlot(group,
"deltaPt"), 1, pt - genPt);
166 fillInRange(getPlot(group,
"deltaPhi"), 1, fDeltaPhi(genPhi, phi));
167 fillInRange(getPlot(group,
"deltaEta"), 1, genEta - eta);
176 float pt = tunePTrack->pt();
177 float phi = tunePTrack->phi();
178 float eta = tunePTrack->eta();
181 float pfPt = muon->
pt();
182 float pfPhi = muon->
p4().phi();
183 float pfEta = muon->
p4().eta();
184 float dPtOverPt = (pfPt /
pt) - 1;
186 if (pt < theHighPtTh) {
187 fillInRange(getPlot(group,
"code"), 2, muonTrackType(muon,
false), muonTrackType(muon,
true));
188 fillInRange(getPlot(group,
"deltaPtOverPt"), 1, dPtOverPt);
190 fillInRange(getPlot(group,
"codeHighPt"), 2, muonTrackType(muon,
false), muonTrackType(muon,
true));
191 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"), 1, dPtOverPt);
194 fillInRange(getPlot(group,
"deltaPt"), 1, pfPt - pt);
195 fillInRange(getPlot(group,
"deltaPhi"), 1, fDeltaPhi(pfPhi, phi));
196 fillInRange(getPlot(group,
"deltaEta"), 1, pfEta - eta);
198 if (theRunOnMC && genMuon)
202 float dPtOverPtGen = (pt /
genPt) - 1;
203 float dPtOverPtGenPF = (pfPt /
genPt) - 1;
205 if (pt < theHighPtTh) {
206 fillInRange(getPlot(group,
"deltaPtOverPtPFvsTUNEP"), 2, dPtOverPtGen, dPtOverPtGenPF);
208 fillInRange(getPlot(group,
"deltaPtOverPtHighPtPFvsTUNEP"), 2, dPtOverPtGen, dPtOverPtGenPF);
217 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Booking histos for group :" << group <<
"\n";
221 bool isPFvsTUNEP = group.find(
"PFvsTUNEP") != string::npos;
225 hName =
"deltaPtOverPt" +
group;
226 thePlots[
group][
"deltaPtOverPt"] = ibooker.
book1D(hName.c_str(), hName.c_str(), 101, -1.01, 1.01);
228 hName =
"deltaPtOverPtHighPt" +
group;
229 thePlots[
group][
"deltaPtOverPtHighPt"] = ibooker.
book1D(hName.c_str(), hName.c_str(), 101, -1.01, 1.01);
231 hName =
"deltaPt" +
group;
232 thePlots[
group][
"deltaPt"] = ibooker.
book1D(hName.c_str(), hName.c_str(), 201., -10.25, 10.25);
234 hName =
"deltaPhi" +
group;
235 thePlots[
group][
"deltaPhi"] = ibooker.
book1D(hName.c_str(), hName.c_str(), 51., 0, .0102);
237 hName =
"deltaEta" +
group;
238 thePlots[
group][
"deltaEta"] = ibooker.
book1D(hName.c_str(), hName.c_str(), 101., -.00505, .00505);
241 hName =
"code" +
group;
244 setCodeLabels(plot, 1);
245 setCodeLabels(plot, 2);
247 hName =
"codeHighPt" +
group;
248 plot = ibooker.
book2D(hName.c_str(), hName.c_str(), 7, -.5, 6.5, 7, -.5, 6.5);
250 setCodeLabels(plot, 1);
251 setCodeLabels(plot, 2);
254 hName =
"deltaPtOverPtPFvsTUNEP" +
group;
255 thePlots[
group][
"deltaPtOverPtPFvsTUNEP"] =
256 ibooker.
book2D(hName.c_str(), hName.c_str(), 101, -1.01, 1.01, 101, -1.01, 1.01);
258 hName =
"deltaPtOverPtHighPtPFvsTUNEP" +
group;
259 thePlots[
group][
"deltaPtOverPtHighPtPFvsTUNEP"] =
260 ibooker.
book2D(hName.c_str(), hName.c_str(), 101, -1.01, 1.01, 101, -1.01, 1.01);
263 hName =
"code" +
group;
266 setCodeLabels(plot, 1);
268 hName =
"codeHighPt" +
group;
269 plot = ibooker.
book1D(hName.c_str(), hName.c_str(), 7, -.5, 6.5);
271 setCodeLabels(plot, 1);
276 map<string, map<string, MonitorElement *> >::iterator groupIt = thePlots.find(group);
277 if (groupIt == thePlots.end()) {
278 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] GROUP : " << group <<
" is not a valid plot group. Returning 0.\n";
282 map<string, MonitorElement *>::iterator typeIt = groupIt->second.find(type);
283 if (typeIt == groupIt->second.end()) {
284 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] TYPE : " << type <<
" is not a valid type for GROUP : " << group
285 <<
". Returning 0.\n";
289 return typeIt->second;
300 float fPhiDiff = fabs(acos(
cos(phi1 - phi2)));
305 TAxis *axis =
nullptr;
312 axis = histo->GetXaxis();
314 axis = histo->GetYaxis();
319 axis->SetBinLabel(1,
"Inner Track");
320 axis->SetBinLabel(2,
"Outer Track");
321 axis->SetBinLabel(3,
"Combined");
322 axis->SetBinLabel(4,
"TPFMS");
323 axis->SetBinLabel(5,
"Picky");
324 axis->SetBinLabel(6,
"DYT");
325 axis->SetBinLabel(7,
"None");
331 TAxis *axis[2] = {
nullptr,
nullptr};
332 axis[0] = histo->GetXaxis();
334 axis[1] = histo->GetYaxis();
336 double value[2] = {0, 0};
340 for (
int i = 0;
i < nAxis; ++
i) {
341 double min = axis[
i]->GetXmin();
342 double max = axis[
i]->GetXmax();
345 value[
i] = axis[
i]->GetBinCenter(1);
348 value[
i] = axis[
i]->GetBinCenter(axis[
i]->GetNbins());
352 plot->
Fill(value[0], value[1]);
354 plot->
Fill(value[0]);
359 case Muon::InnerTrack:
361 case Muon::OuterTrack:
363 case Muon::CombinedTrack:
382 MuonCollection::const_iterator muonIt = muons->begin();
383 MuonCollection::const_iterator muonEnd = muons->end();
385 for (; muonIt != muonEnd; ++muonIt) {
389 if (theRunOnMC && gens.
isValid()) {
390 GenParticleCollection::const_iterator genIt = gens->begin();
391 GenParticleCollection::const_iterator genEnd = gens->end();
393 for (; genIt != genEnd; ++genIt) {
394 if (
abs(genIt->pdgId()) == 13) {
398 float genPhi = genIt->phi();
399 float genEta = genIt->eta();
401 float dR =
deltaR(muonEta, muonPhi, genEta, genPhi);
403 if (dR < theRecoGenR && dR < bestDR) {
411 theRecoGen.push_back(
RecoGenPair(&(*muonIt), bestGen));
420 bool hasPrimaryVertex =
false;
423 vector<Vertex>::const_iterator vertexIt = vertex->begin();
424 vector<Vertex>::const_iterator vertexEnd = vertex->end();
426 for (; vertexIt != vertexEnd; ++vertexIt) {
427 if (vertexIt->isValid() && !vertexIt->isFake()) {
428 posVtx = vertexIt->position();
429 errVtx = vertexIt->error();
430 hasPrimaryVertex =
true;
436 if (!hasPrimaryVertex) {
437 LogInfo(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] PrimaryVertex not found, use BeamSpot position instead.\n";
442 errVtx(2, 2) = beamSpot->
sigmaZ();
int muonTrackType(const reco::Muon *muon, bool usePF)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
T getParameter(std::string const &) const
~MuonPFAnalyzer() override
Destructor.
const reco::Vertex getPrimaryVertex(edm::Handle< reco::VertexCollection > &vertex, edm::Handle< reco::BeamSpot > &beamSpot)
float sumPt
sum-pt of tracks
virtual MuonTrackType muonBestTrackType() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
virtual TrackRef innerTrack() const
void setCurrentFolder(std::string const &fullpath)
math::Error< dimension >::type Error
covariance error matrix (3x3)
double pt() const final
transverse momentum
MonitorElement * getPlot(const std::string &group, const std::string &type)
void bookHistos(DQMStore::IBooker &, const std::string &)
void setCodeLabels(MonitorElement *plot, int nAxis)
#define DEFINE_FWK_MODULE(type)
void fillInRange(MonitorElement *plot, int nAxis, double x, double y=0)
void analyze(const edm::Event &, const edm::EventSetup &) override
float combRelIso(const reco::Muon *muon)
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
math::XYZPoint Point
point in the space
double BeamWidthX() const
beam width X
const LorentzVector & p4() const final
four-momentum Lorentz vector
EventID const & min(EventID const &lh, EventID const &rh)
bool isNull() const
Checks for null.
float fDeltaPhi(float phi1, float phi2)
double sigmaZ() const
sigma z
double BeamWidthY() const
beam width Y
virtual MuonTrackType tunePMuonBestTrackType() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
void recoToGenMatch(edm::Handle< reco::MuonCollection > &reco, edm::Handle< reco::GenParticleCollection > &gen)
const Point & position() const
position
virtual TrackRef tunePMuonBestTrack() const
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
std::pair< const reco::Muon *, const reco::GenParticle * > RecoGenPair
primaryVertex
hltOfflineBeamSpot for HLTMON
MuonPFAnalyzer(const edm::ParameterSet &)
Constructor.
const MuonIsolation & isolationR03() const
EventID const & max(EventID const &lh, EventID const &rh)