Skip to content

Commit

Permalink
Merge pull request #46280 from mmusich/mm_StandalonaTrackMonitor_test…
Browse files Browse the repository at this point in the history
…s_14_1_X

[14.1.X] Miscellaneous backports to `DQM/TrackingMonitorSource`
  • Loading branch information
cmsbuild authored Oct 9, 2024
2 parents d670bc8 + 514a64c commit ee94214
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 34 deletions.
19 changes: 12 additions & 7 deletions DQM/TrackingMonitorSource/plugins/StandaloneTrackMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ void StandaloneTrackMonitor::fillDescriptions(edm::ConfigurationDescriptions& de
desc.addUntracked<bool>("haveAllHistograms", false);
desc.addUntracked<std::string>("puScaleFactorFile", "PileupScaleFactor.root");
desc.addUntracked<std::string>("trackScaleFactorFile", "PileupScaleFactor.root");
desc.addUntracked<std::vector<std::string> >("MVAProducers");
desc.addUntracked<edm::InputTag>("TrackProducerForMVA");
desc.addUntracked<std::vector<std::string> >("MVAProducers", {"initialStepClassifier1", "initialStepClassifier2"});
desc.addUntracked<edm::InputTag>("TrackProducerForMVA", edm::InputTag("initialStepTracks"));

desc.addUntracked<edm::InputTag>("TCProducer");
desc.addUntracked<std::string>("AlgoName");
desc.addUntracked<edm::InputTag>("TCProducer", edm::InputTag("initialStepTrackCandidates"));
desc.addUntracked<std::string>("AlgoName", "GenTk");
desc.addUntracked<bool>("verbose", false);

{
Expand Down Expand Up @@ -1315,7 +1315,8 @@ void StandaloneTrackMonitor::analyze(edm::Event const& iEvent, edm::EventSetup c
edm::Handle<reco::VertexCollection> vertexColl;
iEvent.getByToken(vertexToken_, vertexColl);
if (!vertexColl.isValid()) {
edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
edm::LogError("StandaloneTrackMonitor") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
return;
}
if (vertexColl->empty()) {
edm::LogError("StandalonaTrackMonitor") << "No good vertex in the event!!" << std::endl;
Expand All @@ -1326,14 +1327,18 @@ void StandaloneTrackMonitor::analyze(edm::Event const& iEvent, edm::EventSetup c
// Beam spot
edm::Handle<reco::BeamSpot> beamSpot;
iEvent.getByToken(bsToken_, beamSpot);
if (!beamSpot.isValid())
if (!beamSpot.isValid()) {
edm::LogError("StandalonaTrackMonitor") << "Beamspot for input tag: " << bsTag_ << " not found!!";
return;
}

// Track collection
edm::Handle<reco::TrackCollection> tracks;
iEvent.getByToken(trackToken_, tracks);
if (!tracks.isValid())
if (!tracks.isValid()) {
edm::LogError("StandalonaTrackMonitor") << "TrackCollection for input tag: " << trackTag_ << " not found!!";
return;
}

// Access PU information
double wfac = 1.0; // for data
Expand Down
7 changes: 7 additions & 0 deletions DQM/TrackingMonitorSource/plugins/TrackMultiplicityFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ bool TrackMultiplicityFilter::filter(edm::StreamID iStream, edm::Event& iEvent,
bool pass = false;
edm::Handle<reco::TrackCollection> tracks;
iEvent.getByToken(tracksToken_, tracks);

if (!tracks.isValid()) {
edm::LogError("TrackMultiplicityFilter")
<< "Error >> Failed to get TrackMultiplicityFilter for label: " << tracksTag_;
return false;
}

double count = std::count_if(tracks->begin(), tracks->end(), selector_);
pass = (count >= nmin_);

Expand Down
23 changes: 13 additions & 10 deletions DQM/TrackingMonitorSource/plugins/TtbarTrackProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,19 @@ void TtbarTrackProducer::produce(edm::StreamID streamID, edm::Event& iEvent, edm

edm::Handle<reco::JetTagCollection> bTagHandle;
iEvent.getByToken(bjetsToken_, bTagHandle);
const reco::JetTagCollection& bTags = *(bTagHandle.product());
std::vector<TLorentzVector> list_bjets;

if (!bTags.empty()) {
for (unsigned bj = 0; bj != bTags.size(); ++bj) {
TLorentzVector lv_bjets;
lv_bjets.SetPtEtaPhiE(
bTags[bj].first->pt(), bTags[bj].first->eta(), bTags[bj].first->phi(), bTags[bj].first->energy());
if (bTags[bj].second > btagFactor_)
list_bjets.push_back(lv_bjets);

if (bTagHandle.isValid()) {
const reco::JetTagCollection& bTags = *(bTagHandle.product());
std::vector<TLorentzVector> list_bjets;

if (!bTags.empty()) {
for (unsigned bj = 0; bj != bTags.size(); ++bj) {
TLorentzVector lv_bjets;
lv_bjets.SetPtEtaPhiE(
bTags[bj].first->pt(), bTags[bj].first->eta(), bTags[bj].first->phi(), bTags[bj].first->energy());
if (bTags[bj].second > btagFactor_)
list_bjets.push_back(lv_bjets);
}
}
}

Expand Down
33 changes: 30 additions & 3 deletions DQM/TrackingMonitorSource/plugins/V0EventSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#include <vector>
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

class V0EventSelector : public edm::stream::EDFilter<> {
public:
Expand All @@ -19,25 +21,50 @@ class V0EventSelector : public edm::stream::EDFilter<> {
private:
const edm::EDGetTokenT<reco::VertexCompositeCandidateCollection> vccToken_;
const unsigned int minNumCandidates_;
const double massMin_;
const double massMax_;
};

V0EventSelector::V0EventSelector(const edm::ParameterSet& iConfig)
: vccToken_{consumes<reco::VertexCompositeCandidateCollection>(
iConfig.getParameter<edm::InputTag>("vertexCompositeCandidates"))},
minNumCandidates_{iConfig.getParameter<unsigned int>("minCandidates")} {}
minNumCandidates_{iConfig.getParameter<unsigned int>("minCandidates")},
massMin_{iConfig.getParameter<double>("massMin")},
massMax_{iConfig.getParameter<double>("massMax")} {
produces<reco::VertexCompositeCandidateCollection>();
}

bool V0EventSelector::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<reco::VertexCompositeCandidateCollection> vccHandle;
iEvent.getByToken(vccToken_, vccHandle);
auto filteredVCC = std::make_unique<reco::VertexCompositeCandidateCollection>();

// early return if the input collection is empty
if (!vccHandle.isValid()) {
iEvent.put(std::move(filteredVCC));
return false;
}

for (const auto& vcc : *vccHandle) {
if (vcc.mass() >= massMin_ && vcc.mass() <= massMax_) {
filteredVCC->push_back(vcc);
}
}

bool pass = filteredVCC->size() >= minNumCandidates_;
iEvent.put(std::move(filteredVCC));

return vccHandle->size() >= minNumCandidates_;
return pass;
}

void V0EventSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("vertexCompositeCandidates", edm::InputTag("generalV0Candidates:Kshort"));
desc.add<unsigned int>("minCandidates", 1); // Change '1' to your desired minimum number of candidates
desc.add<unsigned int>("minCandidates", 1)->setComment("Minimum number of candidates required");
desc.add<double>("massMin", 0.0)->setComment("Minimum mass in GeV");
desc.add<double>("massMax", std::numeric_limits<double>::max())->setComment("Maximum mass in GeV");
descriptions.addWithDefaultLabel(desc);
}

// Define this module as a plug-in
DEFINE_FWK_MODULE(V0EventSelector);
11 changes: 6 additions & 5 deletions DQM/TrackingMonitorSource/plugins/ZEEDetails.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void ZEEDetails::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup
if (beamSpot.isValid()) {
trkd0 = -(trk->dxy(beamSpot->position()));
} else {
edm::LogError("ElectronTrackProducer") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
edm::LogError("ZEEDetails") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
}
if (std::fabs(trkd0) >= maxD0_)
continue;
Expand Down Expand Up @@ -261,16 +261,17 @@ void ZEEDetails::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup
finalelectrons.push_back(ele);
}
} else {
edm::LogError("ElectronTrackProducer") << "Error >> Failed to get ElectronCollection for label: " << electronTag_;
edm::LogError("ZEEDetails") << "Error >> Failed to get ElectronCollection for label: " << electronTag_;
}

edm::Handle<reco::VertexCollection> vertexColl;
iEvent.getByToken(vertexToken_, vertexColl);
if (!vertexColl.isValid()) {
edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
edm::LogError("ZEEDetails") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
return;
}
if (vertexColl->empty()) {
edm::LogError("DqmTrackStudy") << "No good vertex in the event!!";
edm::LogError("ZEEDetails") << "No good vertex in the event!!";
return;
}

Expand All @@ -294,7 +295,7 @@ void ZEEDetails::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup
}
}
} else
edm::LogError("DqmTrackStudy") << "PUSummary for input tag: " << puSummaryTag_ << " not found!!";
edm::LogError("ZEEDetails") << "PUSummary for input tag: " << puSummaryTag_ << " not found!!";
}

for (unsigned int I = 0; I != finalelectrons.size(); I++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
ttbarEventSelector = cms.EDFilter("ttbarEventSelector")
ttbarTracks = cms.EDProducer("TtbarTrackProducer")

# Added modules for V0Monitoring
# Added modules for V0Monitoring (standard)
KshortMonitor = v0Monitor.clone()
KshortMonitor.FolderName = "StandaloneTrackMonitor/V0Monitoring/Ks"
KshortMonitor.v0 = "generalV0Candidates:Kshort"
Expand All @@ -108,6 +108,18 @@
LambdaMonitor.histoPSet.massPSet = cms.PSet(nbins = cms.int32(100),
xmin = cms.double(1.050),
xmax = cms.double(1.250))

# Added modules for V0Monitoring (for restricted mass candidates)
SelectedKshortMonitor = KshortMonitor.clone(
FolderName = "StandaloneTrackMonitor/V0Monitoring/SelectedKs",
v0 = "KShortEventSelector"
)

SelectedLambdaMonitor = LambdaMonitor.clone(
FolderName = "StandaloneTrackMonitor/V0Monitoring/SelectedLambda",
v0 = "LambdaEventSelector"
)

##################
# For MinBias
##################
Expand Down Expand Up @@ -171,31 +183,31 @@
* KShortEventSelector
* KshortTracks
* standaloneTrackMonitorK0
* KshortMonitor)
* SelectedKshortMonitor)

standaloneValidationK0sMC = cms.Sequence(
hltPathFilter
* selectedPrimaryVertices
* KShortEventSelector
* KshortTracks
* standaloneTrackMonitorK0MC
* KshortMonitor)
* SelectedKshortMonitor)

standaloneValidationLambdas = cms.Sequence(
hltPathFilter
* selectedPrimaryVertices
* LambdaEventSelector
* LambdaTracks
* standaloneTrackMonitorLambda
* LambdaMonitor)
* SelectedLambdaMonitor)

standaloneValidationLambdasMC = cms.Sequence(
hltPathFilter
* selectedPrimaryVertices
* LambdaEventSelector
* LambdaTracks
* standaloneTrackMonitorLambdaMC
* LambdaMonitor)
* SelectedLambdaMonitor)

##################
# For ZtoEE
Expand Down
17 changes: 13 additions & 4 deletions DQM/TrackingMonitorSource/python/V0Selections_cfi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from DQM.TrackingMonitorSource.v0EventSelector_cfi import *
from DQM.TrackingMonitorSource.v0VertexTrackProducer_cfi import *

KShortEventSelector = v0EventSelector.clone()
KShortEventSelector = v0EventSelector.clone(
vertexCompositeCandidates = "generalV0Candidates:Kshort",
massMin = 0.47,
massMax = 0.52,
)

LambdaEventSelector = v0EventSelector.clone(
vertexCompositeCandidates = "generalV0Candidates:Lambda"
vertexCompositeCandidates = "generalV0Candidates:Lambda",
massMin = 1.11,
massMax = 1.128
)

KshortTracks = v0VertexTrackProducer.clone()
KshortTracks = v0VertexTrackProducer.clone(
vertexCompositeCandidates = "KShortEventSelector"
)
LambdaTracks = v0VertexTrackProducer.clone(
vertexCompositeCandidates = "generalV0Candidates:Lambda"
vertexCompositeCandidates = "LambdaEventSelector"
)
6 changes: 6 additions & 0 deletions DQM/TrackingMonitorSource/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
<test name="testTrackingDATAMC" command="testTrackingDATAMC.sh"/>
<test name="testTrackingResolution" command="testTrackingResolution.sh"/>
<environment>
<bin file="testTrackingDQMAnalyzers.cc" name="testTrackingDQMAnalyzers">
<use name="FWCore/TestProcessor"/>
<use name="catch2"/>
</bin>
</environment>
Loading

0 comments on commit ee94214

Please sign in to comment.