Skip to content

Commit

Permalink
Merge pull request #36 from michelif/micheli_TnPPlusSmearing
Browse files Browse the repository at this point in the history
Implementing selection for Tag and Probe + fixing bug in logic
  • Loading branch information
mgouzevi committed Feb 22, 2018
2 parents 415d72a + 58ae747 commit 3b045b8
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 18 deletions.
2 changes: 1 addition & 1 deletion interface/bbggTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class bbggTools{
std::vector<flashgg::DiPhotonCandidate> DiPhotonKinematicSelection(vector<flashgg::DiPhotonCandidate> diphoCol, bool DoMassCut = 0);
std::vector<flashgg::DiPhotonCandidate> DiPhotonIDSelection( std::vector<flashgg::DiPhotonCandidate> diphoCol);
std::vector<flashgg::DiPhotonCandidate> GetDiPhotonsInCategory( std::vector<std::pair<flashgg::DiPhotonCandidate, int > > SelectedDiPhotons, int category );
std::vector<std::pair<flashgg::DiPhotonCandidate, int > > EvaluatePhotonIDs( std::vector<flashgg::DiPhotonCandidate> diphoCol, unsigned int doCustomID = 0);
std::vector<std::pair<flashgg::DiPhotonCandidate, int > > EvaluatePhotonIDs( std::vector<flashgg::DiPhotonCandidate> diphoCol, unsigned int doCustomID = 0, unsigned int doTnP = 0);
bool passHgg76XPreselection(const flashgg::DiPhotonCandidate * dipho, std::map<std::string, int> myTriggersResults);
bool passHggPreselection(const flashgg::DiPhotonCandidate * dipho);
bool passPreselectionTnP2016(const flashgg::DiPhotonCandidate * dipho, std::map<std::string, int> myTriggersResults);
Expand Down
24 changes: 18 additions & 6 deletions plugins/bbggTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ inputTagJets_( iConfig.getParameter<std::vector<edm::InputTag> >( "inputTagJets"
phCorrEE = iConfig.getUntrackedParameter<std::vector<double > >("phCorrEE");

is2016 = iConfig.getUntrackedParameter<unsigned int>("is2016", def_is2016);
doTnP = iConfig.getUntrackedParameter<unsigned int>("doTnP", def_doTnP);
doTnP = iConfig.getUntrackedParameter<unsigned int>("doTnP",def_doTnP);

BenchNum = iConfig.getUntrackedParameter<unsigned int>("benchmark", 0);

//photon selection parameters
Expand Down Expand Up @@ -500,6 +501,9 @@ inputTagJets_( iConfig.getParameter<std::vector<edm::InputTag> >( "inputTagJets"
myTriggers = iConfig.getUntrackedParameter<std::vector<std::string> >("myTriggers", def_myTriggers);
triggerToken_ = consumes<edm::TriggerResults>( iConfig.getParameter<edm::InputTag>( "triggerTag" ) );
// METToken_ = consumes<edm::View<pat::MET> >(iConfig.getParameter<edm::InputTag>("metTag"));
if (is2016){
triggerToken_ = consumes<edm::TriggerResults>( edm::InputTag("TriggerResults", "", "HLT" )) ;
}

rhoToken_ = consumes<double>( iConfig.getParameter<edm::InputTag>( "rhoTag" ) );
vertexToken_ = consumes<edm::View<reco::Vertex> >( iConfig.getParameter<edm::InputTag> ( "VertexTag" ) );
Expand Down Expand Up @@ -794,6 +798,7 @@ void
Handle<View<flashgg::DiPhotonCandidate> > diPhotons;
iEvent.getByToken( diPhotonToken_, diPhotons );


const double rhoFixedGrd = globVar_->valueOf(globVar_->indexOf("rho"));
tools_.setRho(rhoFixedGrd);
const double nPVs = globVar_->valueOf(globVar_->indexOf("nvtx"));
Expand Down Expand Up @@ -947,7 +952,7 @@ void
if(doTnP && is2016){
Handle<edm::TriggerResults> trigResults;
iEvent.getByToken(triggerToken_, trigResults);
const edm::TriggerNames &names = iEvent.triggerNames(*trigResults);
const edm::TriggerNames &names = iEvent.triggerNames(*trigResults);
myTriggerResults = tools_.TriggerSelection(myTriggers, names, trigResults);
PreSelDipho = tools_.DiPhotonPreselectionTnP2016( diphotonCollection, myTriggerResults);
}
Expand All @@ -958,13 +963,19 @@ void


//Kinematic selection
std::vector<flashgg::DiPhotonCandidate> KinDiPhoton = tools_.DiPhotonKinematicSelection( PreSelDipho, 1);
if(DEBUG) std::cout << "[bbggTree::analyze] Number of kinematic-selected diphotons: " << KinDiPhoton.size() << std::endl;
std::vector<flashgg::DiPhotonCandidate> KinDiPhoton;
if(!doTnP) KinDiPhoton = tools_.DiPhotonKinematicSelection( PreSelDipho, 1);
else {
KinDiPhoton = PreSelDipho;
}
// if(DEBUG)
if( KinDiPhoton.size() < 1) return;
h_Efficiencies->Fill(3, genTotalWeight*gen_NRW);

//Evaluate photon IDs
vector<pair<flashgg::DiPhotonCandidate, int> > KinDiPhotonWithID = tools_.EvaluatePhotonIDs( KinDiPhoton, doCustomPhotonMVA );
vector<pair<flashgg::DiPhotonCandidate, int> > KinDiPhotonWithID;
if(!doTnP) KinDiPhotonWithID = tools_.EvaluatePhotonIDs( KinDiPhoton, doCustomPhotonMVA );
else KinDiPhotonWithID = tools_.EvaluatePhotonIDs( KinDiPhoton, doCustomPhotonMVA, 1 );
vector<flashgg::DiPhotonCandidate> SignalDiPhotons = tools_.GetDiPhotonsInCategory( KinDiPhotonWithID, 2 );
vector<flashgg::DiPhotonCandidate> CRDiPhotons = tools_.GetDiPhotonsInCategory( KinDiPhotonWithID, 1 );

Expand Down Expand Up @@ -1125,7 +1136,8 @@ void
leadingPhotonR9full5x5 = diphoCand.leadingPhoton()->full5x5_r9();
subleadingPhotonR9full5x5 = diphoCand.subLeadingPhoton()->full5x5_r9();

diphotonCandidate = diphoCand.p4();
// diphotonCandidate = diphoCand.p4(); //this is wrong since diphoton collection is not updated by the smearer
diphotonCandidate = (diphoCand.leadingPhoton()->p4()+diphoCand.subLeadingPhoton()->p4());
leadingPhoton = diphoCand.leadingPhoton()->p4();
subleadingPhoton = diphoCand.subLeadingPhoton()->p4();

Expand Down
6 changes: 3 additions & 3 deletions python/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
_doSelectionTree = cms.untracked.uint32(1)

##Tags and Objects
_triggerTag = cms.InputTag("TriggerResults", "", "HLT2")
_triggerTag = cms.InputTag("TriggerResults", "", "HLT2") #this might be changed into HLT2 if running on 2015 data
_myTriggers = cms.untracked.vstring("HLT_Diphoton30_18_R9Id_OR_IsoCaloId_AND_HE_R9Id_Mass90_v")
#_DiPhotonTag = cms.untracked.InputTag('flashggDiPhotons')
_DiPhotonTag = cms.untracked.InputTag('flashggPreselectedDiPhotons')
Expand Down Expand Up @@ -96,9 +96,9 @@
_randomLabel = cms.untracked.string("rnd_g_JER")
_jetScale = cms.untracked.int32(1)
##Photon corrections/
_doPhotonScale = cms.untracked.int32(1) #-10: not applied | -1: -1sigma | 0: central | 1: 1sigma
_doPhotonScale = cms.untracked.int32(0) #-10: not applied | -1: -1sigma | 0: central | 1: 1sigma
_doPhotonExtraScale = cms.untracked.int32(0) #-10: not applied | -1: -1sigma | 0: central | 1: 1sigma
_doPhotonSmearing = cms.untracked.int32(1) #-10: not applied | -1: -1sigma | 0: central | 1: 1sigma
_doPhotonSmearing = cms.untracked.int32(0) #-10: not applied | -1: -1sigma | 0: central | 1: 1sigma

#_PhotonCorrectionFile = cms.untracked.string("EgammaAnalysis/ElectronTools/data/80X_ichepV2_2016_pho")
_PhotonCorrectionFile = cms.untracked.string("flashgg/Systematics/data/Moriond17_74x_pho")
Expand Down
19 changes: 15 additions & 4 deletions src/bbggPhotonCorrector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void bbggPhotonCorrector::SmearPhotonsInDiPhotons(std::vector<flashgg::DiPhotonC
SmearPhoton(diPhos[dp].getLeadingPhoton());
SmearPhoton(diPhos[dp].getSubLeadingPhoton());
float afterLeadingCorr = diPhos[dp].getLeadingPhoton().energy();
if (DEBUG) std::cout << "[bbggPhotonCorrector::SmearPhotonsInDiPhotons] Before smear: " << beforeLeadingCorr << " - after smear: " << afterLeadingCorr << std::endl;
if (DEBUG) std::cout << "[bbggPhotonCorrector::SmearPhotonsInDiPhotons] Before smear: " << beforeLeadingCorr << " - after smear: " << afterLeadingCorr << std::endl;
}
}

Expand All @@ -39,11 +39,22 @@ void bbggPhotonCorrector::ScalePhotonsInDiPhotons(std::vector<flashgg::DiPhotonC
scaler_.doSmearings = false;
scaler_.doScale = true;
for ( unsigned int dp = 0; dp < diPhos.size(); dp++) {
float beforeLeadingCorr = diPhos[dp].getLeadingPhoton().energy();
float beforeLeadingCorr = diPhos[dp].getLeadingPhoton().energy();
bbggPhotonCorrector::LorentzVector leadingPhoBef = diPhos[dp].getLeadingPhoton().p4();
bbggPhotonCorrector::LorentzVector subleadingPhoBef = diPhos[dp].getSubLeadingPhoton().p4();

if(DEBUG) std::cout<<"ORIGINAL Mass"<<(leadingPhoBef+subleadingPhoBef).M()<<std::endl;

ScalePhoton(diPhos[dp].getLeadingPhoton());
ScalePhoton(diPhos[dp].getSubLeadingPhoton());
float afterLeadingCorr = diPhos[dp].getLeadingPhoton().energy();
if (DEBUG) std::cout << "[bbggPhotonCorrector::ScalePhotonsInDiPhotons] Before scale: " << beforeLeadingCorr << " - after scale: " << afterLeadingCorr << std::endl;
if(DEBUG){
bbggPhotonCorrector::LorentzVector leadingPho = diPhos[dp].getLeadingPhoton().p4();
bbggPhotonCorrector::LorentzVector subleadingPho = diPhos[dp].getSubLeadingPhoton().p4();

std::cout<<"smearedMass"<<(leadingPho+subleadingPho).M()<<std::endl;
}
}
}

Expand Down Expand Up @@ -94,8 +105,8 @@ void bbggPhotonCorrector::ScalePhoton(flashgg::Photon & photon)

if( DEBUG ) {
std::cout << " " << ": Photon has energy= " << photon.energy() << " eta=" << photon.eta()
<< " and we apply a scale factor of " << ( 100 * scale ) << "% to get new energy=" << scale*photon.energy() << std::endl;
}
<< " and we apply a scale factor of " << ( 100 * scale/photon.energy() ) << "% to get new energy=" << scale*photon.energy() << std::endl;
}
bbggPhotonCorrector::LorentzVector thisp4 = photon.p4();
photon.setP4( scale*thisp4);
}
Expand Down
9 changes: 5 additions & 4 deletions src/bbggTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ std::vector<flashgg::DiPhotonCandidate> bbggTools::DiPhotonPreselectionTnP2016(v
bool bbggTools::passPreselectionTnP2016(const flashgg::DiPhotonCandidate * dipho, std::map<std::string, int> myTriggersResults){

bool isPreselected = false;
//this should not be needed since photons are preselected, but just be sure

if ( myTriggersResults["HLT_Ele27_WPTight_Gsf_v"] != 1 )
return false;
Expand Down Expand Up @@ -219,7 +220,7 @@ std::map<std::string,int> bbggTools::TriggerSelection(std::vector<std::string> m
int accepted = 0;
for ( unsigned int i = 0; i < triggerBits->size(); i++)
{
// if(DEBUG) std::cout << "[bbggTools::TriggerSelection] Trigger name: " << names.triggerName(i) << " \t Decision: " << triggerBits->accept(i) << std::endl;
// if(DEBUG) std::cout << "[bbggTools::TriggerSelection] Trigger name: " << names.triggerName(i) << " \t Decision: " << triggerBits->accept(i) << std::endl;
if((names.triggerName(i)).find(myTriggers[j]) != std::string::npos )
{
if(triggerBits->accept(i) == 1){
Expand Down Expand Up @@ -756,11 +757,10 @@ vector<flashgg::DiPhotonCandidate> bbggTools::GetDiPhotonsInCategory( vector<pai
catDiPhotons.push_back(it->first);
}
}

return catDiPhotons;
}

vector<pair<flashgg::DiPhotonCandidate, int > > bbggTools::EvaluatePhotonIDs( vector<flashgg::DiPhotonCandidate> diphoCol, unsigned int doCustomID)
vector<pair<flashgg::DiPhotonCandidate, int > > bbggTools::EvaluatePhotonIDs( vector<flashgg::DiPhotonCandidate> diphoCol, unsigned int doCustomID,unsigned int doTnP)
{
indexSel_=-1;
vector<pair<flashgg::DiPhotonCandidate, int > > PreselDiPhotons;
Expand Down Expand Up @@ -794,7 +794,8 @@ vector<pair<flashgg::DiPhotonCandidate, int > > bbggTools::EvaluatePhotonIDs( ve
for( int whichPho = 0; whichPho < 2; whichPho++)
{
if( _PhotonDoElectronVeto[whichPho] ) {
pho_ids[whichPho] = pho_elv[whichPho];
if(!doTnP) pho_ids[whichPho] = pho_elv[whichPho];
else pho_ids[whichPho] = pho_elv[whichPho] > 0 ? 0:1;
}
int pho1Index = 0; //Index 0 = barrel, 1 = endcap
double pho_eta = (whichPho) ? fabs(pho2_eta) : fabs(pho1_eta);
Expand Down
157 changes: 157 additions & 0 deletions test/RunJobs/MakeTrees_FLASHgg_MC_TnP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import FWCore.ParameterSet.Config as cms
from flashgg.bbggTools.pColors import *

process = cms.Process("bbggtree")
process.load("flashgg.bbggTools.bbggTree_cfi")
process.bbggtree.rho = cms.InputTag('fixedGridRhoAll')
process.bbggtree.vertexes = cms.InputTag("offlineSlimmedPrimaryVertices")
process.bbggtree.puInfo=cms.InputTag("slimmedAddPileupInfo")
process.bbggtree.lumiWeight = cms.double(1.0)
process.bbggtree.intLumi = cms.double(1.0)
process.bbggtree.puReWeight=cms.bool(True)
process.bbggtree.puBins=cms.vdouble()
process.bbggtree.dataPu=cms.vdouble()
process.bbggtree.mcPu=cms.vdouble()
print "I'M HERE 1"

process.source = cms.Source("PoolSource",
# replace 'myfile.root' with the source file you want to use
fileNames = cms.untracked.vstring("test.root")
)
process.load("FWCore.MessageService.MessageLogger_cfi")
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) )
process.MessageLogger.cerr.FwkReport.reportEvery = cms.untracked.int32( 2000 )

# import flashgg customization
from flashgg.MetaData.JobConfig import customize
import FWCore.ParameterSet.VarParsing as VarParsing
# set default options if needed
customize.setDefault("maxEvents",-1)
customize.setDefault("targetLumi",2.58e+3)

customize.register('doSelection',
False,
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.bool,
'False: Make tree before selection; True: Make tree after selection')
customize.register('doDoubleCountingMitigation',
False,
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.bool,
'False: Do not remove double counted photons from QCD/GJet/DiPhotonJets; True: Remove double counted photons from QCD/GJet/DiPhotonJets')
customize.register('nPromptPhotons',
0,
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
'Number of prompt photons to be selected - to use this, set doDoubleCountingMitigation=1')
customize.register('PURW',
1,
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.bool,
"Do PU reweighting? Doesn't work on 76X")

customize.register('bench',
0,
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
"Benchmark number for Non-Res weight. SHould be in range 1-12")



# call the customization
customize(process)

process.bbggtree.puReWeight=cms.bool( bool(customize.PURW) )
if customize.PURW == False:
process.bbggtree.puTarget = cms.vdouble()
print "I'M HERE 2.0"


process.bbggtree.benchmark=cms.untracked.uint32(customize.bench)
if customize.bench>0:
print "I'M HERE 2.1"
process.bbggtree.getNonResGenInfo=cms.untracked.bool(True)

print "I'M HERE 2.2"

maxEvents = 5
if customize.maxEvents:
maxEvents = int(customize.maxEvents)

inputFile = "/store/user/rateixei/flashgg/RunIISpring15-50ns/Spring15BetaV2/GluGluToRadionToHHTo2B2G_M-650_narrow_13TeV-madgraph/RunIISpring15-50ns-Spring15BetaV2-v0-RunIISpring15DR74-Asympt25ns_MCRUN2_74_V9-v1/150804_164203/0000/myMicroAODOutputFile_1.root" #RadFiles['650']
if customize.inputFiles:
inputFile = customize.inputFiles

outputFile = "rest_rad700.root"
if customize.outputFile:
outputFile = customize.outputFile

print customize.inputFiles, customize.outputFile, customize.maxEvents, customize.doSelection, customize.doDoubleCountingMitigation, customize.nPromptPhotons

process.bbggtree.OutFileName = cms.untracked.string(outputFile)

print bcolors.OKBLUE + "########################################################################" + bcolors.ENDC
print bcolors.OKBLUE + "# _ _ _ _ _ _ _____ #" + bcolors.ENDC
print bcolors.OKBLUE + "# | | | || | | || | | | |_ _| #" + bcolors.ENDC
print bcolors.OKBLUE + "# | |_| || |_| || |__ | |__ __ _ __ _ | | _ __ ___ ___ #" + bcolors.ENDC
print bcolors.OKBLUE + "# | _ || _ || '_ \ | '_ \ / _` | / _` | | | | '__| / _ \ / _ \ #" + bcolors.ENDC
print bcolors.OKBLUE + "# | | | || | | || |_) || |_) || (_| || (_| | | | | | | __/| __/ #" + bcolors.ENDC
print bcolors.OKBLUE + "# \_| |_/\_| |_/|_.__/ |_.__/ \__, | \__, | \_/ |_| \___| \___| #" + bcolors.ENDC
print bcolors.OKBLUE + "# __/ | __/ | #" + bcolors.ENDC
print bcolors.OKBLUE + "# |___/ |___/ #" + bcolors.ENDC
print bcolors.OKBLUE + "########################################################################" + bcolors.ENDC
print bcolors.FAIL + "Is it performing the analysis selection?",customize.doSelection, bcolors.ENDC
print bcolors.FAIL + "Is it removing double counted photons from QCD/GJet/DiPhotonJets?",customize.doDoubleCountingMitigation, bcolors.ENDC
if customize.doSelection is True:
process.bbggtree.doSelectionTree = cms.untracked.uint32(1)
if customize.doSelection is False:
process.bbggtree.doSelectionTree = cms.untracked.uint32(0)
if customize.doDoubleCountingMitigation is True:
process.bbggtree.doDoubleCountingMitigation = cms.untracked.uint32(1)
process.bbggtree.nPromptPhotons = cms.untracked.uint32(customize.nPromptPhotons)
print "Number of prompt photons in DiPhotonCandidate:",customize.nPromptPhotons
if customize.doDoubleCountingMitigation is False:
process.bbggtree.doDoubleCountingMitigation = cms.untracked.uint32(0)

process.bbggtree.doSigmaMdecorr = 1
process.bbggtree.sigmaMdecorrFile = cms.untracked.FileInPath("flashgg/Taggers/data/diphoMVA_sigmaMoMdecorr_split_Mgg40_180.root")
process.bbggtree.MVAResultTag = cms.InputTag('flashggDiPhotonMVA')

#set using TnP and ele trigger for 2016
process.bbggtree.doTnP = cms.untracked.uint32(1)
process.bbggtree.myTriggers = cms.untracked.vstring("HLT_Ele27_WPTight_Gsf_v")
#process.bbggtree.myTriggers = cms.untracked.vstring("HLT_Diphoton30_18_R9Id_OR_IsoCaloId_AND_HE_R9Id_Mass90_v")

#### 2015 triggers
#process.hltHighLevel= hltHighLevel.clone(HLTPaths = cms.vstring("HLT_Diphoton30_18_R9Id_OR_IsoCaloId_AND_HE_R9Id_Mass95_v*",
# "HLT_Diphoton30PV_18PV_R9Id_AND_IsoCaloId_AND_HE_R9Id_DoublePixelVeto_Mass55_v*",
# "HLT_Diphoton30EB_18EB_R9Id_OR_IsoCaloId_AND_HE_R9Id_DoublePixelVeto_Mass55_v*") )
#### 2016 trigger
#process.hltHighLevel= hltHighLevel.clone(HLTPaths = cms.vstring("HLT_Diphoton30_18_R9Id_OR_IsoCaloId_AND_HE_R9Id_Mass90_v*",

import flashgg.Taggers.flashggTags_cff as flashggTags
process.load("flashgg.Taggers.flashggTags_cff")

import flashgg.Taggers.flashggUpdatedIdMVADiPhotons_cfi as flashggPhotonMVA
flashggPhotonMVA.flashggUpdatedIdMVADiPhotons.reRunRegression = cms.bool(False)
process.load("flashgg.Taggers.flashggUpdatedIdMVADiPhotons_cfi")

import flashgg.Taggers.flashggPreselectedDiPhotons_cfi as flashggPreSelection
process.load("flashgg.Taggers.flashggPreselectedDiPhotons_cfi")
#invert electron veto for TnP
flashggPreSelection.flashggPreselectedDiPhotons.variables[-1] = "-(passElectronVeto - 1)"

import flashgg.Taggers.flashggDiPhotonMVA_cfi as flashggDiPhotonMVA
process.load("flashgg.Taggers.flashggDiPhotonMVA_cfi")
flashggDiPhotonMVA.DiPhotonTag = cms.untracked.InputTag('flashggDiPhotons')


process.p = cms.Path( flashggPhotonMVA.flashggUpdatedIdMVADiPhotons
* flashggPreSelection.flashggPreselectedDiPhotons
* flashggDiPhotonMVA.flashggDiPhotonMVA
* flashggTags.flashggUnpackedJets
* process.bbggtree )

#process.p = cms.Path( flashggPhotonMVA.flashggUpdatedIdMVADiPhotons
# * flashggTags.flashggUnpackedJets
# * process.bbggtree)
Loading

0 comments on commit 3b045b8

Please sign in to comment.