Skip to content

Commit

Permalink
Merge pull request cms-sw#93 from amarini/topic_multipd
Browse files Browse the repository at this point in the history
multi primary datasets and drawSyst
  • Loading branch information
amarini authored Dec 1, 2016
2 parents 8b70c14 + 79fb06c commit 8bb8462
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ __init__.py

## ROOT OBJECT
*.root

### TEST
test/combine*
test/mysub*
test/sub*
test/crabTest/*dat
5 changes: 4 additions & 1 deletion interface/AnalysisBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AnalysisBase : public Named
{
private:
Output *output_; // set automatically
bool multipd_{false};

protected:
// --- this are the default values. override these functions
Expand All @@ -32,7 +33,7 @@ class AnalysisBase : public Named
void doInit() {Init();}
void doEnd() { End();}
int doAnalyze(Event*e,string systname){ SetCuts(e); return analyze(e,systname);}
//
//
virtual void inline SetOutput( Output *o ) { output_ = o ;}
virtual int analyze(Event*,string systname){return EVENT_NOT_USED;}
virtual void Init(){}
Expand All @@ -55,6 +56,8 @@ class AnalysisBase : public Named
string GetLabel(Event *e);
inline void AddLabel(string s) {labels.push_back(s);}
inline void AddLabels(vector<string> &v) { for(string &s : v ) labels.push_back(s);}
//
inline void SetMultiPrimaryDataset(bool x=true) { multipd_=x;}

inline TFile* GetOutputFile(){ return output_->GetFile() ;} // TMVA wants the file pointer
// Tree Operations ----
Expand Down
108 changes: 95 additions & 13 deletions script/drawSyst.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,122 @@

from optparse import OptionParser
import ROOT
from array import array
parser= OptionParser()
parser.add_option("-i","--input",type='string',help="Input ROOT file. [Default=%default]", default="DY.root")
parser.add_option("","--base",type='string',help="Base [Default=%default]", default="ChargedHiggsTauNu/Vars/Mt_WJets")
parser.add_option("","--syst",type='string',help="Syst [Default=%default]", default="PU")
parser.add_option("","--rebin",type='int',help="Rebin [Default=%default]", default=20)
opts, args = parser.parse_args()

def Rebin(h):
''' Rebin with un-even bins '''
mybins=array('d',[0,20,40,60,80,100,120,140,160,180,200,220,240,260,280,300,350,400,500,600,700,800,900,1000,1500,2000,8000])
#h1 = ROOT.TH1D(h.GetName()+"_rebin",h.GetTitle(),len(mybins)-1,mybins)
h1=h.Rebin(len(mybins)-1,h.GetName()+"_rebin",mybins)
return h1


fIn=ROOT.TFile.Open(opts.input)

if fIn==None:
print "[ERROR] File", opts.input, "doesn't exist"
raise IOError

h=fIn.Get(opts.base)
hUp=fIn.Get(opts.base+"_"+opts.syst+"Up")
hDown=fIn.Get(opts.base+"_"+opts.syst+"Down")

h.Rebin(opts.rebin)
hUp.Rebin(opts.rebin)
hDown.Rebin(opts.rebin)
if h==None:
print "[ERROR] Hist", opts.base, "doesn't exist"
raise IOError

hL=[]

if opts.syst!='Pdf' and opts.syst != 'Scale':
hUp=fIn.Get(opts.base+"_"+opts.syst+"Up")
hDown=fIn.Get(opts.base+"_"+opts.syst+"Down")
if hUp==None or hDown==None:
print "[ERROR] Hist", opts.base+"_"+opts.syst+"Up/Down", "doesn't exist"
raise IOError
hL = [hUp,hDown]
elif opts.syst=='Scale':
for w in [ 'R','F','RF']:
for s in ['Up','Down']:
hTmp=fIn.Get(opts.base+"_Scale"+w+s)
if hTmp==None:
print "[ERROR] Hist", opts.base+"_Scale"+w+s, "doesn't exist"
raise IOError
hL.append(hTmp)
elif opts.syst=='Pdf':
for i in range(0,100):
hTmp=fIn.Get(opts.base+"_Pdf%d"%i)
if hTmp==None:
print "[ERROR] Hist", opts.base+"_Pdf%d"%i, "doesn't exist"
raise IOError
hL.append(hTmp)

if opts.rebin> 999:
h=Rebin(h)
else:
h.Rebin(opts.rebin)

for idx,hTmp in enumerate(hL):
if opts.rebin> 999:
hL[idx]=Rebin(hTmp)
else:
hTmp.Rebin(opts.rebin)
#hUp.Rebin(opts.rebin)
#hDown.Rebin(opts.rebin)

h.SetLineColor(ROOT.kBlack)
hUp.SetLineColor(ROOT.kBlue)
hDown.SetLineColor(ROOT.kRed)

if len(hL)==2:
colors=[ROOT.kBlue,ROOT.kRed]
elif len(hL)==6:
colors=[ROOT.kBlue,ROOT.kBlue-4,ROOT.kRed,ROOT.kRed-4,ROOT.kGreen+2,ROOT.kGreen]
else:
colors=[
ROOT.kOrange-7,ROOT.kOrange-4,ROOT.kOrange,ROOT.kOrange+2,
ROOT.kRed+2,ROOT.kRed,ROOT.kRed-4,ROOT.kRed-7,
ROOT.kMagenta-7,ROOT.kMagenta-4,ROOT.kMagenta,ROOT.kMagenta+2,
ROOT.kBlue+2,ROOT.kBlue,ROOT.kBlue-4,ROOT.kBlue-7,
ROOT.kCyan,
ROOT.kGreen-7,ROOT.kGreen-4,ROOT.kGreen,ROOT.kGreen+2
]
for hTmp in hL:
mycolor=colors[0]
colors=colors[1:]+ [mycolor]
hTmp.SetLineColor(mycolor)

h.SetLineWidth(2)
hUp.SetLineWidth(2)
hDown.SetLineWidth(2)

hUp.SetLineStyle(7)
hDown.SetLineStyle(7)

for hTmp in hL:
hTmp.SetLineWidth(2)
hTmp.SetLineStyle(7)



h.Draw("HIST")
hUp.Draw("HIST SAME")
hDown.Draw("HIST SAME")
for hTmp in hL:
hTmp.Draw("HIST SAME")

c2=ROOT.TCanvas("c2")
r=h.Clone("r")

rL=[]
for hTmp in hL:
rTmp=hTmp.Clone("r"+hTmp.GetName())
rL.append(rTmp)

r.Divide(h)
for rTmp in rL:
rTmp.Divide(h)

r.Draw("HIST")
for rTmp in rL:
rTmp.Draw("HIST SAME")

r.GetYaxis().SetRangeUser(0.,2.)
raw_input("ok?")


19 changes: 18 additions & 1 deletion src/AnalysisBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,25 @@ string AnalysisBase::GetLabel(Event *e){
// return label;

label = "Other";

if (multipd_ and e->IsRealData() )
{
// filename
label = "Data"; // general backup option
for (string& s: AllLabel() )
{

if (e->IsRealData()) label = "Data";
if (e->GetName().find(s) != string::npos )
{
label=s;
break; // match the first
}
}
}
else if (e->IsRealData())
{
label = "Data";
}
else{
for (string& s: AllLabel() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/Loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void Looper::NewFile()

if ( event_->IsRealData() ) {
cout<<"[Looper]::[NewFile]::[INFO] Data file found"<<endl;;
event_ -> GetWeight() -> LoadMC("data");
event_ -> GetWeight() -> LoadMC("data");
}
// -- Load current MC --
else {
Expand Down

0 comments on commit 8bb8462

Please sign in to comment.