44 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Initializing configuration from parameterset.\n";
46 theGenLabel_ = consumes<GenParticleCollection>(pSet.
getParameter<
InputTag>(
"inputTagGenParticles"));
51 theHighPtTh = pSet.
getParameter<
double>(
"highPtThreshold");
52 theRecoGenR = pSet.
getParameter<
double>(
"recoGenDeltaR");
58 theMuonKinds.push_back(
"");
59 theMuonKinds.push_back(
"Tight");
60 theMuonKinds.push_back(
"TightIso");
67 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Destructor called.\n";
97 event.getByToken(theRecoLabel_, muons);
100 event.getByToken(theGenLabel_, genMuons);
103 event.getByToken(theBeamSpotLabel_, beamSpot);
106 event.getByToken(theVertexLabel_, vertex);
110 recoToGenMatch(muons, genMuons);
112 RecoGenCollection::const_iterator recoGenIt = theRecoGen.begin();
113 RecoGenCollection::const_iterator recoGenEnd = theRecoGen.end();
115 for (;recoGenIt!=recoGenEnd;++recoGenIt)
118 const Muon *
muon = recoGenIt->first;
123 vector<string>::const_iterator kindIt = theMuonKinds.begin();
124 vector<string>::const_iterator kindEnd = theMuonKinds.end();
126 for (;kindIt!=kindEnd;++kindIt)
129 const string &
kind = (*kindIt);
131 if (kind.find(
"Tight") != string::npos &&
134 if (kind.find(
"Iso") != string::npos &&
135 combRelIso(muon) > theIsoCut)
continue;
145 float pt = tunePTrack->pt();
146 float phi = tunePTrack->phi();
147 float eta = tunePTrack->eta();
150 float genPhi = genMuon->
p4().phi();
151 float genEta = genMuon->
p4().eta();
153 float dPtOverPt = (pt /
genPt) - 1;
155 if (pt < theHighPtTh)
158 fillInRange(getPlot(group,
"code"),1,muonTrackType(muon,
false));
159 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
163 fillInRange(getPlot(group,
"codeHighPt"),1,muonTrackType(muon,
false));
164 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
167 fillInRange(getPlot(group,
"deltaPt"),1,(pt - genPt));
168 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(genPhi,phi));
169 fillInRange(getPlot(group,
"deltaEta"),1,genEta - eta);
179 float pt = muon->
pt();
180 float phi = muon->
p4().phi();
181 float eta = muon->
p4().eta();
184 float genPhi = genMuon->
p4().phi();
185 float genEta = genMuon->
p4().eta();
187 float dPtOverPt = (pt /
genPt) - 1;
189 if (pt < theHighPtTh)
191 fillInRange(getPlot(group,
"code"),1,muonTrackType(muon,
true));
192 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
196 fillInRange(getPlot(group,
"codeHighPt"),1,muonTrackType(muon,
true));
197 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
201 fillInRange(getPlot(group,
"deltaPt"),1,pt - genPt);
202 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(genPhi,phi));
203 fillInRange(getPlot(group,
"deltaEta"),1,genEta - eta);
217 float pt = tunePTrack->pt();
218 float phi = tunePTrack->phi();
219 float eta = tunePTrack->eta();
222 float pfPt = muon->
pt();
223 float pfPhi = muon->
p4().phi();
224 float pfEta = muon->
p4().eta();
225 float dPtOverPt = (pfPt /
pt) - 1;
228 if (pt < theHighPtTh)
231 muonTrackType(muon,
false),muonTrackType(muon,
true));
232 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
237 2,muonTrackType(muon,
false),muonTrackType(muon,
true));
238 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
242 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(pfPhi,phi));
243 fillInRange(getPlot(group,
"deltaEta"),1,pfEta - eta);
246 if (theRunOnMC && genMuon)
251 float dPtOverPtGen = (pt /
genPt) - 1;
252 float dPtOverPtGenPF = (pfPt /
genPt) - 1;
254 if (pt < theHighPtTh)
256 fillInRange(getPlot(group,
"deltaPtOverPtPFvsTUNEP"),
257 2,dPtOverPtGen,dPtOverPtGenPF);
261 fillInRange(getPlot(group,
"deltaPtOverPtHighPtPFvsTUNEP"),
262 2,dPtOverPtGen,dPtOverPtGenPF);
278 const string &
group) {
282 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Booking histos for group :" 288 bool isPFvsTUNEP = group.find(
"PFvsTUNEP") != string::npos;
293 hName =
"deltaPtOverPt" +
group;
294 thePlots[
group][
"deltaPtOverPt"] = ibooker.
book1D(hName.c_str(),hName.c_str(),101,-1.01,1.01);
296 hName =
"deltaPtOverPtHighPt" +
group;
297 thePlots[
group][
"deltaPtOverPtHighPt"] = ibooker.
book1D(hName.c_str(),hName.c_str(),101,-1.01,1.01);
299 hName =
"deltaPt" +
group;
300 thePlots[
group][
"deltaPt"] = ibooker.
book1D(hName.c_str(),hName.c_str(),201.,-10.25,10.25);
302 hName =
"deltaPhi"+
group;
303 thePlots[
group][
"deltaPhi"] = ibooker.
book1D(hName.c_str(),hName.c_str(),51.,0,.0102);
305 hName =
"deltaEta"+
group;
306 thePlots[
group][
"deltaEta"] = ibooker.
book1D(hName.c_str(),hName.c_str(),101.,-.00505,.00505);
313 hName =
"code"+
group;
316 setCodeLabels(plot,1);
317 setCodeLabels(plot,2);
319 hName =
"codeHighPt"+
group;
320 plot = ibooker.
book2D(hName.c_str(),hName.c_str(),7,-.5,6.5,7,-.5,6.5);
322 setCodeLabels(plot,1);
323 setCodeLabels(plot,2);
328 hName =
"deltaPtOverPtPFvsTUNEP" +
group;
329 thePlots[
group][
"deltaPtOverPtPFvsTUNEP"] =
330 ibooker.
book2D(hName.c_str(),hName.c_str(),
331 101,-1.01,1.01,101,-1.01,1.01);
333 hName =
"deltaPtOverPtHighPtPFvsTUNEP" +
group;
334 thePlots[
group][
"deltaPtOverPtHighPtPFvsTUNEP"] =
335 ibooker.
book2D(hName.c_str(),hName.c_str(),
336 101,-1.01,1.01,101,-1.01,1.01);
339 hName =
"code"+
group;
342 setCodeLabels(plot,1);
344 hName =
"codeHighPt"+
group;
345 plot = ibooker.
book1D(hName.c_str(),hName.c_str(),7,-.5,6.5);
347 setCodeLabels(plot,1);
354 const string &
type) {
356 map<string,map<string,MonitorElement *> >::iterator groupIt = thePlots.find(group);
357 if (groupIt == thePlots.end()) {
358 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] GROUP : " << group
359 <<
" is not a valid plot group. Returning 0.\n";
363 map<string,MonitorElement *>::iterator typeIt = groupIt->second.find(type);
364 if (typeIt == groupIt->second.end()) {
365 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] TYPE : " << type
366 <<
" is not a valid type for GROUP : " << group
367 <<
". Returning 0.\n";
371 return typeIt->second;
389 float fPhiDiff = fabs(acos(
cos(phi1-phi2)));
404 axis =histo->GetXaxis();
406 axis =histo->GetYaxis();
410 axis->SetBinLabel(1,
"Inner Track");
411 axis->SetBinLabel(2,
"Outer Track");
412 axis->SetBinLabel(3,
"Combined");
413 axis->SetBinLabel(4,
"TPFMS");
414 axis->SetBinLabel(5,
"Picky");
415 axis->SetBinLabel(6,
"DYT");
416 axis->SetBinLabel(7,
"None");
426 TAxis *axis[2] = {0, 0};
427 axis[0] = histo->GetXaxis();
429 axis[1] = histo->GetYaxis();
431 double value[2] = {0, 0};
435 for (
int i = 0;
i<nAxis;++
i)
437 double min = axis[
i]->GetXmin();
438 double max = axis[
i]->GetXmax();
441 value[
i] = axis[
i]->GetBinCenter(1);
444 value[
i] = axis[
i]->GetBinCenter(axis[
i]->GetNbins());
448 plot->
Fill(value[0],value[1]);
450 plot->
Fill(value[0]);
458 case Muon::InnerTrack :
460 case Muon::OuterTrack :
462 case Muon::CombinedTrack :
488 MuonCollection::const_iterator muonIt = muons->begin();
489 MuonCollection::const_iterator muonEnd = muons->end();
491 for(; muonIt!=muonEnd; ++muonIt)
497 if (theRunOnMC && gens.
isValid())
500 GenParticleCollection::const_iterator genIt = gens->begin();
501 GenParticleCollection::const_iterator genEnd = gens->end();
503 for(; genIt!=genEnd; ++genIt)
506 if (
abs(genIt->pdgId()) == 13 )
512 float genPhi = genIt->phi();
513 float genEta = genIt->eta();
518 if (dR < theRecoGenR && dR < bestDR)
529 theRecoGen.push_back(
RecoGenPair(&(*muonIt), bestGen));
543 bool hasPrimaryVertex =
false;
548 vector<Vertex>::const_iterator vertexIt = vertex->begin();
549 vector<Vertex>::const_iterator vertexEnd = vertex->end();
551 for (;vertexIt!=vertexEnd;++vertexIt)
553 if (vertexIt->isValid() &&
556 posVtx = vertexIt->position();
557 errVtx = vertexIt->error();
558 hasPrimaryVertex =
true;
564 if ( !hasPrimaryVertex ) {
567 "[MuonPFAnalyzer] PrimaryVertex not found, use BeamSpot position instead.\n";
572 errVtx(2,2) = beamSpot->
sigmaZ();
int muonTrackType(const reco::Muon *muon, bool usePF)
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
const reco::Vertex getPrimaryVertex(edm::Handle< reco::VertexCollection > &vertex, edm::Handle< reco::BeamSpot > &beamSpot)
~MuonPFAnalyzer()
Destructor.
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
#define DEFINE_FWK_MODULE(type)
math::Error< dimension >::type Error
covariance error matrix (3x3)
void bookHistos(DQMStore::IBooker &, const std::string &)
void setCodeLabels(MonitorElement *plot, int nAxis)
MonitorElement * getPlot(const std::string &group, const std::string &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)
MonitorElement * book1D(Args &&...args)
Abs< T >::type abs(const T &t)
math::XYZPoint Point
point in the space
double BeamWidthX() const
beam width X
EventID const & min(EventID const &lh, EventID const &rh)
bool isNull() const
Checks for null.
double deltaR(double eta1, double eta2, double phi1, double phi2)
float fDeltaPhi(float phi1, float phi2)
void setCurrentFolder(const std::string &fullpath)
MonitorElement * book2D(Args &&...args)
double sigmaZ() const
sigma z
double BeamWidthY() const
beam width Y
virtual MuonTrackType tunePMuonBestTrackType() const
void recoToGenMatch(edm::Handle< reco::MuonCollection > &reco, edm::Handle< reco::GenParticleCollection > &gen)
def fillInRange(schema, fillmin, fillmax, amodetag, startT, stopT)
std::pair< const reco::Muon *, const reco::GenParticle * > RecoGenPair
const Point & position() const
position
virtual TrackRef tunePMuonBestTrack() const
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
virtual const LorentzVector & p4() const final
four-momentum Lorentz vector
MuonPFAnalyzer(const edm::ParameterSet &)
Constructor.
const MuonIsolation & isolationR03() const
EventID const & max(EventID const &lh, EventID const &rh)