45 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Initializing configuration from parameterset.\n";
47 theGenLabel_ = consumes<GenParticleCollection>(pSet.
getParameter<
InputTag>(
"inputTagGenParticles"));
52 theHighPtTh = pSet.
getParameter<
double>(
"highPtThreshold");
53 theRecoGenR = pSet.
getParameter<
double>(
"recoGenDeltaR");
59 theMuonKinds.push_back(
"");
60 theMuonKinds.push_back(
"Tight");
61 theMuonKinds.push_back(
"TightIso");
71 "[MuonPFAnalyzer] Destructor called.\n";
82 "[MuonPFAnalyzer] Booking histograms.\n";
111 event.getByToken(theRecoLabel_, muons);
114 event.getByToken(theGenLabel_, genMuons);
117 event.getByToken(theBeamSpotLabel_, beamSpot);
120 event.getByToken(theVertexLabel_, vertex);
122 const Vertex primaryVertex = getPrimaryVertex(vertex, beamSpot);
124 recoToGenMatch(muons, genMuons);
126 RecoGenCollection::const_iterator recoGenIt = theRecoGen.begin();
127 RecoGenCollection::const_iterator recoGenEnd = theRecoGen.end();
129 for (;recoGenIt!=recoGenEnd;++recoGenIt)
132 const Muon *
muon = recoGenIt->first;
137 vector<string>::const_iterator kindIt = theMuonKinds.
begin();
138 vector<string>::const_iterator kindEnd = theMuonKinds.end();
140 for (;kindIt!=kindEnd;++kindIt)
143 const string & kind = (*kindIt);
145 if (kind.find(
"Tight") != string::npos &&
148 if (kind.find(
"Iso") != string::npos &&
149 combRelIso(muon) > theIsoCut)
continue;
157 string group =
"TUNEP" + kind;
159 float pt = tunePTrack->pt();
160 float phi = tunePTrack->phi();
161 float eta = tunePTrack->eta();
163 float genPt = genMuon->
pt();
164 float genPhi = genMuon->
p4().phi();
165 float genEta = genMuon->
p4().eta();
167 float dPtOverPt = (pt / genPt) - 1;
169 if (pt < theHighPtTh)
172 fillInRange(getPlot(group,
"code"),1,muonTrackType(muon,
false));
173 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
177 fillInRange(getPlot(group,
"codeHighPt"),1,muonTrackType(muon,
false));
178 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
181 fillInRange(getPlot(group,
"deltaPt"),1,(pt - genPt));
182 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(genPhi,phi));
183 fillInRange(getPlot(group,
"deltaEta"),1,genEta - eta);
190 string group =
"PF" + kind;
193 float pt = muon->
pt();
194 float phi = muon->
p4().phi();
195 float eta = muon->
p4().eta();
197 float genPt = genMuon->
pt();
198 float genPhi = genMuon->
p4().phi();
199 float genEta = genMuon->
p4().eta();
201 float dPtOverPt = (pt / genPt) - 1;
203 if (pt < theHighPtTh)
205 fillInRange(getPlot(group,
"code"),1,muonTrackType(muon,
true));
206 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
210 fillInRange(getPlot(group,
"codeHighPt"),1,muonTrackType(muon,
true));
211 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
215 fillInRange(getPlot(group,
"deltaPt"),1,pt - genPt);
216 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(genPhi,phi));
217 fillInRange(getPlot(group,
"deltaEta"),1,genEta - eta);
229 string group =
"PFvsTUNEP" + kind;
231 float pt = tunePTrack->pt();
232 float phi = tunePTrack->phi();
233 float eta = tunePTrack->eta();
236 float pfPt = muon->
pt();
237 float pfPhi = muon->
p4().phi();
238 float pfEta = muon->
p4().eta();
239 float dPtOverPt = (pfPt /
pt) - 1;
242 if (pt < theHighPtTh)
245 muonTrackType(muon,
false),muonTrackType(muon,
true));
246 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
251 2,muonTrackType(muon,
false),muonTrackType(muon,
true));
252 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
256 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(pfPhi,phi));
257 fillInRange(getPlot(group,
"deltaEta"),1,pfEta - eta);
260 if (theRunOnMC && genMuon)
264 float genPt = genMuon->
pt();
265 float dPtOverPtGen = (pt / genPt) - 1;
266 float dPtOverPtGenPF = (pfPt / genPt) - 1;
268 if (pt < theHighPtTh)
270 fillInRange(getPlot(group,
"deltaPtOverPtPFvsTUNEP"),
271 2,dPtOverPtGen,dPtOverPtGenPF);
275 fillInRange(getPlot(group,
"deltaPtOverPtHighPtPFvsTUNEP"),
276 2,dPtOverPtGen,dPtOverPtGenPF);
295 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Booking histos for group :"
298 theDbe->setCurrentFolder(
string(theFolder) + group);
301 bool isPFvsTUNEP = group.find(
"PFvsTUNEP") != string::npos;
306 hName =
"deltaPtOverPt" + group;
307 thePlots[group][
"deltaPtOverPt"] = theDbe->book1D(hName.c_str(),hName.c_str(),101,-1.01,1.01);
309 hName =
"deltaPtOverPtHighPt" + group;
310 thePlots[group][
"deltaPtOverPtHighPt"] = theDbe->book1D(hName.c_str(),hName.c_str(),101,-1.01,1.01);
312 hName =
"deltaPt" + group;
313 thePlots[group][
"deltaPt"] = theDbe->book1D(hName.c_str(),hName.c_str(),201.,-10.25,10.25);
315 hName =
"deltaPhi"+group;
316 thePlots[group][
"deltaPhi"] = theDbe->book1D(hName.c_str(),hName.c_str(),51.,0,.0102);
318 hName =
"deltaEta"+group;
319 thePlots[group][
"deltaEta"] = theDbe->book1D(hName.c_str(),hName.c_str(),101.,-.00505,.00505);
326 hName =
"code"+group;
327 MonitorElement *
plot = theDbe->book2D(hName.c_str(),hName.c_str(),7,-.5,6.5,7,-.5,6.5);
328 thePlots[group][
"code"] =
plot;
329 setCodeLabels(plot,1);
330 setCodeLabels(plot,2);
332 hName =
"codeHighPt"+group;
333 plot = theDbe->book2D(hName.c_str(),hName.c_str(),7,-.5,6.5,7,-.5,6.5);
334 thePlots[group][
"codeHighPt"] =
plot;
335 setCodeLabels(plot,1);
336 setCodeLabels(plot,2);
341 hName =
"deltaPtOverPtPFvsTUNEP" + group;
342 thePlots[group][
"deltaPtOverPtPFvsTUNEP"] =
343 theDbe->book2D(hName.c_str(),hName.c_str(),
344 101,-1.01,1.01,101,-1.01,1.01);
346 hName =
"deltaPtOverPtHighPtPFvsTUNEP" + group;
347 thePlots[group][
"deltaPtOverPtHighPtPFvsTUNEP"] =
348 theDbe->book2D(hName.c_str(),hName.c_str(),
349 101,-1.01,1.01,101,-1.01,1.01);
352 hName =
"code"+group;
354 thePlots[group][
"code"] =
plot;
355 setCodeLabels(plot,1);
357 hName =
"codeHighPt"+group;
358 plot = theDbe->book1D(hName.c_str(),hName.c_str(),7,-.5,6.5);
359 thePlots[group][
"codeHighPt"] =
plot;
360 setCodeLabels(plot,1);
367 const string &
type) {
369 map<string,map<string,MonitorElement *> >::iterator groupIt = thePlots.find(group);
370 if (groupIt == thePlots.end()) {
371 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] GROUP : " << group
372 <<
" is not a valid plot group. Returning 0.\n";
376 map<string,MonitorElement *>::iterator typeIt = groupIt->second.find(type);
377 if (typeIt == groupIt->second.end()) {
378 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] TYPE : " << type
379 <<
" is not a valid type for GROUP : " << group
380 <<
". Returning 0.\n";
384 return typeIt->second;
402 float fPhiDiff = fabs(acos(
cos(phi1-phi2)));
417 axis =histo->GetXaxis();
419 axis =histo->GetYaxis();
423 axis->SetBinLabel(1,
"Inner Track");
424 axis->SetBinLabel(2,
"Outer Track");
425 axis->SetBinLabel(3,
"Combined");
426 axis->SetBinLabel(4,
"TPFMS");
427 axis->SetBinLabel(5,
"Picky");
428 axis->SetBinLabel(6,
"DYT");
429 axis->SetBinLabel(7,
"None");
439 TAxis *axis[2] = {0, 0};
440 axis[0] = histo->GetXaxis();
442 axis[1] = histo->GetYaxis();
444 double value[2] = {0, 0};
448 for (
int i = 0;
i<nAxis;++
i)
450 double min = axis[
i]->GetXmin();
451 double max = axis[
i]->GetXmax();
454 value[
i] = axis[
i]->GetBinCenter(1);
457 value[
i] = axis[
i]->GetBinCenter(axis[
i]->GetNbins());
461 plot->
Fill(value[0],value[1]);
463 plot->
Fill(value[0]);
471 case Muon::InnerTrack :
473 case Muon::OuterTrack :
475 case Muon::CombinedTrack :
501 MuonCollection::const_iterator muonIt = muons->begin();
502 MuonCollection::const_iterator muonEnd = muons->end();
504 for(; muonIt!=muonEnd; ++muonIt)
510 if (theRunOnMC && gens.
isValid())
513 GenParticleCollection::const_iterator genIt = gens->begin();
514 GenParticleCollection::const_iterator genEnd = gens->end();
516 for(; genIt!=genEnd; ++genIt)
519 if (
abs(genIt->pdgId()) == 13 )
525 float genPhi = genIt->phi();
526 float genEta = genIt->eta();
531 if (dR < theRecoGenR && dR < bestDR)
542 theRecoGen.push_back(
RecoGenPair(&(*muonIt), bestGen));
556 bool hasPrimaryVertex =
false;
561 vector<Vertex>::const_iterator vertexIt = vertex->begin();
562 vector<Vertex>::const_iterator vertexEnd = vertex->end();
564 for (;vertexIt!=vertexEnd;++vertexIt)
566 if (vertexIt->isValid() &&
569 posVtx = vertexIt->position();
570 errVtx = vertexIt->error();
571 hasPrimaryVertex =
true;
577 if ( !hasPrimaryVertex ) {
580 "[MuonPFAnalyzer] PrimaryVertex not found, use BeamSpot position instead.\n";
582 posVtx = beamSpot->position();
583 errVtx(0,0) = beamSpot->BeamWidthX();
584 errVtx(1,1) = beamSpot->BeamWidthY();
585 errVtx(2,2) = beamSpot->sigmaZ();
589 const Vertex primaryVertex(posVtx,errVtx);
591 return primaryVertex;
int muonTrackType(const reco::Muon *muon, bool usePF)
T getParameter(std::string const &) const
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
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
virtual TrackRef innerTrack() const
math::Error< dimension >::type Error
covariance error matrix (3x3)
DEFINE_FWK_MODULE(HiMixingModule)
void setCodeLabels(MonitorElement *plot, int nAxis)
MonitorElement * getPlot(const std::string &group, const std::string &type)
bool isNull() const
Checks for null.
virtual void analyze(const edm::Event &, const edm::EventSetup &)
Perform the PF - TUNEP muon analysis.
void fillInRange(MonitorElement *plot, int nAxis, double x, double y=0)
virtual const_iterator begin() const
first daughter const_iterator
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
EventID const & min(EventID const &lh, EventID const &rh)
void bookHistos(const std::string &group)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
double deltaR(double eta1, double eta2, double phi1, double phi2)
float fDeltaPhi(float phi1, float phi2)
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
Initialize an book plots.
virtual MuonTrackType tunePMuonBestTrackType() const
void recoToGenMatch(edm::Handle< reco::MuonCollection > &reco, edm::Handle< reco::GenParticleCollection > &gen)
std::pair< const reco::Muon *, const reco::GenParticle * > RecoGenPair
virtual TrackRef tunePMuonBestTrack() const
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
virtual float pt() const GCC11_FINAL
transverse momentum
MuonPFAnalyzer(const edm::ParameterSet &)
Constructor.
const MuonIsolation & isolationR03() const
EventID const & max(EventID const &lh, EventID const &rh)