Skip to content

Commit

Permalink
Merge pull request cms-sw#16559 from makortel/mtvMva
Browse files Browse the repository at this point in the history
Monitor track selection MVAs in MultiTrackValidator
  • Loading branch information
cmsbuild authored Nov 15, 2016
2 parents 9cd784b + e10a1e6 commit 35c450c
Show file tree
Hide file tree
Showing 15 changed files with 458 additions and 30 deletions.
4 changes: 3 additions & 1 deletion DQMServices/ClientConfig/interface/DQMGenericClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class DQMGenericClient : public DQMEDHarvester
struct CDOption
{
std::string name;
bool ascending;
};

void computeEfficiency(DQMStore::IBooker& ibooker,
Expand Down Expand Up @@ -91,7 +92,8 @@ class DQMGenericClient : public DQMEDHarvester
void makeCumulativeDist(DQMStore::IBooker& ibooker,
DQMStore::IGetter& igetter,
const std::string& startDir,
const std::string& cdName);
const std::string& cdName,
bool ascending=true);

void limitedFit(MonitorElement * srcME, MonitorElement * meanME, MonitorElement * sigmaME);

Expand Down
19 changes: 14 additions & 5 deletions DQMServices/ClientConfig/plugins/DQMGenericClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,14 @@ DQMGenericClient::DQMGenericClient(const ParameterSet& pset)
args.push_back(*iToken);
}

if ( args.size() != 1 ) {
if ( args.size() == 0 || args.size() > 2) {
LogInfo("DQMGenericClient") << "Wrong input to cdCmds\n";
continue;
}

CDOption opt;
opt.name = args[0];
opt.ascending = args.size() == 2 ? (args[1] != "descending") : true;

cdOptions_.push_back(opt);
}
Expand All @@ -296,6 +297,7 @@ DQMGenericClient::DQMGenericClient(const ParameterSet& pset)
{
CDOption opt;
opt.name = cdSet->getUntrackedParameter<string>("name");
opt.ascending = cdSet->getUntrackedParameter<bool>("ascending",true);

cdOptions_.push_back(opt);
}
Expand Down Expand Up @@ -369,7 +371,7 @@ void DQMGenericClient::dqmEndJob(DQMStore::IBooker & ibooker, DQMStore::IGetter
for ( vector<CDOption>::const_iterator cdOption = cdOptions_.begin();
cdOption != cdOptions_.end(); ++cdOption )
{
makeCumulativeDist(ibooker, igetter, dirName, cdOption->name);
makeCumulativeDist(ibooker, igetter, dirName, cdOption->name, cdOption->ascending);
}

for ( vector<EfficOption>::const_iterator efficOption = efficOptions_.begin();
Expand Down Expand Up @@ -788,7 +790,7 @@ void DQMGenericClient::normalizeToEntries(DQMStore::IBooker& ibooker, DQMStore::
return;
}

void DQMGenericClient::makeCumulativeDist(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, const std::string& startDir, const std::string& cdName)
void DQMGenericClient::makeCumulativeDist(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter, const std::string& startDir, const std::string& cdName, bool ascending)
{
if ( ! igetter.dirExists(startDir) ) {
if ( verbose_ >= 2 || (verbose_ == 1 && !isWildcardUsed_) ) {
Expand Down Expand Up @@ -822,8 +824,15 @@ void DQMGenericClient::makeCumulativeDist(DQMStore::IBooker& ibooker, DQMStore::

int n_bins = cd->GetNbinsX() + 1;

for (int i = 1; i <= n_bins; i++) {
cd->SetBinContent(i,cd->GetBinContent(i) + cd->GetBinContent(i-1));
if(ascending) {
for (int i = 1; i <= n_bins; i++) {
cd->SetBinContent(i,cd->GetBinContent(i) + cd->GetBinContent(i-1));
}
}
else {
for (int i = n_bins-1; i >= 0; i--) { // n_bins points to the overflow bin
cd->SetBinContent(i,cd->GetBinContent(i) + cd->GetBinContent(i+1));
}
}

return;
Expand Down
16 changes: 13 additions & 3 deletions Validation/RecoTrack/interface/MTVHistoProducerAlgoForTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MTVHistoProducerAlgoForTracker {
void bookRecoPVAssociationHistos(DQMStore::IBooker& ibook);
void bookRecodEdxHistos(DQMStore::IBooker& ibook);
void bookSeedHistos(DQMStore::IBooker& ibook);

void bookMVAHistos(DQMStore::IBooker& ibook, size_t nMVAs);

void fill_generic_simTrack_histos(const TrackingParticle::Vector&,const TrackingParticle::Point& vertex, int bx);
void fill_simTrackBased_histos(int numSimTracks);
Expand All @@ -57,7 +57,9 @@ class MTVHistoProducerAlgoForTracker {
int numVertices,
double dR,
const math::XYZPoint *pvPosition,
const TrackingVertex::LorentzVector *simPVPosition);
const TrackingVertex::LorentzVector *simPVPosition,
const std::vector<float>& mvas,
unsigned int selectsLoose, unsigned int selectsHP);

void fill_recoAssociated_simTrack_histos(int count,
const reco::GenParticle& tp,
Expand All @@ -80,7 +82,9 @@ class MTVHistoProducerAlgoForTracker {
int numVertices,
int nSimHits,
double sharedFraction,
double dR);
double dR,
const std::vector<float>& mvas,
unsigned int selectsLoose, unsigned int selectsHP);

void fill_dedx_recoTrack_histos(int count, const edm::RefToBase<reco::Track>& trackref, const std::vector< const edm::ValueMap<reco::DeDxData> *>& v_dEdx);

Expand Down Expand Up @@ -150,6 +154,7 @@ class MTVHistoProducerAlgoForTracker {
double minVertcount, maxVertcount; int nintVertcount;
double minTracks, maxTracks; int nintTracks;
double minPVz, maxPVz; int nintPVz;
double minMVA, maxMVA; int nintMVA;

const bool doSeedPlots_;

Expand Down Expand Up @@ -206,6 +211,11 @@ class MTVHistoProducerAlgoForTracker {

std::vector<MonitorElement*> h_reco_seedingLayerSet, h_assoc2_seedingLayerSet, h_looper_seedingLayerSet, h_pileup_seedingLayerSet;

std::vector<std::vector<MonitorElement*> > h_reco_mva, h_assoc2_mva;
std::vector<std::vector<MonitorElement*> > h_reco_mvacut, h_assoc_mvacut, h_assoc2_mvacut, h_simul2_mvacut;
std::vector<std::vector<MonitorElement*> > h_reco_mva_hp, h_assoc2_mva_hp;
std::vector<std::vector<MonitorElement*> > h_reco_mvacut_hp, h_assoc_mvacut_hp, h_assoc2_mvacut_hp, h_simul2_mvacut_hp;

// dE/dx
// in the future these might become an array
std::vector<std::vector<MonitorElement*>> h_dedx_estim;
Expand Down
6 changes: 6 additions & 0 deletions Validation/RecoTrack/interface/MultiTrackValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MultiTrackValidator : public DQMEDAnalyzer, protected MultiTrackValidatorB
const bool dodEdxPlots_;
const bool doPVAssociationPlots_;
const bool doSeedPlots_;
const bool doMVAPlots_;
std::unique_ptr<MTVHistoProducerAlgoForTracker> histoProducerAlgo_;

private:
Expand All @@ -51,6 +52,11 @@ class MultiTrackValidator : public DQMEDAnalyzer, protected MultiTrackValidatorB
edm::EDGetTokenT<edm::ValueMap<unsigned int> > tpNPixelLayersToken_;
edm::EDGetTokenT<edm::ValueMap<unsigned int> > tpNStripStereoLayersToken_;


using MVACollection = std::vector<float>;
using QualityMaskCollection = std::vector<unsigned char>;
std::vector<std::vector<std::tuple<edm::EDGetTokenT<MVACollection>, edm::EDGetTokenT<QualityMaskCollection> > > > mvaQualityCollectionTokens_;

std::string dirName_;

bool useGsf;
Expand Down
102 changes: 100 additions & 2 deletions Validation/RecoTrack/plugins/MultiTrackValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/transform.h"

#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
Expand Down Expand Up @@ -40,6 +41,12 @@ using namespace std;
using namespace edm;

typedef edm::Ref<edm::HepMCProduct, HepMC::GenParticle > GenParticleRef;
namespace {
bool trackSelected(unsigned char mask, unsigned char qual) {
return mask & 1<<qual;
}

}

MultiTrackValidator::MultiTrackValidator(const edm::ParameterSet& pset):
MultiTrackValidatorBase(pset,consumesCollector()),
Expand All @@ -53,6 +60,7 @@ MultiTrackValidator::MultiTrackValidator(const edm::ParameterSet& pset):
dodEdxPlots_(pset.getUntrackedParameter<bool>("dodEdxPlots")),
doPVAssociationPlots_(pset.getUntrackedParameter<bool>("doPVAssociationPlots")),
doSeedPlots_(pset.getUntrackedParameter<bool>("doSeedPlots")),
doMVAPlots_(pset.getUntrackedParameter<bool>("doMVAPlots")),
simPVMaxZ_(pset.getUntrackedParameter<double>("simPVMaxZ"))
{
ParameterSet psetForHistoProducerAlgo = pset.getParameter<ParameterSet>("histoProducerAlgoBlock");
Expand All @@ -76,6 +84,22 @@ MultiTrackValidator::MultiTrackValidator(const edm::ParameterSet& pset):
vertexAssociatorToken_ = consumes<reco::VertexToTrackingVertexAssociator>(pset.getUntrackedParameter<edm::InputTag>("vertexAssociator"));
}

if(doMVAPlots_) {
mvaQualityCollectionTokens_.resize(labelToken.size());
auto mvaPSet = pset.getUntrackedParameter<edm::ParameterSet>("mvaLabels");
for(size_t iIter=0; iIter<labelToken.size(); ++iIter) {
edm::EDConsumerBase::Labels labels;
labelsForToken(labelToken[iIter], labels);
if(mvaPSet.exists(labels.module)) {
mvaQualityCollectionTokens_[iIter] = edm::vector_transform(mvaPSet.getUntrackedParameter<std::vector<std::string> >(labels.module),
[&](const std::string& tag) {
return std::make_tuple(consumes<MVACollection>(edm::InputTag(tag, "MVAValues")),
consumes<QualityMaskCollection>(edm::InputTag(tag, "QualityMasks")));
});
}
}
}

tpSelector = TrackingParticleSelector(pset.getParameter<double>("ptMinTP"),
pset.getParameter<double>("minRapidityTP"),
pset.getParameter<double>("maxRapidityTP"),
Expand Down Expand Up @@ -226,6 +250,7 @@ void MultiTrackValidator::bookHistograms(DQMStore::IBooker& ibook, edm::Run cons
histoProducerAlgo_->bookRecoHistos(ibook);
if (dodEdxPlots_) histoProducerAlgo_->bookRecodEdxHistos(ibook);
if (doPVAssociationPlots_) histoProducerAlgo_->bookRecoPVAssociationHistos(ibook);
if (doMVAPlots_) histoProducerAlgo_->bookMVAHistos(ibook, mvaQualityCollectionTokens_[www].size());
}

if(doSeedPlots_) {
Expand Down Expand Up @@ -535,6 +560,10 @@ void MultiTrackValidator::analyze(const edm::Event& event, const edm::EventSetup
v_dEdx.push_back(dEdx2Handle.product());
}

std::vector<const MVACollection *> mvaCollections;
std::vector<const QualityMaskCollection *> qualityMaskCollections;
std::vector<float> mvaValues;

int w=0; //counter counting the number of sets of histograms
for (unsigned int ww=0;ww<associators.size();ww++){
for (unsigned int www=0;www<label.size();www++, w++){ // need to increment w here, since there are many continues in the loop body
Expand Down Expand Up @@ -603,6 +632,24 @@ void MultiTrackValidator::analyze(const edm::Event& event, const edm::EventSetup
reco::RecoToSimCollection const & recSimColl = *recSimCollP;
reco::SimToRecoCollection const & simRecColl = *simRecCollP;

// read MVA collections
if(doMVAPlots_ && !mvaQualityCollectionTokens_[www].empty()) {
edm::Handle<MVACollection> hmva;
edm::Handle<QualityMaskCollection> hqual;
for(const auto& tokenTpl: mvaQualityCollectionTokens_[www]) {
event.getByToken(std::get<0>(tokenTpl), hmva);
event.getByToken(std::get<1>(tokenTpl), hqual);

mvaCollections.push_back(hmva.product());
qualityMaskCollections.push_back(hqual.product());
if(mvaCollections.back()->size() != trackCollection.size()) {
throw cms::Exception("Configuration") << "Inconsistency in track collection and MVA sizes. Track collection " << www << " has " << trackCollection.size() << " tracks, whereas the MVA " << (mvaCollections.size()-1) << " for it has " << mvaCollections.back()->size() << " entries. Double-check your configuration.";
}
if(qualityMaskCollections.back()->size() != trackCollection.size()) {
throw cms::Exception("Configuration") << "Inconsistency in track collection and quality mask sizes. Track collection " << www << " has " << trackCollection.size() << " tracks, whereas the quality mask " << (qualityMaskCollections.size()-1) << " for it has " << qualityMaskCollections.back()->size() << " entries. Double-check your configuration.";
}
}
}

// ########################################################
// fill simulation histograms (LOOP OVER TRACKINGPARTICLES)
Expand Down Expand Up @@ -681,6 +728,8 @@ void MultiTrackValidator::analyze(const edm::Event& event, const edm::EventSetup
// fill RecoAssociated SimTracks' histograms
// ##############################################
const reco::Track* matchedTrackPointer=0;
unsigned int selectsLoose = mvaCollections.size();
unsigned int selectsHP = mvaCollections.size();
if(simRecColl.find(tpr) != simRecColl.end()){
auto const & rt = simRecColl[tpr];
if (rt.size()!=0) {
Expand All @@ -690,6 +739,32 @@ void MultiTrackValidator::analyze(const edm::Event& event, const edm::EventSetup
LogTrace("TrackValidator") << "TrackingParticle #" << st
<< " with pt=" << sqrt(momentumTP.perp2())
<< " associated with quality:" << rt.begin()->second <<"\n";

if(doMVAPlots_) {
// for each MVA we need to take the value of the track
// with largest MVA value (for the cumulative histograms)
//
// also identify the first MVA that possibly selects any
// track matched to this TrackingParticle, separately
// for loose and highPurity qualities
for(size_t imva=0; imva<mvaCollections.size(); ++imva) {
const auto& mva = *(mvaCollections[imva]);
const auto& qual = *(qualityMaskCollections[imva]);

auto iMatch = rt.begin();
float maxMva = mva[iMatch->first.key()];
for(; iMatch!=rt.end(); ++iMatch) {
auto itrk = iMatch->first.key();
maxMva = std::max(maxMva, mva[itrk]);

if(selectsLoose >= imva && trackSelected(qual[itrk], reco::TrackBase::loose))
selectsLoose = imva;
if(selectsHP >= imva && trackSelected(qual[itrk], reco::TrackBase::highPurity))
selectsHP = imva;
}
mvaValues.push_back(maxMva);
}
}
}
}else{
LogTrace("TrackValidator")
Expand All @@ -708,7 +783,8 @@ void MultiTrackValidator::analyze(const edm::Event& event, const edm::EventSetup
int nSimLayers = nLayers_tPCeff[tpr];
int nSimPixelLayers = nPixelLayers_tPCeff[tpr];
int nSimStripMonoAndStereoLayers = nStripMonoAndStereoLayers_tPCeff[tpr];
histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,tp,momentumTP,vertexTP,dxySim,dzSim,dxyPVSim,dzPVSim,nSimHits,nSimLayers,nSimPixelLayers,nSimStripMonoAndStereoLayers,matchedTrackPointer,puinfo.getPU_NumInteractions(), dR, thePVposition, theSimPVPosition);
histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,tp,momentumTP,vertexTP,dxySim,dzSim,dxyPVSim,dzPVSim,nSimHits,nSimLayers,nSimPixelLayers,nSimStripMonoAndStereoLayers,matchedTrackPointer,puinfo.getPU_NumInteractions(), dR, thePVposition, theSimPVPosition, mvaValues, selectsLoose, selectsHP);
mvaValues.clear();
sts++;
if(matchedTrackPointer)
asts++;
Expand Down Expand Up @@ -818,8 +894,28 @@ void MultiTrackValidator::analyze(const edm::Event& event, const edm::EventSetup
<< " NOT associated to any TrackingParticle" << "\n";
}

// set MVA values for this track
// take also the indices of first MVAs to select by loose and
// HP quality
unsigned int selectsLoose = mvaCollections.size();
unsigned int selectsHP = mvaCollections.size();
if(doMVAPlots_) {
for(size_t imva=0; imva<mvaCollections.size(); ++imva) {
const auto& mva = *(mvaCollections[imva]);
const auto& qual = *(qualityMaskCollections[imva]);
mvaValues.push_back(mva[i]);

if(selectsLoose >= imva && trackSelected(qual[i], reco::TrackBase::loose))
selectsLoose = imva;
if(selectsHP >= imva && trackSelected(qual[i], reco::TrackBase::highPurity))
selectsHP = imva;
}
}

double dR=dR_trk[i];
histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track, ttopo, bs.position(), thePVposition, theSimPVPosition, isSimMatched,isSigSimMatched, isChargeMatched, numAssocRecoTracks, puinfo.getPU_NumInteractions(), nSimHits, sharedFraction, dR);
histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track, ttopo, bs.position(), thePVposition, theSimPVPosition, isSimMatched,isSigSimMatched, isChargeMatched, numAssocRecoTracks, puinfo.getPU_NumInteractions(), nSimHits, sharedFraction, dR, mvaValues, selectsLoose, selectsHP);
mvaValues.clear();

if(doSummaryPlots_) {
h_reco_coll[ww]->Fill(www);
if(isSimMatched) {
Expand Down Expand Up @@ -873,6 +969,8 @@ void MultiTrackValidator::analyze(const edm::Event& event, const edm::EventSetup
//nrecHit_vs_nsimHit_rec2sim[w]->Fill(track->numberOfValidHits(), (int)(simhits.end()-simhits.begin() ));

} // End of for(View<Track>::size_type i=0; i<trackCollection.size(); ++i){
mvaCollections.clear();
qualityMaskCollections.clear();

histoProducerAlgo_->fill_trackBased_histos(w,at,rT,st);
// Fill seed-specific histograms
Expand Down
4 changes: 3 additions & 1 deletion Validation/RecoTrack/plugins/MultiTrackValidatorGenPs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ void MultiTrackValidatorGenPs::analyze(const edm::Event& event, const edm::Event
v_dEdx.push_back(dEdx2Handle.product());
}

std::vector<float> mvaDummy;

int w=0; //counter counting the number of sets of histograms
for (unsigned int www=0;www<label.size();www++){
//
Expand Down Expand Up @@ -348,7 +350,7 @@ void MultiTrackValidatorGenPs::analyze(const edm::Event& event, const edm::Event


double dR=0;//fixme: plots vs dR not implemented for now
histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track, ttopo, bs.position(), nullptr, nullptr, isGenMatched,isSigGenMatched, isChargeMatched, numAssocRecoTracks, puinfo.getPU_NumInteractions(), nSimHits, sharedFraction,dR);
histoProducerAlgo_->fill_generic_recoTrack_histos(w,*track, ttopo, bs.position(), nullptr, nullptr, isGenMatched,isSigGenMatched, isChargeMatched, numAssocRecoTracks, puinfo.getPU_NumInteractions(), nSimHits, sharedFraction, dR, mvaDummy, 0, 0);

// dE/dx
if (dodEdxPlots_) histoProducerAlgo_->fill_dedx_recoTrack_histos(w,track, v_dEdx);
Expand Down
6 changes: 4 additions & 2 deletions Validation/RecoTrack/plugins/TrackerSeedValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ void TrackerSeedValidator::analyze(const edm::Event& event, const edm::EventSetu
const auto& nPixelLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nPixelLayers>(nlayers_tPCeff_ptrs));
const auto& nStripMonoAndStereoLayers_tPCeff = *(std::get<TrackingParticleNumberOfLayers::nStripMonoAndStereoLayers>(nlayers_tPCeff_ptrs));

std::vector<float> mvaDummy;

int w=0;
for (unsigned int ww=0;ww<associators.size();ww++){
edm::Handle<reco::TrackToTrackingParticleAssociator> theAssociator;
Expand Down Expand Up @@ -273,7 +275,7 @@ void TrackerSeedValidator::analyze(const edm::Event& event, const edm::EventSetu

double dR=0;//fixme: plots vs dR not implemented for now
histoProducerAlgo_->fill_recoAssociated_simTrack_histos(w,*tp,tp->momentum(),tp->vertex(),dxySim,dzSim,0,0,nSimHits,nSimLayers,nSimPixelLayers,nSimStripMonoAndStereoLayers,
matchedTrackPointer,puinfo.getPU_NumInteractions(),dR, nullptr, nullptr);
matchedTrackPointer,puinfo.getPU_NumInteractions(),dR, nullptr, nullptr, mvaDummy, 0, 0);

sts++;
if (matchedTrackPointer) asts++;
Expand Down Expand Up @@ -361,7 +363,7 @@ void TrackerSeedValidator::analyze(const edm::Event& event, const edm::EventSetu
histoProducerAlgo_->fill_generic_recoTrack_histos(w,*trackFromSeed, ttopo, bs.position(), nullptr, nullptr, isSimMatched,isSigSimMatched,
isChargeMatched, numAssocSeeds,
puinfo.getPU_NumInteractions(),
nSimHits, sharedFraction, dR);
nSimHits, sharedFraction, dR, mvaDummy, 0, 0);

//Fill other histos
try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
maxPVz = cms.double(60),
nintPVz = cms.int32(120),

# MVA distributions
minMVA = cms.double(-1),
maxMVA = cms.double(1),
nintMVA = cms.int32(100),

#
#parameters for resolution plots
ptRes_rangeMin = cms.double(-0.1),
Expand Down
Loading

0 comments on commit 35c450c

Please sign in to comment.