Skip to content

Commit

Permalink
Merge pull request cms-sw#66 from amarini/topic_improvements
Browse files Browse the repository at this point in the history
improvements remove fitter if no combine. Improvements in tau energy …
  • Loading branch information
amarini authored Jun 22, 2016
2 parents 2e63308 + cf53fb5 commit 1174f0d
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 17 deletions.
9 changes: 8 additions & 1 deletion aux/sf_database.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ btag csv aux/CSVv2.csv
eleveto th2f aux/CutBasedID_VetoWP_76X_18Feb.txt_SF2D.root veto
## POG Tau
tauid base 1.0 0.06
tauid2 tf1 1.0 1.0+0.0002*x
## trigger
tauLeg3p json-sami aux/tauLegTriggerEfficiency2015_3prong.json
tauLeg13p json-sami aux/tauLegTriggerEfficiency2015_13prong.json
Expand All @@ -60,5 +61,11 @@ metLegBtagMedium json-sami aux/metLegTriggerEfficiency2015_btagMedium.json
### top reweighting ###
#######################
topreweight tf2 TMath::Sqrt(TMath::Exp(0.156-0.00137*x)*TMath::Exp(0.156-0.00137*y))
wreweight tf1 1./(1.1003+4.23574e-06*x+1.35084e-06*x*x)
#wreweight tf1 1./(1.1003+4.23574e-06*x+1.35084e-06*x*x)
#
##recoil
#wreweight tf1 9.43894e-01+1.52030e+00*TMath::Exp(-x*2.22628e-02)
###
#ht
#wreweight tf1 1.14898-4.60339e-04*x+2.24492e-07*x*x
wreweight tf1 9.36537e-01+8.31558e-05*x-2.76664e-07*x*x
2 changes: 1 addition & 1 deletion dat/configTauNu.dat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Correct=NONE
config=MitPhiCorrector|fileName="aux/MetPhi.root"
#config=TauRegression|fileName="aux/bdt_regression_taugun.xml"
#Smear=NONE
Smear=NONE,JES,JER,@SmearSF("BTAG"!"btag"),@SmearSF("TAU"!"tauid"),@SmearSF("TRIG"!"tauLeg13p"),@SmearSF("TRIGMET"!"metLegBtagMedium")
Smear=NONE,JES,JER,@SmearSF("BTAG"!"btag"),@SmearSF("TAU"!"tauid"),@SmearSF("TAUHIGHPT"!"tauid2"),@SmearSF("TRIG"!"tauLeg13p"),@SmearSF("TRIGMET"!"metLegBtagMedium")
## QCD Purity
#@SmearSF("RFAC","tauinvisospline")
#Smear=@SmearScales(1!0),@SmearScales(0!1),@SmearScales(1!1)
Expand Down
4 changes: 4 additions & 0 deletions interface/Fitter.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef FITTER_H
#define FITTER_H

#ifdef HAVE_COMBINE

// --- STD ---
#include <string>
#include <vector>
Expand Down Expand Up @@ -97,6 +99,8 @@ class Fitter : virtual public BaseFitter{

#endif

#endif

// Local Variables:
// mode:c++
// indent-tabs-mode:nil
Expand Down
1 change: 1 addition & 0 deletions interface/Lepton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "interface/Object.hpp"
#include "interface/Trigger.hpp"
#include "interface/Smearable.hpp"

class Lepton : virtual public Object,
virtual public Trigger
Expand Down
4 changes: 2 additions & 2 deletions interface/Loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class Looper{
inline void AddCSVSF(string label, string filename){event_->GetWeight() ->AddCSVSF(label,filename);}
inline void AddTh2fSF(string label, string filename){event_->GetWeight() ->AddTh2fSF(label,filename);}

inline void AddTF2SF(string label, string formula){event_->GetWeight() ->AddTF2SF(label,formula);}
inline void AddTF1SF(string label, string formula){event_->GetWeight() ->AddTF1SF(label,formula);}
inline void AddTF2SF(string label, string formula,string err=""){event_->GetWeight() ->AddTF2SF(label,formula,err);}
inline void AddTF1SF(string label, string formula,string err=""){event_->GetWeight() ->AddTF1SF(label,formula,err);}

// -- PU Reweight
inline void AddTarget( TH1*h, int runMin=-1, int runMax =-1,double lumi=-1){ event_ -> GetWeight() -> AddTarget(h,runMin,runMax,lumi);}
Expand Down
2 changes: 1 addition & 1 deletion interface/Smearable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Smearer{
enum smearType{
JES=0,
JER,
TAU,
TAUESCALE,
NONE
};

Expand Down
8 changes: 8 additions & 0 deletions interface/Smearer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SmearBase : public Named {
// ---
virtual int smear(Event *e){return 0;}; // 0 = success; 1 not applicable to the event
virtual inline vector<Jet*> &GetJets(Event *e){return e->jets_;}
virtual inline vector<Tau*> &GetTaus(Event *e){return e->taus_;}
virtual inline Met &GetMet(Event *e){return e->met_;}
};

Expand All @@ -46,6 +47,13 @@ class SmearJes : virtual public SmearBase
virtual int smear(Event*e);
};

class SmearTauScale : virtual public SmearBase
{
public:
SmearTauScale() : SmearBase(){ name_ = "TAUSCALE";}
virtual int smear(Event*e);
};

class SmearJer:virtual public SmearBase
{
public:
Expand Down
10 changes: 9 additions & 1 deletion interface/Tau.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
#include "interface/Lepton.hpp"
#include "interface/GenParticle.hpp"
#include "interface/Trigger.hpp"
#include "interface/Smearable.hpp"

class Event;

class Tau: virtual public Object,
virtual public Lepton,
virtual public Trigger
virtual public Trigger,
virtual public SmearableBase
{
float etacut_;
bool doEleRej_;
bool doMuRej_;
int rematch_ {-1};
float escale_{0.03};


public:
Expand All @@ -33,6 +36,10 @@ class Tau: virtual public Object,
virtual int IsTau() const ;
virtual int IsTauInvIso() const ;
inline int IsObject() const override{ return IsTau(); }
inline float Pt() const override {
if (syst==0)return p4.Pt() ;
else return (p4.Pt() * (1.0+syst*escale_));
}

// Return 15 = tau, 21 = Gluon, 1-4 = UDSC (maybe only 1)
// 0 no match
Expand All @@ -45,6 +52,7 @@ class Tau: virtual public Object,
virtual void clearSyst(){
Lepton::clearSyst();
Object::clearSyst();
syst=0;
}

// --- REGRESSION
Expand Down
4 changes: 2 additions & 2 deletions interface/Weight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class Weight : virtual public SmearableBase {
void AddSplineSF(string label, double pt, double sf, double err);
void AddCSVSF(string label, string filename);

void AddTF1SF(string label, string formula);
void AddTF2SF(string label, string formula);
void AddTF1SF(string label, string formula,string errFormula);
void AddTF2SF(string label, string formula,string errFormula);

void clearSF( ){ sf_ =1.0;}
void clearPU( ){ pu_ . clearTarget() ;};
Expand Down
4 changes: 2 additions & 2 deletions python/Loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ def applyJson(obj,fname):
if key['type'] == 'csv':
loop.AddCSVSF(label, key['filename'])
if key['type'] == 'tf1':
loop.AddTF1SF(label, key['formula'])
loop.AddTF1SF(label, key['formula'],key['errFormula'])
if key['type'] == 'tf2':
loop.AddTF2SF(label, key['formula'])
loop.AddTF2SF(label, key['formula'],key['errFormula'])
if 'veto' in key:
if opts.verbose: print " * setting veto for",label
sf = loop.GetSF(label).SetVeto()
Expand Down
2 changes: 2 additions & 0 deletions python/ParseDat.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def ReadSFDB(file,verbose=False):

elif type == 'tf1' or type=='tf2':
R['formula'] = l.split(' ' )[2]
try: R['errFormula'] = l.split(' ')[3]
except: R['errFormula']=''
sf=0.0 ## ignored
err=0.0 ## ignored

Expand Down
26 changes: 26 additions & 0 deletions src/AnalysisChargedHiggsQCDPurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ void ChargedHiggsQCDPurity::Init()
Book( dir + "MtIsoInv"+"_"+ l , ("MtIsoInv "+ l).c_str(),1000,0.,1000.);
Book( none + "EtMissIsoInv"+"_"+ l , ("EtMissIsoInv "+ l).c_str(),1000,0.,1000.);
Book( none + "EtMiss"+"_"+ l , ("EtMiss "+ l).c_str(),1000,0.,1000.); // copy of the Tau Nu ?

Book( none+"RbbMin_"+l,"RbbMin "+l+";R_{bb}^{min}",100,0,2*TMath::Pi());
Book( none+"RCollMin_"+l,"RCollMin "+l+";R_{coll}^{min}",100,0,2*TMath::Pi());

Book( none+"RbbMinIsoInv_"+l,"RbbMin IsoInv "+l+";R_{bb}^{min}",100,0,2*TMath::Pi());
Book( none+"RCollMinIsoInv_"+l,"RCollMin IsoInv "+l+";R_{coll}^{min}",100,0,2*TMath::Pi());
}

}
Expand Down Expand Up @@ -208,6 +214,16 @@ int ChargedHiggsQCDPurity::analyze(Event*e,string systname)
Fill( none + "EtMiss" +"_"+label,systname, e->GetMet().Pt(), e->weight() );
}

if (t!=NULL and direct.passAllExcept(ChargedHiggsTauNu::AngRbb) )
{
Fill( none + "RbbMin" +"_"+label,systname, e->RbbMin(), e->weight() );
}

if (t!=NULL and direct.passAllExcept(ChargedHiggsTauNu::AngColl) )
{
Fill( none + "RCollMin" +"_"+label,systname, e->RCollMin(), e->weight() );
}

if (t!=NULL and direct.passAll() )
{
//if ( not e->IsRealData()) e->ApplySF("btag");
Expand Down Expand Up @@ -266,6 +282,16 @@ int ChargedHiggsQCDPurity::analyze(Event*e,string systname)

}

if (inverse.passAllExcept(ChargedHiggsTauNu::AngRbb) )
{
Fill( none + "RbbMin" +"_"+label,systname, e->RbbMin(3,tInv), e->weight() );
}

if (inverse.passAllExcept(ChargedHiggsTauNu::AngColl) )
{
Fill( none + "RCollMin" +"_"+label,systname, e->RCollMin(3,tInv), e->weight() );
}

// remove trigger & met
unsigned mymask = 0 ;
for(unsigned i=0;i<ChargedHiggsTauNu::MaxCut;++i){
Expand Down
1 change: 1 addition & 0 deletions src/AnalysisChargedHiggsTauNu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ int ChargedHiggsTauNu::analyze(Event*e,string systname)
if (cut.passAll() )
{
e->ApplySF("tauid"); // only in MC
e->ApplySF("tauid2"); // only in MC

//if(e->IsRealData() and (systname=="NONE" or systname=="")) Log(__FUNCTION__,"SYNC",Form("%d,%d,%ld",e->runNum(),e->lumiNum(),e->eventNum()) );
//
Expand Down
15 changes: 12 additions & 3 deletions src/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,17 @@ void Event::ApplyTopReweight(){

void Event::ApplyWReweight(){

#warning noWR
return ;
// #warning noWR
// return ;
//Logger::getInstance().LogN("Event",__FUNCTION__,"LOG","ApplyWReweight Macro called" + GetWeight() -> GetMC() ,5);
/*if (
GetWeight() -> GetMC() . find("W0JetsToLNu") != string::npos or
GetWeight() -> GetMC() . find("W1JetsToLNu") != string::npos or
GetWeight() -> GetMC() . find("W2JetsToLNu") != string::npos or
GetWeight() -> GetMC() . find("W3JetsToLNu") != string::npos or
GetWeight() -> GetMC() . find("W4JetsToLNu") != string::npos
){ ApplySF("wreweight2");}
*/

if( GetWeight() -> GetMC() . find("TT") == string::npos and
GetWeight() -> GetMC() . find("W0JetsToLNu") == string::npos and
Expand All @@ -536,7 +544,8 @@ void Event::ApplyWReweight(){
}

Logger::getInstance().LogN("Event",__FUNCTION__,"INFO","Top And W Reweighting",5);
SetPtEtaSF("wreweight",GetMet().Pt(),0.);
//SetPtEtaSF("wreweight",GetMet().Pt(),0.);
SetPtEtaSF("wreweight",Ht(),0.);
ApplySF("wreweight");

}
Expand Down
16 changes: 16 additions & 0 deletions src/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,22 @@ void LoadNero::FillMet(){
//event_ -> met_ . SetValueDown(Smearer::JES , ((TLorentzVector*)(*met->metSyst)[BareMet::JesDown]) -> Pt() );
event_-> met_ . SetFilled(Smearer::JES);

// ---- TAU SCALE
BareTaus *bt = dynamic_cast<BareTaus*> ( bare_ [ names_[ "BareTaus" ] ] ); assert (bt !=NULL);
TLorentzVector tauUp, tauDown;
tauUp = *(TLorentzVector*)(*met -> p4) [0];
tauDown= *(TLorentzVector*)(*met -> p4) [0];
for (int iTau=0;iTau< bt -> p4 ->GetEntries() ; ++iTau)
{
TLorentzVector delta;
delta.SetPtEtaPhiE( 1.03 * ((TLorentzVector*)(*bt->p4)[iTau])->Pt(), ((TLorentzVector*)(*bt->p4)[iTau])->Eta(), ((TLorentzVector*)(*bt->p4)[iTau])->Phi(), ((TLorentzVector*)(*bt->p4)[iTau])->E() * 1.03);
tauUp += delta;
tauDown -= delta;
}
event_ -> met_ . SetValueUp (Smearer::TAUESCALE , tauUp.Pt() );
event_ -> met_ . SetValueDown(Smearer::TAUESCALE , tauDown.Pt() );
event_-> met_ . SetFilled(Smearer::TAUESCALE);

//Log(__FUNCTION__,"DEBUG",Form("Met=%f MetJesUp=%f",((TLorentzVector*)(*met -> p4) [0])->Pt() , ((TLorentzVector*)(*met->metSyst)[BareMet::JesUp]) -> Pt()));

//Log(__FUNCTION__,"DEBUG","Going to Fill Jer MET");
Expand Down
22 changes: 22 additions & 0 deletions src/Smearer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ int SmearPdfs::smear(Event*e)
return SMEAR_OK;
}

int SmearTauScale::smear(Event *e)
{
// only on data apply Jes
//if( not e->IsRealData() ) return SMEAR_NA;
TLorentzVector metSystShift;

for (auto t : GetTaus(e))
{
t->syst = syst_;
}


// this is not const like in e->GetMet()
//#warning NO MET IN JES
GetMet(e) . syst = syst_;
GetMet(e) . SetSmearType(Smearer::TAUESCALE);

if ( not GetMet(e) . IsFilled() ) Log(__FUNCTION__,"WARNING","JES Smearing not filled in MET");

return SMEAR_OK;
}


// Local Variables:
// mode:c++
Expand Down
8 changes: 4 additions & 4 deletions src/Weight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void Weight::AddTh2fSF(string label, string filename)
sf_db[label] = p;
}

void Weight::AddTF1SF(string label, string formula)
void Weight::AddTF1SF(string label, string formula,string errFormula)
{
if (sf_db.find(label) != sf_db.end() )
{
Expand All @@ -116,10 +116,10 @@ void Weight::AddTF1SF(string label, string formula)
}
SF_TF1 *p = new SF_TF1();
p -> label = label; // before formula
p -> init(formula);
p -> init(formula,errFormula);
sf_db[label] = p;
}
void Weight::AddTF2SF(string label, string formula)
void Weight::AddTF2SF(string label, string formula,string errFormula)
{
if (sf_db.find(label) != sf_db.end() )
{
Expand All @@ -128,7 +128,7 @@ void Weight::AddTF2SF(string label, string formula)
}
SF_TF2 *p = new SF_TF2();
p -> label = label; // before formula
p -> init(formula);
p -> init(formula,errFormula);
sf_db[label] = p;
}

Expand Down

0 comments on commit 1174f0d

Please sign in to comment.