Skip to content

Commit

Permalink
Merge pull request #188 from susy2015/varriedUpdates
Browse files Browse the repository at this point in the history
Varied updates

merging changes given that the travis failures are in the scram build and cannot be replicated on sl7
  • Loading branch information
pastika authored Feb 13, 2020
2 parents d6c0594 + 457b315 commit ad32a08
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 53 deletions.
21 changes: 7 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language: cpp

env:
global:
- DOCKER_CONTAINER: cmssw/slc6-base:latest
- DOCKER_CONTAINER: aperloff/cms-cvmfs-docker:latest
- GH_REPO_NAME: TopTagger
- GH_ORG_NAME: susy2015
- DOXYFILE: $TRAVIS_BUILD_DIR/.Doxyfile
Expand All @@ -16,26 +16,19 @@ branches:
- /.*/

before_install:
- sudo apt-get -qq update
- sudo apt-get install -qq autofs attr gdb git uuid-dev uuid fuse
- wget --no-check-certificate https://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest_all.deb
- sudo dpkg -i cvmfs-release-latest_all.deb
- sudo apt-get update
- sudo apt-get install -qq cvmfs cvmfs-config-default
- sudo cvmfs_config setup
- sudo echo "CVMFS_HTTP_PROXY=\"DIRECT\"" | sudo tee /etc/cvmfs/default.local > /dev/null
- sudo echo CVMFS_REPOSITORIES=cms.cern.ch | sudo tee -a /etc/cvmfs/default.local > /dev/null
- sudo service autofs restart
- cvmfs_config probe
- sudo cvmfs_config chksetup
- sudo docker pull $DOCKER_CONTAINER

compiler:
- gcc

script:
- chmod +x $TRAVIS_BUILD_DIR/.travis/runTests.sh
- sudo docker run -v /cvmfs:/cvmfs -v $TRAVIS_BUILD_DIR:$TRAVIS_BUILD_DIR $DOCKER_CONTAINER $TRAVIS_BUILD_DIR/.travis/runTests.sh $TRAVIS_BUILD_DIR
- echo "UID" $(id -u)
- echo "GID" $(id -g)
- pwd
- ls -la
- ls -la ..
- sudo docker run -it -P --device /dev/fuse --cap-add SYS_ADMIN -e CVMFS_MOUNTS="cms.cern.ch oasis.opensciencegrid.org" -e MY_UID=$(id -u) -e MY_GID=$(id -g) -v $TRAVIS_BUILD_DIR:$TRAVIS_BUILD_DIR $DOCKER_CONTAINER $TRAVIS_BUILD_DIR/.travis/runTests.sh $TRAVIS_BUILD_DIR

after_success:
- if [ "$TRAVIS_BRANCH" = "$TARGET_BRANCH" ] || [ ! -z $TRAVIS_TAG ]; then if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sudo apt-get install doxygen doxygen-doc doxygen-latex doxygen-gui graphviz; fi; fi
Expand Down
8 changes: 7 additions & 1 deletion .travis/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ CMSSW_VERSION=CMSSW_10_2_9
set -ex

TRAVIS_BUILD_DIR=$1
cd $TRAVIS_BUILD_DIR/..
echo "UID" $(id -u)
echo "GID" $(id -g)
pwd
ls -la
cd /home/cmsuser/
pwd
ls -la
export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch
export SCRAM_ARCH=slc6_amd64_gcc630
export CMSSW_GIT_REFERENCE=/cvmfs/cms.cern.ch/cmssw.git/
Expand Down
10 changes: 10 additions & 0 deletions TopTagger/interface/TTMOpenCVMVA.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

#include <string>
#include <vector>
#include <memory>

#ifdef SHOTTOPTAGGER_DO_OPENCV
#include "opencv/cv.h"
#include "opencv/ml.h"
#endif

namespace ttUtility
{
class MVAInputCalculator;
}

/**
*This module implements an interface to the OpenCV randomforest package for filtering top candidates. This module can either pass entries directly into the final top list, or filter entries out of the final top list if they do not pass the selection criteria.
*
Expand All @@ -34,6 +40,10 @@ class TTMOpenCVMVA : public TTModule
cv::Ptr<cv::ml::RTrees> treePtr_;
std::vector<std::string> vars_;

//variable calclator
std::unique_ptr<ttUtility::MVAInputCalculator> varCalculator_;
std::vector<float> values_;

#endif

public:
Expand Down
6 changes: 3 additions & 3 deletions TopTagger/interface/TopTaggerUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,14 @@ namespace ttUtility
}

template<typename TLVCONTAINERTYPE = std::vector<TLorentzVector>, typename INTCONTAINERTYPE = std::vector<int> >
std::pair<std::vector<TLorentzVector>, std::vector<std::vector<const TLorentzVector*>>> GetTopdauGenLVecFromNano(const TLVCONTAINERTYPE& genDecayLVec, const INTCONTAINERTYPE& genDecayPdgIdVec, const INTCONTAINERTYPE& genDecayStatFlag, const INTCONTAINERTYPE& genDecayMomIdxVec)
std::pair<std::vector<TLorentzVector>, std::vector<std::vector<const TLorentzVector*>>> GetTopdauGenLVecFromNano(const TLVCONTAINERTYPE& genDecayLVec, const INTCONTAINERTYPE& genDecayPdgIdVec, const INTCONTAINERTYPE& genDecayStatFlag, const INTCONTAINERTYPE& genDecayMomIdxVec, const int targedId = 6, const unsigned int targetDaughters = 3)
{
std::pair<std::vector<TLorentzVector>, std::vector<std::vector<const TLorentzVector*>>> returnVal;
for(unsigned iTop=0; iTop < genDecayLVec.size(); ++iTop)
{
int pdgId = genDecayPdgIdVec[iTop];
int statFlag = genDecayStatFlag[iTop]; //statFlag bits 0x2100 mean last copy and from hard process
if(abs(pdgId) == 6 && ((statFlag & 0x2100) == 0x2100))
if(abs(pdgId) == targedId && ((statFlag & 0x2100) == 0x2100))
{
//This is a top
//Search for daughters of this gen particle
Expand All @@ -746,7 +746,7 @@ namespace ttUtility
}
}

if(daughters.size() >= 3)
if(daughters.size() >= targetDaughters)
{
//hadronic top found
returnVal.first.push_back(genDecayLVec[iTop]);
Expand Down
36 changes: 19 additions & 17 deletions TopTagger/python/TopTaggerProducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(self, cfgName="TopTagger.cfg", cfgWD=".", suffix=None, saveAK8=Fals

if self.saveCandidates:
self.suffixResolved = "Candidate" + self.suffix
else:
self.suffixResolved = self.suffix

def beginJob(self):
pass
Expand All @@ -51,33 +53,33 @@ def endJob(self):
def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
self.isFirstEventOfFile = True
self.out = wrappedOutputTree
self.out.branch("ResolvedTop%s_pt"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved, limitedPrecision=12)
self.out.branch("ResolvedTop%s_eta"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved, limitedPrecision=12)
self.out.branch("ResolvedTop%s_phi"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved, limitedPrecision=12)
self.out.branch("ResolvedTop%s_mass"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved, limitedPrecision=12)
self.out.branch("ResolvedTop%s_discriminator"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved, limitedPrecision=12)
self.out.branch("ResolvedTop%s_pt"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_eta"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_phi"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_mass"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_discriminator"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_j1Idx"%self.suffixResolved, "I", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_j2Idx"%self.suffixResolved, "I", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_j3Idx"%self.suffixResolved, "I", lenVar="nResolvedTop%s"%self.suffixResolved)
self.out.branch("ResolvedTop%s_genMatch"%self.suffixResolved, "O", lenVar="nResolvedTop%s"%self.suffixResolved)

if self.saveSFAndSyst:
self.out.branch("ResolvedTop%s_sf"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved, limitedPrecision=12)
self.out.branch("ResolvedTop%s_sf"%self.suffixResolved, "F", lenVar="nResolvedTop%s"%self.suffixResolved)
for syst in self.systToSave:
self.out.branch("ResolvedTop%s_syst_%s"%(self.suffixResolved, syst), "F", lenVar="nResolvedTop%s"%self.suffixResolved, limitedPrecision=12)
self.out.branch("ResolvedTop%s_syst_%s"%(self.suffixResolved, syst), "F", lenVar="nResolvedTop%s"%self.suffixResolved)

if self.saveAK8:
self.out.branch("MergedTop%s_pt"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedTop%s_eta"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedTop%s_phi"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedTop%s_mass"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedTop%s_discriminator"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedTop%s_pt"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix)
self.out.branch("MergedTop%s_eta"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix)
self.out.branch("MergedTop%s_phi"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix)
self.out.branch("MergedTop%s_mass"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix)
self.out.branch("MergedTop%s_discriminator"%self.suffix, "F", lenVar="nMergedTop%s"%self.suffix)

self.out.branch("MergedW%s_pt"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedW%s_eta"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedW%s_phi"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedW%s_mass"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedW%s_discriminator"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix, limitedPrecision=12)
self.out.branch("MergedW%s_pt"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix)
self.out.branch("MergedW%s_eta"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix)
self.out.branch("MergedW%s_phi"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix)
self.out.branch("MergedW%s_mass"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix)
self.out.branch("MergedW%s_discriminator"%self.suffix, "F", lenVar="nMergedW%s"%self.suffix)


def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
Expand Down
45 changes: 28 additions & 17 deletions TopTagger/src/TTMOpenCVMVA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ void TTMOpenCVMVA::getParameters(const cfg::CfgDocument* cfgDoc, const std::stri
{
THROW_TTEXCEPTION("Incorrect number of variables specified!!! " + std::to_string(treePtr_->getVarCount()) + "expected " + std::to_string(vars_.size()) + " found.");
}

//load variables
varCalculator_.reset(new ttUtility::TrijetInputCalculator());
//map variables
varCalculator_->mapVars(vars_);
values_.resize(vars_.size());
varCalculator_->setPtr(values_.data());

#else
//Mark variables unused to suppress warnings
(void)cfgDoc;
Expand All @@ -86,28 +94,31 @@ void TTMOpenCVMVA::run(TopTaggerResults& ttResults)
{
//Prepare data from top candidate (this code is shared with training tuple producer)
//Perhaps one day the intermediate map can be bypassed ...
std::map<std::string, double> varMap = ttUtility::createMVAInputs(topCand, csvThreshold_);
// std::map<std::string, double> varMap = ttUtility::createMVAInputs(topCand, csvThreshold_);

//Construct opencv data matrix for prediction
cv::Mat inputData(vars_.size(), 1, 5); //the last 5 is for CV_32F var type

//populate opencv data matrix based on desired input variables
for(unsigned int i = 0; i < vars_.size(); ++i)
{
inputData.at<float>(i, 0) = varMap[vars_[i]];
}

//predict value
double discriminator = treePtr_->predict(inputData);
topCand.setDiscriminator(discriminator);

//Check number of b-tagged jets in the top
bool passBrequirements = maxNbInTop_ < 0 || topCand.getNBConstituents(csvThreshold_, bEtaCut_) <= maxNbInTop_;

//place in final top list if it passes the threshold
if(discriminator > discriminator_ && passBrequirements)
if(varCalculator_->calculateVars(topCand, 0))
{
tops.push_back(&topCand);
//populate opencv data matrix based on desired input variables
for(unsigned int i = 0; i < values_.size(); ++i)
{
inputData.at<float>(i, 0) = values_[i];
}

//predict value
double discriminator = treePtr_->predict(inputData);
topCand.setDiscriminator(discriminator);

//Check number of b-tagged jets in the top
bool passBrequirements = maxNbInTop_ < 0 || topCand.getNBConstituents(csvThreshold_, bEtaCut_) <= maxNbInTop_;

//place in final top list if it passes the threshold
if(discriminator > discriminator_ && passBrequirements)
{
tops.push_back(&topCand);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion TopTagger/src/TopTaggerUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ namespace ttUtility
{
if(j_m_lab_[i] >= 0) *(basePtr_ + j_m_lab_[i] + len_*iCand) = top_constituents[i]->p().M();
if(j_CSV_lab_[i] >= 0) *(basePtr_ + j_CSV_lab_[i] + len_*iCand) = top_constituents[i]->getBTagDisc();
if(j_QGL_[i] >= 0) *(basePtr_ + j_QGL_lab_[i] + len_*iCand) = relu(top_constituents[i]->getExtraVar("qgLikelihood"));
if(j_QGL_lab_[i] >= 0) *(basePtr_ + j_QGL_lab_[i] + len_*iCand) = relu(top_constituents[i]->getExtraVar("qgLikelihood"));
if(j_qgPtD_lab_[i] >= 0) *(basePtr_ + j_qgPtD_lab_[i] + len_*iCand) = relu(top_constituents[i]->getExtraVar("qgPtD"));
if(j_qgAxis1_lab_[i] >= 0) *(basePtr_ + j_qgAxis1_lab_[i] + len_*iCand) = relu(top_constituents[i]->getExtraVar("qgAxis1"));
if(j_qgAxis2_lab_[i] >= 0) *(basePtr_ + j_qgAxis2_lab_[i] + len_*iCand) = relu(top_constituents[i]->getExtraVar("qgAxis2"));
Expand Down

0 comments on commit ad32a08

Please sign in to comment.