forked from h2gglobe/h2gglobe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PtSpinSmearer.cc
146 lines (117 loc) · 4.77 KB
/
PtSpinSmearer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "PtSpinSmearer.h"
#include "PhotonReducedInfo.h"
#include "TRandom3.h"
#include <assert.h>
#include "Macros/Normalization_8TeV.h"
PtSpinSmearer::PtSpinSmearer(const std::string & theFile, Normalization_8TeV * norm) : efficiency_file(theFile), norm_(norm)
{
name_="PtSpinSmearer";
}
PtSpinSmearer::~PtSpinSmearer()
{
}
void PtSpinSmearer::readMassPoint(int mass){
ptSpinSmearersSM_[mass] = std::vector<TH1*>(3,(TH1*)0);
ptSpinSmearersGGGRAV_[mass] = std::vector<TH1*>(3,(TH1*)0);
ptSpinSmearersQQGRAV_[mass] = std::vector<TH1*>(3,(TH1*)0);
// sm files
TH1* temp = (TH1F*) thePtSpinFile_->Get( Form("smNomRat%d",mass) );
assert(temp!=0);
ptSpinSmearersSM_[mass][0]=(TH1F*) temp->Clone(Form("smPtMass%d",mass));
ptSpinSmearersSM_[mass][0]->SetDirectory(0);
temp = (TH1F*) thePtSpinFile_->Get( Form("smUpRat%d",mass) );
assert(temp!=0);
ptSpinSmearersSM_[mass][1]=(TH1F*) temp->Clone(Form("smPtMass%d_up",mass));
ptSpinSmearersSM_[mass][1]->SetDirectory(0);
temp = (TH1F*) thePtSpinFile_->Get( Form("smDownRat%d",mass) );
assert(temp!=0);
ptSpinSmearersSM_[mass][2]=(TH1F*) temp->Clone(Form("smPtMass%d_down",mass));
ptSpinSmearersSM_[mass][2]->SetDirectory(0);
// gg files
temp = (TH1F*) thePtSpinFile_->Get( Form("ggNomRat%d",mass) );
assert(temp!=0);
ptSpinSmearersGGGRAV_[mass][0]=(TH1F*) temp->Clone(Form("ggPtMass%d",mass));
ptSpinSmearersGGGRAV_[mass][0]->SetDirectory(0);
temp = (TH1F*) thePtSpinFile_->Get( Form("ggUpRat%d",mass) );
assert(temp!=0);
ptSpinSmearersGGGRAV_[mass][1]=(TH1F*) temp->Clone(Form("ggPtMass%d_up",mass));
ptSpinSmearersGGGRAV_[mass][1]->SetDirectory(0);
temp = (TH1F*) thePtSpinFile_->Get( Form("ggDownRat%d",mass) );
assert(temp!=0);
ptSpinSmearersGGGRAV_[mass][2]=(TH1F*) temp->Clone(Form("ggPtMass%d_down",mass));
ptSpinSmearersGGGRAV_[mass][2]->SetDirectory(0);
// qq files
temp = (TH1F*) thePtSpinFile_->Get( Form("qqNomRat%d",mass) );
assert(temp!=0);
ptSpinSmearersQQGRAV_[mass][0]=(TH1F*) temp->Clone(Form("qqPtMass%d",mass));
ptSpinSmearersQQGRAV_[mass][0]->SetDirectory(0);
temp = (TH1F*) thePtSpinFile_->Get( Form("qqUpRat%d",mass) );
assert(temp!=0);
ptSpinSmearersQQGRAV_[mass][1]=(TH1F*) temp->Clone(Form("qqPtMass%d_up",mass));
ptSpinSmearersQQGRAV_[mass][1]->SetDirectory(0);
temp = (TH1F*) thePtSpinFile_->Get( Form("qqDownRat%d",mass) );
assert(temp!=0);
ptSpinSmearersQQGRAV_[mass][2]=(TH1F*) temp->Clone(Form("qqPtMass%d_down",mass));
ptSpinSmearersQQGRAV_[mass][2]->SetDirectory(0);
}
bool PtSpinSmearer::smearEvent( float & weight, const TLorentzVector & p4, const int nPu, const int sample_type, float syst_shift ) const
{
int genMassPoint;
string genType;
if( sample_type >= 0 ) { return true; }
genMassPoint = std::round(norm_->GetMass(sample_type));
TString type = norm_->GetProcess(sample_type);
if( type == "ggh" ) {
genType = "sm";
} else if ( type == "qq_grav" ) {
genType="qq";
} else if ( type == "gg_grav" ) {
genType="gg";
} else {
return true; // this is the case of backgrounds
}
double kWeight = getWeight( p4, nPu, genMassPoint, genType, syst_shift );
weight = (kWeight > 0) ? kWeight : 0;
return true;
}
bool PtSpinSmearer::init()
{
cout << name_ << " - Opening PtSpin file"<<endl;
thePtSpinFile_ = TFile::Open( efficiency_file.c_str() );
assert(thePtSpinFile_!=0);
readMassPoint(125);
readMassPoint(126);
thePtSpinFile_->Close();
return true;
}
double PtSpinSmearer::getPtSpin(int genMassPoint, std::string genType, int id, double gPT ) const {
if(genMassPoint==125 || genMassPoint==126) {
if (genType=="sm") {
const TH1* tmp = ptSpinSmearersSM_.find(genMassPoint)->second[id];
return tmp->GetBinContent(tmp->FindFixBin(gPT));
}
else if (genType=="gg"){
const TH1* tmp = ptSpinSmearersGGGRAV_.find(genMassPoint)->second[id];
return tmp->GetBinContent(tmp->FindFixBin(gPT));
}
else if (genType=="qq"){
const TH1* tmp = ptSpinSmearersQQGRAV_.find(genMassPoint)->second[id];
return tmp->GetBinContent(tmp->FindFixBin(gPT));
}
else {
assert(0.);
return 0.;
}
}
assert(0); return 0.;
}
double PtSpinSmearer::getWeight( const TLorentzVector & p4, const int nPu, const int & genMassPoint, const std::string & genType, float syst_shift) const
{
float gPT = p4.Pt();
// this is consistent with samples available on Tue Jun 21 18:10:03 CEST 2011
// bins are very fine, therefore interpolation between bins can be neglegted for now
int varId = syst_shift > 0 ? 1 : 2;
double nominal = getPtSpin( genMassPoint, genType, 0, gPT );
double variation = getPtSpin( genMassPoint, genType, varId, gPT );
return ( nominal + (variation-nominal) * fabs(syst_shift) );
}