Skip to content

Commit

Permalink
Merge pull request cms-sw#6 from nhanvtran/IsoAndFixes-91X
Browse files Browse the repository at this point in the history
updated submission scripts and isolation analyzer
  • Loading branch information
nhanvtran authored Apr 24, 2017
2 parents c2a15b1 + 757015c commit 22c13d0
Show file tree
Hide file tree
Showing 8 changed files with 462 additions and 3 deletions.
58 changes: 58 additions & 0 deletions NtupleProducer/interface/isoanalyzer.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef FASTPUPPI_NTUPLERPRODUCER_ISOANALYZER_HH
#define FASTPUPPI_NTUPLERPRODUCER_ISOANALYZER_HH
#include "combiner.hh"
#include "TFile.h"
#include "TTree.h"
#include <algorithm>
#include <iostream>
#include <fastjet/PseudoJet.hh>
#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"

class isoanalyzer {
public:
isoanalyzer(std::string iFile, int debug=0);
void setGenMuons(const reco::GenParticleCollection &iGenParticles,int iIndex);
void matchMuons(std::vector<combiner::Particle> &iParticle);
void computeIso(std::vector<combiner::Particle> &iParticle, float coneSize, std::string type);
// double genmatch(int iId, fastjet::PseudoJet &matchjet,std::vector < fastjet::PseudoJet > &genjets);
void clear();
inline void fill() {fFile->cd(); fTree->Fill();}
inline void write() {fFile->cd(); fTree->Write(); fFile->Write();}
private:
TFile *fFile;
TTree *fTree;
int fBase;
int fSize;
int fNVars;

float _gmu1_pt;
float _gmu1_eta;
float _gmu1_phi;
float _gmu2_pt;
float _gmu2_eta;
float _gmu2_phi;

TLorentzVector _mu1;
TLorentzVector _mu2;

float _mu1_pt;
float _mu1_eta;
float _mu1_phi;
float _mu1_iso_pf;
float _mu1_iso_tk;
float _mu1_iso_tkvtx;
float _mu1_iso_pup;

float _mu2_pt;
float _mu2_eta;
float _mu2_phi;
float _mu2_iso_pf;
float _mu2_iso_tk;
float _mu2_iso_tkvtx;
float _mu2_iso_pup;


int fDebug;
};
#endif
17 changes: 17 additions & 0 deletions NtupleProducer/plugins/NtupleProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "FastPUPPI/NtupleProducer/interface/combiner.hh"
#include "FastPUPPI/NtupleProducer/interface/metanalyzer.hh"
#include "FastPUPPI/NtupleProducer/interface/jetanalyzer.hh"
#include "FastPUPPI/NtupleProducer/interface/isoanalyzer.hh"
#include "FastPUPPI/NtupleProducer/interface/L1TPFUtils.h"
#include "FastPUPPI/NtupleProducer/interface/DiscretePF.h"

Expand Down Expand Up @@ -133,6 +134,7 @@ class NtupleProducer : public edm::EDProducer {
combiner * rawconnector_;
metanalyzer* metanalyzer_;
jetanalyzer* jetanalyzer_;
isoanalyzer* isoanalyzer_;
// discretized version
l1tpf_int::RegionMapper l1regions_;
l1tpf_int::PFAlgo l1pfalgo_;
Expand Down Expand Up @@ -217,9 +219,11 @@ NtupleProducer::NtupleProducer(const edm::ParameterSet& iConfig):
if (fOutputName.empty()) {
metanalyzer_ = nullptr;
jetanalyzer_ = nullptr;
isoanalyzer_ = nullptr;
} else {
metanalyzer_ = new metanalyzer("MetFile.root");
jetanalyzer_ = new jetanalyzer("JetFile.root");
isoanalyzer_ = new isoanalyzer("IsoFile.root");
}
produces<PFOutputCollection>("TK");
produces<PFOutputCollection>("RawCalo");
Expand Down Expand Up @@ -577,6 +581,18 @@ NtupleProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
jetanalyzer_->setJets(lPupCands,6);
jetanalyzer_->fill();
}

if (isoanalyzer_) {
isoanalyzer_->clear();
isoanalyzer_->setGenMuons(genParticles,1);
isoanalyzer_->matchMuons(lCands);
isoanalyzer_->computeIso(lCands , 0.3, "pf");
isoanalyzer_->computeIso(lTKCands , 0.3, "tk");
isoanalyzer_->computeIso(lTKVtxCands, 0.3, "tkvtx");
isoanalyzer_->computeIso(lPupCands , 0.3, "pup");
isoanalyzer_->fill();
}

}
void NtupleProducer::addPF(std::vector<combiner::Particle> &iCandidates,std::string iLabel,edm::Event& iEvent) {
corrCandidates_.reset( new PFOutputCollection );
Expand Down Expand Up @@ -770,6 +786,7 @@ NtupleProducer::endJob() {
connector_->write();
metanalyzer_->write();
jetanalyzer_->write();
isoanalyzer_->write();
fOutputFile->cd();
fTotalEvents->Write();
fOutputFile->Write();
Expand Down
7 changes: 5 additions & 2 deletions NtupleProducer/python/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ label=$4
cfg=$5

#cp $dir/runNtupleProducer_cfg_tmp.py .
echo "location = " $dir/$cfg
cp $dir/$cfg runNtupleProducer_cfg_tmp.py
sed "s@XXXX@$eosdir/$file@g" runNtupleProducer_cfg_tmp.py > runNtupleProducer_cfg.py
cd $dir
eval `scramv1 runtime -sh`
cd -
ls -lrt
cat runNtupleProducer_cfg.py
cmsRun runNtupleProducer_cfg.py
#mv ntuple.root $dir/F${label}$file
mv MetFile.root $dir/M${cfg}${label}$file
mv JetFile.root $dir/J${cfg}${label}$file
mv MetFile.root $dir/M_${label}$file
mv JetFile.root $dir/J_${label}$file
#mv puppi.root $dir/PUP${label}$file
rm puppi.root
2 changes: 1 addition & 1 deletion NtupleProducer/python/runNtupleProducer_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

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(-1))
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10))
process.MessageLogger.cerr.FwkReport.reportEvery = 10

process.source = cms.Source("PoolSource",
Expand Down
103 changes: 103 additions & 0 deletions NtupleProducer/python/runNtupleProducer_cfg_tmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import FWCore.ParameterSet.Config as cms

scenario = "D12"
#scenario = "D4T"
from Configuration.StandardSequences.Eras import eras

if "T" in scenario:
process = cms.Process("OUT", eras.Phase2C2_timing)
else:
process = cms.Process("OUT", eras.Phase2C2)

process.load('Configuration.StandardSequences.Services_cff')
if "D12" in scenario: process.load('Configuration.Geometry.GeometryExtended2023D12Reco_cff')
if "D11" in scenario: process.load('Configuration.Geometry.GeometryExtended2023D11Reco_cff')
if "D4" in scenario: process.load('Configuration.Geometry.GeometryExtended2023D4Reco_cff')
process.load('Configuration.StandardSequences.MagneticField_cff')
process.load('Configuration.StandardSequences.EndOfProcess_cff')
process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff')
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '')

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(-1))
process.MessageLogger.cerr.FwkReport.reportEvery = 10

process.source = cms.Source("PoolSource",
# replace 'myfile.root' with the source file you want to use
fileNames = cms.untracked.vstring(
'XXXX'
)
)

process.load('FastPUPPI.NtupleProducer.l1tPFCaloProducersFromOfflineRechits_cff')
process.load('FastPUPPI.NtupleProducer.l1tPFTkProducersFromOfflineTracks_cfi')

process.InfoOut = cms.EDProducer('NtupleProducer',
L1TrackTag = cms.InputTag('l1tPFTkProducersFromOfflineTracksStrips'),
EcalTPTag = cms.InputTag('l1tPFEcalProducerFromOfflineRechits','towers'),
HGEcalTPTag = cms.InputTag('l1tPFHGCalEEProducerFromOfflineRechits','towers'),
HcalTPTag = cms.InputTag('l1tPFHcalProducerFromOfflineRechits','towers'),
HGHcalTPTag = cms.InputTag('l1tPFHGCalFHProducerFromOfflineRechits','towers'),
BHHcalTPTag = cms.InputTag('l1tPFHGCalBHProducerFromOfflineRechits','towers'),
HFTPTag = cms.InputTag('l1tPFHFProducerFromOfflineRechits','towers'),
MuonTPTag = cms.InputTag('gmtStage2Digis','Muon'),
genParTag = cms.InputTag('genParticles'),
zeroSuppress = cms.bool(False),
corrector = cms.string("/afs/cern.ch/work/n/ntran/private/Correlator/analysis/go15-gpetruc/CMSSW_9_1_0_pre2/src/FastPUPPI/NtupleProducer/data/pion_eta_phi.root"),
corrector2 = cms.string("/afs/cern.ch/work/n/ntran/private/Correlator/analysis/go15-gpetruc/CMSSW_9_1_0_pre2/src/FastPUPPI/NtupleProducer/data/pion_eta_phi_res_old.root"),
ecorrector = cms.string("/afs/cern.ch/work/n/ntran/private/Correlator/analysis/go15-gpetruc/CMSSW_9_1_0_pre2/src/FastPUPPI/NtupleProducer/data/ecorr.root"),
trackres = cms.string("/afs/cern.ch/work/n/ntran/private/Correlator/analysis/go15-gpetruc/CMSSW_9_1_0_pre2/src/FastPUPPI/NtupleProducer/data/tkres.root"),
eleres = cms.string("/afs/cern.ch/work/n/ntran/private/Correlator/analysis/go15-gpetruc/CMSSW_9_1_0_pre2/src/FastPUPPI/NtupleProducer/data/eres.root"),
pionres = cms.string("/afs/cern.ch/work/n/ntran/private/Correlator/analysis/go15-gpetruc/CMSSW_9_1_0_pre2/src/FastPUPPI/NtupleProducer/data/pionres.root"),
trkPtCut = cms.double(YYYY),
metRate = cms.bool(ZZZZ),
etaCharged = cms.double(2.5),
puppiPtCut = cms.double(4.0),
vtxRes = cms.double(0.333),
debug = cms.untracked.int32(1),
outputName = cms.untracked.string("ntuple.root"),
)


process.l1Puppi = cms.Sequence(process.l1tPFCaloProducersFromOfflineRechits+process.l1tPFTkProducersFromOfflineTracksStrips)

process.p = cms.Path(process.l1Puppi * process.InfoOut )

if False: # turn on CMSSW downstream processing and output
process.InfoOut.outputName = ""; # turn off Ntuples

from RecoJets.JetProducers.ak4PFJets_cfi import ak4PFJets
process.ak4L1RawCalo = ak4PFJets.clone(src = 'InfoOut:RawCalo')
process.ak4L1Calo = ak4PFJets.clone(src = 'InfoOut:Calo')
process.ak4L1TK = ak4PFJets.clone(src = 'InfoOut:TK')
process.ak4L1PF = ak4PFJets.clone(src = 'InfoOut:PF')
process.ak4L1Puppi = ak4PFJets.clone(src = 'InfoOut:Puppi')

from RecoMET.METProducers.PFMET_cfi import pfMet
pfMet.calculateSignificance = False
process.l1MetRawCalo = pfMet.clone(src = "InfoOut:RawCalo")
process.l1MetCalo = pfMet.clone(src = "InfoOut:Calo")
process.l1MetTK = pfMet.clone(src = "InfoOut:TK")
process.l1MetPF = pfMet.clone(src = "InfoOut:PF")
process.l1MetPuppi = pfMet.clone(src = "InfoOut:Puppi")

process.l1JetMET = cms.Sequence(
process.ak4L1RawCalo + process.ak4L1Calo + process.ak4L1TK + process.ak4L1PF + process.ak4L1Puppi +
process.l1MetRawCalo + process.l1MetCalo + process.l1MetTK + process.l1MetPF + process.l1MetPuppi
)

process.p = cms.Path(process.l1Puppi * process.InfoOut * process.l1JetMET )

process.out = cms.OutputModule("PoolOutputModule",
fileName = cms.untracked.string("l1pf_out.root"),
outputCommands = cms.untracked.vstring("drop *",
"keep *_gmtStage2Digis_*_*",
"keep *_genParticles_*_*",
"keep *_ak4GenJetsNoNu_*_*",
"keep *_genMetTrue_*_*",
"keep *_*_*_OUT",
)
)
process.e = cms.EndPath(process.out)
60 changes: 60 additions & 0 deletions NtupleProducer/python/submit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/python
import sys
import os
import argparse

parser = argparse.ArgumentParser(description='Submit some dang jobs')
parser.add_argument('-v','--verbose', dest='verbose', action='store_true',
help='verbosity')
parser.add_argument('--submit', dest='submit', action='store_true',
help='submit')
parser.add_argument('--metRate', dest='metRate', action='store_true',
help='metRate')
parser.add_argument('--sample', dest='sample', default='dy_140',
help='data sample to run on')
parser.add_argument('--tkptcut', dest='tkptcut', default='2.0',
help='data sample to run on')

args = parser.parse_args()

def main():

print args.sample;
if args.verbose: print "verbose!"

tplFileIn = 'runNtupleProducer_cfg_tmp.py'
tplFileOut = 'runNtupleProducer_cfg_tmpO.py'

cursample = args.sample

samples = {};
samples['dy_140'] = '/store/relval/CMSSW_9_1_0_pre1/RelValZMM_14/GEN-SIM-RECO/PU25ns_90X_upgrade2023_realistic_v9_D12PU140-v1/00000';
samples['tt_140'] = '/store/relval/CMSSW_9_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-RECO/PU25ns_90X_upgrade2023_realistic_v9_D11PU140-v1/00000';
samples['qcdmu_140'] = '/store/relval/CMSSW_9_1_0_pre1/RelValQCD_Pt-20toInf_MuEnrichedPt15_14TeV/GEN-SIM-RECO/PU25ns_90X_upgrade2023_realistic_v9_D12PU140-v1/00000'
samples['mugun_140'] = '/store/relval/CMSSW_9_1_0_pre1/RelValSingleMuPt1Extended/GEN-SIM-RECO/PU25ns_90X_upgrade2023_realistic_v9_D12PU140-v1/00000'
oput = os.listdir('/eos/cms'+samples[cursample]);
# print oput

sMetRate = "False"
if args.metRate: sMetRate = "True"
sTkPtCut = args.tkptcut;

fIn = open(tplFileIn, "r") ;
fOut = open(tplFileOut, "wr");
for line in fIn:
newline = line.replace('YYYY',sTkPtCut)
newline2 = newline.replace('ZZZZ',sMetRate)
fOut.write(newline2[:-1] + "\n");
print newline2[:-1]

for i,n in enumerate(oput):
label = cursample+"_"+sTkPtCut
if args.metRate: label += "_metrate"
command = "bsub -q cmscaf1nh -o out.%%J run.sh %s %s $PWD %s %s" % (samples[cursample],n,label,tplFileOut)
print args.submit, args.sample, label, command
if args.submit: os.system(command);

##---------------------------------------
if __name__ == '__main__':
main();
##---------------------------------------
22 changes: 22 additions & 0 deletions NtupleProducer/python/submitpy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#!/bin/bash

#python submit.py --sample dy_140 --tkptcut 2.0 --submit
#python submit.py --sample tt_140 --tkptcut 2.0 --submit
#python submit.py --sample qcdmu_140 --tkptcut 2.0 --submit
#python submit.py --sample mugun_140 --tkptcut 2.0 --metRate --submit

python submit.py --sample dy_140 --tkptcut 2.5 --submit
python submit.py --sample tt_140 --tkptcut 2.5 --submit
python submit.py --sample qcdmu_140 --tkptcut 2.5 --submit
python submit.py --sample mugun_140 --tkptcut 2.5 --metRate --submit

python submit.py --sample dy_140 --tkptcut 3.0 --submit
python submit.py --sample tt_140 --tkptcut 3.0 --submit
python submit.py --sample qcdmu_140 --tkptcut 3.0 --submit
python submit.py --sample mugun_140 --tkptcut 3.0 --metRate --submit

python submit.py --sample dy_140 --tkptcut 0.0 --submit
python submit.py --sample tt_140 --tkptcut 0.0 --submit
python submit.py --sample qcdmu_140 --tkptcut 0.0 --submit
python submit.py --sample mugun_140 --tkptcut 0.0 --metRate --submit
Loading

0 comments on commit 22c13d0

Please sign in to comment.