50 "[MuonPFAnalyzer] Initializing configuration from parameterset.\n";
57 theHighPtTh = pSet.
getParameter<
double>(
"highPtThreshold");
58 theRecoGenR = pSet.
getParameter<
double>(
"recoGenDeltaR");
64 theMuonKinds.push_back(
"");
65 theMuonKinds.push_back(
"Tight");
66 theMuonKinds.push_back(
"TightIso");
76 "[MuonPFAnalyzer] Destructor called.\n";
87 "[MuonPFAnalyzer] Booking histograms.\n";
116 event.getByLabel(theRecoLabel, muons);
119 event.getByLabel(theGenLabel, genMuons);
122 event.getByLabel(theBeamSpotLabel, beamSpot);
125 event.getByLabel(theVertexLabel, vertex);
127 const Vertex primaryVertex = getPrimaryVertex(vertex, beamSpot);
129 recoToGenMatch(muons, genMuons);
131 RecoGenCollection::const_iterator recoGenIt = theRecoGen.begin();
132 RecoGenCollection::const_iterator recoGenEnd = theRecoGen.end();
134 for (;recoGenIt!=recoGenEnd;++recoGenIt)
137 const Muon *
muon = recoGenIt->first;
142 vector<string>::const_iterator kindIt = theMuonKinds.
begin();
143 vector<string>::const_iterator kindEnd = theMuonKinds.end();
145 for (;kindIt!=kindEnd;++kindIt)
148 const string & kind = (*kindIt);
150 if (kind.find(
"Tight") != string::npos &&
153 if (kind.find(
"Iso") != string::npos &&
154 combRelIso(muon) > theIsoCut)
continue;
162 string group =
"TUNEP" + kind;
164 float pt = tunePTrack->pt();
165 float phi = tunePTrack->phi();
166 float eta = tunePTrack->eta();
168 float genPt = genMuon->
pt();
169 float genPhi = genMuon->
p4().phi();
170 float genEta = genMuon->
p4().eta();
172 float dPtOverPt = (pt / genPt) - 1;
174 if (pt < theHighPtTh)
177 fillInRange(getPlot(group,
"code"),1,muonTrackType(muon,
false));
178 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
182 fillInRange(getPlot(group,
"codeHighPt"),1,muonTrackType(muon,
false));
183 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
186 fillInRange(getPlot(group,
"deltaPt"),1,(pt - genPt));
187 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(genPhi,phi));
188 fillInRange(getPlot(group,
"deltaEta"),1,genEta - eta);
195 string group =
"PF" + kind;
198 float pt = muon->
pt();
199 float phi = muon->
p4().phi();
200 float eta = muon->
p4().eta();
202 float genPt = genMuon->
pt();
203 float genPhi = genMuon->
p4().phi();
204 float genEta = genMuon->
p4().eta();
206 float dPtOverPt = (pt / genPt) - 1;
208 if (pt < theHighPtTh)
210 fillInRange(getPlot(group,
"code"),1,muonTrackType(muon,
true));
211 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
215 fillInRange(getPlot(group,
"codeHighPt"),1,muonTrackType(muon,
true));
216 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
220 fillInRange(getPlot(group,
"deltaPt"),1,pt - genPt);
221 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(genPhi,phi));
222 fillInRange(getPlot(group,
"deltaEta"),1,genEta - eta);
234 string group =
"PFvsTUNEP" + kind;
236 float pt = tunePTrack->pt();
237 float phi = tunePTrack->phi();
238 float eta = tunePTrack->eta();
241 float pfPt = muon->
pt();
242 float pfPhi = muon->
p4().phi();
243 float pfEta = muon->
p4().eta();
244 float dPtOverPt = (pfPt / pt) - 1;
247 if (pt < theHighPtTh)
250 muonTrackType(muon,
false),muonTrackType(muon,
true));
251 fillInRange(getPlot(group,
"deltaPtOverPt"),1,dPtOverPt);
256 2,muonTrackType(muon,
false),muonTrackType(muon,
true));
257 fillInRange(getPlot(group,
"deltaPtOverPtHighPt"),1,dPtOverPt);
261 fillInRange(getPlot(group,
"deltaPhi"),1,fDeltaPhi(pfPhi,phi));
262 fillInRange(getPlot(group,
"deltaEta"),1,pfEta - eta);
265 if (theRunOnMC && genMuon)
269 float genPt = genMuon->
pt();
270 float dPtOverPtGen = (pt / genPt) - 1;
271 float dPtOverPtGenPF = (pfPt / genPt) - 1;
273 if (pt < theHighPtTh)
275 fillInRange(getPlot(group,
"deltaPtOverPtPFvsTUNEP"),
276 2,dPtOverPtGen,dPtOverPtGenPF);
280 fillInRange(getPlot(group,
"deltaPtOverPtHighPtPFvsTUNEP"),
281 2,dPtOverPtGen,dPtOverPtGenPF);
300 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] Booking histos for group :"
303 theDbe->setCurrentFolder(
string(theFolder) + group);
306 bool isPFvsTUNEP = group.find(
"PFvsTUNEP") != string::npos;
311 hName =
"deltaPtOverPt" + group;
312 thePlots[group][
"deltaPtOverPt"] = theDbe->book1D(hName.c_str(),hName.c_str(),101,-1.01,1.01);
314 hName =
"deltaPtOverPtHighPt" + group;
315 thePlots[group][
"deltaPtOverPtHighPt"] = theDbe->book1D(hName.c_str(),hName.c_str(),101,-1.01,1.01);
317 hName =
"deltaPt" + group;
318 thePlots[group][
"deltaPt"] = theDbe->book1D(hName.c_str(),hName.c_str(),201.,-10.25,10.25);
320 hName =
"deltaPhi"+group;
321 thePlots[group][
"deltaPhi"] = theDbe->book1D(hName.c_str(),hName.c_str(),51.,0,.0102);
323 hName =
"deltaEta"+group;
324 thePlots[group][
"deltaEta"] = theDbe->book1D(hName.c_str(),hName.c_str(),101.,-.00505,.00505);
331 hName =
"code"+group;
332 MonitorElement *
plot = theDbe->book2D(hName.c_str(),hName.c_str(),7,-.5,6.5,7,-.5,6.5);
333 thePlots[group][
"code"] =
plot;
334 setCodeLabels(plot,1);
335 setCodeLabels(plot,2);
337 hName =
"codeHighPt"+group;
338 plot = theDbe->book2D(hName.c_str(),hName.c_str(),7,-.5,6.5,7,-.5,6.5);
339 thePlots[group][
"codeHighPt"] =
plot;
340 setCodeLabels(plot,1);
341 setCodeLabels(plot,2);
346 hName =
"deltaPtOverPtPFvsTUNEP" + group;
347 thePlots[group][
"deltaPtOverPtPFvsTUNEP"] =
348 theDbe->book2D(hName.c_str(),hName.c_str(),
349 101,-1.01,1.01,101,-1.01,1.01);
351 hName =
"deltaPtOverPtHighPtPFvsTUNEP" + group;
352 thePlots[group][
"deltaPtOverPtHighPtPFvsTUNEP"] =
353 theDbe->book2D(hName.c_str(),hName.c_str(),
354 101,-1.01,1.01,101,-1.01,1.01);
357 hName =
"code"+group;
359 thePlots[group][
"code"] =
plot;
360 setCodeLabels(plot,1);
362 hName =
"codeHighPt"+group;
363 plot = theDbe->book1D(hName.c_str(),hName.c_str(),7,-.5,6.5);
364 thePlots[group][
"codeHighPt"] =
plot;
365 setCodeLabels(plot,1);
372 const string &
type) {
374 map<string,map<string,MonitorElement *> >::iterator groupIt = thePlots.find(group);
375 if (groupIt == thePlots.end()) {
376 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] GROUP : " << group
377 <<
" is not a valid plot group. Returning 0.\n";
381 map<string,MonitorElement *>::iterator typeIt = groupIt->second.find(type);
382 if (typeIt == groupIt->second.end()) {
383 LogTrace(
"MuonPFAnalyzer") <<
"[MuonPFAnalyzer] TYPE : " << type
384 <<
" is not a valid type for GROUP : " << group
385 <<
". Returning 0.\n";
389 return typeIt->second;
407 float fPhiDiff = fabs(acos(
cos(phi1-phi2)));
422 axis =histo->GetXaxis();
424 axis =histo->GetYaxis();
428 axis->SetBinLabel(1,
"Inner Track");
429 axis->SetBinLabel(2,
"Outer Track");
430 axis->SetBinLabel(3,
"Combined");
431 axis->SetBinLabel(4,
"TPFMS");
432 axis->SetBinLabel(5,
"Picky");
433 axis->SetBinLabel(6,
"DYT");
434 axis->SetBinLabel(7,
"None");
444 TAxis *axis[2] = {0, 0};
445 axis[0] = histo->GetXaxis();
447 axis[1] = histo->GetYaxis();
449 double value[2] = {0, 0};
453 for (
int i = 0;
i<nAxis;++
i)
455 double min = axis[
i]->GetXmin();
456 double max = axis[
i]->GetXmax();
459 value[
i] = axis[
i]->GetBinCenter(1);
462 value[
i] = axis[
i]->GetBinCenter(axis[
i]->GetNbins());
466 plot->
Fill(value[0],value[1]);
468 plot->
Fill(value[0]);
476 case Muon::InnerTrack :
478 case Muon::OuterTrack :
480 case Muon::CombinedTrack :
506 MuonCollection::const_iterator muonIt = muons->begin();
507 MuonCollection::const_iterator muonEnd = muons->end();
509 for(; muonIt!=muonEnd; ++muonIt)
515 if (theRunOnMC && gens.
isValid())
518 GenParticleCollection::const_iterator genIt = gens->begin();
519 GenParticleCollection::const_iterator genEnd = gens->end();
521 for(; genIt!=genEnd; ++genIt)
524 if (
abs(genIt->pdgId()) == 13 )
527 float muonPhi = muonIt->phi();
528 float muonEta = muonIt->eta();
530 float genPhi = genIt->phi();
531 float genEta = genIt->eta();
536 if (dR < theRecoGenR && dR < bestDR)
547 theRecoGen.push_back(
RecoGenPair(&(*muonIt), bestGen));
561 bool hasPrimaryVertex =
false;
566 vector<Vertex>::const_iterator vertexIt = vertex->begin();
567 vector<Vertex>::const_iterator vertexEnd = vertex->end();
569 for (;vertexIt!=vertexEnd;++vertexIt)
571 if (vertexIt->isValid() &&
574 posVtx = vertexIt->position();
575 errVtx = vertexIt->error();
576 hasPrimaryVertex =
true;
582 if ( !hasPrimaryVertex ) {
585 "[MuonPFAnalyzer] PrimaryVertex not found, use BeamSpot position instead.\n";
587 posVtx = beamSpot->position();
588 errVtx(0,0) = beamSpot->BeamWidthX();
589 errVtx(1,1) = beamSpot->BeamWidthY();
590 errVtx(2,2) = beamSpot->sigmaZ();
594 const Vertex primaryVertex(posVtx,errVtx);
596 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)
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)