22 using namespace trigger;
31 m_muon = muonGmtPair.
m_muon;
32 m_gmt = muonGmtPair.
m_gmt;
33 m_eta = muonGmtPair.
m_eta;
42 float dEta = m_gmt ? (m_gmt->etaValue() -
eta()) : 999.;
43 float dPhi = m_gmt ? (m_gmt->phiValue() -
phi()) : 999.;
45 float dr =
sqrt(dEta*dEta + dPhi*dPhi);
57 m_propagatorAlong = propagatorAlong;
58 m_propagatorOpposite = propagatorOpposite;
60 TrackRef standaloneMuon = m_muon->outerTrack();
63 trajectory = cylExtrapTrkSam(standaloneMuon, 500);
69 trajectory = surfExtrapTrkSam(standaloneMuon, 790);
75 trajectory = surfExtrapTrkSam(standaloneMuon, -790);
93 recoProp = m_propagatorAlong->propagate(recoStart, *myCylinder);
95 recoProp = m_propagatorOpposite->propagate(recoStart, *myCylinder);
111 recoProp = m_propagatorAlong->propagate(recoStart, *myPlane);
113 recoProp = m_propagatorOpposite->propagate(recoStart, *myPlane);
122 GlobalPoint innerPoint(track->innerPosition().x(), track->innerPosition().y(), track->innerPosition().z());
123 GlobalVector innerVec (track->innerMomentum().x(), track->innerMomentum().y(), track->innerMomentum().z());
136 cout <<
"[L1TEfficiencyMuons_Offline:] ____________ Storage initialization ____________ " << endl;
142 if (m_verbose) {
cout <<
"[L1TEfficiencyMuons_Offline:] Pointer for DQM Store: " << dbe << endl;}
155 m_trigProcess_token = consumes<edm::TriggerResults>(ps.
getUntrackedParameter<
string>(
"trigProcess_token"));
160 m_MaxGmtMuonDR = 0.7;
161 m_MaxHltMuonDR = 0.1;
175 if (m_verbose) {
cout <<
"[L1TEfficiencyMuons_Offline:] Called beginJob." << endl;}
183 if (m_verbose) {
cout <<
"[L1TEfficiencyMuons_Offline:] Called endJob." << endl;}
191 if (m_verbose) {
cout <<
"[L1TEfficiencyMuons_Offline:] Called beginRun." << endl;}
196 vector<int>::const_iterator gmtPtCutsIt = m_GmtPtCuts.begin();
197 vector<int>::const_iterator gmtPtCutsEnd = m_GmtPtCuts.end();
199 for (; gmtPtCutsIt!=gmtPtCutsEnd; ++ gmtPtCutsIt) {
200 bookEfficiencyHistos((*gmtPtCutsIt));
206 m_hltConfig.init(run,iSetup,m_trigProcess,changed);
208 vector<string>::const_iterator trigNamesIt = m_trigNames.begin();
209 vector<string>::const_iterator trigNamesEnd = m_trigNames.end();
211 for (; trigNamesIt!=trigNamesEnd; ++trigNamesIt) {
213 TString tNameTmp = TString(*trigNamesIt);
214 TRegexp tNamePattern = TRegexp(tNameTmp,
true);
217 for (
unsigned ipath = 0; ipath < m_hltConfig.size(); ++ipath) {
219 TString tmpName = TString(m_hltConfig.triggerName(ipath));
220 if (tmpName.Contains(tNamePattern)) {
222 m_trigIndices.push_back(tIndex);
227 if (tIndex < 0 && m_verbose) {
228 cout <<
"[L1TEfficiencyMuons_Offline:] Warning: Could not find trigger "
229 << (*trigNamesIt) << endl;
240 if (m_verbose) {
cout <<
"[L1TEfficiencyMuons_Offline:] Called endRun." << endl;}
249 cout <<
"[L1TEfficiencyMuons_Offline:] Called beginLuminosityBlock at LS="
260 cout <<
"[L1TEfficiencyMuons_Offline:] Called endLuminosityBlock at LS="
283 iEvent.
getByToken(m_trigProcess_token,trigResults);
293 const Vertex primaryVertex = getPrimaryVertex(vertex,beamSpot);
295 getTightMuons(muons,primaryVertex);
296 getProbeMuons(trigResults,trigEvent);
297 getMuonGmtPairs(gmtCands);
299 cout <<
"[L1TEfficiencyMuons_Offline:] Computing efficiencies" << endl;
301 vector<MuonGmtPair>::const_iterator muonGmtPairsIt = m_MuonGmtPairs.begin();
302 vector<MuonGmtPair>::const_iterator muonGmtPairsEnd = m_MuonGmtPairs.end();
304 for(; muonGmtPairsIt!=muonGmtPairsEnd; ++muonGmtPairsIt) {
306 float eta = muonGmtPairsIt->eta();
307 float phi = muonGmtPairsIt->phi();
308 float pt = muonGmtPairsIt->pt();
311 float gmtPt = muonGmtPairsIt->gmtPt();
313 vector<int>::const_iterator gmtPtCutsIt = m_GmtPtCuts.begin();
314 vector<int>::const_iterator gmtPtCutsEnd = m_GmtPtCuts.end();
316 for (; gmtPtCutsIt!=gmtPtCutsEnd; ++ gmtPtCutsIt) {
318 int gmtPtCut = (*gmtPtCutsIt);
319 bool gmtAboveCut = (gmtPt > gmtPtCut);
321 stringstream ptCutToTag; ptCutToTag << gmtPtCut;
322 string ptTag = ptCutToTag.str();
324 if (fabs(eta) < m_MaxMuonEta) {
326 m_EfficiencyHistos[gmtPtCut][
"EffvsPt" + ptTag +
"Den"]->Fill(pt);
327 if (gmtAboveCut) m_EfficiencyHistos[gmtPtCut][
"EffvsPt" + ptTag +
"Num"]->Fill(pt);
329 if (pt > gmtPtCut + 8.) {
331 m_EfficiencyHistos[gmtPtCut][
"EffvsPhi" + ptTag +
"Den"]->Fill(phi);
332 m_EfficiencyHistos[gmtPtCut][
"EffvsEta" + ptTag +
"Den"]->Fill(eta);
335 m_EfficiencyHistos[gmtPtCut][
"EffvsPhi" + ptTag +
"Num"]->Fill(phi);
336 m_EfficiencyHistos[gmtPtCut][
"EffvsEta" + ptTag +
"Num"]->Fill(eta);
343 cout <<
"[L1TEfficiencyMuons_Offline:] Computation finished" << endl;
352 if(m_verbose){
cout <<
"[L1TEfficiencyMuons_Offline:] Booking Control Plot Histos" << endl;}
354 dbe->setCurrentFolder(
"L1T/Efficiency/Muons/Control");
356 string name =
"MuonGmtDeltaR";
357 m_ControlHistos[
name] = dbe->book1D(name.c_str(),name.c_str(),25.,0.,2.5);
359 name =
"NTightVsAll";
360 m_ControlHistos[
name] = dbe->book2D(name.c_str(),name.c_str(),5,-0.5,4.5,5,-0.5,4.5);
362 name =
"NProbesVsTight";
363 m_ControlHistos[
name] = dbe->book2D(name.c_str(),name.c_str(),5,-0.5,4.5,5,-0.5,4.5);
372 cout <<
"[L1TEfficiencyMuons_Offline:] Booking Efficiency Plot Histos for pt cut = "
376 stringstream ptCutToTag; ptCutToTag << ptCut;
377 string ptTag = ptCutToTag.str();
379 dbe->setCurrentFolder(
"L1T/Efficiency/Muons/");
381 string effTag[2] = {
"Den",
"Num"};
383 for(
int iEffTag=0; iEffTag<2; ++ iEffTag) {
384 string name =
"EffvsPt" + ptTag + effTag[iEffTag];
385 m_EfficiencyHistos[ptCut][
name] = dbe->book1D(name.c_str(),name.c_str(),16,0.,40.);
387 name =
"EffvsPhi" + ptTag + effTag[iEffTag];
388 m_EfficiencyHistos[ptCut][
name] = dbe->book1D(name.c_str(),name.c_str(),12,0.,2*
TMath::Pi());
390 name =
"EffvsEta" + ptTag + effTag[iEffTag];
391 m_EfficiencyHistos[ptCut][
name] = dbe->book1D(name.c_str(),name.c_str(),12,-2.4,2.4);
404 bool hasPrimaryVertex =
false;
409 vector<Vertex>::const_iterator vertexIt = vertex->begin();
410 vector<Vertex>::const_iterator vertexEnd = vertex->end();
412 for (;vertexIt!=vertexEnd;++vertexIt)
414 if (vertexIt->isValid() &&
417 posVtx = vertexIt->position();
418 errVtx = vertexIt->error();
419 hasPrimaryVertex =
true;
425 if ( !hasPrimaryVertex ) {
428 cout <<
"[L1TEfficiencyMuons_Offline:] PrimaryVertex not found, use BeamSpot position instead" << endl;
431 posVtx = beamSpot->position();
432 errVtx(0,0) = beamSpot->BeamWidthX();
433 errVtx(1,1) = beamSpot->BeamWidthY();
434 errVtx(2,2) = beamSpot->sigmaZ();
438 const Vertex primaryVertex(posVtx,errVtx);
440 return primaryVertex;
449 cout <<
"[L1TEfficiencyMuons_Offline:] Getting tight muons" << endl;
451 m_TightMuons.clear();
453 MuonCollection::const_iterator muonIt = muons->begin();
454 MuonCollection::const_iterator muonEnd = muons->end();
456 for(; muonIt!=muonEnd; ++muonIt) {
458 m_TightMuons.push_back(&(*muonIt));
462 m_ControlHistos[
"NTightVsAll"]->Fill(muons->size(),m_TightMuons.size());
471 cout <<
"[L1TEfficiencyMuons_Offline:] getting probe muons" << endl;
473 m_ProbeMuons.clear();
475 vector<const Muon*>::const_iterator probeCandIt = m_TightMuons.begin();
476 vector<const Muon*>::const_iterator tightMuonsEnd = m_TightMuons.end();
478 for (; probeCandIt!=tightMuonsEnd; ++probeCandIt) {
480 bool tagHasTrig =
false;
481 vector<const Muon*>::const_iterator tagCandIt = m_TightMuons.begin();
483 for (; tagCandIt!=tightMuonsEnd; ++tagCandIt) {
484 if ((*tagCandIt) == (*probeCandIt))
continue;
485 tagHasTrig |= matchHlt(trigEvent,(*tagCandIt));
488 if (tagHasTrig) m_ProbeMuons.push_back((*probeCandIt));
492 m_ControlHistos[
"NProbesVsTight"]->Fill(m_TightMuons.size(),m_ProbeMuons.size());
499 m_MuonGmtPairs.clear();
501 cout <<
"[L1TEfficiencyMuons_Offline:] Getting muon GMT pairs" << endl;
503 vector<const Muon*>::const_iterator probeMuIt = m_ProbeMuons.begin();
504 vector<const Muon*>::const_iterator probeMuEnd = m_ProbeMuons.end();
506 vector<L1MuGMTExtendedCand> gmtContainer = gmtCands->getRecord(0).getGMTCands();
508 vector<L1MuGMTExtendedCand>::const_iterator gmtIt;
509 vector<L1MuGMTExtendedCand>::const_iterator gmtEnd = gmtContainer.end();
511 for (; probeMuIt!=probeMuEnd; ++probeMuIt) {
514 pairBestCand.
propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
516 gmtIt = gmtContainer.begin();
518 for(; gmtIt!=gmtEnd; ++gmtIt) {
521 pairTmpCand.
propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
523 if (pairTmpCand.
dR() < m_MaxGmtMuonDR && pairTmpCand.
gmtPt() > pairBestCand.
gmtPt())
524 pairBestCand = pairTmpCand;
528 m_MuonGmtPairs.push_back(pairBestCand);
530 m_ControlHistos[
"MuonGmtDeltaR"]->Fill(pairBestCand.
dR());
540 double matchDeltaR = 9999;
544 vector<int>::const_iterator trigIndexIt = m_trigIndices.begin();
545 vector<int>::const_iterator trigIndexEnd = m_trigIndices.end();
547 for(; trigIndexIt!=trigIndexEnd; ++trigIndexIt) {
549 const vector<string> moduleLabels(m_hltConfig.moduleLabels(*trigIndexIt));
550 const unsigned moduleIndex = m_hltConfig.size((*trigIndexIt))-2;
551 const unsigned hltFilterIndex = triggerEvent->filterIndex(
InputTag(moduleLabels[moduleIndex],
554 if (hltFilterIndex < triggerEvent->sizeFilters()) {
555 const Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
556 const Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
558 const unsigned nTriggers = triggerVids.size();
559 for (
size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
560 const TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
562 double dRtmp =
deltaR((*mu),trigObject);
563 if (dRtmp < matchDeltaR) matchDeltaR = dRtmp;
569 return (matchDeltaR < m_MaxHltMuonDR);
LuminosityBlockID id() const
TkRotation< Scalar > RotationType
T getUntrackedParameter(std::string const &, T const &) const
MuonGmtPair(const reco::Muon *muon, const L1MuGMTExtendedCand *gmt)
void getTightMuons(edm::Handle< reco::MuonCollection > &muons, const reco::Vertex &vertex)
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
const reco::Vertex getPrimaryVertex(edm::Handle< reco::VertexCollection > &vertex, edm::Handle< reco::BeamSpot > &beamSpot)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
Geom::Phi< T > phi() const
math::Error< dimension >::type Error
covariance error matrix (3x3)
GlobalPoint globalPosition() const
const L1MuGMTExtendedCand * m_gmt
void bookEfficiencyHistos(int ptCut)
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
Point3DBase< Scalar, GlobalTag > PositionType
Single trigger physics object (e.g., an isolated muon)
double dPhi(double phi1, double phi2)
static PlanePointer build(Args &&...args)
TrajectoryStateOnSurface cylExtrapTrkSam(reco::TrackRef track, double rho)
const reco::Muon * m_muon
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
math::XYZPoint Point
point in the space
L1TEfficiencyMuons_Offline(const edm::ParameterSet &ps)
void getMuonGmtPairs(edm::Handle< L1MuGMTReadoutCollection > &gmtCands)
void getProbeMuons(edm::Handle< edm::TriggerResults > &trigResults, edm::Handle< trigger::TriggerEvent > &trigEvent)
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
void analyze(const edm::Event &e, const edm::EventSetup &c)
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
FreeTrajectoryState freeTrajStateMuon(reco::TrackRef track)
void propagate(edm::ESHandle< MagneticField > bField, edm::ESHandle< Propagator > propagatorAlong, edm::ESHandle< Propagator > propagatorOpposite)
std::vector< size_type > Keys
TrajectoryStateOnSurface surfExtrapTrkSam(reco::TrackRef track, double z)
LuminosityBlockNumber_t luminosityBlock() const
virtual ~L1TEfficiencyMuons_Offline()
bool matchHlt(edm::Handle< trigger::TriggerEvent > &triggerEvent, const reco::Muon *mu)
bool isTightMuon(const reco::Muon &, const reco::Vertex &)