-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merging jet uncertainty evaluator #114
base: master
Are you sure you want to change the base?
Changes from 26 commits
f195ebb
eef611d
43d20eb
ef1593a
c16c2f7
4aeabb7
a78925c
9886bd9
1b6de59
0c74542
0c21443
d4bce5b
4810b9c
137084c
752627d
d7fa1c0
acb1ac0
4ddb662
490f9b3
da5d011
9877bc3
535dd8b
04afb12
e010f7e
01b7ae7
f415804
b230ea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ class topObjectSelection : public nanoBase | |
|
||
Float_t b_maxBDiscr_nonb; | ||
|
||
UInt_t m_unFlag; | ||
|
||
public: | ||
// YOU MUST SET UP ALL IN THE BELOW!!! | ||
// (SetCutValues() will force you to do it) | ||
|
@@ -73,8 +75,11 @@ class topObjectSelection : public nanoBase | |
return Muon_isPFcand[ nIdx ] && ( Muon_globalMu[ nIdx ] || Muon_trackerMu[ nIdx ] ); | ||
}; | ||
virtual bool additionalConditionForGenJet(UInt_t nIdx) {return true;}; | ||
virtual bool additionalConditionForJet(UInt_t nIdx) {return true;}; | ||
virtual bool additionalConditionForBJet(UInt_t nIdx) {return true;}; | ||
|
||
virtual bool additionalConditionForJet(UInt_t nIdx, Float_t &fJetPt, Float_t &fJetEta, Float_t &fJetPhi, Float_t &fJetMass) | ||
{return true;}; | ||
virtual bool additionalConditionForBJet(UInt_t nIdx, Float_t &fJetPt, Float_t &fJetEta, Float_t &fJetPhi, Float_t &fJetMass) | ||
{return true;}; | ||
|
||
public: | ||
std::vector<TParticle> muonSelection(); | ||
|
@@ -87,8 +92,9 @@ class topObjectSelection : public nanoBase | |
|
||
std::vector<TParticle> genJetSelection(); | ||
|
||
topObjectSelection(TTree *tree=0, TTree *had=0, TTree *hadTruth=0, Bool_t isMC = false); | ||
topObjectSelection(TTree *tree=0, Bool_t isMC=false) : topObjectSelection(tree, 0, 0, isMC) {} | ||
topObjectSelection(TTree *tree=0, TTree *had=0, TTree *hadTruth=0, Bool_t isMC = false, UInt_t unFlag = 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we name unFlag better? Its just for JES/JER, so maybe jetUnc? |
||
topObjectSelection(TTree *tree=0, Bool_t isMC=false, UInt_t unFlag = 0) : | ||
topObjectSelection(tree, 0, 0, isMC, unFlag) {} | ||
~topObjectSelection() {} | ||
|
||
// In this function you need to set all the cut conditions in the above | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,39 @@ nanoBase::nanoBase(TTree *tree, TTree *had, TTree *hadTruth, Bool_t isMC) : | |
m_btagSF.load(calib, BTagEntry::FLAV_B, "comb"); | ||
m_btagSF_up.load(calib, BTagEntry::FLAV_B, "comb"); | ||
m_btagSF_dn.load(calib, BTagEntry::FLAV_B, "comb"); | ||
|
||
m_jecUnc = NULL; | ||
m_rndEngine = NULL; | ||
|
||
if (isMC) { | ||
std::string env = getenv("CMSSW_BASE"); | ||
|
||
std::string strPathJetResSFObj = env+"/src/nano/analysis/data/jer/" | ||
"Summer16_25nsV1_MC_SF_AK4PFchs.txt"; | ||
std::string strPathJetResObj = env+"/src/nano/analysis/data/jer/" | ||
"Summer16_25nsV1_MC_PtResolution_AK4PFchs.txt"; | ||
std::string strPathJecUnc = env + "/src/nano/analysis/data/jer/" | ||
"Summer16_23Sep2016V4_MC_UncertaintySources_AK4PFchs.txt"; | ||
|
||
if (!exists_test(strPathJetResSFObj) || !exists_test(strPathJetResObj) || | ||
!exists_test(strPathJecUnc)) | ||
{ | ||
std::cout << "Missing data file, run getFiles and try again" << std::endl; | ||
exit(50); | ||
} | ||
|
||
m_jetResSFObj = JMENano::JetResolutionScaleFactor(strPathJetResSFObj.c_str()); | ||
m_jetResObj = JMENano::JetResolution(strPathJetResObj.c_str()); | ||
|
||
m_rndEngine = new TRandom3(12345); | ||
|
||
|
||
JetCorrectorParameters JetCorPar(strPathJecUnc, "Total"); | ||
m_jecUnc = new JetCorrectionUncertainty(JetCorPar); | ||
} | ||
|
||
m_fDRcone_JER = 0.4; // For AK4 jets | ||
m_fResFactorMathcer = 3; // According to https://twiki.cern.ch/twiki/bin/viewauth/CMS/JetResolution | ||
} | ||
|
||
nanoBase::~nanoBase() | ||
|
@@ -41,6 +74,90 @@ nanoBase::~nanoBase() | |
m_output->Write(); | ||
m_output->Close(); | ||
} | ||
|
||
if (m_jecUnc != NULL) delete m_jecUnc; | ||
if (m_rndEngine != NULL) delete m_rndEngine; | ||
} | ||
|
||
// In uncertainty study we need to switch the kinematic variables of jets | ||
// In default, these are same as the original ones, but when a user wants to study systematic uncertainty | ||
// so that he/she needs to switch them to the evaluated ones, | ||
// just touching them in anlalyser class will be okay, and this is for it. | ||
void nanoBase::GetJetMassPt(UInt_t nIdx, | ||
Float_t &fJetMass, Float_t &fJetPt, Float_t &fJetEta, Float_t &fJetPhi, UInt_t unFlag) | ||
{ | ||
Float_t fCorrFactor = 1.0; | ||
|
||
fJetMass = Jet_mass[nIdx]; | ||
fJetPt = Jet_pt[nIdx]; | ||
fJetEta = Jet_eta[nIdx]; | ||
fJetPhi = Jet_phi[nIdx]; | ||
|
||
//if ( m_isMC && ( unFlag & ( OptFlag_JER_Up | OptFlag_JER_Dn | OptFlag_JES_Up | OptFlag_JES_Dn ) ) != 0 ) | ||
if (m_isMC) { | ||
// Evaluating the central part cJER of the factor | ||
JMENano::JetParameters jetPars = {{JMENano::Binning::JetPt, fJetPt}, | ||
{JMENano::Binning::JetEta, fJetEta}, | ||
{JMENano::Binning::Rho, fixedGridRhoFastjetAll}}; | ||
|
||
const double jetRes = m_jetResObj.getResolution(jetPars); // Note: this is relative resolution. | ||
const double cJER = m_jetResSFObj.getScaleFactor(jetPars, | ||
((unFlag & (OptFlag_JER_Up | OptFlag_JER_Dn)) == 0 ? Variation::NOMINAL : | ||
((unFlag & OptFlag_JER_Up) != 0 ? Variation::UP : Variation::DOWN))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing, we can use plain flags rather than bit fields for these options |
||
|
||
// We need corresponding genJet | ||
Int_t nIdxGen = GetMatchGenJet(nIdx, fJetPt * jetRes); | ||
const double genJetPt = GenJet_pt[nIdxGen]; | ||
|
||
if ( nIdxGen >= 0 ) { | ||
fCorrFactor = (genJetPt+(fJetPt-genJetPt)*cJER)/fJetPt; | ||
} else { | ||
const double smear = m_rndEngine->Gaus(0, 1); | ||
fCorrFactor = (cJER <= 1 ? 1 : 1+smear*jetRes*sqrt(cJER*cJER-1)); | ||
} | ||
|
||
if ((unFlag & (OptFlag_JES_Up | OptFlag_JES_Dn)) != 0) { // JES | ||
// The evaluator needs pT and eta of the current jet | ||
m_jecUnc->setJetPt(fCorrFactor*fJetPt); | ||
m_jecUnc->setJetEta(fJetEta); | ||
|
||
if ((unFlag & OptFlag_JES_Up) != 0) { | ||
fCorrFactor *= 1+m_jecUnc->getUncertainty(true); | ||
} else { | ||
fCorrFactor *= 1-m_jecUnc->getUncertainty(true); | ||
} | ||
} | ||
} | ||
|
||
fJetMass *= fCorrFactor; | ||
fJetPt *= fCorrFactor; | ||
} | ||
|
||
|
||
Int_t nanoBase::GetMatchGenJet(UInt_t nIdxJet, Float_t fResolution) { | ||
UInt_t i; | ||
|
||
double dEta, dPhi, dR; | ||
double dRFound = m_fDRcone_JER; | ||
UInt_t nIdxFound = 999; | ||
|
||
for (i = 0; i < nGenJet; i++) { | ||
dEta = Jet_eta[nIdxJet]-GenJet_eta[i]; | ||
dPhi = std::abs(Jet_phi[nIdxJet]-GenJet_phi[i]); | ||
if (dPhi > (double)M_PI) dPhi -= (double)(2*M_PI); | ||
|
||
dR = std::sqrt(dEta*dEta+dPhi*dPhi); | ||
|
||
if (dR >= (double)m_fDRcone_JER*0.5) continue; | ||
if (dRFound > dR) { | ||
if (std::abs(Jet_pt[nIdxJet] - GenJet_pt[i]) >= m_fResFactorMathcer*fResolution) continue; | ||
|
||
dRFound = dR; | ||
nIdxFound = i; | ||
} | ||
} | ||
|
||
return (dRFound < 0.75*(double)m_fDRcone_JER ? (Int_t)nIdxFound : -1); | ||
} | ||
|
||
void nanoBase::Loop() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove this now