Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including short tracks resolution method in DQM #43613

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions DQM/TrackingMonitorSource/plugins/ShortenedTrackResolution.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// user includes
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/Utilities/interface/transform.h" // for edm::vector_transform

// ROOT includes
#include "TLorentzVector.h"

class ShortenedTrackResolution : public DQMEDAnalyzer {
public:
ShortenedTrackResolution(const edm::ParameterSet &);
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);

protected:
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;

private:
const std::string folderName_;
const std::vector<std::string> hitsRemain_;
const double minTracksEta_;
const double maxTracksEta_;
const double minTracksPt_;
const double maxTracksPt_;

const double maxDr_;
const edm::InputTag tracksTag_;
const std::vector<edm::InputTag> tracksRerecoTag_;
const edm::EDGetTokenT<std::vector<reco::Track>> tracksToken_;
const std::vector<edm::EDGetTokenT<std::vector<reco::Track>>> tracksRerecoToken_;

std::vector<MonitorElement *> histsPtAll_;
};

// -----------------------------
// constructors and destructor
// -----------------------------
ShortenedTrackResolution::ShortenedTrackResolution(const edm::ParameterSet &ps)
: folderName_(ps.getUntrackedParameter<std::string>("folderName", "TrackRefitting")),
hitsRemain_(ps.getUntrackedParameter<std::vector<std::string>>("hitsRemainInput")),
minTracksEta_(ps.getUntrackedParameter<double>("minTracksEtaInput", 0.0)),
maxTracksEta_(ps.getUntrackedParameter<double>("maxTracksEtaInput", 2.2)),
minTracksPt_(ps.getUntrackedParameter<double>("minTracksPtInput", 15.0)),
maxTracksPt_(ps.getUntrackedParameter<double>("maxTracksPtInput", 99999.9)),
maxDr_(ps.getUntrackedParameter<double>("maxDrInput", 0.01)),
tracksTag_(ps.getUntrackedParameter<edm::InputTag>("tracksInputTag", edm::InputTag("generalTracks", "", "DQM"))),
tracksRerecoTag_(ps.getUntrackedParameter<std::vector<edm::InputTag>>("tracksRerecoInputTag")),
tracksToken_(consumes<std::vector<reco::Track>>(tracksTag_)),
tracksRerecoToken_(edm::vector_transform(
tracksRerecoTag_, [this](edm::InputTag const &tag) { return consumes<std::vector<reco::Track>>(tag); })) {
histsPtAll_.clear();
}

//__________________________________________________________________________________
void ShortenedTrackResolution::bookHistograms(DQMStore::IBooker &iBook,
edm::Run const &iRun,
edm::EventSetup const &iSetup) {
std::string currentFolder = folderName_ + "/";
iBook.setCurrentFolder(currentFolder);

for (int i = 0; i < int(hitsRemain_.size()); ++i) {
histsPtAll_.push_back(iBook.book1D(
"trackPt" + hitsRemain_[i] + "lAllPt", "Track p_{T} - " + hitsRemain_[i] + " layers", 41, 0.0, 2.0));
}
}

//__________________________________________________________________________________
void ShortenedTrackResolution::analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) {
const auto &tracks = iEvent.getHandle(tracksToken_);

if (!tracks.isValid()) {
edm::LogError("ShortenedTrackResolution") << "Missing input track collection " << tracksTag_.encode() << std::endl;
return;
}

for (const auto &track : *tracks) {
const reco::HitPattern &hp = track.hitPattern();
if (int(int(hp.numberOfValidHits()) - int(hp.numberOfAllHits(reco::HitPattern::TRACK_HITS))) != 0) {
break;
}

TLorentzVector tvec;
tvec.SetPtEtaPhiM(track.pt(), track.eta(), track.phi(), 0.0);

int i = 0; // token index
for (const auto &token : tracksRerecoToken_) {
const auto &tracks_rereco = iEvent.getHandle(token);

for (const auto &track_rereco : *tracks_rereco) {
TLorentzVector trerecovec;
trerecovec.SetPtEtaPhiM(track_rereco.pt(), track_rereco.eta(), track_rereco.phi(), 0.0);
double deltaR = tvec.DeltaR(trerecovec);

if (deltaR < maxDr_) {
if (track_rereco.pt() >= minTracksPt_ && track_rereco.pt() <= maxTracksPt_ &&
std::abs(track_rereco.eta()) >= minTracksEta_ && std::abs(track_rereco.eta()) <= maxTracksEta_) {
histsPtAll_[i]->Fill(1.0 * track_rereco.pt() / track.pt());
}
}
}
++i;
}
}
}

//__________________________________________________________________________________
void ShortenedTrackResolution::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc;
desc.addUntracked<std::string>("folderName", "TrackRefitting");
desc.addUntracked<std::vector<std::string>>("hitsRemainInput", {});
desc.addUntracked<double>("minTracksEtaInput", 0.0);
desc.addUntracked<double>("maxTracksEtaInput", 2.2);
desc.addUntracked<double>("minTracksPtInput", 15.0);
desc.addUntracked<double>("maxTracksPtInput", 99999.9);
desc.addUntracked<double>("maxDrInput", 0.01);
desc.addUntracked<edm::InputTag>("tracksInputTag", edm::InputTag("generalTracks", "", "DQM"));
desc.addUntracked<std::vector<edm::InputTag>>("tracksRerecoInputTag", {});
descriptions.addWithDefaultLabel(desc);
}

// Define this as a plug-in
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(ShortenedTrackResolution);
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,16 @@ def _copyIfExists(mod, pset, name):

TrackingDQMSourceTier0 += TrackSeedMonSequence

from DQM.TrackingMonitorSource.shortTrackResolution_cff import *

# MessageLog
for module in selectedModules :
label = str(module)+'LogMessageMonCommon'
TrackingDQMSourceTier0 += locals()[label]
TrackingDQMSourceTier0 += voMonitoringSequence
TrackingDQMSourceTier0 += voWcutMonitoringSequence
TrackingDQMSourceTier0 += primaryVertexResolution
TrackingDQMSourceTier0 += shortTrackResolution3to8
TrackingDQMSourceTier0 += dqmInfoTracking


Expand All @@ -426,6 +429,7 @@ def _copyIfExists(mod, pset, name):
TrackingDQMSourceTier0Common += voMonitoringCommonSequence
TrackingDQMSourceTier0Common += voWcutMonitoringCommonSequence
TrackingDQMSourceTier0Common += primaryVertexResolution
TrackingDQMSourceTier0Common += shortTrackResolution3to8
TrackingDQMSourceTier0Common += dqmInfoTracking

TrackingDQMSourceTier0MinBias = cms.Sequence(cms.ignore(trackingDQMgoodOfflinePrimaryVertices))
Expand Down
69 changes: 69 additions & 0 deletions DQM/TrackingMonitorSource/python/shortTrackResolution_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import FWCore.ParameterSet.Config as cms
from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer

from RecoTracker.FinalTrackSelectors.SingleLongTrackProducer_cfi import *

from RecoTracker.FinalTrackSelectors.trackerTrackHitFilter_cfi import trackerTrackHitFilter as _trackerTrackHitFilter
ShortTrackCandidates = _trackerTrackHitFilter.clone(src = "SingleLongTrackProducer",
truncateTracks = True,
replaceWithInactiveHits = True,
rejectBadStoNHits = True,
usePixelQualityFlag = True)

from Configuration.Eras.Modifier_phase2_tracker_cff import phase2_tracker
phase2_tracker.toModify(ShortTrackCandidates,
isPhase2 = True)

ShortTrackCandidates3 = ShortTrackCandidates.clone(minimumHits = 3,
layersRemaining = 3)

ShortTrackCandidates4 = ShortTrackCandidates.clone(minimumHits = 4,
layersRemaining = 4)

ShortTrackCandidates5 = ShortTrackCandidates.clone(minimumHits = 5,
layersRemaining = 5)

ShortTrackCandidates6 = ShortTrackCandidates.clone(minimumHits = 6,
layersRemaining = 6)

ShortTrackCandidates7 = ShortTrackCandidates.clone(minimumHits = 7,
layersRemaining = 7)

ShortTrackCandidates8 = ShortTrackCandidates.clone(minimumHits = 8,
layersRemaining = 8)

import RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff
RefittedShortTracks = RecoTracker.TrackProducer.CTFFinalFitWithMaterial_cff.ctfWithMaterialTracks.clone(src = 'ShortTrackCandidates')

RefittedShortTracks3 = RefittedShortTracks.clone(src = 'ShortTrackCandidates3')
RefittedShortTracks4 = RefittedShortTracks.clone(src = 'ShortTrackCandidates4')
RefittedShortTracks5 = RefittedShortTracks.clone(src = 'ShortTrackCandidates5')
RefittedShortTracks6 = RefittedShortTracks.clone(src = 'ShortTrackCandidates6')
RefittedShortTracks7 = RefittedShortTracks.clone(src = 'ShortTrackCandidates7')
RefittedShortTracks8 = RefittedShortTracks.clone(src = 'ShortTrackCandidates8')

from DQM.TrackingMonitorSource.shortenedTrackResolution_cfi import shortenedTrackResolution as _shortenedTrackResolution
trackingResolution = _shortenedTrackResolution.clone(folderName = "Tracking/ShortTrackResolution",
hitsRemainInput = ["3","4","5","6","7","8"],
minTracksEtaInput = 0.0,
maxTracksEtaInput = 2.2,
minTracksPtInput = 15.0,
maxTracksPtInput = 99999.9,
maxDrInput = 0.01,
tracksInputTag = "SingleLongTrackProducer",
tracksRerecoInputTag = ["RefittedShortTracks3","RefittedShortTracks4","RefittedShortTracks5","RefittedShortTracks6","RefittedShortTracks7","RefittedShortTracks8"])

shortTrackResolution3to8 = cms.Sequence(SingleLongTrackProducer *
ShortTrackCandidates3 *
ShortTrackCandidates4 *
ShortTrackCandidates5 *
ShortTrackCandidates6 *
ShortTrackCandidates7 *
ShortTrackCandidates8 *
RefittedShortTracks3 *
RefittedShortTracks4 *
RefittedShortTracks5 *
RefittedShortTracks6 *
RefittedShortTracks7 *
RefittedShortTracks8 *
trackingResolution)
Loading