Skip to content

Commit

Permalink
Merge pull request #91 from robervalwalsh/analysis-2015
Browse files Browse the repository at this point in the history
Jet ID
  • Loading branch information
robervalwalsh authored Dec 6, 2016
2 parents ee45b99 + a8ad058 commit 1c125f7
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 25 deletions.
17 changes: 17 additions & 0 deletions Analysis/Tools/interface/Analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ namespace analysis {
public:
Analysis(const std::string & inputFilelist, const std::string & evtinfo = "MssmHbb/Events/EventInfo");
~Analysis();

// Info
void tag(const std::string &);
std::string tag();

// Event
int numberEvents();
Expand All @@ -61,6 +65,8 @@ namespace analysis {
int run();
int lumiSection();
bool isMC();
std::string fileName();
std::string fileFullName();

// PileupInfo
int nPileup();
Expand Down Expand Up @@ -106,6 +112,8 @@ namespace analysis {
// Trigger results
void triggerResults(const std::string & path);
int triggerResult(const std::string & trig);
int triggerL1Prescale(const std::string & trig);
int triggerHLTPrescale(const std::string & trig);

// Generator Filter
FilterResults generatorFilter(const std::string & path);
Expand Down Expand Up @@ -141,6 +149,9 @@ namespace analysis {
TCollection * fileList_;
std::string inputFilelist_;

// Info
std::string tag_;

// btagging efficiencies
TFile * fileBtagEff_;
std::map<std::string,TH2F *> h2_btageff_;
Expand Down Expand Up @@ -306,6 +317,10 @@ namespace analysis {
}

// ========================================================
inline void Analysis::tag(const std::string & t) { std::cout << "Tag " << t << " has been defined." << std::endl ;
tag_ = t; }
inline std::string Analysis::tag() { return tag_ ; }


inline int Analysis::numberEvents() { return nevents_; }
inline int Analysis::size() { return nevents_; }
Expand All @@ -324,6 +339,8 @@ namespace analysis {
inline void Analysis::btagEfficienciesAlgo(const std::string & algo ) { btageff_algo_ = algo; }
inline void Analysis::btagEfficienciesFlavour(const std::string & flavour) { btageff_flavour_ = flavour; }

inline std::string Analysis::fileFullName() { return std::string(t_event_ -> GetFile() -> GetName()) ; }

// inline std::string Analysis::getGenParticleCollection() { return genParticleCollection_; }

}
Expand Down
42 changes: 35 additions & 7 deletions Analysis/Tools/interface/Jet.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,24 @@ namespace analysis {
/// returns the vector of pointers to the generated partons
std::vector< std::shared_ptr<GenParticle> > partons() const;
/// returns jet energy resolution
float JerResolution() const;
/// returns jet energy resolution SF
float JerSf() const;
/// returns jet energy resolution SF Down variation
float JerSfDown() const;
/// returns jet energy resolution SF Up variation
float JerSfUp() const;
float JerResolution() const;
/// returns jet energy resolution SF
float JerSf() const;
/// returns jet energy resolution SF Down variation
float JerSfDown() const;
/// returns jet energy resolution SF Up variation
float JerSfUp() const;

float neutralHadronFraction() const ;
float neutralEmFraction() const ;
int neutralMultiplicity() const ;
float chargedHadronFraction() const ;
float chargedEmFraction() const ;
int chargedMultiplicity() const ;
float muonFraction() const ;
int constituents() const ;


// Sets
/// sets the btag value
void btag(const float &);
Expand Down Expand Up @@ -106,6 +116,14 @@ namespace analysis {
/// remove parton from jet parton list
int removeParton(const int &);

void neutralHadronFraction(const float & nHadFrac);
void neutralEmFraction(const float & nEmFrac);
void neutralMultiplicity(const int & nMult);
void chargedHadronFraction(const float & cHadFrac);
void chargedEmFraction(const float & cEmFrac);
void chargedMultiplicity(const int & cMult);
void muonFraction(const float & muFrac);

/// calculates the jet id
void id(const float & nHadFrac,
const float & nEmFrac ,
Expand Down Expand Up @@ -150,6 +168,16 @@ namespace analysis {
float jerSFDown_;
/// jet energy resolution
float jerResolution_;

float nHadFrac_;
float nEmFrac_;
int nMult_;
float cHadFrac_;
float cEmFrac_;
int cMult_;
float muFrac_;
int nConst_;

private:
// ----------member data ---------------------------

Expand Down
4 changes: 2 additions & 2 deletions Analysis/Tools/interface/strip.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

sed 's/]],/&\n/g' $1 > temp; sed -e 's/{//g' -e 's/}//g' -e 's/"//g' -e 's/,//g' -e 's/]//g' -e 's/\[//g' -e 's/://g' temp > t ; mv t temp
sed 's/]],/&\n/g' $1 > temp; sed -e 's/{//g' -e 's/}//g' -e 's/"//g' -e 's/,/ /g' -e 's/]/ /g' -e 's/\[/ /g' -e 's/:/ /g' temp > t ; mv t temp
sed -i 's/^[ \t]*//' temp
sed -i '/^$/d' temp
cat temp
#cat temp


20 changes: 19 additions & 1 deletion Analysis/Tools/src/Analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "TKey.h"
#include "Analysis/Tools/interface/Analysis.h"
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>

using namespace analysis;
using namespace analysis::tools;
Expand Down Expand Up @@ -193,6 +194,17 @@ int Analysis::triggerResult(const std::string & trig)
return triggerResults_[trig];
}

int Analysis::triggerL1Prescale(const std::string & trig)
{
// if ( t_triggerResults_ == NULL ) return -1.;
return triggerResultsPS_["psl1_"+trig];
}
int Analysis::triggerHLTPrescale(const std::string & trig)
{
// if ( t_triggerResults_ == NULL ) return -1.;
return triggerResultsPS_["pshlt_"+trig];
}


// ===========================================================
// ================= METADATA ============================
Expand Down Expand Up @@ -478,4 +490,10 @@ void triggerNames(std::string &trueTriggerNames,const char *myTriggerNames, TTre
}
*/


std::string Analysis::fileName()
{
std::string filename;
filename = boost::filesystem::basename(this->fileFullName())+boost::filesystem::extension(this->fileFullName());
return filename ;
}

70 changes: 55 additions & 15 deletions Analysis/Tools/src/Jet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,22 @@ float Jet::jecUncert() const { return jecUnc_;
std::vector<int> Jet::flavours() const { return flavours_; }
std::vector< std::shared_ptr<GenParticle> >\
Jet::partons() const { return partons_; }
std::string Jet::extendedFlavour() const { return extendedFlavour_; }
float Jet::JerResolution() const { return jerResolution_;}
float Jet::JerSf() const { return jerSF_; }
float Jet::JerSfDown() const { return jerSFDown_; }
float Jet::JerSfUp() const { return jerSFUp_; }
std::string Jet::extendedFlavour() const { return extendedFlavour_; }
float Jet::JerResolution() const { return jerResolution_;}
float Jet::JerSf() const { return jerSF_; }
float Jet::JerSfDown() const { return jerSFDown_; }
float Jet::JerSfUp() const { return jerSFUp_; }

float Jet::neutralHadronFraction() const { return nHadFrac_; }
float Jet::neutralEmFraction() const { return nEmFrac_; }
int Jet::neutralMultiplicity() const { return nMult_; }
float Jet::chargedHadronFraction() const { return cHadFrac_; }
float Jet::chargedEmFraction() const { return cEmFrac_; }
int Jet::chargedMultiplicity() const { return cMult_; }
float Jet::muonFraction() const { return muFrac_; }
int Jet::constituents() const { return nConst_; }



// Sets
void Jet::btag (const float & btag) { btag_ = btag; }
Expand All @@ -79,10 +90,10 @@ void Jet::jecUncert(const float & ju) { jecUnc_
void Jet::addParton(const std::shared_ptr<GenParticle> & parton) { partons_.push_back(parton);
flavours_.push_back(parton->pdgId()); }
void Jet::btagAlgo (const std::string & algo ) { btagAlgo_ = algo; }
void Jet::JerResolution(const float & jerResolution) { jerResolution_ = jerResolution; }
void Jet::JerSf(const float & jerSf) { jerSF_ = jerSf; }
void Jet::JerSfDown(const float & jerSfDown) { jerSFDown_ = jerSfDown; }
void Jet::JerSfUp(const float & jerSfUp) { jerSFUp_ = jerSfUp; }
void Jet::JerResolution(const float & jerResolution) { jerResolution_ = jerResolution; }
void Jet::JerSf(const float & jerSf) { jerSF_ = jerSf; }
void Jet::JerSfDown(const float & jerSfDown) { jerSFDown_ = jerSfDown; }
void Jet::JerSfUp(const float & jerSfUp) { jerSFUp_ = jerSfUp; }

int Jet::removeParton(const int & i)
{
Expand Down Expand Up @@ -168,18 +179,47 @@ void Jet::id (const float & nHadFrac,
const float & muFrac )
{
// Jet ID
// Update: https://twiki.cern.ch/twiki/bin/view/CMS/JetID?rev=95#Recommendations_for_13_TeV_data
int nM = (int)round(nMult);
int cM = (int)round(cMult);
int numConst = nM + cM;
if ( fabs(p4_.Eta()) <= 3. )
if ( fabs(p4_.Eta()) <= 2.7 )
{
idloose_ = ((nHadFrac<0.99 && nEmFrac<0.99 && numConst>1) && ((abs(p4_.Eta())<=2.4 && cHadFrac>0 && cM>0 && cEmFrac<0.99) || fabs(p4_.Eta())>2.4) && fabs(p4_.Eta())<=2.7);
idtight_ = ((nHadFrac<0.90 && nEmFrac<0.90 && numConst>1) && ((abs(p4_.Eta())<=2.4 && cHadFrac>0 && cM>0 && cEmFrac<0.99) || fabs(p4_.Eta())>2.4) && fabs(p4_.Eta())<=2.7);
}
else if ( fabs(p4_.Eta()) > 2.7 && fabs(p4_.Eta()) <= 3. )
{
idloose_ = ((nHadFrac<0.99 && nEmFrac<0.99 && numConst>1) && ((abs(p4_.Eta())<=2.4 && cHadFrac>0 && cM>0 && cEmFrac<0.99) || fabs(p4_.Eta())>2.4) && fabs(p4_.Eta())<=3.0);
idtight_ = ((nHadFrac<0.90 && nEmFrac<0.90 && numConst>1) && ((abs(p4_.Eta())<=2.4 && cHadFrac>0 && cM>0 && cEmFrac<0.99) || fabs(p4_.Eta())>2.4) && fabs(p4_.Eta())<=3.0);
idloose_ = (nEmFrac<0.90 && nM>2);
idtight_ = (nEmFrac<0.90 && nM>2);
}
else
{
idloose_ = (nEmFrac<0.90 && nM>10 && fabs(p4_.Eta())>3.0);
idtight_ = (nEmFrac<0.90 && nM>10 && fabs(p4_.Eta())>3.0);
}
idloose_ = (nEmFrac<0.90 && nM>10);
idtight_ = (nEmFrac<0.90 && nM>10);
}

// if ( tag_ == "JetIdOld" )
// {
// if ( fabs(p4_.Eta()) <= 3.0 )
// {
// idloose_ = ((nHadFrac<0.99 && nEmFrac<0.99 && numConst>1) && ((abs(p4_.Eta())<=2.4 && cHadFrac>0 && cM>0 && cEmFrac<0.99) || fabs(p4_.Eta())>2.4) && fabs(p4_.Eta())<=3.0);
// idtight_ = ((nHadFrac<0.90 && nEmFrac<0.90 && numConst>1) && ((abs(p4_.Eta())<=2.4 && cHadFrac>0 && cM>0 && cEmFrac<0.99) || fabs(p4_.Eta())>2.4) && fabs(p4_.Eta())<=3.0);
// }
// else
// {
// idloose_ = (nEmFrac<0.90 && nM>10);
// idtight_ = (nEmFrac<0.90 && nM>10);
// }
// }

nHadFrac_ = nHadFrac;
nEmFrac_ = nEmFrac;
nMult_ = nM;
cHadFrac_ = cHadFrac;
cEmFrac_ = cEmFrac;
cMult_ = cM;
muFrac_ = muFrac;
nConst_ = numConst;

}

0 comments on commit 1c125f7

Please sign in to comment.