-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
MTD TDR Reconstruction + MTD Track Association BDT #28815
Changes from 21 commits
2d922a3
f79a5f9
70df858
de07f69
e479e16
a5c0d82
ef85193
71b0d07
491d468
25f208d
1e64154
0040676
ce23d1d
50a51d4
3f05707
61f775f
b04490c
ca8c653
6566048
4cce131
6c3b270
15a7fb5
f6caa8e
e2abc64
fd68170
6b41c7d
1a41a1d
d4a01be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,9 @@ namespace pat { | |
const bool storeHcalDepthEndcapOnly_; | ||
|
||
const bool storeTiming_; | ||
const bool timeFromValueMap_; | ||
const edm::EDGetTokenT<edm::ValueMap<float>> t0Map_; | ||
const edm::EDGetTokenT<edm::ValueMap<float>> t0ErrMap_; | ||
|
||
// for debugging | ||
float calcDxy(float dx, float dy, float phi) const { return -dx * std::sin(phi) + dy * std::cos(phi); } | ||
|
@@ -143,7 +146,13 @@ pat::PATPackedCandidateProducer::PATPackedCandidateProducer(const edm::Parameter | |
covariancePackingSchemas_(iConfig.getParameter<std::vector<int>>("covariancePackingSchemas")), | ||
pfCandidateTypesForHcalDepth_(iConfig.getParameter<std::vector<int>>("pfCandidateTypesForHcalDepth")), | ||
storeHcalDepthEndcapOnly_(iConfig.getParameter<bool>("storeHcalDepthEndcapOnly")), | ||
storeTiming_(iConfig.getParameter<bool>("storeTiming")) { | ||
storeTiming_(iConfig.getParameter<bool>("storeTiming")), | ||
timeFromValueMap_(!iConfig.getParameter<edm::InputTag>("timeMap").encode().empty() || | ||
!iConfig.getParameter<edm::InputTag>("timeMapErr").encode().empty()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the logic in the ::produce suggests that both should be not empty ==> use |
||
t0Map_(timeFromValueMap_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("timeMap")) | ||
: edm::EDGetTokenT<edm::ValueMap<float>>()), | ||
t0ErrMap_(timeFromValueMap_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("timeMapErr")) | ||
: edm::EDGetTokenT<edm::ValueMap<float>>()) { | ||
std::vector<edm::InputTag> sv_tags = | ||
iConfig.getParameter<std::vector<edm::InputTag>>("secondaryVerticesForWhiteList"); | ||
for (auto itag : sv_tags) { | ||
|
@@ -219,6 +228,13 @@ void pat::PATPackedCandidateProducer::produce(edm::StreamID, edm::Event &iEvent, | |
} | ||
} | ||
|
||
edm::Handle<edm::ValueMap<float>> t0Map; | ||
edm::Handle<edm::ValueMap<float>> t0ErrMap; | ||
if (timeFromValueMap_) { | ||
iEvent.getByToken(t0Map_, t0Map); | ||
iEvent.getByToken(t0ErrMap_, t0ErrMap); | ||
} | ||
|
||
edm::Handle<reco::VertexCollection> PVs; | ||
iEvent.getByToken(PVs_, PVs); | ||
reco::VertexRef PV(PVs.id()); | ||
|
@@ -425,8 +441,18 @@ void pat::PATPackedCandidateProducer::produce(edm::StreamID, edm::Event &iEvent, | |
mappingPuppi[((*puppiCandsMap)[pkref]).key()] = ic; | ||
} | ||
|
||
if (storeTiming_ && cand.isTimeValid()) { | ||
outPtrP->back().setTime(cand.time(), cand.timeError()); | ||
if (storeTiming_) { | ||
if (timeFromValueMap_) { | ||
if (cand.trackRef().isNonnull()) { | ||
auto t0 = (*t0Map)[cand.trackRef()]; | ||
auto t0Err = (*t0ErrMap)[cand.trackRef()]; | ||
outPtrP->back().setTime(t0, t0Err); | ||
} | ||
} else { | ||
if (cand.isTimeValid()) { | ||
outPtrP->back().setTime(cand.time(), cand.timeError()); | ||
} | ||
} | ||
} | ||
|
||
mapping[ic] = ic; // trivial at the moment! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from RecoMTD.TrackExtender.trackExtenderWithMTD_cfi import * | ||
from RecoMTD.TimingIDTools.trackPUIDMVA_cfi import * | ||
|
||
fastTimingGlobalRecoTask = cms.Task(trackExtenderWithMTD) | ||
fastTimingGlobalRecoTask = cms.Task(trackExtenderWithMTD,trackPUIDMVA) | ||
fastTimingGlobalReco = cms.Sequence(fastTimingGlobalRecoTask) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<use name="FWCore/Framework"/> | ||
<use name="FWCore/ParameterSet"/> | ||
<use name="DataFormats/TrackReco"/> | ||
<use name="DataFormats/BeamSpot"/> | ||
<use name="DataFormats/RecoCandidate"/> | ||
<use name="DataFormats/Candidate"/> | ||
<use name="DataFormats/VertexReco"/> | ||
<use name="CommonTools/MVAUtils"/> | ||
|
||
<export> | ||
<lib name="1"/> | ||
</export> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef COMMONTOOLS_RECOALGOS_TRACKPUIDMVA | ||
#define COMMONTOOLS_RECOALGOS_TRACKPUIDMVA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use an include guard matching the full file name subsystem_package_fileName_h |
||
|
||
#include "DataFormats/VertexReco/interface/Vertex.h" | ||
#include "DataFormats/VertexReco/interface/VertexFwd.h" | ||
#include "DataFormats/TrackReco/interface/Track.h" | ||
#include "DataFormats/TrackReco/interface/TrackFwd.h" | ||
#include "DataFormats/Common/interface/ValueMap.h" | ||
|
||
#include "CommonTools/MVAUtils/interface/TMVAEvaluator.h" | ||
|
||
class TrackPUIDMVA { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a name in the global namespace and it appears generic, not related to MTD. |
||
public: | ||
//---ctors--- | ||
TrackPUIDMVA(std::string weights_file); | ||
|
||
//---dtor--- | ||
~TrackPUIDMVA(){}; | ||
|
||
//---getters--- | ||
// 4D | ||
float operator()(const reco::TrackRef& trk, | ||
const reco::TrackRef& ext_trk, | ||
const edm::ValueMap<float>& btl_chi2s, | ||
const edm::ValueMap<float>& btl_time_chi2s, | ||
const edm::ValueMap<float>& etl_chi2s, | ||
const edm::ValueMap<float>& etl_time_chi2s, | ||
const edm::ValueMap<float>& tmtds, | ||
const edm::ValueMap<float>& trk_lengths) const; | ||
|
||
private: | ||
std::vector<std::string> vars_, spec_vars_; | ||
std::unique_ptr<TMVAEvaluator> mva_; | ||
}; | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<export> | ||
</export> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be dropped |
||
<library name="RecoMTDTimingIDTools_plugins" file="*.cc"> | ||
<use name="FWCore/Framework"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, all "use" statements can be outside of the "library" section. shouldn't there be a @makortel @smuzaffar is this flag not needed anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @slava77 , in Yes the |
||
<use name="FWCore/ParameterSet"/> | ||
<use name="DataFormats/TrackReco"/> | ||
<use name="DataFormats/BeamSpot"/> | ||
<use name="DataFormats/RecoCandidate"/> | ||
<use name="DataFormats/Candidate"/> | ||
<use name="DataFormats/VertexReco"/> | ||
<use name="CommonTools/MVAUtils"/> | ||
<use name="RecoMTD/TimingIDTools"/> | ||
</library> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ class TOFPIDProducer : public edm::stream::EDProducer<> { | |
double maxDz_; | ||
double maxDtSignificance_; | ||
double minProbHeavy_; | ||
double fixedT0Error_; | ||
}; | ||
|
||
TOFPIDProducer::TOFPIDProducer(const ParameterSet& iConfig) | ||
|
@@ -67,7 +68,8 @@ TOFPIDProducer::TOFPIDProducer(const ParameterSet& iConfig) | |
vtxMaxSigmaT_(iConfig.getParameter<double>("vtxMaxSigmaT")), | ||
maxDz_(iConfig.getParameter<double>("maxDz")), | ||
maxDtSignificance_(iConfig.getParameter<double>("maxDtSignificance")), | ||
minProbHeavy_(iConfig.getParameter<double>("minProbHeavy")) { | ||
minProbHeavy_(iConfig.getParameter<double>("minProbHeavy")), | ||
fixedT0Error_(iConfig.getParameter<double>("fixedT0Error")) { | ||
produces<edm::ValueMap<float>>(t0Name); | ||
produces<edm::ValueMap<float>>(sigmat0Name); | ||
produces<edm::ValueMap<float>>(t0safeName); | ||
|
@@ -93,7 +95,7 @@ void TOFPIDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio | |
->setComment("Input ValueMap for track path lengh from beamline to MTD"); | ||
desc.add<edm::InputTag>("pSrc", edm::InputTag("trackExtenderWithMTD:generalTrackp")) | ||
->setComment("Input ValueMap for track momentum magnitude (normally from refit with MTD hits)"); | ||
desc.add<edm::InputTag>("vtxsSrc", edm::InputTag("unsortedOfflinePrimaryVertices4DnoPID")) | ||
desc.add<edm::InputTag>("vtxsSrc", edm::InputTag("unsortedOfflinePrimaryVertices4DwithPID")) | ||
->setComment("Input primary vertex collection"); | ||
desc.add<double>("vtxMaxSigmaT", 0.025) | ||
->setComment("Maximum primary vertex time uncertainty for use in particle id [ns]"); | ||
|
@@ -104,6 +106,7 @@ void TOFPIDProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio | |
"Maximum distance in time (normalized by uncertainty) for track-primary vertex association for particle id"); | ||
desc.add<double>("minProbHeavy", 0.75) | ||
->setComment("Minimum probability for a particle to be a kaon or proton before reassigning the timestamp"); | ||
desc.add<double>("fixedT0Error", 0.)->setComment("Use a fixed T0 uncertainty [ns]"); | ||
|
||
descriptions.add("tofPIDProducer", desc); | ||
} | ||
|
@@ -174,7 +177,7 @@ void TOFPIDProducer::produce(edm::Event& ev, const edm::EventSetup& es) { | |
float t0 = t0In[trackref]; | ||
float t0safe = t0; | ||
float sigmat0safe = sigmat0In[trackref]; | ||
float sigmatmtd = sigmatmtdIn[trackref]; | ||
float sigmatmtd = (sigmatmtdIn[trackref] > 0. && fixedT0Error_ > 0.) ? fixedT0Error_ : sigmatmtdIn[trackref]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking: is it correct here to require that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we want to keep the sigmatmd = 0 when to time is associated |
||
float sigmat0 = sigmatmtd; | ||
|
||
float prob_pi = -1.; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/stream/EDProducer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
|
||
#include "DataFormats/VertexReco/interface/VertexFwd.h" | ||
#include "DataFormats/TrackReco/interface/TrackFwd.h" | ||
#include "DataFormats/Common/interface/ValueMap.h" | ||
#include "DataFormats/BeamSpot/interface/BeamSpot.h" | ||
#include "DataFormats/TrackReco/interface/Track.h" | ||
#include "DataFormats/VertexReco/interface/Vertex.h" | ||
|
||
#include "RecoMTD/TimingIDTools/interface/TrackPUIDMVA.h" | ||
|
||
using namespace std; | ||
using namespace edm; | ||
|
||
class TrackPUIDMVAProducer : public edm::stream::EDProducer<> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar to TrackPUIDMVA, "MTD" or "Timing" in the name may be useful, to avoid conflicts/ambiguity with some other track PU ID (if it ever appears) |
||
public: | ||
TrackPUIDMVAProducer(const ParameterSet& pset); | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); | ||
|
||
template <class H, class T> | ||
void fillValueMap(edm::Event& iEvent, | ||
const edm::Handle<H>& handle, | ||
const std::vector<T>& vec, | ||
const std::string& name) const; | ||
|
||
void produce(edm::Event& ev, const edm::EventSetup& es) final; | ||
|
||
private: | ||
static constexpr char mvaName[] = "mtdQualMVA"; | ||
|
||
edm::EDGetTokenT<reco::TrackCollection> tracksToken_; | ||
edm::EDGetTokenT<reco::TrackCollection> tracksMTDToken_; | ||
|
||
edm::EDGetTokenT<edm::ValueMap<float>> btlMatchChi2Token_; | ||
edm::EDGetTokenT<edm::ValueMap<float>> btlMatchTimeChi2Token_; | ||
edm::EDGetTokenT<edm::ValueMap<float>> etlMatchChi2Token_; | ||
edm::EDGetTokenT<edm::ValueMap<float>> etlMatchTimeChi2Token_; | ||
edm::EDGetTokenT<edm::ValueMap<float>> mtdTimeToken_; | ||
edm::EDGetTokenT<edm::ValueMap<float>> pathLengthToken_; | ||
edm::EDGetTokenT<edm::ValueMap<int>> trackAssocToken_; | ||
|
||
TrackPUIDMVA mva_; | ||
}; | ||
|
||
TrackPUIDMVAProducer::TrackPUIDMVAProducer(const ParameterSet& iConfig) | ||
: tracksToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracksSrc"))), | ||
tracksMTDToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("tracksMTDSrc"))), | ||
btlMatchChi2Token_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("btlMatchChi2Src"))), | ||
btlMatchTimeChi2Token_( | ||
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("btlMatchTimeChi2Src"))), | ||
etlMatchChi2Token_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("etlMatchChi2Src"))), | ||
etlMatchTimeChi2Token_( | ||
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("etlMatchTimeChi2Src"))), | ||
mtdTimeToken_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("mtdTimeSrc"))), | ||
pathLengthToken_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("pathLengthSrc"))), | ||
trackAssocToken_(consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::InputTag>("trackAssocSrc"))), | ||
mva_(iConfig.getParameter<edm::FileInPath>("trackPUID_mtdQualBDT_weights_file").fullPath()) { | ||
produces<edm::ValueMap<float>>(mvaName); | ||
} | ||
|
||
// Configuration descriptions | ||
void TrackPUIDMVAProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("tracksSrc", edm::InputTag("generalTracks"))->setComment("Input tracks collection"); | ||
desc.add<edm::InputTag>("tracksMTDSrc", edm::InputTag("trackExtenderWithMTD")) | ||
->setComment("Input tracks collection for MTD extended tracks"); | ||
desc.add<edm::InputTag>("btlMatchChi2Src", edm::InputTag("trackExtenderWithMTD", "btlMatchChi2")) | ||
->setComment("BTL Chi2 Matching value Map"); | ||
desc.add<edm::InputTag>("btlMatchTimeChi2Src", edm::InputTag("trackExtenderWithMTD", "btlMatchTimeChi2")) | ||
->setComment("BTL Chi2 Matching value Map"); | ||
desc.add<edm::InputTag>("etlMatchChi2Src", edm::InputTag("trackExtenderWithMTD", "etlMatchChi2")) | ||
->setComment("ETL Chi2 Matching value Map"); | ||
desc.add<edm::InputTag>("etlMatchTimeChi2Src", edm::InputTag("trackExtenderWithMTD", "etlMatchTimeChi2")) | ||
->setComment("ETL Chi2 Matching value Map"); | ||
desc.add<edm::InputTag>("mtdTimeSrc", edm::InputTag("trackExtenderWithMTD", "tmtd")) | ||
->setComment("MTD TIme value Map"); | ||
desc.add<edm::InputTag>("pathLengthSrc", edm::InputTag("trackExtenderWithMTD", "pathLength")) | ||
->setComment("MTD PathLength value Map"); | ||
desc.add<edm::InputTag>("trackAssocSrc", edm::InputTag("trackExtenderWithMTD", "generalTrackassoc")) | ||
->setComment("Association between General and MTD Extended tracks"); | ||
desc.add<edm::FileInPath>("trackPUID_mtdQualBDT_weights_file", | ||
edm::FileInPath("RecoMTD/TimingIDTools/data/clf4D_MTDquality_bo.xml")) | ||
->setComment("Track MTD quality BDT weights"); | ||
descriptions.add("trackPUIDMVAProducer", desc); | ||
} | ||
|
||
template <class H, class T> | ||
void TrackPUIDMVAProducer::fillValueMap(edm::Event& iEvent, | ||
const edm::Handle<H>& handle, | ||
const std::vector<T>& vec, | ||
const std::string& name) const { | ||
auto out = std::make_unique<edm::ValueMap<T>>(); | ||
typename edm::ValueMap<T>::Filler filler(*out); | ||
filler.insert(handle, vec.begin(), vec.end()); | ||
filler.fill(); | ||
iEvent.put(std::move(out), name); | ||
} | ||
|
||
void TrackPUIDMVAProducer::produce(edm::Event& ev, const edm::EventSetup& es) { | ||
edm::Handle<reco::TrackCollection> tracksH; | ||
ev.getByToken(tracksToken_, tracksH); | ||
const auto& tracks = *tracksH; | ||
|
||
edm::Handle<reco::TrackCollection> tracksMTDH; | ||
ev.getByToken(tracksMTDToken_, tracksMTDH); | ||
|
||
const auto& btlMatchChi2 = ev.get(btlMatchChi2Token_); | ||
const auto& btlMatchTimeChi2 = ev.get(btlMatchTimeChi2Token_); | ||
const auto& etlMatchChi2 = ev.get(etlMatchChi2Token_); | ||
const auto& etlMatchTimeChi2 = ev.get(etlMatchTimeChi2Token_); | ||
const auto& pathLength = ev.get(pathLengthToken_); | ||
const auto& trackAssoc = ev.get(trackAssocToken_); | ||
const auto& mtdTime = ev.get(mtdTimeToken_); | ||
|
||
std::vector<float> mvaOutRaw; | ||
|
||
//Loop over tracks collection | ||
for (unsigned int itrack = 0; itrack < tracks.size(); ++itrack) { | ||
const reco::Track& track = tracks[itrack]; | ||
const reco::TrackRef trackref(tracksH, itrack); | ||
|
||
if (trackAssoc[trackref] == -1) { | ||
mvaOutRaw.push_back(-1.); | ||
continue; | ||
} else { | ||
//---training performed only above 0.5 GeV | ||
if (track.pt() < 0.5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic number 0.5 should be named constant |
||
mvaOutRaw.push_back(-1.); | ||
else { | ||
const reco::TrackRef mtdTrackref = reco::TrackRef(tracksMTDH, trackAssoc[trackref]); | ||
mvaOutRaw.push_back(mva_( | ||
trackref, mtdTrackref, btlMatchChi2, btlMatchTimeChi2, etlMatchChi2, etlMatchTimeChi2, mtdTime, pathLength)); | ||
} | ||
} | ||
} | ||
fillValueMap(ev, tracksH, mvaOutRaw, mvaName); | ||
} | ||
|
||
//define this as a plug-in | ||
#include <FWCore/Framework/interface/MakerMacros.h> | ||
DEFINE_FWK_MODULE(TrackPUIDMVAProducer); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from RecoMTD.TimingIDTools.trackPUIDMVAProducer_cfi import * | ||
|
||
trackPUIDMVA = trackPUIDMVAProducer.clone() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here as well, it seems to me that having "MTD" would be useful to denote the nature of the running producer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like changes in this file should not be needed anymore.