Skip to content

Commit

Permalink
Merge pull request #145 from johnalison/mergeTo12_1_X
Browse files Browse the repository at this point in the history
Merge updates for 12_1_x and BTV HLT Dev
  • Loading branch information
soureek authored Dec 1, 2021
2 parents 03e8183 + ad4912f commit a408998
Show file tree
Hide file tree
Showing 108 changed files with 4,027,990 additions and 1,809 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.pyc
*.root
*.txt
*.*~
#*.*#
__init__.py
*.log

pydump.py
test/CRAB/crab_projects_*
5 changes: 5 additions & 0 deletions BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
<use name="JetMETCorrections/Objects"/>
<use name="RecoBTag/BTagTools"/>
<use name="RecoMuon/TrackingTools"/>
<use name="SimGeneral/HepPDTRecord"/>
<use name="fastjet"/>
<use name="fastjet-contrib"/>
<use name="SimDataFormats/Track"/>
<!--
<use name="SimDataFormats/JetMatching"/>
-->
<use name="SimTracker/TrackAssociation"/>
<use name="SimTracker/Records"/>
<use name="TrackingTools/TransientTrack"/>
Expand Down
57 changes: 57 additions & 0 deletions DQMStudy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Following are instructions for detailed DQM studies :

Setup the RecoBTag-PerformanceMeasurements pactkage as described in the README.md

# Make Target Reference BTagAnalyzer NTuple
```
cp RecoBTag/PerformanceMeasurements/python/defaults/Run3.py RecoBTag/PerformanceMeasurements/python/defaults/Run3Reference.py
[ edit Run3Refernce to point to the right file ]
cd RecoBTag/PerformanceMeasurements/test/
cmsRun runBTagAnalyzer_cfg.py defaults=Run3Reference runOnData=(True or False, depending on your needs)
cd -
```

# Make Target Reference BTagAnalyzer NTuple
```
cp RecoBTag/PerformanceMeasurements/python/defaults/Run3.py RecoBTag/PerformanceMeasurements/python/defaults/Run3Target.py
[ edit Run3Target to point to the right file ]
cd RecoBTag/PerformanceMeasurements/test/
cmsRun runBTagAnalyzer_cfg.py defaults=Run3Target runOnData=(True or False, depending on your needs)
cd -
```

### Process Ntuples To make ROOT file with histograms

Additional Software setup to process BTagNtuples for offline validation monitoring

```
git cms-merge-topic johnalison:MakePy3Bind11ParameterSetsIncludingCommandLineArguments
git clone -b BTVDQM [email protected]:patrickbryant/nTupleAnalysis.git
git clone -b 12_1_X [email protected]:johnalison/TriggerStudies.git
```

```
BTagAnalyzer TriggerStudies/NtupleAna/scripts/BTagAnalyzer_cfg.py \
--inputRAW path/to/target/BTagAnalyzer/Ntuple/JetTree.root \
--inputAOD path/to/reference/BTagAnalyzer/Ntuple/JetTree.root \
-o $PWD \
-y Run3 \
--histogramming 1 \
--histFile hists_Run3_offlineValidation.root \
--isMC \
--doTracks \
--jetDetailString matchedJet.allTaggers.innerPixHit.noInnerPixHit.DeepJetBins \
--pfJetName "" \
--nevents -1
```



### Make plots presentation
```
git clone -b 12_1_X [email protected]:johnalison/ROOTHelp.git
source ROOTHelp/setup.sh
source TriggerStudies/plotting/offlineDQMPlots.sh hists_Run3_offlineValidation.root hists_Run3_offlineValidation targetName [python3]
```
Outpus a slides in hists_Run3_offlineValidation directory
give the option python3 to actually make the plots
52 changes: 44 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
## Software setup

```
cmsrel CMSSW_10_6_20
cd CMSSW_10_6_20/src
cmsrel CMSSW_12_1_0_pre2
cd CMSSW_12_1_0_pre2/src
cmsenv
for bash
export CMSSW_GIT_REFERENCE=/cvmfs/cms.cern.ch/cmssw.git.daily
for tcsh
setenv CMSSW_GIT_REFERENCE /cvmfs/cms.cern.ch/cmssw.git.daily
git cms-init
git clone -b 10_6_X_UL2016_PreliminaryJECs --depth 1 https://github.com/cms-btv-pog/RecoBTag-PerformanceMeasurements.git RecoBTag/PerformanceMeasurements
git clone -b 12_1_X --recursive https://github.com/johnalison/RecoBTag-PerformanceMeasurements.git RecoBTag/PerformanceMeasurements
scram b -j8
scram b -j12
```

Expand All @@ -30,6 +29,7 @@ NOTE1: due to the structure of the preliminary JECs, there are 2 different "defa
This means in your crab configuration file, you will have to check which file you are running on, and pick the correct default set accordingly. As an example, one might do something like:

# Make Target Reference BTagAnalyzer NTuple
```
For MC samples:
...
Expand All @@ -51,14 +51,50 @@ else:

NOTE2: The preliminary JECs are only available for AK4PFCHS jets, and therefore you **_can not have any FatJet observables listed in you varGroup!_**. Otherwise the BTA will automatically assume you are running over FatJets and it will use the JECs included in the global tag, rather than in the local SQLite .db files!



To run the tests for integrating changes run:
# To run the tests for integrating changes run:

```
cd RecoBTag/PerformanceMeasurements/test/
./run_tests.sh
```


## BTagAnalyzer General information

The content of the output ntuple is by default empty and has to be configured according to your needs. The ```store*Variables``` options have been removed.
The new variable configuration can be customized in the file ```RecoBTag/PerformanceMeasurements/python/varGroups_cfi.py```.
New variables need also to be added (apart from adding them in the code) in ```RecoBTag/PerformanceMeasurements/python/variables_cfi.py```


## How to get the latest HLT configuration
For MC:
```
hltGetConfiguration /dev/CMSSW_12_0_0/GRun/V2 \
--full \
--offline \
--unprescale \
--mc \
--process HLT2 \
--globaltag auto:phase1_2021_realistic \
--max-events 10 \
> tmp.py
```
```
edmConfigDump tmp.py > HLT_dev_CMSSW_12_0_0_GRun_V3_configDump_MC.py
```
For data:
```
hltGetConfiguration /dev/CMSSW_12_0_0/GRun \
--full \
--offline \
--unprescale \
--data \
--process HLT2 \
--globaltag auto:run3_hlt \
--max-events 10 \
--customise HLTrigger/Configuration/customizeHLTforCMSSW.customiseFor2018Input \
> tmp_data.py
```
```
edmConfigDump tmp_data.py > HLT_dev_CMSSW_12_0_0_GRun_V3_configDump_Data.py
```
Binary file added data/PhaseIIFall17_V3_MC.db
Binary file not shown.
Binary file added data/PhaseIIFall17_V5b_MC.db
Binary file not shown.
198 changes: 198 additions & 0 deletions interface/AnalyzerBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#ifndef ANALYZERBASE_H
#define ANALYZERBASE_H

// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/Common/interface/RefToPtr.h"
#include "DataFormats/JetReco/interface/JetTracksAssociation.h"
#include "DataFormats/BTauReco/interface/CandIPTagInfo.h"
#include "DataFormats/BTauReco/interface/CandSoftLeptonTagInfo.h"
#include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h"
#include "DataFormats/BTauReco/interface/TrackIPTagInfo.h"
#include "DataFormats/Math/interface/deltaR.h"

#include "DataFormats/GeometrySurface/interface/Line.h"
#include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"

//#include "SimTracker/Records/interface/TrackAssociatorRecord.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"

#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "RecoBTag/PerformanceMeasurements/interface/CategoryFinder.h"

// reco track and vertex
#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
#include "DataFormats/BTauReco/interface/JetTag.h"
#include "DataFormats/JetReco/interface/JetCollection.h"
#include "DataFormats/JetReco/interface/Jet.h"

#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
#include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TFile.h"
#include "TTree.h"
#include "TVector3.h"
#include "TLorentzVector.h"
#include "Math/GenVector/VectorUtil.h"
#include "Math/GenVector/PxPyPzE4D.h"
#include "TGraphErrors.h"

#include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h"

#include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
#include "SimTracker/TrackHistory/interface/TrackCategories.h"
#include "SimTracker/TrackHistory/interface/TrackClassifier.h"
#include "DataFormats/BTauReco/interface/SoftLeptonTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepFlavourFeatures.h"
#include "DataFormats/BTauReco/interface/DeepDoubleXFeatures.h"
#include "DataFormats/BTauReco/interface/DeepBoostedJetFeatures.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
#include "DataFormats/PatCandidates/interface/MET.h"

// trigger
#include "DataFormats/Common/interface/TriggerResults.h"
#include "FWCore/Framework/interface/TriggerNamesService.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"

#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
#include "DataFormats/JetReco/interface/JetCollection.h"
#include "DataFormats/JetReco/interface/GenJetCollection.h"
#include "DataFormats/PatCandidates/interface/Jet.h"
#include "DataFormats/PatCandidates/interface/Muon.h"

// reconstruct IP
#include "TrackingTools/IPTools/interface/IPTools.h"

// Math clusters to TrackingParticles
#include "SimTracker/TrackerHitAssociation/interface/ClusterTPAssociation.h"

#include "RecoBTau/JetTagComputer/interface/GenericMVAJetTagComputer.h"
#include "RecoBTau/JetTagComputer/interface/GenericMVAJetTagComputerWrapper.h"
#include "RecoBTau/JetTagComputer/interface/JetTagComputer.h"
#include "RecoBTau/JetTagComputer/interface/JetTagComputerRecord.h"
#include "RecoBTag/SecondaryVertex/interface/CombinedSVComputer.h"
#include "RecoBTag/SecondaryVertex/interface/TrackKinematics.h"
#include "RecoBTag/SecondaryVertex/interface/V0Filter.h"
// #include "RecoBTag/ImpactParameter/plugins/IPProducer.h"
#include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h"

#include "TrackingTools/GeomPropagators/interface/AnalyticalImpactPointExtrapolator.h"

#include "FWCore/Utilities/interface/RegexMatch.h"
#include <boost/regex.hpp>

#include "RecoBTag/PerformanceMeasurements/interface/JetInfoBranches.h"
#include "RecoBTag/PerformanceMeasurements/interface/EventInfoBranches.h"
#include "RecoBTag/PerformanceMeasurements/interface/BookHistograms.h"
#include "RecoBTag/PerformanceMeasurements/interface/VariableParser.h"

#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
#include "FWCore/Common/interface/Provenance.h"
#include "PhysicsTools/SelectorUtils/interface/PFJetIDSelectionFunctor.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"

#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "TrackingTools/IPTools/interface/IPTools.h"

#include "fastjet/contrib/Njettiness.hh"

// #include "RecoBTag/SecondaryVertex/interface/CombinedSVSoftLeptonComputer.h"
#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepDoubleXTagInfo.h"
#include "DataFormats/BTauReco/interface/DeepBoostedJetTagInfo.h"



namespace analyzerBase{

//
// constants, enums and typedefs
//
typedef edm::View<pat::Jet> PatJetCollection;
typedef std::vector<edm::Ptr<pat::Jet> > PatJetPtrCollection;

//
// class declaration
//

struct orderByPt {
const std::string mCorrLevel;
orderByPt(const std::string& fCorrLevel) : mCorrLevel(fCorrLevel) {}
bool operator ()(edm::Ptr<pat::Jet> const& a, edm::Ptr<pat::Jet> const& b) {
if( mCorrLevel=="Uncorrected" )
return a->correctedJet("Uncorrected").pt() > b->correctedJet("Uncorrected").pt();
else
return a->pt() > b->pt();
}
};

class simPrimaryVertex {
public:
simPrimaryVertex(double x1,double y1,double z1):x(x1),y(y1),z(z1),ptsq(0),nGenTrk(0){};
double x,y,z;
HepMC::FourVector ptot;
//HepLorentzVector ptot;
double ptsq;
int nGenTrk;
std::vector<int> finalstateParticles;
std::vector<int> simTrackIndex;
std::vector<int> genVertex;
const reco::Vertex *recVtx;
};

const reco::TrackBaseRef toTrackRef(const reco::TrackRef & trk);
const reco::TrackBaseRef toTrackRef(const edm::Ptr<reco::Candidate> & cnd);

const math::XYZPoint & position(const reco::Vertex & sv);
const math::XYZPoint & position(const reco::VertexCompositePtrCandidate & sv);
const double xError(const reco::Vertex & sv);
const double xError(const reco::VertexCompositePtrCandidate & sv);
const double yError(const reco::Vertex & sv);
const double yError(const reco::VertexCompositePtrCandidate & sv);
const double zError(const reco::Vertex & sv);
const double zError(const reco::VertexCompositePtrCandidate & sv);
const double chi2(const reco::Vertex & sv);
const double chi2(const reco::VertexCompositePtrCandidate & sv);
const double ndof(const reco::Vertex & sv);
const double ndof(const reco::VertexCompositePtrCandidate & sv);
const unsigned int vtxTracks(const reco::Vertex & sv);
const unsigned int vtxTracks(const reco::VertexCompositePtrCandidate & sv);

// This is needed to get a TrackingParticle --> Cluster match (instead of Cluster-->TP) (only needed in processJets)
using P = std::pair<OmniClusterRef, TrackingParticleRef>;
bool compare(const P& i, const P& j);


enum JetFlavor {UNDEFINED, G, UD, S, C, GCC, CC, B, GBB, BB, LeptonicB, LeptonicB_C, TAU};

JetFlavor jet_flavour(const pat::Jet& jet,
const std::vector<reco::GenParticle>& gToBB,
const std::vector<reco::GenParticle>& gToCC,
const std::vector<reco::GenParticle>& neutrinosLepB,
const std::vector<reco::GenParticle>& neutrinosLepB_C,
const std::vector<reco::GenParticle>& alltaus,
bool usePhysForLightAndUndefined=false);

}
#endif
Loading

0 comments on commit a408998

Please sign in to comment.