Skip to content

Commit

Permalink
Merge pull request cms-sw#44 from gpetruc/106X
Browse files Browse the repository at this point in the history
Update to latest L1PF_10_6_1p2_X
  • Loading branch information
gpetruc committed Sep 19, 2019
2 parents 97695f1 + 2928227 commit 07c7e19
Show file tree
Hide file tree
Showing 14 changed files with 686 additions and 64 deletions.
2 changes: 1 addition & 1 deletion NtupleProducer/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<use name="DataFormats/JetReco"/>
<use name="DataFormats/METReco"/>
<use name="RecoMET/METAlgorithms"/>
<use name="FastSimulation/BaseParticlePropagator"/>
<use name="CommonTools/BaseParticlePropagator"/>
<use name="DataFormats/ParticleFlowReco"/>
<use name="SimDataFormats/CaloAnalysis"/>
<use name="DataFormats/L1THGCal"/>
Expand Down
39 changes: 26 additions & 13 deletions NtupleProducer/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Basic Instructions

```
cmsrel CMSSW_10_6_0_pre4
cd CMSSW_10_6_0_pre4/src
cmsrel CMSSW_10_6_1_patch2
cd CMSSW_10_6_1_patch2/src
cmsenv
git cms-init
git cms-checkout-topic -u p2l1pfp:L1PF_10_6_X
git cms-checkout-topic -u p2l1pfp:L1PF_10_6_1p2_X
# scripts
git clone git@github.com:p2l1pfp/FastPUPPI.git -b 106X
Expand Down Expand Up @@ -34,12 +34,11 @@ cmsRun runRespNTupler.py

NB:
* For single particle add `goGun()` at the end of the script, remove it for jets.
* For 93X samples, add a `goOld()` at the end of the script to select 93X calibrations (note that these are not updated at the moment)

To run the ntuplizer over many files, from within `NtupleProducer/python` do for instance:
```
./scripts/prun.sh runRespNTupler.py --v3 TTbar_PU0 TTbar_PU0
./scripts/prun.sh runRespNTupler.py --v3 SinglePion_PU0 SinglePion_PU0 --inline-customize 'goGun()'
./scripts/prun.sh runRespNTupler.py --v0 TTbar_PU0 TTbar_PU0.v0
./scripts/prun.sh runRespNTupler.py --v0 ParticleGun_PU0 ParticleGun_PU0.v0 --inline-customize 'goGun()'
```
Look into the prun.sh script to check the paths to the input files and the corresponding options.

Expand All @@ -53,7 +52,7 @@ This produces both a response ntuple like the one for the runRespNTupler.py, but
To run the ntuplizer over many files do for instance:

```
./scripts/prun.sh runPerformanceNTuple.py TTbar_PU200 TTbar_PU200
./scripts/prun.sh runPerformanceNTuple.py --v0 TTbar_PU200 TTbar_PU200.v0 --inline-customize 'addCHS();addTKs()';
```

The third step is to produce the plots from the ntuple. The plotting scripts are in:
Expand All @@ -62,18 +61,32 @@ The third step is to produce the plots from the ntuple. The plotting scripts are
1) For single particle or jet response:

```
python scripts/respPlots.py respTupleNew_SinglePion_PU0.root plots_dir -w l1pfnew -p pion
python scripts/respPlots.py respTupleNew_TTbar_PU200.root plots_dir -w l1pfnew -p jet
python scripts/respPlots.py respTupleNew_SinglePion_PU0.v0.root plots_dir -w l1pfw -p pion
python scripts/respPlots.py respTupleNew_TTbar_PU200.v0.root plots_dir -w l1pf -p jet
```

2) For jet, MET and HT plots, the first step is to produce JECs
```
python scripts/makeJecs.py perfNano_TTbar_PU200.root -A -o jecs.root
python scripts/makeJecs.py perfNano_TTbar_PU200.v0.root -A -o jecs.root
```
then you can use `jetHtSuite.py` to make the plots

```
python scripts/jetHtSuite.py perfNano_TTbar_PU200.root perfNano_SingleNeutrino_PU200.root plots_dir -w oldcomp,newcomp -v ht
python scripts/jetHtSuite.py perfNano_TTbar_PU200.root perfNano_SingleNeutrino_PU200.root plots_dir -w oldcomp,newcomp -v met
python scripts/jetHtSuite.py perfNano_TTbar_PU200.root perfNano_SingleNeutrino_PU200.root plots_dir -w oldcomp,newcomp -v jet4
python scripts/jetHtSuite.py perfNano_TTbar_PU200.root perfNano_SingleNeutrino_PU200.root plots_dir -w l1pfpu -v ht
python scripts/jetHtSuite.py perfNano_TTbar_PU200.root perfNano_SingleNeutrino_PU200.root plots_dir -w l1pfpu -v met
python scripts/jetHtSuite.py perfNano_TTbar_PU200.root perfNano_SingleNeutrino_PU200.root plots_dir -w l1pfpu -v jet4
```

3) For object multiplicitly studies:

Plot the number of elements in a given detector (`Barrel`, `HGCal`, `HGCalNoTK`, `HF`):
```
python scripts/objMultiplicityPlot.py perfTuple_TTbar_PU200.root -d Barrel plotdir
```
* note: you should add `goRegional()` to the options in `runPerformanceNTuple.py` if you want to get meaningful numbers per region and not just overall


Print out the multiplicities needed to avoid truncation at a given confidence level
```
python scripts/objMultiplicityPlot.py perfTuple_TTbar_PU200.root -d HF --cl 0.95
```
24 changes: 24 additions & 0 deletions NtupleProducer/plugins/ResponseNTuplizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,27 @@ class ResponseNTuplizer : public edm::one::EDAnalyzer<edm::one::SharedResources,
}
static std::string typecode() { assert(false); }
};
template<typename T> struct
CopyVecT {
std::string name;
edm::EDGetTokenT<T> token;
T buffer;
CopyVecT(const edm::InputTag &tag, edm::EDGetTokenT<T> tok) :
name(tag.label()+tag.instance()),
token(tok),
buffer() {}
void get(const edm::Event &iEv) {
edm::Handle<T> handle;
iEv.getByToken(token, handle);
buffer = *handle;
}
void makeBranches(TTree *tree) {
tree->Branch((name).c_str(), &buffer);
}
};
std::vector<CopyT<unsigned>> copyUInts_;
std::vector<CopyT<float>> copyFloats_;
std::vector<CopyVecT<std::vector<unsigned>>> copyVecUInts_;
float bZ_;
};
template<> std::string ResponseNTuplizer::CopyT<unsigned>::typecode() { return "i"; }
Expand Down Expand Up @@ -278,6 +297,9 @@ ResponseNTuplizer::ResponseNTuplizer(const edm::ParameterSet& iConfig) :
for (const edm::InputTag &tag : iConfig.getParameter<std::vector<edm::InputTag>>("copyFloats")) {
copyFloats_.emplace_back(tag, consumes<float>(tag));
}
for (const edm::InputTag &tag : iConfig.getParameter<std::vector<edm::InputTag>>("copyVecUInts")) {
copyVecUInts_.emplace_back(tag, consumes<std::vector<unsigned>>(tag));
}
}

ResponseNTuplizer::~ResponseNTuplizer() { }
Expand All @@ -292,6 +314,7 @@ ResponseNTuplizer::beginJob()
}
for (auto & c : copyUInts_) c.makeBranches(tree_);
for (auto & c : copyFloats_) c.makeBranches(tree_);
for (auto & c : copyVecUInts_) c.makeBranches(tree_);
}


Expand Down Expand Up @@ -332,6 +355,7 @@ ResponseNTuplizer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSet
}
for (auto & c : copyUInts_) c.get(iEvent);
for (auto & c : copyFloats_) c.get(iEvent);
for (auto & c : copyVecUInts_) c.get(iEvent);
mc_.id = 998; tree_->Fill(); // so that we write only one per event


Expand Down
2 changes: 1 addition & 1 deletion NtupleProducer/python/runInputs104X.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"keep *_hgcalConcentratorProducer*_*_IN",
#"keep *_hgcalBackEndLayer1Producer*_*_IN",
"keep *_hgcalBackEndLayer2Producer*_*_IN",
"keep *_hgcalTowerMapProducer_*_IN",
#"keep *_hgcalTowerMapProducer_*_IN",
"keep *_hgcalTowerProducer_*_IN",
# muons
"keep *_simGmtStage2Digis__*",
Expand Down
112 changes: 99 additions & 13 deletions NtupleProducer/python/runPerformanceNTuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
process.load("FWCore.MessageLogger.MessageLogger_cfi")
process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True), allowUnscheduled = cms.untracked.bool(False) )
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(100))
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1))
process.MessageLogger.cerr.FwkReport.reportEvery = 1

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring('file:/eos/cms/store/cmst3/user/gpetrucc/l1tr/105X/NewInputs104X/010319/TTbar_PU200/inputs104X_TTbar_PU200_job1.root'),
fileNames = cms.untracked.vstring(
'file:/eos/cms/store/cmst3/user/gpetrucc/l1tr/105X/NewInputs104X/010319/TTbar_PU200/inputs104X_TTbar_PU200_job1.root',
),
duplicateCheckMode = cms.untracked.string("noDuplicateCheck"),
skipBadFiles = cms.untracked.bool(True),
inputCommands = cms.untracked.vstring("keep *",
Expand Down Expand Up @@ -56,7 +58,8 @@
process.genMetBarrelTrue
)

def monitorPerf(label, tag, makeResp=True, makeRespSplit=True, makeJets=True, makeMET=True, makeCentralMET=True, makeBarrelMET=True):
def monitorPerf(label, tag, makeResp=True, makeRespSplit=True, makeJets=True, makeMET=True, makeCentralMET=True, makeBarrelMET=True,
makeInputMultiplicities=False, makeOutputMultiplicities=False):
def _add(name, what):
setattr(process, name, what)
process.extraPFStuff.add(what)
Expand Down Expand Up @@ -88,6 +91,19 @@ def _add(name, what):
_add('barrel'+label, cms.EDFilter("CandPtrSelector", src = cms.InputTag(tag), cut = cms.string("abs(eta) < 1.5")))
_add('met'+label+'Barrel', pfMet.clone(src = 'barrel'+label, calculateSignificance = False))
setattr(process.l1pfmetBarrelTable.mets, label, cms.InputTag('met'+label+'Barrel'))
if makeInputMultiplicities:
D = tag.split(":")[0] # l1pfProducer[Barrel,HGCal,HF] usually
I = tag.split(":")[1] # Calo, EmCalo, TK, or Mu, usually
for X in ["tot","max"]:
process.ntuple.copyUInts.append( "%s:%sNL1%s" % (D,X,I))
process.ntuple.copyVecUInts.append( "%s:vecNL1%s" % (D,I))
if makeOutputMultiplicities:
D = tag.split(":")[0] # l1pfProducer[Barrel,HGCal,HF] usually
P = tag.split(":")[1] # PF or Puppi, usually
for O in [""] + "Charged Neutral ChargedHadron NeutralHadron Photon Electron Muon".split():
for X in ["tot","max"]:
process.ntuple.copyUInts.append( "%s:%sNL1%s%s" % (D,X,P,O))
process.ntuple.copyVecUInts.append( "%s:vecNL1%s%s" % (D,P,O))

process.ntuple = cms.EDAnalyzer("ResponseNTuplizer",
genJets = cms.InputTag("ak4GenJetsNoNu"),
Expand All @@ -101,7 +117,9 @@ def _add(name, what):
),
copyUInts = cms.VInputTag(),
copyFloats = cms.VInputTag(),
copyVecUInts = cms.VInputTag(),
)

process.extraPFStuff.add(process.pfTracksFromL1Tracks)


Expand Down Expand Up @@ -133,15 +151,92 @@ def _add(name, what):
monitorPerf("L1PF", "l1pfCandidates:PF")
monitorPerf("L1Puppi", "l1pfCandidates:Puppi")

for D in ['Barrel','HF','HGCal','HGCalNoTK']:
monitorPerf("L1%sCalo"%D,"l1pfProducer%s:Calo"%D, makeResp=False, makeRespSplit=False, makeJets=False, makeMET=False,
makeCentralMET=False, makeBarrelMET=False, makeInputMultiplicities=True)
monitorPerf("L1%sEmCalo"%D,"l1pfProducer%s:EmCalo"%D, makeResp=False, makeRespSplit=False, makeJets=False, makeMET=False,
makeCentralMET=False, makeBarrelMET=False, makeInputMultiplicities=True)
monitorPerf("L1%sTK"%D,"l1pfProducer%s:TK"%D, makeResp=False, makeRespSplit=False, makeJets=False, makeMET=False,
makeCentralMET=False, makeBarrelMET=False, makeInputMultiplicities=True)
monitorPerf("L1%sMu"%D,"l1pfProducer%s:Mu"%D, makeResp=False, makeRespSplit=False, makeJets=False, makeMET=False,
makeCentralMET=False, makeBarrelMET=False, makeInputMultiplicities=True)

monitorPerf("L1%sPF"%D,"l1pfProducer%s:PF"%D, makeResp=False, makeRespSplit=False, makeJets=False, makeMET=False,
makeCentralMET=False, makeBarrelMET=False, makeOutputMultiplicities=True)
monitorPerf("L1%sPuppi"%D,"l1pfProducer%s:Puppi"%D, makeResp=False, makeRespSplit=False, makeJets=False, makeMET=False,
makeCentralMET=False, makeBarrelMET=False, makeOutputMultiplicities=True)

# define regions
def goRegional():
process.l1pfProducerBarrel.regions = cms.VPSet(
cms.PSet(
etaBoundaries = cms.vdouble(-1.5, -0.75, 0, 0.75, 1.5),
etaExtra = cms.double(0.25),
phiExtra = cms.double(0.25),
phiSlices = cms.uint32(9)
)
)
process.l1pfProducerHGCalNoTK.regions = cms.VPSet(
cms.PSet(
etaBoundaries = cms.vdouble(-3, -2.5),
etaExtra = cms.double(0.25),
phiExtra = cms.double(0.25),
phiSlices = cms.uint32(9)
),
cms.PSet(
etaBoundaries = cms.vdouble(2.5, 3),
etaExtra = cms.double(0.25),
phiExtra = cms.double(0.25),
phiSlices = cms.uint32(9)
)
)
process.l1pfProducerHGCal.regions = cms.VPSet(
cms.PSet(
etaBoundaries = cms.vdouble(-2.5, -1.5),
etaExtra = cms.double(0.25),
phiExtra = cms.double(0.25),
phiSlices = cms.uint32(9)
),
cms.PSet(
etaBoundaries = cms.vdouble(1.5, 2.5),
etaExtra = cms.double(0.25),
phiExtra = cms.double(0.25),
phiSlices = cms.uint32(9)
)
)
process.l1pfProducerHF.regions = cms.VPSet(
cms.PSet(
etaBoundaries = cms.vdouble(-5, -4.5, -4, -3.5, -3),
etaExtra = cms.double(0.25),
phiExtra = cms.double(0.25),
phiSlices = cms.uint32(9)
),
cms.PSet(
etaBoundaries = cms.vdouble(3, 3.5, 4, 4.5, 5),
etaExtra = cms.double(0.25),
phiExtra = cms.double(0.25),
phiSlices = cms.uint32(9)
)
)

process.runPF.associate(process.extraPFStuff)
# to check available tags:
#process.content = cms.EDAnalyzer("EventContentAnalyzer")
process.p = cms.Path(
process.runPF +
process.ntuple +
process.ntuple + #process.content +
process.l1pfjetTable +
process.l1pfmetTable + process.l1pfmetCentralTable + process.l1pfmetBarrelTable
)
process.TFileService = cms.Service("TFileService", fileName = cms.string("perfTuple.root"))

# for full debug:
#process.out = cms.OutputModule("PoolOutputModule",
# fileName = cms.untracked.string("debugPF.root"),
# SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring("p"))
# )
#process.end = cms.EndPath(process.out)

process.outnano = cms.OutputModule("NanoAODOutputModule",
fileName = cms.untracked.string("perfNano.root"),
SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring('p')),
Expand Down Expand Up @@ -300,12 +395,3 @@ def goGun(calib=1):
def goMT(nthreads=2):
process.options.numberOfThreads = cms.untracked.uint32(nthreads)
process.options.numberOfStreams = cms.untracked.uint32(0)
def goOld():
process.pfClustersFromL1EGClusters.corrector = "L1Trigger/Phase2L1ParticleFlow/data/emcorr_barrel_93X.root"
process.pfClustersFromHGC3DClustersEM.corrector = "L1Trigger/Phase2L1ParticleFlow/data/emcorr_hgc_old3d_93X.root"
process.pfClustersFromCombinedCalo.hadCorrector = "L1Trigger/Phase2L1ParticleFlow/data/hadcorr_93X.root"
process.pfClustersFromHGC3DClusters.corrector = "L1Trigger/Phase2L1ParticleFlow/data/hadcorr_HGCal3D_STC_93X.root"
process.pfClustersFromCombinedCaloHCal.hadCorrector = "L1Trigger/Phase2L1ParticleFlow/data/hadcorr_barrel_93X.root"
process.pfClustersFromCombinedCaloHF.hadCorrector = "L1Trigger/Phase2L1ParticleFlow/data/hfcorr_93X.root"


70 changes: 70 additions & 0 deletions NtupleProducer/python/scripts/correlateRespTuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python
import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True
ROOT.gROOT.SetBatch(True)

import os
from sys import argv

from collections import defaultdict

from PhysicsTools.HeppyCore.utils.deltar import *
from PhysicsTools.HeppyCore.statistics.tree import *


from optparse import OptionParser
parser = OptionParser("%(prog) -w what infile1 infile2 ")
parser.add_option("--id", "--mc_id", dest="mc_id", type=int, nargs=1, default=0, help="MC ")
parser.add_option("-w", "--what", dest="what", action="append", default=[])
parser.add_option("-o", "--out", dest="out", default="correlatedRespTuple.root")
options, args = parser.parse_args()
nfiles = len(args)

fout = ROOT.TFile(options.out, "RECREATE")
otree = Tree("t","t","F")
for x in "run","lumi","event","mc_id": otree.var(x,int);
for x in "pt","eta","phi": otree.var("mc_"+x);
for j in range(nfiles):
for x in options.what: otree.var("%s_%d" % (x,j))

events = {}

for ia, arg in enumerate(args):
tfile = ROOT.TFile(arg)
tree = tfile.Get("ntuple/tree")
for e in tree:
if e.mc_id != options.mc_id: continue
evid = e.run, e.lumi, e.event
if evid not in events:
if ia != 0: continue
events[evid] = {}
pid = tuple(map(int, (e.mc_pt*100, e.mc_eta*100, e.mc_phi*100)))
if ia == 0:
events[evid][pid] = [ [ getattr(e,x) for x in options.what ] ]
else:
if pid not in events[evid]: continue
events[evid][pid].append( [ getattr(e,x) for x in options.what ] )

print "Found %d events" % len(events)

otree.fill("mc_id", options.mc_id)
for evid, pids in sorted(events.iteritems()):
otree.fill("run", evid[0])
otree.fill("lumi", evid[1])
otree.fill("event", evid[2])
for pid, data in pids.iteritems():
otree.fill("mc_pt", 0.01*pid[0])
otree.fill("mc_eta", 0.01*pid[1])
otree.fill("mc_phi", 0.01*pid[2])
for j, row in enumerate(data):
for (x,v) in zip(options.what,row):
otree.fill("%s_%d" % (x,j), v)
otree.tree.Fill()
print ""
print "Output entries: %d" % otree.tree.GetEntries()
fout.cd()
fout.WriteTObject(otree.tree)
fout.Close()



0 comments on commit 07c7e19

Please sign in to comment.